Skip to content

[NewPM][BPF] Add BPFPassRegistry.def NFCI #86241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions llvm/lib/Target/BPF/BPFPassRegistry.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===- BPFPassRegistry.def - Registry of BPF passes -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file is used as the registry of passes that are part of the
// BPF backend.
//
//===----------------------------------------------------------------------===//

// NOTE: NO INCLUDE GUARD DESIRED!

#ifndef FUNCTION_PASS
#define FUNCTION_PASS(NAME, CREATE_PASS)
#endif
FUNCTION_PASS("bpf-aspace-simplify", BPFASpaceCastSimplifyPass())
FUNCTION_PASS("bpf-ir-peephole", BPFIRPeepholePass())
#undef FUNCTION_PASS

#ifndef FUNCTION_PASS_WITH_PARAMS
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS)
#endif
FUNCTION_PASS_WITH_PARAMS(
"bpf-preserve-static-offset", "BPFPreserveStaticOffsetPass",
[=](bool AllowPartial) {
return BPFPreserveStaticOffsetPass(AllowPartial);
},
parseBPFPreserveStaticOffsetOptions, "allow-partial")
#undef FUNCTION_PASS_WITH_PARAMS
25 changes: 8 additions & 17 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,16 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
return new BPFPassConfig(*this, PM);
}

static Expected<bool> parseBPFPreserveStaticOffsetOptions(StringRef Params) {
return PassBuilder::parseSinglePassOption(Params, "allow-partial",
"BPFPreserveStaticOffsetPass");
}

void BPFTargetMachine::registerPassBuilderCallbacks(
PassBuilder &PB, bool PopulateClassToPassNames) {
PB.registerPipelineParsingCallback(
[](StringRef PassName, FunctionPassManager &FPM,
ArrayRef<PassBuilder::PipelineElement>) {
if (PassName == "bpf-ir-peephole") {
FPM.addPass(BPFIRPeepholePass());
return true;
}
if (PassName == "bpf-preserve-static-offset") {
FPM.addPass(BPFPreserveStaticOffsetPass(false));
return true;
}
if (PassName == "bpf-aspace-simplify") {
FPM.addPass(BPFASpaceCastSimplifyPass());
return true;
}
return false;
});
#define GET_PASS_REGISTRY "BPFPassRegistry.def"
#include "llvm/Passes/TargetPassRegistry.inc"

PB.registerPipelineStartEPCallback(
[=](ModulePassManager &MPM, OptimizationLevel) {
FunctionPassManager FPM;
Expand Down