Skip to content

Commit 7c55b1b

Browse files
chore: move attribute definitions to dedicated file (#68)
This PR moves all attribute definitions from `SubstraitTypes.td` to a new file `SubstraitAttrs.td` in order to separate the definitions of the two things better. Having them in one file was acceptable for boot strapping but the file has grow significantly lately, so I think it's time to clean up a bit. Signed-off-by: Ingo Müller <[email protected]>
1 parent 39864c6 commit 7c55b1b

File tree

4 files changed

+131
-114
lines changed

4 files changed

+131
-114
lines changed

include/substrait-mlir/Dialect/Substrait/IR/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
# Add dialect, types, and ops.
12
add_mlir_dialect(SubstraitOps substrait)
23
add_dependencies(MLIRSubstraitDialect MLIRSubstraitOpsIncGen)
34

4-
# Add Enums
5+
# Add enums.
56
set(LLVM_TARGET_DEFINITIONS SubstraitOps.td)
67
mlir_tablegen(SubstraitEnums.h.inc -gen-enum-decls)
78
mlir_tablegen(SubstraitEnums.cpp.inc -gen-enum-defs)
89
add_public_tablegen_target(MLIRSubstraitEnumsIncGen)
910
add_dependencies(MLIRSubstraitDialect MLIRSubstraitEnumsIncGen)
1011

11-
# Add custom type attributes
12-
set(LLVM_TARGET_DEFINITIONS SubstraitTypes.td)
12+
# Add attributes.
13+
set(LLVM_TARGET_DEFINITIONS SubstraitAttrs.td)
1314
mlir_tablegen(SubstraitOpsAttrs.h.inc --gen-attrdef-decls)
1415
mlir_tablegen(SubstraitOpsAttrs.cpp.inc --gen-attrdef-defs)
1516
add_public_tablegen_target(MLIRSubstraitAttrsIncGen)
1617
add_dependencies(MLIRSubstraitDialect MLIRSubstraitAttrsIncGen)
1718

19+
# Add interfaces.
1820
set(LLVM_TARGET_DEFINITIONS SubstraitInterfaces.td)
1921
mlir_tablegen(SubstraitOpInterfaces.h.inc -gen-op-interface-decls)
2022
mlir_tablegen(SubstraitOpInterfaces.cpp.inc -gen-op-interface-defs)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//===-- SubstraitAttrs.td - Substrait dialect attributes ---*- tablegen -*-===//
2+
//
3+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef SUBSTRAIT_DIALECT_SUBSTRAIT_IR_SUBSTRAITATTRS
10+
#define SUBSTRAIT_DIALECT_SUBSTRAIT_IR_SUBSTRAITATTRS
11+
12+
include "substrait-mlir/Dialect/Substrait/IR/SubstraitDialect.td"
13+
include "substrait-mlir/Dialect/Substrait/IR/SubstraitTypes.td"
14+
include "mlir/IR/AttrTypeBase.td"
15+
include "mlir/IR/BuiltinAttributeInterfaces.td"
16+
17+
// Base class for Substrait dialect attribute types.
18+
class Substrait_Attr<string name, string typeMnemonic, list<Trait> traits = []>
19+
: AttrDef<Substrait_Dialect, name, traits> {
20+
let mnemonic = typeMnemonic;
21+
}
22+
23+
def Substrait_AdvancedExtensionAttr
24+
: Substrait_Attr<"AdvancedExtension", "advanced_extension"> {
25+
let summary = "Represents the `AdvancedExtenssion` message of Substrait";
26+
let parameters = (ins
27+
OptionalParameter<"StringAttr">:$optimization,
28+
OptionalParameter<"StringAttr">:$enhancement
29+
);
30+
let assemblyFormat = [{
31+
( `optimization` `=` $optimization^ )?
32+
( `enhancement` `=` $enhancement^ )?
33+
}];
34+
let genVerifyDecl = 1;
35+
}
36+
37+
def Substrait_DateAttr : Substrait_Attr<"Date", "date",
38+
[TypedAttrInterface]> {
39+
let summary = "Substrait date type";
40+
let description = [{
41+
This type represents a substrait date attribute type.
42+
}];
43+
let parameters = (ins "int32_t":$value);
44+
let assemblyFormat = [{ `<` $value `>` }];
45+
let extraClassDeclaration = [{
46+
::mlir::Type getType() const {
47+
return DateType::get(getContext());
48+
}
49+
}];
50+
}
51+
52+
def Substrait_TimeAttr : Substrait_Attr<"Time", "time",
53+
[TypedAttrInterface]> {
54+
let summary = "Substrait time type";
55+
let description = [{
56+
This type represents a substrait time attribute type.
57+
}];
58+
let parameters = (ins "int64_t":$value);
59+
let assemblyFormat = [{ `<` $value `` `us` `>` }];
60+
let extraClassDeclaration = [{
61+
::mlir::Type getType() const {
62+
return TimeType::get(getContext());
63+
}
64+
}];
65+
}
66+
67+
def Substrait_TimestampAttr : Substrait_Attr<"Timestamp", "timestamp",
68+
[TypedAttrInterface]> {
69+
let summary = "Substrait timezone-unaware timestamp type";
70+
let description = [{
71+
This type represents a substrait timezone-unaware timestamp attribute type.
72+
}];
73+
let parameters = (ins "int64_t":$value);
74+
let assemblyFormat = [{ `<` $value `` `us` `>` }];
75+
let extraClassDeclaration = [{
76+
::mlir::Type getType() const {
77+
return TimestampType::get(getContext());
78+
}
79+
}];
80+
}
81+
82+
def Substrait_TimestampTzAttr : Substrait_Attr<"TimestampTz", "timestamp_tz",
83+
[TypedAttrInterface]> {
84+
let summary = "Substrait timezone-aware timestamp type";
85+
let description = [{
86+
This type represents a substrait timezone-aware timestamp attribute type.
87+
}];
88+
let parameters = (ins "int64_t":$value);
89+
let assemblyFormat = [{ `<` $value `` `us` `>` }];
90+
let extraClassDeclaration = [{
91+
::mlir::Type getType() const {
92+
return TimestampTzType::get(getContext());
93+
}
94+
}];
95+
}
96+
97+
/// Attributes of currently supported atomic types, listed in order of substrait
98+
/// specification.
99+
def Substrait_AtomicAttributes {
100+
list<Attr> attrs = [
101+
SI1Attr, // Boolean
102+
SI8Attr, // I8
103+
SI16Attr, // I16
104+
SI32Attr, // I32
105+
SI64Attr, // I64
106+
F32Attr, // FP32
107+
F64Attr, // FP64
108+
TypedStrAttr<Substrait_StringType>, // String
109+
TypedStrAttr<Substrait_BinaryType>, // Binary
110+
Substrait_TimestampAttr, // Timestamp
111+
Substrait_TimestampTzAttr, // TimestampTZ
112+
Substrait_DateAttr, // Date
113+
Substrait_TimeAttr, // Time
114+
];
115+
}
116+
117+
/// Attribute of one of the currently supported atomic types.
118+
def Substrait_AtomicAttribute : AnyAttrOf<Substrait_AtomicAttributes.attrs>;
119+
120+
#endif // SUBSTRAIT_DIALECT_SUBSTRAIT_IR_SUBSTRAITATTRS

include/substrait-mlir/Dialect/Substrait/IR/SubstraitOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef SUBSTRAIT_DIALECT_SUBSTRAIT_IR_SUBSTRAITOPS
1010
#define SUBSTRAIT_DIALECT_SUBSTRAIT_IR_SUBSTRAITOPS
1111

12+
include "substrait-mlir/Dialect/Substrait/IR/SubstraitAttrs.td"
1213
include "substrait-mlir/Dialect/Substrait/IR/SubstraitDialect.td"
1314
include "substrait-mlir/Dialect/Substrait/IR/SubstraitEnums.td"
1415
include "substrait-mlir/Dialect/Substrait/IR/SubstraitInterfaces.td"

include/substrait-mlir/Dialect/Substrait/IR/SubstraitTypes.td

Lines changed: 5 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@
1111

1212
include "substrait-mlir/Dialect/Substrait/IR/SubstraitDialect.td"
1313
include "mlir/IR/CommonTypeConstraints.td"
14-
include "mlir/IR/OpBase.td"
15-
include "mlir/IR/BuiltinAttributeInterfaces.td"
1614

1715
// Base class for Substrait dialect types.
1816
class Substrait_Type<string name, string typeMnemonic, list<Trait> traits = []>
1917
: TypeDef<Substrait_Dialect, name, traits> {
2018
let mnemonic = typeMnemonic;
2119
}
2220

23-
// Base class for Substrait dialect attribute types.
24-
class Substrait_Attr<string name, string typeMnemonic, list<Trait> traits = []>
25-
: AttrDef<Substrait_Dialect, name, traits> {
26-
let mnemonic = typeMnemonic;
27-
}
28-
2921
def Substrait_BinaryType : Substrait_Type<"Binary", "binary"> {
3022
let summary = "Substrait binary type";
3123
let description = [{
@@ -36,22 +28,7 @@ def Substrait_BinaryType : Substrait_Type<"Binary", "binary"> {
3628
def Substrait_DateType : Substrait_Type<"Date", "date"> {
3729
let summary = "Substrait date type";
3830
let description = [{
39-
This type represents a substrait date type.
40-
}];
41-
}
42-
43-
def Substrait_DateAttr : Substrait_Attr<"Date", "date",
44-
[TypedAttrInterface]> {
45-
let summary = "Substrait date type";
46-
let description = [{
47-
This type represents a substrait date attribute type.
48-
}];
49-
let parameters = (ins "int32_t":$value);
50-
let assemblyFormat = [{ `<` $value `>` }];
51-
let extraClassDeclaration = [{
52-
::mlir::Type getType() const {
53-
return DateType::get(getContext());
54-
}
31+
This type represents a substrait date type.
5532
}];
5633
}
5734

@@ -65,73 +42,27 @@ def Substrait_StringType : Substrait_Type<"String", "string"> {
6542
def Substrait_TimeType : Substrait_Type<"Time", "time"> {
6643
let summary = "Substrait time type";
6744
let description = [{
68-
This type represents a substrait time type.
69-
}];
70-
}
71-
72-
def Substrait_TimeAttr : Substrait_Attr<"Time", "time",
73-
[TypedAttrInterface]> {
74-
let summary = "Substrait time type";
75-
let description = [{
76-
This type represents a substrait time attribute type.
77-
}];
78-
let parameters = (ins "int64_t":$value);
79-
let assemblyFormat = [{ `<` $value `` `us` `>` }];
80-
let extraClassDeclaration = [{
81-
::mlir::Type getType() const {
82-
return TimeType::get(getContext());
83-
}
45+
This type represents a substrait time type.
8446
}];
8547
}
8648

8749
def Substrait_TimestampType : Substrait_Type<"Timestamp", "timestamp"> {
8850
let summary = "Substrait timezone-unaware timestamp type";
8951
let description = [{
90-
This type represents a substrait timezone-unaware timestamp type.
91-
}];
92-
}
93-
94-
def Substrait_TimestampAttr : Substrait_Attr<"Timestamp", "timestamp",
95-
[TypedAttrInterface]> {
96-
let summary = "Substrait timezone-unaware timestamp type";
97-
let description = [{
98-
This type represents a substrait timezone-unaware timestamp attribute type.
99-
}];
100-
let parameters = (ins "int64_t":$value);
101-
let assemblyFormat = [{ `<` $value `` `us` `>` }];
102-
let extraClassDeclaration = [{
103-
::mlir::Type getType() const {
104-
return TimestampType::get(getContext());
105-
}
52+
This type represents a substrait timezone-unaware timestamp type.
10653
}];
10754
}
10855

10956
def Substrait_TimestampTzType : Substrait_Type<"TimestampTz", "timestamp_tz"> {
11057
let summary = "Substrait timezone-aware timestamp type";
11158
let description = [{
112-
This type represents a substrait timezone-aware timestamp type.
113-
}];
114-
}
115-
116-
def Substrait_TimestampTzAttr : Substrait_Attr<"TimestampTz", "timestamp_tz",
117-
[TypedAttrInterface]> {
118-
let summary = "Substrait timezone-aware timestamp type";
119-
let description = [{
120-
This type represents a substrait timezone-aware timestamp attribute type.
121-
}];
122-
let parameters = (ins "int64_t":$value);
123-
let assemblyFormat = [{ `<` $value `` `us` `>` }];
124-
let extraClassDeclaration = [{
125-
::mlir::Type getType() const {
126-
return TimestampTzType::get(getContext());
127-
}
59+
This type represents a substrait timezone-aware timestamp type.
12860
}];
12961
}
13062

131-
/// Currently supported atomic types, listed in order of substrait specification.
63+
/// Currently supported atomic types, listed in order of substrait specification.
13264
/// These correspond directly to the types in
13365
/// https://github.com/substrait-io/substrait/blob/main/proto/substrait/type.proto.
134-
// TODO(ingomueller): Add the other low-hanging fruits here.
13566
def Substrait_AtomicTypes {
13667
list<Type> types = [
13768
SI1, // Boolean
@@ -150,26 +81,6 @@ def Substrait_AtomicTypes {
15081
];
15182
}
15283

153-
/// Attributes of currently supported atomic types, listed in order of substrait
154-
/// specification.
155-
def Substrait_AtomicAttributes {
156-
list<Attr> attrs = [
157-
SI1Attr, // Boolean
158-
SI8Attr, // I8
159-
SI16Attr, // I16
160-
SI32Attr, // I32
161-
SI64Attr, // I64
162-
F32Attr, // FP32
163-
F64Attr, // FP64
164-
TypedStrAttr<Substrait_StringType>, // String
165-
TypedStrAttr<Substrait_BinaryType>, // Binary
166-
Substrait_TimestampAttr, // Timestamp
167-
Substrait_TimestampTzAttr, // TimestampTZ
168-
Substrait_DateAttr, // Date
169-
Substrait_TimeAttr, // Time
170-
];
171-
}
172-
17384
def Substrait_AnyType : Substrait_Type<"Any", "any"> {
17485
let summary = "Represents the `type_url` of a `google.protobuf.Any` message";
17586
let description = [{
@@ -182,23 +93,6 @@ def Substrait_AnyType : Substrait_Type<"Any", "any"> {
18293

18394
}
18495

185-
def Substrait_AdvancedExtensionAttr
186-
: Substrait_Attr<"AdvancedExtension", "advanced_extension"> {
187-
let summary = "Represents the `AdvancedExtenssion` message of Substrait";
188-
let parameters = (ins
189-
OptionalParameter<"StringAttr">:$optimization, // XXX: verify type
190-
OptionalParameter<"StringAttr">:$enhancement
191-
);
192-
let assemblyFormat = [{
193-
( `optimization` `=` $optimization^ )?
194-
( `enhancement` `=` $enhancement^ )?
195-
}];
196-
let genVerifyDecl = 1;
197-
}
198-
199-
/// Attribute of one of the currently supported atomic types.
200-
def Substrait_AtomicAttribute : AnyAttrOf<Substrait_AtomicAttributes.attrs>;
201-
20296
/// One of the currently supported atomic types.
20397
def Substrait_AtomicType : AnyTypeOf<Substrait_AtomicTypes.types>;
20498

0 commit comments

Comments
 (0)