Skip to content

Commit f5b36e5

Browse files
committed
[AMDGPU] Emit MessagePack HSA Metadata for v3 code object
Continue to present HSA metadata as YAML in ASM and when output by tools (e.g. llvm-readobj), but encode it in Messagepack in the code object. Differential Revision: https://reviews.llvm.org/D48179 llvm-svn: 348963
1 parent 3f8f004 commit f5b36e5

31 files changed

+3658
-154
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
//===- AMDGPUMetadataVerifier.h - MsgPack Types -----------------*- 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+
/// This is a verifier for AMDGPU HSA metadata, which can verify both
12+
/// well-typed metadata and untyped metadata. When verifying in the non-strict
13+
/// mode, untyped metadata is coerced into the correct type if possible.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
18+
#define LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H
19+
20+
#include "llvm/BinaryFormat/MsgPackTypes.h"
21+
22+
namespace llvm {
23+
namespace AMDGPU {
24+
namespace HSAMD {
25+
namespace V3 {
26+
27+
/// Verifier for AMDGPU HSA metadata.
28+
///
29+
/// Operates in two modes:
30+
///
31+
/// In strict mode, metadata must already be well-typed.
32+
///
33+
/// In non-strict mode, metadata is coerced into expected types when possible.
34+
class MetadataVerifier {
35+
bool Strict;
36+
37+
bool verifyScalar(msgpack::Node &Node, msgpack::ScalarNode::ScalarKind SKind,
38+
function_ref<bool(msgpack::ScalarNode &)> verifyValue = {});
39+
bool verifyInteger(msgpack::Node &Node);
40+
bool verifyArray(msgpack::Node &Node,
41+
function_ref<bool(msgpack::Node &)> verifyNode,
42+
Optional<size_t> Size = None);
43+
bool verifyEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required,
44+
function_ref<bool(msgpack::Node &)> verifyNode);
45+
bool
46+
verifyScalarEntry(msgpack::MapNode &MapNode, StringRef Key, bool Required,
47+
msgpack::ScalarNode::ScalarKind SKind,
48+
function_ref<bool(msgpack::ScalarNode &)> verifyValue = {});
49+
bool verifyIntegerEntry(msgpack::MapNode &MapNode, StringRef Key,
50+
bool Required);
51+
bool verifyKernelArgs(msgpack::Node &Node);
52+
bool verifyKernel(msgpack::Node &Node);
53+
54+
public:
55+
/// Construct a MetadataVerifier, specifying whether it will operate in \p
56+
/// Strict mode.
57+
MetadataVerifier(bool Strict) : Strict(Strict) {}
58+
59+
/// Verify given HSA metadata.
60+
///
61+
/// \returns True when successful, false when metadata is invalid.
62+
bool verify(msgpack::Node &HSAMetadataRoot);
63+
};
64+
65+
} // end namespace V3
66+
} // end namespace HSAMD
67+
} // end namespace AMDGPU
68+
} // end namespace llvm
69+
70+
#endif // LLVM_BINARYFORMAT_AMDGPUMETADATAVERIFIER_H

llvm/include/llvm/BinaryFormat/ELF.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -1361,14 +1361,20 @@ enum {
13611361
GNU_PROPERTY_X86_FEATURE_1_SHSTK = 1 << 1
13621362
};
13631363

1364-
// AMDGPU specific notes.
1364+
// AMD specific notes. (Code Object V2)
13651365
enum {
13661366
// Note types with values between 0 and 9 (inclusive) are reserved.
13671367
NT_AMD_AMDGPU_HSA_METADATA = 10,
13681368
NT_AMD_AMDGPU_ISA = 11,
13691369
NT_AMD_AMDGPU_PAL_METADATA = 12
13701370
};
13711371

1372+
// AMDGPU specific notes. (Code Object V3)
1373+
enum {
1374+
// Note types with values between 0 and 31 (inclusive) are reserved.
1375+
NT_AMDGPU_METADATA = 32
1376+
};
1377+
13721378
enum {
13731379
GNU_ABI_TAG_LINUX = 0,
13741380
GNU_ABI_TAG_HURD = 1,

llvm/include/llvm/Support/AMDGPUMetadata.h

+15
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,21 @@ std::error_code fromString(std::string String, Metadata &HSAMetadata);
431431
/// Converts \p HSAMetadata to \p String.
432432
std::error_code toString(Metadata HSAMetadata, std::string &String);
433433

434+
//===----------------------------------------------------------------------===//
435+
// HSA metadata for v3 code object.
436+
//===----------------------------------------------------------------------===//
437+
namespace V3 {
438+
/// HSA metadata major version.
439+
constexpr uint32_t VersionMajor = 1;
440+
/// HSA metadata minor version.
441+
constexpr uint32_t VersionMinor = 0;
442+
443+
/// HSA metadata beginning assembler directive.
444+
constexpr char AssemblerDirectiveBegin[] = ".amdgpu_metadata";
445+
/// HSA metadata ending assembler directive.
446+
constexpr char AssemblerDirectiveEnd[] = ".end_amdgpu_metadata";
447+
} // end namespace V3
448+
434449
} // end namespace HSAMD
435450

436451
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)