From 0099f85232b700c3aa6bc771c5219de71af9626e Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Fri, 17 Jan 2020 09:49:44 +0100 Subject: [PATCH] aco: print assembly with CLRXdisasm for GFX6-GFX7 if found on the system MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit LLVM only supports GFX8+. Using CLRXdisasm works most of the time, so it's useful to add support for it. Original patch by Daniel Schürmann. Signed-off-by: Samuel Pitoiset Reviewed-by: Daniel Schürmann Tested-by: Marge Bot Part-of: --- src/amd/compiler/aco_print_asm.cpp | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/amd/compiler/aco_print_asm.cpp b/src/amd/compiler/aco_print_asm.cpp index 4b0ce26994b..74115e10cd3 100644 --- a/src/amd/compiler/aco_print_asm.cpp +++ b/src/amd/compiler/aco_print_asm.cpp @@ -8,13 +8,51 @@ namespace aco { +/* LLVM disassembler only supports GFX8+, try to disassemble with CLRXdisasm + * for GFX6-GFX7 if found on the system, this is better than nothing. +*/ +void print_asm_gfx6_gfx7(Program *program, std::vector& binary, + std::ostream& out) +{ + char path[] = "/tmp/fileXXXXXX"; + char line[2048], command[128]; + FILE *p; + int fd; + + /* Dump the binary into a temporary file. */ + fd = mkstemp(path); + if (fd < 0) + return; + + for (uint32_t w : binary) + { + if (write(fd, &w, sizeof(w)) == -1) + goto fail; + } + + sprintf(command, "clrxdisasm --gpuType=%s -r %s", + program->chip_class == GFX6 ? "gfx600" : "gfx700", path); + + p = popen(command, "r"); + if (p) { + while (fgets(line, sizeof(line), p)) + out << line; + pclose(p); + } + +fail: + close(fd); + unlink(path); +} + void print_asm(Program *program, std::vector& binary, unsigned exec_size, std::ostream& out) { if (program->chip_class <= GFX7) { - out << "Disassembly for this GPU currently not supported." << std::endl; + print_asm_gfx6_gfx7(program, binary, out); return; } + std::vector referenced_blocks(program->blocks.size()); referenced_blocks[0] = true; for (Block& block : program->blocks) { -- 2.30.2