[cfe-dev] Static constructors: _cxx_global_var_initN vs _GLOBAL__sub_I_XXX

David Chisnall via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 7 01:44:24 PST 2016


On 7 Jan 2016, at 09:36, Andrew Parker via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> I'd just like to understand what the logic is behind the generation of these functions. It looks to me like there's implicit constructor priority however the priority member of the @llvm.global_ctors array is never used (well, it's always 65535).
> 
> Does anyone know the secrets behind this?

It’s fairly simple.  Doing it this way makes it easy to emit the constructors one at a time (the ctors array is an appending global, but it’s still immutable after creation - you can’t add fields to it) and lets the inliner condense the constructors into a single function where appropriate (and allows the same code to be used to generate the static constructor initialisation paths as global initialisation).

The inliner priorities might want tweaking a bit here though, as we’ve seen cases where, after inlining, you end up with truly massive basic blocks that end up causing the register allocator to spent 5+ minutes at compile time, to save a few nanoseconds of run time.

David




More information about the cfe-dev mailing list