Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ir_function_can_inline.cpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * \file ir_function_can_inline.cpp
  25. *
  26. * Determines if we can inline a function call using ir_function_inlining.cpp.
  27. *
  28. * The primary restriction is that we can't return from the function
  29. * other than as the last instruction. We could potentially work
  30. * around this for some constructs by flattening control flow and
  31. * moving the return to the end, or by using breaks from a do {} while
  32. * (0) loop surrounding the function body.
  33. */
  34. #include "ir.h"
  35. class ir_function_can_inline_visitor : public ir_hierarchical_visitor {
  36. public:
  37. ir_function_can_inline_visitor()
  38. {
  39. this->num_returns = 0;
  40. }
  41. virtual ir_visitor_status visit_enter(ir_return *);
  42. int num_returns;
  43. };
  44. ir_visitor_status
  45. ir_function_can_inline_visitor::visit_enter(ir_return *ir)
  46. {
  47. (void) ir;
  48. this->num_returns++;
  49. return visit_continue;
  50. }
  51. bool
  52. can_inline(ir_call *call)
  53. {
  54. ir_function_can_inline_visitor v;
  55. const ir_function_signature *callee = call->get_callee();
  56. v.run((exec_list *) &callee->body);
  57. ir_instruction *last = (ir_instruction *)callee->body.get_tail();
  58. if (last && !last->as_return())
  59. v.num_returns++;
  60. return v.num_returns == 1;
  61. }