From 34ed45557e9b8a834af2816e774165a0ee7acdd2 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 21 Oct 2015 15:23:10 -0700 Subject: [PATCH] i965: Add annotation_insert_error() and support for printing errors. Will allow annotations to contain error messages (indicating an instruction violates a rule for instance) that are printed after the disassembly of the block. Reviewed-by: Kenneth Graunke --- .../drivers/dri/i965/intel_asm_annotation.c | 71 +++++++++++++++++-- .../drivers/dri/i965/intel_asm_annotation.h | 7 ++ 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c b/src/mesa/drivers/dri/i965/intel_asm_annotation.c index fe9d80a5e67..52878fde43e 100644 --- a/src/mesa/drivers/dri/i965/intel_asm_annotation.c +++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.c @@ -69,6 +69,10 @@ dump_assembly(void *assembly, int num_annotations, struct annotation *annotation brw_disassemble(devinfo, assembly, start_offset, end_offset, stderr); + if (annotation[i].error) { + fputs(annotation[i].error, stderr); + } + if (annotation[i].block_end) { fprintf(stderr, " END B%d", annotation[i].block_end->num); foreach_list_typed(struct bblock_link, successor_link, link, @@ -82,25 +86,34 @@ dump_assembly(void *assembly, int num_annotations, struct annotation *annotation fprintf(stderr, "\n"); } -void annotate(const struct brw_device_info *devinfo, - struct annotation_info *annotation, const struct cfg_t *cfg, - struct backend_instruction *inst, unsigned offset) +static bool +annotation_array_ensure_space(struct annotation_info *annotation) { - if (annotation->mem_ctx == NULL) - annotation->mem_ctx = ralloc_context(NULL); - if (annotation->ann_size <= annotation->ann_count) { int old_size = annotation->ann_size; annotation->ann_size = MAX2(1024, annotation->ann_size * 2); annotation->ann = reralloc(annotation->mem_ctx, annotation->ann, struct annotation, annotation->ann_size); if (!annotation->ann) - return; + return false; memset(annotation->ann + old_size, 0, (annotation->ann_size - old_size) * sizeof(struct annotation)); } + return true; +} + +void annotate(const struct brw_device_info *devinfo, + struct annotation_info *annotation, const struct cfg_t *cfg, + struct backend_instruction *inst, unsigned offset) +{ + if (annotation->mem_ctx == NULL) + annotation->mem_ctx = ralloc_context(NULL); + + if (!annotation_array_ensure_space(annotation)) + return; + struct annotation *ann = &annotation->ann[annotation->ann_count++]; ann->offset = offset; if ((INTEL_DEBUG & DEBUG_ANNOTATION) != 0) { @@ -156,3 +169,47 @@ annotation_finalize(struct annotation_info *annotation, } annotation->ann[annotation->ann_count].offset = next_inst_offset; } + +void +annotation_insert_error(struct annotation_info *annotation, unsigned offset, + const char *error) +{ + struct annotation *ann; + + if (!annotation->ann_count) + return; + + /* We may have to split an annotation, so ensure we have enough space + * allocated for that case up front. + */ + if (!annotation_array_ensure_space(annotation)) + return; + + for (int i = 0; i < annotation->ann_count; i++) { + struct annotation *cur = &annotation->ann[i]; + struct annotation *next = &annotation->ann[i + 1]; + ann = cur; + + if (next->offset <= offset) + continue; + + if (offset + sizeof(brw_inst) != next->offset) { + memmove(next, cur, + (annotation->ann_count - i + 2) * sizeof(struct annotation)); + cur->error = NULL; + cur->error_length = 0; + cur->block_end = NULL; + next->offset = offset + sizeof(brw_inst); + next->block_start = NULL; + annotation->ann_count++; + } + break; + } + + assume(ann != NULL); + + if (ann->error) + ralloc_strcat(&ann->error, error); + else + ann->error = ralloc_strdup(annotation->mem_ctx, error); +} diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.h b/src/mesa/drivers/dri/i965/intel_asm_annotation.h index 6c72326f058..662a4b4e0f7 100644 --- a/src/mesa/drivers/dri/i965/intel_asm_annotation.h +++ b/src/mesa/drivers/dri/i965/intel_asm_annotation.h @@ -37,6 +37,9 @@ struct cfg_t; struct annotation { int offset; + size_t error_length; + char *error; + /* Pointers to the basic block in the CFG if the instruction group starts * or ends a basic block. */ @@ -69,6 +72,10 @@ annotate(const struct brw_device_info *devinfo, void annotation_finalize(struct annotation_info *annotation, unsigned offset); +void +annotation_insert_error(struct annotation_info *annotation, unsigned offset, + const char *error); + #ifdef __cplusplus } /* extern "C" */ #endif -- 2.30.2