Mesa (master): aco: print assembly with CLRXdisasm for GFX6-GFX7 if found on the system

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 17 17:58:30 UTC 2020


Module: Mesa
Branch: master
Commit: 0099f85232b700c3aa6bc771c5219de71af9626e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0099f85232b700c3aa6bc771c5219de71af9626e

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Fri Jan 17 09:49:44 2020 +0100

aco: print assembly with CLRXdisasm for GFX6-GFX7 if found on the system

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 <samuel.pitoiset at gmail.com>
Reviewed-by: Daniel Schürmann <daniel at schuermann.dev>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3439>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3439>

---

 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<uint32_t>& 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<uint32_t>& 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<bool> referenced_blocks(program->blocks.size());
    referenced_blocks[0] = true;
    for (Block& block : program->blocks) {



More information about the mesa-commit mailing list