Branch data Line data Source code
1 : : /* Gimple folding definitions.
2 : :
3 : : Copyright (C) 2011-2025 Free Software Foundation, Inc.
4 : : Contributed by Richard Guenther <rguenther@suse.de>
5 : :
6 : : This file is part of GCC.
7 : :
8 : : GCC is free software; you can redistribute it and/or modify it under
9 : : the terms of the GNU General Public License as published by the Free
10 : : Software Foundation; either version 3, or (at your option) any later
11 : : version.
12 : :
13 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 : : for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GCC; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : #ifndef GCC_GIMPLE_FOLD_H
23 : : #define GCC_GIMPLE_FOLD_H
24 : :
25 : : extern tree canonicalize_constructor_val (tree, tree);
26 : : extern tree get_symbol_constant_value (tree);
27 : : struct c_strlen_data;
28 : : extern bool get_range_strlen (tree, c_strlen_data *, unsigned eltsize);
29 : : extern void gimplify_and_update_call_from_tree (gimple_stmt_iterator *, tree);
30 : : extern bool update_gimple_call (gimple_stmt_iterator *, tree, int, ...);
31 : : extern bool fold_stmt (gimple_stmt_iterator *, bitmap = nullptr);
32 : : extern bool fold_stmt (gimple_stmt_iterator *, tree (*) (tree), bitmap = nullptr);
33 : : extern bool fold_stmt_inplace (gimple_stmt_iterator *);
34 : : extern tree maybe_fold_and_comparisons (tree, enum tree_code, tree, tree,
35 : : enum tree_code, tree, tree,
36 : : basic_block = nullptr);
37 : : extern tree maybe_fold_or_comparisons (tree, enum tree_code, tree, tree,
38 : : enum tree_code, tree, tree,
39 : : basic_block = nullptr);
40 : : extern bool optimize_atomic_compare_exchange_p (gimple *);
41 : : extern void fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *);
42 : : extern tree no_follow_ssa_edges (tree);
43 : : extern tree follow_single_use_edges (tree);
44 : : extern tree follow_all_ssa_edges (tree);
45 : : extern tree gimple_fold_stmt_to_constant_1 (gimple *, tree (*) (tree),
46 : : tree (*) (tree) = no_follow_ssa_edges);
47 : : extern tree gimple_fold_stmt_to_constant (gimple *, tree (*) (tree));
48 : : extern tree fold_ctor_reference (tree, tree, const poly_uint64&,
49 : : const poly_uint64&, tree,
50 : : unsigned HOST_WIDE_INT * = NULL);
51 : : extern tree fold_const_aggregate_ref_1 (tree, tree (*) (tree));
52 : : extern tree fold_const_aggregate_ref (tree);
53 : : extern tree gimple_get_virt_method_for_binfo (HOST_WIDE_INT, tree,
54 : : bool *can_refer = NULL);
55 : : extern tree gimple_get_virt_method_for_vtable (HOST_WIDE_INT, tree,
56 : : unsigned HOST_WIDE_INT,
57 : : bool *can_refer = NULL);
58 : : extern tree gimple_fold_indirect_ref (tree);
59 : : extern bool gimple_fold_builtin_sprintf (gimple_stmt_iterator *);
60 : : extern bool gimple_fold_builtin_snprintf (gimple_stmt_iterator *);
61 : : extern bool gimple_needing_rewrite_undefined (gimple *);
62 : : extern void rewrite_to_defined_unconditional (gimple_stmt_iterator *);
63 : : extern gimple_seq rewrite_to_defined_unconditional (gimple *);
64 : : extern void replace_call_with_value (gimple_stmt_iterator *, tree);
65 : : extern tree tree_vec_extract (gimple_stmt_iterator *, tree, tree, tree, tree);
66 : : extern void gsi_replace_with_seq_vops (gimple_stmt_iterator *, gimple_seq);
67 : :
68 : : /* gimple_build, functionally matching fold_buildN, outputs stmts
69 : : int the provided sequence, matching and simplifying them on-the-fly.
70 : : Supposed to replace force_gimple_operand (fold_buildN (...), ...). */
71 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
72 : : enum gsi_iterator_update,
73 : : location_t, enum tree_code, tree, tree);
74 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
75 : : enum gsi_iterator_update,
76 : : location_t, enum tree_code, tree, tree, tree);
77 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
78 : : enum gsi_iterator_update,
79 : : location_t, enum tree_code, tree, tree, tree, tree);
80 : : template<class ...Args>
81 : : inline tree
82 : 538041 : gimple_build (gimple_seq *seq, location_t loc,
83 : : enum tree_code code, tree type, Args ...ops)
84 : : {
85 : : static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
86 : : "Number of operands must be from one to three");
87 : 538041 : gimple_stmt_iterator gsi = gsi_last (*seq);
88 : 538041 : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
89 : 538041 : loc, code, type, ops...);
90 : : }
91 : : template<class ...Args>
92 : : inline tree
93 : 344997 : gimple_build (gimple_seq *seq, enum tree_code code, tree type, Args ...ops)
94 : : {
95 : : static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
96 : : "Number of operands must be from one to three");
97 : 344997 : gimple_stmt_iterator gsi = gsi_last (*seq);
98 : 344997 : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
99 : 344997 : UNKNOWN_LOCATION, code, type, ops...);
100 : : }
101 : :
102 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
103 : : enum gsi_iterator_update,
104 : : location_t, combined_fn, tree);
105 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
106 : : enum gsi_iterator_update,
107 : : location_t, combined_fn, tree, tree);
108 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
109 : : enum gsi_iterator_update,
110 : : location_t, combined_fn, tree, tree, tree);
111 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
112 : : enum gsi_iterator_update,
113 : : location_t, combined_fn, tree, tree, tree, tree);
114 : : template<class ...Args>
115 : : inline tree
116 : 371 : gimple_build (gimple_seq *seq, location_t loc,
117 : : combined_fn fn, tree type, Args ...args)
118 : : {
119 : : static_assert (sizeof...(args) < 4,
120 : : "Number of arguments must be less than four");
121 : 371 : gimple_stmt_iterator gsi = gsi_last (*seq);
122 : 371 : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
123 : 371 : loc, fn, type, args...);
124 : : }
125 : : template<class ...Args>
126 : : inline tree
127 : 23508 : gimple_build (gimple_seq *seq, combined_fn fn, tree type, Args ...args)
128 : : {
129 : : static_assert (sizeof...(args) < 4,
130 : : "Number of arguments must be less than four");
131 : 23508 : gimple_stmt_iterator gsi = gsi_last (*seq);
132 : 23508 : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
133 : 23508 : UNKNOWN_LOCATION, fn, type, args...);
134 : : }
135 : :
136 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
137 : : enum gsi_iterator_update,
138 : : location_t, code_helper, tree, tree);
139 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
140 : : enum gsi_iterator_update,
141 : : location_t, code_helper, tree, tree, tree);
142 : : extern tree gimple_build (gimple_stmt_iterator *, bool,
143 : : enum gsi_iterator_update,
144 : : location_t, code_helper, tree, tree, tree, tree);
145 : :
146 : : template<class ...Args>
147 : : inline tree
148 : : gimple_build (gimple_seq *seq, location_t loc,
149 : : code_helper code, tree type, Args ...ops)
150 : : {
151 : : static_assert (sizeof...(ops) < 4,
152 : : "Number of operands must be less than four");
153 : : gimple_stmt_iterator gsi = gsi_last (*seq);
154 : : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
155 : : loc, code, type, ops...);
156 : : }
157 : : template<class ...Args>
158 : : inline tree
159 : 22330 : gimple_build (gimple_seq *seq,
160 : : code_helper code, tree type, Args ...ops)
161 : : {
162 : : static_assert (sizeof...(ops) < 4,
163 : : "Number of operands must be less than four");
164 : 22330 : gimple_stmt_iterator gsi = gsi_last (*seq);
165 : 22330 : return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
166 : 22330 : UNKNOWN_LOCATION, code, type, ops...);
167 : : }
168 : :
169 : : extern tree gimple_convert (gimple_stmt_iterator *, bool,
170 : : enum gsi_iterator_update,
171 : : location_t, tree, tree);
172 : : inline tree
173 : 28854 : gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
174 : : {
175 : 28854 : gimple_stmt_iterator gsi = gsi_last (*seq);
176 : 28854 : return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING, loc, type, op);
177 : : }
178 : : inline tree
179 : 1806852 : gimple_convert (gimple_seq *seq, tree type, tree op)
180 : : {
181 : 1806852 : gimple_stmt_iterator gsi = gsi_last (*seq);
182 : 1806852 : return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING,
183 : 1806852 : UNKNOWN_LOCATION, type, op);
184 : : }
185 : :
186 : : extern tree gimple_convert_to_ptrofftype (gimple_stmt_iterator *, bool,
187 : : enum gsi_iterator_update,
188 : : location_t, tree);
189 : : inline tree
190 : 203 : gimple_convert_to_ptrofftype (gimple_seq *seq, location_t loc, tree op)
191 : : {
192 : 203 : gimple_stmt_iterator gsi = gsi_last (*seq);
193 : 203 : return gimple_convert_to_ptrofftype (&gsi, false, GSI_CONTINUE_LINKING,
194 : 203 : loc, op);
195 : : }
196 : : inline tree
197 : : gimple_convert_to_ptrofftype (gimple_seq *seq, tree op)
198 : : {
199 : : gimple_stmt_iterator gsi = gsi_last (*seq);
200 : : return gimple_convert_to_ptrofftype (&gsi, false, GSI_CONTINUE_LINKING,
201 : : UNKNOWN_LOCATION, op);
202 : : }
203 : :
204 : : extern tree gimple_build_vector_from_val (gimple_stmt_iterator *, bool,
205 : : enum gsi_iterator_update,
206 : : location_t, tree, tree);
207 : : inline tree
208 : 154 : gimple_build_vector_from_val (gimple_seq *seq, location_t loc,
209 : : tree type, tree op)
210 : : {
211 : 154 : gimple_stmt_iterator gsi = gsi_last (*seq);
212 : 154 : return gimple_build_vector_from_val (&gsi, false, GSI_CONTINUE_LINKING,
213 : 154 : loc, type, op);
214 : : }
215 : : inline tree
216 : 306784 : gimple_build_vector_from_val (gimple_seq *seq, tree type, tree op)
217 : : {
218 : 306784 : gimple_stmt_iterator gsi = gsi_last (*seq);
219 : 306784 : return gimple_build_vector_from_val (&gsi, false, GSI_CONTINUE_LINKING,
220 : 306784 : UNKNOWN_LOCATION, type, op);
221 : : }
222 : :
223 : : class tree_vector_builder;
224 : : extern tree gimple_build_vector (gimple_stmt_iterator *, bool,
225 : : enum gsi_iterator_update,
226 : : location_t, tree_vector_builder *);
227 : : inline tree
228 : : gimple_build_vector (gimple_seq *seq, location_t loc,
229 : : tree_vector_builder *builder)
230 : : {
231 : : gimple_stmt_iterator gsi = gsi_last (*seq);
232 : : return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
233 : : loc, builder);
234 : : }
235 : : inline tree
236 : 364274 : gimple_build_vector (gimple_seq *seq, tree_vector_builder *builder)
237 : : {
238 : 364274 : gimple_stmt_iterator gsi = gsi_last (*seq);
239 : 364274 : return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
240 : 364274 : UNKNOWN_LOCATION, builder);
241 : : }
242 : :
243 : : extern tree gimple_build_round_up (gimple_stmt_iterator *, bool,
244 : : enum gsi_iterator_update,
245 : : location_t, tree, tree,
246 : : unsigned HOST_WIDE_INT);
247 : : inline tree
248 : 0 : gimple_build_round_up (gimple_seq *seq, location_t loc,
249 : : tree type, tree old_size, unsigned HOST_WIDE_INT align)
250 : : {
251 : 0 : gimple_stmt_iterator gsi = gsi_last (*seq);
252 : 0 : return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
253 : 0 : loc, type, old_size, align);
254 : : }
255 : : inline tree
256 : : gimple_build_round_up (gimple_seq *seq, tree type, tree old_size,
257 : : unsigned HOST_WIDE_INT align)
258 : : {
259 : : gimple_stmt_iterator gsi = gsi_last (*seq);
260 : : return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
261 : : UNKNOWN_LOCATION, type, old_size, align);
262 : : }
263 : :
264 : : extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
265 : : extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
266 : : extern void mark_lhs_in_seq_for_dce (bitmap, gimple_seq);
267 : :
268 : : /* In gimple-match.cc. */
269 : : extern tree gimple_simplify (enum tree_code, tree, tree,
270 : : gimple_seq *, tree (*)(tree));
271 : : extern tree gimple_simplify (enum tree_code, tree, tree, tree,
272 : : gimple_seq *, tree (*)(tree));
273 : : extern tree gimple_simplify (enum tree_code, tree, tree, tree, tree,
274 : : gimple_seq *, tree (*)(tree));
275 : : extern tree gimple_simplify (combined_fn, tree, tree,
276 : : gimple_seq *, tree (*)(tree));
277 : : extern tree gimple_simplify (combined_fn, tree, tree, tree,
278 : : gimple_seq *, tree (*)(tree));
279 : : extern tree gimple_simplify (combined_fn, tree, tree, tree, tree,
280 : : gimple_seq *, tree (*)(tree));
281 : :
282 : : #endif /* GCC_GIMPLE_FOLD_H */
|