14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
24 #include "llvm/Support/DataTypes.h"
31 class MachineFunction;
37 class MachineBranchProbabilityInfo;
68 : PhysReg(PhysReg), LaneMask(LaneMask) {}
79 std::vector<MachineBasicBlock *> Predecessors;
80 std::vector<MachineBasicBlock *> Successors;
85 std::vector<BranchProbability> Probs;
86 typedef std::vector<BranchProbability>::iterator probability_iterator;
87 typedef std::vector<BranchProbability>::const_iterator
88 const_probability_iterator;
91 typedef std::vector<RegisterMaskPair> LiveInVector;
96 unsigned Alignment = 0;
103 bool AddressTaken =
false;
106 bool IsEHFuncletEntry =
false;
109 bool IsCleanupFuncletEntry =
false;
113 mutable MCSymbol *CachedMCSymbol =
nullptr;
120 ~MachineBasicBlock();
159 unsigned size()
const {
return (
unsigned)Insts.size(); }
160 bool empty()
const {
return Insts.empty(); }
205 return &MachineBasicBlock::Insts;
220 typedef std::vector<MachineBasicBlock *>::reverse_iterator
222 typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
224 typedef std::vector<MachineBasicBlock *>::reverse_iterator
226 typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
233 {
return Predecessors.rbegin();}
235 {
return Predecessors.rbegin();}
237 {
return Predecessors.rend(); }
239 {
return Predecessors.rend(); }
241 return (
unsigned)Predecessors.size();
249 {
return Successors.rbegin(); }
251 {
return Successors.rbegin(); }
253 {
return Successors.rend(); }
255 {
return Successors.rend(); }
257 return (
unsigned)Successors.size();
284 LiveIns.push_back(RegMaskPair);
420 bool NormalizeSuccProbs =
false);
428 bool NormalizeSuccProbs =
false);
538 template<
typename IT>
540 assert((I ==
end() || I->getParent() ==
this) &&
541 "iterator points outside of basic block");
547 assert((I ==
end() || I->getParent() ==
this) &&
548 "iterator points outside of basic block");
550 "Cannot insert instruction with bundle flags");
556 assert((I ==
end() || I->getParent() ==
this) &&
557 "iterator points outside of basic block");
559 "Cannot insert instruction with bundle flags");
586 return erase(I, std::next(I));
603 assert(!
I->isBundled() &&
"Cannot remove bundled instructions");
625 splice(Where, Other, From, std::next(From));
685 unsigned Neighborhood=10)
const;
708 const_probability_iterator
739 public std::unary_function<const MachineBasicBlock*, unsigned> {
810 B(I == MBB.
begin() ? MBB.
end() : std::prev(I)),
814 return B == MBB.
end() ? MBB.
begin() : std::next(B);
826 template<
typename IterT>
828 while (It != End && It->isDebugValue())
837 template<
class IterT>
839 while (It != Begin && It->isDebugValue())
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 MachineBasicBlock * NodeRef
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
const_iterator getLastNonDebugInstr() const
A common definition of LaneBitmask for use in TableGen and CodeGen.
pred_reverse_iterator pred_rend()
MachineBasicBlock * NodeRef
const_instr_iterator instr_begin() const
instr_iterator instr_begin()
iterator_range< livein_iterator > liveins() const
instr_iterator instr_end()
iterator erase(iterator where)
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()
Instructions::const_reverse_iterator const_reverse_instr_iterator
aarch64 AArch64 CCMP Pass
Instructions::const_iterator const_instr_iterator
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().
MachineBasicBlock::pred_iterator ChildIteratorType
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
friend class MachineFunction
iterator_range< livein_iterator > liveins_dbg() const
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Template traits for intrusive list.
void addSuccessorWithoutProb(MachineBasicBlock *Succ)
Add Succ as a successor of this MachineBasicBlock.
DebugLoc findDebugLoc(iterator MBBI)
MachineInstrBundleIterator< MachineInstr > iterator
void moveAfter(MachineBasicBlock *NewBefore)
Manage lifetime of a slot tracker for printing IR.
MachineBasicBlock * NodeRef
iterator_range< const_succ_iterator > successors() const
Instructions::iterator instr_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...
std::vector< MachineBasicBlock * >::const_reverse_iterator const_pred_reverse_iterator
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.
const_iterator getFirstNonDebugInstr() const
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.
std::vector< MachineBasicBlock * >::iterator succ_iterator
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...
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)
iterator_range< const_instr_iterator > const_instr_range
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
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().
std::vector< MachineBasicBlock * >::iterator pred_iterator
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()
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
const_reverse_instr_iterator instr_rend() const
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
Register is known to be fully dead.
void splice(iterator where, iplist_impl &L2)
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
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()
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. ...
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
const_instr_range instrs() const
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions.
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.
bool hasEHPadSuccessor() const
Iterator for intrusive lists based on ilist_node.
base_list_type::iterator iterator
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 *)
const_succ_reverse_iterator succ_rbegin() const
std::vector< MachineBasicBlock * >::const_reverse_iterator const_succ_reverse_iterator
const_succ_reverse_iterator succ_rend() const
void updateTerminator()
Update the terminator instructions in block to account for changes to the layout. ...
std::vector< MachineBasicBlock * >::reverse_iterator succ_reverse_iterator
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
reverse_instr_iterator instr_rend()
A range adaptor for a pair of iterators.
StringRef getName() const
Return the name of the corresponding LLVM basic block, or "(null)".
void push_back(pointer val)
MachineBasicBlock::const_succ_iterator ChildIteratorType
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
Replace successor OLD with NEW and update probability info.
void setHasAddressTaken()
Set this block to reflect that it potentially is the target of an indirect branch.
MachineFunction * getParent()
MachineInstrBundleIterator< const MachineInstr, true > const_reverse_iterator
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.
pointer remove(iterator &IT)
bool hasAddressTaken() const
Test whether this block is potentially the target of an indirect branch.
const_pred_iterator pred_begin() const
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 '...
const MachineBasicBlock * NodeRef
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.
const uint32_t * getEndClobberMask(const TargetRegisterInfo *TRI) const
Get the clobber mask for the end of the basic block.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static ChildIteratorType child_begin(NodeRef N)
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::reverse_iterator reverse_instr_iterator
iterator_range< instr_iterator > instr_range
MachineBasicBlock::const_pred_iterator ChildIteratorType
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...
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
static ChildIteratorType child_end(NodeRef N)
std::vector< MachineBasicBlock * >::reverse_iterator pred_reverse_iterator
LiveInVector::const_iterator livein_iterator
MachineInstrBundleIterator< const MachineInstr > const_iterator
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
iterator insertAfter(iterator where, pointer New)
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
unsigned pred_size() const
static ChildIteratorType child_end(NodeRef N)
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.