[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / AMDGPU / AMDGPUHSAMetadataStreamer.h
blob80ac8ca67bcd1eddd251e44b1e06e039201ec698
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 ///
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
16 #define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
18 #include "AMDGPU.h"
19 #include "AMDKernelCodeT.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/BinaryFormat/MsgPackDocument.h"
22 #include "llvm/Support/AMDGPUMetadata.h"
24 namespace llvm {
26 class AMDGPUTargetStreamer;
27 class Argument;
28 class DataLayout;
29 class Function;
30 class MDNode;
31 class Module;
32 struct SIProgramInfo;
33 class Type;
35 namespace AMDGPU {
36 namespace HSAMD {
38 class MetadataStreamer {
39 public:
40 virtual ~MetadataStreamer(){};
42 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
44 virtual void begin(const Module &Mod) = 0;
46 virtual void end() = 0;
48 virtual void emitKernel(const MachineFunction &MF,
49 const SIProgramInfo &ProgramInfo) = 0;
52 class MetadataStreamerV3 final : public MetadataStreamer {
53 private:
54 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
55 std::make_unique<msgpack::Document>();
57 void dump(StringRef HSAMetadataString) const;
59 void verify(StringRef HSAMetadataString) const;
61 Optional<StringRef> getAccessQualifier(StringRef AccQual) const;
63 Optional<StringRef> getAddressSpaceQualifier(unsigned AddressSpace) const;
65 StringRef getValueKind(Type *Ty, StringRef TypeQual,
66 StringRef BaseTypeName) const;
68 StringRef getValueType(Type *Ty, StringRef TypeName) const;
70 std::string getTypeName(Type *Ty, bool Signed) const;
72 msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
74 msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
75 const SIProgramInfo &ProgramInfo) const;
77 void emitVersion();
79 void emitPrintf(const Module &Mod);
81 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
83 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
85 void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
87 void emitKernelArg(const Argument &Arg, unsigned &Offset,
88 msgpack::ArrayDocNode Args);
90 void emitKernelArg(const DataLayout &DL, Type *Ty, StringRef ValueKind,
91 unsigned &Offset, msgpack::ArrayDocNode Args,
92 unsigned PointeeAlign = 0, StringRef Name = "",
93 StringRef TypeName = "", StringRef BaseTypeName = "",
94 StringRef AccQual = "", StringRef TypeQual = "");
96 void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
97 msgpack::ArrayDocNode Args);
99 msgpack::DocNode &getRootMetadata(StringRef Key) {
100 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
103 msgpack::DocNode &getHSAMetadataRoot() {
104 return HSAMetadataDoc->getRoot();
107 public:
108 MetadataStreamerV3() = default;
109 ~MetadataStreamerV3() = default;
111 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
113 void begin(const Module &Mod) override;
115 void end() override;
117 void emitKernel(const MachineFunction &MF,
118 const SIProgramInfo &ProgramInfo) override;
121 class MetadataStreamerV2 final : public MetadataStreamer {
122 private:
123 Metadata HSAMetadata;
125 void dump(StringRef HSAMetadataString) const;
127 void verify(StringRef HSAMetadataString) const;
129 AccessQualifier getAccessQualifier(StringRef AccQual) const;
131 AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
133 ValueKind getValueKind(Type *Ty, StringRef TypeQual,
134 StringRef BaseTypeName) const;
136 ValueType getValueType(Type *Ty, StringRef TypeName) const;
138 std::string getTypeName(Type *Ty, bool Signed) const;
140 std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
142 Kernel::CodeProps::Metadata getHSACodeProps(
143 const MachineFunction &MF,
144 const SIProgramInfo &ProgramInfo) const;
145 Kernel::DebugProps::Metadata getHSADebugProps(
146 const MachineFunction &MF,
147 const SIProgramInfo &ProgramInfo) const;
149 void emitVersion();
151 void emitPrintf(const Module &Mod);
153 void emitKernelLanguage(const Function &Func);
155 void emitKernelAttrs(const Function &Func);
157 void emitKernelArgs(const Function &Func);
159 void emitKernelArg(const Argument &Arg);
161 void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
162 unsigned PointeeAlign = 0,
163 StringRef Name = "", StringRef TypeName = "",
164 StringRef BaseTypeName = "", StringRef AccQual = "",
165 StringRef TypeQual = "");
167 void emitHiddenKernelArgs(const Function &Func);
169 const Metadata &getHSAMetadata() const {
170 return HSAMetadata;
173 public:
174 MetadataStreamerV2() = default;
175 ~MetadataStreamerV2() = default;
177 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
179 void begin(const Module &Mod) override;
181 void end() override;
183 void emitKernel(const MachineFunction &MF,
184 const SIProgramInfo &ProgramInfo) override;
187 } // end namespace HSAMD
188 } // end namespace AMDGPU
189 } // end namespace llvm
191 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H