13 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H 14 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H 38 class MachineFunction;
40 class ModuleSlotTracker;
45 class TargetRegisterClass;
46 class TargetRegisterInfo;
77 : PhysReg(PhysReg), LaneMask(LaneMask) {}
89 std::vector<MachineBasicBlock *> Predecessors;
90 std::vector<MachineBasicBlock *> Successors;
95 std::vector<BranchProbability> Probs;
96 using probability_iterator = std::vector<BranchProbability>::iterator;
97 using const_probability_iterator =
98 std::vector<BranchProbability>::const_iterator;
103 using LiveInVector = std::vector<RegisterMaskPair>;
104 LiveInVector LiveIns;
111 bool IsEHPad =
false;
115 bool AddressTaken =
false;
119 bool LabelMustBeEmitted =
false;
124 bool IsEHScopeEntry =
false;
127 bool IsEHFuncletEntry =
false;
130 bool IsCleanupFuncletEntry =
false;
134 mutable MCSymbol *CachedMCSymbol =
nullptr;
156 std::string getFullName()
const;
187 unsigned size()
const {
return (
unsigned)Insts.size(); }
188 bool empty()
const {
return Insts.empty(); }
221 return reverse_iterator::getAtBundleBegin(instr_rbegin());
224 return const_reverse_iterator::getAtBundleBegin(instr_rbegin());
233 return &MachineBasicBlock::Insts;
257 std::vector<MachineBasicBlock *>::reverse_iterator;
259 std::vector<MachineBasicBlock *>::const_reverse_iterator;
261 std::vector<MachineBasicBlock *>::reverse_iterator;
263 std::vector<MachineBasicBlock *>::const_reverse_iterator;
269 {
return Predecessors.rbegin();}
271 {
return Predecessors.rbegin();}
273 {
return Predecessors.rend(); }
275 {
return Predecessors.rend(); }
277 return (
unsigned)Predecessors.size();
285 {
return Successors.rbegin(); }
287 {
return Successors.rbegin(); }
289 {
return Successors.rend(); }
291 {
return Successors.rend(); }
293 return (
unsigned)Successors.size();
320 LiveIns.push_back(RegMaskPair);
326 void sortUniqueLiveIns();
354 return make_range(livein_begin_dbg(), livein_end());
361 return make_range(livein_begin(), livein_end());
389 bool hasEHPadSuccessor()
const;
412 bool isLegalToHoistInto()
const;
426 void updateTerminator();
461 void validateSuccProbs()
const;
468 bool NormalizeSuccProbs =
false);
476 bool NormalizeSuccProbs =
false);
491 bool NormalizeSuccProbs =
false);
530 bool canFallThrough();
577 return !
empty() && back().isReturn();
583 return !
empty() && back().isEHScopeReturn();
612 template<
typename IT>
614 assert((I ==
end() || I->getParent() ==
this) &&
615 "iterator points outside of basic block");
621 assert((I ==
end() || I->getParent() ==
this) &&
622 "iterator points outside of basic block");
624 "Cannot insert instruction with bundle flags");
630 assert((I ==
end() || I->getParent() ==
this) &&
631 "iterator points outside of basic block");
633 "Cannot insert instruction with bundle flags");
640 assert((I == instr_end() || I->getParent() ==
this) &&
641 "iterator points outside of basic block");
643 "Cannot insert instruction with bundle flags");
644 while (I->isBundledWithSucc())
672 return erase(I, std::next(I));
689 assert(!I->isBundled() &&
"Cannot remove bundled instructions");
711 splice(Where, Other, From, std::next(From));
730 void eraseFromParent();
786 unsigned Neighborhood = 10)
const;
791 bool IsStandalone =
true)
const;
793 const SlotIndexes * =
nullptr,
bool IsStandalone =
true)
const;
796 void printAsOperand(
raw_ostream &OS,
bool PrintType =
true)
const;
807 return IrrLoopHeaderWeight;
811 IrrLoopHeaderWeight = Weight;
816 probability_iterator getProbabilityIterator(
succ_iterator I);
817 const_probability_iterator
928 : MBB(*BB), I(I), B(I == MBB.
begin() ? MBB.
end() :
std::prev(I)),
930 assert(I == BB->
end() || I->getParent() == BB);
934 return B == MBB.
end() ? MBB.
begin() : std::next(B);
946 template<
typename IterT>
948 while (It != End && It->isDebugInstr())
957 template<
class IterT>
959 while (It != Begin && It->isDebugInstr())
966 #endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H Pass interface - Implemented by all 'passes'.
pred_reverse_iterator pred_rbegin()
const_iterator getLastNonDebugInstr() const
const_iterator end(StringRef path)
Get end iterator over path.
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
A common definition of LaneBitmask for use in TableGen and CodeGen.
pred_reverse_iterator pred_rend()
instr_iterator instr_begin()
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Wrapper class representing physical registers. Should be passed by value.
instr_iterator instr_end()
instr_iterator insertAfterBundle(instr_iterator I, MachineInstr *MI)
If I is bundled then insert MI into the instruction list after the end of the bundle, otherwise insert MI immediately after I.
iterator erase(iterator where)
bool isEHScopeReturnBlock() const
Convenience function that returns true if the bock ends in a EH scope return instruction.
This class represents lattice values for constants.
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 ...
const_pred_reverse_iterator pred_rbegin() const
RegisterMaskPair(MCPhysReg PhysReg, LaneBitmask LaneMask)
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
MachineInstr & instr_front()
const_succ_iterator succ_begin() const
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
static ChildIteratorType child_begin(NodeRef N)
const_succ_reverse_iterator succ_rbegin() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
void setIrrLoopHeaderWeight(uint64_t Weight)
MachineBasicBlock::succ_iterator ChildIteratorType
const_reverse_instr_iterator instr_rbegin() const
MachineInstr & instr_back()
iterator_range< iterator > phis()
Returns a range that iterates over the phis in the basic block.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
Template traits for intrusive list.
const_pred_iterator pred_end() const
DebugLoc findDebugLoc(iterator MBBI)
unsigned const TargetRegisterInfo * TRI
Manage lifetime of a slot tracker for printing IR.
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
iterator insert(iterator I, MachineInstr *MI)
Insert MI into the instruction list before I.
static ChildIteratorType child_begin(NodeRef N)
iterator_range< succ_iterator > successors()
void splice(iterator Where, MachineBasicBlock *Other, iterator From, iterator To)
Take a block of instructions from MBB 'Other' in the range [From, To), and insert them into this MBB ...
const MachineInstr & back() const
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
MachineBasicBlock::pred_iterator ChildIteratorType
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
static unsigned addLiveIn(MachineFunction &MF, unsigned PReg, const TargetRegisterClass *RC)
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
iterator erase(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
void insert(iterator I, IT S, IT E)
Insert a range of instructions into the instruction list before I.
static constexpr LaneBitmask getAll()
static StringRef getName(Value *V)
iterator_range< iterator > terminators()
LiveInVector::const_iterator livein_iterator
void setIsCleanupFuncletEntry(bool V=true)
Indicates if this is the entry block of a cleanup funclet.
MachineBasicBlock::iterator end()
Align getAlignment() const
Return alignment of the basic block.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
A simple intrusive list implementation.
static ChildIteratorType child_end(NodeRef N)
const_pred_reverse_iterator pred_rend() const
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
instr_iterator getInstrIterator() const
const_succ_reverse_iterator succ_rend() const
static Instructions MachineBasicBlock::* getSublistAccess(MachineInstr *)
Support for MachineInstr::getNextNode().
BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
If this edge is a critical edge, insert a new node to split the critical edge.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
succ_reverse_iterator succ_rend()
reverse_iterator rbegin()
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
unsigned operator()(const MachineBasicBlock *MBB) const
Interval::succ_iterator succ_end(Interval *I)
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
void setIsEHScopeEntry(bool V=true)
Indicates if this is the entry block of an EH scope, i.e., the block that that used to have a catchpa...
std::vector< MachineBasicBlock * >::const_reverse_iterator const_succ_reverse_iterator
An ilist node that can access its parent list.
instr_iterator erase_instr(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
const_reverse_iterator rbegin() const
LLVM Basic Block Representation.
static ChildIteratorType child_end(NodeRef N)
succ_reverse_iterator succ_rbegin()
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 ...
static ChildIteratorType child_begin(NodeRef N)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
livein_iterator livein_end() const
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
Register is known to be fully dead.
void splice(iterator where, iplist_impl &L2)
This class prints out the machine instructions using the MIR serialization format.
Interval::pred_iterator pred_end(Interval *I)
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
MachineBasicBlock::const_succ_iterator ChildIteratorType
bool livein_empty() const
iterator_range< pred_iterator > predecessors()
std::vector< MachineBasicBlock * >::iterator pred_iterator
LivenessQueryResult
Possible outcome of a register liveness query to computeRegisterLiveness()
Register is known to be (at least partially) live.
succ_iterator succ_begin()
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
iterator erase(iterator I)
Remove an instruction or bundle from the instruction list and delete it.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
iterator erase(iterator I, iterator E)
Remove a range of instructions from the instruction list and delete them.
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
This struct is a compact representation of a valid (non-zero power of two) alignment.
const_iterator begin() const
constexpr bool empty(const T &RangeOrContainer)
Test whether RangeOrContainer is empty. Similar to C++17 std::empty.
static BranchProbability getUnknown()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
print lazy value Lazy Value Info Printer Pass
const MachineInstr & instr_back() const
Iterator for intrusive lists based on ilist_node.
void setAlignment(Align A)
Set alignment of the basic block.
reverse_instr_iterator instr_rbegin()
iterator_range< const_iterator > phis() const
BlockVerifier::State From
void setLabelMustBeEmitted()
Set this block to reflect that, regardless how we flow to it, we need its label be emitted...
void removeNodeFromList(NodeTy *)
livein_iterator livein_begin_dbg() const
Unlike livein_begin, this method does not check that the liveness information is accurate.
const_instr_iterator instr_end() const
iterator_range< livein_iterator > liveins_dbg() const
MachineBasicBlock::iterator getInitial()
void addLiveIn(const RegisterMaskPair &RegMaskPair)
static void deleteNode(NodeTy *V)
unsigned pred_size() const
IterT skipDebugInstructionsBackward(IterT It, IterT Begin)
Decrement It until it points to a non-debug instruction or to Begin and return the resulting iterator...
reverse_instr_iterator instr_rend()
const_iterator getFirstTerminator() const
MachineBasicBlock::const_pred_iterator ChildIteratorType
A range adaptor for a pair of iterators.
static NodeRef getEntryNode(Inverse< MachineBasicBlock *> G)
void push_back(pointer val)
DebugLoc findPrevDebugLoc(iterator MBBI)
const MachineInstr & front() const
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
std::vector< MachineBasicBlock * >::const_reverse_iterator const_pred_reverse_iterator
MachineFunction * getParent()
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...
iterator_range< const_succ_iterator > successors() const
void setIsEHFuncletEntry(bool V=true)
Indicates if this is the entry block of an EH funclet.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate IT block based on arch"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT, "arm-no-restrict-it", "Allow IT blocks based on ARMv7")))
iterator_range< const_pred_iterator > predecessors() const
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)
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 '...
std::vector< MachineBasicBlock * >::reverse_iterator pred_reverse_iterator
bool isEHPad() const
Returns true if the block is a landing pad.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
static NodeRef getEntryNode(const MachineBasicBlock *BB)
static NodeRef getEntryNode(Inverse< const MachineBasicBlock *> G)
void push_back(MachineInstr *MI)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
Pair of physical register and lane mask.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
const_instr_iterator instr_begin() const
const_iterator end() const
const_succ_iterator succ_end() const
static ChildIteratorType child_begin(NodeRef N)
std::vector< MachineBasicBlock * >::reverse_iterator succ_reverse_iterator
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
bool hasLabelMustBeEmitted() const
Test whether this block must have its label emitted.
iterator_range< livein_iterator > liveins() const
Instructions::iterator instr_iterator
const_iterator getFirstNonDebugInstr() const
iterator_range< const_iterator > terminators() const
Optional< uint64_t > getIrrLoopHeaderWeight() const
const_reverse_instr_iterator instr_rend() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static ChildIteratorType child_end(NodeRef N)
const_instr_range instrs() const
const_pred_iterator pred_begin() const
Callbacks do nothing by default in iplist and ilist.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
Simple wrapper around std::function<void(raw_ostream&)>.
iterator insertAfter(iterator where, pointer New)
Instructions::const_iterator const_instr_iterator
const_reverse_iterator rend() const
static ChildIteratorType child_end(NodeRef N)
std::vector< MachineBasicBlock * >::iterator succ_iterator
MachineInstrSpan(MachineBasicBlock::iterator I, MachineBasicBlock *BB)
const MachineInstr & instr_front() const
static NodeRef getEntryNode(MachineBasicBlock *BB)
void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator)
Callback before transferring nodes to this list.
MachineBasicBlock::iterator begin()