Skip to content

Commit ca7f906

Browse files
committed
Refactor RegAllocType cl option to use a custom parser
This will allow -sgpr-regalloc-npm=greedy to reuse the same parser.
1 parent 55f42d6 commit ca7f906

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

llvm/include/llvm/Target/CGPassBuilderOption.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_TARGET_CGPASSBUILDEROPTION_H
1515
#define LLVM_TARGET_CGPASSBUILDEROPTION_H
1616

17+
#include "llvm/Support/CommandLine.h"
1718
#include "llvm/Target/TargetOptions.h"
1819
#include <optional>
1920

@@ -22,6 +23,21 @@ namespace llvm {
2223
enum class RunOutliner { TargetDefault, AlwaysOutline, NeverOutline };
2324
enum class RegAllocType { Unset, Default, Basic, Fast, Greedy, PBQP };
2425

26+
class RegAllocTypeParser : public cl::parser<RegAllocType> {
27+
public:
28+
RegAllocTypeParser(cl::Option &O) : cl::parser<RegAllocType>(O) {}
29+
void initialize() {
30+
cl::parser<RegAllocType>::initialize();
31+
addLiteralOption("default", RegAllocType::Default,
32+
"Default register allocator");
33+
addLiteralOption("pbqp", RegAllocType::PBQP, "PBQP register allocator");
34+
addLiteralOption("fast", RegAllocType::Fast, "Fast register allocator");
35+
addLiteralOption("basic", RegAllocType::Basic, "Basic register allocator");
36+
addLiteralOption("greedy", RegAllocType::Greedy,
37+
"Greedy register allocator");
38+
}
39+
};
40+
2541
// Not one-on-one but mostly corresponding to commandline options in
2642
// TargetPassConfig.cpp.
2743
struct CGPassBuilderOption {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# REQUIRES x86_64-registered-target
2+
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O3 -regalloc-npm=fast -print-pipeline-passes %s 2>&1 | FileCheck %s
3+
# RUN: llc -mtriple=x86_64-unknown-linux-gnu -enable-new-pm -O3 -regalloc-npm=greedy -print-pipeline-passes %s 2>&1 | FileCheck %s --check-prefix=CHECK-GREEDY
4+
5+
# CHECK: regallocfast
6+
# CHECK-GREEDY: greedy<all>

llvm/tools/llc/NewPMDriver.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,10 @@
4848

4949
using namespace llvm;
5050

51-
static cl::opt<RegAllocType> RegAlloc(
52-
"regalloc-npm", cl::desc("Register allocator to use for new pass manager"),
53-
cl::Hidden, cl::init(RegAllocType::Unset),
54-
cl::values(
55-
clEnumValN(RegAllocType::Default, "default",
56-
"Default register allocator"),
57-
clEnumValN(RegAllocType::PBQP, "pbqp", "PBQP register allocator"),
58-
clEnumValN(RegAllocType::Fast, "fast", "Fast register allocator"),
59-
clEnumValN(RegAllocType::Basic, "basic", "Basic register allocator"),
60-
clEnumValN(RegAllocType::Greedy, "greedy",
61-
"Greedy register allocator")));
51+
static cl::opt<RegAllocType, false, RegAllocTypeParser>
52+
RegAlloc("regalloc-npm",
53+
cl::desc("Register allocator to use for new pass manager"),
54+
cl::Hidden, cl::init(RegAllocType::Unset));
6255

6356
static cl::opt<bool>
6457
DebugPM("debug-pass-manager", cl::Hidden,

0 commit comments

Comments
 (0)