For PWR9, PPC backend migrates to the new Post RA MI scheduler. We continue to use PostRA top down list scheduler for PWR8 and older processors. Given that each function can override module's target-cpu, we need a mechanism that allows us to use proper scheduler, depending on the function's target-cpu.
The solution here has the following components:
1- We add a new method MachineFunctionPass::skipFunction (const MachineFunction &) which internally passes the pass ID to Machine Function's subtarget and ask whether this pass should run for this subtarget or not. If Subtarget is OK, we then internally call FunctionPass::skipFunction.
2- A new virtual getPassID method is added to MachineFunctionPass. Each subclass, can override this to return proper ID. This is used in the skipFunction of (1).
3- Some refactoring in TargetPassConfig and PPCTargetMachine is done to allow PPC to add both PostRA schedulers to the pipeline and disable the post RA scheduler with command line options.
4- TargetSubtargetInfo now has a virtual runPass method that is called by the new skipFunction method of (1).
I have tested this by checking which pass is run when invoking llc and pass different value for mcpu option. To commit those tests, I would need to run test that rely on checking DEBUG output of these passes. I am not clear if committing this kind of testcase is OK/necessary or not. Comments are welcome. I have checked that -print-after= option works properly with these changes. I have not checked if the subtarget constructed for a function that overrides target-cpu contains all necessary information. But I believe that is a separate problem. We have to check that at some point and fix any bug that we find. (I suspect that the project that allowed functions to override target-cpus has done that check....)
I recently changed the callback for IfConversion/ExpandBundle to take a MachineFunction& instead of a Function& which should also make life slightly easier in this case.