LLVM 19.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
22
23namespace llvm {
24
25class AMDGPUTargetStreamer;
26class Argument;
27class DataLayout;
28class Function;
29class MachineFunction;
30class MDNode;
31class Module;
32struct SIProgramInfo;
33class Type;
34
35namespace AMDGPU {
36
37namespace IsaInfo {
38class AMDGPUTargetID;
39}
40
41namespace HSAMD {
42
44public:
45 virtual ~MetadataStreamer() = default;
46
47 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
48
49 virtual void begin(const Module &Mod,
50 const IsaInfo::AMDGPUTargetID &TargetID) = 0;
51
52 virtual void end() = 0;
53
54 virtual void emitKernel(const MachineFunction &MF,
55 const SIProgramInfo &ProgramInfo) = 0;
56
57protected:
58 virtual void emitVersion() = 0;
59 virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
60 msgpack::ArrayDocNode Args) = 0;
61 virtual void emitKernelAttrs(const Function &Func,
62 msgpack::MapDocNode Kern) = 0;
63};
64
66 : public MetadataStreamer {
67protected:
68 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
69 std::make_unique<msgpack::Document>();
70
71 void dump(StringRef HSAMetadataString) const;
72
73 void verify(StringRef HSAMetadataString) const;
74
75 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
76
77 std::optional<StringRef>
78 getAddressSpaceQualifier(unsigned AddressSpace) const;
79
80 StringRef getValueKind(Type *Ty, StringRef TypeQual,
81 StringRef BaseTypeName) const;
82
83 std::string getTypeName(Type *Ty, bool Signed) const;
84
85 msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
86
87 msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
88 const SIProgramInfo &ProgramInfo,
89 unsigned CodeObjectVersion) const;
90
91 void emitVersion() override;
92
93 void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
94
95 void emitPrintf(const Module &Mod);
96
97 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
98
99 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
100
101 void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern);
102
103 void emitKernelArg(const Argument &Arg, unsigned &Offset,
105
106 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
107 StringRef ValueKind, unsigned &Offset,
109 MaybeAlign PointeeAlign = std::nullopt,
110 StringRef Name = "", StringRef TypeName = "",
111 StringRef BaseTypeName = "", StringRef ActAccQual = "",
112 StringRef AccQual = "", StringRef TypeQual = "");
113
114 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
115 msgpack::ArrayDocNode Args) override;
116
118 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
119 }
120
122 return HSAMetadataDoc->getRoot();
123 }
124
125public:
128
129 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
130
131 void begin(const Module &Mod,
132 const IsaInfo::AMDGPUTargetID &TargetID) override;
133
134 void end() override;
135
136 void emitKernel(const MachineFunction &MF,
137 const SIProgramInfo &ProgramInfo) override;
138};
139
141protected:
142 void emitVersion() override;
143 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
144 msgpack::ArrayDocNode Args) override;
145 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
146
147public:
150};
151
153protected:
154 void emitVersion() override;
155
156public:
159};
160
161} // end namespace HSAMD
162} // end namespace AMDGPU
163} // end namespace llvm
164
165#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
AMDGPU metadata definitions and in-memory representations.
RelocType Type
Definition: COFFYAML.cpp:391
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:135
static std::string getTypeName(OverloadKind Kind, Type *Ty)
std::string Name
uint64_t Offset
Definition: ELF_riscv.cpp:478
Machine Check Debug Module
This file declares a class that exposes a simple in-memory representation of a document of MsgPack ob...
ppc ctr loops verify
Module * Mod
static void emitVersion(raw_ostream &OS)
void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args) override
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override
virtual void emitKernel(const MachineFunction &MF, const SIProgramInfo &ProgramInfo)=0
virtual void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset, msgpack::ArrayDocNode Args)=0
virtual void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern)=0
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer)=0
virtual void begin(const Module &Mod, const IsaInfo::AMDGPUTargetID &TargetID)=0
This class represents an incoming formal argument to a Function.
Definition: Argument.h:31
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
Metadata node.
Definition: Metadata.h:1067
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
A DocNode that is an array.
A node in a MsgPack Document.
MapDocNode & getMap(bool Convert=false)
Get a MapDocNode for a map node.
A DocNode that is a map.
ValueKind
Value kinds.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
@ Offset
Definition: DWP.cpp:456
AddressSpace
Definition: NVPTXBaseInfo.h:21
@ Mod
The access may modify the value stored in memory.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition: Alignment.h:117
Track resource usage for kernels / entry functions.
Definition: SIProgramInfo.h:31