LLVM  8.0.1
AMDGPUHSAMetadataStreamer.h
Go to the documentation of this file.
1 //===--- AMDGPUHSAMetadataStreamer.h ----------------------------*- 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 /// \file
11 /// AMDGPU HSA Metadata Streamer.
12 ///
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
17 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
18 
19 #include "AMDGPU.h"
20 #include "AMDKernelCodeT.h"
21 #include "llvm/ADT/StringRef.h"
24 
25 namespace llvm {
26 
27 class AMDGPUTargetStreamer;
28 class Argument;
29 class DataLayout;
30 class Function;
31 class MDNode;
32 class Module;
33 struct SIProgramInfo;
34 class Type;
35 
36 namespace AMDGPU {
37 namespace HSAMD {
38 
40 public:
41  virtual ~MetadataStreamer(){};
42 
43  virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
44 
45  virtual void begin(const Module &Mod) = 0;
46 
47  virtual void end() = 0;
48 
49  virtual void emitKernel(const MachineFunction &MF,
50  const SIProgramInfo &ProgramInfo) = 0;
51 };
52 
53 class MetadataStreamerV3 final : public MetadataStreamer {
54 private:
55  std::shared_ptr<msgpack::Node> HSAMetadataRoot =
56  std::make_shared<msgpack::MapNode>();
57 
58  void dump(StringRef HSAMetadataString) const;
59 
60  void verify(StringRef HSAMetadataString) const;
61 
62  Optional<StringRef> getAccessQualifier(StringRef AccQual) const;
63 
64  Optional<StringRef> getAddressSpaceQualifier(unsigned AddressSpace) const;
65 
66  StringRef getValueKind(Type *Ty, StringRef TypeQual,
67  StringRef BaseTypeName) const;
68 
69  StringRef getValueType(Type *Ty, StringRef TypeName) const;
70 
71  std::string getTypeName(Type *Ty, bool Signed) const;
72 
73  std::shared_ptr<msgpack::ArrayNode>
74  getWorkGroupDimensions(MDNode *Node) const;
75 
76  std::shared_ptr<msgpack::MapNode>
77  getHSAKernelProps(const MachineFunction &MF,
78  const SIProgramInfo &ProgramInfo) const;
79 
80  void emitVersion();
81 
82  void emitPrintf(const Module &Mod);
83 
84  void emitKernelLanguage(const Function &Func, msgpack::MapNode &Kern);
85 
86  void emitKernelAttrs(const Function &Func, msgpack::MapNode &Kern);
87 
88  void emitKernelArgs(const Function &Func, msgpack::MapNode &Kern);
89 
90  void emitKernelArg(const Argument &Arg, unsigned &Offset,
92 
93  void emitKernelArg(const DataLayout &DL, Type *Ty, StringRef ValueKind,
94  unsigned &Offset, msgpack::ArrayNode &Args,
95  unsigned PointeeAlign = 0, StringRef Name = "",
96  StringRef TypeName = "", StringRef BaseTypeName = "",
97  StringRef AccQual = "", StringRef TypeQual = "");
98 
99  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
100  msgpack::ArrayNode &Args);
101 
102  std::shared_ptr<msgpack::Node> &getRootMetadata(StringRef Key) {
103  return (*cast<msgpack::MapNode>(HSAMetadataRoot.get()))[Key];
104  }
105 
106  std::shared_ptr<msgpack::Node> &getHSAMetadataRoot() {
107  return HSAMetadataRoot;
108  }
109 
110 public:
111  MetadataStreamerV3() = default;
112  ~MetadataStreamerV3() = default;
113 
114  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
115 
116  void begin(const Module &Mod) override;
117 
118  void end() override;
119 
120  void emitKernel(const MachineFunction &MF,
121  const SIProgramInfo &ProgramInfo) override;
122 };
123 
124 class MetadataStreamerV2 final : public MetadataStreamer {
125 private:
126  Metadata HSAMetadata;
127 
128  void dump(StringRef HSAMetadataString) const;
129 
130  void verify(StringRef HSAMetadataString) const;
131 
132  AccessQualifier getAccessQualifier(StringRef AccQual) const;
133 
134  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
135 
136  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
137  StringRef BaseTypeName) const;
138 
139  ValueType getValueType(Type *Ty, StringRef TypeName) const;
140 
141  std::string getTypeName(Type *Ty, bool Signed) const;
142 
143  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
144 
145  Kernel::CodeProps::Metadata getHSACodeProps(
146  const MachineFunction &MF,
147  const SIProgramInfo &ProgramInfo) const;
148  Kernel::DebugProps::Metadata getHSADebugProps(
149  const MachineFunction &MF,
150  const SIProgramInfo &ProgramInfo) const;
151 
152  void emitVersion();
153 
154  void emitPrintf(const Module &Mod);
155 
156  void emitKernelLanguage(const Function &Func);
157 
158  void emitKernelAttrs(const Function &Func);
159 
160  void emitKernelArgs(const Function &Func);
161 
162  void emitKernelArg(const Argument &Arg);
163 
164  void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
165  unsigned PointeeAlign = 0,
166  StringRef Name = "", StringRef TypeName = "",
167  StringRef BaseTypeName = "", StringRef AccQual = "",
168  StringRef TypeQual = "");
169 
170  void emitHiddenKernelArgs(const Function &Func);
171 
172  const Metadata &getHSAMetadata() const {
173  return HSAMetadata;
174  }
175 
176 public:
177  MetadataStreamerV2() = default;
178  ~MetadataStreamerV2() = default;
179 
180  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
181 
182  void begin(const Module &Mod) override;
183 
184  void end() override;
185 
186  void emitKernel(const MachineFunction &MF,
187  const SIProgramInfo &ProgramInfo) override;
188 };
189 
190 } // end namespace HSAMD
191 } // end namespace AMDGPU
192 } // end namespace llvm
193 
194 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
In-memory representation of HSA metadata.
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:111
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:49
This class represents an incoming formal argument to a Function.
Definition: Argument.h:30
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
Definition: TypeName.h:28
Metadata node.
Definition: Metadata.h:864
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:22
amdgpu Simplify well known AMD library false Value Value const Twine & Name
In-memory representation of kernel debug properties metadata.
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
Key
PAL metadata keys.
virtual void begin(const Module &Mod)=0
This is a data structure for representing MessagePack "documents", with methods to go to and from Mes...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
ValueKind
Value kinds.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
AccessQualifier
Access qualifiers.
AddressSpace
Definition: NVPTXBaseInfo.h:22
ValueType
Value types.
The access may modify the value stored in memory.
amdgpu Simplify well known AMD library false Value Value * Arg
AddressSpaceQualifier
Address space qualifiers.
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
In-memory representation of kernel code properties metadata.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
AMDGPU metadata definitions and in-memory representations.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0