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-2023 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 #ifndef GCC_HW_DOLOOP_H
22 #define GCC_HW_DOLOOP_H
24 /* We need to keep a vector of loops */
25 typedef struct hwloop_info_d
*hwloop_info
;
27 /* Information about a loop we have found (or are in the process of
29 struct GTY (()) hwloop_info_d
31 /* loop number, for dumps */
34 /* Next loop in the graph. */
37 /* Vector of blocks only within the loop, including those within
39 vec
<basic_block
> blocks
;
41 /* Same information in a bitmap. */
44 /* Vector of inner loops within this loop. Includes loops of every
46 vec
<hwloop_info
> loops
;
48 /* All edges that jump into the loop. */
49 vec
<edge
, va_gc
> *incoming
;
51 /* The ports currently using this infrastructure can typically
52 handle two cases: all incoming edges have the same destination
53 block, or all incoming edges have the same source block. These
54 two members are set to the common source or destination we found,
55 or NULL if different blocks were found. If both are NULL the
56 loop can't be optimized. */
57 basic_block incoming_src
;
58 basic_block incoming_dest
;
60 /* First block in the loop. This is the one branched to by the loop_end
64 /* Last block in the loop (the one with the loop_end insn). */
67 /* The successor block of the loop. This is the one the loop_end insn
69 basic_block successor
;
71 /* The last instruction in the tail. */
74 /* The loop_end insn. */
77 /* The iteration register. */
80 /* The new label placed at the beginning of the loop. */
81 rtx_insn
*start_label
;
83 /* The new label placed at the end of the loop. */
86 /* The length of the loop. */
89 /* The nesting depth of the loop. Innermost loops are given a depth
90 of 1. Only successfully optimized doloops are counted; if an inner
91 loop was marked as bad, it does not increase the depth of its parent
93 This value is valid when the target's optimize function is called. */
96 /* True if we can't optimize this loop. */
99 /* True if we have visited this loop during the optimization phase. */
102 /* The following values are collected before calling the target's optimize
103 function and are not valid earlier. */
105 /* Record information about control flow: whether the loop has calls
106 or asm statements, whether it has edges that jump out of the loop,
107 or edges that jump within the loop. */
113 /* True if there is an instruction other than the doloop_end which uses the
114 iteration register. */
116 /* True if the iteration register lives past the doloop instruction. */
117 bool iter_reg_used_outside
;
119 /* Hard registers set at any point in the loop, except for the loop counter
120 register's set in the doloop_end instruction. */
121 HARD_REG_SET regs_set_in_loop
;
124 /* A set of hooks to be defined by a target that wants to use the reorg_loops
127 reorg_loops is intended to handle cases where special hardware loop
128 setup instructions are required before the loop, for example to set
129 up loop counter registers that are not exposed to the register
130 allocator, or to inform the hardware about loop bounds.
132 reorg_loops performs analysis to discover loop_end patterns created
133 by the earlier loop-doloop pass, and sets up a hwloop_info
134 structure for each such insn it finds. It then tries to discover
135 the basic blocks containing the loop by tracking the lifetime of
136 the iteration register.
138 If a valid loop can't be found, the FAIL function is called;
139 otherwise the OPT function is called for each loop, visiting
140 innermost loops first and ascending. */
141 struct hw_doloop_hooks
143 /* Examine INSN. If it is a suitable doloop_end pattern, return the
144 iteration register, which should be a single hard register.
145 Otherwise, return NULL_RTX. */
146 rtx (*end_pattern_reg
) (rtx_insn
*insn
);
147 /* Optimize LOOP. The target should perform any additional analysis
148 (e.g. checking that the loop isn't too long), and then perform
149 its transformations. Return true if successful, false if the
150 loop should be marked bad. If it returns false, the FAIL
151 function is called. */
152 bool (*opt
) (hwloop_info loop
);
153 /* Handle a loop that was marked bad for any reason. This could be
154 used to split the doloop_end pattern. */
155 void (*fail
) (hwloop_info loop
);
158 extern void reorg_loops (bool, struct hw_doloop_hooks
*);
160 #endif /* GCC_HW_DOLOOP_H */