14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15 #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;
101 using LiveInVector = std::vector<RegisterMaskPair>;
102 LiveInVector LiveIns;
106 unsigned Alignment = 0;
109 bool IsEHPad =
false;
113 bool AddressTaken =
false;
116 bool IsEHFuncletEntry =
false;
119 bool IsCleanupFuncletEntry =
false;
123 mutable MCSymbol *CachedMCSymbol =
nullptr;
169 unsigned size()
const {
return (
unsigned)Insts.size(); }
170 bool empty()
const {
return Insts.empty(); }
215 return &MachineBasicBlock::Insts;
231 std::vector<MachineBasicBlock *>::reverse_iterator;
233 std::vector<MachineBasicBlock *>::const_reverse_iterator;
235 std::vector<MachineBasicBlock *>::reverse_iterator;
237 std::vector<MachineBasicBlock *>::const_reverse_iterator;
243 {
return Predecessors.rbegin();}
245 {
return Predecessors.rbegin();}
247 {
return Predecessors.rend(); }
249 {
return Predecessors.rend(); }
251 return (
unsigned)Predecessors.size();
259 {
return Successors.rbegin(); }
261 {
return Successors.rbegin(); }
263 {
return Successors.rend(); }
265 {
return Successors.rend(); }
267 return (
unsigned)Successors.size();
294 LiveIns.push_back(RegMaskPair);
436 bool NormalizeSuccProbs =
false);
444 bool NormalizeSuccProbs =
false);
562 template<
typename IT>
564 assert((I ==
end() || I->getParent() ==
this) &&
565 "iterator points outside of basic block");
571 assert((I ==
end() || I->getParent() ==
this) &&
572 "iterator points outside of basic block");
574 "Cannot insert instruction with bundle flags");
580 assert((I ==
end() || I->getParent() ==
this) &&
581 "iterator points outside of basic block");
583 "Cannot insert instruction with bundle flags");
610 return erase(I, std::next(I));
627 assert(!
I->isBundled() &&
"Cannot remove bundled instructions");
649 splice(Where, Other, From, std::next(From));
713 unsigned Neighborhood = 10)
const;
735 const_probability_iterator
766 public std::unary_function<const MachineBasicBlock*, unsigned> {
840 B(I == MBB.
begin() ? MBB.
end() : std::prev(I)),
844 return B == MBB.
end() ? MBB.
begin() : std::next(B);
856 template<
typename IterT>
858 while (It != End && It->isDebugValue())
867 template<
class IterT>
869 while (It != Begin && It->isDebugValue())
876 #endif // LLVM_CODEGEN_MACHINEBASICBLOCK_H
Pass interface - Implemented by all 'passes'.
pred_reverse_iterator pred_rbegin()
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")))
unsigned succ_size() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
bool isEHPad() const
Returns true if the block is a landing pad.
const_iterator getLastNonDebugInstr() const
A common definition of LaneBitmask for use in TableGen and CodeGen.
pred_reverse_iterator pred_rend()
const_instr_iterator instr_begin() const
instr_iterator instr_begin()
iterator_range< livein_iterator > liveins() const
instr_iterator instr_end()
static NodeRef getEntryNode(Inverse< const MachineBasicBlock * > G)
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 ...
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
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
static ChildIteratorType child_begin(NodeRef N)
instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
static LaneBitmask getAll()
iterator getFirstNonDebugInstr()
Returns an iterator to the first non-debug instruction in the basic block, or end().
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
MachineBasicBlock::succ_iterator ChildIteratorType
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
static NodeRef getEntryNode(Inverse< MachineBasicBlock * > G)
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *FromMBB)
Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor bloc...
MachineInstr & instr_back()
bool isCleanupFuncletEntry() const
Returns true if this is the entry block of a cleanup funclet.
void transferSuccessors(MachineBasicBlock *FromMBB)
Transfers all the successors from MBB to this machine basic block (i.e., copies all the successors Fr...
iterator_range< const_iterator > terminators() const
iterator_range< livein_iterator > liveins_dbg() const
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
Template traits for intrusive list.
void addSuccessorWithoutProb(MachineBasicBlock *Succ)
Add Succ as a successor of this MachineBasicBlock.
DebugLoc findDebugLoc(iterator MBBI)
void moveAfter(MachineBasicBlock *NewBefore)
Manage lifetime of a slot tracker for printing IR.
MachineInstrBundleIterator< const MachineInstr > const_iterator
iterator_range< const_succ_iterator > successors() const
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.
MachineBasicBlock * removeFromParent()
This method unlinks 'this' from the containing function, and returns it, but does not delete it...
void setAlignment(unsigned Align)
Set alignment of the basic block.
void removeLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll())
Remove the specified register from the live in set.
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 ...
MachineInstrSpan provides an interface to get an iteration range containing the instruction it was in...
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.
MachineBasicBlock::pred_iterator ChildIteratorType
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const_iterator getFirstNonDebugInstr() const
iterator_range< const_instr_iterator > const_instr_range
iterator erase(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
MachineBasicBlock * getFallThrough()
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
void insert(iterator I, IT S, IT E)
Insert a range of instructions into the instruction list before I.
Reg
All possible values of the reg field in the ModR/M byte.
iterator_range< iterator > terminators()
MachineInstr * remove_instr(MachineInstr *I)
Remove the possibly bundled instruction from the instruction list without deleting it...
LiveInVector::const_iterator livein_iterator
const MachineInstr & instr_front() const
void setIsCleanupFuncletEntry(bool V=true)
Indicates if this is the entry block of a cleanup funclet.
MachineBasicBlock::iterator end()
A simple intrusive list implementation.
static ChildIteratorType child_end(NodeRef N)
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
const_succ_iterator succ_end() const
const MachineInstr & front() const
static void normalizeProbabilities(ProbabilityIter Begin, ProbabilityIter End)
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
bool canFallThrough()
Return true if the block can implicitly transfer control to the block after it by falling off the end...
static Instructions MachineBasicBlock::* getSublistAccess(MachineInstr *)
Support for MachineInstr::getNextNode().
bool livein_empty() const
Instructions::reverse_iterator reverse_instr_iterator
MachineInstrBundleIterator< const MachineInstr, true > const_reverse_iterator
const uint32_t * getBeginClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the start of this basic block.
iterator getLastNonDebugInstr()
Returns an iterator to the last non-debug instruction in the basic block, or end().
void printAsOperand(raw_ostream &OS, bool PrintType=true) const
void setSuccProbability(succ_iterator I, BranchProbability Prob)
Set successor probability of a given iterator.
succ_reverse_iterator succ_rend()
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been <def>ined and not <kill>ed as of just before Before...
const_pred_iterator pred_end() const
reverse_iterator rbegin()
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
const_reverse_instr_iterator instr_rend() const
iterator_range< instr_iterator > instr_range
std::vector< MachineBasicBlock * >::const_reverse_iterator const_succ_reverse_iterator
MachineInstrBundleIterator< MachineInstr > iterator
An ilist node that can access its parent list.
bool isReturn(QueryType Type=AnyInBundle) const
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
instr_iterator erase_instr(MachineInstr *I)
Remove an instruction from the instruction list and delete it.
livein_iterator livein_begin() const
LLVM Basic Block Representation.
static ChildIteratorType child_end(NodeRef N)
succ_reverse_iterator succ_rbegin()
static ChildIteratorType child_begin(NodeRef N)
const_iterator begin() const
livein_iterator livein_begin_dbg() const
Unlike livein_begin, this method does not check that the liveness information is accurate.
livein_iterator livein_end() const
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
Register is known to be fully dead.
void clearLiveIns()
Clear live in list.
bool isEHFuncletEntry() const
Returns true if this is the entry block of an EH funclet.
static const unsigned End
static MachineInstrBundleIterator getAtBundleBegin(instr_iterator MI)
Get the bundle iterator for the given instruction's bundle.
This class prints out the machine instructions using the MIR serialization format.
const_reverse_instr_iterator instr_rbegin() const
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
MachineBasicBlock::const_succ_iterator ChildIteratorType
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
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()
const_iterator getFirstTerminator() const
const MachineInstr & instr_back() const
void moveBefore(MachineBasicBlock *NewAfter)
Move 'this' block before or after the specified block.
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()
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
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.
bool isReturnBlock() const
Convenience function that returns true if the block ends in a return instruction. ...
const_instr_range instrs() const
bool canSplitCriticalEdge(const MachineBasicBlock *Succ) const
Check if the edge between this block and the given successor Succ, can be split.
std::string getFullName() const
Return a formatted string to identify this block and its parent function.
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
bool hasEHPadSuccessor() const
Iterator for intrusive lists based on ilist_node.
const_iterator end() const
void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
reverse_instr_iterator instr_rbegin()
void removeNodeFromList(NodeTy *)
bool isLegalToHoistInto() const
Returns true if it is legal to hoist instructions into this block.
const_succ_reverse_iterator succ_rbegin() const
const_succ_reverse_iterator succ_rend() const
void updateTerminator()
Update the terminator instructions in block to account for changes to the layout. ...
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
void validateSuccProbs() const
Validate successors' probabilities and check if the sum of them is approximate one.
instr_iterator getInstrIterator() const
MachineBasicBlock::iterator getInitial()
void addLiveIn(const RegisterMaskPair &RegMaskPair)
static void deleteNode(NodeTy *V)
void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
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_reverse_iterator rbegin() const
Instructions::const_reverse_iterator const_reverse_instr_iterator
reverse_instr_iterator instr_rend()
MachineBasicBlock::const_pred_iterator ChildIteratorType
A range adaptor for a pair of iterators.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
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.
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()
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 setIsEHFuncletEntry(bool V=true)
Indicates if this is the entry block of an EH funclet.
bool hasSuccessorProbabilities() const
Return true if any of the successors have probabilities attached to them.
Representation of each machine instruction.
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
const_pred_iterator pred_begin() const
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
Register liveness not decidable from local neighborhood.
static NodeRef getEntryNode(const MachineBasicBlock *BB)
const_reverse_iterator rend() const
void push_back(MachineInstr *MI)
const_pred_reverse_iterator pred_rbegin() const
Pair of physical register and lane mask.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static ChildIteratorType child_begin(NodeRef N)
std::vector< MachineBasicBlock * >::reverse_iterator succ_reverse_iterator
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.
bool isLiveIn(MCPhysReg Reg, LaneBitmask LaneMask=LaneBitmask::getAll()) const
Return true if the specified register is in the live in set.
Instructions::iterator instr_iterator
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P)
Split the critical edge from this block to the given successor block, and return the newly created bl...
static ChildIteratorType child_end(NodeRef N)
static const Function * getParent(const Value *V)
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...
iterator SkipPHIsLabelsAndDebug(iterator I)
Return the first instruction in MBB after I that is not a PHI, label or debug.
const_pred_reverse_iterator pred_rend() const
bool isPredecessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a predecessor of this block.
StringRef - Represent a constant reference to a string, i.e.
const MachineInstr & back() const
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB will be emitted immediately after this block, such that if this bloc...
const_instr_iterator instr_end() const
Instructions::const_iterator const_instr_iterator
unsigned pred_size() const
static ChildIteratorType child_end(NodeRef N)
std::vector< MachineBasicBlock * >::iterator succ_iterator
unsigned operator()(const MachineBasicBlock *MBB) const
bool CorrectExtraCFGEdges(MachineBasicBlock *DestA, MachineBasicBlock *DestB, bool IsCond)
Various pieces of code can cause excess edges in the CFG to be inserted.
static NodeRef getEntryNode(MachineBasicBlock *BB)
void transferNodesFromList(ilist_callback_traits &OldList, Iterator, Iterator)
Callback before transferring nodes to this list.
iterator_range< const_pred_iterator > predecessors() const
MachineBasicBlock::iterator begin()
unsigned getAlignment() const
Return alignment of the basic block.