Go to the documentation of this file.
26 #define DEBUG_TYPE "ir"
27 STATISTIC(NumInstrRenumberings,
"Number of renumberings across all blocks");
31 return F->getValueSymbolTable();
40 BB->invalidateOrders();
52 insertInto(NewParent, InsertBefore);
55 "Cannot insert block before another block with no function!");
61 assert(NewParent &&
"Expected a parent");
62 assert(!Parent &&
"Already has a parent");
91 assert(
getParent() ==
nullptr &&
"BasicBlock still linked into the program!");
96 void BasicBlock::setParent(
Function *parent) {
98 InstList.setSymTabObject(&Parent, parent);
105 return !isa<DbgInfoIntrinsic>(
I) &&
106 !(SkipPseudoOp && isa<PseudoProbeInst>(
I));
115 return !isa<DbgInfoIntrinsic>(
I) &&
116 !(SkipPseudoOp && isa<PseudoProbeInst>(
I));
152 if (InstList.empty())
154 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
155 if (!RI || RI == &InstList.front())
167 if (
auto *BI = dyn_cast<BitCastInst>(Prev)) {
170 if (!Prev || RV != Prev)
175 if (
auto *CI = dyn_cast<CallInst>(Prev)) {
176 if (CI->isMustTailCall())
183 if (InstList.empty())
185 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
186 if (!RI || RI == &InstList.front())
189 if (
auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
190 if (
Function *
F = CI->getCalledFunction())
191 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
201 while (
auto *Succ =
BB->getUniqueSuccessor()) {
202 if (!Visited.
insert(Succ).second)
206 return BB->getTerminatingDeoptimizeCall();
211 if (!isa<PHINode>(
I))
218 if (isa<PHINode>(
I) || isa<DbgInfoIntrinsic>(
I))
221 if (SkipPseudoOp && isa<PseudoProbeInst>(
I))
232 if (isa<PHINode>(
I) || isa<DbgInfoIntrinsic>(
I))
235 if (
I.isLifetimeStartOrEnd())
238 if (SkipPseudoOp && isa<PseudoProbeInst>(
I))
252 if (InsertPt->isEHPad()) ++InsertPt;
258 I.dropAllReferences();
263 if (PI ==
E)
return nullptr;
266 return (PI ==
E) ? ThePred :
nullptr ;
271 if (PI ==
E)
return nullptr;
274 for (;PI !=
E; ++PI) {
293 if (
SI ==
E)
return nullptr;
296 return (
SI ==
E) ? TheSucc :
nullptr ;
301 if (
SI ==
E)
return nullptr;
304 for (;
SI !=
E; ++
SI) {
315 return make_range<phi_iterator>(
P,
nullptr);
319 bool KeepOneInputPHIs) {
322 "Pred is not a predecessor!");
328 unsigned NumPreds = cast<PHINode>(
front()).getNumIncomingValues();
330 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
331 if (KeepOneInputPHIs)
340 if (
Value *PhiConstant = Phi.hasConstantValue()) {
341 Phi.replaceAllUsesWith(PhiConstant);
342 Phi.eraseFromParent();
349 if (isa<LandingPadInst>(FirstNonPHI))
369 return !
Term->isExceptionalTerminator();
374 assert(
F &&
"Block must have a parent function to use this API");
375 return this == &
F->getEntryBlock();
385 "Trying to get me to create degenerate basic block!");
394 New->getInstList().splice(New->end(),
this->getInstList(),
I,
end());
405 New->replaceSuccessorsPhiUsesWith(
this, New);
411 "Can't use splitBasicBlockBefore on degenerate BB!");
413 "Trying to get me to create degenerate basic block!");
416 "cannot split on multi incoming phis");
423 New->getInstList().splice(New->end(),
this->getInstList(),
begin(),
I);
447 PHINode *PN = dyn_cast<PHINode>(&
I);
462 Succ->replacePhiUsesWith(Old, New);
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))
502 BasicBlockBits
Bits = getBasicBlockBits();
503 Bits.InstrOrderValid =
true;
504 setBasicBlockBits(
Bits);
506 NumInstrRenumberings++;
518 "cached instruction ordering is incorrect");
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
This is an optimization pass for GlobalISel generic memory operations.
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
Return a value (possibly void), from a function.
InstListType::iterator iterator
Instruction iterators...
const Function * getParent() const
Return the enclosing method, or null if none.
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.
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Interval::succ_iterator succ_end(Interval *I)
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
The landingpad instruction holds all of the information necessary to generate correct exception handl...
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.
The instances of the Type class are immutable: once they are created, they are never changed.
Specialization of filter_iterator_base for forward iteration only.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
auto successors(MachineBasicBlock *BB)
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
bool canSplitPredecessors() const
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...
static IntegerType * getInt32Ty(LLVMContext &C)
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
void invalidateParentIListOrdering(ParentClass *Parent)
Notify basic blocks when an instruction is inserted.
LLVM Basic Block Representation.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
(vector float) vec_cmpeq(*A, *B) C
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
iterator begin()
Instruction iterator methods.
bool isLandingPad() const
Return true if this basic block is a landing pad.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
STATISTIC(NumFunctions, "Total number of functions")
auto predecessors(MachineBasicBlock *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.
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.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
This is an important base class in LLVM.
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
Module * getParent()
Get the module that this global value is contained inside of...
This is an important class for using LLVM in a threaded context.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
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...
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...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StandardInstrumentations SI(Debug, VerifyEach)
print Print MemDeps of function
A Module instance is used to store all the information related to an LLVM module.
The address of a basic block.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
Analysis the ScalarEvolution expression for r is this
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.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
self_iterator getIterator()
void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
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...
const Instruction & front() const
LLVMContext & getContext() const
Get the context in which this basic block lives.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Iterator for intrusive lists based on ilist_node.
Interval::pred_iterator pred_end(Interval *I)
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const Instruction * getFirstNonPHIOrDbgOrLifetime(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic,...
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...
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
This class provides a symbol table of name/value pairs.
A range adaptor for a pair of iterators.
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
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...
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Optional< uint64_t > getIrrLoopHeaderWeight() const
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
This class represents a function call, abstracting a target machine's calling convention.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Value * getOperand(unsigned i) const
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
StringRef getString() const
Conditional or Unconditional Branch instruction.
LLVM Value Representation.
void destroyConstant()
Called if some element of this constant is no longer valid.
InstListType::const_iterator const_iterator
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.