LLVM  16.0.0git
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/ADT/Statistic.h"
17 #include "llvm/IR/CFG.h"
18 #include "llvm/IR/Constants.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/IR/IntrinsicInst.h"
21 #include "llvm/IR/LLVMContext.h"
22 #include "llvm/IR/Type.h"
23 
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "ir"
27 STATISTIC(NumInstrRenumberings, "Number of renumberings across all blocks");
28 
30  if (Function *F = getParent())
31  return F->getValueSymbolTable();
32  return nullptr;
33 }
34 
36  return getType()->getContext();
37 }
38 
40  BB->invalidateOrders();
41 }
42 
43 // Explicit instantiation of SymbolTableListTraits since some of the methods
44 // are not in the public header file...
46 
47 BasicBlock::BasicBlock(LLVMContext &C, const Twine &Name, Function *NewParent,
48  BasicBlock *InsertBefore)
49  : Value(Type::getLabelTy(C), Value::BasicBlockVal), Parent(nullptr) {
50 
51  if (NewParent)
52  insertInto(NewParent, InsertBefore);
53  else
54  assert(!InsertBefore &&
55  "Cannot insert block before another block with no function!");
56 
57  setName(Name);
58 }
59 
60 void BasicBlock::insertInto(Function *NewParent, BasicBlock *InsertBefore) {
61  assert(NewParent && "Expected a parent");
62  assert(!Parent && "Already has a parent");
63 
64  if (InsertBefore)
65  NewParent->getBasicBlockList().insert(InsertBefore->getIterator(), this);
66  else
67  NewParent->getBasicBlockList().push_back(this);
68 }
69 
72 
73  // If the address of the block is taken and it is being deleted (e.g. because
74  // it is dead), this means that there is either a dangling constant expr
75  // hanging off the block, or an undefined use of the block (source code
76  // expecting the address of a label to keep the block alive even though there
77  // is no indirect branch). Handle these cases by zapping the BlockAddress
78  // nodes. There are no other possible uses at this point.
79  if (hasAddressTaken()) {
80  assert(!use_empty() && "There should be at least one blockaddress!");
81  Constant *Replacement =
83  while (!use_empty()) {
84  BlockAddress *BA = cast<BlockAddress>(user_back());
86  BA->getType()));
87  BA->destroyConstant();
88  }
89  }
90 
91  assert(getParent() == nullptr && "BasicBlock still linked into the program!");
93  InstList.clear();
94 }
95 
96 void BasicBlock::setParent(Function *parent) {
97  // Set Parent=parent, updating instruction symtab entries as appropriate.
98  InstList.setSymTabObject(&Parent, parent);
99 }
100 
102  std::function<bool(const Instruction &)>>>
103 BasicBlock::instructionsWithoutDebug(bool SkipPseudoOp) const {
104  std::function<bool(const Instruction &)> Fn = [=](const Instruction &I) {
105  return !isa<DbgInfoIntrinsic>(I) &&
106  !(SkipPseudoOp && isa<PseudoProbeInst>(I));
107  };
108  return make_filter_range(*this, Fn);
109 }
110 
114  std::function<bool(Instruction &)> Fn = [=](Instruction &I) {
115  return !isa<DbgInfoIntrinsic>(I) &&
116  !(SkipPseudoOp && isa<PseudoProbeInst>(I));
117  };
118  return make_filter_range(*this, Fn);
119 }
120 
122  std::function<bool(const Instruction &)>>::difference_type
124  return std::distance(instructionsWithoutDebug().begin(),
126 }
127 
129  getParent()->getBasicBlockList().remove(getIterator());
130 }
131 
133  return getParent()->getBasicBlockList().erase(getIterator());
134 }
135 
137  MovePos->getParent()->getBasicBlockList().splice(
138  MovePos->getIterator(), getParent()->getBasicBlockList(), getIterator());
139 }
140 
142  MovePos->getParent()->getBasicBlockList().splice(
143  ++MovePos->getIterator(), getParent()->getBasicBlockList(),
144  getIterator());
145 }
146 
148  return getParent()->getParent();
149 }
150 
152  if (InstList.empty())
153  return nullptr;
154  const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
155  if (!RI || RI == &InstList.front())
156  return nullptr;
157 
158  const Instruction *Prev = RI->getPrevNode();
159  if (!Prev)
160  return nullptr;
161 
162  if (Value *RV = RI->getReturnValue()) {
163  if (RV != Prev)
164  return nullptr;
165 
166  // Look through the optional bitcast.
167  if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
168  RV = BI->getOperand(0);
169  Prev = BI->getPrevNode();
170  if (!Prev || RV != Prev)
171  return nullptr;
172  }
173  }
174 
175  if (auto *CI = dyn_cast<CallInst>(Prev)) {
176  if (CI->isMustTailCall())
177  return CI;
178  }
179  return nullptr;
180 }
181 
183  if (InstList.empty())
184  return nullptr;
185  auto *RI = dyn_cast<ReturnInst>(&InstList.back());
186  if (!RI || RI == &InstList.front())
187  return nullptr;
188 
189  if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
190  if (Function *F = CI->getCalledFunction())
191  if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
192  return CI;
193 
194  return nullptr;
195 }
196 
198  const BasicBlock* BB = this;
200  Visited.insert(BB);
201  while (auto *Succ = BB->getUniqueSuccessor()) {
202  if (!Visited.insert(Succ).second)
203  return nullptr;
204  BB = Succ;
205  }
206  return BB->getTerminatingDeoptimizeCall();
207 }
208 
210  for (const Instruction &I : *this)
211  if (!isa<PHINode>(I))
212  return &I;
213  return nullptr;
214 }
215 
216 const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
217  for (const Instruction &I : *this) {
218  if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
219  continue;
220 
221  if (SkipPseudoOp && isa<PseudoProbeInst>(I))
222  continue;
223 
224  return &I;
225  }
226  return nullptr;
227 }
228 
229 const Instruction *
231  for (const Instruction &I : *this) {
232  if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
233  continue;
234 
235  if (I.isLifetimeStartOrEnd())
236  continue;
237 
238  if (SkipPseudoOp && isa<PseudoProbeInst>(I))
239  continue;
240 
241  return &I;
242  }
243  return nullptr;
244 }
245 
247  const Instruction *FirstNonPHI = getFirstNonPHI();
248  if (!FirstNonPHI)
249  return end();
250 
251  const_iterator InsertPt = FirstNonPHI->getIterator();
252  if (InsertPt->isEHPad()) ++InsertPt;
253  return InsertPt;
254 }
255 
257  const Instruction *FirstNonPHI = getFirstNonPHI();
258  if (!FirstNonPHI)
259  return end();
260 
261  const_iterator InsertPt = FirstNonPHI->getIterator();
262  if (InsertPt->isEHPad())
263  ++InsertPt;
264 
265  if (isEntryBlock()) {
266  const_iterator End = end();
267  while (InsertPt != End &&
268  (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
269  isa<PseudoProbeInst>(*InsertPt))) {
270  if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
271  if (!AI->isStaticAlloca())
272  break;
273  }
274  ++InsertPt;
275  }
276  }
277  return InsertPt;
278 }
279 
281  for (Instruction &I : *this)
282  I.dropAllReferences();
283 }
284 
286  const_pred_iterator PI = pred_begin(this), E = pred_end(this);
287  if (PI == E) return nullptr; // No preds.
288  const BasicBlock *ThePred = *PI;
289  ++PI;
290  return (PI == E) ? ThePred : nullptr /*multiple preds*/;
291 }
292 
294  const_pred_iterator PI = pred_begin(this), E = pred_end(this);
295  if (PI == E) return nullptr; // No preds.
296  const BasicBlock *PredBB = *PI;
297  ++PI;
298  for (;PI != E; ++PI) {
299  if (*PI != PredBB)
300  return nullptr;
301  // The same predecessor appears multiple times in the predecessor list.
302  // This is OK.
303  }
304  return PredBB;
305 }
306 
307 bool BasicBlock::hasNPredecessors(unsigned N) const {
308  return hasNItems(pred_begin(this), pred_end(this), N);
309 }
310 
311 bool BasicBlock::hasNPredecessorsOrMore(unsigned N) const {
312  return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
313 }
314 
316  const_succ_iterator SI = succ_begin(this), E = succ_end(this);
317  if (SI == E) return nullptr; // no successors
318  const BasicBlock *TheSucc = *SI;
319  ++SI;
320  return (SI == E) ? TheSucc : nullptr /* multiple successors */;
321 }
322 
324  const_succ_iterator SI = succ_begin(this), E = succ_end(this);
325  if (SI == E) return nullptr; // No successors
326  const BasicBlock *SuccBB = *SI;
327  ++SI;
328  for (;SI != E; ++SI) {
329  if (*SI != SuccBB)
330  return nullptr;
331  // The same successor appears multiple times in the successor list.
332  // This is OK.
333  }
334  return SuccBB;
335 }
336 
338  PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
339  return make_range<phi_iterator>(P, nullptr);
340 }
341 
343  bool KeepOneInputPHIs) {
344  // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
345  assert((hasNUsesOrMore(16) || llvm::is_contained(predecessors(this), Pred)) &&
346  "Pred is not a predecessor!");
347 
348  // Return early if there are no PHI nodes to update.
349  if (empty() || !isa<PHINode>(begin()))
350  return;
351 
352  unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
353  for (PHINode &Phi : make_early_inc_range(phis())) {
354  Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
355  if (KeepOneInputPHIs)
356  continue;
357 
358  // If we have a single predecessor, removeIncomingValue may have erased the
359  // PHI node itself.
360  if (NumPreds == 1)
361  continue;
362 
363  // Try to replace the PHI node with a constant value.
364  if (Value *PhiConstant = Phi.hasConstantValue()) {
365  Phi.replaceAllUsesWith(PhiConstant);
366  Phi.eraseFromParent();
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 
397  const Function *F = getParent();
398  assert(F && "Block must have a parent function to use this API");
399  return this == &F->getEntryBlock();
400 }
401 
403  bool Before) {
404  if (Before)
405  return splitBasicBlockBefore(I, BBName);
406 
407  assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
408  assert(I != InstList.end() &&
409  "Trying to get me to create degenerate basic block!");
410 
412  this->getNextNode());
413 
414  // Save DebugLoc of split point before invalidating iterator.
415  DebugLoc Loc = I->getDebugLoc();
416  // Move all of the specified instructions from the original basic block into
417  // the new basic block.
418  New->splice(New->end(), this, I, end());
419 
420  // Add a branch instruction to the newly formed basic block.
421  BranchInst *BI = BranchInst::Create(New, this);
422  BI->setDebugLoc(Loc);
423 
424  // Now we must loop through all of the successors of the New block (which
425  // _were_ the successors of the 'this' block), and update any PHI nodes in
426  // successors. If there were PHI nodes in the successors, then they need to
427  // know that incoming branches will be from New, not from Old (this).
428  //
429  New->replaceSuccessorsPhiUsesWith(this, New);
430  return New;
431 }
432 
434  assert(getTerminator() &&
435  "Can't use splitBasicBlockBefore on degenerate BB!");
436  assert(I != InstList.end() &&
437  "Trying to get me to create degenerate basic block!");
438 
439  assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
440  "cannot split on multi incoming phis");
441 
442  BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(), this);
443  // Save DebugLoc of split point before invalidating iterator.
444  DebugLoc Loc = I->getDebugLoc();
445  // Move all of the specified instructions from the original basic block into
446  // the new basic block.
447  New->splice(New->end(), this, begin(), I);
448 
449  // Loop through all of the predecessors of the 'this' block (which will be the
450  // predecessors of the New block), replace the specified successor 'this'
451  // block to point at the New block and update any PHI nodes in 'this' block.
452  // If there were PHI nodes in 'this' block, the PHI nodes are updated
453  // to reflect that the incoming branches will be from the New block and not
454  // from predecessors of the 'this' block.
455  // Save predecessors to separate vector before modifying them.
456  SmallVector<BasicBlock *, 4> Predecessors;
457  for (BasicBlock *Pred : predecessors(this))
458  Predecessors.push_back(Pred);
459  for (BasicBlock *Pred : Predecessors) {
460  Instruction *TI = Pred->getTerminator();
461  TI->replaceSuccessorWith(this, New);
462  this->replacePhiUsesWith(Pred, New);
463  }
464  // Add a branch instruction from "New" to "this" Block.
465  BranchInst *BI = BranchInst::Create(this, New);
466  BI->setDebugLoc(Loc);
467 
468  return New;
469 }
470 
472  BasicBlock::iterator FromBeginIt,
473  BasicBlock::iterator FromEndIt) {
474 #ifdef EXPENSIVE_CHECKS
475  // Check that FromBeginIt is befor FromEndIt.
476  auto FromBBEnd = FromBB->end();
477  for (auto It = FromBeginIt; It != FromEndIt; ++It)
478  assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
479 #endif // EXPENSIVE_CHECKS
480  getInstList().splice(ToIt, FromBB->getInstList(), FromBeginIt, FromEndIt);
481 }
482 
484  BasicBlock::iterator ToIt) {
485  return getInstList().erase(FromIt, ToIt);
486 }
487 
489  // N.B. This might not be a complete BasicBlock, so don't assume
490  // that it ends with a non-phi instruction.
491  for (Instruction &I : *this) {
492  PHINode *PN = dyn_cast<PHINode>(&I);
493  if (!PN)
494  break;
495  PN->replaceIncomingBlockWith(Old, New);
496  }
497 }
498 
500  BasicBlock *New) {
501  Instruction *TI = getTerminator();
502  if (!TI)
503  // Cope with being called on a BasicBlock that doesn't have a terminator
504  // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
505  return;
506  for (BasicBlock *Succ : successors(TI))
507  Succ->replacePhiUsesWith(Old, New);
508 }
509 
511  this->replaceSuccessorsPhiUsesWith(this, New);
512 }
513 
515  return isa<LandingPadInst>(getFirstNonPHI());
516 }
517 
519  return dyn_cast<LandingPadInst>(getFirstNonPHI());
520 }
521 
522 std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
523  const Instruction *TI = getTerminator();
524  if (MDNode *MDIrrLoopHeader =
525  TI->getMetadata(LLVMContext::MD_irr_loop)) {
526  MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
527  if (MDName->getString().equals("loop_header_weight")) {
528  auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
529  return std::optional<uint64_t>(CI->getValue().getZExtValue());
530  }
531  }
532  return std::nullopt;
533 }
534 
536  while (isa<DbgInfoIntrinsic>(It))
537  ++It;
538  return It;
539 }
540 
542  unsigned Order = 0;
543  for (Instruction &I : *this)
544  I.Order = Order++;
545 
546  // Set the bit to indicate that the instruction order valid and cached.
547  BasicBlockBits Bits = getBasicBlockBits();
548  Bits.InstrOrderValid = true;
549  setBasicBlockBits(Bits);
550 
551  NumInstrRenumberings++;
552 }
553 
554 #ifndef NDEBUG
555 /// In asserts builds, this checks the numbering. In non-asserts builds, it
556 /// is defined as a no-op inline function in BasicBlock.h.
558  if (!isInstrOrderValid())
559  return;
560  const Instruction *Prev = nullptr;
561  for (const Instruction &I : *this) {
562  assert((!Prev || Prev->comesBefore(&I)) &&
563  "cached instruction ordering is incorrect");
564  Prev = &I;
565  }
566 }
567 #endif
llvm::SuccIterator
Definition: CFG.h:138
llvm::BasicBlock::getTerminatingDeoptimizeCall
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:182
llvm::BasicBlock::splice
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition: BasicBlock.h:457
llvm::BasicBlock::end
iterator end()
Definition: BasicBlock.h:308
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Instruction::replaceSuccessorWith
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
Definition: Instruction.cpp:846
llvm::ReturnInst
Return a value (possibly void), from a function.
Definition: Instructions.h:3050
llvm::BasicBlock::iterator
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
llvm::BasicBlock::getParent
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:104
IntrinsicInst.h
llvm::hasNItems
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.
Definition: STLExtras.h:2311
llvm::Function::getBasicBlockList
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Definition: Function.h:684
llvm::succ_end
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:102
llvm::Function
Definition: Function.h:60
llvm::BasicBlock::hasNPredecessorsOrMore
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:311
P
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
Definition: README-SSE.txt:411
llvm::BasicBlock::instructionsWithoutDebug
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.
Definition: BasicBlock.cpp:103
llvm::ReturnInst::getReturnValue
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
Definition: Instructions.h:3095
llvm::ilist_node_with_parent< BasicBlock, Function >::getNextNode
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1199
Statistic.h
llvm::BasicBlock::empty
bool empty() const
Definition: BasicBlock.h:317
llvm::LandingPadInst
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Definition: Instructions.h:2949
llvm::BasicBlock::replaceSuccessorsPhiUsesWith
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...
Definition: BasicBlock.cpp:499
llvm::BasicBlock::sizeWithoutDebug
filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
Definition: BasicBlock.cpp:123
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::filter_iterator_impl
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:560
llvm::BasicBlock::eraseFromParent
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
Definition: BasicBlock.cpp:132
llvm::tgtok::Bits
@ Bits
Definition: TGLexer.h:50
llvm::BasicBlock::getSingleSuccessor
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:315
llvm::Instruction::comesBefore
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
Definition: Instruction.cpp:121
llvm::BasicBlock::splitBasicBlock
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:402
llvm::SmallPtrSet< const BasicBlock *, 8 >
llvm::successors
auto successors(MachineBasicBlock *BB)
Definition: MachineSSAContext.h:29
llvm::BasicBlock::getSinglePredecessor
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:285
STLExtras.h
llvm::BasicBlock::hasNPredecessors
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
Definition: BasicBlock.cpp:307
llvm::BasicBlock::canSplitPredecessors
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:371
llvm::BasicBlock::splitBasicBlockBefore
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...
Definition: BasicBlock.cpp:433
llvm::Type::getInt32Ty
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:239
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::BasicBlock::getUniqueSuccessor
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:323
llvm::invalidateParentIListOrdering
void invalidateParentIListOrdering(ParentClass *Parent)
Notify basic blocks when an instruction is inserted.
Definition: SymbolTableListTraitsImpl.h:25
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
Constants.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::ConstantExpr::getIntToPtr
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2188
llvm::BasicBlock::begin
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:306
SI
@ SI
Definition: SIInstrInfo.cpp:7966
llvm::BasicBlock::isLandingPad
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:514
SymbolTableListTraitsImpl.h
llvm::BasicBlock::getFirstInsertionPt
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:246
llvm::PHINode::replaceIncomingBlockWith
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
Definition: Instructions.h:2838
llvm::skipDebugIntrinsics
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
Definition: BasicBlock.cpp:535
llvm::BasicBlock::getValueSymbolTable
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
Definition: BasicBlock.cpp:29
llvm::Instruction
Definition: Instruction.h:42
llvm::BasicBlock::phis
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:364
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::predecessors
auto predecessors(MachineBasicBlock *BB)
Definition: MachineSSAContext.h:30
llvm::ConstantInt::get
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:879
llvm::hasNItemsOrMore
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.
Definition: STLExtras.h:2336
llvm::BasicBlock::getModule
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:147
llvm::BasicBlock::getFirstNonPHI
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:209
llvm::Value::use_empty
bool use_empty() const
Definition: Value.h:344
Type.h
llvm::BasicBlock::getPostdominatingDeoptimizeCall
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
Definition: BasicBlock.cpp:197
llvm::BasicBlock::renumberInstructions
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:541
llvm::Instruction::getMetadata
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:276
CFG.h
llvm::StringRef::equals
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:164
llvm::BasicBlock::isEntryBlock
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
Definition: BasicBlock.cpp:396
llvm::Value::user_back
User * user_back()
Definition: Value.h:407
llvm::BasicBlock::hasAddressTaken
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:484
BasicBlock.h
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
llvm::SymbolTableListTraits
Definition: GlobalAlias.h:26
llvm::BasicBlock::removeFromParent
void removeFromParent()
Unlink 'this' from the containing function, but do not delete it.
Definition: BasicBlock.cpp:128
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
llvm::BasicBlock::getIrrLoopHeaderWeight
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:522
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::Value::hasNUsesOrMore
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
Definition: Value.cpp:152
llvm::BasicBlock::isLegalToHoistInto
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Definition: BasicBlock.cpp:383
llvm::BranchInst::Create
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
Definition: Instructions.h:3188
llvm::BasicBlock::isInstrOrderValid
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:526
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::succ_begin
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:99
llvm::make_early_inc_range
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...
Definition: STLExtras.h:716
llvm::is_contained
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1868
llvm::Instruction::setDebugLoc
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:356
llvm::ilist_node_with_parent::getPrevNode
NodeTy * getPrevNode()
Definition: ilist_node.h:275
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:82
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::MDNode
Metadata node.
Definition: Metadata.h:944
llvm::BasicBlock::~BasicBlock
~BasicBlock()
Definition: BasicBlock.cpp:70
llvm::BlockAddress
The address of a basic block.
Definition: Constants.h:849
llvm::BasicBlock::moveAfter
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:141
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
llvm::BasicBlock::getUniquePredecessor
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:293
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:532
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:97
llvm::ilist_node_impl::getIterator
self_iterator getIterator()
Definition: ilist_node.h:82
llvm::BasicBlock::erase
BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
Definition: BasicBlock.cpp:483
llvm::BasicBlock::validateInstrOrdering
void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
Definition: BasicBlock.cpp:557
llvm::PredIterator
Definition: CFG.h:42
llvm::BasicBlock::dropAllReferences
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:280
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::make_filter_range
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:632
llvm::BasicBlock::front
const Instruction & front() const
Definition: BasicBlock.h:318
llvm::BasicBlock::getContext
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:35
llvm::BasicBlock::replacePhiUsesWith
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.
Definition: BasicBlock.cpp:488
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::ilist_iterator
Iterator for intrusive lists based on ilist_node.
Definition: ilist_iterator.h:57
llvm::pred_end
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:112
llvm::Instruction::isEHPad
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:669
llvm::BasicBlock::getFirstNonPHIOrDbgOrLifetime
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,...
Definition: BasicBlock.cpp:230
llvm::pred_begin
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:109
llvm::BasicBlock::getInstList
const InstListType & getInstList() const
Return the underlying instruction list container.
Definition: BasicBlock.h:373
Instructions.h
llvm::BasicBlock::moveBefore
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition: BasicBlock.cpp:136
llvm::ValueSymbolTable
This class provides a symbol table of name/value pairs.
Definition: ValueSymbolTable.h:37
N
#define N
llvm::iterator_range
A range adaptor for a pair of iterators.
Definition: iterator_range.h:30
llvm::BasicBlock::getFirstNonPHIOrDbg
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,...
Definition: BasicBlock.cpp:216
llvm::PHINode
Definition: Instructions.h:2697
llvm::BasicBlock::getTerminator
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.h:119
llvm::BasicBlock::removePredecessor
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Definition: BasicBlock.cpp:342
llvm::BasicBlock::getLandingPadInst
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:518
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
BB
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
Definition: README.txt:39
LLVMContext.h
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::AllocaInst
an instruction to allocate memory on the stack
Definition: Instructions.h:59
llvm::User::getOperand
Value * getOperand(unsigned i) const
Definition: User.h:169
llvm::BasicBlock::getTerminatingMustTailCall
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:151
llvm::MDString::getString
StringRef getString() const
Definition: Metadata.cpp:508
llvm::BranchInst
Conditional or Unconditional Branch instruction.
Definition: Instructions.h:3132
llvm::M68kBeads::Term
@ Term
Definition: M68kBaseInfo.h:71
llvm::MDString
A single uniqued string.
Definition: Metadata.h:612
llvm::BasicBlock::getFirstNonPHIOrDbgOrAlloca
const_iterator getFirstNonPHIOrDbgOrAlloca() const
Returns an iterator to the first instruction in this block that is not a PHINode, a debug intrinsic,...
Definition: BasicBlock.cpp:256
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::Constant::destroyConstant
void destroyConstant()
Called if some element of this constant is no longer valid.
Definition: Constants.cpp:450
llvm::BasicBlock::const_iterator
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
llvm::SmallPtrSetImpl::insert
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Definition: SmallPtrSet.h:365