Skip to content

Commit cc30faa

Browse files
committed
[AMDGPU][R600] Move R600TargetMachine into R600CodeGenPassBuilder(NFC).
1 parent da16d0d commit cc30faa

File tree

7 files changed

+187
-220
lines changed

7 files changed

+187
-220
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPassBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
#include "GCNSchedStrategy.h"
3333
#include "GCNVOPDUtils.h"
3434
#include "R600.h"
35+
#include "R600CodeGenPassBuilder.h"
3536
#include "R600MachineFunctionInfo.h"
36-
#include "R600TargetMachine.h"
3737
#include "SIFixSGPRCopies.h"
3838
#include "SIMachineFunctionInfo.h"
3939
#include "SIMachineScheduler.h"

llvm/lib/Target/AMDGPU/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ add_llvm_target(AMDGPUCodeGen
137137
R600Packetizer.cpp
138138
R600RegisterInfo.cpp
139139
R600Subtarget.cpp
140-
R600TargetMachine.cpp
141140
R600TargetTransformInfo.cpp
142141
SIAnnotateControlFlow.cpp
143142
SIFixSGPRCopies.cpp

llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.cpp

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,159 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
//
9+
/// \file
10+
/// This file contains both AMDGPU-R600 target machine and the CodeGen pass
11+
/// builder. The target machine contains all of the hardware specific
12+
/// information needed to emit code for R600 GPUs and the CodeGen pass builder
13+
/// handles the same for new pass manager infrastructure.
14+
//
15+
//===----------------------------------------------------------------------===//
816

917
#include "R600CodeGenPassBuilder.h"
10-
#include "R600TargetMachine.h"
18+
#include "R600.h"
19+
#include "R600MachineScheduler.h"
20+
#include "R600TargetTransformInfo.h"
21+
#include "llvm/Transforms/Scalar.h"
22+
#include <optional>
1123

1224
using namespace llvm;
1325

26+
static cl::opt<bool>
27+
EnableR600StructurizeCFG("r600-ir-structurize",
28+
cl::desc("Use StructurizeCFG IR pass"),
29+
cl::init(true));
30+
31+
static cl::opt<bool> EnableR600IfConvert("r600-if-convert",
32+
cl::desc("Use if conversion pass"),
33+
cl::ReallyHidden, cl::init(true));
34+
35+
static cl::opt<bool, true> EnableAMDGPUFunctionCallsOpt(
36+
"amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
37+
cl::location(AMDGPUTargetMachine::EnableFunctionCalls), cl::init(true),
38+
cl::Hidden);
39+
40+
static ScheduleDAGInstrs *createR600MachineScheduler(MachineSchedContext *C) {
41+
return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
42+
}
43+
44+
static MachineSchedRegistry R600SchedRegistry("r600",
45+
"Run R600's custom scheduler",
46+
createR600MachineScheduler);
47+
48+
//===----------------------------------------------------------------------===//
49+
// R600 Target Machine (R600 -> Cayman) - Legacy Pass Manager interface.
50+
//===----------------------------------------------------------------------===//
51+
52+
R600TargetMachine::R600TargetMachine(const Target &T, const Triple &TT,
53+
StringRef CPU, StringRef FS,
54+
const TargetOptions &Options,
55+
std::optional<Reloc::Model> RM,
56+
std::optional<CodeModel::Model> CM,
57+
CodeGenOptLevel OL, bool JIT)
58+
: AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
59+
setRequiresStructuredCFG(true);
60+
61+
// Override the default since calls aren't supported for r600.
62+
if (EnableFunctionCalls &&
63+
EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
64+
EnableFunctionCalls = false;
65+
}
66+
67+
const TargetSubtargetInfo *
68+
R600TargetMachine::getSubtargetImpl(const Function &F) const {
69+
StringRef GPU = getGPUName(F);
70+
StringRef FS = getFeatureString(F);
71+
72+
SmallString<128> SubtargetKey(GPU);
73+
SubtargetKey.append(FS);
74+
75+
auto &I = SubtargetMap[SubtargetKey];
76+
if (!I) {
77+
// This needs to be done before we create a new subtarget since any
78+
// creation will depend on the TM and the code generation flags on the
79+
// function that reside in TargetOptions.
80+
resetTargetOptions(F);
81+
I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
82+
}
83+
84+
return I.get();
85+
}
86+
87+
TargetTransformInfo
88+
R600TargetMachine::getTargetTransformInfo(const Function &F) const {
89+
return TargetTransformInfo(R600TTIImpl(this, F));
90+
}
91+
92+
namespace {
93+
class R600PassConfig final : public AMDGPUPassConfig {
94+
public:
95+
R600PassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
96+
: AMDGPUPassConfig(TM, PM) {}
97+
98+
ScheduleDAGInstrs *
99+
createMachineScheduler(MachineSchedContext *C) const override {
100+
return createR600MachineScheduler(C);
101+
}
102+
103+
bool addPreISel() override;
104+
bool addInstSelector() override;
105+
void addPreRegAlloc() override;
106+
void addPreSched2() override;
107+
void addPreEmitPass() override;
108+
};
109+
} // namespace
110+
111+
//===----------------------------------------------------------------------===//
112+
// R600 Legacy Pass Setup
113+
//===----------------------------------------------------------------------===//
114+
115+
bool R600PassConfig::addPreISel() {
116+
AMDGPUPassConfig::addPreISel();
117+
118+
if (EnableR600StructurizeCFG)
119+
addPass(createStructurizeCFGPass());
120+
return false;
121+
}
122+
123+
bool R600PassConfig::addInstSelector() {
124+
addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
125+
return false;
126+
}
127+
128+
void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
129+
130+
void R600PassConfig::addPreSched2() {
131+
addPass(createR600EmitClauseMarkers());
132+
if (EnableR600IfConvert)
133+
addPass(&IfConverterID);
134+
addPass(createR600ClauseMergePass());
135+
}
136+
137+
void R600PassConfig::addPreEmitPass() {
138+
addPass(createR600MachineCFGStructurizerPass());
139+
addPass(createR600ExpandSpecialInstrsPass());
140+
addPass(&FinalizeMachineBundlesID);
141+
addPass(createR600Packetizer());
142+
addPass(createR600ControlFlowFinalizer());
143+
}
144+
145+
TargetPassConfig *R600TargetMachine::createPassConfig(PassManagerBase &PM) {
146+
return new R600PassConfig(*this, PM);
147+
}
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+
}
156+
157+
//===----------------------------------------------------------------------===//
158+
// R600 Target Machine (R600 -> Cayman)
159+
//===----------------------------------------------------------------------===//
160+
14161
R600CodeGenPassBuilder::R600CodeGenPassBuilder(
15162
R600TargetMachine &TM, const CGPassBuilderOption &Opts,
16163
PassInstrumentationCallbacks *PIC)

llvm/lib/Target/AMDGPU/R600CodeGenPassBuilder.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,48 @@
99
#ifndef LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H
1010
#define LLVM_LIB_TARGET_AMDGPU_R600CODEGENPASSBUILDER_H
1111

12+
#include "AMDGPUCodeGenPassBuilder.h"
13+
#include "R600Subtarget.h"
1214
#include "llvm/MC/MCStreamer.h"
1315
#include "llvm/Passes/CodeGenPassBuilder.h"
16+
#include "llvm/Target/TargetMachine.h"
17+
#include <optional>
1418

1519
namespace llvm {
1620

17-
class R600TargetMachine;
21+
//===----------------------------------------------------------------------===//
22+
// R600 Target Machine (R600 -> Cayman) - For Legacy Pass Manager.
23+
//===----------------------------------------------------------------------===//
24+
25+
class R600TargetMachine final : public AMDGPUTargetMachine {
26+
private:
27+
mutable StringMap<std::unique_ptr<R600Subtarget>> SubtargetMap;
28+
29+
public:
30+
R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
31+
StringRef FS, const TargetOptions &Options,
32+
std::optional<Reloc::Model> RM,
33+
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
34+
bool JIT);
35+
36+
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
37+
38+
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
39+
raw_pwrite_stream *DwoOut,
40+
CodeGenFileType FileType,
41+
const CGPassBuilderOption &Opt,
42+
PassInstrumentationCallbacks *PIC) override;
43+
44+
const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
45+
46+
TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
47+
48+
bool isMachineVerifierClean() const override { return false; }
49+
50+
MachineFunctionInfo *
51+
createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F,
52+
const TargetSubtargetInfo *STI) const override;
53+
};
1854

1955
class R600CodeGenPassBuilder
2056
: public CodeGenPassBuilder<R600CodeGenPassBuilder, R600TargetMachine> {

llvm/lib/Target/AMDGPU/R600ISelLowering.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
#include "R600ISelLowering.h"
1515
#include "AMDGPU.h"
1616
#include "MCTargetDesc/R600MCTargetDesc.h"
17+
#include "R600CodeGenPassBuilder.h"
1718
#include "R600Defines.h"
18-
#include "R600InstrInfo.h"
1919
#include "R600MachineFunctionInfo.h"
2020
#include "R600Subtarget.h"
21-
#include "R600TargetMachine.h"
2221
#include "llvm/CodeGen/MachineFunction.h"
2322
#include "llvm/IR/IntrinsicsAMDGPU.h"
2423
#include "llvm/IR/IntrinsicsR600.h"

llvm/lib/Target/AMDGPU/R600TargetMachine.cpp

Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
 (0)