To prevent targets from adding optional passes for -O0,
TargetMachine::registerPassBuilderCallbacks() needs an OptimizationLevel
parameter to see if it's O0.
Currently no existing users require this, but some targets that haven't
implemented TargetMachine::registerPassBuilderCallbacks() yet will
require it, e.g. AMDGPU.
This requires moving OptimizationLevel out of PassBuilder, or else
TargetMachine.h will have to #include all of PassBuilder.h.
Since registerPassBuilderCallbacks() now requires an OptimizationLevel,
we can't call it in PassBuilder's constructor. Rather, it's called when
we create a full pipeline, whether default or LTO or O0. This makes
sense since there's no need to run registerPassBuilderCallbacks() when
adding individual passes via PassBuilder, only when creating full
pipelines.
Maybe I missed something. Except for PipelineStartEPCallback, all the other EP callbacks already take OptimizationLevel as input, do we only need to extend PipelineStartEPCallback to also take OptimizationLevel as input?