LLVM 23.0.0git
ADCE.cpp
Go to the documentation of this file.
1//===- ADCE.cpp - Code to perform dead code elimination -------------------===//
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 Aggressive Dead Code Elimination pass. This pass
10// optimistically assumes that all instructions are dead until proven otherwise,
11// allowing it to eliminate dead computations that other DCE passes do not
12// catch, particularly involving loop computations.
13//
14//===----------------------------------------------------------------------===//
15
17#include "llvm/ADT/DenseMap.h"
21#include "llvm/ADT/SetVector.h"
24#include "llvm/ADT/Statistic.h"
25#include "llvm/Analysis/CFG.h"
31#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/CFG.h"
33#include "llvm/IR/DebugInfo.h"
35#include "llvm/IR/DebugLoc.h"
36#include "llvm/IR/Dominators.h"
37#include "llvm/IR/Function.h"
38#include "llvm/IR/IRBuilder.h"
40#include "llvm/IR/Instruction.h"
43#include "llvm/IR/PassManager.h"
44#include "llvm/IR/Use.h"
45#include "llvm/IR/Value.h"
49#include "llvm/Support/Debug.h"
52#include <cassert>
53#include <cstddef>
54#include <utility>
55
56using namespace llvm;
57
58#define DEBUG_TYPE "adce"
59
60STATISTIC(NumRemoved, "Number of instructions removed");
61STATISTIC(NumBranchesRemoved, "Number of branch instructions removed");
62
63// This is a temporary option until we change the interface to this pass based
64// on optimization level.
65static cl::opt<bool> RemoveControlFlowFlag("adce-remove-control-flow",
66 cl::init(true), cl::Hidden);
67
68// This option enables removing of may-be-infinite loops which have no other
69// effect.
70static cl::opt<bool> RemoveLoops("adce-remove-loops", cl::init(false),
72
73namespace {
74
75/// Information about basic blocks relevant to dead code elimination.
76struct BlockInfoType {
77 /// True when this block contains a live instructions.
78 bool Live = false;
79
80 /// True when this block is known to have live PHI nodes.
81 bool HasLivePhiNodes = false;
82
83 /// Control dependence sources need to be live for this block.
84 bool CFLive = false;
85
86 /// Post-order numbering of reverse control flow graph.
87 unsigned PostOrder = 0;
88};
89
90struct ADCEChanged {
91 bool ChangedAnything = false;
92 bool ChangedNonDebugInstr = false;
93 bool ChangedControlFlow = false;
94};
95
96class AggressiveDeadCodeElimination {
97 Function &F;
98
99 // ADCE does not use DominatorTree per se, but it updates it to preserve the
100 // analysis.
101 DominatorTree *DT;
102 PostDominatorTree &PDT;
103
104 /// Mapping of blocks to associated information, indexed by block number.
106
107 /// Set of live instructions.
108 SmallPtrSet<Instruction *, 32> LiveInst;
109 bool isLive(Instruction *I) { return LiveInst.contains(I); }
110
111 /// Instructions known to be live where we need to mark
112 /// reaching definitions as live.
114
115 /// Debug info scopes around a live instruction.
116 SmallPtrSet<const Metadata *, 32> AliveScopes;
117
118 /// Set of blocks with not known to have live terminators.
119 SmallSetVector<BasicBlock *, 16> BlocksWithDeadTerminators;
120
121 /// The set of blocks which we have determined whose control
122 /// dependence sources must be live and which have not had
123 /// those dependences analyzed.
124 SmallPtrSet<BasicBlock *, 16> NewLiveBlocks;
125
126 /// Set up auxiliary data structures for Instructions and BasicBlocks and
127 /// initialize the Worklist to the set of must-be-live Instruscions.
128 void initialize();
129
130 BlockInfoType &getBlockInfo(BasicBlock *BB) {
131 return BlockInfo[BB->getNumber()];
132 }
133
134 /// Return true for operations which are always treated as live.
135 bool isAlwaysLive(Instruction &I);
136
137 /// Return true for instrumentation instructions for value profiling.
138 bool isInstrumentsConstant(Instruction &I);
139
140 /// Propagate liveness to reaching definitions.
141 void markLiveInstructions();
142
143 /// Mark an instruction as live.
144 void markLive(Instruction *I);
145
146 /// Mark a block as live.
147 void markLive(BasicBlock *BB);
148
149 /// Mark terminators of control predecessors of a PHI node live.
150 void markPhiLive(PHINode *PN);
151
152 /// Record the Debug Scopes which surround live debug information.
153 void collectLiveScopes(const DILocalScope &LS);
154 void collectLiveScopes(const DILocation &DL);
155
156 /// Analyze dead branches to find those whose branches are the sources
157 /// of control dependences impacting a live block. Those branches are
158 /// marked live.
159 void markLiveBranchesFromControlDependences();
160
161 /// Remove instructions not marked live, return if any instruction was
162 /// removed.
163 ADCEChanged removeDeadInstructions();
164
165 /// Identify connected sections of the control flow graph which have
166 /// dead terminators and rewrite the control flow graph to remove them.
167 bool updateDeadRegions();
168
169 /// Set the BlockInfo::PostOrder field based on a post-order
170 /// numbering of the reverse control flow graph.
171 void computeReversePostOrder();
172
173 /// Make the terminator of this block an unconditional branch to \p Target.
174 void makeUnconditional(BasicBlock *BB, BasicBlock *Target);
175
176public:
177 AggressiveDeadCodeElimination(Function &F, DominatorTree *DT,
178 PostDominatorTree &PDT)
179 : F(F), DT(DT), PDT(PDT) {}
180
181 ADCEChanged performDeadCodeElimination();
182};
183
184} // end anonymous namespace
185
186ADCEChanged AggressiveDeadCodeElimination::performDeadCodeElimination() {
187 initialize();
188 markLiveInstructions();
189 return removeDeadInstructions();
190}
191
192void AggressiveDeadCodeElimination::initialize() {
193 BlockInfo.resize(F.getMaxBlockNumber());
194 size_t NumInsts = 0;
195 for (auto &BB : F)
196 NumInsts += BB.size();
197 LiveInst.reserve(NumInsts);
198
199 // Collect the set of "root" instructions that are known live.
200 for (Instruction &I : instructions(F))
201 if (isAlwaysLive(I))
202 markLive(&I);
203
205 return;
206
207 if (!RemoveLoops) {
208 // Mark all terminators that have backedges as live.
210 FindFunctionBackedges(F, Backedges);
211 for (const auto &[Src, Dst] : Backedges)
212 markLive(const_cast<Instruction *>(Src->getTerminator()));
213 }
214
215 // Mark blocks live if there is no path from the block to a
216 // return of the function.
217 // We do this by seeing which of the postdomtree root children exit the
218 // program, and for all others, mark the subtree live.
219 for (const auto &PDTChild : children<DomTreeNode *>(PDT.getRootNode())) {
220 auto *BB = PDTChild->getBlock();
221 // Real function return
222 if (isa<ReturnInst>(BB->back())) {
223 LLVM_DEBUG(dbgs() << "post-dom root child is a return: " << BB->getName()
224 << '\n';);
225 continue;
226 }
227
228 // This child is something else, like an infinite loop.
229 for (auto *DFNode : depth_first(PDTChild))
230 markLive(&DFNode->getBlock()->back());
231 }
232
233 // Treat the entry block as always live
234 auto *BB = &F.getEntryBlock();
235 auto &EntryInfo = getBlockInfo(BB);
236 EntryInfo.Live = true;
237 if (isa<UncondBrInst>(BB->back()))
238 markLive(&BB->back());
239
240 // Build initial collection of blocks with dead terminators
241 for (auto &BB : F)
242 if (!isLive(&BB.back()))
243 BlocksWithDeadTerminators.insert(&BB);
244}
245
246bool AggressiveDeadCodeElimination::isAlwaysLive(Instruction &I) {
247 // TODO -- use llvm::isInstructionTriviallyDead
248 if (I.isEHPad() || I.mayHaveSideEffects()) {
249 // Skip any value profile instrumentation calls if they are
250 // instrumenting constants.
251 if (isInstrumentsConstant(I))
252 return false;
253 return true;
254 }
255 if (!I.isTerminator())
256 return false;
258 return false;
259 return true;
260}
261
262// Check if this instruction is a runtime call for value profiling and
263// if it's instrumenting a constant.
264bool AggressiveDeadCodeElimination::isInstrumentsConstant(Instruction &I) {
265 // TODO -- move this test into llvm::isInstructionTriviallyDead
266 if (CallInst *CI = dyn_cast<CallInst>(&I))
267 if (Function *Callee = CI->getCalledFunction())
268 if (Callee->getName() == getInstrProfValueProfFuncName())
269 if (isa<Constant>(CI->getArgOperand(0)))
270 return true;
271 return false;
272}
273
274void AggressiveDeadCodeElimination::markLiveInstructions() {
275 // Propagate liveness backwards to operands.
276 do {
277 // Worklist holds newly discovered live instructions
278 // where we need to mark the inputs as live.
279 while (!Worklist.empty()) {
280 Instruction *LiveInst = Worklist.pop_back_val();
281 LLVM_DEBUG(dbgs() << "work live: "; LiveInst->dump(););
282
283 for (Use &OI : LiveInst->operands())
284 if (Instruction *Inst = dyn_cast<Instruction>(OI))
285 markLive(Inst);
286
287 if (auto *PN = dyn_cast<PHINode>(LiveInst))
288 markPhiLive(PN);
289 }
290
291 // After data flow liveness has been identified, examine which branch
292 // decisions are required to determine live instructions are executed.
293 markLiveBranchesFromControlDependences();
294
295 } while (!Worklist.empty());
296}
297
298void AggressiveDeadCodeElimination::markLive(Instruction *I) {
299 auto [It, Inserted] = LiveInst.insert(I);
300 if (!Inserted)
301 return;
302
303 LLVM_DEBUG(dbgs() << "mark live: "; I->dump());
304 Worklist.push_back(I);
305
306 // Collect the live debug info scopes attached to this instruction.
307 if (const DILocation *DL = I->getDebugLoc())
308 collectLiveScopes(*DL);
309
310 // Mark the containing block live
311 BasicBlock *BB = I->getParent();
312 if (I == &BB->back()) {
313 BlocksWithDeadTerminators.remove(BB);
314 // For live terminators, mark destination blocks
315 // live to preserve this control flow edges.
316 if (!isa<UncondBrInst>(I))
317 for (auto *Succ : I->successors())
318 markLive(Succ);
319 }
320 markLive(BB);
321}
322
323void AggressiveDeadCodeElimination::markLive(BasicBlock *BB) {
324 auto &BBInfo = BlockInfo[BB->getNumber()];
325 if (BBInfo.Live)
326 return;
327 LLVM_DEBUG(dbgs() << "mark block live: " << BB->getName() << '\n');
328 BBInfo.Live = true;
329 if (!BBInfo.CFLive) {
330 BBInfo.CFLive = true;
331 NewLiveBlocks.insert(BB);
332 }
333
334 // Mark unconditional branches at the end of live
335 // blocks as live since there is no work to do for them later
336 if (isa<UncondBrInst>(BB->back()))
337 markLive(&BB->back());
338}
339
340void AggressiveDeadCodeElimination::collectLiveScopes(const DILocalScope &LS) {
341 if (!AliveScopes.insert(&LS).second)
342 return;
343
344 if (isa<DISubprogram>(LS))
345 return;
346
347 // Tail-recurse through the scope chain.
348 collectLiveScopes(cast<DILocalScope>(*LS.getScope()));
349}
350
351void AggressiveDeadCodeElimination::collectLiveScopes(const DILocation &DL) {
352 // Even though DILocations are not scopes, shove them into AliveScopes so we
353 // don't revisit them.
354 if (!AliveScopes.insert(&DL).second)
355 return;
356
357 // Collect live scopes from the scope chain.
358 collectLiveScopes(*DL.getScope());
359
360 // Tail-recurse through the inlined-at chain.
361 if (const DILocation *IA = DL.getInlinedAt())
362 collectLiveScopes(*IA);
363}
364
365void AggressiveDeadCodeElimination::markPhiLive(PHINode *PN) {
366 auto &Info = getBlockInfo(PN->getParent());
367 // Only need to check this once per block.
368 if (Info.HasLivePhiNodes)
369 return;
370 Info.HasLivePhiNodes = true;
371
372 // If a predecessor block is not live, mark it as control-flow live
373 // which will trigger marking live branches upon which
374 // that block is control dependent.
375 for (auto *PredBB : predecessors(PN->getParent())) {
376 auto &Info = getBlockInfo(PredBB);
377 if (!Info.CFLive) {
378 Info.CFLive = true;
379 NewLiveBlocks.insert(PredBB);
380 }
381 }
382}
383
384void AggressiveDeadCodeElimination::markLiveBranchesFromControlDependences() {
385 if (BlocksWithDeadTerminators.empty())
386 return;
387
388 LLVM_DEBUG({
389 dbgs() << "new live blocks:\n";
390 for (auto *BB : NewLiveBlocks)
391 dbgs() << "\t" << BB->getName() << '\n';
392 dbgs() << "dead terminator blocks:\n";
393 for (auto *BB : BlocksWithDeadTerminators)
394 dbgs() << "\t" << BB->getName() << '\n';
395 });
396
397 // The dominance frontier of a live block X in the reverse
398 // control graph is the set of blocks upon which X is control
399 // dependent. The following sequence computes the set of blocks
400 // which currently have dead terminators that are control
401 // dependence sources of a block which is in NewLiveBlocks.
402
403 const SmallPtrSet<BasicBlock *, 16> BWDT(llvm::from_range,
404 BlocksWithDeadTerminators);
406 ReverseIDFCalculator IDFs(PDT);
407 IDFs.setDefiningBlocks(NewLiveBlocks);
408 IDFs.setLiveInBlocks(BWDT);
409 IDFs.calculate(IDFBlocks);
410 NewLiveBlocks.clear();
411
412 // Dead terminators which control live blocks are now marked live.
413 for (auto *BB : IDFBlocks) {
414 LLVM_DEBUG(dbgs() << "live control in: " << BB->getName() << '\n');
415 markLive(BB->getTerminator());
416 }
417}
418
419//===----------------------------------------------------------------------===//
420//
421// Routines to update the CFG and SSA information before removing dead code.
422//
423//===----------------------------------------------------------------------===//
424ADCEChanged AggressiveDeadCodeElimination::removeDeadInstructions() {
425 ADCEChanged Changed;
426 // Updates control and dataflow around dead blocks
427 Changed.ChangedControlFlow = updateDeadRegions();
428
429 LLVM_DEBUG({
430 for (Instruction &I : instructions(F)) {
431 // Check if the instruction is alive.
432 if (isLive(&I))
433 continue;
434
435 if (auto *DII = dyn_cast<DbgVariableIntrinsic>(&I)) {
436 // Check if the scope of this variable location is alive.
437 if (AliveScopes.count(DII->getDebugLoc()->getScope()))
438 continue;
439
440 // If intrinsic is pointing at a live SSA value, there may be an
441 // earlier optimization bug: if we know the location of the variable,
442 // why isn't the scope of the location alive?
443 for (Value *V : DII->location_ops()) {
444 if (Instruction *II = dyn_cast<Instruction>(V)) {
445 if (isLive(II)) {
446 dbgs() << "Dropping debug info for " << *DII << "\n";
447 break;
448 }
449 }
450 }
451 }
452 }
453 });
454
455 // The inverse of the live set is the dead set. These are those instructions
456 // that have no side effects and do not influence the control flow or return
457 // value of the function, and may therefore be deleted safely.
458 // NOTE: We reuse the Worklist vector here for memory efficiency.
459 for (Instruction &I : llvm::reverse(instructions(F))) {
460 // With "RemoveDIs" debug-info stored in DbgVariableRecord objects,
461 // debug-info attached to this instruction, and drop any for scopes that
462 // aren't alive, like the rest of this loop does. Extending support to
463 // assignment tracking is future work.
464 for (DbgRecord &DR : make_early_inc_range(I.getDbgRecordRange())) {
465 // Avoid removing a DVR that is linked to instructions because it holds
466 // information about an existing store.
467 if (DbgVariableRecord *DVR = dyn_cast<DbgVariableRecord>(&DR);
468 DVR && DVR->isDbgAssign())
469 if (!at::getAssignmentInsts(DVR).empty())
470 continue;
471 if (AliveScopes.count(DR.getDebugLoc()->getScope()))
472 continue;
473 I.dropOneDbgRecord(&DR);
474 }
475
476 // Check if the instruction is alive.
477 if (isLive(&I))
478 continue;
479
480 Changed.ChangedNonDebugInstr = true;
481
482 // Prepare to delete.
483 Worklist.push_back(&I);
485 }
486
487 for (Instruction *&I : Worklist)
488 I->dropAllReferences();
489
490 for (Instruction *&I : Worklist) {
491 ++NumRemoved;
492 I->eraseFromParent();
493 }
494
495 Changed.ChangedAnything = Changed.ChangedControlFlow || !Worklist.empty();
496
497 return Changed;
498}
499
500// A dead region is the set of dead blocks with a common live post-dominator.
501bool AggressiveDeadCodeElimination::updateDeadRegions() {
502 LLVM_DEBUG({
503 dbgs() << "final dead terminator blocks: " << '\n';
504 for (auto *BB : BlocksWithDeadTerminators)
505 dbgs() << '\t' << BB->getName()
506 << (getBlockInfo(BB).Live ? " LIVE\n" : "\n");
507 });
508
509 // Don't compute the post ordering unless we needed it.
510 bool HavePostOrder = false;
511 bool Changed = false;
513
514 for (auto *BB : BlocksWithDeadTerminators) {
515 if (isa<UncondBrInst>(BB->back())) {
516 LiveInst.insert(&BB->back());
517 continue;
518 }
519
520 if (!HavePostOrder) {
521 computeReversePostOrder();
522 HavePostOrder = true;
523 }
524
525 // Add an unconditional branch to the successor closest to the
526 // end of the function which insures a path to the exit for each
527 // live edge.
528 BasicBlock *PreferredSucc = nullptr;
529 unsigned PreferredSuccPostOrder = 0;
530 for (auto *Succ : successors(BB)) {
531 unsigned SuccPostOrder = BlockInfo[Succ->getNumber()].PostOrder;
532 if (PreferredSuccPostOrder < SuccPostOrder) {
533 PreferredSucc = Succ;
534 PreferredSuccPostOrder = SuccPostOrder;
535 }
536 }
537 assert((PreferredSucc && PreferredSuccPostOrder > 0) &&
538 "Failed to find safe successor for dead branch");
539
540 // Collect removed successors to update the (Post)DominatorTrees.
541 SmallPtrSet<BasicBlock *, 4> RemovedSuccessors;
542 bool First = true;
543 for (auto *Succ : successors(BB)) {
544 if (!First || Succ != PreferredSucc) {
545 Succ->removePredecessor(BB);
546 RemovedSuccessors.insert(Succ);
547 } else
548 First = false;
549 }
550 makeUnconditional(BB, PreferredSucc);
551
552 // Inform the dominators about the deleted CFG edges.
553 for (auto *Succ : RemovedSuccessors) {
554 // It might have happened that the same successor appeared multiple times
555 // and the CFG edge wasn't really removed.
556 if (Succ != PreferredSucc) {
557 LLVM_DEBUG(dbgs() << "ADCE: (Post)DomTree edge enqueued for deletion"
558 << BB->getName() << " -> " << Succ->getName()
559 << "\n");
560 DeletedEdges.push_back({DominatorTree::Delete, BB, Succ});
561 }
562 }
563
564 NumBranchesRemoved += 1;
565 Changed = true;
566 }
567
568 if (!DeletedEdges.empty())
569 DomTreeUpdater(DT, &PDT, DomTreeUpdater::UpdateStrategy::Eager)
570 .applyUpdates(DeletedEdges);
571
572 return Changed;
573}
574
575// reverse top-sort order
576void AggressiveDeadCodeElimination::computeReversePostOrder() {
577 // This provides a post-order numbering of the reverse control flow graph
578 // Note that it is incomplete in the presence of infinite loops but we don't
579 // need numbers blocks which don't reach the end of the functions since
580 // all branches in those blocks are forced live.
581
582 // For each block without successors, extend the DFS from the block
583 // backward through the graph
584 SmallPtrSet<BasicBlock*, 16> Visited;
585 unsigned PostOrder = 0;
586 for (auto &BB : F) {
587 if (!succ_empty(&BB))
588 continue;
589 for (BasicBlock *Block : inverse_post_order_ext(&BB,Visited))
590 getBlockInfo(Block).PostOrder = PostOrder++;
591 }
592}
593
594void AggressiveDeadCodeElimination::makeUnconditional(BasicBlock *BB,
595 BasicBlock *Target) {
596 Instruction *PredTerm = BB->getTerminator();
597 // Collect the live debug info scopes attached to this instruction.
598 if (const DILocation *DL = PredTerm->getDebugLoc())
599 collectLiveScopes(*DL);
600
601 // Just mark live an existing unconditional branch
602 if (auto *BI = dyn_cast<UncondBrInst>(PredTerm)) {
603 BI->setSuccessor(Target);
604 LiveInst.insert(PredTerm);
605 return;
606 }
607 LLVM_DEBUG(dbgs() << "making unconditional " << BB->getName() << '\n');
608 NumBranchesRemoved += 1;
609 IRBuilder<> Builder(PredTerm);
610 auto *NewTerm = Builder.CreateBr(Target);
611 LiveInst.insert(NewTerm);
612 if (const DILocation *DL = PredTerm->getDebugLoc())
613 NewTerm->setDebugLoc(DL);
614 PredTerm->eraseFromParent();
615}
616
617//===----------------------------------------------------------------------===//
618//
619// Pass Manager integration code
620//
621//===----------------------------------------------------------------------===//
623 // ADCE does not need DominatorTree, but require DominatorTree here
624 // to update analysis if it is already available.
625 auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(F);
626 auto &PDT = FAM.getResult<PostDominatorTreeAnalysis>(F);
627 ADCEChanged Changed =
628 AggressiveDeadCodeElimination(F, DT, PDT).performDeadCodeElimination();
629 if (!Changed.ChangedAnything)
630 return PreservedAnalyses::all();
631
633 if (!Changed.ChangedControlFlow) {
635 if (!Changed.ChangedNonDebugInstr) {
636 // Only removing debug instructions does not affect MemorySSA.
637 //
638 // Therefore we preserve MemorySSA when only removing debug instructions
639 // since otherwise later passes may behave differently which then makes
640 // the presence of debug info affect code generation.
642 }
643 }
646
647 return PA;
648}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< bool > RemoveLoops("adce-remove-loops", cl::init(false), cl::Hidden)
static cl::opt< bool > RemoveControlFlowFlag("adce-remove-control-flow", cl::init(true), cl::Hidden)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static bool isAlwaysLive(Instruction *I)
This file defines the DenseMap class.
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
This is the interface for a simple mod/ref and alias analysis over globals.
This file defines the little GraphTraits<X> template class that should be specialized by classes that...
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
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:171
#define LLVM_DEBUG(...)
Definition Debug.h:114
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
unsigned getNumber() const
Definition BasicBlock.h:95
const Instruction & back() const
Definition BasicBlock.h:486
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Definition BasicBlock.h:237
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Analysis pass which computes a DominatorTree.
Definition Dominators.h:278
DomTreeNodeBase< NodeT > * getRootNode()
getRootNode - This returns the entry node for the CFG of the function.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
An analysis that produces MemorySSA for a function.
Definition MemorySSA.h:922
Analysis pass which computes a PostDominatorTree.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
void reserve(size_type NewNumEntries)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void resize(size_type N)
void push_back(const T &Elt)
op_range operands()
Definition User.h:267
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:322
LLVM_ABI void dump() const
Support for debugging, callable in GDB: V->dump()
const ParentTy * getParent() const
Definition ilist_node.h:34
Changed
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
LLVM_ABI AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
initializer< Ty > init(const Ty &Val)
bool empty() const
Definition BasicBlock.h:101
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
bool succ_empty(const Instruction *I)
Definition CFG.h:153
iterator_range< ipo_ext_iterator< T, SetType > > inverse_post_order_ext(const T &G, SetType &S)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
Definition Utils.cpp:1725
auto successors(const MachineBasicBlock *BB)
constexpr from_range_t from_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition STLExtras.h:634
auto reverse(ContainerTy &&C)
Definition STLExtras.h:408
IDFCalculator< true > ReverseIDFCalculator
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
Definition ModRef.h:74
IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
auto predecessors(const MachineBasicBlock *BB)
StringRef getInstrProfValueProfFuncName()
Return the name profile runtime entry point to do value profiling for a given site.
Definition InstrProf.h:112
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
iterator_range< df_iterator< T > > depth_first(const T &G)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void FindFunctionBackedges(const Function &F, SmallVectorImpl< std::pair< const BasicBlock *, const BasicBlock * > > &Result)
Analyze the specified function to find all of the loop backedges in the function and return them.
Definition CFG.cpp:36
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Definition ADCE.cpp:622