[RFC] Introducing classes for the codegen driven by new pass manager

It is necessary to summarize the work up to now because there are some things different with this RFC as the development progresses:

  1. In NPM, FunctionAnalysisManager owns the MachineFunction (yes, MachineFunctionAnalysis is revived) rather than MachineModuleInfo.
  2. Due to 1, we can support “machine module pass” naturally, machine module pass is just a kind of module pass that iterates over all MachineFunctionAnalysis::Result, and like other pass manager, MachineFunctionPassManager is a instance of template PassManager. Memory footprint should not change much if there is no machine module pass in pipeline.
  3. Like IR pass, doInitialization and doFinalization are not supported. If a pass really need to iterate over a module to initialize or finalize some things, it should be converted to a normal module pass, e.g. the legacy MIRPrintingPass is divided into PrintMIRPreparePass and PrintMIRPass, see PR79440. Some non-trivial logic in these functions, e.g. machine learning based advisors, should move them to constructors and handle input parameters in PassBuilder.cpp. It may introduce granularity issues, but we can handle the order of GlobalMerge , AsmPrinter and other passes in backend comments correctly.
  4. A new CodeGen pipeline builder by extending PassBuilder is proposed, which reuses registerPassBuilderCallbacks (PR116913).

Now llc can run machine function passes over mir file by option -passes=... and can generate mir after instruction selection on some targets. All target independent machine function passes are ported to NPM (thanks to Akshat Oke).
Finally, thanks to aeubanks, arsenm and other code reviewers for reviewing these changes and suggestions.

1 Like