Skip to content

[RegAllocFast][NPM] Make RegAllocFastPassOptions a nested class #127984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

optimisan
Copy link
Contributor

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

@optimisan
Copy link
Contributor Author

optimisan commented Feb 20, 2025

@optimisan optimisan marked this pull request as ready for review February 20, 2025 10:21
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

@llvm/pr-subscribers-llvm-regalloc

Author: Akshat Oke (optimisan)

Changes

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 --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(';');

Making all reg alloc classes have an `::Option` class makes things nicer
to construct them.
@optimisan optimisan force-pushed the users/Akshat-Oke/fast-ra-options branch from fd718fa to 254dabf Compare February 21, 2025 06:12
@optimisan optimisan changed the base branch from users/Akshat-Oke/12-11-_regalloc_newpm_plug_greedy_ra_in_codegen_pipeline to main February 21, 2025 06:13
@optimisan optimisan merged commit 36d304d into llvm:main Feb 21, 2025
6 of 10 checks passed
@optimisan optimisan deleted the users/Akshat-Oke/fast-ra-options branch February 21, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants