[llvm-branch-commits] [llvm] [RegAllocFast][NPM] Make RegAllocFastPassOptions a nested class (PR #127984)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Feb 20 02:33:26 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-regalloc

Author: Akshat Oke (optimisan)

<details>
<summary>Changes</summary>

Making all reg alloc classes have an `::Option` class makes things nicer to construct them.

---
Full diff: https://github.com/llvm/llvm-project/pull/127984.diff


3 Files Affected:

- (modified) llvm/include/llvm/CodeGen/RegAllocFast.h (+14-10) 
- (modified) llvm/include/llvm/Passes/MachinePassRegistry.def (+1-1) 
- (modified) llvm/lib/Passes/PassBuilder.cpp (+2-2) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/RegAllocFast.h b/llvm/include/llvm/CodeGen/RegAllocFast.h
index b2ca9e10bf464..015b666400e05 100644
--- a/llvm/include/llvm/CodeGen/RegAllocFast.h
+++ b/llvm/include/llvm/CodeGen/RegAllocFast.h
@@ -9,23 +9,24 @@
 #ifndef LLVM_CODEGEN_REGALLOCFAST_H
 #define LLVM_CODEGEN_REGALLOCFAST_H
 
+#include "llvm/ADT/StringRef.h"
 #include "llvm/CodeGen/MachinePassManager.h"
 #include "llvm/CodeGen/RegAllocCommon.h"
 
 namespace llvm {
 
-struct RegAllocFastPassOptions {
-  RegAllocFilterFunc Filter = nullptr;
-  StringRef FilterName = "all";
-  bool ClearVRegs = true;
-};
-
 class RegAllocFastPass : public PassInfoMixin<RegAllocFastPass> {
-  RegAllocFastPassOptions Opts;
-
 public:
-  RegAllocFastPass(RegAllocFastPassOptions Opts = RegAllocFastPassOptions())
-      : Opts(Opts) {}
+  struct Options {
+    RegAllocFilterFunc Filter;
+    StringRef FilterName;
+    bool ClearVRegs;
+    Options(RegAllocFilterFunc F = nullptr, StringRef FN = "all",
+            bool CV = true)
+        : Filter(F), FilterName(FN), ClearVRegs(CV) {}
+  };
+
+  RegAllocFastPass(Options Opts = Options()) : Opts(Opts) {}
 
   MachineFunctionProperties getRequiredProperties() const {
     return MachineFunctionProperties().set(
@@ -52,6 +53,9 @@ class RegAllocFastPass : public PassInfoMixin<RegAllocFastPass> {
                      function_ref<StringRef(StringRef)> MapClassName2PassName);
 
   static bool isRequired() { return true; }
+
+private:
+  Options Opts;
 };
 
 } // namespace llvm
diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def
index bb1a59a9c4ed3..31f260c560dd6 100644
--- a/llvm/include/llvm/Passes/MachinePassRegistry.def
+++ b/llvm/include/llvm/Passes/MachinePassRegistry.def
@@ -189,7 +189,7 @@ MACHINE_FUNCTION_PASS("verify<machine-trace-metrics>", MachineTraceMetricsVerifi
 #endif
 MACHINE_FUNCTION_PASS_WITH_PARAMS(
     "regallocfast", "RegAllocFastPass",
-    [](RegAllocFastPassOptions Opts) { return RegAllocFastPass(Opts); },
+    [](RegAllocFastPass::Options Opts) { return RegAllocFastPass(Opts); },
     [PB = this](StringRef Params) {
       return parseRegAllocFastPassOptions(*PB, Params);
     },
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 4e21ef0704e5d..614cbe85ff2bd 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1333,9 +1333,9 @@ Expected<SmallVector<std::string, 0>> parseInternalizeGVs(StringRef Params) {
   return Expected<SmallVector<std::string, 0>>(std::move(PreservedGVs));
 }
 
-Expected<RegAllocFastPassOptions>
+Expected<RegAllocFastPass::Options>
 parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) {
-  RegAllocFastPassOptions Opts;
+  RegAllocFastPass::Options Opts;
   while (!Params.empty()) {
     StringRef ParamName;
     std::tie(ParamName, Params) = Params.split(';');

``````````

</details>


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


More information about the llvm-branch-commits mailing list