[Mesa-dev] [PATCH 6/9] i965: Add annotation_insert_error() and support for printing errors.

Matt Turner mattst88 at gmail.com
Wed Oct 21 15:58:14 PDT 2015


Will allow annotations to contain error messages (indicating an
instruction violates a rule for instance) that are printed after the
disassembly of the block.
---
 src/mesa/drivers/dri/i965/intel_asm_annotation.c | 60 ++++++++++++++++++++++++
 src/mesa/drivers/dri/i965/intel_asm_annotation.h |  7 +++
 2 files changed, 67 insertions(+)

diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.c b/src/mesa/drivers/dri/i965/intel_asm_annotation.c
index 58830db..eaee386 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,
@@ -152,3 +156,59 @@ 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 = NULL;
+
+   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->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;
+
+      memset(annotation->ann + old_size, 0,
+             (annotation->ann_size - old_size) * sizeof(struct annotation));
+   }
+
+   for (int i = 0; i <= annotation->ann_count; i++) {
+      if (annotation->ann[i].offset <= offset)
+         continue;
+
+      struct annotation *cur = &annotation->ann[i - 1];
+      struct annotation *next = &annotation->ann[i];
+      ann = cur;
+
+      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);
+
+   ralloc_asprintf_rewrite_tail(&ann->error, &ann->error_length, error);
+
+   /* FIXME: ralloc_vasprintf_rewrite_tail() allocates memory out of the
+    * null context. We have to reparent the it if we want it to be freed
+    * with the rest of the annotation context.
+    */
+   ralloc_steal(annotation->mem_ctx, ann->error);
+}
diff --git a/src/mesa/drivers/dri/i965/intel_asm_annotation.h b/src/mesa/drivers/dri/i965/intel_asm_annotation.h
index 6c72326..662a4b4 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.4.9



More information about the mesa-dev mailing list