LLVM 20.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"
23#include <optional>
24
25using namespace llvm;
26
27static cl::opt<bool>
28 EnableR600StructurizeCFG("r600-ir-structurize",
29 cl::desc("Use StructurizeCFG IR pass"),
30 cl::init(true));
31
32static cl::opt<bool> EnableR600IfConvert("r600-if-convert",
33 cl::desc("Use if conversion pass"),
35
37 "amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
40
42 return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
43}
44
46 "Run R600's custom scheduler",
48
49//===----------------------------------------------------------------------===//
50// R600 Target Machine (R600 -> Cayman)
51//===----------------------------------------------------------------------===//
52
54 StringRef CPU, StringRef FS,
56 std::optional<Reloc::Model> RM,
57 std::optional<CodeModel::Model> CM,
58 CodeGenOptLevel OL, bool JIT)
59 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
61
62 // Override the default since calls aren't supported for r600.
64 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
65 EnableFunctionCalls = false;
66}
67
70 StringRef GPU = getGPUName(F);
72
73 SmallString<128> SubtargetKey(GPU);
74 SubtargetKey.append(FS);
75
76 auto &I = SubtargetMap[SubtargetKey];
77 if (!I) {
78 // This needs to be done before we create a new subtarget since any
79 // creation will depend on the TM and the code generation flags on the
80 // function that reside in TargetOptions.
82 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
83 }
84
85 return I.get();
86}
87
90 return TargetTransformInfo(R600TTIImpl(this, F));
91}
92
93namespace {
94class R600PassConfig final : public AMDGPUPassConfig {
95public:
96 R600PassConfig(TargetMachine &TM, PassManagerBase &PM)
97 : AMDGPUPassConfig(TM, PM) {}
98
100 createMachineScheduler(MachineSchedContext *C) const override {
102 }
103
104 bool addPreISel() override;
105 bool addInstSelector() override;
106 void addPreRegAlloc() override;
107 void addPreSched2() override;
108 void addPreEmitPass() override;
109};
110} // namespace
111
112//===----------------------------------------------------------------------===//
113// R600 Pass Setup
114//===----------------------------------------------------------------------===//
115
116bool R600PassConfig::addPreISel() {
118
120 addPass(createStructurizeCFGPass());
121 return false;
122}
123
124bool R600PassConfig::addInstSelector() {
125 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
126 return false;
127}
128
129void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
130
131void R600PassConfig::addPreSched2() {
134 addPass(&IfConverterID);
135 addPass(createR600ClauseMergePass());
136}
137
138void R600PassConfig::addPreEmitPass() {
141 addPass(&FinalizeMachineBundlesID);
142 addPass(createR600Packetizer());
144}
145
147 return new R600PassConfig(*this, PM);
148}
149
152 CodeGenFileType FileType, const CGPassBuilderOption &Opts,
154 R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
155 return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
156}
157
159 BumpPtrAllocator &Allocator, const Function &F,
160 const TargetSubtargetInfo *STI) const {
161 return R600MachineFunctionInfo::create<R600MachineFunctionInfo>(
162 Allocator, F, static_cast<const R600Subtarget *>(STI));
163}
164
165//===----------------------------------------------------------------------===//
166// R600 CodeGen Pass Builder interface.
167//===----------------------------------------------------------------------===//
168
170 R600TargetMachine &TM, const CGPassBuilderOption &Opts,
172 : CodeGenPassBuilder(TM, Opts, PIC) {
174}
175
176void R600CodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
177 // TODO: Add passes pre instruction selection.
178}
179
180void R600CodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass,
181 CreateMCStreamer) const {
182 // TODO: Add AsmPrinter.
183}
184
186 // TODO: Add instruction selector.
187 return Error::success();
188}
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
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 TargetTransformInfo::Concept conforming object specific to the R600 target machine.
Basic Register Allocator
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
StringRef getGPUName(const Function &F) const
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
This class provides access to building LLVM's passes.
Error buildPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType) const
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
MachineSchedRegistry provides a selection of available machine instruction schedulers.
void addPreISel(AddIRPass &addPass) const
R600CodeGenPassBuilder(R600TargetMachine &TM, const CGPassBuilderOption &Opts, PassInstrumentationCallbacks *PIC)
void addAsmPrinter(AddMachinePass &, CreateMCStreamer) const
Error addInstSelector(AddMachinePass &) const
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.
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:51
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
Definition: TargetMachine.h:96
void setRequiresStructuredCFG(bool Value)
std::unique_ptr< const MCSubtargetInfo > STI
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:44
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.
Definition: raw_ostream.h:434
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ ReallyHidden
Definition: CommandLine.h:138
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:463
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
char & FinalizeMachineBundlesID
FinalizeMachineBundles - This pass finalize machine instruction bundles (created earlier,...
FunctionPass * createR600ExpandSpecialInstrsPass()
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:83
FunctionPass * createR600EmitClauseMarkers()
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
FunctionPass * createR600ISelDag(TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a R600-specific.
FunctionPass * createR600ControlFlowFinalizer()
FunctionPass * createR600ClauseMergePass()
FunctionPass * createR600VectorRegMerger()
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...
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...