[llvm-dev] Enabling statistics in release builds / static constructors

Matthias Braun via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 13 11:53:04 PST 2016


Analyzing a compilers behavior and timings is an important tool to track code size and compile time regressions. One of the tools we would like to use are Statistic variable (llvm/include/ADT/Statistic.h). However today I cannot enable them in release builds without a performance hits because the lazy initialisation present forces a memory fence on every single increment of the statistic variable. This is trivial to fix: Do the initialization in the constructor. See https://reviews.llvm.org/D27724

I am writing this mail because I expect opposition against introducing static constructors. Looking at previous discussions it is obvious that a lot of static constructor usage is bad as it promotes global state that should better be put into LLVMContext.
However lazily initializing the Statistic variables makes them in no way less static, we just somewhat delay the initialization at the price of a heavy performance penalty on usage. I don't see a better alternative at the moment.

- Matthias


More information about the llvm-dev mailing list