Merge remote branch 'cworth/master'
authorEric Anholt <eric@anholt.net>
Thu, 24 Jun 2010 22:13:03 +0000 (15:13 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 24 Jun 2010 22:13:03 +0000 (15:13 -0700)
Conflicts:
ast_to_hir.cpp
ir.cpp

This brings in the talloc-based memory management work, so that the
compiler (almost) no longer leaks memory.

1  2 
ast_to_hir.cpp
ir.cpp
ir_clone.cpp
ir_function_inlining.cpp

diff --cc ast_to_hir.cpp
@@@ -519,17 -522,16 +522,19 @@@ do_assignment(exec_list *instructions, 
      * temporary and return a deref of that temporary.  If the rvalue
      * ends up not being used, the temp will get copy-propagated out.
      */
-    ir_variable *var = new ir_variable(rhs->type, "assignment_tmp");
+    ir_variable *var = new(ctx) ir_variable(rhs->type, "assignment_tmp");
 -   instructions->push_tail(new(ctx) ir_assignment(new(ctx) ir_dereference_variable(var),
++   ir_dereference_variable *deref_var = new(ctx) ir_dereference_variable(var);
 +   instructions->push_tail(var);
-    instructions->push_tail(new ir_assignment(new ir_dereference_variable(var),
-                                            rhs,
-                                            NULL));
++   instructions->push_tail(new(ctx) ir_assignment(deref_var,
+                                                 rhs,
+                                                 NULL));
++   deref_var = new(ctx) ir_dereference_variable(var);
  
-    instructions->push_tail(new ir_assignment(lhs,
-                                            new ir_dereference_variable(var),
-                                            NULL));
+    instructions->push_tail(new(ctx) ir_assignment(lhs,
 -                                                new(ctx) ir_dereference_variable(var),
++                                                deref_var,
+                                                 NULL));
  
-    return new ir_dereference_variable(var);
+    return new(ctx) ir_dereference_variable(var);
  }
  
  
diff --cc ir.cpp
Simple merge
diff --cc ir_clone.cpp
@@@ -238,36 -251,3 +251,37 @@@ ir_function_signature::clone(struct has
     /* FINISHME */
     abort();
  }
-       return new ir_constant(this->type, &this->value);
 +
 +ir_instruction *
 +ir_constant::clone(struct hash_table *ht) const
 +{
++   void *ctx = talloc_parent(this);
 +   (void)ht;
 +
 +   switch (this->type->base_type) {
 +   case GLSL_TYPE_UINT:
 +   case GLSL_TYPE_INT:
 +   case GLSL_TYPE_FLOAT:
 +   case GLSL_TYPE_BOOL:
-       ir_constant *c = new ir_constant;
++      return new(ctx) ir_constant(this->type, &this->value);
 +
 +   case GLSL_TYPE_STRUCT: {
++      ir_constant *c = new(ctx) ir_constant;
 +
 +      c->type = this->type;
 +      for (exec_node *node = this->components.head
 +            ; !node->is_tail_sentinal()
 +            ; node = node->next) {
 +       ir_constant *const orig = (ir_constant *) node;
 +
 +       c->components.push_tail(orig->clone(NULL));
 +      }
 +
 +      return c;
 +   }
 +
 +   default:
 +      assert(!"Should not get here."); break;
 +      return NULL;
 +   }
 +}
@@@ -91,26 -91,6 +91,27 @@@ do_function_inlining(exec_list *instruc
     return v.progress;
  }
  
-        ir_rvalue *lhs = new ir_dereference_variable(retval);
-        ret->insert_before(new ir_assignment(lhs, ret->value, NULL));
 +static void
 +replace_return_with_assignment(ir_instruction *ir, void *data)
 +{
++   void *ctx = talloc_parent(ir);
 +   ir_variable *retval = (ir_variable *)data;
 +   ir_return *ret = ir->as_return();
 +
 +   if (ret) {
 +      if (ret->value) {
++       ir_rvalue *lhs = new(ctx) ir_dereference_variable(retval);
++       ret->insert_before(new(ctx) ir_assignment(lhs, ret->value, NULL));
 +       ret->remove();
 +      } else {
 +       /* un-valued return has to be the last return, or we shouldn't
 +        * have reached here. (see can_inline()).
 +        */
 +       assert(!ret->next->is_tail_sentinal());
 +      }
 +   }
 +}
 +
  ir_rvalue *
  ir_call::generate_inline(ir_instruction *next_ir)
  {
        next_ir->insert_before(parameters[i]);
  
        /* Move the actual param into our param variable if it's an 'in' type. */
 -      if (parameters[i]->mode == ir_var_in ||
 -        parameters[i]->mode == ir_var_inout) {
 +      if (sig_param->mode == ir_var_in ||
 +        sig_param->mode == ir_var_inout) {
         ir_assignment *assign;
  
-        assign = new ir_assignment(new ir_dereference_variable(parameters[i]),
-                                   param, NULL);
+        assign = new(ctx) ir_assignment(new(ctx) ir_dereference_variable(parameters[i]),
+                                        param, NULL);
         next_ir->insert_before(assign);
        }