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