blob: 8d4c51763f63d8387e3f23cd0fec9082288d69de [file] [log] [blame]
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +00001//===--- AMDGPUCodeObjectMetadataStreamer.h ---------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file
11/// \brief AMDGPU Code Object Metadata Streamer.
12///
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATASTREAMER_H
17#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATASTREAMER_H
18
Yaxun Liu1a14bfa2017-03-27 14:04:01 +000019#include "AMDGPU.h"
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000020#include "AMDGPUCodeObjectMetadata.h"
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +000021#include "AMDKernelCodeT.h"
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000022#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/ErrorOr.h"
24
25namespace llvm {
26
27class Argument;
28class DataLayout;
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000029class Function;
30class MDNode;
31class Module;
32class Type;
33
34namespace AMDGPU {
35namespace CodeObject {
36
37class MetadataStreamer final {
38private:
39 Metadata CodeObjectMetadata;
Yaxun Liu1a14bfa2017-03-27 14:04:01 +000040 AMDGPUAS AMDGPUASI;
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000041
42 void dump(StringRef YamlString) const;
43
44 void verify(StringRef YamlString) const;
45
46 AccessQualifier getAccessQualifier(StringRef AccQual) const;
47
48 AddressSpaceQualifier getAddressSpaceQualifer(unsigned AddressSpace) const;
49
50 ValueKind getValueKind(Type *Ty, StringRef TypeQual,
51 StringRef BaseTypeName) const;
52
53 ValueType getValueType(Type *Ty, StringRef TypeName) const;
54
55 std::string getTypeName(Type *Ty, bool Signed) const;
56
57 std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
58
59 void emitVersion();
60
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000061 void emitPrintf(const Module &Mod);
62
63 void emitKernelLanguage(const Function &Func);
64
65 void emitKernelAttrs(const Function &Func);
66
67 void emitKernelArgs(const Function &Func);
68
69 void emitKernelArg(const Argument &Arg);
70
71 void emitKernelArg(const DataLayout &DL, Type *Ty, ValueKind ValueKind,
72 StringRef TypeQual = "", StringRef BaseTypeName = "",
73 StringRef AccQual = "", StringRef Name = "",
74 StringRef TypeName = "");
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +000075
76 void emitKernelCodeProps(const amd_kernel_code_t &KernelCode);
77
Konstantin Zhuravlyova780ffa2017-03-22 23:10:46 +000078 void emitKernelDebugProps(const amd_kernel_code_t &KernelCode);
79
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000080public:
81 MetadataStreamer() = default;
82 ~MetadataStreamer() = default;
83
Konstantin Zhuravlyov4cbb6892017-03-22 23:27:09 +000084 void begin(const Module &Mod);
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000085
86 void end() {}
87
Konstantin Zhuravlyovca0e7f62017-03-22 22:54:39 +000088 void emitKernel(const Function &Func, const amd_kernel_code_t &KernelCode);
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000089
90 ErrorOr<std::string> toYamlString();
91
Konstantin Zhuravlyov4cbb6892017-03-22 23:27:09 +000092 ErrorOr<std::string> toYamlString(StringRef YamlString);
Konstantin Zhuravlyov7498cd62017-03-22 22:32:22 +000093};
94
95} // end namespace CodeObject
96} // end namespace AMDGPU
97} // end namespace llvm
98
99#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUCODEOBJECTMETADATASTREAMER_H