[Mlir-commits] [mlir] ddc2eb0 - [mlir] Adds getUpperBound() to LoopLikeInterface.

Krzysztof Drewniak llvmlistbot at llvm.org
Tue Apr 19 12:56:53 PDT 2022


Author: Krzysztof Drewniak
Date: 2022-04-19T19:56:44Z
New Revision: ddc2eb0ada99cab81b6fae5f0cca999643a4b9f7

URL: https://github.com/llvm/llvm-project/commit/ddc2eb0ada99cab81b6fae5f0cca999643a4b9f7
DIFF: https://github.com/llvm/llvm-project/commit/ddc2eb0ada99cab81b6fae5f0cca999643a4b9f7.diff

LOG: [mlir] Adds getUpperBound() to LoopLikeInterface.

getUpperBound is analogous to getLowerBound(), except for the upper
bound, and is used in range analysis.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D124020

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
    mlir/include/mlir/Dialect/SCF/SCFOps.td
    mlir/include/mlir/Interfaces/LoopLikeInterface.td
    mlir/lib/Dialect/Affine/IR/AffineOps.cpp
    mlir/lib/Dialect/SCF/SCF.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
index 3880ad88c1ee0..854c582a42b58 100644
--- a/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
+++ b/mlir/include/mlir/Dialect/Affine/IR/AffineOps.td
@@ -109,7 +109,8 @@ def AffineApplyOp : Affine_Op<"apply", [NoSideEffect]> {
 def AffineForOp : Affine_Op<"for",
     [AutomaticAllocationScope, ImplicitAffineTerminator, RecursiveSideEffects,
      DeclareOpInterfaceMethods<LoopLikeOpInterface,
-     ["getSingleInductionVar", "getSingleLowerBound", "getSingleStep"]>]> {
+     ["getSingleInductionVar", "getSingleLowerBound", "getSingleStep",
+      "getSingleUpperBound"]>]> {
   let summary = "for operation";
   let description = [{
     Syntax:

diff  --git a/mlir/include/mlir/Dialect/SCF/SCFOps.td b/mlir/include/mlir/Dialect/SCF/SCFOps.td
index 638d45d8f15dc..420675272ddd7 100644
--- a/mlir/include/mlir/Dialect/SCF/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/SCFOps.td
@@ -111,7 +111,8 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
 
 def ForOp : SCF_Op<"for",
       [AutomaticAllocationScope, DeclareOpInterfaceMethods<LoopLikeOpInterface,
-       ["getSingleInductionVar", "getSingleLowerBound", "getSingleStep"]>,
+       ["getSingleInductionVar", "getSingleLowerBound", "getSingleStep",
+        "getSingleUpperBound"]>,
        DeclareOpInterfaceMethods<RegionBranchOpInterface>,
        SingleBlockImplicitTerminator<"scf::YieldOp">,
        RecursiveSideEffects]> {

diff  --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
index 18b81760c7ae6..4e3dd574c7435 100644
--- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
@@ -61,7 +61,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       }]
     >,
     InterfaceMethod<[{
-        Return the single lower bound value or attribute if it exist, otherwise
+        Return the single lower bound value or attribute if it exists, otherwise
         return llvm::None.
       }],
       /*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
@@ -73,7 +73,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       }]
     >,
     InterfaceMethod<[{
-        Return the single step value or attribute if it exist, otherwise
+        Return the single step value or attribute if it exists, otherwise
         return llvm::None.
       }],
       /*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
@@ -84,6 +84,18 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
         return llvm::None;
       }]
     >,
+    InterfaceMethod<[{
+        Return the single upper bound value or attribute if it exists, otherwise
+        return llvm::None.
+      }],
+      /*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
+      /*methodName=*/"getSingleUpperBound",
+      /*args=*/(ins),
+      /*methodBody=*/"",
+      /*defaultImplementation=*/[{
+        return llvm::None;
+      }]
+    >,
   ];
 }
 

diff  --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index 2ea601a4f0f46..60ada4eaa9b52 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -1873,6 +1873,13 @@ Optional<OpFoldResult> AffineForOp::getSingleStep() {
   return OpFoldResult(b.getI64IntegerAttr(getStep()));
 }
 
+Optional<OpFoldResult> AffineForOp::getSingleUpperBound() {
+  if (!hasConstantUpperBound())
+    return llvm::None;
+  OpBuilder b(getContext());
+  return OpFoldResult(b.getI64IntegerAttr(getConstantUpperBound()));
+}
+
 /// Returns true if the provided value is the induction variable of a
 /// AffineForOp.
 bool mlir::isForInductionVar(Value val) {

diff  --git a/mlir/lib/Dialect/SCF/SCF.cpp b/mlir/lib/Dialect/SCF/SCF.cpp
index d160057838d31..eb3c57d36e896 100644
--- a/mlir/lib/Dialect/SCF/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/SCF.cpp
@@ -356,6 +356,10 @@ Optional<OpFoldResult> ForOp::getSingleStep() {
   return OpFoldResult(getStep());
 }
 
+Optional<OpFoldResult> ForOp::getSingleUpperBound() {
+  return OpFoldResult(getUpperBound());
+}
+
 /// Prints the initialization list in the form of
 ///   <prefix>(%inner = %outer, %inner2 = %outer2, <...>)
 /// where 'inner' values are assumed to be region arguments and 'outer' values


        


More information about the Mlir-commits mailing list