Skip to content

Commit 231d3cb

Browse files
bcardosolopeslanza
authored andcommitted
[CIR] Add TLS models to CIR and teach GlobalOp about them
1 parent b88bfb2 commit 231d3cb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,22 @@ def SignedOverflowBehaviorEnum : I32EnumAttr<
16591659
let cppNamespace = "::mlir::cir::sob";
16601660
}
16611661

1662+
/// Definition of TLS related kinds.
1663+
def TLS_GeneralDynamic :
1664+
I32EnumAttrCase<"GeneralDynamic", 0, "tls_dyn">;
1665+
def TLS_LocalDynamic :
1666+
I32EnumAttrCase<"LocalDynamic", 1, "tls_local_dyn">;
1667+
def TLS_InitialExec :
1668+
I32EnumAttrCase<"InitialExec", 2, "tls_init_exec">;
1669+
def TLS_LocalExec :
1670+
I32EnumAttrCase<"LocalExec", 3, "tls_local_exec">;
1671+
1672+
def TLSModel : I32EnumAttr<
1673+
"TLS_Model",
1674+
"TLS model",
1675+
[TLS_GeneralDynamic, TLS_LocalDynamic, TLS_InitialExec, TLS_LocalExec]> {
1676+
let cppNamespace = "::mlir::cir";
1677+
}
16621678

16631679
def GlobalOp : CIR_Op<"global", [Symbol, DeclareOpInterfaceMethods<RegionBranchOpInterface>, NoRegionArguments]> {
16641680
let summary = "Declares or defines a global variable";
@@ -1694,6 +1710,7 @@ def GlobalOp : CIR_Op<"global", [Symbol, DeclareOpInterfaceMethods<RegionBranchO
16941710
OptionalAttr<StrAttr>:$sym_visibility,
16951711
TypeAttr:$sym_type,
16961712
Arg<GlobalLinkageKind, "linkage type">:$linkage,
1713+
OptionalAttr<TLSModel>:$tls_model,
16971714
// Note this can also be a FlatSymbolRefAttr
16981715
OptionalAttr<AnyAttr>:$initial_value,
16991716
UnitAttr:$constant,
@@ -1706,6 +1723,7 @@ def GlobalOp : CIR_Op<"global", [Symbol, DeclareOpInterfaceMethods<RegionBranchO
17061723
($sym_visibility^)?
17071724
(`constant` $constant^)?
17081725
$linkage
1726+
($tls_model^)?
17091727
$sym_name
17101728
custom<GlobalOpTypeAndInitialValue>($sym_type, $initial_value, $ctorRegion, $dtorRegion)
17111729
attr-dict

clang/test/CIR/IR/global.cir

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ module {
5858
cir.func @f34() global_dtor(777) {
5959
cir.return
6060
}
61+
62+
cir.global external tls_dyn @model0 = #cir.int<0> : !s32i
63+
cir.global external tls_local_dyn @model1 = #cir.int<0> : !s32i
64+
cir.global external tls_init_exec @model2 = #cir.int<0> : !s32i
65+
cir.global external tls_local_exec @model3 = #cir.int<0> : !s32i
6166
}
6267

6368
// CHECK: cir.global external @a = #cir.int<3> : !s32i
@@ -81,4 +86,9 @@ module {
8186
// CHECK: cir.func @f31() global_ctor
8287
// CHECK: cir.func @f32() global_ctor(777)
8388
// CHECK: cir.func @f33() global_dtor
84-
// CHECK: cir.func @f34() global_dtor(777)
89+
// CHECK: cir.func @f34() global_dtor(777)
90+
91+
// CHECK: cir.global external tls_dyn @model0 = #cir.int<0> : !s32i
92+
// CHECK: cir.global external tls_local_dyn @model1 = #cir.int<0> : !s32i
93+
// CHECK: cir.global external tls_init_exec @model2 = #cir.int<0> : !s32i
94+
// CHECK: cir.global external tls_local_exec @model3 = #cir.int<0> : !s32i

0 commit comments

Comments
 (0)