-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][dataflow]Fix dense backward dataflow intraprocedural hook #76865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-mlir Author: None (drblallo) ChangesThe dataflow analysis framework within MLIR allows to customize the transfer function when a The check to see if the analysis was executed in intraprocedural mode was executed after the check to see if the callee had the CallableOpInterface, and thus intraprocedural analyses would behave as interpocedural ones when performing indirect calls. This commit fixes the issue by performing the check for intraprocedurality first. Full diff: https://github.com/llvm/llvm-project/pull/76865.diff 2 Files Affected:
diff --git a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
index 08d89d6db788c8..33056ff7cd25a5 100644
--- a/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp
@@ -283,17 +283,22 @@ void AbstractDenseBackwardDataFlowAnalysis::visitCallOperation(
AbstractDenseLattice *before) {
// Find the callee.
Operation *callee = call.resolveCallable(&symbolTable);
- auto callable = dyn_cast_or_null<CallableOpInterface>(callee);
- if (!callable)
- return setToExitState(before);
+ auto callable = dyn_cast_or_null<CallableOpInterface>(callee);
// No region means the callee is only declared in this module.
- Region *region = callable.getCallableRegion();
- if (!region || region->empty() || !getSolverConfig().isInterprocedural()) {
+ // If that is the case or if the solver is not interprocedural,
+ // let the hook handle it.
+ if (!getSolverConfig().isInterprocedural() ||
+ (callable && (!callable.getCallableRegion() || callable.getCallableRegion()->empty()))) {
return visitCallControlFlowTransfer(
call, CallControlFlowAction::ExternalCallee, after, before);
}
+ if (!callable)
+ return setToExitState(before);
+
+ Region *region = callable.getCallableRegion();
+
// Call-level control flow specifies the data flow here.
//
// func.func @callee() {
diff --git a/mlir/test/Analysis/DataFlow/test-next-access.mlir b/mlir/test/Analysis/DataFlow/test-next-access.mlir
index 70069b10a93983..8825c699dd1305 100644
--- a/mlir/test/Analysis/DataFlow/test-next-access.mlir
+++ b/mlir/test/Analysis/DataFlow/test-next-access.mlir
@@ -575,3 +575,21 @@ func.func @call_opaque_callee(%arg0: memref<f32>) {
memref.load %arg0[] {name = "post"} : memref<f32>
return
}
+
+// -----
+
+// CHECK-LABEL: @indirect_call
+func.func @indirect_call(%arg0: memref<f32>, %arg1: (memref<f32>) -> ()) {
+ // IP: name = "pre"
+ // IP-SAME: next_access = ["unknown"]
+ // IP_AR: name = "pre"
+ // IP_AR-SAME: next_access = ["unknown"]
+ // LOCAL: name = "pre"
+ // LOCAL-SAME: next_access = ["unknown"]
+ // LC_AR: name = "pre"
+ // LC_AR-SAME: next_access = {{\[}}["call"]]
+ memref.load %arg0[] {name = "pre"} : memref<f32>
+ func.call_indirect %arg1(%arg0) {name = "call"} : (memref<f32>) -> ()
+ memref.load %arg0[] {name = "post"} : memref<f32>
+ return
+}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
ad47238
to
94c97cc
Compare
The dataflow analysis framework within MLIR allows to customize the transfer function when a `call-like` operation is encuntered. The check to see if the analysis was executed in intraprocedural mode was executed after the check to see if the callee had the CallableOpInterface, and thus intraprocedural analyses would behave as interpocedural ones when performing indirect calls. This commit fixes the issue by performing the check for intraprocedurality first.
94c97cc
to
915a045
Compare
The dataflow analysis framework within MLIR allows to customize the transfer function when a
call-like
operation is encuntered.The check to see if the analysis was executed in intraprocedural mode was executed after the check to see if the callee had the CallableOpInterface, and thus intraprocedural analyses would behave as interpocedural ones when performing indirect calls.
This commit fixes the issue by performing the check for intraprocedurality first.
Dense forward analyses were already behaving correctly. https://github.com/llvm/llvm-project/blob/main/mlir/lib/Analysis/DataFlow/DenseAnalysis.cpp#L63