i965/fs: Debug the optimization passes by dumping instr to file.
authorMatt Turner <mattst88@gmail.com>
Mon, 7 Apr 2014 17:25:50 +0000 (10:25 -0700)
committerMatt Turner <mattst88@gmail.com>
Sun, 1 Jun 2014 20:18:52 +0000 (13:18 -0700)
With INTEL_DEBUG=optimizer, write the output of dump_instructions() to a
file each time an optimization pass makes progress. This lets you easily
diff successive files to see what an optimization pass did.

Example filenames written when running glxgears:
   fs8-0000-00-start
   fs8-0000-01-04-opt_copy_propagate
   fs8-0000-01-06-dead_code_eliminate
   fs8-0000-01-12-compute_to_mrf
   fs8-0000-02-06-dead_code_eliminate
        |   |  |   |
        |   |  |   `-- optimization pass name
        |   |  |
        |   |  `-- optimization pass number in the loop
        |   |
        |   `-- optimization loop interation
        |
        `-- shader program number

Note that with INTEL_DEBUG=optimizer, we disable compact_virtual_grfs,
so that we can diff instruction lists across loop interations without
the register numbers being changes.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_fs.cpp

index c9b31fef5b2af715129051d9af470646ffb63ee3..1a83c8c2c2c2641434d6347a524caa90d45ac667 100644 (file)
@@ -1714,6 +1714,9 @@ fs_visitor::split_virtual_grfs()
 void
 fs_visitor::compact_virtual_grfs()
 {
+   if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER))
+      return;
+
    /* Mark which virtual GRFs are used, and count how many. */
    int remap_table[this->virtual_grf_count];
    memset(remap_table, -1, sizeof(remap_table));
@@ -3020,24 +3023,50 @@ fs_visitor::run()
 
       opt_drop_redundant_mov_to_flags();
 
+#define OPT(pass, args...) do {                                            \
+      pass_num++;                                                          \
+      bool this_progress = pass(args);                                     \
+                                                                           \
+      if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER) && this_progress) {      \
+         char filename[64];                                                \
+         snprintf(filename, 64, "fs%d-%04d-%02d-%02d-" #pass,              \
+                  dispatch_width, shader_prog->Name, iteration, pass_num); \
+                                                                           \
+         backend_visitor::dump_instructions(filename);                     \
+      }                                                                    \
+                                                                           \
+      progress = progress || this_progress;                                \
+   } while (false)
+
+      if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER)) {
+         char filename[64];
+         snprintf(filename, 64, "fs%d-%04d-00-start",
+                  dispatch_width, shader_prog->Name);
+
+         backend_visitor::dump_instructions(filename);
+      }
+
       bool progress;
+      int iteration = 0;
       do {
         progress = false;
+         iteration++;
+         int pass_num = 0;
 
          compact_virtual_grfs();
 
-        progress = remove_duplicate_mrf_writes() || progress;
-
-        progress = opt_algebraic() || progress;
-        progress = opt_cse() || progress;
-        progress = opt_copy_propagate() || progress;
-         progress = opt_peephole_predicated_break() || progress;
-         progress = dead_code_eliminate() || progress;
-         progress = opt_peephole_sel() || progress;
-         progress = dead_control_flow_eliminate(this) || progress;
-         progress = opt_saturate_propagation() || progress;
-         progress = register_coalesce() || progress;
-        progress = compute_to_mrf() || progress;
+         OPT(remove_duplicate_mrf_writes);
+
+         OPT(opt_algebraic);
+         OPT(opt_cse);
+         OPT(opt_copy_propagate);
+         OPT(opt_peephole_predicated_break);
+         OPT(dead_code_eliminate);
+         OPT(opt_peephole_sel);
+         OPT(dead_control_flow_eliminate, this);
+         OPT(opt_saturate_propagation);
+         OPT(register_coalesce);
+         OPT(compute_to_mrf);
       } while (progress);
 
       lower_uniform_pull_constant_loads();