Skip to content

[mlir][scf] scf.for support inline which contains affine map op. #124082

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gumingsiyi
Copy link

I want inline a call op in a scf.for region.
But there is a affine map in the function.
The inliner don't work because of the affine map.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

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 permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

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.

@llvmbot
Copy link
Member

llvmbot commented Jan 23, 2025

@llvm/pr-subscribers-mlir-scf

@llvm/pr-subscribers-mlir

Author: gumingsiyi (gumingsiyi)

Changes

I want inline a call op in a scf.for region.
But there is a affine map in the function.
The inliner don't work because of the affine map.


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

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/SCF/IR/SCFOps.td (+3-2)
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 6f408b3c924de8..6d61f724fab4f0 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -133,8 +133,9 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
 // ForOp
 //===----------------------------------------------------------------------===//
 
-def ForOp : SCF_Op<"for",
-      [AutomaticAllocationScope, DeclareOpInterfaceMethods<LoopLikeOpInterface,
+def ForOp : SCF_Op<"for", [
+  AffineScope, AutomaticAllocationScope,
+  DeclareOpInterfaceMethods<LoopLikeOpInterface,
        ["getInitsMutable", "getLoopResults", "getRegionIterArgs",
         "getLoopInductionVars", "getLoopLowerBounds", "getLoopSteps",
         "getLoopUpperBounds", "getYieldedValuesMutable",

[AutomaticAllocationScope, DeclareOpInterfaceMethods<LoopLikeOpInterface,
def ForOp : SCF_Op<"for", [
AffineScope, AutomaticAllocationScope,
DeclareOpInterfaceMethods<LoopLikeOpInterface,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think AffineScope should not be introduced in the loop. In the loop, the SSA value generated each time may change, so it is very likely that they are not valid symbols. For example, if a function returns an Index type, the SSA value will change. In addition, the value of the passed parameter, such as memref<?x?xf32>, memref.dim may also change after the function call is completed. Introducing AffineScope here will make all the above values ​​become valid symbols.

The key to the problem should be that your function is in the top level of AffineScope, and the values ​​inside it are all valid symbols, but after being inlined, it is placed in the for loop and they become illegal symbols.

Maybe you should run your function through a lower-affine pass before inlining it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢!

Copy link
Member

@linuxlonelyeagle linuxlonelyeagle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment, hope it help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants