GCC Middle and Back End API Reference
hw-doloop.h
Go to the documentation of this file.
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-2024 Free Software Foundation, Inc.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_HW_DOLOOP_H
22#define GCC_HW_DOLOOP_H
23
24/* We need to keep a vector of loops */
25typedef struct hwloop_info_d *hwloop_info;
26
27/* Information about a loop we have found (or are in the process of
28 finding). */
29struct GTY (()) hwloop_info_d
30{
31 /* loop number, for dumps */
33
34 /* Next loop in the graph. */
36
37 /* Vector of blocks only within the loop, including those within
38 inner loops. */
40
41 /* Same information in a bitmap. */
43
44 /* Vector of inner loops within this loop. Includes loops of every
45 nesting level. */
47
48 /* All edges that jump into the loop. */
50
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. */
59
60 /* First block in the loop. This is the one branched to by the loop_end
61 insn. */
63
64 /* Last block in the loop (the one with the loop_end insn). */
66
67 /* The successor block of the loop. This is the one the loop_end insn
68 falls into. */
70
71 /* The last instruction in the tail. */
73
74 /* The loop_end insn. */
76
77 /* The iteration register. */
79
80 /* The new label placed at the beginning of the loop. */
82
83 /* The new label placed at the end of the loop. */
85
86 /* The length of the loop. */
87 int length;
88
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
92 loop.
93 This value is valid when the target's optimize function is called. */
94 int depth;
95
96 /* True if we can't optimize this loop. */
97 bool bad;
98
99 /* True if we have visited this loop during the optimization phase. */
101
102 /* The following values are collected before calling the target's optimize
103 function and are not valid earlier. */
104
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. */
112
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. */
118
119 /* Hard registers set at any point in the loop, except for the loop counter
120 register's set in the doloop_end instruction. */
122};
123
124/* A set of hooks to be defined by a target that wants to use the reorg_loops
125 functionality.
126
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.
131
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.
137
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. */
142{
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. */
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. */
153 /* Handle a loop that was marked bad for any reason. This could be
154 used to split the doloop_end pattern. */
156};
157
158extern void reorg_loops (bool, struct hw_doloop_hooks *);
159
160#endif /* GCC_HW_DOLOOP_H */
Definition cfgloop.h:120
struct rtx_def * rtx
Definition coretypes.h:57
#define GTY(x)
Definition coretypes.h:41
class bitmap_head * bitmap
Definition coretypes.h:51
HARD_REG_ELT_TYPE HARD_REG_SET
Definition hard-reg-set.h:47
void reorg_loops(bool, struct hw_doloop_hooks *)
Definition hw-doloop.cc:618
struct hwloop_info_d * hwloop_info
Definition hw-doloop.h:25
Definition basic-block.h:117
Definition hw-doloop.h:142
bool(* opt)(hwloop_info loop)
Definition hw-doloop.h:152
void(* fail)(hwloop_info loop)
Definition hw-doloop.h:155
rtx(* end_pattern_reg)(rtx_insn *insn)
Definition hw-doloop.h:146
Definition hw-doloop.h:30
bool jumps_outof
Definition hw-doloop.h:111
bool iter_reg_used_outside
Definition hw-doloop.h:117
rtx_insn * loop_end
Definition hw-doloop.h:75
bool bad
Definition hw-doloop.h:97
vec< edge, va_gc > * incoming
Definition hw-doloop.h:49
basic_block head
Definition hw-doloop.h:62
rtx_insn * last_insn
Definition hw-doloop.h:72
rtx iter_reg
Definition hw-doloop.h:78
hwloop_info next
Definition hw-doloop.h:35
int length
Definition hw-doloop.h:87
int loop_no
Definition hw-doloop.h:32
bool has_call
Definition hw-doloop.h:108
HARD_REG_SET regs_set_in_loop
Definition hw-doloop.h:121
rtx end_label
Definition hw-doloop.h:84
bool has_asm
Definition hw-doloop.h:109
bool jumps_within
Definition hw-doloop.h:110
basic_block tail
Definition hw-doloop.h:65
vec< hwloop_info > loops
Definition hw-doloop.h:46
bitmap block_bitmap
Definition hw-doloop.h:42
vec< basic_block > blocks
Definition hw-doloop.h:39
basic_block incoming_src
Definition hw-doloop.h:57
int depth
Definition hw-doloop.h:94
rtx_insn * start_label
Definition hw-doloop.h:81
bool iter_reg_used
Definition hw-doloop.h:115
basic_block incoming_dest
Definition hw-doloop.h:58
basic_block successor
Definition hw-doloop.h:69
bool visited
Definition hw-doloop.h:100
Definition rtl.h:312
Definition rtl.h:546
Definition vec.h:450
#define bool
Definition system.h:886