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.
35 * If statement_list is true (the default), this is a list of statements, so
36 * v->base_ir will be set to point to each statement just before iterating
37 * over it, and restored after iteration is complete. If statement_list is
38 * false, this is a list that appears inside a statement (e.g. a parameter
39 * list), so v->base_ir will be left alone.
42 * This function will operate correctly if a node being processed is removed
43 * from the list. However, if nodes are added to the list after the node being
44 * processed, some of the added nodes may not be processed.
47 visit_list_elements(ir_hierarchical_visitor
*v
, exec_list
*l
,
50 ir_instruction
*prev_base_ir
= v
->base_ir
;
52 foreach_list_safe(n
, l
) {
53 ir_instruction
*const ir
= (ir_instruction
*) n
;
56 ir_visitor_status s
= ir
->accept(v
);
58 if (s
!= visit_continue
)
62 v
->base_ir
= prev_base_ir
;
64 return visit_continue
;
69 ir_variable::accept(ir_hierarchical_visitor
*v
)
71 return v
->visit(this);
76 ir_loop::accept(ir_hierarchical_visitor
*v
)
78 ir_visitor_status s
= v
->visit_enter(this);
80 if (s
!= visit_continue
)
81 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
83 s
= visit_list_elements(v
, &this->body_instructions
);
87 if (s
!= visit_continue_with_parent
) {
89 s
= this->from
->accept(v
);
90 if (s
!= visit_continue
)
91 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
95 s
= this->to
->accept(v
);
96 if (s
!= visit_continue
)
97 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
100 if (this->increment
) {
101 s
= this->increment
->accept(v
);
102 if (s
!= visit_continue
)
103 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
107 return v
->visit_leave(this);
112 ir_loop_jump::accept(ir_hierarchical_visitor
*v
)
114 return v
->visit(this);
119 ir_function_signature::accept(ir_hierarchical_visitor
*v
)
121 ir_visitor_status s
= v
->visit_enter(this);
122 if (s
!= visit_continue
)
123 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
125 s
= visit_list_elements(v
, &this->parameters
);
129 s
= visit_list_elements(v
, &this->body
);
130 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
135 ir_function::accept(ir_hierarchical_visitor
*v
)
137 ir_visitor_status s
= v
->visit_enter(this);
138 if (s
!= visit_continue
)
139 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
141 s
= visit_list_elements(v
, &this->signatures
, false);
142 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
147 ir_expression::accept(ir_hierarchical_visitor
*v
)
149 ir_visitor_status s
= v
->visit_enter(this);
151 if (s
!= visit_continue
)
152 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
154 for (unsigned i
= 0; i
< this->get_num_operands(); i
++) {
155 switch (this->operands
[i
]->accept(v
)) {
159 case visit_continue_with_parent
:
160 // I wish for Java's labeled break-statement here.
169 return v
->visit_leave(this);
173 ir_texture::accept(ir_hierarchical_visitor
*v
)
175 ir_visitor_status s
= v
->visit_enter(this);
176 if (s
!= visit_continue
)
177 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
179 s
= this->sampler
->accept(v
);
180 if (s
!= visit_continue
)
181 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
183 if (this->coordinate
) {
184 s
= this->coordinate
->accept(v
);
185 if (s
!= visit_continue
)
186 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
189 if (this->projector
) {
190 s
= this->projector
->accept(v
);
191 if (s
!= visit_continue
)
192 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
195 if (this->shadow_comparitor
) {
196 s
= this->shadow_comparitor
->accept(v
);
197 if (s
!= visit_continue
)
198 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
202 s
= this->offset
->accept(v
);
203 if (s
!= visit_continue
)
204 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
211 s
= this->lod_info
.bias
->accept(v
);
212 if (s
!= visit_continue
)
213 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
218 s
= this->lod_info
.lod
->accept(v
);
219 if (s
!= visit_continue
)
220 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
223 s
= this->lod_info
.grad
.dPdx
->accept(v
);
224 if (s
!= visit_continue
)
225 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
227 s
= this->lod_info
.grad
.dPdy
->accept(v
);
228 if (s
!= visit_continue
)
229 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
233 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
238 ir_swizzle::accept(ir_hierarchical_visitor
*v
)
240 ir_visitor_status s
= v
->visit_enter(this);
241 if (s
!= visit_continue
)
242 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
244 s
= this->val
->accept(v
);
245 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
250 ir_dereference_variable::accept(ir_hierarchical_visitor
*v
)
252 return v
->visit(this);
257 ir_dereference_array::accept(ir_hierarchical_visitor
*v
)
259 ir_visitor_status s
= v
->visit_enter(this);
260 if (s
!= visit_continue
)
261 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
263 /* The array index is not the target of the assignment, so clear the
264 * 'in_assignee' flag. Restore it after returning from the array index.
266 const bool was_in_assignee
= v
->in_assignee
;
267 v
->in_assignee
= false;
268 s
= this->array_index
->accept(v
);
269 v
->in_assignee
= was_in_assignee
;
271 if (s
!= visit_continue
)
272 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
274 s
= this->array
->accept(v
);
275 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
280 ir_dereference_record::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 s
= this->record
->accept(v
);
287 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
292 ir_assignment::accept(ir_hierarchical_visitor
*v
)
294 ir_visitor_status s
= v
->visit_enter(this);
295 if (s
!= visit_continue
)
296 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
298 v
->in_assignee
= true;
299 s
= this->lhs
->accept(v
);
300 v
->in_assignee
= false;
301 if (s
!= visit_continue
)
302 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
304 s
= this->rhs
->accept(v
);
305 if (s
!= visit_continue
)
306 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
309 s
= this->condition
->accept(v
);
311 return (s
== visit_stop
) ? s
: v
->visit_leave(this);
316 ir_constant::accept(ir_hierarchical_visitor
*v
)
318 return v
->visit(this);
323 ir_call::accept(ir_hierarchical_visitor
*v
)
325 ir_visitor_status s
= v
->visit_enter(this);
326 if (s
!= visit_continue
)
327 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
329 s
= visit_list_elements(v
, &this->actual_parameters
, false);
333 return v
->visit_leave(this);
338 ir_return::accept(ir_hierarchical_visitor
*v
)
340 ir_visitor_status s
= v
->visit_enter(this);
341 if (s
!= visit_continue
)
342 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
344 ir_rvalue
*val
= this->get_value();
347 if (s
!= visit_continue
)
348 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
351 return v
->visit_leave(this);
356 ir_discard::accept(ir_hierarchical_visitor
*v
)
358 ir_visitor_status s
= v
->visit_enter(this);
359 if (s
!= visit_continue
)
360 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
362 if (this->condition
!= NULL
) {
363 s
= this->condition
->accept(v
);
364 if (s
!= visit_continue
)
365 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
368 return v
->visit_leave(this);
373 ir_if::accept(ir_hierarchical_visitor
*v
)
375 ir_visitor_status s
= v
->visit_enter(this);
376 if (s
!= visit_continue
)
377 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
379 s
= this->condition
->accept(v
);
380 if (s
!= visit_continue
)
381 return (s
== visit_continue_with_parent
) ? visit_continue
: s
;
383 if (s
!= visit_continue_with_parent
) {
384 s
= visit_list_elements(v
, &this->then_instructions
);
389 if (s
!= visit_continue_with_parent
) {
390 s
= visit_list_elements(v
, &this->else_instructions
);
395 return v
->visit_leave(this);