LLVM 17.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"
21#include "llvm/IR/LLVMContext.h"
22#include "llvm/IR/Type.h"
23
24using namespace llvm;
25
26#define DEBUG_TYPE "ir"
27STATISTIC(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
47BasicBlock::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
60void 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->insert(InsertBefore->getIterator(), this);
66 else
67 NewParent->insert(NewParent->end(), 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
96void 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 &)>>>
103BasicBlock::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 getParent()->splice(MovePos, getParent(), getIterator());
138}
139
141 MovePos->getParent()->splice(++MovePos->getIterator(), getParent(),
142 getIterator());
143}
144
146 return getParent()->getParent();
147}
148
150 if (InstList.empty())
151 return nullptr;
152 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
153 if (!RI || RI == &InstList.front())
154 return nullptr;
155
156 const Instruction *Prev = RI->getPrevNode();
157 if (!Prev)
158 return nullptr;
159
160 if (Value *RV = RI->getReturnValue()) {
161 if (RV != Prev)
162 return nullptr;
163
164 // Look through the optional bitcast.
165 if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
166 RV = BI->getOperand(0);
167 Prev = BI->getPrevNode();
168 if (!Prev || RV != Prev)
169 return nullptr;
170 }
171 }
172
173 if (auto *CI = dyn_cast<CallInst>(Prev)) {
174 if (CI->isMustTailCall())
175 return CI;
176 }
177 return nullptr;
178}
179
181 if (InstList.empty())
182 return nullptr;
183 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
184 if (!RI || RI == &InstList.front())
185 return nullptr;
186
187 if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
188 if (Function *F = CI->getCalledFunction())
189 if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
190 return CI;
191
192 return nullptr;
193}
194
196 const BasicBlock* BB = this;
198 Visited.insert(BB);
199 while (auto *Succ = BB->getUniqueSuccessor()) {
200 if (!Visited.insert(Succ).second)
201 return nullptr;
202 BB = Succ;
203 }
204 return BB->getTerminatingDeoptimizeCall();
205}
206
208 if (InstList.empty())
209 return nullptr;
210 for (const Instruction &I : *this)
211 if (isa<LoadInst>(I) || isa<StoreInst>(I) || isa<CallBase>(I))
212 return &I;
213 return nullptr;
214}
215
217 for (const Instruction &I : *this)
218 if (!isa<PHINode>(I))
219 return &I;
220 return nullptr;
221}
222
223const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
224 for (const Instruction &I : *this) {
225 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
226 continue;
227
228 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
229 continue;
230
231 return &I;
232 }
233 return nullptr;
234}
235
236const Instruction *
238 for (const Instruction &I : *this) {
239 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
240 continue;
241
242 if (I.isLifetimeStartOrEnd())
243 continue;
244
245 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
246 continue;
247
248 return &I;
249 }
250 return nullptr;
251}
252
254 const Instruction *FirstNonPHI = getFirstNonPHI();
255 if (!FirstNonPHI)
256 return end();
257
258 const_iterator InsertPt = FirstNonPHI->getIterator();
259 if (InsertPt->isEHPad()) ++InsertPt;
260 return InsertPt;
261}
262
264 const Instruction *FirstNonPHI = getFirstNonPHI();
265 if (!FirstNonPHI)
266 return end();
267
268 const_iterator InsertPt = FirstNonPHI->getIterator();
269 if (InsertPt->isEHPad())
270 ++InsertPt;
271
272 if (isEntryBlock()) {
274 while (InsertPt != End &&
275 (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
276 isa<PseudoProbeInst>(*InsertPt))) {
277 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
278 if (!AI->isStaticAlloca())
279 break;
280 }
281 ++InsertPt;
282 }
283 }
284 return InsertPt;
285}
286
288 for (Instruction &I : *this)
289 I.dropAllReferences();
290}
291
293 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
294 if (PI == E) return nullptr; // No preds.
295 const BasicBlock *ThePred = *PI;
296 ++PI;
297 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
298}
299
301 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
302 if (PI == E) return nullptr; // No preds.
303 const BasicBlock *PredBB = *PI;
304 ++PI;
305 for (;PI != E; ++PI) {
306 if (*PI != PredBB)
307 return nullptr;
308 // The same predecessor appears multiple times in the predecessor list.
309 // This is OK.
310 }
311 return PredBB;
312}
313
314bool BasicBlock::hasNPredecessors(unsigned N) const {
315 return hasNItems(pred_begin(this), pred_end(this), N);
316}
317
319 return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
320}
321
323 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
324 if (SI == E) return nullptr; // no successors
325 const BasicBlock *TheSucc = *SI;
326 ++SI;
327 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
328}
329
331 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
332 if (SI == E) return nullptr; // No successors
333 const BasicBlock *SuccBB = *SI;
334 ++SI;
335 for (;SI != E; ++SI) {
336 if (*SI != SuccBB)
337 return nullptr;
338 // The same successor appears multiple times in the successor list.
339 // This is OK.
340 }
341 return SuccBB;
342}
343
345 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
346 return make_range<phi_iterator>(P, nullptr);
347}
348
350 bool KeepOneInputPHIs) {
351 // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
353 "Pred is not a predecessor!");
354
355 // Return early if there are no PHI nodes to update.
356 if (empty() || !isa<PHINode>(begin()))
357 return;
358
359 unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
360 for (PHINode &Phi : make_early_inc_range(phis())) {
361 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
362 if (KeepOneInputPHIs)
363 continue;
364
365 // If we have a single predecessor, removeIncomingValue may have erased the
366 // PHI node itself.
367 if (NumPreds == 1)
368 continue;
369
370 // Try to replace the PHI node with a constant value.
371 if (Value *PhiConstant = Phi.hasConstantValue()) {
372 Phi.replaceAllUsesWith(PhiConstant);
373 Phi.eraseFromParent();
374 }
375 }
376}
377
379 const Instruction *FirstNonPHI = getFirstNonPHI();
380 if (isa<LandingPadInst>(FirstNonPHI))
381 return true;
382 // This is perhaps a little conservative because constructs like
383 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
384 // cannot handle such things just yet.
385 if (FirstNonPHI->isEHPad())
386 return false;
387 return true;
388}
389
391 auto *Term = getTerminator();
392 // No terminator means the block is under construction.
393 if (!Term)
394 return true;
395
396 // If the block has no successors, there can be no instructions to hoist.
397 assert(Term->getNumSuccessors() > 0);
398
399 // Instructions should not be hoisted across exception handling boundaries.
400 return !Term->isExceptionalTerminator();
401}
402
404 const Function *F = getParent();
405 assert(F && "Block must have a parent function to use this API");
406 return this == &F->getEntryBlock();
407}
408
410 bool Before) {
411 if (Before)
412 return splitBasicBlockBefore(I, BBName);
413
414 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
415 assert(I != InstList.end() &&
416 "Trying to get me to create degenerate basic block!");
417
419 this->getNextNode());
420
421 // Save DebugLoc of split point before invalidating iterator.
422 DebugLoc Loc = I->getDebugLoc();
423 // Move all of the specified instructions from the original basic block into
424 // the new basic block.
425 New->splice(New->end(), this, I, end());
426
427 // Add a branch instruction to the newly formed basic block.
428 BranchInst *BI = BranchInst::Create(New, this);
429 BI->setDebugLoc(Loc);
430
431 // Now we must loop through all of the successors of the New block (which
432 // _were_ the successors of the 'this' block), and update any PHI nodes in
433 // successors. If there were PHI nodes in the successors, then they need to
434 // know that incoming branches will be from New, not from Old (this).
435 //
436 New->replaceSuccessorsPhiUsesWith(this, New);
437 return New;
438}
439
442 "Can't use splitBasicBlockBefore on degenerate BB!");
443 assert(I != InstList.end() &&
444 "Trying to get me to create degenerate basic block!");
445
446 assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
447 "cannot split on multi incoming phis");
448
449 BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(), this);
450 // Save DebugLoc of split point before invalidating iterator.
451 DebugLoc Loc = I->getDebugLoc();
452 // Move all of the specified instructions from the original basic block into
453 // the new basic block.
454 New->splice(New->end(), this, begin(), I);
455
456 // Loop through all of the predecessors of the 'this' block (which will be the
457 // predecessors of the New block), replace the specified successor 'this'
458 // block to point at the New block and update any PHI nodes in 'this' block.
459 // If there were PHI nodes in 'this' block, the PHI nodes are updated
460 // to reflect that the incoming branches will be from the New block and not
461 // from predecessors of the 'this' block.
462 // Save predecessors to separate vector before modifying them.
463 SmallVector<BasicBlock *, 4> Predecessors;
464 for (BasicBlock *Pred : predecessors(this))
465 Predecessors.push_back(Pred);
466 for (BasicBlock *Pred : Predecessors) {
467 Instruction *TI = Pred->getTerminator();
468 TI->replaceSuccessorWith(this, New);
469 this->replacePhiUsesWith(Pred, New);
470 }
471 // Add a branch instruction from "New" to "this" Block.
472 BranchInst *BI = BranchInst::Create(this, New);
473 BI->setDebugLoc(Loc);
474
475 return New;
476}
477
479 BasicBlock::iterator FromBeginIt,
480 BasicBlock::iterator FromEndIt) {
481#ifdef EXPENSIVE_CHECKS
482 // Check that FromBeginIt is befor FromEndIt.
483 auto FromBBEnd = FromBB->end();
484 for (auto It = FromBeginIt; It != FromEndIt; ++It)
485 assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
486#endif // EXPENSIVE_CHECKS
487 getInstList().splice(ToIt, FromBB->getInstList(), FromBeginIt, FromEndIt);
488}
489
492 return InstList.erase(FromIt, ToIt);
493}
494
496 // N.B. This might not be a complete BasicBlock, so don't assume
497 // that it ends with a non-phi instruction.
498 for (Instruction &I : *this) {
499 PHINode *PN = dyn_cast<PHINode>(&I);
500 if (!PN)
501 break;
502 PN->replaceIncomingBlockWith(Old, New);
503 }
504}
505
507 BasicBlock *New) {
509 if (!TI)
510 // Cope with being called on a BasicBlock that doesn't have a terminator
511 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
512 return;
513 for (BasicBlock *Succ : successors(TI))
514 Succ->replacePhiUsesWith(Old, New);
515}
516
518 this->replaceSuccessorsPhiUsesWith(this, New);
519}
520
522 return isa<LandingPadInst>(getFirstNonPHI());
523}
524
526 return dyn_cast<LandingPadInst>(getFirstNonPHI());
527}
528
529std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
530 const Instruction *TI = getTerminator();
531 if (MDNode *MDIrrLoopHeader =
532 TI->getMetadata(LLVMContext::MD_irr_loop)) {
533 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
534 if (MDName->getString().equals("loop_header_weight")) {
535 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
536 return std::optional<uint64_t>(CI->getValue().getZExtValue());
537 }
538 }
539 return std::nullopt;
540}
541
543 while (isa<DbgInfoIntrinsic>(It))
544 ++It;
545 return It;
546}
547
549 unsigned Order = 0;
550 for (Instruction &I : *this)
551 I.Order = Order++;
552
553 // Set the bit to indicate that the instruction order valid and cached.
554 BasicBlockBits Bits = getBasicBlockBits();
555 Bits.InstrOrderValid = true;
556 setBasicBlockBits(Bits);
557
558 NumInstrRenumberings++;
559}
560
561#ifndef NDEBUG
562/// In asserts builds, this checks the numbering. In non-asserts builds, it
563/// is defined as a no-op inline function in BasicBlock.h.
565 if (!isInstrOrderValid())
566 return;
567 const Instruction *Prev = nullptr;
568 for (const Instruction &I : *this) {
569 assert((!Prev || Prev->comesBefore(&I)) &&
570 "cached instruction ordering is incorrect");
571 Prev = &I;
572 }
573}
574#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::string Name
bool End
Definition: ELF_riscv.cpp:464
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define P(N)
@ SI
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition: Statistic.h:167
an instruction to allocate memory on the stack
Definition: Instructions.h:58
LLVM Basic Block Representation.
Definition: BasicBlock.h:56
BasicBlock::iterator erase(BasicBlock::iterator FromIt, BasicBlock::iterator ToIt)
Erases a range of instructions from FromIt to (not including) ToIt.
Definition: BasicBlock.cpp:490
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:506
iterator end()
Definition: BasicBlock.h:328
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:326
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:384
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:525
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:253
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:548
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
bool empty() const
Definition: BasicBlock.h:337
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:440
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:507
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
Definition: BasicBlock.h:554
friend void Instruction::removeFromParent()
InstListType::const_iterator const_iterator
Definition: BasicBlock.h:88
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
Definition: BasicBlock.cpp:216
const Instruction & front() const
Definition: BasicBlock.h:338
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:105
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
Definition: BasicBlock.cpp:403
ValueSymbolTable * getValueSymbolTable()
Returns a pointer to the symbol table if one exists.
Definition: BasicBlock.cpp:29
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:140
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
Definition: BasicBlock.cpp:314
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:409
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:330
friend iplist< Instruction >::iterator Instruction::eraseFromParent()
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
Definition: BasicBlock.cpp:292
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:529
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:180
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:495
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:237
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:300
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:322
const Function * getParent() const
Return the enclosing method, or null if none.
Definition: BasicBlock.h:112
void validateInstrOrdering() const
Asserts that instruction order numbers are marked invalid, or that they are in ascending order.
Definition: BasicBlock.cpp:564
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:223
filter_iterator< BasicBlock::const_iterator, std::function< bool(constInstruction &)> >::difference_type sizeWithoutDebug() const
Return the size of the basic block ignoring debug instructions.
Definition: BasicBlock.cpp:123
InstListType::iterator iterator
Instruction iterators...
Definition: BasicBlock.h:87
LLVMContext & getContext() const
Get the context in which this basic block lives.
Definition: BasicBlock.cpp:35
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:263
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:287
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition: BasicBlock.h:254
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:521
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:127
bool canSplitPredecessors() const
Definition: BasicBlock.cpp:378
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:149
friend BasicBlock::iterator Instruction::insertInto(BasicBlock *BB, BasicBlock::iterator It)
bool isLegalToHoistInto() const
Return true if it is legal to hoist instructions into this block.
Definition: BasicBlock.cpp:390
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:318
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:549
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
Definition: BasicBlock.cpp:195
const Instruction * getFirstMayFaultInst() const
Returns the first potential AsynchEH faulty instruction currently it checks for loads/stores (which m...
Definition: BasicBlock.cpp:207
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition: BasicBlock.h:480
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:145
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Definition: BasicBlock.cpp:349
The address of a basic block.
Definition: Constants.h:874
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
This class represents a function call, abstracting a target machine's calling convention.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Definition: Constants.cpp:2199
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:888
This is an important base class in LLVM.
Definition: Constant.h:41
void destroyConstant()
Called if some element of this constant is no longer valid.
Definition: Constants.cpp:458
A debug info location.
Definition: DebugLoc.h:33
void splice(Function::iterator ToIt, Function *FromF)
Transfer all blocks from FromF to this function at ToIt.
Definition: Function.h:697
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition: Function.h:692
iterator end()
Definition: Function.h:763
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:652
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
Definition: Instruction.h:700
void replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB)
Replace specified successor OldBB to point at the provided block.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Definition: Instruction.h:275
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
Definition: Instruction.h:362
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
The landingpad instruction holds all of the information necessary to generate correct exception handl...
Metadata node.
Definition: Metadata.h:950
A single uniqued string.
Definition: Metadata.h:611
StringRef getString() const
Definition: Metadata.cpp:509
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
void replaceIncomingBlockWith(const BasicBlock *Old, BasicBlock *New)
Replace every incoming basic block Old to basic block New.
Return a value (possibly void), from a function.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
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
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:450
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:164
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
static IntegerType * getInt32Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
Definition: User.h:169
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:535
User * user_back()
Definition: Value.h:407
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
Definition: Value.cpp:153
bool use_empty() const
Definition: Value.h:344
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:589
Iterator for intrusive lists based on ilist_node.
self_iterator getIterator()
Definition: ilist_node.h:82
BasicBlock * getNextNode()
Get the next node, or nullptr for the list tail.
Definition: ilist_node.h:289
void splice(iterator where, iplist_impl &L2)
Definition: ilist.h:266
iterator erase(iterator where)
Definition: ilist.h:204
pointer remove(iterator &IT)
Definition: ilist.h:188
void clear()
Definition: ilist.h:246
A range adaptor for a pair of iterators.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Interval::succ_iterator succ_end(Interval *I)
Definition: Interval.h:102
auto successors(const MachineBasicBlock *BB)
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
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:748
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:2514
Interval::pred_iterator pred_end(Interval *I)
Definition: Interval.h:112
BasicBlock::iterator skipDebugIntrinsics(BasicBlock::iterator It)
Advance It while it points to a debug instruction and return the result.
Definition: BasicBlock.cpp:542
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:2489
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
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:664
void invalidateParentIListOrdering(ParentClass *Parent)
Notify basic blocks when an instruction is inserted.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition: STLExtras.h:1976
#define N