How to register a pass as being optional?

I’ve created a post-RA pass runOnMachineFunction that gets registed with the pass manager like this:

static RegisterPass X(“regbankfixup”, “Register Bank Conflict FixUp Pass”);

And and whenever I run clang or llc now the pass runs. Initially, until I’m sure this pass doesn’t break things I’d like it to be opt-in - ie I’d like to have the pass run only when the -regbankfixup commandline option is passed to clang or llc, but this seems doable only from opt. Is there no way to set things up such that the pass gets run when an option is passed to llc or (ideally) clang?

Phil

The easiest thing to do is make it run every time, but return immediately if a command-line option is not specified. A number of passes use a similar pattern, skipping execution entirely if some cheap-to-test prerequisite is not met.

David

I usually see it done differently in clang/llvm: the cl::opt flag is added to the PassManagerBuilder and the pass is added only if the flag is set.
For instance: -combine-loads, -use-cfl-aa, -mlsm, ...