annotate gcc/hw-doloop.h @ 158:494b0b89df80 default tip

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