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);
470 PhysRegDefs.
set(*AS);
472 if (PhysRegClobbers.
test(Reg))
480 if (Def && !RuledOut) {
481 int FI = std::numeric_limits<int>::min();
482 if ((!HasNonInvariantUse && IsLICMCandidate(*MI)) ||
484 Candidates.
push_back(CandidateInfo(MI, Def, FI));
490 void MachineLICMBase::HoistRegionPostRA() {
513 for (
const auto &LI : BB->liveins()) {
515 PhysRegDefs.
set(*AI);
518 SpeculationState = SpeculateUnknown;
520 ProcessMI(&MI, PhysRegDefs, PhysRegClobbers, StoredFIs, Candidates);
526 if (TI != Preheader->
end()) {
530 unsigned Reg = MO.getReg();
546 for (CandidateInfo &Candidate : Candidates) {
547 if (Candidate.FI != std::numeric_limits<int>::min() &&
548 StoredFIs.
count(Candidate.FI))
551 unsigned Def = Candidate.Def;
552 if (!PhysRegClobbers.
test(Def) && !TermRegs.
test(Def)) {
556 if (!MO.isReg() || MO.isDef() || !MO.getReg())
558 unsigned Reg = MO.getReg();
559 if (PhysRegDefs.
test(Reg) ||
560 PhysRegClobbers.
test(Reg)) {
568 HoistPostRA(MI, Candidate.Def);
575 void MachineLICMBase::AddToLiveIns(
unsigned Reg) {
577 if (!BB->isLiveIn(Reg))
581 if (!MO.isReg() || !MO.getReg() || MO.isDef())
continue;
616 if (SpeculationState != SpeculateUnknown)
617 return SpeculationState == SpeculateFalse;
624 if (!DT->
dominates(BB, CurrentLoopExitingBlock)) {
625 SpeculationState = SpeculateTrue;
630 SpeculationState = SpeculateFalse;
652 if (OpenChildren[Node])
656 ExitScope(Node->getBlock());
660 unsigned Left = --OpenChildren[Parent];
663 ExitScope(Parent->getBlock());
684 while (!WorkList.
empty()) {
686 assert(Node &&
"Null dominator tree node?");
700 const std::vector<MachineDomTreeNode*> &Children = Node->
getChildren();
701 unsigned NumChildren = Children.size();
709 OpenChildren[Node] = NumChildren;
713 for (
int i = (
int)NumChildren-1; i >= 0; --i) {
715 ParentMap[Child] = Node;
720 if (Scopes.
size() == 0)
726 InitRegPressure(Preheader);
735 SpeculationState = SpeculateUnknown;
737 MII = MBB->
begin(),
E = MBB->
end(); MII !=
E; ) {
740 if (!Hoist(MI, Preheader))
741 UpdateRegPressure(MI);
748 ExitScopeIfDone(Node, OpenChildren, ParentMap);
755 void MachineLICMBase::SinkIntoLoop() {
765 if (IsLoopInvariantInst(*
I) && !HasLoopPHIUse(&*
I))
796 if (!CanSink || !B || B == Preheader)
810 std::fill(RegPressure.
begin(), RegPressure.
end(), 0);
824 UpdateRegPressure(&MI,
true);
828 void MachineLICMBase::UpdateRegPressure(
const MachineInstr *MI,
829 bool ConsiderUnseenAsDef) {
830 auto Cost = calcRegisterCost(MI,
true, ConsiderUnseenAsDef);
831 for (
const auto &RPIdAndCost : Cost) {
832 unsigned Class = RPIdAndCost.first;
833 if (static_cast<int>(RegPressure[Class]) < -RPIdAndCost.second)
834 RegPressure[Class] = 0;
836 RegPressure[Class] += RPIdAndCost.second;
847 MachineLICMBase::calcRegisterCost(
const MachineInstr *MI,
bool ConsiderSeen,
848 bool ConsiderUnseenAsDef) {
856 unsigned Reg = MO.
getReg();
861 bool isNew = ConsiderSeen ? RegSeen.
insert(Reg).second :
false;
870 if (isNew && !isKill && ConsiderUnseenAsDef)
873 else if (!isNew && isKill)
879 for (; *PS != -1; ++PS) {
880 if (Cost.
find(*PS) == Cost.
end())
901 if (PSV->isGOT() || PSV->isConstantPool())
918 bool FoundCallerPresReg =
false;
926 unsigned Reg = MO.getReg();
936 FoundCallerPresReg =
true;
937 }
else if (!MO.isImm()) {
941 return FoundCallerPresReg;
969 "copy dst is not a virtual reg");
982 bool DontMoveAcrossStore =
true;
1005 bool MachineLICMBase::IsLoopInvariantInst(
MachineInstr &I) {
1006 if (!IsLICMCandidate(I))
1014 unsigned Reg = MO.getReg();
1015 if (Reg == 0)
continue;
1030 }
else if (!MO.isDead()) {
1044 "Machine instr not mapped for this vreg?!");
1058 bool MachineLICMBase::HasLoopPHIUse(
const MachineInstr *
MI)
const {
1063 if (!MO.isReg() || !MO.isDef())
1065 unsigned Reg = MO.getReg();
1070 if (
UseMI.isPHI()) {
1087 }
while (!Work.
empty());
1093 bool MachineLICMBase::HasHighOperandLatency(
MachineInstr &MI,
1095 unsigned Reg)
const {
1100 if (
UseMI.isCopyLike())
1104 for (
unsigned i = 0, e =
UseMI.getNumOperands(); i != e; ++i) {
1108 unsigned MOReg = MO.
getReg();
1125 bool MachineLICMBase::IsCheapInstruction(
MachineInstr &MI)
const {
1129 bool isCheap =
false;
1131 for (
unsigned i = 0, e = MI.
getNumOperands(); NumDefs && i != e; ++i) {
1136 unsigned Reg = DefMO.
getReg();
1153 for (
const auto &RPIdAndCost : Cost) {
1154 if (RPIdAndCost.second <= 0)
1157 unsigned Class = RPIdAndCost.first;
1158 int Limit = RegLimit[Class];
1165 for (
const auto &
RP : BackTrace)
1166 if (static_cast<int>(
RP[Class]) + RPIdAndCost.second >= Limit)
1176 void MachineLICMBase::UpdateBackTraceRegPressure(
const MachineInstr *MI) {
1179 auto Cost = calcRegisterCost(MI,
false,
1183 for (
auto &
RP : BackTrace)
1184 for (
const auto &RPIdAndCost : Cost)
1185 RP[RPIdAndCost.first] += RPIdAndCost.second;
1190 bool MachineLICMBase::IsProfitableToHoist(
MachineInstr &MI) {
1209 bool CheapInstr = IsCheapInstruction(MI);
1210 bool CreatesCopy = HasLoopPHIUse(&MI);
1213 if (CheapInstr && CreatesCopy) {
1214 LLVM_DEBUG(
dbgs() <<
"Won't hoist cheap instr with loop PHI use: " << MI);
1229 unsigned Reg = MO.
getReg();
1232 if (MO.
isDef() && HasHighOperandLatency(MI, i, Reg)) {
1245 auto Cost = calcRegisterCost(&MI,
false,
1250 if (!CanCauseHighRegPressure(Cost, CheapInstr)) {
1258 LLVM_DEBUG(
dbgs() <<
"Won't hoist instr with loop PHI use: " << MI);
1266 (!IsGuaranteedToExecute(MI.
getParent()) && !MayCSE(&MI))) {
1297 unsigned LoadRegIndex;
1303 if (NewOpc == 0)
return nullptr;
1316 "unfoldMemoryOperand failed when getOpcodeAfterMemoryUnfold " 1319 "Unfolded a load into multiple instructions!");
1322 MBB->insert(Pos, NewMIs[0]);
1323 MBB->insert(Pos, NewMIs[1]);
1326 if (!IsLoopInvariantInst(*NewMIs[0]) || !IsProfitableToHoist(*NewMIs[0])) {
1327 NewMIs[0]->eraseFromParent();
1328 NewMIs[1]->eraseFromParent();
1333 UpdateRegPressure(NewMIs[1]);
1351 MachineLICMBase::LookForDuplicate(
const MachineInstr *MI,
1352 std::vector<const MachineInstr*> &PrevMIs) {
1365 DenseMap<
unsigned, std::vector<const MachineInstr *>>::iterator &CI) {
1371 if (
const MachineInstr *Dup = LookForDuplicate(MI, CI->second)) {
1383 MO.
getReg() == Dup->getOperand(i).getReg()) &&
1384 "Instructions with different phys regs are not identical!");
1392 for (
unsigned i = 0, e = Defs.
size(); i != e; ++i) {
1393 unsigned Idx = Defs[i];
1395 unsigned DupReg = Dup->getOperand(Idx).getReg();
1400 for (
unsigned j = 0; j != i; ++j)
1401 MRI->
setRegClass(Dup->getOperand(Defs[j]).getReg(), OrigRCs[j]);
1406 for (
unsigned Idx : Defs) {
1408 unsigned DupReg = Dup->getOperand(Idx).getReg();
1425 CI = CSEMap.
find(Opcode);
1431 return LookForDuplicate(MI, CI->second) !=
nullptr;
1439 if (!IsLoopInvariantInst(*MI) || !IsProfitableToHoist(*MI)) {
1441 MI = ExtractHoistableLoad(MI);
1442 if (!MI)
return false;
1453 dbgs() <<
"Hoisting " << *
MI;
1464 InitCSEMap(Preheader);
1465 FirstInLoop =
false;
1471 CI = CSEMap.
find(Opcode);
1472 if (!EliminateCSE(MI, CI)) {
1482 UpdateBackTraceRegPressure(MI);
1488 if (MO.isReg() && MO.isDef() && !MO.isDead())
1492 if (CI != CSEMap.
end())
1493 CI->second.push_back(MI);
1495 CSEMap[Opcode].push_back(MI);
1510 if (CurPreheader == reinterpret_cast<MachineBasicBlock *>(-1))
1513 if (!CurPreheader) {
1515 if (!CurPreheader) {
1523 if (!CurPreheader) {
1529 return CurPreheader;
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.
This class represents lattice values for constants.
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.
void push_back(const T &Elt)
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< 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
Retuns the total number of operands.
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
ArrayRef< MachineMemOperand * > memoperands() const
Access to memory operands of the instruction.
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.