14 #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
15 #define LLVM_CODEGEN_MACHINEBASICBLOCK_H
19 #include "llvm/Support/DataTypes.h"
26 class MachineFunction;
31 class MachineBranchProbabilityInfo;
71 std::vector<MachineBasicBlock *> Predecessors;
72 std::vector<MachineBasicBlock *> Successors;
77 std::vector<uint32_t> Weights;
78 typedef std::vector<uint32_t>::iterator weight_iterator;
79 typedef std::vector<uint32_t>::const_iterator const_weight_iterator;
83 std::vector<unsigned> LiveIns;
143 template<
typename Ty,
typename IterTy>
145 :
public std::iterator<std::bidirectional_iterator_tag, Ty, ptrdiff_t> {
152 assert(!mi.isBundledWithPred() &&
153 "It's not legal to initialize bundle_iterator with a bundled MI");
156 assert((!mi || !mi->isBundledWithPred()) &&
157 "It's not legal to initialize bundle_iterator with a bundled MI");
160 template<
class OtherTy,
class OtherIterTy>
168 operator Ty*()
const {
return MII; }
180 while (MII->isBundledWithPred());
184 while (MII->isBundledWithSucc())
219 unsigned size()
const {
return (
unsigned)Insts.
size(); }
262 typedef std::vector<MachineBasicBlock *>::reverse_iterator
264 typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
266 typedef std::vector<MachineBasicBlock *>::reverse_iterator
268 typedef std::vector<MachineBasicBlock *>::const_reverse_iterator
275 {
return Predecessors.rbegin();}
277 {
return Predecessors.rbegin();}
279 {
return Predecessors.rend(); }
281 {
return Predecessors.rend(); }
283 return (
unsigned)Predecessors.size();
291 {
return Successors.rbegin(); }
293 {
return Successors.rbegin(); }
295 {
return Successors.rend(); }
297 {
return Successors.rend(); }
299 return (
unsigned)Successors.size();
327 std::sort(LiveIns.begin(), LiveIns.end());
328 LiveIns.erase(std::unique(LiveIns.begin(), LiveIns.end()), LiveIns.end());
507 template<
typename IT>
509 assert((I ==
end() || I->getParent() ==
this) &&
510 "iterator points outside of basic block");
511 Insts.
insert(I.getInstrIterator(), S, E);
516 assert((I ==
end() || I->getParent() ==
this) &&
517 "iterator points outside of basic block");
519 "Cannot insert instruction with bundle flags");
520 return Insts.
insert(I.getInstrIterator(),
MI);
525 assert((I ==
end() || I->getParent() ==
this) &&
526 "iterator points outside of basic block");
528 "Cannot insert instruction with bundle flags");
548 return Insts.
erase(I.getInstrIterator(), E.getInstrIterator());
555 return erase(I, std::next(I));
572 assert(!
I->isBundled() &&
"Cannot remove bundled instructions");
594 splice(Where, Other, From, std::next(From));
604 Insts.
splice(Where.getInstrIterator(), Other->Insts,
605 From.getInstrIterator(), To.getInstrIterator());
658 unsigned Neighborhood=10)
const;
718 public std::unary_function<const MachineBasicBlock*, unsigned> {
805 B(I == MBB.
begin() ? MBB.
end() : std::prev(I)),
809 return B == MBB.
end() ? MBB.
begin() : std::next(B);
Pass interface - Implemented by all 'passes'.
static ChildIteratorType child_end(NodeType *N)
pred_reverse_iterator pred_rbegin()
unsigned succ_size() const
static void noteHead(MachineInstr *, MachineInstr *)
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
const_iterator getLastNonDebugInstr() const
pred_reverse_iterator pred_rend()
const_instr_iterator instr_begin() const
instr_iterator instr_begin()
void transferNodesFromList(ilist_node_traits &, ilist_iterator< NodeTy >, ilist_iterator< NodeTy >)
void removeNodeFromList(NodeTy *)
instr_iterator instr_end()
bool operator==(const bundle_iterator &x) const
iplist< MachineInstr >::iterator iterator
static NodeTy * createNode(const NodeTy &V)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
int getNumber() const
getNumber - MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a M...
void setIsLandingPad(bool V=true)
setIsLandingPad - Indicates the block is a landing pad.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
MachineInstr & instr_front()
Instructions::const_iterator const_instr_iterator
const_succ_iterator succ_begin() const
instr_iterator getFirstInstrTerminator()
getFirstInstrTerminator - Same getFirstTerminator but it ignores bundles and return an instr_iterator...
iterator getFirstNonDebugInstr()
getFirstNonDebugInstr - returns an iterator to the first non-debug instruction in the basic block...
MachineBasicBlock::pred_iterator ChildIteratorType
bundle_iterator(const bundle_iterator< OtherTy, OtherIterTy > &I)
std::vector< unsigned >::const_iterator livein_iterator
iterator getFirstTerminator()
getFirstTerminator - returns an iterator to the first terminator instruction of this basic block...
MachineBasicBlock::succ_iterator ChildIteratorType
MachineInstr & instr_back()
void removeLiveIn(unsigned Reg)
removeLiveIn - Remove the specified register from the live in set.
static NodeType * getEntryNode(MachineBasicBlock *BB)
iterator_range< const_iterator > terminators() const
void addLiveIn(unsigned Reg)
Adds the specified register as a live in.
iterator insertAfter(iterator I, MachineInstr *MI)
Insert MI into the instruction list after I.
DebugLoc findDebugLoc(iterator MBBI)
void moveAfter(MachineBasicBlock *NewBefore)
void transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB)
transferSuccessorsAndUpdatePHIs - Transfers all the successors, as in transferSuccessors, and update PHI operands in the successor blocks which refer to fromMBB to refer to this.
Manage lifetime of a slot tracker for printing IR.
iterator_range< const_succ_iterator > successors() const
std::reverse_iterator< const_instr_iterator > const_reverse_instr_iterator
MachineInstr * createSentinel() 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()
removeFromParent - This method unlinks 'this' from the containing function, and returns it...
void setAlignment(unsigned Align)
setAlignment - Set alignment of the basic block.
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 ...
reverse_iterator rbegin()
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
livein_iterator livein_begin() const
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New)
ReplaceUsesOfBlockWith - Given a machine basic block that branched to 'Old', change the code and CFG ...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing function and deletes it...
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
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"), clEnumValEnd))
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()
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P)
SplitCriticalEdge - Split the critical edge from this block to the given successor block...
ilist_default_traits - Default template traits for intrusive list.
MachineInstr * remove_instr(MachineInstr *I)
Remove the possibly bundled instruction from the instruction list without deleting it...
const MachineInstr & instr_front() const
void destroySentinel(MachineInstr *) const
MachineBasicBlock::iterator end()
static NodeType * getEntryNode(const MachineBasicBlock *BB)
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
void transferSuccessors(MachineBasicBlock *fromMBB)
transferSuccessors - Transfers all the successors from MBB to this machine basic block (i...
std::reverse_iterator< instr_iterator > reverse_instr_iterator
const_succ_iterator succ_end() const
const MachineInstr & front() const
bool canFallThrough()
canFallThrough - Return true if the block can implicitly transfer control to the block after it by fa...
bool livein_empty() const
iterator getLastNonDebugInstr()
getLastNonDebugInstr - returns an iterator to the last non-debug instruction in the basic block...
std::vector< MachineBasicBlock * >::iterator pred_iterator
void printAsOperand(raw_ostream &OS, bool PrintType=true) const
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()
bundle_iterator operator--(int)
const BasicBlock * getBasicBlock() const
getBasicBlock - Return the LLVM basic block that this instance corresponded to originally.
const MachineBasicBlock NodeType
static NodeType * getEntryNode(Inverse< MachineBasicBlock * > G)
static void deleteNode(NodeTy *V)
const_reverse_instr_iterator instr_rend() const
bundle_iterator< MachineInstr, instr_iterator > iterator
IterTy getInstrIterator() const
static NodeType * getEntryNode(Inverse< const MachineBasicBlock * > G)
iterator SkipPHIsAndLabels(iterator I)
SkipPHIsAndLabels - 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.
LLVM Basic Block Representation.
static ChildIteratorType child_end(NodeType *N)
succ_reverse_iterator succ_rbegin()
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const
const_iterator begin() const
livein_iterator livein_end() const
DebugLoc findDebugLoc(instr_iterator MBBI)
findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE instructions...
bundle_iterator - MachineBasicBlock iterator that automatically skips over MIs that are inside bundle...
iterator insertAfter(iterator where, NodeTy *New)
iterator insert(iterator where, const NodeTy &val)
Register is known to be dead.
std::reverse_iterator< const_iterator > const_reverse_iterator
const MachineBasicBlock * getLandingPadSuccessor() const
getLandingPadSuccessor - If this block has a successor that is a landing pad, return it...
const_reverse_instr_iterator instr_rbegin() const
static ChildIteratorType child_begin(NodeType *N)
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 live.
succ_iterator succ_begin()
const_iterator getFirstTerminator() const
void removeSuccessor(MachineBasicBlock *succ)
removeSuccessor - Remove successor from the successors list of this MachineBasicBlock.
const MachineInstr & instr_back() const
bool operator!=(const bundle_iterator &x) const
void moveBefore(MachineBasicBlock *NewAfter)
moveBefore/moveAfter - 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.
static ChildIteratorType child_begin(NodeType *N)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
const MachineBasicBlock NodeType
iterator erase(iterator I, iterator E)
Remove a range of instructions from the instruction list and delete them.
iterator erase(iterator where)
std::vector< MachineBasicBlock * >::const_iterator const_pred_iterator
static ChildIteratorType child_end(NodeType *N)
std::string getFullName() const
getFullName - Return a formatted string to identify this block and its parent function.
MachineInstr * ensureHead(MachineInstr *) const
const_iterator end() const
reverse_instr_iterator instr_rbegin()
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()
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
isSuccessor - Return true if the specified MBB is a successor of this block.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
void sortUniqueLiveIns()
Sorts and uniques the LiveIns vector.
MachineBasicBlock::iterator getInitial()
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(NoStrictAlign), cl::values(clEnumValN(StrictAlign,"aarch64-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"aarch64-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
const_reverse_iterator rbegin() const
void splice(iterator where, iplist &L2)
reverse_instr_iterator instr_rend()
A range adaptor for a pair of iterators.
StringRef getName() const
getName - Return the name of the corresponding LLVM basic block, or "(null)".
MachineBasicBlock::const_succ_iterator ChildIteratorType
void replaceSuccessor(MachineBasicBlock *Old, MachineBasicBlock *New)
replaceSuccessor - Replace successor OLD with NEW and update weight info.
void setHasAddressTaken()
setHasAddressTaken - Set this block to reflect that it potentially is the target of an indirect branc...
MachineFunction * getParent()
MachineInstr * provideInitialHead() const
Register itself is not live, but some overlapping register is.
bundle_iterator(IterTy mii)
Representation of each machine instruction.
bundle_iterator< const MachineInstr, const_instr_iterator > const_iterator
bundle_iterator operator++(int)
bool hasAddressTaken() const
hasAddressTaken - Test whether this block is potentially the target of an indirect branch...
const_pred_iterator pred_begin() const
bool isLandingPad() const
isLandingPad - Returns true if the block is a landing pad.
void addNodeToList(NodeTy *)
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 '...
bool isLiveIn(unsigned Reg) const
isLiveIn - Return true if the specified register is in the live in set.
ilist_node - Base class that provides next/prev services for nodes that use ilist_nextprev_traits or ...
MachineBasicBlock NodeType
Register liveness not decidable from local neighborhood.
const_reverse_iterator rend() const
void push_back(MachineInstr *MI)
const_pred_reverse_iterator pred_rbegin() const
bundle_iterator & operator--()
iterator getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
void setSuccWeight(succ_iterator I, uint32_t weight)
Set successor weight of a given iterator.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
static ChildIteratorType child_begin(NodeType *N)
MachineBasicBlock::const_pred_iterator ChildIteratorType
MachineBasicBlock NodeType
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
static ChildIteratorType child_begin(NodeType *N)
std::vector< MachineBasicBlock * >::const_iterator const_succ_iterator
std::reverse_iterator< iterator > reverse_iterator
std::vector< MachineBasicBlock * >::reverse_iterator pred_reverse_iterator
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
const_pred_reverse_iterator pred_rend() const
bool isPredecessor(const MachineBasicBlock *MBB) const
isPredecessor - 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
void print(raw_ostream &OS, SlotIndexes *=nullptr) const
bool isLayoutSuccessor(const MachineBasicBlock *MBB) const
isLayoutSuccessor - Return true if the specified MBB will be emitted immediately after this block...
const_instr_iterator instr_end() const
NodeTy * remove(iterator &IT)
bundle_iterator & operator++()
void addSuccessor(MachineBasicBlock *succ, uint32_t weight=0)
addSuccessor - Add succ as a successor of this MachineBasicBlock.
unsigned pred_size() const
bool CorrectExtraCFGEdges(MachineBasicBlock *DestA, MachineBasicBlock *DestB, bool isCond)
CorrectExtraCFGEdges - Various pieces of code can cause excess edges in the CFG to be inserted...
static ChildIteratorType child_end(NodeType *N)
unsigned operator()(const MachineBasicBlock *MBB) const
void push_back(const NodeTy &val)
iterator_range< const_pred_iterator > predecessors() const
MachineBasicBlock::iterator begin()
unsigned getAlignment() const
getAlignment - Return alignment of the basic block.