Skip to content

Commit adf9870

Browse files
committed
[mlir][scf] Implement getSingle... of LoopLikeOpinterface for scf::ParallelOp
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
1 parent 614a8cb commit adf9870

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ def IfOp : SCF_Op<"if", [DeclareOpInterfaceMethods<RegionBranchOpInterface, [
791791
def ParallelOp : SCF_Op<"parallel",
792792
[AutomaticAllocationScope,
793793
AttrSizedOperandSegments,
794-
DeclareOpInterfaceMethods<LoopLikeOpInterface>,
794+
DeclareOpInterfaceMethods<LoopLikeOpInterface, ["getSingleInductionVar",
795+
"getSingleLowerBound", "getSingleUpperBound", "getSingleStep"]>,
795796
RecursiveMemoryEffects,
796797
DeclareOpInterfaceMethods<RegionBranchOpInterface>,
797798
SingleBlockImplicitTerminator<"scf::YieldOp">]> {

mlir/lib/Dialect/SCF/IR/SCF.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2936,6 +2936,30 @@ void ParallelOp::print(OpAsmPrinter &p) {
29362936

29372937
SmallVector<Region *> ParallelOp::getLoopRegions() { return {&getRegion()}; }
29382938

2939+
std::optional<Value> ParallelOp::getSingleInductionVar() {
2940+
if (getNumLoops() != 1)
2941+
return std::nullopt;
2942+
return getBody()->getArgument(0);
2943+
}
2944+
2945+
std::optional<OpFoldResult> ParallelOp::getSingleLowerBound() {
2946+
if (getNumLoops() != 1)
2947+
return std::nullopt;
2948+
return getLowerBound()[0];
2949+
}
2950+
2951+
std::optional<OpFoldResult> ParallelOp::getSingleUpperBound() {
2952+
if (getNumLoops() != 1)
2953+
return std::nullopt;
2954+
return getUpperBound()[0];
2955+
}
2956+
2957+
std::optional<OpFoldResult> ParallelOp::getSingleStep() {
2958+
if (getNumLoops() != 1)
2959+
return std::nullopt;
2960+
return getStep()[0];
2961+
}
2962+
29392963
ParallelOp mlir::scf::getParallelForInductionVarOwner(Value val) {
29402964
auto ivArg = llvm::dyn_cast<BlockArgument>(val);
29412965
if (!ivArg)

0 commit comments

Comments
 (0)