[llvm] [CodeGen][NewPM] Handle `--regalloc-npm` option (PR #94748)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 11 10:18:23 PDT 2024


================
@@ -582,12 +583,28 @@ class PassBuilder {
 
   /// Register callbacks to parse target specific filter field if regalloc pass
   /// needs it. E.g. AMDGPU requires regalloc passes can handle sgpr and vgpr
-  /// separately.
+  /// separately. Currently "all" and "none" are preserved filter name.
   void registerRegClassFilterParsingCallback(
       const std::function<RegClassFilterFunc(StringRef)> &C) {
     RegClassFilterParsingCallbacks.push_back(C);
   }
 
+  /// Parse command line option `--regalloc-npm`
+  /// Should only be called by CodeGenPassBuilder.
+  Error parseRegAllocOpt(StringRef Text);
+
+  /// Target hook to set default regalloc.
+  void setDefaultRegAllocBuilder(
+      const std::function<void(StringMap<MachineFunctionPassManager> &)> &C) {
+    DefaultRegAllocBuilder = C;
+  }
+
+  /// Used by CodeGenPassBuilder to add correct regalloc pass.
+  /// Should only be called by CodeGenPassBuilder.
+  StringMap<MachineFunctionPassManager> &getRegAllocMap() {
----------------
aeubanks wrote:

what do you mean callbacks may add unexpected passes?

basically my suggestion is replace `std::function<void(StringMap<MachineFunctionPassManager> &)>` with `std::function<void(MachineFunctionPassManager &, StringRef, bool)>`, where `StringRef` is the filter and `bool` is optimized or not (or maybe that's part of filter? structure however makes most sense). the default callback adds Fast/GreedyRegAlloc based on `IsOptimized` bool. AMDGPU can set the callback to add its custom regallocs based on the filter, and backends that don't need a regalloc can override the callback to be empty

does that make sense? or is there a benefit of the StringMap over that approach?

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


More information about the llvm-commits mailing list