Skip to content

Commit ddc2eb0

Browse files
committed
[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
1 parent 0eb403a commit ddc2eb0

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

mlir/include/mlir/Dialect/Affine/IR/AffineOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def AffineApplyOp : Affine_Op<"apply", [NoSideEffect]> {
109109
def AffineForOp : Affine_Op<"for",
110110
[AutomaticAllocationScope, ImplicitAffineTerminator, RecursiveSideEffects,
111111
DeclareOpInterfaceMethods<LoopLikeOpInterface,
112-
["getSingleInductionVar", "getSingleLowerBound", "getSingleStep"]>]> {
112+
["getSingleInductionVar", "getSingleLowerBound", "getSingleStep",
113+
"getSingleUpperBound"]>]> {
113114
let summary = "for operation";
114115
let description = [{
115116
Syntax:

mlir/include/mlir/Dialect/SCF/SCFOps.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
111111

112112
def ForOp : SCF_Op<"for",
113113
[AutomaticAllocationScope, DeclareOpInterfaceMethods<LoopLikeOpInterface,
114-
["getSingleInductionVar", "getSingleLowerBound", "getSingleStep"]>,
114+
["getSingleInductionVar", "getSingleLowerBound", "getSingleStep",
115+
"getSingleUpperBound"]>,
115116
DeclareOpInterfaceMethods<RegionBranchOpInterface>,
116117
SingleBlockImplicitTerminator<"scf::YieldOp">,
117118
RecursiveSideEffects]> {

mlir/include/mlir/Interfaces/LoopLikeInterface.td

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
6161
}]
6262
>,
6363
InterfaceMethod<[{
64-
Return the single lower bound value or attribute if it exist, otherwise
64+
Return the single lower bound value or attribute if it exists, otherwise
6565
return llvm::None.
6666
}],
6767
/*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
@@ -73,7 +73,7 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
7373
}]
7474
>,
7575
InterfaceMethod<[{
76-
Return the single step value or attribute if it exist, otherwise
76+
Return the single step value or attribute if it exists, otherwise
7777
return llvm::None.
7878
}],
7979
/*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
@@ -84,6 +84,18 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
8484
return llvm::None;
8585
}]
8686
>,
87+
InterfaceMethod<[{
88+
Return the single upper bound value or attribute if it exists, otherwise
89+
return llvm::None.
90+
}],
91+
/*retTy=*/"::mlir::Optional<::mlir::OpFoldResult>",
92+
/*methodName=*/"getSingleUpperBound",
93+
/*args=*/(ins),
94+
/*methodBody=*/"",
95+
/*defaultImplementation=*/[{
96+
return llvm::None;
97+
}]
98+
>,
8799
];
88100
}
89101

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,13 @@ Optional<OpFoldResult> AffineForOp::getSingleStep() {
18731873
return OpFoldResult(b.getI64IntegerAttr(getStep()));
18741874
}
18751875

1876+
Optional<OpFoldResult> AffineForOp::getSingleUpperBound() {
1877+
if (!hasConstantUpperBound())
1878+
return llvm::None;
1879+
OpBuilder b(getContext());
1880+
return OpFoldResult(b.getI64IntegerAttr(getConstantUpperBound()));
1881+
}
1882+
18761883
/// Returns true if the provided value is the induction variable of a
18771884
/// AffineForOp.
18781885
bool mlir::isForInductionVar(Value val) {

mlir/lib/Dialect/SCF/SCF.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ Optional<OpFoldResult> ForOp::getSingleStep() {
356356
return OpFoldResult(getStep());
357357
}
358358

359+
Optional<OpFoldResult> ForOp::getSingleUpperBound() {
360+
return OpFoldResult(getUpperBound());
361+
}
362+
359363
/// Prints the initialization list in the form of
360364
/// <prefix>(%inner = %outer, %inner2 = %outer2, <...>)
361365
/// where 'inner' values are assumed to be region arguments and 'outer' values

0 commit comments

Comments
 (0)