Skip to content

Commit ba8772e

Browse files
committed
Move pass to a new header, add options
1 parent 492312f commit ba8772e

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//==- RegAllocGreedyPass.h --- greedy register allocator pass ------*-C++-*-==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#include "llvm/CodeGen/MachineFunctionPass.h"
9+
#include "llvm/CodeGen/RegAllocCommon.h"
10+
#include "llvm/CodeGen/RegAllocFast.h"
11+
#include "llvm/IR/PassManager.h"
12+
13+
using namespace llvm;
14+
15+
class RAGreedyPass : public PassInfoMixin<RAGreedyPass> {
16+
17+
public:
18+
struct Options {
19+
RegAllocFilterFunc Filter;
20+
StringRef FilterName;
21+
Options(RegAllocFilterFunc F = nullptr, StringRef FN = "all")
22+
: Filter(F), FilterName(FN) {};
23+
};
24+
25+
RAGreedyPass(Options Opts = Options()) : Opts(Opts) {}
26+
PreservedAnalyses run(MachineFunction &F, MachineFunctionAnalysisManager &AM);
27+
28+
MachineFunctionProperties getRequiredProperties() const {
29+
return MachineFunctionProperties().set(
30+
MachineFunctionProperties::Property::NoPHIs);
31+
}
32+
33+
MachineFunctionProperties getClearedProperties() const {
34+
return MachineFunctionProperties().set(
35+
MachineFunctionProperties::Property::IsSSA);
36+
}
37+
38+
void printPipeline(raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) const;
39+
static bool isRequired() { return true; }
40+
41+
private:
42+
Options Opts;
43+
};

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
6060
#include "llvm/CodeGen/RegAllocEvictionAdvisor.h"
6161
#include "llvm/CodeGen/RegAllocFast.h"
62+
#include "llvm/CodeGen/RegAllocGreedyPass.h"
6263
#include "llvm/CodeGen/RegUsageInfoCollector.h"
6364
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
6465
#include "llvm/CodeGen/RegisterCoalescerPass.h"

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
196196
"filter=reg-filter;no-clear-vregs")
197197

198198
MACHINE_FUNCTION_PASS_WITH_PARAMS(
199-
"regallocgreedy", "RAGreedy",
200-
[](RegAllocFilterFunc F) { return RAGreedyPass(F); },
199+
"regallocgreedy", "RAGreedyPass",
200+
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
201201
[PB = this](StringRef Params) {
202-
// TODO: parseRegAllocFilter(*PB, Params);
203-
return Expected<RegAllocFilterFunc>(nullptr);
204-
}, ""
202+
// TODO: parseRegAllocGreedyFilterFunc(*PB, Params);
203+
return Expected<RAGreedyPass::Options>(RAGreedyPass::Options{});
204+
}, "reg-filter"
205205
)
206206
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
207207

@@ -269,7 +269,6 @@ DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
269269
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)
270270
DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", PrologEpilogCodeInserterPass)
271271
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
272-
DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
273272
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
274273
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
275274
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,16 @@ void RAGreedy::setAnalyses(RequiredAnalyses &Analyses) {
202202
PriorityProvider = Analyses.PriorityProvider;
203203
}
204204

205+
void RAGreedyPass::printPipeline(raw_ostream &OS, function_ref<StringRef(StringRef)> MapClassName2PassName) const {
206+
StringRef FilterName = Opts.FilterName.empty() ? "all" : Opts.FilterName;
207+
OS << "regallocgreedy<" << FilterName << ">";
208+
}
209+
205210
PreservedAnalyses RAGreedyPass::run(MachineFunction &MF,
206211
MachineFunctionAnalysisManager &MFAM) {
207212
MFPropsModifier _(*this, MF);
208213

209-
RAGreedy Impl(Filter);
214+
RAGreedy Impl(Opts.Filter);
210215
RAGreedy::RequiredAnalyses Analyses;
211216

212217
Analyses.VRM = &MFAM.getResult<VirtRegMapAnalysis>(MF);

0 commit comments

Comments
 (0)