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-2026 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 enum tree_code, tree, tree,
42 basic_block = nullptr);
44 enum tree_code, tree, tree,
45 enum tree_code, tree, tree,
46 basic_block = nullptr);
53 const poly_uint64&, tree,
54 unsigned HOST_WIDE_INT * = NULL);
57extern tree gimple_get_virt_method_for_binfo (HOST_WIDE_INT, tree,
58 bool *can_refer = NULL);
59extern tree gimple_get_virt_method_for_vtable (HOST_WIDE_INT, tree,
60 unsigned HOST_WIDE_INT,
61 bool *can_refer = NULL);
66extern bool gimple_needing_rewrite_undefined (gimple *, bool = false);
72
73/* gimple_build, functionally matching fold_buildN, outputs stmts
74 int the provided sequence, matching and simplifying them on-the-fly.
75 Supposed to replace force_gimple_operand (fold_buildN (...), ...). */
78 location_t, enum tree_code, tree, tree);
81 location_t, enum tree_code, tree, tree, tree);
84 location_t, enum tree_code, tree, tree, tree, tree);
85template<class ...Args>
86inline tree
87gimple_build (gimple_seq *seq, location_t loc,
88 enum tree_code code, tree type, Args ...ops)
89{
90 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
91 "Number of operands must be from one to three");
92 gimple_stmt_iterator gsi = gsi_last (*seq);
93 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
94 loc, code, type, ops...);
95}
96template<class ...Args>
97inline tree
98gimple_build (gimple_seq *seq, enum tree_code code, tree type, Args ...ops)
99{
100 static_assert (sizeof...(ops) > 0 && sizeof...(ops) <= 3,
101 "Number of operands must be from one to three");
102 gimple_stmt_iterator gsi = gsi_last (*seq);
103 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
104 UNKNOWN_LOCATION, code, type, ops...);
105}
106
109 location_t, combined_fn, tree);
112 location_t, combined_fn, tree, tree);
115 location_t, combined_fn, tree, tree, tree);
118 location_t, combined_fn, tree, tree, tree, tree);
119template<class ...Args>
120inline tree
121gimple_build (gimple_seq *seq, location_t loc,
122 combined_fn fn, tree type, Args ...args)
123{
124 static_assert (sizeof...(args) < 4,
125 "Number of arguments must be less than four");
126 gimple_stmt_iterator gsi = gsi_last (*seq);
127 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
128 loc, fn, type, args...);
129}
130template<class ...Args>
131inline tree
132gimple_build (gimple_seq *seq, combined_fn fn, tree type, Args ...args)
133{
134 static_assert (sizeof...(args) < 4,
135 "Number of arguments must be less than four");
136 gimple_stmt_iterator gsi = gsi_last (*seq);
137 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
138 UNKNOWN_LOCATION, fn, type, args...);
139}
140
143 location_t, code_helper, tree, tree);
146 location_t, code_helper, tree, tree, tree);
149 location_t, code_helper, tree, tree, tree, tree);
150
151template<class ...Args>
152inline tree
153gimple_build (gimple_seq *seq, location_t loc,
154 code_helper code, tree type, Args ...ops)
155{
156 static_assert (sizeof...(ops) < 4,
157 "Number of operands must be less than four");
158 gimple_stmt_iterator gsi = gsi_last (*seq);
159 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
160 loc, code, type, ops...);
161}
162template<class ...Args>
163inline tree
165 code_helper code, tree type, Args ...ops)
166{
167 static_assert (sizeof...(ops) < 4,
168 "Number of operands must be less than four");
169 gimple_stmt_iterator gsi = gsi_last (*seq);
170 return gimple_build (&gsi, false, GSI_CONTINUE_LINKING,
171 UNKNOWN_LOCATION, code, type, ops...);
172}
173
176 location_t, tree, tree);
177inline tree
178gimple_convert (gimple_seq *seq, location_t loc, tree type, tree op)
179{
180 gimple_stmt_iterator gsi = gsi_last (*seq);
181 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING, loc, type, op);
182}
183inline tree
185{
186 gimple_stmt_iterator gsi = gsi_last (*seq);
187 return gimple_convert (&gsi, false, GSI_CONTINUE_LINKING,
189}
190
193 location_t, tree);
194inline tree
196{
197 gimple_stmt_iterator gsi = gsi_last (*seq);
199 loc, op);
200}
201inline tree
208
211 location_t, tree, tree);
212inline tree
214 tree type, tree op)
215{
216 gimple_stmt_iterator gsi = gsi_last (*seq);
218 loc, type, op);
219}
220inline tree
227
231 location_t, tree_vector_builder *);
232inline tree
233gimple_build_vector (gimple_seq *seq, location_t loc,
234 tree_vector_builder *builder)
235{
236 gimple_stmt_iterator gsi = gsi_last (*seq);
237 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
238 loc, builder);
239}
240inline tree
242{
243 gimple_stmt_iterator gsi = gsi_last (*seq);
244 return gimple_build_vector (&gsi, false, GSI_CONTINUE_LINKING,
245 UNKNOWN_LOCATION, builder);
246}
247
250 location_t, tree, tree,
251 unsigned HOST_WIDE_INT);
252inline tree
253gimple_build_round_up (gimple_seq *seq, location_t loc,
254 tree type, tree old_size, unsigned HOST_WIDE_INT align)
255{
256 gimple_stmt_iterator gsi = gsi_last (*seq);
257 return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
258 loc, type, old_size, align);
259}
260inline tree
262 unsigned HOST_WIDE_INT align)
263{
264 gimple_stmt_iterator gsi = gsi_last (*seq);
265 return gimple_build_round_up (&gsi, false, GSI_CONTINUE_LINKING,
266 UNKNOWN_LOCATION, type, old_size, align);
267}
268
269extern bool gimple_stmt_nonnegative_p (gimple *, int = 0);
270extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0);
272
273/* In gimple-match-exports.cc. */
274extern tree gimple_simplify (enum tree_code, 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));
285 gimple_seq *, tree (*)(tree));
286
287/* Returns true if we are doing the fold before expansion to rtl. */
288inline bool
290{
291 if (!cfun)
292 return false;
293 return (cfun->curr_properties & PROP_last_full_fold) != 0;
294}
295
296#endif /* GCC_GIMPLE_FOLD_H */
Definition tree.h:82
Definition tree-vector-builder.h:29
struct basic_block_def * basic_block
Definition coretypes.h:359
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:485
combined_fn
Definition genmatch.cc:1029
tree_code
Definition genmatch.cc:1011
tree gimple_convert(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, tree type, tree op)
Definition gimple-fold.cc:11587
tree maybe_fold_and_comparisons(tree type, enum tree_code code, enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b, basic_block outer_cond_bb)
Definition gimple-fold.cc:9368
tree follow_all_ssa_edges(tree val)
Definition gimple-fold.cc:7186
bool gimple_fold_builtin_snprintf(gimple_stmt_iterator *gsi)
Definition gimple-fold.cc:3773
bool gimple_needing_rewrite_undefined(gimple *stmt, bool shift_count)
Definition gimple-fold.cc:11035
tree get_symbol_constant_value(tree sym)
Definition gimple-fold.cc:273
static bool get_range_strlen(tree, bitmap, strlen_range_kind, c_strlen_data *, unsigned)
Definition gimple-fold.cc:1937
tree gimple_convert_to_ptrofftype(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, tree op)
Definition gimple-fold.cc:11603
void fold_builtin_atomic_compare_exchange(gimple_stmt_iterator *gsi)
Definition gimple-fold.cc:5852
tree fold_const_aggregate_ref(tree t)
Definition gimple-fold.cc:10741
void replace_call_with_value(gimple_stmt_iterator *gsi, tree val)
Definition gimple-fold.cc:817
bool arith_code_with_undefined_signed_overflow(tree_code code)
Definition gimple-fold.cc:11010
tree fold_ctor_reference(tree type, tree ctor, const poly_uint64 &poly_offset, const poly_uint64 &poly_size, tree from_decl, unsigned HOST_WIDE_INT *suboff)
Definition gimple-fold.cc:10474
void gimplify_and_update_call_from_tree(gimple_stmt_iterator *si_p, tree expr)
Definition gimple-fold.cc:737
bool update_gimple_call(gimple_stmt_iterator *si_p, tree fn, int nargs,...)
Definition gimple-fold.cc:684
bool fold_stmt(gimple_stmt_iterator *gsi, bitmap dce_bitmap)
Definition gimple-fold.cc:7199
tree gimple_build_vector(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, tree_vector_builder *builder)
Definition gimple-fold.cc:11651
tree gimple_get_virt_method_for_binfo(HOST_WIDE_INT token, tree known_binfo, bool *can_refer)
Definition gimple-fold.cc:10864
tree gimple_build_vector_from_val(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, tree type, tree op)
Definition gimple-fold.cc:11617
void gsi_replace_with_seq_vops(gimple_stmt_iterator *si_p, gimple_seq stmts)
Definition gimple-fold.cc:594
bool fold_stmt_inplace(gimple_stmt_iterator *gsi, tree(*valueize)(tree))
Definition gimple-fold.cc:7219
bool gimple_stmt_nonnegative_p(gimple *stmt, int depth)
Definition gimple-fold.cc:11773
tree gimple_fold_stmt_to_constant(gimple *stmt, tree(*valueize)(tree))
Definition gimple-fold.cc:10060
void mark_lhs_in_seq_for_dce(bitmap dce_worklist, gimple_seq seq)
Definition gimple-fold.cc:6510
static gimple_seq rewrite_to_defined_unconditional(gimple_stmt_iterator *gsi, gimple *stmt, bool in_place)
Definition gimple-fold.cc:11101
tree canonicalize_constructor_val(tree cval, tree from_decl)
Definition gimple-fold.cc:200
tree gimple_build_round_up(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, tree type, tree old_size, unsigned HOST_WIDE_INT align)
Definition gimple-fold.cc:11688
tree fold_const_aggregate_ref_1(tree t, tree(*valueize)(tree))
Definition gimple-fold.cc:10574
bool optimize_atomic_compare_exchange_p(gimple *stmt)
Definition gimple-fold.cc:5782
tree gimple_fold_stmt_to_constant_1(gimple *stmt, tree(*valueize)(tree), tree(*gvalueize)(tree))
Definition gimple-fold.cc:9758
tree gimple_fold_indirect_ref(tree t)
Definition gimple-fold.cc:10891
tree no_follow_ssa_edges(tree)
Definition gimple-fold.cc:7167
tree maybe_fold_or_comparisons(tree type, enum tree_code code, enum tree_code code1, tree op1a, tree op1b, enum tree_code code2, tree op2a, tree op2b, basic_block outer_cond_bb)
Definition gimple-fold.cc:9724
tree gimple_get_virt_method_for_vtable(HOST_WIDE_INT token, tree v, unsigned HOST_WIDE_INT offset, bool *can_refer)
Definition gimple-fold.cc:10753
tree follow_single_use_edges(tree val)
Definition gimple-fold.cc:7175
tree gimple_build(gimple_stmt_iterator *gsi, bool before, gsi_iterator_update update, location_t loc, enum tree_code code, tree type, tree op0)
Definition gimple-fold.cc:11305
bool gimple_fold_builtin_sprintf(gimple_stmt_iterator *gsi)
Definition gimple-fold.cc:3643
bool gimple_stmt_integer_valued_real_p(gimple *stmt, int depth)
Definition gimple-fold.cc:11870
tree gimple_simplify(enum tree_code, tree, tree, gimple_seq *, tree(*)(tree))
Definition gimple-match-exports.cc:587
bool fold_before_rtl_expansion_p()
Definition gimple-fold.h:289
tree tree_vec_extract(gimple_stmt_iterator *, tree, tree, tree, tree)
Definition tree-vect-generic.cc:136
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:224
Definition gengtype.h:252
#define NULL
Definition system.h:55
#define PROP_last_full_fold
Definition tree-pass.h:233