Skip to content

Commit 9547e96

Browse files
committed
Revert "Don't require setting dimensions when lowering to garel (#22)"
This reverts commit 56bf019.
1 parent 56bf019 commit 9547e96

41 files changed

Lines changed: 466 additions & 651 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/include/garel/GARelAttr.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def AggregateFunc : I64EnumAttr<
3838
I64EnumAttrCase<"MAX", 2>,
3939
I64EnumAttrCase<"LOR", 3>, /* Logical OR (over i1) */
4040
I64EnumAttrCase<"ARGMIN", 4>,
41-
I64EnumAttrCase<"COUNT", 5>,
4241
]
4342
> {
4443
let cppNamespace = "::garel";
@@ -50,7 +49,7 @@ def Aggregator : GARel_Attr<"Aggregator", "aggregator"> {
5049

5150
let parameters = (ins
5251
"AggregateFunc":$func,
53-
OptionalArrayRefParameter<"ColumnIdx">:$inputs);
52+
ArrayRefParameter<"ColumnIdx">:$inputs);
5453

5554
let assemblyFormat = [{
5655
`<` $func $inputs `>`

compiler/include/garel/GARelOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def ForOp : GARel_Op<"for", [InferTypeOpAdaptor]> {
143143

144144
let arguments = (ins
145145
Variadic<Relation>:$init,
146-
I64Relation:$iters,
146+
I64Attr:$iters,
147147
I64Attr:$resultIdx);
148148

149149
let regions = (region

compiler/include/garel/GARelTypes.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include <mlir/IR/MLIRContext.h>
43
#include <mlir/IR/Types.h>
54

65
#include "garel/GARelAttr.h"
@@ -12,6 +11,4 @@ namespace garel {
1211

1312
bool isColumnType(mlir::Type t);
1413

15-
RelationType getI64RelationType(mlir::MLIRContext *ctx);
16-
1714
} // namespace garel

compiler/include/garel/GARelTypes.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,4 @@ def Tuple : GARel_Type<"Tuple", "tuple"> {
3434

3535
def ColumnType : Type<CPred<"::garel::isColumnType($_self)">, "column type">;
3636

37-
def I64Relation : Type<
38-
CPred<"::garel::getI64RelationType($_self.getContext()) == $_self">,
39-
"relation with a single i64 column",
40-
"RelationType">,
41-
BuildableType<"::garel::getI64RelationType($_builder.getContext())">;
42-
4337
#endif // GAREL_TYPES

compiler/include/graphalg/GraphAlgOps.td

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

470483
def 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

compiler/include/graphalg/GraphAlgPasses.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33

44
include "mlir/Pass/PassBase.td"
55

6-
def GraphAlgSetConstArg : Pass<"graphalg-set-const-arg", "::mlir::ModuleOp"> {
7-
let summary = "Propagate a constant integer argument into a function";
8-
9-
let options = [
10-
Option<"functionName", "func", "std::string", /*default=*/"\"\"", "Name of the function to call">,
11-
Option<"argumentNumber", "argNum", "int", /*default=*/"-1", "The argument number that is constant">,
12-
Option<"value", "value", "std::int64_t", /*default=*/"0", "The value to propagate">,
13-
];
14-
}
15-
166
def GraphAlgPrepareInline : Pass<"graphalg-prepare-inline", "::mlir::ModuleOp"> {
177
let summary = "Prepares the IR for function inlining";
188

compiler/include/graphalg/GraphAlgSetConstArg.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

compiler/src/garel/GARelAttr.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,23 @@ mlir::Type AggregatorAttr::getResultType(mlir::Type inputRel) {
2424
case AggregateFunc::ARGMIN:
2525
// NOTE: argmin(arg, val) also uses first input column as output type.
2626
return llvm::cast<RelationType>(inputRel).getColumns()[getInputs()[0]];
27-
case AggregateFunc::COUNT:
28-
return mlir::IntegerType::get(inputRel.getContext(), 64);
29-
}
30-
}
31-
32-
static std::size_t expectedNumInputs(AggregateFunc f) {
33-
switch (f) {
34-
case AggregateFunc::SUM:
35-
case AggregateFunc::MIN:
36-
case AggregateFunc::MAX:
37-
case AggregateFunc::LOR:
38-
return 1;
39-
case AggregateFunc::ARGMIN:
40-
return 2;
41-
case AggregateFunc::COUNT:
42-
return 0;
4327
}
4428
}
4529

4630
mlir::LogicalResult
4731
AggregatorAttr::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
4832
AggregateFunc func, llvm::ArrayRef<ColumnIdx> inputs) {
49-
if (inputs.size() != expectedNumInputs(func)) {
50-
return emitError() << stringifyAggregateFunc(func) << " expects exactly "
51-
<< expectedNumInputs(func) << " inputs, got "
52-
<< inputs.size();
33+
if (func == AggregateFunc::ARGMIN) {
34+
if (inputs.size() != 2) {
35+
return emitError() << stringifyAggregateFunc(func)
36+
<< " expects exactly two inputs (arg, val), got "
37+
<< inputs.size();
38+
}
39+
} else {
40+
if (inputs.size() != 1) {
41+
return emitError() << stringifyAggregateFunc(func)
42+
<< " expects exactly one input, got " << inputs.size();
43+
}
5344
}
5445

5546
return mlir::success();

compiler/src/garel/GARelTypes.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <llvm/ADT/ArrayRef.h>
22
#include <llvm/ADT/TypeSwitch.h>
33
#include <mlir/IR/Builders.h>
4-
#include <mlir/IR/BuiltinTypes.h>
54
#include <mlir/IR/DialectImplementation.h>
65
#include <mlir/IR/OpImplementation.h>
76

@@ -19,11 +18,6 @@ bool isColumnType(mlir::Type t) {
1918
t.isIndex();
2019
}
2120

22-
RelationType getI64RelationType(mlir::MLIRContext *ctx) {
23-
return RelationType::get(
24-
ctx, mlir::ArrayRef<mlir::Type>{mlir::IntegerType::get(ctx, 64)});
25-
}
26-
2721
// Need to define this here to avoid depending on IPRTypes in
2822
// IPRDialect and creating a cycle.
2923
void GARelDialect::registerTypes() {

0 commit comments

Comments
 (0)