Skip to content

Commit

Permalink
[NewPM][AMDGPU] Add CodeGenPassBuilder (#91040)
Browse files Browse the repository at this point in the history
In order to test SelectionDAG for target AMDGPU, we need
CodeGenPassBuilder.
  • Loading branch information
paperchalice authored May 19, 2024
1 parent 9d15fc0 commit b4ba3fe
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 0 deletions.
38 changes: 38 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
33 changes: 33 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.h
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {

Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class AMDGPUTargetMachine : public LLVMTargetMachine {
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;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AMDGPU/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ add_llvm_target(AMDGPUCodeGen
AMDGPUAtomicOptimizer.cpp
AMDGPUAttributor.cpp
AMDGPUCallLowering.cpp
AMDGPUCodeGenPassBuilder.cpp
AMDGPUCodeGenPrepare.cpp
AMDGPUCombinerHelper.cpp
AMDGPUCtorDtorLowering.cpp
Expand Down Expand Up @@ -119,6 +120,7 @@ add_llvm_target(AMDGPUCodeGen
GCNVOPDUtils.cpp
R600AsmPrinter.cpp
R600ClauseMergePass.cpp
R600CodeGenPassBuilder.cpp
R600ControlFlowFinalizer.cpp
R600EmitClauseMarkers.cpp
R600ExpandSpecialInstrs.cpp
Expand Down Expand Up @@ -182,6 +184,7 @@ add_llvm_target(AMDGPUCodeGen
GlobalISel
HipStdPar
IPO
IRPrinter
MC
MIRParser
Passes
Expand Down
33 changes: 33 additions & 0 deletions llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
32 changes: 32 additions & 0 deletions llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions llvm/lib/Target/AMDGPU/R600TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions llvm/lib/Target/AMDGPU/R600TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class R600TargetMachine final : public AMDGPUTargetMachine {

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;
Expand Down

0 comments on commit b4ba3fe

Please sign in to comment.