Mercurial > hg > CbC > CbC_gcc
diff gcc/function.c @ 67:f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author | nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 22 Mar 2011 17:18:12 +0900 |
parents | b7f97abdc517 |
children | 1b10fe6932e1 04ced10e8804 |
line wrap: on
line diff
--- a/gcc/function.c Tue May 25 18:58:51 2010 +0900 +++ b/gcc/function.c Tue Mar 22 17:18:12 2011 +0900 @@ -1,7 +1,7 @@ /* Expands front end tree to back end RTL for GCC. Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, - 2010 Free Software Foundation, Inc. + 2010, 2011 Free Software Foundation, Inc. This file is part of GCC. @@ -37,7 +37,7 @@ #include "system.h" #include "coretypes.h" #include "tm.h" -#include "rtl.h" +#include "rtl-error.h" #include "tree.h" #include "flags.h" #include "except.h" @@ -51,7 +51,6 @@ #include "recog.h" #include "output.h" #include "basic-block.h" -#include "toplev.h" #include "hashtab.h" #include "ggc.h" #include "tm_p.h" @@ -132,7 +131,7 @@ htab_t types_used_by_vars_hash = NULL; -tree types_used_by_cur_var_decl = NULL; +VEC(tree,gc) *types_used_by_cur_var_decl; /* Forward declarations. */ @@ -340,7 +339,7 @@ static void add_frame_space (HOST_WIDE_INT start, HOST_WIDE_INT end) { - struct frame_space *space = GGC_NEW (struct frame_space); + struct frame_space *space = ggc_alloc_frame_space (); space->next = crtl->frame_space_list; crtl->frame_space_list = space; space->start = start; @@ -356,18 +355,21 @@ -2 means use BITS_PER_UNIT, positive specifies alignment boundary in bits. - If REDUCE_ALIGNMENT_OK is true, it is OK to reduce alignment. + KIND has ASLK_REDUCE_ALIGN bit set if it is OK to reduce + alignment and ASLK_RECORD_PAD bit set if we should remember + extra space we allocated for alignment purposes. When we are + called from assign_stack_temp_for_type, it is not set so we don't + track the same stack slot in two independent lists. We do not round to stack_boundary here. */ rtx assign_stack_local_1 (enum machine_mode mode, HOST_WIDE_INT size, - int align, - bool reduce_alignment_ok ATTRIBUTE_UNUSED) + int align, int kind) { rtx x, addr; int bigend_correction = 0; - HOST_WIDE_INT slot_offset, old_frame_offset; + HOST_WIDE_INT slot_offset = 0, old_frame_offset; unsigned int alignment, alignment_in_bits; if (align == 0) @@ -413,7 +415,7 @@ /* It is OK to reduce the alignment as long as the requested size is 0 or the estimated stack alignment >= mode alignment. */ - gcc_assert (reduce_alignment_ok + gcc_assert ((kind & ASLK_REDUCE_ALIGN) || size == 0 || (crtl->stack_alignment_estimated >= GET_MODE_ALIGNMENT (mode))); @@ -431,21 +433,24 @@ if (mode != BLKmode || size != 0) { - struct frame_space **psp; - - for (psp = &crtl->frame_space_list; *psp; psp = &(*psp)->next) + if (kind & ASLK_RECORD_PAD) { - struct frame_space *space = *psp; - if (!try_fit_stack_local (space->start, space->length, size, - alignment, &slot_offset)) - continue; - *psp = space->next; - if (slot_offset > space->start) - add_frame_space (space->start, slot_offset); - if (slot_offset + size < space->start + space->length) - add_frame_space (slot_offset + size, - space->start + space->length); - goto found_space; + struct frame_space **psp; + + for (psp = &crtl->frame_space_list; *psp; psp = &(*psp)->next) + { + struct frame_space *space = *psp; + if (!try_fit_stack_local (space->start, space->length, size, + alignment, &slot_offset)) + continue; + *psp = space->next; + if (slot_offset > space->start) + add_frame_space (space->start, slot_offset); + if (slot_offset + size < space->start + space->length) + add_frame_space (slot_offset + size, + space->start + space->length); + goto found_space; + } } } else if (!STACK_ALIGNMENT_NEEDED) @@ -461,20 +466,26 @@ frame_offset -= size; try_fit_stack_local (frame_offset, size, size, alignment, &slot_offset); - if (slot_offset > frame_offset) - add_frame_space (frame_offset, slot_offset); - if (slot_offset + size < old_frame_offset) - add_frame_space (slot_offset + size, old_frame_offset); + if (kind & ASLK_RECORD_PAD) + { + if (slot_offset > frame_offset) + add_frame_space (frame_offset, slot_offset); + if (slot_offset + size < old_frame_offset) + add_frame_space (slot_offset + size, old_frame_offset); + } } else { frame_offset += size; try_fit_stack_local (old_frame_offset, size, size, alignment, &slot_offset); - if (slot_offset > old_frame_offset) - add_frame_space (old_frame_offset, slot_offset); - if (slot_offset + size < frame_offset) - add_frame_space (slot_offset + size, frame_offset); + if (kind & ASLK_RECORD_PAD) + { + if (slot_offset > old_frame_offset) + add_frame_space (old_frame_offset, slot_offset); + if (slot_offset + size < frame_offset) + add_frame_space (slot_offset + size, frame_offset); + } } found_space: @@ -514,7 +525,7 @@ rtx assign_stack_local (enum machine_mode mode, HOST_WIDE_INT size, int align) { - return assign_stack_local_1 (mode, size, align, false); + return assign_stack_local_1 (mode, size, align, ASLK_RECORD_PAD); } @@ -683,7 +694,7 @@ insert_temp_slot_address (rtx address, struct temp_slot *temp_slot) { void **slot; - struct temp_slot_address_entry *t = GGC_NEW (struct temp_slot_address_entry); + struct temp_slot_address_entry *t = ggc_alloc_temp_slot_address_entry (); t->address = address; t->temp_slot = temp_slot; t->hash = temp_slot_address_compute_hash (t); @@ -835,7 +846,7 @@ if (best_p->size - rounded_size >= alignment) { - p = GGC_NEW (struct temp_slot); + p = ggc_alloc_temp_slot (); p->in_use = p->addr_taken = 0; p->size = best_p->size - rounded_size; p->base_offset = best_p->base_offset + rounded_size; @@ -859,7 +870,7 @@ { HOST_WIDE_INT frame_offset_old = frame_offset; - p = GGC_NEW (struct temp_slot); + p = ggc_alloc_temp_slot (); /* We are passing an explicit alignment request to assign_stack_local. One side effect of that is assign_stack_local will not round SIZE @@ -869,11 +880,13 @@ and round it now. We also make sure ALIGNMENT is at least BIGGEST_ALIGNMENT. */ gcc_assert (mode != BLKmode || align == BIGGEST_ALIGNMENT); - p->slot = assign_stack_local (mode, - (mode == BLKmode - ? CEIL_ROUND (size, (int) align / BITS_PER_UNIT) - : size), - align); + p->slot = assign_stack_local_1 (mode, + (mode == BLKmode + ? CEIL_ROUND (size, + (int) align + / BITS_PER_UNIT) + : size), + align, 0); p->align = align; @@ -929,8 +942,11 @@ if (type != 0) { MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type); - MEM_SET_IN_STRUCT_P (slot, (AGGREGATE_TYPE_P (type) - || TREE_CODE (type) == COMPLEX_TYPE)); + gcc_checking_assert (!MEM_SCALAR_P (slot) && !MEM_IN_STRUCT_P (slot)); + if (AGGREGATE_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE) + MEM_IN_STRUCT_P (slot) = 1; + else + MEM_SCALAR_P (slot) = 1; } MEM_NOTRAP_P (slot) = 1; @@ -1406,6 +1422,11 @@ #endif offset = cfa_offset; } + else if (x == virtual_preferred_stack_boundary_rtx) + { + new_rtx = GEN_INT (crtl->preferred_stack_boundary / BITS_PER_UNIT); + offset = 0; + } else return NULL_RTX; @@ -1780,8 +1801,21 @@ if (! EXPR_P (t)) { *walk_subtrees = 0; - if (DECL_P (t) && DECL_RTL_SET_P (t)) - instantiate_decl_rtl (DECL_RTL (t)); + if (DECL_P (t)) + { + if (DECL_RTL_SET_P (t)) + instantiate_decl_rtl (DECL_RTL (t)); + if (TREE_CODE (t) == PARM_DECL && DECL_NAMELESS (t) + && DECL_INCOMING_RTL (t)) + instantiate_decl_rtl (DECL_INCOMING_RTL (t)); + if ((TREE_CODE (t) == VAR_DECL + || TREE_CODE (t) == RESULT_DECL) + && DECL_HAS_VALUE_EXPR_P (t)) + { + tree v = DECL_VALUE_EXPR (t); + walk_tree (&v, instantiate_expr, NULL, NULL); + } + } } return NULL; } @@ -1794,7 +1828,7 @@ { tree t; - for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) + for (t = BLOCK_VARS (let); t; t = DECL_CHAIN (t)) { if (DECL_RTL_SET_P (t)) instantiate_decl_rtl (DECL_RTL (t)); @@ -1816,10 +1850,11 @@ static void instantiate_decls (tree fndecl) { - tree decl, t, next; + tree decl; + unsigned ix; /* Process all parameters of the function. */ - for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) + for (decl = DECL_ARGUMENTS (fndecl); decl; decl = DECL_CHAIN (decl)) { instantiate_decl_rtl (DECL_RTL (decl)); instantiate_decl_rtl (DECL_INCOMING_RTL (decl)); @@ -1830,19 +1865,25 @@ } } + if ((decl = DECL_RESULT (fndecl)) + && TREE_CODE (decl) == RESULT_DECL) + { + if (DECL_RTL_SET_P (decl)) + instantiate_decl_rtl (DECL_RTL (decl)); + if (DECL_HAS_VALUE_EXPR_P (decl)) + { + tree v = DECL_VALUE_EXPR (decl); + walk_tree (&v, instantiate_expr, NULL, NULL); + } + } + /* Now process all variables defined in the function or its subblocks. */ instantiate_decls_1 (DECL_INITIAL (fndecl)); - t = cfun->local_decls; - cfun->local_decls = NULL_TREE; - for (; t; t = next) - { - next = TREE_CHAIN (t); - decl = TREE_VALUE (t); - if (DECL_RTL_SET_P (decl)) - instantiate_decl_rtl (DECL_RTL (decl)); - ggc_free (t); - } + FOR_EACH_LOCAL_DECL (cfun, ix, decl) + if (DECL_RTL_SET_P (decl)) + instantiate_decl_rtl (DECL_RTL (decl)); + VEC_free (tree, gc, cfun->local_decls); } /* Pass through the INSNS of function FNDECL and convert virtual register @@ -1905,6 +1946,18 @@ /* Indicate that, from now on, assign_stack_local should use frame_pointer_rtx. */ virtuals_instantiated = 1; + + /* See allocate_dynamic_stack_space for the rationale. */ +#ifdef SETJMP_VIA_SAVE_AREA + if (flag_stack_usage && cfun->calls_setjmp) + { + int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; + dynamic_offset = (dynamic_offset + align - 1) / align * align; + current_function_dynamic_stack_size + += current_function_dynamic_alloc_count * dynamic_offset; + } +#endif + return 0; } @@ -2177,7 +2230,7 @@ unsigned i; tree p; - for (i = 0; VEC_iterate (tree, *args, i, p); ++i) + FOR_EACH_VEC_ELT (tree, *args, i, p) { tree type = TREE_TYPE (p); if (TREE_CODE (type) == COMPLEX_TYPE @@ -2228,7 +2281,7 @@ VEC(tree, heap) *fnargs = NULL; tree arg; - for (arg = DECL_ARGUMENTS (fndecl); arg; arg = TREE_CHAIN (arg)) + for (arg = DECL_ARGUMENTS (fndecl); arg; arg = DECL_CHAIN (arg)) VEC_safe_push (tree, heap, fnargs, arg); all->orig_fnargs = DECL_ARGUMENTS (fndecl); @@ -2242,12 +2295,13 @@ tree decl; decl = build_decl (DECL_SOURCE_LOCATION (fndecl), - PARM_DECL, NULL_TREE, type); + PARM_DECL, get_identifier (".result_ptr"), type); DECL_ARG_TYPE (decl) = type; DECL_ARTIFICIAL (decl) = 1; - DECL_IGNORED_P (decl) = 1; - - TREE_CHAIN (decl) = all->orig_fnargs; + DECL_NAMELESS (decl) = 1; + TREE_CONSTANT (decl) = 1; + + DECL_CHAIN (decl) = all->orig_fnargs; all->orig_fnargs = decl; VEC_safe_insert (tree, heap, fnargs, 0, decl); @@ -2278,7 +2332,7 @@ /* NAMED_ARG is a misnomer. We really mean 'non-variadic'. */ if (!cfun->stdarg) data->named_arg = 1; /* No variadic parms. */ - else if (TREE_CHAIN (parm)) + else if (DECL_CHAIN (parm)) data->named_arg = 1; /* Not the last non-variadic parm. */ else if (targetm.calls.strict_argument_naming (&all->args_so_far)) data->named_arg = 1; /* Only variadic ones are unnamed. */ @@ -2374,13 +2428,10 @@ return; } -#ifdef FUNCTION_INCOMING_ARG - entry_parm = FUNCTION_INCOMING_ARG (all->args_so_far, data->promoted_mode, - data->passed_type, data->named_arg); -#else - entry_parm = FUNCTION_ARG (all->args_so_far, data->promoted_mode, - data->passed_type, data->named_arg); -#endif + entry_parm = targetm.calls.function_incoming_arg (&all->args_so_far, + data->promoted_mode, + data->passed_type, + data->named_arg); if (entry_parm == 0) data->promoted_mode = data->passed_mode; @@ -2404,13 +2455,9 @@ if (targetm.calls.pretend_outgoing_varargs_named (&all->args_so_far)) { rtx tem; -#ifdef FUNCTION_INCOMING_ARG - tem = FUNCTION_INCOMING_ARG (all->args_so_far, data->promoted_mode, - data->passed_type, true); -#else - tem = FUNCTION_ARG (all->args_so_far, data->promoted_mode, - data->passed_type, true); -#endif + tem = targetm.calls.function_incoming_arg (&all->args_so_far, + data->promoted_mode, + data->passed_type, true); in_regs = tem != NULL; } } @@ -2561,7 +2608,7 @@ align = BITS_PER_UNIT; /* If we're padding upward, we know that the alignment of the slot - is FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're + is TARGET_FUNCTION_ARG_BOUNDARY. If we're using slot_offset, we're intentionally forcing upward padding. Otherwise we have to come up with a guess at the alignment based on OFFSET_RTX. */ if (data->locate.where_pad != downward || data->entry_parm) @@ -2867,6 +2914,21 @@ SET_DECL_RTL (parm, stack_parm); } +/* A subroutine of assign_parm_setup_reg, called through note_stores. + This collects sets and clobbers of hard registers in a HARD_REG_SET, + which is pointed to by DATA. */ +static void +record_hard_reg_sets (rtx x, const_rtx pat ATTRIBUTE_UNUSED, void *data) +{ + HARD_REG_SET *pset = (HARD_REG_SET *)data; + if (REG_P (x) && REGNO (x) < FIRST_PSEUDO_REGISTER) + { + int nregs = hard_regno_nregs[REGNO (x)][GET_MODE (x)]; + while (nregs-- > 0) + SET_HARD_REG_BIT (*pset, REGNO (x) + nregs); + } +} + /* A subroutine of assign_parms. Allocate a pseudo to hold the current parameter. Get it there. Perform all ABI specified conversions. */ @@ -2874,10 +2936,12 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm, struct assign_parm_data_one *data) { - rtx parmreg; + rtx parmreg, validated_mem; + rtx equiv_stack_parm; enum machine_mode promoted_nominal_mode; int unsignedp = TYPE_UNSIGNED (TREE_TYPE (parm)); bool did_conversion = false; + bool need_conversion, moved; /* Store the parm in a pseudoregister during the function, but we may need to do it in a wider mode. Using 2 here makes the result @@ -2906,11 +2970,19 @@ /* Copy the value into the register, thus bridging between assign_parm_find_data_types and expand_expr_real_1. */ - if (data->nominal_mode != data->passed_mode - || promoted_nominal_mode != data->promoted_mode) + + equiv_stack_parm = data->stack_parm; + validated_mem = validize_mem (data->entry_parm); + + need_conversion = (data->nominal_mode != data->passed_mode + || promoted_nominal_mode != data->promoted_mode); + moved = false; + + if (need_conversion + && GET_MODE_CLASS (data->nominal_mode) == MODE_INT + && data->nominal_mode == data->passed_mode + && data->nominal_mode == GET_MODE (data->entry_parm)) { - int save_tree_used; - /* ENTRY_PARM has been converted to PROMOTED_MODE, its mode, by the caller. We now have to convert it to NOMINAL_MODE, if different. However, PARMREG may be in @@ -2926,13 +2998,71 @@ In addition, the conversion may involve a call, which could clobber parameters which haven't been copied to pseudo - registers yet. Therefore, we must first copy the parm to - a pseudo reg here, and save the conversion until after all + registers yet. + + First, we try to emit an insn which performs the necessary + conversion. We verify that this insn does not clobber any + hard registers. */ + + enum insn_code icode; + rtx op0, op1; + + icode = can_extend_p (promoted_nominal_mode, data->passed_mode, + unsignedp); + + op0 = parmreg; + op1 = validated_mem; + if (icode != CODE_FOR_nothing + && insn_data[icode].operand[0].predicate (op0, promoted_nominal_mode) + && insn_data[icode].operand[1].predicate (op1, data->passed_mode)) + { + enum rtx_code code = unsignedp ? ZERO_EXTEND : SIGN_EXTEND; + rtx insn, insns; + HARD_REG_SET hardregs; + + start_sequence (); + insn = gen_extend_insn (op0, op1, promoted_nominal_mode, + data->passed_mode, unsignedp); + emit_insn (insn); + insns = get_insns (); + + moved = true; + CLEAR_HARD_REG_SET (hardregs); + for (insn = insns; insn && moved; insn = NEXT_INSN (insn)) + { + if (INSN_P (insn)) + note_stores (PATTERN (insn), record_hard_reg_sets, + &hardregs); + if (!hard_reg_set_empty_p (hardregs)) + moved = false; + } + + end_sequence (); + + if (moved) + { + emit_insn (insns); + if (equiv_stack_parm != NULL_RTX) + equiv_stack_parm = gen_rtx_fmt_e (code, GET_MODE (parmreg), + equiv_stack_parm); + } + } + } + + if (moved) + /* Nothing to do. */ + ; + else if (need_conversion) + { + /* We did not have an insn to convert directly, or the sequence + generated appeared unsafe. We must first copy the parm to a + pseudo reg, and save the conversion until after all parameters have been moved. */ + int save_tree_used; rtx tempreg = gen_reg_rtx (GET_MODE (data->entry_parm)); - emit_move_insn (tempreg, validize_mem (data->entry_parm)); + emit_move_insn (tempreg, validated_mem); push_to_sequence2 (all->first_conversion_insn, all->last_conversion_insn); tempreg = convert_to_mode (data->nominal_mode, tempreg, unsignedp); @@ -2962,7 +3092,7 @@ did_conversion = true; } else - emit_move_insn (parmreg, validize_mem (data->entry_parm)); + emit_move_insn (parmreg, validated_mem); /* If we were passed a pointer but the actual value can safely live in a register, put it in one. */ @@ -3047,7 +3177,7 @@ } else if ((set = single_set (linsn)) != 0 && SET_DEST (set) == parmreg) - set_unique_reg_note (linsn, REG_EQUIV, data->stack_parm); + set_unique_reg_note (linsn, REG_EQUIV, equiv_stack_parm); } /* For pointer data type, suggest pointer register. */ @@ -3225,7 +3355,7 @@ assign_parms_initialize_all (&all); fnargs = assign_parms_augmented_arg_list (&all); - for (i = 0; VEC_iterate (tree, fnargs, i, parm); ++i) + FOR_EACH_VEC_ELT (tree, fnargs, i, parm) { struct assign_parm_data_one data; @@ -3243,8 +3373,9 @@ /* Estimate stack alignment from parameter alignment. */ if (SUPPORTS_STACK_ALIGNMENT) { - unsigned int align = FUNCTION_ARG_BOUNDARY (data.promoted_mode, - data.passed_type); + unsigned int align + = targetm.calls.function_arg_boundary (data.promoted_mode, + data.passed_type); align = MINIMUM_ALIGNMENT (data.passed_type, data.promoted_mode, align); if (TYPE_ALIGN (data.nominal_type) > align) @@ -3258,7 +3389,7 @@ } } - if (cfun->stdarg && !TREE_CHAIN (parm)) + if (cfun->stdarg && !DECL_CHAIN (parm)) assign_parms_setup_varargs (&all, &data, false); /* Find out where the parameter arrives in this function. */ @@ -3275,8 +3406,8 @@ set_decl_incoming_rtl (parm, data.entry_parm, data.passed_pointer); /* Update info on where next arg arrives in registers. */ - FUNCTION_ARG_ADVANCE (all.args_so_far, data.promoted_mode, - data.passed_type, data.named_arg); + targetm.calls.function_arg_advance (&all.args_so_far, data.promoted_mode, + data.passed_type, data.named_arg); assign_parm_adjust_stack_rtl (&data); @@ -3330,13 +3461,22 @@ rtx x; if (DECL_BY_REFERENCE (result)) - x = addr; + { + SET_DECL_VALUE_EXPR (result, all.function_result_decl); + x = addr; + } else { + SET_DECL_VALUE_EXPR (result, + build1 (INDIRECT_REF, TREE_TYPE (result), + all.function_result_decl)); addr = convert_memory_address (Pmode, addr); x = gen_rtx_MEM (DECL_MODE (result), addr); set_mem_attributes (x, result, 1); } + + DECL_HAS_VALUE_EXPR_P (result) = 1; + SET_DECL_RTL (result, x); } @@ -3369,8 +3509,9 @@ /* See how many bytes, if any, of its args a function should try to pop on return. */ - crtl->args.pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl), - crtl->args.size); + crtl->args.pops_args = targetm.calls.return_pops_args (fndecl, + TREE_TYPE (fndecl), + crtl->args.size); /* For stdarg.h function, save info about regs and stack space used by the named args. */ @@ -3452,7 +3593,7 @@ assign_parms_initialize_all (&all); fnargs = assign_parms_augmented_arg_list (&all); - for (i = 0; VEC_iterate (tree, fnargs, i, parm); ++i) + FOR_EACH_VEC_ELT (tree, fnargs, i, parm) { struct assign_parm_data_one data; @@ -3464,8 +3605,8 @@ continue; /* Update info on where next arg arrives in registers. */ - FUNCTION_ARG_ADVANCE (all.args_so_far, data.promoted_mode, - data.passed_type, data.named_arg); + targetm.calls.function_arg_advance (&all.args_so_far, data.promoted_mode, + data.passed_type, data.named_arg); /* ??? Once upon a time variable_size stuffed parameter list SAVE_EXPRs (amongst others) onto a pending sizes list. This @@ -3495,28 +3636,28 @@ && compare_tree_int (DECL_SIZE_UNIT (parm), STACK_CHECK_MAX_VAR_SIZE) > 0)) { - local = create_tmp_var (type, get_name (parm)); + local = create_tmp_reg (type, get_name (parm)); DECL_IGNORED_P (local) = 0; /* If PARM was addressable, move that flag over to the local copy, as its address will be taken, - not the PARMs. */ + not the PARMs. Keep the parms address taken + as we'll query that flag during gimplification. */ if (TREE_ADDRESSABLE (parm)) - { - TREE_ADDRESSABLE (parm) = 0; - TREE_ADDRESSABLE (local) = 1; - } + TREE_ADDRESSABLE (local) = 1; } else { tree ptr_type, addr; ptr_type = build_pointer_type (type); - addr = create_tmp_var (ptr_type, get_name (parm)); + addr = create_tmp_reg (ptr_type, get_name (parm)); DECL_IGNORED_P (addr) = 0; local = build_fold_indirect_ref (addr); t = built_in_decls[BUILT_IN_ALLOCA]; t = build_call_expr (t, 1, DECL_SIZE_UNIT (parm)); + /* The call has been built for a variable-sized object. */ + ALLOCA_FOR_VAR_P (t) = 1; t = fold_convert (ptr_type, t); t = build2 (MODIFY_EXPR, TREE_TYPE (addr), addr, t); gimplify_and_add (t, &stmts); @@ -3553,9 +3694,10 @@ FNDECL is the function in which the argument was defined. There are two types of rounding that are done. The first, controlled by - FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument - list to be aligned to the specific boundary (in bits). This rounding - affects the initial and starting offsets, but not the argument size. + TARGET_FUNCTION_ARG_BOUNDARY, forces the offset from the start of the + argument list to be aligned to the specific boundary (in bits). This + rounding affects the initial and starting offsets, but not the argument + size. The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, optionally rounds the size of the parm to PARM_BOUNDARY. The @@ -3606,7 +3748,7 @@ sizetree = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); where_pad = FUNCTION_ARG_PADDING (passed_mode, type); - boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); + boundary = targetm.calls.function_arg_boundary (passed_mode, type); locate->where_pad = where_pad; /* Alignment can't exceed MAX_SUPPORTED_STACK_ALIGNMENT. */ @@ -3837,7 +3979,7 @@ { tree decl, sub; - for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) + for (decl = BLOCK_VARS (block); decl; decl = DECL_CHAIN (decl)) { if (TREE_CODE (decl) == VAR_DECL && DECL_RTL_SET_P (decl) @@ -3859,7 +4001,7 @@ { tree decl; for (decl = DECL_ARGUMENTS (current_function_decl); - decl; decl = TREE_CHAIN (decl)) + decl; decl = DECL_CHAIN (decl)) if (DECL_RTL (decl) != 0 && REG_P (DECL_RTL (decl)) && regno_clobbered_at_setjmp (setjmp_crosses, REGNO (DECL_RTL (decl)))) @@ -3884,6 +4026,46 @@ } +/* Reverse the order of elements in the fragment chain T of blocks, + and return the new head of the chain (old last element). */ + +static tree +block_fragments_nreverse (tree t) +{ + tree prev = 0, block, next; + for (block = t; block; block = next) + { + next = BLOCK_FRAGMENT_CHAIN (block); + BLOCK_FRAGMENT_CHAIN (block) = prev; + prev = block; + } + return prev; +} + +/* Reverse the order of elements in the chain T of blocks, + and return the new head of the chain (old last element). + Also do the same on subblocks and reverse the order of elements + in BLOCK_FRAGMENT_CHAIN as well. */ + +static tree +blocks_nreverse_all (tree t) +{ + tree prev = 0, block, next; + for (block = t; block; block = next) + { + next = BLOCK_CHAIN (block); + BLOCK_CHAIN (block) = prev; + BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block)); + if (BLOCK_FRAGMENT_CHAIN (block) + && BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE) + BLOCK_FRAGMENT_CHAIN (block) + = block_fragments_nreverse (BLOCK_FRAGMENT_CHAIN (block)); + prev = block; + } + return prev; +} + + /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END}, and create duplicate blocks. */ /* ??? Need an option to either create block fragments or to create @@ -3910,7 +4092,7 @@ /* Recreate the block tree from the note nesting. */ reorder_blocks_1 (get_insns (), block, &block_stack); - BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block)); + BLOCK_SUBBLOCKS (block) = blocks_nreverse_all (BLOCK_SUBBLOCKS (block)); VEC_free (tree, heap, block_stack); } @@ -3942,9 +4124,8 @@ tree block = NOTE_BLOCK (insn); tree origin; - origin = (BLOCK_FRAGMENT_ORIGIN (block) - ? BLOCK_FRAGMENT_ORIGIN (block) - : block); + gcc_assert (BLOCK_FRAGMENT_ORIGIN (block) == NULL_TREE); + origin = block; /* If we have seen this block before, that means it now spans multiple address regions. Create a new fragment. */ @@ -3981,8 +4162,6 @@ else if (NOTE_KIND (insn) == NOTE_INSN_BLOCK_END) { NOTE_BLOCK (insn) = VEC_pop (tree, *p_block_stack); - BLOCK_SUBBLOCKS (current_block) - = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); current_block = BLOCK_SUPERCONTEXT (current_block); } } @@ -3995,12 +4174,12 @@ tree blocks_nreverse (tree t) { - tree prev = 0, decl, next; - for (decl = t; decl; decl = next) + tree prev = 0, block, next; + for (block = t; block; block = next) { - next = BLOCK_CHAIN (decl); - BLOCK_CHAIN (decl) = prev; - prev = decl; + next = BLOCK_CHAIN (block); + BLOCK_CHAIN (block) = prev; + prev = block; } return prev; } @@ -4084,7 +4263,7 @@ /* If VAR is present in a subblock of BLOCK, return the subblock. */ -tree +DEBUG_FUNCTION tree debug_find_var_in_block_tree (tree var, tree block) { tree t; @@ -4129,7 +4308,7 @@ if (optimization_current_node != opts) { optimization_current_node = opts; - cl_optimization_restore (TREE_OPTIMIZATION (opts)); + cl_optimization_restore (&global_options, TREE_OPTIMIZATION (opts)); } targetm.set_current_function (fndecl); @@ -4196,7 +4375,7 @@ tree result; tree fntype = fndecl ? TREE_TYPE (fndecl) : NULL_TREE; - cfun = GGC_CNEW (struct function); + cfun = ggc_alloc_cleared_function (); init_eh_for_function (); @@ -4224,15 +4403,15 @@ cfun->returns_struct = 1; } - cfun->stdarg - = (fntype - && TYPE_ARG_TYPES (fntype) != 0 - && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) - != void_type_node)); + cfun->stdarg = stdarg_p (fntype); /* Assume all registers in stdarg functions need to be saved. */ cfun->va_list_gpr_size = VA_LIST_MAX_GPR_SIZE; cfun->va_list_fpr_size = VA_LIST_MAX_FPR_SIZE; + + /* ??? This could be set on a per-function basis by the front-end + but is this worth the hassle? */ + cfun->can_throw_non_call_exceptions = flag_non_call_exceptions; } } @@ -4246,7 +4425,7 @@ allocate_struct_function (fndecl, false); } -/* Reset cfun, and other non-struct-function variables to defaults as +/* Reset crtl and other non-struct-function variables to defaults as appropriate for emitting rtl at the start of a function. */ static void @@ -4259,6 +4438,12 @@ init_expr (); default_rtl_profile (); + if (flag_stack_usage) + { + cfun->su = ggc_alloc_cleared_stack_usage (); + cfun->su->static_stack_size = -1; + } + cse_not_expected = ! optimize; /* Caller save not needed yet. */ @@ -4697,7 +4882,7 @@ tree decl; for (decl = DECL_ARGUMENTS (fn); - decl; decl = TREE_CHAIN (decl)) + decl; decl = DECL_CHAIN (decl)) if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) && !TREE_NO_WARNING (decl)) @@ -4736,6 +4921,7 @@ probe_stack_range (STACK_OLD_CHECK_PROTECT, max_frame_size); seq = get_insns (); end_sequence (); + set_insn_locators (seq, prologue_locator); emit_insn_before (seq, stack_check_probe_note); break; } @@ -4766,7 +4952,7 @@ /* Output the label for the actual return from the function. */ emit_label (return_label); - if (USING_SJLJ_EXCEPTIONS) + if (targetm.except_unwind_info (&global_options) == UI_SJLJ) { /* Let except.c know where it should emit the call to unregister the function context for sjlj exceptions. */ @@ -4778,7 +4964,7 @@ /* We want to ensure that instructions that may trap are not moved into the epilogue by scheduling, because we don't always emit unwind information for the epilogue. */ - if (flag_non_call_exceptions) + if (cfun->can_throw_non_call_exceptions) emit_insn (gen_blockage ()); } @@ -4924,7 +5110,8 @@ /* @@@ This is a kludge. We want to ensure that instructions that may trap are not moved into the epilogue by scheduling, because we don't always emit unwind information for the epilogue. */ - if (! USING_SJLJ_EXCEPTIONS && flag_non_call_exceptions) + if (cfun->can_throw_non_call_exceptions + && targetm.except_unwind_info (&global_options) != UI_SJLJ) emit_insn (gen_blockage ()); /* If stack protection is enabled for this function, check the guard. */ @@ -4937,10 +5124,15 @@ if (! EXIT_IGNORE_STACK && cfun->calls_alloca) { - rtx tem = 0; - - emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); - emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); + rtx tem = 0, seq; + + start_sequence (); + emit_stack_save (SAVE_FUNCTION, &tem); + seq = get_insns (); + end_sequence (); + emit_insn_before (seq, parm_birth_insn); + + emit_stack_restore (SAVE_FUNCTION, tem); } /* ??? This should no longer be necessary since stupid is no longer with @@ -4977,6 +5169,8 @@ push_topmost_sequence (); emit_insn_after (seq, entry_of_function ()); pop_topmost_sequence (); + + crtl->arg_pointer_save_area_init = true; } return ret; @@ -5003,19 +5197,25 @@ } } -/* INSN has been duplicated as COPY, as part of duping a basic block. - If INSN is an epilogue insn, then record COPY as epilogue as well. */ +/* INSN has been duplicated or replaced by as COPY, perhaps by duplicating a + basic block, splitting or peepholes. If INSN is a prologue or epilogue + insn, then record COPY as well. */ void -maybe_copy_epilogue_insn (rtx insn, rtx copy) +maybe_copy_prologue_epilogue_insn (rtx insn, rtx copy) { + htab_t hash; void **slot; - if (epilogue_insn_hash == NULL - || htab_find (epilogue_insn_hash, insn) == NULL) - return; - - slot = htab_find_slot (epilogue_insn_hash, copy, INSERT); + hash = epilogue_insn_hash; + if (!hash || !htab_find (hash, insn)) + { + hash = prologue_insn_hash; + if (!hash || !htab_find (hash, insn)) + return; + } + + slot = htab_find_slot (hash, copy, INSERT); gcc_assert (*slot == NULL); *slot = copy; } @@ -5081,17 +5281,50 @@ static void thread_prologue_and_epilogue_insns (void) { - int inserted = 0; + bool inserted; + rtx seq ATTRIBUTE_UNUSED, epilogue_end ATTRIBUTE_UNUSED; + edge entry_edge ATTRIBUTE_UNUSED; edge e; -#if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue) - rtx seq; -#endif -#if defined (HAVE_epilogue) || defined(HAVE_return) - rtx epilogue_end = NULL_RTX; -#endif edge_iterator ei; rtl_profile_for_bb (ENTRY_BLOCK_PTR); + + inserted = false; + seq = NULL_RTX; + epilogue_end = NULL_RTX; + + /* Can't deal with multiple successors of the entry block at the + moment. Function should always have at least one entry + point. */ + gcc_assert (single_succ_p (ENTRY_BLOCK_PTR)); + entry_edge = single_succ_edge (ENTRY_BLOCK_PTR); + + if (flag_split_stack + && (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (cfun->decl)) + == NULL)) + { +#ifndef HAVE_split_stack_prologue + gcc_unreachable (); +#else + gcc_assert (HAVE_split_stack_prologue); + + start_sequence (); + emit_insn (gen_split_stack_prologue ()); + seq = get_insns (); + end_sequence (); + + record_insns (seq, NULL, &prologue_insn_hash); + set_insn_locators (seq, prologue_locator); + + /* This relies on the fact that committing the edge insertion + will look for basic blocks within the inserted instructions, + which in turn relies on the fact that we are not in CFG + layout mode here. */ + insert_insn_on_edge (seq, entry_edge); + inserted = true; +#endif + } + #ifdef HAVE_prologue if (HAVE_prologue) { @@ -5108,25 +5341,18 @@ record_insns (seq, NULL, &prologue_insn_hash); emit_note (NOTE_INSN_PROLOGUE_END); -#ifndef PROFILE_BEFORE_PROLOGUE /* Ensure that instructions are not moved into the prologue when profiling is on. The call to the profiling routine can be emitted within the live range of a call-clobbered register. */ - if (crtl->profile) + if (!targetm.profile_before_prologue () && crtl->profile) emit_insn (gen_blockage ()); -#endif seq = get_insns (); end_sequence (); set_insn_locators (seq, prologue_locator); - /* Can't deal with multiple successors of the entry block - at the moment. Function should always have at least one - entry point. */ - gcc_assert (single_succ_p (ENTRY_BLOCK_PTR)); - - insert_insn_on_edge (seq, single_succ_edge (ENTRY_BLOCK_PTR)); - inserted = 1; + insert_insn_on_edge (seq, entry_edge); + inserted = true; } #endif @@ -5151,9 +5377,7 @@ basic_block last; rtx label; - FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds) - if (e->flags & EDGE_FALLTHRU) - break; + e = find_fallthru_edge (EXIT_BLOCK_PTR->preds); if (e == NULL) goto epilogue_done; last = e->src; @@ -5274,9 +5498,7 @@ There really shouldn't be a mixture -- either all should have been converted or none, however... */ - FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR->preds) - if (e->flags & EDGE_FALLTHRU) - break; + e = find_fallthru_edge (EXIT_BLOCK_PTR->preds); if (e == NULL) goto epilogue_done; @@ -5286,7 +5508,8 @@ start_sequence (); epilogue_end = emit_note (NOTE_INSN_EPILOGUE_BEG); seq = gen_epilogue (); - emit_jump_insn (seq); + if (seq) + emit_jump_insn (seq); /* Retain a map of the epilogue insns. */ record_insns (seq, NULL, &epilogue_insn_hash); @@ -5296,7 +5519,7 @@ end_sequence (); insert_insn_on_edge (seq, e); - inserted = 1; + inserted = true; } else #endif @@ -5547,6 +5770,8 @@ break; else t = TREE_TYPE (t); + if (TREE_CODE (t) == ERROR_MARK) + return; if (TYPE_NAME (t) == NULL_TREE || TYPE_NAME (t) == TYPE_NAME (TYPE_MAIN_VARIANT (t))) t = TYPE_MAIN_VARIANT (t); @@ -5558,9 +5783,7 @@ /* So this might be a type referenced by a global variable. Record that type so that we can later decide to emit its debug information. */ - types_used_by_cur_var_decl = - tree_cons (t, NULL, types_used_by_cur_var_decl); - + VEC_safe_push (tree, gc, types_used_by_cur_var_decl, t); } } @@ -5619,8 +5842,7 @@ if (*slot == NULL) { struct types_used_by_vars_entry *entry; - entry = (struct types_used_by_vars_entry*) ggc_alloc - (sizeof (struct types_used_by_vars_entry)); + entry = ggc_alloc_types_used_by_vars_entry (); entry->type = type; entry->var_decl = var_decl; *slot = entry; @@ -5652,12 +5874,17 @@ { if (optimize) cleanup_cfg (CLEANUP_EXPENSIVE); + /* On some machines, the prologue and epilogue code, or parts thereof, can be represented as RTL. Doing so lets us schedule insns between it and the rest of the code and also allows delayed branch scheduling to operate in the epilogue. */ - thread_prologue_and_epilogue_insns (); + + /* The stack usage info is finalized during prologue expansion. */ + if (flag_stack_usage) + output_stack_usage (); + return 0; }