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.
27 * \file ir_hv_accept.cpp
28 * Implementations of all hierarchical visitor accept methods for IR
33 * Process a list of nodes using a hierarchical vistor
36 * This function will operate correctly if a node being processed is removed
37 * from list. However, if nodes are added to the list after the node being
38 * processed, some of the added noded may not be processed.
40 static ir_visitor_status
41 visit_list_elements(ir_hierarchical_visitor
*v
, exec_list
*l
)
45 for (exec_node
*n
= l
->head
; n
->next
!= NULL
; n
= next
) {
48 ir_instruction
*const ir
= (ir_instruction
*) n
;
49 ir_visitor_status s
= ir
->accept(v
);
51 if (s
!= visit_continue
)
55 return visit_continue
;
60 ir_variable::accept(ir_hierarchical_visitor
*v
)
62 return v
->visit(this);
67 ir_loop::accept(ir_hierarchical_visitor
*v
)
69 ir_visitor_status s
= v
->visit_enter(this);
71 if (s
!= visit_continue
)
72 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
74 s
= visit_list_elements(v
, &this->body_instructions
);
78 if (s
!= visit_continue_with_parent
) {
80 s
= this->from
->accept(v
);
81 if (s
!= visit_continue
)
82 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
86 s
= this->to
->accept(v
);
87 if (s
!= visit_continue
)
88 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
91 if (this->increment
) {
92 s
= this->increment
->accept(v
);
93 if (s
!= visit_continue
)
94 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
98 return v
->visit_leave(this);
103 ir_loop_jump::accept(ir_hierarchical_visitor
*v
)
105 return v
->visit(this);
110 ir_function_signature::accept(ir_hierarchical_visitor
*v
)
112 ir_visitor_status s
= v
->visit_enter(this);
113 if (s
!= visit_continue
)
114 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
116 s
= visit_list_elements(v
, &this->body
);
117 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
122 ir_function::accept(ir_hierarchical_visitor
*v
)
124 ir_visitor_status s
= v
->visit_enter(this);
125 if (s
!= visit_continue
)
126 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
128 s
= visit_list_elements(v
, &this->signatures
);
129 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
134 ir_expression::accept(ir_hierarchical_visitor
*v
)
136 ir_visitor_status s
= v
->visit_enter(this);
138 if (s
!= visit_continue
)
139 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
141 for (unsigned i
= 0; i
< this->get_num_operands(); i
++) {
142 switch (this->operands
[i
]->accept(v
)) {
146 case visit_continue_with_parent
:
147 // I wish for Java's labeled break-statement here.
156 return v
->visit_leave(this);
160 ir_texture::accept(ir_hierarchical_visitor
*v
)
162 return visit_continue_with_parent
;
167 ir_swizzle::accept(ir_hierarchical_visitor
*v
)
169 ir_visitor_status s
= v
->visit_enter(this);
170 if (s
!= visit_continue
)
171 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
173 s
= this->val
->accept(v
);
174 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
179 ir_dereference_variable::accept(ir_hierarchical_visitor
*v
)
181 return v
->visit(this);
186 ir_dereference_array::accept(ir_hierarchical_visitor
*v
)
188 ir_visitor_status s
= v
->visit_enter(this);
189 if (s
!= visit_continue
)
190 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
192 s
= this->array_index
->accept(v
);
193 if (s
!= visit_continue
)
194 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
196 s
= this->array
->accept(v
);
197 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
202 ir_dereference_record::accept(ir_hierarchical_visitor
*v
)
204 ir_visitor_status s
= v
->visit_enter(this);
205 if (s
!= visit_continue
)
206 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
208 s
= this->record
->accept(v
);
209 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
214 ir_assignment::accept(ir_hierarchical_visitor
*v
)
216 ir_visitor_status s
= v
->visit_enter(this);
217 if (s
!= visit_continue
)
218 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
220 s
= this->lhs
->accept(v
);
221 if (s
!= visit_continue
)
222 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
224 s
= this->rhs
->accept(v
);
225 if (s
!= visit_continue
)
226 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
229 s
= this->condition
->accept(v
);
231 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
236 ir_constant::accept(ir_hierarchical_visitor
*v
)
238 return v
->visit(this);
243 ir_call::accept(ir_hierarchical_visitor
*v
)
245 ir_visitor_status s
= v
->visit_enter(this);
246 if (s
!= visit_continue
)
247 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
249 s
= visit_list_elements(v
, &this->actual_parameters
);
253 return v
->visit_leave(this);
258 ir_return::accept(ir_hierarchical_visitor
*v
)
260 ir_visitor_status s
= v
->visit_enter(this);
261 if (s
!= visit_continue
)
262 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
264 ir_rvalue
*val
= this->get_value();
267 if (s
!= visit_continue
)
268 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
271 return v
->visit_leave(this);
276 ir_if::accept(ir_hierarchical_visitor
*v
)
278 ir_visitor_status s
= v
->visit_enter(this);
279 if (s
!= visit_continue
)
280 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
282 s
= this->condition
->accept(v
);
283 if (s
!= visit_continue
)
284 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
286 if (s
!= visit_continue_with_parent
) {
287 s
= visit_list_elements(v
, &this->then_instructions
);
292 if (s
!= visit_continue_with_parent
) {
293 s
= visit_list_elements(v
, &this->else_instructions
);
298 return v
->visit_leave(this);