[llvm] [NewPM][CodeGen] Refactoring CodeGenPassBuilder (PR #89708)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 04:22:49 PDT 2024


paperchalice wrote:

> can you expand on the commit description? e.g. I'm not sure what "Support pass substitution" means.

Some targets (ARM, RISCV etc.) and option `--misched-postra` require use `PostMachineSchedulerPass` rather `PostRASchedulerPass`, in fact, this is the only use of this function.

> btw, related to this, I was talking to Chandler about the new PM design, and one thing he was very insistent on was that we don't have some sort of automatic scheduling of module vs function passes, as we currently do in `AddIRPass`/`AddMachinePass`. this is because there have been cases in the past where it was very easy to accidentally add a module pass in the middle of a function pipeline without noticing. forcing the programmer to insert adaptors and break up function pipelines in makes it very clear what's going on.
> 
> this is of course much harder with the codegen pipeline than the optimization pipeline since each backend wants to customize it. the idea was to have a "default" pipeline that constructs the pipeline from various phases which backends can override. for example,
> 
> ```
> ModulePassManager buildPipeline() {
>   ModulePassManager MPM;
>   FunctionPassManager IRPasses = createIRPasses();
>   MachineFunctionPassManager MIRPasses = createMIRPasses();
>   IRPasses.addPass(createFunctionToMachineFunctionAdaptor(std::move(MIRPasses));
>   MPM.addPass(createModuleToFunctionAdaptor(std::move(IRPasses));
>   return MPM;
> }
> 
> FunctionPassManager createIRPasses() {
>   FunctionPassManager FPM;
>   FPM.addPass(CodeGenPreparePass());
>   ...
>   return FPM;
> }
> 
> MachineFunctionPassManager createMIRPasses() {
>   MachineFunctionPassManager MFPM;
>   MFPM.addPass(ISel());
>   MFPM.addPass(createRegAllocPasses());
>   ...
>   return MFPM;
> }
> ```
> 
> and any of these either smaller building blocks (e.g. createRegAllocPasses()), or the top level pipeline (which can use the smaller building blocks), are overridable by each backend
> 
> I'm unsure how feasible this actually is in practice though. having PassBuilder hooks to insert passes in specific parts of the pipeline would help with this though

Oh, I see it. In fact I'm not sure whether IR pipelines in CodeGen pipelines are order sensitive for all targets, at least for now, some targets (like DirectX and AArch64) need to insert module passes around CodeGenPrepare and this part is order sensitive:
https://github.com/llvm/llvm-project/blob/76ea5feb1f12ab35547a3aa1bc1b84d4bca69aa7/llvm/lib/CodeGen/TargetPassConfig.cpp#L937-L942
But provide pass insertion points in a finer granularity to ensure the `module->function->machine-function->function->module` pattern is better.


https://github.com/llvm/llvm-project/pull/89708


More information about the llvm-commits mailing list