Skip to content

Commit e079f53

Browse files
committed
[NewPM][BPF] Add BPFCodeGenPassBuilder
We need a simple enough target to make codegen pipeline as short as possible.
1 parent 8917afa commit e079f53

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===-- BPFCodeGenPassBuilder.cpp -----------------------------------------===//
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 implement BPFCodeGenPassBuilder class.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#include "BPFCodeGenPassBuilder.h"
14+
#include "BPFTargetMachine.h"
15+
16+
using namespace llvm;
17+
18+
BPFCodeGenPassBuilder::BPFCodeGenPassBuilder(BPFTargetMachine &TM,
19+
const CGPassBuilderOption &Opts,
20+
PassInstrumentationCallbacks *PIC)
21+
: CodeGenPassBuilder(TM, Opts, PIC) {}
22+
23+
void BPFCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
24+
// TODO: Add passes pre instruction selection.
25+
}
26+
27+
void BPFCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
28+
CreateMCStreamer) const {
29+
// TODO: Add AsmPrinter.
30+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//===- BPFCodeGenPassBuilder.h - Build BPF codegen pipeline -----*- 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+
#ifndef LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H
10+
#define LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H
11+
12+
#include "llvm/MC/MCStreamer.h"
13+
#include "llvm/Passes/CodeGenPassBuilder.h"
14+
15+
namespace llvm {
16+
17+
class BPFTargetMachine;
18+
19+
class BPFCodeGenPassBuilder
20+
: public CodeGenPassBuilder<BPFCodeGenPassBuilder, BPFTargetMachine> {
21+
public:
22+
BPFCodeGenPassBuilder(BPFTargetMachine &TM, const CGPassBuilderOption &Opts,
23+
PassInstrumentationCallbacks *PIC);
24+
25+
void addPreISel(AddIRPass &addPass) const;
26+
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
27+
};
28+
29+
} // namespace llvm
30+
31+
#endif // LLVM_LIB_TARGET_BPF_BPFCODEGENPASSBUILDER_H

llvm/lib/Target/BPF/BPFTargetMachine.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "BPFTargetMachine.h"
1414
#include "BPF.h"
15+
#include "BPFCodeGenPassBuilder.h"
1516
#include "BPFTargetTransformInfo.h"
1617
#include "MCTargetDesc/BPFMCAsmInfo.h"
1718
#include "TargetInfo/BPFTargetInfo.h"
@@ -108,6 +109,14 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
108109
return new BPFPassConfig(*this, PM);
109110
}
110111

112+
Error BPFTargetMachine::buildCodeGenPipeline(
113+
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
114+
CodeGenFileType FileType, const CGPassBuilderOption &Opts,
115+
PassInstrumentationCallbacks *PIC) {
116+
BPFCodeGenPassBuilder CGPB(*this, Opts, PIC);
117+
return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
118+
}
119+
111120
static Expected<bool> parseBPFPreserveStaticOffsetOptions(StringRef Params) {
112121
return PassBuilder::parseSinglePassOption(Params, "allow-partial",
113122
"BPFPreserveStaticOffsetPass");

llvm/lib/Target/BPF/BPFTargetMachine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class BPFTargetMachine : public LLVMTargetMachine {
3636

3737
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
3838

39+
Error buildCodeGenPipeline(ModulePassManager &, raw_pwrite_stream &,
40+
raw_pwrite_stream *, CodeGenFileType,
41+
const CGPassBuilderOption &,
42+
PassInstrumentationCallbacks *) override;
43+
3944
TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
4045

4146
TargetLoweringObjectFile *getObjFileLowering() const override {

llvm/lib/Target/BPF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ add_llvm_target(BPFCodeGen
2626
BPFAsmPrinter.cpp
2727
BPFASpaceCastSimplifyPass.cpp
2828
BPFCheckAndAdjustIR.cpp
29+
BPFCodeGenPassBuilder.cpp
2930
BPFFrameLowering.cpp
3031
BPFInstrInfo.cpp
3132
BPFIRPeephole.cpp

0 commit comments

Comments
 (0)