Skip to content

Commit 2aa5bae

Browse files
authored
[NewPM][BPF] Add BPFPassRegistry.def NFCI (#86241)
Prepare migration for dag-isel.
1 parent 7ac7d41 commit 2aa5bae

File tree

2 files changed

+40
-17
lines changed

2 files changed

+40
-17
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===- BPFPassRegistry.def - Registry of BPF passes -------------*- 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+
//
9+
// This file is used as the registry of passes that are part of the
10+
// BPF backend.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
// NOTE: NO INCLUDE GUARD DESIRED!
15+
16+
#ifndef FUNCTION_PASS
17+
#define FUNCTION_PASS(NAME, CREATE_PASS)
18+
#endif
19+
FUNCTION_PASS("bpf-aspace-simplify", BPFASpaceCastSimplifyPass())
20+
FUNCTION_PASS("bpf-ir-peephole", BPFIRPeepholePass())
21+
#undef FUNCTION_PASS
22+
23+
#ifndef FUNCTION_PASS_WITH_PARAMS
24+
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
25+
#endif
26+
FUNCTION_PASS_WITH_PARAMS(
27+
"bpf-preserve-static-offset", "BPFPreserveStaticOffsetPass",
28+
[=](bool AllowPartial) {
29+
return BPFPreserveStaticOffsetPass(AllowPartial);
30+
},
31+
parseBPFPreserveStaticOffsetOptions, "allow-partial")
32+
#undef FUNCTION_PASS_WITH_PARAMS

llvm/lib/Target/BPF/BPFTargetMachine.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,16 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
108108
return new BPFPassConfig(*this, PM);
109109
}
110110

111+
static Expected<bool> parseBPFPreserveStaticOffsetOptions(StringRef Params) {
112+
return PassBuilder::parseSinglePassOption(Params, "allow-partial",
113+
"BPFPreserveStaticOffsetPass");
114+
}
115+
111116
void BPFTargetMachine::registerPassBuilderCallbacks(
112117
PassBuilder &PB, bool PopulateClassToPassNames) {
113-
PB.registerPipelineParsingCallback(
114-
[](StringRef PassName, FunctionPassManager &FPM,
115-
ArrayRef<PassBuilder::PipelineElement>) {
116-
if (PassName == "bpf-ir-peephole") {
117-
FPM.addPass(BPFIRPeepholePass());
118-
return true;
119-
}
120-
if (PassName == "bpf-preserve-static-offset") {
121-
FPM.addPass(BPFPreserveStaticOffsetPass(false));
122-
return true;
123-
}
124-
if (PassName == "bpf-aspace-simplify") {
125-
FPM.addPass(BPFASpaceCastSimplifyPass());
126-
return true;
127-
}
128-
return false;
129-
});
118+
#define GET_PASS_REGISTRY "BPFPassRegistry.def"
119+
#include "llvm/Passes/TargetPassRegistry.inc"
120+
130121
PB.registerPipelineStartEPCallback(
131122
[=](ModulePassManager &MPM, OptimizationLevel) {
132123
FunctionPassManager FPM;

0 commit comments

Comments
 (0)