Skip to content

Commit 5d82e1a

Browse files
committed
Move pass to a new header, add options
1 parent f9ae873 commit 5d82e1a

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
@@ -56,6 +56,7 @@
5656
#include "llvm/CodeGen/PreISelIntrinsicLowering.h"
5757
#include "llvm/CodeGen/RegAllocEvictionAdvisor.h"
5858
#include "llvm/CodeGen/RegAllocFast.h"
59+
#include "llvm/CodeGen/RegAllocGreedyPass.h"
5960
#include "llvm/CodeGen/RegUsageInfoCollector.h"
6061
#include "llvm/CodeGen/RegUsageInfoPropagate.h"
6162
#include "llvm/CodeGen/RegisterUsageInfo.h"

llvm/include/llvm/Passes/MachinePassRegistry.def

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

191191
MACHINE_FUNCTION_PASS_WITH_PARAMS(
192-
"regallocgreedy", "RAGreedy",
193-
[](RegAllocFilterFunc F) { return RAGreedyPass(F); },
192+
"regallocgreedy", "RAGreedyPass",
193+
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
194194
[PB = this](StringRef Params) {
195-
// TODO: parseRegAllocFilter(*PB, Params);
196-
return Expected<RegAllocFilterFunc>(nullptr);
197-
}, ""
195+
// TODO: parseRegAllocGreedyFilterFunc(*PB, Params);
196+
return Expected<RAGreedyPass::Options>(RAGreedyPass::Options{});
197+
}, "reg-filter"
198198
)
199199
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
200200

@@ -266,7 +266,6 @@ DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
266266
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)
267267
DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", PrologEpilogCodeInserterPass)
268268
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
269-
DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
270269
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
271270
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
272271
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)