https://github.com/xlauko created https://github.com/llvm/llvm-project/pull/220885
Continues the migration for the three enums reached through hand-written parsers and printers rather than a plain argument reference. cir.atomic.fetch references $binop from its declarative format, so that one gains an `enum()` wrapper like the rest. The other two need no code changes. printAssumeBundle and parseAssumeBundle are already typed on cir::AssumeBundleKindAttr, and the wrapper keeps that class name, so custom<AssumeBundle> still compiles and behaves the same. InlineAsmOp::print streams getAsmFlavor(), which returns the enum and uses the operator<< that -gen-enum-decls emits, not the attribute. DefaultValuedAttr keeps taking the same C++ default expression for $bundle_kind. Operation syntax is unchanged. --- Stacked on #220884. Based on `users/xlauko/cir-enum-06-mem-order-sync-scope`, so the diff shown is this commit alone. >From 5a3dad0e192794dbc6ad044079c6bb318fa5eb35 Mon Sep 17 00:00:00 2001 From: Henrich Lauko <[email protected]> Date: Thu, 3 Sep 2026 11:29:23 +0000 Subject: [PATCH] [CIR] Migrate AssumeBundleKind, AtomicFetchKind and AsmFlavor off IntegerAttr Continues the migration for the three enums reached through hand-written parsers and printers rather than a plain argument reference. cir.atomic.fetch references $binop from its declarative format, so that one gains an `enum()` wrapper like the rest. The other two need no code changes. printAssumeBundle and parseAssumeBundle are already typed on cir::AssumeBundleKindAttr, and the wrapper keeps that class name, so custom<AssumeBundle> still compiles and behaves the same. InlineAsmOp::print streams getAsmFlavor(), which returns the enum and uses the operator<< that -gen-enum-decls emits, not the attribute. DefaultValuedAttr keeps taking the same C++ default expression for $bundle_kind. Operation syntax is unchanged. --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 25 ++++++++++++----- clang/test/CIR/IR/enum-attrs.cir | 28 ++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 47e9d6ce33546..b89ea1dc5950b 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -5414,7 +5414,11 @@ def CIR_LifetimeEndOp : CIR_Op<"lifetime.end"> { def CIR_AsmFlavor : CIR_I32EnumAttr<"AsmFlavor", "ATT or Intel", [I32EnumAttrCase<"x86_att", 0>, - I32EnumAttrCase<"x86_intel", 1>]>; + I32EnumAttrCase<"x86_intel", 1>]> { + let genSpecializedAttr = 0; +} + +def CIR_AsmFlavorAttr : CIR_EnumAttr<CIR_AsmFlavor, "asm_flavor">; def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> { let description = [{ @@ -5477,7 +5481,7 @@ def CIR_InlineAsmOp : CIR_Op<"asm", [RecursiveMemoryEffects]> { let arguments = (ins VariadicOfVariadic<AnyType, "operands_segments">:$asm_operands, StrAttr:$asm_string, StrAttr:$constraints, UnitAttr:$side_effects, - CIR_AsmFlavor:$asm_flavor, ArrayAttr:$operand_attrs, + CIR_AsmFlavorAttr:$asm_flavor, ArrayAttr:$operand_attrs, DenseI32ArrayAttr:$operands_segments); let builders = [OpBuilder<(ins @@ -6988,8 +6992,12 @@ def CIR_AssumeBundleKind : CIR_I32EnumAttr< I32EnumAttrCase<"SeparateStorage", 2, "separate_storage">, I32EnumAttrCase<"Dereferenceable", 3, "dereferenceable"> ]> { + let genSpecializedAttr = 0; } +def CIR_AssumeBundleKindAttr + : CIR_EnumAttr<CIR_AssumeBundleKind, "assume_bundle">; + def CIR_AssumeOp : CIR_Op<"assume"> { let summary = "Tell the optimizer that a boolean value is true"; let description = [{ @@ -7016,7 +7024,7 @@ def CIR_AssumeOp : CIR_Op<"assume"> { let arguments = (ins CIR_BoolType:$predicate, - DefaultValuedAttr<CIR_AssumeBundleKind, + DefaultValuedAttr<CIR_AssumeBundleKindAttr, "::cir::AssumeBundleKind::None">:$bundle_kind, Variadic<CIR_AnyType>:$bundle_args ); @@ -8875,7 +8883,12 @@ def CIR_AtomicFetchKind : CIR_I32EnumAttr< I32EnumAttrCase<"Minimum", 11, "minimum">, I32EnumAttrCase<"MaximumNum", 12, "maximum_num">, I32EnumAttrCase<"MinimumNum", 13, "minimum_num"> -]>; +]> { + let genSpecializedAttr = 0; +} + +def CIR_AtomicFetchKindAttr + : CIR_EnumAttr<CIR_AtomicFetchKind, "atomic_fetch">; def CIR_AtomicFetchOp : CIR_Op<"atomic.fetch", [ AllTypesMatch<["result", "val"]>, @@ -8925,7 +8938,7 @@ def CIR_AtomicFetchOp : CIR_Op<"atomic.fetch", [ let arguments = (ins Arg<CIR_PtrToIntOrFloatType, "", [MemRead, MemWrite]>:$ptr, CIR_AnyIntOrFloatType:$val, - CIR_AtomicFetchKind:$binop, + CIR_AtomicFetchKindAttr:$binop, Arg<CIR_MemOrderAttr, "memory order">:$mem_order, Arg<CIR_SyncScopeKindAttr, "synchronization scope">:$sync_scope, UnitAttr:$is_volatile, @@ -8933,7 +8946,7 @@ def CIR_AtomicFetchOp : CIR_Op<"atomic.fetch", [ ); let assemblyFormat = [{ - $binop enum($mem_order) + enum($binop) enum($mem_order) `syncscope` `(` enum($sync_scope) `)` (`fetch_first` $fetch_first^)? $ptr `,` $val diff --git a/clang/test/CIR/IR/enum-attrs.cir b/clang/test/CIR/IR/enum-attrs.cir index 4e9deb4fa2304..ca020a8b28030 100644 --- a/clang/test/CIR/IR/enum-attrs.cir +++ b/clang/test/CIR/IR/enum-attrs.cir @@ -89,6 +89,34 @@ cir.func @sync_scope_attr() { // CHECK: cir.func @sync_scope_attr() { // CHECK: cir.return {cir.test = [#cir.sync_scope<single_thread>, #cir.sync_scope<hip_workgroup>, #cir.sync_scope<opencl_all_svm_devices>]} +cir.func @atomic_fetch_attr() { + cir.return {cir.test = [#cir.atomic_fetch<add>, + #cir.atomic_fetch<nand>, + #cir.atomic_fetch<minimum_num>]} +} + +// CHECK: cir.func @atomic_fetch_attr() { +// CHECK: cir.return {cir.test = [#cir.atomic_fetch<add>, #cir.atomic_fetch<nand>, #cir.atomic_fetch<minimum_num>]} + +// The None case declares no keyword, so it spells as its symbol name. +cir.func @assume_bundle_attr() { + cir.return {cir.test = [#cir.assume_bundle<None>, + #cir.assume_bundle<align>, + #cir.assume_bundle<separate_storage>, + #cir.assume_bundle<dereferenceable>]} +} + +// CHECK: cir.func @assume_bundle_attr() { +// CHECK: cir.return {cir.test = [#cir.assume_bundle<None>, #cir.assume_bundle<align>, #cir.assume_bundle<separate_storage>, #cir.assume_bundle<dereferenceable>]} + +cir.func @asm_flavor_attr() { + cir.return {cir.test = [#cir.asm_flavor<x86_att>, + #cir.asm_flavor<x86_intel>]} +} + +// CHECK: cir.func @asm_flavor_attr() { +// CHECK: cir.return {cir.test = [#cir.asm_flavor<x86_att>, #cir.asm_flavor<x86_intel>]} + // The operations themselves keep printing a bare keyword. cir.func @operations_print_bare_keywords(%arg0: !s32i, %arg1: !s32i, %arg2: !cir.ptr<!s32i>) { _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
