Skip to content

[NewPM][BPF] Add BPFCodeGenPassBuilder #94158

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions llvm/lib/Target/BPF/BPFCodeGenPassBuilder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- BPFCodeGenPassBuilder.cpp -----------------------------------------===//
//
// 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 implements BPFCodeGenPassBuilder class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove this comment, it's not very useful

//
//===----------------------------------------------------------------------===//

#include "BPFCodeGenPassBuilder.h"
#include "BPFTargetMachine.h"

using namespace llvm;

BPFCodeGenPassBuilder::BPFCodeGenPassBuilder(BPFTargetMachine &TM,
const CGPassBuilderOption &Opts,
PassInstrumentationCallbacks *PIC)
: CodeGenPassBuilder(TM, Opts, PIC) {}

void BPFCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
// TODO: Add passes pre instruction selection.
}

void BPFCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
CreateMCStreamer) const {
// TODO: Add AsmPrinter.
}
31 changes: 31 additions & 0 deletions llvm/lib/Target/BPF/BPFCodeGenPassBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===- BPFCodeGenPassBuilder.h - Build BPF codegen pipeline -----*- 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
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H
#define LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H

#include "llvm/MC/MCStreamer.h"
#include "llvm/Passes/CodeGenPassBuilder.h"

namespace llvm {

class BPFTargetMachine;

class BPFCodeGenPassBuilder
: public CodeGenPassBuilder<BPFCodeGenPassBuilder, BPFTargetMachine> {
public:
BPFCodeGenPassBuilder(BPFTargetMachine &TM, const CGPassBuilderOption &Opts,
PassInstrumentationCallbacks *PIC);

void addPreISel(AddIRPass &addPass) const;
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
};

} // namespace llvm

#endif // LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H
9 changes: 9 additions & 0 deletions llvm/lib/Target/BPF/BPFTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "BPFTargetMachine.h"
#include "BPF.h"
#include "BPFCodeGenPassBuilder.h"
#include "BPFTargetTransformInfo.h"
#include "MCTargetDesc/BPFMCAsmInfo.h"
#include "TargetInfo/BPFTargetInfo.h"
Expand Down Expand Up @@ -108,6 +109,14 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
return new BPFPassConfig(*this, PM);
}

Error BPFTargetMachine::buildCodeGenPipeline(
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
CodeGenFileType FileType, const CGPassBuilderOption &Opts,
PassInstrumentationCallbacks *PIC) {
BPFCodeGenPassBuilder CGPB(*this, Opts, PIC);
return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
}

static Expected<bool> parseBPFPreserveStaticOffsetOptions(StringRef Params) {
return PassBuilder::parseSinglePassOption(Params, "allow-partial",
"BPFPreserveStaticOffsetPass");
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Target/BPF/BPFTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class BPFTargetMachine : public LLVMTargetMachine {

TargetPassConfig *createPassConfig(PassManagerBase &PM) override;

Error buildCodeGenPipeline(ModulePassManager &, raw_pwrite_stream &,
raw_pwrite_stream *, CodeGenFileType,
const CGPassBuilderOption &,
PassInstrumentationCallbacks *) override;

TargetTransformInfo getTargetTransformInfo(const Function &F) const override;

TargetLoweringObjectFile *getObjFileLowering() const override {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/BPF/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_llvm_target(BPFCodeGen
BPFAsmPrinter.cpp
BPFASpaceCastSimplifyPass.cpp
BPFCheckAndAdjustIR.cpp
BPFCodeGenPassBuilder.cpp
BPFFrameLowering.cpp
BPFInstrInfo.cpp
BPFIRPeephole.cpp
Expand Down
Loading