X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglsl%2Fir_clone.cpp;h=4314efa76d402e12ed3ed293521b126da2d894fc;hb=d7949eefcba39d48edd8af53f2d88d58f8cd5381;hp=c7b786f0c4828766784a358b0e2d8b4277942266;hpb=4e6a3e0d2d148747002ab9e9c1dffe63e912c688;p=mesa.git diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index c7b786f0c48..4314efa76d4 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -22,10 +22,16 @@ */ #include +#include "main/compiler.h" #include "ir.h" #include "glsl_types.h" -extern "C" { -#include "hash_table.h" +#include "program/hash_table.h" + +ir_rvalue * +ir_rvalue::clone(void *mem_ctx, struct hash_table *ht) const +{ + /* The only possible instantiation is the generic error value. */ + return error_value(mem_ctx); } /** @@ -36,25 +42,44 @@ extern "C" { * eventually. */ ir_variable * -ir_variable::clone(struct hash_table *ht) const +ir_variable::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_variable *var = new(ctx) ir_variable(type, name); + ir_variable *var = new(mem_ctx) ir_variable(this->type, this->name, + (ir_variable_mode) this->mode); var->max_array_access = this->max_array_access; var->read_only = this->read_only; var->centroid = this->centroid; var->invariant = this->invariant; - var->shader_in = this->shader_in; - var->shader_out = this->shader_out; - var->mode = this->mode; var->interpolation = this->interpolation; - var->array_lvalue = this->array_lvalue; var->location = this->location; + var->index = this->index; + var->uniform_block = this->uniform_block; var->warn_extension = this->warn_extension; + var->origin_upper_left = this->origin_upper_left; + var->pixel_center_integer = this->pixel_center_integer; + var->explicit_location = this->explicit_location; + var->explicit_index = this->explicit_index; + var->has_initializer = this->has_initializer; + var->depth_layout = this->depth_layout; + + var->num_state_slots = this->num_state_slots; + if (this->state_slots) { + /* FINISHME: This really wants to use something like talloc_reference, but + * FINISHME: ralloc doesn't have any similar function. + */ + var->state_slots = ralloc_array(var, ir_state_slot, + this->num_state_slots); + memcpy(var->state_slots, this->state_slots, + sizeof(this->state_slots[0]) * var->num_state_slots); + } if (this->constant_value) - var->constant_value = this->constant_value->clone(ht); + var->constant_value = this->constant_value->clone(mem_ctx, ht); + + if (this->constant_initializer) + var->constant_initializer = + this->constant_initializer->clone(mem_ctx, ht); if (ht) { hash_table_insert(ht, var, (void *)const_cast(this)); @@ -64,118 +89,115 @@ ir_variable::clone(struct hash_table *ht) const } ir_swizzle * -ir_swizzle::clone(struct hash_table *ht) const +ir_swizzle::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_swizzle(this->val->clone(ht), this->mask); + return new(mem_ctx) ir_swizzle(this->val->clone(mem_ctx, ht), this->mask); } ir_return * -ir_return::clone(struct hash_table *ht) const +ir_return::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_rvalue *new_value = NULL; if (this->value) - new_value = this->value->clone(ht); + new_value = this->value->clone(mem_ctx, ht); - return new(ctx) ir_return(new_value); + return new(mem_ctx) ir_return(new_value); } ir_discard * -ir_discard::clone(struct hash_table *ht) const +ir_discard::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_rvalue *new_condition = NULL; if (this->condition != NULL) - new_condition = this->condition->clone(ht); + new_condition = this->condition->clone(mem_ctx, ht); - return new(ctx) ir_discard(new_condition); + return new(mem_ctx) ir_discard(new_condition); } ir_loop_jump * -ir_loop_jump::clone(struct hash_table *ht) const +ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); (void)ht; - return new(ctx) ir_loop_jump(this->mode); + return new(mem_ctx) ir_loop_jump(this->mode); } ir_if * -ir_if::clone(struct hash_table *ht) const +ir_if::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_if *new_if = new(ctx) ir_if(this->condition->clone(ht)); + ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht)); foreach_iter(exec_list_iterator, iter, this->then_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_if->then_instructions.push_tail(ir->clone(ht)); + new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht)); } foreach_iter(exec_list_iterator, iter, this->else_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_if->else_instructions.push_tail(ir->clone(ht)); + new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht)); } return new_if; } ir_loop * -ir_loop::clone(struct hash_table *ht) const +ir_loop::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_loop *new_loop = new(ctx) ir_loop(); + ir_loop *new_loop = new(mem_ctx) ir_loop(); if (this->from) - new_loop->from = this->from->clone(ht); + new_loop->from = this->from->clone(mem_ctx, ht); if (this->to) - new_loop->to = this->to->clone(ht); + new_loop->to = this->to->clone(mem_ctx, ht); if (this->increment) - new_loop->increment = this->increment->clone(ht); + new_loop->increment = this->increment->clone(mem_ctx, ht); new_loop->counter = counter; foreach_iter(exec_list_iterator, iter, this->body_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_loop->body_instructions.push_tail(ir->clone(ht)); + new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht)); } + new_loop->cmp = this->cmp; return new_loop; } ir_call * -ir_call::clone(struct hash_table *ht) const +ir_call::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); + ir_dereference_variable *new_return_ref = NULL; + if (this->return_deref != NULL) + new_return_ref = this->return_deref->clone(mem_ctx, ht); + exec_list new_parameters; foreach_iter(exec_list_iterator, iter, this->actual_parameters) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_parameters.push_tail(ir->clone(ht)); + new_parameters.push_tail(ir->clone(mem_ctx, ht)); } - return new(ctx) ir_call(this->callee, &new_parameters); + return new(mem_ctx) ir_call(this->callee, new_return_ref, &new_parameters); } ir_expression * -ir_expression::clone(struct hash_table *ht) const +ir_expression::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_rvalue *op[2] = {NULL, NULL}; + ir_rvalue *op[Elements(this->operands)] = { NULL, }; unsigned int i; for (i = 0; i < get_num_operands(); i++) { - op[i] = this->operands[i]->clone(ht); + op[i] = this->operands[i]->clone(mem_ctx, ht); } - return new(ctx) ir_expression(this->operation, this->type, op[0], op[1]); + return new(mem_ctx) ir_expression(this->operation, this->type, + op[0], op[1], op[2], op[3]); } ir_dereference_variable * -ir_dereference_variable::clone(struct hash_table *ht) const +ir_dereference_variable::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_variable *new_var; if (ht) { @@ -186,55 +208,56 @@ ir_dereference_variable::clone(struct hash_table *ht) const new_var = this->var; } - return new(ctx) ir_dereference_variable(new_var); + return new(mem_ctx) ir_dereference_variable(new_var); } ir_dereference_array * -ir_dereference_array::clone(struct hash_table *ht) const +ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_dereference_array(this->array->clone(ht), - this->array_index->clone(ht)); + return new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, ht), + this->array_index->clone(mem_ctx, + ht)); } ir_dereference_record * -ir_dereference_record::clone(struct hash_table *ht) const +ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_dereference_record(this->record->clone(ht), - this->field); + return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht), + this->field); } ir_texture * -ir_texture::clone(struct hash_table *ht) const +ir_texture::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_texture *new_tex = new(ctx) ir_texture(this->op); + ir_texture *new_tex = new(mem_ctx) ir_texture(this->op); + new_tex->type = this->type; - new_tex->sampler = this->sampler->clone(ht); - new_tex->coordinate = this->coordinate->clone(ht); + new_tex->sampler = this->sampler->clone(mem_ctx, ht); + if (this->coordinate) + new_tex->coordinate = this->coordinate->clone(mem_ctx, ht); if (this->projector) - new_tex->projector = this->projector->clone(ht); + new_tex->projector = this->projector->clone(mem_ctx, ht); if (this->shadow_comparitor) { - new_tex->shadow_comparitor = this->shadow_comparitor->clone(ht); + new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht); } - for (int i = 0; i < 3; i++) - new_tex->offsets[i] = this->offsets[i]; + if (this->offset != NULL) + new_tex->offset = this->offset->clone(mem_ctx, ht); switch (this->op) { case ir_tex: break; case ir_txb: - new_tex->lod_info.bias = this->lod_info.bias->clone(ht); + new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht); break; case ir_txl: case ir_txf: - new_tex->lod_info.lod = this->lod_info.lod->clone(ht); + case ir_txs: + new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht); break; case ir_txd: - new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(ht); - new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(ht); + new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(mem_ctx, ht); + new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht); break; } @@ -242,30 +265,29 @@ ir_texture::clone(struct hash_table *ht) const } ir_assignment * -ir_assignment::clone(struct hash_table *ht) const +ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const { ir_rvalue *new_condition = NULL; if (this->condition) - new_condition = this->condition->clone(ht); + new_condition = this->condition->clone(mem_ctx, ht); - void *ctx = talloc_parent(this); - return new(ctx) ir_assignment(this->lhs->clone(ht), - this->rhs->clone(ht), - new_condition); + return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), + this->rhs->clone(mem_ctx, ht), + new_condition, + this->write_mask); } ir_function * -ir_function::clone(struct hash_table *ht) const +ir_function::clone(void *mem_ctx, struct hash_table *ht) const { - void *mem_ctx = talloc_parent(this); ir_function *copy = new(mem_ctx) ir_function(this->name); foreach_list_const(node, &this->signatures) { const ir_function_signature *const sig = (const ir_function_signature *const) node; - ir_function_signature *sig_copy = sig->clone(ht); + ir_function_signature *sig_copy = sig->clone(mem_ctx, ht); copy->add_signature(sig_copy); if (ht != NULL) @@ -277,42 +299,51 @@ ir_function::clone(struct hash_table *ht) const } ir_function_signature * -ir_function_signature::clone(struct hash_table *ht) const +ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const +{ + ir_function_signature *copy = this->clone_prototype(mem_ctx, ht); + + copy->is_defined = this->is_defined; + + /* Clone the instruction list. + */ + foreach_list_const(node, &this->body) { + const ir_instruction *const inst = (const ir_instruction *) node; + + ir_instruction *const inst_copy = inst->clone(mem_ctx, ht); + copy->body.push_tail(inst_copy); + } + + return copy; +} + +ir_function_signature * +ir_function_signature::clone_prototype(void *mem_ctx, struct hash_table *ht) const { - void *mem_ctx = talloc_parent(this); ir_function_signature *copy = new(mem_ctx) ir_function_signature(this->return_type); - copy->is_defined = this->is_defined; - copy->is_built_in = this->is_built_in; + copy->is_defined = false; + copy->is_builtin = this->is_builtin; + copy->origin = this; - /* Clone the parameter list. + /* Clone the parameter list, but NOT the body. */ foreach_list_const(node, &this->parameters) { const ir_variable *const param = (const ir_variable *) node; assert(const_cast(param)->as_variable() != NULL); - ir_variable *const param_copy = param->clone(ht); + ir_variable *const param_copy = param->clone(mem_ctx, ht); copy->parameters.push_tail(param_copy); } - /* Clone the instruction list. - */ - foreach_list_const(node, &this->body) { - const ir_instruction *const inst = (const ir_instruction *) node; - - ir_instruction *const inst_copy = inst->clone(ht); - copy->body.push_tail(inst_copy); - } - return copy; } ir_constant * -ir_constant::clone(struct hash_table *ht) const +ir_constant::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); (void)ht; switch (this->type->base_type) { @@ -320,25 +351,36 @@ ir_constant::clone(struct hash_table *ht) const case GLSL_TYPE_INT: case GLSL_TYPE_FLOAT: case GLSL_TYPE_BOOL: - return new(ctx) ir_constant(this->type, &this->value); + return new(mem_ctx) ir_constant(this->type, &this->value); case GLSL_TYPE_STRUCT: { - ir_constant *c = new(ctx) ir_constant; + ir_constant *c = new(mem_ctx) ir_constant; c->type = this->type; for (exec_node *node = this->components.head - ; !node->is_tail_sentinal() + ; !node->is_tail_sentinel() ; node = node->next) { ir_constant *const orig = (ir_constant *) node; - c->components.push_tail(orig->clone(NULL)); + c->components.push_tail(orig->clone(mem_ctx, NULL)); } return c; } + case GLSL_TYPE_ARRAY: { + ir_constant *c = new(mem_ctx) ir_constant; + + c->type = this->type; + c->array_elements = ralloc_array(c, ir_constant *, this->type->length); + for (unsigned i = 0; i < this->type->length; i++) { + c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL); + } + return c; + } + default: - assert(!"Should not get here."); break; + assert(!"Should not get here."); return NULL; } } @@ -356,10 +398,10 @@ public: /* Try to find the function signature referenced by the ir_call in the * table. If it is found, replace it with the value from the table. */ - const ir_function_signature *const sig = - (ir_function_signature *) hash_table_find(this->ht, ir->get_callee()); + ir_function_signature *sig = + (ir_function_signature *) hash_table_find(this->ht, ir->callee); if (sig != NULL) - ir->set_callee(sig); + ir->callee = sig; /* Since this may be used before function call parameters are flattened, * the children also need to be processed. @@ -381,14 +423,14 @@ fixup_function_calls(struct hash_table *ht, exec_list *instructions) void -clone_ir_list(exec_list *out, const exec_list *in) +clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in) { struct hash_table *ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); foreach_list_const(node, in) { const ir_instruction *const original = (ir_instruction *) node; - ir_instruction *copy = original->clone(ht); + ir_instruction *copy = original->clone(mem_ctx, ht); out->push_tail(copy); }