LLVM  14.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 MCELFStreamer;
21 class MCSymbol;
22 class formatted_raw_ostream;
23 
24 namespace AMDGPU {
25 namespace HSAMD {
26 struct Metadata;
27 }
28 } // namespace AMDGPU
29 
30 namespace amdhsa {
31 struct kernel_descriptor_t;
32 }
33 
35  AMDGPUPALMetadata PALMetadata;
36 
37 protected:
38  // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
40 
41  MCContext &getContext() const { return Streamer.getContext(); }
42 
43 public:
45 
46  AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
47 
48  virtual void EmitDirectiveAMDGCNTarget() = 0;
49 
51  uint32_t Minor) = 0;
52 
53  virtual void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor,
54  uint32_t Stepping,
55  StringRef VendorName,
56  StringRef ArchName) = 0;
57 
58  virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
59 
60  virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
61 
62  virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
63  Align Alignment) = 0;
64 
65  /// \returns True on success, false on failure.
66  virtual bool EmitISAVersion() = 0;
67 
68  /// \returns True on success, false on failure.
69  virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
70 
71  /// \returns True on success, false on failure.
72  virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
73 
74  /// Emit HSA Metadata
75  ///
76  /// When \p Strict is true, known metadata elements must already be
77  /// well-typed. When \p Strict is false, known types are inferred and
78  /// the \p HSAMetadata structure is updated with the correct types.
79  ///
80  /// \returns True on success, false on failure.
81  virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) = 0;
82 
83  /// \returns True on success, false on failure.
84  virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
85 
86  /// \returns True on success, false on failure.
87  virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) = 0;
88 
89  virtual void EmitAmdhsaKernelDescriptor(
90  const MCSubtargetInfo &STI, StringRef KernelName,
91  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
92  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) = 0;
93 
94  static StringRef getArchNameFromElfMach(unsigned ElfMach);
95  static unsigned getElfMach(StringRef GPU);
96 
98  return TargetID;
99  }
101  return TargetID;
102  }
104  assert(TargetID == None && "TargetID can only be initialized once");
105  TargetID.emplace(STI);
106  }
107  void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
108  initializeTargetID(STI);
109 
110  assert(getTargetID() != None && "TargetID is None");
111  getTargetID()->setTargetIDFromFeaturesString(FeatureString);
112  }
113 };
114 
117 public:
119 
120  void finish() override;
121 
122  void EmitDirectiveAMDGCNTarget() override;
123 
125  uint32_t Minor) override;
126 
128  uint32_t Stepping, StringRef VendorName,
129  StringRef ArchName) override;
130 
131  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
132 
133  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
134 
135  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
136 
137  /// \returns True on success, false on failure.
138  bool EmitISAVersion() override;
139 
140  /// \returns True on success, false on failure.
141  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
142 
143  /// \returns True on success, false on failure.
144  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
145 
146  /// \returns True on success, false on failure.
147  bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
148 
150  const MCSubtargetInfo &STI, StringRef KernelName,
151  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
152  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override;
153 };
154 
156  const MCSubtargetInfo &STI;
157  MCStreamer &Streamer;
158 
159  void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
160  function_ref<void(MCELFStreamer &)> EmitDesc);
161 
162  unsigned getEFlags();
163 
164  unsigned getEFlagsR600();
165  unsigned getEFlagsAMDGCN();
166 
167  unsigned getEFlagsUnknownOS();
168  unsigned getEFlagsAMDHSA();
169  unsigned getEFlagsAMDPAL();
170  unsigned getEFlagsMesa3D();
171 
172  unsigned getEFlagsV3();
173  unsigned getEFlagsV4();
174 
175 public:
177 
179 
180  void finish() override;
181 
182  void EmitDirectiveAMDGCNTarget() override;
183 
185  uint32_t Minor) override;
186 
188  uint32_t Stepping, StringRef VendorName,
189  StringRef ArchName) override;
190 
191  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
192 
193  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
194 
195  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
196 
197  /// \returns True on success, false on failure.
198  bool EmitISAVersion() override;
199 
200  /// \returns True on success, false on failure.
201  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
202 
203  /// \returns True on success, false on failure.
204  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
205 
206  /// \returns True on success, false on failure.
207  bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
208 
210  const MCSubtargetInfo &STI, StringRef KernelName,
211  const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
212  uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr) override;
213 };
214 
215 }
216 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::AMDGPUTargetStreamer::getTargetID
const Optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID() const
Definition: AMDGPUTargetStreamer.h:97
llvm
This file implements support for optimizing divisions by a constant.
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:41
llvm::AMDGPUTargetAsmStreamer::EmitISAVersion
bool EmitISAVersion() override
Definition: AMDGPUTargetStreamer.cpp:249
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::AMDGPUTargetAsmStreamer::AMDGPUTargetAsmStreamer
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
Definition: AMDGPUTargetStreamer.cpp:188
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:304
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectVersion
void EmitDirectiveHSACodeObjectVersion(uint32_t Major, uint32_t Minor) override
Definition: AMDGPUTargetStreamer.cpp:209
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:103
llvm::AMDGPUTargetELFStreamer::EmitHSAMetadata
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
Definition: AMDGPUTargetStreamer.cpp:746
llvm::AMDGPUTargetStreamer::TargetID
Optional< AMDGPU::IsaInfo::AMDGPUTargetID > TargetID
Definition: AMDGPUTargetStreamer.h:39
llvm::AMDGPUTargetELFStreamer::EmitCodeEnd
bool EmitCodeEnd(const MCSubtargetInfo &STI) override
Definition: AMDGPUTargetStreamer.cpp:797
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
llvm::AMDGPUTargetAsmStreamer::EmitAMDKernelCodeT
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
Definition: AMDGPUTargetStreamer.cpp:227
llvm::AMDGPUTargetStreamer::EmitHSAMetadata
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)=0
Emit HSA Metadata.
llvm::MCELFStreamer
Definition: MCELFStreamer.h:24
llvm::AMDGPUTargetAsmStreamer::EmitAMDGPUSymbolType
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override
Definition: AMDGPUTargetStreamer.cpp:233
llvm::AMDGPUTargetStreamer::AMDGPUTargetStreamer
AMDGPUTargetStreamer(MCStreamer &S)
Definition: AMDGPUTargetStreamer.h:44
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:652
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:665
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:654
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveAMDGCNTarget
void EmitDirectiveAMDGCNTarget() override
Definition: AMDGPUTargetStreamer.cpp:205
llvm::AMDGPUTargetAsmStreamer::finish
void finish() override
Definition: AMDGPUTargetStreamer.cpp:195
uint64_t
llvm::AMDGPUTargetAsmStreamer::EmitDirectiveHSACodeObjectISAV2
void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor, uint32_t Stepping, StringRef VendorName, StringRef ArchName) override
Definition: AMDGPUTargetStreamer.cpp:216
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:107
llvm::AMDGPUTargetStreamer::EmitISAVersion
virtual bool EmitISAVersion()=0
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:474
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:708
llvm::AMDGPUTargetELFStreamer::EmitAMDKernelCodeT
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override
Definition: AMDGPUTargetStreamer.cpp:693
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:823
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:58
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
llvm::AMDGPUTargetStreamer
Definition: AMDGPUTargetStreamer.h:34
amd_kernel_code_t
AMD Kernel Code Object (amd_kernel_code_t).
Definition: AMDKernelCodeT.h:526
AMDGPUPALMetadata.h
llvm::AMDGPUTargetAsmStreamer
Definition: AMDGPUTargetStreamer.h:115
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:481
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:701
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:79
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
MCStreamer.h
LineType::Metadata
@ Metadata
llvm::AMDGPUTargetELFStreamer
Definition: AMDGPUTargetStreamer.h:155
llvm::AMDGPUTargetStreamer::getPALMetadata
AMDGPUPALMetadata * getPALMetadata()
Definition: AMDGPUTargetStreamer.h:46
llvm::AMDGPUTargetAsmStreamer::EmitHSAMetadata
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override
Definition: AMDGPUTargetStreamer.cpp:266
llvm::AMDGPUTargetELFStreamer::EmitISAVersion
bool EmitISAVersion() override
Definition: AMDGPUTargetStreamer.cpp:727
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:282
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:243
llvm::AMDGPUTargetStreamer::getTargetID
Optional< AMDGPU::IsaInfo::AMDGPUTargetID > & getTargetID()
Definition: AMDGPUTargetStreamer.h:100
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::AMDGPUTargetELFStreamer::AMDGPUTargetELFStreamer
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: AMDGPUTargetStreamer.cpp:470
AMDGPUBaseInfo.h
llvm::AMDGPUTargetStreamer::getElfMach
static unsigned getElfMach(StringRef GPU)
Definition: AMDGPUTargetStreamer.cpp:124