aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib
diff options
context:
space:
mode:
authorJeff Niu <jeff@modular.com>2022-07-30 22:20:08 -0400
committerJeff Niu <jeff@modular.com>2022-07-31 16:03:46 -0400
commit62fe67f9eb02cd5add1f70514fdcd1b324b14028 (patch)
treeef4515cc0c8513ad28b6ad861779557505c89844 /mlir/lib
parent68b0aaad56a5fd216c97e8861c013eafc2cc653c (diff)
[mlir][DCA] Fix visiting call ops when run at function scopes
When dead-code analysis is run at the scope of a function, call ops to other functions at the same level were being marked as unreachable, since the analysis optimistically assumes the call op to have no known predecessors and that all predecessors are known, but the callee would never get visited. This patch fixes the bug by checking if a referenced function is above the top-level op of the analysis, and is thus considered an external callable. Fixes #56830 Reviewed By: zero9178 Differential Revision: https://reviews.llvm.org/D130829
Diffstat (limited to 'mlir/lib')
-rw-r--r--mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 327ef4f90b51..0f7a00c69eab 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -118,6 +118,7 @@ LogicalResult DeadCodeAnalysis::initialize(Operation *top) {
}
void DeadCodeAnalysis::initializeSymbolCallables(Operation *top) {
+ analysisScope = top;
auto walkFn = [&](Operation *symTable, bool allUsesVisible) {
Region &symbolTableRegion = symTable->getRegion(0);
Block *symbolTableBlock = &symbolTableRegion.front();
@@ -278,14 +279,14 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint point) {
}
void DeadCodeAnalysis::visitCallOperation(CallOpInterface call) {
- Operation *callableOp = nullptr;
- if (Value callableValue = call.getCallableForCallee().dyn_cast<Value>())
- callableOp = callableValue.getDefiningOp();
- else
- callableOp = call.resolveCallable(&symbolTable);
+ Operation *callableOp = call.resolveCallable(&symbolTable);
// A call to a externally-defined callable has unknown predecessors.
- const auto isExternalCallable = [](Operation *op) {
+ const auto isExternalCallable = [this](Operation *op) {
+ // A callable outside the analysis scope is an external callable.
+ if (!analysisScope->isAncestor(op))
+ return true;
+ // Otherwise, check if the callable region is defined.
if (auto callable = dyn_cast<CallableOpInterface>(op))
return !callable.getCallableRegion();
return false;