1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00
llvm-mirror/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
Konstantin Zhuravlyov a76ecb87cf AMDGPU: Add target id and code object v4 support
- Add target id support (https://clang.llvm.org/docs/ClangOffloadBundler.html#target-id)
  - Add code object v4 support (https://llvm.org/docs/AMDGPUUsage.html#elf-code-object)
    - Add kernarg_size to kernel descriptor
    - Change trap handler ABI to no longer move queue pointer into s[0:1]
  - Cleanup ELF definitions
    - Add V2, V3, V4 suffixes to make a clear distinction for code object version
    - Consolidate note names

Differential Revision: https://reviews.llvm.org/D95638
2021-03-24 11:54:05 -04:00

208 lines
6.2 KiB
C++

//===--- AMDGPUHSAMetadataStreamer.h ----------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
/// \file
/// AMDGPU HSA Metadata Streamer.
///
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H
#include "Utils/AMDGPUBaseInfo.h"
#include "llvm/BinaryFormat/MsgPackDocument.h"
#include "llvm/Support/AMDGPUMetadata.h"
#include "llvm/Support/Alignment.h"
namespace llvm {
class AMDGPUTargetStreamer;
class Argument;
class DataLayout;
class Function;
class MachineFunction;
class MDNode;
class Module;
struct SIProgramInfo;
class Type;
namespace AMDGPU {
namespace HSAMD {
class MetadataStreamer {
public:
virtual ~MetadataStreamer(){};
virtual bool emitTo(AMDGPUTargetStreamer &TargetStreamer) = 0;
virtual void begin(const Module &Mod,
const IsaInfo::AMDGPUTargetID &TargetID) = 0;
virtual void end() = 0;
virtual void emitKernel(const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) = 0;
};
// TODO: Rename MetadataStreamerV3 -> MetadataStreamerMsgPackV3.
class MetadataStreamerV3 : public MetadataStreamer {
protected:
std::unique_ptr<msgpack::Document> HSAMetadataDoc =
std::make_unique<msgpack::Document>();
void dump(StringRef HSAMetadataString) const;
void verify(StringRef HSAMetadataString) const;
Optional<StringRef> getAccessQualifier(StringRef AccQual) const;
Optional<StringRef> getAddressSpaceQualifier(unsigned AddressSpace) const;
StringRef getValueKind(Type *Ty, StringRef TypeQual,
StringRef BaseTypeName) const;
std::string getTypeName(Type *Ty, bool Signed) const;
msgpack::ArrayDocNode getWorkGroupDimensions(MDNode *Node) const;
msgpack::MapDocNode getHSAKernelProps(const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) const;
void emitVersion();
void emitPrintf(const Module &Mod);
void emitKernelLanguage(const Function &Func, msgpack::MapDocNode Kern);
void emitKernelAttrs(const Function &Func, msgpack::MapDocNode Kern);
void emitKernelArgs(const Function &Func, msgpack::MapDocNode Kern);
void emitKernelArg(const Argument &Arg, unsigned &Offset,
msgpack::ArrayDocNode Args);
void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
StringRef ValueKind, unsigned &Offset,
msgpack::ArrayDocNode Args, MaybeAlign PointeeAlign = None,
StringRef Name = "", StringRef TypeName = "",
StringRef BaseTypeName = "", StringRef AccQual = "",
StringRef TypeQual = "");
void emitHiddenKernelArgs(const Function &Func, unsigned &Offset,
msgpack::ArrayDocNode Args);
msgpack::DocNode &getRootMetadata(StringRef Key) {
return HSAMetadataDoc->getRoot().getMap(/*Convert=*/true)[Key];
}
msgpack::DocNode &getHSAMetadataRoot() {
return HSAMetadataDoc->getRoot();
}
public:
MetadataStreamerV3() = default;
~MetadataStreamerV3() = default;
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
void begin(const Module &Mod,
const IsaInfo::AMDGPUTargetID &TargetID) override;
void end() override;
void emitKernel(const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) override;
};
// TODO: Rename MetadataStreamerV4 -> MetadataStreamerMsgPackV4.
class MetadataStreamerV4 final : public MetadataStreamerV3 {
void emitVersion();
void emitTargetID(const IsaInfo::AMDGPUTargetID &TargetID);
public:
MetadataStreamerV4() = default;
~MetadataStreamerV4() = default;
void begin(const Module &Mod,
const IsaInfo::AMDGPUTargetID &TargetID) override;
};
// TODO: Rename MetadataStreamerV2 -> MetadataStreamerYamlV2.
class MetadataStreamerV2 final : public MetadataStreamer {
private:
Metadata HSAMetadata;
void dump(StringRef HSAMetadataString) const;
void verify(StringRef HSAMetadataString) const;
AccessQualifier getAccessQualifier(StringRef AccQual) const;
AddressSpaceQualifier getAddressSpaceQualifier(unsigned AddressSpace) const;
ValueKind getValueKind(Type *Ty, StringRef TypeQual,
StringRef BaseTypeName) const;
std::string getTypeName(Type *Ty, bool Signed) const;
std::vector<uint32_t> getWorkGroupDimensions(MDNode *Node) const;
Kernel::CodeProps::Metadata getHSACodeProps(
const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) const;
Kernel::DebugProps::Metadata getHSADebugProps(
const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) const;
void emitVersion();
void emitPrintf(const Module &Mod);
void emitKernelLanguage(const Function &Func);
void emitKernelAttrs(const Function &Func);
void emitKernelArgs(const Function &Func);
void emitKernelArg(const Argument &Arg);
void emitKernelArg(const DataLayout &DL, Type *Ty, Align Alignment,
ValueKind ValueKind, MaybeAlign PointeeAlign = None,
StringRef Name = "", StringRef TypeName = "",
StringRef BaseTypeName = "", StringRef AccQual = "",
StringRef TypeQual = "");
void emitHiddenKernelArgs(const Function &Func);
const Metadata &getHSAMetadata() const {
return HSAMetadata;
}
public:
MetadataStreamerV2() = default;
~MetadataStreamerV2() = default;
bool emitTo(AMDGPUTargetStreamer &TargetStreamer) override;
void begin(const Module &Mod,
const IsaInfo::AMDGPUTargetID &TargetID) override;
void end() override;
void emitKernel(const MachineFunction &MF,
const SIProgramInfo &ProgramInfo) override;
};
} // end namespace HSAMD
} // end namespace AMDGPU
} // end namespace llvm
#endif // LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUHSAMETADATASTREAMER_H