Skip to content

[mlir] Fix loop-like interface #95817

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
Jun 19, 2024
Merged

Conversation

ikulagin
Copy link
Contributor

Using the this pointer inside interface methods is illegal because it breaks concept-based interfaces.
It is necessary to use $_op instead.

@llvmbot llvmbot added the mlir label Jun 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/pr-subscribers-mlir

Author: Ivan Kulagin (ikulagin)

Changes

Using the this pointer inside interface methods is illegal because it breaks concept-based interfaces.
It is necessary to use $_op instead.


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

1 Files Affected:

  • (modified) mlir/include/mlir/Interfaces/LoopLikeInterface.td (+4-4)
diff --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
index b748d5e29114a..7db624ba43974 100644
--- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
@@ -246,7 +246,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// If there is a single induction variable return it, otherwise return
     /// std::nullopt.
     ::std::optional<::mlir::Value> getSingleInductionVar() {
-      auto inductionVars = this->getLoopInductionVars();
+      auto inductionVars = $_op.getLoopInductionVars();
       if (inductionVars.has_value() && (*inductionVars).size() == 1)
           return (*inductionVars)[0];
         return std::nullopt;
@@ -254,7 +254,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Return the single lower bound value or attribute if it exists, otherwise
     /// return std::nullopt.
     ::std::optional<::mlir::OpFoldResult> getSingleLowerBound() {
-      auto lowerBounds = this->getLoopLowerBounds();
+      auto lowerBounds = $_op.getLoopLowerBounds();
       if (lowerBounds.has_value() && (*lowerBounds).size() == 1)
           return (*lowerBounds)[0];
       return std::nullopt;
@@ -262,7 +262,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Return the single step value or attribute if it exists, otherwise
     /// return std::nullopt.
     ::std::optional<::mlir::OpFoldResult> getSingleStep() {
-      auto steps = this->getLoopSteps(); 
+      auto steps = $_op.getLoopSteps();
       if (steps.has_value() && (*steps).size() == 1)
           return (*steps)[0];
       return std::nullopt;
@@ -270,7 +270,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Return the single upper bound value or attribute if it exists, otherwise
     /// return std::nullopt.
     ::std::optional<::mlir::OpFoldResult> getSingleUpperBound() {
-      auto upperBounds = this->getLoopUpperBounds();
+      auto upperBounds = $_op.getLoopUpperBounds();
       if (upperBounds.has_value() && (*upperBounds).size() == 1)
           return (*upperBounds)[0];
       return std::nullopt;

@ikulagin
Copy link
Contributor Author

@joker-eph @makslevental
Please review the suggested fixes

@makslevental
Copy link
Contributor

Was there a fail somewhere? I mean I think you're right but I'm shocked this has never come up before...

@ikulagin
Copy link
Contributor Author

Was there a fail somewhere? I mean I think you're right but I'm shocked this has never come up before...

Fortunately, the llvm-project codebase uses the buggy methods as follows:

if (auto loop = dyn_cast<LoopLikeOpInterface>(op)) {
    std::optional<Value> iv = loop.getSingleInductionVar();
    ....
}

in this case, the correct implementation of getLoopInductionVars will be called inside the getSingleInductionVar.
If this method were called on a specific operation, for example, AffineForOp, then inside the method getSingleInductionVar the default implementation of the getLoopInductionVars method would be called, and the getSingleInductionVar method will always return std::nullopt

@makslevental makslevental merged commit c38b1fa into llvm:main Jun 19, 2024
9 checks passed
@ikulagin ikulagin deleted the fix-looplikeiface branch June 21, 2024 23:06
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
Using the `this` pointer inside interface methods is illegal because it
breaks concept-based interfaces.
 It is necessary to use `$_op` instead.

Co-authored-by: ikulagin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants