diff options
author | paperchalice <liujunchang97@outlook.com> | 2024-05-19 15:57:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-19 15:57:02 +0800 |
commit | b4ba3fe0068b2391e24ebf9a0ec6f56a8ac224b4 (patch) | |
tree | ef67e7b83ac55c30ece94762f4fb018a0817a7f8 | |
parent | 9d15fc0060b584141674dddfedb06b0b58ad7aae (diff) | |
download | llvm-b4ba3fe0068b2391e24ebf9a0ec6f56a8ac224b4.zip llvm-b4ba3fe0068b2391e24ebf9a0ec6f56a8ac224b4.tar.gz llvm-b4ba3fe0068b2391e24ebf9a0ec6f56a8ac224b4.tar.bz2 |
[NewPM][AMDGPU] Add CodeGenPassBuilder (#91040)
In order to test SelectionDAG for target AMDGPU, we need
CodeGenPassBuilder.
-rw-r--r-- | llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp | 38 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h | 33 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h | 6 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/CMakeLists.txt | 3 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h | 32 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/R600TargetMachine.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Target/AMDGPU/R600TargetMachine.h | 6 |
9 files changed, 169 insertions, 0 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp new file mode 100644 index 0000000..01ab61a --- /dev/null +++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp @@ -0,0 +1,38 @@ +//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.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 +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUCodeGenPassBuilder.h" +#include "AMDGPUTargetMachine.h" + +using namespace llvm; + +AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder( + AMDGPUTargetMachine &TM, const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) + : CodeGenPassBuilder(TM, Opts, PIC) { + Opt.RequiresCodeGenSCCOrder = true; + // Exceptions and StackMaps are not supported, so these passes will never do + // anything. + // Garbage collection is not supported. + disablePass<StackMapLivenessPass, FuncletLayoutPass, + ShadowStackGCLoweringPass>(); +} + +void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const { + // TODO: Add passes pre instruction selection. +} + +void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass, + CreateMCStreamer) const { + // TODO: Add AsmPrinter. +} + +Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &) const { + // TODO: Add instruction selector. + return Error::success(); +} diff --git a/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h new file mode 100644 index 0000000..5f79e30 --- /dev/null +++ b/llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h @@ -0,0 +1,33 @@ +//===- lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h -----------*- 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_AMDGPU_AMDGPUCODEGENPASSBUILDER_H +#define LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H + +#include "llvm/MC/MCStreamer.h" +#include "llvm/Passes/CodeGenPassBuilder.h" + +namespace llvm { + +class AMDGPUTargetMachine; + +class AMDGPUCodeGenPassBuilder + : public CodeGenPassBuilder<AMDGPUCodeGenPassBuilder, AMDGPUTargetMachine> { +public: + AMDGPUCodeGenPassBuilder(AMDGPUTargetMachine &TM, + const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC); + + void addPreISel(AddIRPass &addPass) const; + void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const; + Error addInstSelector(AddMachinePass &) const; +}; + +} // namespace llvm + +#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUCODEGENPASSBUILDER_H diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index 305a6c8..20329de 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -15,6 +15,7 @@ #include "AMDGPUTargetMachine.h" #include "AMDGPU.h" #include "AMDGPUAliasAnalysis.h" +#include "AMDGPUCodeGenPassBuilder.h" #include "AMDGPUCtorDtorLowering.h" #include "AMDGPUExportClustering.h" #include "AMDGPUIGroupLP.h" @@ -646,6 +647,14 @@ parseAMDGPUAtomicOptimizerStrategy(StringRef Params) { return make_error<StringError>("invalid parameter", inconvertibleErrorCode()); } +Error AMDGPUTargetMachine::buildCodeGenPipeline( + ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, + CodeGenFileType FileType, const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) { + AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC); + return CGPB.buildPipeline(MPM, Out, DwoOut, FileType); +} + void AMDGPUTargetMachine::registerPassBuilderCallbacks( PassBuilder &PB, bool PopulateClassToPassNames) { diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h index 30ab388..e48cb8f 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -52,6 +52,12 @@ public: return TLOF.get(); } + Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, + raw_pwrite_stream *DwoOut, + CodeGenFileType FileType, + const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) override; + void registerPassBuilderCallbacks(PassBuilder &PB, bool PopulateClassToPassNames) override; void registerDefaultAliasAnalyses(AAManager &) override; diff --git a/llvm/lib/Target/AMDGPU/CMakeLists.txt b/llvm/lib/Target/AMDGPU/CMakeLists.txt index 48325a0..ead81b4 100644 --- a/llvm/lib/Target/AMDGPU/CMakeLists.txt +++ b/llvm/lib/Target/AMDGPU/CMakeLists.txt @@ -50,6 +50,7 @@ add_llvm_target(AMDGPUCodeGen AMDGPUAtomicOptimizer.cpp AMDGPUAttributor.cpp AMDGPUCallLowering.cpp + AMDGPUCodeGenPassBuilder.cpp AMDGPUCodeGenPrepare.cpp AMDGPUCombinerHelper.cpp AMDGPUCtorDtorLowering.cpp @@ -119,6 +120,7 @@ add_llvm_target(AMDGPUCodeGen GCNVOPDUtils.cpp R600AsmPrinter.cpp R600ClauseMergePass.cpp + R600CodeGenPassBuilder.cpp R600ControlFlowFinalizer.cpp R600EmitClauseMarkers.cpp R600ExpandSpecialInstrs.cpp @@ -182,6 +184,7 @@ add_llvm_target(AMDGPUCodeGen GlobalISel HipStdPar IPO + IRPrinter MC MIRParser Passes diff --git a/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp b/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp new file mode 100644 index 0000000..a57b3aa --- /dev/null +++ b/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp @@ -0,0 +1,33 @@ +//===-- R600CodeGenPassBuilder.cpp ------ Build R600 CodeGen pipeline -----===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "R600CodeGenPassBuilder.h" +#include "R600TargetMachine.h" + +using namespace llvm; + +R600CodeGenPassBuilder::R600CodeGenPassBuilder( + R600TargetMachine &TM, const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) + : CodeGenPassBuilder(TM, Opts, PIC) { + Opt.RequiresCodeGenSCCOrder = true; +} + +void R600CodeGenPassBuilder::addPreISel(AddIRPass &addPass) const { + // TODO: Add passes pre instruction selection. +} + +void R600CodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass, + CreateMCStreamer) const { + // TODO: Add AsmPrinter. +} + +Error R600CodeGenPassBuilder::addInstSelector(AddMachinePass &) const { + // TODO: Add instruction selector. + return Error::success(); +} diff --git a/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h b/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h new file mode 100644 index 0000000..be7c935 --- /dev/null +++ b/llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h @@ -0,0 +1,32 @@ +//===-- R600CodeGenPassBuilder.h -- Build R600 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_AMDGPU_R600CODEGENPASSBUILDER_H +#define LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H + +#include "llvm/MC/MCStreamer.h" +#include "llvm/Passes/CodeGenPassBuilder.h" + +namespace llvm { + +class R600TargetMachine; + +class R600CodeGenPassBuilder + : public CodeGenPassBuilder<R600CodeGenPassBuilder, R600TargetMachine> { +public: + R600CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC); + + void addPreISel(AddIRPass &addPass) const; + void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const; + Error addInstSelector(AddMachinePass &) const; +}; + +} // namespace llvm + +#endif // LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H diff --git a/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp b/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp index 2461263..c550cfa 100644 --- a/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp @@ -15,6 +15,7 @@ #include "R600TargetMachine.h" #include "AMDGPUTargetMachine.h" #include "R600.h" +#include "R600CodeGenPassBuilder.h" #include "R600MachineScheduler.h" #include "R600TargetTransformInfo.h" #include "llvm/Transforms/Scalar.h" @@ -144,3 +145,11 @@ void R600PassConfig::addPreEmitPass() { TargetPassConfig *R600TargetMachine::createPassConfig(PassManagerBase &PM) { return new R600PassConfig(*this, PM); } + +Error R600TargetMachine::buildCodeGenPipeline( + ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, + CodeGenFileType FileType, const CGPassBuilderOption &Opts, + PassInstrumentationCallbacks *PIC) { + R600CodeGenPassBuilder CGPB(*this, Opts, PIC); + return CGPB.buildPipeline(MPM, Out, DwoOut, FileType); +} diff --git a/llvm/lib/Target/AMDGPU/R600TargetMachine.h b/llvm/lib/Target/AMDGPU/R600TargetMachine.h index af8dcb8..29e370e 100644 --- a/llvm/lib/Target/AMDGPU/R600TargetMachine.h +++ b/llvm/lib/Target/AMDGPU/R600TargetMachine.h @@ -38,6 +38,12 @@ public: TargetPassConfig *createPassConfig(PassManagerBase &PM) override; + Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, + raw_pwrite_stream *DwoOut, + CodeGenFileType FileType, + const CGPassBuilderOption &Opt, + PassInstrumentationCallbacks *PIC) override; + const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override; TargetTransformInfo getTargetTransformInfo(const Function &F) const override; |