[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / AMDGPU / MCTargetDesc / AMDGPUTargetStreamer.h
blob683b3e363b9aa0ed2575101e65ada01d963eea3f
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 "AMDKernelCodeT.h"
13 #include "Utils/AMDGPUPALMetadata.h"
14 #include "llvm/BinaryFormat/MsgPackDocument.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/MC/MCSubtargetInfo.h"
17 #include "llvm/Support/AMDGPUMetadata.h"
18 #include "llvm/Support/AMDHSAKernelDescriptor.h"
20 namespace llvm {
21 #include "AMDGPUPTNote.h"
23 class DataLayout;
24 class Function;
25 class MCELFStreamer;
26 class MCSymbol;
27 class MDNode;
28 class Module;
29 class Type;
31 class AMDGPUTargetStreamer : public MCTargetStreamer {
32 AMDGPUPALMetadata PALMetadata;
34 protected:
35 MCContext &getContext() const { return Streamer.getContext(); }
37 public:
38 AMDGPUTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
40 AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
42 virtual void EmitDirectiveAMDGCNTarget(StringRef Target) = 0;
44 virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
45 uint32_t Minor) = 0;
47 virtual void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
48 uint32_t Stepping,
49 StringRef VendorName,
50 StringRef ArchName) = 0;
52 virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
54 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
56 virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
57 unsigned Align) = 0;
59 /// \returns True on success, false on failure.
60 virtual bool EmitISAVersion(StringRef IsaVersionString) = 0;
62 /// \returns True on success, false on failure.
63 virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
65 /// \returns True on success, false on failure.
66 virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
68 /// Emit HSA Metadata
69 ///
70 /// When \p Strict is true, known metadata elements must already be
71 /// well-typed. When \p Strict is false, known types are inferred and
72 /// the \p HSAMetadata structure is updated with the correct types.
73 ///
74 /// \returns True on success, false on failure.
75 virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) = 0;
77 /// \returns True on success, false on failure.
78 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
80 /// \returns True on success, false on failure.
81 virtual bool EmitCodeEnd() = 0;
83 virtual void EmitAmdhsaKernelDescriptor(
84 const MCSubtargetInfo &STI, StringRef KernelName,
85 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
86 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
87 bool ReserveXNACK) = 0;
89 static StringRef getArchNameFromElfMach(unsigned ElfMach);
90 static unsigned getElfMach(StringRef GPU);
93 class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer {
94 formatted_raw_ostream &OS;
95 public:
96 AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
98 void finish() override;
100 void EmitDirectiveAMDGCNTarget(StringRef Target) override;
102 void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
103 uint32_t Minor) override;
105 void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
106 uint32_t Stepping, StringRef VendorName,
107 StringRef ArchName) override;
109 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
111 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
113 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override;
115 /// \returns True on success, false on failure.
116 bool EmitISAVersion(StringRef IsaVersionString) override;
118 /// \returns True on success, false on failure.
119 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
121 /// \returns True on success, false on failure.
122 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
124 /// \returns True on success, false on failure.
125 bool EmitCodeEnd() override;
127 void EmitAmdhsaKernelDescriptor(
128 const MCSubtargetInfo &STI, StringRef KernelName,
129 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
130 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
131 bool ReserveXNACK) override;
134 class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer {
135 MCStreamer &Streamer;
137 void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
138 function_ref<void(MCELFStreamer &)> EmitDesc);
140 public:
141 AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
143 MCELFStreamer &getStreamer();
145 void finish() override;
147 void EmitDirectiveAMDGCNTarget(StringRef Target) override;
149 void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
150 uint32_t Minor) override;
152 void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
153 uint32_t Stepping, StringRef VendorName,
154 StringRef ArchName) override;
156 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
158 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
160 void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override;
162 /// \returns True on success, false on failure.
163 bool EmitISAVersion(StringRef IsaVersionString) override;
165 /// \returns True on success, false on failure.
166 bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
168 /// \returns True on success, false on failure.
169 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
171 /// \returns True on success, false on failure.
172 bool EmitCodeEnd() override;
174 void EmitAmdhsaKernelDescriptor(
175 const MCSubtargetInfo &STI, StringRef KernelName,
176 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
177 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
178 bool ReserveXNACK) override;
182 #endif