GCC Middle and Back End API Reference
gimple-fold.h
Go to the documentation of this file.
1/* Gimple folding definitions.
2
3 Copyright (C) 2011-2025 Free Software Foundation, Inc.
4 Contributed by Richard Guenther <rguenther@suse.de>
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16for more details.
17
18You should have received a copy of the GNU General Public License
19along 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#include "tree-pass.h"
26
29struct c_strlen_data;
30extern bool get_range_strlen (tree, c_strlen_data *, unsigned eltsize);
32extern bool update_gimple_call (gimple_stmt_iterator *, tree, int, ...);
36extern bool fold_stmt (gimple_stmt_iterator *, bitmap = nullptr);
37extern bool fold_stmt (gimple_stmt_iterator *, tree (*) (tree), bitmap = nullptr);
40 enum tree_code, tree, tree,
41 basic_block = nullptr);
43 enum tree_code, tree, tree,
44 basic_block = nullptr);
51 const poly_uint64&, tree,
52 unsigned HOST_WIDE_INT * = NULL);
55extern tree gimple_get_virt_method_for_binfo (HOST_WIDE_INT, tree,
56 bool *can_refer = NULL);
57extern tree gimple_get_virt_method_for_vtable (HOST_WIDE_INT, tree,
58 unsigned HOST_WIDE_INT,
59 bool *can_refer = NULL);
70
71/* gimple_build, functionally matching fold_buildN, outputs stmts
72 int the provided sequence, matching and simplifying them on-the-fly.
73 Supposed to replace force_gimple_operand (fold_buildN (...), ...). */
76 location_t, enum tree_code, tree, tree);
79 location_t, enum tree_code, tree, tree, tree);
82 location_t, enum tree_code, tree, tree, tree, tree);
83template<class ...Args>
84inline tree
85gimple_build (gimple_seq *seq, location_t loc,
86 enum tree_code code, tree type, Args ...ops)
87{
88 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
89 "Number of operands must be from one to three");
90 gimple_stmt_iterator gsi = gsi_last (*seq);
91 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
92 loc, code, type, ops...);
93}
94template<class ...Args>
95inline tree
96gimple_build (gimple_seq *seq, enum tree_code code, tree type, Args ...ops)
97{
98 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
99 "Number of operands must be from one to three");
100 gimple_stmt_iterator gsi = gsi_last (*seq);
101 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
102 UNKNOWN_LOCATION, code, type, ops...);
103}
104
107 location_t, combined_fn, tree);
110 location_t, combined_fn, tree, tree);
113 location_t, combined_fn, tree, tree, tree);
116 location_t, combined_fn, tree, tree, tree, tree);
117template<class ...Args>
118inline tree
119gimple_build (gimple_seq *seq, location_t loc,
120 combined_fn fn, tree type, Args ...args)
121{
122 static_assert (sizeof...(args) < 4,
123 "Number of arguments must be less than four");
124 gimple_stmt_iterator gsi = gsi_last (*seq);
125 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
126 loc, fn, type, args...);
127}
128template<class ...Args>
129inline tree
130gimple_build (gimple_seq *seq, combined_fn fn, tree type, Args ...args)
131{
132 static_assert (sizeof...(args) < 4,
133 "Number of arguments must be less than four");
134 gimple_stmt_iterator gsi = gsi_last (*seq);
135 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
136 UNKNOWN_LOCATION, fn, type, args...);
137}
138
141 location_t, code_helper, tree, tree);
144 location_t, code_helper, tree, tree, tree);
147 location_t, code_helper, tree, tree, tree, tree);
148
149template<class ...Args>
150inline tree
151gimple_build (gimple_seq *seq, location_t loc,
152 code_helper code, tree type, Args ...ops)
153{
154 static_assert (sizeof...(ops) < 4,
155 "Number of operands must be less than four");
156 gimple_stmt_iterator gsi = gsi_last (*seq);
157 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
158 loc, code, type, ops...);
159}
160template<class ...Args>
161inline tree
163 code_helper code, tree type, Args ...ops)
164{
165 static_assert (sizeof...(ops) < 4,
166 "Number of operands must be less than four");
167 gimple_stmt_iterator gsi = gsi_last (*seq);
168 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
169 UNKNOWN_LOCATION, code, type, ops...);
170}
171
174 location_t, tree, tree);
175inline tree
176gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
177{
178 gimple_stmt_iterator gsi = gsi_last (*seq);
179 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING, loc, type, op);
180}
181inline tree
183{
184 gimple_stmt_iterator gsi = gsi_last (*seq);
185 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING,
187}
188
191 location_t, tree);
192inline tree
194{
195 gimple_stmt_iterator gsi = gsi_last (*seq);
197 loc, op);
198}
199inline tree
206
209 location_t, tree, tree);
210inline tree
212 tree type, tree op)
213{
214 gimple_stmt_iterator gsi = gsi_last (*seq);
216 loc, type, op);
217}
218inline tree
225
229 location_t, tree_vector_builder *);
230inline tree
231gimple_build_vector (gimple_seq *seq, location_t loc,
232 tree_vector_builder *builder)
233{
234 gimple_stmt_iterator gsi = gsi_last (*seq);
235 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
236 loc, builder);
237}
238inline tree
240{
241 gimple_stmt_iterator gsi = gsi_last (*seq);
242 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
243 UNKNOWN_LOCATION, builder);
244}
245
248 location_t, tree, tree,
249 unsigned HOST_WIDE_INT);
250inline tree
251gimple_build_round_up (gimple_seq *seq, location_t loc,
252 tree type, tree old_size, unsigned HOST_WIDE_INT align)
253{
254 gimple_stmt_iterator gsi = gsi_last (*seq);
255 return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
256 loc, type, old_size, align);
257}
258inline tree
260 unsigned HOST_WIDE_INT align)
261{
262 gimple_stmt_iterator gsi = gsi_last (*seq);
263 return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
264 UNKNOWN_LOCATION, type, old_size, align);
265}
266
267extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0);
268extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
270
271/* In gimple-match.cc. */
272extern tree gimple_simplify (enum tree_code, tree, tree,
273 gimple_seq *, tree (*)(tree));
275 gimple_seq *, tree (*)(tree));
277 gimple_seq *, tree (*)(tree));
279 gimple_seq *, tree (*)(tree));
281 gimple_seq *, tree (*)(tree));
283 gimple_seq *, tree (*)(tree));
284
285/* Returns true if we are doing the fold before expansion to rtl. */
286inline bool
288{
289 if (!cfun)
290 return false;
291 return (cfun->curr_properties & PROP_last_full_fold) != 0;
292}
293
294#endif /* GCC_GIMPLE_FOLD_H */
Definition tree.h:82
Definition tree-vector-builder.h:29
struct basic_block_def * basic_block
Definition coretypes.h:357
gimple * gimple_seq
Definition coretypes.h:100
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
#define cfun
Definition function.h:480
combined_fn
Definition genmatch.cc:1020
tree_code
Definition genmatch.cc:1002
tree no_follow_ssa_edges(tree)
Definition gimple-fold.cc:6895
tree get_symbol_constant_value(tree)
Definition gimple-fold.cc:273
void gsi_replace_with_seq_vops(gimple_stmt_iterator *, gimple_seq)
Definition gimple-fold.cc:583
tree gimple_convert_to_ptrofftype(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, tree)
void mark_lhs_in_seq_for_dce(bitmap, gimple_seq)
Definition gimple-fold.cc:6231
bool gimple_needing_rewrite_undefined(gimple *)
Definition gimple-fold.cc:10693
bool update_gimple_call(gimple_stmt_iterator *, tree, int,...)
Definition gimple-fold.cc:673
bool arith_code_with_undefined_signed_overflow(tree_code)
Definition gimple-fold.cc:10670
tree gimple_convert(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, tree, tree)
bool gimple_fold_builtin_snprintf(gimple_stmt_iterator *)
Definition gimple-fold.cc:3630
tree maybe_fold_and_comparisons(tree, enum tree_code, tree, tree, enum tree_code, tree, tree, basic_block=nullptr)
Definition gimple-fold.cc:9035
tree gimple_simplify(enum tree_code, tree, tree, gimple_seq *, tree(*)(tree))
Definition gimple-match-exports.cc:578
tree fold_ctor_reference(tree, tree, const poly_uint64 &, const poly_uint64 &, tree, unsigned HOST_WIDE_INT *=NULL)
Definition gimple-fold.cc:10134
tree gimple_fold_stmt_to_constant(gimple *, tree(*)(tree))
Definition gimple-fold.cc:9720
tree follow_single_use_edges(tree)
Definition gimple-fold.cc:6903
tree gimple_build_vector(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, tree_vector_builder *)
bool gimple_fold_builtin_sprintf(gimple_stmt_iterator *)
Definition gimple-fold.cc:3500
bool gimple_stmt_nonnegative_warnv_p(gimple *, bool *, int=0)
Definition gimple-fold.cc:11401
tree maybe_fold_or_comparisons(tree, enum tree_code, tree, tree, enum tree_code, tree, tree, basic_block=nullptr)
Definition gimple-fold.cc:9387
tree gimple_get_virt_method_for_vtable(HOST_WIDE_INT, tree, unsigned HOST_WIDE_INT, bool *can_refer=NULL)
Definition gimple-fold.cc:10413
void gimplify_and_update_call_from_tree(gimple_stmt_iterator *, tree)
Definition gimple-fold.cc:726
tree gimple_build_vector_from_val(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, tree, tree)
bool fold_before_rtl_expansion_p()
Definition gimple-fold.h:287
tree gimple_build_round_up(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, tree, tree, unsigned HOST_WIDE_INT)
tree gimple_fold_stmt_to_constant_1(gimple *, tree(*)(tree), tree(*)(tree)=no_follow_ssa_edges)
Definition gimple-fold.cc:9418
tree tree_vec_extract(gimple_stmt_iterator *, tree, tree, tree, tree)
Definition tree-vect-generic.cc:136
bool gimple_stmt_integer_valued_real_p(gimple *, int=0)
Definition gimple-fold.cc:11502
tree gimple_build(gimple_stmt_iterator *, bool, enum gsi_iterator_update, location_t, enum tree_code, tree, tree)
bool get_range_strlen(tree, c_strlen_data *, unsigned eltsize)
Definition gimple-fold.cc:1976
tree fold_const_aggregate_ref_1(tree, tree(*)(tree))
Definition gimple-fold.cc:10234
void rewrite_to_defined_unconditional(gimple_stmt_iterator *)
Definition gimple-fold.cc:10864
bool fold_stmt_inplace(gimple_stmt_iterator *, tree(*)(tree)=no_follow_ssa_edges)
Definition gimple-fold.cc:6947
bool fold_stmt(gimple_stmt_iterator *, bitmap=nullptr)
Definition gimple-fold.cc:6927
tree canonicalize_constructor_val(tree, tree)
Definition gimple-fold.cc:200
tree follow_all_ssa_edges(tree)
Definition gimple-fold.cc:6914
tree gimple_get_virt_method_for_binfo(HOST_WIDE_INT, tree, bool *can_refer=NULL)
Definition gimple-fold.cc:10524
void replace_call_with_value(gimple_stmt_iterator *, tree)
Definition gimple-fold.cc:806
bool optimize_atomic_compare_exchange_p(gimple *)
Definition gimple-fold.cc:5608
tree no_follow_ssa_edges(tree)
Definition gimple-fold.cc:6895
void fold_builtin_atomic_compare_exchange(gimple_stmt_iterator *)
Definition gimple-fold.cc:5678
tree fold_const_aggregate_ref(tree)
Definition gimple-fold.cc:10401
tree gimple_fold_indirect_ref(tree)
Definition gimple-fold.cc:10551
gimple_stmt_iterator gsi_last(gimple_seq &seq)
Definition gimple-iterator.h:148
gsi_iterator_update
Definition gimple-iterator.h:52
@ GSI_CONTINUE_LINKING
Definition gimple-iterator.h:56
#define UNKNOWN_LOCATION
Definition input.h:32
poly_int< NUM_POLY_INT_COEFFS, unsigned HOST_WIDE_INT > poly_uint64
Definition poly-int-types.h:25
Definition builtins.h:71
Definition gimple-iterator.h:26
Definition gimple.h:221
Definition gengtype.h:252
#define NULL
Definition system.h:50
#define PROP_last_full_fold
Definition tree-pass.h:228