29 return F->getValueSymbolTable();
43 :
Value(
Type::getLabelTy(C),
Value::BasicBlockVal), Parent(nullptr) {
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) {
121 if (InstList.empty())
return nullptr;
126 if (InstList.empty())
129 if (!RI || RI == &InstList.front())
141 if (
auto *BI = dyn_cast<BitCastInst>(Prev)) {
144 if (!Prev || RV != Prev)
149 if (
auto *CI = dyn_cast<CallInst>(Prev)) {
150 if (CI->isMustTailCall())
157 if (InstList.empty())
160 if (!RI || RI == &InstList.front())
163 if (
auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
164 if (
Function *
F = CI->getCalledFunction())
165 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
173 if (!isa<PHINode>(I))
180 if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
187 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
190 if (
auto *II = dyn_cast<IntrinsicInst>(&I))
191 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
192 II->getIntrinsicID() == Intrinsic::lifetime_end)
206 if (InsertPt->isEHPad()) ++InsertPt;
219 if (PI ==
E)
return nullptr;
222 return (PI ==
E) ? ThePred :
nullptr ;
232 if (PI ==
E)
return nullptr;
235 for (;PI !=
E; ++PI) {
246 if (SI ==
E)
return nullptr;
249 return (SI ==
E) ? TheSucc :
nullptr ;
254 if (SI ==
E)
return nullptr;
257 for (;SI !=
E; ++
SI) {
277 bool DontDeleteUselessPHIs) {
280 "removePredecessor: BB is not a predecessor!");
282 if (InstList.empty())
return;
299 assert(max_idx != 0 &&
"PHI Node in block with 0 predecessors!?!?!");
304 if (
this == Other) max_idx = 3;
308 if (max_idx <= 2 && !DontDeleteUselessPHIs) {
312 PN->removeIncomingValue(Pred, !DontDeleteUselessPHIs);
316 if (PN->getIncomingValue(0) != PN)
317 PN->replaceAllUsesWith(PN->getIncomingValue(0));
336 Value* PNV =
nullptr;
348 if (isa<LandingPadInst>(FirstNonPHI))
365 assert(Term->getNumSuccessors() > 0);
368 return !Term->isExceptional();
384 assert(I != InstList.end() &&
385 "Trying to get me to create degenerate basic block!");
409 for (
auto &PN : Successor->
phis()) {
410 int Idx = PN.getBasicBlockIndex(
this);
412 PN.setIncomingBlock((
unsigned)Idx, New);
413 Idx = PN.getBasicBlockIndex(
this);
429 for (
iterator II = Succ->begin(),
IE = Succ->end(); II !=
IE; ++II) {
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
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.
void dropAllReferences()
Drop all references to operands.
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
iterator erase(iterator where)
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. ...
This class represents a function call, abstracting a target machine's calling convention.
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling .experimental.deoptimize prior to the terminating return instruc...
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
iterator begin()
Instruction iterator methods.
The address of a basic block.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
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...
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool canSplitPredecessors() const
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Interval::succ_iterator succ_end(Interval *I)
void replaceSuccessorsPhiUsesWith(BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of to it...
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Subclasses of this class are all able to terminate a basic block.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
LLVM Basic Block Representation.
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
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...
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
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)
const InstListType & getInstList() const
Return the underlying instruction list container.
Value * getOperand(unsigned i) const
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()
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
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...
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
void setIncomingBlock(unsigned i, BasicBlock *BB)
Type * getType() const
All values are typed, get the type of this value.
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)
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
A range adaptor for a pair of iterators.
void push_back(pointer val)
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
pointer remove(iterator &IT)
iterator insert(iterator where, pointer New)
static IntegerType * getInt32Ty(LLVMContext &C)
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.
bool isLandingPad() const
Return true if this basic block is a landing pad.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void destroyConstant()
Called if some element of this constant is no longer valid.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVMContext & getContext() const
Get the context in which this basic block lives.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Instruction * getFirstNonPHIOrDbgOrLifetime() const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic...
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
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...