1 //===----RTLs/amdgpu/utils/UtilitiesRTL.h ------------------------- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // RTL Utilities for AMDGPU plugins
11 //===----------------------------------------------------------------------===//
15 #include "Shared/Debug.h"
16 #include "Utils/ELF.h"
18 #include "omptarget.h"
20 #include "llvm/Frontend/Offloading/Utility.h"
28 // The implicit arguments of COV5 AMDGPU kernels.
29 struct AMDGPUImplicitArgsTy
{
36 uint8_t Unused0
[46]; // 46 byte offset.
38 uint8_t Unused1
[54]; // 54 byte offset.
39 uint32_t DynamicLdsSize
;
40 uint8_t Unused2
[132]; // 132 byte offset.
43 // Dummy struct for COV4 implicitargs.
44 struct AMDGPUImplicitArgsTyCOV4
{
48 /// Returns the size in bytes of the implicit arguments of AMDGPU kernels.
49 /// `Version` is the ELF ABI version, e.g. COV5.
50 inline uint32_t getImplicitArgsSize(uint16_t Version
) {
51 return Version
< ELF::ELFABIVERSION_AMDGPU_HSA_V5
52 ? sizeof(AMDGPUImplicitArgsTyCOV4
)
53 : sizeof(AMDGPUImplicitArgsTy
);
56 /// Reads the AMDGPU specific metadata from the ELF file and propagates the
58 inline Error
readAMDGPUMetaDataFromImage(
59 MemoryBufferRef MemBuffer
,
60 StringMap
<offloading::amdgpu::AMDGPUKernelMetaData
> &KernelInfoMap
,
61 uint16_t &ELFABIVersion
) {
62 Error Err
= llvm::offloading::amdgpu::getAMDGPUMetaDataFromImage(
63 MemBuffer
, KernelInfoMap
, ELFABIVersion
);
66 DP("ELFABIVERSION Version: %u\n", ELFABIVersion
);
70 } // namespace hsa_utils