LLVM 18.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
224 return getFirstNonPHI()->getIterator();
225}
226
227const Instruction *BasicBlock::getFirstNonPHIOrDbg(bool SkipPseudoOp) const {
228 for (const Instruction &I : *this) {
229 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
230 continue;
231
232 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
233 continue;
234
235 return &I;
236 }
237 return nullptr;
238}
239
240const Instruction *
242 for (const Instruction &I : *this) {
243 if (isa<PHINode>(I) || isa<DbgInfoIntrinsic>(I))
244 continue;
245
246 if (I.isLifetimeStartOrEnd())
247 continue;
248
249 if (SkipPseudoOp && isa<PseudoProbeInst>(I))
250 continue;
251
252 return &I;
253 }
254 return nullptr;
255}
256
258 const Instruction *FirstNonPHI = getFirstNonPHI();
259 if (!FirstNonPHI)
260 return end();
261
262 const_iterator InsertPt = FirstNonPHI->getIterator();
263 if (InsertPt->isEHPad()) ++InsertPt;
264 return InsertPt;
265}
266
268 const Instruction *FirstNonPHI = getFirstNonPHI();
269 if (!FirstNonPHI)
270 return end();
271
272 const_iterator InsertPt = FirstNonPHI->getIterator();
273 if (InsertPt->isEHPad())
274 ++InsertPt;
275
276 if (isEntryBlock()) {
278 while (InsertPt != End &&
279 (isa<AllocaInst>(*InsertPt) || isa<DbgInfoIntrinsic>(*InsertPt) ||
280 isa<PseudoProbeInst>(*InsertPt))) {
281 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&*InsertPt)) {
282 if (!AI->isStaticAlloca())
283 break;
284 }
285 ++InsertPt;
286 }
287 }
288 return InsertPt;
289}
290
292 for (Instruction &I : *this)
293 I.dropAllReferences();
294}
295
297 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
298 if (PI == E) return nullptr; // No preds.
299 const BasicBlock *ThePred = *PI;
300 ++PI;
301 return (PI == E) ? ThePred : nullptr /*multiple preds*/;
302}
303
305 const_pred_iterator PI = pred_begin(this), E = pred_end(this);
306 if (PI == E) return nullptr; // No preds.
307 const BasicBlock *PredBB = *PI;
308 ++PI;
309 for (;PI != E; ++PI) {
310 if (*PI != PredBB)
311 return nullptr;
312 // The same predecessor appears multiple times in the predecessor list.
313 // This is OK.
314 }
315 return PredBB;
316}
317
318bool BasicBlock::hasNPredecessors(unsigned N) const {
319 return hasNItems(pred_begin(this), pred_end(this), N);
320}
321
323 return hasNItemsOrMore(pred_begin(this), pred_end(this), N);
324}
325
327 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
328 if (SI == E) return nullptr; // no successors
329 const BasicBlock *TheSucc = *SI;
330 ++SI;
331 return (SI == E) ? TheSucc : nullptr /* multiple successors */;
332}
333
335 const_succ_iterator SI = succ_begin(this), E = succ_end(this);
336 if (SI == E) return nullptr; // No successors
337 const BasicBlock *SuccBB = *SI;
338 ++SI;
339 for (;SI != E; ++SI) {
340 if (*SI != SuccBB)
341 return nullptr;
342 // The same successor appears multiple times in the successor list.
343 // This is OK.
344 }
345 return SuccBB;
346}
347
349 PHINode *P = empty() ? nullptr : dyn_cast<PHINode>(&*begin());
350 return make_range<phi_iterator>(P, nullptr);
351}
352
354 bool KeepOneInputPHIs) {
355 // Use hasNUsesOrMore to bound the cost of this assertion for complex CFGs.
357 "Pred is not a predecessor!");
358
359 // Return early if there are no PHI nodes to update.
360 if (empty() || !isa<PHINode>(begin()))
361 return;
362
363 unsigned NumPreds = cast<PHINode>(front()).getNumIncomingValues();
364 for (PHINode &Phi : make_early_inc_range(phis())) {
365 Phi.removeIncomingValue(Pred, !KeepOneInputPHIs);
366 if (KeepOneInputPHIs)
367 continue;
368
369 // If we have a single predecessor, removeIncomingValue may have erased the
370 // PHI node itself.
371 if (NumPreds == 1)
372 continue;
373
374 // Try to replace the PHI node with a constant value.
375 if (Value *PhiConstant = Phi.hasConstantValue()) {
376 Phi.replaceAllUsesWith(PhiConstant);
377 Phi.eraseFromParent();
378 }
379 }
380}
381
383 const Instruction *FirstNonPHI = getFirstNonPHI();
384 if (isa<LandingPadInst>(FirstNonPHI))
385 return true;
386 // This is perhaps a little conservative because constructs like
387 // CleanupBlockInst are pretty easy to split. However, SplitBlockPredecessors
388 // cannot handle such things just yet.
389 if (FirstNonPHI->isEHPad())
390 return false;
391 return true;
392}
393
395 auto *Term = getTerminator();
396 // No terminator means the block is under construction.
397 if (!Term)
398 return true;
399
400 // If the block has no successors, there can be no instructions to hoist.
401 assert(Term->getNumSuccessors() > 0);
402
403 // Instructions should not be hoisted across special terminators, which may
404 // have side effects or return values.
405 return !Term->isSpecialTerminator();
406}
407
409 const Function *F = getParent();
410 assert(F && "Block must have a parent function to use this API");
411 return this == &F->getEntryBlock();
412}
413
415 bool Before) {
416 if (Before)
417 return splitBasicBlockBefore(I, BBName);
418
419 assert(getTerminator() && "Can't use splitBasicBlock on degenerate BB!");
420 assert(I != InstList.end() &&
421 "Trying to get me to create degenerate basic block!");
422
424 this->getNextNode());
425
426 // Save DebugLoc of split point before invalidating iterator.
427 DebugLoc Loc = I->getDebugLoc();
428 // Move all of the specified instructions from the original basic block into
429 // the new basic block.
430 New->splice(New->end(), this, I, end());
431
432 // Add a branch instruction to the newly formed basic block.
433 BranchInst *BI = BranchInst::Create(New, this);
434 BI->setDebugLoc(Loc);
435
436 // Now we must loop through all of the successors of the New block (which
437 // _were_ the successors of the 'this' block), and update any PHI nodes in
438 // successors. If there were PHI nodes in the successors, then they need to
439 // know that incoming branches will be from New, not from Old (this).
440 //
441 New->replaceSuccessorsPhiUsesWith(this, New);
442 return New;
443}
444
447 "Can't use splitBasicBlockBefore on degenerate BB!");
448 assert(I != InstList.end() &&
449 "Trying to get me to create degenerate basic block!");
450
451 assert((!isa<PHINode>(*I) || getSinglePredecessor()) &&
452 "cannot split on multi incoming phis");
453
454 BasicBlock *New = BasicBlock::Create(getContext(), BBName, getParent(), this);
455 // Save DebugLoc of split point before invalidating iterator.
456 DebugLoc Loc = I->getDebugLoc();
457 // Move all of the specified instructions from the original basic block into
458 // the new basic block.
459 New->splice(New->end(), this, begin(), I);
460
461 // Loop through all of the predecessors of the 'this' block (which will be the
462 // predecessors of the New block), replace the specified successor 'this'
463 // block to point at the New block and update any PHI nodes in 'this' block.
464 // If there were PHI nodes in 'this' block, the PHI nodes are updated
465 // to reflect that the incoming branches will be from the New block and not
466 // from predecessors of the 'this' block.
467 // Save predecessors to separate vector before modifying them.
468 SmallVector<BasicBlock *, 4> Predecessors;
469 for (BasicBlock *Pred : predecessors(this))
470 Predecessors.push_back(Pred);
471 for (BasicBlock *Pred : Predecessors) {
472 Instruction *TI = Pred->getTerminator();
473 TI->replaceSuccessorWith(this, New);
474 this->replacePhiUsesWith(Pred, New);
475 }
476 // Add a branch instruction from "New" to "this" Block.
477 BranchInst *BI = BranchInst::Create(this, New);
478 BI->setDebugLoc(Loc);
479
480 return New;
481}
482
484 BasicBlock::iterator FromBeginIt,
485 BasicBlock::iterator FromEndIt) {
486#ifdef EXPENSIVE_CHECKS
487 // Check that FromBeginIt is befor FromEndIt.
488 auto FromBBEnd = FromBB->end();
489 for (auto It = FromBeginIt; It != FromEndIt; ++It)
490 assert(It != FromBBEnd && "FromBeginIt not before FromEndIt!");
491#endif // EXPENSIVE_CHECKS
492 getInstList().splice(ToIt, FromBB->getInstList(), FromBeginIt, FromEndIt);
493}
494
497 return InstList.erase(FromIt, ToIt);
498}
499
501 // N.B. This might not be a complete BasicBlock, so don't assume
502 // that it ends with a non-phi instruction.
503 for (Instruction &I : *this) {
504 PHINode *PN = dyn_cast<PHINode>(&I);
505 if (!PN)
506 break;
507 PN->replaceIncomingBlockWith(Old, New);
508 }
509}
510
512 BasicBlock *New) {
514 if (!TI)
515 // Cope with being called on a BasicBlock that doesn't have a terminator
516 // yet. Clang's CodeGenFunction::EmitReturnBlock() likes to do this.
517 return;
518 for (BasicBlock *Succ : successors(TI))
519 Succ->replacePhiUsesWith(Old, New);
520}
521
523 this->replaceSuccessorsPhiUsesWith(this, New);
524}
525
527 return isa<LandingPadInst>(getFirstNonPHI());
528}
529
531 return dyn_cast<LandingPadInst>(getFirstNonPHI());
532}
533
534std::optional<uint64_t> BasicBlock::getIrrLoopHeaderWeight() const {
535 const Instruction *TI = getTerminator();
536 if (MDNode *MDIrrLoopHeader =
537 TI->getMetadata(LLVMContext::MD_irr_loop)) {
538 MDString *MDName = cast<MDString>(MDIrrLoopHeader->getOperand(0));
539 if (MDName->getString().equals("loop_header_weight")) {
540 auto *CI = mdconst::extract<ConstantInt>(MDIrrLoopHeader->getOperand(1));
541 return std::optional<uint64_t>(CI->getValue().getZExtValue());
542 }
543 }
544 return std::nullopt;
545}
546
548 while (isa<DbgInfoIntrinsic>(It))
549 ++It;
550 return It;
551}
552
554 unsigned Order = 0;
555 for (Instruction &I : *this)
556 I.Order = Order++;
557
558 // Set the bit to indicate that the instruction order valid and cached.
559 BasicBlockBits Bits = getBasicBlockBits();
560 Bits.InstrOrderValid = true;
561 setBasicBlockBits(Bits);
562
563 NumInstrRenumberings++;
564}
565
566#ifndef NDEBUG
567/// In asserts builds, this checks the numbering. In non-asserts builds, it
568/// is defined as a no-op inline function in BasicBlock.h.
570 if (!isInstrOrderValid())
571 return;
572 const Instruction *Prev = nullptr;
573 for (const Instruction &I : *this) {
574 assert((!Prev || Prev->comesBefore(&I)) &&
575 "cached instruction ordering is incorrect");
576 Prev = &I;
577 }
578}
579#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:469
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)
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:495
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:511
iterator end()
Definition: BasicBlock.h:337
iterator begin()
Instruction iterator methods.
Definition: BasicBlock.h:335
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
Definition: BasicBlock.h:393
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Definition: BasicBlock.cpp:530
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:257
void renumberInstructions()
Renumber instructions and mark the ordering as valid.
Definition: BasicBlock.cpp:553
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:346
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:445
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
Definition: BasicBlock.h:516
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
Definition: BasicBlock.cpp:223
void invalidateOrders()
Mark instruction ordering invalid. Done on every instruction insert.
Definition: BasicBlock.h:563
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:347
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:408
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:318
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:414
const BasicBlock * getUniqueSuccessor() const
Return the successor of this block if it has a unique successor.
Definition: BasicBlock.cpp:334
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:296
std::optional< uint64_t > getIrrLoopHeaderWeight() const
Definition: BasicBlock.cpp:534
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:500
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:241
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Definition: BasicBlock.cpp:304
const BasicBlock * getSingleSuccessor() const
Return the successor of this block if it has a single successor.
Definition: BasicBlock.cpp:326
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:569
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:227
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:267
void dropAllReferences()
Cause all subinstructions to "let go" of all the references that said subinstructions are maintaining...
Definition: BasicBlock.cpp:291
void moveBefore(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it into the function that MovePos lives ...
Definition: BasicBlock.h:263
bool isLandingPad() const
Return true if this basic block is a landing pad.
Definition: BasicBlock.cpp:526
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:382
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:394
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
Definition: BasicBlock.cpp:322
bool isInstrOrderValid() const
Returns true if the Order field of child Instructions is valid.
Definition: BasicBlock.h:558
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:489
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:353
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:699
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
Definition: Function.h:694
iterator end()
Definition: Function.h:765
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:734
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:302
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:389
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:366
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Definition: SmallPtrSet.h:451
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:507
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:666
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:2422
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:547
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:2397
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:582
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:1884
#define N