[LLVMdev] [RFC] Removing static initializers for command line options
Pete Cooper
peter_cooper at apple.com
Wed Aug 20 09:53:16 PDT 2014
> On Aug 20, 2014, at 9:31 AM, Rafael Espíndola <rafael.espindola at gmail.com> wrote:
>
>> So, we do have 2 solutions: a global variable, and a call to GetValue. As you can see, either way isn’t perfect, but if you can think of another solution i’m sure we can discuss it.
>
> Pass the passinfo to the pass constructor maybe?
>
> I still don't understand what the problem with the global is. It has
> the same value for all users. As Chandler pointed out, having
I just assumed that all globals are bad. Perhaps thats not true in all cases.
>
> static cl::opt<bool> ScalarizeLoadStore
> ("scalarize-load-store", cl::Hidden, cl::init(false),
> cl::desc("Allow the scalarizer pass to scalarize loads and store"));
>
> right now is just our way of making
>
> // Allow the scalarizer pass to scalarize loads and store
> const static bool ScalarizeLoadStore = false;
>
> more convenient to developers so they don't have to edit/compile to
> test it with a different value. From a library user point of view they
> should be exactly the same: a constant that is *always* false.
>
> Another option (not my preference) would be to use globals just as keys:
>
> typedef <something> LLVMOptionKey;
> ...
> static LLVMOptionKey ScalarizeLoadStoreKey; //global
You could do this if the key is the name of the option, but that detaches the name from the rest of the calls which may be quite far apart in the code. Otherwise so long as the key type doesn’t have a static constructor, this is fine with me.
Thanks,
Pete
> ...
> cl::OptionRegistry::createOption<bool>(&ScalarizeLoadStoreKey,
> "ScalarizeLoadStore",
> "scalarize-load-store", cl::Hidden, cl::init(false),
> cl::desc("Allow the scalarizer pass to scalarize loads and store"));
> ....
> bool ScalarizeLoadStore =
> cl::OptionRegistry::getValue<bool>(&ScalarizeLoadStoreKey); // local
>
> That way we avoid exposing ScalarizeLoadStore to library users since
> the getValue takes a key they cannot guess instead of well known
> string.
>
> Cheers,
> Rafael
More information about the llvm-dev
mailing list