[Mesa-dev] [PATCH 5/6] i965/disasm: Label support in shader disassembly for instructions with UIP/JIP

Toni Lönnberg toni.lonnberg at intel.com
Mon Feb 20 13:27:17 UTC 2017


From: "Lonnberg, Toni" <toni.lonnberg at intel.com>

Shader instructions which use UIP/JIP now get formatted with a label instead
of an immediate value if the "disasm" flag has been set in the INTEL_DEBUG
debug flags, and the jump targets themselves also get printed as labels into
the shader disassembly.
---
 src/intel/tools/disasm.c                       | 49 ++++++++++++++++++++--
 src/mesa/drivers/dri/i965/brw_context.h        |  3 +-
 src/mesa/drivers/dri/i965/brw_disasm.c         | 56 +++++++++++++++++++++-----
 src/mesa/drivers/dri/i965/brw_eu.c             | 41 +++++++++++++++++--
 src/mesa/drivers/dri/i965/brw_eu_compact.c     |  4 +-
 src/mesa/drivers/dri/i965/brw_fs_generator.cpp | 10 ++++-
 src/mesa/drivers/dri/i965/test_eu_compact.c    |  2 +-
 7 files changed, 142 insertions(+), 23 deletions(-)

diff --git a/src/intel/tools/disasm.c b/src/intel/tools/disasm.c
index 4ac7b90..0865718 100644
--- a/src/intel/tools/disasm.c
+++ b/src/intel/tools/disasm.c
@@ -49,13 +49,53 @@ gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly,
                        int start, FILE *out)
 {
    struct gen_device_info *devinfo = &disasm->devinfo;
-   bool dump_hex = false;
+   bool dump_hex = (INTEL_DEBUG & DEBUG_HEX) != 0;
    int offset = start;
 
+   void *mem_ctx = ralloc_context(NULL);
+   struct brw_label *root = NULL;
+
+   if ((INTEL_DEBUG & DEBUG_DISASM) != 0) {
+      while (true) {
+         brw_inst *insn = assembly + offset;
+         brw_inst uncompacted;
+
+         bool compacted = brw_inst_cmpt_control(devinfo, insn);
+
+         if (compacted) {
+            brw_compact_inst *compacted = (void *)insn;
+            brw_uncompact_instruction(devinfo, &uncompacted, compacted);
+            insn = &uncompacted;
+         }
+
+         if (brw_has_uip(devinfo, brw_inst_opcode(devinfo, insn)))
+            brw_create_label(&root, offset + brw_inst_uip(devinfo, insn), mem_ctx);
+
+         if (brw_has_jip(devinfo, brw_inst_opcode(devinfo, insn)))
+            brw_create_label(&root, offset + brw_inst_jip(devinfo, insn), mem_ctx);
+
+         offset += compacted ? 8 : 16;
+
+        uint32_t opcode = brw_inst_opcode(devinfo, insn);
+        if (opcode == 0 || (is_send(opcode) && brw_inst_eot(devinfo, insn))) {
+           break;
+        }
+      }
+   }
+
    /* This loop exits when send-with-EOT or when opcode is 0 */
+   offset = start;
    while (true) {
       brw_inst *insn = assembly + offset;
       brw_inst uncompacted;
+
+      if (root != NULL) {
+        const struct brw_label *label = brw_find_label(root, offset);
+        if (label != NULL) {
+           fprintf(out, "\n_label%d:\n", label->number);
+        }
+      }
+
       bool compacted = brw_inst_cmpt_control(devinfo, insn);
       if (0)
          fprintf(out, "0x%08x: ", offset);
@@ -70,7 +110,6 @@ gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly,
 
          brw_uncompact_instruction(devinfo, &uncompacted, compacted);
          insn = &uncompacted;
-         offset += 8;
       } else {
          if (dump_hex) {
             fprintf(out, "0x%08x 0x%08x 0x%08x 0x%08x ",
@@ -79,10 +118,10 @@ gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly,
                    ((uint32_t *)insn)[1],
                    ((uint32_t *)insn)[0]);
          }
-         offset += 16;
       }
 
-      brw_disassemble_inst(out, devinfo, insn, compacted);
+      brw_disassemble_inst(out, devinfo, insn, compacted, offset, root);
+      offset += compacted ? 8 : 16;
 
       /* Simplistic, but efficient way to terminate disasm */
       uint32_t opcode = brw_inst_opcode(devinfo, insn);
@@ -90,6 +129,8 @@ gen_disasm_disassemble(struct gen_disasm *disasm, void *assembly,
          break;
       }
    }
+
+   ralloc_free(mem_ctx);
 }
 
 struct gen_disasm *
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index ec5c16c..850d882 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1367,7 +1367,8 @@ void brw_vec4_alloc_reg_set(struct brw_compiler *compiler);
 
 /* brw_disasm.c */
 int brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
-                         struct brw_inst *inst, bool is_compacted);
+                         struct brw_inst *inst, bool is_compacted,
+                         int offset, struct brw_label *label_root);
 
 /* brw_vs.c */
 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_disasm.c b/src/mesa/drivers/dri/i965/brw_disasm.c
index 458e0db..6df3bd1 100644
--- a/src/mesa/drivers/dri/i965/brw_disasm.c
+++ b/src/mesa/drivers/dri/i965/brw_disasm.c
@@ -1218,13 +1218,14 @@ brw_disassemble_imm(const struct gen_device_info *devinfo,
    brw_inst inst;
    inst.data[0] = (((uint64_t) dw1) << 32) | ((uint64_t) dw0);
    inst.data[1] = (((uint64_t) dw3) << 32) | ((uint64_t) dw2);
-   return brw_disassemble_inst(stderr, devinfo, &inst, false);
+   return brw_disassemble_inst(stderr, devinfo, &inst, false, 0, NULL);
 }
 #endif
 
 int
 brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
-                     brw_inst *inst, bool is_compacted)
+                     brw_inst *inst, bool is_compacted,
+                     int offset, struct brw_label *label_root)
 {
    int err = 0;
    int space = 0;
@@ -1291,16 +1292,51 @@ brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
 
    if (brw_has_uip(devinfo, opcode)) {
       /* Instructions that have UIP also have JIP. */
-      pad(file, 16);
-      format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
-      pad(file, 32);
-      format(file, "UIP: %d", brw_inst_uip(devinfo, inst));
-   } else if (brw_has_jip(devinfo, opcode)) {
-      pad(file, 16);
-      if (devinfo->gen >= 7) {
+      if (label_root != NULL) {
+         const struct brw_label *branch = NULL;
+
+         pad(file, 16);
+         branch = brw_find_label(label_root, offset + brw_inst_jip(devinfo, inst));
+         if (branch != NULL)
+            format(file, "_label%d", branch->number);
+         else
+            format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
+
+         pad(file, 32);
+         branch = brw_find_label(label_root, offset + brw_inst_uip(devinfo, inst));
+         if (branch != NULL)
+            format(file, "_label%d", branch->number);
+         else
+            format(file, "UIP: %d", brw_inst_uip(devinfo, inst));
+      } else {
+         pad(file, 16);
          format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
+         pad(file, 32);
+         format(file, "UIP: %d", brw_inst_uip(devinfo, inst));
+      }
+   } else if (brw_has_jip(devinfo, opcode)) {
+      if (label_root != NULL) {
+         const struct brw_label *branch = NULL;
+         int jip;
+
+         if (devinfo->gen >= 7)
+            jip = brw_inst_jip(devinfo, inst);
+         else
+            jip = brw_inst_gen6_jump_count(devinfo, inst);
+
+         pad(file, 16);
+         branch = brw_find_label(label_root, offset + jip);
+         if (branch != NULL)
+            format(file, "_label%d", branch->number);
+         else
+            format(file, "JIP: %d", jip);
       } else {
-         format(file, "JIP: %d", brw_inst_gen6_jump_count(devinfo, inst));
+         pad(file, 16);
+         if (devinfo->gen >= 7) {
+            format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
+         } else {
+            format(file, "JIP: %d", brw_inst_gen6_jump_count(devinfo, inst));
+         }
       }
    } else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_BREAK ||
                                opcode == BRW_OPCODE_CONTINUE ||
diff --git a/src/mesa/drivers/dri/i965/brw_eu.c b/src/mesa/drivers/dri/i965/brw_eu.c
index 1061799..5104e55 100644
--- a/src/mesa/drivers/dri/i965/brw_eu.c
+++ b/src/mesa/drivers/dri/i965/brw_eu.c
@@ -417,9 +417,43 @@ brw_disassemble(const struct gen_device_info *devinfo,
 {
    bool dump_hex = (INTEL_DEBUG & DEBUG_HEX) != 0;
 
+   void *mem_ctx = ralloc_context(NULL);
+   struct brw_label *root = NULL;
+
+   if ((INTEL_DEBUG & DEBUG_DISASM) != 0) {
+      for (int offset = start; offset < end;) {
+         brw_inst *insn = assembly + offset;
+         brw_inst uncompacted;
+
+         bool compacted = brw_inst_cmpt_control(devinfo, insn);
+
+         if (compacted) {
+            brw_compact_inst *compacted = (void *)insn;
+            brw_uncompact_instruction(devinfo, &uncompacted, compacted);
+            insn = &uncompacted;
+         }
+
+         if (brw_has_uip(devinfo, brw_inst_opcode(devinfo, insn)))
+            brw_create_label(&root, offset + brw_inst_uip(devinfo, insn), mem_ctx);
+
+         if (brw_has_jip(devinfo, brw_inst_opcode(devinfo, insn)))
+            brw_create_label(&root, offset + brw_inst_jip(devinfo, insn), mem_ctx);
+
+         offset += compacted ? 8 : 16;
+      }
+   }
+
    for (int offset = start; offset < end;) {
       brw_inst *insn = assembly + offset;
       brw_inst uncompacted;
+
+      if (root != NULL) {
+        const struct brw_label *label = brw_find_label(root, offset);
+        if (label != NULL) {
+           fprintf(out, "\n_label%d:\n", label->number);
+        }
+      }
+
       bool compacted = brw_inst_cmpt_control(devinfo, insn);
       if (0)
          fprintf(out, "0x%08x: ", offset);
@@ -434,7 +468,6 @@ brw_disassemble(const struct gen_device_info *devinfo,
 
 	 brw_uncompact_instruction(devinfo, &uncompacted, compacted);
 	 insn = &uncompacted;
-	 offset += 8;
       } else {
 	 if (dump_hex) {
 	    fprintf(out, "0x%08x 0x%08x 0x%08x 0x%08x ",
@@ -443,11 +476,13 @@ brw_disassemble(const struct gen_device_info *devinfo,
 		    ((uint32_t *)insn)[1],
 		    ((uint32_t *)insn)[0]);
 	 }
-	 offset += 16;
       }
 
-      brw_disassemble_inst(out, devinfo, insn, compacted);
+      brw_disassemble_inst(out, devinfo, insn, compacted, offset, root);
+      offset += compacted ? 8 : 16;
    }
+
+   ralloc_free(mem_ctx);
 }
 
 enum gen {
diff --git a/src/mesa/drivers/dri/i965/brw_eu_compact.c b/src/mesa/drivers/dri/i965/brw_eu_compact.c
index 68321e7..d20c6d1 100644
--- a/src/mesa/drivers/dri/i965/brw_eu_compact.c
+++ b/src/mesa/drivers/dri/i965/brw_eu_compact.c
@@ -1262,10 +1262,10 @@ void brw_debug_compact_uncompact(const struct gen_device_info *devinfo,
            devinfo->gen);
 
    fprintf(stderr, "  before: ");
-   brw_disassemble_inst(stderr, devinfo, orig, true);
+   brw_disassemble_inst(stderr, devinfo, orig, true, 0, NULL);
 
    fprintf(stderr, "  after:  ");
-   brw_disassemble_inst(stderr, devinfo, uncompacted, false);
+   brw_disassemble_inst(stderr, devinfo, uncompacted, false, 0, NULL);
 
    uint32_t *before_bits = (uint32_t *)orig;
    uint32_t *after_bits = (uint32_t *)uncompacted;
diff --git a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
index 26ffbb1..6ea6ca8 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_generator.cpp
@@ -2101,8 +2101,14 @@ fs_generator::generate_code(const cfg_t *cfg, int dispatch_width)
               spill_count, fill_count, promoted_constants, before_size, after_size,
               100.0f * (before_size - after_size) / before_size);
 
-      dump_assembly(p->store, annotation.ann_count, annotation.ann,
-                    p->devinfo);
+      if ((INTEL_DEBUG & DEBUG_DISASM) != 0) {
+        brw_disassemble(p->devinfo, p->store, start_offset, start_offset + after_size, stderr);
+        fprintf(stderr, "\n");
+      } else {
+        dump_assembly(p->store, annotation.ann_count, annotation.ann,
+                      p->devinfo);
+      }
+
       ralloc_free(annotation.mem_ctx);
    }
    assert(validated);
diff --git a/src/mesa/drivers/dri/i965/test_eu_compact.c b/src/mesa/drivers/dri/i965/test_eu_compact.c
index 874412c..aa9cd99 100644
--- a/src/mesa/drivers/dri/i965/test_eu_compact.c
+++ b/src/mesa/drivers/dri/i965/test_eu_compact.c
@@ -49,7 +49,7 @@ test_compact_instruction(struct brw_codegen *p, brw_inst src)
       if (memcmp(&unchanged, &dst, sizeof(dst))) {
 	 fprintf(stderr, "Failed to compact, but dst changed\n");
 	 fprintf(stderr, "  Instruction: ");
-	 brw_disassemble_inst(stderr, p->devinfo, &src, false);
+	 brw_disassemble_inst(stderr, p->devinfo, &src, false, NULL);
 	 return false;
       }
    }
-- 
2.7.4



More information about the mesa-dev mailing list