30#define DEBUG_TYPE "ir"
31STATISTIC(NumInstrRenumberings,
"Number of renumberings across all blocks");
35 return I->DebugMarker;
38 I->DebugMarker = Marker;
44 return createMarker(&*It);
49 setTrailingDbgRecords(
DM);
64 DVI->eraseFromParent();
71 DLI->eraseFromParent();
75 if (DbgVarRecs.
empty())
95 for (
auto &Inst : *
this) {
96 if (!Inst.DebugMarker)
101 InstList.insert(Inst.getIterator(),
102 DR.createDebugIntrinsic(getModule(),
nullptr));
110 assert(!getTrailingDbgRecords());
115 for (
auto &Inst : *
this) {
116 if (!Inst.DebugMarker)
119 dbgs() <<
"@ " << Inst.DebugMarker <<
" ";
120 Inst.DebugMarker->dump();
127 return F->getValueSymbolTable();
132 return getType()->getContext();
146 : Value(Type::getLabelTy(
C), Value::BasicBlockVal), Parent(nullptr) {
149 insertInto(NewParent, InsertBefore);
152 "Cannot insert block before another block with no function!");
154 end().getNodePtr()->setParent(
this);
159 assert(NewParent &&
"Expected a parent");
160 assert(!Parent &&
"Already has a parent");
165 NewParent->
insert(NewParent->
end(),
this);
169 validateInstrOrdering();
177 if (hasAddressTaken()) {
186 assert(
getParent() ==
nullptr &&
"BasicBlock still linked into the program!");
188 for (
auto &Inst : *
this) {
189 if (!Inst.DebugMarker)
191 Inst.DebugMarker->eraseFromParent();
196void BasicBlock::setParent(
Function *parent) {
198 if (Parent != parent)
199 Number = parent ? parent->NextBlockNum++ : -1u;
200 InstList.setSymTabObject(&Parent, parent);
204 getParent()->getBasicBlockList().remove(getIterator());
208 return getParent()->getBasicBlockList().erase(getIterator());
225 return getModule()->getDataLayout();
229 if (InstList.empty())
232 if (!RI || RI == &InstList.front())
245 RV = BI->getOperand(0);
247 if (!Prev || RV != Prev)
253 if (CI->isMustTailCall())
260 if (InstList.empty())
263 if (!RI || RI == &InstList.front())
267 if (
Function *
F = CI->getCalledFunction())
268 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
279 if (!Visited.
insert(Succ).second)
287 if (InstList.empty())
295const Instruction* BasicBlock::getFirstNonPHI()
const {
349 if (
I.isLifetimeStartOrEnd())
367 if (InsertPt ==
end())
370 if (InsertPt->isEHPad()) ++InsertPt;
374 InsertPt.setHeadBit(
true);
380 if (InsertPt ==
end())
383 if (InsertPt->isEHPad())
386 if (isEntryBlock()) {
388 while (InsertPt != End &&
392 if (!AI->isStaticAlloca())
400 InsertPt.setHeadBit(
false);
406 I.dropAllReferences();
411 if (PI ==
E)
return nullptr;
414 return (PI ==
E) ? ThePred :
nullptr ;
419 if (PI ==
E)
return nullptr;
422 for (;PI !=
E; ++PI) {
441 if (
SI ==
E)
return nullptr;
444 return (
SI ==
E) ? TheSucc :
nullptr ;
449 if (
SI ==
E)
return nullptr;
452 for (;
SI !=
E; ++
SI) {
467 bool KeepOneInputPHIs) {
470 "Pred is not a predecessor!");
478 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
479 if (KeepOneInputPHIs)
488 if (Value *PhiConstant =
Phi.hasConstantValue()) {
489 Phi.replaceAllUsesWith(PhiConstant);
490 Phi.eraseFromParent();
502 if (FirstNonPHI->isEHPad())
518 return !
Term->isSpecialTerminator();
523 assert(
F &&
"Block must have a parent function to use this API");
524 return this == &
F->getEntryBlock();
530 "Trying to get me to create degenerate basic block!");
538 Loc = Loc->getWithoutAtom();
546 BI->setDebugLoc(Loc);
553 New->replaceSuccessorsPhiUsesWith(
this, New);
559 "Can't use splitBasicBlockBefore on degenerate BB!");
561 "Trying to get me to create degenerate basic block!");
564 "cannot split on multi incoming phis");
570 Loc = Loc->getWithoutAtom();
587 this->replacePhiUsesWith(Pred, New);
591 BI->setDebugLoc(Loc);
622 Succ->replacePhiUsesWith(Old, New);
626 this->replaceSuccessorsPhiUsesWith(
this, New);
639 if (
MDNode *MDIrrLoopHeader =
642 if (MDName->
getString() ==
"loop_header_weight") {
644 return std::optional<uint64_t>(CI->getValue().getZExtValue());
662 SubclassOptionalData |= InstrOrderValid;
664 NumInstrRenumberings++;
683 DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
684 if (!TrailingDbgRecords)
689 Term->DebugMarker->absorbDebugValues(*TrailingDbgRecords,
false);
691 deleteTrailingDbgRecords();
714 bool InsertAtHead = Dest.getHeadBit();
715 bool ReadFromHead =
First.getHeadBit();
722 DbgMarker *SrcTrailingDbgRecords = Src->getTrailingDbgRecords();
723 if (!SrcTrailingDbgRecords)
726 Dest->adoptDbgRecords(Src, Src->end(), InsertAtHead);
728 assert(!Src->getTrailingDbgRecords());
735 if (Src->empty() ||
First != Src->begin() || !ReadFromHead)
739 if (!
First->hasDbgRecords())
742 createMarker(Dest)->absorbDebugValues(*
First->DebugMarker, InsertAtHead);
782 DbgMarker *MoreDanglingDbgRecords =
nullptr;
783 DbgMarker *OurTrailingDbgRecords = getTrailingDbgRecords();
784 if (Dest ==
end() && !Dest.getHeadBit() && OurTrailingDbgRecords) {
787 if (!
First.getHeadBit() &&
First->hasDbgRecords()) {
788 MoreDanglingDbgRecords = Src->getMarker(
First);
792 if (
First->hasDbgRecords()) {
800 First->adoptDbgRecords(
this,
end(),
true);
808 deleteTrailingDbgRecords();
809 First.setHeadBit(
true);
813 spliceDebugInfoImpl(Dest, Src,
First,
Last);
817 if (!MoreDanglingDbgRecords)
833 bool InsertAtHead = Dest.getHeadBit();
834 bool ReadFromHead =
First.getHeadBit();
837 bool ReadFromTail = !
Last.getTailBit();
838 bool LastIsEnd = (
Last == Src->end());
904 if ((DestMarker = getMarker(Dest))) {
906 assert(DestMarker == getTrailingDbgRecords());
907 deleteTrailingDbgRecords();
915 if (ReadFromTail && Src->getMarker(
Last)) {
920 assert(FromLast == Src->getTrailingDbgRecords());
921 createMarker(Dest)->absorbDebugValues(*FromLast,
true);
923 Src->deleteTrailingDbgRecords();
926 Dest->adoptDbgRecords(Src,
Last,
true);
928 assert(!Src->getTrailingDbgRecords());
931 DbgMarker *OntoDest = createMarker(Dest);
939 if (!ReadFromHead &&
First->hasDbgRecords()) {
940 if (
Last != Src->end()) {
955 DbgMarker *NewDestMarker = createMarker(Dest);
973#ifdef EXPENSIVE_CHECKS
975 auto FromBBEnd = Src->end();
977 assert(It != FromBBEnd &&
"FromBeginIt not before FromEndIt!");
983 spliceDebugInfoEmptyBlock(Dest, Src,
First,
Last);
990 getInstList().splice(Dest, Src->getInstList(),
First,
Last);
992 flushTerminatorDbgRecords();
996 assert(
I->getParent() ==
this);
998 iterator NextIt = std::next(
I->getIterator());
999 DbgMarker *NextMarker = createMarker(NextIt);
1004 InstListType::iterator Where) {
1005 assert(Where ==
end() || Where->getParent() ==
this);
1006 bool InsertAtHead = Where.getHeadBit();
1008 M->insertDbgRecord(DR, InsertAtHead);
1012 return getMarker(std::next(
I->getIterator()));
1020 return It->DebugMarker;
1024 Instruction *
I, std::optional<DbgRecord::self_iterator> Pos) {
1081 if (!isInstrOrderValid())
1086 "cached instruction ordering is incorrect");
1093 getContext().pImpl->setTrailingDbgRecords(
this, foo);
1097 return getContext().pImpl->getTrailingDbgRecords(
this);
1101 getContext().pImpl->deleteTrailingDbgRecords(
this);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
VarLocInsertPt getNextNode(const DbgRecord *DVR)
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Machine Check Debug Module
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
StandardInstrumentations SI(Mod->getContext(), Debug, VerifyEach)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static SymbolRef::Type getType(const Symbol *Sym)
an instruction to allocate memory on the stack
LLVM Basic Block Representation.
LLVM_ABI BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
LLVM_ABI 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...
LLVM_ABI 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.
LLVM_ABI const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM_ABI void setTrailingDbgRecords(DbgMarker *M)
Record that the collection of DbgRecords in M "trails" after the last instruction of this block.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI void renumberInstructions()
Renumber instructions and mark the ordering as valid.
LLVM_ABI DbgMarker * createMarker(Instruction *I)
Attach a DbgMarker to the given instruction.
LLVM_ABI 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...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
LLVM_ABI void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
friend void Instruction::removeFromParent()
LLVM_ABI void convertToNewDbgValues()
Convert variable location debugging information stored in dbg.value intrinsics into DbgMarkers / DbgR...
InstListType::const_iterator const_iterator
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
friend BasicBlock::iterator Instruction::eraseFromParent()
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
LLVM_ABI ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
LLVM_ABI void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
LLVM_ABI bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
LLVM_ABI void convertFromNewDbgValues()
Convert variable location debugging information stored in DbgMarkers and DbgRecords into the dbg....
LLVM_ABI const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
LLVM_ABI const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM_ABI std::optional< uint64_t > getIrrLoopHeaderWeight() const
LLVM_ABI void dumpDbgValues() const
LLVM_ABI const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
LLVM_ABI 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.
LLVM_ABI const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
LLVM_ABI const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
LLVM_ABI void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
LLVM_ABI void insertDbgRecordAfter(DbgRecord *DR, Instruction *I)
Insert a DbgRecord into a block at the position given by I.
LLVM_ABI_FOR_TEST void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
LLVM_ABI DbgMarker * getMarker(InstListType::iterator It)
Return the DbgMarker for the position given by It, so that DbgRecords can be inserted there.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVM_ABI const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
LLVM_ABI void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
LLVM_ABI 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 ...
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
LLVM_ABI bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_ABI DbgMarker * getTrailingDbgRecords()
Fetch the collection of DbgRecords that "trail" after the last instruction of this block,...
LLVM_ABI bool canSplitPredecessors() const
LLVM_ABI 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)
LLVM_ABI bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
LLVM_ABI bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
LLVM_ABI const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
LLVM_ABI DbgMarker * getNextMarker(Instruction *I)
Return the DbgMarker for the position that comes after I.
LLVM_ABI 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.
LLVM_ABI const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
The address of a basic block.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
LLVM_ABI void destroyConstant()
Called if some element of this constant is no longer valid.
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.label instruction.
Records a position in IR for a source label (DILabel).
Per-instruction record of debug-info.
LLVM_ABI void removeFromParent()
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
LLVM_ABI void eraseFromParent()
LLVM_ABI iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange()
Produce a range over all the DbgRecords in this Marker.
LLVM_ABI void insertDbgRecord(DbgRecord *New, bool InsertAtHead)
Insert a DbgRecord into this DbgMarker, at the end of the list.
simple_ilist< DbgRecord > StoredDbgRecords
List of DbgRecords, the non-instruction equivalent of llvm.dbg.
LLVM_ABI void absorbDebugValues(DbgMarker &Src, bool InsertAtHead)
Transfer any DbgRecords from Src into this DbgMarker.
Base class for non-instruction debug metadata records that have positions within IR.
This is the common base class for debug info intrinsics for variables.
Record of a variable value-assignment, aka a non instruction representation of the dbg....
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
LLVM_ABI void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
LLVM_ABI bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
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...
LLVM_ABI StringRef getString() const
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
Return a value (possibly void), from a function.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Unconditional Branch instruction.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
This class provides a symbol table of name/value pairs.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
self_iterator getIterator()
typename base_list_type::iterator iterator
A range adaptor for a pair of iterators.
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
NodeAddr< PhiNode * > Phi
Context & getContext() const
LLVM_ABI iterator begin() const
LLVM_ABI Instruction * getTerminator() const
LLVM_ABI Instruction & front() const
This is an optimization pass for GlobalISel generic memory operations.
auto pred_end(const MachineBasicBlock *BB)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
PredIterator< const BasicBlock, Value::const_user_iterator > const_pred_iterator
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
auto dyn_cast_or_null(const Y &Val)
LLVM_ABI BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
RNSuccIterator< NodeRef, BlockT, RegionT > succ_begin(NodeRef Node)
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
RNSuccIterator< NodeRef, BlockT, RegionT > succ_end(NodeRef Node)
void invalidateParentIListOrdering(ParentClass *Parent)
Notify basic blocks when an instruction is inserted.
auto pred_begin(const MachineBasicBlock *BB)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Instruction::const_succ_iterator const_succ_iterator
Option to add extra bits to the ilist_iterator.
Option to add a pointer to this list's owner in every node.