[Mesa-dev] [PATCH 18/23] glsl: Constify ir_instruction::equals
Ian Romanick
idr at freedesktop.org
Fri Mar 20 13:58:18 PDT 2015
From: Ian Romanick <ian.d.romanick at intel.com>
The casts to remove const from ir are ugly. The alternative was to add
const versions of all the as_foo functions, and I just couldn't get up
the motivation to do that.
If there's a third option that is better, I would love to hear about
it. :)
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Francisco Jerez <currojerez at riseup.net>
---
src/glsl/ir.h | 21 ++++++++++++++-------
src/glsl/ir_equals.cpp | 34 ++++++++++++++++++++--------------
2 files changed, 34 insertions(+), 21 deletions(-)
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index fdc22ed..385d661 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -183,7 +183,8 @@ public:
* in particular. No support for other instruction types (assignments,
* jumps, calls, etc.) is planned.
*/
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
protected:
ir_instruction(enum ir_node_type t)
@@ -1598,7 +1599,8 @@ public:
*/
ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1, ir_rvalue *op2);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
@@ -1909,7 +1911,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
/**
* Return a string representing the ir_texture_opcode.
@@ -2010,7 +2013,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
bool is_lvalue() const
{
@@ -2063,7 +2067,8 @@ public:
virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
/**
* Get the variable that is ultimately referenced by an r-value
@@ -2109,7 +2114,8 @@ public:
virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
/**
* Get the variable that is ultimately referenced by an r-value
@@ -2219,7 +2225,8 @@ public:
virtual ir_visitor_status accept(ir_hierarchical_visitor *);
- virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
+ virtual bool equals(const ir_instruction *ir,
+ enum ir_node_type ignore = ir_type_unset) const;
/**
* Get a particular component of a constant as a specific type
diff --git a/src/glsl/ir_equals.cpp b/src/glsl/ir_equals.cpp
index 65376cd..d8066a0 100644
--- a/src/glsl/ir_equals.cpp
+++ b/src/glsl/ir_equals.cpp
@@ -28,7 +28,8 @@
* can't access a's vtable in that case.
*/
static bool
-possibly_null_equals(ir_instruction *a, ir_instruction *b, enum ir_node_type ignore)
+possibly_null_equals(const ir_instruction *a, const ir_instruction *b,
+ enum ir_node_type ignore)
{
if (!a || !b)
return !a && !b;
@@ -41,15 +42,15 @@ possibly_null_equals(ir_instruction *a, ir_instruction *b, enum ir_node_type ign
* about.
*/
bool
-ir_instruction::equals(ir_instruction *, enum ir_node_type)
+ir_instruction::equals(const ir_instruction *, enum ir_node_type) const
{
return false;
}
bool
-ir_constant::equals(ir_instruction *ir, enum ir_node_type)
+ir_constant::equals(const ir_instruction *ir, enum ir_node_type) const
{
- const ir_constant *other = ir->as_constant();
+ const ir_constant *other = ((ir_instruction *)ir)->as_constant();
if (!other)
return false;
@@ -65,9 +66,11 @@ ir_constant::equals(ir_instruction *ir, enum ir_node_type)
}
bool
-ir_dereference_variable::equals(ir_instruction *ir, enum ir_node_type)
+ir_dereference_variable::equals(const ir_instruction *ir,
+ enum ir_node_type) const
{
- const ir_dereference_variable *other = ir->as_dereference_variable();
+ const ir_dereference_variable *other =
+ ((ir_instruction *)ir)->as_dereference_variable();
if (!other)
return false;
@@ -75,9 +78,11 @@ ir_dereference_variable::equals(ir_instruction *ir, enum ir_node_type)
}
bool
-ir_dereference_array::equals(ir_instruction *ir, enum ir_node_type ignore)
+ir_dereference_array::equals(const ir_instruction *ir,
+ enum ir_node_type ignore) const
{
- const ir_dereference_array *other = ir->as_dereference_array();
+ const ir_dereference_array *other =
+ ((ir_instruction *)ir)->as_dereference_array();
if (!other)
return false;
@@ -94,9 +99,10 @@ ir_dereference_array::equals(ir_instruction *ir, enum ir_node_type ignore)
}
bool
-ir_swizzle::equals(ir_instruction *ir, enum ir_node_type ignore)
+ir_swizzle::equals(const ir_instruction *ir,
+ enum ir_node_type ignore) const
{
- const ir_swizzle *other = ir->as_swizzle();
+ const ir_swizzle *other = ((ir_instruction *)ir)->as_swizzle();
if (!other)
return false;
@@ -116,9 +122,9 @@ ir_swizzle::equals(ir_instruction *ir, enum ir_node_type ignore)
}
bool
-ir_texture::equals(ir_instruction *ir, enum ir_node_type ignore)
+ir_texture::equals(const ir_instruction *ir, enum ir_node_type ignore) const
{
- const ir_texture *other = ir->as_texture();
+ const ir_texture *other = ((ir_instruction *)ir)->as_texture();
if (!other)
return false;
@@ -179,9 +185,9 @@ ir_texture::equals(ir_instruction *ir, enum ir_node_type ignore)
}
bool
-ir_expression::equals(ir_instruction *ir, enum ir_node_type ignore)
+ir_expression::equals(const ir_instruction *ir, enum ir_node_type ignore) const
{
- const ir_expression *other = ir->as_expression();
+ const ir_expression *other = ((ir_instruction *)ir)->as_expression();
if (!other)
return false;
--
2.1.0
More information about the mesa-dev
mailing list