Skip to content

[mlir][bufferization] Check OpFilter before casting to BufferizableOpInterface #85690

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

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

d0k
Copy link
Member

@d0k d0k commented Mar 18, 2024

This doesn't change functionality, but lets us avoid attaching all the interfaces after 513cdb8 turned casting without loading into an error.

…Interface

This doesn't change functionality, but lets us avoid attaching all the
interfaces after 513cdb8 turned casting
without loading into an error.
@d0k d0k requested a review from matthias-springer as a code owner March 18, 2024 19:56
@llvmbot llvmbot added mlir mlir:bufferization Bufferization infrastructure labels Mar 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 18, 2024

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-bufferization

Author: Benjamin Kramer (d0k)

Changes

This doesn't change functionality, but lets us avoid attaching all the interfaces after 513cdb8 turned casting without loading into an error.


Full diff: https://github.com/llvm/llvm-project/pull/85690.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp (+2-2)
  • (modified) mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp (+1-3)
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
index 8f0f6d1fcc8490..55c9299c58effd 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp
@@ -344,11 +344,11 @@ bool BufferizationOptions::isOpAllowed(Operation *op) const {
 
 BufferizableOpInterface
 BufferizationOptions::dynCastBufferizableOp(Operation *op) const {
+  if (!isOpAllowed(op))
+    return nullptr;
   auto bufferizableOp = dyn_cast<BufferizableOpInterface>(op);
   if (!bufferizableOp)
     return nullptr;
-  if (!isOpAllowed(op))
-    return nullptr;
   return bufferizableOp;
 }
 
diff --git a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
index 6a0ad66549965a..8dbf701620121a 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
@@ -453,7 +453,7 @@ LogicalResult bufferization::bufferizeOp(Operation *op,
   // canonicalize away (or canonicalize to more precise layouts).
   SmallVector<Operation *> worklist;
   op->walk<WalkOrder::PostOrder>([&](Operation *op) {
-    if (hasTensorSemantics(op))
+    if (options.isOpAllowed(op) && hasTensorSemantics(op))
       worklist.push_back(op);
   });
 
@@ -472,8 +472,6 @@ LogicalResult bufferization::bufferizeOp(Operation *op,
     auto bufferizableOp = options.dynCastBufferizableOp(nextOp);
     if (!bufferizableOp)
       continue;
-    if (!options.isOpAllowed(nextOp))
-      continue;
     // Skip ops that no longer have tensor semantics.
     if (!hasTensorSemantics(nextOp))
       continue;

@d0k d0k merged commit db60491 into llvm:main Mar 19, 2024
@d0k d0k deleted the opfilter branch March 19, 2024 12:30
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…Interface (llvm#85690)

This doesn't change functionality, but lets us avoid attaching all the
interfaces after 513cdb8 turned casting
without loading into an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mlir:bufferization Bufferization infrastructure mlir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants