28 return F->getValueSymbolTable();
48 "Cannot insert block before another block with no function!");
54 assert(NewParent &&
"Expected a parent");
55 assert(!Parent &&
"Already has a parent");
82 assert(
getParent() ==
nullptr &&
"BasicBlock still linked into the program!");
87 void BasicBlock::setParent(
Function *parent) {
93 std::function<bool(const Instruction &)>>>
95 std::function<bool(const Instruction &)> Fn = [](
const Instruction &
I) {
96 return !isa<DbgInfoIntrinsic>(
I);
102 std::function<bool(Instruction &)>>>
104 std::function<bool(Instruction &)> Fn = [](
Instruction &
I) {
105 return !isa<DbgInfoIntrinsic>(
I);
138 if (InstList.empty() || !InstList.back().isTerminator())
140 return &InstList.back();
144 if (InstList.empty())
147 if (!RI || RI == &InstList.front())
159 if (
auto *BI = dyn_cast<BitCastInst>(Prev)) {
162 if (!Prev || RV != Prev)
167 if (
auto *CI = dyn_cast<CallInst>(Prev)) {
168 if (CI->isMustTailCall())
175 if (InstList.empty())
178 if (!RI || RI == &InstList.front())
181 if (
auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
182 if (
Function *
F = CI->getCalledFunction())
183 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
191 if (!isa<PHINode>(I))
198 if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
205 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
222 if (InsertPt->isEHPad()) ++InsertPt;
235 if (PI ==
E)
return nullptr;
238 return (PI ==
E) ? ThePred :
nullptr ;
248 if (PI ==
E)
return nullptr;
251 for (;PI !=
E; ++PI) {
270 if (SI ==
E)
return nullptr;
273 return (SI ==
E) ? TheSucc :
nullptr ;
278 if (SI ==
E)
return nullptr;
281 for (;SI !=
E; ++
SI) {
292 return make_range<phi_iterator>(
P,
nullptr);
302 bool KeepOneInputPHIs) {
305 "removePredecessor: BB is not a predecessor!");
307 if (InstList.empty())
return;
324 assert(max_idx != 0 &&
"PHI Node in block with 0 predecessors!?!?!");
329 if (
this == Other) max_idx = 3;
333 if (max_idx <= 2 && !KeepOneInputPHIs) {
337 PN->removeIncomingValue(Pred, !KeepOneInputPHIs);
341 if (PN->getIncomingValue(0) != PN)
342 PN->replaceAllUsesWith(PN->getIncomingValue(0));
361 Value* PNV =
nullptr;
373 if (isa<LandingPadInst>(FirstNonPHI))
390 assert(Term->getNumSuccessors() > 0);
393 return !Term->isExceptionalTerminator();
409 assert(I != InstList.end() &&
410 "Trying to get me to create degenerate basic block!");
434 for (
auto &PN : Successor->
phis()) {
435 int Idx = PN.getBasicBlockIndex(
this);
437 PN.setIncomingBlock((
unsigned)Idx, New);
438 Idx = PN.getBasicBlockIndex(
this);
454 for (
iterator II = Succ->begin(),
IE = Succ->end(); II !=
IE; ++II) {
478 if (
MDNode *MDIrrLoopHeader =
480 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
482 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
490 while (isa<DbgInfoIntrinsic>(It))
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
bool canSplitPredecessors() const
This class provides a symbol table of name/value pairs.
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
void dropAllReferences()
Drop all references to operands.
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
iterator erase(iterator where)
This class represents lattice values for constants.
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
void insertInto(Function *Parent, BasicBlock *InsertBefore=nullptr)
Insert unlinked basic block into a function.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
This class represents a function call, abstracting a target machine's calling convention.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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...
LLVMContext & getContext() const
Get the context in which this basic block lives.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
iterator begin()
Instruction iterator methods.
InstListType::const_iterator const_iterator
The address of a basic block.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void setName(const Twine &Name)
Change the name of the value.
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
const Instruction * getFirstNonPHIOrDbgOrLifetime() const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic...
static Type * getLabelTy(LLVMContext &C)
Type * getType() const
All values are typed, get the type of this value.
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.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Value * getOperand(unsigned i) const
Interval::succ_iterator succ_end(Interval *I)
StringRef getString() const
void replaceSuccessorsPhiUsesWith(BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of to it...
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug() const
Return a const iterator range over the instructions in the block, skipping any debug instructions...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
void setSymTabObject(TPtr *, TPtr)
setSymTabObject - This is called when (f.e.) the parent of a basic block changes. ...
void splice(iterator where, iplist_impl &L2)
Interval::pred_iterator pred_end(Interval *I)
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, typename std::enable_if< !std::is_same< typename std::iterator_traits< typename std::remove_reference< decltype(Begin)>::type >::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value(Type *Ty, unsigned scid)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool isLandingPad() const
Return true if this basic block is a landing pad.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
const InstListType & getInstList() const
Return the underlying instruction list container.
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
Iterator for intrusive lists based on ilist_node.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
void setIncomingBlock(unsigned i, BasicBlock *BB)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
unsigned getNumIncomingValues() const
Return the number of incoming edges.
A range adaptor for a pair of iterators.
void push_back(pointer val)
InstListType::iterator iterator
Instruction iterators...
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
pointer remove(iterator &IT)
iterator insert(iterator where, pointer New)
static IntegerType * getInt32Ty(LLVMContext &C)
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
Optional< uint64_t > getIrrLoopHeaderWeight() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
void destroyConstant()
Called if some element of this constant is no longer valid.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
succ_range successors(Instruction *I)
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, typename std::enable_if< !std::is_same< typename std::iterator_traits< typename std::remove_reference< decltype(Begin)>::type >::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Specialization of filter_iterator_base for forward iteration only.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.