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