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);
111 std::function<bool(const Instruction &)>>::difference_type
145 if (InstList.empty() || !InstList.back().isTerminator())
147 return &InstList.back();
151 if (InstList.empty())
154 if (!RI || RI == &InstList.front())
166 if (
auto *BI = dyn_cast<BitCastInst>(Prev)) {
169 if (!Prev || RV != Prev)
174 if (
auto *CI = dyn_cast<CallInst>(Prev)) {
175 if (CI->isMustTailCall())
182 if (InstList.empty())
185 if (!RI || RI == &InstList.front())
188 if (
auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
189 if (
Function *
F = CI->getCalledFunction())
190 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
198 if (!isa<PHINode>(I))
205 if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
212 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
229 if (InsertPt->isEHPad()) ++InsertPt;
242 if (PI ==
E)
return nullptr;
245 return (PI ==
E) ? ThePred :
nullptr ;
255 if (PI ==
E)
return nullptr;
258 for (;PI !=
E; ++PI) {
277 if (SI ==
E)
return nullptr;
280 return (SI ==
E) ? TheSucc :
nullptr ;
285 if (SI ==
E)
return nullptr;
288 for (;SI !=
E; ++
SI) {
299 return make_range<phi_iterator>(
P,
nullptr);
309 bool KeepOneInputPHIs) {
312 "removePredecessor: BB is not a predecessor!");
314 if (InstList.empty())
return;
331 assert(max_idx != 0 &&
"PHI Node in block with 0 predecessors!?!?!");
336 if (
this == Other) max_idx = 3;
340 if (max_idx <= 2 && !KeepOneInputPHIs) {
344 PN->removeIncomingValue(Pred, !KeepOneInputPHIs);
348 if (PN->getIncomingValue(0) != PN)
349 PN->replaceAllUsesWith(PN->getIncomingValue(0));
368 Value* PNV =
nullptr;
380 if (isa<LandingPadInst>(FirstNonPHI))
397 assert(Term->getNumSuccessors() > 0);
400 return !Term->isExceptionalTerminator();
416 assert(I != InstList.end() &&
417 "Trying to get me to create degenerate basic block!");
437 New->replaceSuccessorsPhiUsesWith(
this, New);
481 if (
MDNode *MDIrrLoopHeader =
483 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
485 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
493 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.
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
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...
void setName(const Twine &Name)
Change the name of the value.
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...
filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
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
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...
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...
UnaryPredicate for_each(R &&Range, UnaryPredicate P)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly...
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.