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())
96 for (
auto &Inst : *
this) {
97 if (!Inst.DebugMarker)
102 InstList.insert(Inst.getIterator(),
103 DR.createDebugIntrinsic(getModule(),
nullptr));
112 assert(!getTrailingDbgRecords());
118 for (
auto &Inst : *
this) {
119 if (!Inst.DebugMarker)
122 dbgs() <<
"@ " << Inst.DebugMarker <<
" ";
123 Inst.DebugMarker->dump();
130 return F->getValueSymbolTable();
135 return getType()->getContext();
149 : Value(Type::getLabelTy(
C), Value::BasicBlockVal), Parent(nullptr) {
152 insertInto(NewParent, InsertBefore);
155 "Cannot insert block before another block with no function!");
157 end().getNodePtr()->setParent(
this);
162 assert(NewParent &&
"Expected a parent");
163 assert(!Parent &&
"Already has a parent");
168 NewParent->
insert(NewParent->
end(),
this);
172 validateInstrOrdering();
180 if (hasAddressTaken()) {
189 assert(
getParent() ==
nullptr &&
"BasicBlock still linked into the program!");
191 for (
auto &Inst : *
this) {
192 if (!Inst.DebugMarker)
194 Inst.DebugMarker->eraseFromParent();
199void BasicBlock::setParent(
Function *parent) {
201 if (Parent != parent)
202 Number = parent ? parent->NextBlockNum++ : -1u;
203 InstList.setSymTabObject(&Parent, parent);
207 getParent()->getBasicBlockList().remove(getIterator());
211 return getParent()->getBasicBlockList().erase(getIterator());
228 return getModule()->getDataLayout();
232 if (InstList.empty())
235 if (!RI || RI == &InstList.front())
248 if (CI->isMustTailCall())
255 if (InstList.empty())
258 if (!RI || RI == &InstList.front())
262 if (
Function *
F = CI->getCalledFunction())
263 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
274 if (!Visited.
insert(Succ).second)
282 if (InstList.empty())
330 if (
I.isLifetimeStartOrEnd())
348 if (InsertPt ==
end())
351 if (InsertPt->isEHPad()) ++InsertPt;
355 InsertPt.setHeadBit(
true);
361 if (InsertPt ==
end())
364 if (InsertPt->isEHPad())
367 if (isEntryBlock()) {
369 while (InsertPt != End &&
373 if (!AI->isStaticAlloca())
381 InsertPt.setHeadBit(
false);
387 I.dropAllReferences();
392 if (PI ==
E)
return nullptr;
395 return (PI ==
E) ? ThePred :
nullptr ;
400 if (PI ==
E)
return nullptr;
403 for (;PI !=
E; ++PI) {
422 if (
SI ==
E)
return nullptr;
425 return (
SI ==
E) ? TheSucc :
nullptr ;
430 if (
SI ==
E)
return nullptr;
433 for (;
SI !=
E; ++
SI) {
448 bool KeepOneInputPHIs) {
451 "Pred is not a predecessor!");
459 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
460 if (KeepOneInputPHIs)
469 if (Value *PhiConstant =
Phi.hasConstantValue()) {
470 Phi.replaceAllUsesWith(PhiConstant);
471 Phi.eraseFromParent();
483 if (FirstNonPHI->isEHPad())
499 return !
Term->isSpecialTerminator();
504 assert(
F &&
"Block must have a parent function to use this API");
505 return this == &
F->getEntryBlock();
511 "Trying to get me to create degenerate basic block!");
519 Loc = Loc->getWithoutAtom();
534 New->replaceSuccessorsPhiUsesWith(
this, New);
540 "Can't use splitBasicBlockBefore on degenerate BB!");
542 "Trying to get me to create degenerate basic block!");
545 "cannot split on multi incoming phis");
551 Loc = Loc->getWithoutAtom();
568 this->replacePhiUsesWith(Pred, New);
603 Succ->replacePhiUsesWith(Old, New);
607 this->replaceSuccessorsPhiUsesWith(
this, New);
620 if (
MDNode *MDIrrLoopHeader =
623 if (MDName->
getString() ==
"loop_header_weight") {
625 return std::optional<uint64_t>(CI->getValue().getZExtValue());
643 SubclassOptionalData |= InstrOrderValid;
645 NumInstrRenumberings++;
664 DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
665 if (!TrailingDbgRecords)
670 Term->DebugMarker->absorbDebugValues(*TrailingDbgRecords,
false);
672 deleteTrailingDbgRecords();
695 bool InsertAtHead = Dest.getHeadBit();
696 bool ReadFromHead =
First.getHeadBit();
703 DbgMarker *SrcTrailingDbgRecords = Src->getTrailingDbgRecords();
704 if (!SrcTrailingDbgRecords)
707 Dest->adoptDbgRecords(Src, Src->end(), InsertAtHead);
709 assert(!Src->getTrailingDbgRecords());
716 if (Src->empty() ||
First != Src->begin() || !ReadFromHead)
720 if (!
First->hasDbgRecords())
723 createMarker(Dest)->absorbDebugValues(*
First->DebugMarker, InsertAtHead);
763 DbgMarker *MoreDanglingDbgRecords =
nullptr;
764 DbgMarker *OurTrailingDbgRecords = getTrailingDbgRecords();
765 if (Dest ==
end() && !Dest.getHeadBit() && OurTrailingDbgRecords) {
768 if (!
First.getHeadBit() &&
First->hasDbgRecords()) {
769 MoreDanglingDbgRecords = Src->getMarker(
First);
773 if (
First->hasDbgRecords()) {
781 First->adoptDbgRecords(
this,
end(),
true);
789 deleteTrailingDbgRecords();
790 First.setHeadBit(
true);
794 spliceDebugInfoImpl(Dest, Src,
First,
Last);
798 if (!MoreDanglingDbgRecords)
814 bool InsertAtHead = Dest.getHeadBit();
815 bool ReadFromHead =
First.getHeadBit();
818 bool ReadFromTail = !
Last.getTailBit();
819 bool LastIsEnd = (
Last == Src->end());
885 if ((DestMarker = getMarker(Dest))) {
887 assert(DestMarker == getTrailingDbgRecords());
888 deleteTrailingDbgRecords();
896 if (ReadFromTail && Src->getMarker(
Last)) {
901 assert(FromLast == Src->getTrailingDbgRecords());
902 createMarker(Dest)->absorbDebugValues(*FromLast,
true);
904 Src->deleteTrailingDbgRecords();
907 Dest->adoptDbgRecords(Src,
Last,
true);
909 assert(!Src->getTrailingDbgRecords());
912 DbgMarker *OntoDest = createMarker(Dest);
920 if (!ReadFromHead &&
First->hasDbgRecords()) {
921 if (
Last != Src->end()) {
936 DbgMarker *NewDestMarker = createMarker(Dest);
954#ifdef EXPENSIVE_CHECKS
956 auto FromBBEnd = Src->end();
958 assert(It != FromBBEnd &&
"FromBeginIt not before FromEndIt!");
964 spliceDebugInfoEmptyBlock(Dest, Src,
First,
Last);
971 getInstList().splice(Dest, Src->getInstList(),
First,
Last);
973 flushTerminatorDbgRecords();
977 assert(
I->getParent() ==
this);
979 iterator NextIt = std::next(
I->getIterator());
980 DbgMarker *NextMarker = createMarker(NextIt);
985 InstListType::iterator Where) {
986 assert(Where ==
end() || Where->getParent() ==
this);
987 bool InsertAtHead = Where.getHeadBit();
989 M->insertDbgRecord(DR, InsertAtHead);
993 return getMarker(std::next(
I->getIterator()));
1001 return It->DebugMarker;
1005 Instruction *
I, std::optional<DbgRecord::self_iterator> Pos) {
1062 if (!isInstrOrderValid())
1067 "cached instruction ordering is incorrect");
1074 getContext().pImpl->setTrailingDbgRecords(
this, foo);
1078 return getContext().pImpl->getTrailingDbgRecords(
this);
1082 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)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
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 bool 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 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...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
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
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.