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_rvalue_visitor.cpp
27 * Generic class to implement the common pattern we have of wanting to
28 * visit each ir_rvalue * and possibly change that node to a different
33 #include "ir_visitor.h"
34 #include "ir_rvalue_visitor.h"
35 #include "ir_print_visitor.h"
36 #include "glsl_types.h"
39 ir_rvalue_visitor::visit_leave(ir_expression
*ir
)
43 for (operand
= 0; operand
< ir
->get_num_operands(); operand
++) {
44 handle_rvalue(&ir
->operands
[operand
]);
47 return visit_continue
;
51 ir_rvalue_visitor::visit_leave(ir_texture
*ir
)
53 handle_rvalue(&ir
->coordinate
);
54 handle_rvalue(&ir
->projector
);
55 handle_rvalue(&ir
->shadow_comparitor
);
56 handle_rvalue(&ir
->offset
);
62 handle_rvalue(&ir
->lod_info
.bias
);
66 handle_rvalue(&ir
->lod_info
.lod
);
69 handle_rvalue(&ir
->lod_info
.grad
.dPdx
);
70 handle_rvalue(&ir
->lod_info
.grad
.dPdy
);
74 return visit_continue
;
78 ir_rvalue_visitor::visit_leave(ir_swizzle
*ir
)
80 handle_rvalue(&ir
->val
);
81 return visit_continue
;
85 ir_rvalue_visitor::visit_leave(ir_dereference_array
*ir
)
87 /* The array index is not the target of the assignment, so clear the
88 * 'in_assignee' flag. Restore it after returning from the array index.
90 const bool was_in_assignee
= this->in_assignee
;
91 this->in_assignee
= false;
92 handle_rvalue(&ir
->array_index
);
93 this->in_assignee
= was_in_assignee
;
95 handle_rvalue(&ir
->array
);
96 return visit_continue
;
100 ir_rvalue_visitor::visit_leave(ir_dereference_record
*ir
)
102 handle_rvalue(&ir
->record
);
103 return visit_continue
;
107 ir_rvalue_visitor::visit_leave(ir_assignment
*ir
)
109 handle_rvalue(&ir
->rhs
);
110 handle_rvalue(&ir
->condition
);
112 return visit_continue
;
116 ir_rvalue_visitor::visit_leave(ir_call
*ir
)
118 foreach_iter(exec_list_iterator
, iter
, *ir
) {
119 ir_rvalue
*param
= (ir_rvalue
*)iter
.get();
120 ir_rvalue
*new_param
= param
;
121 handle_rvalue(&new_param
);
123 if (new_param
!= param
) {
124 param
->replace_with(new_param
);
127 return visit_continue
;
131 ir_rvalue_visitor::visit_leave(ir_return
*ir
)
133 handle_rvalue(&ir
->value
);;
134 return visit_continue
;
138 ir_rvalue_visitor::visit_leave(ir_if
*ir
)
140 handle_rvalue(&ir
->condition
);
141 return visit_continue
;