26 #include "llvm/Config/llvm-config.h" 40 #define DEBUG_TYPE "codegen" 44 cl::desc(
"When printing machine IR, annotate instructions and blocks with " 45 "SlotIndexes when available"),
49 : BB(B),
Number(-1), xParent(&MF) {
55 MachineBasicBlock::~MachineBasicBlock() {
60 if (!CachedMCSymbol) {
70 return CachedMCSymbol;
99 I->AddRegOperandsToUseLists(RegInfo);
111 assert(!N->
getParent() &&
"machine instruction already in a basic block");
112 N->setParent(Parent);
117 N->AddRegOperandsToUseLists(MF->
getRegInfo());
118 MF->handleInsertion(*N);
128 MF->handleRemoval(*N);
129 N->RemoveRegOperandsFromUseLists(MF->
getRegInfo());
132 N->setParent(
nullptr);
140 assert(Parent->getParent() == FromList.Parent->getParent() &&
141 "cannot transfer MachineInstrs between MachineFunctions");
144 if (
this == &FromList)
147 assert(Parent != FromList.Parent &&
"Two lists have the same parent?");
151 for (; First != Last; ++First)
152 First->setParent(Parent);
157 Parent->getParent()->DeleteMachineInstr(MI);
162 while (I !=
E && I->isPHI())
164 assert((I ==
E || !I->isInsideBundle()) &&
165 "First non-phi MI cannot be inside a bundle!");
174 while (I != E && (I->isPHI() || I->isPosition() ||
179 assert((I == E || !I->isInsideBundle()) &&
180 "First non-phi / non-label instruction is inside a bundle!");
189 while (I != E && (I->isPHI() || I->isPosition() || I->isDebugInstr() ||
194 assert((I == E || !I->isInsideBundle()) &&
195 "First non-phi / non-label / non-debug " 196 "instruction is inside a bundle!");
202 while (
I != B && ((--
I)->isTerminator() ||
I->isDebugInstr()))
204 while (
I !=
E && !
I->isTerminator())
211 while (
I != B && ((--
I)->isTerminator() ||
I->isDebugInstr()))
213 while (
I !=
E && !
I->isTerminator())
229 if (
I->isDebugInstr() ||
I->isInsideBundle())
244 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 258 return LBB->getName();
276 bool IsStandalone)
const {
279 OS <<
"Can't print out MachineBasicBlock because parent MachineFunction" 287 print(OS, MST, Indexes, IsStandalone);
292 bool IsStandalone)
const {
295 OS <<
"Can't print out MachineBasicBlock because parent MachineFunction" 304 bool HasAttributes =
false;
309 HasAttributes =
true;
313 OS <<
"<ir-block badref>";
315 OS << (
Twine(
"%ir-block.") +
Twine(Slot)).str();
320 OS << (HasAttributes ?
", " :
" (");
321 OS <<
"address-taken";
322 HasAttributes =
true;
325 OS << (HasAttributes ?
", " :
" (");
327 HasAttributes =
true;
330 OS << (HasAttributes ?
", " :
" (");
332 HasAttributes =
true;
341 bool HasLineAttributes =
false;
345 if (Indexes) OS <<
'\t';
347 OS <<
"; predecessors: ";
354 HasLineAttributes =
true;
358 if (Indexes) OS <<
'\t';
360 OS.
indent(2) <<
"successors: ";
370 if (!Probs.empty() && IsStandalone) {
387 HasLineAttributes =
true;
391 if (Indexes) OS <<
'\t';
392 OS.
indent(2) <<
"liveins: ";
395 for (
const auto &LI :
liveins()) {
400 if (!LI.LaneMask.all())
403 HasLineAttributes =
true;
406 if (HasLineAttributes)
409 bool IsInBundle =
false;
422 OS.
indent(IsInBundle ? 4 : 2);
423 MI.
print(OS, MST, IsStandalone,
false,
false,
436 if (IrrLoopHeaderWeight && IsStandalone) {
437 if (Indexes) OS <<
'\t';
438 OS.
indent(2) <<
"; Irreducible loop header weight: " 439 << IrrLoopHeaderWeight.
getValue() <<
'\n';
451 if (I == LiveIns.end())
454 I->LaneMask &= ~LaneMask;
455 if (I->LaneMask.none())
462 LiveInVector::iterator LI = LiveIns.begin() + (I - LiveIns.begin());
463 return LiveIns.erase(LI);
469 return I !=
livein_end() && (I->LaneMask & LaneMask).any();
478 LiveInVector::const_iterator
I = LiveIns.begin();
479 LiveInVector::const_iterator J;
480 LiveInVector::iterator Out = LiveIns.begin();
481 for (; I != LiveIns.end(); ++Out, I = J) {
482 unsigned PhysReg = I->PhysReg;
484 for (J = std::next(I); J != LiveIns.end() && J->PhysReg == PhysReg; ++J)
485 LaneMask |= J->LaneMask;
486 Out->PhysReg = PhysReg;
487 Out->LaneMask = LaneMask;
489 LiveIns.erase(Out, LiveIns.end());
496 assert(RC &&
"Register class is required");
498 "Only the entry block and landing pads can have physreg live ins");
507 for (;I !=
E && I->isCopy(); ++
I)
508 if (I->getOperand(1).getReg() == PhysReg) {
509 Register VirtReg = I->getOperand(0).getReg();
543 assert(!B &&
"UpdateTerminators requires analyzable predecessors!");
555 if ((*SI)->isEHPad())
557 assert(!TBB &&
"Found more than one non-landing-pad successor!");
595 if ((*SI)->isEHPad() || *
SI == TBB)
597 assert(!FallthroughBB &&
"Found more than one fallthrough successor.");
601 if (!FallthroughBB) {
630 TII->
insertBranch(*
this, FallthroughBB,
nullptr, Cond, DL);
634 TII->
insertBranch(*
this, FallthroughBB,
nullptr, Cond, DL);
644 for (
auto Prob : Probs)
645 Sum += Prob.getNumerator();
651 "The sum of successors's probabilities exceeds one.");
659 if (!(Probs.empty() && !Successors.empty()))
660 Probs.push_back(Prob);
661 Successors.push_back(Succ);
662 Succ->addPredecessor(
this);
670 Successors.push_back(Succ);
671 Succ->addPredecessor(
this);
676 bool NormalizeSuccProbs) {
678 assert(OldI !=
succ_end() &&
"Old is not a successor of this block!");
680 "New is already a successor of this block!");
688 : *getProbabilityIterator(OldI));
689 if (NormalizeSuccProbs)
694 bool NormalizeSuccProbs) {
701 assert(I != Successors.end() &&
"Not a current successor!");
705 if (!Probs.empty()) {
706 probability_iterator WI = getProbabilityIterator(I);
708 if (NormalizeSuccProbs)
712 (*I)->removePredecessor(
this);
713 return Successors.erase(I);
736 assert(OldI != E &&
"Old is not a successor of this block");
740 Old->removePredecessor(
this);
741 New->addPredecessor(
this);
748 if (!Probs.empty()) {
749 auto ProbIter = getProbabilityIterator(NewI);
750 if (!ProbIter->isUnknown())
751 *ProbIter += *getProbabilityIterator(OldI);
758 if (Orig->Probs.empty())
765 Predecessors.push_back(Pred);
770 assert(I != Predecessors.end() &&
"Pred is not a predecessor of this block!");
771 Predecessors.erase(I);
783 if (!FromMBB->Probs.empty()) {
784 auto Prob = *FromMBB->Probs.begin();
800 if (!FromMBB->Probs.empty()) {
801 auto Prob = *FromMBB->Probs.begin();
853 if (!TBB)
return &*Fallthrough;
859 return &*Fallthrough;
863 if (Cond.
empty())
return nullptr;
867 return (FBB ==
nullptr) ? &*Fallthrough :
nullptr;
893 Indexes->insertMBBInMaps(NMBB);
908 if (!OI->isReg() || OI->getReg() == 0 ||
909 !OI->isUse() || !OI->isKill() || OI->isUndef())
914 KilledRegs.push_back(Reg);
916 OI->setIsKill(
false);
929 if (!OI->isReg() || OI->getReg() == 0)
959 E = Terminators.
end();
I !=
E; ++
I) {
961 Indexes->removeMachineInstrFromMaps(**
I);
976 if (Indexes->hasIndex(MI))
977 Indexes->removeMachineInstrFromMaps(MI);
978 Indexes->insertMachineInstrInMaps(MI);
987 for (
const auto &LI : Succ->
liveins())
994 while (!KilledRegs.empty()) {
995 unsigned Reg = KilledRegs.pop_back_val();
997 if (!(--
I)->addRegisterKilled(Reg, TRI,
false))
1020 SlotIndex StartIndex = Indexes->getMBBEndIdx(
this);
1022 SlotIndex EndIndex = Indexes->getMBBEndIdx(NMBB);
1028 I !=
E &&
I->isPHI(); ++
I) {
1029 for (
unsigned ni = 1, ne =
I->getNumOperands(); ni != ne; ni += 2) {
1030 if (
I->getOperand(ni+1).getMBB() == NMBB) {
1040 "PHI sources should be live out of their predecessors.");
1053 if (!LI.
liveAt(PrevIndex))
1057 if (isLiveOut && isLastMBB) {
1059 assert(VNI &&
"LiveInterval should have VNInfo where it is live.");
1061 }
else if (!isLiveOut && !isLastMBB) {
1073 MDT->recordSplitCriticalEdge(
this, Succ, NMBB);
1079 if (
MachineLoop *DestLoop = MLI->getLoopFor(Succ)) {
1080 if (TIL == DestLoop) {
1082 DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase());
1083 }
else if (TIL->contains(DestLoop)) {
1085 TIL->addBasicBlockToLoop(NMBB, MLI->getBase());
1086 }
else if (DestLoop->contains(TIL)) {
1088 DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase());
1094 assert(DestLoop->getHeader() == Succ &&
1095 "Should not create irreducible loops!");
1097 P->addBasicBlockToLoop(NMBB, MLI->getBase());
1125 if (TII->
analyzeBranch(*const_cast<MachineBasicBlock *>(
this), TBB, FBB, Cond,
1133 if (TBB && TBB == FBB) {
1134 LLVM_DEBUG(
dbgs() <<
"Won't split critical edge after degenerate " 1157 return Insts.
erase(I);
1170 "Cannot insert instruction with bundle flags");
1172 if (I !=
instr_end() && I->isBundledWithPred()) {
1176 return Insts.
insert(I, MI);
1197 assert(Old != New &&
"Cannot replace self with self!");
1202 if (!I->isTerminator())
break;
1206 for (
unsigned i = 0,
e = I->getNumOperands(); i !=
e; ++i)
1207 if (I->getOperand(i).isMBB() &&
1208 I->getOperand(i).getMBB() == Old)
1209 I->getOperand(i).setMBB(New);
1250 bool Changed =
false;
1254 if (!DestA && !DestB) {
1258 }
else if (DestA && !DestB) {
1263 assert(DestA && DestB && IsCond &&
1264 "CFG in a bad state. Cannot correct CFG edges");
1273 if (!SeenMBBs.
insert(MBB).second ||
1274 (MBB != DestA && MBB != DestB && !MBB->
isEHPad())) {
1295 return MBBI->getDebugLoc();
1305 if (!MBBI->isDebugInstr())
return MBBI->getDebugLoc();
1315 while (TI !=
end() && !TI->isBranch())
1319 DL = TI->getDebugLoc();
1320 for (++TI ; TI !=
end() ; ++TI)
1333 const auto &Prob = *getProbabilityIterator(Succ);
1334 if (Prob.isUnknown()) {
1337 unsigned KnownProbNum = 0;
1339 for (
auto &
P : Probs) {
1340 if (!
P.isUnknown()) {
1345 return Sum.getCompl() / (Probs.size() - KnownProbNum);
1356 *getProbabilityIterator(I) = Prob;
1360 MachineBasicBlock::const_probability_iterator
1361 MachineBasicBlock::getProbabilityIterator(
1363 assert(Probs.size() == Successors.size() &&
"Async probability list!");
1364 const size_t index = std::distance(Successors.begin(),
I);
1365 assert(index < Probs.size() &&
"Not a current successor!");
1366 return Probs.begin() + index;
1370 MachineBasicBlock::probability_iterator
1372 assert(Probs.size() == Successors.size() &&
"Async probability list!");
1373 const size_t index = std::distance(Successors.begin(),
I);
1374 assert(index < Probs.size() &&
"Not a current successor!");
1375 return Probs.begin() + index;
1387 unsigned Neighborhood)
const {
1388 unsigned N = Neighborhood;
1392 for (; I !=
end() && N > 0; ++
I) {
1393 if (I->isDebugInstr())
1431 if (I->isDebugInstr())
1460 }
while (I !=
begin() && N > 0);
1465 while (I !=
begin() && std::prev(I)->isDebugInstr())
1503 "Liveness information is accurate");
1504 return LiveIns.begin();
Pass interface - Implemented by all 'passes'.
void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
const MCAsmInfo * getAsmInfo() const
unsigned Log2(Align A)
Returns the log2 of the alignment.
mop_iterator operands_end()
void validateSuccProbs() const
Validate successors' probabilities and check if the sum of them is approximate one.
instr_iterator instr_begin()
Wrapper class representing physical registers. Should be passed by value.
instr_iterator instr_end()
MachineBasicBlock * getMBB() const
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
MachineBasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
iterator erase(iterator where)
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void addNodeToList(NodeTy *)
When an MBB is added to an MF, we need to update the parent pointer of the MBB, the MBB numbering...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before...
A Module instance is used to store all the information related to an LLVM module. ...
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
void push_back(const T &Elt)
iterator getFirstNonDebugInstr()
Returns an iterator to the first non-debug instruction in the basic block, or end().
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
LiveInterval - This class represents the liveness of a register, or stack slot.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
bool requiresStructuredCFG() const
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
virtual const uint32_t * getNoPreservedMask() const
Return a register mask that clobbers everything.
virtual unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, ArrayRef< MachineOperand > Cond, const DebugLoc &DL, int *BytesAdded=nullptr) const
Insert branch code into the end of the specified MachineBasicBlock.
Template traits for intrusive list.
void addSuccessorWithoutProb(MachineBasicBlock *Succ)
Add Succ as a successor of this MachineBasicBlock.
PhysRegInfo AnalyzePhysRegInBundle(const MachineInstr &MI, unsigned Reg, const TargetRegisterInfo *TRI)
AnalyzePhysRegInBundle - Analyze how the current instruction or bundle uses a physical register...
This represents a simple continuous liveness interval for a value.
void moveAfter(MachineBasicBlock *NewBefore)
unsigned const TargetRegisterInfo * TRI
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Manage lifetime of a slot tracker for printing IR.
MachineInstrBundleIterator< const MachineInstr > const_iterator
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
VNInfo - Value Number Information.
virtual unsigned removeBranch(MachineBasicBlock &MBB, int *BytesRemoved=nullptr) const
Remove the branching code at the end of the specific MBB.
MachineBasicBlock * removeFromParent()
This method unlinks 'this' from the containing function, and returns it, but does not delete it...
BasicBlockListType::const_iterator const_iterator
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
iterator_range< succ_iterator > successors()
bool removeKill(MachineInstr &MI)
removeKill - Delete a kill corresponding to the specified machine instruction.
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Given a machine basic block that branched to 'Old', change the code and CFG so that it branches to 'N...
void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const
Check if the edge between this block and the given successor Succ, can be split.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const HexagonInstrInfo * TII
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getNumOperands() const
Retuns the total number of operands.
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
MachineBasicBlock * getFallThrough()
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
bool hasEHPadSuccessor() const
SlotIndex getInstructionIndex(const MachineInstr &MI) const
Returns the base index for the given instruction.
static void unbundleSingleMI(MachineInstr *MI)
Prepare MI to be removed from its bundle.
MachineInstr * remove_instr(MachineInstr *I)
Remove the possibly bundled instruction from the instruction list without deleting it...
virtual bool isBasicBlockPrologue(const MachineInstr &MI) const
True if the instruction is bound to the top of its basic block and no other instructions shall be ins...
LiveInVector::const_iterator livein_iterator
bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Align getAlignment() const
Return alignment of the basic block.
Context object for machine code objects.
bool regsOverlap(Register regA, Register regB) const
Returns true if the two registers are equal or alias each other.
void unbundleFromPred()
Break bundle above this instruction.
DebugLoc findPrevDebugLoc(instr_iterator MBBI)
Find the previous valid DebugLoc preceding MBBI, skipping and DBG_VALUE instructions.
void insertMBBInMaps(MachineBasicBlock *MBB)
bool hasInterval(Register Reg) const
bool Killed
There is a use operand of reg or a super-register with kill flag set.
iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
const T & getValue() const LLVM_LVALUE_FUNCTION
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
virtual const TargetInstrInfo * getInstrInfo() const
const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
bool Defined
Reg or one of its aliases is defined.
bool isInsideBundle() const
Return true if MI is in a bundle (but not the first MI in a bundle).
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
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...
Analysis containing CSE Info
BasicBlockListType::iterator iterator
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
MCContext & getContext() const
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
initializer< Ty > init(const Ty &Val)
iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool Read
Reg or one of its aliases is read.
bool liveAt(SlotIndex index) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
livein_iterator livein_end() const
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
void setMBB(MachineBasicBlock *MBB)
Register is known to be fully dead.
void setFlag(MIFlag Flag)
Set a MI flag.
SlotIndex getMBBStartIdx(unsigned Num) const
Returns the first index in the given basic block number.
void clearFlag(MIFlag Flag)
clearFlag - Clear a MI flag.
static cl::opt< bool > PrintSlotIndexes("print-slotindexes", cl::desc("When printing machine IR, annotate instructions and blocks with " "SlotIndexes when available"), cl::init(true), cl::Hidden)
StringRef getPrivateLabelPrefix() const
bool isLegalToHoistInto() const
Returns true if it is legal to hoist instructions into this block.
void clearLiveIns()
Clear live in list.
bool FullyDefined
Reg or a super-register is defined.
void replacePhiUsesWith(MachineBasicBlock *Old, MachineBasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old...
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
void remove(iterator MBBI)
self_iterator getIterator()
bool livein_empty() const
LiveInterval & getInterval(Register Reg)
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
iterator_range< pred_iterator > predecessors()
void print(raw_ostream &OS, bool IsStandalone=true, bool SkipOpers=false, bool SkipDebugLoc=false, bool AddNewLine=true, const TargetInstrInfo *TII=nullptr) const
Print this MI to OS.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
std::vector< MachineBasicBlock * >::iterator pred_iterator
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
Register is known to be (at least partially) live.
succ_iterator succ_begin()
void incorporateFunction(const Function &F)
Incorporate the given function.
void repairIntervalsInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, ArrayRef< unsigned > OrigRegs)
Update live intervals for instructions in a range of iterators.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
void moveBefore(MachineBasicBlock *NewAfter)
Move 'this' block before or after the specified block.
VarInfo & getVarInfo(unsigned RegIdx)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
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()
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
virtual bool isPredicated(const MachineInstr &MI) const
Returns true if the instruction is already predicated.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void sort(IteratorTy Start, IteratorTy End)
void addNewBlock(MachineBasicBlock *BB, MachineBasicBlock *DomBB, MachineBasicBlock *SuccBB)
addNewBlock - Add a new basic block BB between DomBB and SuccBB.
std::vector< MachineInstr * > Kills
Kills - List of MachineInstruction's which are the last use of this virtual register (kill it) in the...
static BranchProbability getUnknown()
void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified segment from this range.
Iterator for intrusive lists based on ilist_node.
Information about how a physical register Reg is used by a set of operands.
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
static uint32_t getDenominator()
void splice(iterator InsertPt, iterator MBBI)
void removeNodeFromList(NodeTy *)
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...
void updateTerminator()
Update the terminator instructions in block to account for changes to the layout. ...
static void deleteNode(NodeTy *V)
void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
IterT skipDebugInstructionsBackward(IterT It, IterT Begin)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
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 replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
unsigned succ_size() const
IterT skipDebugInstructionsForward(IterT It, IterT End)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator...
void copySuccessor(MachineBasicBlock *Orig, succ_iterator I)
Copy a successor (and any probability info) from original block to this block's.
const MachineBasicBlock * getParent() const
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
pointer remove(iterator &IT)
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator insert(iterator where, pointer New)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_NODISCARD bool empty() const
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
Register liveness not decidable from local neighborhood.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
StringRef getName() const
Return a constant reference to the value's name.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
Pair of physical register and lane mask.
bool PartialDeadDef
Reg is Defined and all defs of reg or an overlapping register are dead.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
Optional< uint64_t > getIrrLoopHeaderWeight() const
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
void removeFromMBBNumbering(unsigned N)
removeFromMBBNumbering - Remove the specific machine basic block from our tracker, this is only really to be used by the MachineBasicBlock implementation.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
void splitSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New, bool NormalizeSuccProbs=false)
Split the old successor into old plus new and updates the probability info.
iterator_range< livein_iterator > liveins() const
Instructions::iterator instr_iterator
virtual bool reverseBranchCondition(SmallVectorImpl< MachineOperand > &Cond) const
Reverses the branch condition of the specified condition list, returning false on success and true if...
void erase(iterator MBBI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void insert(iterator MBBI, MachineBasicBlock *MBB)
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P)
Split the critical edge from this block to the given successor block, and return the newly created bl...
void unbundleFromSucc()
Break bundle below this instruction.
std::string getFullName() const
Return a formatted string to identify this block and its parent function.
unsigned addToMBBNumbering(MachineBasicBlock *MBB)
Adds the MBB to the internal numbering.
Module * getParent()
Get the module that this global value is contained inside of...
mop_iterator operands_begin()
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
This class implements an extremely fast bulk output stream that can only output to a stream...
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
bool isBarrier(QueryType Type=AnyInBundle) const
Returns true if the specified instruction stops control flow from executing the instruction immediate...
StringRef - Represent a constant reference to a string, i.e.
void printAsOperand(raw_ostream &OS, bool PrintType=true) const
static BranchProbability getZero()
const uint32_t * getBeginClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the start of this basic block.
Register getReg() const
getReg - Returns the register number.
Simple wrapper around std::function<void(raw_ostream&)>.
const MachineOperand & getOperand(unsigned i) const
SlotIndex - An opaque wrapper around machine indexes.
bool Clobbered
There is a regmask operand indicating Reg is clobbered.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
uint32_t getNumerator() const
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
std::vector< MachineBasicBlock * >::iterator succ_iterator
livein_iterator livein_begin() const
bool CorrectExtraCFGEdges(MachineBasicBlock *DestA, MachineBasicBlock *DestB, bool IsCond)
Various pieces of code can cause excess edges in the CFG to be inserted.
Wrapper class representing virtual and physical registers.
void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator)
Callback before transferring nodes to this list.
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.