2015-06-27 05:15:07 +08:00
|
|
|
//===-- AMDGPUTargetStreamer.h - AMDGPU Target Streamer --------*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-11 16:00:27 +08:00
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
|
2015-08-16 15:55:08 +08:00
|
|
|
|
2015-06-27 05:58:31 +08:00
|
|
|
#include "AMDKernelCodeT.h"
|
2018-12-13 03:39:27 +08:00
|
|
|
#include "llvm/BinaryFormat/MsgPackTypes.h"
|
2015-06-27 05:15:07 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2017-10-14 23:40:33 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2017-10-12 06:59:35 +08:00
|
|
|
#include "llvm/Support/AMDGPUMetadata.h"
|
2018-06-13 02:02:46 +08:00
|
|
|
#include "llvm/Support/AMDHSAKernelDescriptor.h"
|
2016-03-11 16:00:27 +08:00
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
namespace llvm {
|
2016-12-19 19:43:15 +08:00
|
|
|
#include "AMDGPUPTNote.h"
|
2015-06-27 05:15:07 +08:00
|
|
|
|
2016-11-11 05:18:49 +08:00
|
|
|
class DataLayout;
|
|
|
|
class Function;
|
2015-06-27 05:15:07 +08:00
|
|
|
class MCELFStreamer;
|
2016-03-11 16:00:27 +08:00
|
|
|
class MCSymbol;
|
2016-11-11 05:18:49 +08:00
|
|
|
class MDNode;
|
|
|
|
class Module;
|
|
|
|
class Type;
|
2015-06-27 05:15:07 +08:00
|
|
|
|
|
|
|
class AMDGPUTargetStreamer : public MCTargetStreamer {
|
2016-12-19 19:43:15 +08:00
|
|
|
protected:
|
|
|
|
MCContext &getContext() const { return Streamer.getContext(); }
|
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
public:
|
2017-10-14 23:40:33 +08:00
|
|
|
AMDGPUTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
|
|
|
|
|
2018-06-22 03:38:56 +08:00
|
|
|
virtual void EmitDirectiveAMDGCNTarget(StringRef Target) = 0;
|
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
|
|
|
|
uint32_t Minor) = 0;
|
|
|
|
|
|
|
|
virtual void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
|
|
|
|
uint32_t Stepping,
|
|
|
|
StringRef VendorName,
|
|
|
|
StringRef ArchName) = 0;
|
2015-06-27 05:58:31 +08:00
|
|
|
|
|
|
|
virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
|
2015-11-06 19:45:14 +08:00
|
|
|
|
|
|
|
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
|
2015-12-03 03:47:57 +08:00
|
|
|
|
2017-10-14 23:40:33 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
virtual bool EmitISAVersion(StringRef IsaVersionString) = 0;
|
|
|
|
|
2017-10-12 06:59:35 +08:00
|
|
|
/// \returns True on success, false on failure.
|
2018-12-13 03:39:27 +08:00
|
|
|
virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
|
|
|
|
|
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
|
|
|
|
|
|
|
|
/// Emit HSA Metadata
|
|
|
|
///
|
|
|
|
/// When \p Strict is true, known metadata elements must already be
|
|
|
|
/// well-typed. When \p Strict is false, known types are inferred and
|
|
|
|
/// the \p HSAMetadata structure is updated with the correct types.
|
|
|
|
///
|
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
virtual bool EmitHSAMetadata(std::shared_ptr<msgpack::Node> &HSAMetadata,
|
|
|
|
bool Strict) = 0;
|
2017-03-23 06:32:22 +08:00
|
|
|
|
|
|
|
/// \returns True on success, false on failure.
|
2017-10-12 06:59:35 +08:00
|
|
|
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
|
2017-10-04 03:03:52 +08:00
|
|
|
|
2017-10-12 06:41:09 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
virtual bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) = 0;
|
2018-06-13 02:02:46 +08:00
|
|
|
|
|
|
|
virtual void EmitAmdhsaKernelDescriptor(
|
2018-06-22 03:38:56 +08:00
|
|
|
const MCSubtargetInfo &STI, StringRef KernelName,
|
|
|
|
const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
|
|
|
|
uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
|
|
|
|
bool ReserveXNACK) = 0;
|
2018-09-13 02:50:47 +08:00
|
|
|
|
|
|
|
static StringRef getArchNameFromElfMach(unsigned ElfMach);
|
|
|
|
static unsigned getElfMach(StringRef GPU);
|
2015-06-27 05:15:07 +08:00
|
|
|
};
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer {
|
2015-06-27 05:15:07 +08:00
|
|
|
formatted_raw_ostream &OS;
|
|
|
|
public:
|
|
|
|
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
|
2018-06-22 03:38:56 +08:00
|
|
|
|
|
|
|
void EmitDirectiveAMDGCNTarget(StringRef Target) override;
|
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
|
|
|
|
uint32_t Minor) override;
|
|
|
|
|
|
|
|
void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
|
|
|
|
uint32_t Stepping, StringRef VendorName,
|
|
|
|
StringRef ArchName) override;
|
2015-06-27 05:58:31 +08:00
|
|
|
|
|
|
|
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
|
2015-11-06 19:45:14 +08:00
|
|
|
|
|
|
|
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
2015-12-03 03:47:57 +08:00
|
|
|
|
2017-10-14 23:40:33 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitISAVersion(StringRef IsaVersionString) override;
|
|
|
|
|
2018-12-13 03:39:27 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitHSAMetadata(std::shared_ptr<msgpack::Node> &HSAMetadata,
|
|
|
|
bool Strict) override;
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
/// \returns True on success, false on failure.
|
2017-10-12 06:59:35 +08:00
|
|
|
bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
|
2017-10-04 03:03:52 +08:00
|
|
|
|
2017-10-12 06:41:09 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override;
|
2018-06-13 02:02:46 +08:00
|
|
|
|
|
|
|
void EmitAmdhsaKernelDescriptor(
|
2018-06-22 03:38:56 +08:00
|
|
|
const MCSubtargetInfo &STI, StringRef KernelName,
|
|
|
|
const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
|
|
|
|
uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
|
|
|
|
bool ReserveXNACK) override;
|
2015-06-27 05:15:07 +08:00
|
|
|
};
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer {
|
2015-06-27 05:15:07 +08:00
|
|
|
MCStreamer &Streamer;
|
|
|
|
|
2018-12-13 03:39:27 +08:00
|
|
|
void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
|
|
|
|
function_ref<void(MCELFStreamer &)> EmitDesc);
|
2016-12-19 19:43:15 +08:00
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
public:
|
2018-02-17 06:33:59 +08:00
|
|
|
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
|
2015-06-27 05:15:07 +08:00
|
|
|
|
|
|
|
MCELFStreamer &getStreamer();
|
|
|
|
|
2018-06-22 03:38:56 +08:00
|
|
|
void EmitDirectiveAMDGCNTarget(StringRef Target) override;
|
|
|
|
|
2015-06-27 05:15:07 +08:00
|
|
|
void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
|
|
|
|
uint32_t Minor) override;
|
|
|
|
|
|
|
|
void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
|
|
|
|
uint32_t Stepping, StringRef VendorName,
|
|
|
|
StringRef ArchName) override;
|
2015-06-27 05:58:31 +08:00
|
|
|
|
|
|
|
void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
|
|
|
|
|
2015-11-06 19:45:14 +08:00
|
|
|
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
2015-12-03 03:47:57 +08:00
|
|
|
|
2017-10-14 23:40:33 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitISAVersion(StringRef IsaVersionString) override;
|
|
|
|
|
2018-12-13 03:39:27 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitHSAMetadata(std::shared_ptr<msgpack::Node> &HSAMetadata,
|
|
|
|
bool Strict) override;
|
|
|
|
|
2017-03-23 06:32:22 +08:00
|
|
|
/// \returns True on success, false on failure.
|
2017-10-12 06:59:35 +08:00
|
|
|
bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
|
2017-10-04 03:03:52 +08:00
|
|
|
|
2017-10-12 06:41:09 +08:00
|
|
|
/// \returns True on success, false on failure.
|
|
|
|
bool EmitPALMetadata(const AMDGPU::PALMD::Metadata &PALMetadata) override;
|
2018-06-13 02:02:46 +08:00
|
|
|
|
|
|
|
void EmitAmdhsaKernelDescriptor(
|
2018-06-22 03:38:56 +08:00
|
|
|
const MCSubtargetInfo &STI, StringRef KernelName,
|
|
|
|
const amdhsa::kernel_descriptor_t &KernelDescriptor, uint64_t NextVGPR,
|
|
|
|
uint64_t NextSGPR, bool ReserveVCC, bool ReserveFlatScr,
|
|
|
|
bool ReserveXNACK) override;
|
2015-06-27 05:15:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2015-08-16 15:55:08 +08:00
|
|
|
#endif
|