Skip to content

Commit d4cb75e

Browse files
[mlir][bufferization] Module bufferization: Delete obsolete code (llvm#127455)
Delete `equivalenceAnalysis`, which has been incorporated into the `getAliasingValues` API. Also add an additional test case to ensure that equivalence is properly propagated across function boundaries.
1 parent 55fb793 commit d4cb75e

File tree

2 files changed

+19
-35
lines changed

2 files changed

+19
-35
lines changed

mlir/lib/Dialect/Bufferization/Transforms/OneShotModuleBufferize.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -289,35 +289,6 @@ static func::FuncOp getCalledFunction(func::CallOp callOp) {
289289
SymbolTable::lookupNearestSymbolFrom(callOp, sym));
290290
}
291291

292-
/// Gather equivalence info of CallOps.
293-
/// Note: This only adds new equivalence info if the called function was already
294-
/// analyzed.
295-
// TODO: This does not handle cyclic function call graphs etc.
296-
static void equivalenceAnalysis(func::FuncOp funcOp,
297-
OneShotAnalysisState &state,
298-
FuncAnalysisState &funcState) {
299-
funcOp->walk([&](func::CallOp callOp) {
300-
func::FuncOp calledFunction = getCalledFunction(callOp);
301-
assert(calledFunction && "could not retrieved called func::FuncOp");
302-
303-
// No equivalence info available for the called function.
304-
if (!funcState.equivalentFuncArgs.count(calledFunction))
305-
return WalkResult::skip();
306-
307-
for (auto it : funcState.equivalentFuncArgs[calledFunction]) {
308-
int64_t returnIdx = it.first;
309-
int64_t bbargIdx = it.second;
310-
if (!state.isInPlace(callOp->getOpOperand(bbargIdx)))
311-
continue;
312-
Value returnVal = callOp.getResult(returnIdx);
313-
Value argVal = callOp->getOperand(bbargIdx);
314-
state.unionEquivalenceClasses(returnVal, argVal);
315-
}
316-
317-
return WalkResult::advance();
318-
});
319-
}
320-
321292
/// Return "true" if the given function signature has tensor semantics.
322293
static bool hasTensorSignature(func::FuncOp funcOp) {
323294
return llvm::any_of(funcOp.getFunctionType().getInputs(),
@@ -493,9 +464,6 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
493464
// Now analyzing function.
494465
funcState.startFunctionAnalysis(funcOp);
495466

496-
// Gather equivalence info for CallOps.
497-
equivalenceAnalysis(funcOp, state, funcState);
498-
499467
// Analyze funcOp.
500468
if (failed(analyzeOp(funcOp, state, statistics)))
501469
return failure();
@@ -514,9 +482,6 @@ mlir::bufferization::analyzeModuleOp(ModuleOp moduleOp,
514482
if (!state.getOptions().isOpAllowed(funcOp))
515483
continue;
516484

517-
// Gather equivalence info for CallOps.
518-
equivalenceAnalysis(funcOp, state, funcState);
519-
520485
// Analyze funcOp.
521486
if (failed(analyzeOp(funcOp, state, statistics)))
522487
return failure();

mlir/test/Dialect/Bufferization/Transforms/one-shot-module-bufferize-analysis.mlir

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: mlir-opt %s -one-shot-bufferize="bufferize-function-boundaries test-analysis-only" -split-input-file | FileCheck %s
2+
// RUN: mlir-opt %s -one-shot-bufferize="bufferize-function-boundaries test-analysis-only dump-alias-sets" -split-input-file | FileCheck %s --check-prefix=CHECK-ALIAS
23

34
// Run fuzzer with different seeds.
45
// RUN: mlir-opt %s -one-shot-bufferize="bufferize-function-boundaries test-analysis-only analysis-heuristic=fuzzer analysis-fuzzer-seed=23" -split-input-file -o /dev/null
@@ -1406,3 +1407,21 @@ func.func @caller(%c: i1, %t0: tensor<5xf32>, %t1: tensor<5xf32>, %t2: tensor<5x
14061407
return %r : tensor<5xf32>
14071408
}
14081409

1410+
// -----
1411+
1412+
// CHECK-ALIAS-LABEL: func @foo
1413+
func.func @foo(%arg0: tensor<?xf32>) -> tensor<?xf32> {
1414+
// CHECK-ALIAS: return
1415+
// CHECK-ALIAS-SAME: __equivalent_func_args__ = [0]
1416+
return %arg0 : tensor<?xf32>
1417+
}
1418+
1419+
// CHECK-ALIAS: func @bar(%[[arg0:.*]]: tensor<?xf32>
1420+
func.func @bar(%arg0: tensor<?xf32>) -> tensor<?xf32> {
1421+
// CHECK-ALIAS: %[[call:.*]] = call @foo(%[[arg0]])
1422+
// CHECK-ALIAS-SAME: {__inplace_operands_attr__ = ["true"], __opresult_alias_set_attr__ = [{{\[}}"%[[call]]", "%[[arg0]]"]]}
1423+
%x = call @foo(%arg0) : (tensor<?xf32>) -> tensor<?xf32>
1424+
// CHECK-ALIAS: return
1425+
// CHECK-ALIAS-SAME: __equivalent_func_args__ = [0]
1426+
return %x : tensor<?xf32>
1427+
}

0 commit comments

Comments
 (0)