2017-10-12 06:18:53 +08:00
|
|
|
//===--- AMDGPUMetadata.cpp -------------------------------------*- C++ -*-===//
|
2017-06-07 02:35:50 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2017-06-07 02:35:50 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// AMDGPU metadata definitions and in-memory representations.
|
2017-06-07 02:35:50 +08:00
|
|
|
///
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-10-12 06:41:09 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-10-12 06:18:53 +08:00
|
|
|
#include "llvm/Support/AMDGPUMetadata.h"
|
2017-06-07 02:35:50 +08:00
|
|
|
#include "llvm/Support/YAMLTraits.h"
|
|
|
|
|
|
|
|
using namespace llvm::AMDGPU;
|
2017-10-12 06:18:53 +08:00
|
|
|
using namespace llvm::AMDGPU::HSAMD;
|
2017-06-07 02:35:50 +08:00
|
|
|
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata)
|
|
|
|
LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata)
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace yaml {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<AccessQualifier> {
|
|
|
|
static void enumeration(IO &YIO, AccessQualifier &EN) {
|
|
|
|
YIO.enumCase(EN, "Default", AccessQualifier::Default);
|
|
|
|
YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
|
|
|
|
YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
|
|
|
|
YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<AddressSpaceQualifier> {
|
|
|
|
static void enumeration(IO &YIO, AddressSpaceQualifier &EN) {
|
|
|
|
YIO.enumCase(EN, "Private", AddressSpaceQualifier::Private);
|
|
|
|
YIO.enumCase(EN, "Global", AddressSpaceQualifier::Global);
|
|
|
|
YIO.enumCase(EN, "Constant", AddressSpaceQualifier::Constant);
|
|
|
|
YIO.enumCase(EN, "Local", AddressSpaceQualifier::Local);
|
|
|
|
YIO.enumCase(EN, "Generic", AddressSpaceQualifier::Generic);
|
|
|
|
YIO.enumCase(EN, "Region", AddressSpaceQualifier::Region);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ValueKind> {
|
|
|
|
static void enumeration(IO &YIO, ValueKind &EN) {
|
|
|
|
YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
|
|
|
|
YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
|
|
|
|
YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
|
|
|
|
YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
|
|
|
|
YIO.enumCase(EN, "Image", ValueKind::Image);
|
|
|
|
YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
|
|
|
|
YIO.enumCase(EN, "Queue", ValueKind::Queue);
|
|
|
|
YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
|
|
|
|
YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
|
|
|
|
YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
|
|
|
|
YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
|
|
|
|
YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
|
|
|
|
YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
|
|
|
|
YIO.enumCase(EN, "HiddenCompletionAction",
|
|
|
|
ValueKind::HiddenCompletionAction);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct ScalarEnumerationTraits<ValueType> {
|
|
|
|
static void enumeration(IO &YIO, ValueType &EN) {
|
|
|
|
YIO.enumCase(EN, "Struct", ValueType::Struct);
|
|
|
|
YIO.enumCase(EN, "I8", ValueType::I8);
|
|
|
|
YIO.enumCase(EN, "U8", ValueType::U8);
|
|
|
|
YIO.enumCase(EN, "I16", ValueType::I16);
|
|
|
|
YIO.enumCase(EN, "U16", ValueType::U16);
|
|
|
|
YIO.enumCase(EN, "F16", ValueType::F16);
|
|
|
|
YIO.enumCase(EN, "I32", ValueType::I32);
|
|
|
|
YIO.enumCase(EN, "U32", ValueType::U32);
|
|
|
|
YIO.enumCase(EN, "F32", ValueType::F32);
|
|
|
|
YIO.enumCase(EN, "I64", ValueType::I64);
|
|
|
|
YIO.enumCase(EN, "U64", ValueType::U64);
|
|
|
|
YIO.enumCase(EN, "F64", ValueType::F64);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<Kernel::Attrs::Metadata> {
|
|
|
|
static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
|
|
|
|
YIO.mapOptional(Kernel::Attrs::Key::ReqdWorkGroupSize,
|
|
|
|
MD.mReqdWorkGroupSize, std::vector<uint32_t>());
|
|
|
|
YIO.mapOptional(Kernel::Attrs::Key::WorkGroupSizeHint,
|
|
|
|
MD.mWorkGroupSizeHint, std::vector<uint32_t>());
|
|
|
|
YIO.mapOptional(Kernel::Attrs::Key::VecTypeHint,
|
|
|
|
MD.mVecTypeHint, std::string());
|
2017-10-11 03:39:48 +08:00
|
|
|
YIO.mapOptional(Kernel::Attrs::Key::RuntimeHandle, MD.mRuntimeHandle,
|
|
|
|
std::string());
|
2017-06-07 02:35:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<Kernel::Arg::Metadata> {
|
|
|
|
static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
|
2017-06-07 02:35:50 +08:00
|
|
|
YIO.mapRequired(Kernel::Arg::Key::Size, MD.mSize);
|
|
|
|
YIO.mapRequired(Kernel::Arg::Key::Align, MD.mAlign);
|
|
|
|
YIO.mapRequired(Kernel::Arg::Key::ValueKind, MD.mValueKind);
|
|
|
|
YIO.mapRequired(Kernel::Arg::Key::ValueType, MD.mValueType);
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,
|
|
|
|
uint32_t(0));
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual,
|
|
|
|
AddressSpaceQualifier::Unknown);
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapOptional(Kernel::Arg::Key::AccQual, MD.mAccQual,
|
|
|
|
AccessQualifier::Unknown);
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::ActualAccQual, MD.mActualAccQual,
|
|
|
|
AccessQualifier::Unknown);
|
2017-06-07 02:35:50 +08:00
|
|
|
YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false);
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false);
|
|
|
|
YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false);
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false);
|
2017-06-07 02:35:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<Kernel::CodeProps::Metadata> {
|
|
|
|
static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentSize,
|
|
|
|
MD.mKernargSegmentSize);
|
|
|
|
YIO.mapRequired(Kernel::CodeProps::Key::GroupSegmentFixedSize,
|
|
|
|
MD.mGroupSegmentFixedSize);
|
|
|
|
YIO.mapRequired(Kernel::CodeProps::Key::PrivateSegmentFixedSize,
|
|
|
|
MD.mPrivateSegmentFixedSize);
|
|
|
|
YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentAlign,
|
|
|
|
MD.mKernargSegmentAlign);
|
|
|
|
YIO.mapRequired(Kernel::CodeProps::Key::WavefrontSize,
|
|
|
|
MD.mWavefrontSize);
|
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::NumSGPRs,
|
|
|
|
MD.mNumSGPRs, uint16_t(0));
|
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::NumVGPRs,
|
|
|
|
MD.mNumVGPRs, uint16_t(0));
|
2017-10-19 01:31:09 +08:00
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::MaxFlatWorkGroupSize,
|
|
|
|
MD.mMaxFlatWorkGroupSize, uint32_t(0));
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::IsDynamicCallStack,
|
|
|
|
MD.mIsDynamicCallStack, false);
|
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::IsXNACKEnabled,
|
|
|
|
MD.mIsXNACKEnabled, false);
|
2017-11-29 01:51:08 +08:00
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledSGPRs,
|
|
|
|
MD.mNumSpilledSGPRs, uint16_t(0));
|
|
|
|
YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledVGPRs,
|
|
|
|
MD.mNumSpilledVGPRs, uint16_t(0));
|
2017-06-07 02:35:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<Kernel::DebugProps::Metadata> {
|
|
|
|
static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
|
|
|
|
YIO.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion,
|
|
|
|
MD.mDebuggerABIVersion, std::vector<uint32_t>());
|
|
|
|
YIO.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs,
|
|
|
|
MD.mReservedNumVGPRs, uint16_t(0));
|
|
|
|
YIO.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR,
|
|
|
|
MD.mReservedFirstVGPR, uint16_t(-1));
|
|
|
|
YIO.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR,
|
|
|
|
MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
|
|
|
|
YIO.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR,
|
|
|
|
MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct MappingTraits<Kernel::Metadata> {
|
|
|
|
static void mapping(IO &YIO, Kernel::Metadata &MD) {
|
|
|
|
YIO.mapRequired(Kernel::Key::Name, MD.mName);
|
2017-10-15 03:03:51 +08:00
|
|
|
YIO.mapRequired(Kernel::Key::SymbolName, MD.mSymbolName);
|
2017-06-07 02:35:50 +08:00
|
|
|
YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
|
|
|
|
YIO.mapOptional(Kernel::Key::LanguageVersion, MD.mLanguageVersion,
|
|
|
|
std::vector<uint32_t>());
|
|
|
|
if (!MD.mAttrs.empty() || !YIO.outputting())
|
|
|
|
YIO.mapOptional(Kernel::Key::Attrs, MD.mAttrs);
|
|
|
|
if (!MD.mArgs.empty() || !YIO.outputting())
|
|
|
|
YIO.mapOptional(Kernel::Key::Args, MD.mArgs);
|
|
|
|
if (!MD.mCodeProps.empty() || !YIO.outputting())
|
|
|
|
YIO.mapOptional(Kernel::Key::CodeProps, MD.mCodeProps);
|
|
|
|
if (!MD.mDebugProps.empty() || !YIO.outputting())
|
|
|
|
YIO.mapOptional(Kernel::Key::DebugProps, MD.mDebugProps);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2017-10-12 06:18:53 +08:00
|
|
|
struct MappingTraits<HSAMD::Metadata> {
|
|
|
|
static void mapping(IO &YIO, HSAMD::Metadata &MD) {
|
2017-06-07 02:35:50 +08:00
|
|
|
YIO.mapRequired(Key::Version, MD.mVersion);
|
|
|
|
YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
|
|
|
|
if (!MD.mKernels.empty() || !YIO.outputting())
|
|
|
|
YIO.mapOptional(Key::Kernels, MD.mKernels);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace yaml
|
|
|
|
|
|
|
|
namespace AMDGPU {
|
2017-10-12 06:18:53 +08:00
|
|
|
namespace HSAMD {
|
2017-06-07 02:35:50 +08:00
|
|
|
|
2017-10-12 06:59:35 +08:00
|
|
|
std::error_code fromString(std::string String, Metadata &HSAMetadata) {
|
|
|
|
yaml::Input YamlInput(String);
|
2017-10-12 06:18:53 +08:00
|
|
|
YamlInput >> HSAMetadata;
|
2017-06-07 02:35:50 +08:00
|
|
|
return YamlInput.error();
|
|
|
|
}
|
|
|
|
|
2017-10-12 06:59:35 +08:00
|
|
|
std::error_code toString(Metadata HSAMetadata, std::string &String) {
|
|
|
|
raw_string_ostream YamlStream(String);
|
2017-06-07 02:35:50 +08:00
|
|
|
yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
|
2017-10-12 06:18:53 +08:00
|
|
|
YamlOutput << HSAMetadata;
|
2017-06-07 02:35:50 +08:00
|
|
|
return std::error_code();
|
|
|
|
}
|
|
|
|
|
2017-10-12 06:18:53 +08:00
|
|
|
} // end namespace HSAMD
|
2017-06-07 02:35:50 +08:00
|
|
|
} // end namespace AMDGPU
|
|
|
|
} // end namespace llvm
|