LLVM  11.0.0git
AMDGPUHSAMetadataStreamer.h
Go to the documentation of this file.
1 //===--- AMDGPUHSAMetadataStreamer.h ----------------------------*- 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 /// \file
10 /// AMDGPU HSA Metadata Streamer.
11 ///
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
16 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
17 
18 #include "AMDGPU.h"
19 #include "AMDKernelCodeT.h"
20 #include "llvm/ADT/StringRef.h"
23 
24 namespace llvm {
25 
26 class AMDGPUTargetStreamer;
27 class Argument;
28 class DataLayout;
29 class Function;
30 class MachineFunction;
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::unique_ptr<msgpack::Document> HSAMetadataDoc =
56  std::make_unique<msgpack::Document>();
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  msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
74 
75  msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
76  const SIProgramInfo &ProgramInfo) const;
77 
78  void emitVersion();
79 
80  void emitPrintf(const Module &Mod);
81 
82  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
83 
84  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
85 
86  void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
87 
88  void emitKernelArg(const Argument &Arg, unsigned &Offset,
90 
91  void emitKernelArg(const DataLayout &DL, Type *Ty, StringRef ValueKind,
92  unsigned &Offset, msgpack::ArrayDocNode Args,
93  unsigned PointeeAlign = 0, StringRef Name = "",
94  StringRef TypeName = "", StringRef BaseTypeName = "",
95  StringRef AccQual = "", StringRef TypeQual = "");
96 
97  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
99 
100  msgpack::DocNode &getRootMetadata(StringRef Key) {
101  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
102  }
103 
104  msgpack::DocNode &getHSAMetadataRoot() {
105  return HSAMetadataDoc->getRoot();
106  }
107 
108 public:
109  MetadataStreamerV3() = default;
110  ~MetadataStreamerV3() = default;
111 
112  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
113 
114  void begin(const Module &Mod) override;
115 
116  void end() override;
117 
118  void emitKernel(const MachineFunction &MF,
119  const SIProgramInfo &ProgramInfo) override;
120 };
121 
122 class MetadataStreamerV2 final : public MetadataStreamer {
123 private:
124  Metadata HSAMetadata;
125 
126  void dump(StringRef HSAMetadataString) const;
127 
128  void verify(StringRef HSAMetadataString) const;
129 
130  AccessQualifier getAccessQualifier(StringRef AccQual) const;
131 
132  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
133 
134  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
135  StringRef BaseTypeName) const;
136 
137  ValueType getValueType(Type *Ty, StringRef TypeName) const;
138 
139  std::string getTypeName(Type *Ty, bool Signed) const;
140 
141  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
142 
143  Kernel::CodeProps::Metadata getHSACodeProps(
144  const MachineFunction &MF,
145  const SIProgramInfo &ProgramInfo) const;
146  Kernel::DebugProps::Metadata getHSADebugProps(
147  const MachineFunction &MF,
148  const SIProgramInfo &ProgramInfo) const;
149 
150  void emitVersion();
151 
152  void emitPrintf(const Module &Mod);
153 
154  void emitKernelLanguage(const Function &Func);
155 
156  void emitKernelAttrs(const Function &Func);
157 
158  void emitKernelArgs(const Function &Func);
159 
160  void emitKernelArg(const Argument &Arg);
161 
162  void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
163  unsigned PointeeAlign = 0,
164  StringRef Name = "", StringRef TypeName = "",
165  StringRef BaseTypeName = "", StringRef AccQual = "",
166  StringRef TypeQual = "");
167 
168  void emitHiddenKernelArgs(const Function &Func);
169 
170  const Metadata &getHSAMetadata() const {
171  return HSAMetadata;
172  }
173 
174 public:
175  MetadataStreamerV2() = default;
176  ~MetadataStreamerV2() = default;
177 
178  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
179 
180  void begin(const Module &Mod) override;
181 
182  void end() override;
183 
184  void emitKernel(const MachineFunction &MF,
185  const SIProgramInfo &ProgramInfo) override;
186 };
187 
188 } // end namespace HSAMD
189 } // end namespace AMDGPU
190 } // end namespace llvm
191 
192 #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
This class represents an incoming formal argument to a Function.
Definition: Argument.h:29
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
Machine Debugify Module
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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:27
Metadata node.
Definition: Metadata.h:870
static void emitVersion(raw_ostream &OS)
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:21
A DocNode that is an array.
In-memory representation of kernel debug properties metadata.
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
MapDocNode & getMap(bool Convert=false)
Get a MapDocNode for a map node.
Key
PAL metadata keys.
virtual void begin(const Module &Mod)=0
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.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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:21
ValueType
Value types.
The access may modify the value stored in memory.
A DocNode that is a map.
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:57
AMDGPU metadata definitions and in-memory representations.
A node in a MsgPack Document.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0