Skip to content

Commit

Permalink
llvm-readobj: Print AMDGPU note type names
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D38751


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315813 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kzhuravl committed Oct 14, 2017
1 parent e7b2dc3 commit 5376db4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
28 changes: 28 additions & 0 deletions test/CodeGen/AMDGPU/elf-notes.ll
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
; OSABI-PAL-NOT: .amd_amdgpu_hsa_metadata
; OSABI-PAL: .amd_amdgpu_pal_metadata

; RUN: llc -mtriple=amdgcn-amd-unknown -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-UNK-ELF --check-prefix=GFX800 %s
; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-HSA-ELF --check-prefix=GFX800 %s
; RUN: llc -mtriple=amdgcn-amd-amdpal -mcpu=gfx800 -mattr=+code-object-v3 -filetype=obj < %s | llvm-readobj -elf-output-style=GNU -notes | FileCheck --check-prefix=GCN --check-prefix=OSABI-PAL-ELF --check-prefix=GFX800 %s

; R600-NOT: .hsa_code_object_version
; R600-NOT: .hsa_code_object_isa
; R600-NOT: .amd_amdgpu_isa
Expand All @@ -33,3 +37,27 @@
define amdgpu_kernel void @elf_notes() {
ret void
}

; OSABI-UNK-ELF-NOT: Unknown note type
; OSABI-UNK-ELF: NT_AMD_AMDGPU_ISA (ISA Version)
; 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
; OSABI-UNK-ELF-NOT: NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)
; OSABI-UNK-ELF-NOT: Unknown note type

; OSABI-HSA-ELF-NOT: Unknown note type
; OSABI-HSA-ELF: NT_AMD_AMDGPU_ISA (ISA Version)
; OSABI-HSA-ELF-NOT: Unknown note type
; OSABI-HSA-ELF: NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)
; 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

; OSABI-PAL-ELF-NOT: Unknown note type
; OSABI-PAL-ELF: NT_AMD_AMDGPU_ISA (ISA Version)
; 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-NOT: Unknown note type
12 changes: 6 additions & 6 deletions test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1293,11 +1293,11 @@ attributes #0 = { "runtime-handle"="__test_block_invoke_kernel_runtime_handle" }
!110 = !{!"__block_literal"}

; NOTES: Displaying notes found at file offset 0x{{[0-9]+}}
; NOTES-NEXT: Owner Data size Description
; NOTES-NEXT: AMD 0x00000008 Unknown note type: (0x00000001)
; NOTES-NEXT: AMD 0x0000001b Unknown note type: (0x00000003)
; GFX700: AMD 0x00008f64 Unknown note type: (0x0000000a)
; GFX800: AMD 0x000092e4 Unknown note type: (0x0000000a)
; GFX900: AMD 0x00008f64 Unknown note type: (0x0000000a)
; 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
29 changes: 27 additions & 2 deletions tools/llvm-readobj/ELFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3393,7 +3393,7 @@ static std::string getGNUNoteTypeName(const uint32_t NT) {
std::string string;
raw_string_ostream OS(string);
OS << format("Unknown note type (0x%08x)", NT);
return string;
return OS.str();
}

static std::string getFreeBSDNoteTypeName(const uint32_t NT) {
Expand Down Expand Up @@ -3421,7 +3421,30 @@ static std::string getFreeBSDNoteTypeName(const uint32_t NT) {
std::string string;
raw_string_ostream OS(string);
OS << format("Unknown note type (0x%08x)", NT);
return string;
return OS.str();
}

static std::string getAMDGPUNoteTypeName(const uint32_t NT) {
static const struct {
uint32_t ID;
const char *Name;
} Notes[] = {
{ELF::NT_AMD_AMDGPU_HSA_METADATA,
"NT_AMD_AMDGPU_HSA_METADATA (HSA Metadata)"},
{ELF::NT_AMD_AMDGPU_ISA,
"NT_AMD_AMDGPU_ISA (ISA Version)"},
{ELF::NT_AMD_AMDGPU_PAL_METADATA,
"NT_AMD_AMDGPU_PAL_METADATA (PAL Metadata)"}
};

for (const auto &Note : Notes)
if (Note.ID == NT)
return std::string(Note.Name);

std::string string;
raw_string_ostream OS(string);
OS << format("Unknown note type (0x%08x)", NT);
return OS.str();
}

template <typename ELFT>
Expand Down Expand Up @@ -3504,6 +3527,8 @@ void GNUStyle<ELFT>::printNotes(const ELFFile<ELFT> *Obj) {
printGNUNote<ELFT>(OS, Type, Descriptor, DescriptorSize);
} else if (Name == "FreeBSD") {
OS << getFreeBSDNoteTypeName(Type) << '\n';
} else if (Name == "AMD") {
OS << getAMDGPUNoteTypeName(Type) << '\n';
} else {
OS << "Unknown note type: (" << format_hex(Type, 10) << ')';
}
Expand Down

0 comments on commit 5376db4

Please sign in to comment.