@@ -136,8 +136,8 @@ def ExecuteRegionOp : SCF_Op<"execute_region", [
136136def ForOp : SCF_Op<"for",
137137 [AutomaticAllocationScope, DeclareOpInterfaceMethods<LoopLikeOpInterface,
138138 ["getInitsMutable", "getLoopResults", "getRegionIterArgs",
139- "getSingleInductionVar ", "getSingleLowerBound ", "getSingleStep ",
140- "getSingleUpperBound ", "getYieldedValuesMutable",
139+ "getLoopInductionVars ", "getLoopLowerBounds ", "getLoopSteps ",
140+ "getLoopUpperBounds ", "getYieldedValuesMutable",
141141 "promoteIfSingleIteration", "replaceWithAdditionalYields",
142142 "yieldTiledValuesAndReplace"]>,
143143 AllTypesMatch<["lowerBound", "upperBound", "step"]>,
@@ -301,8 +301,8 @@ def ForallOp : SCF_Op<"forall", [
301301 AttrSizedOperandSegments,
302302 AutomaticAllocationScope,
303303 DeclareOpInterfaceMethods<LoopLikeOpInterface,
304- ["getInitsMutable", "getRegionIterArgs", "getSingleInductionVar ",
305- "getSingleLowerBound ", "getSingleUpperBound ", "getSingleStep ",
304+ ["getInitsMutable", "getRegionIterArgs", "getLoopInductionVars ",
305+ "getLoopLowerBounds ", "getLoopUpperBounds ", "getLoopSteps ",
306306 "promoteIfSingleIteration", "yieldTiledValuesAndReplace"]>,
307307 RecursiveMemoryEffects,
308308 SingleBlockImplicitTerminator<"scf::InParallelOp">,
@@ -510,22 +510,31 @@ def ForallOp : SCF_Op<"forall", [
510510 ];
511511
512512 let extraClassDeclaration = [{
513- // Get lower bounds as OpFoldResult.
513+ /// Get induction variables.
514+ SmallVector<Value> getInductionVars() {
515+ std::optional<SmallVector<Value>> maybeInductionVars = getLoopInductionVars();
516+ assert(maybeInductionVars.has_value() && "expected values");
517+ return *maybeInductionVars;
518+ }
519+ /// Get lower bounds as OpFoldResult.
514520 SmallVector<OpFoldResult> getMixedLowerBound() {
515- Builder b(getOperation()->getContext());
516- return getMixedValues(getStaticLowerBound(), getDynamicLowerBound(), b);
521+ std::optional<SmallVector<OpFoldResult>> maybeLowerBounds = getLoopLowerBounds();
522+ assert(maybeLowerBounds.has_value() && "expected values");
523+ return *maybeLowerBounds;
517524 }
518525
519- // Get upper bounds as OpFoldResult.
526+ /// Get upper bounds as OpFoldResult.
520527 SmallVector<OpFoldResult> getMixedUpperBound() {
521- Builder b(getOperation()->getContext());
522- return getMixedValues(getStaticUpperBound(), getDynamicUpperBound(), b);
528+ std::optional<SmallVector<OpFoldResult>> maybeUpperBounds = getLoopUpperBounds();
529+ assert(maybeUpperBounds.has_value() && "expected values");
530+ return *maybeUpperBounds;
523531 }
524532
525- // Get steps as OpFoldResult.
533+ /// Get steps as OpFoldResult.
526534 SmallVector<OpFoldResult> getMixedStep() {
527- Builder b(getOperation()->getContext());
528- return getMixedValues(getStaticStep(), getDynamicStep(), b);
535+ std::optional<SmallVector<OpFoldResult>> maybeSteps = getLoopSteps();
536+ assert(maybeSteps.has_value() && "expected values");
537+ return *maybeSteps;
529538 }
530539
531540 /// Get lower bounds as values.
@@ -584,10 +593,6 @@ def ForallOp : SCF_Op<"forall", [
584593 getNumDynamicControlOperands() + getRank());
585594 }
586595
587- ::mlir::ValueRange getInductionVars() {
588- return getBody()->getArguments().take_front(getRank());
589- }
590-
591596 ::mlir::Value getInductionVar(int64_t idx) {
592597 return getInductionVars()[idx];
593598 }
@@ -765,8 +770,8 @@ def IfOp : SCF_Op<"if", [DeclareOpInterfaceMethods<RegionBranchOpInterface, [
765770def ParallelOp : SCF_Op<"parallel",
766771 [AutomaticAllocationScope,
767772 AttrSizedOperandSegments,
768- DeclareOpInterfaceMethods<LoopLikeOpInterface, ["getSingleInductionVar ",
769- "getSingleLowerBound ", "getSingleUpperBound ", "getSingleStep "]>,
773+ DeclareOpInterfaceMethods<LoopLikeOpInterface, ["getLoopInductionVars ",
774+ "getLoopLowerBounds ", "getLoopUpperBounds ", "getLoopSteps "]>,
770775 RecursiveMemoryEffects,
771776 DeclareOpInterfaceMethods<RegionBranchOpInterface>,
772777 SingleBlockImplicitTerminator<"scf::ReduceOp">,
@@ -846,8 +851,11 @@ def ParallelOp : SCF_Op<"parallel",
846851 ];
847852
848853 let extraClassDeclaration = [{
849- ValueRange getInductionVars() {
850- return getBody()->getArguments();
854+ /// Get induction variables.
855+ SmallVector<Value> getInductionVars() {
856+ std::optional<SmallVector<Value>> maybeInductionVars = getLoopInductionVars();;
857+ assert(maybeInductionVars.has_value() && "expected values");
858+ return *maybeInductionVars;
851859 }
852860 unsigned getNumLoops() { return getStep().size(); }
853861 unsigned getNumReductions() { return getInitVals().size(); }
0 commit comments