LLVM 23.0.0git
R600TargetMachine.cpp
Go to the documentation of this file.
1//===-- R600TargetMachine.cpp - TargetMachine for hw codegen targets-------===//
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/// \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 pass pipeline for new pass manager.
14//
15//===----------------------------------------------------------------------===//
16
17#include "R600TargetMachine.h"
18#include "R600.h"
24#include <optional>
25
26using namespace llvm;
27
28static cl::opt<bool>
29 EnableR600StructurizeCFG("r600-ir-structurize",
30 cl::desc("Use StructurizeCFG IR pass"),
31 cl::init(true));
32
33static cl::opt<bool> EnableR600IfConvert("r600-if-convert",
34 cl::desc("Use if conversion pass"),
36
38 "amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
41
43 return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
44}
45
47 "Run R600's custom scheduler",
49
50//===----------------------------------------------------------------------===//
51// R600 CodeGen Pass Builder interface.
52//===----------------------------------------------------------------------===//
53
55 : public CodeGenPassBuilder<R600CodeGenPassBuilder, R600TargetMachine> {
56public:
59
60 void addPreISel(PassManagerWrapper &PMW) const;
62 void addAsmPrinter(PassManagerWrapper &PMW) const;
63 void addAsmPrinterEnd(PassManagerWrapper &PMW) const;
65};
66
67//===----------------------------------------------------------------------===//
68// R600 Target Machine (R600 -> Cayman)
69//===----------------------------------------------------------------------===//
70
72 StringRef CPU, StringRef FS,
74 std::optional<Reloc::Model> RM,
75 std::optional<CodeModel::Model> CM,
76 CodeGenOptLevel OL, bool JIT)
77 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
79
80 // Override the default since calls aren't supported for r600.
82 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
83 EnableFunctionCalls = false;
84}
85
88 StringRef GPU = getGPUName(F);
90
91 SmallString<128> SubtargetKey(GPU);
92 SubtargetKey.append(FS);
93
94 auto &I = SubtargetMap[SubtargetKey];
95 if (!I)
96 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
97
98 return I.get();
99}
100
103 return TargetTransformInfo(std::make_unique<R600TTIImpl>(this, F));
104}
105
110
111namespace {
112class R600PassConfig final : public AMDGPUPassConfig {
113public:
114 R600PassConfig(TargetMachine &TM, PassManagerBase &PM)
115 : AMDGPUPassConfig(TM, PM) {}
116
117 bool addPreISel() override;
118 bool addInstSelector() override;
119 void addPreRegAlloc() override;
120 void addPreSched2() override;
121 void addPreEmitPass() override;
122};
123} // namespace
124
125//===----------------------------------------------------------------------===//
126// R600 Pass Setup
127//===----------------------------------------------------------------------===//
128
129bool R600PassConfig::addPreISel() {
131
133 addPass(createStructurizeCFGPass());
134 return false;
135}
136
137bool R600PassConfig::addInstSelector() {
138 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
139 return false;
140}
141
142void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
143
144void R600PassConfig::addPreSched2() {
147 addPass(&IfConverterID);
148 addPass(createR600ClauseMergePass());
149}
150
151void R600PassConfig::addPreEmitPass() {
154 addPass(createR600Packetizer());
156}
157
159 return new R600PassConfig(*this, PM);
160}
161
164 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
165 const CGPassBuilderOption &Opts, MCContext &Ctx,
167 R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
168 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
169}
170
177
178//===----------------------------------------------------------------------===//
179// R600 CodeGen Pass Builder interface.
180//===----------------------------------------------------------------------===//
181
188
190 // TODO: Add passes pre instruction selection.
191}
192
194 // TODO: Add AsmPrinterBegin
195}
196
198 // TODO: Add AsmPrinter.
199}
200
202 // TODO: Add AsmPrinterEnd
203}
204
206 // TODO: Add instruction selector.
207 return Error::success();
208}
Interfaces for producing common pass manager configurations.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
ModuleAnalysisManager MAM
PassInstrumentationCallbacks PIC
R600 Machine Scheduler interface.
static cl::opt< bool > EnableR600IfConvert("r600-if-convert", cl::desc("Use if conversion pass"), cl::ReallyHidden, cl::init(true))
static cl::opt< bool > EnableR600StructurizeCFG("r600-ir-structurize", cl::desc("Use StructurizeCFG IR pass"), cl::init(true))
static ScheduleDAGInstrs * createR600MachineScheduler(MachineSchedContext *C)
static MachineSchedRegistry R600SchedRegistry("r600", "Run R600's custom scheduler", createR600MachineScheduler)
static cl::opt< bool, true > EnableAMDGPUFunctionCallsOpt("amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"), cl::location(AMDGPUTargetMachine::EnableFunctionCalls), cl::init(true), cl::Hidden)
The AMDGPU TargetMachine interface definition for hw codegen targets.
This file a TargetTransformInfoImplBase conforming object specific to the R600 target machine.
void addAsmPrinter(PassManagerWrapper &PMW) const
void addAsmPrinterEnd(PassManagerWrapper &PMW) const
Error addInstSelector(PassManagerWrapper &PMW) const
void addPreISel(PassManagerWrapper &PMW) const
void addAsmPrinterBegin(PassManagerWrapper &PMW) const
R600CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
bool addPreISel() override
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
const TargetSubtargetInfo * getSubtargetImpl() const
StringRef getFeatureString(const Function &F) const
AMDGPUTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL)
StringRef getGPUName(const Function &F) const
Error buildPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx) const
CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Context object for machine code objects.
Definition MCContext.h:83
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
R600TargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opt, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
ScheduleDAGInstrs * createMachineScheduler(MachineSchedContext *C) const override
Create an instance of ScheduleDAGInstrs to be run within the standard MachineScheduler pass for this ...
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
A ScheduleDAG for scheduling lists of MachineInstr.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:68
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
void setRequiresStructuredCFG(bool Value)
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
Target-Independent Code Generator Pass Configuration Options.
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
An abstract base class for streams implementations that also support a pwrite operation.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createR600ExpandSpecialInstrsPass()
LLVM_ABI Pass * createStructurizeCFGPass(bool SkipUniformRegions=false)
When SkipUniformRegions is true the structizer will not structurize regions that only contain uniform...
FunctionPass * createR600Packetizer()
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:111
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
FunctionPass * createR600EmitClauseMarkers()
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
FunctionPass * createR600ISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a R600-specific.
FunctionPass * createR600ControlFlowFinalizer()
FunctionPass * createR600ClauseMergePass()
FunctionPass * createR600VectorRegMerger()
LLVM_ABI char & IfConverterID
IfConverter - This pass performs machine code if conversion.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
FunctionPass * createR600MachineCFGStructurizerPass()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...