1 /* Gimple folding definitions.
3 Copyright (C) 2011-2022 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
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
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
);
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
);
67 /* gimple_build, functionally matching fold_buildN, outputs stmts
68 int the provided sequence, matching and simplifying them on-the-fly.
69 Supposed to replace force_gimple_operand (fold_buildN (...), ...). */
70 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
71 enum gsi_iterator_update
,
72 location_t
, enum tree_code
, tree
, tree
);
73 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
74 enum gsi_iterator_update
,
75 location_t
, enum tree_code
, tree
, tree
, tree
);
76 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
77 enum gsi_iterator_update
,
78 location_t
, enum tree_code
, tree
, tree
, tree
, tree
);
79 template<class ...Args
>
81 gimple_build (gimple_seq
*seq
, location_t loc
,
82 enum tree_code code
, tree type
, Args
...ops
)
84 static_assert (sizeof...(ops
) > 0 && sizeof...(ops
) <= 3,
85 "Number of operands must be from one to three");
86 gimple_stmt_iterator gsi
= gsi_last (*seq
);
87 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
88 loc
, code
, type
, ops
...);
90 template<class ...Args
>
92 gimple_build (gimple_seq
*seq
, enum tree_code code
, tree type
, Args
...ops
)
94 static_assert (sizeof...(ops
) > 0 && sizeof...(ops
) <= 3,
95 "Number of operands must be from one to three");
96 gimple_stmt_iterator gsi
= gsi_last (*seq
);
97 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
98 UNKNOWN_LOCATION
, code
, type
, ops
...);
101 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
102 enum gsi_iterator_update
,
103 location_t
, combined_fn
, tree
);
104 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
105 enum gsi_iterator_update
,
106 location_t
, combined_fn
, tree
, tree
);
107 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
108 enum gsi_iterator_update
,
109 location_t
, combined_fn
, tree
, tree
, tree
);
110 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
111 enum gsi_iterator_update
,
112 location_t
, combined_fn
, tree
, tree
, tree
, tree
);
113 template<class ...Args
>
115 gimple_build (gimple_seq
*seq
, location_t loc
,
116 combined_fn fn
, tree type
, Args
...args
)
118 static_assert (sizeof...(args
) < 4,
119 "Number of arguments must be less than four");
120 gimple_stmt_iterator gsi
= gsi_last (*seq
);
121 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
122 loc
, fn
, type
, args
...);
124 template<class ...Args
>
126 gimple_build (gimple_seq
*seq
, combined_fn fn
, tree type
, Args
...args
)
128 static_assert (sizeof...(args
) < 4,
129 "Number of arguments must be less than four");
130 gimple_stmt_iterator gsi
= gsi_last (*seq
);
131 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
132 UNKNOWN_LOCATION
, fn
, type
, args
...);
135 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
136 enum gsi_iterator_update
,
137 location_t
, code_helper
, tree
, tree
);
138 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
139 enum gsi_iterator_update
,
140 location_t
, code_helper
, tree
, tree
, tree
);
141 extern tree
gimple_build (gimple_stmt_iterator
*, bool,
142 enum gsi_iterator_update
,
143 location_t
, code_helper
, tree
, tree
, tree
, tree
);
145 template<class ...Args
>
147 gimple_build (gimple_seq
*seq
, location_t loc
,
148 code_helper code
, tree type
, Args
...ops
)
150 static_assert (sizeof...(ops
) < 4,
151 "Number of operands must be less than four");
152 gimple_stmt_iterator gsi
= gsi_last (*seq
);
153 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
154 loc
, code
, type
, ops
...);
156 template<class ...Args
>
158 gimple_build (gimple_seq
*seq
,
159 code_helper code
, tree type
, Args
...ops
)
161 static_assert (sizeof...(ops
) < 4,
162 "Number of operands must be less than four");
163 gimple_stmt_iterator gsi
= gsi_last (*seq
);
164 return gimple_build (&gsi
, false, GSI_CONTINUE_LINKING
,
165 UNKNOWN_LOCATION
, code
, type
, ops
...);
168 extern tree
gimple_convert (gimple_stmt_iterator
*, bool,
169 enum gsi_iterator_update
,
170 location_t
, tree
, tree
);
172 gimple_convert (gimple_seq
*seq
, location_t loc
, tree type
, tree op
)
174 gimple_stmt_iterator gsi
= gsi_last (*seq
);
175 return gimple_convert (&gsi
, false, GSI_CONTINUE_LINKING
, loc
, type
, op
);
178 gimple_convert (gimple_seq
*seq
, tree type
, tree op
)
180 gimple_stmt_iterator gsi
= gsi_last (*seq
);
181 return gimple_convert (&gsi
, false, GSI_CONTINUE_LINKING
,
182 UNKNOWN_LOCATION
, type
, op
);
185 extern tree
gimple_convert_to_ptrofftype (gimple_stmt_iterator
*, bool,
186 enum gsi_iterator_update
,
189 gimple_convert_to_ptrofftype (gimple_seq
*seq
, location_t loc
, tree op
)
191 gimple_stmt_iterator gsi
= gsi_last (*seq
);
192 return gimple_convert_to_ptrofftype (&gsi
, false, GSI_CONTINUE_LINKING
,
196 gimple_convert_to_ptrofftype (gimple_seq
*seq
, tree op
)
198 gimple_stmt_iterator gsi
= gsi_last (*seq
);
199 return gimple_convert_to_ptrofftype (&gsi
, false, GSI_CONTINUE_LINKING
,
200 UNKNOWN_LOCATION
, op
);
203 extern tree
gimple_build_vector_from_val (gimple_stmt_iterator
*, bool,
204 enum gsi_iterator_update
,
205 location_t
, tree
, tree
);
207 gimple_build_vector_from_val (gimple_seq
*seq
, location_t loc
,
210 gimple_stmt_iterator gsi
= gsi_last (*seq
);
211 return gimple_build_vector_from_val (&gsi
, false, GSI_CONTINUE_LINKING
,
215 gimple_build_vector_from_val (gimple_seq
*seq
, tree type
, tree op
)
217 gimple_stmt_iterator gsi
= gsi_last (*seq
);
218 return gimple_build_vector_from_val (&gsi
, false, GSI_CONTINUE_LINKING
,
219 UNKNOWN_LOCATION
, type
, op
);
222 class tree_vector_builder
;
223 extern tree
gimple_build_vector (gimple_stmt_iterator
*, bool,
224 enum gsi_iterator_update
,
225 location_t
, tree_vector_builder
*);
227 gimple_build_vector (gimple_seq
*seq
, location_t loc
,
228 tree_vector_builder
*builder
)
230 gimple_stmt_iterator gsi
= gsi_last (*seq
);
231 return gimple_build_vector (&gsi
, false, GSI_CONTINUE_LINKING
,
235 gimple_build_vector (gimple_seq
*seq
, tree_vector_builder
*builder
)
237 gimple_stmt_iterator gsi
= gsi_last (*seq
);
238 return gimple_build_vector (&gsi
, false, GSI_CONTINUE_LINKING
,
239 UNKNOWN_LOCATION
, builder
);
242 extern tree
gimple_build_round_up (gimple_stmt_iterator
*, bool,
243 enum gsi_iterator_update
,
244 location_t
, tree
, tree
,
245 unsigned HOST_WIDE_INT
);
247 gimple_build_round_up (gimple_seq
*seq
, location_t loc
,
248 tree type
, tree old_size
, unsigned HOST_WIDE_INT align
)
250 gimple_stmt_iterator gsi
= gsi_last (*seq
);
251 return gimple_build_round_up (&gsi
, false, GSI_CONTINUE_LINKING
,
252 loc
, type
, old_size
, align
);
255 gimple_build_round_up (gimple_seq
*seq
, tree type
, tree old_size
,
256 unsigned HOST_WIDE_INT align
)
258 gimple_stmt_iterator gsi
= gsi_last (*seq
);
259 return gimple_build_round_up (&gsi
, false, GSI_CONTINUE_LINKING
,
260 UNKNOWN_LOCATION
, type
, old_size
, align
);
263 extern bool gimple_stmt_nonnegative_warnv_p (gimple
*, bool *, int = 0);
264 extern bool gimple_stmt_integer_valued_real_p (gimple
*, int = 0);
266 /* In gimple-match.cc. */
267 extern tree
gimple_simplify (enum tree_code
, tree
, tree
,
268 gimple_seq
*, tree (*)(tree
));
269 extern tree
gimple_simplify (enum tree_code
, tree
, tree
, tree
,
270 gimple_seq
*, tree (*)(tree
));
271 extern tree
gimple_simplify (enum tree_code
, tree
, tree
, tree
, tree
,
272 gimple_seq
*, tree (*)(tree
));
273 extern tree
gimple_simplify (combined_fn
, tree
, tree
,
274 gimple_seq
*, tree (*)(tree
));
275 extern tree
gimple_simplify (combined_fn
, tree
, tree
, tree
,
276 gimple_seq
*, tree (*)(tree
));
277 extern tree
gimple_simplify (combined_fn
, tree
, tree
, tree
, tree
,
278 gimple_seq
*, tree (*)(tree
));
280 #endif /* GCC_GIMPLE_FOLD_H */