-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[mlir][scf] Implement getSingle... of LoopLikeOpInterface for scf::ForallOp #67883
Conversation
…rallOp 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`.
@llvm/pr-subscribers-mlir-scf @llvm/pr-subscribers-mlir ChangesThe This patch implements those methods, returning the respective bounds or steps Full diff: https://github.com/llvm/llvm-project/pull/67883.diff 2 Files Affected:
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)
|
…rallelOp This adds implementations for `getSingleIterationVar`, `getSingleLowerBound`, `getSingleUpperBound`, `getSingleStep` of `LoopLikeOpInterface` to `scf::ParallelOp`. Until now, the implementations for these methods defaulted to returning `std::nullopt`, even in the special case where the parallel Op only has one dimension. Related: llvm#67883
…rallelOp (#68511) This adds implementations for `getSingleIterationVar`, `getSingleLowerBound`, `getSingleUpperBound`, `getSingleStep` of `LoopLikeOpInterface` to `scf::ParallelOp`. Until now, the implementations for these methods defaulted to returning `std::nullopt`, even in the special case where the parallel Op only has one dimension. Related: #67883
The
getSingle(IterationVar|UpperBound|LowerBound|Step)
methods ofLoopLikeOpInterface
areuseful 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
.