[clang] [CIR] Drop dead ceremony around the CIR enum attributes (PR #220890)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 7 06:27:06 PDT 2026
https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/220890
>From 5491ddebd3cfe0dc1fadba652e1b373738320933 Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Thu, 3 Sep 2026 12:44:31 +0000
Subject: [PATCH 1/3] [CIR] Migrate the FPClassTest bit enum and unquote its
flags
cir.is_fp_class printed its flags inconsistently. Single-bit values came out
bare, as in `fcSNan`, while group values and combinations came out quoted, as
in `"fcInf"` and `"fcSNan|fcNegInf"`. That comes from I32BitEnumAttr setting
printBitEnumQuoted, which EnumAttr.td keeps only for backwards compatibility.
Clearing the bit and using the `enum` directive selects the separator-aware
parser and printer, so every value now spells unquoted:
cir.is_fp_class %x, fcSNan|fcNegInf : (!cir.float) -> !cir.bool
The enum also drops its specialized IntegerAttr for a CIR_EnumAttr wrapper,
giving it the standalone spelling `#cir.fp_class<fcSNan|fcNegInf>`. This
changes operation syntax, so it updates 37 CHECK lines.
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7a9ecbe435b3f..847710a2744f9 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6967,6 +6967,14 @@ def FPClassTestEnum
FPClass_Sub, FPClass_Zero, FPClass_PosFin, FPClass_NegFin, FPClass_Fin,
FPClass_Pos, FPClass_Neg, FPClass_All]> {
let printBitEnumPrimaryGroups = 1;
+
+ // I32BitEnumAttr turns this on for backwards compatibility, which makes the
+ // operation printer quote every value that is not a single bit. Turning it
+ // off, together with the `enum` directive on cir.is_fp_class, gets a
+ // separator-aware parser and printer that spell every value unquoted.
+ let printBitEnumQuoted = 0;
+
+ let genSpecializedAttr = 0;
}
def CIR_FPClassTestAttr : CIR_EnumAttr<FPClassTestEnum, "fp_class">;
>From 08b4f7897feadafd004d0534389d642c60562cfa Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Thu, 3 Sep 2026 12:44:31 +0000
Subject: [PATCH 2/3] [CIR] Move the CIR enums off the legacy EnumAttrInfo
hierarchy
MLIR has two enum hierarchies. `EnumAttrInfo` doubles as an `IntegerAttr`
constraint, so every CIR enum had to clear `genSpecializedAttr` to say it did
not want one. `EnumInfo` describes a C++ enum and nothing more.
Derive the CIR bases from `I32Enum`, `I64Enum` and `I32BitEnum`, and widen
`CIR_EnumAttr` to the `EnumInfo` that upstream `EnumAttr` already takes. The
flag no longer exists to clear. `FPClassTestEnum` gets unquoted printing from
`BitEnumBase` rather than overriding `printBitEnumQuoted`, and
`CIR_KnownFuncKind` drops a `parameterPrinter` the generated `operator<<`
now covers, still spelling `#cir.func_identity<"std::find">`.
AMDGPU wraps an `I32Enum` in an `EnumAttr` with this same bracketed format.
Parsing moves to the generated `FieldParser`, whose diagnostic names the
accepted spellings, so two `expected-error` lines change. Generated attribute
code drops 16 KB as 28 inlined parsers collapse into it.
---
clang/include/clang/CIR/Dialect/IR/CIROps.td | 8 --------
1 file changed, 8 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 847710a2744f9..7a9ecbe435b3f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -6967,14 +6967,6 @@ def FPClassTestEnum
FPClass_Sub, FPClass_Zero, FPClass_PosFin, FPClass_NegFin, FPClass_Fin,
FPClass_Pos, FPClass_Neg, FPClass_All]> {
let printBitEnumPrimaryGroups = 1;
-
- // I32BitEnumAttr turns this on for backwards compatibility, which makes the
- // operation printer quote every value that is not a single bit. Turning it
- // off, together with the `enum` directive on cir.is_fp_class, gets a
- // separator-aware parser and printer that spell every value unquoted.
- let printBitEnumQuoted = 0;
-
- let genSpecializedAttr = 0;
}
def CIR_FPClassTestAttr : CIR_EnumAttr<FPClassTestEnum, "fp_class">;
>From ffec4adae2be56e98d23705bf9eb414882854470 Mon Sep 17 00:00:00 2001
From: Henrich Lauko <hlauko at nvidia.com>
Date: Thu, 3 Sep 2026 12:44:31 +0000
Subject: [PATCH 3/3] [CIR] Drop dead ceremony around the CIR enum attributes
Five things that no longer earn their place in the CIR enum attribute
machinery.
CIR_CleanupKindAttr carried three. Its cppClassName restated the default
AttrDef already derives. Its skipDefaultBuilders plus hand-written
AttrBuilder existed only to default $value to CleanupKind::All, which no
caller relies on, so the generated builders stayed suppressed for nothing.
And its summary and description restated the name, overriding the enum's own
"cleanup kind" that EnumAttr would otherwise inherit. The isNormal, isEH and
isNormalAndEH helpers stay.
CIR_TLSModelAttr's summary restated its name the same way, so only that goes.
CIR_DefaultValuedEnumParameter has never had a user.
NFC.
---
.../include/clang/CIR/Dialect/IR/CIREnumAttr.td | 5 -----
clang/include/clang/CIR/Dialect/IR/CIROps.td | 16 ----------------
2 files changed, 21 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td b/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td
index dd3761c8250e8..ad23afa9a56cc 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIREnumAttr.td
@@ -47,11 +47,6 @@ class CIR_EnumAttr<EnumInfo info, string name = "", list<Trait> traits = []>
let assemblyFormat = "`<` $value `>`";
}
-class CIR_DefaultValuedEnumParameter<EnumAttrInfo info, string value = "">
- : EnumParameter<info> {
- let defaultValue = value;
-}
-
def CIR_LangAddressSpace : CIR_I32Enum<
"LangAddressSpace", "language address space kind", [
I32EnumAttrCase<"Default", 0, "default">,
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 7a9ecbe435b3f..6d149e6b1ccaa 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -1369,21 +1369,6 @@ def CIR_CleanupKind : CIR_I32Enum<"CleanupKind", "cleanup kind", [
]>;
def CIR_CleanupKindAttr : CIR_EnumAttr<CIR_CleanupKind, "cleanup"> {
- let summary = "Cleanup kind attribute";
- let description = [{
- Cleanup kind attributes.
- }];
-
- let cppClassName = "CleanupKindAttr";
-
- let skipDefaultBuilders = 1;
- let builders = [
- AttrBuilder<(ins CArg<"CleanupKind",
- "cir::CleanupKind::All">:$value), [{
- return $_get($_ctxt, value);
- }]>
- ];
-
let extraClassDeclaration = [{
bool isNormal() const {
return getValue() == CleanupKind::Normal ||
@@ -3348,7 +3333,6 @@ def CIR_TLSModel : CIR_I32Enum<"TLSModel", "TLS model", [
]>;
def CIR_TLSModelAttr: CIR_EnumAttr<CIR_TLSModel, "tls_model"> {
- let summary = "TLS Model attribute";
let description = [{
The TLS mode for the global, which comes from either the
`tls_model` attribute, or `-ftls-model` flag.
More information about the cfe-commits
mailing list