Customize pass builder


Is it possible to customize optimizations to be run in the optimizer? I have very specific backend, that actually needs only few optimizations. But I can’t figure out how to customize it, PassBuilder has no virtual methods, so I can’t just override it and make my own pipeline.

Also, is it correct that there are no options to disable specific optimizations? In previous projects I worked with, we always have disable option for every optimization. I wonder why LLVM doesn’t have it.

The default PassBuilder pipelines only provide a handful of options and a few hooks to add additional passes.

If you want to create a pipeline that is substantially different from the default one, you should construct it from scratch. You could do this either by…

  1. …specifying your pipeline as a string. Run opt -passes='default<O2>' -print-pipeline-passes to see how this looks like for the default pipeline. This also works if you use the C API.
  2. …constructing a module pass manager from scratch in C++. This is what PassBuilderPipelines.cpp does for the default pipeline.