2 * Copyright © 2013 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
27 * Helper for checking equality when one instruction might be NULL, since you
28 * can't access a's vtable in that case.
31 possibly_null_equals(ir_instruction
*a
, ir_instruction
*b
)
40 * The base equality function: Return not equal for anything we don't know
44 ir_instruction::equals(ir_instruction
*ir
)
50 ir_constant::equals(ir_instruction
*ir
)
52 const ir_constant
*other
= ir
->as_constant();
56 if (type
!= other
->type
)
59 for (unsigned i
= 0; i
< type
->components(); i
++) {
60 if (value
.u
[i
] != other
->value
.u
[i
])
68 ir_dereference_variable::equals(ir_instruction
*ir
)
70 const ir_dereference_variable
*other
= ir
->as_dereference_variable();
74 return var
== other
->var
;
78 ir_dereference_array::equals(ir_instruction
*ir
)
80 const ir_dereference_array
*other
= ir
->as_dereference_array();
84 if (type
!= other
->type
)
87 if (!array
->equals(other
->array
))
90 if (!array_index
->equals(other
->array_index
))
97 ir_swizzle::equals(ir_instruction
*ir
)
99 const ir_swizzle
*other
= ir
->as_swizzle();
103 if (type
!= other
->type
)
106 if (mask
.x
!= other
->mask
.x
||
107 mask
.y
!= other
->mask
.y
||
108 mask
.z
!= other
->mask
.z
||
109 mask
.w
!= other
->mask
.w
) {
113 return val
->equals(other
->val
);
117 ir_texture::equals(ir_instruction
*ir
)
119 const ir_texture
*other
= ir
->as_texture();
123 if (type
!= other
->type
)
129 if (!possibly_null_equals(coordinate
, other
->coordinate
))
132 if (!possibly_null_equals(projector
, other
->projector
))
135 if (!possibly_null_equals(shadow_comparitor
, other
->shadow_comparitor
))
138 if (!possibly_null_equals(offset
, other
->offset
))
141 if (!sampler
->equals(other
->sampler
))
147 case ir_query_levels
:
150 if (!lod_info
.bias
->equals(other
->lod_info
.bias
))
156 if (!lod_info
.lod
->equals(other
->lod_info
.lod
))
160 if (!lod_info
.grad
.dPdx
->equals(other
->lod_info
.grad
.dPdx
) ||
161 !lod_info
.grad
.dPdy
->equals(other
->lod_info
.grad
.dPdy
))
165 if (!lod_info
.sample_index
->equals(other
->lod_info
.sample_index
))
169 if (!lod_info
.component
->equals(other
->lod_info
.component
))
173 assert(!"Unrecognized texture op");
180 ir_expression::equals(ir_instruction
*ir
)
182 const ir_expression
*other
= ir
->as_expression();
186 if (type
!= other
->type
)
189 if (operation
!= other
->operation
)
192 for (unsigned i
= 0; i
< get_num_operands(); i
++) {
193 if (!operands
[i
]->equals(other
->operands
[i
]))