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
index 25bbe2f2defa9c1ea143168b9788b43cc98be13a,ddd4b7326622277249ea9fdc4a52c36fe3a68bb2..33eb27533fd916f3fd1eb4583c6d2c0682ec7815
@@@ -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
index 6db5073f75f51ba4e3f87a15ad9aebfa1d326ac6,5ffd3fc00b2ccbc0bb528023e8207dbdeb589e24..84176383fca83c1e1d8048db0e8fc8c7e663ba6d
@@@ -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;
 +   }
 +}
index 851c0dd9f7b1c4c8f75ab48dbd0c055b96e5ba59,8a1cf4f1d24384c753ef041aaddd514677b9d115..e55780c940eb4a06f4b4c042c58a3a29beab624d
@@@ -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);
        }