LLVM  9.0.0svn
BasicBlock.cpp
Go to the documentation of this file.
1 //===-- BasicBlock.cpp - Implement BasicBlock related methods -------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the BasicBlock class for the IR library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/BasicBlock.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/IR/CFG.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/Instructions.h"
19 #include "llvm/IR/IntrinsicInst.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Type.h"
22 #include <algorithm>
23 
24 using namespace llvm;
25 
27  if (Function *F = getParent())
28  return F->getValueSymbolTable();
29  return nullptr;
30 }
31 
33  return getType()->getContext();
34 }
35 
36 // Explicit instantiation of SymbolTableListTraits since some of the methods
37 // are not in the public header file...
39 
41  BasicBlock *InsertBefore)
42  : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(nullptr) {
43 
44  if (NewParent)
45  insertInto(NewParent, InsertBefore);
46  else
47  assert(!InsertBefore &&
48  "Cannot insert block before another block with no function!");
49 
50  setName(Name);
51 }
52 
53 void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
54  assert(NewParent && "Expected a parent");
55  assert(!Parent && "Already has a parent");
56 
57  if (InsertBefore)
58  NewParent->getBasicBlockList().insert(InsertBefore->getIterator(), this);
59  else
60  NewParent->getBasicBlockList().push_back(this);
61 }
62 
64  // If the address of the block is taken and it is being deleted (e.g. because
65  // it is dead), this means that there is either a dangling constant expr
66  // hanging off the block, or an undefined use of the block (source code
67  // expecting the address of a label to keep the block alive even though there
68  // is no indirect branch). Handle these cases by zapping the BlockAddress
69  // nodes. There are no other possible uses at this point.
70  if (hasAddressTaken()) {
71  assert(!use_empty() && "There should be at least one blockaddress!");
72  Constant *Replacement =
74  while (!use_empty()) {
75  BlockAddress *BA = cast<BlockAddress>(user_back());
77  BA->getType()));
78  BA->destroyConstant();
79  }
80  }
81 
82  assert(getParent() == nullptr && "BasicBlock still linked into the program!");
84  InstList.clear();
85 }
86 
87 void BasicBlock::setParent(Function *parent) {
88  // Set Parent=parent, updating instruction symtab entries as appropriate.
89  InstList.setSymTabObject(&Parent, parent);
90 }
91 
93  std::function<bool(const Instruction &)>>>
95  std::function<bool(const Instruction &)> Fn = [](const Instruction &I) {
96  return !isa<DbgInfoIntrinsic>(I);
97  };
98  return make_filter_range(*this, Fn);
99 }
100 
102  std::function<bool(Instruction &)>>>
104  std::function<bool(Instruction &)> Fn = [](Instruction &I) {
105  return !isa<DbgInfoIntrinsic>(I);
106  };
107  return make_filter_range(*this, Fn);
108 }
109 
112 }
113 
116 }
117 
118 /// Unlink this basic block from its current function and
119 /// insert it into the function that MovePos lives in, right before MovePos.
121  MovePos->getParent()->getBasicBlockList().splice(
122  MovePos->getIterator(), getParent()->getBasicBlockList(), getIterator());
123 }
124 
125 /// Unlink this basic block from its current function and
126 /// insert it into the function that MovePos lives in, right after MovePos.
128  MovePos->getParent()->getBasicBlockList().splice(
129  ++MovePos->getIterator(), getParent()->getBasicBlockList(),
130  getIterator());
131 }
132 
134  return getParent()->getParent();
135 }
136 
138  if (InstList.empty() || !InstList.back().isTerminator())
139  return nullptr;
140  return &InstList.back();
141 }
142 
144  if (InstList.empty())
145  return nullptr;
146  const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
147  if (!RI || RI == &InstList.front())
148  return nullptr;
149 
150  const Instruction *Prev = RI->getPrevNode();
151  if (!Prev)
152  return nullptr;
153 
154  if (Value *RV = RI->getReturnValue()) {
155  if (RV != Prev)
156  return nullptr;
157 
158  // Look through the optional bitcast.
159  if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
160  RV = BI->getOperand(0);
161  Prev = BI->getPrevNode();
162  if (!Prev || RV != Prev)
163  return nullptr;
164  }
165  }
166 
167  if (auto *CI = dyn_cast<CallInst>(Prev)) {
168  if (CI->isMustTailCall())
169  return CI;
170  }
171  return nullptr;
172 }
173 
175  if (InstList.empty())
176  return nullptr;
177  auto *RI = dyn_cast<ReturnInst>(&InstList.back());
178  if (!RI || RI == &InstList.front())
179  return nullptr;
180 
181  if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
182  if (Function *F = CI->getCalledFunction())
183  if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
184  return CI;
185 
186  return nullptr;
187 }
188 
190  for (const Instruction &I : *this)
191  if (!isa<PHINode>(I))
192  return &I;
193  return nullptr;
194 }
195 
197  for (const Instruction &I : *this)
198  if (!isa<PHINode>(I) && !isa<DbgInfoIntrinsic>(I))
199  return &I;
200  return nullptr;
201 }
202 
204  for (const Instruction &I : *this) {
205  if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
206  continue;
207 
208  if (I.isLifetimeStartOrEnd())
209  continue;
210 
211  return &I;
212  }
213  return nullptr;
214 }
215 
217  const Instruction *FirstNonPHI = getFirstNonPHI();
218  if (!FirstNonPHI)
219  return end();
220 
221  const_iterator InsertPt = FirstNonPHI->getIterator();
222  if (InsertPt->isEHPad()) ++InsertPt;
223  return InsertPt;
224 }
225 
227  for (Instruction &I : *this)
228  I.dropAllReferences();
229 }
230 
231 /// If this basic block has a single predecessor block,
232 /// return the block, otherwise return a null pointer.
234  const_pred_iterator PI = pred_begin(this), E = pred_end(this);
235  if (PI == E) return nullptr; // No preds.
236  const BasicBlock *ThePred = *PI;
237  ++PI;
238  return (PI == E) ? ThePred : nullptr /*multiple preds*/;
239 }
240 
241 /// If this basic block has a unique predecessor block,
242 /// return the block, otherwise return a null pointer.
243 /// Note that unique predecessor doesn't mean single edge, there can be
244 /// multiple edges from the unique predecessor to this block (for example
245 /// a switch statement with multiple cases having the same destination).
247  const_pred_iterator PI = pred_begin(this), E = pred_end(this);
248  if (PI == E) return nullptr; // No preds.
249  const BasicBlock *PredBB = *PI;
250  ++PI;
251  for (;PI != E; ++PI) {
252  if (*PI != PredBB)
253  return nullptr;
254  // The same predecessor appears multiple times in the predecessor list.
255  // This is OK.
256  }
257  return PredBB;
258 }
259 
260 bool BasicBlock::hasNPredecessors(unsigned N) const {
261  return hasNItems(pred_begin(this), pred_end(this), N);
262 }
263 
264 bool BasicBlock::hasNPredecessorsOrMore(unsigned N) const {
265  return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
266 }
267 
269  succ_const_iterator SI = succ_begin(this), E = succ_end(this);
270  if (SI == E) return nullptr; // no successors
271  const BasicBlock *TheSucc = *SI;
272  ++SI;
273  return (SI == E) ? TheSucc : nullptr /* multiple successors */;
274 }
275 
277  succ_const_iterator SI = succ_begin(this), E = succ_end(this);
278  if (SI == E) return nullptr; // No successors
279  const BasicBlock *SuccBB = *SI;
280  ++SI;
281  for (;SI != E; ++SI) {
282  if (*SI != SuccBB)
283  return nullptr;
284  // The same successor appears multiple times in the successor list.
285  // This is OK.
286  }
287  return SuccBB;
288 }
289 
291  PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
292  return make_range<phi_iterator>(P, nullptr);
293 }
294 
295 /// This method is used to notify a BasicBlock that the
296 /// specified Predecessor of the block is no longer able to reach it. This is
297 /// actually not used to update the Predecessor list, but is actually used to
298 /// update the PHI nodes that reside in the block. Note that this should be
299 /// called while the predecessor still refers to this block.
300 ///
302  bool KeepOneInputPHIs) {
303  assert((hasNUsesOrMore(16)||// Reduce cost of this assertion for complex CFGs.
304  find(pred_begin(this), pred_end(this), Pred) != pred_end(this)) &&
305  "removePredecessor: BB is not a predecessor!");
306 
307  if (InstList.empty()) return;
308  PHINode *APN = dyn_cast<PHINode>(&front());
309  if (!APN) return; // Quick exit.
310 
311  // If there are exactly two predecessors, then we want to nuke the PHI nodes
312  // altogether. However, we cannot do this, if this in this case:
313  //
314  // Loop:
315  // %x = phi [X, Loop]
316  // %x2 = add %x, 1 ;; This would become %x2 = add %x2, 1
317  // br Loop ;; %x2 does not dominate all uses
318  //
319  // This is because the PHI node input is actually taken from the predecessor
320  // basic block. The only case this can happen is with a self loop, so we
321  // check for this case explicitly now.
322  //
323  unsigned max_idx = APN->getNumIncomingValues();
324  assert(max_idx != 0 && "PHI Node in block with 0 predecessors!?!?!");
325  if (max_idx == 2) {
326  BasicBlock *Other = APN->getIncomingBlock(APN->getIncomingBlock(0) == Pred);
327 
328  // Disable PHI elimination!
329  if (this == Other) max_idx = 3;
330  }
331 
332  // <= Two predecessors BEFORE I remove one?
333  if (max_idx <= 2 && !KeepOneInputPHIs) {
334  // Yup, loop through and nuke the PHI nodes
335  while (PHINode *PN = dyn_cast<PHINode>(&front())) {
336  // Remove the predecessor first.
337  PN->removeIncomingValue(Pred, !KeepOneInputPHIs);
338 
339  // If the PHI _HAD_ two uses, replace PHI node with its now *single* value
340  if (max_idx == 2) {
341  if (PN->getIncomingValue(0) != PN)
342  PN->replaceAllUsesWith(PN->getIncomingValue(0));
343  else
344  // We are left with an infinite loop with no entries: kill the PHI.
345  PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
346  getInstList().pop_front(); // Remove the PHI node
347  }
348 
349  // If the PHI node already only had one entry, it got deleted by
350  // removeIncomingValue.
351  }
352  } else {
353  // Okay, now we know that we need to remove predecessor #pred_idx from all
354  // PHI nodes. Iterate over each PHI node fixing them up
355  PHINode *PN;
356  for (iterator II = begin(); (PN = dyn_cast<PHINode>(II)); ) {
357  ++II;
358  PN->removeIncomingValue(Pred, false);
359  // If all incoming values to the Phi are the same, we can replace the Phi
360  // with that value.
361  Value* PNV = nullptr;
362  if (!KeepOneInputPHIs && (PNV = PN->hasConstantValue()))
363  if (PNV != PN) {
364  PN->replaceAllUsesWith(PNV);
365  PN->eraseFromParent();
366  }
367  }
368  }
369 }
370 
372  const Instruction *FirstNonPHI = getFirstNonPHI();
373  if (isa<LandingPadInst>(FirstNonPHI))
374  return true;
375  // This is perhaps a little conservative because constructs like
376  // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
377  // cannot handle such things just yet.
378  if (FirstNonPHI->isEHPad())
379  return false;
380  return true;
381 }
382 
384  auto *Term = getTerminator();
385  // No terminator means the block is under construction.
386  if (!Term)
387  return true;
388 
389  // If the block has no successors, there can be no instructions to hoist.
390  assert(Term->getNumSuccessors() > 0);
391 
392  // Instructions should not be hoisted across exception handling boundaries.
393  return !Term->isExceptionalTerminator();
394 }
395 
396 /// This splits a basic block into two at the specified
397 /// instruction. Note that all instructions BEFORE the specified iterator stay
398 /// as part of the original basic block, an unconditional branch is added to
399 /// the new BB, and the rest of the instructions in the BB are moved to the new
400 /// BB, including the old terminator. This invalidates the iterator.
401 ///
402 /// Note that this only works on well formed basic blocks (must have a
403 /// terminator), and 'I' must not be the end of instruction list (which would
404 /// cause a degenerate basic block to be formed, having a terminator inside of
405 /// the basic block).
406 ///
408  assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
409  assert(I != InstList.end() &&
410  "Trying to get me to create degenerate basic block!");
411 
413  this->getNextNode());
414 
415  // Save DebugLoc of split point before invalidating iterator.
416  DebugLoc Loc = I->getDebugLoc();
417  // Move all of the specified instructions from the original basic block into
418  // the new basic block.
419  New->getInstList().splice(New->end(), this->getInstList(), I, end());
420 
421  // Add a branch instruction to the newly formed basic block.
422  BranchInst *BI = BranchInst::Create(New, this);
423  BI->setDebugLoc(Loc);
424 
425  // Now we must loop through all of the successors of the New block (which
426  // _were_ the successors of the 'this' block), and update any PHI nodes in
427  // successors. If there were PHI nodes in the successors, then they need to
428  // know that incoming branches will be from New, not from Old.
429  //
430  for (succ_iterator I = succ_begin(New), E = succ_end(New); I != E; ++I) {
431  // Loop over any phi nodes in the basic block, updating the BB field of
432  // incoming values...
433  BasicBlock *Successor = *I;
434  for (auto &PN : Successor->phis()) {
435  int Idx = PN.getBasicBlockIndex(this);
436  while (Idx != -1) {
437  PN.setIncomingBlock((unsigned)Idx, New);
438  Idx = PN.getBasicBlockIndex(this);
439  }
440  }
441  }
442  return New;
443 }
444 
446  Instruction *TI = getTerminator();
447  if (!TI)
448  // Cope with being called on a BasicBlock that doesn't have a terminator
449  // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
450  return;
451  for (BasicBlock *Succ : successors(TI)) {
452  // N.B. Succ might not be a complete BasicBlock, so don't assume
453  // that it ends with a non-phi instruction.
454  for (iterator II = Succ->begin(), IE = Succ->end(); II != IE; ++II) {
455  PHINode *PN = dyn_cast<PHINode>(II);
456  if (!PN)
457  break;
458  int i;
459  while ((i = PN->getBasicBlockIndex(this)) >= 0)
460  PN->setIncomingBlock(i, New);
461  }
462  }
463 }
464 
465 /// Return true if this basic block is a landing pad. I.e., it's
466 /// the destination of the 'unwind' edge of an invoke instruction.
468  return isa<LandingPadInst>(getFirstNonPHI());
469 }
470 
471 /// Return the landingpad instruction associated with the landing pad.
474 }
475 
477  const Instruction *TI = getTerminator();
478  if (MDNode *MDIrrLoopHeader =
480  MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
481  if (MDName->getString().equals("loop_header_weight")) {
482  auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
483  return Optional<uint64_t>(CI->getValue().getZExtValue());
484  }
485  }
486  return Optional<uint64_t>();
487 }
488 
490  while (isa<DbgInfoIntrinsic>(It))
491  ++It;
492  return It;
493 }
uint64_t CallInst * C
Return a value (possibly void), from a function.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks &#39;this&#39; from the containing basic block and deletes it.
Definition: Instruction.cpp:67
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:371
This class provides a symbol table of name/value pairs.
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
Definition: BasicBlock.cpp:260
void dropAllReferences()
Drop all references to operands.
Definition: User.h:294
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:288
iterator erase(iterator where)
Definition: ilist.h:265
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Definition: BasicBlock.cpp:383
Various leaf nodes.
Definition: ISDOpcodes.h:59
void insertInto(Function *Parent, BasicBlock *InsertBefore=nullptr)
Insert unlinked basic block into a function.
Definition: BasicBlock.cpp:53
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:64
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.
Definition: BasicBlock.cpp:301
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked &#39;musttail&#39; prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:143
This class represents a function call, abstracting a target machine&#39;s calling convention.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:1759
A debug info location.
Definition: DebugLoc.h:33
Metadata node.
Definition: Metadata.h:863
F(f)
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...
Definition: BasicBlock.cpp:137
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:32
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:268
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:90
The address of a basic block.
Definition: Constants.h:839
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Definition: BasicBlock.cpp:133
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:174
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...
Definition: Twine.h:80
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:285
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:809
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...
Definition: Interval.h:102
bool empty() const
Definition: BasicBlock.h:279
const Instruction * getFirstNonPHIOrDbgOrLifetime() const
Returns a pointer to the first instruction in this block that is not a PHINode, a debug intrinsic...
Definition: BasicBlock.cpp:203
static Type * getLabelTy(LLVMContext &C)
Definition: Type.cpp:161
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:244
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:246
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:268
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:234
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:429
Value * getOperand(unsigned i) const
Definition: User.h:169
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:105
StringRef getString() const
Definition: Metadata.cpp:463
void replaceSuccessorsPhiUsesWith(BasicBlock *New)
Update all phi nodes in this basic block&#39;s successors to refer to basic block New instead of to it...
Definition: BasicBlock.cpp:445
#define P(N)
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
Definition: Value.cpp:135
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.
Definition: BasicBlock.cpp:189
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
Definition: BasicBlock.cpp:216
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:321
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:233
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
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...
Definition: BasicBlock.cpp:94
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const Instruction & front() const
Definition: BasicBlock.h:280
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...
Definition: Interval.h:112
void pop_front()
Definition: ilist.h:312
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)
Definition: ilist.h:327
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:115
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:99
self_iterator getIterator()
Definition: ilist_node.h:81
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.
Definition: STLExtras.h:1565
static UndefValue * get(Type *T)
Static factory methods - Return an &#39;undef&#39; object of the specified type.
Definition: Constants.cpp:1414
Value(Type *Ty, unsigned scid)
Definition: Value.cpp:52
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...
Definition: STLExtras.h:1206
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:467
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
Definition: BasicBlock.h:391
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:264
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.
Definition: BasicBlock.h:333
void removeFromParent()
Unlink &#39;this&#39; from the containing function, but do not delete it.
Definition: BasicBlock.cpp:110
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...
Definition: BasicBlock.cpp:127
void setIncomingBlock(unsigned i, BasicBlock *BB)
iterator end()
Definition: BasicBlock.h:270
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.
Definition: Constants.cpp:621
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)
Definition: ilist.h:311
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:89
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:160
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
pointer remove(iterator &IT)
Definition: ilist.h:249
iterator insert(iterator where, pointer New)
Definition: ilist.h:226
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:175
void clear()
Definition: ilist.h:307
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:106
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink &#39;this&#39; from the containing function and delete it.
Definition: BasicBlock.cpp:114
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
Definition: BasicBlock.cpp:26
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
Optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:476
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:322
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:632
void destroyConstant()
Called if some element of this constant is no longer valid.
Definition: Constants.cpp:361
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:324
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:407
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...
Definition: STLExtras.h:427
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
LLVM Value Representation.
Definition: Value.h:72
succ_range successors(Instruction *I)
Definition: CFG.h:259
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.
Definition: STLExtras.h:1548
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:586
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:353
A single uniqued string.
Definition: Metadata.h:603
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:472
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
Definition: BasicBlock.cpp:196
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
Definition: BasicBlock.cpp:489
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition: BasicBlock.cpp:120
bool use_empty() const
Definition: Value.h:322
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:226
User * user_back()
Definition: Value.h:385
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:276