13#ifndef LLVM_IR_BASICBLOCK_H
14#define LLVM_IR_BASICBLOCK_H
33class AssemblyAnnotationWriter;
41class ValueSymbolTable;
42class DbgVariableRecord;
105 assert(
getParent() &&
"only basic blocks in functions have valid numbers");
154 std::optional<DbgRecord::self_iterator> Pos);
190 ilist_iterator_bits<true>,
191 ilist_parent<BasicBlock>>;
198 InstListType::iterator InsertPos);
200 InstListType::iterator I,
204 const Instruction *From, std::optional<DbgRecord::self_iterator> FromHere,
213 Function *Parent = nullptr,
214 BasicBlock *InsertBefore = nullptr) {
228 return const_cast<Module *
>(
240 if (InstList.empty() || !InstList.back().isTerminator())
242 return &InstList.back();
442 bool ShouldPreserveUseListOrder =
false,
443 bool IsForDebug =
false)
const;
469 inline size_t size()
const {
return InstList.size(); }
470 inline bool empty()
const {
return InstList.empty(); }
477 template <
typename PHINodeT = PHINode,
typename BBIteratorT = iterator>
480 std::forward_iterator_tag, PHINodeT> {
493 template <
typename PHINodeU,
typename BBIteratorU,
494 typename = std::enable_if_t<
495 std::is_convertible<PHINodeU *, PHINodeT *>::value>>
503 using phi_iterator_impl::iterator_facade_base::operator++;
505 assert(PN &&
"Cannot increment the end iterator!");
506 PN = dyn_cast<PHINodeT>(std::next(BBIteratorT(PN)));
527 const InstListType &getInstList()
const {
return InstList; }
532 static InstListType BasicBlock::*getSublistAccess(Instruction *) {
533 return &BasicBlock::InstList;
560 return V->getValueID() == Value::BasicBlockVal;
639 auto FromItNext = std::next(FromIt);
641 if (ToIt == FromIt || ToIt == FromItNext)
643 splice(ToIt, FromBB, FromIt, FromItNext);
659 return getBasicBlockBits().BlockAddressRefCount != 0;
701 return getBasicBlockBits().InstrOrderValid;
707 BasicBlockBits Bits = getBasicBlockBits();
708 Bits.InstrOrderValid =
false;
709 setBasicBlockBits(Bits);
726#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
729#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
730#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
732#define BEGIN_TWO_BYTE_PACK()
733#define END_TWO_BYTE_PACK()
738 struct BasicBlockBits {
739 unsigned short BlockAddressRefCount : 15;
740 unsigned short InstrOrderValid : 1;
744#undef BEGIN_TWO_BYTE_PACK
745#undef END_TWO_BYTE_PACK
748 BasicBlockBits getBasicBlockBits()
const {
749 static_assert(
sizeof(BasicBlockBits) ==
sizeof(
unsigned short),
750 "too many bits for Value::SubclassData");
752 BasicBlockBits AsBits;
753 memcpy(&AsBits, &ValueData,
sizeof(AsBits));
758 void setBasicBlockBits(BasicBlockBits AsBits) {
760 memcpy(&
D, &AsBits,
sizeof(
D));
769 void AdjustBlockAddressRefCount(
int Amt) {
770 BasicBlockBits
Bits = getBasicBlockBits();
771 Bits.BlockAddressRefCount += Amt;
772 setBasicBlockBits(Bits);
773 assert(
Bits.BlockAddressRefCount < 255 &&
"Refcount wrap-around");
778 void setValueSubclassData(
unsigned short D) {
812 reinterpret_cast<void *
>(It.getNodePtr())) ^
818 return LHS ==
RHS &&
LHS.getHeadBit() ==
RHS.getHeadBit();
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
This file defines the DenseMap class.
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
unsigned getNumber() const
Instruction * getFirstMayFaultInst()
iterator begin()
Instruction iterator methods.
void deleteTrailingDbgRecords()
Delete any trailing DbgRecords at the end of this block, see setTrailingDbgRecords.
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.
void setTrailingDbgRecords(DbgMarker *M)
Record that the collection of DbgRecords in M "trails" after the last instruction of this block.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
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.
InstListType::iterator getFirstNonPHIIt()
DbgMarker * createMarker(Instruction *I)
Attach a DbgMarker to the given instruction.
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,...
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
BasicBlock * splitBasicBlockBefore(Instruction *I, const Twine &BBName="")
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
friend void Instruction::removeFromParent()
void convertToNewDbgValues()
Convert variable location debugging information stored in dbg.value intrinsics into DbgMarkers / DbgR...
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
void setIsNewDbgInfoFormat(bool NewFlag)
Ensure the block is in "old" dbg.value format (NewFlag == false) or in the new format (NewFlag == tru...
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()
friend BasicBlock::iterator Instruction::eraseFromParent()
void setNewDbgInfoFormatFlag(bool NewFlag)
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()
void convertFromNewDbgValues()
Convert variable location debugging information stored in DbgMarkers and DbgRecords into the dbg....
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
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)
void dumpDbgValues() const
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
InstListType::reverse_iterator reverse_iterator
friend void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I, bool Preserve)
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 flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
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 DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
const_reverse_iterator rend() const
void insertDbgRecordAfter(DbgRecord *DR, Instruction *I)
Insert a DbgRecord into a block at the position given by I.
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,...
DbgMarker * getMarker(InstListType::iterator It)
Return the DbgMarker for the position given by It, so that DbgRecords can be inserted there.
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,...
SymbolTableList< Instruction, ilist_iterator_bits< true >, ilist_parent< BasicBlock > > InstListType
Instruction * getTerminator()
BasicBlock & operator=(const BasicBlock &)=delete
iterator getFirstNonPHIOrDbgOrAlloca()
bool IsNewDbgInfoFormat
Flag recording whether or not this block stores debug-info in the form of intrinsic instructions (fal...
CallInst * getTerminatingDeoptimizeCall()
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
void reinsertInstInDbgRecords(Instruction *I, std::optional< DbgRecord::self_iterator > Pos)
In rare circumstances instructions can be speculatively removed from blocks, and then be re-inserted ...
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.
DbgMarker * getTrailingDbgRecords()
Fetch the collection of DbgRecords that "trail" after the last instruction of this 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 ...
DbgMarker * getNextMarker(Instruction *I)
Return the DbgMarker for the position that comes after I.
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.
A parsed version of the target data layout string in and methods for querying it.
Per-instruction record of debug-info.
Base class for non-instruction debug metadata records that have positions within IR.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
iterator_range< simple_ilist< DbgRecord >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DbgRecord >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
InstListType::iterator insertInto(BasicBlock *ParentBB, InstListType::iterator It)
Inserts an unlinked instruction into ParentBB at position It and returns the iterator of the inserted...
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.
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.
static BasicBlock::iterator getEmptyKey()
static unsigned getHashValue(const BasicBlock::iterator &It)
static bool isEqual(const BasicBlock::iterator &LHS, const BasicBlock::iterator &RHS)
static BasicBlock::iterator getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Option to add extra bits to the ilist_iterator.
Option to add a pointer to this list's owner in every node.