glsl2: Remove generate_temporary and global temporary counter.
Most places in the code simply use a static name, which works because names are never used to look up an ir_variable. generate_temporary is simply unnecessary (and looks like it would leak memory, and isn't thread safe...)
This commit is contained in:
@@ -542,27 +542,6 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
|
|||||||
return new(ctx) ir_dereference_variable(var);
|
return new(ctx) ir_dereference_variable(var);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a new temporary and add its declaration to the instruction stream
|
|
||||||
*/
|
|
||||||
static ir_variable *
|
|
||||||
generate_temporary(const glsl_type *type, exec_list *instructions,
|
|
||||||
struct _mesa_glsl_parse_state *state)
|
|
||||||
{
|
|
||||||
void *ctx = state;
|
|
||||||
char *name = (char *) malloc(sizeof(char) * 13);
|
|
||||||
|
|
||||||
snprintf(name, 13, "tmp_%08X", state->temp_index);
|
|
||||||
state->temp_index++;
|
|
||||||
|
|
||||||
ir_variable *const var = new(ctx) ir_variable(type, name);
|
|
||||||
instructions->push_tail(var);
|
|
||||||
|
|
||||||
return var;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static ir_rvalue *
|
static ir_rvalue *
|
||||||
get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue)
|
get_lvalue_copy(exec_list *instructions, ir_rvalue *lvalue)
|
||||||
{
|
{
|
||||||
@@ -840,8 +819,8 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
error_emitted = true;
|
error_emitted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ir_variable *const tmp = generate_temporary(glsl_type::bool_type,
|
ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
|
||||||
instructions, state);
|
"and_tmp");
|
||||||
|
|
||||||
ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
|
ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
|
||||||
ir_assignment *const then_assign =
|
ir_assignment *const then_assign =
|
||||||
@@ -892,8 +871,8 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
ir_if *const stmt = new(ctx) ir_if(op[0]);
|
ir_if *const stmt = new(ctx) ir_if(op[0]);
|
||||||
instructions->push_tail(stmt);
|
instructions->push_tail(stmt);
|
||||||
|
|
||||||
ir_variable *const tmp = generate_temporary(glsl_type::bool_type,
|
ir_variable *const tmp = new(ctx) ir_variable(glsl_type::bool_type,
|
||||||
instructions, state);
|
"or_tmp");
|
||||||
|
|
||||||
op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state);
|
op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state);
|
||||||
|
|
||||||
@@ -1068,8 +1047,7 @@ ast_expression::hir(exec_list *instructions,
|
|||||||
&& (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) {
|
&& (cond_val != NULL) && (then_val != NULL) && (else_val != NULL)) {
|
||||||
result = (cond_val->value.b[0]) ? then_val : else_val;
|
result = (cond_val->value.b[0]) ? then_val : else_val;
|
||||||
} else {
|
} else {
|
||||||
ir_variable *const tmp = generate_temporary(type,
|
ir_variable *const tmp = new(ctx) ir_variable(type, "conditional_tmp");
|
||||||
instructions, state);
|
|
||||||
|
|
||||||
ir_if *const stmt = new(ctx) ir_if(op[0]);
|
ir_if *const stmt = new(ctx) ir_if(op[0]);
|
||||||
instructions->push_tail(stmt);
|
instructions->push_tail(stmt);
|
||||||
|
@@ -67,9 +67,6 @@ struct _mesa_glsl_parse_state {
|
|||||||
/** Was there an error during compilation? */
|
/** Was there an error during compilation? */
|
||||||
bool error;
|
bool error;
|
||||||
|
|
||||||
/** Index of last generated anonymous temporary. */
|
|
||||||
unsigned temp_index;
|
|
||||||
|
|
||||||
/** Loop or switch statement containing the current instructions. */
|
/** Loop or switch statement containing the current instructions. */
|
||||||
class ir_instruction *loop_or_switch_nesting;
|
class ir_instruction *loop_or_switch_nesting;
|
||||||
|
|
||||||
|
@@ -124,7 +124,6 @@ compile_shader(struct gl_shader *shader)
|
|||||||
state->symbols = new(shader) glsl_symbol_table;
|
state->symbols = new(shader) glsl_symbol_table;
|
||||||
state->info_log = talloc_strdup(shader, "");
|
state->info_log = talloc_strdup(shader, "");
|
||||||
state->error = false;
|
state->error = false;
|
||||||
state->temp_index = 0;
|
|
||||||
state->loop_or_switch_nesting = NULL;
|
state->loop_or_switch_nesting = NULL;
|
||||||
state->ARB_texture_rectangle_enable = true;
|
state->ARB_texture_rectangle_enable = true;
|
||||||
|
|
||||||
|
@@ -1938,7 +1938,6 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader)
|
|||||||
state->symbols = new(shader) glsl_symbol_table;
|
state->symbols = new(shader) glsl_symbol_table;
|
||||||
state->info_log = talloc_strdup(shader, "");
|
state->info_log = talloc_strdup(shader, "");
|
||||||
state->error = false;
|
state->error = false;
|
||||||
state->temp_index = 0;
|
|
||||||
state->loop_or_switch_nesting = NULL;
|
state->loop_or_switch_nesting = NULL;
|
||||||
state->ARB_texture_rectangle_enable = true;
|
state->ARB_texture_rectangle_enable = true;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user