@@ -403,16 +403,22 @@ def BroadcastOp : Core_Op<"broadcast", [
403403 let hasVerifier = 1;
404404}
405405
406- // Not core according to spec, but we don't want to unroll in the general case.
407- def ForConstOp : Core_Op<"for_const", [
406+ def ForOp : Core_Op<"for", [
408407 Pure,
409- AllTypesMatch<["rangeBegin", "rangeEnd"]> ,
408+ AttrSizedOperandSegments ,
410409 DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getEntrySuccessorOperands"]>]> {
411- let summary = "For loop with constant bounds";
410+ let summary = "For loop with dynamic bounds";
412411
413412 let description = [{
414- A loop iterating over the integer range starting at `rangeBegin`
415- (inclusive) and ending at `rangeEnd` (exclusive).
413+ A loop iterating over one of three ranges:
414+ 1) `dynBegin` (inclusive) to `dynEnd` (exclusive)
415+ 2) `begin` to `begin` + `iters`, where `iters` is an integer
416+ 3) `begin` to `begin` + `iters`, where `iters` is a matrix dimension
417+
418+ Only instances with range types 2 or 3 are considered part of GraphAlg
419+ Core. Constant propagation is expected to transform range type 1 into
420+ either 2 or 3.
421+
416422 The `body` region is executed once for every value in the integer range
417423 (that value is passed as the first block argument).
418424 At the first iteration of the loop, the other block arguments take the
@@ -432,58 +438,39 @@ def ForConstOp : Core_Op<"for_const", [
432438
433439 let arguments = (ins
434440 Variadic<Matrix>:$initArgs,
435- I64Scalar:$rangeBegin,
436- I64Scalar:$rangeEnd);
441+ Optional<I64Scalar>:$dynBegin,
442+ Optional<I64Scalar>:$dynEnd,
443+ OptionalAttr<I64Attr>:$begin,
444+ OptionalAttr<DimAttr>:$iters);
437445
438446 let results = (outs Variadic<Matrix>:$results);
439447
440448 let regions = (region SizedRegion<1>:$body, MaxSizedRegion<1>:$until);
441449
442450 let assemblyFormat = [{
443- `range ` `(`
444- $rangeBegin `,`
445- $rangeEnd
446- `) ` `:` type($rangeEnd)
451+ (`dyn_begin ` `` `=` `` $dynBegin^)?
452+ (`dyn_end` `` `=` `` $dynEnd^)?
453+ (`begin` `` `=` `` $begin^)?
454+ (`iters ` `` `=` `` $iters^)?
447455 `init` `(` $initArgs `)` `:` type($initArgs) `->` type($results) attr-dict
448456 `body` $body
449457 `until` $until
450458 }];
451459
460+ let hasVerifier = 1;
452461 let hasRegionVerifier = 1;
453- }
454-
455- def ForDimOp : Core_Op<"for_dim", [
456- Pure,
457- DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getEntrySuccessorOperands"]>]> {
458- let summary = "For loop over a matrix dimension";
459-
460- let description = [{
461- A loop iterating over the half-open range [0..`dim`).
462-
463- This op is otherwise equivalent to `ForConstOp`.
464- }];
465-
466- let arguments = (ins Variadic<Matrix>:$initArgs, DimAttr:$dim);
467-
468- let results = (outs Variadic<Matrix>:$results);
469-
470- let regions = (region SizedRegion<1>:$body, MaxSizedRegion<1>:$until);
462+ let hasFolder = 1;
471463
472- let assemblyFormat = [{
473- `range` `(` custom<BareAttr>($dim) `)`
474- `init` `(` $initArgs `)` `:` type($initArgs) `->` type($results) attr-dict
475- `body` $body
476- `until` $until
464+ let extraClassDeclaration = [{
465+ /** Whether at least one of `dyn_begin` and `dyn_end` is set. */
466+ bool isDynamicRange();
477467 }];
478-
479- let hasRegionVerifier = 1;
480- let hasCanonicalizer = 1;
481468}
482469
483470def YieldOp : Core_Op<"yield", [
484471 Pure,
485472 Terminator,
486- ParentOneOf<["ForConstOp", "ForDimOp"] >,
473+ HasParent<"ForOp" >,
487474 DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface>]> {
488475 let summary = "Yield from a loop body";
489476
0 commit comments