aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r--mesalib/src/glsl/Makefile.sources1
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.cpp1
-rw-r--r--mesalib/src/glsl/ir.h22
-rw-r--r--mesalib/src/glsl/ir_equals.cpp198
-rw-r--r--mesalib/src/glsl/link_interface_blocks.cpp271
-rw-r--r--mesalib/src/glsl/opt_algebraic.cpp19
-rw-r--r--mesalib/src/glsl/opt_cse.cpp180
7 files changed, 486 insertions, 206 deletions
diff --git a/mesalib/src/glsl/Makefile.sources b/mesalib/src/glsl/Makefile.sources
index 744b0adcf..2e81dedda 100644
--- a/mesalib/src/glsl/Makefile.sources
+++ b/mesalib/src/glsl/Makefile.sources
@@ -33,6 +33,7 @@ LIBGLSL_FILES = \
$(GLSL_SRCDIR)/ir_clone.cpp \
$(GLSL_SRCDIR)/ir_constant_expression.cpp \
$(GLSL_SRCDIR)/ir.cpp \
+ $(GLSL_SRCDIR)/ir_equals.cpp \
$(GLSL_SRCDIR)/ir_expression_flattening.cpp \
$(GLSL_SRCDIR)/ir_function_can_inline.cpp \
$(GLSL_SRCDIR)/ir_function_detect_recursion.cpp \
diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp
index d922db9db..f401f03bc 100644
--- a/mesalib/src/glsl/glsl_parser_extras.cpp
+++ b/mesalib/src/glsl/glsl_parser_extras.cpp
@@ -1529,7 +1529,6 @@ _mesa_glsl_compile_shader(struct gl_context *ctx, struct gl_shader *shader,
shader->CompileStatus = !state->error;
shader->InfoLog = state->info_log;
shader->Version = state->language_version;
- shader->InfoLog = state->info_log;
shader->IsES = state->es_shader;
memcpy(shader->builtins_to_link, state->builtins_to_link,
diff --git a/mesalib/src/glsl/ir.h b/mesalib/src/glsl/ir.h
index 2f06fb9ea..7859702ed 100644
--- a/mesalib/src/glsl/ir.h
+++ b/mesalib/src/glsl/ir.h
@@ -139,6 +139,16 @@ public:
virtual class ir_jump * as_jump() { return NULL; }
/*@}*/
+ /**
+ * IR equality method: Return true if the referenced instruction would
+ * return the same value as this one.
+ *
+ * This intended to be used for CSE and algebraic optimizations, on rvalues
+ * in particular. No support for other instruction types (assignments,
+ * jumps, calls, etc.) is planned.
+ */
+ virtual bool equals(ir_instruction *ir);
+
protected:
ir_instruction()
{
@@ -1405,6 +1415,8 @@ public:
return this;
}
+ virtual bool equals(ir_instruction *ir);
+
virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
/**
@@ -1739,6 +1751,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+ virtual bool equals(ir_instruction *ir);
+
/**
* Return a string representing the ir_texture_opcode.
*/
@@ -1843,6 +1857,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+ virtual bool equals(ir_instruction *ir);
+
bool is_lvalue() const
{
return val->is_lvalue() && !mask.has_duplicates;
@@ -1907,6 +1923,8 @@ public:
return this;
}
+ virtual bool equals(ir_instruction *ir);
+
/**
* Get the variable that is ultimately referenced by an r-value
*/
@@ -1965,6 +1983,8 @@ public:
return this;
}
+ virtual bool equals(ir_instruction *ir);
+
/**
* Get the variable that is ultimately referenced by an r-value
*/
@@ -2099,6 +2119,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
+ virtual bool equals(ir_instruction *ir);
+
/**
* Get a particular component of a constant as a specific type
*
diff --git a/mesalib/src/glsl/ir_equals.cpp b/mesalib/src/glsl/ir_equals.cpp
new file mode 100644
index 000000000..7cfe1e66b
--- /dev/null
+++ b/mesalib/src/glsl/ir_equals.cpp
@@ -0,0 +1,198 @@
+/*
+ * Copyright © 2013 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 "ir.h"
+
+/**
+ * Helper for checking equality when one instruction might be NULL, since you
+ * can't access a's vtable in that case.
+ */
+static bool
+possibly_null_equals(ir_instruction *a, ir_instruction *b)
+{
+ if (!a || !b)
+ return !a && !b;
+
+ return a->equals(b);
+}
+
+/**
+ * The base equality function: Return not equal for anything we don't know
+ * about.
+ */
+bool
+ir_instruction::equals(ir_instruction *ir)
+{
+ return false;
+}
+
+bool
+ir_constant::equals(ir_instruction *ir)
+{
+ const ir_constant *other = ir->as_constant();
+ if (!other)
+ return false;
+
+ if (type != other->type)
+ return false;
+
+ for (unsigned i = 0; i < type->components(); i++) {
+ if (value.u[i] != other->value.u[i])
+ return false;
+ }
+
+ return true;
+}
+
+bool
+ir_dereference_variable::equals(ir_instruction *ir)
+{
+ const ir_dereference_variable *other = ir->as_dereference_variable();
+ if (!other)
+ return false;
+
+ return var == other->var;
+}
+
+bool
+ir_dereference_array::equals(ir_instruction *ir)
+{
+ const ir_dereference_array *other = ir->as_dereference_array();
+ if (!other)
+ return false;
+
+ if (type != other->type)
+ return false;
+
+ if (!array->equals(other->array))
+ return false;
+
+ if (!array_index->equals(other->array_index))
+ return false;
+
+ return true;
+}
+
+bool
+ir_swizzle::equals(ir_instruction *ir)
+{
+ const ir_swizzle *other = ir->as_swizzle();
+ if (!other)
+ return false;
+
+ if (type != other->type)
+ return false;
+
+ if (mask.x != other->mask.x ||
+ mask.y != other->mask.y ||
+ mask.z != other->mask.z ||
+ mask.w != other->mask.w) {
+ return false;
+ }
+
+ return val->equals(other->val);
+}
+
+bool
+ir_texture::equals(ir_instruction *ir)
+{
+ const ir_texture *other = ir->as_texture();
+ if (!other)
+ return false;
+
+ if (type != other->type)
+ return false;
+
+ if (op != other->op)
+ return false;
+
+ if (!possibly_null_equals(coordinate, other->coordinate))
+ return false;
+
+ if (!possibly_null_equals(projector, other->projector))
+ return false;
+
+ if (!possibly_null_equals(shadow_comparitor, other->shadow_comparitor))
+ return false;
+
+ if (!possibly_null_equals(offset, other->offset))
+ return false;
+
+ if (!sampler->equals(other->sampler))
+ return false;
+
+ switch (op) {
+ case ir_tex:
+ case ir_lod:
+ case ir_query_levels:
+ break;
+ case ir_txb:
+ if (!lod_info.bias->equals(other->lod_info.bias))
+ return false;
+ break;
+ case ir_txl:
+ case ir_txf:
+ case ir_txs:
+ if (!lod_info.lod->equals(other->lod_info.lod))
+ return false;
+ break;
+ case ir_txd:
+ if (!lod_info.grad.dPdx->equals(other->lod_info.grad.dPdx) ||
+ !lod_info.grad.dPdy->equals(other->lod_info.grad.dPdy))
+ return false;
+ break;
+ case ir_txf_ms:
+ if (!lod_info.sample_index->equals(other->lod_info.sample_index))
+ return false;
+ break;
+ case ir_tg4:
+ if (!lod_info.component->equals(other->lod_info.component))
+ return false;
+ break;
+ default:
+ assert(!"Unrecognized texture op");
+ }
+
+ return true;
+}
+
+bool
+ir_expression::equals(ir_instruction *ir)
+{
+ const ir_expression *other = ir->as_expression();
+ if (!other)
+ return false;
+
+ if (type != other->type)
+ return false;
+
+ if (operation != other->operation)
+ return false;
+
+ for (unsigned i = 0; i < get_num_operands(); i++) {
+ if (!operands[i]->equals(other->operands[i]))
+ return false;
+ }
+
+ return true;
+}
diff --git a/mesalib/src/glsl/link_interface_blocks.cpp b/mesalib/src/glsl/link_interface_blocks.cpp
index 4f1c9d396..a7fceb9ba 100644
--- a/mesalib/src/glsl/link_interface_blocks.cpp
+++ b/mesalib/src/glsl/link_interface_blocks.cpp
@@ -30,13 +30,211 @@
#include "glsl_symbol_table.h"
#include "linker.h"
#include "main/macros.h"
+#include "program/hash_table.h"
+
+
+namespace {
+
+/**
+ * Information about a single interface block definition that we need to keep
+ * track of in order to check linkage rules.
+ *
+ * Note: this class is expected to be short lived, so it doesn't make copies
+ * of the strings it references; it simply borrows the pointers from the
+ * ir_variable class.
+ */
+struct interface_block_definition
+{
+ /**
+ * Extract an interface block definition from an ir_variable that
+ * represents either the interface instance (for named interfaces), or a
+ * member of the interface (for unnamed interfaces).
+ */
+ explicit interface_block_definition(const ir_variable *var)
+ : type(var->get_interface_type()),
+ instance_name(NULL),
+ array_size(-1)
+ {
+ if (var->is_interface_instance()) {
+ instance_name = var->name;
+ if (var->type->is_array())
+ array_size = var->type->length;
+ }
+ }
+
+ /**
+ * Interface block type
+ */
+ const glsl_type *type;
+
+ /**
+ * For a named interface block, the instance name. Otherwise NULL.
+ */
+ const char *instance_name;
+
+ /**
+ * For an interface block array, the array size (or 0 if unsized).
+ * Otherwise -1.
+ */
+ int array_size;
+};
+
+
+/**
+ * Check if two interfaces match, according to intrastage interface matching
+ * rules. If they do, and the first interface uses an unsized array, it will
+ * be updated to reflect the array size declared in the second interface.
+ */
+bool
+intrastage_match(interface_block_definition *a,
+ const interface_block_definition *b,
+ ir_variable_mode mode)
+{
+ /* Types must match. */
+ if (a->type != b->type)
+ return false;
+
+ /* Presence/absence of interface names must match. */
+ if ((a->instance_name == NULL) != (b->instance_name == NULL))
+ return false;
+
+ /* For uniforms, instance names need not match. For shader ins/outs,
+ * it's not clear from the spec whether they need to match, but
+ * Mesa's implementation relies on them matching.
+ */
+ if (a->instance_name != NULL && mode != ir_var_uniform &&
+ strcmp(a->instance_name, b->instance_name) != 0) {
+ return false;
+ }
+
+ /* Array vs. nonarray must be consistent, and sizes must be
+ * consistent, with the exception that unsized arrays match sized
+ * arrays.
+ */
+ if ((a->array_size == -1) != (b->array_size == -1))
+ return false;
+ if (b->array_size != 0) {
+ if (a->array_size == 0)
+ a->array_size = b->array_size;
+ else if (a->array_size != b->array_size)
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * Check if two interfaces match, according to interstage (in/out) interface
+ * matching rules.
+ *
+ * If \c extra_array_level is true, then vertex-to-geometry shader matching
+ * rules are enforced (i.e. a successful match requires the consumer interface
+ * to be an array and the producer interface to be a non-array).
+ */
+bool
+interstage_match(const interface_block_definition *producer,
+ const interface_block_definition *consumer,
+ bool extra_array_level)
+{
+ /* Unsized arrays should not occur during interstage linking. They
+ * should have all been assigned a size by link_intrastage_shaders.
+ */
+ assert(consumer->array_size != 0);
+ assert(producer->array_size != 0);
+
+ /* Types must match. */
+ if (consumer->type != producer->type)
+ return false;
+ if (extra_array_level) {
+ /* Consumer must be an array, and producer must not. */
+ if (consumer->array_size == -1)
+ return false;
+ if (producer->array_size != -1)
+ return false;
+ } else {
+ /* Array vs. nonarray must be consistent, and sizes must be consistent.
+ * Since unsized arrays have been ruled out, we can check this by just
+ * making sure the sizes are equal.
+ */
+ if (consumer->array_size != producer->array_size)
+ return false;
+ }
+ return true;
+}
+
+
+/**
+ * This class keeps track of a mapping from an interface block name to the
+ * necessary information about that interface block to determine whether to
+ * generate a link error.
+ *
+ * Note: this class is expected to be short lived, so it doesn't make copies
+ * of the strings it references; it simply borrows the pointers from the
+ * ir_variable class.
+ */
+class interface_block_definitions
+{
+public:
+ interface_block_definitions()
+ : mem_ctx(ralloc_context(NULL)),
+ ht(hash_table_ctor(0, hash_table_string_hash,
+ hash_table_string_compare))
+ {
+ }
+
+ ~interface_block_definitions()
+ {
+ hash_table_dtor(ht);
+ ralloc_free(mem_ctx);
+ }
+
+ /**
+ * Lookup the interface definition having the given block name. Return
+ * NULL if none is found.
+ */
+ interface_block_definition *lookup(const char *block_name)
+ {
+ return (interface_block_definition *) hash_table_find(ht, block_name);
+ }
+
+ /**
+ * Add a new interface definition.
+ */
+ void store(const interface_block_definition &def)
+ {
+ interface_block_definition *hash_entry =
+ rzalloc(mem_ctx, interface_block_definition);
+ *hash_entry = def;
+ hash_table_insert(ht, hash_entry, def.type->name);
+ }
+
+private:
+ /**
+ * Ralloc context for data structures allocated by this class.
+ */
+ void *mem_ctx;
+
+ /**
+ * Hash table mapping interface block name to an \c
+ * interface_block_definition struct. interface_block_definition structs
+ * are allocated using \c mem_ctx.
+ */
+ hash_table *ht;
+};
+
+
+}; /* anonymous namespace */
+
void
validate_intrastage_interface_blocks(struct gl_shader_program *prog,
const gl_shader **shader_list,
unsigned num_shaders)
{
- glsl_symbol_table interfaces;
+ interface_block_definitions in_interfaces;
+ interface_block_definitions out_interfaces;
+ interface_block_definitions uniform_interfaces;
for (unsigned int i = 0; i < num_shaders; i++) {
if (shader_list[i] == NULL)
@@ -52,17 +250,36 @@ validate_intrastage_interface_blocks(struct gl_shader_program *prog,
if (iface_type == NULL)
continue;
- const glsl_type *old_iface_type =
- interfaces.get_interface(iface_type->name,
- (enum ir_variable_mode) var->mode);
+ interface_block_definitions *definitions;
+ switch (var->mode) {
+ case ir_var_shader_in:
+ definitions = &in_interfaces;
+ break;
+ case ir_var_shader_out:
+ definitions = &out_interfaces;
+ break;
+ case ir_var_uniform:
+ definitions = &uniform_interfaces;
+ break;
+ default:
+ /* Only in, out, and uniform interfaces are legal, so we should
+ * never get here.
+ */
+ assert(!"illegal interface type");
+ continue;
+ }
- if (old_iface_type == NULL) {
+ const interface_block_definition def(var);
+ interface_block_definition *prev_def =
+ definitions->lookup(iface_type->name);
+
+ if (prev_def == NULL) {
/* This is the first time we've seen the interface, so save
- * it into our symbol table.
+ * it into the appropriate data structure.
*/
- interfaces.add_interface(iface_type->name, iface_type,
- (enum ir_variable_mode) var->mode);
- } else if (old_iface_type != iface_type) {
+ definitions->store(def);
+ } else if (!intrastage_match(prev_def, &def,
+ (ir_variable_mode) var->mode)) {
linker_error(prog, "definitions of interface block `%s' do not"
" match\n", iface_type->name);
return;
@@ -76,7 +293,9 @@ validate_interstage_interface_blocks(struct gl_shader_program *prog,
const gl_shader *producer,
const gl_shader *consumer)
{
- glsl_symbol_table interfaces;
+ interface_block_definitions inout_interfaces;
+ interface_block_definitions uniform_interfaces;
+ const bool extra_array_level = consumer->Type == GL_GEOMETRY_SHADER;
/* Add non-output interfaces from the consumer to the symbol table. */
foreach_list(node, consumer->ir) {
@@ -84,9 +303,9 @@ validate_interstage_interface_blocks(struct gl_shader_program *prog,
if (!var || !var->get_interface_type() || var->mode == ir_var_shader_out)
continue;
- interfaces.add_interface(var->get_interface_type()->name,
- var->get_interface_type(),
- (enum ir_variable_mode) var->mode);
+ interface_block_definitions *definitions = var->mode == ir_var_uniform ?
+ &uniform_interfaces : &inout_interfaces;
+ definitions->store(interface_block_definition(var));
}
/* Verify that the producer's interfaces match. */
@@ -95,17 +314,29 @@ validate_interstage_interface_blocks(struct gl_shader_program *prog,
if (!var || !var->get_interface_type() || var->mode == ir_var_shader_in)
continue;
- enum ir_variable_mode consumer_mode =
- var->mode == ir_var_uniform ? ir_var_uniform : ir_var_shader_in;
- const glsl_type *expected_type =
- interfaces.get_interface(var->get_interface_type()->name,
- consumer_mode);
+ interface_block_definitions *definitions = var->mode == ir_var_uniform ?
+ &uniform_interfaces : &inout_interfaces;
+ interface_block_definition *consumer_def =
+ definitions->lookup(var->get_interface_type()->name);
/* The consumer doesn't use this output block. Ignore it. */
- if (expected_type == NULL)
+ if (consumer_def == NULL)
continue;
- if (var->get_interface_type() != expected_type) {
+ const interface_block_definition producer_def(var);
+ bool match;
+ if (var->mode == ir_var_uniform) {
+ /* Uniform matching rules are the same for interstage and intrastage
+ * linking.
+ */
+ match = intrastage_match(consumer_def, &producer_def,
+ (ir_variable_mode) var->mode);
+ } else {
+ match = interstage_match(&producer_def, consumer_def,
+ extra_array_level);
+ }
+
+ if (!match) {
linker_error(prog, "definitions of interface block `%s' do not "
"match\n", var->get_interface_type()->name);
return;
diff --git a/mesalib/src/glsl/opt_algebraic.cpp b/mesalib/src/glsl/opt_algebraic.cpp
index a07e153ae..05a589989 100644
--- a/mesalib/src/glsl/opt_algebraic.cpp
+++ b/mesalib/src/glsl/opt_algebraic.cpp
@@ -357,7 +357,6 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
case ir_binop_logic_and:
- /* FINISHME: Also simplify (a && a) to (a). */
if (is_vec_one(op_const[0])) {
return ir->operands[1];
} else if (is_vec_one(op_const[1])) {
@@ -371,11 +370,13 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
*/
return logic_not(logic_or(op_expr[0]->operands[0],
op_expr[1]->operands[0]));
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a && a) == a */
+ return ir->operands[0];
}
break;
case ir_binop_logic_xor:
- /* FINISHME: Also simplify (a ^^ a) to (false). */
if (is_vec_zero(op_const[0])) {
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
@@ -384,11 +385,13 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
return logic_not(ir->operands[1]);
} else if (is_vec_one(op_const[1])) {
return logic_not(ir->operands[0]);
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a ^^ a) == false */
+ return ir_constant::zero(mem_ctx, ir->type);
}
break;
case ir_binop_logic_or:
- /* FINISHME: Also simplify (a || a) to (a). */
if (is_vec_zero(op_const[0])) {
return ir->operands[1];
} else if (is_vec_zero(op_const[1])) {
@@ -407,6 +410,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
*/
return logic_not(logic_and(op_expr[0]->operands[0],
op_expr[1]->operands[0]));
+ } else if (ir->operands[0]->equals(ir->operands[1])) {
+ /* (a || a) == a */
+ return ir->operands[0];
}
break;
@@ -414,10 +420,11 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp)
return op_expr[0]->operands[0];
- /* FINISHME: We should do rcp(rsq(x)) -> sqrt(x) for some
- * backends, except that some backends will have done sqrt ->
- * rcp(rsq(x)) and we don't want to undo it for them.
+ /* While ir_to_mesa.cpp will lower sqrt(x) to rcp(rsq(x)), it does so at
+ * its IR level, so we can always apply this transformation.
*/
+ if (op_expr[0] && op_expr[0]->operation == ir_unop_rsq)
+ return sqrt(op_expr[0]->operands[0]);
/* As far as we know, all backends are OK with rsq. */
if (op_expr[0] && op_expr[0]->operation == ir_unop_sqrt) {
diff --git a/mesalib/src/glsl/opt_cse.cpp b/mesalib/src/glsl/opt_cse.cpp
index c53b4c6e7..8f73940d8 100644
--- a/mesalib/src/glsl/opt_cse.cpp
+++ b/mesalib/src/glsl/opt_cse.cpp
@@ -243,184 +243,6 @@ is_cse_candidate(ir_rvalue *ir)
return v.ok;
}
-static bool
-equals(ir_rvalue *a, ir_rvalue *b);
-
-static bool
-equals(ir_constant *a, ir_constant *b)
-{
- if (!a || !b)
- return false;
-
- if (a->type != b->type)
- return false;
-
- for (unsigned i = 0; i < a->type->components(); i++) {
- if (a->value.u[i] != b->value.u[i])
- return false;
- }
-
- return true;
-}
-
-static bool
-equals(ir_dereference_variable *a, ir_dereference_variable *b)
-{
- if (!a || !b)
- return false;
-
- return a->var == b->var;
-}
-
-static bool
-equals(ir_dereference_array *a, ir_dereference_array *b)
-{
- if (!a || !b)
- return false;
-
- if (!equals(a->array, b->array))
- return false;
-
- if (!equals(a->array_index, b->array_index))
- return false;
-
- return true;
-}
-
-static bool
-equals(ir_swizzle *a, ir_swizzle *b)
-{
- if (!a || !b)
- return false;
-
- if (a->type != b->type)
- return false;
-
- if (a->mask.x != b->mask.x ||
- a->mask.y != b->mask.y ||
- a->mask.z != b->mask.z ||
- a->mask.w != b->mask.w) {
- return false;
- }
-
- return equals(a->val, b->val);
-}
-
-static bool
-equals(ir_texture *a, ir_texture *b)
-{
- if (!a || !b)
- return false;
-
- if (a->type != b->type)
- return false;
-
- if (a->op != b->op)
- return false;
-
- if (!equals(a->coordinate, b->coordinate))
- return false;
-
- if (!equals(a->projector, b->projector))
- return false;
-
- if (!equals(a->shadow_comparitor, b->shadow_comparitor))
- return false;
-
- if (!equals(a->offset, b->offset))
- return false;
-
- if (!equals(a->sampler, b->sampler))
- return false;
-
- switch (a->op) {
- case ir_tex:
- case ir_lod:
- case ir_query_levels:
- break;
- case ir_txb:
- if (!equals(a->lod_info.bias, b->lod_info.bias))
- return false;
- break;
- case ir_txl:
- case ir_txf:
- case ir_txs:
- if (!equals(a->lod_info.lod, b->lod_info.lod))
- return false;
- break;
- case ir_txd:
- if (!equals(a->lod_info.grad.dPdx, b->lod_info.grad.dPdx) ||
- !equals(a->lod_info.grad.dPdy, b->lod_info.grad.dPdy))
- return false;
- break;
- case ir_txf_ms:
- if (!equals(a->lod_info.sample_index, b->lod_info.sample_index))
- return false;
- break;
- case ir_tg4:
- if (!equals(a->lod_info.component, b->lod_info.component))
- return false;
- break;
- default:
- assert(!"Unrecognized texture op");
- }
-
- return true;
-}
-
-static bool
-equals(ir_expression *a, ir_expression *b)
-{
- if (!a || !b)
- return false;
-
- if (a->type != b->type)
- return false;
-
- if (a->operation != b->operation)
- return false;
-
- for (unsigned i = 0; i < a->get_num_operands(); i++) {
- if (!equals(a->operands[i], b->operands[i]))
- return false;
- }
-
- return true;
-}
-
-static bool
-equals(ir_rvalue *a, ir_rvalue *b)
-{
- if (!a || !b)
- return !a && !b;
-
- if (a->type != b->type)
- return false;
-
- switch (a->ir_type) {
- case ir_type_texture:
- return equals(a->as_texture(), b->as_texture());
-
- case ir_type_constant:
- return equals(a->as_constant(), b->as_constant());
-
- case ir_type_expression:
- return equals(a->as_expression(), b->as_expression());
-
- case ir_type_dereference_variable:
- return equals(a->as_dereference_variable(), b->as_dereference_variable());
-
- case ir_type_dereference_array:
- return equals(a->as_dereference_array(), b->as_dereference_array());
-
- case ir_type_swizzle:
- return equals(a->as_swizzle(), b->as_swizzle());
-
- default:
- return false;
- }
-}
-
/**
* Tries to find and return a reference to a previous computation of a given
* expression.
@@ -441,7 +263,7 @@ cse_visitor::try_cse(ir_rvalue *rvalue)
printf("\n");
}
- if (!equals(rvalue, *entry->val))
+ if (!rvalue->equals(*entry->val))
continue;
if (debug) {