[Mesa-dev] [PATCH 1/5] glsl: Move get_error_instruction() from ir_call to ir_constant.

Ian Romanick idr at freedesktop.org
Wed Sep 21 18:34:46 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/20/2011 06:28 PM, Kenneth Graunke wrote:
| All this does is generate a bogus value with error type; the fact
| that it was in ir_call was rather arbitrary to begin with.
| ir_constant is an equally arbitrary place. The rationale is that a
| future commit will change ir_calls from rvalues to statements, and
| all uses of this function expect an rvalue.

There was nothing arbitrary about it.  It generates an invalid ir_call
when encountering an error while processing an
ast_function_expression.  At the time the thinking was that there
would be other get_error_instruction methods in other class.  The
thinking was also that objects in expression trees might eventually
become flyweights.  Neither of those things ever happened.

| Signed-off-by: Kenneth Graunke<kenneth at whitecape.org> ---
| src/glsl/ast_function.cpp        |   32
| ++++++++++++++++---------------- src/glsl/hir_field_selection.cpp |
| 2 +- src/glsl/ir.cpp                  |   19 +++++++++----------
| src/glsl/ir.h                    |   14 +++++++-------
| src/glsl/ir_clone.cpp            |    5 ++--- 5 files changed, 35
| insertions(+), 37 deletions(-)
|
| diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
| index ca45934..392b7f9 100644 --- a/src/glsl/ast_function.cpp +++
| b/src/glsl/ast_function.cpp @@ -164,7 +164,7 @@
| match_function_by_name(exec_list *instructions, const char *name,
| _mesa_glsl_error(loc, state, "parameter `%s' must be a constant
| expression", formal->name); -	    return
| ir_call::get_error_instruction(ctx); +	    return
| ir_constant::error_value(ctx); }
|
| if ((formal->mode == ir_var_out) @@ -328,7 +328,7 @@
| match_function_by_name(exec_list *instructions, const char *name,
|
| }
|
| -      return ir_call::get_error_instruction(ctx); +      return
| ir_constant::error_value(ctx); } }
|
| @@ -504,7 +504,7 @@ process_array_constructor(exec_list
| *instructions, "parameter%s", (constructor_type->length != 0) ? "at
| least" : "exactly", min_param, (min_param<= 1) ? "" : "s"); -
| return ir_call::get_error_instruction(ctx); +      return
| ir_constant::error_value(ctx); }
|
| if (constructor_type->length == 0) { @@ -1141,7 +1141,7 @@
| ast_function_expression::hir(exec_list *instructions,
| _mesa_glsl_error(&  loc, state, "unknown type `%s' (structure name
| " "may be shadowed by a variable with the same name)",
| type->type_name); -	 return ir_call::get_error_instruction(ctx); +
| return ir_constant::error_value(ctx); }
|
|
| @@ -1150,14 +1150,14 @@ ast_function_expression::hir(exec_list
| *instructions, if (constructor_type->is_sampler()) {
| _mesa_glsl_error(&  loc, state, "cannot construct sampler type
| `%s'", constructor_type->name); -	 return
| ir_call::get_error_instruction(ctx); +	 return
| ir_constant::error_value(ctx); }
|
| if (constructor_type->is_array()) { if (state->language_version<=
| 110) { _mesa_glsl_error(&  loc, state, "array constructors
| forbidden in GLSL 1.10"); -	    return
| ir_call::get_error_instruction(ctx); +	    return
| ir_constant::error_value(ctx); }
|
| return process_array_constructor(instructions, constructor_type, @@
| -1188,7 +1188,7 @@ ast_function_expression::hir(exec_list
| *instructions, "insufficient parameters to constructor " "for
| `%s'", constructor_type->name); -	       return
| ir_call::get_error_instruction(ctx); +	       return
| ir_constant::error_value(ctx); }
|
| if
| (apply_implicit_conversion(constructor_type->fields.structure[i].type,
|
|
@@ -1202,7 +1202,7 @@ ast_function_expression::hir(exec_list *instructions,
| constructor_type->fields.structure[i].name, ir->type->name,
| constructor_type->fields.structure[i].type->name); -	       return
| ir_call::get_error_instruction(ctx);; +	       return
| ir_constant::error_value(ctx);; }
|
| node = node->next; @@ -1211,7 +1211,7 @@
| ast_function_expression::hir(exec_list *instructions, if
| (!node->is_tail_sentinel()) { _mesa_glsl_error(&loc, state, "too
| many parameters in constructor " "for `%s'",
| constructor_type->name); -	    return
| ir_call::get_error_instruction(ctx); +	    return
| ir_constant::error_value(ctx); }
|
| ir_rvalue *const constant = @@ -1225,7 +1225,7 @@
| ast_function_expression::hir(exec_list *instructions, }
|
| if (!constructor_type->is_numeric()&&
| !constructor_type->is_boolean()) -	 return
| ir_call::get_error_instruction(ctx); +	 return
| ir_constant::error_value(ctx);
|
| /* Total number of components of the type being constructed. */
| const unsigned type_components = constructor_type->components(); @@
| -1252,14 +1252,14 @@ ast_function_expression::hir(exec_list
| *instructions, _mesa_glsl_error(&  loc, state, "too many parameters
| to `%s' " "constructor", constructor_type->name); -	    return
| ir_call::get_error_instruction(ctx); +	    return
| ir_constant::error_value(ctx); }
|
| if (!result->type->is_numeric()&&  !result->type->is_boolean()) {
| _mesa_glsl_error(&  loc, state, "cannot construct `%s' from a "
| "non-numeric data type", constructor_type->name); -	    return
| ir_call::get_error_instruction(ctx); +	    return
| ir_constant::error_value(ctx); }
|
| /* Count the number of matrix and nonmatrix parameters.  This @@
| -1284,7 +1284,7 @@ ast_function_expression::hir(exec_list
| *instructions, _mesa_glsl_error(&  loc, state, "cannot construct
| `%s' from a " "matrix in GLSL 1.10", constructor_type->name); -
| return ir_call::get_error_instruction(ctx); +	 return
| ir_constant::error_value(ctx); }
|
| /* From page 50 (page 56 of the PDF) of the GLSL 1.50 spec: @@
| -1298,7 +1298,7 @@ ast_function_expression::hir(exec_list
| *instructions, _mesa_glsl_error(&  loc, state, "for matrix `%s'
| constructor, " "matrix must be only parameter",
| constructor_type->name); -	 return
| ir_call::get_error_instruction(ctx); +	 return
| ir_constant::error_value(ctx); }
|
| /* From page 28 (page 34 of the PDF) of the GLSL 1.10 spec: @@
| -1312,7 +1312,7 @@ ast_function_expression::hir(exec_list
| *instructions, _mesa_glsl_error(&  loc, state, "too few components
| to construct " "`%s'", constructor_type->name); -	 return
| ir_call::get_error_instruction(ctx); +	 return
| ir_constant::error_value(ctx); }
|
| /* Later, we cast each parameter to the same base type as the @@
| -1404,5 +1404,5 @@ ast_function_expression::hir(exec_list
| *instructions, &actual_parameters, state); }
|
| -   return ir_call::get_error_instruction(ctx); +   return
| ir_constant::error_value(ctx); } diff --git
| a/src/glsl/hir_field_selection.cpp
| b/src/glsl/hir_field_selection.cpp index 3c33127..8258ee8 100644
| --- a/src/glsl/hir_field_selection.cpp +++
| b/src/glsl/hir_field_selection.cpp @@ -98,5 +98,5 @@
| _mesa_ast_field_selection_to_hir(const ast_expression *expr,
| expr->primary_expression.identifier); }
|
| -   return result ? result : ir_call::get_error_instruction(ctx); +
| return result ? result : ir_constant::error_value(ctx); } diff
| --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index d6594cd..70d0ae2
| 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -725,6
| +725,15 @@ ir_constant::zero(void *mem_ctx, const glsl_type *type)
| return c; }
|
| +ir_constant * +ir_constant::error_value(void *ctx) +{ +
| ir_constant *ir = new(ctx) ir_constant; + +   ir->type =
| glsl_type::error_type; +   return ir; +} + bool
| ir_constant::get_bool_component(unsigned i) const { @@ -1446,16
| +1455,6 @@ ir_function::has_user_signature() return false; }
|
| - -ir_call * -ir_call::get_error_instruction(void *ctx) -{ -
| ir_call *call = new(ctx) ir_call; - -   call->type =
| glsl_type::error_type; -   return call; -} - void
| ir_call::set_callee(ir_function_signature *sig) { diff --git
| a/src/glsl/ir.h b/src/glsl/ir.h index cc4e680..f809867 100644 ---
| a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -1003,13 +1003,6 @@ public:
| virtual ir_visitor_status accept(ir_hierarchical_visitor *);
|
| /** -    * Get a generic ir_call object when an error occurs -
| * -    * Any allocation will be performed with 'ctx' as ralloc
| owner. -    */ -   static ir_call *get_error_instruction(void
| *ctx); - -   /** * Get an iterator for the set of acutal
| parameters */ exec_list_iterator iterator() @@ -1548,6 +1541,13 @@
| public: */ static ir_constant *zero(void *mem_ctx, const glsl_type
| *type);
|
| +   /** +    * Return a generic ir_constant object of error_type +
| * +    * Allocation will be performed with 'mem_ctx' as talloc
| owner. +    */ +   static ir_constant *error_value(void *mem_ctx);
| + virtual ir_constant *clone(void *mem_ctx, struct hash_table *)
| const;
|
| virtual ir_constant *constant_expression_value(); diff --git
| a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index
| c1befa9..e8b946a 100644 --- a/src/glsl/ir_clone.cpp +++
| b/src/glsl/ir_clone.cpp @@ -156,9 +156,6 @@ ir_loop::clone(void
| *mem_ctx, struct hash_table *ht) const ir_call *
| ir_call::clone(void *mem_ctx, struct hash_table *ht) const { -   if
| (this->type == glsl_type::error_type) -      return
| ir_call::get_error_instruction(mem_ctx); - exec_list
| new_parameters;
|
| foreach_iter(exec_list_iterator, iter, this->actual_parameters) {
| @@ -334,6 +331,8 @@ ir_constant::clone(void *mem_ctx, struct
| hash_table *ht) const (void)ht;
|
| switch (this->type->base_type) { +   case GLSL_TYPE_ERROR: +
| return ir_constant::error_value(mem_ctx); case GLSL_TYPE_UINT: case
| GLSL_TYPE_INT: case GLSL_TYPE_FLOAT:

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk56kLYACgkQX1gOwKyEAw9npgCdFh3CoFIZCGVZKcP7Qw8XJKvm
xrMAnjPNip5948K72h1tFJ2qvz+uh/ff
=nWYW
-----END PGP SIGNATURE-----


More information about the mesa-dev mailing list