[llvm-dev] How to register a pass as being optional?

Mehdi Amini via llvm-dev llvm-dev at lists.llvm.org
Mon May 16 08:30:16 PDT 2016


> On May 10, 2016, at 3:52 AM, David Chisnall via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> On 10 May 2016, at 01:26, Phil Tomson via llvm-dev <llvm-dev at lists.llvm.org> wrote:
>> 
>> I've created a post-RA pass runOnMachineFunction that gets registed with the pass manager like this:
>> 
>> 
>> static RegisterPass<RegBankFixUpPass> 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?
> 
> 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.

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, ...

-- 
Mehdi



More information about the llvm-dev mailing list