13#ifndef LLVM_IR_BASICBLOCK_H
14#define LLVM_IR_BASICBLOCK_H
33class AssemblyAnnotationWriter;
40class ValueSymbolTable;
150 std::optional<DPValue::self_iterator> Pos);
186 ilist_iterator_bits<true>>;
193 InstListType::iterator InsertPos);
195 InstListType::iterator I,
198 const Instruction *From, std::optional<DPValue::self_iterator> FromHere,
207 Function *Parent = nullptr,
208 BasicBlock *InsertBefore = nullptr) {
222 return const_cast<Module *
>(
229 if (InstList.empty() || !InstList.back().isTerminator())
231 return &InstList.back();
431 bool ShouldPreserveUseListOrder =
false,
432 bool IsForDebug =
false)
const;
458 inline size_t size()
const {
return InstList.size(); }
459 inline bool empty()
const {
return InstList.empty(); }
466 template <
typename PHINodeT = PHINode,
typename BBIteratorT = iterator>
469 std::forward_iterator_tag, PHINodeT> {
482 template <
typename PHINodeU,
typename BBIteratorU,
483 typename = std::enable_if_t<
484 std::is_convertible<PHINodeU *, PHINodeT *>::value>>
492 using phi_iterator_impl::iterator_facade_base::operator++;
494 assert(PN &&
"Cannot increment the end iterator!");
495 PN = dyn_cast<PHINodeT>(std::next(BBIteratorT(PN)));
516 const InstListType &getInstList()
const {
return InstList; }
521 static InstListType BasicBlock::*getSublistAccess(Instruction *) {
522 return &BasicBlock::InstList;
549 return V->getValueID() == Value::BasicBlockVal;
628 auto FromItNext = std::next(FromIt);
630 if (ToIt == FromIt || ToIt == FromItNext)
632 splice(ToIt, FromBB, FromIt, FromItNext);
648 return getBasicBlockBits().BlockAddressRefCount != 0;
690 return getBasicBlockBits().InstrOrderValid;
696 BasicBlockBits Bits = getBasicBlockBits();
697 Bits.InstrOrderValid =
false;
698 setBasicBlockBits(Bits);
715#if defined(_AIX) && (!defined(__GNUC__) || defined(__clang__))
718#define BEGIN_TWO_BYTE_PACK() _Pragma("pack(2)")
719#define END_TWO_BYTE_PACK() _Pragma("pack(pop)")
721#define BEGIN_TWO_BYTE_PACK()
722#define END_TWO_BYTE_PACK()
727 struct BasicBlockBits {
728 unsigned short BlockAddressRefCount : 15;
729 unsigned short InstrOrderValid : 1;
733#undef BEGIN_TWO_BYTE_PACK
734#undef END_TWO_BYTE_PACK
737 BasicBlockBits getBasicBlockBits()
const {
738 static_assert(
sizeof(BasicBlockBits) ==
sizeof(
unsigned short),
739 "too many bits for Value::SubclassData");
741 BasicBlockBits AsBits;
742 memcpy(&AsBits, &ValueData,
sizeof(AsBits));
747 void setBasicBlockBits(BasicBlockBits AsBits) {
749 memcpy(&
D, &AsBits,
sizeof(
D));
758 void AdjustBlockAddressRefCount(
int Amt) {
759 BasicBlockBits
Bits = getBasicBlockBits();
760 Bits.BlockAddressRefCount += Amt;
761 setBasicBlockBits(Bits);
762 assert(
Bits.BlockAddressRefCount < 255 &&
"Refcount wrap-around");
767 void setValueSubclassData(
unsigned short D) {
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
DPMarker * getMarker(InstListType::iterator It)
Return the DPMarker for the position given by It, so that DPValues can be inserted there.
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...
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()
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.
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 DPMarker / DPValu...
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()
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.
DPMarker * getTrailingDPValues()
Fetch the collection of DPValues that "trail" after the last instruction of this block,...
BasicBlock * getSinglePredecessor()
void convertFromNewDbgValues()
Convert variable location debugging information stored in DPMarkers and DPValues 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.
DPMarker * createMarker(Instruction *I)
Attach a DPMarker to the given instruction.
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true)
void dumpDbgValues() const
bool validateDbgValues(bool Assert=true, bool Msg=false, raw_ostream *OS=nullptr)
Validate any DPMarkers / DPValues attached to instructions in this block, and block-level stored data...
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 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.
void setTrailingDPValues(DPMarker *M)
Record that the collection of DPValues in M "trails" after the last instruction of this block.
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()
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 reinsertInstInDPValues(Instruction *I, std::optional< DPValue::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.
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
void deleteTrailingDPValues()
Delete any trailing DPValues at the end of this block, see setTrailingDPValues.
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)
void insertDPValueAfter(DPValue *DPV, Instruction *I)
Insert a DPValue into a block at the position given by I.
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true)
DPMarker * getNextMarker(Instruction *I)
Return the DPMarker for the position that comes after I.
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 ...
SymbolTableList< Instruction, ilist_iterator_bits< true > > InstListType
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.
void insertDPValueBefore(DPValue *DPV, InstListType::iterator Here)
Insert a DPValue into a block at the position given by Here.
void flushTerminatorDbgValues()
Eject any debug-info trailing at the end of a block.
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.
Per-instruction record of debug-info.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
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.
iterator_range< simple_ilist< DPValue >::iterator > cloneDebugInfoFrom(const Instruction *From, std::optional< simple_ilist< DPValue >::iterator > FromHere=std::nullopt, bool InsertAtHead=false)
Clone any debug-info attached to From onto this instruction.
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.
Option to add extra bits to the ilist_iterator.