Skip to content

[MLIR][Interfaces] Make LoopLikeOpInterface inheritable outside of MLIR #128743

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
Feb 25, 2025

Conversation

definelicht
Copy link
Contributor

Many interface methods did not prefix the mlir namespace, which prevented inheriting from this interface from an interface defined outside the mlir namespace. Prefix namespaces everywhere to enable this.

@llvmbot
Copy link
Member

llvmbot commented Feb 25, 2025

@llvm/pr-subscribers-mlir

Author: Johannes de Fine Licht (definelicht)

Changes

Many interface methods did not prefix the mlir namespace, which prevented inheriting from this interface from an interface defined outside the mlir namespace. Prefix namespaces everywhere to enable this.


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

1 Files Affected:

  • (modified) mlir/include/mlir/Interfaces/LoopLikeInterface.td (+33-29)
diff --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
index c6bffe347419e..16e14e6a2e4e0 100644
--- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
@@ -239,7 +239,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Returns if a block is inside a loop (within the current function). This
     /// can either be because the block is nested inside a LoopLikeInterface, or
     /// because the control flow graph is cyclic
-    static bool blockIsInLoop(Block *block);
+    static bool blockIsInLoop(::mlir::Block *block);
   }];
 
   let extraSharedClassDeclaration = [{
@@ -249,7 +249,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       auto inductionVars = $_op.getLoopInductionVars();
       if (inductionVars.has_value() && (*inductionVars).size() == 1)
           return (*inductionVars)[0];
-        return std::nullopt;
+        return ::std::nullopt;
     }
     /// Return the single lower bound value or attribute if it exists, otherwise
     /// return std::nullopt.
@@ -257,7 +257,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       auto lowerBounds = $_op.getLoopLowerBounds();
       if (lowerBounds.has_value() && (*lowerBounds).size() == 1)
           return (*lowerBounds)[0];
-      return std::nullopt;
+      return ::std::nullopt;
     }
     /// Return the single step value or attribute if it exists, otherwise
     /// return std::nullopt.
@@ -265,7 +265,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       auto steps = $_op.getLoopSteps();
       if (steps.has_value() && (*steps).size() == 1)
           return (*steps)[0];
-      return std::nullopt;
+      return ::std::nullopt;
     }
     /// Return the single upper bound value or attribute if it exists, otherwise
     /// return std::nullopt.
@@ -287,8 +287,9 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
                                           bool replaceInitOperandUsesInLoop) {
       return $_op.replaceWithAdditionalYields(
           rewriter, newInitOperands, replaceInitOperandUsesInLoop,
-          [](OpBuilder &b, Location loc, ArrayRef<BlockArgument> newBBArgs) {
-            return SmallVector<Value>(newBBArgs);
+          [](::mlir::OpBuilder &b, ::mlir::Location loc,
+             ::mlir::ArrayRef<::mlir::BlockArgument> newBBArgs) {
+            return ::mlir::SmallVector<::mlir::Value>(newBBArgs);
           });
     }
 
@@ -298,9 +299,9 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       auto mutableValues = $_op.getYieldedValuesMutable();
       if (!mutableValues || mutableValues->empty())
         return {};
-      Operation *yieldOp = mutableValues->begin()->getOwner();
+      ::mlir::Operation *yieldOp = mutableValues->begin()->getOwner();
       unsigned firstOperandIndex = mutableValues->begin()->getOperandNumber();
-      return OperandRange(
+      return ::mlir::OperandRange(
           yieldOp->operand_begin() + firstOperandIndex,
           yieldOp->operand_begin() + firstOperandIndex + mutableValues->size());
     }
@@ -312,7 +313,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       if (initsMutable.empty())
         return ::mlir::OperandRange($_op->operand_end(), $_op->operand_end());
       unsigned firstOperandIndex = initsMutable.begin()->getOperandNumber();
-      return OperandRange(
+      return ::mlir::OperandRange(
           $_op->operand_begin() + firstOperandIndex,
           $_op->operand_begin() + firstOperandIndex + initsMutable.size());
     }
@@ -320,7 +321,8 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Return the region iter_arg that corresponds to the given init operand.
     /// Return an "empty" block argument if the given operand is not an init
     /// operand of this loop op.
-    BlockArgument getTiedLoopRegionIterArg(OpOperand *opOperand) {
+    ::mlir::BlockArgument getTiedLoopRegionIterArg(
+        ::mlir::OpOperand *opOperand) {
       auto initsMutable = $_op.getInitsMutable();
       auto it = llvm::find(initsMutable, *opOperand);
       if (it == initsMutable.end())
@@ -331,88 +333,90 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
     /// Return the region iter_arg that corresponds to the given loop result.
     /// Return an "empty" block argument if the given OpResult is not a loop
     /// result or if this op does not expose any loop results.
-    BlockArgument getTiedLoopRegionIterArg(OpResult opResult) {
+    ::mlir::BlockArgument getTiedLoopRegionIterArg(::mlir::OpResult opResult) {
       auto loopResults = $_op.getLoopResults();
       if (!loopResults)
         return {};
       auto it = llvm::find(*loopResults, opResult);
       if (it == loopResults->end())
         return {};
-      return $_op.getRegionIterArgs()[std::distance(loopResults->begin(), it)];
+      return $_op.getRegionIterArgs()[
+          ::std::distance(loopResults->begin(), it)];
     }
 
     /// Return the init operand that corresponds to the given region iter_arg.
     /// Return "nullptr" if the given block argument is not a region iter_arg
     /// of this loop op.
-    OpOperand *getTiedLoopInit(BlockArgument bbArg) {
+    ::mlir::OpOperand *getTiedLoopInit(::mlir::BlockArgument bbArg) {
       auto iterArgs = $_op.getRegionIterArgs();
-      auto it = llvm::find(iterArgs, bbArg);
+      auto it = ::llvm::find(iterArgs, bbArg);
       if (it == iterArgs.end())
         return {};
-      return &$_op.getInitsMutable()[std::distance(iterArgs.begin(), it)];
+      return &$_op.getInitsMutable()[::std::distance(iterArgs.begin(), it)];
     }
 
     /// Return the init operand that corresponds to the given loop result.
     /// Return "nullptr" if the given OpResult is not a loop result or if this
     /// op does not expose any loop results.
-    OpOperand *getTiedLoopInit(OpResult opResult) {
+    ::mlir::OpOperand *getTiedLoopInit(::mlir::OpResult opResult) {
       auto loopResults = $_op.getLoopResults();
       if (!loopResults)
         return nullptr;
-      auto it = llvm::find(*loopResults, opResult);
+      auto it = ::llvm::find(*loopResults, opResult);
       if (it == loopResults->end())
         return nullptr;
-      return &$_op.getInitsMutable()[std::distance(loopResults->begin(), it)];
+      return &$_op.getInitsMutable()[::std::distance(
+          loopResults->begin(), it)];
     }
 
     /// Return the yielded value that corresponds to the given region iter_arg.
     /// Return "nullptr" if the given block argument is not a region iter_arg
     /// of this loop op or if there is no yield corresponding to this `bbArg`.
-    OpOperand *getTiedLoopYieldedValue(BlockArgument bbArg) {
+    ::mlir::OpOperand *getTiedLoopYieldedValue(::mlir::BlockArgument bbArg) {
       auto iterArgs = $_op.getRegionIterArgs();
-      auto it = llvm::find(iterArgs, bbArg);
+      auto it = ::llvm::find(iterArgs, bbArg);
       if (it == iterArgs.end())
         return {};
-      std::optional<llvm::MutableArrayRef<::mlir::OpOperand>> yieldValues =
+      ::std::optional<::llvm::MutableArrayRef<::mlir::OpOperand>> yieldValues =
         $_op.getYieldedValuesMutable();
       if (!yieldValues)
         return {};
-      return &yieldValues.value()[std::distance(iterArgs.begin(), it)];
+      return &yieldValues.value()[::std::distance(iterArgs.begin(), it)];
     }
 
     /// Return the loop result that corresponds to the given init operand.
     /// Return an "empty" OpResult if the given operand is not an init operand
     /// of this loop op or if this op does not expose any loop results.
-    OpResult getTiedLoopResult(OpOperand *opOperand) {
+    ::mlir::OpResult getTiedLoopResult(::mlir::OpOperand *opOperand) {
       auto loopResults = $_op.getLoopResults();
       if (!loopResults)
         return {};
       auto initsMutable = $_op.getInitsMutable();
-      auto it = llvm::find(initsMutable, *opOperand);
+      auto it = ::llvm::find(initsMutable, *opOperand);
       if (it == initsMutable.end())
         return {};
-      return (*loopResults)[std::distance(initsMutable.begin(), it)];
+      return (*loopResults)[::std::distance(initsMutable.begin(), it)];
     }
 
     /// Return the loop result that corresponds to the given region iter_arg.
     /// Return an "empty" OpResult if the given block argument is not a region
     /// iter_arg of this loop op or if this op does not expose any loop results.
-    OpResult getTiedLoopResult(BlockArgument bbArg) {
+    ::mlir::OpResult getTiedLoopResult(::mlir::BlockArgument bbArg) {
       auto loopResults = $_op.getLoopResults();
       if (!loopResults)
         return {};
       auto iterArgs = $_op.getRegionIterArgs();
-      auto it = llvm::find(iterArgs, bbArg);
+      auto it = ::llvm::find(iterArgs, bbArg);
       if (it == iterArgs.end())
         return {};
-      return (*loopResults)[std::distance(iterArgs.begin(), it)];
+      return (*loopResults)[::std::distance(iterArgs.begin(), it)];
     }
   }];
 
   let verifyWithRegions = 1;
 
   let verify = [{
-    return detail::verifyLoopLikeOpInterface($_op);
+    return ::mlir::detail::verifyLoopLikeOpInterface($_op);
   }];
 }
 

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix.

Copy link
Contributor

@gysit gysit left a comment

Choose a reason for hiding this comment

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

LGTM modulo nits.

Many interface methods did not prefix the `mlir` namespace, which
prevented inheriting from this interface from an interface defined
outside the `mlir` namespace. Prefix namespaces everywhere to enable
this.
@definelicht definelicht force-pushed the make-loop-interface-inheritable branch from 086214f to c4ae5c5 Compare February 25, 2025 18:30
@definelicht definelicht merged commit 303d7fa into llvm:main Feb 25, 2025
11 checks passed
@definelicht definelicht deleted the make-loop-interface-inheritable branch February 25, 2025 20:54
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.

5 participants