Skip to content

Commit fe13cb9

Browse files
authored
[CodeGen][NewPM] Port RegAllocGreedy to NPM (#119540)
Leaving out NPM command line support for the next patch.
1 parent 75aff78 commit fe13cb9

File tree

10 files changed

+245
-65
lines changed

10 files changed

+245
-65
lines changed

llvm/include/llvm/CodeGen/MachineFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ class LLVM_ABI MachineFunction {
927927

928928
/// Run the current MachineFunction through the machine code verifier, useful
929929
/// for debugger use.
930+
/// TODO: Add the param for LiveStacks analysis.
930931
/// \returns true if no problems were found.
931932
bool verify(LiveIntervals *LiveInts, SlotIndexes *Indexes,
932933
const char *Banner = nullptr, raw_ostream *OS = nullptr,

llvm/include/llvm/CodeGen/Passes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace llvm {
171171
extern char &LiveRangeShrinkID;
172172

173173
/// Greedy register allocator.
174-
extern char &RAGreedyID;
174+
extern char &RAGreedyLegacyID;
175175

176176
/// Basic register allocator.
177177
extern char &RABasicID;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
public:
17+
struct Options {
18+
RegAllocFilterFunc Filter;
19+
StringRef FilterName;
20+
Options(RegAllocFilterFunc F = nullptr, StringRef FN = "all")
21+
: Filter(F), FilterName(FN) {};
22+
};
23+
24+
RAGreedyPass(Options Opts = Options()) : Opts(Opts) {}
25+
PreservedAnalyses run(MachineFunction &F, MachineFunctionAnalysisManager &AM);
26+
27+
MachineFunctionProperties getRequiredProperties() const {
28+
return MachineFunctionProperties().set(
29+
MachineFunctionProperties::Property::NoPHIs);
30+
}
31+
32+
MachineFunctionProperties getClearedProperties() const {
33+
return MachineFunctionProperties().set(
34+
MachineFunctionProperties::Property::IsSSA);
35+
}
36+
37+
void
38+
printPipeline(raw_ostream &OS,
39+
function_ref<StringRef(StringRef)> MapClassName2PassName) const;
40+
static bool isRequired() { return true; }
41+
42+
private:
43+
Options Opts;
44+
};

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void initializeProfileSummaryInfoWrapperPassPass(PassRegistry &);
248248
void initializePromoteLegacyPassPass(PassRegistry &);
249249
void initializeRABasicPass(PassRegistry &);
250250
void initializePseudoProbeInserterPass(PassRegistry &);
251-
void initializeRAGreedyPass(PassRegistry &);
251+
void initializeRAGreedyLegacyPass(PassRegistry &);
252252
void initializeReachingDefAnalysisPass(PassRegistry &);
253253
void initializeReassociateLegacyPassPass(PassRegistry &);
254254
void initializeRegAllocEvictionAdvisorAnalysisLegacyPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

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

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS(
195195
return parseRegAllocFastPassOptions(*PB, Params);
196196
},
197197
"filter=reg-filter;no-clear-vregs")
198+
199+
MACHINE_FUNCTION_PASS_WITH_PARAMS(
200+
"greedy", "RAGreedyPass",
201+
[](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); },
202+
[PB = this](StringRef Params) {
203+
// TODO: parseRegAllocGreedyFilterFunc(*PB, Params);
204+
return Expected<RAGreedyPass::Options>(RAGreedyPass::Options{});
205+
}, "reg-filter"
206+
)
198207
#undef MACHINE_FUNCTION_PASS_WITH_PARAMS
199208

200209
// After a pass is converted to new pass manager, its entry should be moved from
@@ -260,7 +269,6 @@ DUMMY_MACHINE_FUNCTION_PASS("processimpdefs", ProcessImplicitDefsPass)
260269
DUMMY_MACHINE_FUNCTION_PASS("prologepilog", PrologEpilogInserterPass)
261270
DUMMY_MACHINE_FUNCTION_PASS("prologepilog-code", PrologEpilogCodeInserterPass)
262271
DUMMY_MACHINE_FUNCTION_PASS("ra-basic", RABasicPass)
263-
DUMMY_MACHINE_FUNCTION_PASS("ra-greedy", RAGreedyPass)
264272
DUMMY_MACHINE_FUNCTION_PASS("ra-pbqp", RAPBQPPass)
265273
DUMMY_MACHINE_FUNCTION_PASS("regalloc", RegAllocPass)
266274
DUMMY_MACHINE_FUNCTION_PASS("regallocscoringpass", RegAllocScoringPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
112112
initializePreISelIntrinsicLoweringLegacyPassPass(Registry);
113113
initializeProcessImplicitDefsPass(Registry);
114114
initializeRABasicPass(Registry);
115-
initializeRAGreedyPass(Registry);
115+
initializeRAGreedyLegacyPass(Registry);
116116
initializeRegAllocFastPass(Registry);
117117
initializeRegUsageInfoCollectorLegacyPass(Registry);
118118
initializeRegUsageInfoPropagationLegacyPass(Registry);

0 commit comments

Comments
 (0)