Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 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: |
| 10 | * |
| 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 |
| 13 | * Software. |
| 14 | * |
| 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. |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * \file ir_rvalue_visitor.cpp |
| 26 | * |
| 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 |
| 29 | * class. |
| 30 | */ |
| 31 | |
| 32 | #include "ir.h" |
| 33 | #include "ir_visitor.h" |
| 34 | #include "ir_rvalue_visitor.h" |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 35 | #include "glsl_types.h" |
| 36 | |
| 37 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 38 | ir_rvalue_base_visitor::rvalue_visit(ir_expression *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 39 | { |
| 40 | unsigned int operand; |
| 41 | |
| 42 | for (operand = 0; operand < ir->get_num_operands(); operand++) { |
| 43 | handle_rvalue(&ir->operands[operand]); |
| 44 | } |
| 45 | |
| 46 | return visit_continue; |
| 47 | } |
| 48 | |
| 49 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 50 | ir_rvalue_base_visitor::rvalue_visit(ir_texture *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 51 | { |
| 52 | handle_rvalue(&ir->coordinate); |
| 53 | handle_rvalue(&ir->projector); |
| 54 | handle_rvalue(&ir->shadow_comparitor); |
Kenneth Graunke | c5a27b5 | 2011-01-08 23:49:23 -0800 | [diff] [blame] | 55 | handle_rvalue(&ir->offset); |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 56 | |
| 57 | switch (ir->op) { |
| 58 | case ir_tex: |
Dave Airlie | 110ca8b | 2012-09-23 19:50:41 +1000 | [diff] [blame] | 59 | case ir_lod: |
Chris Forbes | 7a4754d | 2013-09-26 19:37:30 +1200 | [diff] [blame] | 60 | case ir_query_levels: |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 61 | break; |
| 62 | case ir_txb: |
| 63 | handle_rvalue(&ir->lod_info.bias); |
| 64 | break; |
| 65 | case ir_txf: |
| 66 | case ir_txl: |
Kenneth Graunke | 1e3bcbd | 2011-02-25 14:45:33 -0800 | [diff] [blame] | 67 | case ir_txs: |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 68 | handle_rvalue(&ir->lod_info.lod); |
| 69 | break; |
Chris Forbes | ffb53b4 | 2012-12-21 21:33:37 +1300 | [diff] [blame] | 70 | case ir_txf_ms: |
| 71 | handle_rvalue(&ir->lod_info.sample_index); |
| 72 | break; |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 73 | case ir_txd: |
| 74 | handle_rvalue(&ir->lod_info.grad.dPdx); |
| 75 | handle_rvalue(&ir->lod_info.grad.dPdy); |
| 76 | break; |
Chris Forbes | 88ee9bc | 2013-10-05 18:26:56 +1300 | [diff] [blame] | 77 | case ir_tg4: |
| 78 | handle_rvalue(&ir->lod_info.component); |
| 79 | break; |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | return visit_continue; |
| 83 | } |
| 84 | |
| 85 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 86 | ir_rvalue_base_visitor::rvalue_visit(ir_swizzle *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 87 | { |
| 88 | handle_rvalue(&ir->val); |
| 89 | return visit_continue; |
| 90 | } |
| 91 | |
| 92 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 93 | ir_rvalue_base_visitor::rvalue_visit(ir_dereference_array *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 94 | { |
Ian Romanick | c8ee8e0 | 2010-08-05 15:29:24 -0700 | [diff] [blame] | 95 | /* The array index is not the target of the assignment, so clear the |
| 96 | * 'in_assignee' flag. Restore it after returning from the array index. |
| 97 | */ |
| 98 | const bool was_in_assignee = this->in_assignee; |
| 99 | this->in_assignee = false; |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 100 | handle_rvalue(&ir->array_index); |
Ian Romanick | c8ee8e0 | 2010-08-05 15:29:24 -0700 | [diff] [blame] | 101 | this->in_assignee = was_in_assignee; |
| 102 | |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 103 | handle_rvalue(&ir->array); |
| 104 | return visit_continue; |
| 105 | } |
| 106 | |
| 107 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 108 | ir_rvalue_base_visitor::rvalue_visit(ir_dereference_record *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 109 | { |
| 110 | handle_rvalue(&ir->record); |
| 111 | return visit_continue; |
| 112 | } |
| 113 | |
| 114 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 115 | ir_rvalue_base_visitor::rvalue_visit(ir_assignment *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 116 | { |
| 117 | handle_rvalue(&ir->rhs); |
| 118 | handle_rvalue(&ir->condition); |
| 119 | |
| 120 | return visit_continue; |
| 121 | } |
| 122 | |
| 123 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 124 | ir_rvalue_base_visitor::rvalue_visit(ir_call *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 125 | { |
Matt Turner | c6a16f6 | 2014-06-24 21:58:35 -0700 | [diff] [blame] | 126 | foreach_in_list_safe(ir_rvalue, param, &ir->actual_parameters) { |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 127 | ir_rvalue *new_param = param; |
| 128 | handle_rvalue(&new_param); |
| 129 | |
| 130 | if (new_param != param) { |
| 131 | param->replace_with(new_param); |
| 132 | } |
| 133 | } |
| 134 | return visit_continue; |
| 135 | } |
| 136 | |
| 137 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 138 | ir_rvalue_base_visitor::rvalue_visit(ir_return *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 139 | { |
| 140 | handle_rvalue(&ir->value);; |
| 141 | return visit_continue; |
| 142 | } |
| 143 | |
| 144 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 145 | ir_rvalue_base_visitor::rvalue_visit(ir_if *ir) |
Eric Anholt | b3b0cf6 | 2010-08-13 20:39:24 -0700 | [diff] [blame] | 146 | { |
| 147 | handle_rvalue(&ir->condition); |
| 148 | return visit_continue; |
| 149 | } |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 150 | |
Iago Toral Quiroga | 8639eff | 2014-06-20 10:26:29 +0200 | [diff] [blame] | 151 | ir_visitor_status |
| 152 | ir_rvalue_base_visitor::rvalue_visit(ir_emit_vertex *ir) |
| 153 | { |
| 154 | handle_rvalue(&ir->stream); |
| 155 | return visit_continue; |
| 156 | } |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 157 | |
| 158 | ir_visitor_status |
Iago Toral Quiroga | 4b3fc21 | 2014-06-20 10:38:53 +0200 | [diff] [blame] | 159 | ir_rvalue_base_visitor::rvalue_visit(ir_end_primitive *ir) |
| 160 | { |
| 161 | handle_rvalue(&ir->stream); |
| 162 | return visit_continue; |
| 163 | } |
| 164 | |
| 165 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 166 | ir_rvalue_visitor::visit_leave(ir_expression *ir) |
| 167 | { |
| 168 | return rvalue_visit(ir); |
| 169 | } |
| 170 | |
| 171 | ir_visitor_status |
| 172 | ir_rvalue_visitor::visit_leave(ir_texture *ir) |
| 173 | { |
| 174 | return rvalue_visit(ir); |
| 175 | } |
| 176 | |
| 177 | ir_visitor_status |
| 178 | ir_rvalue_visitor::visit_leave(ir_swizzle *ir) |
| 179 | { |
| 180 | return rvalue_visit(ir); |
| 181 | } |
| 182 | |
| 183 | ir_visitor_status |
| 184 | ir_rvalue_visitor::visit_leave(ir_dereference_array *ir) |
| 185 | { |
| 186 | return rvalue_visit(ir); |
| 187 | } |
| 188 | |
| 189 | ir_visitor_status |
| 190 | ir_rvalue_visitor::visit_leave(ir_dereference_record *ir) |
| 191 | { |
| 192 | return rvalue_visit(ir); |
| 193 | } |
| 194 | |
| 195 | ir_visitor_status |
| 196 | ir_rvalue_visitor::visit_leave(ir_assignment *ir) |
| 197 | { |
| 198 | return rvalue_visit(ir); |
| 199 | } |
| 200 | |
| 201 | ir_visitor_status |
| 202 | ir_rvalue_visitor::visit_leave(ir_call *ir) |
| 203 | { |
| 204 | return rvalue_visit(ir); |
| 205 | } |
| 206 | |
| 207 | ir_visitor_status |
| 208 | ir_rvalue_visitor::visit_leave(ir_return *ir) |
| 209 | { |
| 210 | return rvalue_visit(ir); |
| 211 | } |
| 212 | |
| 213 | ir_visitor_status |
| 214 | ir_rvalue_visitor::visit_leave(ir_if *ir) |
| 215 | { |
| 216 | return rvalue_visit(ir); |
| 217 | } |
| 218 | |
| 219 | ir_visitor_status |
Iago Toral Quiroga | 8639eff | 2014-06-20 10:26:29 +0200 | [diff] [blame] | 220 | ir_rvalue_visitor::visit_leave(ir_emit_vertex *ir) |
| 221 | { |
| 222 | return rvalue_visit(ir); |
| 223 | } |
| 224 | |
| 225 | ir_visitor_status |
Iago Toral Quiroga | 4b3fc21 | 2014-06-20 10:38:53 +0200 | [diff] [blame] | 226 | ir_rvalue_visitor::visit_leave(ir_end_primitive *ir) |
| 227 | { |
| 228 | return rvalue_visit(ir); |
| 229 | } |
| 230 | |
| 231 | ir_visitor_status |
Eric Anholt | 8c2a983 | 2012-07-20 14:10:44 -0700 | [diff] [blame] | 232 | ir_rvalue_enter_visitor::visit_enter(ir_expression *ir) |
| 233 | { |
| 234 | return rvalue_visit(ir); |
| 235 | } |
| 236 | |
| 237 | ir_visitor_status |
| 238 | ir_rvalue_enter_visitor::visit_enter(ir_texture *ir) |
| 239 | { |
| 240 | return rvalue_visit(ir); |
| 241 | } |
| 242 | |
| 243 | ir_visitor_status |
| 244 | ir_rvalue_enter_visitor::visit_enter(ir_swizzle *ir) |
| 245 | { |
| 246 | return rvalue_visit(ir); |
| 247 | } |
| 248 | |
| 249 | ir_visitor_status |
| 250 | ir_rvalue_enter_visitor::visit_enter(ir_dereference_array *ir) |
| 251 | { |
| 252 | return rvalue_visit(ir); |
| 253 | } |
| 254 | |
| 255 | ir_visitor_status |
| 256 | ir_rvalue_enter_visitor::visit_enter(ir_dereference_record *ir) |
| 257 | { |
| 258 | return rvalue_visit(ir); |
| 259 | } |
| 260 | |
| 261 | ir_visitor_status |
| 262 | ir_rvalue_enter_visitor::visit_enter(ir_assignment *ir) |
| 263 | { |
| 264 | return rvalue_visit(ir); |
| 265 | } |
| 266 | |
| 267 | ir_visitor_status |
| 268 | ir_rvalue_enter_visitor::visit_enter(ir_call *ir) |
| 269 | { |
| 270 | return rvalue_visit(ir); |
| 271 | } |
| 272 | |
| 273 | ir_visitor_status |
| 274 | ir_rvalue_enter_visitor::visit_enter(ir_return *ir) |
| 275 | { |
| 276 | return rvalue_visit(ir); |
| 277 | } |
| 278 | |
| 279 | ir_visitor_status |
| 280 | ir_rvalue_enter_visitor::visit_enter(ir_if *ir) |
| 281 | { |
| 282 | return rvalue_visit(ir); |
| 283 | } |
Iago Toral Quiroga | 8639eff | 2014-06-20 10:26:29 +0200 | [diff] [blame] | 284 | |
| 285 | ir_visitor_status |
| 286 | ir_rvalue_enter_visitor::visit_enter(ir_emit_vertex *ir) |
| 287 | { |
| 288 | return rvalue_visit(ir); |
| 289 | } |
Iago Toral Quiroga | 4b3fc21 | 2014-06-20 10:38:53 +0200 | [diff] [blame] | 290 | |
| 291 | ir_visitor_status |
| 292 | ir_rvalue_enter_visitor::visit_enter(ir_end_primitive *ir) |
| 293 | { |
| 294 | return rvalue_visit(ir); |
| 295 | } |