1 //===-- AMDGPUTargetStreamer.h - AMDGPU Target Streamer --------*- C++ -*--===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H 11 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H 12 13 #include "AMDKernelCodeT.h" 14 #include "llvm/MC/MCStreamer.h" 15 #include "llvm/MC/MCSubtargetInfo.h" 16 #include "llvm/Support/AMDGPUMetadata.h" 17 #include "llvm/Support/AMDHSAKernelDescriptor.h" 18 19 namespace llvm { 20 #include "AMDGPUPTNote.h" 21 22 class DataLayout; 23 class Function; 24 class MCELFStreamer; 25 class MCSymbol; 26 class MDNode; 27 class Module; 28 class Type; 29 30 class AMDGPUTargetStreamer : public MCTargetStreamer { 31 protected: getContext()32 MCContext &getContext() const { return Streamer.getContext(); } 33 34 /// \returns Equivalent EF_AMDGPU_MACH_* value for given \p GPU name. 35 unsigned getMACH(StringRef GPU) const; 36 37 public: 38 /// \returns Equivalent GPU name for an EF_AMDGPU_MACH_* value. 39 static const char *getMachName(unsigned Mach); 40 AMDGPUTargetStreamer(MCStreamer & S)41 AMDGPUTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} 42 43 virtual void EmitDirectiveAMDGCNTarget(StringRef Target) = 0; 44 45 virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major, 46 uint32_t Minor) = 0; 47 48 virtual void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, 49 uint32_t Stepping, 50 StringRef VendorName, 51 StringRef ArchName) = 0; 52 53 virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0; 54 55 virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0; 56 57 /// \returns True on success, false on failure. 58 virtual bool EmitISAVersion(StringRef IsaVersionString) = 0; 59 60 /// \returns True on success, false on failure. 61 virtual bool EmitHSAMetadata(StringRef HSAMetadataString); 62 63 /// \returns True on success, false on failure. 64 virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0; 65 66 /// \returns True on success, false on failure. 67 virtual bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) = 0; 68 69 virtual void EmitAmdhsaKernelDescriptor( 70 const MCSubtargetInfo &STI, StringRef KernelName, 71 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, 72 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, 73 bool ReserveXNACK) = 0; 74 }; 75 76 class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer { 77 formatted_raw_ostream &OS; 78 public: 79 AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS); 80 81 void EmitDirectiveAMDGCNTarget(StringRef Target) override; 82 83 void EmitDirectiveHSACodeObjectVersion(uint32_t Major, 84 uint32_t Minor) override; 85 86 void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, 87 uint32_t Stepping, StringRef VendorName, 88 StringRef ArchName) override; 89 90 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override; 91 92 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override; 93 94 /// \returns True on success, false on failure. 95 bool EmitISAVersion(StringRef IsaVersionString) override; 96 97 /// \returns True on success, false on failure. 98 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override; 99 100 /// \returns True on success, false on failure. 101 bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override; 102 103 void EmitAmdhsaKernelDescriptor( 104 const MCSubtargetInfo &STI, StringRef KernelName, 105 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, 106 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, 107 bool ReserveXNACK) override; 108 }; 109 110 class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer { 111 MCStreamer &Streamer; 112 113 void EmitAMDGPUNote(const MCExpr *DescSize, unsigned NoteType, 114 function_ref<void(MCELFStreamer &)> EmitDesc); 115 116 public: 117 AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI); 118 119 MCELFStreamer &getStreamer(); 120 121 void EmitDirectiveAMDGCNTarget(StringRef Target) override; 122 123 void EmitDirectiveHSACodeObjectVersion(uint32_t Major, 124 uint32_t Minor) override; 125 126 void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor, 127 uint32_t Stepping, StringRef VendorName, 128 StringRef ArchName) override; 129 130 void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override; 131 132 void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override; 133 134 /// \returns True on success, false on failure. 135 bool EmitISAVersion(StringRef IsaVersionString) override; 136 137 /// \returns True on success, false on failure. 138 bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override; 139 140 /// \returns True on success, false on failure. 141 bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override; 142 143 void EmitAmdhsaKernelDescriptor( 144 const MCSubtargetInfo &STI, StringRef KernelName, 145 const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR, 146 uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr, 147 bool ReserveXNACK) override; 148 }; 149 150 } 151 #endif 152