c++: only cache constexpr calls that are constant exprs
[official-gcc.git] / gcc / gimple-fold.h
blob2fd58db9a2e990038234e62880b4f74f0eabe792
1 /* Gimple folding definitions.
3 Copyright (C) 2011-2023 Free Software Foundation, Inc.
4 Contributed by Richard Guenther <rguenther@suse.de>
6 This file is part of GCC.
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.
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.
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/>. */
22 #ifndef GCC_GIMPLE_FOLD_H
23 #define GCC_GIMPLE_FOLD_H
25 extern tree create_tmp_reg_or_ssa_name (tree, gimple *stmt = NULL);
26 extern tree canonicalize_constructor_val (tree, tree);
27 extern tree get_symbol_constant_value (tree);
28 struct c_strlen_data;
29 extern bool get_range_strlen (tree, c_strlen_data *, unsigned eltsize);
30 extern void gimplify_and_update_call_from_tree (gimple_stmt_iterator *, tree);
31 extern bool update_gimple_call (gimple_stmt_iterator *, tree, int, ...);
32 extern bool fold_stmt (gimple_stmt_iterator *);
33 extern bool fold_stmt (gimple_stmt_iterator *, tree (*) (tree));
34 extern bool fold_stmt_inplace (gimple_stmt_iterator *);
35 extern tree maybe_fold_and_comparisons (tree, enum tree_code, tree, tree,
36 enum tree_code, tree, tree,
37 basic_block = nullptr);
38 extern tree maybe_fold_or_comparisons (tree, enum tree_code, tree, tree,
39 enum tree_code, tree, tree,
40 basic_block = nullptr);
41 extern bool optimize_atomic_compare_exchange_p (gimple *);
42 extern void fold_builtin_atomic_compare_exchange (gimple_stmt_iterator *);
43 extern tree no_follow_ssa_edges (tree);
44 extern tree follow_single_use_edges (tree);
45 extern tree follow_all_ssa_edges (tree);
46 extern tree gimple_fold_stmt_to_constant_1 (gimple *, tree (*) (tree),
47 tree (*) (tree) = no_follow_ssa_edges);
48 extern tree gimple_fold_stmt_to_constant (gimple *, tree (*) (tree));
49 extern tree fold_ctor_reference (tree, tree, const poly_uint64&,
50 const poly_uint64&, tree,
51 unsigned HOST_WIDE_INT * = NULL);
52 extern tree fold_const_aggregate_ref_1 (tree, tree (*) (tree));
53 extern tree fold_const_aggregate_ref (tree);
54 extern tree gimple_get_virt_method_for_binfo (HOST_WIDE_INT, tree,
55 bool *can_refer = NULL);
56 extern tree gimple_get_virt_method_for_vtable (HOST_WIDE_INT, tree,
57 unsigned HOST_WIDE_INT,
58 bool *can_refer = NULL);
59 extern tree gimple_fold_indirect_ref (tree);
60 extern bool gimple_fold_builtin_sprintf (gimple_stmt_iterator *);
61 extern bool gimple_fold_builtin_snprintf (gimple_stmt_iterator *);
62 extern bool arith_code_with_undefined_signed_overflow (tree_code);
63 extern gimple_seq rewrite_to_defined_overflow (gimple *, bool = false);
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);
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 gimple_build (gimple_seq *seq, location_t loc,
83 enum tree_code code, tree type, Args ...ops)
85 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
86 "Number of operands must be from one to three");
87 gimple_stmt_iterator gsi = gsi_last (*seq);
88 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
89 loc, code, type, ops...);
91 template<class ...Args>
92 inline tree
93 gimple_build (gimple_seq *seq, enum tree_code code, tree type, Args ...ops)
95 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
96 "Number of operands must be from one to three");
97 gimple_stmt_iterator gsi = gsi_last (*seq);
98 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
99 UNKNOWN_LOCATION, code, type, ops...);
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 gimple_build (gimple_seq *seq, location_t loc,
117 combined_fn fn, tree type, Args ...args)
119 static_assert (sizeof...(args) < 4,
120 "Number of arguments must be less than four");
121 gimple_stmt_iterator gsi = gsi_last (*seq);
122 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
123 loc, fn, type, args...);
125 template<class ...Args>
126 inline tree
127 gimple_build (gimple_seq *seq, combined_fn fn, tree type, Args ...args)
129 static_assert (sizeof...(args) < 4,
130 "Number of arguments must be less than four");
131 gimple_stmt_iterator gsi = gsi_last (*seq);
132 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
133 UNKNOWN_LOCATION, fn, type, args...);
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);
146 template<class ...Args>
147 inline tree
148 gimple_build (gimple_seq *seq, location_t loc,
149 code_helper code, tree type, Args ...ops)
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...);
157 template<class ...Args>
158 inline tree
159 gimple_build (gimple_seq *seq,
160 code_helper code, tree type, Args ...ops)
162 static_assert (sizeof...(ops) < 4,
163 "Number of operands must be less than four");
164 gimple_stmt_iterator gsi = gsi_last (*seq);
165 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
166 UNKNOWN_LOCATION, code, type, ops...);
169 extern tree gimple_convert (gimple_stmt_iterator *, bool,
170 enum gsi_iterator_update,
171 location_t, tree, tree);
172 inline tree
173 gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
175 gimple_stmt_iterator gsi = gsi_last (*seq);
176 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING, loc, type, op);
178 inline tree
179 gimple_convert (gimple_seq *seq, tree type, tree op)
181 gimple_stmt_iterator gsi = gsi_last (*seq);
182 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING,
183 UNKNOWN_LOCATION, type, op);
186 extern tree gimple_convert_to_ptrofftype (gimple_stmt_iterator *, bool,
187 enum gsi_iterator_update,
188 location_t, tree);
189 inline tree
190 gimple_convert_to_ptrofftype (gimple_seq *seq, location_t loc, tree op)
192 gimple_stmt_iterator gsi = gsi_last (*seq);
193 return gimple_convert_to_ptrofftype (&gsi, false, GSI_CONTINUE_LINKING,
194 loc, op);
196 inline tree
197 gimple_convert_to_ptrofftype (gimple_seq *seq, tree op)
199 gimple_stmt_iterator gsi = gsi_last (*seq);
200 return gimple_convert_to_ptrofftype (&gsi, false, GSI_CONTINUE_LINKING,
201 UNKNOWN_LOCATION, op);
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 gimple_build_vector_from_val (gimple_seq *seq, location_t loc,
209 tree type, tree op)
211 gimple_stmt_iterator gsi = gsi_last (*seq);
212 return gimple_build_vector_from_val (&gsi, false, GSI_CONTINUE_LINKING,
213 loc, type, op);
215 inline tree
216 gimple_build_vector_from_val (gimple_seq *seq, tree type, tree op)
218 gimple_stmt_iterator gsi = gsi_last (*seq);
219 return gimple_build_vector_from_val (&gsi, false, GSI_CONTINUE_LINKING,
220 UNKNOWN_LOCATION, type, op);
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)
231 gimple_stmt_iterator gsi = gsi_last (*seq);
232 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
233 loc, builder);
235 inline tree
236 gimple_build_vector (gimple_seq *seq, tree_vector_builder *builder)
238 gimple_stmt_iterator gsi = gsi_last (*seq);
239 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
240 UNKNOWN_LOCATION, builder);
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 gimple_build_round_up (gimple_seq *seq, location_t loc,
249 tree type, tree old_size, unsigned HOST_WIDE_INT align)
251 gimple_stmt_iterator gsi = gsi_last (*seq);
252 return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
253 loc, type, old_size, align);
255 inline tree
256 gimple_build_round_up (gimple_seq *seq, tree type, tree old_size,
257 unsigned HOST_WIDE_INT align)
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);
264 extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
265 extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
267 /* In gimple-match.cc. */
268 extern tree gimple_simplify (enum tree_code, tree, tree,
269 gimple_seq *, tree (*)(tree));
270 extern tree gimple_simplify (enum tree_code, tree, tree, tree,
271 gimple_seq *, tree (*)(tree));
272 extern tree gimple_simplify (enum tree_code, tree, tree, tree, tree,
273 gimple_seq *, tree (*)(tree));
274 extern tree gimple_simplify (combined_fn, tree, tree,
275 gimple_seq *, tree (*)(tree));
276 extern tree gimple_simplify (combined_fn, tree, tree, tree,
277 gimple_seq *, tree (*)(tree));
278 extern tree gimple_simplify (combined_fn, tree, tree, tree, tree,
279 gimple_seq *, tree (*)(tree));
281 #endif /* GCC_GIMPLE_FOLD_H */