2015-06-23 Paolo Carlini <paolo.carlini@oracle.com>
[official-gcc.git] / gcc / emit-rtl.h
blobcccb1acbdcb6515bfc44d0bd8053c436499b364f
1 /* Exported functions from emit-rtl.c
2 Copyright (C) 2004-2015 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
9 version.
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
14 for more details.
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
23 struct temp_slot;
24 typedef struct temp_slot *temp_slot_p;
26 /* Datastructures maintained for currently processed function in RTL form. */
27 struct GTY(()) rtl_data {
28 struct expr_status expr;
29 struct emit_status emit;
30 struct varasm_status varasm;
31 struct incoming_args args;
32 struct function_subsections subsections;
33 struct rtl_eh eh;
35 /* For function.c */
37 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
38 defined, the needed space is pushed by the prologue. */
39 int outgoing_args_size;
41 /* If nonzero, an RTL expression for the location at which the current
42 function returns its result. If the current function returns its
43 result in a register, current_function_return_rtx will always be
44 the hard register containing the result. */
45 rtx return_rtx;
46 /* If nonxero, an RTL expression for the lcoation at which the current
47 function returns bounds for its result. */
48 rtx return_bnd;
50 /* Vector of initial-value pairs. Each pair consists of a pseudo
51 register of approprite mode that stores the initial value a hard
52 register REGNO, and that hard register itself. */
53 /* ??? This could be a VEC but there is currently no way to define an
54 opaque VEC type. */
55 struct initial_value_struct *hard_reg_initial_vals;
57 /* A variable living at the top of the frame that holds a known value.
58 Used for detecting stack clobbers. */
59 tree stack_protect_guard;
61 /* List (chain of INSN_LIST) of labels heading the current handlers for
62 nonlocal gotos. */
63 rtx_insn_list *x_nonlocal_goto_handler_labels;
65 /* Label that will go on function epilogue.
66 Jumping to this label serves as a "return" instruction
67 on machines which require execution of the epilogue on all returns. */
68 rtx_code_label *x_return_label;
70 /* Label that will go on the end of function epilogue.
71 Jumping to this label serves as a "naked return" instruction
72 on machines which require execution of the epilogue on all returns. */
73 rtx_code_label *x_naked_return_label;
75 /* List (chain of EXPR_LISTs) of all stack slots in this function.
76 Made for the sake of unshare_all_rtl. */
77 rtx_expr_list *x_stack_slot_list;
79 /* List of empty areas in the stack frame. */
80 struct frame_space *frame_space_list;
82 /* Place after which to insert the tail_recursion_label if we need one. */
83 rtx_note *x_stack_check_probe_note;
85 /* Location at which to save the argument pointer if it will need to be
86 referenced. There are two cases where this is done: if nonlocal gotos
87 exist, or if vars stored at an offset from the argument pointer will be
88 needed by inner routines. */
89 rtx x_arg_pointer_save_area;
91 /* Dynamic Realign Argument Pointer used for realigning stack. */
92 rtx drap_reg;
94 /* Offset to end of allocated area of stack frame.
95 If stack grows down, this is the address of the last stack slot allocated.
96 If stack grows up, this is the address for the next slot. */
97 HOST_WIDE_INT x_frame_offset;
99 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
100 rtx_insn *x_parm_birth_insn;
102 /* List of all used temporaries allocated, by level. */
103 vec<temp_slot_p, va_gc> *x_used_temp_slots;
105 /* List of available temp slots. */
106 struct temp_slot *x_avail_temp_slots;
108 /* Current nesting level for temporaries. */
109 int x_temp_slot_level;
111 /* The largest alignment needed on the stack, including requirement
112 for outgoing stack alignment. */
113 unsigned int stack_alignment_needed;
115 /* Preferred alignment of the end of stack frame, which is preferred
116 to call other functions. */
117 unsigned int preferred_stack_boundary;
119 /* The minimum alignment of parameter stack. */
120 unsigned int parm_stack_boundary;
122 /* The largest alignment of slot allocated on the stack. */
123 unsigned int max_used_stack_slot_alignment;
125 /* The stack alignment estimated before reload, with consideration of
126 following factors:
127 1. Alignment of local stack variables (max_used_stack_slot_alignment)
128 2. Alignment requirement to call other functions
129 (preferred_stack_boundary)
130 3. Alignment of non-local stack variables but might be spilled in
131 local stack. */
132 unsigned int stack_alignment_estimated;
134 /* For reorg. */
136 /* Nonzero if function being compiled called builtin_return_addr or
137 builtin_frame_address with nonzero count. */
138 bool accesses_prior_frames;
140 /* Nonzero if the function calls __builtin_eh_return. */
141 bool calls_eh_return;
143 /* Nonzero if function saves all registers, e.g. if it has a nonlocal
144 label that can reach the exit block via non-exceptional paths. */
145 bool saves_all_registers;
147 /* Nonzero if function being compiled has nonlocal gotos to parent
148 function. */
149 bool has_nonlocal_goto;
151 /* Nonzero if function being compiled has an asm statement. */
152 bool has_asm_statement;
154 /* This bit is used by the exception handling logic. It is set if all
155 calls (if any) are sibling calls. Such functions do not have to
156 have EH tables generated, as they cannot throw. A call to such a
157 function, however, should be treated as throwing if any of its callees
158 can throw. */
159 bool all_throwers_are_sibcalls;
161 /* Nonzero if stack limit checking should be enabled in the current
162 function. */
163 bool limit_stack;
165 /* Nonzero if profiling code should be generated. */
166 bool profile;
168 /* Nonzero if the current function uses the constant pool. */
169 bool uses_const_pool;
171 /* Nonzero if the current function uses pic_offset_table_rtx. */
172 bool uses_pic_offset_table;
174 /* Nonzero if the current function needs an lsda for exception handling. */
175 bool uses_eh_lsda;
177 /* Set when the tail call has been produced. */
178 bool tail_call_emit;
180 /* Nonzero if code to initialize arg_pointer_save_area has been emitted. */
181 bool arg_pointer_save_area_init;
183 /* Nonzero if current function must be given a frame pointer.
184 Set in reload1.c or lra-eliminations.c if anything is allocated
185 on the stack there. */
186 bool frame_pointer_needed;
188 /* When set, expand should optimize for speed. */
189 bool maybe_hot_insn_p;
191 /* Nonzero if function stack realignment is needed. This flag may be
192 set twice: before and after reload. It is set before reload wrt
193 stack alignment estimation before reload. It will be changed after
194 reload if by then criteria of stack realignment is different.
195 The value set after reload is the accurate one and is finalized. */
196 bool stack_realign_needed;
198 /* Nonzero if function stack realignment is tried. This flag is set
199 only once before reload. It affects register elimination. This
200 is used to generate DWARF debug info for stack variables. */
201 bool stack_realign_tried;
203 /* Nonzero if function being compiled needs dynamic realigned
204 argument pointer (drap) if stack needs realigning. */
205 bool need_drap;
207 /* Nonzero if function stack realignment estimation is done, namely
208 stack_realign_needed flag has been set before reload wrt estimated
209 stack alignment info. */
210 bool stack_realign_processed;
212 /* Nonzero if function stack realignment has been finalized, namely
213 stack_realign_needed flag has been set and finalized after reload. */
214 bool stack_realign_finalized;
216 /* True if dbr_schedule has already been called for this function. */
217 bool dbr_scheduled_p;
219 /* True if current function can not throw. Unlike
220 TREE_NOTHROW (current_function_decl) it is set even for overwritable
221 function where currently compiled version of it is nothrow. */
222 bool nothrow;
224 /* True if we performed shrink-wrapping for the current function. */
225 bool shrink_wrapped;
227 /* Nonzero if function being compiled doesn't modify the stack pointer
228 (ignoring the prologue and epilogue). This is only valid after
229 pass_stack_ptr_mod has run. */
230 bool sp_is_unchanging;
232 /* Nonzero if function being compiled doesn't contain any calls
233 (ignoring the prologue and epilogue). This is set prior to
234 local register allocation and is valid for the remaining
235 compiler passes. */
236 bool is_leaf;
238 /* Nonzero if the function being compiled is a leaf function which only
239 uses leaf registers. This is valid after reload (specifically after
240 sched2) and is useful only if the port defines LEAF_REGISTERS. */
241 bool uses_only_leaf_regs;
243 /* Nonzero if the function being compiled has undergone hot/cold partitioning
244 (under flag_reorder_blocks_and_partition) and has at least one cold
245 block. */
246 bool has_bb_partition;
248 /* Nonzero if the function being compiled has completed the bb reordering
249 pass. */
250 bool bb_reorder_complete;
252 /* Like regs_ever_live, but 1 if a reg is set or clobbered from an
253 asm. Unlike regs_ever_live, elements of this array corresponding
254 to eliminable regs (like the frame pointer) are set if an asm
255 sets them. */
256 HARD_REG_SET asm_clobbers;
259 #define return_label (crtl->x_return_label)
260 #define naked_return_label (crtl->x_naked_return_label)
261 #define stack_slot_list (crtl->x_stack_slot_list)
262 #define parm_birth_insn (crtl->x_parm_birth_insn)
263 #define frame_offset (crtl->x_frame_offset)
264 #define stack_check_probe_note (crtl->x_stack_check_probe_note)
265 #define arg_pointer_save_area (crtl->x_arg_pointer_save_area)
266 #define used_temp_slots (crtl->x_used_temp_slots)
267 #define avail_temp_slots (crtl->x_avail_temp_slots)
268 #define temp_slot_level (crtl->x_temp_slot_level)
269 #define nonlocal_goto_handler_labels (crtl->x_nonlocal_goto_handler_labels)
270 #define frame_pointer_needed (crtl->frame_pointer_needed)
271 #define stack_realign_fp (crtl->stack_realign_needed && !crtl->need_drap)
272 #define stack_realign_drap (crtl->stack_realign_needed && crtl->need_drap)
274 extern GTY(()) struct rtl_data x_rtl;
276 /* Accessor to RTL datastructures. We keep them statically allocated now since
277 we never keep multiple functions. For threaded compiler we might however
278 want to do differently. */
279 #define crtl (&x_rtl)
281 /* Return whether two MEM_ATTRs are equal. */
282 bool mem_attrs_eq_p (const struct mem_attrs *, const struct mem_attrs *);
284 /* Set the alias set of MEM to SET. */
285 extern void set_mem_alias_set (rtx, alias_set_type);
287 /* Set the alignment of MEM to ALIGN bits. */
288 extern void set_mem_align (rtx, unsigned int);
290 /* Set the address space of MEM to ADDRSPACE. */
291 extern void set_mem_addr_space (rtx, addr_space_t);
293 /* Set the expr for MEM to EXPR. */
294 extern void set_mem_expr (rtx, tree);
296 /* Set the offset for MEM to OFFSET. */
297 extern void set_mem_offset (rtx, HOST_WIDE_INT);
299 /* Clear the offset recorded for MEM. */
300 extern void clear_mem_offset (rtx);
302 /* Set the size for MEM to SIZE. */
303 extern void set_mem_size (rtx, HOST_WIDE_INT);
305 /* Clear the size recorded for MEM. */
306 extern void clear_mem_size (rtx);
308 /* Set the attributes for MEM appropriate for a spill slot. */
309 extern void set_mem_attrs_for_spill (rtx);
310 extern tree get_spill_slot_decl (bool);
312 /* Return a memory reference like MEMREF, but with its address changed to
313 ADDR. The caller is asserting that the actual piece of memory pointed
314 to is the same, just the form of the address is being changed, such as
315 by putting something into a register. */
316 extern rtx replace_equiv_address (rtx, rtx, bool = false);
318 /* Likewise, but the reference is not required to be valid. */
319 extern rtx replace_equiv_address_nv (rtx, rtx, bool = false);
321 extern rtx gen_blockage (void);
322 extern rtvec gen_rtvec (int, ...);
323 extern rtx copy_insn_1 (rtx);
324 extern rtx copy_insn (rtx);
325 extern rtx_insn *copy_delay_slot_insn (rtx_insn *);
326 extern rtx gen_int_mode (HOST_WIDE_INT, machine_mode);
327 extern rtx_insn *emit_copy_of_insn_after (rtx_insn *, rtx_insn *);
328 extern void set_reg_attrs_from_value (rtx, rtx);
329 extern void set_reg_attrs_for_parm (rtx, rtx);
330 extern void set_reg_attrs_for_decl_rtl (tree t, rtx x);
331 extern void adjust_reg_mode (rtx, machine_mode);
332 extern int mem_expr_equal_p (const_tree, const_tree);
334 extern bool need_atomic_barrier_p (enum memmodel, bool);
336 /* Return the current sequence. */
338 static inline struct sequence_stack *
339 get_current_sequence (void)
341 return &crtl->emit.seq;
344 /* Return the outermost sequence. */
346 static inline struct sequence_stack *
347 get_topmost_sequence (void)
349 struct sequence_stack *seq, *top;
351 seq = get_current_sequence ();
354 top = seq;
355 seq = seq->next;
356 } while (seq);
357 return top;
360 /* Return the first insn of the current sequence or current function. */
362 static inline rtx_insn *
363 get_insns (void)
365 return get_current_sequence ()->first;
368 /* Specify a new insn as the first in the chain. */
370 static inline void
371 set_first_insn (rtx_insn *insn)
373 gcc_checking_assert (!insn || !PREV_INSN (insn));
374 get_current_sequence ()->first = insn;
377 /* Return the last insn emitted in current sequence or current function. */
379 static inline rtx_insn *
380 get_last_insn (void)
382 return get_current_sequence ()->last;
385 /* Specify a new insn as the last in the chain. */
387 static inline void
388 set_last_insn (rtx_insn *insn)
390 gcc_checking_assert (!insn || !NEXT_INSN (insn));
391 get_current_sequence ()->last = insn;
394 /* Return a number larger than any instruction's uid in this function. */
396 static inline int
397 get_max_uid (void)
399 return crtl->emit.x_cur_insn_uid;
402 extern void set_decl_incoming_rtl (tree, rtx, bool);
404 /* Return a memory reference like MEMREF, but with its mode changed
405 to MODE and its address changed to ADDR.
406 (VOIDmode means don't change the mode.
407 NULL for ADDR means don't change the address.) */
408 extern rtx change_address (rtx, machine_mode, rtx);
410 /* Return a memory reference like MEMREF, but with its mode changed
411 to MODE and its address offset by OFFSET bytes. */
412 #define adjust_address(MEMREF, MODE, OFFSET) \
413 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 0, 0)
415 /* Likewise, but the reference is not required to be valid. */
416 #define adjust_address_nv(MEMREF, MODE, OFFSET) \
417 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 0, 0)
419 /* Return a memory reference like MEMREF, but with its mode changed
420 to MODE and its address offset by OFFSET bytes. Assume that it's
421 for a bitfield and conservatively drop the underlying object if we
422 cannot be sure to stay within its bounds. */
423 #define adjust_bitfield_address(MEMREF, MODE, OFFSET) \
424 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, 0)
426 /* As for adjust_bitfield_address, but specify that the width of
427 BLKmode accesses is SIZE bytes. */
428 #define adjust_bitfield_address_size(MEMREF, MODE, OFFSET, SIZE) \
429 adjust_address_1 (MEMREF, MODE, OFFSET, 1, 1, 1, SIZE)
431 /* Likewise, but the reference is not required to be valid. */
432 #define adjust_bitfield_address_nv(MEMREF, MODE, OFFSET) \
433 adjust_address_1 (MEMREF, MODE, OFFSET, 0, 1, 1, 0)
435 /* Return a memory reference like MEMREF, but with its mode changed
436 to MODE and its address changed to ADDR, which is assumed to be
437 increased by OFFSET bytes from MEMREF. */
438 #define adjust_automodify_address(MEMREF, MODE, ADDR, OFFSET) \
439 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 1)
441 /* Likewise, but the reference is not required to be valid. */
442 #define adjust_automodify_address_nv(MEMREF, MODE, ADDR, OFFSET) \
443 adjust_automodify_address_1 (MEMREF, MODE, ADDR, OFFSET, 0)
445 extern rtx adjust_address_1 (rtx, machine_mode, HOST_WIDE_INT, int, int,
446 int, HOST_WIDE_INT);
447 extern rtx adjust_automodify_address_1 (rtx, machine_mode, rtx,
448 HOST_WIDE_INT, int);
450 /* Return a memory reference like MEMREF, but whose address is changed by
451 adding OFFSET, an RTX, to it. POW2 is the highest power of two factor
452 known to be in OFFSET (possibly 1). */
453 extern rtx offset_address (rtx, rtx, unsigned HOST_WIDE_INT);
455 /* Given REF, a MEM, and T, either the type of X or the expression
456 corresponding to REF, set the memory attributes. OBJECTP is nonzero
457 if we are making a new object of this type. */
458 extern void set_mem_attributes (rtx, tree, int);
460 /* Similar, except that BITPOS has not yet been applied to REF, so if
461 we alter MEM_OFFSET according to T then we should subtract BITPOS
462 expecting that it'll be added back in later. */
463 extern void set_mem_attributes_minus_bitpos (rtx, tree, int, HOST_WIDE_INT);
465 /* Return OFFSET if XEXP (MEM, 0) - OFFSET is known to be ALIGN
466 bits aligned for 0 <= OFFSET < ALIGN / BITS_PER_UNIT, or
467 -1 if not known. */
468 extern int get_mem_align_offset (rtx, unsigned int);
470 /* Return a memory reference like MEMREF, but with its mode widened to
471 MODE and adjusted by OFFSET. */
472 extern rtx widen_memory_access (rtx, machine_mode, HOST_WIDE_INT);
474 #endif /* GCC_EMIT_RTL_H */