57 #define DEBUG_TYPE "machinelicm" 61 cl::desc(
"MachineLICM should avoid speculation"),
66 cl::desc(
"MachineLICM should hoist even cheap instructions"),
71 cl::desc(
"MachineLICM should sink instructions into " 72 "loops to avoid register spills"),
80 "Number of machine instructions hoisted out of loops");
82 "Number of instructions hoisted in low reg pressure situation");
84 "Number of high latency instructions hoisted");
86 "Number of hoisted machine instructions CSEed");
88 "Number of machine instructions hoisted out of loops post regalloc");
90 "Number of stores of const phys reg hoisted out of loops");
144 unsigned SpeculationState;
147 MachineLICMBase(
char &PassID,
bool PreRegAlloc)
161 void releaseMemory()
override {
171 struct CandidateInfo {
177 : MI(mi), Def(def), FI(fi) {}
180 void HoistRegionPostRA();
188 void AddToLiveIns(
unsigned Reg);
214 void ExitScopeIfDone(
229 bool ConsiderUnseenAsDef);
232 bool ConsiderUnseenAsDef =
false);
238 std::vector<const MachineInstr *> &PrevMIs);
242 DenseMap<
unsigned, std::vector<const MachineInstr *>>::iterator &CI);
253 class MachineLICM :
public MachineLICMBase {
256 MachineLICM() : MachineLICMBase(ID,
false) {
261 class EarlyMachineLICM :
public MachineLICMBase {
264 EarlyMachineLICM() : MachineLICMBase(ID,
true) {
278 "Machine Loop Invariant Code Motion",
false,
false)
286 "Early
Machine Loop Invariant Code Motion", false, false)
291 "Early
Machine Loop Invariant Code Motion", false, false)
296 if (!CurLoop->getLoopPredecessor())
300 if (L->getLoopPredecessor())
310 Changed = FirstInLoop =
false;
317 SchedModel.
init(&ST);
319 PreRegAlloc = MRI->
isSSA();
330 RegPressure.
resize(NumRPS);
331 std::fill(RegPressure.
begin(), RegPressure.
end(), 0);
333 for (
unsigned i = 0, e = NumRPS; i != e; ++i)
338 MLI = &getAnalysis<MachineLoopInfo>();
339 DT = &getAnalysis<MachineDominatorTree>();
340 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
343 while (!Worklist.empty()) {
344 CurLoop = Worklist.pop_back_val();
345 CurPreheader =
nullptr;
351 Worklist.append(CurLoop->
begin(), CurLoop->
end());
386 if (!MemOp->isStore() || !MemOp->getPseudoValue())
389 dyn_cast<FixedStackPseudoSourceValue>(MemOp->getPseudoValue())) {
390 if (
Value->getFrameIndex() == FI)
404 bool RuledOut =
false;
405 bool HasNonInvariantUse =
false;
410 int FI = MO.getIndex();
411 if (!StoredFIs.
count(FI) &&
415 HasNonInvariantUse =
true;
421 if (MO.isRegMask()) {
428 unsigned Reg = MO.getReg();
432 "Not expecting virtual register!");
435 if (Reg && (PhysRegDefs.
test(Reg) || PhysRegClobbers.
test(Reg)))
438 HasNonInvariantUse =
true;
442 if (MO.isImplicit()) {
444 PhysRegClobbers.
set(*AI);
464 if (PhysRegDefs.
test(*
AS))
465 PhysRegClobbers.
set(*
AS);
466 PhysRegDefs.
set(*
AS);
468 if (PhysRegClobbers.
test(Reg))
476 if (Def && !RuledOut) {
477 int FI = std::numeric_limits<int>::min();
478 if ((!HasNonInvariantUse && IsLICMCandidate(*MI)) ||
480 Candidates.
push_back(CandidateInfo(MI, Def, FI));
486 void MachineLICMBase::HoistRegionPostRA() {
500 const std::vector<MachineBasicBlock *> &Blocks = CurLoop->
getBlocks();
510 for (
const auto &LI : BB->liveins()) {
512 PhysRegDefs.
set(*AI);
515 SpeculationState = SpeculateUnknown;
517 ProcessMI(&MI, PhysRegDefs, PhysRegClobbers, StoredFIs, Candidates);
523 if (TI != Preheader->
end()) {
527 unsigned Reg = MO.getReg();
543 for (CandidateInfo &Candidate : Candidates) {
544 if (Candidate.FI != std::numeric_limits<int>::min() &&
545 StoredFIs.
count(Candidate.FI))
548 unsigned Def = Candidate.Def;
549 if (!PhysRegClobbers.
test(Def) && !TermRegs.
test(Def)) {
553 if (!MO.isReg() || MO.isDef() || !MO.getReg())
555 unsigned Reg = MO.getReg();
556 if (PhysRegDefs.
test(Reg) ||
557 PhysRegClobbers.
test(Reg)) {
565 HoistPostRA(MI, Candidate.Def);
572 void MachineLICMBase::AddToLiveIns(
unsigned Reg) {
573 const std::vector<MachineBasicBlock *> &Blocks = CurLoop->
getBlocks();
575 if (!BB->isLiveIn(Reg))
579 if (!MO.isReg() || !MO.getReg() || MO.isDef())
continue;
614 if (SpeculationState != SpeculateUnknown)
615 return SpeculationState == SpeculateFalse;
622 if (!DT->
dominates(BB, CurrentLoopExitingBlock)) {
623 SpeculationState = SpeculateTrue;
628 SpeculationState = SpeculateFalse;
650 if (OpenChildren[Node])
654 ExitScope(Node->getBlock());
658 unsigned Left = --OpenChildren[Parent];
661 ExitScope(Parent->getBlock());
682 while (!WorkList.
empty()) {
684 assert(Node &&
"Null dominator tree node?");
698 const std::vector<MachineDomTreeNode*> &Children = Node->
getChildren();
699 unsigned NumChildren = Children.size();
707 OpenChildren[Node] = NumChildren;
711 for (
int i = (
int)NumChildren-1; i >= 0; --i) {
713 ParentMap[Child] = Node;
718 if (Scopes.
size() == 0)
724 InitRegPressure(Preheader);
733 SpeculationState = SpeculateUnknown;
735 MII = MBB->
begin(),
E = MBB->
end(); MII !=
E; ) {
738 if (!Hoist(MI, Preheader))
739 UpdateRegPressure(MI);
746 ExitScopeIfDone(Node, OpenChildren, ParentMap);
753 void MachineLICMBase::SinkIntoLoop() {
763 if (IsLoopInvariantInst(*
I) && !HasLoopPHIUse(&*
I))
794 if (!CanSink || !B || B == Preheader)
808 std::fill(RegPressure.
begin(), RegPressure.
end(), 0);
822 UpdateRegPressure(&MI,
true);
826 void MachineLICMBase::UpdateRegPressure(
const MachineInstr *MI,
827 bool ConsiderUnseenAsDef) {
828 auto Cost = calcRegisterCost(MI,
true, ConsiderUnseenAsDef);
829 for (
const auto &RPIdAndCost : Cost) {
830 unsigned Class = RPIdAndCost.first;
831 if (static_cast<int>(RegPressure[Class]) < -RPIdAndCost.second)
832 RegPressure[Class] = 0;
834 RegPressure[Class] += RPIdAndCost.second;
845 MachineLICMBase::calcRegisterCost(
const MachineInstr *MI,
bool ConsiderSeen,
846 bool ConsiderUnseenAsDef) {
854 unsigned Reg = MO.
getReg();
859 bool isNew = ConsiderSeen ? RegSeen.
insert(Reg).second :
false;
868 if (isNew && !isKill && ConsiderUnseenAsDef)
871 else if (!isNew && isKill)
877 for (; *PS != -1; ++PS) {
878 if (Cost.
find(*PS) == Cost.
end())
899 if (PSV->isGOT() || PSV->isConstantPool())
916 bool FoundCallerPresReg =
false;
924 unsigned Reg = MO.getReg();
934 FoundCallerPresReg =
true;
935 }
else if (!MO.isImm()) {
939 return FoundCallerPresReg;
967 "copy dst is not a virtual reg");
980 bool DontMoveAcrossStore =
true;
1003 bool MachineLICMBase::IsLoopInvariantInst(
MachineInstr &I) {
1004 if (!IsLICMCandidate(I))
1012 unsigned Reg = MO.getReg();
1013 if (Reg == 0)
continue;
1028 }
else if (!MO.isDead()) {
1042 "Machine instr not mapped for this vreg?!");
1056 bool MachineLICMBase::HasLoopPHIUse(
const MachineInstr *
MI)
const {
1061 if (!MO.isReg() || !MO.isDef())
1063 unsigned Reg = MO.getReg();
1068 if (
UseMI.isPHI()) {
1085 }
while (!Work.
empty());
1091 bool MachineLICMBase::HasHighOperandLatency(
MachineInstr &MI,
1093 unsigned Reg)
const {
1098 if (
UseMI.isCopyLike())
1102 for (
unsigned i = 0, e =
UseMI.getNumOperands(); i != e; ++i) {
1106 unsigned MOReg = MO.
getReg();
1123 bool MachineLICMBase::IsCheapInstruction(
MachineInstr &MI)
const {
1127 bool isCheap =
false;
1129 for (
unsigned i = 0, e = MI.
getNumOperands(); NumDefs && i != e; ++i) {
1134 unsigned Reg = DefMO.
getReg();
1151 for (
const auto &RPIdAndCost : Cost) {
1152 if (RPIdAndCost.second <= 0)
1155 unsigned Class = RPIdAndCost.first;
1156 int Limit = RegLimit[Class];
1163 for (
const auto &
RP : BackTrace)
1164 if (static_cast<int>(
RP[Class]) + RPIdAndCost.second >= Limit)
1174 void MachineLICMBase::UpdateBackTraceRegPressure(
const MachineInstr *MI) {
1177 auto Cost = calcRegisterCost(MI,
false,
1181 for (
auto &
RP : BackTrace)
1182 for (
const auto &RPIdAndCost : Cost)
1183 RP[RPIdAndCost.first] += RPIdAndCost.second;
1188 bool MachineLICMBase::IsProfitableToHoist(
MachineInstr &MI) {
1207 bool CheapInstr = IsCheapInstruction(MI);
1208 bool CreatesCopy = HasLoopPHIUse(&MI);
1211 if (CheapInstr && CreatesCopy) {
1212 LLVM_DEBUG(
dbgs() <<
"Won't hoist cheap instr with loop PHI use: " << MI);
1227 unsigned Reg = MO.
getReg();
1230 if (MO.
isDef() && HasHighOperandLatency(MI, i, Reg)) {
1243 auto Cost = calcRegisterCost(&MI,
false,
1248 if (!CanCauseHighRegPressure(Cost, CheapInstr)) {
1256 LLVM_DEBUG(
dbgs() <<
"Won't hoist instr with loop PHI use: " << MI);
1264 (!IsGuaranteedToExecute(MI.
getParent()) && !MayCSE(&MI))) {
1295 unsigned LoadRegIndex;
1301 if (NewOpc == 0)
return nullptr;
1314 "unfoldMemoryOperand failed when getOpcodeAfterMemoryUnfold " 1317 "Unfolded a load into multiple instructions!");
1320 MBB->insert(Pos, NewMIs[0]);
1321 MBB->insert(Pos, NewMIs[1]);
1324 if (!IsLoopInvariantInst(*NewMIs[0]) || !IsProfitableToHoist(*NewMIs[0])) {
1325 NewMIs[0]->eraseFromParent();
1326 NewMIs[1]->eraseFromParent();
1331 UpdateRegPressure(NewMIs[1]);
1349 MachineLICMBase::LookForDuplicate(
const MachineInstr *MI,
1350 std::vector<const MachineInstr*> &PrevMIs) {
1363 DenseMap<
unsigned, std::vector<const MachineInstr *>>::iterator &CI) {
1369 if (
const MachineInstr *Dup = LookForDuplicate(MI, CI->second)) {
1381 MO.
getReg() == Dup->getOperand(i).getReg()) &&
1382 "Instructions with different phys regs are not identical!");
1390 for (
unsigned i = 0, e = Defs.
size(); i != e; ++i) {
1391 unsigned Idx = Defs[i];
1393 unsigned DupReg = Dup->getOperand(Idx).getReg();
1398 for (
unsigned j = 0; j != i; ++j)
1399 MRI->
setRegClass(Dup->getOperand(Defs[j]).getReg(), OrigRCs[j]);
1404 for (
unsigned Idx : Defs) {
1406 unsigned DupReg = Dup->getOperand(Idx).getReg();
1423 CI = CSEMap.
find(Opcode);
1429 return LookForDuplicate(MI, CI->second) !=
nullptr;
1437 if (!IsLoopInvariantInst(*MI) || !IsProfitableToHoist(*MI)) {
1439 MI = ExtractHoistableLoad(MI);
1440 if (!MI)
return false;
1451 dbgs() <<
"Hoisting " << *
MI;
1462 InitCSEMap(Preheader);
1463 FirstInLoop =
false;
1469 CI = CSEMap.
find(Opcode);
1470 if (!EliminateCSE(MI, CI)) {
1480 UpdateBackTraceRegPressure(MI);
1486 if (MO.isReg() && MO.isDef() && !MO.isDead())
1490 if (CI != CSEMap.
end())
1491 CI->second.push_back(MI);
1493 CSEMap[Opcode].push_back(MI);
1508 if (CurPreheader == reinterpret_cast<MachineBasicBlock *>(-1))
1511 if (!CurPreheader) {
1513 if (!CurPreheader) {
1521 if (!CurPreheader) {
1527 return CurPreheader;
void push_back(const T &Elt)
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
instr_iterator instr_begin()
bool use_nodbg_empty(unsigned RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register...
virtual unsigned getNumRegPressureSets() const =0
Get the number of dimensions of register pressure.
instr_iterator instr_end()
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
Compute iterated dominance frontiers using a linear time algorithm.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
char & MachineLICMID
This pass performs loop invariant code motion on machine instructions.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
virtual const TargetLowering * getTargetLowering() const
bool test(unsigned Idx) const
void setBitsNotInMask(const uint32_t *Mask, unsigned MaskWords=~0u)
setBitsNotInMask - Add a bit to this vector for every '0' bit in Mask.
virtual const int * getRegClassPressureSets(const TargetRegisterClass *RC) const =0
Get the dimensions of register pressure impacted by this register class.
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
block Block Frequency true
static bool isExitBlock(BasicBlock *BB, const SmallVectorImpl< BasicBlock *> &ExitBlocks)
Return true if the specified block is in the list.
iterator_range< mmo_iterator > memoperands()
iterator_range< mop_iterator > operands()
bool isCopyLike() const
Return true if the instruction behaves like a copy.
static bool mayLoadFromGOTOrConstantPool(MachineInstr &MI)
Return true if this machine instruction loads from global offset table or constant pool...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
A description of a memory reference used in the backend.
Each TargetRegisterClass has a per register weight, and weight limit which must be less than the limi...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
Provide an instruction scheduling machine model to CodeGen passes.
const HexagonInstrInfo * TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
const TargetRegisterClass * getRegClass(const MCInstrDesc &MCID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
Given a machine instruction descriptor, returns the register class constraint for OpNum...
static bool isOperandKill(const MachineOperand &MO, MachineRegisterInfo *MRI)
virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr &MI, unsigned Reg, bool UnfoldLoad, bool UnfoldStore, SmallVectorImpl< MachineInstr *> &NewMIs) const
unfoldMemoryOperand - Separate a single instruction which folded a load or a store or a load and a st...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
virtual bool hasLowDefLatency(const TargetSchedModel &SchedModel, const MachineInstr &DefMI, unsigned DefIdx) const
Compute operand latency of a def of 'Reg'.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static cl::opt< bool > AvoidSpeculation("avoid-speculation", cl::desc("MachineLICM should avoid speculation"), cl::init(true), cl::Hidden)
BlockT * getHeader() const
MachineInstr * getVRegDef(unsigned Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
void getExitBlocks(SmallVectorImpl< BlockT *> &ExitBlocks) const
Return all of the successor blocks of this loop.
Machine Loop Invariant Code Motion
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
void clearKillFlags(unsigned Reg) const
clearKillFlags - Iterate over all the uses of the given register and clear the kill flag from the Mac...
Base class for the actual dominator tree node.
const std::vector< DomTreeNodeBase * > & getChildren() const
COFF::MachineTypes Machine
virtual const TargetInstrInfo * getInstrInfo() const
MachineBasicBlock * findNearestCommonDominator(MachineBasicBlock *A, MachineBasicBlock *B)
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
bool isDereferenceableInvariantLoad(AliasAnalysis *AA) const
Return true if this load instruction never traps and points to a memory location whose value doesn't ...
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
TargetInstrInfo - Interface to description of machine instruction set.
bool isSuperRegister(unsigned RegA, unsigned RegB) const
Returns true if RegB is a super-register of RegA.
iterator find(const_arg_type_t< KeyT > Val)
bool mayStore(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly modify memory.
unsigned getNumRegs() const
Return the number of registers this target has (useful for sizing arrays holding per register informa...
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineInstrBuilder & UseMI
Machine Loop Invariant Code false early Early Machine Loop Invariant Code static false bool LoopIsOuterMostWithPredecessor(MachineLoop *CurLoop)
Test if the given loop is the outer-most loop that has a unique predecessor.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
static cl::opt< bool > HoistCheapInsts("hoist-cheap-insts", cl::desc("MachineLICM should hoist even cheap instructions"), cl::init(false), cl::Hidden)
MCRegAliasIterator enumerates all registers aliasing Reg.
Represent the analysis usage information of a pass.
static bool InstructionStoresToFI(const MachineInstr *MI, int FI)
Return true if instruction stores to the specified frame.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void init(const TargetSubtargetInfo *TSInfo)
Initialize the machine model for instruction scheduling.
void getExitingBlocks(SmallVectorImpl< BlockT *> &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
bool isImplicitDef() const
virtual bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify=false) const
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
static bool isInvariantStore(const MachineInstr &MI, const TargetRegisterInfo *TRI, const MachineRegisterInfo *MRI)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
bool isConstantPhysReg(unsigned PhysReg) const
Returns true if PhysReg is unallocatable and constant throughout the function.
void initializeMachineLICMPass(PassRegistry &)
This base class for TargetLowering contains the SelectionDAG-independent parts that can be used from ...
virtual bool isAsCheapAsAMove(const MachineInstr &MI) const
Return true if the instruction is as cheap as a move instruction.
BlockT * getLoopPredecessor() const
If the given loop's header has exactly one unique predecessor outside the loop, return it...
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Iterator for intrusive lists based on ilist_node.
MachineOperand class - Representation of each machine instruction operand.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
virtual const RegClassWeight & getRegClassWeight(const TargetRegisterClass *RC) const =0
Get the weight in units of pressure for this register class.
bool dominates(const MachineDomTreeNode *A, const MachineDomTreeNode *B) const
virtual bool hasHighOperandLatency(const TargetSchedModel &SchedModel, const MachineRegisterInfo *MRI, const MachineInstr &DefMI, unsigned DefIdx, const MachineInstr &UseMI, unsigned UseIdx) const
Compute operand latency between a def of 'Reg' and a use in the current loop.
LLVM_NODISCARD T pop_back_val()
char & EarlyMachineLICMID
This pass performs loop invariant code motion on machine instructions.
Machine Loop Invariant Code false early machinelicm
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
unsigned pred_size() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
void setDebugLoc(DebugLoc dl)
Replace current source information with new such.
Special value supplied for machine level alias analysis.
void replaceRegWith(unsigned FromReg, unsigned ToReg)
replaceRegWith - Replace all instances of FromReg with ToReg in the machine function.
unsigned succ_size() const
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
TargetSubtargetInfo - Generic base class for all target subtargets.
LoopT * getParentLoop() const
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_NODISCARD bool empty() const
virtual unsigned isLoadFromStackSlot(const MachineInstr &MI, int &FrameIndex) const
If the specified machine instruction is a direct load from a stack slot, return the virtual or physic...
virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, unsigned Idx) const =0
Get the register unit pressure limit for this dimension.
Represents a single loop in the control flow graph.
ArrayRef< BlockT * > getBlocks() const
Get a list of the basic blocks which make up this loop.
bool canFoldAsLoad(QueryType Type=IgnoreBundle) const
Return true for instructions that can be folded as memory operands in other instructions.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
virtual bool produceSameValue(const MachineInstr &MI0, const MachineInstr &MI1, const MachineRegisterInfo *MRI=nullptr) const
Return true if two machine instructions would produce identical values.
INITIALIZE_PASS_BEGIN(MachineLICM, DEBUG_TYPE, "Machine Loop Invariant Code Motion", false, false) INITIALIZE_PASS_END(MachineLICM
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
virtual bool isCallerPreservedPhysReg(unsigned PhysReg, const MachineFunction &MF) const
Physical registers that may be modified within a function but are guaranteed to be restored before an...
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool hasOneNonDBGUse(unsigned RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static bool isCopyFeedingInvariantStore(const MachineInstr &MI, const MachineRegisterInfo *MRI, const TargetRegisterInfo *TRI)
iterator_range< use_instr_iterator > use_instructions(unsigned Reg) const
void initializeEarlyMachineLICMPass(PassRegistry &)
bool mayLoad(QueryType Type=AnyInBundle) const
Return true if this instruction could possibly read memory.
bool memoperands_empty() const
Return true if we don't have any memory operands which described the memory access done by this instr...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P)
Split the critical edge from this block to the given successor block, and return the newly created bl...
static cl::opt< bool > HoistConstStores("hoist-const-stores", cl::desc("Hoist invariant stores"), cl::init(true), cl::Hidden)
LLVM Value Representation.
static cl::opt< bool > SinkInstsToAvoidSpills("sink-insts-to-avoid-spills", cl::desc("MachineLICM should sink instructions into " "loops to avoid register spills"), cl::init(false), cl::Hidden)
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the innermost loop that BB lives in.
bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore...
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
A specialized PseudoSourceValue for holding FixedStack values, which must include a frame index...
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
bool isTriviallyReMaterializable(const MachineInstr &MI, AliasAnalysis *AA=nullptr) const
Return true if the instruction is trivially rematerializable, meaning it has no side effects and requ...
virtual unsigned lookThruCopyLike(unsigned SrcReg, const MachineRegisterInfo *MRI) const
Returns the original SrcReg unless it is the target of a copy-like operation, in which case we chain ...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc, bool UnfoldLoad, bool UnfoldStore, unsigned *LoadRegIndex=nullptr) const
Returns the opcode of the would be new instruction after load / store are unfolded from an instructio...
bool isSafeToMove(AliasAnalysis *AA, bool &SawStore) const
Return true if it is safe to move this instruction.
unsigned createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
bool isSpillSlotObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a spill slot.
This file describes how to lower LLVM code to machine code.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.