[Mesa-dev] [PATCH 3/5] i965: Give dump_instructions() a filename argument.

Matt Turner mattst88 at gmail.com
Fri May 30 19:35:21 PDT 2014


This will allow debugging code to dump the IR after an optimization pass
makes progress (the next patch). Only let it open and write to a file if
the effective user isn't root.
---
 src/mesa/drivers/dri/i965/brw_fs.cpp              | 22 +++++++++++++++++++---
 src/mesa/drivers/dri/i965/brw_fs.h                |  1 +
 src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp |  2 +-
 src/mesa/drivers/dri/i965/brw_shader.cpp          | 22 ++++++++++++++++++++--
 src/mesa/drivers/dri/i965/brw_shader.h            |  1 +
 5 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8bd3f61..c9b31fe 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -2571,17 +2571,33 @@ fs_visitor::lower_uniform_pull_constant_loads()
 void
 fs_visitor::dump_instructions()
 {
+   dump_instructions(NULL);
+}
+
+void
+fs_visitor::dump_instructions(const char *name)
+{
    calculate_register_pressure();
+   FILE *file = stderr;
+   if (name && geteuid() != 0) {
+      file = fopen(name, "w");
+      if (!file)
+         file = stderr;
+   }
 
    int ip = 0, max_pressure = 0;
    foreach_list(node, &this->instructions) {
       backend_instruction *inst = (backend_instruction *)node;
       max_pressure = MAX2(max_pressure, regs_live_at_ip[ip]);
-      fprintf(stderr, "{%3d} %4d: ", regs_live_at_ip[ip], ip);
-      dump_instruction(inst);
+      fprintf(file, "{%3d} %4d: ", regs_live_at_ip[ip], ip);
+      dump_instruction(inst, file);
       ++ip;
    }
-   fprintf(stderr, "Maximum %3d registers live at once.\n", max_pressure);
+   fprintf(file, "Maximum %3d registers live at once.\n", max_pressure);
+
+   if (file != stderr) {
+      fclose(file);
+   }
 }
 
 void
diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index 90cf6fb..789f0b3 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -484,6 +484,7 @@ public:
    int implied_mrf_writes(fs_inst *inst);
 
    virtual void dump_instructions();
+   virtual void dump_instructions(const char *name);
    void dump_instruction(backend_instruction *inst);
    void dump_instruction(backend_instruction *inst, FILE *file);
 
diff --git a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
index 717a94e..bbaf810 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_reg_allocate.cpp
@@ -498,7 +498,7 @@ fs_visitor::assign_regs(bool allow_spilling)
 
       if (reg == -1) {
          fail("no register to spill:\n");
-         dump_instructions();
+         dump_instructions(NULL);
       } else if (allow_spilling) {
          spill_reg(reg);
       }
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index f4f1334..69eab59 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -700,11 +700,29 @@ backend_instruction::has_side_effects() const
 void
 backend_visitor::dump_instructions()
 {
+   dump_instructions(NULL);
+}
+
+void
+backend_visitor::dump_instructions(const char *name)
+{
+   FILE *file = stderr;
+   if (name && geteuid() != 0) {
+      file = fopen(name, "w");
+      if (!file)
+         file = stderr;
+   }
+
    int ip = 0;
    foreach_list(node, &this->instructions) {
       backend_instruction *inst = (backend_instruction *)node;
-      fprintf(stderr, "%d: ", ip++);
-      dump_instruction(inst);
+      if (!name)
+         fprintf(stderr, "%d: ", ip++);
+      dump_instruction(inst, file);
+   }
+
+   if (file != stderr) {
+      fclose(file);
    }
 }
 
diff --git a/src/mesa/drivers/dri/i965/brw_shader.h b/src/mesa/drivers/dri/i965/brw_shader.h
index 0dc8778..222b0a9 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.h
+++ b/src/mesa/drivers/dri/i965/brw_shader.h
@@ -111,6 +111,7 @@ public:
    virtual void dump_instruction(backend_instruction *inst) = 0;
    virtual void dump_instruction(backend_instruction *inst, FILE *file) = 0;
    virtual void dump_instructions();
+   virtual void dump_instructions(const char *name);
 
    void assign_common_binding_table_offsets(uint32_t next_binding_table_offset);
 
-- 
1.8.3.2



More information about the mesa-dev mailing list