14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H 15 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H 39 class MachineFunction;
41 class ModuleSlotTracker;
46 class TargetRegisterClass;
47 class TargetRegisterInfo;
78 : PhysReg(PhysReg), LaneMask(LaneMask) {}
90 std::vector<MachineBasicBlock *> Predecessors;
91 std::vector<MachineBasicBlock *> Successors;
96 std::vector<BranchProbability> Probs;
97 using probability_iterator = std::vector<BranchProbability>::iterator;
98 using const_probability_iterator =
99 std::vector<BranchProbability>::const_iterator;
104 using LiveInVector = std::vector<RegisterMaskPair>;
105 LiveInVector LiveIns;
109 unsigned Alignment = 0;
112 bool IsEHPad =
false;
116 bool AddressTaken =
false;
121 bool IsEHScopeEntry =
false;
124 bool IsEHFuncletEntry =
false;
127 bool IsCleanupFuncletEntry =
false;
131 mutable MCSymbol *CachedMCSymbol =
nullptr;
153 std::string getFullName()
const;
177 unsigned size()
const {
return (
unsigned)Insts.size(); }
178 bool empty()
const {
return Insts.empty(); }
211 return reverse_iterator::getAtBundleBegin(instr_rbegin());
214 return const_reverse_iterator::getAtBundleBegin(instr_rbegin());
223 return &MachineBasicBlock::Insts;
247 std::vector<MachineBasicBlock *>::reverse_iterator;
249 std::vector<MachineBasicBlock *>::const_reverse_iterator;
251 std::vector<MachineBasicBlock *>::reverse_iterator;
253 std::vector<MachineBasicBlock *>::const_reverse_iterator;
259 {
return Predecessors.rbegin();}
261 {
return Predecessors.rbegin();}
263 {
return Predecessors.rend(); }
265 {
return Predecessors.rend(); }
267 return (
unsigned)Predecessors.size();
275 {
return Successors.rbegin(); }
277 {
return Successors.rbegin(); }
279 {
return Successors.rend(); }
281 {
return Successors.rend(); }
283 return (
unsigned)Successors.size();
310 LiveIns.push_back(RegMaskPair);
316 void sortUniqueLiveIns();
344 return make_range(livein_begin_dbg(), livein_end());
351 return make_range(livein_begin(), livein_end());
381 bool hasEHPadSuccessor()
const;
404 bool isLegalToHoistInto()
const;
418 void updateTerminator();
453 void validateSuccProbs()
const;
460 bool NormalizeSuccProbs =
false);
468 bool NormalizeSuccProbs =
false);
483 bool NormalizeSuccProbs =
false);
522 bool canFallThrough();
569 return !
empty() && back().isReturn();
575 return !
empty() && back().isEHScopeReturn();
604 template<
typename IT>
606 assert((I ==
end() || I->getParent() ==
this) &&
607 "iterator points outside of basic block");
613 assert((I ==
end() || I->getParent() ==
this) &&
614 "iterator points outside of basic block");
616 "Cannot insert instruction with bundle flags");
622 assert((I ==
end() || I->getParent() ==
this) &&
623 "iterator points outside of basic block");
625 "Cannot insert instruction with bundle flags");
652 return erase(I, std::next(I));
669 assert(!I->isBundled() &&
"Cannot remove bundled instructions");
691 splice(Where, Other, From, std::next(From));
710 void eraseFromParent();
762 unsigned Neighborhood = 10)
const;
767 bool IsStandalone =
true)
const;
769 const SlotIndexes * =
nullptr,
bool IsStandalone =
true)
const;
772 void printAsOperand(
raw_ostream &OS,
bool PrintType =
true)
const;
783 return IrrLoopHeaderWeight;
787 IrrLoopHeaderWeight = Weight;
792 probability_iterator getProbabilityIterator(
succ_iterator I);
793 const_probability_iterator
910 return B == MBB.
end() ? MBB.
begin() : std::next(B);
922 template<
typename IterT>
924 while (It != End && It->isDebugInstr())
933 template<
class IterT>
935 while (It != Begin && It->isDebugInstr())
942 #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.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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.
instr_iterator instr_end()
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
MachineInstrSpan(MachineBasicBlock::iterator I)
iterator insert(iterator I, MachineInstr *MI)
Insert MI into the instruction list before I.
void setAlignment(unsigned Align)
Set alignment of the basic block.
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()
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()
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
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)
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
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.
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
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
unsigned getAlignment() const
Return alignment of the basic block.
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.
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.
reverse_instr_iterator instr_rbegin()
iterator_range< const_iterator > phis() const
BlockVerifier::State From
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)
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)
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
static const Function * getParent(const Value *V)
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
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()