MLIR 23.0.0git
DeadCodeAnalysis.cpp
Go to the documentation of this file.
1//===- DeadCodeAnalysis.cpp - Dead code analysis --------------------------===//
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
13#include "mlir/IR/Attributes.h"
14#include "mlir/IR/Block.h"
15#include "mlir/IR/Diagnostics.h"
16#include "mlir/IR/Location.h"
17#include "mlir/IR/Operation.h"
19#include "mlir/IR/SymbolTable.h"
20#include "mlir/IR/Value.h"
21#include "mlir/IR/ValueRange.h"
24#include "mlir/Support/LLVM.h"
25#include "llvm/ADT/ScopeExit.h"
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/DebugLog.h"
29#include <cassert>
30#include <optional>
31
32#define DEBUG_TYPE "dead-code-analysis"
33
34using namespace mlir;
35using namespace mlir::dataflow;
36
37//===----------------------------------------------------------------------===//
38// Executable
39//===----------------------------------------------------------------------===//
40
42 if (live)
44 live = true;
46}
47
49 os << (live ? "live" : "dead");
50}
51
54
55 if (ProgramPoint *pp = llvm::dyn_cast_if_present<ProgramPoint *>(anchor)) {
56 if (pp->isBlockStart()) {
57 // Re-invoke the analyses on the block itself.
58 for (DataFlowAnalysis *analysis : subscribers)
59 solver->enqueue({pp, analysis});
60 // Re-invoke the analyses on all operations in the block.
61 for (DataFlowAnalysis *analysis : subscribers)
62 for (Operation &op : *pp->getBlock())
63 solver->enqueue({solver->getProgramPointAfter(&op), analysis});
64 }
65 } else if (auto *latticeAnchor =
66 llvm::dyn_cast_if_present<GenericLatticeAnchor *>(anchor)) {
67 // Re-invoke the analysis on the successor block.
68 if (auto *edge = dyn_cast<CFGEdge>(latticeAnchor)) {
69 for (DataFlowAnalysis *analysis : subscribers)
70 solver->enqueue(
71 {solver->getProgramPointBefore(edge->getTo()), analysis});
72 }
73 }
74}
75
76//===----------------------------------------------------------------------===//
77// PredecessorState
78//===----------------------------------------------------------------------===//
79
82 os << "(all) ";
83 os << "predecessors:";
84 if (getKnownPredecessors().empty())
85 os << " (none)";
86 else
87 os << "\n";
88 llvm::interleave(
90 [&](Operation *op) {
91 os << " " << OpWithFlags(op, OpPrintingFlags().skipRegions());
92 },
93 "\n");
94}
95
97 return knownPredecessors.insert(predecessor) ? ChangeResult::Change
99}
100
102 ChangeResult result = join(predecessor);
103 if (!inputs.empty()) {
104 ValueRange &curInputs = successorInputs[predecessor];
105 if (curInputs != inputs) {
106 curInputs = inputs;
108 }
109 }
110 return result;
111}
112
113//===----------------------------------------------------------------------===//
114// CFGEdge
115//===----------------------------------------------------------------------===//
116
118 return FusedLoc::get(
119 getFrom()->getParent()->getContext(),
120 {getFrom()->getParent()->getLoc(), getTo()->getParent()->getLoc()});
121}
122
124 getFrom()->print(os);
125 os << "\n -> \n";
126 getTo()->print(os);
127}
128
129//===----------------------------------------------------------------------===//
130// DeadCodeAnalysis
131//===----------------------------------------------------------------------===//
132
137
139 LDBG() << "Initializing DeadCodeAnalysis for top-level op: "
140 << OpWithFlags(top, OpPrintingFlags().skipRegions());
141 // Mark the top-level blocks as executable.
142 for (Region &region : top->getRegions()) {
143 if (region.empty())
144 continue;
145 auto *state =
147 propagateIfChanged(state, state->setToLive());
148 LDBG() << "Marked entry block live for region in op: "
149 << OpWithFlags(top, OpPrintingFlags().skipRegions());
150 }
151
152 // If the top level op is a callable, we cannot identify all of its callers.
153 if (isa<CallableOpInterface>(top)) {
155 propagateIfChanged(state, state->setHasUnknownPredecessors());
156 LDBG() << "[init] Marked callable root as having unknown predecessors: "
157 << OpWithFlags(top, OpPrintingFlags().skipRegions());
158 }
159
160 // Mark as overdefined the predecessors of symbol callables with potentially
161 // unknown predecessors.
162 initializeSymbolCallables(top);
163
164 return initializeRecursively(top);
165}
166
167void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
168 LDBG() << "[init] Entering initializeSymbolCallables for top-level op: "
169 << OpWithFlags(top, OpPrintingFlags().skipRegions());
170 analysisScope = top;
171 hasSymbolTable = top->hasTrait<OpTrait::SymbolTable>();
172 auto walkFn = [&](Operation *symTable, bool allUsesVisible) {
173 LDBG() << "[init] Processing symbol table op: "
174 << OpWithFlags(symTable, OpPrintingFlags().skipRegions());
175 Region &symbolTableRegion = symTable->getRegion(0);
176 Block *symbolTableBlock = &symbolTableRegion.front();
177
178 bool foundSymbolCallable = false;
179 for (auto callable : symbolTableBlock->getOps<CallableOpInterface>()) {
180 LDBG() << "[init] Found CallableOpInterface: "
181 << OpWithFlags(callable.getOperation(),
182 OpPrintingFlags().skipRegions());
183 Region *callableRegion = callable.getCallableRegion();
184 if (!callableRegion)
185 continue;
186 auto symbol = dyn_cast<SymbolOpInterface>(callable.getOperation());
187 if (!symbol)
188 continue;
189
190 // Public symbol callables or those for which we can't see all uses have
191 // potentially unknown callsites.
192 if (symbol.isPublic() || (!allUsesVisible && symbol.isNested())) {
193 auto *state =
195 propagateIfChanged(state, state->setHasUnknownPredecessors());
196 LDBG() << "[init] Marked callable as having unknown predecessors: "
197 << OpWithFlags(callable.getOperation(),
198 OpPrintingFlags().skipRegions());
199 }
200 foundSymbolCallable = true;
201 }
202
203 // Exit early if no eligible symbol callables were found in the table.
204 if (!foundSymbolCallable)
205 return;
206
207 // Walk the symbol table to check for non-call uses of symbols.
208 std::optional<SymbolTable::UseRange> uses =
209 SymbolTable::getSymbolUses(&symbolTableRegion);
210 if (!uses) {
211 // If we couldn't gather the symbol uses, conservatively assume that
212 // we can't track information for any nested symbols.
213 LDBG() << "[init] Could not gather symbol uses, conservatively marking "
214 "all nested callables as having unknown predecessors";
215 return top->walk([&](CallableOpInterface callable) {
216 auto *state =
218 propagateIfChanged(state, state->setHasUnknownPredecessors());
219 LDBG() << "[init] Marked nested callable as "
220 "having unknown predecessors: "
221 << OpWithFlags(callable.getOperation(),
222 OpPrintingFlags().skipRegions());
223 });
224 }
225
226 for (const SymbolTable::SymbolUse &use : *uses) {
227 if (isa<CallOpInterface>(use.getUser()))
228 continue;
229 // If a callable symbol has a non-call use, then we can't be guaranteed to
230 // know all callsites.
231 Operation *symbol = symbolTable.lookupSymbolIn(top, use.getSymbolRef());
232 if (!symbol)
233 continue;
235 propagateIfChanged(state, state->setHasUnknownPredecessors());
236 LDBG() << "[init] Found non-call use for symbol, "
237 "marked as having unknown predecessors: "
238 << OpWithFlags(symbol, OpPrintingFlags().skipRegions());
239 }
240 };
241 SymbolTable::walkSymbolTables(top, /*allSymUsesVisible=*/!top->getBlock(),
242 walkFn);
243 LDBG() << "[init] Finished initializeSymbolCallables for top-level op: "
244 << OpWithFlags(top, OpPrintingFlags().skipRegions());
245}
246
247/// Returns true if the operation is a returning terminator in region
248/// control-flow or the terminator of a callable region.
250 return op->getBlock() != nullptr && !op->getNumSuccessors() &&
251 isa<RegionBranchOpInterface, CallableOpInterface>(op->getParentOp()) &&
252 op->getBlock()->getTerminator() == op;
253}
254
255LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
256 LDBG() << "[init] Entering initializeRecursively for op: "
257 << OpWithFlags(op, OpPrintingFlags().skipRegions());
258 // Initialize the analysis by visiting every op with control-flow semantics.
259 if (op->getNumRegions() || op->getNumSuccessors() ||
260 isRegionOrCallableReturn(op) || isa<CallOpInterface>(op)) {
261 LDBG() << "[init] Visiting op with control-flow semantics: "
262 << OpWithFlags(op, OpPrintingFlags().skipRegions());
263 // When the liveness of the parent block changes, make sure to
264 // re-invoke the analysis on the op.
265 if (op->getBlock())
267 ->blockContentSubscribe(this);
268 // Visit the op.
270 return failure();
271 }
272 // Recurse on nested operations.
273 if (op->getNumRegions()) {
274 // If we haven't seen a symbol table yet, check if the current operation
275 // has one. If so, update the flag to allow for resolving callables in
276 // nested regions.
277 bool savedHasSymbolTable = hasSymbolTable;
278 llvm::scope_exit restoreHasSymbolTable(
279 [&]() { hasSymbolTable = savedHasSymbolTable; });
280 if (!hasSymbolTable && op->hasTrait<OpTrait::SymbolTable>())
281 hasSymbolTable = true;
282
283 for (Region &region : op->getRegions()) {
284 LDBG() << "[init] Recursing into region of op: "
285 << OpWithFlags(op, OpPrintingFlags().skipRegions());
286 for (Operation &nestedOp : region.getOps()) {
287 LDBG() << "[init] Recursing into nested op: "
288 << OpWithFlags(&nestedOp, OpPrintingFlags().skipRegions());
289 if (failed(initializeRecursively(&nestedOp)))
290 return failure();
291 }
292 }
293 }
294 LDBG() << "[init] Finished initializeRecursively for op: "
295 << OpWithFlags(op, OpPrintingFlags().skipRegions());
296 return success();
297}
298
299void DeadCodeAnalysis::markEdgeLive(Block *from, Block *to) {
300 LDBG() << "Marking edge live from block " << from << " to block " << to;
302 propagateIfChanged(state, state->setToLive());
303 auto *edgeState =
305 propagateIfChanged(edgeState, edgeState->setToLive());
306}
307
308void DeadCodeAnalysis::markEntryBlocksLive(Operation *op) {
309 LDBG() << "Marking entry blocks live for op: "
310 << OpWithFlags(op, OpPrintingFlags().skipRegions());
311 for (Region &region : op->getRegions()) {
312 if (region.empty())
313 continue;
314 auto *state =
316 propagateIfChanged(state, state->setToLive());
317 LDBG() << "Marked entry block live for region in op: "
318 << OpWithFlags(op, OpPrintingFlags().skipRegions());
319 }
320}
321
323 LDBG() << "Visiting program point: " << *point;
324 if (point->isBlockStart())
325 return success();
326 Operation *op = point->getPrevOp();
327 LDBG() << "Visiting operation: "
328 << OpWithFlags(op, OpPrintingFlags().skipRegions());
329
330 // If the parent block is not executable, there is nothing to do.
331 if (op->getBlock() != nullptr &&
333 ->isLive()) {
334 LDBG() << "Parent block not live, skipping op: "
335 << OpWithFlags(op, OpPrintingFlags().skipRegions());
336 return success();
337 }
338
339 // We have a live call op. Add this as a live predecessor of the callee.
340 if (auto call = dyn_cast<CallOpInterface>(op)) {
341 LDBG() << "Visiting call operation: "
342 << OpWithFlags(op, OpPrintingFlags().skipRegions());
343 visitCallOperation(call);
344 }
345
346 // Visit the regions.
347 if (op->getNumRegions()) {
348 // Check if we can reason about the region control-flow.
349 if (auto branch = dyn_cast<RegionBranchOpInterface>(op)) {
350 LDBG() << "Visiting region branch operation: "
351 << OpWithFlags(op, OpPrintingFlags().skipRegions());
352 visitRegionBranchOperation(branch);
353
354 // Check if this is a callable operation.
355 } else if (auto callable = dyn_cast<CallableOpInterface>(op)) {
356 LDBG() << "Visiting callable operation: "
357 << OpWithFlags(op, OpPrintingFlags().skipRegions());
358 const auto *callsites = getOrCreateFor<PredecessorState>(
360
361 // If the callsites could not be resolved or are known to be non-empty,
362 // mark the callable as executable.
363 if (!callsites->allPredecessorsKnown() ||
364 !callsites->getKnownPredecessors().empty())
365 markEntryBlocksLive(callable);
366
367 // Otherwise, conservatively mark all entry blocks as executable.
368 } else {
369 LDBG() << "Marking all entry blocks live for op: "
370 << OpWithFlags(op, OpPrintingFlags().skipRegions());
371 markEntryBlocksLive(op);
372 }
373 }
374
375 if (isRegionOrCallableReturn(op)) {
376 if (auto branch = dyn_cast<RegionBranchOpInterface>(op->getParentOp())) {
377 LDBG() << "Visiting region terminator: "
378 << OpWithFlags(op, OpPrintingFlags().skipRegions());
379 // Visit the exiting terminator of a region.
380 visitRegionTerminator(op, branch);
381 } else if (auto callable =
382 dyn_cast<CallableOpInterface>(op->getParentOp())) {
383 LDBG() << "Visiting callable terminator: "
384 << OpWithFlags(op, OpPrintingFlags().skipRegions());
385 // Visit the exiting terminator of a callable.
386 visitCallableTerminator(op, callable);
387 }
388 }
389 // Visit the successors.
390 if (op->getNumSuccessors()) {
391 // Check if we can reason about the control-flow.
392 if (auto branch = dyn_cast<BranchOpInterface>(op)) {
393 LDBG() << "Visiting branch operation: "
394 << OpWithFlags(op, OpPrintingFlags().skipRegions());
395 visitBranchOperation(branch);
396
397 // Otherwise, conservatively mark all successors as exectuable.
398 } else {
399 LDBG() << "Marking all successors live for op: "
400 << OpWithFlags(op, OpPrintingFlags().skipRegions());
401 for (Block *successor : op->getSuccessors())
402 markEdgeLive(op->getBlock(), successor);
403 }
404 }
405
406 return success();
407}
408
409void DeadCodeAnalysis::visitCallOperation(CallOpInterface call) {
410 LDBG() << "visitCallOperation: "
411 << OpWithFlags(call.getOperation(), OpPrintingFlags().skipRegions());
412
413 Operation *callableOp = nullptr;
414 if (hasSymbolTable)
415 callableOp = call.resolveCallableInTable(&symbolTable);
416 else
417 LDBG()
418 << "No symbol table present in analysis scope, can't resolve callable";
419
420 // A call to a externally-defined callable has unknown predecessors.
421 const auto isExternalCallable = [this](Operation *op) {
422 // A callable outside the analysis scope is an external callable.
423 if (!analysisScope->isAncestor(op))
424 return true;
425 // Otherwise, check if the callable region is defined.
426 if (auto callable = dyn_cast<CallableOpInterface>(op))
427 return !callable.getCallableRegion();
428 return false;
429 };
430
431 // TODO: Add support for non-symbol callables when necessary. If the
432 // callable has non-call uses we would mark as having reached pessimistic
433 // fixpoint, otherwise allow for propagating the return values out.
434 if (isa_and_nonnull<SymbolOpInterface>(callableOp) &&
435 !isExternalCallable(callableOp)) {
436 // Add the live callsite.
437 auto *callsites =
439 propagateIfChanged(callsites, callsites->join(call));
440 LDBG() << "Added callsite as predecessor for callable: "
441 << OpWithFlags(callableOp, OpPrintingFlags().skipRegions());
442 } else {
443 // Mark this call op's predecessors as overdefined.
444 auto *predecessors =
446 propagateIfChanged(predecessors, predecessors->setHasUnknownPredecessors());
447 LDBG() << "Marked call op's predecessors as unknown for: "
448 << OpWithFlags(call.getOperation(), OpPrintingFlags().skipRegions());
449 }
450}
451
452/// Get the constant values of the operands of an operation. If any of the
453/// constant value lattices are uninitialized, return std::nullopt to indicate
454/// the analysis should bail out.
455std::optional<SmallVector<Attribute>>
456DeadCodeAnalysis::getOperandValues(Operation *op) {
457 SmallVector<Attribute> operands;
458 operands.reserve(op->getNumOperands());
459 for (Value operand : op->getOperands()) {
460 Lattice<ConstantValue> *cv = getOrCreate<Lattice<ConstantValue>>(operand);
461 cv->useDefSubscribe(this);
462 // If any of the operands' values are uninitialized, bail out.
463 if (cv->getValue().isUninitialized())
464 return std::nullopt;
465 operands.push_back(cv->getValue().getConstantValue());
466 }
467 return operands;
468}
469
470void DeadCodeAnalysis::visitBranchOperation(BranchOpInterface branch) {
471 LDBG() << "visitBranchOperation: "
472 << OpWithFlags(branch.getOperation(), OpPrintingFlags().skipRegions());
473 // Try to deduce a single successor for the branch.
474 std::optional<SmallVector<Attribute>> operands = getOperandValues(branch);
475 if (!operands)
476 return;
477
478 if (Block *successor = branch.getSuccessorForOperands(*operands)) {
479 markEdgeLive(branch->getBlock(), successor);
480 LDBG() << "Branch has single successor: " << successor;
481 } else {
482 // Otherwise, mark all successors as executable and outgoing edges.
483 for (Block *successor : branch->getSuccessors())
484 markEdgeLive(branch->getBlock(), successor);
485 LDBG() << "Branch has multiple/all successors live";
486 }
487}
488
489void DeadCodeAnalysis::visitRegionBranchOperation(
490 RegionBranchOpInterface branch) {
491 LDBG() << "visitRegionBranchOperation: "
492 << OpWithFlags(branch.getOperation(), OpPrintingFlags().skipRegions());
493 // Try to deduce which regions are executable.
494 std::optional<SmallVector<Attribute>> operands = getOperandValues(branch);
495 if (!operands)
496 return;
497
498 SmallVector<RegionSuccessor> successors;
499 branch.getEntrySuccessorRegions(*operands, successors);
500
501 visitRegionBranchEdges(branch, branch.getOperation(), successors);
502}
503
504void DeadCodeAnalysis::visitRegionTerminator(Operation *op,
505 RegionBranchOpInterface branch) {
506 LDBG() << "visitRegionTerminator: " << *op;
507 std::optional<SmallVector<Attribute>> operands = getOperandValues(op);
508 if (!operands)
509 return;
510
511 SmallVector<RegionSuccessor> successors;
512 auto terminator = dyn_cast<RegionBranchTerminatorOpInterface>(op);
513 if (!terminator)
514 return;
515 terminator.getSuccessorRegions(*operands, successors);
516 visitRegionBranchEdges(branch, op, successors);
517}
518
519void DeadCodeAnalysis::visitRegionBranchEdges(
520 RegionBranchOpInterface regionBranchOp, Operation *predecessorOp,
521 const SmallVector<RegionSuccessor> &successors) {
522 for (const RegionSuccessor &successor : successors) {
523 // The successor can be either an entry block or the parent operation.
524 ProgramPoint *point =
525 successor.isParent()
526 ? getProgramPointAfter(regionBranchOp)
527 : getProgramPointBefore(&successor.getSuccessor()->front());
528
529 // Mark the entry block as executable.
530 auto *state = getOrCreate<Executable>(point);
531 propagateIfChanged(state, state->setToLive());
532 LDBG() << "Marked region successor live: " << *point;
533
534 // Add the parent op as a predecessor.
535 auto *predecessors = getOrCreate<PredecessorState>(point);
537 predecessors,
538 predecessors->join(predecessorOp,
539 regionBranchOp.getSuccessorInputs(successor)));
540 LDBG() << "Added region branch as predecessor for successor: " << *point;
541 }
542}
543
544void DeadCodeAnalysis::visitCallableTerminator(Operation *op,
545 CallableOpInterface callable) {
546 LDBG() << "visitCallableTerminator: " << *op;
547 // Add as predecessors to all callsites this return op.
548 auto *callsites = getOrCreateFor<PredecessorState>(
550 bool canResolve = op->hasTrait<OpTrait::ReturnLike>();
551 for (Operation *predecessor : callsites->getKnownPredecessors()) {
552 assert(isa<CallOpInterface>(predecessor));
553 auto *predecessors =
555 if (canResolve) {
556 propagateIfChanged(predecessors, predecessors->join(op));
557 LDBG() << "Added callable terminator as predecessor for callsite: "
558 << OpWithFlags(predecessor, OpPrintingFlags().skipRegions());
559 } else {
560 // If the terminator is not a return-like, then conservatively assume we
561 // can't resolve the predecessor.
562 propagateIfChanged(predecessors,
563 predecessors->setHasUnknownPredecessors());
564 LDBG() << "Could not resolve callable terminator for callsite: "
565 << OpWithFlags(predecessor, OpPrintingFlags().skipRegions());
566 }
567 }
568}
return success()
static bool isRegionOrCallableReturn(Operation *op)
Returns true if the operation is a returning terminator in region control-flow or the terminator of a...
b getContext())
virtual void onUpdate(DataFlowSolver *solver) const
This function is called by the solver when the analysis state is updated to enqueue more work items.
LatticeAnchor anchor
The lattice anchor to which the state belongs.
friend class DataFlowSolver
Allow the framework to access the dependents.
Block represents an ordered list of Operations.
Definition Block.h:33
iterator_range< op_iterator< OpT > > getOps()
Return an iterator range over the operations within this block that are of 'OpT'.
Definition Block.h:203
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
Definition Block.cpp:27
Operation * getTerminator()
Get the terminator operation of this block.
Definition Block.cpp:249
void print(raw_ostream &os)
Base class for all data-flow analyses.
ProgramPoint * getProgramPointBefore(Operation *op)
Get a uniqued program point instance.
void propagateIfChanged(AnalysisState *state, ChangeResult changed)
Propagate an update to a state if it changed.
StateT * getOrCreate(AnchorT anchor)
Get the analysis state associated with the lattice anchor.
ProgramPoint * getProgramPointAfter(Operation *op)
DataFlowAnalysis(DataFlowSolver &solver)
Create an analysis with a reference to the parent solver.
AnchorT * getLatticeAnchor(Args &&...args)
Get or create a custom lattice anchor.
void registerAnchorKind()
Register a custom lattice anchor class.
friend class DataFlowSolver
Allow the data-flow solver to access the internals of this class.
const StateT * getOrCreateFor(ProgramPoint *dependent, AnchorT anchor)
Get a read-only analysis state for the given point and create a dependency on dependent.
void enqueue(WorkItem item)
Push a work item onto the worklist.
ProgramPoint * getProgramPointBefore(Operation *op)
Get a uniqued program point instance.
ProgramPoint * getProgramPointAfter(Operation *op)
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
Set of flags used to control the behavior of the various IR print methods (e.g.
A trait used to provide symbol table functionalities to a region operation.
A wrapper class that allows for printing an operation with a set of flags, useful to act as a "stream...
Definition Operation.h:1111
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Definition Operation.h:686
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Definition Operation.h:749
unsigned getNumSuccessors()
Definition Operation.h:706
Block * getBlock()
Returns the operation block that contains this operation.
Definition Operation.h:213
unsigned getNumRegions()
Returns the number of regions held by this operation.
Definition Operation.h:674
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition Operation.h:234
unsigned getNumOperands()
Definition Operation.h:346
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
Definition Operation.h:677
operand_range getOperands()
Returns an iterator on the underlying Value's.
Definition Operation.h:378
bool isAncestor(Operation *other)
Return true if this operation is an ancestor of the other operation.
Definition Operation.h:263
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
Definition Operation.h:797
SuccessorRange getSuccessors()
Definition Operation.h:703
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Definition Region.h:26
Block & front()
Definition Region.h:65
Location getLoc()
Return a location for this region.
Definition Region.cpp:31
static void walkSymbolTables(Operation *op, bool allSymUsesVisible, function_ref< void(Operation *, bool)> callback)
Walks all symbol table operations nested within, and including, op.
static std::optional< UseRange > getSymbolUses(Operation *from)
Get an iterator range for all of the uses, for any symbol, that are nested within the given operation...
This class provides an abstraction over the different types of ranges over Values.
Definition ValueRange.h:387
void useDefSubscribe(DataFlowAnalysis *analysis)
Subscribe an analysis to updates of the lattice.
Location getLoc() const override
Get a fused location of both blocks.
Block * getTo() const
Get the target block.
Block * getFrom() const
Get the block from which the edge originates.
void print(raw_ostream &os) const override
Print the blocks between the control-flow edge.
DeadCodeAnalysis(DataFlowSolver &solver)
LogicalResult visit(ProgramPoint *point) override
Visit an operation with control-flow semantics and deduce which of its successors are live.
LogicalResult initialize(Operation *top) override
Initialize the analysis by visiting every operation with potential control-flow semantics.
void onUpdate(DataFlowSolver *solver) const override
When the state of the lattice anchor is changed to live, re-invoke subscribed analyses on the operati...
ChangeResult setToLive()
Set the state of the lattice anchor to live.
void print(raw_ostream &os) const override
Print the liveness.
ValueT & getValue()
Return the value held by this lattice.
ArrayRef< Operation * > getKnownPredecessors() const
Get the known predecessors.
bool allPredecessorsKnown() const
Returns true if all predecessors are known.
void print(raw_ostream &os) const override
Print the known predecessors.
ChangeResult join(Operation *predecessor)
Add a known predecessor.
detail::InFlightRemark failed(Location loc, RemarkOpts opts)
Report an optimization remark that failed.
Definition Remarks.h:578
Include the generated interface declarations.
ChangeResult
A result type used to indicate if a change happened.
Program point represents a specific location in the execution of a program.
Operation * getPrevOp() const
Get the previous operation of this program point.