29 return F->getValueSymbolTable();
49 "Cannot insert block before another block with no function!");
55 assert(NewParent &&
"Expected a parent");
56 assert(!Parent &&
"Already has a parent");
83 assert(
getParent() ==
nullptr &&
"BasicBlock still linked into the program!");
88 void BasicBlock::setParent(
Function *parent) {
94 std::function<bool(const Instruction &)>>>
96 std::function<bool(const Instruction &)> Fn = [](
const Instruction &
I) {
97 return !isa<DbgInfoIntrinsic>(
I);
103 std::function<bool(Instruction &)>>>
105 std::function<bool(Instruction &)> Fn = [](
Instruction &
I) {
106 return !isa<DbgInfoIntrinsic>(
I);
139 if (InstList.empty() || !InstList.back().isTerminator())
141 return &InstList.back();
145 if (InstList.empty())
148 if (!RI || RI == &InstList.front())
160 if (
auto *BI = dyn_cast<BitCastInst>(Prev)) {
163 if (!Prev || RV != Prev)
168 if (
auto *CI = dyn_cast<CallInst>(Prev)) {
169 if (CI->isMustTailCall())
176 if (InstList.empty())
179 if (!RI || RI == &InstList.front())
182 if (
auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
183 if (
Function *
F = CI->getCalledFunction())
192 if (!isa<PHINode>(I))
199 if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
206 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
223 if (InsertPt->isEHPad()) ++InsertPt;
236 if (PI ==
E)
return nullptr;
239 return (PI ==
E) ? ThePred :
nullptr ;
249 if (PI ==
E)
return nullptr;
252 for (;PI !=
E; ++PI) {
271 if (SI ==
E)
return nullptr;
274 return (SI ==
E) ? TheSucc :
nullptr ;
279 if (SI ==
E)
return nullptr;
282 for (;SI !=
E; ++
SI) {
293 return make_range<phi_iterator>(
P,
nullptr);
303 bool DontDeleteUselessPHIs) {
306 "removePredecessor: BB is not a predecessor!");
308 if (InstList.empty())
return;
325 assert(max_idx != 0 &&
"PHI Node in block with 0 predecessors!?!?!");
330 if (
this == Other) max_idx = 3;
334 if (max_idx <= 2 && !DontDeleteUselessPHIs) {
338 PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
342 if (PN->getIncomingValue(0) != PN)
343 PN->replaceAllUsesWith(PN->getIncomingValue(0));
362 Value* PNV =
nullptr;
374 if (isa<LandingPadInst>(FirstNonPHI))
391 assert(Term->getNumSuccessors() > 0);
394 return !Term->isExceptionalTerminator();
410 assert(I != InstList.end() &&
411 "Trying to get me to create degenerate basic block!");
435 for (
auto &PN : Successor->
phis()) {
436 int Idx = PN.getBasicBlockIndex(
this);
438 PN.setIncomingBlock((
unsigned)Idx, New);
439 Idx = PN.getBasicBlockIndex(
this);
455 for (
iterator II = Succ->begin(),
IE = Succ->end(); II !=
IE; ++II) {
479 if (
MDNode *MDIrrLoopHeader =
481 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
483 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
491 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.
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
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. ...
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...
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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 LLVM_ATTRIBUTE_ALWAYS_INLINE 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.