[llvm-branch-commits] [clang] [CIR] Migrate GlobalLinkageKind, CallingConv and SideEffect off IntegerAttr (PR #220887)
Henrich Lauko via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Sep 4 07:36:14 PDT 2026
https://github.com/xlauko updated https://github.com/llvm/llvm-project/pull/220887
>From f216b35e1a2530e5c1e898c042c79c1c0843e298 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] [CIR] Migrate GlobalLinkageKind, CallingConv and SideEffect
off IntegerAttr
GlobalLinkageKind, CallingConv and SideEffect generated IntegerAttr
subclasses with no dialect spelling of their own. Each now sets
genSpecializedAttr = 0 and gains a CIR_EnumAttr wrapper, and cir.global wraps
$linkage in `enum()`. GlobalLinkageKind spells `#cir.linkage<internal>`,
dropping both the `global_` prefix and the `_kind` suffix.
cir.func and cir.call print all three by hand, but they stream
stringifyGlobalLinkageKind(getLinkage()) and friends, which take the enum
rather than the attribute, so those sites are unchanged.
Operation syntax is unchanged.
---
.../include/clang/CIR/Dialect/IR/CIRAttrs.td | 4 +++
clang/include/clang/CIR/Dialect/IR/CIROps.td | 25 +++++++++++------
clang/test/CIR/IR/enum-attrs.cir | 28 +++++++++++++++++++
3 files changed, 49 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
index fa90ceba97115..00f8b5b2f571f 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
@@ -1898,8 +1898,12 @@ def CIR_SideEffect : CIR_I32EnumAttr<
%2 = cir.call @add(%0, %1) : (!s32i, !s32i) -> !s32i side_effect(const)
```
}];
+
+ let genSpecializedAttr = 0;
}
+def CIR_SideEffectAttr : CIR_EnumAttr<CIR_SideEffect, "side_effect">;
+
//===----------------------------------------------------------------------===//
// StaticLocalGuardAttr
//===----------------------------------------------------------------------===//
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index d9747386f04d0..e4071b20d3f0c 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -3345,7 +3345,12 @@ def CIR_GlobalLinkageKind : CIR_I32EnumAttr<
I32EnumAttrCase<"ExternalWeakLinkage", 9, "extern_weak">,
// Tentative definitions.
I32EnumAttrCase<"CommonLinkage", 10, "common">
-]>;
+]> {
+ let genSpecializedAttr = 0;
+}
+
+def CIR_GlobalLinkageKindAttr
+ : CIR_EnumAttr<CIR_GlobalLinkageKind, "linkage">;
// TODO(CIR): For starters, cir.global has only name and type. The other
// properties of a global variable will be added over time as more of ClangIR
@@ -3411,7 +3416,7 @@ def CIR_GlobalOp : CIR_RegionBranchOpBase<"global", [
>:$global_visibility,
OptionalAttr<StrAttr>:$sym_visibility,
TypeAttr:$sym_type,
- CIR_GlobalLinkageKind:$linkage,
+ CIR_GlobalLinkageKindAttr:$linkage,
OptionalAttr<MemorySpaceAttrInterface>:$addr_space,
OptionalAttr<CIR_TLSModelAttr>:$tls_model,
OptionalAttr<CIR_ThreadLocalGlobalWrapperInitAttr>:$tls_refs,
@@ -3437,7 +3442,7 @@ def CIR_GlobalOp : CIR_RegionBranchOpBase<"global", [
($sym_visibility^)?
($global_visibility^)?
(`constant` $constant^)?
- $linkage
+ enum($linkage)
(`comdat` $comdat^)?
(`tls_model` `=` enum($tls_model)^)?
(`tls_refs` `=` $tls_refs^)?
@@ -4202,7 +4207,11 @@ def CIR_CallingConv : CIR_I32EnumAttr<"CallingConv", "calling convention", [
I32EnumAttrCase<"SpirFunction", 2, "spir_function">,
I32EnumAttrCase<"SpirKernel", 3, "spir_kernel">,
I32EnumAttrCase<"AMDGPUKernel", 4, "amdgpu_kernel">
-]>;
+]> {
+ let genSpecializedAttr = 0;
+}
+
+def CIR_CallingConvAttr : CIR_EnumAttr<CIR_CallingConv, "calling_conv">;
def CIR_FuncOp : CIR_Op<"func", [
AutomaticAllocationScope, CallableOpInterface, SymbolName, SymbolVisibility,
@@ -4296,11 +4305,11 @@ def CIR_FuncOp : CIR_Op<"func", [
UnitAttr:$no_proto,
UnitAttr:$dso_local,
DefaultValuedAttr<
- CIR_GlobalLinkageKind,
+ CIR_GlobalLinkageKindAttr,
"cir::GlobalLinkageKind::ExternalLinkage"
>:$linkage,
DefaultValuedAttr<
- CIR_CallingConv,
+ CIR_CallingConvAttr,
"cir::CallingConv::C"
>:$calling_conv,
OptionalAttr<StrAttr>:$sym_visibility,
@@ -4308,7 +4317,7 @@ def CIR_FuncOp : CIR_Op<"func", [
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs,
OptionalAttr<FlatSymbolRefAttr>:$aliasee,
- OptionalAttr<CIR_SideEffect>:$side_effect,
+ OptionalAttr<CIR_SideEffectAttr>:$side_effect,
OptionalAttr<FlatSymbolRefAttr>:$personality,
CIR_OptionalPriorityAttr:$global_ctor_priority,
CIR_OptionalPriorityAttr:$global_dtor_priority,
@@ -4612,7 +4621,7 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
UnitAttr:$nothrow,
OptionalAttr<CIR_InlineKindAttr>:$inline_kind,
UnitAttr:$musttail,
- DefaultValuedAttr<CIR_SideEffect, "SideEffect::All">:$side_effect,
+ DefaultValuedAttr<CIR_SideEffectAttr, "SideEffect::All">:$side_effect,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs
);
diff --git a/clang/test/CIR/IR/enum-attrs.cir b/clang/test/CIR/IR/enum-attrs.cir
index 53983a5c2cf2c..2e675c2681b94 100644
--- a/clang/test/CIR/IR/enum-attrs.cir
+++ b/clang/test/CIR/IR/enum-attrs.cir
@@ -105,6 +105,28 @@ cir.func @asm_flavor_attr() {
#cir.asm_flavor<x86_intel>]}
}
+// CHECK-LABEL: cir.func @linkage_attr() {
+cir.func @linkage_attr() {
+ // CHECK: cir.return {cir.test = [#cir.linkage<external>, #cir.linkage<linkonce_odr>, #cir.linkage<cir_private>]}
+ cir.return {cir.test = [#cir.linkage<external>,
+ #cir.linkage<linkonce_odr>,
+ #cir.linkage<cir_private>]}
+}
+
+// CHECK-LABEL: cir.func @calling_conv_attr() {
+cir.func @calling_conv_attr() {
+ // CHECK: cir.return {cir.test = [#cir.calling_conv<c>, #cir.calling_conv<ptx_kernel>, #cir.calling_conv<amdgpu_kernel>]}
+ cir.return {cir.test = [#cir.calling_conv<c>, #cir.calling_conv<ptx_kernel>,
+ #cir.calling_conv<amdgpu_kernel>]}
+}
+
+// CHECK-LABEL: cir.func @side_effect_attr() {
+cir.func @side_effect_attr() {
+ // CHECK: cir.return {cir.test = [#cir.side_effect<all>, #cir.side_effect<pure>, #cir.side_effect<const>]}
+ cir.return {cir.test = [#cir.side_effect<all>, #cir.side_effect<pure>,
+ #cir.side_effect<const>]}
+}
+
// The operations themselves keep printing a bare keyword.
// CHECK-LABEL: cir.func @mem_order_sync_scope_ops(%arg0: !cir.ptr<!s32i>) {
@@ -116,4 +138,10 @@ cir.func @mem_order_sync_scope_ops(%arg0: !cir.ptr<!s32i>) {
cir.return
}
+// cir.global's linkage is the one bare keyword that cannot be checked from
+// inside a function.
+
+// CHECK-LABEL: cir.global "private" internal @g = #cir.int<0> : !s32i
+cir.global "private" internal @g = #cir.int<0> : !s32i
+
}
More information about the llvm-branch-commits
mailing list