Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUTargetStreamer.h
Line
Count
Source
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 "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"
19
20
namespace llvm {
21
#include "AMDGPUPTNote.h"
22
23
class DataLayout;
24
class Function;
25
class MCELFStreamer;
26
class MCSymbol;
27
class MDNode;
28
class Module;
29
class Type;
30
31
class AMDGPUTargetStreamer : public MCTargetStreamer {
32
  AMDGPUPALMetadata PALMetadata;
33
34
protected:
35
267
  MCContext &getContext() const { return Streamer.getContext(); }
36
37
public:
38
3.01k
  AMDGPUTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
39
40
3.45k
  AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
41
42
  virtual void EmitDirectiveAMDGCNTarget(StringRef Target) = 0;
43
44
  virtual void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
45
                                                 uint32_t Minor) = 0;
46
47
  virtual void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
48
                                             uint32_t Stepping,
49
                                             StringRef VendorName,
50
                                             StringRef ArchName) = 0;
51
52
  virtual void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) = 0;
53
54
  virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) = 0;
55
56
  virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size,
57
                             unsigned Align) = 0;
58
59
  /// \returns True on success, false on failure.
60
  virtual bool EmitISAVersion(StringRef IsaVersionString) = 0;
61
62
  /// \returns True on success, false on failure.
63
  virtual bool EmitHSAMetadataV2(StringRef HSAMetadataString);
64
65
  /// \returns True on success, false on failure.
66
  virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
67
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;
76
77
  /// \returns True on success, false on failure.
78
  virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) = 0;
79
80
  /// \returns True on success, false on failure.
81
  virtual bool EmitCodeEnd() = 0;
82
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;
88
89
  static StringRef getArchNameFromElfMach(unsigned ElfMach);
90
  static unsigned getElfMach(StringRef GPU);
91
};
92
93
class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer {
94
  formatted_raw_ostream &OS;
95
public:
96
  AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
97
98
  void finish() override;
99
100
  void EmitDirectiveAMDGCNTarget(StringRef Target) override;
101
102
  void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
103
                                         uint32_t Minor) override;
104
105
  void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
106
                                     uint32_t Stepping, StringRef VendorName,
107
                                     StringRef ArchName) override;
108
109
  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
110
111
  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
112
113
  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override;
114
115
  /// \returns True on success, false on failure.
116
  bool EmitISAVersion(StringRef IsaVersionString) override;
117
118
  /// \returns True on success, false on failure.
119
  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
120
121
  /// \returns True on success, false on failure.
122
  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
123
124
  /// \returns True on success, false on failure.
125
  bool EmitCodeEnd() override;
126
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;
132
};
133
134
class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer {
135
  MCStreamer &Streamer;
136
137
  void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
138
                function_ref<void(MCELFStreamer &)> EmitDesc);
139
140
public:
141
  AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
142
143
  MCELFStreamer &getStreamer();
144
145
  void finish() override;
146
147
  void EmitDirectiveAMDGCNTarget(StringRef Target) override;
148
149
  void EmitDirectiveHSACodeObjectVersion(uint32_t Major,
150
                                         uint32_t Minor) override;
151
152
  void EmitDirectiveHSACodeObjectISA(uint32_t Major, uint32_t Minor,
153
                                     uint32_t Stepping, StringRef VendorName,
154
                                     StringRef ArchName) override;
155
156
  void EmitAMDKernelCodeT(const amd_kernel_code_t &Header) override;
157
158
  void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
159
160
  void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, unsigned Align) override;
161
162
  /// \returns True on success, false on failure.
163
  bool EmitISAVersion(StringRef IsaVersionString) override;
164
165
  /// \returns True on success, false on failure.
166
  bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
167
168
  /// \returns True on success, false on failure.
169
  bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) override;
170
171
  /// \returns True on success, false on failure.
172
  bool EmitCodeEnd() override;
173
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;
179
};
180
181
}
182
#endif