GCC Middle and Back End API Reference
expr.h
Go to the documentation of this file.
1/* Definitions for code generation pass of GNU compiler.
2 Copyright (C) 1987-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_EXPR_H
21#define GCC_EXPR_H
22
23/* This is the 4th arg to `expand_expr'.
24 EXPAND_STACK_PARM means we are possibly expanding a call param onto
25 the stack.
26 EXPAND_SUM means it is ok to return a PLUS rtx or MULT rtx.
27 EXPAND_INITIALIZER is similar but also record any labels on forced_labels.
28 EXPAND_CONST_ADDRESS means it is ok to return a MEM whose address
29 is a constant that is not a legitimate address.
30 EXPAND_WRITE means we are only going to write to the resulting rtx.
31 EXPAND_MEMORY means we are interested in a memory result, even if
32 the memory is constant and we could have propagated a constant value,
33 or the memory is unaligned on a STRICT_ALIGNMENT target. */
37
38/* Prevent the compiler from deferring stack pops. See
39 inhibit_defer_pop for more information. */
40#define NO_DEFER_POP (inhibit_defer_pop += 1)
41
42/* Allow the compiler to defer stack pops. See inhibit_defer_pop for
43 more information. */
44#define OK_DEFER_POP (inhibit_defer_pop -= 1)
45
46/* This structure is used to pass around information about exploded
47 unary, binary and trinary expressions between expand_expr_real_1 and
48 friends. */
56
57/* This is run during target initialization to set up which modes can be
58 used directly in memory and to initialize the block move optab. */
59extern void init_expr_target (void);
60
61/* This is run at the start of compiling a function. */
62extern void init_expr (void);
63
64/* Emit some rtl insns to move data between rtx's, converting machine modes.
65 Both modes must be floating or both fixed. */
66extern void convert_move (rtx, rtx, int);
67
68/* Convert an rtx to specified machine mode and return the result. */
69extern rtx convert_to_mode (machine_mode, rtx, int);
70
71/* Convert an rtx to MODE from OLDMODE and return the result. */
72extern rtx convert_modes (machine_mode mode, machine_mode oldmode,
73 rtx x, int unsignedp);
74
75/* Variant of convert_modes for ABI parameter passing/return. */
76extern rtx convert_float_to_wider_int (machine_mode mode, machine_mode fmode,
77 rtx x);
78
79/* Variant of convert_modes for ABI parameter passing/return. */
80extern rtx convert_wider_int_to_float (machine_mode mode, machine_mode imode,
81 rtx x);
82
83/* Expand a call to memcpy or memmove or memcmp, and return the result. */
85 bool);
86
87inline rtx
88emit_block_copy_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
89{
90 return emit_block_op_via_libcall (BUILT_IN_MEMCPY, dst, src, size, tailcall);
91}
92
93inline rtx
94emit_block_move_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
95{
96 return emit_block_op_via_libcall (BUILT_IN_MEMMOVE, dst, src, size, tailcall);
97}
98
99inline rtx
100emit_block_comp_via_libcall (rtx dst, rtx src, rtx size, bool tailcall = false)
101{
102 return emit_block_op_via_libcall (BUILT_IN_MEMCMP, dst, src, size, tailcall);
103}
104
105/* Emit code to move a block Y to a block X. */
107{
111 /* Like BLOCK_OP_NORMAL, but the libcall can be tail call optimized. */
113 /* Like BLOCK_OP_NO_LIBCALL, but instead of emitting a libcall return
114 pc_rtx to indicate nothing has been emitted and let the caller handle
115 it. */
118
119typedef rtx (*by_pieces_constfn) (void *, void *, HOST_WIDE_INT,
121
122/* The second pointer passed to by_pieces_constfn. */
128
130 unsigned ctz_size = 0);
132 unsigned int, HOST_WIDE_INT,
133 unsigned HOST_WIDE_INT,
134 unsigned HOST_WIDE_INT,
135 unsigned HOST_WIDE_INT,
136 bool bail_out_libcall = false,
137 bool *is_move_done = NULL,
138 bool might_overlap = false,
139 unsigned ctz_size = 0);
140extern rtx emit_block_cmp_hints (rtx, rtx, rtx, tree, rtx, bool,
141 by_pieces_constfn, void *,
142 unsigned ctz_len = 0);
143extern bool emit_storent_insn (rtx to, rtx from);
144
145/* Copy all or part of a value X into registers starting at REGNO.
146 The number of registers to be filled is NREGS. */
147extern void move_block_to_reg (int, rtx, int, machine_mode);
148
149/* Copy all or part of a BLKmode value X out of registers starting at REGNO.
150 The number of registers to be filled is NREGS. */
151extern void move_block_from_reg (int, rtx, int);
152
153/* Generate a non-consecutive group of registers represented by a PARALLEL. */
154extern rtx gen_group_rtx (rtx);
155
156/* Load a BLKmode value into non-consecutive registers represented by a
157 PARALLEL. */
158extern void emit_group_load (rtx, rtx, tree, poly_int64);
159
160/* Similarly, but load into new temporaries. */
162
163/* Move a non-consecutive group of registers represented by a PARALLEL into
164 a non-consecutive group of registers represented by a PARALLEL. */
165extern void emit_group_move (rtx, rtx);
166
167/* Move a group of registers represented by a PARALLEL into pseudos. */
169
170/* Store a BLKmode value from non-consecutive registers represented by a
171 PARALLEL. */
172extern void emit_group_store (rtx, rtx, tree, poly_int64);
173
175
176/* Mark REG as holding a parameter for the next CALL_INSN.
177 Mode is TYPE_MODE of the non-promoted parameter, or VOIDmode. */
178extern void use_reg_mode (rtx *, rtx, machine_mode);
179extern void clobber_reg_mode (rtx *, rtx, machine_mode);
180
181extern rtx copy_blkmode_to_reg (machine_mode, tree);
182
183/* Mark REG as holding a parameter for the next CALL_INSN. */
184inline void
186{
188}
189
190/* Mark REG as clobbered by the call with FUSAGE as CALL_INSN_FUNCTION_USAGE. */
191inline void
193{
195}
196
197/* Mark NREGS consecutive regs, starting at REGNO, as holding parameters
198 for the next CALL_INSN. */
199extern void use_regs (rtx *, int, int);
200
201/* Mark a PARALLEL as holding a parameter for the next CALL_INSN. */
202extern void use_group_regs (rtx *, rtx);
203
204#ifdef GCC_INSN_CODES_H
205extern rtx expand_cmpstrn_or_cmpmem (insn_code, rtx, rtx, rtx, tree, rtx,
207#endif
208
209/* Write zeros through the storage of OBJECT.
210 If OBJECT has BLKmode, SIZE is its length in bytes. */
213 unsigned int, HOST_WIDE_INT,
214 unsigned HOST_WIDE_INT,
215 unsigned HOST_WIDE_INT,
216 unsigned HOST_WIDE_INT,
217 unsigned);
218/* The same, but always output an library call. */
219extern rtx set_storage_via_libcall (rtx, rtx, rtx, bool = false);
220
221/* Expand a setmem pattern; return true if successful. */
222extern bool set_storage_via_setmem (rtx, rtx, rtx, unsigned int,
223 unsigned int, HOST_WIDE_INT,
224 unsigned HOST_WIDE_INT,
225 unsigned HOST_WIDE_INT,
226 unsigned HOST_WIDE_INT);
227
228/* Return true if it is desirable to store LEN bytes generated by
229 CONSTFUN with several move instructions by store_by_pieces
230 function. CONSTFUNDATA is a pointer which will be passed as argument
231 in every CONSTFUN call.
232 ALIGN is maximum alignment we can assume.
233 MEMSETP is true if this is a real memset/bzero, not a copy
234 of a const string. */
235extern bool can_store_by_pieces (unsigned HOST_WIDE_INT,
237 void *, unsigned int, bool);
238
239/* Generate several move instructions to store LEN bytes generated by
240 CONSTFUN to block TO. (A MEM rtx with BLKmode). CONSTFUNDATA is a
241 pointer which will be passed as argument in every CONSTFUN call.
242 ALIGN is maximum alignment we can assume.
243 MEMSETP is true if this is a real memset/bzero, not a copy.
244 Returns TO + LEN. */
246 void *, unsigned int, bool, memop_ret);
247
248/* Generate several move instructions to clear LEN bytes of block TO. (A MEM
249 rtx with BLKmode). ALIGN is maximum alignment we can assume. */
250
251extern void clear_by_pieces (rtx, unsigned HOST_WIDE_INT, unsigned int);
252
253/* If can_store_by_pieces passes for worst-case values near MAX_LEN, call
254 store_by_pieces within conditionals so as to handle variable LEN efficiently,
255 storing VAL, if non-NULL_RTX, or valc instead. */
256extern bool try_store_by_multiple_pieces (rtx to, rtx len,
257 unsigned int ctz_len,
258 unsigned HOST_WIDE_INT min_len,
259 unsigned HOST_WIDE_INT max_len,
260 rtx val, char valc,
261 unsigned int align);
262
263/* Emit insns to set X from Y. */
264extern rtx_insn *emit_move_insn (rtx, rtx);
265extern rtx_insn *gen_move_insn (rtx, rtx);
266
267/* Emit insns to set X from Y, with no frills. */
269
270extern rtx_insn *emit_move_complex_push (machine_mode, rtx, rtx);
272extern rtx read_complex_part (rtx, bool);
273extern void write_complex_part (rtx, rtx, bool, bool);
274extern rtx read_complex_part (rtx, bool);
275extern rtx emit_move_resolve_push (machine_mode, rtx);
276
277/* Push a block of length SIZE (perhaps variable)
278 and return an rtx to address the beginning of the block. */
279extern rtx push_block (rtx, poly_int64, int);
280
281/* Generate code to push something onto the stack, given its mode and type. */
282extern bool emit_push_insn (rtx, machine_mode, tree, rtx, unsigned int,
283 int, rtx, poly_int64, rtx, rtx, int, rtx, bool);
284
285/* Extract the accessible bit-range from a COMPONENT_REF. */
286extern void get_bit_range (poly_uint64 *, poly_uint64 *, tree,
287 poly_int64 *, tree *);
288
289/* Expand an assignment that stores the value of FROM into TO. */
290extern void expand_assignment (tree, tree, bool);
291
292/* Generate code for computing expression EXP,
293 and storing the value into TARGET.
294 If SUGGEST_REG is nonzero, copy the value through a register
295 and return that register, if that is possible. */
296extern rtx store_expr (tree, rtx, int, bool, bool);
297
298/* Given an rtx that may include add and multiply operations,
299 generate them as insns and return a pseudo-reg containing the value.
300 Useful after calling expand_expr with 1 as sum_ok. */
301extern rtx force_operand (rtx, rtx);
302
303/* Work horses for expand_expr. */
304extern rtx expand_expr_real (tree, rtx, machine_mode,
305 enum expand_modifier, rtx *, bool);
306extern rtx expand_expr_real_1 (tree, rtx, machine_mode,
307 enum expand_modifier, rtx *, bool);
308extern rtx expand_expr_real_2 (sepops, rtx, machine_mode,
309 enum expand_modifier);
310extern rtx expand_expr_real_gassign (gassign *, rtx, machine_mode,
311 enum expand_modifier modifier,
312 rtx * = nullptr, bool = false);
313
314/* Generate code for computing expression EXP.
315 An rtx for the computed value is returned. The value is never null.
316 In the case of a void EXP, const0_rtx is returned. */
317inline rtx
318expand_expr (tree exp, rtx target, machine_mode mode,
319 enum expand_modifier modifier)
320{
321 return expand_expr_real (exp, target, mode, modifier, NULL, false);
322}
323
324inline rtx
329
330
331/* Return STRING_CST and set offset, size and decl, if the first
332 argument corresponds to a string constant. */
333extern tree string_constant (tree, tree *, tree *, tree *);
334/* Similar to string_constant, return a STRING_CST corresponding
335 to the value representation of the first argument if it's
336 a constant. */
337extern tree byte_representation (tree, tree *, tree *, tree *);
338
339extern enum tree_code maybe_optimize_mod_cmp (enum tree_code, tree *, tree *);
340extern void maybe_optimize_sub_cmp_0 (enum tree_code, tree *, tree *);
341
342/* Two different ways of generating switch statements. */
343extern bool try_casesi (tree, tree, tree, tree, rtx, rtx, rtx,
345extern bool try_tablejump (tree, tree, tree, tree, rtx, rtx,
347
348extern bool safe_from_p (const_rtx, tree, int);
349
350/* Get the personality libfunc for a function decl. */
352
353/* Determine whether the LEN bytes can be moved by using several move
354 instructions. Return nonzero if a call to move_by_pieces should
355 succeed. */
356extern bool can_move_by_pieces (unsigned HOST_WIDE_INT, unsigned int);
357
359
362 bool *);
363extern bool immediate_const_ctor_p (const_tree, unsigned int words = 1);
364extern void store_constructor (tree, rtx, int, poly_int64, bool);
366
367extern void expand_operands (tree, tree, rtx, rtx*, rtx*,
368 enum expand_modifier);
369
370/* rtl.h and tree.h were included. */
371/* Return an rtx for the size in bytes of the value of an expr. */
372extern rtx expr_size (tree);
373
375extern bool non_mem_decl_p (tree);
376
377#endif /* GCC_EXPR_H */
Definition machmode.h:823
Definition profile-count.h:147
struct rtx_def * rtx
Definition coretypes.h:57
const union tree_node * const_tree
Definition coretypes.h:98
union tree_node * tree
Definition coretypes.h:97
rtx expand_cmpstrn_or_cmpmem(insn_code icode, rtx target, rtx arg1_rtx, rtx arg2_rtx, tree arg3_type, rtx arg3_rtx, HOST_WIDE_INT align)
Definition expr.cc:2557
bool can_store_by_pieces(unsigned HOST_WIDE_INT, by_pieces_constfn, void *, unsigned int, bool)
Definition expr.cc:1734
void init_expr_target(void)
Definition expr.cc:113
void use_reg_mode(rtx *, rtx, machine_mode)
Definition expr.cc:3736
rtx_insn * emit_move_insn(rtx, rtx)
Definition expr.cc:4603
rtx copy_blkmode_to_reg(machine_mode, tree)
Definition expr.cc:3609
void use_group_regs(rtx *, rtx)
Definition expr.cc:3778
rtx emit_group_move_into_temps(rtx)
Definition expr.cc:3183
rtx emit_block_move_via_libcall(rtx dst, rtx src, rtx size, bool tailcall=false)
Definition expr.h:94
rtx convert_to_mode(machine_mode, rtx, int)
Definition expr.cc:845
rtx read_complex_part(rtx, bool)
Definition expr.cc:4097
rtx expand_expr_real_gassign(gassign *, rtx, machine_mode, enum expand_modifier modifier, rtx *=nullptr, bool=false)
Definition expr.cc:11070
rtx_insn * emit_move_complex_push(machine_mode, rtx, rtx)
Definition expr.cc:4291
rtx emit_group_load_into_temps(rtx, rtx, tree, poly_int64)
Definition expr.cc:3136
rtx get_personality_function(tree)
Definition expr.cc:14023
void clobber_reg(rtx *fusage, rtx reg)
Definition expr.h:192
rtx emit_block_op_via_libcall(enum built_in_function, rtx, rtx, rtx, bool)
Definition expr.cc:2514
rtx(* by_pieces_constfn)(void *, void *, HOST_WIDE_INT, fixed_size_mode)
Definition expr.h:119
struct separate_ops * sepops
bool mem_ref_refers_to_non_mem_p(tree)
Definition expr.cc:5929
void maybe_optimize_sub_cmp_0(enum tree_code, tree *, tree *)
Definition expr.cc:13375
void write_complex_part(rtx, rtx, bool, bool)
Definition expr.cc:4035
rtx expand_expr_real(tree, rtx, machine_mode, enum expand_modifier, rtx *, bool)
Definition expr.cc:9433
void get_bit_range(poly_uint64 *, poly_uint64 *, tree, poly_int64 *, tree *)
Definition expr.cc:5836
rtx expr_size(tree)
Definition expr.cc:14057
void emit_group_move(rtx, rtx)
Definition expr.cc:3166
block_op_methods
Definition expr.h:107
@ BLOCK_OP_CALL_PARM
Definition expr.h:110
@ BLOCK_OP_NORMAL
Definition expr.h:108
@ BLOCK_OP_TAILCALL
Definition expr.h:112
@ BLOCK_OP_NO_LIBCALL
Definition expr.h:109
@ BLOCK_OP_NO_LIBCALL_RET
Definition expr.h:116
rtx convert_modes(machine_mode mode, machine_mode oldmode, rtx x, int unsignedp)
Definition expr.cc:861
rtx convert_float_to_wider_int(machine_mode mode, machine_mode fmode, rtx x)
Definition expr.cc:951
tree string_constant(tree, tree *, tree *, tree *)
Definition expr.cc:13057
bool emit_push_insn(rtx, machine_mode, tree, rtx, unsigned int, int, rtx, poly_int64, rtx, rtx, int, rtx, bool)
Definition expr.cc:5264
rtx push_block(rtx, poly_int64, int)
Definition expr.cc:4850
HOST_WIDE_INT int_expr_size(const_tree exp)
Definition expr.cc:14077
bool try_casesi(tree, tree, tree, tree, rtx, rtx, rtx, profile_probability)
Definition expr.cc:13741
rtx clear_storage_hints(rtx, rtx, enum block_op_methods, unsigned int, HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned)
Definition expr.cc:3838
rtx expand_expr_real_1(tree, rtx, machine_mode, enum expand_modifier, rtx *, bool)
Definition expr.cc:11122
enum tree_code maybe_optimize_mod_cmp(enum tree_code, tree *, tree *)
Definition expr.cc:13186
rtx emit_block_comp_via_libcall(rtx dst, rtx src, rtx size, bool tailcall=false)
Definition expr.h:100
bool safe_from_p(const_rtx, tree, int)
Definition expr.cc:8727
rtx expand_expr(tree exp, rtx target, machine_mode mode, enum expand_modifier modifier)
Definition expr.h:318
expand_modifier
Definition expr.h:34
@ EXPAND_MEMORY
Definition expr.h:36
@ EXPAND_WRITE
Definition expr.h:35
@ EXPAND_CONST_ADDRESS
Definition expr.h:35
@ EXPAND_SUM
Definition expr.h:34
@ EXPAND_NORMAL
Definition expr.h:34
@ EXPAND_INITIALIZER
Definition expr.h:35
@ EXPAND_STACK_PARM
Definition expr.h:34
rtx_insn * emit_move_insn_1(rtx, rtx)
Definition expr.cc:4546
rtx emit_block_cmp_hints(rtx, rtx, rtx, tree, rtx, bool, by_pieces_constfn, void *, unsigned ctz_len=0)
Definition expr.cc:2619
rtx gen_group_rtx(rtx)
Definition expr.cc:2913
bool set_storage_via_setmem(rtx, rtx, rtx, unsigned int, unsigned int, HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT)
Definition expr.cc:3948
tree byte_representation(tree, tree *, tree *, tree *)
Definition expr.cc:13067
rtx store_expr(tree, rtx, int, bool, bool)
Definition expr.cc:6535
bool categorize_ctor_elements(const_tree, HOST_WIDE_INT *, HOST_WIDE_INT *, HOST_WIDE_INT *, bool *)
Definition expr.cc:7229
bool immediate_const_ctor_p(const_tree, unsigned int words=1)
Definition expr.cc:7247
void clobber_reg_mode(rtx *, rtx, machine_mode)
Definition expr.cc:3751
void convert_move(rtx, rtx, int)
Definition expr.cc:216
rtx expand_normal(tree exp)
Definition expr.h:325
void init_expr(void)
Definition expr.cc:204
rtx emit_block_move(rtx, rtx, rtx, enum block_op_methods, unsigned ctz_size=0)
void expand_operands(tree, tree, rtx, rtx *, rtx *, enum expand_modifier)
Definition expr.cc:9013
rtx force_operand(rtx, rtx)
Definition expr.cc:8574
rtx store_by_pieces(rtx, unsigned HOST_WIDE_INT, by_pieces_constfn, void *, unsigned int, bool, memop_ret)
Definition expr.cc:1816
void emit_group_store(rtx, rtx, tree, poly_int64)
Definition expr.cc:3207
rtx maybe_emit_group_store(rtx, tree)
Definition expr.cc:3478
bool emit_storent_insn(rtx to, rtx from)
Definition expr.cc:6478
void use_regs(rtx *, int, int)
Definition expr.cc:3763
void expand_assignment(tree, tree, bool)
Definition expr.cc:5953
void use_reg(rtx *fusage, rtx reg)
Definition expr.h:185
unsigned HOST_WIDE_INT highest_pow2_factor(const_tree)
Definition expr.cc:8923
rtx convert_wider_int_to_float(machine_mode mode, machine_mode imode, rtx x)
Definition expr.cc:964
bool can_move_by_pieces(unsigned HOST_WIDE_INT, unsigned int)
Definition expr.cc:1089
rtx_insn * emit_move_complex_parts(rtx, rtx)
Definition expr.cc:4334
rtx emit_block_move_hints(rtx, rtx, rtx, enum block_op_methods, unsigned int, HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT, bool bail_out_libcall=false, bool *is_move_done=NULL, bool might_overlap=false, unsigned ctz_size=0)
Definition expr.cc:2000
bool try_store_by_multiple_pieces(rtx to, rtx len, unsigned int ctz_len, unsigned HOST_WIDE_INT min_len, unsigned HOST_WIDE_INT max_len, rtx val, char valc, unsigned int align)
Definition builtins.cc:4355
rtx set_storage_via_libcall(rtx, rtx, rtx, bool=false)
Definition expr.cc:3919
rtx emit_move_resolve_push(machine_mode, rtx)
Definition expr.cc:4236
void store_constructor(tree, rtx, int, poly_int64, bool)
Definition expr.cc:7409
void move_block_from_reg(int, rtx, int)
Definition expr.cc:2876
void emit_group_load(rtx, rtx, tree, poly_int64)
Definition expr.cc:3113
void clear_by_pieces(rtx, unsigned HOST_WIDE_INT, unsigned int)
Definition expr.cc:1843
rtx_insn * gen_move_insn(rtx, rtx)
Definition expr.cc:4740
rtx expand_expr_real_2(sepops, rtx, machine_mode, enum expand_modifier)
Definition expr.cc:9646
bool try_tablejump(tree, tree, tree, tree, rtx, rtx, profile_probability)
Definition expr.cc:13890
void move_block_to_reg(int, rtx, int, machine_mode)
Definition expr.cc:2844
rtx clear_storage(rtx, rtx, enum block_op_methods)
Definition expr.cc:3904
bool non_mem_decl_p(tree)
Definition expr.cc:5912
rtx emit_block_copy_via_libcall(rtx dst, rtx src, rtx size, bool tailcall=false)
Definition expr.h:88
double exp(double)
built_in_function
Definition genmatch.cc:354
tree_code
Definition genmatch.cc:347
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
memop_ret
Definition rtl.h:4263
#define NULL_RTX
Definition rtl.h:705
Definition expr.h:124
rtx data
Definition expr.h:125
fixed_size_mode mode
Definition expr.h:126
Definition gimple.h:904
Definition rtl.h:311
Definition rtl.h:545
Definition expr.h:50
tree op1
Definition expr.h:54
location_t location
Definition expr.h:52
enum tree_code code
Definition expr.h:51
tree op0
Definition expr.h:54
tree op2
Definition expr.h:54
tree type
Definition expr.h:53
Definition tree-tailcall.cc:110
#define NULL
Definition system.h:50