]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/emit-rtl.h
[Ada] Small improvement to Expand_N_Unchecked_Type_Conversion
[thirdparty/gcc.git] / gcc / emit-rtl.h
CommitLineData
78528714 1/* Exported functions from emit-rtl.c
8d9254fc 2 Copyright (C) 2004-2020 Free Software Foundation, Inc.
78528714
JQ
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
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
78528714
JQ
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
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
78528714
JQ
19
20#ifndef GCC_EMIT_RTL_H
21#define GCC_EMIT_RTL_H
22
99b1c316
MS
23class temp_slot;
24typedef class temp_slot *temp_slot_p;
bd785b44 25class predefined_function_abi;
2bb8cb58 26
16a16ec7
AM
27/* Information mainlined about RTL representation of incoming arguments. */
28struct GTY(()) incoming_args {
29 /* Number of bytes of args popped by function being compiled on its return.
30 Zero if no bytes are to be popped.
31 May affect compilation of return insn or of function epilogue. */
a20c5714 32 poly_int64_pod pops_args;
16a16ec7
AM
33
34 /* If function's args have a fixed size, this is that size, in bytes.
35 Otherwise, it is -1.
36 May affect compilation of return insn or of function epilogue. */
a20c5714 37 poly_int64_pod size;
16a16ec7
AM
38
39 /* # bytes the prologue should push and pretend that the caller pushed them.
40 The prologue must do this, but only if parms can be passed in
41 registers. */
42 int pretend_args_size;
43
44 /* This is the offset from the arg pointer to the place where the first
45 anonymous arg can be found, if there is one. */
46 rtx arg_offset_rtx;
47
48 /* Quantities of various kinds of registers
49 used for the current function's args. */
50 CUMULATIVE_ARGS info;
51
52 /* The arg pointer hard register, or the pseudo into which it was copied. */
53 rtx internal_arg_pointer;
54};
55
56
2bb8cb58
AM
57/* Datastructures maintained for currently processed function in RTL form. */
58struct GTY(()) rtl_data {
8194c537
DM
59 void init_stack_alignment ();
60
2bb8cb58
AM
61 struct expr_status expr;
62 struct emit_status emit;
63 struct varasm_status varasm;
64 struct incoming_args args;
65 struct function_subsections subsections;
66 struct rtl_eh eh;
67
bd785b44
RS
68 /* The ABI of the function, i.e. the interface it presents to its callers.
69 This is the ABI that should be queried to see which registers the
70 function needs to save before it uses them.
71
72 Other functions (including those called by this function) might use
73 different ABIs. */
74 const predefined_function_abi *GTY((skip)) abi;
75
2bb8cb58
AM
76 /* For function.c */
77
78 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
79 defined, the needed space is pushed by the prologue. */
a20c5714 80 poly_int64_pod outgoing_args_size;
2bb8cb58
AM
81
82 /* If nonzero, an RTL expression for the location at which the current
83 function returns its result. If the current function returns its
84 result in a register, current_function_return_rtx will always be
85 the hard register containing the result. */
86 rtx return_rtx;
2bb8cb58
AM
87
88 /* Vector of initial-value pairs. Each pair consists of a pseudo
89 register of approprite mode that stores the initial value a hard
90 register REGNO, and that hard register itself. */
91 /* ??? This could be a VEC but there is currently no way to define an
92 opaque VEC type. */
93 struct initial_value_struct *hard_reg_initial_vals;
94
95 /* A variable living at the top of the frame that holds a known value.
96 Used for detecting stack clobbers. */
97 tree stack_protect_guard;
98
a49a975f
JJ
99 /* The __stack_chk_guard variable or expression holding the stack
100 protector canary value. */
101 tree stack_protect_guard_decl;
102
2bb8cb58
AM
103 /* List (chain of INSN_LIST) of labels heading the current handlers for
104 nonlocal gotos. */
105 rtx_insn_list *x_nonlocal_goto_handler_labels;
106
107 /* Label that will go on function epilogue.
108 Jumping to this label serves as a "return" instruction
109 on machines which require execution of the epilogue on all returns. */
110 rtx_code_label *x_return_label;
111
112 /* Label that will go on the end of function epilogue.
113 Jumping to this label serves as a "naked return" instruction
114 on machines which require execution of the epilogue on all returns. */
115 rtx_code_label *x_naked_return_label;
116
117 /* List (chain of EXPR_LISTs) of all stack slots in this function.
118 Made for the sake of unshare_all_rtl. */
8c39f8ae 119 vec<rtx, va_gc> *x_stack_slot_list;
2bb8cb58
AM
120
121 /* List of empty areas in the stack frame. */
99b1c316 122 class frame_space *frame_space_list;
2bb8cb58
AM
123
124 /* Place after which to insert the tail_recursion_label if we need one. */
125 rtx_note *x_stack_check_probe_note;
126
127 /* Location at which to save the argument pointer if it will need to be
128 referenced. There are two cases where this is done: if nonlocal gotos
129 exist, or if vars stored at an offset from the argument pointer will be
130 needed by inner routines. */
131 rtx x_arg_pointer_save_area;
132
133 /* Dynamic Realign Argument Pointer used for realigning stack. */
134 rtx drap_reg;
135
136 /* Offset to end of allocated area of stack frame.
137 If stack grows down, this is the address of the last stack slot allocated.
138 If stack grows up, this is the address for the next slot. */
f075bd95 139 poly_int64_pod x_frame_offset;
2bb8cb58
AM
140
141 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
142 rtx_insn *x_parm_birth_insn;
143
144 /* List of all used temporaries allocated, by level. */
145 vec<temp_slot_p, va_gc> *x_used_temp_slots;
146
147 /* List of available temp slots. */
99b1c316 148 class temp_slot *x_avail_temp_slots;
2bb8cb58
AM
149
150 /* Current nesting level for temporaries. */
151 int x_temp_slot_level;
152
153 /* The largest alignment needed on the stack, including requirement
154 for outgoing stack alignment. */
155 unsigned int stack_alignment_needed;
156
157 /* Preferred alignment of the end of stack frame, which is preferred
158 to call other functions. */
159 unsigned int preferred_stack_boundary;
160
161 /* The minimum alignment of parameter stack. */
162 unsigned int parm_stack_boundary;
163
164 /* The largest alignment of slot allocated on the stack. */
165 unsigned int max_used_stack_slot_alignment;
166
167 /* The stack alignment estimated before reload, with consideration of
168 following factors:
169 1. Alignment of local stack variables (max_used_stack_slot_alignment)
170 2. Alignment requirement to call other functions
171 (preferred_stack_boundary)
172 3. Alignment of non-local stack variables but might be spilled in
173 local stack. */
174 unsigned int stack_alignment_estimated;
175
6607bdd9
L
176 /* How many NOP insns to place at each function entry by default. */
177 unsigned short patch_area_size;
178
179 /* How far the real asm entry point is into this area. */
180 unsigned short patch_area_entry;
181
2bb8cb58
AM
182 /* For reorg. */
183
184 /* Nonzero if function being compiled called builtin_return_addr or
185 builtin_frame_address with nonzero count. */
186 bool accesses_prior_frames;
187
188 /* Nonzero if the function calls __builtin_eh_return. */
189 bool calls_eh_return;
190
191 /* Nonzero if function saves all registers, e.g. if it has a nonlocal
192 label that can reach the exit block via non-exceptional paths. */
193 bool saves_all_registers;
194
195 /* Nonzero if function being compiled has nonlocal gotos to parent
196 function. */
197 bool has_nonlocal_goto;
198
199 /* Nonzero if function being compiled has an asm statement. */
200 bool has_asm_statement;
201
202 /* This bit is used by the exception handling logic. It is set if all
203 calls (if any) are sibling calls. Such functions do not have to
204 have EH tables generated, as they cannot throw. A call to such a
205 function, however, should be treated as throwing if any of its callees
206 can throw. */
207 bool all_throwers_are_sibcalls;
208
209 /* Nonzero if stack limit checking should be enabled in the current
210 function. */
211 bool limit_stack;
212
213 /* Nonzero if profiling code should be generated. */
214 bool profile;
215
216 /* Nonzero if the current function uses the constant pool. */
217 bool uses_const_pool;
218
219 /* Nonzero if the current function uses pic_offset_table_rtx. */
220 bool uses_pic_offset_table;
221
222 /* Nonzero if the current function needs an lsda for exception handling. */
223 bool uses_eh_lsda;
224
225 /* Set when the tail call has been produced. */
226 bool tail_call_emit;
227
228 /* Nonzero if code to initialize arg_pointer_save_area has been emitted. */
229 bool arg_pointer_save_area_init;
230
231 /* Nonzero if current function must be given a frame pointer.
232 Set in reload1.c or lra-eliminations.c if anything is allocated
233 on the stack there. */
234 bool frame_pointer_needed;
235
236 /* When set, expand should optimize for speed. */
237 bool maybe_hot_insn_p;
238
239 /* Nonzero if function stack realignment is needed. This flag may be
240 set twice: before and after reload. It is set before reload wrt
241 stack alignment estimation before reload. It will be changed after
242 reload if by then criteria of stack realignment is different.
243 The value set after reload is the accurate one and is finalized. */
244 bool stack_realign_needed;
245
246 /* Nonzero if function stack realignment is tried. This flag is set
247 only once before reload. It affects register elimination. This
248 is used to generate DWARF debug info for stack variables. */
249 bool stack_realign_tried;
250
251 /* Nonzero if function being compiled needs dynamic realigned
252 argument pointer (drap) if stack needs realigning. */
253 bool need_drap;
254
255 /* Nonzero if function stack realignment estimation is done, namely
256 stack_realign_needed flag has been set before reload wrt estimated
257 stack alignment info. */
258 bool stack_realign_processed;
259
260 /* Nonzero if function stack realignment has been finalized, namely
261 stack_realign_needed flag has been set and finalized after reload. */
262 bool stack_realign_finalized;
263
264 /* True if dbr_schedule has already been called for this function. */
265 bool dbr_scheduled_p;
266
67914693 267 /* True if current function cannot throw. Unlike
2bb8cb58
AM
268 TREE_NOTHROW (current_function_decl) it is set even for overwritable
269 function where currently compiled version of it is nothrow. */
270 bool nothrow;
271
272 /* True if we performed shrink-wrapping for the current function. */
273 bool shrink_wrapped;
274
20a6ece0
SB
275 /* True if we performed shrink-wrapping for separate components for
276 the current function. */
277 bool shrink_wrapped_separate;
278
2bb8cb58
AM
279 /* Nonzero if function being compiled doesn't modify the stack pointer
280 (ignoring the prologue and epilogue). This is only valid after
281 pass_stack_ptr_mod has run. */
282 bool sp_is_unchanging;
283
284 /* Nonzero if function being compiled doesn't contain any calls
285 (ignoring the prologue and epilogue). This is set prior to
55dabf65 286 register allocation in IRA and is valid for the remaining
2bb8cb58
AM
287 compiler passes. */
288 bool is_leaf;
289
290 /* Nonzero if the function being compiled is a leaf function which only
291 uses leaf registers. This is valid after reload (specifically after
292 sched2) and is useful only if the port defines LEAF_REGISTERS. */
293 bool uses_only_leaf_regs;
294
295 /* Nonzero if the function being compiled has undergone hot/cold partitioning
296 (under flag_reorder_blocks_and_partition) and has at least one cold
297 block. */
298 bool has_bb_partition;
299
300 /* Nonzero if the function being compiled has completed the bb reordering
301 pass. */
302 bool bb_reorder_complete;
303
304 /* Like regs_ever_live, but 1 if a reg is set or clobbered from an
305 asm. Unlike regs_ever_live, elements of this array corresponding
306 to eliminable regs (like the frame pointer) are set if an asm
307 sets them. */
308 HARD_REG_SET asm_clobbers;
8cac4d85
BS
309
310 /* The highest address seen during shorten_branches. */
311 int max_insn_address;
2bb8cb58
AM
312};
313
314#define return_label (crtl->x_return_label)
315#define naked_return_label (crtl->x_naked_return_label)
316#define stack_slot_list (crtl->x_stack_slot_list)
317#define parm_birth_insn (crtl->x_parm_birth_insn)
318#define frame_offset (crtl->x_frame_offset)
319#define stack_check_probe_note (crtl->x_stack_check_probe_note)
320#define arg_pointer_save_area (crtl->x_arg_pointer_save_area)
321#define used_temp_slots (crtl->x_used_temp_slots)
322#define avail_temp_slots (crtl->x_avail_temp_slots)
323#define temp_slot_level (crtl->x_temp_slot_level)
324#define nonlocal_goto_handler_labels (crtl->x_nonlocal_goto_handler_labels)
325#define frame_pointer_needed (crtl->frame_pointer_needed)
326#define stack_realign_fp (crtl->stack_realign_needed && !crtl->need_drap)
327#define stack_realign_drap (crtl->stack_realign_needed && crtl->need_drap)
328
329extern GTY(()) struct rtl_data x_rtl;
330
331/* Accessor to RTL datastructures. We keep them statically allocated now since
332 we never keep multiple functions. For threaded compiler we might however
333 want to do differently. */
334#define crtl (&x_rtl)
335
96b3c03f 336/* Return whether two MEM_ATTRs are equal. */
99b1c316 337bool mem_attrs_eq_p (const class mem_attrs *, const class mem_attrs *);
96b3c03f 338
78528714 339/* Set the alias set of MEM to SET. */
4862826d 340extern void set_mem_alias_set (rtx, alias_set_type);
78528714
JQ
341
342/* Set the alignment of MEM to ALIGN bits. */
343extern void set_mem_align (rtx, unsigned int);
344
09e881c9
BE
345/* Set the address space of MEM to ADDRSPACE. */
346extern void set_mem_addr_space (rtx, addr_space_t);
347
78528714
JQ
348/* Set the expr for MEM to EXPR. */
349extern void set_mem_expr (rtx, tree);
350
351/* Set the offset for MEM to OFFSET. */
d05d7551 352extern void set_mem_offset (rtx, poly_int64);
527210c4
RS
353
354/* Clear the offset recorded for MEM. */
355extern void clear_mem_offset (rtx);
78528714
JQ
356
357/* Set the size for MEM to SIZE. */
d05d7551 358extern void set_mem_size (rtx, poly_int64);
f5541398
RS
359
360/* Clear the size recorded for MEM. */
361extern void clear_mem_size (rtx);
78528714 362
f6129d66
RH
363/* Set the attributes for MEM appropriate for a spill slot. */
364extern void set_mem_attrs_for_spill (rtx);
3d7e23f6 365extern tree get_spill_slot_decl (bool);
f6129d66 366
78528714
JQ
367/* Return a memory reference like MEMREF, but with its address changed to
368 ADDR. The caller is asserting that the actual piece of memory pointed
369 to is the same, just the form of the address is being changed, such as
370 by putting something into a register. */
23b33725 371extern rtx replace_equiv_address (rtx, rtx, bool = false);
78528714
JQ
372
373/* Likewise, but the reference is not required to be valid. */
23b33725 374extern rtx replace_equiv_address_nv (rtx, rtx, bool = false);
78528714 375
5936d944
JH
376extern rtx gen_blockage (void);
377extern rtvec gen_rtvec (int, ...);
378extern rtx copy_insn_1 (rtx);
379extern rtx copy_insn (rtx);
f8f0516e 380extern rtx_insn *copy_delay_slot_insn (rtx_insn *);
0c12fc9b 381extern rtx gen_int_mode (poly_int64, machine_mode);
a1950df3 382extern rtx_insn *emit_copy_of_insn_after (rtx_insn *, rtx_insn *);
5936d944
JH
383extern void set_reg_attrs_from_value (rtx, rtx);
384extern void set_reg_attrs_for_parm (rtx, rtx);
385extern void set_reg_attrs_for_decl_rtl (tree t, rtx x);
ef4bddc2 386extern void adjust_reg_mode (rtx, machine_mode);
5936d944 387extern int mem_expr_equal_p (const_tree, const_tree);
0c12fc9b 388extern rtx gen_int_shift_amount (machine_mode, poly_int64);
5936d944 389
8930883e
MK
390extern bool need_atomic_barrier_p (enum memmodel, bool);
391
614d5bd8
AM
392/* Return the current sequence. */
393
394static inline struct sequence_stack *
395get_current_sequence (void)
396{
397 return &crtl->emit.seq;
398}
399
400/* Return the outermost sequence. */
401
402static inline struct sequence_stack *
403get_topmost_sequence (void)
404{
405 struct sequence_stack *seq, *top;
406
407 seq = get_current_sequence ();
408 do
409 {
410 top = seq;
411 seq = seq->next;
412 } while (seq);
413 return top;
414}
415
5936d944
JH
416/* Return the first insn of the current sequence or current function. */
417
981ac3c7 418static inline rtx_insn *
5936d944
JH
419get_insns (void)
420{
614d5bd8 421 return get_current_sequence ()->first;
5936d944
JH
422}
423
424/* Specify a new insn as the first in the chain. */
425
426static inline void
fee3e72c 427set_first_insn (rtx_insn *insn)
5936d944 428{
06795261 429 gcc_checking_assert (!insn || !PREV_INSN (insn));
614d5bd8 430 get_current_sequence ()->first = insn;
5936d944
JH
431}
432
433/* Return the last insn emitted in current sequence or current function. */
434
981ac3c7 435static inline rtx_insn *
5936d944
JH
436get_last_insn (void)
437{
614d5bd8 438 return get_current_sequence ()->last;
5936d944
JH
439}
440
441/* Specify a new insn as the last in the chain. */
442
443static inline void
fee3e72c 444set_last_insn (rtx_insn *insn)
5936d944 445{
06795261 446 gcc_checking_assert (!insn || !NEXT_INSN (insn));
614d5bd8 447 get_current_sequence ()->last = insn;
5936d944
JH
448}
449
450/* Return a number larger than any instruction's uid in this function. */
451
452static inline int
453get_max_uid (void)
454{
455 return crtl->emit.x_cur_insn_uid;
456}
d8a2d370 457
c0cc00c4 458extern bool valid_for_const_vector_p (machine_mode, rtx);
59d06c05
RS
459extern rtx gen_const_vec_duplicate (machine_mode, rtx);
460extern rtx gen_vec_duplicate (machine_mode, rtx);
461
ef339d6e
RS
462extern rtx gen_const_vec_series (machine_mode, rtx, rtx);
463extern rtx gen_vec_series (machine_mode, rtx, rtx);
464
d8a2d370
DN
465extern void set_decl_incoming_rtl (tree, rtx, bool);
466
36566b39
PK
467/* Return a memory reference like MEMREF, but with its mode changed
468 to MODE and its address changed to ADDR.
469 (VOIDmode means don't change the mode.
470 NULL for ADDR means don't change the address.) */
471extern rtx change_address (rtx, machine_mode, rtx);
472
473/* Return a memory reference like MEMREF, but with its mode changed
474 to MODE and its address offset by OFFSET bytes. */
475#define adjust_address(MEMREF, MODE, OFFSET) \
476 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 0, 0)
477
478/* Likewise, but the reference is not required to be valid. */
479#define adjust_address_nv(MEMREF, MODE, OFFSET) \
480 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 0, 0)
481
482/* Return a memory reference like MEMREF, but with its mode changed
483 to MODE and its address offset by OFFSET bytes. Assume that it's
484 for a bitfield and conservatively drop the underlying object if we
485 cannot be sure to stay within its bounds. */
486#define adjust_bitfield_address(MEMREF, MODE, OFFSET) \
487 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, 0)
488
489/* As for adjust_bitfield_address, but specify that the width of
490 BLKmode accesses is SIZE bytes. */
491#define adjust_bitfield_address_size(MEMREF, MODE, OFFSET, SIZE) \
492 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, SIZE)
493
494/* Likewise, but the reference is not required to be valid. */
495#define adjust_bitfield_address_nv(MEMREF, MODE, OFFSET) \
496 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 1, 0)
497
498/* Return a memory reference like MEMREF, but with its mode changed
499 to MODE and its address changed to ADDR, which is assumed to be
500 increased by OFFSET bytes from MEMREF. */
501#define adjust_automodify_address(MEMREF, MODE, ADDR, OFFSET) \
502 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 1)
503
504/* Likewise, but the reference is not required to be valid. */
505#define adjust_automodify_address_nv(MEMREF, MODE, ADDR, OFFSET) \
506 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 0)
507
d05d7551
RS
508extern rtx adjust_address_1 (rtx, machine_mode, poly_int64, int, int,
509 int, poly_int64);
36566b39 510extern rtx adjust_automodify_address_1 (rtx, machine_mode, rtx,
d05d7551 511 poly_int64, int);
36566b39
PK
512
513/* Return a memory reference like MEMREF, but whose address is changed by
514 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
515 known to be in OFFSET (possibly 1). */
516extern rtx offset_address (rtx, rtx, unsigned HOST_WIDE_INT);
517
518/* Given REF, a MEM, and T, either the type of X or the expression
519 corresponding to REF, set the memory attributes. OBJECTP is nonzero
520 if we are making a new object of this type. */
521extern void set_mem_attributes (rtx, tree, int);
522
523/* Similar, except that BITPOS has not yet been applied to REF, so if
524 we alter MEM_OFFSET according to T then we should subtract BITPOS
525 expecting that it'll be added back in later. */
d05d7551 526extern void set_mem_attributes_minus_bitpos (rtx, tree, int, poly_int64);
36566b39
PK
527
528/* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN
529 bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or
530 -1 if not known. */
531extern int get_mem_align_offset (rtx, unsigned int);
532
533/* Return a memory reference like MEMREF, but with its mode widened to
534 MODE and adjusted by OFFSET. */
d05d7551 535extern rtx widen_memory_access (rtx, machine_mode, poly_int64);
36566b39 536
51b86113
DM
537extern void maybe_set_max_label_num (rtx_code_label *x);
538
78528714 539#endif /* GCC_EMIT_RTL_H */