Eric Anholt | cad9766 | 2010-04-07 11:46:26 -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_function_inlining.cpp |
| 26 | * |
| 27 | * Replaces calls to functions with the body of the function. |
| 28 | */ |
| 29 | |
| 30 | #define NULL 0 |
| 31 | #include "ir.h" |
| 32 | #include "ir_visitor.h" |
| 33 | #include "ir_function_inlining.h" |
Eric Anholt | 0d42321 | 2010-04-16 12:53:46 -0700 | [diff] [blame] | 34 | #include "ir_expression_flattening.h" |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 35 | #include "glsl_types.h" |
| 36 | |
Eric Anholt | bdd9b1f | 2010-05-05 11:45:30 -0700 | [diff] [blame] | 37 | class ir_function_inlining_visitor : public ir_visitor { |
| 38 | public: |
| 39 | ir_function_inlining_visitor() |
| 40 | { |
| 41 | /* empty */ |
| 42 | } |
| 43 | |
| 44 | virtual ~ir_function_inlining_visitor() |
| 45 | { |
| 46 | /* empty */ |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * \name Visit methods |
| 51 | * |
| 52 | * As typical for the visitor pattern, there must be one \c visit method for |
| 53 | * each concrete subclass of \c ir_instruction. Virtual base classes within |
| 54 | * the hierarchy should not have \c visit methods. |
| 55 | */ |
| 56 | /*@{*/ |
| 57 | virtual void visit(ir_variable *); |
| 58 | virtual void visit(ir_loop *); |
| 59 | virtual void visit(ir_loop_jump *); |
| 60 | virtual void visit(ir_function_signature *); |
| 61 | virtual void visit(ir_function *); |
| 62 | virtual void visit(ir_expression *); |
| 63 | virtual void visit(ir_swizzle *); |
| 64 | virtual void visit(ir_dereference *); |
| 65 | virtual void visit(ir_assignment *); |
| 66 | virtual void visit(ir_constant *); |
| 67 | virtual void visit(ir_call *); |
| 68 | virtual void visit(ir_return *); |
| 69 | virtual void visit(ir_if *); |
| 70 | /*@}*/ |
| 71 | }; |
| 72 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 73 | class variable_remap : public exec_node { |
| 74 | public: |
| 75 | variable_remap(const ir_variable *old_var, ir_variable *new_var) |
| 76 | : old_var(old_var), new_var(new_var) |
| 77 | { |
| 78 | /* empty */ |
| 79 | } |
| 80 | const ir_variable *old_var; |
| 81 | ir_variable *new_var; |
| 82 | }; |
| 83 | |
| 84 | class ir_function_cloning_visitor : public ir_visitor { |
| 85 | public: |
| 86 | ir_function_cloning_visitor(ir_variable *retval) |
| 87 | : retval(retval) |
| 88 | { |
| 89 | /* empty */ |
| 90 | } |
| 91 | |
| 92 | virtual ~ir_function_cloning_visitor() |
| 93 | { |
| 94 | /* empty */ |
| 95 | } |
| 96 | |
| 97 | void remap_variable(const ir_variable *old_var, ir_variable *new_var) { |
| 98 | variable_remap *remap = new variable_remap(old_var, new_var); |
| 99 | this->remap_list.push_tail(remap); |
| 100 | } |
| 101 | |
| 102 | ir_variable *get_remapped_variable(ir_variable *var) { |
| 103 | foreach_iter(exec_list_iterator, iter, this->remap_list) { |
| 104 | variable_remap *remap = (variable_remap *)iter.get(); |
| 105 | |
| 106 | if (var == remap->old_var) |
| 107 | return remap->new_var; |
| 108 | } |
| 109 | |
| 110 | /* Not a reapped variable, so a global scoped reference, for example. */ |
| 111 | return var; |
| 112 | } |
| 113 | |
| 114 | /* List of variable_remap for mapping from original function body variables |
| 115 | * to inlined function body variables. |
| 116 | */ |
| 117 | exec_list remap_list; |
| 118 | |
| 119 | /* Return value for the inlined function. */ |
| 120 | ir_variable *retval; |
| 121 | |
| 122 | /** |
| 123 | * \name Visit methods |
| 124 | * |
| 125 | * As typical for the visitor pattern, there must be one \c visit method for |
| 126 | * each concrete subclass of \c ir_instruction. Virtual base classes within |
| 127 | * the hierarchy should not have \c visit methods. |
| 128 | */ |
| 129 | /*@{*/ |
| 130 | virtual void visit(ir_variable *); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 131 | virtual void visit(ir_loop *); |
| 132 | virtual void visit(ir_loop_jump *); |
| 133 | virtual void visit(ir_function_signature *); |
| 134 | virtual void visit(ir_function *); |
| 135 | virtual void visit(ir_expression *); |
| 136 | virtual void visit(ir_swizzle *); |
| 137 | virtual void visit(ir_dereference *); |
| 138 | virtual void visit(ir_assignment *); |
| 139 | virtual void visit(ir_constant *); |
| 140 | virtual void visit(ir_call *); |
| 141 | virtual void visit(ir_return *); |
| 142 | virtual void visit(ir_if *); |
| 143 | /*@}*/ |
| 144 | |
| 145 | ir_instruction *result; |
| 146 | }; |
| 147 | |
| 148 | void |
| 149 | ir_function_cloning_visitor::visit(ir_variable *ir) |
| 150 | { |
| 151 | ir_variable *new_var = ir->clone(); |
| 152 | |
| 153 | this->result = new_var; |
| 154 | |
| 155 | this->remap_variable(ir, new_var); |
| 156 | } |
| 157 | |
| 158 | void |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 159 | ir_function_cloning_visitor::visit(ir_loop *ir) |
| 160 | { |
Eric Anholt | e8e9748 | 2010-04-22 17:52:59 -0700 | [diff] [blame] | 161 | /* FINISHME: Implement loop cloning. */ |
| 162 | assert(0); |
| 163 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 164 | (void)ir; |
| 165 | this->result = NULL; |
| 166 | } |
| 167 | |
| 168 | void |
| 169 | ir_function_cloning_visitor::visit(ir_loop_jump *ir) |
| 170 | { |
Eric Anholt | e8e9748 | 2010-04-22 17:52:59 -0700 | [diff] [blame] | 171 | /* FINISHME: Implement loop cloning. */ |
| 172 | assert(0); |
| 173 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 174 | (void) ir; |
| 175 | this->result = NULL; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | void |
| 180 | ir_function_cloning_visitor::visit(ir_function_signature *ir) |
| 181 | { |
Eric Anholt | e8e9748 | 2010-04-22 17:52:59 -0700 | [diff] [blame] | 182 | assert(0); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 183 | (void)ir; |
| 184 | this->result = NULL; |
| 185 | } |
| 186 | |
| 187 | |
| 188 | void |
| 189 | ir_function_cloning_visitor::visit(ir_function *ir) |
| 190 | { |
Eric Anholt | e8e9748 | 2010-04-22 17:52:59 -0700 | [diff] [blame] | 191 | assert(0); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 192 | (void) ir; |
| 193 | this->result = NULL; |
| 194 | } |
| 195 | |
| 196 | void |
| 197 | ir_function_cloning_visitor::visit(ir_expression *ir) |
| 198 | { |
| 199 | unsigned int operand; |
| 200 | ir_rvalue *op[2] = {NULL, NULL}; |
| 201 | |
| 202 | for (operand = 0; operand < ir->get_num_operands(); operand++) { |
| 203 | ir->operands[operand]->accept(this); |
| 204 | op[operand] = this->result->as_rvalue(); |
| 205 | assert(op[operand]); |
| 206 | } |
| 207 | |
| 208 | this->result = new ir_expression(ir->operation, ir->type, op[0], op[1]); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | void |
| 213 | ir_function_cloning_visitor::visit(ir_swizzle *ir) |
| 214 | { |
| 215 | ir->val->accept(this); |
| 216 | |
| 217 | this->result = new ir_swizzle(this->result->as_rvalue(), ir->mask); |
| 218 | } |
| 219 | |
| 220 | void |
| 221 | ir_function_cloning_visitor::visit(ir_dereference *ir) |
| 222 | { |
Eric Anholt | c0bfe87 | 2010-04-26 15:01:50 -0700 | [diff] [blame] | 223 | if (ir->mode == ir_dereference::ir_reference_variable) { |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 224 | ir_variable *var = this->get_remapped_variable(ir->variable_referenced()); |
| 225 | this->result = new ir_dereference_variable(var); |
Eric Anholt | c0bfe87 | 2010-04-26 15:01:50 -0700 | [diff] [blame] | 226 | } else if (ir->mode == ir_dereference::ir_reference_array) { |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 227 | ir->var->accept(this); |
| 228 | |
| 229 | ir_rvalue *var = this->result->as_rvalue(); |
Eric Anholt | 6192434 | 2010-04-08 13:40:52 -0700 | [diff] [blame] | 230 | |
| 231 | ir->selector.array_index->accept(this); |
Eric Anholt | 6192434 | 2010-04-08 13:40:52 -0700 | [diff] [blame] | 232 | |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 233 | ir_rvalue *index = this->result->as_rvalue(); |
| 234 | |
| 235 | this->result = new ir_dereference_array(var, index); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 236 | } else { |
Eric Anholt | 6192434 | 2010-04-08 13:40:52 -0700 | [diff] [blame] | 237 | assert(ir->mode == ir_dereference::ir_reference_record); |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 238 | |
| 239 | ir->var->accept(this); |
| 240 | |
| 241 | ir_rvalue *var = this->result->as_rvalue(); |
| 242 | |
| 243 | this->result = new ir_dereference_record(var, strdup(ir->selector.field)); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 244 | } |
| 245 | } |
| 246 | |
| 247 | void |
| 248 | ir_function_cloning_visitor::visit(ir_assignment *ir) |
| 249 | { |
Eric Anholt | 22147be | 2010-04-22 18:41:32 -0700 | [diff] [blame] | 250 | ir_rvalue *lhs, *rhs, *condition = NULL; |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 251 | |
| 252 | ir->lhs->accept(this); |
| 253 | lhs = this->result->as_rvalue(); |
| 254 | |
| 255 | ir->rhs->accept(this); |
| 256 | rhs = this->result->as_rvalue(); |
| 257 | |
Eric Anholt | 22147be | 2010-04-22 18:41:32 -0700 | [diff] [blame] | 258 | if (ir->condition) { |
| 259 | ir->condition->accept(this); |
| 260 | condition = this->result->as_rvalue(); |
| 261 | } |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 262 | |
| 263 | this->result = new ir_assignment(lhs, rhs, condition); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | void |
| 268 | ir_function_cloning_visitor::visit(ir_constant *ir) |
| 269 | { |
| 270 | this->result = ir->clone(); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void |
| 275 | ir_function_cloning_visitor::visit(ir_call *ir) |
| 276 | { |
| 277 | exec_list parameters; |
| 278 | |
| 279 | foreach_iter(exec_list_iterator, iter, *ir) { |
| 280 | ir_rvalue *param = (ir_rvalue *)iter.get(); |
| 281 | |
| 282 | param->accept(this); |
| 283 | parameters.push_tail(this->result); |
| 284 | } |
| 285 | |
| 286 | this->result = new ir_call(ir->get_callee(), ¶meters); |
| 287 | } |
| 288 | |
| 289 | |
| 290 | void |
| 291 | ir_function_cloning_visitor::visit(ir_return *ir) |
| 292 | { |
| 293 | ir_rvalue *rval; |
| 294 | |
| 295 | assert(this->retval); |
| 296 | |
| 297 | rval = ir->get_value(); |
| 298 | rval->accept(this); |
| 299 | rval = this->result->as_rvalue(); |
| 300 | assert(rval); |
| 301 | |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 302 | result = new ir_assignment(new ir_dereference_variable(this->retval), rval, |
| 303 | NULL); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
| 307 | void |
| 308 | ir_function_cloning_visitor::visit(ir_if *ir) |
| 309 | { |
Eric Anholt | e8e9748 | 2010-04-22 17:52:59 -0700 | [diff] [blame] | 310 | /* FINISHME: Implement if cloning. */ |
| 311 | assert(0); |
| 312 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 313 | (void) ir; |
| 314 | result = NULL; |
| 315 | } |
| 316 | |
| 317 | bool |
Eric Anholt | 0d42321 | 2010-04-16 12:53:46 -0700 | [diff] [blame] | 318 | automatic_inlining_predicate(ir_instruction *ir) |
| 319 | { |
| 320 | ir_call *call = ir->as_call(); |
| 321 | |
| 322 | if (call && can_inline(call)) |
| 323 | return true; |
| 324 | |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | bool |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 329 | do_function_inlining(exec_list *instructions) |
| 330 | { |
Eric Anholt | 2a7b2b2 | 2010-04-08 13:42:48 -0700 | [diff] [blame] | 331 | bool progress = false; |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 332 | |
Eric Anholt | 0d42321 | 2010-04-16 12:53:46 -0700 | [diff] [blame] | 333 | do_expression_flattening(instructions, automatic_inlining_predicate); |
| 334 | |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 335 | foreach_iter(exec_list_iterator, iter, *instructions) { |
| 336 | ir_instruction *ir = (ir_instruction *)iter.get(); |
| 337 | ir_assignment *assign = ir->as_assignment(); |
| 338 | ir_call *call; |
| 339 | |
| 340 | if (assign) { |
| 341 | call = assign->rhs->as_call(); |
| 342 | if (!call || !can_inline(call)) |
| 343 | continue; |
| 344 | |
| 345 | /* generates the parameter setup, function body, and returns the return |
| 346 | * value of the function |
| 347 | */ |
| 348 | ir_rvalue *rhs = call->generate_inline(ir); |
| 349 | assert(rhs); |
| 350 | |
| 351 | assign->rhs = rhs; |
| 352 | progress = true; |
| 353 | } else if ((call = ir->as_call()) && can_inline(call)) { |
| 354 | (void)call->generate_inline(ir); |
| 355 | ir->remove(); |
| 356 | progress = true; |
| 357 | } else { |
| 358 | ir_function_inlining_visitor v; |
| 359 | ir->accept(&v); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | return progress; |
| 364 | } |
| 365 | |
| 366 | ir_rvalue * |
| 367 | ir_call::generate_inline(ir_instruction *next_ir) |
| 368 | { |
| 369 | ir_variable **parameters; |
| 370 | int num_parameters; |
| 371 | int i; |
| 372 | ir_variable *retval = NULL; |
| 373 | |
| 374 | num_parameters = 0; |
| 375 | foreach_iter(exec_list_iterator, iter_sig, this->callee->parameters) |
| 376 | num_parameters++; |
| 377 | |
| 378 | parameters = new ir_variable *[num_parameters]; |
| 379 | |
| 380 | /* Generate storage for the return value. */ |
| 381 | if (this->callee->return_type) { |
| 382 | retval = new ir_variable(this->callee->return_type, "__retval"); |
| 383 | next_ir->insert_before(retval); |
| 384 | } |
| 385 | |
| 386 | ir_function_cloning_visitor v = ir_function_cloning_visitor(retval); |
| 387 | |
| 388 | /* Generate the declarations for the parameters to our inlined code, |
| 389 | * and set up the mapping of real function body variables to ours. |
| 390 | */ |
| 391 | i = 0; |
| 392 | exec_list_iterator sig_param_iter = this->callee->parameters.iterator(); |
| 393 | exec_list_iterator param_iter = this->actual_parameters.iterator(); |
| 394 | for (i = 0; i < num_parameters; i++) { |
| 395 | const ir_variable *const sig_param = (ir_variable *) sig_param_iter.get(); |
| 396 | ir_rvalue *param = (ir_rvalue *) param_iter.get(); |
| 397 | |
| 398 | /* Generate a new variable for the parameter. */ |
| 399 | parameters[i] = sig_param->clone(); |
| 400 | next_ir->insert_before(parameters[i]); |
| 401 | |
| 402 | v.remap_variable(sig_param, parameters[i]); |
| 403 | |
| 404 | /* Move the actual param into our param variable if it's an 'in' type. */ |
| 405 | if (parameters[i]->mode == ir_var_in || |
| 406 | parameters[i]->mode == ir_var_inout) { |
| 407 | ir_assignment *assign; |
| 408 | |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 409 | assign = new ir_assignment(new ir_dereference_variable(parameters[i]), |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 410 | param, NULL); |
| 411 | next_ir->insert_before(assign); |
| 412 | } |
| 413 | |
| 414 | sig_param_iter.next(); |
| 415 | param_iter.next(); |
| 416 | } |
| 417 | |
| 418 | /* Generate the inlined body of the function. */ |
| 419 | foreach_iter(exec_list_iterator, iter, callee->body) { |
| 420 | ir_instruction *ir = (ir_instruction *)iter.get(); |
| 421 | |
| 422 | ir->accept(&v); |
| 423 | assert(v.result); |
| 424 | next_ir->insert_before(v.result); |
| 425 | } |
| 426 | |
Kenneth Graunke | c07fdae | 2010-04-30 23:38:50 -0700 | [diff] [blame] | 427 | /* Copy back the value of any 'out' parameters from the function body |
| 428 | * variables to our own. |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 429 | */ |
| 430 | i = 0; |
| 431 | param_iter = this->actual_parameters.iterator(); |
| 432 | for (i = 0; i < num_parameters; i++) { |
| 433 | ir_instruction *const param = (ir_instruction *) param_iter.get(); |
| 434 | |
Kenneth Graunke | c07fdae | 2010-04-30 23:38:50 -0700 | [diff] [blame] | 435 | /* Move our param variable into the actual param if it's an 'out' type. */ |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 436 | if (parameters[i]->mode == ir_var_out || |
| 437 | parameters[i]->mode == ir_var_inout) { |
| 438 | ir_assignment *assign; |
| 439 | |
| 440 | assign = new ir_assignment(param->as_rvalue(), |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 441 | new ir_dereference_variable(parameters[i]), |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 442 | NULL); |
| 443 | next_ir->insert_before(assign); |
| 444 | } |
| 445 | |
| 446 | param_iter.next(); |
| 447 | } |
| 448 | |
| 449 | delete(parameters); |
| 450 | |
| 451 | if (retval) |
Ian Romanick | 70fe8b6 | 2010-05-19 11:37:35 +0200 | [diff] [blame] | 452 | return new ir_dereference_variable(retval); |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 453 | else |
| 454 | return NULL; |
| 455 | } |
| 456 | |
| 457 | void |
| 458 | ir_function_inlining_visitor::visit(ir_variable *ir) |
| 459 | { |
| 460 | (void) ir; |
| 461 | } |
| 462 | |
| 463 | |
| 464 | void |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 465 | ir_function_inlining_visitor::visit(ir_loop *ir) |
| 466 | { |
| 467 | do_function_inlining(&ir->body_instructions); |
| 468 | } |
| 469 | |
| 470 | void |
| 471 | ir_function_inlining_visitor::visit(ir_loop_jump *ir) |
| 472 | { |
| 473 | (void) ir; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | void |
| 478 | ir_function_inlining_visitor::visit(ir_function_signature *ir) |
| 479 | { |
| 480 | do_function_inlining(&ir->body); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | void |
| 485 | ir_function_inlining_visitor::visit(ir_function *ir) |
| 486 | { |
Kenneth Graunke | 9fa99f3 | 2010-04-21 12:30:22 -0700 | [diff] [blame] | 487 | foreach_iter(exec_list_iterator, iter, *ir) { |
| 488 | ir_function_signature *const sig = (ir_function_signature *) iter.get(); |
| 489 | sig->accept(this); |
| 490 | } |
Eric Anholt | cad9766 | 2010-04-07 11:46:26 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void |
| 494 | ir_function_inlining_visitor::visit(ir_expression *ir) |
| 495 | { |
| 496 | unsigned int operand; |
| 497 | |
| 498 | for (operand = 0; operand < ir->get_num_operands(); operand++) { |
| 499 | ir->operands[operand]->accept(this); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | |
| 504 | void |
| 505 | ir_function_inlining_visitor::visit(ir_swizzle *ir) |
| 506 | { |
| 507 | ir->val->accept(this); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | void |
| 512 | ir_function_inlining_visitor::visit(ir_dereference *ir) |
| 513 | { |
| 514 | if (ir->mode == ir_dereference::ir_reference_array) { |
| 515 | ir->selector.array_index->accept(this); |
| 516 | } |
| 517 | ir->var->accept(this); |
| 518 | } |
| 519 | |
| 520 | void |
| 521 | ir_function_inlining_visitor::visit(ir_assignment *ir) |
| 522 | { |
| 523 | ir->rhs->accept(this); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void |
| 528 | ir_function_inlining_visitor::visit(ir_constant *ir) |
| 529 | { |
| 530 | (void) ir; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | void |
| 535 | ir_function_inlining_visitor::visit(ir_call *ir) |
| 536 | { |
| 537 | (void) ir; |
| 538 | } |
| 539 | |
| 540 | |
| 541 | void |
| 542 | ir_function_inlining_visitor::visit(ir_return *ir) |
| 543 | { |
| 544 | (void) ir; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | void |
| 549 | ir_function_inlining_visitor::visit(ir_if *ir) |
| 550 | { |
| 551 | ir->condition->accept(this); |
| 552 | |
| 553 | do_function_inlining(&ir->then_instructions); |
| 554 | do_function_inlining(&ir->else_instructions); |
| 555 | } |