LLVM  9.0.0svn
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 MDNode;
31 class Module;
32 struct SIProgramInfo;
33 class Type;
34 
35 namespace AMDGPU {
36 namespace HSAMD {
37 
39 public:
40  virtual ~MetadataStreamer(){};
41 
42  virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
43 
44  virtual void begin(const Module &Mod) = 0;
45 
46  virtual void end() = 0;
47 
48  virtual void emitKernel(const MachineFunction &MF,
49  const SIProgramInfo &ProgramInfo) = 0;
50 };
51 
52 class MetadataStreamerV3 final : public MetadataStreamer {
53 private:
54  std::shared_ptr<msgpack::Node> HSAMetadataRoot =
55  std::make_shared<msgpack::MapNode>();
56 
57  void dump(StringRef HSAMetadataString) const;
58 
59  void verify(StringRef HSAMetadataString) const;
60 
61  Optional<StringRef> getAccessQualifier(StringRef AccQual) const;
62 
63  Optional<StringRef> getAddressSpaceQualifier(unsigned AddressSpace) const;
64 
65  StringRef getValueKind(Type *Ty, StringRef TypeQual,
66  StringRef BaseTypeName) const;
67 
68  StringRef getValueType(Type *Ty, StringRef TypeName) const;
69 
70  std::string getTypeName(Type *Ty, bool Signed) const;
71 
72  std::shared_ptr<msgpack::ArrayNode>
73  getWorkGroupDimensions(MDNode *Node) const;
74 
75  std::shared_ptr<msgpack::MapNode>
76  getHSAKernelProps(const MachineFunction &MF,
77  const SIProgramInfo &ProgramInfo) const;
78 
79  void emitVersion();
80 
81  void emitPrintf(const Module &Mod);
82 
83  void emitKernelLanguage(const Function &Func, msgpack::MapNode &Kern);
84 
85  void emitKernelAttrs(const Function &Func, msgpack::MapNode &Kern);
86 
87  void emitKernelArgs(const Function &Func, msgpack::MapNode &Kern);
88 
89  void emitKernelArg(const Argument &Arg, unsigned &Offset,
91 
92  void emitKernelArg(const DataLayout &DL, Type *Ty, StringRef ValueKind,
93  unsigned &Offset, msgpack::ArrayNode &Args,
94  unsigned PointeeAlign = 0, StringRef Name = "",
95  StringRef TypeName = "", StringRef BaseTypeName = "",
96  StringRef AccQual = "", StringRef TypeQual = "");
97 
98  void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
99  msgpack::ArrayNode &Args);
100 
101  std::shared_ptr<msgpack::Node> &getRootMetadata(StringRef Key) {
102  return (*cast<msgpack::MapNode>(HSAMetadataRoot.get()))[Key];
103  }
104 
105  std::shared_ptr<msgpack::Node> &getHSAMetadataRoot() {
106  return HSAMetadataRoot;
107  }
108 
109 public:
110  MetadataStreamerV3() = default;
111  ~MetadataStreamerV3() = default;
112 
113  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
114 
115  void begin(const Module &Mod) override;
116 
117  void end() override;
118 
119  void emitKernel(const MachineFunction &MF,
120  const SIProgramInfo &ProgramInfo) override;
121 };
122 
123 class MetadataStreamerV2 final : public MetadataStreamer {
124 private:
125  Metadata HSAMetadata;
126 
127  void dump(StringRef HSAMetadataString) const;
128 
129  void verify(StringRef HSAMetadataString) const;
130 
131  AccessQualifier getAccessQualifier(StringRef AccQual) const;
132 
133  AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
134 
135  ValueKind getValueKind(Type *Ty, StringRef TypeQual,
136  StringRef BaseTypeName) const;
137 
138  ValueType getValueType(Type *Ty, StringRef TypeName) const;
139 
140  std::string getTypeName(Type *Ty, bool Signed) const;
141 
142  std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
143 
144  Kernel::CodeProps::Metadata getHSACodeProps(
145  const MachineFunction &MF,
146  const SIProgramInfo &ProgramInfo) const;
147  Kernel::DebugProps::Metadata getHSADebugProps(
148  const MachineFunction &MF,
149  const SIProgramInfo &ProgramInfo) const;
150 
151  void emitVersion();
152 
153  void emitPrintf(const Module &Mod);
154 
155  void emitKernelLanguage(const Function &Func);
156 
157  void emitKernelAttrs(const Function &Func);
158 
159  void emitKernelArgs(const Function &Func);
160 
161  void emitKernelArg(const Argument &Arg);
162 
163  void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
164  unsigned PointeeAlign = 0,
165  StringRef Name = "", StringRef TypeName = "",
166  StringRef BaseTypeName = "", StringRef AccQual = "",
167  StringRef TypeQual = "");
168 
169  void emitHiddenKernelArgs(const Function &Func);
170 
171  const Metadata &getHSAMetadata() const {
172  return HSAMetadata;
173  }
174 
175 public:
176  MetadataStreamerV2() = default;
177  ~MetadataStreamerV2() = default;
178 
179  bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
180 
181  void begin(const Module &Mod) override;
182 
183  void end() override;
184 
185  void emitKernel(const MachineFunction &MF,
186  const SIProgramInfo &ProgramInfo) override;
187 };
188 
189 } // end namespace HSAMD
190 } // end namespace AMDGPU
191 } // end namespace llvm
192 
193 #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:110
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:48
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:64
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:863
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:21
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:45
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.
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:48
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