1 /* Structure for saving state for a nested function.
2 Copyright (C) 1989-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
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_FUNCTION_H
21 #define GCC_FUNCTION_H
24 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
25 Each element describes one pending sequence.
26 The main insn-chain is saved in the last element of the chain,
27 unless the chain is empty. */
29 struct GTY(()) sequence_stack
{
30 /* First and last insns in the chain of the saved sequence. */
33 struct sequence_stack
*next
;
36 struct GTY(()) emit_status
{
37 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
38 After rtl generation, it is 1 plus the largest register number used. */
41 /* Lowest label number in current function. */
42 int x_first_label_num
;
44 /* seq.first and seq.last are the ends of the doubly-linked chain of
45 rtl for the current function. Both are reset to null at the
46 start of rtl generation for the function.
48 start_sequence saves both of these on seq.next and then starts
49 a new, nested sequence of insns.
51 seq.next is a stack of pending (incomplete) sequences saved by
52 start_sequence. Each element describes one pending sequence.
53 The main insn-chain is the last element of the chain. */
54 struct sequence_stack seq
;
56 /* INSN_UID for next insn emitted.
57 Reset to 1 for each function compiled. */
60 /* INSN_UID for next debug insn emitted. Only used if
61 --param min-nondebug-insn-uid=<value> is given with nonzero value. */
62 int x_cur_debug_insn_uid
;
64 /* The length of the regno_pointer_align, regno_decl, and x_regno_reg_rtx
65 vectors. Since these vectors are needed during the expansion phase when
66 the total number of registers in the function is not yet known, the
67 vectors are copied and made bigger when necessary. */
68 int regno_pointer_align_length
;
70 /* Indexed by pseudo register number, if nonzero gives the known alignment
71 for that pseudo (if REG_POINTER is set in x_regno_reg_rtx).
72 Allocated in parallel with x_regno_reg_rtx. */
73 unsigned char * GTY((skip
)) regno_pointer_align
;
77 /* Indexed by register number, gives an rtx for that register (and only
78 that register). For pseudo registers, it is the unique rtx for
79 that pseudo. For hard registers, it is an rtx of the mode specified
82 FIXME: We could put it into emit_status struct, but gengtype is not
83 able to deal with length attribute nested in top level structures. */
85 extern GTY ((length ("crtl->emit.x_reg_rtx_no"))) rtx
* regno_reg_rtx
;
87 /* For backward compatibility... eventually these should all go away. */
88 #define reg_rtx_no (crtl->emit.x_reg_rtx_no)
90 #define REGNO_POINTER_ALIGN(REGNO) (crtl->emit.regno_pointer_align[REGNO])
92 struct GTY(()) expr_status
{
93 /* Number of units that we should eventually pop off the stack.
94 These are the arguments to function calls that have already returned. */
95 int x_pending_stack_adjust
;
97 /* Under some ABIs, it is the caller's responsibility to pop arguments
98 pushed for function calls. A naive implementation would simply pop
99 the arguments immediately after each call. However, if several
100 function calls are made in a row, it is typically cheaper to pop
101 all the arguments after all of the calls are complete since a
102 single pop instruction can be used. Therefore, GCC attempts to
103 defer popping the arguments until absolutely necessary. (For
104 example, at the end of a conditional, the arguments must be popped,
105 since code outside the conditional won't know whether or not the
106 arguments need to be popped.)
108 When INHIBIT_DEFER_POP is nonzero, however, the compiler does not
109 attempt to defer pops. Instead, the stack is popped immediately
110 after each call. Rather then setting this variable directly, use
111 NO_DEFER_POP and OK_DEFER_POP. */
112 int x_inhibit_defer_pop
;
114 /* If PREFERRED_STACK_BOUNDARY and PUSH_ROUNDING are defined, the stack
115 boundary can be momentarily unaligned while pushing the arguments.
116 Record the delta since last aligned boundary here in order to get
117 stack alignment in the nested function calls working right. */
118 int x_stack_pointer_delta
;
120 /* Nonzero means __builtin_saveregs has already been done in this function.
121 The value is the pseudoreg containing the value __builtin_saveregs
123 rtx x_saveregs_value
;
125 /* Similarly for __builtin_apply_args. */
126 rtx x_apply_args_value
;
128 /* List of labels that must never be deleted. */
129 rtx_insn_list
*x_forced_labels
;
132 typedef struct call_site_record_d
*call_site_record
;
134 /* RTL representation of exception handling. */
135 struct GTY(()) rtl_eh
{
138 rtx_code_label
*ehr_label
;
141 rtx_insn
*sjlj_exit_after
;
143 vec
<uchar
, va_gc
> *action_record_data
;
145 vec
<call_site_record
, va_gc
> *call_site_record_v
[2];
148 #define pending_stack_adjust (crtl->expr.x_pending_stack_adjust)
149 #define inhibit_defer_pop (crtl->expr.x_inhibit_defer_pop)
150 #define saveregs_value (crtl->expr.x_saveregs_value)
151 #define apply_args_value (crtl->expr.x_apply_args_value)
152 #define forced_labels (crtl->expr.x_forced_labels)
153 #define stack_pointer_delta (crtl->expr.x_stack_pointer_delta)
156 struct call_site_record_d
;
159 class ipa_opt_pass_d
;
160 typedef ipa_opt_pass_d
*ipa_opt_pass
;
163 struct GTY(()) varasm_status
{
164 /* If we're using a per-function constant pool, this is it. */
165 struct rtx_constant_pool
*pool
;
167 /* Number of tree-constants deferred during the expansion of this
169 unsigned int deferred_constants
;
172 /* Information mainlined about RTL representation of incoming arguments. */
173 struct GTY(()) incoming_args
{
174 /* Number of bytes of args popped by function being compiled on its return.
175 Zero if no bytes are to be popped.
176 May affect compilation of return insn or of function epilogue. */
179 /* If function's args have a fixed size, this is that size, in bytes.
181 May affect compilation of return insn or of function epilogue. */
184 /* # bytes the prologue should push and pretend that the caller pushed them.
185 The prologue must do this, but only if parms can be passed in
187 int pretend_args_size
;
189 /* This is the offset from the arg pointer to the place where the first
190 anonymous arg can be found, if there is one. */
193 /* Quantities of various kinds of registers
194 used for the current function's args. */
195 CUMULATIVE_ARGS info
;
197 /* The arg pointer hard register, or the pseudo into which it was copied. */
198 rtx internal_arg_pointer
;
201 /* Data for function partitioning. */
202 struct GTY(()) function_subsections
{
203 /* Assembly labels for the hot and cold text sections, to
204 be used by debugger functions for determining the size of text
207 const char *hot_section_label
;
208 const char *cold_section_label
;
209 const char *hot_section_end_label
;
210 const char *cold_section_end_label
;
213 /* Describe an empty area of space in the stack frame. These can be chained
214 into a list; this is used to keep track of space wasted for alignment
216 struct GTY(()) frame_space
218 struct frame_space
*next
;
221 HOST_WIDE_INT length
;
224 struct GTY(()) stack_usage
226 /* # of bytes of static stack space allocated by the function. */
227 HOST_WIDE_INT static_stack_size
;
229 /* # of bytes of dynamic stack space allocated by the function. This is
230 meaningful only if has_unbounded_dynamic_stack_size is zero. */
231 HOST_WIDE_INT dynamic_stack_size
;
233 /* # of bytes of space pushed onto the stack after the prologue. If
234 !ACCUMULATE_OUTGOING_ARGS, it contains the outgoing arguments. */
235 int pushed_stack_size
;
237 /* Nonzero if the amount of stack space allocated dynamically cannot
238 be bounded at compile-time. */
239 unsigned int has_unbounded_dynamic_stack_size
: 1;
242 #define current_function_static_stack_size (cfun->su->static_stack_size)
243 #define current_function_dynamic_stack_size (cfun->su->dynamic_stack_size)
244 #define current_function_pushed_stack_size (cfun->su->pushed_stack_size)
245 #define current_function_has_unbounded_dynamic_stack_size \
246 (cfun->su->has_unbounded_dynamic_stack_size)
247 #define current_function_allocates_dynamic_stack_space \
248 (current_function_dynamic_stack_size != 0 \
249 || current_function_has_unbounded_dynamic_stack_size)
251 /* This structure can save all the important global and static variables
252 describing the status of the current function. */
254 struct GTY(()) function
{
255 struct eh_status
*eh
;
257 /* The control flow graph for this function. */
258 struct control_flow_graph
*cfg
;
260 /* GIMPLE body for this function. */
261 gimple_seq gimple_body
;
263 /* SSA and dataflow information. */
264 struct gimple_df
*gimple_df
;
266 /* The loops in this function. */
267 struct loops
*x_current_loops
;
269 /* The stack usage of this function. */
270 struct stack_usage
*su
;
272 /* Value histograms attached to particular statements. */
273 htab_t
GTY((skip
)) value_histograms
;
275 /* For function.c. */
277 /* Points to the FUNCTION_DECL of this function. */
280 /* A PARM_DECL that should contain the static chain for this function.
281 It will be initialized at the beginning of the function. */
282 tree static_chain_decl
;
284 /* An expression that contains the non-local goto save area. The first
285 word is the saved frame pointer and the second is the saved stack
287 tree nonlocal_goto_save_area
;
289 /* Vector of function local variables, functions, types and constants. */
290 vec
<tree
, va_gc
> *local_decls
;
292 /* In a Cilk function, the VAR_DECL for the frame descriptor. */
293 tree cilk_frame_decl
;
297 /* tm.h can use this to store whatever it likes. */
298 struct machine_function
* GTY ((maybe_undef
)) machine
;
300 /* Language-specific code can use this to store whatever it likes. */
301 struct language_function
* language
;
303 /* Used types hash table. */
304 hash_set
<tree
> *GTY (()) used_types_hash
;
306 /* Dwarf2 Frame Description Entry, containing the Call Frame Instructions
307 used for unwinding. Only set when either dwarf2 unwinding or dwarf2
308 debugging is enabled. */
309 struct dw_fde_node
*fde
;
311 /* Last statement uid. */
314 /* Function sequence number for profiling, debugging, etc. */
317 /* Line number of the start of the function for debugging purposes. */
318 location_t function_start_locus
;
320 /* Line number of the end of the function. */
321 location_t function_end_locus
;
323 /* Properties used by the pass manager. */
324 unsigned int curr_properties
;
325 unsigned int last_verified
;
327 /* Non-null if the function does something that would prevent it from
328 being copied; this applies to both versioning and inlining. Set to
329 a string describing the reason for failure. */
330 const char * GTY((skip
)) cannot_be_copied_reason
;
332 /* Last assigned dependence info clique. */
333 unsigned short last_clique
;
335 /* Collected bit flags. */
337 /* Number of units of general registers that need saving in stdarg
338 function. What unit is depends on the backend, either it is number
339 of bytes, or it can be number of registers. */
340 unsigned int va_list_gpr_size
: 8;
342 /* Number of units of floating point registers that need saving in stdarg
344 unsigned int va_list_fpr_size
: 8;
346 /* Nonzero if function being compiled can call setjmp. */
347 unsigned int calls_setjmp
: 1;
349 /* Nonzero if function being compiled can call alloca,
350 either as a subroutine or builtin. */
351 unsigned int calls_alloca
: 1;
353 /* This will indicate whether a function is a cilk function */
354 unsigned int is_cilk_function
: 1;
356 /* Nonzero if this is a Cilk function that spawns. */
357 unsigned int calls_cilk_spawn
: 1;
359 /* Nonzero if function being compiled receives nonlocal gotos
360 from nested functions. */
361 unsigned int has_nonlocal_label
: 1;
363 /* Nonzero if we've set cannot_be_copied_reason. I.e. if
364 (cannot_be_copied_set && !cannot_be_copied_reason), the function
365 can in fact be copied. */
366 unsigned int cannot_be_copied_set
: 1;
368 /* Nonzero if current function uses stdarg.h or equivalent. */
369 unsigned int stdarg
: 1;
371 unsigned int after_inlining
: 1;
372 unsigned int always_inline_functions_inlined
: 1;
374 /* Nonzero if function being compiled can throw synchronous non-call
376 unsigned int can_throw_non_call_exceptions
: 1;
378 /* Nonzero if instructions that may throw exceptions but don't otherwise
379 contribute to the execution of the program can be deleted. */
380 unsigned int can_delete_dead_exceptions
: 1;
382 /* Fields below this point are not set for abstract functions; see
383 allocate_struct_function. */
385 /* Nonzero if function being compiled needs to be given an address
386 where the value should be stored. */
387 unsigned int returns_struct
: 1;
389 /* Nonzero if function being compiled needs to
390 return the address of where it has put a structure value. */
391 unsigned int returns_pcc_struct
: 1;
393 /* Nonzero if this function has local DECL_HARD_REGISTER variables.
394 In this case code motion has to be done more carefully. */
395 unsigned int has_local_explicit_reg_vars
: 1;
397 /* Nonzero if the current function is a thunk, i.e., a lightweight
398 function implemented by the output_mi_thunk hook) that just
399 adjusts one of its arguments and forwards to another
401 unsigned int is_thunk
: 1;
403 /* Nonzero if the current function contains any loops with
404 loop->force_vectorize set. */
405 unsigned int has_force_vectorize_loops
: 1;
407 /* Nonzero if the current function contains any loops with
408 nonzero value in loop->simduid. */
409 unsigned int has_simduid_loops
: 1;
411 /* Set when the tail call has been identified. */
412 unsigned int tail_call_marked
: 1;
415 /* Add the decl D to the local_decls list of FUN. */
417 void add_local_decl (struct function
*fun
, tree d
);
419 #define FOR_EACH_LOCAL_DECL(FUN, I, D) \
420 FOR_EACH_VEC_SAFE_ELT_REVERSE ((FUN)->local_decls, I, D)
422 /* If va_list_[gf]pr_size is set to this, it means we don't know how
423 many units need to be saved. */
424 #define VA_LIST_MAX_GPR_SIZE 255
425 #define VA_LIST_MAX_FPR_SIZE 255
427 /* The function currently being compiled. */
428 extern GTY(()) struct function
*cfun
;
430 /* In order to ensure that cfun is not set directly, we redefine it so
431 that it is not an lvalue. Rather than assign to cfun, use
432 push_cfun or set_cfun. */
433 #define cfun (cfun + 0)
435 /* Nonzero if we've already converted virtual regs to hard regs. */
436 extern int virtuals_instantiated
;
438 /* Nonzero if at least one trampoline has been created. */
439 extern int trampolines_created
;
441 struct GTY((for_user
)) types_used_by_vars_entry
{
446 struct used_type_hasher
: ggc_hasher
<types_used_by_vars_entry
*>
448 static hashval_t
hash (types_used_by_vars_entry
*);
449 static bool equal (types_used_by_vars_entry
*, types_used_by_vars_entry
*);
452 /* Hash table making the relationship between a global variable
453 and the types it references in its initializer. The key of the
454 entry is a referenced type, and the value is the DECL of the global
455 variable. types_use_by_vars_do_hash and types_used_by_vars_eq below are
456 the hash and equality functions to use for this hash table. */
457 extern GTY(()) hash_table
<used_type_hasher
> *types_used_by_vars_hash
;
459 void types_used_by_var_decl_insert (tree type
, tree var_decl
);
461 /* During parsing of a global variable, this vector contains the types
462 referenced by the global variable. */
463 extern GTY(()) vec
<tree
, va_gc
> *types_used_by_cur_var_decl
;
466 /* Return the loop tree of FN. */
468 inline struct loops
*
469 loops_for_fn (struct function
*fn
)
471 return fn
->x_current_loops
;
474 /* Set the loop tree of FN to LOOPS. */
477 set_loops_for_fn (struct function
*fn
, struct loops
*loops
)
479 gcc_checking_assert (fn
->x_current_loops
== NULL
|| loops
== NULL
);
480 fn
->x_current_loops
= loops
;
483 /* For backward compatibility... eventually these should all go away. */
484 #define current_function_funcdef_no (cfun->funcdef_no)
486 #define current_loops (cfun->x_current_loops)
487 #define dom_computed (cfun->cfg->x_dom_computed)
488 #define n_bbs_in_dom_tree (cfun->cfg->x_n_bbs_in_dom_tree)
489 #define VALUE_HISTOGRAMS(fun) (fun)->value_histograms
491 /* A pointer to a function to create target specific, per-function
493 extern struct machine_function
* (*init_machine_status
) (void);
495 enum direction
{none
, upward
, downward
};
497 /* Structure to record the size of a sequence of arguments
498 as the sum of a tree-expression and a constant. This structure is
499 also used to store offsets from the stack, which might be negative,
500 so the variable part must be ssizetype, not sizetype. */
504 HOST_WIDE_INT constant
;
508 /* Package up various arg related fields of struct args for
509 locate_and_pad_parm. */
510 struct locate_and_pad_arg_data
512 /* Size of this argument on the stack, rounded up for any padding it
513 gets. If REG_PARM_STACK_SPACE is defined, then register parms are
514 counted here, otherwise they aren't. */
515 struct args_size size
;
516 /* Offset of this argument from beginning of stack-args. */
517 struct args_size offset
;
518 /* Offset to the start of the stack slot. Different from OFFSET
519 if this arg pads downward. */
520 struct args_size slot_offset
;
521 /* The amount that the stack pointer needs to be adjusted to
522 force alignment for the next argument. */
523 struct args_size alignment_pad
;
524 /* Which way we should pad this arg. */
525 enum direction where_pad
;
526 /* slot_offset is at least this aligned. */
527 unsigned int boundary
;
530 /* Add the value of the tree INC to the `struct args_size' TO. */
532 #define ADD_PARM_SIZE(TO, INC) \
535 if (tree_fits_shwi_p (inc)) \
536 (TO).constant += tree_to_shwi (inc); \
537 else if ((TO).var == 0) \
538 (TO).var = fold_convert (ssizetype, inc); \
540 (TO).var = size_binop (PLUS_EXPR, (TO).var, \
541 fold_convert (ssizetype, inc)); \
544 #define SUB_PARM_SIZE(TO, DEC) \
547 if (tree_fits_shwi_p (dec)) \
548 (TO).constant -= tree_to_shwi (dec); \
549 else if ((TO).var == 0) \
550 (TO).var = size_binop (MINUS_EXPR, ssize_int (0), \
551 fold_convert (ssizetype, dec)); \
553 (TO).var = size_binop (MINUS_EXPR, (TO).var, \
554 fold_convert (ssizetype, dec)); \
557 /* Convert the implicit sum in a `struct args_size' into a tree
558 of type ssizetype. */
559 #define ARGS_SIZE_TREE(SIZE) \
560 ((SIZE).var == 0 ? ssize_int ((SIZE).constant) \
561 : size_binop (PLUS_EXPR, fold_convert (ssizetype, (SIZE).var), \
562 ssize_int ((SIZE).constant)))
564 /* Convert the implicit sum in a `struct args_size' into an rtx. */
565 #define ARGS_SIZE_RTX(SIZE) \
566 ((SIZE).var == 0 ? GEN_INT ((SIZE).constant) \
567 : expand_normal (ARGS_SIZE_TREE (SIZE)))
569 #define ASLK_REDUCE_ALIGN 1
570 #define ASLK_RECORD_PAD 2
574 extern void push_function_context (void);
575 extern void pop_function_context (void);
577 /* Save and restore status information for a nested function. */
578 extern void free_after_parsing (struct function
*);
579 extern void free_after_compilation (struct function
*);
581 /* Return size needed for stack frame based on slots so far allocated.
582 This size counts from zero. It is not rounded to STACK_BOUNDARY;
583 the caller may have to do that. */
584 extern HOST_WIDE_INT
get_frame_size (void);
586 /* Issue an error message and return TRUE if frame OFFSET overflows in
587 the signed target pointer arithmetics for function FUNC. Otherwise
589 extern bool frame_offset_overflow (HOST_WIDE_INT
, tree
);
591 extern rtx
assign_stack_local_1 (machine_mode
, HOST_WIDE_INT
, int, int);
592 extern rtx
assign_stack_local (machine_mode
, HOST_WIDE_INT
, int);
593 extern rtx
assign_stack_temp_for_type (machine_mode
, HOST_WIDE_INT
, tree
);
594 extern rtx
assign_stack_temp (machine_mode
, HOST_WIDE_INT
);
595 extern rtx
assign_temp (tree
, int, int);
596 extern void update_temp_slot_address (rtx
, rtx
);
597 extern void preserve_temp_slots (rtx
);
598 extern void free_temp_slots (void);
599 extern void push_temp_slots (void);
600 extern void pop_temp_slots (void);
601 extern void init_temp_slots (void);
602 extern rtx
get_hard_reg_initial_reg (rtx
);
603 extern rtx
get_hard_reg_initial_val (machine_mode
, unsigned int);
604 extern rtx
has_hard_reg_initial_val (machine_mode
, unsigned int);
606 /* Called from gimple_expand_cfg. */
607 extern unsigned int emit_initial_value_sets (void);
609 extern bool initial_value_entry (int i
, rtx
*, rtx
*);
610 extern void instantiate_decl_rtl (rtx x
);
611 extern int aggregate_value_p (const_tree
, const_tree
);
612 extern bool use_register_for_decl (const_tree
);
613 extern bool pass_by_reference (CUMULATIVE_ARGS
*, machine_mode
,
615 extern bool reference_callee_copied (CUMULATIVE_ARGS
*, machine_mode
,
617 extern gimple_seq
gimplify_parameters (void);
618 extern void locate_and_pad_parm (machine_mode
, tree
, int, int, int,
619 tree
, struct args_size
*,
620 struct locate_and_pad_arg_data
*);
621 extern void generate_setjmp_warnings (void);
623 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
624 and create duplicate blocks. */
625 extern void reorder_blocks (void);
626 extern void clear_block_marks (tree
);
627 extern tree
blocks_nreverse (tree
);
628 extern tree
block_chainon (tree
, tree
);
630 /* Set BLOCK_NUMBER for all the blocks in FN. */
631 extern void number_blocks (tree
);
633 /* cfun shouldn't be set directly; use one of these functions instead. */
634 extern void set_cfun (struct function
*new_cfun
);
635 extern void push_cfun (struct function
*new_cfun
);
636 extern void pop_cfun (void);
638 extern int get_next_funcdef_no (void);
639 extern int get_last_funcdef_no (void);
640 extern void allocate_struct_function (tree
, bool);
641 extern void push_struct_function (tree fndecl
);
642 extern void push_dummy_function (bool);
643 extern void pop_dummy_function (void);
644 extern void init_dummy_function_start (void);
645 extern void init_function_start (tree
);
646 extern void stack_protect_epilogue (void);
647 extern void expand_function_start (tree
);
648 extern void expand_dummy_function_end (void);
650 extern void thread_prologue_and_epilogue_insns (void);
651 extern void diddle_return_value (void (*)(rtx
, void*), void*);
652 extern void clobber_return_register (void);
653 extern void do_warn_unused_parameter (tree
);
654 extern void expand_function_end (void);
655 extern rtx
get_arg_pointer_save_area (void);
656 extern void maybe_copy_prologue_epilogue_insn (rtx
, rtx
);
657 extern int prologue_epilogue_contains (const_rtx
);
658 extern void emit_return_into_block (bool simple_p
, basic_block bb
);
659 extern void set_return_jump_label (rtx_insn
*);
660 extern bool active_insn_between (rtx_insn
*head
, rtx_insn
*tail
);
661 extern vec
<edge
> convert_jumps_to_returns (basic_block last_bb
, bool simple_p
,
662 vec
<edge
> unconverted
);
663 extern basic_block
emit_return_for_exit (edge exit_fallthru_edge
,
665 extern void reposition_prologue_and_epilogue_notes (void);
667 /* Returns the name of the current function. */
668 extern const char *fndecl_name (tree
);
669 extern const char *function_name (struct function
*);
670 extern const char *current_function_name (void);
672 extern void used_types_insert (tree
);
674 #endif /* GCC_FUNCTION_H */