i965: Add annotation_insert_error() and support for printing errors.
authorMatt Turner <mattst88@gmail.com>
Wed, 21 Oct 2015 22:23:10 +0000 (15:23 -0700)
committerMatt Turner <mattst88@gmail.com>
Thu, 12 Nov 2015 19:00:10 +0000 (11:00 -0800)
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 <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/intel_asm_annotation.c
src/mesa/drivers/dri/i965/intel_asm_annotation.h

index fe9d80a5e6751650b1fd0c1acb08fd1d29316315..52878fde43eb5f14518ea4a39206e22766594627 100644 (file)
@@ -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);
+}
index 6c72326f058d5d6b684d25f825b7387cc36f9bd5..662a4b4e0f7b40fdc915a36f3812bdf4f3914e05 100644 (file)
@@ -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