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