Hi everyone,
I’m trying to identify where Clang defines optimsation pipelines (middle-end and back-end). For the sake of simplicity, I’m mostly interested in plain -O{0|1|2|3}
(I appreciate that LTO, sanitizers and various code-gen flags make this much more nuanced).
I’ve always been under the impression that this is totally custom in Clang (i.e. defined from scratch), but on closer inspection I see that this is done through LLVM’s API instead (i.e. Clang relies on the pipelines defined in LLVM). More specifically, in BackendUtil.cpp:
- EmitAssemblyHelper::RunOptimizationPipeline configures middle-end optimisation pipelines via LLVM’s PassBuilder API
- EmitAssemblyHelper::CreateTargetMachine configures back-end optimisation pipeline through LLVM’s TargetMachine API.
So, the basic pipelines are in fact defined in LLVM. Clang simply forwards the optimisation level (e.g. -O3
) to LLVM. Did I get this right?
For context, I would like to define optimisation flags in Flang. It would be great to make Clang and Flang behave consistently here!
Thank you,
-Andrzej