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 MovePos->getParent()->splice(MovePos->getIterator(), getParent(),
138 getIterator());
139}
140
142 MovePos->getParent()->splice(++MovePos->getIterator(), getParent(),
143 getIterator());
144}
145
147 return getParent()->getParent();
148}
149
151 if (InstList.empty())
152 return nullptr;
153 const ReturnInst *RI = dyn_cast<ReturnInst>(&InstList.back());
154 if (!RI || RI == &InstList.front())
155 return nullptr;
156
157 const Instruction *Prev = RI->getPrevNode();
158 if (!Prev)
159 return nullptr;
160
161 if (Value *RV = RI->getReturnValue()) {
162 if (RV != Prev)
163 return nullptr;
164
165 // Look through the optional bitcast.
166 if (auto *BI = dyn_cast<BitCastInst>(Prev)) {
167 RV = BI->getOperand(0);
168 Prev = BI->getPrevNode();
169 if (!Prev || RV != Prev)
170 return nullptr;
171 }
172 }
173
174 if (auto *CI = dyn_cast<CallInst>(Prev)) {
175 if (CI->isMustTailCall())
176 return CI;
177 }
178 return nullptr;
179}
180
182 if (InstList.empty())
183 return nullptr;
184 auto *RI = dyn_cast<ReturnInst>(&InstList.back());
185 if (!RI || RI == &InstList.front())
186 return nullptr;
187
188 if (auto *CI = dyn_cast_or_null<CallInst>(RI->getPrevNode()))
189 if (Function *F = CI->getCalledFunction())
190 if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
191 return CI;
192
193 return nullptr;
194}
195
197 const BasicBlock* BB = this;
199 Visited.insert(BB);
200 while (auto *Succ = BB->getUniqueSuccessor()) {
201 if (!Visited.insert(Succ).second)
202 return nullptr;
203 BB = Succ;
204 }
205 return BB->getTerminatingDeoptimizeCall();
206}
207
209 for (const Instruction &I : *this)
210 if (!isa<PHINode>(I))
211 return &I;
212 return nullptr;
213}
214
215const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
216 for (const Instruction &I : *this) {
217 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
218 continue;
219
220 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
221 continue;
222
223 return &I;
224 }
225 return nullptr;
226}
227
228const Instruction *
230 for (const Instruction &I : *this) {
231 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
232 continue;
233
234 if (I.isLifetimeStartOrEnd())
235 continue;
236
237 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
238 continue;
239
240 return &I;
241 }
242 return nullptr;
243}
244
246 const Instruction *FirstNonPHI = getFirstNonPHI();
247 if (!FirstNonPHI)
248 return end();
249
250 const_iterator InsertPt = FirstNonPHI->getIterator();
251 if (InsertPt->isEHPad()) ++InsertPt;
252 return InsertPt;
253}
254
256 const Instruction *FirstNonPHI = getFirstNonPHI();
257 if (!FirstNonPHI)
258 return end();
259
260 const_iterator InsertPt = FirstNonPHI->getIterator();
261 if (InsertPt->isEHPad())
262 ++InsertPt;
263
264 if (isEntryBlock()) {
265 const_iterator End = end();
266 while (InsertPt != End &&
267 (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
268 isa<PseudoProbeInst>(*InsertPt))) {
269 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
270 if (!AI->isStaticAlloca())
271 break;
272 }
273 ++InsertPt;
274 }
275 }
276 return InsertPt;
277}
278
280 for (Instruction &I : *this)
281 I.dropAllReferences();
282}
283
285 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
286 if (PI == E) return nullptr; // No preds.
287 const BasicBlock *ThePred = *PI;
288 ++PI;
289 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
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 *PredBB = *PI;
296 ++PI;
297 for (;PI != E; ++PI) {
298 if (*PI != PredBB)
299 return nullptr;
300 // The same predecessor appears multiple times in the predecessor list.
301 // This is OK.
302 }
303 return PredBB;
304}
305
306bool BasicBlock::hasNPredecessors(unsigned N) const {
307 return hasNItems(pred_begin(this), pred_end(this), N);
308}
309
311 return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
312}
313
315 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
316 if (SI == E) return nullptr; // no successors
317 const BasicBlock *TheSucc = *SI;
318 ++SI;
319 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
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 *SuccBB = *SI;
326 ++SI;
327 for (;SI != E; ++SI) {
328 if (*SI != SuccBB)
329 return nullptr;
330 // The same successor appears multiple times in the successor list.
331 // This is OK.
332 }
333 return SuccBB;
334}
335
337 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
338 return make_range<phi_iterator>(P, nullptr);
339}
340
342 bool KeepOneInputPHIs) {
343 // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
345 "Pred is not a predecessor!");
346
347 // Return early if there are no PHI nodes to update.
348 if (empty() || !isa<PHINode>(begin()))
349 return;
350
351 unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
352 for (PHINode &Phi : make_early_inc_range(phis())) {
353 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
354 if (KeepOneInputPHIs)
355 continue;
356
357 // If we have a single predecessor, removeIncomingValue may have erased the
358 // PHI node itself.
359 if (NumPreds == 1)
360 continue;
361
362 // Try to replace the PHI node with a constant value.
363 if (Value *PhiConstant = Phi.hasConstantValue()) {
364 Phi.replaceAllUsesWith(PhiConstant);
365 Phi.eraseFromParent();
366 }
367 }
368}
369
371 const Instruction *FirstNonPHI = getFirstNonPHI();
372 if (isa<LandingPadInst>(FirstNonPHI))
373 return true;
374 // This is perhaps a little conservative because constructs like
375 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
376 // cannot handle such things just yet.
377 if (FirstNonPHI->isEHPad())
378 return false;
379 return true;
380}
381
383 auto *Term = getTerminator();
384 // No terminator means the block is under construction.
385 if (!Term)
386 return true;
387
388 // If the block has no successors, there can be no instructions to hoist.
389 assert(Term->getNumSuccessors() > 0);
390
391 // Instructions should not be hoisted across exception handling boundaries.
392 return !Term->isExceptionalTerminator();
393}
394
396 const Function *F = getParent();
397 assert(F && "Block must have a parent function to use this API");
398 return this == &F->getEntryBlock();
399}
400
402 bool Before) {
403 if (Before)
404 return splitBasicBlockBefore(I, BBName);
405
406 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
407 assert(I != InstList.end() &&
408 "Trying to get me to create degenerate basic block!");
409
411 this->getNextNode());
412
413 // Save DebugLoc of split point before invalidating iterator.
414 DebugLoc Loc = I->getDebugLoc();
415 // Move all of the specified instructions from the original basic block into
416 // the new basic block.
417 New->splice(New->end(), this, I, end());
418
419 // Add a branch instruction to the newly formed basic block.
420 BranchInst *BI = BranchInst::Create(New, this);
421 BI->setDebugLoc(Loc);
422
423 // Now we must loop through all of the successors of the New block (which
424 // _were_ the successors of the 'this' block), and update any PHI nodes in
425 // successors. If there were PHI nodes in the successors, then they need to
426 // know that incoming branches will be from New, not from Old (this).
427 //
428 New->replaceSuccessorsPhiUsesWith(this, New);
429 return New;
430}
431
434 "Can't use splitBasicBlockBefore on degenerate BB!");
435 assert(I != InstList.end() &&
436 "Trying to get me to create degenerate basic block!");
437
438 assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
439 "cannot split on multi incoming phis");
440
441 BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(), this);
442 // Save DebugLoc of split point before invalidating iterator.
443 DebugLoc Loc = I->getDebugLoc();
444 // Move all of the specified instructions from the original basic block into
445 // the new basic block.
446 New->splice(New->end(), this, begin(), I);
447
448 // Loop through all of the predecessors of the 'this' block (which will be the
449 // predecessors of the New block), replace the specified successor 'this'
450 // block to point at the New block and update any PHI nodes in 'this' block.
451 // If there were PHI nodes in 'this' block, the PHI nodes are updated
452 // to reflect that the incoming branches will be from the New block and not
453 // from predecessors of the 'this' block.
454 // Save predecessors to separate vector before modifying them.
455 SmallVector<BasicBlock *, 4> Predecessors;
456 for (BasicBlock *Pred : predecessors(this))
457 Predecessors.push_back(Pred);
458 for (BasicBlock *Pred : Predecessors) {
459 Instruction *TI = Pred->getTerminator();
460 TI->replaceSuccessorWith(this, New);
461 this->replacePhiUsesWith(Pred, New);
462 }
463 // Add a branch instruction from "New" to "this" Block.
464 BranchInst *BI = BranchInst::Create(this, New);
465 BI->setDebugLoc(Loc);
466
467 return New;
468}
469
471 BasicBlock::iterator FromBeginIt,
472 BasicBlock::iterator FromEndIt) {
473#ifdef EXPENSIVE_CHECKS
474 // Check that FromBeginIt is befor FromEndIt.
475 auto FromBBEnd = FromBB->end();
476 for (auto It = FromBeginIt; It != FromEndIt; ++It)
477 assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
478#endif // EXPENSIVE_CHECKS
479 getInstList().splice(ToIt, FromBB->getInstList(), FromBeginIt, FromEndIt);
480}
481
484 return InstList.erase(FromIt, ToIt);
485}
486
488 // N.B. This might not be a complete BasicBlock, so don't assume
489 // that it ends with a non-phi instruction.
490 for (Instruction &I : *this) {
491 PHINode *PN = dyn_cast<PHINode>(&I);
492 if (!PN)
493 break;
494 PN->replaceIncomingBlockWith(Old, New);
495 }
496}
497
499 BasicBlock *New) {
501 if (!TI)
502 // Cope with being called on a BasicBlock that doesn't have a terminator
503 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
504 return;
505 for (BasicBlock *Succ : successors(TI))
506 Succ->replacePhiUsesWith(Old, New);
507}
508
510 this->replaceSuccessorsPhiUsesWith(this, New);
511}
512
514 return isa<LandingPadInst>(getFirstNonPHI());
515}
516
518 return dyn_cast<LandingPadInst>(getFirstNonPHI());
519}
520
521std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
522 const Instruction *TI = getTerminator();
523 if (MDNode *MDIrrLoopHeader =
524 TI->getMetadata(LLVMContext::MD_irr_loop)) {
525 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
526 if (MDName->getString().equals("loop_header_weight")) {
527 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
528 return std::optional<uint64_t>(CI->getValue().getZExtValue());
529 }
530 }
531 return std::nullopt;
532}
533
535 while (isa<DbgInfoIntrinsic>(It))
536 ++It;
537 return It;
538}
539
541 unsigned Order = 0;
542 for (Instruction &I : *this)
543 I.Order = Order++;
544
545 // Set the bit to indicate that the instruction order valid and cached.
546 BasicBlockBits Bits = getBasicBlockBits();
547 Bits.InstrOrderValid = true;
548 setBasicBlockBits(Bits);
549
550 NumInstrRenumberings++;
551}
552
553#ifndef NDEBUG
554/// In asserts builds, this checks the numbering. In non-asserts builds, it
555/// is defined as a no-op inline function in BasicBlock.h.
557 if (!isInstrOrderValid())
558 return;
559 const Instruction *Prev = nullptr;
560 for (const Instruction &I : *this) {
561 assert((!Prev || Prev->comesBefore(&I)) &&
562 "cached instruction ordering is incorrect");
563 Prev = &I;
564 }
565}
566#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
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:482
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:498
iterator end()
Definition: BasicBlock.h:316
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:314
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:372
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:517
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:245
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:540
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:325
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:432
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:495
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
Definition: BasicBlock.h:542
friend void Instruction::removeFromParent()
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
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:208
const Instruction & front() const
Definition: BasicBlock.h:326
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:395
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:141
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
Definition: BasicBlock.cpp:306
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:401
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:322
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:284
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:521
const CallInst * getTerminatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize prior to the terminating return in...
Definition: BasicBlock.cpp:181
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:487
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:229
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:292
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:314
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:556
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:215
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:255
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:279
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:513
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:370
const CallInst * getTerminatingMustTailCall() const
Returns the call instruction marked 'musttail' prior to the terminating return instruction of this ba...
Definition: BasicBlock.cpp:150
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:382
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:310
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:537
const CallInst * getPostdominatingDeoptimizeCall() const
Returns the call instruction calling @llvm.experimental.deoptimize that is present either in current ...
Definition: BasicBlock.cpp:196
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
Definition: BasicBlock.h:468
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:146
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
Definition: BasicBlock.cpp:341
The address of a basic block.
Definition: Constants.h:875
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:2215
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:887
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:687
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition: Function.h:682
iterator end()
Definition: Function.h:753
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:685
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:355
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:943
A single uniqued string.
Definition: Metadata.h:611
StringRef getString() const
Definition: Metadata.cpp:507
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:532
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:152
bool use_empty() const
Definition: Value.h:344
Specialization of filter_iterator_base for forward iteration only.
Definition: STLExtras.h:562
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:330
iterator erase(iterator where)
Definition: ilist.h:268
pointer remove(iterator &IT)
Definition: ilist.h:252
void clear()
Definition: ilist.h:310
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:721
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:2337
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:534
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:2312
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:637
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)
Wrapper function around std::find to detect if an element exists in a container.
Definition: STLExtras.h:1869
#define N