hw-doloop.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Code to analyze doloop loops in order for targets to perform late
  2. optimizations converting doloops to other forms of hardware loops.
  3. Copyright (C) 2011-2015 Free Software Foundation, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_HW_DOLOOP_H
  17. #define GCC_HW_DOLOOP_H
  18. /* We need to keep a vector of loops */
  19. typedef struct hwloop_info_d *hwloop_info;
  20. /* Information about a loop we have found (or are in the process of
  21. finding). */
  22. struct GTY (()) hwloop_info_d
  23. {
  24. /* loop number, for dumps */
  25. int loop_no;
  26. /* Next loop in the graph. */
  27. hwloop_info next;
  28. /* Vector of blocks only within the loop, including those within
  29. inner loops. */
  30. vec<basic_block> blocks;
  31. /* Same information in a bitmap. */
  32. bitmap block_bitmap;
  33. /* Vector of inner loops within this loop. Includes loops of every
  34. nesting level. */
  35. vec<hwloop_info> loops;
  36. /* All edges that jump into the loop. */
  37. vec<edge, va_gc> *incoming;
  38. /* The ports currently using this infrastructure can typically
  39. handle two cases: all incoming edges have the same destination
  40. block, or all incoming edges have the same source block. These
  41. two members are set to the common source or destination we found,
  42. or NULL if different blocks were found. If both are NULL the
  43. loop can't be optimized. */
  44. basic_block incoming_src;
  45. basic_block incoming_dest;
  46. /* First block in the loop. This is the one branched to by the loop_end
  47. insn. */
  48. basic_block head;
  49. /* Last block in the loop (the one with the loop_end insn). */
  50. basic_block tail;
  51. /* The successor block of the loop. This is the one the loop_end insn
  52. falls into. */
  53. basic_block successor;
  54. /* The last instruction in the tail. */
  55. rtx_insn *last_insn;
  56. /* The loop_end insn. */
  57. rtx_insn *loop_end;
  58. /* The iteration register. */
  59. rtx iter_reg;
  60. /* The new label placed at the beginning of the loop. */
  61. rtx_insn *start_label;
  62. /* The new label placed at the end of the loop. */
  63. rtx end_label;
  64. /* The length of the loop. */
  65. int length;
  66. /* The nesting depth of the loop. Innermost loops are given a depth
  67. of 1. Only successfully optimized doloops are counted; if an inner
  68. loop was marked as bad, it does not increase the depth of its parent
  69. loop.
  70. This value is valid when the target's optimize function is called. */
  71. int depth;
  72. /* True if we can't optimize this loop. */
  73. bool bad;
  74. /* True if we have visited this loop during the optimization phase. */
  75. bool visited;
  76. /* The following values are collected before calling the target's optimize
  77. function and are not valid earlier. */
  78. /* Record information about control flow: whether the loop has calls
  79. or asm statements, whether it has edges that jump out of the loop,
  80. or edges that jump within the loop. */
  81. bool has_call;
  82. bool has_asm;
  83. bool jumps_within;
  84. bool jumps_outof;
  85. /* True if there is an instruction other than the doloop_end which uses the
  86. iteration register. */
  87. bool iter_reg_used;
  88. /* True if the iteration register lives past the doloop instruction. */
  89. bool iter_reg_used_outside;
  90. /* Hard registers set at any point in the loop, except for the loop counter
  91. register's set in the doloop_end instruction. */
  92. HARD_REG_SET regs_set_in_loop;
  93. };
  94. /* A set of hooks to be defined by a target that wants to use the reorg_loops
  95. functionality.
  96. reorg_loops is intended to handle cases where special hardware loop
  97. setup instructions are required before the loop, for example to set
  98. up loop counter registers that are not exposed to the register
  99. allocator, or to inform the hardware about loop bounds.
  100. reorg_loops performs analysis to discover loop_end patterns created
  101. by the earlier loop-doloop pass, and sets up a hwloop_info
  102. structure for each such insn it finds. It then tries to discover
  103. the basic blocks containing the loop by tracking the lifetime of
  104. the iteration register.
  105. If a valid loop can't be found, the FAIL function is called;
  106. otherwise the OPT function is called for each loop, visiting
  107. innermost loops first and ascending. */
  108. struct hw_doloop_hooks
  109. {
  110. /* Examine INSN. If it is a suitable doloop_end pattern, return the
  111. iteration register, which should be a single hard register.
  112. Otherwise, return NULL_RTX. */
  113. rtx (*end_pattern_reg) (rtx_insn *insn);
  114. /* Optimize LOOP. The target should perform any additional analysis
  115. (e.g. checking that the loop isn't too long), and then perform
  116. its transformations. Return true if successful, false if the
  117. loop should be marked bad. If it returns false, the FAIL
  118. function is called. */
  119. bool (*opt) (hwloop_info loop);
  120. /* Handle a loop that was marked bad for any reason. This could be
  121. used to split the doloop_end pattern. */
  122. void (*fail) (hwloop_info loop);
  123. };
  124. extern void reorg_loops (bool, struct hw_doloop_hooks *);
  125. #endif /* GCC_HW_DOLOOP_H */