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"
21#include <optional>
22
23using namespace llvm;
24
25static cl::opt<bool>
26 EnableR600StructurizeCFG("r600-ir-structurize",
27 cl::desc("Use StructurizeCFG IR pass"),
28 cl::init(true));
29
30static cl::opt<bool> EnableR600IfConvert("r600-if-convert",
31 cl::desc("Use if conversion pass"),
33
35 "amdgpu-function-calls", cl::desc("Enable AMDGPU function call support"),
38
40 return new ScheduleDAGMILive(C, std::make_unique<R600SchedStrategy>());
41}
42
44 "Run R600's custom scheduler",
46
47//===----------------------------------------------------------------------===//
48// R600 Target Machine (R600 -> Cayman)
49//===----------------------------------------------------------------------===//
50
52 StringRef CPU, StringRef FS,
54 std::optional<Reloc::Model> RM,
55 std::optional<CodeModel::Model> CM,
56 CodeGenOptLevel OL, bool JIT)
57 : AMDGPUTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL) {
59
60 // Override the default since calls aren't supported for r600.
62 EnableAMDGPUFunctionCallsOpt.getNumOccurrences() == 0)
63 EnableFunctionCalls = false;
64}
65
68 StringRef GPU = getGPUName(F);
70
71 SmallString<128> SubtargetKey(GPU);
72 SubtargetKey.append(FS);
73
74 auto &I = SubtargetMap[SubtargetKey];
75 if (!I) {
76 // This needs to be done before we create a new subtarget since any
77 // creation will depend on the TM and the code generation flags on the
78 // function that reside in TargetOptions.
80 I = std::make_unique<R600Subtarget>(TargetTriple, GPU, FS, *this);
81 }
82
83 return I.get();
84}
85
88 return TargetTransformInfo(R600TTIImpl(this, F));
89}
90
91namespace {
92class R600PassConfig final : public AMDGPUPassConfig {
93public:
94 R600PassConfig(LLVMTargetMachine &TM, PassManagerBase &PM)
95 : AMDGPUPassConfig(TM, PM) {}
96
98 createMachineScheduler(MachineSchedContext *C) const override {
100 }
101
102 bool addPreISel() override;
103 bool addInstSelector() override;
104 void addPreRegAlloc() override;
105 void addPreSched2() override;
106 void addPreEmitPass() override;
107};
108} // namespace
109
110//===----------------------------------------------------------------------===//
111// R600 Pass Setup
112//===----------------------------------------------------------------------===//
113
114bool R600PassConfig::addPreISel() {
116
118 addPass(createStructurizeCFGPass());
119 return false;
120}
121
122bool R600PassConfig::addInstSelector() {
123 addPass(createR600ISelDag(getAMDGPUTargetMachine(), getOptLevel()));
124 return false;
125}
126
127void R600PassConfig::addPreRegAlloc() { addPass(createR600VectorRegMerger()); }
128
129void R600PassConfig::addPreSched2() {
132 addPass(&IfConverterID);
133 addPass(createR600ClauseMergePass());
134}
135
136void R600PassConfig::addPreEmitPass() {
139 addPass(&FinalizeMachineBundlesID);
140 addPass(createR600Packetizer());
142}
143
145 return new R600PassConfig(*this, PM);
146}
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
const char LLVMTargetMachineRef TM
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
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.
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:95
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 ...
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
@ ReallyHidden
Definition: CommandLine.h:139
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:450
LocationClass< Ty > location(Ty &L)
Definition: CommandLine.h:470
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()
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...