[clang] [CIR] Introduce LocalInitOp, & lower static locals (PR #193576)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 23 09:48:52 PDT 2026
================
@@ -3848,6 +3803,67 @@ def CIR_FuncOp : CIR_Op<"func", [
}];
}
+//===----------------------------------------------------------------------===//
+// LocalInitOp
+//===----------------------------------------------------------------------===//
+
+def CIR_LocalInitOp : CIR_Op<"local_init", [
+ DeclareOpInterfaceMethods<SymbolUserOpInterface>, NoRegionArguments,
+ ParentOneOf<["cir::FuncOp"]>,
+ HasAtMostOneOfAttrs<["tls", "static_local"]>
+]> {
+ let summary = "initialize a static or thread local object";
+ let description = [{
+ The 'cir.local_init' operation has no result, but is responsible for
+ containing the regions to initialize and destroy the static local
+ variable. This will be handled during lowering-prepare to include the
+ guard variables correctly for the variable.
+
+ Example:
+ ```
+ cir.local_init static_local @GlobalName ctor {
+ %4 = cir.get_global static_local @GlobalName : !cir.ptr<!rec_CtorDtor>
+ %5 = cir.call @_Z5get_iv() : () -> !s32i
+ cir.call @_ZN8CtorDtorC1Ei(%4, %5) : !cir.ptr<!rec_CtorDtor>
+ cir.yield
+ }, dtor {
+ %4 = cir.get_global static_local @_ZZ3foovE8localCD2 :
+ !cir.ptr<!rec_CtorDtor>
+ cir.call @_ZN8CtorDtorD1Ev(%4) : (!cir.ptr<!rec_CtorDtor>) -> ()
+ cir.yield
+ }
+ }];
+ let arguments = (ins
+ FlatSymbolRefAttr : $globalName,
+ UnitAttr : $tls,
+ UnitAttr : $static_local
+ );
+ let regions = (region
+ MaxSizedRegion<1>:$ctorRegion,
+ MaxSizedRegion<1>:$dtorRegion
+ );
+
+ let assemblyFormat = [{
+ (`thread_local` $tls^)?
+ (`static_local` $static_local^)?
+ $globalName attr-dict
+ (`ctor` $ctorRegion^)?
+ (`dtor` $dtorRegion^)?
+ }];
+
+ let extraClassDeclaration = [{
----------------
xlauko wrote:
Can you fix indent here please
https://github.com/llvm/llvm-project/pull/193576
More information about the cfe-commits
mailing list