[LLVMdev] [RFC] Removing static initializers for command line options

Evan Cheng evan.cheng at apple.com
Wed Aug 20 12:12:46 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

Globals are bad for many reasons: namespace pollution, concurrency issues, lack of access control, etc. etc.. Some of them have been discussed in this thread. Perhaps it’s not a big concern for most of the LLVM users. But we have an unique environment where LLVM is shared by multiple clients, and where the concern around exploits are especially strong. So while eliminating globals is not strictly tied to the elimination of static initializers, it is still a strong goal towards providing a LLVM dylib.

Evan

> 
> 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
> ...
> 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
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev





More information about the llvm-dev mailing list