From 1eb7a81f2e43842acd59929ce65db2142b69134d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 24 Nov 2010 21:33:07 -0800 Subject: glsl: Add a virtual as_discard() method. NOTE: This is candidate for the 7.9 branch. --- src/glsl/ir.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/glsl/ir.h') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 850033b185f..62bb0fd7096 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -122,6 +122,7 @@ public: virtual class ir_if * as_if() { return NULL; } virtual class ir_swizzle * as_swizzle() { return NULL; } virtual class ir_constant * as_constant() { return NULL; } + virtual class ir_discard * as_discard() { return NULL; } /*@}*/ protected: @@ -1122,6 +1123,11 @@ public: virtual ir_visitor_status accept(ir_hierarchical_visitor *); + virtual ir_discard *as_discard() + { + return this; + } + ir_rvalue *condition; }; /*@}*/ -- cgit v1.2.3 From 6b937465d4aeab72fabcfe5250d477cf6790a521 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 3 Nov 2010 10:21:07 -0700 Subject: glsl: Add a helper constructor for expressions that works out result type. This doesn't cover all expressions or all operand types, but it will complain if you overreach and it allows for much greater slack on the programmer's part. --- src/glsl/ir.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/glsl/ir.h | 2 ++ 2 files changed, 104 insertions(+) (limited to 'src/glsl/ir.h') diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 2abb95394fd..31b90bf021c 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -231,6 +231,108 @@ ir_expression::ir_expression(int op, const struct glsl_type *type, this->operands[3] = op3; } +ir_expression::ir_expression(int op, ir_rvalue *op0) +{ + this->ir_type = ir_type_expression; + + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = NULL; + this->operands[2] = NULL; + this->operands[3] = NULL; + + assert(op <= ir_last_unop); + + switch (this->operation) { + case ir_unop_bit_not: + case ir_unop_logic_not: + case ir_unop_neg: + case ir_unop_abs: + case ir_unop_sign: + case ir_unop_rcp: + case ir_unop_rsq: + case ir_unop_sqrt: + case ir_unop_exp: + case ir_unop_log: + case ir_unop_exp2: + case ir_unop_log2: + case ir_unop_trunc: + case ir_unop_ceil: + case ir_unop_floor: + case ir_unop_fract: + case ir_unop_round_even: + case ir_unop_cos: + case ir_unop_dFdx: + case ir_unop_dFdy: + this->type = op0->type; + break; + + case ir_unop_any: + this->type = glsl_type::bool_type; + break; + + default: + assert(!"not reached: missing automatic type setup for ir_expression"); + this->type = op0->type; + break; + } +} + +ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) +{ + this->ir_type = ir_type_expression; + + this->operation = ir_expression_operation(op); + this->operands[0] = op0; + this->operands[1] = op1; + this->operands[2] = NULL; + this->operands[3] = NULL; + + assert(op > ir_last_unop); + + switch (this->operation) { + case ir_binop_all_equal: + case ir_binop_any_nequal: + this->type = glsl_type::bool_type; + break; + + case ir_binop_add: + case ir_binop_sub: + case ir_binop_min: + case ir_binop_max: + case ir_binop_pow: + case ir_binop_mul: + if (op0->type->is_scalar()) { + this->type = op1->type; + } else if (op1->type->is_scalar()) { + this->type = op0->type; + } else { + /* FINISHME: matrix types */ + assert(!op0->type->is_matrix() && !op1->type->is_matrix()); + assert(op0->type == op1->type); + this->type = op0->type; + } + break; + + case ir_binop_logic_and: + case ir_binop_logic_or: + if (op0->type->is_scalar()) { + this->type = op1->type; + } else if (op1->type->is_scalar()) { + this->type = op0->type; + } + break; + + case ir_binop_dot: + this->type = glsl_type::float_type; + break; + + default: + assert(!"not reached: missing automatic type setup for ir_expression"); + this->type = glsl_type::float_type; + } +} + unsigned int ir_expression::get_num_operands(ir_expression_operation op) { diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 62bb0fd7096..625397a5995 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -842,12 +842,14 @@ public: * Constructor for unary operation expressions */ ir_expression(int op, const struct glsl_type *type, ir_rvalue *); + ir_expression(int op, ir_rvalue *); /** * Constructor for binary operation expressions */ ir_expression(int op, const struct glsl_type *type, ir_rvalue *, ir_rvalue *); + ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1); /** * Constructor for quad operator expressions -- cgit v1.2.3 From 01a25bb64ecae156729794320f9a39733ff8eeaa Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 11 Nov 2010 12:21:27 -0800 Subject: glsl: Refactor out cloning of function prototypes. This allows us to reuse some code and will be useful later. --- src/glsl/ir.h | 2 ++ src/glsl/ir_clone.cpp | 32 +++++++++++++++++++++----------- src/glsl/ir_import_prototypes.cpp | 17 +---------------- 3 files changed, 24 insertions(+), 27 deletions(-) (limited to 'src/glsl/ir.h') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 625397a5995..102a68b6551 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -376,6 +376,8 @@ public: virtual ir_function_signature *clone(void *mem_ctx, struct hash_table *ht) const; + ir_function_signature *clone_prototype(void *mem_ctx, + struct hash_table *ht) const; virtual void accept(ir_visitor *v) { diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 325f6066154..1522af682bb 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -275,14 +275,33 @@ ir_function::clone(void *mem_ctx, struct hash_table *ht) const ir_function_signature * 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 { ir_function_signature *copy = new(mem_ctx) ir_function_signature(this->return_type); - copy->is_defined = this->is_defined; + copy->is_defined = false; copy->is_builtin = this->is_builtin; - /* 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; @@ -293,15 +312,6 @@ ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const 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(mem_ctx, ht); - copy->body.push_tail(inst_copy); - } - return copy; } diff --git a/src/glsl/ir_import_prototypes.cpp b/src/glsl/ir_import_prototypes.cpp index 2bdc8d9fd7d..4e0b30aa90e 100644 --- a/src/glsl/ir_import_prototypes.cpp +++ b/src/glsl/ir_import_prototypes.cpp @@ -82,22 +82,7 @@ public: { assert(this->function != NULL); - ir_function_signature *copy = - new(mem_ctx) ir_function_signature(ir->return_type); - - copy->is_defined = false; - copy->is_builtin = ir->is_builtin; - - /* Clone the parameter list, but NOT the body. - */ - foreach_list_const(node, &ir->parameters) { - const ir_variable *const param = (const ir_variable *) node; - - assert(const_cast(param)->as_variable() != NULL); - - ir_variable *const param_copy = param->clone(mem_ctx, NULL); - copy->parameters.push_tail(param_copy); - } + ir_function_signature *copy = ir->clone_prototype(mem_ctx, NULL); this->function->add_signature(copy); -- cgit v1.2.3