i965/vec4: Don't lose the force_writemask_all flag during CSE.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_fs_vector_splitting.cpp
index a9125cad8f98cc86a1eaf21465f605b5726df345..01d3a569858b84fc1d8cf90dd538630ca349ccb5 100644 (file)
  * behavior we want for the results of texture lookups, but probably not for
  */
 
-extern "C" {
 #include "main/core.h"
 #include "brw_context.h"
-}
 #include "glsl/ir.h"
 #include "glsl/ir_visitor.h"
 #include "glsl/ir_rvalue_visitor.h"
@@ -121,8 +119,7 @@ ir_vector_reference_visitor::get_variable_entry(ir_variable *var)
       break;
    }
 
-   foreach_list(node, &this->variable_list) {
-      variable_entry *entry = (variable_entry *)node;
+   foreach_in_list(variable_entry, entry, &variable_list) {
       if (entry->var == var)
         return entry;
    }
@@ -219,8 +216,7 @@ ir_vector_splitting_visitor::get_splitting_entry(ir_variable *var)
    if (!var->type->is_vector())
       return NULL;
 
-   foreach_list(node, &*this->variable_list) {
-      variable_entry *entry = (variable_entry *)node;
+   foreach_in_list(variable_entry, entry, variable_list) {
       if (entry->var == var) {
         return entry;
       }
@@ -314,7 +310,7 @@ ir_vector_splitting_visitor::visit_leave(ir_assignment *ir)
         break;
       default:
         ir->fprint(stderr);
-        assert(!"not reached: non-channelwise dereference of LHS.");
+        unreachable("not reached: non-channelwise dereference of LHS.");
       }
 
       ir->lhs = new(mem_ctx) ir_dereference_variable(lhs->components[elem]);
@@ -338,9 +334,7 @@ brw_do_vector_splitting(exec_list *instructions)
    visit_list_elements(&refs, instructions);
 
    /* Trim out variables we can't split. */
-   foreach_list_safe(node, &refs.variable_list) {
-      variable_entry *entry = (variable_entry *)node;
-
+   foreach_in_list_safe(variable_entry, entry, &refs.variable_list) {
       if (debug) {
         fprintf(stderr, "vector %s@%p: whole_access %d\n",
                  entry->var->name, (void *) entry->var,
@@ -360,20 +354,24 @@ brw_do_vector_splitting(exec_list *instructions)
    /* Replace the decls of the vectors to be split with their split
     * components.
     */
-   foreach_list(node, &refs.variable_list) {
-      variable_entry *entry = (variable_entry *)node;
+   foreach_in_list(variable_entry, entry, &refs.variable_list) {
       const struct glsl_type *type;
       type = glsl_type::get_instance(entry->var->type->base_type, 1, 1);
 
       entry->mem_ctx = ralloc_parent(entry->var);
 
       for (unsigned int i = 0; i < entry->var->type->vector_elements; i++) {
-        const char *name = ralloc_asprintf(mem_ctx, "%s_%c",
-                                           entry->var->name,
-                                           "xyzw"[i]);
+         char *const name = ir_variable::temporaries_allocate_names
+            ? ralloc_asprintf(mem_ctx, "%s_%c",
+                              entry->var->name,
+                              "xyzw"[i])
+            : NULL;
 
         entry->components[i] = new(entry->mem_ctx) ir_variable(type, name,
                                                                ir_var_temporary);
+
+         ralloc_free(name);
+
         entry->var->insert_before(entry->components[i]);
       }