i965/fs: Use offset a lot more places
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_cse.cpp
index 381c5697f1056a60880e88a9214b61e4d83333f7..7edbe1915c2fdbbe2d45070c8a89c1daa2cbcddd 100644 (file)
@@ -103,7 +103,7 @@ is_expression(const fs_inst *const inst)
    case SHADER_OPCODE_LOAD_PAYLOAD:
       return !is_copy_payload(inst);
    default:
-      return inst->is_tex();
+      return inst->is_send_from_grf() && !inst->has_side_effects();
    }
 }
 
@@ -157,7 +157,6 @@ instructions_match(fs_inst *a, fs_inst *b)
                           a->mlen == b->mlen &&
                           a->regs_written == b->regs_written &&
                           a->base_mrf == b->base_mrf &&
-                          a->sampler == b->sampler &&
                           a->eot == b->eot &&
                           a->header_present == b->header_present &&
                           a->shadow_compare == b->shadow_compare)
@@ -166,9 +165,10 @@ instructions_match(fs_inst *a, fs_inst *b)
 }
 
 bool
-fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
+fs_visitor::opt_cse_local(bblock_t *block)
 {
    bool progress = false;
+   exec_list aeb;
 
    void *cse_ctx = ralloc_context(NULL);
 
@@ -180,7 +180,7 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
       {
          bool found = false;
 
-         foreach_in_list_use_after(aeb_entry, entry, aeb) {
+         foreach_in_list_use_after(aeb_entry, entry, &aeb) {
             /* Match current instruction's expression against those in AEB. */
             if (instructions_match(inst, entry->generator)) {
                found = true;
@@ -194,7 +194,7 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
             aeb_entry *entry = ralloc(cse_ctx, aeb_entry);
             entry->tmp = reg_undef;
             entry->generator = inst;
-            aeb->push_tail(entry);
+            aeb.push_tail(entry);
          } else {
             /* This is at least our second sighting of this expression.
              * If we don't have a temporary already, make one.
@@ -212,17 +212,15 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
                fs_inst *copy;
                if (written > 1) {
                   fs_reg *sources = ralloc_array(mem_ctx, fs_reg, written);
-                  for (int i = 0; i < written; i++) {
-                     sources[i] = tmp;
-                     sources[i].reg_offset = i;
-                  }
+                  for (int i = 0; i < written; i++)
+                     sources[i] = offset(tmp, i);
                   copy = LOAD_PAYLOAD(orig_dst, sources, written);
                } else {
                   copy = MOV(orig_dst, tmp);
                   copy->force_writemask_all =
                      entry->generator->force_writemask_all;
                }
-               entry->generator->insert_after(copy);
+               entry->generator->insert_after(block, copy);
             }
 
             /* dest <- temp */
@@ -235,16 +233,14 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
                fs_inst *copy;
                if (written > 1) {
                   fs_reg *sources = ralloc_array(mem_ctx, fs_reg, written);
-                  for (int i = 0; i < written; i++) {
-                     sources[i] = tmp;
-                     sources[i].reg_offset = i;
-                  }
+                  for (int i = 0; i < written; i++)
+                     sources[i] = offset(tmp, i);
                   copy = LOAD_PAYLOAD(dst, sources, written);
                } else {
                   copy = MOV(dst, tmp);
                   copy->force_writemask_all = inst->force_writemask_all;
                }
-               inst->insert_before(copy);
+               inst->insert_before(block, copy);
             }
 
             /* Set our iterator so that next time through the loop inst->next
@@ -253,18 +249,12 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
              */
             fs_inst *prev = (fs_inst *)inst->prev;
 
-            inst->remove();
-
-            /* Appending an instruction may have changed our bblock end. */
-            if (inst == block->end) {
-               block->end = prev;
-            }
-
+            inst->remove(block);
             inst = prev;
          }
       }
 
-      foreach_in_list_safe(aeb_entry, entry, aeb) {
+      foreach_in_list_safe(aeb_entry, entry, &aeb) {
          /* Kill all AEB entries that write a different value to or read from
           * the flag register if we just wrote it.
           */
@@ -306,9 +296,6 @@ fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
 
    ralloc_free(cse_ctx);
 
-   if (progress)
-      invalidate_live_intervals();
-
    return progress;
 }
 
@@ -319,14 +306,12 @@ fs_visitor::opt_cse()
 
    calculate_live_intervals();
 
-   cfg_t cfg(&instructions);
-
-   for (int b = 0; b < cfg.num_blocks; b++) {
-      bblock_t *block = cfg.blocks[b];
-      exec_list aeb;
-
-      progress = opt_cse_local(block, &aeb) || progress;
+   foreach_block (block, cfg) {
+      progress = opt_cse_local(block) || progress;
    }
 
+   if (progress)
+      invalidate_live_intervals();
+
    return progress;
 }