]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-iterator.h
[Ada] Use Standard.Natural on bit references to packed arrays
[thirdparty/gcc.git] / gcc / gimple-iterator.h
CommitLineData
5be5c238 1/* Header file for gimple iterators.
8d9254fc 2 Copyright (C) 2013-2020 Free Software Foundation, Inc.
5be5c238
AM
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_GIMPLE_ITERATOR_H
21#define GCC_GIMPLE_ITERATOR_H
22
23/* Iterator object for GIMPLE statement sequences. */
24
84562394 25struct gimple_stmt_iterator
5be5c238
AM
26{
27 /* Sequence node holding the current statement. */
28 gimple_seq_node ptr;
29
30 /* Sequence and basic block holding the statement. These fields
31 are necessary to handle edge cases such as when statement is
32 added to an empty basic block or when the last statement of a
33 block/sequence is removed. */
34 gimple_seq *seq;
35 basic_block bb;
84562394 36};
538dd0b7
DM
37
38/* Iterator over GIMPLE_PHI statements. */
39struct gphi_iterator : public gimple_stmt_iterator
40{
41 gphi *phi () const
42 {
43 return as_a <gphi *> (ptr);
44 }
45};
5be5c238 46
18f429e2
AM
47enum gsi_iterator_update
48{
49 GSI_NEW_STMT, /* Only valid when single statement is added, move
50 iterator to it. */
51 GSI_SAME_STMT, /* Leave the iterator at the same statement. */
52 GSI_CONTINUE_LINKING /* Move iterator to whatever position is suitable
53 for linking other statements in the same
54 direction. */
55};
56
5be5c238
AM
57extern void gsi_insert_seq_before_without_update (gimple_stmt_iterator *,
58 gimple_seq,
59 enum gsi_iterator_update);
60extern void gsi_insert_seq_before (gimple_stmt_iterator *, gimple_seq,
61 enum gsi_iterator_update);
62extern void gsi_insert_seq_after_without_update (gimple_stmt_iterator *,
63 gimple_seq,
64 enum gsi_iterator_update);
65extern void gsi_insert_seq_after (gimple_stmt_iterator *, gimple_seq,
66 enum gsi_iterator_update);
67extern gimple_seq gsi_split_seq_after (gimple_stmt_iterator);
355fe088 68extern void gsi_set_stmt (gimple_stmt_iterator *, gimple *);
5be5c238 69extern void gsi_split_seq_before (gimple_stmt_iterator *, gimple_seq *);
355fe088 70extern bool gsi_replace (gimple_stmt_iterator *, gimple *, bool);
5be5c238 71extern void gsi_replace_with_seq (gimple_stmt_iterator *, gimple_seq, bool);
355fe088 72extern void gsi_insert_before_without_update (gimple_stmt_iterator *, gimple *,
5be5c238 73 enum gsi_iterator_update);
355fe088 74extern void gsi_insert_before (gimple_stmt_iterator *, gimple *,
5be5c238 75 enum gsi_iterator_update);
355fe088 76extern void gsi_insert_after_without_update (gimple_stmt_iterator *, gimple *,
5be5c238 77 enum gsi_iterator_update);
355fe088 78extern void gsi_insert_after (gimple_stmt_iterator *, gimple *,
5be5c238
AM
79 enum gsi_iterator_update);
80extern bool gsi_remove (gimple_stmt_iterator *, bool);
355fe088 81extern gimple_stmt_iterator gsi_for_stmt (gimple *);
41949de9 82extern gimple_stmt_iterator gsi_for_stmt (gimple *, gimple_seq *);
538dd0b7 83extern gphi_iterator gsi_for_phi (gphi *);
5be5c238
AM
84extern void gsi_move_after (gimple_stmt_iterator *, gimple_stmt_iterator *);
85extern void gsi_move_before (gimple_stmt_iterator *, gimple_stmt_iterator *);
86extern void gsi_move_to_bb_end (gimple_stmt_iterator *, basic_block);
355fe088 87extern void gsi_insert_on_edge (edge, gimple *);
5be5c238 88extern void gsi_insert_seq_on_edge (edge, gimple_seq);
355fe088 89extern basic_block gsi_insert_on_edge_immediate (edge, gimple *);
5be5c238
AM
90extern basic_block gsi_insert_seq_on_edge_immediate (edge, gimple_seq);
91extern void gsi_commit_edge_inserts (void);
92extern void gsi_commit_one_edge_insert (edge, basic_block *);
538dd0b7 93extern gphi_iterator gsi_start_phis (basic_block);
f8e89441 94extern void update_modified_stmts (gimple_seq);
5be5c238
AM
95
96/* Return a new iterator pointing to GIMPLE_SEQ's first statement. */
97
98static inline gimple_stmt_iterator
99gsi_start_1 (gimple_seq *seq)
100{
101 gimple_stmt_iterator i;
102
103 i.ptr = gimple_seq_first (*seq);
104 i.seq = seq;
105 i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
106
107 return i;
108}
109
110#define gsi_start(x) gsi_start_1 (&(x))
111
112static inline gimple_stmt_iterator
113gsi_none (void)
114{
115 gimple_stmt_iterator i;
116 i.ptr = NULL;
117 i.seq = NULL;
118 i.bb = NULL;
119 return i;
120}
121
122/* Return a new iterator pointing to the first statement in basic block BB. */
123
124static inline gimple_stmt_iterator
125gsi_start_bb (basic_block bb)
126{
127 gimple_stmt_iterator i;
128 gimple_seq *seq;
129
130 seq = bb_seq_addr (bb);
131 i.ptr = gimple_seq_first (*seq);
132 i.seq = seq;
133 i.bb = bb;
134
135 return i;
136}
137
104cb50b
MJ
138gimple_stmt_iterator gsi_start_edge (edge e);
139
5be5c238
AM
140/* Return a new iterator initially pointing to GIMPLE_SEQ's last statement. */
141
142static inline gimple_stmt_iterator
143gsi_last_1 (gimple_seq *seq)
144{
145 gimple_stmt_iterator i;
146
147 i.ptr = gimple_seq_last (*seq);
148 i.seq = seq;
149 i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
150
151 return i;
152}
153
154#define gsi_last(x) gsi_last_1 (&(x))
155
156/* Return a new iterator pointing to the last statement in basic block BB. */
157
158static inline gimple_stmt_iterator
159gsi_last_bb (basic_block bb)
160{
161 gimple_stmt_iterator i;
162 gimple_seq *seq;
163
164 seq = bb_seq_addr (bb);
165 i.ptr = gimple_seq_last (*seq);
166 i.seq = seq;
167 i.bb = bb;
168
169 return i;
170}
171
172/* Return true if I is at the end of its sequence. */
173
174static inline bool
175gsi_end_p (gimple_stmt_iterator i)
176{
177 return i.ptr == NULL;
178}
179
180/* Return true if I is one statement before the end of its sequence. */
181
182static inline bool
183gsi_one_before_end_p (gimple_stmt_iterator i)
184{
daa6e488 185 return i.ptr != NULL && i.ptr->next == NULL;
5be5c238
AM
186}
187
188/* Advance the iterator to the next gimple statement. */
189
190static inline void
191gsi_next (gimple_stmt_iterator *i)
192{
daa6e488 193 i->ptr = i->ptr->next;
5be5c238
AM
194}
195
196/* Advance the iterator to the previous gimple statement. */
197
198static inline void
199gsi_prev (gimple_stmt_iterator *i)
200{
355fe088 201 gimple *prev = i->ptr->prev;
daa6e488 202 if (prev->next)
5be5c238
AM
203 i->ptr = prev;
204 else
205 i->ptr = NULL;
206}
207
208/* Return the current stmt. */
209
355fe088 210static inline gimple *
5be5c238
AM
211gsi_stmt (gimple_stmt_iterator i)
212{
213 return i.ptr;
214}
215
65f4b875 216/* Return a block statement iterator that points to the first
67a8d719 217 non-label statement in block BB. */
5be5c238
AM
218
219static inline gimple_stmt_iterator
220gsi_after_labels (basic_block bb)
221{
222 gimple_stmt_iterator gsi = gsi_start_bb (bb);
223
67a8d719 224 for (; !gsi_end_p (gsi); )
65f4b875 225 {
67a8d719
AO
226 if (gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL)
227 gsi_next (&gsi);
65f4b875
AO
228 else
229 break;
230 }
5be5c238
AM
231
232 return gsi;
233}
234
235/* Advance the iterator to the next non-debug gimple statement. */
236
237static inline void
238gsi_next_nondebug (gimple_stmt_iterator *i)
239{
240 do
241 {
242 gsi_next (i);
243 }
244 while (!gsi_end_p (*i) && is_gimple_debug (gsi_stmt (*i)));
245}
246
7d1ff6f0 247/* Advance the iterator to the previous non-debug gimple statement. */
5be5c238
AM
248
249static inline void
250gsi_prev_nondebug (gimple_stmt_iterator *i)
251{
252 do
253 {
254 gsi_prev (i);
255 }
256 while (!gsi_end_p (*i) && is_gimple_debug (gsi_stmt (*i)));
257}
258
65f4b875
AO
259/* Return a new iterator pointing to the first non-debug statement in
260 SEQ. */
261
262static inline gimple_stmt_iterator
263gsi_start_nondebug (gimple_seq seq)
264{
265 gimple_stmt_iterator gsi = gsi_start (seq);
266 if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
267 gsi_next_nondebug (&gsi);
268
269 return gsi;
270}
271
5be5c238
AM
272/* Return a new iterator pointing to the first non-debug statement in
273 basic block BB. */
274
275static inline gimple_stmt_iterator
276gsi_start_nondebug_bb (basic_block bb)
277{
278 gimple_stmt_iterator i = gsi_start_bb (bb);
279
280 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
281 gsi_next_nondebug (&i);
282
283 return i;
284}
285
286/* Return a new iterator pointing to the first non-debug non-label statement in
287 basic block BB. */
288
289static inline gimple_stmt_iterator
290gsi_start_nondebug_after_labels_bb (basic_block bb)
291{
292 gimple_stmt_iterator i = gsi_after_labels (bb);
293
294 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
295 gsi_next_nondebug (&i);
296
297 return i;
298}
299
300/* Return a new iterator pointing to the last non-debug statement in
301 basic block BB. */
302
303static inline gimple_stmt_iterator
304gsi_last_nondebug_bb (basic_block bb)
305{
306 gimple_stmt_iterator i = gsi_last_bb (bb);
307
308 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
309 gsi_prev_nondebug (&i);
310
311 return i;
312}
313
55665504
AO
314/* Return true if I is followed only by debug statements in its
315 sequence. */
316
317static inline bool
318gsi_one_nondebug_before_end_p (gimple_stmt_iterator i)
319{
320 if (gsi_one_before_end_p (i))
321 return true;
322 if (gsi_end_p (i))
323 return false;
324 gsi_next_nondebug (&i);
325 return gsi_end_p (i);
326}
327
880dcdae
VI
328/* Advance I statement iterator to the next non-virtual GIMPLE_PHI
329 statement. */
fd29c024
ML
330
331static inline void
538dd0b7 332gsi_next_nonvirtual_phi (gphi_iterator *i)
fd29c024 333{
880dcdae 334 do
fd29c024
ML
335 {
336 gsi_next (i);
880dcdae
VI
337 }
338 while (!gsi_end_p (*i) && virtual_operand_p (gimple_phi_result (i->phi ())));
339}
fd29c024 340
880dcdae
VI
341/* Return a new iterator pointing to the first non-virtual phi statement in
342 basic block BB. */
fd29c024 343
880dcdae
VI
344static inline gphi_iterator
345gsi_start_nonvirtual_phis (basic_block bb)
346{
347 gphi_iterator i = gsi_start_phis (bb);
348
349 if (!gsi_end_p (i) && virtual_operand_p (gimple_phi_result (i.phi ())))
350 gsi_next_nonvirtual_phi (&i);
351
352 return i;
fd29c024
ML
353}
354
5be5c238
AM
355/* Return the basic block associated with this iterator. */
356
357static inline basic_block
358gsi_bb (gimple_stmt_iterator i)
359{
360 return i.bb;
361}
362
363/* Return the sequence associated with this iterator. */
364
365static inline gimple_seq
366gsi_seq (gimple_stmt_iterator i)
367{
368 return *i.seq;
369}
370
1b7f61eb
TV
371/* Determine whether SEQ is a nondebug singleton. */
372
373static inline bool
374gimple_seq_nondebug_singleton_p (gimple_seq seq)
375{
376 gimple_stmt_iterator gsi;
e92e61a7
TV
377
378 /* Find a nondebug gimple. */
1b7f61eb
TV
379 gsi.ptr = gimple_seq_first (seq);
380 gsi.seq = &seq;
381 gsi.bb = NULL;
1b7f61eb
TV
382 while (!gsi_end_p (gsi)
383 && is_gimple_debug (gsi_stmt (gsi)))
384 gsi_next (&gsi);
385
e92e61a7
TV
386 /* No nondebug gimple found, not a singleton. */
387 if (gsi_end_p (gsi))
1b7f61eb
TV
388 return false;
389
e92e61a7
TV
390 /* Find a next nondebug gimple. */
391 gsi_next (&gsi);
1b7f61eb
TV
392 while (!gsi_end_p (gsi)
393 && is_gimple_debug (gsi_stmt (gsi)))
394 gsi_next (&gsi);
395
e92e61a7
TV
396 /* Only a singleton if there's no next nondebug gimple. */
397 return gsi_end_p (gsi);
1b7f61eb
TV
398}
399
5be5c238 400#endif /* GCC_GIMPLE_ITERATOR_H */