* 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);
}
/* 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;
+ }
+}
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);
}