LLVM 22.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(AddIRPass &addPass) const;
61 void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const;
62 Error addInstSelector(AddMachinePass &) const;
63};
64
65//===----------------------------------------------------------------------===//
66// R600 Target Machine (R600 -> Cayman)
67//===----------------------------------------------------------------------===//
68
70 StringRef CPU, StringRef FS,
72 std::optional<Reloc::Model> RM,
73 std::optional<CodeModel::Model> CM,
74 CodeGenOptLevel OL, bool JIT)
75 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
77
78 // Override the default since calls aren't supported for r600.
80 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
81 EnableFunctionCalls = false;
82}
83
86 StringRef GPU = getGPUName(F);
88
89 SmallString<128> SubtargetKey(GPU);
90 SubtargetKey.append(FS);
91
92 auto &I = SubtargetMap[SubtargetKey];
93 if (!I) {
94 // This needs to be done before we create a new subtarget since any
95 // creation will depend on the TM and the code generation flags on the
96 // function that reside in TargetOptions.
98 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
99 }
100
101 return I.get();
102}
103
106 return TargetTransformInfo(std::make_unique<R600TTIImpl>(this, F));
107}
108
113
114namespace {
115class R600PassConfig final : public AMDGPUPassConfig {
116public:
117 R600PassConfig(TargetMachine &TM, PassManagerBase &PM)
118 : AMDGPUPassConfig(TM, PM) {}
119
120 bool addPreISel() override;
121 bool addInstSelector() override;
122 void addPreRegAlloc() override;
123 void addPreSched2() override;
124 void addPreEmitPass() override;
125};
126} // namespace
127
128//===----------------------------------------------------------------------===//
129// R600 Pass Setup
130//===----------------------------------------------------------------------===//
131
132bool R600PassConfig::addPreISel() {
134
136 addPass(createStructurizeCFGPass());
137 return false;
138}
139
140bool R600PassConfig::addInstSelector() {
141 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
142 return false;
143}
144
145void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
146
147void R600PassConfig::addPreSched2() {
150 addPass(&IfConverterID);
151 addPass(createR600ClauseMergePass());
152}
153
154void R600PassConfig::addPreEmitPass() {
157 addPass(createR600Packetizer());
159}
160
162 return new R600PassConfig(*this, PM);
163}
164
167 CodeGenFileType FileType, const CGPassBuilderOption &Opts,
169 R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
170 return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
171}
172
179
180//===----------------------------------------------------------------------===//
181// R600 CodeGen Pass Builder interface.
182//===----------------------------------------------------------------------===//
183
190
191void R600CodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
192 // TODO: Add passes pre instruction selection.
193}
194
195void R600CodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
196 CreateMCStreamer) const {
197 // TODO: Add AsmPrinter.
198}
199
201 // TODO: Add instruction selector.
202 return Error::success();
203}
Interfaces for producing common pass manager configurations.
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
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 addPreISel(AddIRPass &addPass) const
R600CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const
Error addInstSelector(AddMachinePass &) const
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, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType) const
std::function< Expected< std::unique_ptr< MCStreamer > >(MCContext &)> CreateMCStreamer
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
MachineSchedRegistry provides a selection of available machine instruction schedulers.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opt, PassInstrumentationCallbacks *PIC) override
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)
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
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
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
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
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()
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
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.
FunctionPass * createR600MachineCFGStructurizerPass()
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...