1 /* Exported functions from emit-rtl.c
2 Copyright (C) 2004-2019 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_EMIT_RTL_H
21 #define GCC_EMIT_RTL_H
24 typedef class temp_slot
*temp_slot_p
;
26 /* Information mainlined about RTL representation of incoming arguments. */
27 struct GTY(()) incoming_args
{
28 /* Number of bytes of args popped by function being compiled on its return.
29 Zero if no bytes are to be popped.
30 May affect compilation of return insn or of function epilogue. */
31 poly_int64_pod pops_args
;
33 /* If function's args have a fixed size, this is that size, in bytes.
35 May affect compilation of return insn or of function epilogue. */
38 /* # bytes the prologue should push and pretend that the caller pushed them.
39 The prologue must do this, but only if parms can be passed in
41 int pretend_args_size
;
43 /* This is the offset from the arg pointer to the place where the first
44 anonymous arg can be found, if there is one. */
47 /* Quantities of various kinds of registers
48 used for the current function's args. */
51 /* The arg pointer hard register, or the pseudo into which it was copied. */
52 rtx internal_arg_pointer
;
56 /* Datastructures maintained for currently processed function in RTL form. */
57 struct GTY(()) rtl_data
{
58 void init_stack_alignment ();
60 struct expr_status expr
;
61 struct emit_status emit
;
62 struct varasm_status varasm
;
63 struct incoming_args args
;
64 struct function_subsections subsections
;
69 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
70 defined, the needed space is pushed by the prologue. */
71 poly_int64_pod outgoing_args_size
;
73 /* If nonzero, an RTL expression for the location at which the current
74 function returns its result. If the current function returns its
75 result in a register, current_function_return_rtx will always be
76 the hard register containing the result. */
79 /* Vector of initial-value pairs. Each pair consists of a pseudo
80 register of approprite mode that stores the initial value a hard
81 register REGNO, and that hard register itself. */
82 /* ??? This could be a VEC but there is currently no way to define an
84 struct initial_value_struct
*hard_reg_initial_vals
;
86 /* A variable living at the top of the frame that holds a known value.
87 Used for detecting stack clobbers. */
88 tree stack_protect_guard
;
90 /* The __stack_chk_guard variable or expression holding the stack
91 protector canary value. */
92 tree stack_protect_guard_decl
;
94 /* List (chain of INSN_LIST) of labels heading the current handlers for
96 rtx_insn_list
*x_nonlocal_goto_handler_labels
;
98 /* Label that will go on function epilogue.
99 Jumping to this label serves as a "return" instruction
100 on machines which require execution of the epilogue on all returns. */
101 rtx_code_label
*x_return_label
;
103 /* Label that will go on the end of function epilogue.
104 Jumping to this label serves as a "naked return" instruction
105 on machines which require execution of the epilogue on all returns. */
106 rtx_code_label
*x_naked_return_label
;
108 /* List (chain of EXPR_LISTs) of all stack slots in this function.
109 Made for the sake of unshare_all_rtl. */
110 vec
<rtx
, va_gc
> *x_stack_slot_list
;
112 /* List of empty areas in the stack frame. */
113 class frame_space
*frame_space_list
;
115 /* Place after which to insert the tail_recursion_label if we need one. */
116 rtx_note
*x_stack_check_probe_note
;
118 /* Location at which to save the argument pointer if it will need to be
119 referenced. There are two cases where this is done: if nonlocal gotos
120 exist, or if vars stored at an offset from the argument pointer will be
121 needed by inner routines. */
122 rtx x_arg_pointer_save_area
;
124 /* Dynamic Realign Argument Pointer used for realigning stack. */
127 /* Offset to end of allocated area of stack frame.
128 If stack grows down, this is the address of the last stack slot allocated.
129 If stack grows up, this is the address for the next slot. */
130 poly_int64_pod x_frame_offset
;
132 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
133 rtx_insn
*x_parm_birth_insn
;
135 /* List of all used temporaries allocated, by level. */
136 vec
<temp_slot_p
, va_gc
> *x_used_temp_slots
;
138 /* List of available temp slots. */
139 class temp_slot
*x_avail_temp_slots
;
141 /* Current nesting level for temporaries. */
142 int x_temp_slot_level
;
144 /* The largest alignment needed on the stack, including requirement
145 for outgoing stack alignment. */
146 unsigned int stack_alignment_needed
;
148 /* Preferred alignment of the end of stack frame, which is preferred
149 to call other functions. */
150 unsigned int preferred_stack_boundary
;
152 /* The minimum alignment of parameter stack. */
153 unsigned int parm_stack_boundary
;
155 /* The largest alignment of slot allocated on the stack. */
156 unsigned int max_used_stack_slot_alignment
;
158 /* The stack alignment estimated before reload, with consideration of
160 1. Alignment of local stack variables (max_used_stack_slot_alignment)
161 2. Alignment requirement to call other functions
162 (preferred_stack_boundary)
163 3. Alignment of non-local stack variables but might be spilled in
165 unsigned int stack_alignment_estimated
;
169 /* Nonzero if function being compiled called builtin_return_addr or
170 builtin_frame_address with nonzero count. */
171 bool accesses_prior_frames
;
173 /* Nonzero if the function calls __builtin_eh_return. */
174 bool calls_eh_return
;
176 /* Nonzero if function saves all registers, e.g. if it has a nonlocal
177 label that can reach the exit block via non-exceptional paths. */
178 bool saves_all_registers
;
180 /* Nonzero if function being compiled has nonlocal gotos to parent
182 bool has_nonlocal_goto
;
184 /* Nonzero if function being compiled has an asm statement. */
185 bool has_asm_statement
;
187 /* This bit is used by the exception handling logic. It is set if all
188 calls (if any) are sibling calls. Such functions do not have to
189 have EH tables generated, as they cannot throw. A call to such a
190 function, however, should be treated as throwing if any of its callees
192 bool all_throwers_are_sibcalls
;
194 /* Nonzero if stack limit checking should be enabled in the current
198 /* Nonzero if profiling code should be generated. */
201 /* Nonzero if the current function uses the constant pool. */
202 bool uses_const_pool
;
204 /* Nonzero if the current function uses pic_offset_table_rtx. */
205 bool uses_pic_offset_table
;
207 /* Nonzero if the current function needs an lsda for exception handling. */
210 /* Set when the tail call has been produced. */
213 /* Nonzero if code to initialize arg_pointer_save_area has been emitted. */
214 bool arg_pointer_save_area_init
;
216 /* Nonzero if current function must be given a frame pointer.
217 Set in reload1.c or lra-eliminations.c if anything is allocated
218 on the stack there. */
219 bool frame_pointer_needed
;
221 /* When set, expand should optimize for speed. */
222 bool maybe_hot_insn_p
;
224 /* Nonzero if function stack realignment is needed. This flag may be
225 set twice: before and after reload. It is set before reload wrt
226 stack alignment estimation before reload. It will be changed after
227 reload if by then criteria of stack realignment is different.
228 The value set after reload is the accurate one and is finalized. */
229 bool stack_realign_needed
;
231 /* Nonzero if function stack realignment is tried. This flag is set
232 only once before reload. It affects register elimination. This
233 is used to generate DWARF debug info for stack variables. */
234 bool stack_realign_tried
;
236 /* Nonzero if function being compiled needs dynamic realigned
237 argument pointer (drap) if stack needs realigning. */
240 /* Nonzero if function stack realignment estimation is done, namely
241 stack_realign_needed flag has been set before reload wrt estimated
242 stack alignment info. */
243 bool stack_realign_processed
;
245 /* Nonzero if function stack realignment has been finalized, namely
246 stack_realign_needed flag has been set and finalized after reload. */
247 bool stack_realign_finalized
;
249 /* True if dbr_schedule has already been called for this function. */
250 bool dbr_scheduled_p
;
252 /* True if current function cannot throw. Unlike
253 TREE_NOTHROW (current_function_decl) it is set even for overwritable
254 function where currently compiled version of it is nothrow. */
257 /* True if we performed shrink-wrapping for the current function. */
260 /* True if we performed shrink-wrapping for separate components for
261 the current function. */
262 bool shrink_wrapped_separate
;
264 /* Nonzero if function being compiled doesn't modify the stack pointer
265 (ignoring the prologue and epilogue). This is only valid after
266 pass_stack_ptr_mod has run. */
267 bool sp_is_unchanging
;
269 /* Nonzero if function being compiled doesn't contain any calls
270 (ignoring the prologue and epilogue). This is set prior to
271 register allocation in IRA and is valid for the remaining
275 /* Nonzero if the function being compiled is a leaf function which only
276 uses leaf registers. This is valid after reload (specifically after
277 sched2) and is useful only if the port defines LEAF_REGISTERS. */
278 bool uses_only_leaf_regs
;
280 /* Nonzero if the function being compiled has undergone hot/cold partitioning
281 (under flag_reorder_blocks_and_partition) and has at least one cold
283 bool has_bb_partition
;
285 /* Nonzero if the function being compiled has completed the bb reordering
287 bool bb_reorder_complete
;
289 /* Like regs_ever_live, but 1 if a reg is set or clobbered from an
290 asm. Unlike regs_ever_live, elements of this array corresponding
291 to eliminable regs (like the frame pointer) are set if an asm
293 HARD_REG_SET asm_clobbers
;
295 /* The highest address seen during shorten_branches. */
296 int max_insn_address
;
299 #define return_label (crtl->x_return_label)
300 #define naked_return_label (crtl->x_naked_return_label)
301 #define stack_slot_list (crtl->x_stack_slot_list)
302 #define parm_birth_insn (crtl->x_parm_birth_insn)
303 #define frame_offset (crtl->x_frame_offset)
304 #define stack_check_probe_note (crtl->x_stack_check_probe_note)
305 #define arg_pointer_save_area (crtl->x_arg_pointer_save_area)
306 #define used_temp_slots (crtl->x_used_temp_slots)
307 #define avail_temp_slots (crtl->x_avail_temp_slots)
308 #define temp_slot_level (crtl->x_temp_slot_level)
309 #define nonlocal_goto_handler_labels (crtl->x_nonlocal_goto_handler_labels)
310 #define frame_pointer_needed (crtl->frame_pointer_needed)
311 #define stack_realign_fp (crtl->stack_realign_needed && !crtl->need_drap)
312 #define stack_realign_drap (crtl->stack_realign_needed && crtl->need_drap)
314 extern GTY(()) struct rtl_data x_rtl
;
316 /* Accessor to RTL datastructures. We keep them statically allocated now since
317 we never keep multiple functions. For threaded compiler we might however
318 want to do differently. */
319 #define crtl (&x_rtl)
321 /* Return whether two MEM_ATTRs are equal. */
322 bool mem_attrs_eq_p (const class mem_attrs
*, const class mem_attrs
*);
324 /* Set the alias set of MEM to SET. */
325 extern void set_mem_alias_set (rtx
, alias_set_type
);
327 /* Set the alignment of MEM to ALIGN bits. */
328 extern void set_mem_align (rtx
, unsigned int);
330 /* Set the address space of MEM to ADDRSPACE. */
331 extern void set_mem_addr_space (rtx
, addr_space_t
);
333 /* Set the expr for MEM to EXPR. */
334 extern void set_mem_expr (rtx
, tree
);
336 /* Set the offset for MEM to OFFSET. */
337 extern void set_mem_offset (rtx
, poly_int64
);
339 /* Clear the offset recorded for MEM. */
340 extern void clear_mem_offset (rtx
);
342 /* Set the size for MEM to SIZE. */
343 extern void set_mem_size (rtx
, poly_int64
);
345 /* Clear the size recorded for MEM. */
346 extern void clear_mem_size (rtx
);
348 /* Set the attributes for MEM appropriate for a spill slot. */
349 extern void set_mem_attrs_for_spill (rtx
);
350 extern tree
get_spill_slot_decl (bool);
352 /* Return a memory reference like MEMREF, but with its address changed to
353 ADDR. The caller is asserting that the actual piece of memory pointed
354 to is the same, just the form of the address is being changed, such as
355 by putting something into a register. */
356 extern rtx
replace_equiv_address (rtx
, rtx
, bool = false);
358 /* Likewise, but the reference is not required to be valid. */
359 extern rtx
replace_equiv_address_nv (rtx
, rtx
, bool = false);
361 extern rtx
gen_blockage (void);
362 extern rtvec
gen_rtvec (int, ...);
363 extern rtx
copy_insn_1 (rtx
);
364 extern rtx
copy_insn (rtx
);
365 extern rtx_insn
*copy_delay_slot_insn (rtx_insn
*);
366 extern rtx
gen_int_mode (poly_int64
, machine_mode
);
367 extern rtx_insn
*emit_copy_of_insn_after (rtx_insn
*, rtx_insn
*);
368 extern void set_reg_attrs_from_value (rtx
, rtx
);
369 extern void set_reg_attrs_for_parm (rtx
, rtx
);
370 extern void set_reg_attrs_for_decl_rtl (tree t
, rtx x
);
371 extern void adjust_reg_mode (rtx
, machine_mode
);
372 extern int mem_expr_equal_p (const_tree
, const_tree
);
373 extern rtx
gen_int_shift_amount (machine_mode
, poly_int64
);
375 extern bool need_atomic_barrier_p (enum memmodel
, bool);
377 /* Return the current sequence. */
379 static inline struct sequence_stack
*
380 get_current_sequence (void)
382 return &crtl
->emit
.seq
;
385 /* Return the outermost sequence. */
387 static inline struct sequence_stack
*
388 get_topmost_sequence (void)
390 struct sequence_stack
*seq
, *top
;
392 seq
= get_current_sequence ();
401 /* Return the first insn of the current sequence or current function. */
403 static inline rtx_insn
*
406 return get_current_sequence ()->first
;
409 /* Specify a new insn as the first in the chain. */
412 set_first_insn (rtx_insn
*insn
)
414 gcc_checking_assert (!insn
|| !PREV_INSN (insn
));
415 get_current_sequence ()->first
= insn
;
418 /* Return the last insn emitted in current sequence or current function. */
420 static inline rtx_insn
*
423 return get_current_sequence ()->last
;
426 /* Specify a new insn as the last in the chain. */
429 set_last_insn (rtx_insn
*insn
)
431 gcc_checking_assert (!insn
|| !NEXT_INSN (insn
));
432 get_current_sequence ()->last
= insn
;
435 /* Return a number larger than any instruction's uid in this function. */
440 return crtl
->emit
.x_cur_insn_uid
;
443 extern bool valid_for_const_vector_p (machine_mode
, rtx
);
444 extern rtx
gen_const_vec_duplicate (machine_mode
, rtx
);
445 extern rtx
gen_vec_duplicate (machine_mode
, rtx
);
447 extern rtx
gen_const_vec_series (machine_mode
, rtx
, rtx
);
448 extern rtx
gen_vec_series (machine_mode
, rtx
, rtx
);
450 extern void set_decl_incoming_rtl (tree
, rtx
, bool);
452 /* Return a memory reference like MEMREF, but with its mode changed
453 to MODE and its address changed to ADDR.
454 (VOIDmode means don't change the mode.
455 NULL for ADDR means don't change the address.) */
456 extern rtx
change_address (rtx
, machine_mode
, rtx
);
458 /* Return a memory reference like MEMREF, but with its mode changed
459 to MODE and its address offset by OFFSET bytes. */
460 #define adjust_address(MEMREF, MODE, OFFSET) \
461 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 0, 0)
463 /* Likewise, but the reference is not required to be valid. */
464 #define adjust_address_nv(MEMREF, MODE, OFFSET) \
465 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 0, 0)
467 /* Return a memory reference like MEMREF, but with its mode changed
468 to MODE and its address offset by OFFSET bytes. Assume that it's
469 for a bitfield and conservatively drop the underlying object if we
470 cannot be sure to stay within its bounds. */
471 #define adjust_bitfield_address(MEMREF, MODE, OFFSET) \
472 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, 0)
474 /* As for adjust_bitfield_address, but specify that the width of
475 BLKmode accesses is SIZE bytes. */
476 #define adjust_bitfield_address_size(MEMREF, MODE, OFFSET, SIZE) \
477 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, SIZE)
479 /* Likewise, but the reference is not required to be valid. */
480 #define adjust_bitfield_address_nv(MEMREF, MODE, OFFSET) \
481 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 1, 0)
483 /* Return a memory reference like MEMREF, but with its mode changed
484 to MODE and its address changed to ADDR, which is assumed to be
485 increased by OFFSET bytes from MEMREF. */
486 #define adjust_automodify_address(MEMREF, MODE, ADDR, OFFSET) \
487 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 1)
489 /* Likewise, but the reference is not required to be valid. */
490 #define adjust_automodify_address_nv(MEMREF, MODE, ADDR, OFFSET) \
491 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 0)
493 extern rtx
adjust_address_1 (rtx
, machine_mode
, poly_int64
, int, int,
495 extern rtx
adjust_automodify_address_1 (rtx
, machine_mode
, rtx
,
498 /* Return a memory reference like MEMREF, but whose address is changed by
499 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
500 known to be in OFFSET (possibly 1). */
501 extern rtx
offset_address (rtx
, rtx
, unsigned HOST_WIDE_INT
);
503 /* Given REF, a MEM, and T, either the type of X or the expression
504 corresponding to REF, set the memory attributes. OBJECTP is nonzero
505 if we are making a new object of this type. */
506 extern void set_mem_attributes (rtx
, tree
, int);
508 /* Similar, except that BITPOS has not yet been applied to REF, so if
509 we alter MEM_OFFSET according to T then we should subtract BITPOS
510 expecting that it'll be added back in later. */
511 extern void set_mem_attributes_minus_bitpos (rtx
, tree
, int, poly_int64
);
513 /* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN
514 bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or
516 extern int get_mem_align_offset (rtx
, unsigned int);
518 /* Return a memory reference like MEMREF, but with its mode widened to
519 MODE and adjusted by OFFSET. */
520 extern rtx
widen_memory_access (rtx
, machine_mode
, poly_int64
);
522 extern void maybe_set_max_label_num (rtx_code_label
*x
);
524 #endif /* GCC_EMIT_RTL_H */