summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2011-08-17 10:50:17 -0700
committerEric Anholt <[email protected]>2011-08-19 17:06:29 -0700
commit8174945d3346dc049ae56dcb4bf1eab39f5c88aa (patch)
treef90feb78c9d39371a3baa63d6b9d04ca4c20350b /src/mesa
parent3dadc1e3cceac80a1b63cad2e10f0e0f8904531b (diff)
i965/vs: Add simple dead code elimination.
This is copied right from the fragment shader. It is needed for real register allocation to work correctly.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/dri/i965/brw_vec4.cpp31
-rw-r--r--src/mesa/drivers/dri/i965/brw_vec4.h1
-rw-r--r--src/mesa/drivers/dri/i965/brw_vec4_emit.cpp6
3 files changed, 38 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp
index a3ed31a9da0..760bc1f7acd 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp
@@ -127,4 +127,35 @@ vec4_visitor::virtual_grf_interferes(int a, int b)
return start < end;
}
+/**
+ * Must be called after calculate_live_intervales() to remove unused
+ * writes to registers -- register allocation will fail otherwise
+ * because something deffed but not used won't be considered to
+ * interfere with other regs.
+ */
+bool
+vec4_visitor::dead_code_eliminate()
+{
+ bool progress = false;
+ int pc = 0;
+
+ calculate_live_intervals();
+
+ foreach_list_safe(node, &this->instructions) {
+ vec4_instruction *inst = (vec4_instruction *)node;
+
+ if (inst->dst.file == GRF && this->virtual_grf_use[inst->dst.reg] <= pc) {
+ inst->remove();
+ progress = true;
+ }
+
+ pc++;
+ }
+
+ if (progress)
+ live_intervals_valid = false;
+
+ return progress;
+}
+
} /* namespace brw */
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 77a28c7cda7..1db910e2b99 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -381,6 +381,7 @@ public:
void reg_allocate();
void move_grf_array_access_to_scratch();
void calculate_live_intervals();
+ bool dead_code_eliminate();
bool virtual_grf_interferes(int a, int b);
vec4_instruction *emit(enum opcode opcode);
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
index 011af6f2d3e..65ac7d9dc09 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
@@ -558,6 +558,12 @@ vec4_visitor::run()
*/
move_grf_array_access_to_scratch();
+ bool progress;
+ do {
+ progress = false;
+ progress = dead_code_eliminate() || progress;
+ } while (progress);
+
if (failed)
return false;