[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Target / AMDGPU / MCTargetDesc / AMDGPUTargetStreamer.h
blobcef34a5e5a5981fd939e1c6e40d4ca4eacd6cfce
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
10 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
12 #include "Utils/AMDGPUBaseInfo.h"
13 #include "Utils/AMDGPUPALMetadata.h"
14 #include "llvm/MC/MCStreamer.h"
16 struct amd_kernel_code_t;
18 namespace llvm {
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;
29 namespace AMDGPU {
30 namespace HSAMD {
31 struct Metadata;
33 } // namespace AMDGPU
35 namespace amdhsa {
36 struct kernel_descriptor_t;
39 class AMDGPUTargetStreamer : public MCTargetStreamer {
40 AMDGPUPALMetadata PALMetadata;
42 protected:
43 // TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
44 Optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
46 MCContext &getContext() const { return Streamer.getContext(); }
48 public:
49 AMDGPUTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
51 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
53 virtual void EmitDirectiveAMDGCNTarget() = 0;
55 virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
56 uint32_t Minor) = 0;
58 virtual void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor,
59 uint32_t Stepping,
60 StringRef VendorName,
61 StringRef ArchName) = 0;
63 virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
65 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
67 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
68 Align Alignment) = 0;
70 /// \returns True on success, false on failure.
71 virtual bool EmitISAVersion() = 0;
73 /// \returns True on success, false on failure.
74 virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
76 /// \returns True on success, false on failure.
77 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
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;
88 /// \returns True on success, false on failure.
89 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
91 /// \returns True on success, false on failure.
92 virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) = 0;
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;
99 static StringRef getArchNameFromElfMach(unsigned ElfMach);
100 static unsigned getElfMach(StringRef GPU);
102 const Optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
103 return TargetID;
105 Optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
106 return TargetID;
108 void initializeTargetID(const MCSubtargetInfo &STI) {
109 assert(TargetID == None && "TargetID can only be initialized once");
110 TargetID.emplace(STI);
112 void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
113 initializeTargetID(STI);
115 assert(getTargetID() != None && "TargetID is None");
116 getTargetID()->setTargetIDFromFeaturesString(FeatureString);
120 class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer {
121 formatted_raw_ostream &OS;
122 public:
123 AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
125 void finish() override;
127 void EmitDirectiveAMDGCNTarget() override;
129 void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
130 uint32_t Minor) override;
132 void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor,
133 uint32_t Stepping, StringRef VendorName,
134 StringRef ArchName) override;
136 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
138 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
140 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
142 /// \returns True on success, false on failure.
143 bool EmitISAVersion() override;
145 /// \returns True on success, false on failure.
146 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
148 /// \returns True on success, false on failure.
149 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
151 /// \returns True on success, false on failure.
152 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
154 void EmitAmdhsaKernelDescriptor(
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;
160 class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer {
161 const MCSubtargetInfo &STI;
162 MCStreamer &Streamer;
164 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
165 function_ref<void(MCELFStreamer &)> EmitDesc);
167 unsigned getEFlags();
169 unsigned getEFlagsR600();
170 unsigned getEFlagsAMDGCN();
172 unsigned getEFlagsUnknownOS();
173 unsigned getEFlagsAMDHSA();
174 unsigned getEFlagsAMDPAL();
175 unsigned getEFlagsMesa3D();
177 unsigned getEFlagsV3();
178 unsigned getEFlagsV4();
180 public:
181 AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
183 MCELFStreamer &getStreamer();
185 void finish() override;
187 void EmitDirectiveAMDGCNTarget() override;
189 void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
190 uint32_t Minor) override;
192 void EmitDirectiveHSACodeObjectISAV2(uint32_t Major, uint32_t Minor,
193 uint32_t Stepping, StringRef VendorName,
194 StringRef ArchName) override;
196 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
198 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
200 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
202 /// \returns True on success, false on failure.
203 bool EmitISAVersion() override;
205 /// \returns True on success, false on failure.
206 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
208 /// \returns True on success, false on failure.
209 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
211 /// \returns True on success, false on failure.
212 bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
214 void EmitAmdhsaKernelDescriptor(
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;
221 #endif