LLVM 24.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
29 "amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
32
34 return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
35}
36
38 "Run R600's custom scheduler",
40
41//===----------------------------------------------------------------------===//
42// R600 CodeGen Pass Builder interface.
43//===----------------------------------------------------------------------===//
44
56
57//===----------------------------------------------------------------------===//
58// R600 Target Machine (R600 -> Cayman)
59//===----------------------------------------------------------------------===//
60
62 StringRef CPU, StringRef FS,
64 std::optional<Reloc::Model> RM,
65 std::optional<CodeModel::Model> CM,
66 CodeGenOptLevel OL, bool JIT)
67 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
69
70 // Override the default since calls aren't supported for r600.
72 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
73 EnableFunctionCalls = false;
74}
75
78 StringRef GPU = getGPUName(F);
80
81 SmallString<128> SubtargetKey(GPU);
82 SubtargetKey.append(FS);
83
84 auto &I = SubtargetMap[SubtargetKey];
85 if (!I)
86 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
87
88 return I.get();
89}
90
93 return TargetTransformInfo(std::make_unique<R600TTIImpl>(this, F));
94}
95
100
101namespace {
102class R600PassConfig final : public AMDGPUPassConfig {
103public:
104 R600PassConfig(TargetMachine &TM, PassManagerBase &PM)
105 : AMDGPUPassConfig(TM, PM) {}
106
107 bool addPreISel() override;
108 bool addInstSelector() override;
109 void addPreRegAlloc() override;
110 void addPreSched2() override;
111 void addPreEmitPass() override;
112};
113} // namespace
114
115//===----------------------------------------------------------------------===//
116// R600 Pass Setup
117//===----------------------------------------------------------------------===//
118
119bool R600PassConfig::addPreISel() {
121
122 if (CLOpts.r600_ir_structurize)
123 addPass(createStructurizeCFGPass());
124 return false;
125}
126
127bool R600PassConfig::addInstSelector() {
128 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
129 return false;
130}
131
132void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
133
134void R600PassConfig::addPreSched2() {
136 if (CLOpts.r600_if_convert)
137 addPass(&IfConverterID);
138 addPass(createR600ClauseMergePass());
139}
140
141void R600PassConfig::addPreEmitPass() {
144 addPass(createR600Packetizer());
146}
147
149 return new R600PassConfig(*this, PM);
150}
151
154 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
155 const CGPassBuilderOption &Opts, MCContext &Ctx,
157 R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
158 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
159}
160
167
168//===----------------------------------------------------------------------===//
169// R600 CodeGen Pass Builder interface.
170//===----------------------------------------------------------------------===//
171
178
180 // TODO: Add passes pre instruction selection.
181}
182
184 // TODO: Add AsmPrinterBegin
185}
186
188 // TODO: Add AsmPrinter.
189}
190
192 // TODO: Add AsmPrinterEnd
193}
194
196 // TODO: Add instruction selector.
197 return Error::success();
198}
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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 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) override
void addAsmPrinterBegin(PassManagerWrapper &PMW) override
Error addInstSelector(PassManagerWrapper &PMW) override
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
void addPreISel(PassManagerWrapper &PMW) override
{{@ For GlobalISel
void addAsmPrinterEnd(PassManagerWrapper &PMW) override
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...
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
CodeGenPassBuilder(TargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
Error buildPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, MCContext &Ctx)
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)
const TargetSubtargetInfo * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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:28
void append(StringRef RHS)
Append from a StringRef.
Definition SmallString.h:70
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:48
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.
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:309
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
FunctionPass * createR600EmitClauseMarkers()
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
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:391
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...