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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* We need to keep a vector of loops */
22 typedef struct hwloop_info_d
*hwloop_info
;
23 DEF_VEC_P (hwloop_info
);
24 DEF_VEC_ALLOC_P (hwloop_info
,heap
);
26 /* Information about a loop we have found (or are in the process of
28 struct GTY (()) hwloop_info_d
30 /* loop number, for dumps */
33 /* Next loop in the graph. */
36 /* Vector of blocks only within the loop, including those within
38 VEC (basic_block
, heap
) *blocks
;
40 /* Same information in a bitmap. */
43 /* Vector of inner loops within this loop. Includes loops of every
45 VEC (hwloop_info
, heap
) *loops
;
47 /* All edges that jump into the loop. */
48 VEC(edge
, gc
) *incoming
;
50 /* The ports currently using this infrastructure can typically
51 handle two cases: all incoming edges have the same destination
52 block, or all incoming edges have the same source block. These
53 two members are set to the common source or destination we found,
54 or NULL if different blocks were found. If both are NULL the
55 loop can't be optimized. */
56 basic_block incoming_src
;
57 basic_block incoming_dest
;
59 /* First block in the loop. This is the one branched to by the loop_end
63 /* Last block in the loop (the one with the loop_end insn). */
66 /* The successor block of the loop. This is the one the loop_end insn
68 basic_block successor
;
70 /* The last instruction in the tail. */
73 /* The loop_end insn. */
76 /* The iteration register. */
79 /* The new label placed at the beginning of the loop. */
82 /* The new label placed at the end of the loop. */
85 /* The length of the loop. */
88 /* The nesting depth of the loop. Innermost loops are given a depth
89 of 1. Only successfully optimized doloops are counted; if an inner
90 loop was marked as bad, it does not increase the depth of its parent
92 This value is valid when the target's optimize function is called. */
95 /* True if we can't optimize this loop. */
98 /* True if we have visited this loop during the optimization phase. */
101 /* The following values are collected before calling the target's optimize
102 function and are not valid earlier. */
104 /* Record information about control flow: whether the loop has calls
105 or asm statements, whether it has edges that jump out of the loop,
106 or edges that jump within the loop. */
112 /* True if there is an instruction other than the doloop_end which uses the
113 iteration register. */
115 /* True if the iteration register lives past the doloop instruction. */
116 bool iter_reg_used_outside
;
118 /* Hard registers set at any point in the loop, except for the loop counter
119 register's set in the doloop_end instruction. */
120 HARD_REG_SET regs_set_in_loop
;
123 /* A set of hooks to be defined by a target that wants to use the reorg_loops
126 reorg_loops is intended to handle cases where special hardware loop
127 setup instructions are required before the loop, for example to set
128 up loop counter registers that are not exposed to the register
129 allocator, or to inform the hardware about loop bounds.
131 reorg_loops performs analysis to discover loop_end patterns created
132 by the earlier loop-doloop pass, and sets up a hwloop_info
133 structure for each such insn it finds. It then tries to discover
134 the basic blocks containing the loop by tracking the lifetime of
135 the iteration register.
137 If a valid loop can't be found, the FAIL function is called;
138 otherwise the OPT function is called for each loop, visiting
139 innermost loops first and ascending. */
140 struct hw_doloop_hooks
142 /* Examine INSN. If it is a suitable doloop_end pattern, return the
143 iteration register, which should be a single hard register.
144 Otherwise, return NULL_RTX. */
145 rtx (*end_pattern_reg
) (rtx insn
);
146 /* Optimize LOOP. The target should perform any additional analysis
147 (e.g. checking that the loop isn't too long), and then perform
148 its transformations. Return true if successful, false if the
149 loop should be marked bad. If it returns false, the FAIL
150 function is called. */
151 bool (*opt
) (hwloop_info loop
);
152 /* Handle a loop that was marked bad for any reason. This could be
153 used to split the doloop_end pattern. */
154 void (*fail
) (hwloop_info loop
);
157 extern void reorg_loops (bool, struct hw_doloop_hooks
*);