LLVM  12.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 #include "llvm/Support/Alignment.h"
24 
25 namespace llvm {
26 
27 class AMDGPUTargetStreamer;
28 class Argument;
29 class DataLayout;
30 class Function;
31 class MachineFunction;
32 class MDNode;
33 class Module;
34 struct SIProgramInfo;
35 class Type;
36 
37 namespace AMDGPU {
38 namespace HSAMD {
39 
41 public:
42  virtual ~MetadataStreamer(){};
43 
44  virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
45 
46  virtual void begin(const Module &Mod) = 0;
47 
48  virtual void end() = 0;
49 
50  virtual void emitKernel(const MachineFunction &MF,
51  const SIProgramInfo &ProgramInfo) = 0;
52 };
53 
54 class MetadataStreamerV3 final : public MetadataStreamer {
55 private:
56  std::unique_ptr<msgpack::Document> HSAMetadataDoc =
57  std::make_unique<msgpack::Document>();
58 
59  void dump(StringRef HSAMetadataString) const;
60 
61  void verify(StringRef HSAMetadataString) const;
62 
63  Optional<StringRef> getAccessQualifier(StringRef AccQual) const;
64 
65  Optional<StringRef> getAddressSpaceQualifier(unsigned AddressSpace) const;
66 
67  StringRef getValueKind(Type *Ty, StringRef TypeQual,
68  StringRef BaseTypeName) const;
69 
70  std::string getTypeName(Type *Ty, bool Signed) const;
71 
72  msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
73 
74  msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
75  const SIProgramInfo &ProgramInfo) const;
76 
77  void emitVersion();
78 
79  void emitPrintf(const Module &Mod);
80 
81  void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
82 
83  void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
84 
85  void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
86 
87  void emitKernelArg(const Argument &Arg, unsigned &Offset,
89 
90  void emitKernelArg(const DataLayout &DL, Type *Ty, StringRef ValueKind,
91  unsigned &Offset, msgpack::ArrayDocNode Args,
93  StringRef TypeName = "", StringRef BaseTypeName = "",
94  StringRef AccQual = "", StringRef TypeQual = "");
95 
96  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
98 
99  msgpack::DocNode &getRootMetadata(StringRef Key) {
100  return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
101  }
102 
103  msgpack::DocNode &getHSAMetadataRoot() {
104  return HSAMetadataDoc->getRoot();
105  }
106 
107 public:
108  MetadataStreamerV3() = default;
109  ~MetadataStreamerV3() = default;
110 
111  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
112 
113  void begin(const Module &Mod) override;
114 
115  void end() override;
116 
117  void emitKernel(const MachineFunction &MF,
118  const SIProgramInfo &ProgramInfo) override;
119 };
120 
121 class MetadataStreamerV2 final : public MetadataStreamer {
122 private:
123  Metadata HSAMetadata;
124 
125  void dump(StringRef HSAMetadataString) const;
126 
127  void verify(StringRef HSAMetadataString) const;
128 
129  AccessQualifier getAccessQualifier(StringRef AccQual) const;
130 
131  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
132 
133  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
134  StringRef BaseTypeName) const;
135 
136  std::string getTypeName(Type *Ty, bool Signed) const;
137 
138  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
139 
140  Kernel::CodeProps::Metadata getHSACodeProps(
141  const MachineFunction &MF,
142  const SIProgramInfo &ProgramInfo) const;
143  Kernel::DebugProps::Metadata getHSADebugProps(
144  const MachineFunction &MF,
145  const SIProgramInfo &ProgramInfo) const;
146 
147  void emitVersion();
148 
149  void emitPrintf(const Module &Mod);
150 
151  void emitKernelLanguage(const Function &Func);
152 
153  void emitKernelAttrs(const Function &Func);
154 
155  void emitKernelArgs(const Function &Func);
156 
157  void emitKernelArg(const Argument &Arg);
158 
159  void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
161  StringRef TypeName = "", StringRef BaseTypeName = "",
162  StringRef AccQual = "", StringRef TypeQual = "");
163 
164  void emitHiddenKernelArgs(const Function &Func);
165 
166  const Metadata &getHSAMetadata() const {
167  return HSAMetadata;
168  }
169 
170 public:
171  MetadataStreamerV2() = default;
172  ~MetadataStreamerV2() = default;
173 
174  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
175 
176  void begin(const Module &Mod) override;
177 
178  void end() override;
179 
180  void emitKernel(const MachineFunction &MF,
181  const SIProgramInfo &ProgramInfo) override;
182 };
183 
184 } // end namespace HSAMD
185 } // end namespace AMDGPU
186 } // end namespace llvm
187 
188 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
const NoneType None
Definition: None.h:23
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.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
Definition: Alignment.h:119
AddressSpace
Definition: NVPTXBaseInfo.h:21
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
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL