LLVM 19.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/// The AMDGPU-R600 target machine contains all of the hardware specific
11/// information needed to emit code for R600 GPUs.
12//
13//===----------------------------------------------------------------------===//
14
15#include "R600TargetMachine.h"
16#include "AMDGPUTargetMachine.h"
17#include "R600.h"
22#include <optional>
23
24using namespace llvm;
25
26static cl::opt<bool>
27 EnableR600StructurizeCFG("r600-ir-structurize",
28 cl::desc("Use StructurizeCFG IR pass"),
29 cl::init(true));
30
31static cl::opt<bool> EnableR600IfConvert("r600-if-convert",
32 cl::desc("Use if conversion pass"),
34
36 "amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
39
41 return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
42}
43
45 "Run R600's custom scheduler",
47
48//===----------------------------------------------------------------------===//
49// R600 Target Machine (R600 -> Cayman)
50//===----------------------------------------------------------------------===//
51
53 StringRef CPU, StringRef FS,
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) {
60
61 // Override the default since calls aren't supported for r600.
63 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
64 EnableFunctionCalls = false;
65}
66
69 StringRef GPU = getGPUName(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.
81 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
82 }
83
84 return I.get();
85}
86
89 return TargetTransformInfo(R600TTIImpl(this, F));
90}
91
92namespace {
93class R600PassConfig final : public AMDGPUPassConfig {
94public:
95 R600PassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
96 : AMDGPUPassConfig(TM, PM) {}
97
99 createMachineScheduler(MachineSchedContext *C) const override {
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 Pass Setup
113//===----------------------------------------------------------------------===//
114
115bool R600PassConfig::addPreISel() {
117
119 addPass(createStructurizeCFGPass());
120 return false;
121}
122
123bool R600PassConfig::addInstSelector() {
124 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
125 return false;
126}
127
128void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
129
130void R600PassConfig::addPreSched2() {
133 addPass(&IfConverterID);
134 addPass(createR600ClauseMergePass());
135}
136
137void R600PassConfig::addPreEmitPass() {
140 addPass(&FinalizeMachineBundlesID);
141 addPass(createR600Packetizer());
143}
144
146 return new R600PassConfig(*this, PM);
147}
148
151 CodeGenFileType FileType, const CGPassBuilderOption &Opts,
153 R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
154 return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
155}
The AMDGPU TargetMachine interface definition for hw codegen targets.
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
ModulePassManager MPM
const char LLVMTargetMachineRef TM
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.
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
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
This class describes a target machine that is implemented with the LLVM target-independent code gener...
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 ...
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:50
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
Definition: TargetMachine.h:96
void setRequiresStructuredCFG(bool Value)
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()
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...