-
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::ParallelOp #68511
Conversation
@llvm/pr-subscribers-mlir-scf @llvm/pr-subscribers-mlir ChangesThis adds implementations for Related: #67883 Full diff: https://github.com/llvm/llvm-project/pull/68511.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..21847592aebfdcd 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -788,7 +788,8 @@ def IfOp : SCF_Op<"if", [DeclareOpInterfaceMethods<RegionBranchOpInterface, [
def ParallelOp : SCF_Op<"parallel",
[AutomaticAllocationScope,
AttrSizedOperandSegments,
- DeclareOpInterfaceMethods<LoopLikeOpInterface>,
+ DeclareOpInterfaceMethods<LoopLikeOpInterface, ["getSingleInductionVar",
+ "getSingleLowerBound", "getSingleUpperBound", "getSingleStep"]>,
RecursiveMemoryEffects,
DeclareOpInterfaceMethods<RegionBranchOpInterface>,
SingleBlockImplicitTerminator<"scf::YieldOp">]> {
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 8d8481421e18d57..3cc1943d66c3c83 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -2911,6 +2911,30 @@ void ParallelOp::print(OpAsmPrinter &p) {
SmallVector<Region *> ParallelOp::getLoopRegions() { return {&getRegion()}; }
+std::optional<Value> ParallelOp::getSingleInductionVar() {
+ if (getNumLoops() != 1)
+ return std::nullopt;
+ return getBody()->getArgument(0);
+}
+
+std::optional<OpFoldResult> ParallelOp::getSingleLowerBound() {
+ if (getNumLoops() != 1)
+ return std::nullopt;
+ return getLowerBound()[0];
+}
+
+std::optional<OpFoldResult> ParallelOp::getSingleUpperBound() {
+ if (getNumLoops() != 1)
+ return std::nullopt;
+ return getUpperBound()[0];
+}
+
+std::optional<OpFoldResult> ParallelOp::getSingleStep() {
+ if (getNumLoops() != 1)
+ return std::nullopt;
+ return getStep()[0];
+}
+
ParallelOp mlir::scf::getParallelForInductionVarOwner(Value val) {
auto ivArg = llvm::dyn_cast<BlockArgument>(val);
if (!ivArg)
|
bbfafe0
to
342834f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't suppose there is any chance to test this without writing a heavy unittest?
I think a unittest for |
What do you think about something like this? It might be a little overkill just for the |
LGTM |
97148e4
to
a09bedf
Compare
✅ With the latest revision this PR passed the C/C++ code formatter. |
…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
a09bedf
to
6d71605
Compare
Actually I don't understand why this is a C++ unit-test. We have quite a track record of not doing so and making test passes instead. Unless I'm missing something this could easily be done that way? |
I will take a look at this and rewrite it into a test pass if possible |
This adds implementations for
getSingleIterationVar
,getSingleLowerBound
,getSingleUpperBound
,getSingleStep
ofLoopLikeOpInterface
toscf::ParallelOp
. Until now, the implementations for these methods defaulted to returningstd::nullopt
, even in the special case where the parallel Op only has one dimension.Related: #67883