Index: llvm/trunk/test/CodeGen/AMDGPU/elf-notes.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/elf-notes.ll +++ llvm/trunk/test/CodeGen/AMDGPU/elf-notes.ll @@ -17,6 +17,8 @@ ; OSABI-UNK-ELF-NOT: Unknown note type ; OSABI-UNK-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-UNK-ELF: ISA Version: +; OSABI-UNK-ELF: amdgcn-amd-unknown--gfx800 ; OSABI-UNK-ELF-NOT: Unknown note type ; OSABI-UNK-ELF-NOT: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) ; OSABI-UNK-ELF-NOT: Unknown note type @@ -31,8 +33,22 @@ ; OSABI-HSA-ELF-NOT: Unknown note type ; OSABI-HSA-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-HSA-ELF: ISA Version: +; OSABI-HSA-ELF: amdgcn-amd-amdhsa--gfx800 ; OSABI-HSA-ELF-NOT: Unknown note type ; OSABI-HSA-ELF: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) +; OSABI-HSA-ELF: HSA Metadata: +; OSABI-HSA-ELF: --- +; OSABI-HSA-ELF: Version: [ 1, 0 ] +; OSABI-HSA-ELF: Kernels: +; OSABI-HSA-ELF: - Name: elf_notes +; OSABI-HSA-ELF: CodeProps: +; OSABI-HSA-ELF: WavefrontNumSGPRs: 96 +; OSABI-HSA-ELF: KernargSegmentAlign: 32 +; OSABI-HSA-ELF: GroupSegmentAlign: 4 +; OSABI-HSA-ELF: PrivateSegmentAlign: 4 +; OSABI-HSA-ELF: WavefrontSize: 6 +; OSABI-HSA-ELF: ... ; OSABI-HSA-ELF-NOT: Unknown note type ; OSABI-HSA-ELF-NOT: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) ; OSABI-HSA-ELF-NOT: Unknown note type @@ -45,10 +61,14 @@ ; OSABI-PAL-ELF-NOT: Unknown note type ; OSABI-PAL-ELF: NT_AMD_AMDGPU_ISA (ISA Version) +; OSABI-PAL-ELF: ISA Version: +; OSABI-PAL-ELF: amdgcn-amd-amdpal--gfx800 ; OSABI-PAL-ELF-NOT: Unknown note type ; OSABI-PAL-ELF-NOT: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) ; OSABI-PAL-ELF-NOT: Unknown note type ; OSABI-PAL-ELF: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata) +; OSABI-PAL-ELF: PAL Metadata: +; OSABI-PAL-ELF: 0x2e12,0xac02c0,0x2e13,0x80,0x1000001b,0x1,0x10000022,0x60,0x1000003e,0x0 ; OSABI-PAL-ELF-NOT: Unknown note type ; R600-NOT: .hsa_code_object_version Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-deduce-ro-arg.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck %s ; CHECK: - Name: test_ro_arg ; CHECK: Args: Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll @@ -1,6 +1,3 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -amdgpu-dump-hsa-metadata -amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck --check-prefix=PARSER %s ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -amdgpu-dump-hsa-metadata -amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck --check-prefix=PARSER %s ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -amdgpu-dump-hsa-metadata -amdgpu-verify-hsa-metadata -filetype=obj -o - < %s 2>&1 | FileCheck --check-prefix=PARSER %s @@ -1292,12 +1289,4 @@ !101 = !{!"2:1:8:%g\5Cn"} !110 = !{!"__block_literal"} -; NOTES: Displaying notes found at file offset 0x{{[0-9]+}} -; NOTES: Owner Data size Description -; NOTES: AMD 0x00000008 Unknown note type (0x00000001) -; NOTES: AMD 0x0000001b Unknown note type (0x00000003) -; GFX700: AMD 0x00008f64 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) -; GFX800: AMD 0x000092e4 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) -; GFX900: AMD 0x00008f64 NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata) - ; PARSER: AMDGPU HSA Metadata Parser Test: PASS Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-images.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-images.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-images.ll @@ -1,6 +1,6 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s %opencl.image1d_t = type opaque %opencl.image1d_array_t = type opaque Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-1.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-1.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-1.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata | FileCheck %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck %s ; Make sure llc does not crash for invalid opencl version metadata. Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-2.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-2.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-2.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata | FileCheck %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck %s ; Make sure llc does not crash for invalid opencl version metadata. Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-3.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-3.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-invalid-ocl-version-3.ll @@ -1,4 +1,4 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata | FileCheck %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck %s ; Make sure llc does not crash for invalid opencl version metadata. Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-code-props.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-code-props.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-code-props.ll @@ -1,6 +1,6 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s ; CHECK: --- ; CHECK: Version: [ 1, 0 ] Index: llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-debug-props.ll =================================================================== --- llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-debug-props.ll +++ llvm/trunk/test/CodeGen/AMDGPU/hsa-metadata-kernel-debug-props.ll @@ -1,6 +1,6 @@ -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s -; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -amdgpu-code-object-metadata -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX700 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX800 --check-prefix=NOTES %s +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -filetype=obj -o - < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=CHECK --check-prefix=GFX900 --check-prefix=NOTES %s declare void @llvm.dbg.declare(metadata, metadata, metadata) @@ -14,7 +14,7 @@ ; CHECK: ReservedNumVGPRs: 4 ; GFX700: ReservedFirstVGPR: 8 ; GFX800: ReservedFirstVGPR: 8 -; GFX9: ReservedFirstVGPR: 14 +; GFX900: ReservedFirstVGPR: 11 ; CHECK: PrivateSegmentBufferSGPR: 0 ; CHECK: WavefrontPrivateSegmentOffsetSGPR: 11 define amdgpu_kernel void @test(i32 addrspace(1)* %A) #0 !dbg !7 !kernel_arg_addr_space !12 !kernel_arg_access_qual !13 !kernel_arg_type !14 !kernel_arg_base_type !14 !kernel_arg_type_qual !15 { Index: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp +++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp @@ -34,6 +34,7 @@ #include "llvm/Object/Error.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Object/StackMapParser.h" +#include "llvm/Support/AMDGPUMetadata.h" #include "llvm/Support/ARMAttributeParser.h" #include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Casting.h" @@ -156,8 +157,6 @@ void printMipsReginfo() override; void printMipsOptions() override; - void printAMDGPUCodeObjectMetadata() override; - void printStackMap() const override; void printHashHistogram() override; @@ -2353,36 +2352,6 @@ } } -template void ELFDumper::printAMDGPUCodeObjectMetadata() { - const Elf_Shdr *Shdr = findSectionByName(*Obj, ".note"); - if (!Shdr) { - W.startLine() << "There is no .note section in the file.\n"; - return; - } - ArrayRef Sec = unwrapOrError(Obj->getSectionContents(Shdr)); - - const uint32_t CodeObjectMetadataNoteType = 10; - for (auto I = reinterpret_cast(&Sec[0]), - E = I + Sec.size()/4; I != E;) { - uint32_t NameSZ = I[0]; - uint32_t DescSZ = I[1]; - uint32_t Type = I[2]; - I += 3; - - StringRef Name; - if (NameSZ) { - Name = StringRef(reinterpret_cast(I), NameSZ - 1); - I += alignTo<4>(NameSZ)/4; - } - - if (Name == "AMD" && Type == CodeObjectMetadataNoteType) { - StringRef Desc(reinterpret_cast(I), DescSZ); - W.printString(Desc); - } - I += alignTo<4>(DescSZ)/4; - } -} - template void ELFDumper::printStackMap() const { const Elf_Shdr *StackMapSection = nullptr; for (const auto &Sec : unwrapOrError(Obj->sections())) { @@ -3487,6 +3456,39 @@ OS << '\n'; } +template +static void printAMDGPUNote(raw_ostream &OS, uint32_t NoteType, + ArrayRef::Elf_Word> Words, + size_t Size) { + switch (NoteType) { + default: + return; + case ELF::NT_AMD_AMDGPU_HSA_METADATA: + OS << " HSA Metadata:\n" + << StringRef(reinterpret_cast(Words.data()), Size); + break; + case ELF::NT_AMD_AMDGPU_ISA: + OS << " ISA Version:\n" + << " " + << StringRef(reinterpret_cast(Words.data()), Size); + break; + case ELF::NT_AMD_AMDGPU_PAL_METADATA: + const uint32_t *PALMetadataBegin = reinterpret_cast(Words.data()); + const uint32_t *PALMetadataEnd = PALMetadataBegin + Size; + std::vector PALMetadata(PALMetadataBegin, PALMetadataEnd); + std::string PALMetadataString; + auto Error = AMDGPU::PALMD::toString(PALMetadata, PALMetadataString); + OS << " PAL Metadata:\n"; + if (Error) { + OS << " Invalid"; + return; + } + OS << PALMetadataString; + break; + } + OS.flush(); +} + template void GNUStyle::printNotes(const ELFFile *Obj) { const Elf_Ehdr *e = Obj->getHeader(); @@ -3529,6 +3531,7 @@ OS << getFreeBSDNoteTypeName(Type) << '\n'; } else if (Name == "AMD") { OS << getAMDGPUNoteTypeName(Type) << '\n'; + printAMDGPUNote(OS, Type, Descriptor, DescriptorSize); } else { OS << "Unknown note type: (" << format_hex(Type, 10) << ')'; } Index: llvm/trunk/tools/llvm-readobj/ObjDumper.h =================================================================== --- llvm/trunk/tools/llvm-readobj/ObjDumper.h +++ llvm/trunk/tools/llvm-readobj/ObjDumper.h @@ -58,9 +58,6 @@ virtual void printMipsReginfo() { } virtual void printMipsOptions() { } - // Only implemented for AMDGPU ELF at this time. - virtual void printAMDGPUCodeObjectMetadata() {} - // Only implemented for PE/COFF. virtual void printCOFFImports() { } virtual void printCOFFExports() { } Index: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp =================================================================== --- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp +++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp @@ -200,11 +200,6 @@ cl::opt MipsOptions("mips-options", cl::desc("Display the MIPS .MIPS.options section")); - // -amdgpu-code-object-metadata - cl::opt AMDGPUCodeObjectMetadata( - "amdgpu-code-object-metadata", - cl::desc("Display AMDGPU code object metadata")); - // -coff-imports cl::opt COFFImports("coff-imports", cl::desc("Display the PE/COFF import table")); @@ -440,9 +435,6 @@ if (opts::MipsOptions) Dumper->printMipsOptions(); } - if (Obj->getArch() == llvm::Triple::amdgcn) - if (opts::AMDGPUCodeObjectMetadata) - Dumper->printAMDGPUCodeObjectMetadata(); if (opts::SectionGroups) Dumper->printGroupSections(); if (opts::HashHistogram)