LLVM 20.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
23
24namespace llvm {
25
26class AMDGPUTargetStreamer;
27class Argument;
28class DataLayout;
29class Function;
30class MachineFunction;
31class MDNode;
32class Module;
33struct SIProgramInfo;
34class Type;
35
36namespace AMDGPU {
37
38namespace IsaInfo {
39class AMDGPUTargetID;
40}
41
42namespace HSAMD {
43
45public:
46 virtual ~MetadataStreamer() = default;
47
48 virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
49
50 virtual void begin(const Module &Mod,
51 const IsaInfo::AMDGPUTargetID &TargetID) = 0;
52
53 virtual void end() = 0;
54
55 virtual void emitKernel(const MachineFunction &MF,
56 const SIProgramInfo &ProgramInfo) = 0;
57
58protected:
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;
64};
65
67 : public MetadataStreamer {
68protected:
69 std::unique_ptr<DelayedMCExprs> DelayedExprs =
70 std::make_unique<DelayedMCExprs>();
71
72 std::unique_ptr<msgpack::Document> HSAMetadataDoc =
73 std::make_unique<msgpack::Document>();
74
75 void dump(StringRef HSAMetadataString) const;
76
77 void verify(StringRef HSAMetadataString) const;
78
79 std::optional<StringRef> getAccessQualifier(StringRef AccQual) const;
80
81 std::optional<StringRef>
82 getAddressSpaceQualifier(unsigned AddressSpace) const;
83
84 StringRef getValueKind(Type *Ty, StringRef TypeQual,
85 StringRef BaseTypeName) const;
86
87 std::string getTypeName(Type *Ty, bool Signed) const;
88
89 msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
90
91 msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
92 const SIProgramInfo &ProgramInfo,
93 unsigned CodeObjectVersion) const;
94
95 void emitVersion() override;
96
97 void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
98
99 void emitPrintf(const Module &Mod);
100
101 void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
102
103 void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern) override;
104
105 void emitKernelArgs(const MachineFunction &MF, msgpack::MapDocNode Kern);
106
107 void emitKernelArg(const Argument &Arg, unsigned &Offset,
109
110 void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
111 StringRef ValueKind, unsigned &Offset,
113 MaybeAlign PointeeAlign = std::nullopt,
114 StringRef Name = "", StringRef TypeName = "",
115 StringRef BaseTypeName = "", StringRef ActAccQual = "",
116 StringRef AccQual = "", StringRef TypeQual = "");
117
118 void emitHiddenKernelArgs(const MachineFunction &MF, unsigned &Offset,
119 msgpack::ArrayDocNode Args) override;
120
122 return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
123 }
124
126 return HSAMetadataDoc->getRoot();
127 }
128
129public:
132
133 bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
134
135 void begin(const Module &Mod,
136 const IsaInfo::AMDGPUTargetID &TargetID) override;
137
138 void end() override;
139
140 void emitKernel(const MachineFunction &MF,
141 const SIProgramInfo &ProgramInfo) override;
142};
143
145protected:
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;
150
151public:
154};
155
157protected:
158 void emitVersion() override;
159
160public:
163};
164
165} // end namespace HSAMD
166} // end namespace AMDGPU
167} // end namespace llvm
168
169#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
AMDGPU metadata definitions and in-memory representations.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
RelocType Type
Definition: COFFYAML.cpp:391
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:131
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
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * 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:63
Metadata node.
Definition: Metadata.h:1069
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:480
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