2007-01-19 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / function.h
blob22abed5e9ca2b6e9005f1c10bc78a5e22ca1dab6
1 /* Structure for saving state for a nested function.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301, USA. */
22 #ifndef GCC_FUNCTION_H
23 #define GCC_FUNCTION_H
25 #include "tree.h"
26 #include "hashtab.h"
27 #include "hard-reg-set.h"
29 struct var_refs_queue GTY(())
31 rtx modified;
32 enum machine_mode promoted_mode;
33 int unsignedp;
34 struct var_refs_queue *next;
37 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
38 Each element describes one pending sequence.
39 The main insn-chain is saved in the last element of the chain,
40 unless the chain is empty. */
42 struct sequence_stack GTY(())
44 /* First and last insns in the chain of the saved sequence. */
45 rtx first;
46 rtx last;
47 struct sequence_stack *next;
50 extern struct sequence_stack *sequence_stack;
52 /* Stack of single obstacks. */
54 struct simple_obstack_stack
56 struct obstack *obstack;
57 struct simple_obstack_stack *next;
60 struct emit_status GTY(())
62 /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
63 After rtl generation, it is 1 plus the largest register number used. */
64 int x_reg_rtx_no;
66 /* Lowest label number in current function. */
67 int x_first_label_num;
69 /* The ends of the doubly-linked chain of rtl for the current function.
70 Both are reset to null at the start of rtl generation for the function.
72 start_sequence saves both of these on `sequence_stack' and then starts
73 a new, nested sequence of insns. */
74 rtx x_first_insn;
75 rtx x_last_insn;
77 /* Stack of pending (incomplete) sequences saved by `start_sequence'.
78 Each element describes one pending sequence.
79 The main insn-chain is saved in the last element of the chain,
80 unless the chain is empty. */
81 struct sequence_stack *sequence_stack;
83 /* INSN_UID for next insn emitted.
84 Reset to 1 for each function compiled. */
85 int x_cur_insn_uid;
87 /* Location the last line-number NOTE emitted.
88 This is used to avoid generating duplicates. */
89 location_t x_last_location;
91 /* The length of the regno_pointer_align, regno_decl, and x_regno_reg_rtx
92 vectors. Since these vectors are needed during the expansion phase when
93 the total number of registers in the function is not yet known, the
94 vectors are copied and made bigger when necessary. */
95 int regno_pointer_align_length;
97 /* Indexed by pseudo register number, if nonzero gives the known alignment
98 for that pseudo (if REG_POINTER is set in x_regno_reg_rtx).
99 Allocated in parallel with x_regno_reg_rtx. */
100 unsigned char * GTY ((length ("%h.x_reg_rtx_no")))
101 regno_pointer_align;
103 /* Indexed by pseudo register number, gives the rtx for that pseudo.
104 Allocated in parallel with regno_pointer_align. */
105 rtx * GTY ((length ("%h.x_reg_rtx_no"))) x_regno_reg_rtx;
107 /* Call unsaved hard registers really used by given function
108 (including ones used by functions called by given function). */
109 HARD_REG_SET call_used_regs;
112 /* For backward compatibility... eventually these should all go away. */
113 #define reg_rtx_no (cfun->emit->x_reg_rtx_no)
114 #define regno_reg_rtx (cfun->emit->x_regno_reg_rtx)
115 #define seq_stack (cfun->emit->sequence_stack)
117 #define REGNO_POINTER_ALIGN(REGNO) (cfun->emit->regno_pointer_align[REGNO])
119 struct expr_status GTY(())
121 /* Number of units that we should eventually pop off the stack.
122 These are the arguments to function calls that have already returned. */
123 int x_pending_stack_adjust;
125 /* Under some ABIs, it is the caller's responsibility to pop arguments
126 pushed for function calls. A naive implementation would simply pop
127 the arguments immediately after each call. However, if several
128 function calls are made in a row, it is typically cheaper to pop
129 all the arguments after all of the calls are complete since a
130 single pop instruction can be used. Therefore, GCC attempts to
131 defer popping the arguments until absolutely necessary. (For
132 example, at the end of a conditional, the arguments must be popped,
133 since code outside the conditional won't know whether or not the
134 arguments need to be popped.)
136 When INHIBIT_DEFER_POP is nonzero, however, the compiler does not
137 attempt to defer pops. Instead, the stack is popped immediately
138 after each call. Rather then setting this variable directly, use
139 NO_DEFER_POP and OK_DEFER_POP. */
140 int x_inhibit_defer_pop;
142 /* If PREFERRED_STACK_BOUNDARY and PUSH_ROUNDING are defined, the stack
143 boundary can be momentarily unaligned while pushing the arguments.
144 Record the delta since last aligned boundary here in order to get
145 stack alignment in the nested function calls working right. */
146 int x_stack_pointer_delta;
148 /* Nonzero means __builtin_saveregs has already been done in this function.
149 The value is the pseudoreg containing the value __builtin_saveregs
150 returned. */
151 rtx x_saveregs_value;
153 /* Similarly for __builtin_apply_args. */
154 rtx x_apply_args_value;
156 /* List of labels that must never be deleted. */
157 rtx x_forced_labels;
160 #define pending_stack_adjust (cfun->expr->x_pending_stack_adjust)
161 #define inhibit_defer_pop (cfun->expr->x_inhibit_defer_pop)
162 #define saveregs_value (cfun->expr->x_saveregs_value)
163 #define apply_args_value (cfun->expr->x_apply_args_value)
164 #define forced_labels (cfun->expr->x_forced_labels)
165 #define stack_pointer_delta (cfun->expr->x_stack_pointer_delta)
167 struct gimple_df;
168 struct temp_slot;
169 typedef struct temp_slot *temp_slot_p;
171 DEF_VEC_P(temp_slot_p);
172 DEF_VEC_ALLOC_P(temp_slot_p,gc);
174 enum function_frequency {
175 /* This function most likely won't be executed at all.
176 (set only when profile feedback is available). */
177 FUNCTION_FREQUENCY_UNLIKELY_EXECUTED,
178 /* The default value. */
179 FUNCTION_FREQUENCY_NORMAL,
180 /* Optimize this function hard
181 (set only when profile feedback is available). */
182 FUNCTION_FREQUENCY_HOT
185 /* This structure can save all the important global and static variables
186 describing the status of the current function. */
188 struct function GTY(())
190 struct eh_status *eh;
191 struct expr_status *expr;
192 struct emit_status *emit;
193 struct varasm_status *varasm;
195 /* The control flow graph for this function. */
196 struct control_flow_graph *cfg;
197 /* SSA and dataflow information. */
198 struct gimple_df *gimple_df;
200 /* The loops in this function. */
201 struct loops * GTY((skip)) x_current_loops;
203 /* Value histograms attached to particular statements. */
204 htab_t GTY((skip)) value_histograms;
206 /* For function.c. */
208 /* Points to the FUNCTION_DECL of this function. */
209 tree decl;
211 /* Function containing this function, if any. */
212 struct function *outer;
214 /* Number of bytes of args popped by function being compiled on its return.
215 Zero if no bytes are to be popped.
216 May affect compilation of return insn or of function epilogue. */
217 int pops_args;
219 /* If function's args have a fixed size, this is that size, in bytes.
220 Otherwise, it is -1.
221 May affect compilation of return insn or of function epilogue. */
222 int args_size;
224 /* # bytes the prologue should push and pretend that the caller pushed them.
225 The prologue must do this, but only if parms can be passed in
226 registers. */
227 int pretend_args_size;
229 /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is
230 defined, the needed space is pushed by the prologue. */
231 int outgoing_args_size;
233 /* This is the offset from the arg pointer to the place where the first
234 anonymous arg can be found, if there is one. */
235 rtx arg_offset_rtx;
237 /* Quantities of various kinds of registers
238 used for the current function's args. */
239 CUMULATIVE_ARGS args_info;
241 /* If nonzero, an RTL expression for the location at which the current
242 function returns its result. If the current function returns its
243 result in a register, current_function_return_rtx will always be
244 the hard register containing the result. */
245 rtx return_rtx;
247 /* The arg pointer hard register, or the pseudo into which it was copied. */
248 rtx internal_arg_pointer;
250 /* Opaque pointer used by get_hard_reg_initial_val and
251 has_hard_reg_initial_val (see integrate.[hc]). */
252 struct initial_value_struct *hard_reg_initial_vals;
254 /* List (chain of EXPR_LIST) of labels heading the current handlers for
255 nonlocal gotos. */
256 rtx x_nonlocal_goto_handler_labels;
258 /* Label that will go on function epilogue.
259 Jumping to this label serves as a "return" instruction
260 on machines which require execution of the epilogue on all returns. */
261 rtx x_return_label;
263 /* Label that will go on the end of function epilogue.
264 Jumping to this label serves as a "naked return" instruction
265 on machines which require execution of the epilogue on all returns. */
266 rtx x_naked_return_label;
268 /* List (chain of EXPR_LISTs) of all stack slots in this function.
269 Made for the sake of unshare_all_rtl. */
270 rtx x_stack_slot_list;
272 /* Place after which to insert the tail_recursion_label if we need one. */
273 rtx x_stack_check_probe_note;
275 /* Location at which to save the argument pointer if it will need to be
276 referenced. There are two cases where this is done: if nonlocal gotos
277 exist, or if vars stored at an offset from the argument pointer will be
278 needed by inner routines. */
279 rtx x_arg_pointer_save_area;
281 /* Offset to end of allocated area of stack frame.
282 If stack grows down, this is the address of the last stack slot allocated.
283 If stack grows up, this is the address for the next slot. */
284 HOST_WIDE_INT x_frame_offset;
286 /* A PARM_DECL that should contain the static chain for this function.
287 It will be initialized at the beginning of the function. */
288 tree static_chain_decl;
290 /* An expression that contains the non-local goto save area. The first
291 word is the saved frame pointer and the second is the saved stack
292 pointer. */
293 tree nonlocal_goto_save_area;
295 /* Insn after which register parms and SAVE_EXPRs are born, if nonopt. */
296 rtx x_parm_birth_insn;
298 /* List of all used temporaries allocated, by level. */
299 VEC(temp_slot_p,gc) *x_used_temp_slots;
301 /* List of available temp slots. */
302 struct temp_slot *x_avail_temp_slots;
304 /* This slot is initialized as 0 and is added to
305 during the nested function. */
306 struct var_refs_queue *fixup_var_refs_queue;
308 /* Current nesting level for temporaries. */
309 int x_temp_slot_level;
311 /* Highest label number in current function. */
312 int inl_max_label_num;
314 /* Function sequence number for profiling, debugging, etc. */
315 int funcdef_no;
317 /* For flow.c. */
319 /* Highest loop depth seen so far in loop analysis. Used in flow.c
320 for the "failure strategy" when doing liveness analysis starting
321 with non-empty initial sets. */
322 int max_loop_depth;
324 /* For md files. */
326 /* tm.h can use this to store whatever it likes. */
327 struct machine_function * GTY ((maybe_undef)) machine;
329 /* The largest alignment of slot allocated on the stack. */
330 unsigned int stack_alignment_needed;
332 /* Preferred alignment of the end of stack frame. */
333 unsigned int preferred_stack_boundary;
335 /* Language-specific code can use this to store whatever it likes. */
336 struct language_function * language;
338 /* Used types hash table. */
339 htab_t GTY ((param_is (union tree_node))) used_types_hash;
341 /* For reorg. */
343 /* If some insns can be deferred to the delay slots of the epilogue, the
344 delay list for them is recorded here. */
345 rtx epilogue_delay_list;
347 /* Maximal number of entities in the single jumptable. Used to estimate
348 final flowgraph size. */
349 int max_jumptable_ents;
351 /* UIDs for LABEL_DECLs. */
352 int last_label_uid;
354 /* Line number of the end of the function. */
355 location_t function_end_locus;
357 /* Array mapping insn uids to blocks. */
358 VEC(tree,gc) *ib_boundaries_block;
360 /* The variables unexpanded so far. */
361 tree unexpanded_var_list;
363 /* Assembly labels for the hot and cold text sections, to
364 be used by debugger functions for determining the size of text
365 sections. */
367 const char *hot_section_label;
368 const char *cold_section_label;
369 const char *hot_section_end_label;
370 const char *cold_section_end_label;
372 /* String to be used for name of cold text sections, via
373 targetm.asm_out.named_section. */
375 const char *unlikely_text_section_name;
377 /* A variable living at the top of the frame that holds a known value.
378 Used for detecting stack clobbers. */
379 tree stack_protect_guard;
381 /* Collected bit flags. */
383 /* Nonzero if function being compiled needs to be given an address
384 where the value should be stored. */
385 unsigned int returns_struct : 1;
387 /* Nonzero if function being compiled needs to
388 return the address of where it has put a structure value. */
389 unsigned int returns_pcc_struct : 1;
391 /* Nonzero if the current function returns a pointer type. */
392 unsigned int returns_pointer : 1;
394 /* Nonzero if function being compiled can call setjmp. */
395 unsigned int calls_setjmp : 1;
397 /* Nonzero if function being compiled can call alloca,
398 either as a subroutine or builtin. */
399 unsigned int calls_alloca : 1;
401 /* Nonzero if function being compiled called builtin_return_addr or
402 builtin_frame_address with nonzero count. */
403 unsigned int accesses_prior_frames : 1;
405 /* Nonzero if the function calls __builtin_eh_return. */
406 unsigned int calls_eh_return : 1;
408 /* Nonzero if function being compiled receives nonlocal gotos
409 from nested functions. */
410 unsigned int has_nonlocal_label : 1;
412 /* Nonzero if function being compiled has nonlocal gotos to parent
413 function. */
414 unsigned int has_nonlocal_goto : 1;
416 /* Nonzero if the current function is a thunk, i.e., a lightweight
417 function implemented by the output_mi_thunk hook) that just
418 adjusts one of its arguments and forwards to another
419 function. */
420 unsigned int is_thunk : 1;
422 /* This bit is used by the exception handling logic. It is set if all
423 calls (if any) are sibling calls. Such functions do not have to
424 have EH tables generated, as they cannot throw. A call to such a
425 function, however, should be treated as throwing if any of its callees
426 can throw. */
427 unsigned int all_throwers_are_sibcalls : 1;
429 /* Nonzero if profiling code should be generated. */
430 unsigned int profile : 1;
432 /* Nonzero if stack limit checking should be enabled in the current
433 function. */
434 unsigned int limit_stack : 1;
436 /* Nonzero if current function uses stdarg.h or equivalent. */
437 unsigned int stdarg : 1;
439 /* Nonzero if the back-end should not keep track of expressions that
440 determine the size of variable-sized objects. Normally, such
441 expressions are saved away, and then expanded when the next
442 function is started. For example, if a parameter has a
443 variable-sized type, then the size of the parameter is computed
444 when the function body is entered. However, some front-ends do
445 not desire this behavior. */
446 unsigned int x_dont_save_pending_sizes_p : 1;
448 /* Nonzero if the current function uses the constant pool. */
449 unsigned int uses_const_pool : 1;
451 /* Nonzero if the current function uses pic_offset_table_rtx. */
452 unsigned int uses_pic_offset_table : 1;
454 /* Nonzero if the current function needs an lsda for exception handling. */
455 unsigned int uses_eh_lsda : 1;
457 /* Nonzero if code to initialize arg_pointer_save_area has been emitted. */
458 unsigned int arg_pointer_save_area_init : 1;
460 unsigned int after_inlining : 1;
462 /* Set when the call to function itself has been emit. */
463 unsigned int recursive_call_emit : 1;
465 /* Set when the tail call has been produced. */
466 unsigned int tail_call_emit : 1;
468 /* How commonly executed the function is. Initialized during branch
469 probabilities pass. */
470 ENUM_BITFIELD (function_frequency) function_frequency : 2;
472 /* Number of units of general registers that need saving in stdarg
473 function. What unit is depends on the backend, either it is number
474 of bytes, or it can be number of registers. */
475 unsigned int va_list_gpr_size : 8;
477 /* Number of units of floating point registers that need saving in stdarg
478 function. */
479 unsigned int va_list_fpr_size : 8;
481 /* FIXME tuples: This bit is temporarily here to mark when a
482 function has been gimplified, so we can make sure we're not
483 creating non GIMPLE tuples after gimplification. */
484 unsigned gimplified : 1;
487 /* If va_list_[gf]pr_size is set to this, it means we don't know how
488 many units need to be saved. */
489 #define VA_LIST_MAX_GPR_SIZE 255
490 #define VA_LIST_MAX_FPR_SIZE 255
492 /* The function currently being compiled. */
493 extern GTY(()) struct function *cfun;
495 /* Pointer to chain of `struct function' for containing functions. */
496 extern GTY(()) struct function *outer_function_chain;
498 /* Nonzero if we've already converted virtual regs to hard regs. */
499 extern int virtuals_instantiated;
501 /* Nonzero if at least one trampoline has been created. */
502 extern int trampolines_created;
504 /* For backward compatibility... eventually these should all go away. */
505 #define current_function_pops_args (cfun->pops_args)
506 #define current_function_returns_struct (cfun->returns_struct)
507 #define current_function_returns_pcc_struct (cfun->returns_pcc_struct)
508 #define current_function_returns_pointer (cfun->returns_pointer)
509 #define current_function_calls_setjmp (cfun->calls_setjmp)
510 #define current_function_calls_alloca (cfun->calls_alloca)
511 #define current_function_accesses_prior_frames (cfun->accesses_prior_frames)
512 #define current_function_calls_eh_return (cfun->calls_eh_return)
513 #define current_function_is_thunk (cfun->is_thunk)
514 #define current_function_args_info (cfun->args_info)
515 #define current_function_args_size (cfun->args_size)
516 #define current_function_pretend_args_size (cfun->pretend_args_size)
517 #define current_function_outgoing_args_size (cfun->outgoing_args_size)
518 #define current_function_arg_offset_rtx (cfun->arg_offset_rtx)
519 #define current_function_stdarg (cfun->stdarg)
520 #define current_function_internal_arg_pointer (cfun->internal_arg_pointer)
521 #define current_function_return_rtx (cfun->return_rtx)
522 #define current_function_profile (cfun->profile)
523 #define current_function_funcdef_no (cfun->funcdef_no)
524 #define current_function_limit_stack (cfun->limit_stack)
525 #define current_function_uses_pic_offset_table (cfun->uses_pic_offset_table)
526 #define current_function_uses_const_pool (cfun->uses_const_pool)
527 #define current_function_epilogue_delay_list (cfun->epilogue_delay_list)
528 #define current_function_has_nonlocal_label (cfun->has_nonlocal_label)
529 #define current_function_has_nonlocal_goto (cfun->has_nonlocal_goto)
531 #define return_label (cfun->x_return_label)
532 #define naked_return_label (cfun->x_naked_return_label)
533 #define stack_slot_list (cfun->x_stack_slot_list)
534 #define parm_birth_insn (cfun->x_parm_birth_insn)
535 #define frame_offset (cfun->x_frame_offset)
536 #define stack_check_probe_note (cfun->x_stack_check_probe_note)
537 #define arg_pointer_save_area (cfun->x_arg_pointer_save_area)
538 #define used_temp_slots (cfun->x_used_temp_slots)
539 #define avail_temp_slots (cfun->x_avail_temp_slots)
540 #define temp_slot_level (cfun->x_temp_slot_level)
541 #define nonlocal_goto_handler_labels (cfun->x_nonlocal_goto_handler_labels)
542 #define current_loops (cfun->x_current_loops)
543 #define VALUE_HISTOGRAMS(fun) (fun)->value_histograms
545 /* Given a function decl for a containing function,
546 return the `struct function' for it. */
547 struct function *find_function_data (tree);
549 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END},
550 and create duplicate blocks. */
551 extern void reorder_blocks (void);
553 /* Set BLOCK_NUMBER for all the blocks in FN. */
554 extern void number_blocks (tree);
556 extern void clear_block_marks (tree);
557 extern tree blocks_nreverse (tree);
558 extern void reset_block_changes (void);
559 extern void record_block_change (tree);
560 extern void finalize_block_changes (void);
561 extern void check_block_change (rtx, tree *);
562 extern void free_block_changes (void);
564 /* Return size needed for stack frame based on slots so far allocated.
565 This size counts from zero. It is not rounded to STACK_BOUNDARY;
566 the caller may have to do that. */
567 extern HOST_WIDE_INT get_frame_size (void);
569 /* Issue an error message and return TRUE if frame OFFSET overflows in
570 the signed target pointer arithmetics for function FUNC. Otherwise
571 return FALSE. */
572 extern bool frame_offset_overflow (HOST_WIDE_INT, tree);
574 /* A pointer to a function to create target specific, per-function
575 data structures. */
576 extern struct machine_function * (*init_machine_status) (void);
578 /* Save and restore status information for a nested function. */
579 extern void free_after_parsing (struct function *);
580 extern void free_after_compilation (struct function *);
582 extern void init_varasm_status (struct function *);
584 #ifdef RTX_CODE
585 extern void diddle_return_value (void (*)(rtx, void*), void*);
586 extern void clobber_return_register (void);
587 #endif
589 extern rtx get_arg_pointer_save_area (struct function *);
591 /* Returns the name of the current function. */
592 extern const char *current_function_name (void);
594 extern void get_call_invalidated_used_regs (rtx, HARD_REG_SET *, bool);
596 extern void do_warn_unused_parameter (tree);
598 extern bool pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
599 tree, bool);
600 extern bool reference_callee_copied (CUMULATIVE_ARGS *, enum machine_mode,
601 tree, bool);
603 extern void used_types_insert (tree);
605 #endif /* GCC_FUNCTION_H */