Skip to content

Commit b4ba3fe

Browse files
authored
[NewPM][AMDGPU] Add CodeGenPassBuilder (#91040)
In order to test SelectionDAG for target AMDGPU, we need CodeGenPassBuilder.
1 parent 9d15fc0 commit b4ba3fe

9 files changed

+169
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.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+
#include "AMDGPUCodeGenPassBuilder.h"
10+
#include "AMDGPUTargetMachine.h"
11+
12+
using namespace llvm;
13+
14+
AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
15+
AMDGPUTargetMachine &TM, const CGPassBuilderOption &Opts,
16+
PassInstrumentationCallbacks *PIC)
17+
: CodeGenPassBuilder(TM, Opts, PIC) {
18+
Opt.RequiresCodeGenSCCOrder = true;
19+
// Exceptions and StackMaps are not supported, so these passes will never do
20+
// anything.
21+
// Garbage collection is not supported.
22+
disablePass<StackMapLivenessPass, FuncletLayoutPass,
23+
ShadowStackGCLoweringPass>();
24+
}
25+
26+
void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
27+
// TODO: Add passes pre instruction selection.
28+
}
29+
30+
void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
31+
CreateMCStreamer) const {
32+
// TODO: Add AsmPrinter.
33+
}
34+
35+
Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &) const {
36+
// TODO: Add instruction selector.
37+
return Error::success();
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h -----------*- 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_AMDGPU_AMDGPUCODEGENPASSBUILDER_H
10+
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H
11+
12+
#include "llvm/MC/MCStreamer.h"
13+
#include "llvm/Passes/CodeGenPassBuilder.h"
14+
15+
namespace llvm {
16+
17+
class AMDGPUTargetMachine;
18+
19+
class AMDGPUCodeGenPassBuilder
20+
: public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, AMDGPUTargetMachine> {
21+
public:
22+
AMDGPUCodeGenPassBuilder(AMDGPUTargetMachine &TM,
23+
const CGPassBuilderOption &Opts,
24+
PassInstrumentationCallbacks *PIC);
25+
26+
void addPreISel(AddIRPass &addPass) const;
27+
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
28+
Error addInstSelector(AddMachinePass &) const;
29+
};
30+
31+
} // namespace llvm
32+
33+
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "AMDGPUTargetMachine.h"
1616
#include "AMDGPU.h"
1717
#include "AMDGPUAliasAnalysis.h"
18+
#include "AMDGPUCodeGenPassBuilder.h"
1819
#include "AMDGPUCtorDtorLowering.h"
1920
#include "AMDGPUExportClustering.h"
2021
#include "AMDGPUIGroupLP.h"
@@ -646,6 +647,14 @@ parseAMDGPUAtomicOptimizerStrategy(StringRef Params) {
646647
return make_error<StringError>("invalid parameter", inconvertibleErrorCode());
647648
}
648649

650+
Error AMDGPUTargetMachine::buildCodeGenPipeline(
651+
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
652+
CodeGenFileType FileType, const CGPassBuilderOption &Opts,
653+
PassInstrumentationCallbacks *PIC) {
654+
AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
655+
return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
656+
}
657+
649658
void AMDGPUTargetMachine::registerPassBuilderCallbacks(
650659
PassBuilder &PB, bool PopulateClassToPassNames) {
651660

llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class AMDGPUTargetMachine : public LLVMTargetMachine {
5252
return TLOF.get();
5353
}
5454

55+
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
56+
raw_pwrite_stream *DwoOut,
57+
CodeGenFileType FileType,
58+
const CGPassBuilderOption &Opts,
59+
PassInstrumentationCallbacks *PIC) override;
60+
5561
void registerPassBuilderCallbacks(PassBuilder &PB,
5662
bool PopulateClassToPassNames) override;
5763
void registerDefaultAliasAnalyses(AAManager &) override;

llvm/lib/Target/AMDGPU/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_llvm_target(AMDGPUCodeGen
5050
AMDGPUAtomicOptimizer.cpp
5151
AMDGPUAttributor.cpp
5252
AMDGPUCallLowering.cpp
53+
AMDGPUCodeGenPassBuilder.cpp
5354
AMDGPUCodeGenPrepare.cpp
5455
AMDGPUCombinerHelper.cpp
5556
AMDGPUCtorDtorLowering.cpp
@@ -119,6 +120,7 @@ add_llvm_target(AMDGPUCodeGen
119120
GCNVOPDUtils.cpp
120121
R600AsmPrinter.cpp
121122
R600ClauseMergePass.cpp
123+
R600CodeGenPassBuilder.cpp
122124
R600ControlFlowFinalizer.cpp
123125
R600EmitClauseMarkers.cpp
124126
R600ExpandSpecialInstrs.cpp
@@ -182,6 +184,7 @@ add_llvm_target(AMDGPUCodeGen
182184
GlobalISel
183185
HipStdPar
184186
IPO
187+
IRPrinter
185188
MC
186189
MIRParser
187190
Passes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- R600CodeGenPassBuilder.cpp ------ Build R600 CodeGen pipeline -----===//
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+
#include "R600CodeGenPassBuilder.h"
10+
#include "R600TargetMachine.h"
11+
12+
using namespace llvm;
13+
14+
R600CodeGenPassBuilder::R600CodeGenPassBuilder(
15+
R600TargetMachine &TM, const CGPassBuilderOption &Opts,
16+
PassInstrumentationCallbacks *PIC)
17+
: CodeGenPassBuilder(TM, Opts, PIC) {
18+
Opt.RequiresCodeGenSCCOrder = true;
19+
}
20+
21+
void R600CodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
22+
// TODO: Add passes pre instruction selection.
23+
}
24+
25+
void R600CodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
26+
CreateMCStreamer) const {
27+
// TODO: Add AsmPrinter.
28+
}
29+
30+
Error R600CodeGenPassBuilder::addInstSelector(AddMachinePass &) const {
31+
// TODO: Add instruction selector.
32+
return Error::success();
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===-- R600CodeGenPassBuilder.h -- Build R600 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_AMDGPU_R600CODEGENPASSBUILDER_H
10+
#define LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H
11+
12+
#include "llvm/MC/MCStreamer.h"
13+
#include "llvm/Passes/CodeGenPassBuilder.h"
14+
15+
namespace llvm {
16+
17+
class R600TargetMachine;
18+
19+
class R600CodeGenPassBuilder
20+
: public CodeGenPassBuilder<R600CodeGenPassBuilder, R600TargetMachine> {
21+
public:
22+
R600CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts,
23+
PassInstrumentationCallbacks *PIC);
24+
25+
void addPreISel(AddIRPass &addPass) const;
26+
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
27+
Error addInstSelector(AddMachinePass &) const;
28+
};
29+
30+
} // namespace llvm
31+
32+
#endif // LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H

llvm/lib/Target/AMDGPU/R600TargetMachine.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "R600TargetMachine.h"
1616
#include "AMDGPUTargetMachine.h"
1717
#include "R600.h"
18+
#include "R600CodeGenPassBuilder.h"
1819
#include "R600MachineScheduler.h"
1920
#include "R600TargetTransformInfo.h"
2021
#include "llvm/Transforms/Scalar.h"
@@ -144,3 +145,11 @@ void R600PassConfig::addPreEmitPass() {
144145
TargetPassConfig *R600TargetMachine::createPassConfig(PassManagerBase &PM) {
145146
return new R600PassConfig(*this, PM);
146147
}
148+
149+
Error R600TargetMachine::buildCodeGenPipeline(
150+
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
151+
CodeGenFileType FileType, const CGPassBuilderOption &Opts,
152+
PassInstrumentationCallbacks *PIC) {
153+
R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
154+
return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
155+
}

llvm/lib/Target/AMDGPU/R600TargetMachine.h

+6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ class R600TargetMachine final : public AMDGPUTargetMachine {
3838

3939
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
4040

41+
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
42+
raw_pwrite_stream *DwoOut,
43+
CodeGenFileType FileType,
44+
const CGPassBuilderOption &Opt,
45+
PassInstrumentationCallbacks *PIC) override;
46+
4147
const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
4248

4349
TargetTransformInfo getTargetTransformInfo(const Function &F) const override;

0 commit comments

Comments
 (0)