Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Target / AMDGPU / AMDGPUHSAMetadataStreamer.h
blobfd76666dc360bea9115012f72996eebdc8abdbcc
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 "Utils/AMDGPUDelayedMCExpr.h"
19 #include "llvm/BinaryFormat/MsgPackDocument.h"
20 #include "llvm/Support/AMDGPUMetadata.h"
21 #include "llvm/Support/Alignment.h"
22 #include "llvm/Support/Compiler.h"
24 namespace llvm {
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;
36 namespace AMDGPU {
38 namespace IsaInfo {
39 class AMDGPUTargetID;
42 namespace HSAMD {
44 class MetadataStreamer {
45 public:
46 virtual ~MetadataStreamer() = default;
48 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
50 virtual void begin(const Module &Mod,
51 const IsaInfo::AMDGPUTargetID &TargetID) = 0;
53 virtual void end() = 0;
55 virtual void emitKernel(const MachineFunction &MF,
56 const SIProgramInfo &ProgramInfo) = 0;
58 protected:
59 virtual void emitVersion() = 0;
60 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
61 msgpack::ArrayDocNode Args) = 0;
62 virtual void emitKernelAttrs(const Function &Func,
63 msgpack::MapDocNode Kern) = 0;
66 class LLVM_EXTERNAL_VISIBILITY MetadataStreamerMsgPackV4
67 : public MetadataStreamer {
68 protected:
69 std::unique_ptr<DelayedMCExprs> DelayedExprs =
70 std::make_unique<DelayedMCExprs>();
72 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
73 std::make_unique<msgpack::Document>();
75 void dump(StringRef HSAMetadataString) const;
77 void verify(StringRef HSAMetadataString) const;
79 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
81 std::optional<StringRef>
82 getAddressSpaceQualifier(unsigned AddressSpace) const;
84 StringRef getValueKind(Type *Ty, StringRef TypeQual,
85 StringRef BaseTypeName) const;
87 std::string getTypeName(Type *Ty, bool Signed) const;
89 msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
91 msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
92 const SIProgramInfo &ProgramInfo,
93 unsigned CodeObjectVersion) const;
95 void emitVersion() override;
97 void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
99 void emitPrintf(const Module &Mod);
101 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
103 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
105 void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern);
107 void emitKernelArg(const Argument &Arg, unsigned &Offset,
108 msgpack::ArrayDocNode Args);
110 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
111 StringRef ValueKind, unsigned &Offset,
112 msgpack::ArrayDocNode Args,
113 MaybeAlign PointeeAlign = std::nullopt,
114 StringRef Name = "", StringRef TypeName = "",
115 StringRef BaseTypeName = "", StringRef ActAccQual = "",
116 StringRef AccQual = "", StringRef TypeQual = "");
118 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
119 msgpack::ArrayDocNode Args) override;
121 msgpack::DocNode &getRootMetadata(StringRef Key) {
122 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
125 msgpack::DocNode &getHSAMetadataRoot() {
126 return HSAMetadataDoc->getRoot();
129 public:
130 MetadataStreamerMsgPackV4() = default;
131 ~MetadataStreamerMsgPackV4() = default;
133 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
135 void begin(const Module &Mod,
136 const IsaInfo::AMDGPUTargetID &TargetID) override;
138 void end() override;
140 void emitKernel(const MachineFunction &MF,
141 const SIProgramInfo &ProgramInfo) override;
144 class MetadataStreamerMsgPackV5 : public MetadataStreamerMsgPackV4 {
145 protected:
146 void emitVersion() override;
147 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
148 msgpack::ArrayDocNode Args) override;
149 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
151 public:
152 MetadataStreamerMsgPackV5() = default;
153 ~MetadataStreamerMsgPackV5() = default;
156 class MetadataStreamerMsgPackV6 final : public MetadataStreamerMsgPackV5 {
157 protected:
158 void emitVersion() override;
160 public:
161 MetadataStreamerMsgPackV6() = default;
162 ~MetadataStreamerMsgPackV6() = default;
165 } // end namespace HSAMD
166 } // end namespace AMDGPU
167 } // end namespace llvm
169 #endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H