LLVM 22.0.0git
AMDGPUMCTargetDesc.cpp
Go to the documentation of this file.
1//===-- AMDGPUMCTargetDesc.cpp - AMDGPU Target Descriptions ---------------===//
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 provides AMDGPU specific target descriptions.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AMDGPUMCTargetDesc.h"
15#include "AMDGPUELFStreamer.h"
16#include "AMDGPUInstPrinter.h"
17#include "AMDGPUMCAsmInfo.h"
19#include "R600InstPrinter.h"
20#include "R600MCTargetDesc.h"
27#include "llvm/MC/MCInstrDesc.h"
28#include "llvm/MC/MCInstrInfo.h"
31#include "llvm/MC/MCStreamer.h"
35
36using namespace llvm;
37
38#define GET_INSTRINFO_MC_DESC
39#define ENABLE_INSTR_PREDICATE_VERIFIER
40#include "AMDGPUGenInstrInfo.inc"
41
42#define GET_SUBTARGETINFO_MC_DESC
43#include "AMDGPUGenSubtargetInfo.inc"
44
45#define NoSchedModel NoSchedModelR600
46#define GET_SUBTARGETINFO_MC_DESC
47#include "R600GenSubtargetInfo.inc"
48#undef NoSchedModelR600
49
50#define GET_REGINFO_MC_DESC
51#include "AMDGPUGenRegisterInfo.inc"
52
53#define GET_REGINFO_MC_DESC
54#include "R600GenRegisterInfo.inc"
55
57 MCInstrInfo *X = new MCInstrInfo();
58 InitAMDGPUMCInstrInfo(X);
59 return X;
60}
61
64 if (TT.getArch() == Triple::r600)
65 InitR600MCRegisterInfo(X, 0);
66 else
67 InitAMDGPUMCRegisterInfo(X, AMDGPU::PC_REG);
68 return X;
69}
70
73 InitAMDGPUMCRegisterInfo(X, AMDGPU::PC_REG, DwarfFlavour, DwarfFlavour);
74 return X;
75}
76
77static MCSubtargetInfo *
79 if (TT.getArch() == Triple::r600)
80 return createR600MCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
81
82 MCSubtargetInfo *STI =
83 createAMDGPUMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
84
85 // FIXME: We should error for the default target.
86 if (!STI->hasFeature(AMDGPU::FeatureWavefrontSize64) &&
87 !STI->hasFeature(AMDGPU::FeatureWavefrontSize32)) {
88 // If there is no default wave size it must be a generation before gfx10,
89 // these have FeatureWavefrontSize64 in their definition already. For gfx10+
90 // set wave32 as a default.
92 ? AMDGPU::FeatureWavefrontSize32
93 : AMDGPU::FeatureWavefrontSize64);
94 }
95
96 return STI;
97}
98
100 unsigned SyntaxVariant,
101 const MCAsmInfo &MAI,
102 const MCInstrInfo &MII,
103 const MCRegisterInfo &MRI) {
104 if (T.getArch() == Triple::r600)
105 return new R600InstPrinter(MAI, MII, MRI);
106 return new AMDGPUInstPrinter(MAI, MII, MRI);
107}
108
109static MCTargetStreamer *
111 MCInstPrinter *InstPrint) {
112 return new AMDGPUTargetAsmStreamer(S, OS);
113}
114
116 MCStreamer &S,
117 const MCSubtargetInfo &STI) {
118 return new AMDGPUTargetELFStreamer(S, STI);
119}
120
122 return new AMDGPUTargetStreamer(S);
123}
124
126 std::unique_ptr<MCAsmBackend> &&MAB,
127 std::unique_ptr<MCObjectWriter> &&OW,
128 std::unique_ptr<MCCodeEmitter> &&Emitter) {
129 return createAMDGPUELFStreamer(T, Context, std::move(MAB), std::move(OW),
130 std::move(Emitter));
131}
132
133namespace {
134
135class AMDGPUMCInstrAnalysis : public MCInstrAnalysis {
136public:
137 explicit AMDGPUMCInstrAnalysis(const MCInstrInfo *Info)
139
140 bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
141 uint64_t &Target) const override {
142 if (Inst.getNumOperands() == 0 || !Inst.getOperand(0).isImm() ||
143 Info->get(Inst.getOpcode()).operands()[0].OperandType !=
145 return false;
146
147 int64_t Imm = Inst.getOperand(0).getImm();
148 // Our branches take a simm16.
149 Target = SignExtend64<16>(Imm) * 4 + Addr + Size;
150 return true;
151 }
152};
153
154} // end anonymous namespace
155
157 return new AMDGPUMCInstrAnalysis(Info);
158}
159
162
166 for (Target *T : {&getTheR600Target(), &getTheGCNTarget()}) {
168
175 }
176
177 // R600 specific registration
182
183 // GCN specific registration
186
193}
unsigned const MachineRegisterInfo * MRI
static MCInstrInfo * createAMDGPUMCInstrInfo()
static MCTargetStreamer * createAMDGPUAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint)
static MCStreamer * createMCStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > &&MAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter)
static MCSubtargetInfo * createAMDGPUMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS)
static MCInstrAnalysis * createAMDGPUMCInstrAnalysis(const MCInstrInfo *Info)
static MCTargetStreamer * createAMDGPUNullTargetStreamer(MCStreamer &S)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTargetMC()
static MCTargetStreamer * createAMDGPUObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
static MCInstPrinter * createAMDGPUMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI)
static MCRegisterInfo * createAMDGPUMCRegisterInfo(const Triple &TT)
Provides AMDGPU specific target descriptions.
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define LLVM_ABI
Definition: Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
dxil DXContainer Global Emitter
uint64_t Addr
uint64_t Size
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Provides R600 specific target descriptions.
raw_pwrite_stream & OS
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:64
Context object for machine code objects.
Definition: MCContext.h:83
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:188
unsigned getNumOperands() const
Definition: MCInst.h:212
unsigned getOpcode() const
Definition: MCInst.h:202
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:210
virtual bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, uint64_t &Target) const
Given a branch instruction try to get the address the branch targets.
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:27
int64_t getImm() const
Definition: MCInst.h:84
bool isImm() const
Definition: MCInst.h:66
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Streaming machine code generation interface.
Definition: MCStreamer.h:220
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
FeatureBitset ToggleFeature(uint64_t FB)
Toggle a feature and return the re-computed feature bits.
Target specific streamer interface.
Definition: MCStreamer.h:93
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
bool isGFX10Plus(const MCSubtargetInfo &STI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
MCAsmBackend * createAMDGPUAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
Target & getTheR600Target()
The target for R600 GPUs.
MCCodeEmitter * createR600MCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
MCELFStreamer * createAMDGPUELFStreamer(const Triple &T, MCContext &Context, std::unique_ptr< MCAsmBackend > MAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
Target & getTheGCNTarget()
The target for GCN GPUs.
MCRegisterInfo * createGCNMCRegisterInfo(AMDGPUDwarfFlavour DwarfFlavour)
MCInstrInfo * createR600MCInstrInfo()
MCCodeEmitter * createAMDGPUMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
RegisterMCAsmInfo - Helper template for registering a target assembly info implementation.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)