2010-06-23 19:37:12 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2010-11-11 00:33:10 +00:00
|
|
|
#include "main/compiler.h"
|
2010-06-23 19:37:12 +01:00
|
|
|
#include "ir.h"
|
|
|
|
#include "glsl_types.h"
|
2010-07-29 10:40:49 +01:00
|
|
|
#include "program/hash_table.h"
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2011-09-22 23:04:56 +01:00
|
|
|
ir_rvalue *
|
2014-03-27 21:17:53 +00:00
|
|
|
ir_rvalue::clone(void *mem_ctx, struct hash_table *) const
|
2011-09-22 23:04:56 +01:00
|
|
|
{
|
|
|
|
/* The only possible instantiation is the generic error value. */
|
|
|
|
return error_value(mem_ctx);
|
|
|
|
}
|
|
|
|
|
2010-06-23 19:37:12 +01:00
|
|
|
/**
|
|
|
|
* Duplicate an IR variable
|
|
|
|
*/
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_variable *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_variable *var = new(mem_ctx) ir_variable(this->type, this->name,
|
2013-12-12 11:51:01 +00:00
|
|
|
(ir_variable_mode) this->data.mode);
|
2010-06-23 19:37:12 +01:00
|
|
|
|
glsl: move variables in to ir_variable::data, part II
This patch moves following bitfields and variables to the data
structure:
explicit_location, explicit_index, explicit_binding, has_initializer,
is_unmatched_generic_inout, location_frac, from_named_ifc_block_nonarray,
from_named_ifc_block_array, depth_layout, location, index, binding,
max_array_access, atomic
Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
2013-12-12 13:08:59 +00:00
|
|
|
var->data.max_array_access = this->data.max_array_access;
|
2013-09-18 22:15:36 +01:00
|
|
|
if (this->is_interface_instance()) {
|
|
|
|
var->max_ifc_array_access =
|
|
|
|
rzalloc_array(var, unsigned, this->interface_type->length);
|
|
|
|
memcpy(var->max_ifc_array_access, this->max_ifc_array_access,
|
|
|
|
this->interface_type->length * sizeof(unsigned));
|
|
|
|
}
|
2013-12-12 15:13:32 +00:00
|
|
|
|
|
|
|
memcpy(&var->data, &this->data, sizeof(var->data));
|
|
|
|
|
2010-07-08 00:11:10 +01:00
|
|
|
var->warn_extension = this->warn_extension;
|
2011-01-25 18:41:20 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-07-08 00:11:10 +01:00
|
|
|
if (this->constant_value)
|
2010-08-04 20:34:56 +01:00
|
|
|
var->constant_value = this->constant_value->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2011-10-31 21:31:07 +00:00
|
|
|
if (this->constant_initializer)
|
|
|
|
var->constant_initializer =
|
|
|
|
this->constant_initializer->clone(mem_ctx, ht);
|
|
|
|
|
2013-01-22 02:51:15 +00:00
|
|
|
var->interface_type = this->interface_type;
|
|
|
|
|
2010-06-23 19:37:12 +01:00
|
|
|
if (ht) {
|
2010-06-24 21:31:34 +01:00
|
|
|
hash_table_insert(ht, var, (void *)const_cast<ir_variable *>(this));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return var;
|
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_swizzle *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_swizzle::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_swizzle(this->val->clone(mem_ctx, ht), this->mask);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_return *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_return::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
|
|
|
ir_rvalue *new_value = NULL;
|
|
|
|
|
|
|
|
if (this->value)
|
2010-08-04 20:34:56 +01:00
|
|
|
new_value = this->value->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_return(new_value);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_discard *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_discard::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-30 18:47:34 +01:00
|
|
|
{
|
|
|
|
ir_rvalue *new_condition = NULL;
|
|
|
|
|
|
|
|
if (this->condition != NULL)
|
2010-08-04 20:34:56 +01:00
|
|
|
new_condition = this->condition->clone(mem_ctx, ht);
|
2010-06-30 18:47:34 +01:00
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_discard(new_condition);
|
2010-06-30 18:47:34 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_loop_jump *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
|
|
|
(void)ht;
|
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_loop_jump(this->mode);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_if *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_if::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2014-06-25 05:34:05 +01:00
|
|
|
foreach_in_list(ir_instruction, ir, &this->then_instructions) {
|
2010-08-04 20:34:56 +01:00
|
|
|
new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2014-06-25 05:34:05 +01:00
|
|
|
foreach_in_list(ir_instruction, ir, &this->else_instructions) {
|
2010-08-04 20:34:56 +01:00
|
|
|
new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new_if;
|
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_loop *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_loop::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_loop *new_loop = new(mem_ctx) ir_loop();
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2014-06-25 05:34:05 +01:00
|
|
|
foreach_in_list(ir_instruction, ir, &this->body_instructions) {
|
2010-08-04 20:34:56 +01:00
|
|
|
new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new_loop;
|
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_call *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_call::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 22:56:37 +00:00
|
|
|
ir_dereference_variable *new_return_ref = NULL;
|
|
|
|
if (this->return_deref != NULL)
|
|
|
|
new_return_ref = this->return_deref->clone(mem_ctx, ht);
|
|
|
|
|
2010-06-23 19:37:12 +01:00
|
|
|
exec_list new_parameters;
|
|
|
|
|
2014-06-25 05:34:05 +01:00
|
|
|
foreach_in_list(ir_instruction, ir, &this->actual_parameters) {
|
2010-08-04 20:34:56 +01:00
|
|
|
new_parameters.push_tail(ir->clone(mem_ctx, ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
glsl: Convert ir_call to be a statement rather than a value.
Aside from ir_call, our IR is cleanly split into two classes:
- Statements (typeless; used for side effects, control flow)
- Values (deeply nestable, pure, typed expression trees)
Unfortunately, ir_call confused all this:
- For void functions, we placed ir_call directly in the instruction
stream, treating it as an untyped statement. Yet, it was a subclass
of ir_rvalue, and no other ir_rvalue could be used in this way.
- For functions with a return value, ir_call could be placed in
arbitrary expression trees. While this fit naturally with the source
language, it meant that expressions might not be pure, making it
difficult to transform and optimize them. To combat this, we always
emitted ir_call directly in the RHS of an ir_assignment, only using
a temporary variable in expression trees. Many passes relied on this
assumption; the acos and atan built-ins violated it.
This patch makes ir_call a statement (ir_instruction) rather than a
value (ir_rvalue). Non-void calls now take a ir_dereference of a
variable, and store the return value there---effectively a call and
assignment rolled into one. They cannot be embedded in expressions.
All expression trees are now pure, without exception.
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
2012-03-20 22:56:37 +00:00
|
|
|
return new(mem_ctx) ir_call(this->callee, new_return_ref, &new_parameters);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_expression *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_expression::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-11-11 00:33:10 +00:00
|
|
|
ir_rvalue *op[Elements(this->operands)] = { NULL, };
|
2010-06-23 19:37:12 +01:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < get_num_operands(); i++) {
|
2010-08-04 20:34:56 +01:00
|
|
|
op[i] = this->operands[i]->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:01:42 +00:00
|
|
|
return new(mem_ctx) ir_expression(this->operation, this->type,
|
|
|
|
op[0], op[1], op[2], op[3]);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_dereference_variable *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_dereference_variable::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
|
|
|
ir_variable *new_var;
|
|
|
|
|
|
|
|
if (ht) {
|
|
|
|
new_var = (ir_variable *)hash_table_find(ht, this->var);
|
|
|
|
if (!new_var)
|
|
|
|
new_var = this->var;
|
|
|
|
} else {
|
|
|
|
new_var = this->var;
|
|
|
|
}
|
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_dereference_variable(new_var);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_dereference_array *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, ht),
|
|
|
|
this->array_index->clone(mem_ctx,
|
|
|
|
ht));
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_dereference_record *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht),
|
|
|
|
this->field);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_texture *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_texture::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_texture *new_tex = new(mem_ctx) ir_texture(this->op);
|
2010-07-22 23:34:01 +01:00
|
|
|
new_tex->type = this->type;
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
new_tex->sampler = this->sampler->clone(mem_ctx, ht);
|
2011-02-25 22:45:33 +00:00
|
|
|
if (this->coordinate)
|
|
|
|
new_tex->coordinate = this->coordinate->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
if (this->projector)
|
2010-08-04 20:34:56 +01:00
|
|
|
new_tex->projector = this->projector->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
if (this->shadow_comparitor) {
|
2010-08-04 20:34:56 +01:00
|
|
|
new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2011-01-09 07:49:23 +00:00
|
|
|
if (this->offset != NULL)
|
|
|
|
new_tex->offset = this->offset->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
|
|
|
|
switch (this->op) {
|
|
|
|
case ir_tex:
|
2012-09-23 10:50:41 +01:00
|
|
|
case ir_lod:
|
2013-09-26 08:37:30 +01:00
|
|
|
case ir_query_levels:
|
2010-06-23 19:37:12 +01:00
|
|
|
break;
|
|
|
|
case ir_txb:
|
2010-08-04 20:34:56 +01:00
|
|
|
new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
break;
|
|
|
|
case ir_txl:
|
|
|
|
case ir_txf:
|
2011-02-25 22:45:33 +00:00
|
|
|
case ir_txs:
|
2010-08-04 20:34:56 +01:00
|
|
|
new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht);
|
2012-12-21 08:33:37 +00:00
|
|
|
break;
|
|
|
|
case ir_txf_ms:
|
|
|
|
new_tex->lod_info.sample_index = this->lod_info.sample_index->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
break;
|
|
|
|
case ir_txd:
|
2010-08-04 20:34:56 +01:00
|
|
|
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);
|
2010-06-23 19:37:12 +01:00
|
|
|
break;
|
2013-10-05 06:26:56 +01:00
|
|
|
case ir_tg4:
|
|
|
|
new_tex->lod_info.component = this->lod_info.component->clone(mem_ctx, ht);
|
|
|
|
break;
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new_tex;
|
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_assignment *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
|
|
|
ir_rvalue *new_condition = NULL;
|
|
|
|
|
|
|
|
if (this->condition)
|
2010-08-04 20:34:56 +01:00
|
|
|
new_condition = this->condition->clone(mem_ctx, ht);
|
2010-06-23 19:37:12 +01:00
|
|
|
|
2014-03-12 21:24:03 +00:00
|
|
|
ir_assignment *cloned =
|
|
|
|
new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht),
|
|
|
|
this->rhs->clone(mem_ctx, ht),
|
|
|
|
new_condition);
|
|
|
|
cloned->write_mask = this->write_mask;
|
|
|
|
return cloned;
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_function *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_function::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-07-07 19:02:19 +01:00
|
|
|
ir_function *copy = new(mem_ctx) ir_function(this->name);
|
|
|
|
|
2014-06-25 06:29:08 +01:00
|
|
|
foreach_in_list(const ir_function_signature, sig, &this->signatures) {
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_function_signature *sig_copy = sig->clone(mem_ctx, ht);
|
2010-07-07 19:02:19 +01:00
|
|
|
copy->add_signature(sig_copy);
|
|
|
|
|
|
|
|
if (ht != NULL)
|
|
|
|
hash_table_insert(ht, sig_copy,
|
|
|
|
(void *)const_cast<ir_function_signature *>(sig));
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy;
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_function_signature *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-11-11 20:21:27 +00:00
|
|
|
{
|
|
|
|
ir_function_signature *copy = this->clone_prototype(mem_ctx, ht);
|
|
|
|
|
|
|
|
copy->is_defined = this->is_defined;
|
|
|
|
|
|
|
|
/* Clone the instruction list.
|
|
|
|
*/
|
2014-06-25 06:29:08 +01:00
|
|
|
foreach_in_list(const ir_instruction, inst, &this->body) {
|
2010-11-11 20:21:27 +00:00
|
|
|
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
|
2010-06-23 19:37:12 +01:00
|
|
|
{
|
2010-07-07 19:02:19 +01:00
|
|
|
ir_function_signature *copy =
|
|
|
|
new(mem_ctx) ir_function_signature(this->return_type);
|
|
|
|
|
2010-11-11 20:21:27 +00:00
|
|
|
copy->is_defined = false;
|
2013-09-09 22:53:22 +01:00
|
|
|
copy->builtin_avail = this->builtin_avail;
|
2012-05-02 22:11:41 +01:00
|
|
|
copy->origin = this;
|
2010-07-07 19:02:19 +01:00
|
|
|
|
2010-11-11 20:21:27 +00:00
|
|
|
/* Clone the parameter list, but NOT the body.
|
2010-07-07 19:02:19 +01:00
|
|
|
*/
|
2014-06-25 06:29:08 +01:00
|
|
|
foreach_in_list(const ir_variable, param, &this->parameters) {
|
2010-07-07 19:02:19 +01:00
|
|
|
assert(const_cast<ir_variable *>(param)->as_variable() != NULL);
|
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_variable *const param_copy = param->clone(mem_ctx, ht);
|
2010-07-07 19:02:19 +01:00
|
|
|
copy->parameters.push_tail(param_copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return copy;
|
2010-06-23 19:37:12 +01:00
|
|
|
}
|
2010-06-24 00:42:37 +01:00
|
|
|
|
2010-07-07 01:41:02 +01:00
|
|
|
ir_constant *
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
|
2010-06-24 00:42:37 +01:00
|
|
|
{
|
2010-06-24 00:43:08 +01:00
|
|
|
(void)ht;
|
|
|
|
|
2010-06-24 00:42:37 +01:00
|
|
|
switch (this->type->base_type) {
|
|
|
|
case GLSL_TYPE_UINT:
|
|
|
|
case GLSL_TYPE_INT:
|
|
|
|
case GLSL_TYPE_FLOAT:
|
|
|
|
case GLSL_TYPE_BOOL:
|
2010-08-04 20:34:56 +01:00
|
|
|
return new(mem_ctx) ir_constant(this->type, &this->value);
|
2010-06-24 00:42:37 +01:00
|
|
|
|
|
|
|
case GLSL_TYPE_STRUCT: {
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_constant *c = new(mem_ctx) ir_constant;
|
2010-06-24 00:42:37 +01:00
|
|
|
|
|
|
|
c->type = this->type;
|
|
|
|
for (exec_node *node = this->components.head
|
2010-07-29 21:52:25 +01:00
|
|
|
; !node->is_tail_sentinel()
|
2010-06-24 00:42:37 +01:00
|
|
|
; node = node->next) {
|
|
|
|
ir_constant *const orig = (ir_constant *) node;
|
|
|
|
|
2010-08-04 20:34:56 +01:00
|
|
|
c->components.push_tail(orig->clone(mem_ctx, NULL));
|
2010-06-24 00:42:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-07-20 09:06:33 +01:00
|
|
|
case GLSL_TYPE_ARRAY: {
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_constant *c = new(mem_ctx) ir_constant;
|
2010-07-20 09:06:33 +01:00
|
|
|
|
|
|
|
c->type = this->type;
|
2011-01-21 22:32:31 +00:00
|
|
|
c->array_elements = ralloc_array(c, ir_constant *, this->type->length);
|
2010-07-20 09:06:33 +01:00
|
|
|
for (unsigned i = 0; i < this->type->length; i++) {
|
2010-08-04 20:34:56 +01:00
|
|
|
c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL);
|
2010-07-20 09:06:33 +01:00
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2012-12-11 20:56:03 +00:00
|
|
|
case GLSL_TYPE_SAMPLER:
|
2013-11-25 21:50:47 +00:00
|
|
|
case GLSL_TYPE_IMAGE:
|
2013-10-20 20:35:47 +01:00
|
|
|
case GLSL_TYPE_ATOMIC_UINT:
|
2012-12-11 20:56:03 +00:00
|
|
|
case GLSL_TYPE_VOID:
|
|
|
|
case GLSL_TYPE_ERROR:
|
2012-12-11 20:11:16 +00:00
|
|
|
case GLSL_TYPE_INTERFACE:
|
2010-08-14 14:40:39 +01:00
|
|
|
assert(!"Should not get here.");
|
2012-12-11 20:56:03 +00:00
|
|
|
break;
|
2010-06-24 00:42:37 +01:00
|
|
|
}
|
2012-12-11 20:56:03 +00:00
|
|
|
|
|
|
|
return NULL;
|
2010-06-24 00:42:37 +01:00
|
|
|
}
|
2010-07-07 00:01:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class fixup_ir_call_visitor : public ir_hierarchical_visitor {
|
|
|
|
public:
|
|
|
|
fixup_ir_call_visitor(struct hash_table *ht)
|
|
|
|
{
|
|
|
|
this->ht = ht;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ir_visitor_status visit_enter(ir_call *ir)
|
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
2010-07-19 01:45:16 +01:00
|
|
|
ir_function_signature *sig =
|
2011-09-21 02:08:11 +01:00
|
|
|
(ir_function_signature *) hash_table_find(this->ht, ir->callee);
|
2010-07-07 00:01:06 +01:00
|
|
|
if (sig != NULL)
|
2011-09-21 02:08:11 +01:00
|
|
|
ir->callee = sig;
|
2010-07-07 00:01:06 +01:00
|
|
|
|
|
|
|
/* Since this may be used before function call parameters are flattened,
|
|
|
|
* the children also need to be processed.
|
|
|
|
*/
|
|
|
|
return visit_continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct hash_table *ht;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
fixup_function_calls(struct hash_table *ht, exec_list *instructions)
|
|
|
|
{
|
|
|
|
fixup_ir_call_visitor v(ht);
|
|
|
|
v.run(instructions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2010-08-04 20:34:56 +01:00
|
|
|
clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in)
|
2010-07-07 00:01:06 +01:00
|
|
|
{
|
|
|
|
struct hash_table *ht =
|
|
|
|
hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
|
|
|
|
|
2014-06-25 06:29:08 +01:00
|
|
|
foreach_in_list(const ir_instruction, original, in) {
|
2010-08-04 20:34:56 +01:00
|
|
|
ir_instruction *copy = original->clone(mem_ctx, ht);
|
2010-07-07 00:01:06 +01:00
|
|
|
|
|
|
|
out->push_tail(copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a pass over the cloned tree to fix up ir_call nodes to point to the
|
|
|
|
* cloned ir_function_signature nodes. This cannot be done automatically
|
|
|
|
* during cloning because the ir_call might be a forward reference (i.e.,
|
|
|
|
* the function signature that it references may not have been cloned yet).
|
|
|
|
*/
|
|
|
|
fixup_function_calls(ht, out);
|
|
|
|
|
|
|
|
hash_table_dtor(ht);
|
|
|
|
}
|