30#include "llvm/Config/llvm-config.h"
44#define DEBUG_TYPE "codegen"
48 cl::desc(
"When printing machine IR, annotate instructions and blocks with "
49 "SlotIndexes when available"),
53 : BB(
B),
Number(-1), xParent(&MF) {
56 IrrLoopHeaderWeight =
B->getIrrLoopHeaderWeight();
59MachineBasicBlock::~MachineBasicBlock() =
default;
63 if (!CachedMCSymbol) {
80 Suffix = (Suffix +
Twine(
".__part.") +
Twine(SectionID.Number)).str();
82 CachedMCSymbol = Ctx.getOrCreateSymbol(MF->
getName() + Suffix);
86 CachedMCSymbol = Ctx.createBlockSymbol(
91 return CachedMCSymbol;
95 if (!CachedEHContMCSymbol) {
102 return CachedEHContMCSymbol;
106 if (!CachedEndMCSymbol) {
113 return CachedEndMCSymbol;
146 N->getParent()->removeFromMBBNumbering(
N->Number);
148 N->AnalysisNumber = -1;
154 assert(!
N->getParent() &&
"machine instruction already in a basic block");
155 N->setParent(Parent);
161 MF->handleInsertion(*
N);
167 assert(
N->getParent() &&
"machine instruction not in a basic block");
171 MF->handleRemoval(*
N);
172 N->removeRegOperandsFromUseLists(MF->
getRegInfo());
175 N->setParent(
nullptr);
181 instr_iterator
First,
182 instr_iterator
Last) {
183 assert(Parent->getParent() == FromList.Parent->getParent() &&
184 "cannot transfer MachineInstrs between MachineFunctions");
187 if (
this == &FromList)
190 assert(Parent != FromList.Parent &&
"Two lists have the same parent?");
195 First->setParent(Parent);
199 assert(!
MI->getParent() &&
"MI is still in a block!");
200 Parent->getParent()->deleteMachineInstr(
MI);
205 while (
I != E &&
I->isPHI())
207 assert((
I == E || !
I->isInsideBundle()) &&
208 "First non-phi MI cannot be inside a bundle!");
217 while (
I != E && (
I->isPHI() ||
I->isPosition() ||
218 TII->isBasicBlockPrologue(*
I)))
222 assert((
I == E || !
I->isInsideBundle()) &&
223 "First non-phi / non-label instruction is inside a bundle!");
233 while (
I != E && (
I->isPHI() ||
I->isPosition() ||
I->isDebugInstr() ||
234 (SkipPseudoOp &&
I->isPseudoProbe()) ||
235 TII->isBasicBlockPrologue(*
I, Reg)))
239 assert((
I == E || !
I->isInsideBundle()) &&
240 "First non-phi / non-label / non-debug "
241 "instruction is inside a bundle!");
247 while (
I !=
B && ((--
I)->isTerminator() ||
I->isDebugInstr()))
249 while (
I != E && !
I->isTerminator())
256 while (
I !=
B && ((--
I)->isTerminator() ||
I->isDebugInstr()))
258 while (
I != E && !
I->isTerminator())
280 if (
I->isDebugInstr() ||
I->isInsideBundle())
282 if (SkipPseudoOp &&
I->isPseudoProbe())
291 for (
const MachineBasicBlock *Succ :
successors())
301#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
308 for (
const MachineBasicBlock *Succ :
successors()) {
309 if (Succ->isInlineAsmBrIndirectTarget())
323 return LBB->hasName();
329 return LBB->getName();
347 bool IsStandalone)
const {
350 OS <<
"Can't print out MachineBasicBlock because parent MachineFunction"
355 const Module *M =
F.getParent();
358 print(OS, MST, Indexes, IsStandalone);
363 bool IsStandalone)
const {
366 OS <<
"Can't print out MachineBasicBlock because parent MachineFunction"
380 bool HasLineAttributes =
false;
384 if (Indexes) OS <<
'\t';
386 OS <<
"; predecessors: ";
391 HasLineAttributes =
true;
395 if (Indexes) OS <<
'\t';
397 OS.
indent(2) <<
"successors: ";
406 if (!Probs.empty() && IsStandalone) {
422 HasLineAttributes =
true;
426 if (Indexes) OS <<
'\t';
427 OS.
indent(2) <<
"liveins: ";
430 for (
const auto &LI :
liveins()) {
432 if (!LI.LaneMask.all())
435 HasLineAttributes =
true;
438 if (HasLineAttributes)
441 bool IsInBundle =
false;
449 if (IsInBundle && !
MI.isInsideBundle()) {
454 OS.
indent(IsInBundle ? 4 : 2);
455 MI.print(OS, MST, IsStandalone,
false,
false,
468 if (IrrLoopHeaderWeight && IsStandalone) {
469 if (Indexes) OS <<
'\t';
470 OS.
indent(2) <<
"; Irreducible loop header weight: " << *IrrLoopHeaderWeight
494 bool hasAttributes =
false;
503 if (moduleSlotTracker) {
505 }
else if (bb->getParent()) {
512 os <<
"<ir-block badref>";
525 hasAttributes =
true;
534 os << (hasAttributes ?
", " :
" (");
535 os <<
"machine-block-address-taken";
536 hasAttributes =
true;
539 os << (hasAttributes ?
", " :
" (");
540 os <<
"label-must-be-emitted";
541 hasAttributes =
true;
544 os << (hasAttributes ?
", " :
" (");
545 os <<
"ir-block-address-taken ";
547 hasAttributes =
true;
550 os << (hasAttributes ?
", " :
" (");
552 hasAttributes =
true;
555 os << (hasAttributes ?
", " :
" (");
556 os <<
"inlineasm-br-indirect-target";
557 hasAttributes =
true;
560 os << (hasAttributes ?
", " :
" (");
561 os <<
"ehfunclet-entry";
562 hasAttributes =
true;
565 os << (hasAttributes ?
", " :
" (");
566 os <<
"ehscope-entry";
567 hasAttributes =
true;
570 os << (hasAttributes ?
", " :
" (");
571 os <<
"cleanup-funclet-entry";
572 hasAttributes =
true;
575 os << (hasAttributes ?
", " :
" (");
576 os <<
"ehcont-target";
577 hasAttributes =
true;
580 os << (hasAttributes ?
", " :
" (");
582 hasAttributes =
true;
587 os << (hasAttributes ?
", " :
" (");
599 hasAttributes =
true;
602 os << (hasAttributes ?
", " :
" (");
603 os <<
"bb_id " <<
getBBID()->BaseID;
605 os <<
" " <<
getBBID()->CloneID;
606 hasAttributes =
true;
608 if (CallFrameSize != 0) {
609 os << (hasAttributes ?
", " :
" (");
610 os <<
"call-frame-size " << CallFrameSize;
611 hasAttributes =
true;
629 if (
I == LiveIns.end())
632 I->LaneMask &= ~LaneMask;
633 if (
I->LaneMask.none())
647 if (Reg == SRI.getSubReg()) {
648 unsigned SubRegIndex = SRI.getSubRegIndex();
649 LaneBitmask SubRegLaneMask =
TRI->getSubRegIndexLaneMask(SubRegIndex);
660 LiveInVector::iterator LI = LiveIns.begin() + (
I - LiveIns.begin());
661 return LiveIns.erase(LI);
668 return I !=
livein_end() && (
I->LaneMask & LaneMask).any();
679 auto [Unit, UnitMask] = *U;
680 if ((UnitMask & LI.
LaneMask).any() &&
TRI.hasRegUnit(Reg, Unit))
693 LiveInVector::const_iterator
I = LiveIns.begin();
694 LiveInVector::const_iterator J;
695 LiveInVector::iterator Out = LiveIns.begin();
696 for (;
I != LiveIns.end(); ++Out,
I = J) {
699 for (J = std::next(
I); J != LiveIns.end() && J->PhysReg == PhysReg; ++J)
700 LaneMask |= J->LaneMask;
701 Out->PhysReg = PhysReg;
702 Out->LaneMask = LaneMask;
704 LiveIns.erase(Out, LiveIns.end());
711 assert(RC &&
"Register class is required");
713 "Only the entry block and landing pads can have physreg live ins");
722 for (;
I != E &&
I->isCopy(); ++
I)
723 if (
I->getOperand(1).getReg() == PhysReg) {
724 Register VirtReg =
I->getOperand(0).getReg();
725 if (!
MRI.constrainRegClass(VirtReg, RC))
749 if (TerminatorI ==
MBB.end())
753 return TII->getJumpTableIndex(Terminator);
757 MachineBasicBlock *PreviousLayoutSuccessor) {
766 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
769 bool B =
TII->analyzeBranch(*
this,
TBB, FBB,
Cond);
771 assert(!
B &&
"UpdateTerminators requires analyzable predecessors!");
777 TII->removeBranch(*
this);
786 if (!PreviousLayoutSuccessor || !
isSuccessor(PreviousLayoutSuccessor) ||
787 PreviousLayoutSuccessor->
isEHPad())
793 TII->insertBranch(*
this, PreviousLayoutSuccessor,
nullptr,
Cond,
DL);
803 if (
TII->reverseBranchCondition(
Cond))
805 TII->removeBranch(*
this);
806 TII->insertBranch(*
this, FBB,
nullptr,
Cond,
DL);
808 TII->removeBranch(*
this);
815 assert(PreviousLayoutSuccessor);
819 if (PreviousLayoutSuccessor ==
TBB) {
823 TII->removeBranch(*
this);
833 if (
TII->reverseBranchCondition(
Cond)) {
836 TII->insertBranch(*
this, PreviousLayoutSuccessor,
nullptr,
Cond,
DL);
839 TII->removeBranch(*
this);
840 TII->insertBranch(*
this, PreviousLayoutSuccessor,
nullptr,
Cond,
DL);
842 TII->removeBranch(*
this);
843 TII->insertBranch(*
this,
TBB, PreviousLayoutSuccessor,
Cond,
DL);
850 for (
auto Prob : Probs)
851 Sum += Prob.getNumerator();
857 "The sum of successors's probabilities exceeds one.");
865 if (!(Probs.empty() && !Successors.empty()))
866 Probs.push_back(Prob);
867 Successors.push_back(Succ);
868 Succ->addPredecessor(
this);
876 Successors.push_back(Succ);
877 Succ->addPredecessor(
this);
881 MachineBasicBlock *New,
882 bool NormalizeSuccProbs) {
884 assert(OldI !=
succ_end() &&
"Old is not a successor of this block!");
886 "New is already a successor of this block!");
894 : *getProbabilityIterator(OldI));
895 if (NormalizeSuccProbs)
900 bool NormalizeSuccProbs) {
907 assert(
I != Successors.end() &&
"Not a current successor!");
911 if (!Probs.empty()) {
912 probability_iterator WI = getProbabilityIterator(
I);
914 if (NormalizeSuccProbs)
918 (*I)->removePredecessor(
this);
919 return Successors.erase(
I);
923 MachineBasicBlock *New) {
942 assert(OldI != E &&
"Old is not a successor of this block");
946 Old->removePredecessor(
this);
947 New->addPredecessor(
this);
954 if (!Probs.empty()) {
955 auto ProbIter = getProbabilityIterator(NewI);
956 if (!ProbIter->isUnknown())
957 *ProbIter += *getProbabilityIterator(OldI);
964 if (!Orig->Probs.empty())
979 "Pred is not a predecessor of this block!");
980 Predecessors.
erase(std::prev(RI.base()));
988 MachineBasicBlock *Succ = *FromMBB->
succ_begin();
992 if (!FromMBB->Probs.empty()) {
993 auto Prob = *FromMBB->Probs.begin();
1004 if (
this == FromMBB)
1008 MachineBasicBlock *Succ = *FromMBB->
succ_begin();
1009 if (!FromMBB->Probs.empty()) {
1010 auto Prob = *FromMBB->Probs.begin();
1036 return Successors.
size() == 1 ? Successors[0] :
nullptr;
1040 return Predecessors.
size() == 1 ? Predecessors[0] :
nullptr;
1055 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
1058 if (
TII->analyzeBranch(*
this,
TBB, FBB,
Cond)) {
1070 if (!
TBB)
return &*Fallthrough;
1076 return &*Fallthrough;
1080 if (
Cond.empty())
return nullptr;
1084 return (FBB ==
nullptr) ? &*Fallthrough :
nullptr;
1097 if (SplitPoint ==
end()) {
1105 if (UpdateLiveIns) {
1127 LIS->
splitAt(*
this, *SplitBB);
1136 int JumpTableIndex) {
1137 assert(JumpTableIndex >= 0 &&
"need valid index");
1154 if (Pred == &IgnoreMBB)
1159 if (!
TII.analyzeBranch(*Pred, DummyT, DummyF,
Cond,
1166 if (PredJTI == JumpTableIndex)
1184 : MF(MF), Indexes(Indexes) {
1185 MF.setDelegate(
this);
1189 MF.resetDelegate(
this);
1190 for (
auto MI : Insertions)
1191 Indexes->insertMachineInstrInMaps(*
MI);
1197 Insertions.insert(&
MI);
1201 if (Indexes && !Insertions.remove(&
MI))
1202 Indexes->removeMachineInstrFromMaps(
MI);
1210#define GET_RESULT(RESULT, GETTER, INFIX) \
1213 auto *Wrapper = P->getAnalysisIfAvailable<RESULT##INFIX##WrapperPass>(); \
1214 return Wrapper ? &Wrapper->GETTER() : nullptr; \
1216 return MFAM->getCachedResult<RESULT##Analysis>(*MF); \
1219 assert((
P || MFAM) &&
"Need a way to get analysis results!");
1236 MachineBasicBlock *PrevFallthrough =
getNextNode();
1242 bool ChangedIndirectJump =
false;
1247 ChangedIndirectJump =
true;
1254 auto *LIS = Analyses.
LIS;
1257 else if (Analyses.
SI)
1265 if (!MO.isReg() || MO.getReg() == 0)
1279 if (Succ == PrevFallthrough)
1280 PrevFallthrough = NMBB;
1281 auto *Indexes = Analyses.
SI;
1282 if (!ChangedIndirectJump) {
1302 TII->insertBranch(*NMBB, Succ,
nullptr,
Cond,
DL);
1309 for (
unsigned I = 1, E =
MI.getNumOperands();
I != E;
I += 2) {
1311 if (MBBOp.
getMBB() !=
this)
1321 for (
const auto &LI : Succ->
liveins())
1327 SlotIndex StartIndex = Indexes->getMBBEndIdx(
this);
1329 SlotIndex EndIndex = Indexes->getMBBEndIdx(NMBB);
1333 assert(LIS->getInterval(Reg).liveAt(PrevIndex) &&
1334 "PHI sources should be live out of their predecessors.");
1338 auto UpdateLiveOutReg = [&](
Register Reg) {
1339 if (PHISrcRegs.count(Reg))
1341 if (!LIS->hasInterval(Reg))
1345 if (!LI.
liveAt(PrevIndex))
1354 if (SR.liveAt(PrevIndex))
1355 SR.removeSegment(StartIndex, EndIndex);
1365 for (
unsigned Idx : LiveOut) {
1367 NewLiveOut.
set(Idx);
1371 for (
unsigned i = 0, e =
MRI->getNumVirtRegs(); i != e; ++i)
1382 if (Reg.isPhysical())
1383 LIS->removeAllRegUnitsForPhysReg(Reg.asMCReg());
1394 if (
MachineLoop *DestLoop = MLI->getLoopFor(Succ)) {
1395 if (TIL == DestLoop) {
1397 DestLoop->addBasicBlockToLoop(NMBB, *MLI);
1398 }
else if (TIL->contains(DestLoop)) {
1400 TIL->addBasicBlockToLoop(NMBB, *MLI);
1401 }
else if (DestLoop->contains(TIL)) {
1403 DestLoop->addBasicBlockToLoop(NMBB, *MLI);
1409 assert(DestLoop->getHeader() == Succ &&
1410 "Should not create irreducible loops!");
1412 P->addBasicBlockToLoop(NMBB, *MLI);
1443 if (!L || L->getHeader() != Succ)
1455 const MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
1458 if (
TII->analyzeBranch(*
this,
TBB, FBB,
Cond))
1466 LLVM_DEBUG(
dbgs() <<
"Won't split critical edge after degenerate "
1477 if (
MI->isBundledWithSucc() && !
MI->isBundledWithPred())
1478 MI->unbundleFromSucc();
1480 if (
MI->isBundledWithPred() && !
MI->isBundledWithSucc())
1481 MI->unbundleFromPred();
1489 return Insts.erase(
I);
1496 return Insts.remove(
MI);
1501 assert(!
MI->isBundledWithPred() && !
MI->isBundledWithSucc() &&
1502 "Cannot insert instruction with bundle flags");
1508 return Insts.insert(
I,
MI);
1528 MachineBasicBlock *New) {
1529 assert(Old != New &&
"Cannot replace self with self!");
1534 if (!
I->isTerminator())
break;
1539 if (MO.isMBB() && MO.getMBB() == Old)
1548 MachineBasicBlock *New) {
1550 for (
unsigned i = 2, e =
MI.getNumOperands() + 1; i != e; i += 2) {
1564 return MBBI->getDebugLoc();
1573 if (!
MBBI->isDebugInstr())
1574 return MBBI->getDebugLoc();
1585 if (!
MBBI->isDebugInstr())
1586 return MBBI->getDebugLoc();
1596 return MBBI->getDebugLoc();
1606 while (TI !=
end() && !TI->isBranch())
1610 DL = TI->getDebugLoc();
1611 for (++TI ; TI !=
end() ; ++TI)
1624 const auto &Prob = *getProbabilityIterator(Succ);
1625 if (!Prob.isUnknown())
1629 unsigned KnownProbNum = 0;
1631 for (
const auto &
P : Probs) {
1632 if (!
P.isUnknown()) {
1637 return Sum.getCompl() / (Probs.size() - KnownProbNum);
1663 *getProbabilityIterator(
I) = Prob;
1667MachineBasicBlock::const_probability_iterator
1668MachineBasicBlock::getProbabilityIterator(
1670 assert(Probs.size() == Successors.size() &&
"Async probability list!");
1671 const size_t index = std::distance(Successors.begin(),
I);
1672 assert(index < Probs.size() &&
"Not a current successor!");
1673 return Probs.begin() + index;
1677MachineBasicBlock::probability_iterator
1679 assert(Probs.size() == Successors.size() &&
"Async probability list!");
1680 const size_t index = std::distance(Successors.begin(),
I);
1681 assert(index < Probs.size() &&
"Not a current successor!");
1682 return Probs.begin() + index;
1694 unsigned Neighborhood)
const {
1695 assert(Reg.isPhysical());
1696 unsigned N = Neighborhood;
1700 for (;
I !=
end() &&
N > 0; ++
I) {
1701 if (
I->isDebugOrPseudoInstr())
1712 if (Info.FullyDefined || Info.Clobbered)
1721 if (
TRI->regsOverlap(LI.PhysReg, Reg))
1739 if (
I->isDebugOrPseudoInstr())
1753 if (!Info.PartialDeadDef)
1762 if (Info.Killed || Info.Clobbered)
1768 }
while (
I !=
begin() &&
N > 0);
1773 while (
I !=
begin() && std::prev(
I)->isDebugOrPseudoInstr())
1780 if (
TRI->regsOverlap(LI.PhysReg, Reg))
1809 std::vector<RegisterMaskPair> &OldLiveIns) {
1810 assert(OldLiveIns.empty() &&
"Vector must be empty");
1816 "Liveness information is accurate");
1817 return LiveIns.begin();
1823 MCRegister ExceptionPointer, ExceptionSelector;
1831 return liveout_iterator(*
this, ExceptionPointer, ExceptionSelector,
false);
1837 for (
auto I = R.begin(), E = R.end();
I != E; ++
I) {
1845 const MachineBasicBlock &PredMBB) {
1847 Phi.removePHIIncomingValueFor(PredMBB);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
const HexagonInstrInfo * TII
This file contains an interface for creating legacy passes to print out IR in various granularities.
Module.h This file contains the declarations for the Module class.
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define GET_RESULT(RESULT, GETTER, INFIX)
static bool jumpTableHasOtherUses(const MachineFunction &MF, const MachineBasicBlock &IgnoreMBB, int JumpTableIndex)
static void unbundleSingleMI(MachineInstr *MI)
Prepare MI to be removed from its bundle.
static int findJumpTableIndex(const MachineBasicBlock &MBB)
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)
Register const TargetRegisterInfo * TRI
uint64_t IntrinsicInst * II
SmallVector< MachineOperand, 4 > Cond
MachineRegisterInfo & MRI
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
This file describes how to lower LLVM code to machine code.
SlotIndexUpdateDelegate(MachineFunction &MF, SlotIndexes *Indexes)
void MF_HandleRemoval(MachineInstr &MI) override
Callback before a removal. This should not modify the MI directly.
void MF_HandleInsertion(MachineInstr &MI) override
Callback after an insertion. This should not modify the MI directly.
~SlotIndexUpdateDelegate() override
LLVM Basic Block Representation.
static uint32_t getDenominator()
static constexpr BranchProbability getUnknown()
static constexpr BranchProbability getZero()
uint32_t getNumerator() const
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
LLVM_ABI unsigned getLine() const
static LLVM_ABI DebugLoc getMergedLocation(DebugLoc LocA, DebugLoc LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
LLVM_ABI unsigned getCol() const
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void splitCriticalEdge(BasicBlockT *FromBB, BasicBlockT *ToBB, BasicBlockT *NewBB)
Apply updates that the critical edge (FromBB, ToBB) has been split with NewBB.
Module * getParent()
Get the module that this global value is contained inside of...
A helper class to return the specified delimiter string after the first invocation of operator String...
LiveInterval - This class represents the liveness of a register, or stack slot.
iterator_range< subrange_iterator > subranges()
void insertMBBInMaps(MachineBasicBlock *MBB)
Adds an empty block MBB to the SlotIndexes and regmask maps.
void splitAt(MachineBasicBlock &Orig, MachineBasicBlock &SplitBB)
After the tail of Orig has been sliced into SplitBB, updates the SlotIndexes and regmask maps and re-...
A set of physical registers with utility functions to track liveness when walking backward/forward th...
bool liveAt(SlotIndex index) const
LLVM_ABI void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified interval from this live range.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
Context object for machine code objects.
LLVM_ABI MCSymbol * createBlockSymbol(const Twine &Name, bool AlwaysEmit=false)
Get or create a symbol for a basic block.
LLVM_ABI MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
MCRegUnitMaskIterator enumerates a list of register units and their associated lane masks for Reg.
bool isValid() const
Returns true if this iterator is not yet at the end.
Wrapper class representing physical registers. Should be passed by value.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Iterator that enumerates the sub-registers of a Reg and the associated sub-register indices.
bool isValid() const
Returns true if this iterator is not yet at the end.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isInlineAsmBrIndirectTarget() const
Returns true if this is the indirect dest of an INLINEASM_BR.
LLVM_ABI DebugLoc rfindPrevDebugLoc(reverse_instr_iterator MBBI)
Has exact same behavior as findPrevDebugLoc (it also searches towards the beginning of this MBB) exce...
LLVM_ABI void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
LLVM_ABI bool hasEHPadSuccessor() const
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
livein_iterator livein_end() const
LLVM_ABI iterator getFirstTerminatorForward()
Finds the first terminator in a block by scanning forward.
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_ABI 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.
LLVM_ABI MachineInstr * remove_instr(MachineInstr *I)
Remove the possibly bundled instruction from the instruction list without deleting it.
instr_iterator instr_begin()
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
LLVM_ABI void moveBefore(MachineBasicBlock *NewAfter)
Move 'this' block before or after the specified block.
LLVM_ABI void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
LLVM_ABI MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
LLVM_ABI void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
bool hasLabelMustBeEmitted() const
Test whether this block must have its label emitted.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LLVM_ABI BranchProbability getSuccProbability(const_succ_iterator Succ) const
Return probability of the edge from this block to MBB.
iterator_range< livein_iterator > liveins() const
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
reverse_instr_iterator instr_rbegin()
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
LLVM_ABI void addSuccessorWithoutProb(MachineBasicBlock *Succ)
Add Succ as a successor of this MachineBasicBlock.
SmallVectorImpl< MachineBasicBlock * >::const_iterator const_succ_iterator
LLVM_ABI bool hasName() const
Check if there is a name of corresponding LLVM basic block.
void setCallFrameSize(unsigned N)
Set the call frame size on entry to this basic block.
std::optional< UniqueBBID > getBBID() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_ABI MCSymbol * getEHContSymbol() const
Return the Windows EH Continuation Symbol for this basic block.
LLVM_ABI void splitSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New, bool NormalizeSuccProbs=false)
Split the old successor into old plus new and updates the probability info.
@ PrintNameIr
Add IR name where available.
@ PrintNameAttributes
Print attributes.
LLVM_ABI void updateTerminator(MachineBasicBlock *PreviousLayoutSuccessor)
Update the terminator instructions in block to account for changes to block layout which may have bee...
LLVM_ABI const MachineBasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor.
LLVM_ABI iterator SkipPHIsLabelsAndDebug(iterator I, Register Reg=Register(), bool SkipPseudoOp=true)
Return the first instruction in MBB after I that is not a PHI, label or debug.
LLVM_ABI bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
LLVM_ABI void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the first non-debug instruction in the basic block, or end().
succ_iterator succ_begin()
bool livein_empty() const
LLVM_ABI void removeLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
LLVM_ABI void printAsOperand(raw_ostream &OS, bool PrintType=true) const
unsigned getMaxBytesForAlignment() const
Return the maximum amount of padding allowed for aligning the basic block.
LLVM_ABI void validateSuccProbs() const
Validate successors' probabilities and check if the sum of them is approximate one.
bool isIRBlockAddressTaken() const
Test whether this block is the target of an IR BlockAddress.
LiveInVector::const_iterator livein_iterator
LLVM_ABI MCSymbol * getEndSymbol() const
Returns the MCSymbol marking the end of this basic block.
LLVM_ABI void clearLiveIns()
Clear live in list.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
LLVM_ABI LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, MCRegister Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been defined and not killed as of just before Before.
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
LLVM_ABI livein_iterator livein_begin() const
unsigned succ_size() const
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction.
LLVM_ABI const uint32_t * getBeginClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the start of this basic block.
LLVM_ABI void removePHIsIncomingValuesForPredecessor(const MachineBasicBlock &PredMBB)
Iterate over block PHI instructions and remove all incoming values for PredMBB.
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
LLVM_ABI void dump() const
bool isEHScopeEntry() const
Returns true if this is the entry block of an EH scope, i.e., the block that used to have a catchpad ...
LLVM_ABI bool isEntryBlock() const
Returns true if this is the entry block of the function.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
LLVM_ABI void copySuccessor(const MachineBasicBlock *Orig, succ_iterator I)
Copy a successor (and any probability info) from original block to this block's.
SmallVectorImpl< MachineBasicBlock * >::iterator succ_iterator
BasicBlock * getAddressTakenIRBlock() const
Retrieves the BasicBlock which corresponds to this MachineBasicBlock.
LLVM_ABI void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
LLVM_ABI const MachineBasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI liveout_iterator liveout_begin() const
Iterator scanning successor basic blocks' liveins to determine the registers potentially live at the ...
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
LLVM_ABI iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
LLVM_ABI DebugLoc rfindDebugLoc(reverse_instr_iterator MBBI)
Has exact same behavior as findDebugLoc (it also searches towards the end of this MBB) except that th...
LLVM_ABI void print(raw_ostream &OS, const SlotIndexes *=nullptr, bool IsStandalone=true) const
reverse_instr_iterator instr_rend()
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
Instructions::iterator instr_iterator
LLVM_ABI iterator getLastNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the last non-debug instruction in the basic block, or end().
LLVM_ABI 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...
LLVM_ABI bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
LLVM_ABI DebugLoc findPrevDebugLoc(instr_iterator MBBI)
Find the previous valid DebugLoc preceding MBBI, skipping any debug instructions.
LLVM_ABI MachineBasicBlock * splitAt(MachineInstr &SplitInst, bool UpdateLiveIns=true, LiveIntervals *LIS=nullptr)
Split a basic block into 2 pieces at SplitPoint.
LLVM_ABI bool canSplitCriticalEdge(const MachineBasicBlock *Succ, const MachineLoopInfo *MLI=nullptr) const
Check if the edge between this block and the given successor Succ, can be split.
LLVM_ABI void eraseFromParent()
This method unlinks 'this' from the containing function and deletes it.
friend class MachineFunction
LLVM_ABI void removeLiveInOverlappedWith(MCRegister Reg)
Remove the specified register from any overlapped live in.
instr_iterator instr_end()
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
LLVM_ABI bool isLiveInOverlappedWith(MCRegister Reg, const TargetRegisterInfo &TRI) const
Return true if any part of Reg is live in, accounting for live-ins of overlapping registers and their...
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
LLVM_ABI std::string getFullName() const
Return a formatted string to identify this block and its parent function.
bool isBeginSection() const
Returns true if this block begins any section.
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P, MachineDomTreeUpdater *MDTU=nullptr)
bool isEHContTarget() const
Returns true if this is a target of Windows EH Continuation Guard.
unsigned getCallFrameSize() const
Return the call frame size on entry to this basic block.
LLVM_ABI DebugLoc findBranchDebugLoc()
Find and return the merged DebugLoc of the branch instructions of the block.
iterator_range< succ_iterator > successors()
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
reverse_iterator rbegin()
bool isMachineBlockAddressTaken() const
Test whether this block is used as something other than the target of a terminator,...
LLVM_ABI void printName(raw_ostream &os, unsigned printNameFlags=PrintNameIr, ModuleSlotTracker *moduleSlotTracker=nullptr) const
Print the basic block's name as:
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
iterator_range< pred_iterator > predecessors()
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 '...
Align getAlignment() const
Return alignment of the basic block.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI bool isLegalToHoistInto() const
Returns true if it is legal to hoist instructions into this block.
LLVM_ABI bool canPredictBranchProbabilities() const
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
LLVM_ABI bool mayHaveInlineAsmBr() const
Returns true if this block may have an INLINEASM_BR (overestimate, by checking if any of the successo...
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
@ LQR_Dead
Register is known to be fully dead.
@ LQR_Live
Register is known to be (at least partially) live.
@ LQR_Unknown
Register liveness not decidable from local neighborhood.
LLVM_ABI void moveAfter(MachineBasicBlock *NewBefore)
LLVM_ABI const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
LLVM_ABI bool sizeWithoutDebugLargerThan(unsigned Limit) const
LLVM_ABI bool isLiveIn(MCRegister Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
LLVM_ABI MachineBasicBlock * removeFromParent()
This method unlinks 'this' from the containing function, and returns it, but does not delete it.
Instructions::reverse_iterator reverse_instr_iterator
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
unsigned addToMBBNumbering(MachineBasicBlock *MBB)
Adds the MBB to the internal numbering.
unsigned getFunctionNumber() const
getFunctionNumber - Return a unique ID for the current function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
MCContext & getContext() const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
BasicBlockListType::iterator iterator
void remove(iterator MBBI)
unsigned assignAnalysisNumber()
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
void splice(iterator InsertPt, iterator MBBI)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *BB=nullptr, std::optional< UniqueBBID > BBID=std::nullopt)
CreateMachineInstr - Allocate a new MachineInstr.
void erase(iterator MBBI)
void insert(iterator MBBI, MachineBasicBlock *MBB)
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
BasicBlockListType::const_iterator const_iterator
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
LLVM_ABI bool ReplaceMBBInJumpTable(unsigned Idx, MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceMBBInJumpTable - If Old is a target of the jump tables, update the jump table to branch to New...
const std::vector< MachineJumpTableEntry > & getJumpTables() const
MachineOperand class - Representation of each machine instruction operand.
MachineBasicBlock * getMBB() const
void setMBB(MachineBasicBlock *MBB)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
Manage lifetime of a slot tracker for printing IR.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
void incorporateFunction(const Function &F)
Incorporate the given function.
A Module instance is used to store all the information related to an LLVM module.
ExceptionHandling getExceptionModel() const
Returns the exception model recorded by the "exception-model" module flag, or the target's default ex...
Pass interface - Implemented by all 'passes'.
Simple wrapper around std::function<void(raw_ostream&)>.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getPrevSlot() const
Returns the previous slot in the index list.
void insertMBBInMaps(MachineBasicBlock *mbb)
Add the given MachineBasicBlock into the maps.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
bool hasIndex(const MachineInstr &instr) const
Returns true if the given machine instr is mapped to an index, otherwise returns false.
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Returns the first index in the given basic block.
A SetVector that performs no allocations if smaller than a certain size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
virtual Register getExceptionSelectorRegister(ExceptionHandling EH, const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception typeid on entry to a la...
virtual Register getExceptionPointerRegister(ExceptionHandling EH, const Constant *PersonalityFn) const
If a physical register, this returns the register that receives the exception address on entry to an ...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
bool requiresStructuredCFG() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
virtual const TargetLowering * getTargetLowering() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
self_iterator getIterator()
MachineBasicBlock * getNextNode()
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
IterT next_nodbg(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It, then continue incrementing it while it points to a debug instruction.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
@ Kill
The last use of a register.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI PhysRegInfo AnalyzePhysRegInBundle(const MachineInstr &MI, Register Reg, const TargetRegisterInfo *TRI)
AnalyzePhysRegInBundle - Analyze how the current instruction or bundle uses a physical register.
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
IterT skipDebugInstructionsForward(IterT It, IterT End, bool SkipPseudoOp=true)
Increment It until it points to a non-debug instruction or to End and return the resulting iterator.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto instructionsWithoutDebug(IterT It, IterT End, bool SkipPseudoOp=true)
Construct a range iterator which begins at It and moves forwards until End is reached,...
IterT skipDebugInstructionsBackward(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool equal(L &&LRange, R &&RRange)
Wrapper function around std::equal to detect if pair-wise elements between two ranges are the same.
IterT prev_nodbg(IterT It, IterT Begin, bool SkipPseudoOp=true)
Decrement It, then continue decrementing it while it points to a debug instruction.
LLVM_ABI void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name)
Print out a name of an LLVM value without any prefixes.
LLVM_ABI 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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
LLVM_ABI void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs)
Adds registers contained in LiveRegs to the block live-in list of MBB.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
constexpr bool all() const
LLVM_ABI static const MBBSectionID ExceptionSectionID
LLVM_ABI static const MBBSectionID ColdSectionID
Pair of physical register and lane mask.
Split the critical edge from this block to the given successor block, and return the newly created bl...
std::vector< SparseBitVector<> > * LiveOutSets
MachineJumpTableEntry - One jump table in the jump table info.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
Information about how a physical register Reg is used by a set of operands.
static void deleteNode(NodeTy *V)
void removeNodeFromList(NodeTy *)
void addNodeToList(NodeTy *)
When an MBB is added to an MF, we need to update the parent pointer of the MBB, the MBB numbering,...
void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator)
Callback before transferring nodes to this list.
Template traits for intrusive list.