@@ -44,6 +44,21 @@ class CIR_TypedAttr<string name, string attrMnemonic, list<Trait> traits = []>
44
44
let assemblyFormat = [{}];
45
45
}
46
46
47
+ class CIR_I32EnumAttr<string name, string summary, list<I32EnumAttrCase> cases>
48
+ : I32EnumAttr<name, summary, cases> {
49
+ let cppNamespace = "::cir";
50
+ }
51
+
52
+ class CIR_I64EnumAttr<string name, string summary, list<I64EnumAttrCase> cases>
53
+ : I64EnumAttr<name, summary, cases> {
54
+ let cppNamespace = "::cir";
55
+ }
56
+
57
+ class CIR_EnumAttr<EnumAttrInfo info, string name = "", list<Trait> traits = []>
58
+ : EnumAttr<CIR_Dialect, info, name, traits> {
59
+ let assemblyFormat = "`<` $value `>`";
60
+ }
61
+
47
62
class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
48
63
: CIR_Attr<name, attrMnemonic, traits> {
49
64
let returnType = "bool";
@@ -53,18 +68,21 @@ class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
53
68
}
54
69
55
70
//===----------------------------------------------------------------------===//
56
- // LangAttr
71
+ // SourceLanguageAttr
57
72
//===----------------------------------------------------------------------===//
58
73
59
- def CIR_SourceLanguage : I32EnumAttr <"SourceLanguage", "Source language", [
74
+ def CIR_SourceLanguage : CIR_I32EnumAttr <"SourceLanguage", "source language", [
60
75
I32EnumAttrCase<"C", 1, "c">,
61
76
I32EnumAttrCase<"CXX", 2, "cxx">,
62
77
I32EnumAttrCase<"OpenCLC", 3, "opencl_c">
63
78
]> {
64
- let cppNamespace = "::cir";
79
+ // The enum attr class is defined in `CIR_SourceLanguageAttr` below,
80
+ // so that it can define extra class methods.
81
+ let genSpecializedAttr = 0;
65
82
}
66
83
67
- def CIR_LangAttr : CIR_Attr<"Lang", "lang"> {
84
+ def CIR_SourceLanguageAttr : CIR_EnumAttr<CIR_SourceLanguage, "lang"> {
85
+
68
86
let summary = "Module source language";
69
87
let description = [{
70
88
Represents the source language used to generate the module.
@@ -76,17 +94,15 @@ def CIR_LangAttr : CIR_Attr<"Lang", "lang"> {
76
94
// Module compiled from C++.
77
95
module attributes {cir.lang = cir.lang<cxx>} {}
78
96
```
79
- }];
80
97
81
- let parameters = (ins "SourceLanguage":$lang);
82
-
83
- let assemblyFormat = [{
84
- `<` $lang `>`
98
+ Module source language attribute name is `cir.lang` is defined by
99
+ `getSourceLanguageAttrName` method in CIRDialect class.
85
100
}];
86
101
87
102
let extraClassDeclaration = [{
88
- bool isC() const { return getLang() == SourceLanguage::C; };
89
- bool isCXX() const { return getLang() == SourceLanguage::CXX; };
103
+ bool isC() const { return getValue() == SourceLanguage::C; }
104
+ bool isCXX() const { return getValue() == SourceLanguage::CXX; }
105
+ bool isOpenCLC() const { return getValue() == SourceLanguage::OpenCLC; }
90
106
}];
91
107
}
92
108
@@ -516,14 +532,12 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
516
532
// CmpThreeWayInfoAttr
517
533
//===----------------------------------------------------------------------===//
518
534
519
- def CmpOrdering_Strong : I32EnumAttrCase<"Strong", 1, "strong">;
520
- def CmpOrdering_Partial : I32EnumAttrCase<"Partial", 2, "partial">;
521
-
522
- def CmpOrdering : I32EnumAttr<
523
- "CmpOrdering", "three-way comparison ordering kind",
524
- [CmpOrdering_Strong, CmpOrdering_Partial]
525
- > {
526
- let cppNamespace = "::cir";
535
+ def CIR_CmpOrdering : CIR_I32EnumAttr<
536
+ "CmpOrdering", "three-way comparison ordering kind", [
537
+ I32EnumAttrCase<"Strong", 0, "strong">,
538
+ I32EnumAttrCase<"Partial", 1, "partial">
539
+ ]> {
540
+ let genSpecializedAttr = 0;
527
541
}
528
542
529
543
def CmpThreeWayInfoAttr : CIR_Attr<"CmpThreeWayInfo", "cmp3way_info"> {
@@ -542,9 +556,11 @@ def CmpThreeWayInfoAttr : CIR_Attr<"CmpThreeWayInfo", "cmp3way_info"> {
542
556
or neither, respectively.
543
557
}];
544
558
545
- let parameters = (ins "CmpOrdering":$ordering, "int64_t":$lt, "int64_t":$eq,
546
- "int64_t":$gt,
547
- OptionalParameter<"std::optional<int64_t>">:$unordered);
559
+ let parameters = (ins
560
+ EnumParameter<CIR_CmpOrdering>:$ordering,
561
+ "int64_t":$lt, "int64_t":$eq, "int64_t":$gt,
562
+ OptionalParameter<"std::optional<int64_t>">:$unordered
563
+ );
548
564
549
565
let builders = [
550
566
AttrBuilder<(ins "int64_t":$lt, "int64_t":$eq, "int64_t":$gt), [{
@@ -682,18 +698,6 @@ def MethodAttr : CIR_Attr<"Method", "method", [TypedAttrInterface]> {
682
698
}];
683
699
}
684
700
685
- //===----------------------------------------------------------------------===//
686
- // SignedOverflowBehaviorAttr
687
- //===----------------------------------------------------------------------===//
688
-
689
- def SignedOverflowBehaviorAttr : AttrDef<CIR_Dialect, "SignedOverflowBehavior"> {
690
- let mnemonic = "signed_overflow_behavior";
691
- let parameters = (ins
692
- "sob::SignedOverflowBehavior":$behavior
693
- );
694
- let hasCustomAssemblyFormat = 1;
695
- }
696
-
697
701
//===----------------------------------------------------------------------===//
698
702
// GlobalViewAttr
699
703
//===----------------------------------------------------------------------===//
@@ -1133,37 +1137,32 @@ def ASTCallExprAttr : AST<"CallExpr", "call.expr",
1133
1137
// VisibilityAttr
1134
1138
//===----------------------------------------------------------------------===//
1135
1139
1136
- def VK_Default : I32EnumAttrCase<"Default", 1, "default">;
1137
- def VK_Hidden : I32EnumAttrCase<"Hidden", 2, "hidden">;
1138
- def VK_Protected : I32EnumAttrCase<"Protected", 3, "protected">;
1139
-
1140
- def VisibilityKind : I32EnumAttr<"VisibilityKind", "C/C++ visibility", [
1141
- VK_Default, VK_Hidden, VK_Protected
1140
+ def CIR_VisibilityKind : CIR_I32EnumAttr<"VisibilityKind", "C/C++ visibility", [
1141
+ I32EnumAttrCase<"Default", 1, "default">,
1142
+ I32EnumAttrCase<"Hidden", 2, "hidden">,
1143
+ I32EnumAttrCase<"Protected", 3, "protected">
1142
1144
]> {
1143
- let cppNamespace = "::cir" ;
1145
+ let genSpecializedAttr = 0 ;
1144
1146
}
1145
1147
1146
- def VisibilityAttr : CIR_Attr<"Visibility" , "visibility"> {
1148
+ def CIR_VisibilityAttr : CIR_EnumAttr<CIR_VisibilityKind , "visibility"> {
1147
1149
let summary = "Visibility attribute";
1148
1150
let description = [{
1149
1151
Visibility attributes.
1150
1152
}];
1151
- let parameters = (ins "VisibilityKind":$value);
1152
1153
1153
- let assemblyFormat = [{
1154
- $value
1155
- }];
1154
+ let cppClassName = "VisibilityAttr";
1156
1155
1156
+ let skipDefaultBuilders = 1;
1157
1157
let builders = [
1158
1158
AttrBuilder<(ins CArg<"VisibilityKind", "cir::VisibilityKind::Default">:$value), [{
1159
1159
return $_get($_ctxt, value);
1160
1160
}]>
1161
1161
];
1162
1162
1163
- let skipDefaultBuilders = 1;
1164
-
1165
- // Make DefaultValuedAttr accept VisibilityKind as default value ($0).
1166
- let constBuilderCall = "cir::VisibilityAttr::get($_builder.getContext(), $0)";
1163
+ let assemblyFormat = [{
1164
+ $value
1165
+ }];
1167
1166
1168
1167
let extraClassDeclaration = [{
1169
1168
bool isDefault() const { return getValue() == VisibilityKind::Default; };
@@ -1172,7 +1171,6 @@ def VisibilityAttr : CIR_Attr<"Visibility", "visibility"> {
1172
1171
}];
1173
1172
}
1174
1173
1175
-
1176
1174
//===----------------------------------------------------------------------===//
1177
1175
// ExtraFuncAttr
1178
1176
//===----------------------------------------------------------------------===//
@@ -1197,27 +1195,25 @@ def ExtraFuncAttr : CIR_Attr<"ExtraFuncAttributes", "extra"> {
1197
1195
// Printing and parsing also available in CIRDialect.cpp
1198
1196
}
1199
1197
1200
- def NoInline : I32EnumAttrCase<"NoInline", 1, "no">;
1201
- def AlwaysInline : I32EnumAttrCase<"AlwaysInline", 2, "always">;
1202
- def InlineHint : I32EnumAttrCase<"InlineHint", 3, "hint">;
1198
+ //===----------------------------------------------------------------------===//
1199
+ // InlineAttr
1200
+ //===----------------------------------------------------------------------===//
1203
1201
1204
- def InlineKind : I32EnumAttr<"InlineKind", "inlineKind", [
1205
- NoInline, AlwaysInline, InlineHint
1202
+ def CIR_InlineKind : CIR_I32EnumAttr<"InlineKind", "inlineKind", [
1203
+ I32EnumAttrCase<"NoInline", 1, "no">,
1204
+ I32EnumAttrCase<"AlwaysInline", 2, "always">,
1205
+ I32EnumAttrCase<"InlineHint", 3, "hint">
1206
1206
]> {
1207
- let cppNamespace = "::cir" ;
1207
+ let genSpecializedAttr = 0 ;
1208
1208
}
1209
1209
1210
- def InlineAttr : CIR_Attr<"Inline" , "inline"> {
1210
+ def CIR_InlineAttr : CIR_EnumAttr<CIR_InlineKind , "inline"> {
1211
1211
let summary = "Inline attribute";
1212
1212
let description = [{
1213
1213
Inline attributes represents user directives.
1214
1214
}];
1215
1215
1216
- let parameters = (ins "InlineKind":$value);
1217
-
1218
- let assemblyFormat = [{
1219
- `<` $value `>`
1220
- }];
1216
+ let cppClassName = "InlineAttr";
1221
1217
1222
1218
let extraClassDeclaration = [{
1223
1219
bool isNoInline() const { return getValue() == InlineKind::NoInline; };
@@ -1226,6 +1222,10 @@ def InlineAttr : CIR_Attr<"Inline", "inline"> {
1226
1222
}];
1227
1223
}
1228
1224
1225
+ //===----------------------------------------------------------------------===//
1226
+ // Unit Function Attributes
1227
+ //===----------------------------------------------------------------------===//
1228
+
1229
1229
def OptNoneAttr : CIRUnitAttr<"OptNone", "optnone"> {
1230
1230
let storageType = [{ OptNoneAttr }];
1231
1231
}
@@ -1238,21 +1238,19 @@ def ConvergentAttr : CIRUnitAttr<"Convergent", "convergent"> {
1238
1238
let storageType = [{ ConvergentAttr }];
1239
1239
}
1240
1240
1241
- def UWTableKindNone
1242
- : I32EnumAttrCase<"None", 0, "none">;
1243
- def UWTableKindSync
1244
- : I32EnumAttrCase<"Sync", 1, "sync">;
1245
- def UWTableKindAsync
1246
- : I32EnumAttrCase<"Async", 2, "async">;
1241
+ //===----------------------------------------------------------------------===//
1242
+ // UWTableAttr
1243
+ //===----------------------------------------------------------------------===//
1247
1244
1248
- def UWTableKind : I32EnumAttr<"UWTableKind", "Unwind table kind", [
1249
- UWTableKindNone, UWTableKindSync, UWTableKindAsync
1245
+ def CIR_UWTableKind : CIR_I32EnumAttr<"UWTableKind", "Unwind table kind", [
1246
+ I32EnumAttrCase<"None", 0, "none">,
1247
+ I32EnumAttrCase<"Sync", 1, "sync">,
1248
+ I32EnumAttrCase<"Async", 2, "async">
1250
1249
]> {
1251
- let cppNamespace = "::cir";
1252
1250
let genSpecializedAttr = 0;
1253
1251
}
1254
1252
1255
- def UWTableAttr : EnumAttr<CIR_Dialect, UWTableKind , "uwtable"> {
1253
+ def CIR_UWTableAttr : CIR_EnumAttr<CIR_UWTableKind , "uwtable"> {
1256
1254
let summary = "Unwind table kind attribute";
1257
1255
let description = [{
1258
1256
The kind of unwind tables to generate for a function. `none` means no unwind
@@ -1263,9 +1261,6 @@ def UWTableAttr : EnumAttr<CIR_Dialect, UWTableKind, "uwtable"> {
1263
1261
}];
1264
1262
1265
1263
let cppClassName = "UWTableAttr";
1266
- let assemblyFormat = [{
1267
- `<` $value `>`
1268
- }];
1269
1264
}
1270
1265
1271
1266
class CIR_GlobalCtorDtor<string name, string attrMnemonic,
0 commit comments