[Mlir-commits] [mlir] [mlir][scf] Implement getSingle... of LoopLikeOpInterface for scf::ForallOp (PR #67883)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Sep 30 06:54:26 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
<details>
<summary>Changes</summary>
The `getSingle(UpperBound|LowerBound|Step)` methods of `LoopLikeOpInterface` are
useful to quickly query the iteration space of unidimensional loops. Until now,
`scf::ForallOp` always fell back to the default implementation of these methods,
returning `std::nullopt`.
This patch implements those methods, returning the respective bounds or steps
in the special case of `rank == 1`.
---
Full diff: https://github.com/llvm/llvm-project/pull/67883.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/SCF/IR/SCFOps.td (+2-1)
- (modified) mlir/lib/Dialect/SCF/IR/SCF.cpp (+21)
``````````diff
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index e1a604a88715f0e..218d3b09d96fb05 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -331,7 +331,8 @@ def ForallOp : SCF_Op<"forall", [
AttrSizedOperandSegments,
AutomaticAllocationScope,
DeclareOpInterfaceMethods<LoopLikeOpInterface,
- ["promoteIfSingleIteration"]>,
+ ["promoteIfSingleIteration", "getSingleLowerBound",
+ "getSingleUpperBound", "getSingleStep"]>,
RecursiveMemoryEffects,
SingleBlockImplicitTerminator<"scf::InParallelOp">,
DeclareOpInterfaceMethods<RegionBranchOpInterface>,
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 8d8481421e18d57..bfe6ccd7b1169df 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -1526,6 +1526,27 @@ InParallelOp ForallOp::getTerminator() {
return cast<InParallelOp>(getBody()->getTerminator());
}
+std::optional<OpFoldResult> ForallOp::getSingleLowerBound() {
+ if (getRank() != 1)
+ return std::nullopt;
+
+ return getMixedLowerBound()[0];
+}
+
+std::optional<OpFoldResult> ForallOp::getSingleUpperBound() {
+ if (getRank() != 1)
+ return std::nullopt;
+
+ return getMixedUpperBound()[0];
+}
+
+std::optional<OpFoldResult> ForallOp::getSingleStep() {
+ if (getRank() != 1)
+ return std::nullopt;
+
+ return getMixedStep()[0];
+}
+
ForallOp mlir::scf::getForallOpThreadIndexOwner(Value val) {
auto tidxArg = llvm::dyn_cast<BlockArgument>(val);
if (!tidxArg)
``````````
</details>
https://github.com/llvm/llvm-project/pull/67883
More information about the Mlir-commits
mailing list