[LLVMdev] [RFC] Removing static initializers for command line options
Rafael Espíndola
rafael.espindola at gmail.com
Wed Aug 20 09:43:05 PDT 2014
> This is very raw, so excuse any mistakes in the code, but I think i came up with a third option.
>
> What if we added a static method to the Scalarizer class. This method takes pointers to each option storage. If a pointer is null, the function is being called from INITIALIZE_PASS and so we create all the options. If a pointer is not null, we’re being called from the pass constructor and we set the value of that option. I think it would look something like this (which can of course be tidied up).
>
> static void addOptions(bool *ScalarizeLoadStore = nullptr) {
> Option::iterator ScalarizeLoadStoreOpt =
> getOrAddOption<bool>("scalarize-load-store");
> if (ScalarizeLoadStore) {
> // Get the value of the option.
> *ScalarizeLoadStore = ScalarizeLoadStoreOpt.getValue();
> } else {
> // Adding the option with this name. Set up its properties.
> ScalarizeLoadStoreOpt.init(cl::Hidden, cl::init(false),
> cl::desc("Allow the scalarizer pass to scalarize loads and store"));
> }
> }
As long as we are careful to make sure only the command line parsing
can set this, it should be fine. It has some nice properties missing
from the original proposal (including stage2)
* "scalarize-load-store" is written once. Not extra string keys.
* It seems easier to hide it.
* We don't need a LLVMConfig object that gets passed around.
* There is exactly one of exposing features to libraries: change the
constructor and maybe the PassManagerBuilder.
I still don't see the advantage over a static storage, but I am not
strongly oppose to it, as long as there is nothing like
cl::OptionRegistry::SetValue<bool>("ScalarizeLoadStore", true) that
libraries can use.
Cheers,
Rafael
More information about the llvm-dev
mailing list