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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 14:49:09 PDT 2024


aeubanks wrote:

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

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

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


More information about the llvm-commits mailing list