LLVM  13.0.0git
AMDGPUTargetStreamer.h
Go to the documentation of this file.
1 //===-- AMDGPUTargetStreamer.h - AMDGPU Target Streamer --------*- C++ -*--===//
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 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
10 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
11 
12 #include "Utils/AMDGPUBaseInfo.h"
14 #include "llvm/MC/MCStreamer.h"
15 
16 struct amd_kernel_code_t;
17 
18 namespace llvm {
19 
20 class DataLayout;
21 class Function;
22 class MCELFStreamer;
23 class MCSymbol;
24 class MDNode;
25 class Module;
26 class Type;
27 class formatted_raw_ostream;
28 
29 namespace AMDGPU {
30 namespace HSAMD {
31 struct Metadata;
32 }
33 } // namespace AMDGPU
34 
35 namespace amdhsa {
36 struct kernel_descriptor_t;
37 }
38 
40  AMDGPUPALMetadata PALMetadata;
41 
42 protected:
43  // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
45 
46  MCContext &getContext() const { return Streamer.getContext(); }
47 
48 public:
50 
51  AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
52 
53  virtual void EmitDirectiveAMDGCNTarget() = 0;
54 
56  uint32_t Minor) = 0;
57 
58  virtual void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor,
59  uint32_t Stepping,
60  StringRef VendorName,
61  StringRef ArchName) = 0;
62 
63  virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
64 
65  virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
66 
67  virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
68  Align Alignment) = 0;
69 
70  /// \returns True on success, false on failure.
71  virtual bool EmitISAVersion() = 0;
72 
73  /// \returns True on success, false on failure.
74  virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
75 
76  /// \returns True on success, false on failure.
77  virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
78 
79  /// Emit HSA Metadata
80  ///
81  /// When \p Strict is true, known metadata elements must already be
82  /// well-typed. When \p Strict is false, known types are inferred and
83  /// the \p HSAMetadata structure is updated with the correct types.
84  ///
85  /// \returns True on success, false on failure.
86  virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) = 0;
87 
88  /// \returns True on success, false on failure.
89  virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
90 
91  /// \returns True on success, false on failure.
92  virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) = 0;
93 
94  virtual void EmitAmdhsaKernelDescriptor(
95  const MCSubtargetInfo &STI, StringRef KernelName,
96  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
97  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) = 0;
98 
99  static StringRef getArchNameFromElfMach(unsigned ElfMach);
100  static unsigned getElfMach(StringRef GPU);
101 
103  return TargetID;
104  }
106  return TargetID;
107  }
109  assert(TargetID == None && "TargetID can only be initialized once");
110  TargetID.emplace(STI);
111  }
112  void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
113  initializeTargetID(STI);
114 
115  assert(getTargetID() != None && "TargetID is None");
116  getTargetID()->setTargetIDFromFeaturesString(FeatureString);
117  }
118 };
119 
122 public:
124 
125  void finish() override;
126 
127  void EmitDirectiveAMDGCNTarget() override;
128 
130  uint32_t Minor) override;
131 
133  uint32_t Stepping, StringRef VendorName,
134  StringRef ArchName) override;
135 
136  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
137 
138  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
139 
140  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
141 
142  /// \returns True on success, false on failure.
143  bool EmitISAVersion() override;
144 
145  /// \returns True on success, false on failure.
146  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
147 
148  /// \returns True on success, false on failure.
149  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
150 
151  /// \returns True on success, false on failure.
152  bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
153 
155  const MCSubtargetInfo &STI, StringRef KernelName,
156  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
157  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override;
158 };
159 
161  const MCSubtargetInfo &STI;
162  MCStreamer &Streamer;
163 
164  void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
165  function_ref<void(MCELFStreamer &)> EmitDesc);
166 
167  unsigned getEFlags();
168 
169  unsigned getEFlagsR600();
170  unsigned getEFlagsAMDGCN();
171 
172  unsigned getEFlagsUnknownOS();
173  unsigned getEFlagsAMDHSA();
174  unsigned getEFlagsAMDPAL();
175  unsigned getEFlagsMesa3D();
176 
177  unsigned getEFlagsV3();
178  unsigned getEFlagsV4();
179 
180 public:
182 
184 
185  void finish() override;
186 
187  void EmitDirectiveAMDGCNTarget() override;
188 
190  uint32_t Minor) override;
191 
193  uint32_t Stepping, StringRef VendorName,
194  StringRef ArchName) override;
195 
196  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
197 
198  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
199 
200  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
201 
202  /// \returns True on success, false on failure.
203  bool EmitISAVersion() override;
204 
205  /// \returns True on success, false on failure.
206  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
207 
208  /// \returns True on success, false on failure.
209  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
210 
211  /// \returns True on success, false on failure.
212  bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
213 
215  const MCSubtargetInfo &STI, StringRef KernelName,
216  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
217  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override;
218 };
219 
220 }
221 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::AMDGPUTargetStreamer::getTargetID
const Optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID() const
Definition: AMDGPUTargetStreamer.h:102
llvm
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::AMDGPUTargetStreamer::getContext
MCContext & getContext() const
Definition: AMDGPUTargetStreamer.h:46
llvm::AMDGPUTargetAsmStreamer::EmitISAVersion
bool EmitISAVersion() override
Definition: AMDGPUTargetStreamer.cpp:243
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:71
llvm::AMDGPUTargetAsmStreamer::AMDGPUTargetAsmStreamer
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
Definition: AMDGPUTargetStreamer.cpp:182
llvm::AMDGPUTargetStreamer::EmitDirectiveAMDGCNTarget
virtual void EmitDirectiveAMDGCNTarget()=0
llvm::AMDGPUTargetAsmStreamer::EmitAmdhsaKernelDescriptor
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override
Definition: AMDGPUTargetStreamer.cpp:298
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectVersion
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
Definition: AMDGPUTargetStreamer.cpp:203
llvm::AMDGPUTargetStreamer::EmitDirectiveHSACodeObjectVersion
virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor)=0
llvm::Optional
Definition: APInt.h:33
llvm::AMDGPUPALMetadata
Definition: AMDGPUPALMetadata.h:24
llvm::AMDGPUTargetStreamer::EmitAMDKernelCodeT
virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header)=0
llvm::AMDGPUTargetStreamer::initializeTargetID
void initializeTargetID(const MCSubtargetInfo &STI)
Definition: AMDGPUTargetStreamer.h:108
llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
Definition: AMDGPUTargetStreamer.cpp:735
llvm::AMDGPUTargetStreamer::TargetID
Optional< AMDGPU::IsaInfo::AMDGPUTargetID > TargetID
Definition: AMDGPUTargetStreamer.h:44
llvm::AMDGPUTargetELFStreamer::EmitCodeEnd
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
Definition: AMDGPUTargetStreamer.cpp:786
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:197
llvm::AMDGPUTargetAsmStreamer::EmitAMDKernelCodeT
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
Definition: AMDGPUTargetStreamer.cpp:221
llvm::AMDGPUTargetStreamer::EmitHSAMetadata
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)=0
Emit HSA Metadata.
llvm::MCELFStreamer
Definition: MCELFStreamer.h:23
llvm::AMDGPUTargetAsmStreamer::EmitAMDGPUSymbolType
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
Definition: AMDGPUTargetStreamer.cpp:227
llvm::AMDGPUTargetStreamer::AMDGPUTargetStreamer
AMDGPUTargetStreamer(MCStreamer &S)
Definition: AMDGPUTargetStreamer.h:49
llvm::msgpack::Document
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
Definition: MsgPackDocument.h:272
llvm::AMDGPUTargetStreamer::emitAMDGPULDS
virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment)=0
llvm::AMDGPU::HSAMD::Metadata
In-memory representation of HSA metadata.
Definition: AMDGPUMetadata.h:431
llvm::AMDGPUTargetELFStreamer::EmitDirectiveAMDGCNTarget
void EmitDirectiveAMDGCNTarget() override
Definition: AMDGPUTargetStreamer.cpp:641
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:91
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectISAV2
void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
Definition: AMDGPUTargetStreamer.cpp:654
llvm::None
const NoneType None
Definition: None.h:23
llvm::AMDGPUTargetStreamer::EmitAmdhsaKernelDescriptor
virtual void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr)=0
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::AMDGPUTargetELFStreamer::EmitDirectiveHSACodeObjectVersion
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
Definition: AMDGPUTargetStreamer.cpp:643
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveAMDGCNTarget
void EmitDirectiveAMDGCNTarget() override
Definition: AMDGPUTargetStreamer.cpp:199
llvm::AMDGPUTargetAsmStreamer::finish
void finish() override
Definition: AMDGPUTargetStreamer.cpp:189
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectISAV2
void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
Definition: AMDGPUTargetStreamer.cpp:210
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:93
llvm::AMDGPUTargetStreamer::EmitHSAMetadataV2
virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString)
Definition: AMDGPUTargetStreamer.cpp:48
llvm::AMDGPUTargetStreamer::initializeTargetID
void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString)
Definition: AMDGPUTargetStreamer.h:112
llvm::AMDGPUTargetStreamer::EmitISAVersion
virtual bool EmitISAVersion()=0
TemplateParamKind::Type
@ Type
llvm::formatted_raw_ostream
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
Definition: FormattedStream.h:30
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AMDGPUTargetELFStreamer::getStreamer
MCELFStreamer & getStreamer()
Definition: AMDGPUTargetStreamer.cpp:463
llvm::AMDGPUTargetStreamer::EmitHSAMetadataV3
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString)
Definition: AMDGPUTargetStreamer.cpp:55
llvm::AMDGPUTargetELFStreamer::emitAMDGPULDS
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
Definition: AMDGPUTargetStreamer.cpp:697
llvm::AMDGPUTargetELFStreamer::EmitAMDKernelCodeT
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
Definition: AMDGPUTargetStreamer.cpp:682
llvm::AMDGPUTargetELFStreamer::EmitAmdhsaKernelDescriptor
void EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName, const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override
Definition: AMDGPUTargetStreamer.cpp:812
llvm::AMDGPUTargetStreamer::EmitCodeEnd
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI)=0
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
uint32_t
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::AMDGPUTargetStreamer
Definition: AMDGPUTargetStreamer.h:39
amd_kernel_code_t
AMD Kernel Code Object (amd_kernel_code_t).
Definition: AMDKernelCodeT.h:526
AMDGPUPALMetadata.h
llvm::AMDGPUTargetAsmStreamer
Definition: AMDGPUTargetStreamer.h:120
llvm::AMDGPU::HSAMD::Kernel::Key::SymbolName
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Definition: AMDGPUMetadata.h:381
llvm::AMDGPUTargetStreamer::EmitAMDGPUSymbolType
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type)=0
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::AMDGPUTargetELFStreamer::finish
void finish() override
Definition: AMDGPUTargetStreamer.cpp:470
llvm::FPOpFusion::Strict
@ Strict
Definition: TargetOptions.h:39
llvm::amdhsa::kernel_descriptor_t
Definition: AMDHSAKernelDescriptor.h:165
llvm::AMDGPUTargetStreamer::getArchNameFromElfMach
static StringRef getArchNameFromElfMach(unsigned ElfMach)
Definition: AMDGPUTargetStreamer.cpp:62
llvm::AMDGPUTargetStreamer::EmitDirectiveHSACodeObjectISAV2
virtual void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName)=0
llvm::AMDGPUTargetELFStreamer::EmitAMDGPUSymbolType
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
Definition: AMDGPUTargetStreamer.cpp:690
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:278
MCStreamer.h
LineType::Metadata
@ Metadata
llvm::AMDGPUTargetELFStreamer
Definition: AMDGPUTargetStreamer.h:160
llvm::AMDGPUTargetStreamer::getPALMetadata
AMDGPUPALMetadata * getPALMetadata()
Definition: AMDGPUTargetStreamer.h:51
llvm::AMDGPUTargetAsmStreamer::EmitHSAMetadata
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
Definition: AMDGPUTargetStreamer.cpp:260
llvm::AMDGPUTargetELFStreamer::EmitISAVersion
bool EmitISAVersion() override
Definition: AMDGPUTargetStreamer.cpp:716
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::AMDGPUTargetAsmStreamer::EmitCodeEnd
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
Definition: AMDGPUTargetStreamer.cpp:276
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::AMDGPUTargetAsmStreamer::emitAMDGPULDS
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override
Definition: AMDGPUTargetStreamer.cpp:237
llvm::AMDGPUTargetStreamer::getTargetID
Optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID()
Definition: AMDGPUTargetStreamer.h:105
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:165
llvm::AMDGPUTargetELFStreamer::AMDGPUTargetELFStreamer
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: AMDGPUTargetStreamer.cpp:459
AMDGPUBaseInfo.h
llvm::AMDGPUTargetStreamer::getElfMach
static unsigned getElfMach(StringRef GPU)
Definition: AMDGPUTargetStreamer.cpp:121