@@ -44,6 +44,21 @@ class CIR_TypedAttr<string name, string attrMnemonic, list<Trait> traits = []>
4444 let assemblyFormat = [{}];
4545}
4646
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+
4762class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
4863 : CIR_Attr<name, attrMnemonic, traits> {
4964 let returnType = "bool";
@@ -53,18 +68,21 @@ class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
5368}
5469
5570//===----------------------------------------------------------------------===//
56- // LangAttr
71+ // SourceLanguageAttr
5772//===----------------------------------------------------------------------===//
5873
59- def CIR_SourceLanguage : I32EnumAttr <"SourceLanguage", "Source language", [
74+ def CIR_SourceLanguage : CIR_I32EnumAttr <"SourceLanguage", "source language", [
6075 I32EnumAttrCase<"C", 1, "c">,
6176 I32EnumAttrCase<"CXX", 2, "cxx">,
6277 I32EnumAttrCase<"OpenCLC", 3, "opencl_c">
6378]> {
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;
6582}
6683
67- def CIR_LangAttr : CIR_Attr<"Lang", "lang"> {
84+ def CIR_SourceLanguageAttr : CIR_EnumAttr<CIR_SourceLanguage, "lang"> {
85+
6886 let summary = "Module source language";
6987 let description = [{
7088 Represents the source language used to generate the module.
@@ -76,17 +94,15 @@ def CIR_LangAttr : CIR_Attr<"Lang", "lang"> {
7694 // Module compiled from C++.
7795 module attributes {cir.lang = cir.lang<cxx>} {}
7896 ```
79- }];
8097
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.
85100 }];
86101
87102 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; }
90106 }];
91107}
92108
@@ -516,14 +532,12 @@ def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> {
516532// CmpThreeWayInfoAttr
517533//===----------------------------------------------------------------------===//
518534
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;
527541}
528542
529543def CmpThreeWayInfoAttr : CIR_Attr<"CmpThreeWayInfo", "cmp3way_info"> {
@@ -542,9 +556,11 @@ def CmpThreeWayInfoAttr : CIR_Attr<"CmpThreeWayInfo", "cmp3way_info"> {
542556 or neither, respectively.
543557 }];
544558
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+ );
548564
549565 let builders = [
550566 AttrBuilder<(ins "int64_t":$lt, "int64_t":$eq, "int64_t":$gt), [{
@@ -682,18 +698,6 @@ def MethodAttr : CIR_Attr<"Method", "method", [TypedAttrInterface]> {
682698 }];
683699}
684700
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-
697701//===----------------------------------------------------------------------===//
698702// GlobalViewAttr
699703//===----------------------------------------------------------------------===//
@@ -1133,37 +1137,32 @@ def ASTCallExprAttr : AST<"CallExpr", "call.expr",
11331137// VisibilityAttr
11341138//===----------------------------------------------------------------------===//
11351139
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">
11421144]> {
1143- let cppNamespace = "::cir" ;
1145+ let genSpecializedAttr = 0 ;
11441146}
11451147
1146- def VisibilityAttr : CIR_Attr<"Visibility" , "visibility"> {
1148+ def CIR_VisibilityAttr : CIR_EnumAttr<CIR_VisibilityKind , "visibility"> {
11471149 let summary = "Visibility attribute";
11481150 let description = [{
11491151 Visibility attributes.
11501152 }];
1151- let parameters = (ins "VisibilityKind":$value);
11521153
1153- let assemblyFormat = [{
1154- $value
1155- }];
1154+ let cppClassName = "VisibilityAttr";
11561155
1156+ let skipDefaultBuilders = 1;
11571157 let builders = [
11581158 AttrBuilder<(ins CArg<"VisibilityKind", "cir::VisibilityKind::Default">:$value), [{
11591159 return $_get($_ctxt, value);
11601160 }]>
11611161 ];
11621162
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+ }];
11671166
11681167 let extraClassDeclaration = [{
11691168 bool isDefault() const { return getValue() == VisibilityKind::Default; };
@@ -1172,7 +1171,6 @@ def VisibilityAttr : CIR_Attr<"Visibility", "visibility"> {
11721171 }];
11731172}
11741173
1175-
11761174//===----------------------------------------------------------------------===//
11771175// ExtraFuncAttr
11781176//===----------------------------------------------------------------------===//
@@ -1197,27 +1195,25 @@ def ExtraFuncAttr : CIR_Attr<"ExtraFuncAttributes", "extra"> {
11971195 // Printing and parsing also available in CIRDialect.cpp
11981196}
11991197
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+ //===----------------------------------------------------------------------===//
12031201
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">
12061206]> {
1207- let cppNamespace = "::cir" ;
1207+ let genSpecializedAttr = 0 ;
12081208}
12091209
1210- def InlineAttr : CIR_Attr<"Inline" , "inline"> {
1210+ def CIR_InlineAttr : CIR_EnumAttr<CIR_InlineKind , "inline"> {
12111211 let summary = "Inline attribute";
12121212 let description = [{
12131213 Inline attributes represents user directives.
12141214 }];
12151215
1216- let parameters = (ins "InlineKind":$value);
1217-
1218- let assemblyFormat = [{
1219- `<` $value `>`
1220- }];
1216+ let cppClassName = "InlineAttr";
12211217
12221218 let extraClassDeclaration = [{
12231219 bool isNoInline() const { return getValue() == InlineKind::NoInline; };
@@ -1226,6 +1222,10 @@ def InlineAttr : CIR_Attr<"Inline", "inline"> {
12261222 }];
12271223}
12281224
1225+ //===----------------------------------------------------------------------===//
1226+ // Unit Function Attributes
1227+ //===----------------------------------------------------------------------===//
1228+
12291229def OptNoneAttr : CIRUnitAttr<"OptNone", "optnone"> {
12301230 let storageType = [{ OptNoneAttr }];
12311231}
@@ -1238,21 +1238,19 @@ def ConvergentAttr : CIRUnitAttr<"Convergent", "convergent"> {
12381238 let storageType = [{ ConvergentAttr }];
12391239}
12401240
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+ //===----------------------------------------------------------------------===//
12471244
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">
12501249]> {
1251- let cppNamespace = "::cir";
12521250 let genSpecializedAttr = 0;
12531251}
12541252
1255- def UWTableAttr : EnumAttr<CIR_Dialect, UWTableKind , "uwtable"> {
1253+ def CIR_UWTableAttr : CIR_EnumAttr<CIR_UWTableKind , "uwtable"> {
12561254 let summary = "Unwind table kind attribute";
12571255 let description = [{
12581256 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"> {
12631261 }];
12641262
12651263 let cppClassName = "UWTableAttr";
1266- let assemblyFormat = [{
1267- `<` $value `>`
1268- }];
12691264}
12701265
12711266class CIR_GlobalCtorDtor<string name, string attrMnemonic,
0 commit comments