@@ -403,22 +403,16 @@ def BroadcastOp : Core_Op<"broadcast", [
403403 let hasVerifier = 1;
404404}
405405
406- def ForOp : Core_Op<"for", [
406+ // Not core according to spec, but we don't want to unroll in the general case.
407+ def ForConstOp : Core_Op<"for_const", [
407408 Pure,
408- AttrSizedOperandSegments ,
409+ AllTypesMatch<["rangeBegin", "rangeEnd"]> ,
409410 DeclareOpInterfaceMethods<RegionBranchOpInterface, ["getEntrySuccessorOperands"]>]> {
410- let summary = "For loop with dynamic bounds";
411+ let summary = "For loop with constant bounds";
411412
412413 let description = [{
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-
414+ A loop iterating over the integer range starting at `rangeBegin`
415+ (inclusive) and ending at `rangeEnd` (exclusive).
422416 The `body` region is executed once for every value in the integer range
423417 (that value is passed as the first block argument).
424418 At the first iteration of the loop, the other block arguments take the
@@ -438,39 +432,58 @@ def ForOp : Core_Op<"for", [
438432
439433 let arguments = (ins
440434 Variadic<Matrix>:$initArgs,
441- Optional<I64Scalar>:$dynBegin,
442- Optional<I64Scalar>:$dynEnd,
443- OptionalAttr<I64Attr>:$begin,
444- OptionalAttr<DimAttr>:$iters);
435+ I64Scalar:$rangeBegin,
436+ I64Scalar:$rangeEnd);
445437
446438 let results = (outs Variadic<Matrix>:$results);
447439
448440 let regions = (region SizedRegion<1>:$body, MaxSizedRegion<1>:$until);
449441
450442 let assemblyFormat = [{
451- (`dyn_begin ` `` `=` `` $dynBegin^)?
452- (`dyn_end` `` `=` `` $dynEnd^)?
453- (`begin` `` `=` `` $begin^)?
454- (`iters ` `` `=` `` $iters^)?
443+ `range ` `(`
444+ $rangeBegin `,`
445+ $rangeEnd
446+ `) ` `:` type($rangeEnd)
455447 `init` `(` $initArgs `)` `:` type($initArgs) `->` type($results) attr-dict
456448 `body` $body
457449 `until` $until
458450 }];
459451
460- let hasVerifier = 1;
461452 let hasRegionVerifier = 1;
462- let hasFolder = 1;
453+ }
463454
464- let extraClassDeclaration = [{
465- /** Whether at least one of `dyn_begin` and `dyn_end` is set. */
466- bool isDynamicRange();
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`.
467464 }];
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);
471+
472+ let assemblyFormat = [{
473+ `range` `(` custom<BareAttr>($dim) `)`
474+ `init` `(` $initArgs `)` `:` type($initArgs) `->` type($results) attr-dict
475+ `body` $body
476+ `until` $until
477+ }];
478+
479+ let hasRegionVerifier = 1;
480+ let hasCanonicalizer = 1;
468481}
469482
470483def YieldOp : Core_Op<"yield", [
471484 Pure,
472485 Terminator,
473- HasParent<"ForOp" >,
486+ ParentOneOf<["ForConstOp", "ForDimOp"] >,
474487 DeclareOpInterfaceMethods<RegionBranchTerminatorOpInterface>]> {
475488 let summary = "Yield from a loop body";
476489
0 commit comments