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 s
= this->coordinate
->accept(v
);
175 if (s
!= visit_continue
)
176 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
178 if (this->projector
) {
179 s
= this->projector
->accept(v
);
180 if (s
!= visit_continue
)
181 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
184 if (this->shadow_comparitor
) {
185 s
= this->shadow_comparitor
->accept(v
);
186 if (s
!= visit_continue
)
187 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
191 s
= this->offset
->accept(v
);
192 if (s
!= visit_continue
)
193 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
200 s
= this->lod_info
.bias
->accept(v
);
201 if (s
!= visit_continue
)
202 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
206 s
= this->lod_info
.lod
->accept(v
);
207 if (s
!= visit_continue
)
208 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
211 s
= this->lod_info
.grad
.dPdx
->accept(v
);
212 if (s
!= visit_continue
)
213 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
215 s
= this->lod_info
.grad
.dPdy
->accept(v
);
216 if (s
!= visit_continue
)
217 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
221 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
226 ir_swizzle::accept(ir_hierarchical_visitor
*v
)
228 ir_visitor_status s
= v
->visit_enter(this);
229 if (s
!= visit_continue
)
230 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
232 s
= this->val
->accept(v
);
233 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
238 ir_dereference_variable::accept(ir_hierarchical_visitor
*v
)
240 return v
->visit(this);
245 ir_dereference_array::accept(ir_hierarchical_visitor
*v
)
247 ir_visitor_status s
= v
->visit_enter(this);
248 if (s
!= visit_continue
)
249 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
251 /* The array index is not the target of the assignment, so clear the
252 * 'in_assignee' flag. Restore it after returning from the array index.
254 const bool was_in_assignee
= v
->in_assignee
;
255 v
->in_assignee
= false;
256 s
= this->array_index
->accept(v
);
257 v
->in_assignee
= was_in_assignee
;
259 if (s
!= visit_continue
)
260 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
262 s
= this->array
->accept(v
);
263 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
268 ir_dereference_record::accept(ir_hierarchical_visitor
*v
)
270 ir_visitor_status s
= v
->visit_enter(this);
271 if (s
!= visit_continue
)
272 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
274 s
= this->record
->accept(v
);
275 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
280 ir_assignment::accept(ir_hierarchical_visitor
*v
)
282 ir_visitor_status s
= v
->visit_enter(this);
283 if (s
!= visit_continue
)
284 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
286 v
->in_assignee
= true;
287 s
= this->lhs
->accept(v
);
288 v
->in_assignee
= false;
289 if (s
!= visit_continue
)
290 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
292 s
= this->rhs
->accept(v
);
293 if (s
!= visit_continue
)
294 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
297 s
= this->condition
->accept(v
);
299 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
304 ir_constant::accept(ir_hierarchical_visitor
*v
)
306 return v
->visit(this);
311 ir_call::accept(ir_hierarchical_visitor
*v
)
313 ir_visitor_status s
= v
->visit_enter(this);
314 if (s
!= visit_continue
)
315 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
317 s
= visit_list_elements(v
, &this->actual_parameters
);
321 return v
->visit_leave(this);
326 ir_return::accept(ir_hierarchical_visitor
*v
)
328 ir_visitor_status s
= v
->visit_enter(this);
329 if (s
!= visit_continue
)
330 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
332 ir_rvalue
*val
= this->get_value();
335 if (s
!= visit_continue
)
336 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
339 return v
->visit_leave(this);
344 ir_discard::accept(ir_hierarchical_visitor
*v
)
346 ir_visitor_status s
= v
->visit_enter(this);
347 if (s
!= visit_continue
)
348 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
350 if (this->condition
!= NULL
) {
351 s
= this->condition
->accept(v
);
352 if (s
!= visit_continue
)
353 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
356 return v
->visit_leave(this);
361 ir_if::accept(ir_hierarchical_visitor
*v
)
363 ir_visitor_status s
= v
->visit_enter(this);
364 if (s
!= visit_continue
)
365 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
367 s
= this->condition
->accept(v
);
368 if (s
!= visit_continue
)
369 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
371 if (s
!= visit_continue_with_parent
) {
372 s
= visit_list_elements(v
, &this->then_instructions
);
377 if (s
!= visit_continue_with_parent
) {
378 s
= visit_list_elements(v
, &this->else_instructions
);
383 return v
->visit_leave(this);