annotate gcc/rtl-iter.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 /* RTL iterators
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 /* This structure describes the subrtxes of an rtx as follows:
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 - if the rtx has no subrtxes, START and COUNT are both 0.
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 - if all the subrtxes of an rtx are stored in a contiguous block
kono
parents:
diff changeset
25 of XEXPs ("e"s), START is the index of the first XEXP and COUNT
kono
parents:
diff changeset
26 is the number of them.
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 - otherwise START is arbitrary and COUNT is UCHAR_MAX.
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 rtx_all_subrtx_bounds applies to all codes. rtx_nonconst_subrtx_bounds
kono
parents:
diff changeset
31 is like rtx_all_subrtx_bounds except that all constant rtxes are treated
kono
parents:
diff changeset
32 as having no subrtxes. */
kono
parents:
diff changeset
33 struct rtx_subrtx_bound_info {
kono
parents:
diff changeset
34 unsigned char start;
kono
parents:
diff changeset
35 unsigned char count;
kono
parents:
diff changeset
36 };
kono
parents:
diff changeset
37 extern rtx_subrtx_bound_info rtx_all_subrtx_bounds[];
kono
parents:
diff changeset
38 extern rtx_subrtx_bound_info rtx_nonconst_subrtx_bounds[];
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 /* Return true if CODE has no subrtxes. */
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 static inline bool
kono
parents:
diff changeset
43 leaf_code_p (enum rtx_code code)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 return rtx_all_subrtx_bounds[code].count == 0;
kono
parents:
diff changeset
46 }
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Used to iterate over subrtxes of an rtx. T abstracts the type of
kono
parents:
diff changeset
49 access. */
kono
parents:
diff changeset
50 template <typename T>
kono
parents:
diff changeset
51 class generic_subrtx_iterator
kono
parents:
diff changeset
52 {
kono
parents:
diff changeset
53 static const size_t LOCAL_ELEMS = 16;
kono
parents:
diff changeset
54 typedef typename T::value_type value_type;
kono
parents:
diff changeset
55 typedef typename T::rtx_type rtx_type;
kono
parents:
diff changeset
56 typedef typename T::rtunion_type rtunion_type;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 public:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
59 class array_type
111
kono
parents:
diff changeset
60 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
61 public:
111
kono
parents:
diff changeset
62 array_type ();
kono
parents:
diff changeset
63 ~array_type ();
kono
parents:
diff changeset
64 value_type stack[LOCAL_ELEMS];
kono
parents:
diff changeset
65 vec <value_type, va_heap, vl_embed> *heap;
kono
parents:
diff changeset
66 };
kono
parents:
diff changeset
67 generic_subrtx_iterator (array_type &, value_type,
kono
parents:
diff changeset
68 const rtx_subrtx_bound_info *);
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 value_type operator * () const;
kono
parents:
diff changeset
71 bool at_end () const;
kono
parents:
diff changeset
72 void next ();
kono
parents:
diff changeset
73 void skip_subrtxes ();
kono
parents:
diff changeset
74 void substitute (value_type);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 private:
kono
parents:
diff changeset
77 /* The bounds to use for iterating over subrtxes. */
kono
parents:
diff changeset
78 const rtx_subrtx_bound_info *m_bounds;
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 /* The storage used for the worklist. */
kono
parents:
diff changeset
81 array_type &m_array;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* The current rtx. */
kono
parents:
diff changeset
84 value_type m_current;
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 /* The base of the current worklist. */
kono
parents:
diff changeset
87 value_type *m_base;
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 /* The number of subrtxes in M_BASE. */
kono
parents:
diff changeset
90 size_t m_end;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* The following booleans shouldn't end up in registers or memory
kono
parents:
diff changeset
93 but just direct control flow. */
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /* True if the iteration is over. */
kono
parents:
diff changeset
96 bool m_done;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /* True if we should skip the subrtxes of M_CURRENT. */
kono
parents:
diff changeset
99 bool m_skip;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* True if M_CURRENT has been replaced with a different rtx. */
kono
parents:
diff changeset
102 bool m_substitute;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 static void free_array (array_type &);
kono
parents:
diff changeset
105 static size_t add_subrtxes_to_queue (array_type &, value_type *, size_t,
kono
parents:
diff changeset
106 rtx_type);
kono
parents:
diff changeset
107 static value_type *add_single_to_queue (array_type &, value_type *, size_t,
kono
parents:
diff changeset
108 value_type);
kono
parents:
diff changeset
109 };
kono
parents:
diff changeset
110
kono
parents:
diff changeset
111 template <typename T>
kono
parents:
diff changeset
112 inline generic_subrtx_iterator <T>::array_type::array_type () : heap (0) {}
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 template <typename T>
kono
parents:
diff changeset
115 inline generic_subrtx_iterator <T>::array_type::~array_type ()
kono
parents:
diff changeset
116 {
kono
parents:
diff changeset
117 if (__builtin_expect (heap != 0, false))
kono
parents:
diff changeset
118 free_array (*this);
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /* Iterate over X and its subrtxes, in arbitrary order. Use ARRAY to
kono
parents:
diff changeset
122 store the worklist. We use an external array in order to avoid
kono
parents:
diff changeset
123 capturing the fields of this structure when taking the address of
kono
parents:
diff changeset
124 the array. Use BOUNDS to find the bounds of simple "e"-string codes. */
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 template <typename T>
kono
parents:
diff changeset
127 inline generic_subrtx_iterator <T>::
kono
parents:
diff changeset
128 generic_subrtx_iterator (array_type &array, value_type x,
kono
parents:
diff changeset
129 const rtx_subrtx_bound_info *bounds)
kono
parents:
diff changeset
130 : m_bounds (bounds),
kono
parents:
diff changeset
131 m_array (array),
kono
parents:
diff changeset
132 m_current (x),
kono
parents:
diff changeset
133 m_base (m_array.stack),
kono
parents:
diff changeset
134 m_end (0),
kono
parents:
diff changeset
135 m_done (false),
kono
parents:
diff changeset
136 m_skip (false),
kono
parents:
diff changeset
137 m_substitute (false)
kono
parents:
diff changeset
138 {
kono
parents:
diff changeset
139 }
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 /* Return the current subrtx. */
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 template <typename T>
kono
parents:
diff changeset
144 inline typename T::value_type
kono
parents:
diff changeset
145 generic_subrtx_iterator <T>::operator * () const
kono
parents:
diff changeset
146 {
kono
parents:
diff changeset
147 return m_current;
kono
parents:
diff changeset
148 }
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 /* Return true if the iteration has finished. */
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 template <typename T>
kono
parents:
diff changeset
153 inline bool
kono
parents:
diff changeset
154 generic_subrtx_iterator <T>::at_end () const
kono
parents:
diff changeset
155 {
kono
parents:
diff changeset
156 return m_done;
kono
parents:
diff changeset
157 }
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 /* Move on to the next subrtx. */
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 template <typename T>
kono
parents:
diff changeset
162 inline void
kono
parents:
diff changeset
163 generic_subrtx_iterator <T>::next ()
kono
parents:
diff changeset
164 {
kono
parents:
diff changeset
165 if (m_substitute)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 m_substitute = false;
kono
parents:
diff changeset
168 m_skip = false;
kono
parents:
diff changeset
169 return;
kono
parents:
diff changeset
170 }
kono
parents:
diff changeset
171 if (!m_skip)
kono
parents:
diff changeset
172 {
kono
parents:
diff changeset
173 /* Add the subrtxes of M_CURRENT. */
kono
parents:
diff changeset
174 rtx_type x = T::get_rtx (m_current);
kono
parents:
diff changeset
175 if (__builtin_expect (x != 0, true))
kono
parents:
diff changeset
176 {
kono
parents:
diff changeset
177 enum rtx_code code = GET_CODE (x);
kono
parents:
diff changeset
178 ssize_t count = m_bounds[code].count;
kono
parents:
diff changeset
179 if (count > 0)
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 /* Handle the simple case of a single "e" block that is known
kono
parents:
diff changeset
182 to fit into the current array. */
kono
parents:
diff changeset
183 if (__builtin_expect (m_end + count <= LOCAL_ELEMS + 1, true))
kono
parents:
diff changeset
184 {
kono
parents:
diff changeset
185 /* Set M_CURRENT to the first subrtx and queue the rest. */
kono
parents:
diff changeset
186 ssize_t start = m_bounds[code].start;
kono
parents:
diff changeset
187 rtunion_type *src = &x->u.fld[start];
kono
parents:
diff changeset
188 if (__builtin_expect (count > 2, false))
kono
parents:
diff changeset
189 m_base[m_end++] = T::get_value (src[2].rt_rtx);
kono
parents:
diff changeset
190 if (count > 1)
kono
parents:
diff changeset
191 m_base[m_end++] = T::get_value (src[1].rt_rtx);
kono
parents:
diff changeset
192 m_current = T::get_value (src[0].rt_rtx);
kono
parents:
diff changeset
193 return;
kono
parents:
diff changeset
194 }
kono
parents:
diff changeset
195 /* Handle cases which aren't simple "e" sequences or where
kono
parents:
diff changeset
196 the sequence might overrun M_BASE. */
kono
parents:
diff changeset
197 count = add_subrtxes_to_queue (m_array, m_base, m_end, x);
kono
parents:
diff changeset
198 if (count > 0)
kono
parents:
diff changeset
199 {
kono
parents:
diff changeset
200 m_end += count;
kono
parents:
diff changeset
201 if (m_end > LOCAL_ELEMS)
kono
parents:
diff changeset
202 m_base = m_array.heap->address ();
kono
parents:
diff changeset
203 m_current = m_base[--m_end];
kono
parents:
diff changeset
204 return;
kono
parents:
diff changeset
205 }
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207 }
kono
parents:
diff changeset
208 }
kono
parents:
diff changeset
209 else
kono
parents:
diff changeset
210 m_skip = false;
kono
parents:
diff changeset
211 if (m_end == 0)
kono
parents:
diff changeset
212 m_done = true;
kono
parents:
diff changeset
213 else
kono
parents:
diff changeset
214 m_current = m_base[--m_end];
kono
parents:
diff changeset
215 }
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 /* Skip the subrtxes of the current rtx. */
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 template <typename T>
kono
parents:
diff changeset
220 inline void
kono
parents:
diff changeset
221 generic_subrtx_iterator <T>::skip_subrtxes ()
kono
parents:
diff changeset
222 {
kono
parents:
diff changeset
223 m_skip = true;
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 /* Ignore the subrtxes of the current rtx and look at X instead. */
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 template <typename T>
kono
parents:
diff changeset
229 inline void
kono
parents:
diff changeset
230 generic_subrtx_iterator <T>::substitute (value_type x)
kono
parents:
diff changeset
231 {
kono
parents:
diff changeset
232 m_substitute = true;
kono
parents:
diff changeset
233 m_current = x;
kono
parents:
diff changeset
234 }
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 /* Iterators for const_rtx. */
kono
parents:
diff changeset
237 struct const_rtx_accessor
kono
parents:
diff changeset
238 {
kono
parents:
diff changeset
239 typedef const_rtx value_type;
kono
parents:
diff changeset
240 typedef const_rtx rtx_type;
kono
parents:
diff changeset
241 typedef const rtunion rtunion_type;
kono
parents:
diff changeset
242 static rtx_type get_rtx (value_type x) { return x; }
kono
parents:
diff changeset
243 static value_type get_value (rtx_type x) { return x; }
kono
parents:
diff changeset
244 };
kono
parents:
diff changeset
245 typedef generic_subrtx_iterator <const_rtx_accessor> subrtx_iterator;
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 /* Iterators for non-constant rtx. */
kono
parents:
diff changeset
248 struct rtx_var_accessor
kono
parents:
diff changeset
249 {
kono
parents:
diff changeset
250 typedef rtx value_type;
kono
parents:
diff changeset
251 typedef rtx rtx_type;
kono
parents:
diff changeset
252 typedef rtunion rtunion_type;
kono
parents:
diff changeset
253 static rtx_type get_rtx (value_type x) { return x; }
kono
parents:
diff changeset
254 static value_type get_value (rtx_type x) { return x; }
kono
parents:
diff changeset
255 };
kono
parents:
diff changeset
256 typedef generic_subrtx_iterator <rtx_var_accessor> subrtx_var_iterator;
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 /* Iterators for rtx *. */
kono
parents:
diff changeset
259 struct rtx_ptr_accessor
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 typedef rtx *value_type;
kono
parents:
diff changeset
262 typedef rtx rtx_type;
kono
parents:
diff changeset
263 typedef rtunion rtunion_type;
kono
parents:
diff changeset
264 static rtx_type get_rtx (value_type ptr) { return *ptr; }
kono
parents:
diff changeset
265 static value_type get_value (rtx_type &x) { return &x; }
kono
parents:
diff changeset
266 };
kono
parents:
diff changeset
267 typedef generic_subrtx_iterator <rtx_ptr_accessor> subrtx_ptr_iterator;
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 #define ALL_BOUNDS rtx_all_subrtx_bounds
kono
parents:
diff changeset
270 #define NONCONST_BOUNDS rtx_nonconst_subrtx_bounds
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 /* Use ITER to iterate over const_rtx X and its recursive subrtxes,
kono
parents:
diff changeset
273 using subrtx_iterator::array ARRAY as the storage for the worklist.
kono
parents:
diff changeset
274 ARRAY can be reused for multiple consecutive iterations but shouldn't
kono
parents:
diff changeset
275 be shared by two concurrent iterations. TYPE is ALL if all subrtxes
kono
parents:
diff changeset
276 are of interest or NONCONST if it is safe to ignore subrtxes of
kono
parents:
diff changeset
277 constants. */
kono
parents:
diff changeset
278 #define FOR_EACH_SUBRTX(ITER, ARRAY, X, TYPE) \
kono
parents:
diff changeset
279 for (subrtx_iterator ITER (ARRAY, X, TYPE##_BOUNDS); !ITER.at_end (); \
kono
parents:
diff changeset
280 ITER.next ())
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 /* Like FOR_EACH_SUBRTX, but iterate over subrtxes of an rtx X. */
kono
parents:
diff changeset
283 #define FOR_EACH_SUBRTX_VAR(ITER, ARRAY, X, TYPE) \
kono
parents:
diff changeset
284 for (subrtx_var_iterator ITER (ARRAY, X, TYPE##_BOUNDS); !ITER.at_end (); \
kono
parents:
diff changeset
285 ITER.next ())
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 /* Like FOR_EACH_SUBRTX, but iterate over subrtx pointers of rtx pointer X.
kono
parents:
diff changeset
288 For example, if X is &PATTERN (insn) and the pattern is a SET, iterate
kono
parents:
diff changeset
289 over &PATTERN (insn), &SET_DEST (PATTERN (insn)), etc. */
kono
parents:
diff changeset
290 #define FOR_EACH_SUBRTX_PTR(ITER, ARRAY, X, TYPE) \
kono
parents:
diff changeset
291 for (subrtx_ptr_iterator ITER (ARRAY, X, TYPE##_BOUNDS); !ITER.at_end (); \
kono
parents:
diff changeset
292 ITER.next ())