CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
257 lines
8.6 KiB
C++
257 lines
8.6 KiB
C++
//===-- AMDGPUTargetStreamer.h - AMDGPU Target Streamer --------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
|
|
#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUTARGETSTREAMER_H
|
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
|
#include "Utils/AMDGPUPALMetadata.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/MC/MCStreamer.h"
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
namespace llvm {
|
|
|
|
class MCELFStreamer;
|
|
class MCSymbol;
|
|
class formatted_raw_ostream;
|
|
|
|
namespace AMDGPU {
|
|
|
|
struct AMDGPUMCKernelCodeT;
|
|
struct MCKernelDescriptor;
|
|
namespace HSAMD {
|
|
struct Metadata;
|
|
}
|
|
|
|
struct FuncInfo {
|
|
uint32_t NumSGPR = 0;
|
|
uint32_t NumArchVGPR = 0;
|
|
uint32_t NumAccVGPR = 0;
|
|
uint32_t PrivateSegmentSize = 0;
|
|
bool UsesVCC = false;
|
|
bool UsesFlatScratch = false;
|
|
bool HasDynStack = false;
|
|
|
|
MCSymbol *Sym = nullptr;
|
|
};
|
|
|
|
struct InfoSectionData {
|
|
SmallVector<FuncInfo, 8> Funcs;
|
|
SmallVector<std::pair<MCSymbol *, MCSymbol *>, 4> Uses;
|
|
SmallVector<std::pair<MCSymbol *, MCSymbol *>, 8> Calls;
|
|
SmallVector<std::pair<MCSymbol *, std::string>, 4> IndirectCalls;
|
|
SmallVector<std::pair<MCSymbol *, std::string>, 4> TypeIds;
|
|
};
|
|
|
|
} // namespace AMDGPU
|
|
|
|
class AMDGPUTargetStreamer : public MCTargetStreamer {
|
|
AMDGPUPALMetadata PALMetadata;
|
|
|
|
protected:
|
|
// TODO: Move HSAMetadataStream to AMDGPUTargetStreamer.
|
|
std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> TargetID;
|
|
unsigned CodeObjectVersion;
|
|
|
|
MCContext &getContext() const { return Streamer.getContext(); }
|
|
|
|
public:
|
|
AMDGPUTargetStreamer(MCStreamer &S)
|
|
: MCTargetStreamer(S),
|
|
// Assume the default COV for now, EmitDirectiveAMDHSACodeObjectVersion
|
|
// will update this if it is encountered.
|
|
CodeObjectVersion(AMDGPU::getDefaultAMDHSACodeObjectVersion()) {}
|
|
|
|
AMDGPUPALMetadata *getPALMetadata() { return &PALMetadata; }
|
|
|
|
virtual void EmitDirectiveAMDGCNTarget(){};
|
|
|
|
virtual void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) {
|
|
CodeObjectVersion = COV;
|
|
}
|
|
|
|
virtual void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) {};
|
|
|
|
virtual void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type){};
|
|
|
|
virtual void emitAMDGPULDS(MCSymbol *Symbol, unsigned Size, Align Alignment) {
|
|
}
|
|
|
|
virtual void EmitMCResourceInfo(
|
|
const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
|
|
const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
|
|
const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
|
|
const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
|
|
const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) {};
|
|
|
|
virtual void EmitMCResourceMaximums(const MCSymbol *MaxVGPR,
|
|
const MCSymbol *MaxAGPR,
|
|
const MCSymbol *MaxSGPR,
|
|
const MCSymbol *MaxNamedBarrier) {};
|
|
|
|
/// \returns True on success, false on failure.
|
|
virtual bool EmitISAVersion() { return true; }
|
|
|
|
/// \returns True on success, false on failure.
|
|
virtual bool EmitHSAMetadataV3(StringRef HSAMetadataString);
|
|
|
|
/// Emit HSA Metadata
|
|
///
|
|
/// When \p Strict is true, known metadata elements must already be
|
|
/// well-typed. When \p Strict is false, known types are inferred and
|
|
/// the \p HSAMetadata structure is updated with the correct types.
|
|
///
|
|
/// \returns True on success, false on failure.
|
|
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) {
|
|
return true;
|
|
}
|
|
|
|
/// \returns True on success, false on failure.
|
|
virtual bool EmitHSAMetadata(const AMDGPU::HSAMD::Metadata &HSAMetadata) {
|
|
return true;
|
|
}
|
|
|
|
/// \returns True on success, false on failure.
|
|
virtual bool EmitCodeEnd(const MCSubtargetInfo &STI) { return true; }
|
|
|
|
virtual void
|
|
EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName,
|
|
const AMDGPU::MCKernelDescriptor &KernelDescriptor,
|
|
const MCExpr *NextVGPR, const MCExpr *NextSGPR,
|
|
const MCExpr *ReserveVCC,
|
|
const MCExpr *ReserveFlatScr) {}
|
|
|
|
virtual void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) {}
|
|
|
|
static StringRef getArchNameFromElfMach(unsigned ElfMach);
|
|
static unsigned getElfMach(StringRef GPU);
|
|
|
|
const std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() const {
|
|
return TargetID;
|
|
}
|
|
std::optional<AMDGPU::IsaInfo::AMDGPUTargetID> &getTargetID() {
|
|
return TargetID;
|
|
}
|
|
void initializeTargetID(const MCSubtargetInfo &STI) {
|
|
assert(TargetID == std::nullopt && "TargetID can only be initialized once");
|
|
TargetID.emplace(STI);
|
|
}
|
|
void initializeTargetID(const MCSubtargetInfo &STI, StringRef FeatureString) {
|
|
initializeTargetID(STI);
|
|
|
|
assert(getTargetID() != std::nullopt && "TargetID is None");
|
|
getTargetID()->setTargetIDFromFeaturesString(FeatureString);
|
|
}
|
|
};
|
|
|
|
class AMDGPUTargetAsmStreamer final : public AMDGPUTargetStreamer {
|
|
formatted_raw_ostream &OS;
|
|
public:
|
|
AMDGPUTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
|
|
|
|
void finish() override;
|
|
|
|
void EmitDirectiveAMDGCNTarget() override;
|
|
|
|
void EmitDirectiveAMDHSACodeObjectVersion(unsigned COV) override;
|
|
|
|
void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
|
|
|
|
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
|
|
|
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
|
|
|
|
void EmitMCResourceInfo(
|
|
const MCSymbol *NumVGPR, const MCSymbol *NumAGPR,
|
|
const MCSymbol *NumExplicitSGPR, const MCSymbol *NumNamedBarrier,
|
|
const MCSymbol *PrivateSegmentSize, const MCSymbol *UsesVCC,
|
|
const MCSymbol *UsesFlatScratch, const MCSymbol *HasDynamicallySizedStack,
|
|
const MCSymbol *HasRecursion, const MCSymbol *HasIndirectCall) override;
|
|
|
|
void EmitMCResourceMaximums(const MCSymbol *MaxVGPR, const MCSymbol *MaxAGPR,
|
|
const MCSymbol *MaxSGPR,
|
|
const MCSymbol *MaxNamedBarrier) override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitISAVersion() override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
|
|
|
|
void
|
|
EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName,
|
|
const AMDGPU::MCKernelDescriptor &KernelDescriptor,
|
|
const MCExpr *NextVGPR, const MCExpr *NextSGPR,
|
|
const MCExpr *ReserveVCC,
|
|
const MCExpr *ReserveFlatScr) override;
|
|
|
|
void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
|
|
};
|
|
|
|
class AMDGPUTargetELFStreamer final : public AMDGPUTargetStreamer {
|
|
const MCSubtargetInfo &STI;
|
|
MCStreamer &Streamer;
|
|
|
|
void EmitNote(StringRef Name, const MCExpr *DescSize, unsigned NoteType,
|
|
function_ref<void(MCELFStreamer &)> EmitDesc);
|
|
|
|
unsigned getEFlags();
|
|
|
|
unsigned getEFlagsR600();
|
|
unsigned getEFlagsAMDGCN();
|
|
|
|
unsigned getEFlagsUnknownOS();
|
|
unsigned getEFlagsAMDHSA();
|
|
unsigned getEFlagsAMDPAL();
|
|
unsigned getEFlagsMesa3D();
|
|
|
|
unsigned getEFlagsV3();
|
|
unsigned getEFlagsV4();
|
|
unsigned getEFlagsV6();
|
|
|
|
public:
|
|
AMDGPUTargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
|
|
|
|
MCELFStreamer &getStreamer();
|
|
|
|
void finish() override;
|
|
|
|
void EmitDirectiveAMDGCNTarget() override;
|
|
|
|
void EmitAMDKernelCodeT(AMDGPU::AMDGPUMCKernelCodeT &Header) override;
|
|
|
|
void EmitAMDGPUSymbolType(StringRef SymbolName, unsigned Type) override;
|
|
|
|
void emitAMDGPULDS(MCSymbol *Sym, unsigned Size, Align Alignment) override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitISAVersion() override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict) override;
|
|
|
|
/// \returns True on success, false on failure.
|
|
bool EmitCodeEnd(const MCSubtargetInfo &STI) override;
|
|
|
|
void
|
|
EmitAmdhsaKernelDescriptor(const MCSubtargetInfo &STI, StringRef KernelName,
|
|
const AMDGPU::MCKernelDescriptor &KernelDescriptor,
|
|
const MCExpr *NextVGPR, const MCExpr *NextSGPR,
|
|
const MCExpr *ReserveVCC,
|
|
const MCExpr *ReserveFlatScr) override;
|
|
|
|
void emitAMDGPUInfo(const AMDGPU::InfoSectionData &Data) override;
|
|
};
|
|
}
|
|
#endif
|