[LLVMdev] MAJOR API CHANGE: Pass initialization without static constructors
resistor at mac.com
Fri Oct 8 13:29:39 CDT 2010
Hello fellow LLVM-ers,
As those of you who follow llvm-commits have probably noticed, I've been hard at work reworking our pass infrastructure to perform pass initialization/registration without static constructors. This is a boon for clients of the LLVM libraries, as they can now control when and if initialization occurs, as opposed to being forced to incur the initialization cost at startup, negatively impacting their startup times.
The new-style solution consists of an llvm::initializeMyPass method for every pass. These initialization routines must be invoked before the PassManager will be able to resolve pipelines involving your pass. For convenience, LLVM now exposes per-library batch initialization routines, i.e. initializeScalarOpts(), which initialize all the passes within a given library in a single go.
* WHAT THIS MEANS FOR LLVM USERS
Users of LLVM will need to add explicit calls to the initialization routines to their programs. The trivial solution is to perform initialization at the beginning of main(), and to call the batch initialization routines for every LLVM library you link against. Clients interested in improving launch time and/or minimizing unnecessary linkage can defer initialization until it is needs, and/or only call the initialization routines for the individual passes that they depend on.
Dynamically loaded plugins containing passes will continue to use the old-style style initialization scheme, and thus will continue to incur the cost of static constructors. Don't use them if you don't want static constructors.
* WHAT THIS MEANS FOR LLVM DEVELOPERS
I have already done this work for all passes already in the LLVM tree, but developers need to be aware for future work:
You MUST use the new-style INITIALIZE_PASS, INITIALIZE_AG_PASS, and INITIALIZE_ANALYSIS_GROUP macros in place of the old-style RegisterPass<> templates. These macros will create an initializeMyPass() method, which you *MUST* declare in InitializePasses.h, and which you must add to your library's batch initialization method.
More information about the LLVMdev