2 * Copyright © 2010 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.
25 * \file ir_validate.cpp
27 * Attempts to verify that various invariants of the IR tree are true.
29 * In particular, at the moment it makes sure that no single
30 * ir_instruction node except for ir_variable appears multiple times
31 * in the ir tree. ir_variable does appear multiple times: Once as a
32 * declaration in an exec_list, and multiple times as the endpoint of
33 * a dereference chain.
38 #include "ir_visitor.h"
39 #include "ir_optimization.h"
40 #include "glsl_types.h"
41 #include "hash_table.h"
44 * Visitor class for replacing expressions with ir_constant values.
48 class ir_validate
: public ir_hierarchical_visitor
{
50 virtual ir_visitor_status
visit_enter(class ir_constant
*);
51 virtual ir_visitor_status
visit_enter(class ir_loop
*);
52 virtual ir_visitor_status
visit_enter(class ir_function_signature
*);
53 virtual ir_visitor_status
visit_enter(class ir_function
*);
54 virtual ir_visitor_status
visit_enter(class ir_expression
*);
55 virtual ir_visitor_status
visit_enter(class ir_texture
*);
56 virtual ir_visitor_status
visit_enter(class ir_swizzle
*);
57 virtual ir_visitor_status
visit_enter(class ir_dereference_array
*);
58 virtual ir_visitor_status
visit_enter(class ir_dereference_record
*);
59 virtual ir_visitor_status
visit_enter(class ir_assignment
*);
60 virtual ir_visitor_status
visit_enter(class ir_call
*);
61 virtual ir_visitor_status
visit_enter(class ir_return
*);
62 virtual ir_visitor_status
visit_enter(class ir_if
*);
64 void validate_ir(ir_instruction
*ir
);
66 struct hash_table
*ht
;
69 unsigned int hash_func(const void *key
)
71 return (unsigned int)(uintptr_t)key
;
74 int hash_compare_func(const void *key1
, const void *key2
)
76 return key1
== key2
? 0 : 1;
80 ir_validate::validate_ir(ir_instruction
*ir
)
82 if (hash_table_find(this->ht
, ir
)) {
83 printf("Instruction node present twice in ir tree:\n");
88 hash_table_insert(this->ht
, ir
, ir
);
92 ir_validate::visit_enter(ir_constant
*ir
)
95 return visit_continue
;
99 ir_validate::visit_enter(ir_loop
*ir
)
102 return visit_continue
;
106 ir_validate::visit_enter(ir_function_signature
*ir
)
109 return visit_continue
;
113 ir_validate::visit_enter(ir_function
*ir
)
116 return visit_continue
;
120 ir_validate::visit_enter(ir_expression
*ir
)
123 return visit_continue
;
127 ir_validate::visit_enter(ir_texture
*ir
)
130 return visit_continue
;
134 ir_validate::visit_enter(ir_swizzle
*ir
)
137 return visit_continue
;
141 ir_validate::visit_enter(ir_dereference_array
*ir
)
144 return visit_continue
;
148 ir_validate::visit_enter(ir_dereference_record
*ir
)
151 return visit_continue
;
155 ir_validate::visit_enter(ir_assignment
*ir
)
158 return visit_continue
;
162 ir_validate::visit_enter(ir_call
*ir
)
165 return visit_continue
;
169 ir_validate::visit_enter(ir_return
*ir
)
172 return visit_continue
;
176 ir_validate::visit_enter(ir_if
*ir
)
179 return visit_continue
;
183 validate_ir_tree(exec_list
*instructions
)
187 v
.ht
= hash_table_ctor(0, hash_func
, hash_compare_func
);
191 hash_table_dtor(v
.ht
);