You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CIR][CodeGen] Emit globals with constructor initializer (#197)
This change does the CIR generation for globals initialized by a
constructor call. It currently only covers C++ to CIR generation. The
corresponding LLVM lowering will be in a follow-up commit.
A motivating example is
```
class Init {
friend class ios_base;
public:
Init(bool);
~Init();
private:
static bool _S_synced_with_stdio;
};
static Init ioinit(true);
```
Unlike what the default Clang codegen generates LLVM that detaches the
initialization code from the global var definition (like below), we are
taking a different approach that keeps them together, which we think
will make the later dataflow analysis/transform easier.
```
@_ZL8ioinit = internal global %class.Init zeroinitializer, align 1, !dbg !0
define internal void @cxx_global_var_init() #0 section ".text.startup" !dbg !23 {
entry:
call void @_ZN4InitC2Ev(ptr noundef nonnull align 1 dereferenceable(1) @_ZL8ioinit), !dbg !27
%0 = call i32 @cxa_atexit(ptr @_ZN4InitD1Ev, ptr @_ZL8ioinit, ptr @dso_handle) #3, !dbg !29
ret void, !dbg !27
}
```
So on CIR, we have something like:
```
cir.global "private" internal @_ZL8__ioinit = ctor : !ty_22class2EInit22 {
%0 = cir.get_global @_ZL8__ioinit : cir.ptr <!ty_22class2EInit22> loc(#loc8)
%1 = cir.const(#true) : !cir.bool loc(#loc5)
cir.call @_ZN4InitC1Eb(%0, %1) : (!cir.ptr<!ty_22class2EInit22>, !cir.bool) -> () loc(#loc6)
}
```
The destructor support will also be in a separate change.
0 commit comments