13#ifndef LLVM_IR_BASICBLOCK_H
14#define LLVM_IR_BASICBLOCK_H
31class AssemblyAnnotationWriter;
38class ValueSymbolTable;
106 Function *Parent = nullptr,
107 BasicBlock *InsertBefore = nullptr) {
121 return const_cast<Module *
>(
128 if (InstList.empty() || !InstList.back().isTerminator())
130 return &InstList.back();
320 bool ShouldPreserveUseListOrder =
false,
321 bool IsForDebug =
false)
const;
336 inline size_t size()
const {
return InstList.size(); }
337 inline bool empty()
const {
return InstList.empty(); }
344 template <
typename PHINodeT = PHINode,
typename BBIteratorT = iterator>
347 std::forward_iterator_tag, PHINodeT> {
360 template <
typename PHINodeU,
typename BBIteratorU,
361 typename = std::enable_if_t<
362 std::is_convertible<PHINodeU *, PHINodeT *>::value>>
370 using phi_iterator_impl::iterator_facade_base::operator++;
372 assert(PN &&
"Cannot increment the end iterator!");
373 PN = dyn_cast<PHINodeT>(std::next(BBIteratorT(PN)));
394 const InstListType &getInstList()
const {
return InstList; }
399 static InstListType BasicBlock::*getSublistAccess(Instruction *) {
400 return &BasicBlock::InstList;
409 return V->getValueID() == Value::BasicBlockVal;
451 bool Before =
false);
453 bool Before =
false) {
488 auto FromItNext = std::next(FromIt);
490 if (ToIt == FromIt || ToIt == FromItNext)
492 splice(ToIt, FromBB, FromIt, FromItNext);
508 return getBasicBlockBits().BlockAddressRefCount != 0;
550 return getBasicBlockBits().InstrOrderValid;
556 BasicBlockBits Bits = getBasicBlockBits();
557 Bits.InstrOrderValid =
false;
558 setBasicBlockBits(Bits);
575#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
578#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
579#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
581#define BEGIN_TWO_BYTE_PACK()
582#define END_TWO_BYTE_PACK()
587 struct BasicBlockBits {
588 unsigned short BlockAddressRefCount : 15;
589 unsigned short InstrOrderValid : 1;
593#undef BEGIN_TWO_BYTE_PACK
594#undef END_TWO_BYTE_PACK
597 BasicBlockBits getBasicBlockBits()
const {
598 static_assert(
sizeof(BasicBlockBits) ==
sizeof(
unsigned short),
599 "too many bits for Value::SubclassData");
601 BasicBlockBits AsBits;
602 memcpy(&AsBits, &ValueData,
sizeof(AsBits));
607 void setBasicBlockBits(BasicBlockBits AsBits) {
609 memcpy(&
D, &AsBits,
sizeof(
D));
618 void AdjustBlockAddressRefCount(
int Amt) {
619 BasicBlockBits
Bits = getBasicBlockBits();
620 Bits.BlockAddressRefCount += Amt;
621 setBasicBlockBits(Bits);
622 assert(
Bits.BlockAddressRefCount < 255 &&
"Refcount wrap-around");
627 void setValueSubclassData(
unsigned short D) {
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Machine Check Debug Module
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
#define END_TWO_BYTE_PACK()
#define BEGIN_TWO_BYTE_PACK()
Iterator to walk just the phi nodes in the basic block.
bool operator==(const phi_iterator_impl &Arg) const
phi_iterator_impl(const phi_iterator_impl< PHINodeU, BBIteratorU > &Arg)
PHINodeT & operator*() const
phi_iterator_impl()=default
phi_iterator_impl & operator++()
LLVM Basic Block Representation.
BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
BasicBlock(const BasicBlock &)=delete
Instruction * getFirstMayFaultInst()
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const_iterator begin() const
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
SymbolTableList< Instruction > InstListType
reverse_iterator rbegin()
static bool classof(const Value *V)
Methods for support type inquiry through isa, cast, and dyn_cast.
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
BasicBlock * splitBasicBlock(Instruction *I, const Twine &BBName="", bool Before=false)
BasicBlock * splitBasicBlockBefore(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction and insert the new basic blo...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
BasicBlock * splitBasicBlockBefore(Instruction *I, const Twine &BBName="")
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
friend void Instruction::removeFromParent()
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the basic block to an output stream with an optional AssemblyAnnotationWriter.
InstListType::const_iterator const_iterator
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
BasicBlock * getUniqueSuccessor()
const Instruction & front() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
BasicBlock * getSingleSuccessor()
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
BasicBlock * getUniquePredecessor()
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
BasicBlock * getSinglePredecessor()
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
friend iplist< Instruction >::iterator Instruction::eraseFromParent()
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true)
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
InstListType::reverse_iterator reverse_iterator
void replacePhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block to refer to basic block New instead of basic block Old.
const Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB, BasicBlock::iterator FromIt)
Transfer one instruction from FromBB at FromIt to this basic block at ToIt.
const Function * getParent() const
Return the enclosing method, or null if none.
const_reverse_iterator rend() const
void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
filter_iterator< BasicBlock::const_iterator, std::function< bool(constInstruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
InstListType::iterator iterator
Instruction iterators...
Instruction * getFirstNonPHI()
LLVMContext & getContext() const
Get the context in which this basic block lives.
CallInst * getPostdominatingDeoptimizeCall()
const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Instruction * getTerminator()
BasicBlock & operator=(const BasicBlock &)=delete
iterator getFirstNonPHIOrDbgOrAlloca()
CallInst * getTerminatingDeoptimizeCall()
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
bool isLandingPad() const
Return true if this basic block is a landing pad.
InstListType::const_reverse_iterator const_reverse_iterator
bool isEHPad() const
Return true if this basic block is an exception handling block.
CallInst * getTerminatingMustTailCall()
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool canSplitPredecessors() const
const_iterator end() const
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
friend BasicBlock::iterator Instruction::insertInto(BasicBlock *BB, BasicBlock::iterator It)
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true)
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
const Instruction * getFirstMayFaultInst() const
Returns the first potential AsynchEH faulty instruction currently it checks for loads/stores (which m...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
const_reverse_iterator rbegin() const
LandingPadInst * getLandingPadInst()
const Instruction & back() const
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
iterator getFirstInsertionPt()
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
The address of a basic block.
This class represents a function call, abstracting a target machine's calling convention.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
SymbolTableList< Instruction >::iterator insertInto(BasicBlock *ParentBB, SymbolTableList< Instruction >::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This is an important class for using LLVM in a threaded context.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
A Module instance is used to store all the information related to an LLVM module.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
unsigned short getSubclassDataFromValue() const
void setValueSubclassData(unsigned short D)
Specialization of filter_iterator_base for forward iteration only.
Iterator for intrusive lists based on ilist_node.
self_iterator getIterator()
An ilist node that can access its parent list.
base_list_type::const_reverse_iterator const_reverse_iterator
base_list_type::reverse_iterator reverse_iterator
base_list_type::const_iterator const_iterator
base_list_type::iterator iterator
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
This file defines classes to implement an intrusive doubly linked list class (i.e.
This file defines the ilist_node class template, which is a convenient base class for creating classe...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.