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 the list. However, if nodes are added to the list after the node being
38 * processed, some of the added nodes may not be processed.
41 visit_list_elements(ir_hierarchical_visitor
*v
, exec_list
*l
)
43 ir_instruction
*prev_base_ir
= v
->base_ir
;
45 foreach_list_safe(n
, l
) {
46 ir_instruction
*const ir
= (ir_instruction
*) n
;
48 ir_visitor_status s
= ir
->accept(v
);
50 if (s
!= visit_continue
)
53 v
->base_ir
= prev_base_ir
;
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->parameters
);
120 s
= visit_list_elements(v
, &this->body
);
121 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
126 ir_function::accept(ir_hierarchical_visitor
*v
)
128 ir_visitor_status s
= v
->visit_enter(this);
129 if (s
!= visit_continue
)
130 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
132 s
= visit_list_elements(v
, &this->signatures
);
133 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
138 ir_expression::accept(ir_hierarchical_visitor
*v
)
140 ir_visitor_status s
= v
->visit_enter(this);
142 if (s
!= visit_continue
)
143 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
145 for (unsigned i
= 0; i
< this->get_num_operands(); i
++) {
146 switch (this->operands
[i
]->accept(v
)) {
150 case visit_continue_with_parent
:
151 // I wish for Java's labeled break-statement here.
160 return v
->visit_leave(this);
164 ir_texture::accept(ir_hierarchical_visitor
*v
)
166 ir_visitor_status s
= v
->visit_enter(this);
167 if (s
!= visit_continue
)
168 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
170 s
= this->sampler
->accept(v
);
171 if (s
!= visit_continue
)
172 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
174 if (this->coordinate
) {
175 s
= this->coordinate
->accept(v
);
176 if (s
!= visit_continue
)
177 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
180 if (this->projector
) {
181 s
= this->projector
->accept(v
);
182 if (s
!= visit_continue
)
183 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
186 if (this->shadow_comparitor
) {
187 s
= this->shadow_comparitor
->accept(v
);
188 if (s
!= visit_continue
)
189 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
193 s
= this->offset
->accept(v
);
194 if (s
!= visit_continue
)
195 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
202 s
= this->lod_info
.bias
->accept(v
);
203 if (s
!= visit_continue
)
204 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
209 s
= this->lod_info
.lod
->accept(v
);
210 if (s
!= visit_continue
)
211 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
214 s
= this->lod_info
.grad
.dPdx
->accept(v
);
215 if (s
!= visit_continue
)
216 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
218 s
= this->lod_info
.grad
.dPdy
->accept(v
);
219 if (s
!= visit_continue
)
220 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
224 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
229 ir_swizzle::accept(ir_hierarchical_visitor
*v
)
231 ir_visitor_status s
= v
->visit_enter(this);
232 if (s
!= visit_continue
)
233 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
235 s
= this->val
->accept(v
);
236 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
241 ir_dereference_variable::accept(ir_hierarchical_visitor
*v
)
243 return v
->visit(this);
248 ir_dereference_array::accept(ir_hierarchical_visitor
*v
)
250 ir_visitor_status s
= v
->visit_enter(this);
251 if (s
!= visit_continue
)
252 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
254 /* The array index is not the target of the assignment, so clear the
255 * 'in_assignee' flag. Restore it after returning from the array index.
257 const bool was_in_assignee
= v
->in_assignee
;
258 v
->in_assignee
= false;
259 s
= this->array_index
->accept(v
);
260 v
->in_assignee
= was_in_assignee
;
262 if (s
!= visit_continue
)
263 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
265 s
= this->array
->accept(v
);
266 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
271 ir_dereference_record::accept(ir_hierarchical_visitor
*v
)
273 ir_visitor_status s
= v
->visit_enter(this);
274 if (s
!= visit_continue
)
275 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
277 s
= this->record
->accept(v
);
278 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
283 ir_assignment::accept(ir_hierarchical_visitor
*v
)
285 ir_visitor_status s
= v
->visit_enter(this);
286 if (s
!= visit_continue
)
287 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
289 v
->in_assignee
= true;
290 s
= this->lhs
->accept(v
);
291 v
->in_assignee
= false;
292 if (s
!= visit_continue
)
293 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
295 s
= this->rhs
->accept(v
);
296 if (s
!= visit_continue
)
297 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
300 s
= this->condition
->accept(v
);
302 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
307 ir_constant::accept(ir_hierarchical_visitor
*v
)
309 return v
->visit(this);
314 ir_call::accept(ir_hierarchical_visitor
*v
)
316 ir_visitor_status s
= v
->visit_enter(this);
317 if (s
!= visit_continue
)
318 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
320 s
= visit_list_elements(v
, &this->actual_parameters
);
324 return v
->visit_leave(this);
329 ir_return::accept(ir_hierarchical_visitor
*v
)
331 ir_visitor_status s
= v
->visit_enter(this);
332 if (s
!= visit_continue
)
333 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
335 ir_rvalue
*val
= this->get_value();
338 if (s
!= visit_continue
)
339 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
342 return v
->visit_leave(this);
347 ir_discard::accept(ir_hierarchical_visitor
*v
)
349 ir_visitor_status s
= v
->visit_enter(this);
350 if (s
!= visit_continue
)
351 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
353 if (this->condition
!= NULL
) {
354 s
= this->condition
->accept(v
);
355 if (s
!= visit_continue
)
356 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
359 return v
->visit_leave(this);
364 ir_if::accept(ir_hierarchical_visitor
*v
)
366 ir_visitor_status s
= v
->visit_enter(this);
367 if (s
!= visit_continue
)
368 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
370 s
= this->condition
->accept(v
);
371 if (s
!= visit_continue
)
372 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
374 if (s
!= visit_continue_with_parent
) {
375 s
= visit_list_elements(v
, &this->then_instructions
);
380 if (s
!= visit_continue_with_parent
) {
381 s
= visit_list_elements(v
, &this->else_instructions
);
386 return v
->visit_leave(this);