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

Rafael Espíndola rafael.espindola at gmail.com
Wed Aug 20 09:31:27 PDT 2014


> 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

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




More information about the llvm-dev mailing list