glsl: Add the possibility for ir_variable to have a non-ralloced name
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 8 Jul 2014 23:57:33 +0000 (16:57 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 30 Sep 2014 20:34:42 +0000 (13:34 -0700)
Specifically, ir_var_temporary variables constructed with a NULL name
will all have the name "compiler_temp" in static storage.

No change Valgrind massif results for a trimmed apitrace of dota2.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_validate.cpp

index 0ae9b899c0a9f3d39329a1d0c4d07d427d06312f..9c58f869dc46495a76426da3333dee37d835f13c 100644 (file)
@@ -1543,12 +1543,30 @@ ir_swizzle::variable_referenced() const
 }
 
 
+const char ir_variable::tmp_name[] = "compiler_temp";
+
 ir_variable::ir_variable(const struct glsl_type *type, const char *name,
                         ir_variable_mode mode)
    : ir_instruction(ir_type_variable)
 {
    this->type = type;
-   this->name = ralloc_strdup(this, name);
+
+   /* The ir_variable clone method may call this constructor with name set to
+    * tmp_name.
+    */
+   assert(name != NULL
+          || mode == ir_var_temporary
+          || mode == ir_var_function_in
+          || mode == ir_var_function_out
+          || mode == ir_var_function_inout);
+   assert(name != ir_variable::tmp_name
+          || mode == ir_var_temporary);
+   if (mode == ir_var_temporary
+       && (name == NULL || name == ir_variable::tmp_name)) {
+      this->name = ir_variable::tmp_name;
+   } else {
+      this->name = ralloc_strdup(this, name);
+   }
 
    this->u.max_ifc_array_access = NULL;
 
index f2186a5af8a3ea41804fd8381ad80962c178998f..3c947412f40db3b4e60fd5ba9c972c7f610b90c6 100644 (file)
@@ -575,6 +575,11 @@ public:
       return this->u.state_slots;
    }
 
+   inline bool is_name_ralloced() const
+   {
+      return this->name != ir_variable::tmp_name;
+   }
+
    /**
     * Enable emitting extension warnings for this variable
     */
@@ -886,6 +891,11 @@ private:
     * \sa ir_variable::location
     */
    const glsl_type *interface_type;
+
+   /**
+    * Name used for anonymous compiler temporaries
+    */
+   static const char tmp_name[];
 };
 
 /**
index 51598629117f317c55fdc7b04983e11f1c7536fd..5a6f8bbf5ee4ac585b55b6b010298f0e8bc64681 100644 (file)
@@ -654,7 +654,7 @@ ir_validate::visit(ir_variable *ir)
     * in the ir_dereference_variable handler to ensure that a variable is
     * declared before it is dereferenced.
     */
-   if (ir->name)
+   if (ir->name && ir->is_name_ralloced())
       assert(ralloc_parent(ir->name) == ir);
 
    hash_table_insert(ht, ir, ir);