]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gimple-iterator.h
gimple-walk.h: New File.
[thirdparty/gcc.git] / gcc / gimple-iterator.h
CommitLineData
5be5c238
AM
1/* Header file for gimple iterators.
2 Copyright (C) 2013 Free Software Foundation, Inc.
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
25typedef struct gimple_stmt_iterator_d
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;
36} gimple_stmt_iterator;
37
38extern void gsi_insert_seq_before_without_update (gimple_stmt_iterator *,
39 gimple_seq,
40 enum gsi_iterator_update);
41extern void gsi_insert_seq_before (gimple_stmt_iterator *, gimple_seq,
42 enum gsi_iterator_update);
43extern void gsi_insert_seq_after_without_update (gimple_stmt_iterator *,
44 gimple_seq,
45 enum gsi_iterator_update);
46extern void gsi_insert_seq_after (gimple_stmt_iterator *, gimple_seq,
47 enum gsi_iterator_update);
48extern gimple_seq gsi_split_seq_after (gimple_stmt_iterator);
49extern void gsi_set_stmt (gimple_stmt_iterator *, gimple);
50extern void gsi_split_seq_before (gimple_stmt_iterator *, gimple_seq *);
51extern void gsi_replace (gimple_stmt_iterator *, gimple, bool);
52extern void gsi_replace_with_seq (gimple_stmt_iterator *, gimple_seq, bool);
53extern void gsi_insert_before_without_update (gimple_stmt_iterator *, gimple,
54 enum gsi_iterator_update);
55extern void gsi_insert_before (gimple_stmt_iterator *, gimple,
56 enum gsi_iterator_update);
57extern void gsi_insert_after_without_update (gimple_stmt_iterator *, gimple,
58 enum gsi_iterator_update);
59extern void gsi_insert_after (gimple_stmt_iterator *, gimple,
60 enum gsi_iterator_update);
61extern bool gsi_remove (gimple_stmt_iterator *, bool);
62extern gimple_stmt_iterator gsi_for_stmt (gimple);
63extern void gsi_move_after (gimple_stmt_iterator *, gimple_stmt_iterator *);
64extern void gsi_move_before (gimple_stmt_iterator *, gimple_stmt_iterator *);
65extern void gsi_move_to_bb_end (gimple_stmt_iterator *, basic_block);
66extern void gsi_insert_on_edge (edge, gimple);
67extern void gsi_insert_seq_on_edge (edge, gimple_seq);
68extern basic_block gsi_insert_on_edge_immediate (edge, gimple);
69extern basic_block gsi_insert_seq_on_edge_immediate (edge, gimple_seq);
70extern void gsi_commit_edge_inserts (void);
71extern void gsi_commit_one_edge_insert (edge, basic_block *);
72extern gimple_stmt_iterator gsi_start_phis (basic_block);
73
74/* Return a new iterator pointing to GIMPLE_SEQ's first statement. */
75
76static inline gimple_stmt_iterator
77gsi_start_1 (gimple_seq *seq)
78{
79 gimple_stmt_iterator i;
80
81 i.ptr = gimple_seq_first (*seq);
82 i.seq = seq;
83 i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
84
85 return i;
86}
87
88#define gsi_start(x) gsi_start_1 (&(x))
89
90static inline gimple_stmt_iterator
91gsi_none (void)
92{
93 gimple_stmt_iterator i;
94 i.ptr = NULL;
95 i.seq = NULL;
96 i.bb = NULL;
97 return i;
98}
99
100/* Return a new iterator pointing to the first statement in basic block BB. */
101
102static inline gimple_stmt_iterator
103gsi_start_bb (basic_block bb)
104{
105 gimple_stmt_iterator i;
106 gimple_seq *seq;
107
108 seq = bb_seq_addr (bb);
109 i.ptr = gimple_seq_first (*seq);
110 i.seq = seq;
111 i.bb = bb;
112
113 return i;
114}
115
116/* Return a new iterator initially pointing to GIMPLE_SEQ's last statement. */
117
118static inline gimple_stmt_iterator
119gsi_last_1 (gimple_seq *seq)
120{
121 gimple_stmt_iterator i;
122
123 i.ptr = gimple_seq_last (*seq);
124 i.seq = seq;
125 i.bb = i.ptr ? gimple_bb (i.ptr) : NULL;
126
127 return i;
128}
129
130#define gsi_last(x) gsi_last_1 (&(x))
131
132/* Return a new iterator pointing to the last statement in basic block BB. */
133
134static inline gimple_stmt_iterator
135gsi_last_bb (basic_block bb)
136{
137 gimple_stmt_iterator i;
138 gimple_seq *seq;
139
140 seq = bb_seq_addr (bb);
141 i.ptr = gimple_seq_last (*seq);
142 i.seq = seq;
143 i.bb = bb;
144
145 return i;
146}
147
148/* Return true if I is at the end of its sequence. */
149
150static inline bool
151gsi_end_p (gimple_stmt_iterator i)
152{
153 return i.ptr == NULL;
154}
155
156/* Return true if I is one statement before the end of its sequence. */
157
158static inline bool
159gsi_one_before_end_p (gimple_stmt_iterator i)
160{
161 return i.ptr != NULL && i.ptr->gsbase.next == NULL;
162}
163
164/* Advance the iterator to the next gimple statement. */
165
166static inline void
167gsi_next (gimple_stmt_iterator *i)
168{
169 i->ptr = i->ptr->gsbase.next;
170}
171
172/* Advance the iterator to the previous gimple statement. */
173
174static inline void
175gsi_prev (gimple_stmt_iterator *i)
176{
177 gimple prev = i->ptr->gsbase.prev;
178 if (prev->gsbase.next)
179 i->ptr = prev;
180 else
181 i->ptr = NULL;
182}
183
184/* Return the current stmt. */
185
186static inline gimple
187gsi_stmt (gimple_stmt_iterator i)
188{
189 return i.ptr;
190}
191
192/* Return a block statement iterator that points to the first non-label
193 statement in block BB. */
194
195static inline gimple_stmt_iterator
196gsi_after_labels (basic_block bb)
197{
198 gimple_stmt_iterator gsi = gsi_start_bb (bb);
199
200 while (!gsi_end_p (gsi) && gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL)
201 gsi_next (&gsi);
202
203 return gsi;
204}
205
206/* Advance the iterator to the next non-debug gimple statement. */
207
208static inline void
209gsi_next_nondebug (gimple_stmt_iterator *i)
210{
211 do
212 {
213 gsi_next (i);
214 }
215 while (!gsi_end_p (*i) && is_gimple_debug (gsi_stmt (*i)));
216}
217
218/* Advance the iterator to the next non-debug gimple statement. */
219
220static inline void
221gsi_prev_nondebug (gimple_stmt_iterator *i)
222{
223 do
224 {
225 gsi_prev (i);
226 }
227 while (!gsi_end_p (*i) && is_gimple_debug (gsi_stmt (*i)));
228}
229
230/* Return a new iterator pointing to the first non-debug statement in
231 basic block BB. */
232
233static inline gimple_stmt_iterator
234gsi_start_nondebug_bb (basic_block bb)
235{
236 gimple_stmt_iterator i = gsi_start_bb (bb);
237
238 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
239 gsi_next_nondebug (&i);
240
241 return i;
242}
243
244/* Return a new iterator pointing to the first non-debug non-label statement in
245 basic block BB. */
246
247static inline gimple_stmt_iterator
248gsi_start_nondebug_after_labels_bb (basic_block bb)
249{
250 gimple_stmt_iterator i = gsi_after_labels (bb);
251
252 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
253 gsi_next_nondebug (&i);
254
255 return i;
256}
257
258/* Return a new iterator pointing to the last non-debug statement in
259 basic block BB. */
260
261static inline gimple_stmt_iterator
262gsi_last_nondebug_bb (basic_block bb)
263{
264 gimple_stmt_iterator i = gsi_last_bb (bb);
265
266 if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
267 gsi_prev_nondebug (&i);
268
269 return i;
270}
271
272/* Return the basic block associated with this iterator. */
273
274static inline basic_block
275gsi_bb (gimple_stmt_iterator i)
276{
277 return i.bb;
278}
279
280/* Return the sequence associated with this iterator. */
281
282static inline gimple_seq
283gsi_seq (gimple_stmt_iterator i)
284{
285 return *i.seq;
286}
287
288#endif /* GCC_GIMPLE_ITERATOR_H */