const struct keybox *keybox = entry->key;
struct iris_compiled_shader *shader = entry->data;
fprintf(stderr, "%s:\n", cache_name(keybox->cache_id));
- brw_disassemble(devinfo, shader->map, 0,
- shader->prog_data->program_size, stderr);
+ brw_disassemble_with_labels(devinfo, shader->map, 0,
+ shader->prog_data->program_size, stderr);
}
}
brw_validate_instructions(devinfo, assembly, start, end, disasm_info);
+ void *mem_ctx = ralloc_context(NULL);
+ const struct brw_label *root_label =
+ brw_label_assembly(devinfo, assembly, start, end, mem_ctx);
+
foreach_list_typed(struct inst_group, group, link,
&disasm_info->group_list) {
struct exec_node *next_node = exec_node_get_next(&group->link);
int start_offset = group->offset;
int end_offset = next->offset;
- brw_disassemble(devinfo, assembly, start_offset, end_offset, out);
+ brw_disassemble(devinfo, assembly, start_offset, end_offset,
+ root_label, out);
if (group->error) {
fputs(group->error, out);
}
}
+ ralloc_free(mem_ctx);
ralloc_free(disasm_info);
}
if (unlikely(INTEL_DEBUG & DEBUG_CLIP)) {
fprintf(stderr, "clip:\n");
- brw_disassemble(compiler->devinfo,
- program, 0, *final_assembly_size, stderr);
+ brw_disassemble_with_labels(compiler->devinfo,
+ program, 0, *final_assembly_size, stderr);
fprintf(stderr, "\n");
}
if (unlikely(INTEL_DEBUG & DEBUG_SF)) {
fprintf(stderr, "sf:\n");
- brw_disassemble(compiler->devinfo,
- program, 0, *final_assembly_size, stderr);
+ brw_disassemble_with_labels(compiler->devinfo,
+ program, 0, *final_assembly_size, stderr);
fprintf(stderr, "\n");
}
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
+static void
+write_label(FILE *file, const struct gen_device_info *devinfo,
+ const struct brw_label *root_label,
+ int offset, int jump)
+{
+ if (root_label != NULL) {
+ int to_bytes_scale = sizeof(brw_inst) / brw_jump_scale(devinfo);
+ const struct brw_label *label =
+ brw_find_label(root_label, offset + jump * to_bytes_scale);
+ if (label != NULL) {
+ format(file, " LABEL%d", label->number);
+ }
+ }
+}
+
int
brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
- const brw_inst *inst, bool is_compacted)
+ const brw_inst *inst, bool is_compacted,
+ int offset, const struct brw_label *root_label)
{
int err = 0;
int space = 0;
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));
+ string(file, "JIP: ");
+ write_label(file, devinfo, root_label, offset, brw_inst_jip(devinfo, inst));
+
+ pad(file, 38);
+ string(file, "UIP: ");
+ write_label(file, devinfo, root_label, offset, brw_inst_uip(devinfo, inst));
} else if (brw_has_jip(devinfo, opcode)) {
- pad(file, 16);
+ int jip;
if (devinfo->gen >= 7) {
- format(file, "JIP: %d", brw_inst_jip(devinfo, inst));
+ jip = brw_inst_jip(devinfo, inst);
} else {
- format(file, "JIP: %d", brw_inst_gen6_jump_count(devinfo, inst));
+ jip = brw_inst_gen6_jump_count(devinfo, inst);
}
+
+ pad(file, 16);
+ string(file, "JIP: ");
+ write_label(file, devinfo, root_label, offset, jip);
} else if (devinfo->gen < 6 && (opcode == BRW_OPCODE_BREAK ||
opcode == BRW_OPCODE_CONTINUE ||
opcode == BRW_OPCODE_ELSE)) {
UNUSED FILE *fp) {}
void
-dump_assembly(void *assembly, struct disasm_info *disasm,
- const unsigned *block_latency)
+dump_assembly(void *assembly, int start_offset, int end_offset,
+ struct disasm_info *disasm, const unsigned *block_latency)
{
const struct gen_device_info *devinfo = disasm->devinfo;
const char *last_annotation_string = NULL;
const void *last_annotation_ir = NULL;
+ void *mem_ctx = ralloc_context(NULL);
+ const struct brw_label *root_label =
+ brw_label_assembly(devinfo, assembly, start_offset, end_offset, mem_ctx);
+
foreach_list_typed(struct inst_group, group, link, &disasm->group_list) {
struct exec_node *next_node = exec_node_get_next(&group->link);
if (exec_node_is_tail_sentinel(next_node))
fprintf(stderr, " %s\n", last_annotation_string);
}
- brw_disassemble(devinfo, assembly, start_offset, end_offset, stderr);
+ brw_disassemble(devinfo, assembly, start_offset, end_offset,
+ root_label, stderr);
if (group->error) {
fputs(group->error, stderr);
}
}
fprintf(stderr, "\n");
+
+ ralloc_free(mem_ctx);
}
struct disasm_info *
};
void
-dump_assembly(void *assembly, struct disasm_info *disasm,
- const unsigned *block_latency);
+dump_assembly(void *assembly, int start_offset, int end_offset,
+ struct disasm_info *disasm, const unsigned *block_latency);
struct disasm_info *
disasm_initialize(const struct gen_device_info *devinfo,
}
}
+const struct brw_label *
+brw_label_assembly(const struct gen_device_info *devinfo,
+ const void *assembly, int start, int end, void *mem_ctx)
+{
+ struct brw_label *root_label = NULL;
+
+ int to_bytes_scale = sizeof(brw_inst) / brw_jump_scale(devinfo);
+
+ for (int offset = start; offset < end;) {
+ const brw_inst *inst = (const brw_inst *) ((const char *) assembly + offset);
+ brw_inst uncompacted;
+
+ bool is_compact = brw_inst_cmpt_control(devinfo, inst);
+
+ if (is_compact) {
+ brw_compact_inst *compacted = (brw_compact_inst *)inst;
+ brw_uncompact_instruction(devinfo, &uncompacted, compacted);
+ inst = &uncompacted;
+ }
+
+ if (brw_has_uip(devinfo, brw_inst_opcode(devinfo, inst))) {
+ /* Instructions that have UIP also have JIP. */
+ brw_create_label(&root_label,
+ offset + brw_inst_uip(devinfo, inst) * to_bytes_scale, mem_ctx);
+ brw_create_label(&root_label,
+ offset + brw_inst_jip(devinfo, inst) * to_bytes_scale, mem_ctx);
+ } else if (brw_has_jip(devinfo, brw_inst_opcode(devinfo, inst))) {
+ int jip;
+ if (devinfo->gen >= 7) {
+ jip = brw_inst_jip(devinfo, inst);
+ } else {
+ jip = brw_inst_gen6_jump_count(devinfo, inst);
+ }
+
+ brw_create_label(&root_label, offset + jip * to_bytes_scale, mem_ctx);
+ }
+
+ if (is_compact) {
+ offset += sizeof(brw_compact_inst);
+ } else {
+ offset += sizeof(brw_inst);
+ }
+ }
+
+ return root_label;
+}
+
+void
+brw_disassemble_with_labels(const struct gen_device_info *devinfo,
+ const void *assembly, int start, int end, FILE *out)
+{
+ void *mem_ctx = ralloc_context(NULL);
+ const struct brw_label *root_label =
+ brw_label_assembly(devinfo, assembly, start, end, mem_ctx);
+
+ brw_disassemble(devinfo, assembly, start, end, root_label, out);
+
+ ralloc_free(mem_ctx);
+}
+
void
brw_disassemble(const struct gen_device_info *devinfo,
- const void *assembly, int start, int end, FILE *out)
+ const void *assembly, int start, int end,
+ const struct brw_label *root_label, FILE *out)
{
bool dump_hex = (INTEL_DEBUG & DEBUG_HEX) != 0;
for (int offset = start; offset < end;) {
const brw_inst *insn = (const brw_inst *)((char *)assembly + offset);
brw_inst uncompacted;
+
+ if (root_label != NULL) {
+ const struct brw_label *label = brw_find_label(root_label, offset);
+ if (label != NULL) {
+ fprintf(out, "\nLABEL%d:\n", label->number);
+ }
+ }
+
bool compacted = brw_inst_cmpt_control(devinfo, insn);
if (0)
fprintf(out, "0x%08x: ", offset);
brw_uncompact_instruction(devinfo, &uncompacted, compacted);
insn = &uncompacted;
- offset += 8;
- } else {
if (dump_hex) {
unsigned char * insn_ptr = ((unsigned char *)&insn[0]);
for (int i = 0 ; i < 16; i = i + 4) {
insn_ptr[i + 3]);
}
}
- offset += 16;
}
- brw_disassemble_inst(out, devinfo, insn, compacted);
+ brw_disassemble_inst(out, devinfo, insn, compacted, offset, root_label);
+
+ if (compacted) {
+ offset += sizeof(brw_compact_inst);
+ } else {
+ offset += sizeof(brw_inst);
+ }
}
}
const struct brw_label *brw_find_label(const struct brw_label *root, int offset);
void brw_create_label(struct brw_label **labels, int offset, void *mem_ctx);
int brw_disassemble_inst(FILE *file, const struct gen_device_info *devinfo,
- const struct brw_inst *inst, bool is_compacted);
+ const struct brw_inst *inst, bool is_compacted,
+ int offset, const struct brw_label *root_label);
+const struct brw_label *brw_label_assembly(const struct gen_device_info *devinfo,
+ const void *assembly, int start, int end,
+ void *mem_ctx);
+void brw_disassemble_with_labels(const struct gen_device_info *devinfo,
+ const void *assembly, int start, int end, FILE *out);
void brw_disassemble(const struct gen_device_info *devinfo,
- const void *assembly, int start, int end, FILE *out);
+ const void *assembly, int start, int end,
+ const struct brw_label *root_label, FILE *out);
const unsigned *brw_get_program( struct brw_codegen *p, unsigned *sz );
bool brw_try_override_assembly(struct brw_codegen *p, int start_offset,
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;
/* overriding the shader makes disasm_info invalid */
if (!brw_try_override_assembly(p, start_offset, sha1buf)) {
- dump_assembly(p->store, disasm_info, perf.block_latency);
+ dump_assembly(p->store, start_offset, p->next_insn_offset,
+ disasm_info, perf.block_latency);
} else {
fprintf(stderr, "Successfully overrode shader with sha1 %s\n\n", sha1buf);
}
/* overriding the shader makes disasm_info invalid */
if (!brw_try_override_assembly(p, 0, sha1buf)) {
- dump_assembly(p->store, disasm_info, perf.block_latency);
+ dump_assembly(p->store, 0, p->next_insn_offset,
+ disasm_info, perf.block_latency);
} else {
fprintf(stderr, "Successfully overrode shader with sha1 %s\n\n", sha1buf);
}
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, 0, NULL);
return false;
}
}
p->next_insn_offset, disasm);
if (print) {
- dump_assembly(p->store, disasm, NULL);
+ dump_assembly(p->store, 0, p->next_insn_offset, disasm, NULL);
}
ralloc_free(disasm);
}
/* Disassemble i965 instructions from buffer assembly */
- brw_disassemble(devinfo, assembly, start, end, stdout);
+ brw_disassemble_with_labels(devinfo, assembly, start, end, stdout);
result = EXIT_SUCCESS;
fprintf(stderr, "Native code for %s %s shader %s from disk cache:\n",
nir->info.label ? nir->info.label : "unnamed",
_mesa_shader_stage_to_string(nir->info.stage), nir->info.name);
- brw_disassemble(&brw->screen->devinfo, program, 0,
- prog_data->program_size, stderr);
+ brw_disassemble_with_labels(&brw->screen->devinfo, program, 0,
+ prog_data->program_size, stderr);
}
brw_upload_cache(&brw->cache, cache_id, &prog_key, brw_prog_key_size(stage),
if (unlikely(INTEL_DEBUG & DEBUG_GS)) {
fprintf(stderr, "gs:\n");
- brw_disassemble(&brw->screen->devinfo, c.func.store,
- 0, program_size, stderr);
+ brw_disassemble_with_labels(&brw->screen->devinfo, c.func.store,
+ 0, program_size, stderr);
fprintf(stderr, "\n");
}
for (unsigned i = 0; i < cache->size; i++) {
for (item = cache->items[i]; item; item = item->next) {
fprintf(stderr, "%s:\n", cache_name(i));
- brw_disassemble(&brw->screen->devinfo, cache->map,
- item->offset, item->size, stderr);
+ brw_disassemble_with_labels(&brw->screen->devinfo, cache->map,
+ item->offset, item->size, stderr);
}
}
}