From: Richard Sandiford Date: Thu, 21 Dec 2017 07:01:00 +0000 (+0000) Subject: poly_int: argument sizes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a20c5714c689bf1c0c7a2d2589b4df0eaa4635fb;p=gcc.git poly_int: argument sizes This patch changes various bits of state related to argument sizes so that they have type poly_int64 rather than HOST_WIDE_INT. This includes: - incoming_args::pops_args and incoming_args::size - rtl_data::outgoing_args_size - pending_stack_adjust - stack_pointer_delta - stack_usage::pushed_stack_size - args_size::constant It also changes TARGET_RETURN_POPS_ARGS so that the size of the arguments passed in and the size returned by the hook are both poly_int64s. 2017-12-21 Richard Sandiford Alan Hayward David Sherwood gcc/ * target.def (return_pops_args): Treat both the input and output sizes as poly_int64s rather than HOST_WIDE_INTS. * targhooks.h (default_return_pops_args): Update accordingly. * targhooks.c (default_return_pops_args): Likewise. * doc/tm.texi: Regenerate. * emit-rtl.h (incoming_args): Change pops_args, size and outgoing_args_size from int to poly_int64_pod. * function.h (expr_status): Change x_pending_stack_adjust and x_stack_pointer_delta from int to poly_int64. (args_size::constant): Change from HOST_WIDE_INT to poly_int64. (ARGS_SIZE_RTX): Update accordingly. * calls.c (highest_outgoing_arg_in_use): Change from int to unsigned int. (stack_usage_watermark, stored_args_watermark): New variables. (stack_region_maybe_used_p, mark_stack_region_used): New functions. (emit_call_1): Change the stack_size and rounded_stack_size parameters from HOST_WIDE_INT to poly_int64. Track n_popped as a poly_int64. (save_fixed_argument_area): Check stack_usage_watermark. (initialize_argument_information): Change old_pending_adj from a HOST_WIDE_INT * to a poly_int64_pod *. (compute_argument_block_size): Return the size as a poly_int64 rather than an int. (finalize_must_preallocate): Track polynomial argument sizes. (compute_argument_addresses): Likewise. (internal_arg_pointer_based_exp): Track polynomial offsets. (mem_overlaps_already_clobbered_arg_p): Rename to... (mem_might_overlap_already_clobbered_arg_p): ...this and take the size as a poly_uint64 rather than an unsigned HOST_WIDE_INT. Check stored_args_used_watermark. (load_register_parameters): Update accordingly. (check_sibcall_argument_overlap_1): Likewise. (combine_pending_stack_adjustment_and_call): Take the unadjusted args size as a poly_int64 rather than an int. Return a bool indicating whether the optimization was possible and return the new adjustment by reference. (check_sibcall_argument_overlap): Track polynomail argument sizes. Update stored_args_watermark. (can_implement_as_sibling_call_p): Handle polynomial argument sizes. (expand_call): Likewise. Maintain stack_usage_watermark and stored_args_watermark. Update calls to combine_pending_stack_adjustment_and_call. (emit_library_call_value_1): Handle polynomial argument sizes. Call stack_region_maybe_used_p and mark_stack_region_used. Maintain stack_usage_watermark. (store_one_arg): Likewise. Update call to mem_overlaps_already_clobbered_arg_p. * config/arm/arm.c (arm_output_function_prologue): Add a cast to HOST_WIDE_INT. * config/avr/avr.c (avr_outgoing_args_size): Likewise. * config/microblaze/microblaze.c (microblaze_function_prologue): Likewise. * config/cr16/cr16.c (cr16_return_pops_args): Update for new TARGET_RETURN_POPS_ARGS interface. (cr16_compute_frame, cr16_initial_elimination_offset): Add casts to HOST_WIDE_INT. * config/ft32/ft32.c (ft32_compute_frame): Likewise. * config/i386/i386.c (ix86_return_pops_args): Update for new TARGET_RETURN_POPS_ARGS interface. (ix86_expand_split_stack_prologue): Add a cast to HOST_WIDE_INT. * config/moxie/moxie.c (moxie_compute_frame): Likewise. * config/m68k/m68k.c (m68k_return_pops_args): Update for new TARGET_RETURN_POPS_ARGS interface. * config/vax/vax.c (vax_return_pops_args): Likewise. * config/pa/pa.h (STACK_POINTER_OFFSET): Add a cast to poly_int64. (EXIT_IGNORE_STACK): Update reference to crtl->outgoing_args_size. * config/arm/arm.h (CALLER_INTERWORKING_SLOT_SIZE): Likewise. * config/powerpcspe/aix.h (STACK_DYNAMIC_OFFSET): Likewise. * config/powerpcspe/darwin.h (STACK_DYNAMIC_OFFSET): Likewise. * config/powerpcspe/powerpcspe.h (STACK_DYNAMIC_OFFSET): Likewise. * config/rs6000/aix.h (STACK_DYNAMIC_OFFSET): Likewise. * config/rs6000/darwin.h (STACK_DYNAMIC_OFFSET): Likewise. * config/rs6000/rs6000.h (STACK_DYNAMIC_OFFSET): Likewise. * dojump.h (saved_pending_stack_adjust): Change x_pending_stack_adjust and x_stack_pointer_delta from int to poly_int64. * dojump.c (do_pending_stack_adjust): Update accordingly. * explow.c (allocate_dynamic_stack_space): Handle polynomial stack_pointer_deltas. * function.c (STACK_DYNAMIC_OFFSET): Add a cast to poly_int64. (pad_to_arg_alignment): Track polynomial offsets. (assign_parm_find_stack_rtl): Likewise. (assign_parms, locate_and_pad_parm): Handle polynomial argument sizes. * toplev.c (output_stack_usage): Update reference to current_function_pushed_stack_size. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r255921 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d682556a80..729ce4eaf03 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,92 @@ +2017-12-21 Richard Sandiford + Alan Hayward + David Sherwood + + * target.def (return_pops_args): Treat both the input and output + sizes as poly_int64s rather than HOST_WIDE_INTS. + * targhooks.h (default_return_pops_args): Update accordingly. + * targhooks.c (default_return_pops_args): Likewise. + * doc/tm.texi: Regenerate. + * emit-rtl.h (incoming_args): Change pops_args, size and + outgoing_args_size from int to poly_int64_pod. + * function.h (expr_status): Change x_pending_stack_adjust and + x_stack_pointer_delta from int to poly_int64. + (args_size::constant): Change from HOST_WIDE_INT to poly_int64. + (ARGS_SIZE_RTX): Update accordingly. + * calls.c (highest_outgoing_arg_in_use): Change from int to + unsigned int. + (stack_usage_watermark, stored_args_watermark): New variables. + (stack_region_maybe_used_p, mark_stack_region_used): New functions. + (emit_call_1): Change the stack_size and rounded_stack_size + parameters from HOST_WIDE_INT to poly_int64. Track n_popped + as a poly_int64. + (save_fixed_argument_area): Check stack_usage_watermark. + (initialize_argument_information): Change old_pending_adj from + a HOST_WIDE_INT * to a poly_int64_pod *. + (compute_argument_block_size): Return the size as a poly_int64 + rather than an int. + (finalize_must_preallocate): Track polynomial argument sizes. + (compute_argument_addresses): Likewise. + (internal_arg_pointer_based_exp): Track polynomial offsets. + (mem_overlaps_already_clobbered_arg_p): Rename to... + (mem_might_overlap_already_clobbered_arg_p): ...this and take the + size as a poly_uint64 rather than an unsigned HOST_WIDE_INT. + Check stored_args_used_watermark. + (load_register_parameters): Update accordingly. + (check_sibcall_argument_overlap_1): Likewise. + (combine_pending_stack_adjustment_and_call): Take the unadjusted + args size as a poly_int64 rather than an int. Return a bool + indicating whether the optimization was possible and return + the new adjustment by reference. + (check_sibcall_argument_overlap): Track polynomail argument sizes. + Update stored_args_watermark. + (can_implement_as_sibling_call_p): Handle polynomial argument sizes. + (expand_call): Likewise. Maintain stack_usage_watermark and + stored_args_watermark. Update calls to + combine_pending_stack_adjustment_and_call. + (emit_library_call_value_1): Handle polynomial argument sizes. + Call stack_region_maybe_used_p and mark_stack_region_used. + Maintain stack_usage_watermark. + (store_one_arg): Likewise. Update call to + mem_overlaps_already_clobbered_arg_p. + * config/arm/arm.c (arm_output_function_prologue): Add a cast to + HOST_WIDE_INT. + * config/avr/avr.c (avr_outgoing_args_size): Likewise. + * config/microblaze/microblaze.c (microblaze_function_prologue): + Likewise. + * config/cr16/cr16.c (cr16_return_pops_args): Update for new + TARGET_RETURN_POPS_ARGS interface. + (cr16_compute_frame, cr16_initial_elimination_offset): Add casts + to HOST_WIDE_INT. + * config/ft32/ft32.c (ft32_compute_frame): Likewise. + * config/i386/i386.c (ix86_return_pops_args): Update for new + TARGET_RETURN_POPS_ARGS interface. + (ix86_expand_split_stack_prologue): Add a cast to HOST_WIDE_INT. + * config/moxie/moxie.c (moxie_compute_frame): Likewise. + * config/m68k/m68k.c (m68k_return_pops_args): Update for new + TARGET_RETURN_POPS_ARGS interface. + * config/vax/vax.c (vax_return_pops_args): Likewise. + * config/pa/pa.h (STACK_POINTER_OFFSET): Add a cast to poly_int64. + (EXIT_IGNORE_STACK): Update reference to crtl->outgoing_args_size. + * config/arm/arm.h (CALLER_INTERWORKING_SLOT_SIZE): Likewise. + * config/powerpcspe/aix.h (STACK_DYNAMIC_OFFSET): Likewise. + * config/powerpcspe/darwin.h (STACK_DYNAMIC_OFFSET): Likewise. + * config/powerpcspe/powerpcspe.h (STACK_DYNAMIC_OFFSET): Likewise. + * config/rs6000/aix.h (STACK_DYNAMIC_OFFSET): Likewise. + * config/rs6000/darwin.h (STACK_DYNAMIC_OFFSET): Likewise. + * config/rs6000/rs6000.h (STACK_DYNAMIC_OFFSET): Likewise. + * dojump.h (saved_pending_stack_adjust): Change x_pending_stack_adjust + and x_stack_pointer_delta from int to poly_int64. + * dojump.c (do_pending_stack_adjust): Update accordingly. + * explow.c (allocate_dynamic_stack_space): Handle polynomial + stack_pointer_deltas. + * function.c (STACK_DYNAMIC_OFFSET): Add a cast to poly_int64. + (pad_to_arg_alignment): Track polynomial offsets. + (assign_parm_find_stack_rtl): Likewise. + (assign_parms, locate_and_pad_parm): Handle polynomial argument sizes. + * toplev.c (output_stack_usage): Update reference to + current_function_pushed_stack_size. + 2017-12-21 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/calls.c b/gcc/calls.c index 1387d152e9e..9b7e1189918 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -128,7 +128,11 @@ struct arg_data static char *stack_usage_map; /* Size of STACK_USAGE_MAP. */ -static int highest_outgoing_arg_in_use; +static unsigned int highest_outgoing_arg_in_use; + +/* Assume that any stack location at this byte index is used, + without checking the contents of stack_usage_map. */ +static unsigned HOST_WIDE_INT stack_usage_watermark = HOST_WIDE_INT_M1U; /* A bitmap of virtual-incoming stack space. Bit is set if the corresponding stack location's tail call argument has been already stored into the stack. @@ -137,6 +141,10 @@ static int highest_outgoing_arg_in_use; overwritten with tail call arguments. */ static sbitmap stored_args_map; +/* Assume that any virtual-incoming location at this byte index has been + stored, without checking the contents of stored_args_map. */ +static unsigned HOST_WIDE_INT stored_args_watermark; + /* stack_arg_under_construction is nonzero when an argument may be initialized with a constructor call (including a C function that returns a BLKmode struct) and expand_call must take special action @@ -144,9 +152,6 @@ static sbitmap stored_args_map; argument list for the constructor call. */ static int stack_arg_under_construction; -static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT, - HOST_WIDE_INT, rtx, rtx, int, rtx, int, - cumulative_args_t); static void precompute_register_parameters (int, struct arg_data *, int *); static void store_bounds (struct arg_data *, struct arg_data *); static int store_one_arg (struct arg_data *, rtx, int, int, int); @@ -154,13 +159,6 @@ static void store_unaligned_arguments_into_pseudos (struct arg_data *, int); static int finalize_must_preallocate (int, int, struct arg_data *, struct args_size *); static void precompute_arguments (int, struct arg_data *); -static int compute_argument_block_size (int, struct args_size *, tree, tree, int); -static void initialize_argument_information (int, struct arg_data *, - struct args_size *, int, - tree, tree, - tree, tree, cumulative_args_t, int, - rtx *, int *, int *, int *, - bool *, bool); static void compute_argument_addresses (struct arg_data *, rtx, int); static rtx rtx_for_function_call (tree, tree); static void load_register_parameters (struct arg_data *, int, rtx *, int, @@ -169,8 +167,6 @@ static int special_function_p (const_tree, int); static int check_sibcall_argument_overlap_1 (rtx); static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int); -static int combine_pending_stack_adjustment_and_call (int, struct args_size *, - unsigned int); static tree split_complex_types (tree); #ifdef REG_PARM_STACK_SPACE @@ -178,6 +174,46 @@ static rtx save_fixed_argument_area (int, rtx, int *, int *); static void restore_fixed_argument_area (rtx, rtx, int, int); #endif +/* Return true if bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing + stack region might already be in use. */ + +static bool +stack_region_maybe_used_p (poly_uint64 lower_bound, poly_uint64 upper_bound, + unsigned int reg_parm_stack_space) +{ + unsigned HOST_WIDE_INT const_lower, const_upper; + const_lower = constant_lower_bound (lower_bound); + if (!upper_bound.is_constant (&const_upper)) + const_upper = HOST_WIDE_INT_M1U; + + if (const_upper > stack_usage_watermark) + return true; + + /* Don't worry about things in the fixed argument area; + it has already been saved. */ + const_lower = MAX (const_lower, reg_parm_stack_space); + const_upper = MIN (const_upper, highest_outgoing_arg_in_use); + for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i) + if (stack_usage_map[i]) + return true; + return false; +} + +/* Record that bytes [LOWER_BOUND, UPPER_BOUND) of the outgoing + stack region are now in use. */ + +static void +mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound) +{ + unsigned HOST_WIDE_INT const_lower, const_upper; + const_lower = constant_lower_bound (lower_bound); + if (upper_bound.is_constant (&const_upper)) + for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i) + stack_usage_map[i] = 1; + else + stack_usage_watermark = MIN (stack_usage_watermark, const_lower); +} + /* Force FUNEXP into a form suitable for the address of a CALL, and return that as an rtx. Also load the static chain register if FNDECL is a nested function. @@ -340,17 +376,17 @@ prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value, static void emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED, tree funtype ATTRIBUTE_UNUSED, - HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED, - HOST_WIDE_INT rounded_stack_size, + poly_int64 stack_size ATTRIBUTE_UNUSED, + poly_int64 rounded_stack_size, HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED, rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg, int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags, cumulative_args_t args_so_far ATTRIBUTE_UNUSED) { - rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size); + rtx rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode); rtx call, funmem, pat; int already_popped = 0; - HOST_WIDE_INT n_popped = 0; + poly_int64 n_popped = 0; /* Sibling call patterns never pop arguments (no sibcall(_value)_pop patterns exist). Any popping that the callee does on return will @@ -408,12 +444,12 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU if no arguments are actually popped. If the target does not have "call" or "call_value" insns, then we must use the popping versions even if the call has no arguments to pop. */ - else if (n_popped > 0 + else if (maybe_ne (n_popped, 0) || !(valreg ? targetm.have_call_value () : targetm.have_call ())) { - rtx n_pop = GEN_INT (n_popped); + rtx n_pop = gen_int_mode (n_popped, Pmode); /* If this subroutine pops its own args, record that in the call insn if possible, for the sake of frame pointer elimination. */ @@ -487,7 +523,7 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU if the context of the call as a whole permits. */ inhibit_defer_pop = old_inhibit_defer_pop; - if (n_popped > 0) + if (maybe_ne (n_popped, 0)) { if (!already_popped) CALL_INSN_FUNCTION_USAGE (call_insn) @@ -495,7 +531,7 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx), CALL_INSN_FUNCTION_USAGE (call_insn)); rounded_stack_size -= n_popped; - rounded_stack_size_rtx = GEN_INT (rounded_stack_size); + rounded_stack_size_rtx = gen_int_mode (rounded_stack_size, Pmode); stack_pointer_delta -= n_popped; add_args_size_note (call_insn, stack_pointer_delta); @@ -519,7 +555,7 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU If returning from the subroutine does pop the args, indicate that the stack pointer will be changed. */ - if (rounded_stack_size != 0) + if (maybe_ne (rounded_stack_size, 0)) { if (ecf_flags & ECF_NORETURN) /* Just pretend we did the pop. */ @@ -542,8 +578,8 @@ emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNU ??? It will be worthwhile to enable combine_stack_adjustments even for such machines. */ - else if (n_popped) - anti_adjust_stack (GEN_INT (n_popped)); + else if (maybe_ne (n_popped, 0)) + anti_adjust_stack (gen_int_mode (n_popped, Pmode)); } /* Determine if the function identified by FNDECL is one with @@ -1009,8 +1045,8 @@ precompute_register_parameters (int num_actuals, struct arg_data *args, static rtx save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save) { - int low; - int high; + unsigned int low; + unsigned int high; /* Compute the boundary of the area that needs to be saved, if any. */ high = reg_parm_stack_space; @@ -1021,7 +1057,7 @@ save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_sa high = highest_outgoing_arg_in_use; for (low = 0; low < high; low++) - if (stack_usage_map[low] != 0) + if (stack_usage_map[low] != 0 || low >= stack_usage_watermark) { int num_to_save; machine_mode save_mode; @@ -1722,7 +1758,8 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, tree fndecl, tree fntype, cumulative_args_t args_so_far, int reg_parm_stack_space, - rtx *old_stack_level, int *old_pending_adj, + rtx *old_stack_level, + poly_int64_pod *old_pending_adj, int *must_preallocate, int *ecf_flags, bool *may_tailcall, bool call_from_thunk_p) { @@ -2133,14 +2170,14 @@ initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved for arguments passed in registers. */ -static int +static poly_int64 compute_argument_block_size (int reg_parm_stack_space, struct args_size *args_size, tree fndecl ATTRIBUTE_UNUSED, tree fntype ATTRIBUTE_UNUSED, int preferred_stack_boundary ATTRIBUTE_UNUSED) { - int unadjusted_args_size = args_size->constant; + poly_int64 unadjusted_args_size = args_size->constant; /* For accumulate outgoing args mode we don't need to align, since the frame will be already aligned. Align to STACK_BOUNDARY in order to prevent @@ -2163,7 +2200,8 @@ compute_argument_block_size (int reg_parm_stack_space, /* We don't handle this case yet. To handle it correctly we have to add the delta, round and subtract the delta. Currently no machine description requires this support. */ - gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1))); + gcc_assert (multiple_p (stack_pointer_delta, + preferred_stack_boundary)); args_size->var = round_up (args_size->var, preferred_stack_boundary); } @@ -2186,15 +2224,13 @@ compute_argument_block_size (int reg_parm_stack_space, preferred_stack_boundary /= BITS_PER_UNIT; if (preferred_stack_boundary < 1) preferred_stack_boundary = 1; - args_size->constant = (((args_size->constant - + stack_pointer_delta - + preferred_stack_boundary - 1) - / preferred_stack_boundary - * preferred_stack_boundary) + args_size->constant = (aligned_upper_bound (args_size->constant + + stack_pointer_delta, + preferred_stack_boundary) - stack_pointer_delta); - args_size->constant = MAX (args_size->constant, - reg_parm_stack_space); + args_size->constant = upper_bound (args_size->constant, + reg_parm_stack_space); if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) args_size->constant -= reg_parm_stack_space; @@ -2299,7 +2335,7 @@ finalize_must_preallocate (int must_preallocate, int num_actuals, if (! must_preallocate) { int partial_seen = 0; - int copy_to_evaluate_size = 0; + poly_int64 copy_to_evaluate_size = 0; int i; for (i = 0; i < num_actuals && ! must_preallocate; i++) @@ -2324,8 +2360,8 @@ finalize_must_preallocate (int must_preallocate, int num_actuals, += int_size_in_bytes (TREE_TYPE (args[i].tree_value)); } - if (copy_to_evaluate_size * 2 >= args_size->constant - && args_size->constant > 0) + if (maybe_ne (args_size->constant, 0) + && maybe_ge (copy_to_evaluate_size * 2, args_size->constant)) must_preallocate = 1; } return must_preallocate; @@ -2345,10 +2381,14 @@ compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals if (argblock) { rtx arg_reg = argblock; - int i, arg_offset = 0; + int i; + poly_int64 arg_offset = 0; if (GET_CODE (argblock) == PLUS) - arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1)); + { + arg_reg = XEXP (argblock, 0); + arg_offset = rtx_to_poly_int64 (XEXP (argblock, 1)); + } for (i = 0; i < num_actuals; i++) { @@ -2356,7 +2396,7 @@ compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset); rtx addr; unsigned int align, boundary; - unsigned int units_on_stack = 0; + poly_uint64 units_on_stack = 0; machine_mode partial_mode = VOIDmode; /* Skip this parm if it will not be passed on the stack. */ @@ -2380,7 +2420,7 @@ compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals /* Only part of the parameter is being passed on the stack. Generate a simple memory reference of the correct size. */ units_on_stack = args[i].locate.size.constant; - unsigned int bits_on_stack = units_on_stack * BITS_PER_UNIT; + poly_uint64 bits_on_stack = units_on_stack * BITS_PER_UNIT; partial_mode = int_mode_for_size (bits_on_stack, 1).else_blk (); args[i].stack = gen_rtx_MEM (partial_mode, addr); set_mem_size (args[i].stack, units_on_stack); @@ -2393,12 +2433,16 @@ compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals } align = BITS_PER_UNIT; boundary = args[i].locate.boundary; + poly_int64 offset_val; if (args[i].locate.where_pad != PAD_DOWNWARD) align = boundary; - else if (CONST_INT_P (offset)) + else if (poly_int_rtx_p (offset, &offset_val)) { - align = INTVAL (offset) * BITS_PER_UNIT | boundary; - align = least_bit_hwi (align); + align = least_bit_hwi (boundary); + unsigned int offset_align + = known_alignment (offset_val) * BITS_PER_UNIT; + if (offset_align != 0) + align = MIN (align, offset_align); } set_mem_align (args[i].stack, align); @@ -2552,12 +2596,13 @@ internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel) if (REG_P (rtl) && HARD_REGISTER_P (rtl)) return NULL_RTX; - if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1))) + poly_int64 offset; + if (GET_CODE (rtl) == PLUS && poly_int_rtx_p (XEXP (rtl, 1), &offset)) { rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel); if (val == NULL_RTX || val == pc_rtx) return val; - return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1))); + return plus_constant (Pmode, val, offset); } /* When called at the topmost level, scan pseudo assignments in between the @@ -2588,45 +2633,53 @@ internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel) return NULL_RTX; } -/* Return true if and only if SIZE storage units (usually bytes) - starting from address ADDR overlap with already clobbered argument - area. This function is used to determine if we should give up a - sibcall. */ +/* Return true if SIZE bytes starting from address ADDR might overlap an + already-clobbered argument area. This function is used to determine + if we should give up a sibcall. */ static bool -mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size) +mem_might_overlap_already_clobbered_arg_p (rtx addr, poly_uint64 size) { - HOST_WIDE_INT i; + poly_int64 i; + unsigned HOST_WIDE_INT start, end; rtx val; - if (bitmap_empty_p (stored_args_map)) + if (bitmap_empty_p (stored_args_map) + && stored_args_watermark == HOST_WIDE_INT_M1U) return false; val = internal_arg_pointer_based_exp (addr, true); if (val == NULL_RTX) return false; - else if (val == pc_rtx) + else if (!poly_int_rtx_p (val, &i)) return true; - else - i = INTVAL (val); + + if (known_eq (size, 0U)) + return false; if (STACK_GROWS_DOWNWARD) i -= crtl->args.pretend_args_size; else i += crtl->args.pretend_args_size; - if (ARGS_GROW_DOWNWARD) i = -i - size; - if (size > 0) - { - unsigned HOST_WIDE_INT k; + /* We can ignore any references to the function's pretend args, + which at this point would manifest as negative values of I. */ + if (known_le (i, 0) && known_le (size, poly_uint64 (-i))) + return false; - for (k = 0; k < size; k++) - if (i + k < SBITMAP_SIZE (stored_args_map) - && bitmap_bit_p (stored_args_map, i + k)) - return true; - } + start = maybe_lt (i, 0) ? 0 : constant_lower_bound (i); + if (!(i + size).is_constant (&end)) + end = HOST_WIDE_INT_M1U; + + if (end > stored_args_watermark) + return true; + + end = MIN (end, SBITMAP_SIZE (stored_args_map)); + for (unsigned HOST_WIDE_INT k = start; k < end; ++k) + if (bitmap_bit_p (stored_args_map, k)) + return true; return false; } @@ -2730,7 +2783,7 @@ load_register_parameters (struct arg_data *args, int num_actuals, providing that this has non-zero size. */ if (is_sibcall && size != 0 - && (mem_overlaps_already_clobbered_arg_p + && (mem_might_overlap_already_clobbered_arg_p (XEXP (args[i].value, 0), size))) *sibcall_failure = 1; @@ -2799,27 +2852,32 @@ load_register_parameters (struct arg_data *args, int num_actuals, /* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY bytes, then we would need to push some additional bytes to pad the - arguments. So, we compute an adjust to the stack pointer for an + arguments. So, we try to compute an adjust to the stack pointer for an amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE bytes. Then, when the arguments are pushed the stack will be perfectly - aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should - be popped after the call. Returns the adjustment. */ + aligned. -static int -combine_pending_stack_adjustment_and_call (int unadjusted_args_size, + Return true if this optimization is possible, storing the adjustment + in ADJUSTMENT_OUT and setting ARGS_SIZE->CONSTANT to the number of + bytes that should be popped after the call. */ + +static bool +combine_pending_stack_adjustment_and_call (poly_int64_pod *adjustment_out, + poly_int64 unadjusted_args_size, struct args_size *args_size, unsigned int preferred_unit_stack_boundary) { /* The number of bytes to pop so that the stack will be under-aligned by UNADJUSTED_ARGS_SIZE bytes. */ - HOST_WIDE_INT adjustment; + poly_int64 adjustment; /* The alignment of the stack after the arguments are pushed, if we just pushed the arguments without adjust the stack here. */ unsigned HOST_WIDE_INT unadjusted_alignment; - unadjusted_alignment - = ((stack_pointer_delta + unadjusted_args_size) - % preferred_unit_stack_boundary); + if (!known_misalignment (stack_pointer_delta + unadjusted_args_size, + preferred_unit_stack_boundary, + &unadjusted_alignment)) + return false; /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes as possible -- leaving just enough left to cancel out the @@ -2828,15 +2886,24 @@ combine_pending_stack_adjustment_and_call (int unadjusted_args_size, -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */ /* Begin by trying to pop all the bytes. */ - unadjusted_alignment - = (unadjusted_alignment - - (pending_stack_adjust % preferred_unit_stack_boundary)); + unsigned HOST_WIDE_INT tmp_misalignment; + if (!known_misalignment (pending_stack_adjust, + preferred_unit_stack_boundary, + &tmp_misalignment)) + return false; + unadjusted_alignment -= tmp_misalignment; adjustment = pending_stack_adjust; /* Push enough additional bytes that the stack will be aligned after the arguments are pushed. */ if (preferred_unit_stack_boundary > 1 && unadjusted_alignment) adjustment -= preferred_unit_stack_boundary - unadjusted_alignment; + /* We need to know whether the adjusted argument size + (UNADJUSTED_ARGS_SIZE - ADJUSTMENT) constitutes an allocation + or a deallocation. */ + if (!ordered_p (adjustment, unadjusted_args_size)) + return false; + /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of bytes after the call. The right number is the entire PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required @@ -2844,7 +2911,8 @@ combine_pending_stack_adjustment_and_call (int unadjusted_args_size, args_size->constant = pending_stack_adjust - adjustment + unadjusted_args_size; - return adjustment; + *adjustment_out = adjustment; + return true; } /* Scan X expression if it does not dereference any argument slots @@ -2870,8 +2938,8 @@ check_sibcall_argument_overlap_1 (rtx x) return 0; if (code == MEM) - return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0), - GET_MODE_SIZE (GET_MODE (x))); + return (mem_might_overlap_already_clobbered_arg_p + (XEXP (x, 0), GET_MODE_SIZE (GET_MODE (x)))); /* Scan all subexpressions. */ fmt = GET_RTX_FORMAT (code); @@ -2903,7 +2971,8 @@ static int check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg, int mark_stored_args_map) { - int low, high; + poly_uint64 low, high; + unsigned HOST_WIDE_INT const_low, const_high; if (insn == NULL_RTX) insn = get_insns (); @@ -2921,9 +2990,14 @@ check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg, low = -arg->locate.slot_offset.constant - arg->locate.size.constant; else low = arg->locate.slot_offset.constant; + high = low + arg->locate.size.constant; - for (high = low + arg->locate.size.constant; low < high; low++) - bitmap_set_bit (stored_args_map, low); + const_low = constant_lower_bound (low); + if (high.is_constant (&const_high)) + for (unsigned HOST_WIDE_INT i = const_low; i < const_high; ++i) + bitmap_set_bit (stored_args_map, i); + else + stored_args_watermark = MIN (stored_args_watermark, const_low); } return insn != NULL_RTX; } @@ -3066,7 +3140,8 @@ can_implement_as_sibling_call_p (tree exp, function, we cannot change it into a sibling call. crtl->args.pretend_args_size is not part of the stack allocated by our caller. */ - if (args_size.constant > (crtl->args.size - crtl->args.pretend_args_size)) + if (maybe_gt (args_size.constant, + crtl->args.size - crtl->args.pretend_args_size)) { maybe_complain_about_tail_call (exp, "callee required more stack slots" @@ -3076,10 +3151,12 @@ can_implement_as_sibling_call_p (tree exp, /* If the callee pops its own arguments, then it must pop exactly the same number of arguments as the current function. */ - if (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant) - != targetm.calls.return_pops_args (current_function_decl, - TREE_TYPE (current_function_decl), - crtl->args.size)) + if (maybe_ne (targetm.calls.return_pops_args (fndecl, funtype, + args_size.constant), + targetm.calls.return_pops_args (current_function_decl, + TREE_TYPE + (current_function_decl), + crtl->args.size))) { maybe_complain_about_tail_call (exp, "inconsistent number of" @@ -3169,7 +3246,7 @@ expand_call (tree exp, rtx target, int ignore) struct args_size args_size; struct args_size adjusted_args_size; /* Size of arguments before any adjustments (such as rounding). */ - int unadjusted_args_size; + poly_int64 unadjusted_args_size; /* Data on reg parms scanned so far. */ CUMULATIVE_ARGS args_so_far_v; cumulative_args_t args_so_far; @@ -3202,22 +3279,23 @@ expand_call (tree exp, rtx target, int ignore) rtx save_area = 0; /* Place that it is saved */ #endif - int initial_highest_arg_in_use = highest_outgoing_arg_in_use; + unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use; char *initial_stack_usage_map = stack_usage_map; + unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark; char *stack_usage_map_buf = NULL; - int old_stack_allocated; + poly_int64 old_stack_allocated; /* State variables to track stack modifications. */ rtx old_stack_level = 0; int old_stack_arg_under_construction = 0; - int old_pending_adj = 0; + poly_int64 old_pending_adj = 0; int old_inhibit_defer_pop = inhibit_defer_pop; /* Some stack pointer alterations we make are performed via allocate_dynamic_stack_space. This modifies the stack_pointer_delta, which we then also need to save/restore along the way. */ - int old_stack_pointer_delta = 0; + poly_int64 old_stack_pointer_delta = 0; rtx call_fusage; tree addr = CALL_EXPR_FN (exp); @@ -3481,7 +3559,8 @@ expand_call (tree exp, rtx target, int ignore) || reg_mentioned_p (virtual_outgoing_args_rtx, structure_value_addr)) && (args_size.var - || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant))) + || (!ACCUMULATE_OUTGOING_ARGS + && maybe_ne (args_size.constant, 0)))) structure_value_addr = copy_to_reg (structure_value_addr); /* Tail calls can make things harder to debug, and we've traditionally @@ -3597,10 +3676,10 @@ expand_call (tree exp, rtx target, int ignore) call sequence. Also do the adjustments before a throwing call, otherwise exception handling can fail; PR 19225. */ - if (pending_stack_adjust >= 32 - || (pending_stack_adjust > 0 + if (maybe_ge (pending_stack_adjust, 32) + || (maybe_ne (pending_stack_adjust, 0) && (flags & ECF_MAY_BE_ALLOCA)) - || (pending_stack_adjust > 0 + || (maybe_ne (pending_stack_adjust, 0) && flag_exceptions && !(flags & ECF_NOTHROW)) || pass == 0) do_pending_stack_adjust (); @@ -3646,8 +3725,10 @@ expand_call (tree exp, rtx target, int ignore) argblock = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size); - stored_args_map = sbitmap_alloc (args_size.constant); + HOST_WIDE_INT map_size = constant_lower_bound (args_size.constant); + stored_args_map = sbitmap_alloc (map_size); bitmap_clear (stored_args_map); + stored_args_watermark = HOST_WIDE_INT_M1U; } /* If we have no actual push instructions, or shouldn't use them, @@ -3677,14 +3758,14 @@ expand_call (tree exp, rtx target, int ignore) in the area reserved for register arguments, which may be part of the stack frame. */ - int needed = adjusted_args_size.constant; + poly_int64 needed = adjusted_args_size.constant; /* Store the maximum argument space used. It will be pushed by the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow checking). */ - if (needed > crtl->outgoing_args_size) - crtl->outgoing_args_size = needed; + crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size, + needed); if (must_preallocate) { @@ -3710,12 +3791,16 @@ expand_call (tree exp, rtx target, int ignore) if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) needed += reg_parm_stack_space; + poly_int64 limit = needed; if (ARGS_GROW_DOWNWARD) - highest_outgoing_arg_in_use - = MAX (initial_highest_arg_in_use, needed + 1); - else - highest_outgoing_arg_in_use - = MAX (initial_highest_arg_in_use, needed); + limit += 1; + + /* For polynomial sizes, this is the maximum possible + size needed for arguments with a constant size + and offset. */ + HOST_WIDE_INT const_limit = constant_lower_bound (limit); + highest_outgoing_arg_in_use + = MAX (initial_highest_arg_in_use, const_limit); free (stack_usage_map_buf); stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use); @@ -3740,23 +3825,25 @@ expand_call (tree exp, rtx target, int ignore) } else { - if (inhibit_defer_pop == 0) + /* Try to reuse some or all of the pending_stack_adjust + to get this space. */ + if (inhibit_defer_pop == 0 + && (combine_pending_stack_adjustment_and_call + (&needed, + unadjusted_args_size, + &adjusted_args_size, + preferred_unit_stack_boundary))) { - /* Try to reuse some or all of the pending_stack_adjust - to get this space. */ - needed - = (combine_pending_stack_adjustment_and_call - (unadjusted_args_size, - &adjusted_args_size, - preferred_unit_stack_boundary)); - /* combine_pending_stack_adjustment_and_call computes an adjustment before the arguments are allocated. Account for them and see whether or not the stack needs to go up or down. */ needed = unadjusted_args_size - needed; - if (needed < 0) + /* Checked by + combine_pending_stack_adjustment_and_call. */ + gcc_checking_assert (ordered_p (needed, 0)); + if (maybe_lt (needed, 0)) { /* We're releasing stack space. */ /* ??? We can avoid any adjustment at all if we're @@ -3773,11 +3860,12 @@ expand_call (tree exp, rtx target, int ignore) /* Special case this because overhead of `push_block' in this case is non-trivial. */ - if (needed == 0) + if (known_eq (needed, 0)) argblock = virtual_outgoing_args_rtx; else { - argblock = push_block (GEN_INT (needed), 0, 0); + rtx needed_rtx = gen_int_mode (needed, Pmode); + argblock = push_block (needed_rtx, 0, 0); if (ARGS_GROW_DOWNWARD) argblock = plus_constant (Pmode, argblock, needed); } @@ -3803,10 +3891,11 @@ expand_call (tree exp, rtx target, int ignore) if (stack_arg_under_construction) { rtx push_size - = GEN_INT (adjusted_args_size.constant - + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype - : TREE_TYPE (fndecl))) ? 0 - : reg_parm_stack_space)); + = (gen_int_mode + (adjusted_args_size.constant + + (OUTGOING_REG_PARM_STACK_SPACE (!fndecl ? fntype + : TREE_TYPE (fndecl)) + ? 0 : reg_parm_stack_space), Pmode)); if (old_stack_level == 0) { emit_stack_save (SAVE_BLOCK, &old_stack_level); @@ -3825,6 +3914,7 @@ expand_call (tree exp, rtx target, int ignore) stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use); stack_usage_map = stack_usage_map_buf; highest_outgoing_arg_in_use = 0; + stack_usage_watermark = HOST_WIDE_INT_M1U; } /* We can pass TRUE as the 4th argument because we just saved the stack pointer and will restore it right after @@ -3860,24 +3950,23 @@ expand_call (tree exp, rtx target, int ignore) /* Perform stack alignment before the first push (the last arg). */ if (argblock == 0 - && adjusted_args_size.constant > reg_parm_stack_space - && adjusted_args_size.constant != unadjusted_args_size) + && maybe_gt (adjusted_args_size.constant, reg_parm_stack_space) + && maybe_ne (adjusted_args_size.constant, unadjusted_args_size)) { /* When the stack adjustment is pending, we get better code by combining the adjustments. */ - if (pending_stack_adjust - && ! inhibit_defer_pop) - { - pending_stack_adjust - = (combine_pending_stack_adjustment_and_call - (unadjusted_args_size, - &adjusted_args_size, - preferred_unit_stack_boundary)); - do_pending_stack_adjust (); - } + if (maybe_ne (pending_stack_adjust, 0) + && ! inhibit_defer_pop + && (combine_pending_stack_adjustment_and_call + (&pending_stack_adjust, + unadjusted_args_size, + &adjusted_args_size, + preferred_unit_stack_boundary))) + do_pending_stack_adjust (); else if (argblock == 0) - anti_adjust_stack (GEN_INT (adjusted_args_size.constant - - unadjusted_args_size)); + anti_adjust_stack (gen_int_mode (adjusted_args_size.constant + - unadjusted_args_size, + Pmode)); } /* Now that the stack is properly aligned, pops can't safely be deferred during the evaluation of the arguments. */ @@ -3891,9 +3980,10 @@ expand_call (tree exp, rtx target, int ignore) && pass && adjusted_args_size.var == 0) { - int pushed = adjusted_args_size.constant + pending_stack_adjust; - if (pushed > current_function_pushed_stack_size) - current_function_pushed_stack_size = pushed; + poly_int64 pushed = (adjusted_args_size.constant + + pending_stack_adjust); + current_function_pushed_stack_size + = upper_bound (current_function_pushed_stack_size, pushed); } funexp = rtx_for_function_call (fndecl, addr); @@ -3928,7 +4018,7 @@ expand_call (tree exp, rtx target, int ignore) /* We don't allow passing huge (> 2^30 B) arguments by value. It would cause an overflow later on. */ - if (adjusted_args_size.constant + if (constant_lower_bound (adjusted_args_size.constant) >= (1 << (HOST_BITS_PER_INT - 2))) { sorry ("passing too large argument on stack"); @@ -4111,7 +4201,8 @@ expand_call (tree exp, rtx target, int ignore) /* Stack must be properly aligned now. */ gcc_assert (!pass - || !(stack_pointer_delta % preferred_unit_stack_boundary)); + || multiple_p (stack_pointer_delta, + preferred_unit_stack_boundary)); /* Generate the actual call instruction. */ emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size, @@ -4339,6 +4430,7 @@ expand_call (tree exp, rtx target, int ignore) stack_arg_under_construction = old_stack_arg_under_construction; highest_outgoing_arg_in_use = initial_highest_arg_in_use; stack_usage_map = initial_stack_usage_map; + stack_usage_watermark = initial_stack_usage_watermark; sibcall_failure = 1; } else if (ACCUMULATE_OUTGOING_ARGS && pass) @@ -4363,12 +4455,14 @@ expand_call (tree exp, rtx target, int ignore) emit_move_insn (stack_area, args[i].save_area); else emit_block_move (stack_area, args[i].save_area, - GEN_INT (args[i].locate.size.constant), + (gen_int_mode + (args[i].locate.size.constant, Pmode)), BLOCK_OP_CALL_PARM); } highest_outgoing_arg_in_use = initial_highest_arg_in_use; stack_usage_map = initial_stack_usage_map; + stack_usage_watermark = initial_stack_usage_watermark; } /* If this was alloca, record the new stack level. */ @@ -4411,8 +4505,9 @@ expand_call (tree exp, rtx target, int ignore) /* Verify that we've deallocated all the stack we used. */ gcc_assert ((flags & ECF_NORETURN) - || (old_stack_allocated - == stack_pointer_delta - pending_stack_adjust)); + || known_eq (old_stack_allocated, + stack_pointer_delta + - pending_stack_adjust)); } /* If something prevents making this a sibling call, @@ -4579,7 +4674,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, int struct_value_size = 0; int flags; int reg_parm_stack_space = 0; - int needed; + poly_int64 needed; rtx_insn *before_call; bool have_push_fusage; tree tfom; /* type_for_mode (outmode, 0) */ @@ -4592,8 +4687,9 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, #endif /* Size of the stack reserved for parameter registers. */ - int initial_highest_arg_in_use = highest_outgoing_arg_in_use; + unsigned int initial_highest_arg_in_use = highest_outgoing_arg_in_use; char *initial_stack_usage_map = stack_usage_map; + unsigned HOST_WIDE_INT initial_stack_usage_watermark = stack_usage_watermark; char *stack_usage_map_buf = NULL; rtx struct_value = targetm.calls.struct_value_rtx (0, 0); @@ -4825,27 +4921,25 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, assemble_external_libcall (fun); original_args_size = args_size; - args_size.constant = (((args_size.constant - + stack_pointer_delta - + STACK_BYTES - 1) - / STACK_BYTES - * STACK_BYTES) - - stack_pointer_delta); + args_size.constant = (aligned_upper_bound (args_size.constant + + stack_pointer_delta, + STACK_BYTES) + - stack_pointer_delta); - args_size.constant = MAX (args_size.constant, - reg_parm_stack_space); + args_size.constant = upper_bound (args_size.constant, + reg_parm_stack_space); if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) args_size.constant -= reg_parm_stack_space; - if (args_size.constant > crtl->outgoing_args_size) - crtl->outgoing_args_size = args_size.constant; + crtl->outgoing_args_size = upper_bound (crtl->outgoing_args_size, + args_size.constant); if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS) { - int pushed = args_size.constant + pending_stack_adjust; - if (pushed > current_function_pushed_stack_size) - current_function_pushed_stack_size = pushed; + poly_int64 pushed = args_size.constant + pending_stack_adjust; + current_function_pushed_stack_size + = upper_bound (current_function_pushed_stack_size, pushed); } if (ACCUMULATE_OUTGOING_ARGS) @@ -4870,11 +4964,15 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) needed += reg_parm_stack_space; + poly_int64 limit = needed; if (ARGS_GROW_DOWNWARD) - highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, - needed + 1); - else - highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, needed); + limit += 1; + + /* For polynomial sizes, this is the maximum possible size needed + for arguments with a constant size and offset. */ + HOST_WIDE_INT const_limit = constant_lower_bound (limit); + highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, + const_limit); stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use); stack_usage_map = stack_usage_map_buf; @@ -4902,14 +5000,15 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, else { if (!PUSH_ARGS) - argblock = push_block (GEN_INT (args_size.constant), 0, 0); + argblock = push_block (gen_int_mode (args_size.constant, Pmode), 0, 0); } /* We push args individually in reverse order, perform stack alignment before the first push (the last arg). */ if (argblock == 0) - anti_adjust_stack (GEN_INT (args_size.constant - - original_args_size.constant)); + anti_adjust_stack (gen_int_mode (args_size.constant + - original_args_size.constant, + Pmode)); argnum = nargs - 1; @@ -4949,7 +5048,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, rtx reg = argvec[argnum].reg; int partial = argvec[argnum].partial; unsigned int parm_align = argvec[argnum].locate.boundary; - int lower_bound = 0, upper_bound = 0, i; + poly_int64 lower_bound = 0, upper_bound = 0; if (! (reg != 0 && partial == 0)) { @@ -4973,18 +5072,11 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, upper_bound = lower_bound + argvec[argnum].locate.size.constant; } - i = lower_bound; - /* Don't worry about things in the fixed argument area; - it has already been saved. */ - if (i < reg_parm_stack_space) - i = reg_parm_stack_space; - while (i < upper_bound && stack_usage_map[i] == 0) - i++; - - if (i < upper_bound) + if (stack_region_maybe_used_p (lower_bound, upper_bound, + reg_parm_stack_space)) { /* We need to make a save area. */ - unsigned int size + poly_uint64 size = argvec[argnum].locate.size.constant * BITS_PER_UNIT; machine_mode save_mode = int_mode_for_size (size, 1).else_blk (); @@ -5004,7 +5096,9 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, emit_block_move (validize_mem (copy_rtx (argvec[argnum].save_area)), stack_area, - GEN_INT (argvec[argnum].locate.size.constant), + (gen_int_mode + (argvec[argnum].locate.size.constant, + Pmode)), BLOCK_OP_CALL_PARM); } else @@ -5018,14 +5112,14 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align, partial, reg, 0, argblock, - GEN_INT (argvec[argnum].locate.offset.constant), + (gen_int_mode + (argvec[argnum].locate.offset.constant, Pmode)), reg_parm_stack_space, ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad), false); /* Now mark the segment we just used. */ if (ACCUMULATE_OUTGOING_ARGS) - for (i = lower_bound; i < upper_bound; i++) - stack_usage_map[i] = 1; + mark_stack_region_used (lower_bound, upper_bound); NO_DEFER_POP; @@ -5147,8 +5241,8 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, ? hard_libcall_value (outmode, orgfun) : NULL_RTX); /* Stack must be properly aligned now. */ - gcc_assert (!(stack_pointer_delta - & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1))); + gcc_assert (multiple_p (stack_pointer_delta, + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)); before_call = get_last_insn (); @@ -5286,7 +5380,8 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, emit_block_move (stack_area, validize_mem (copy_rtx (argvec[count].save_area)), - GEN_INT (argvec[count].locate.size.constant), + (gen_int_mode + (argvec[count].locate.size.constant, Pmode)), BLOCK_OP_CALL_PARM); else emit_move_insn (stack_area, argvec[count].save_area); @@ -5294,6 +5389,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value, highest_outgoing_arg_in_use = initial_highest_arg_in_use; stack_usage_map = initial_stack_usage_map; + stack_usage_watermark = initial_stack_usage_watermark; } free (stack_usage_map_buf); @@ -5390,8 +5486,8 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, tree pval = arg->tree_value; rtx reg = 0; int partial = 0; - int used = 0; - int i, lower_bound = 0, upper_bound = 0; + poly_int64 used = 0; + poly_int64 lower_bound = 0, upper_bound = 0; int sibcall_failure = 0; if (TREE_CODE (pval) == ERROR_MARK) @@ -5412,7 +5508,10 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* stack_slot is negative, but we want to index stack_usage_map with positive values. */ if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) - upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1; + { + rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1); + upper_bound = -rtx_to_poly_int64 (offset) + 1; + } else upper_bound = 0; @@ -5421,25 +5520,21 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, else { if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) - lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)); + { + rtx offset = XEXP (XEXP (arg->stack_slot, 0), 1); + lower_bound = rtx_to_poly_int64 (offset); + } else lower_bound = 0; upper_bound = lower_bound + arg->locate.size.constant; } - i = lower_bound; - /* Don't worry about things in the fixed argument area; - it has already been saved. */ - if (i < reg_parm_stack_space) - i = reg_parm_stack_space; - while (i < upper_bound && stack_usage_map[i] == 0) - i++; - - if (i < upper_bound) + if (stack_region_maybe_used_p (lower_bound, upper_bound, + reg_parm_stack_space)) { /* We need to make a save area. */ - unsigned int size = arg->locate.size.constant * BITS_PER_UNIT; + poly_uint64 size = arg->locate.size.constant * BITS_PER_UNIT; machine_mode save_mode = int_mode_for_size (size, 1).else_blk (); rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0)); @@ -5452,7 +5547,8 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, preserve_temp_slots (arg->save_area); emit_block_move (validize_mem (copy_rtx (arg->save_area)), stack_area, - GEN_INT (arg->locate.size.constant), + (gen_int_mode + (arg->locate.size.constant, Pmode)), BLOCK_OP_CALL_PARM); } else @@ -5529,8 +5625,8 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* Check for overlap with already clobbered argument area. */ if ((flags & ECF_SIBCALL) && MEM_P (arg->value) - && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0), - arg->locate.size.constant)) + && mem_might_overlap_already_clobbered_arg_p (XEXP (arg->value, 0), + arg->locate.size.constant)) sibcall_failure = 1; /* Don't allow anything left on stack from computation @@ -5582,17 +5678,15 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, if (targetm.calls.function_arg_padding (arg->mode, TREE_TYPE (pval)) == PAD_DOWNWARD) { - int pad = used - size; - if (pad) - { - unsigned int pad_align = least_bit_hwi (pad) * BITS_PER_UNIT; - parm_align = MIN (parm_align, pad_align); - } + poly_int64 pad = used - size; + unsigned int pad_align = known_alignment (pad) * BITS_PER_UNIT; + if (pad_align != 0) + parm_align = MIN (parm_align, pad_align); } /* This isn't already where we want it on the stack, so put it there. This can either be done with push or copy insns. */ - if (used + if (maybe_ne (used, 0) && !emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, parm_align, partial, reg, used - size, argblock, ARGS_SIZE_RTX (arg->locate.offset), @@ -5610,7 +5704,7 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* BLKmode, at least partly to be pushed. */ unsigned int parm_align; - int excess; + poly_int64 excess; rtx size_rtx; /* Pushing a nonscalar. @@ -5646,10 +5740,12 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, { if (arg->locate.size.var) parm_align = BITS_PER_UNIT; - else if (excess) + else { - unsigned int excess_align = least_bit_hwi (excess) * BITS_PER_UNIT; - parm_align = MIN (parm_align, excess_align); + unsigned int excess_align + = known_alignment (excess) * BITS_PER_UNIT; + if (excess_align != 0) + parm_align = MIN (parm_align, excess_align); } } @@ -5658,7 +5754,7 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* emit_push_insn might not work properly if arg->value and argblock + arg->locate.offset areas overlap. */ rtx x = arg->value; - int i = 0; + poly_int64 i = 0; if (XEXP (x, 0) == crtl->args.internal_arg_pointer || (GET_CODE (XEXP (x, 0)) == PLUS @@ -5667,7 +5763,7 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, && CONST_INT_P (XEXP (XEXP (x, 0), 1)))) { if (XEXP (x, 0) != crtl->args.internal_arg_pointer) - i = INTVAL (XEXP (XEXP (x, 0), 1)); + i = rtx_to_poly_int64 (XEXP (XEXP (x, 0), 1)); /* arg.locate doesn't contain the pretend_args_size offset, it's part of argblock. Ensure we don't count it in I. */ @@ -5678,33 +5774,28 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* expand_call should ensure this. */ gcc_assert (!arg->locate.offset.var - && arg->locate.size.var == 0 - && CONST_INT_P (size_rtx)); + && arg->locate.size.var == 0); + poly_int64 size_val = rtx_to_poly_int64 (size_rtx); - if (arg->locate.offset.constant > i) - { - if (arg->locate.offset.constant < i + INTVAL (size_rtx)) - sibcall_failure = 1; - } - else if (arg->locate.offset.constant < i) - { - /* Use arg->locate.size.constant instead of size_rtx - because we only care about the part of the argument - on the stack. */ - if (i < (arg->locate.offset.constant - + arg->locate.size.constant)) - sibcall_failure = 1; - } - else + if (known_eq (arg->locate.offset.constant, i)) { /* Even though they appear to be at the same location, if part of the outgoing argument is in registers, they aren't really at the same location. Check for this by making sure that the incoming size is the same as the outgoing size. */ - if (arg->locate.size.constant != INTVAL (size_rtx)) + if (maybe_ne (arg->locate.size.constant, size_val)) sibcall_failure = 1; } + else if (maybe_in_range_p (arg->locate.offset.constant, + i, size_val)) + sibcall_failure = 1; + /* Use arg->locate.size.constant instead of size_rtx + because we only care about the part of the argument + on the stack. */ + else if (maybe_in_range_p (i, arg->locate.offset.constant, + arg->locate.size.constant)) + sibcall_failure = 1; } } @@ -5738,8 +5829,7 @@ store_one_arg (struct arg_data *arg, rtx argblock, int flags, /* Mark all slots this store used. */ if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL) && argblock && ! variable_size && arg->stack) - for (i = lower_bound; i < upper_bound; i++) - stack_usage_map[i] = 1; + mark_stack_region_used (lower_bound, upper_bound); /* Once we have pushed something, pops can't safely be deferred during the rest of the arguments. */ diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index f914285e16e..2aa64917e4c 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -19993,8 +19993,8 @@ arm_output_function_prologue (FILE *f) if (IS_CMSE_ENTRY (func_type)) asm_fprintf (f, "\t%@ Non-secure entry function: called from non-secure code.\n"); - asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %wd\n", - crtl->args.size, + asm_fprintf (f, "\t%@ args = %wd, pretend = %d, frame = %wd\n", + (HOST_WIDE_INT) crtl->args.size, crtl->args.pretend_args_size, (HOST_WIDE_INT) get_frame_size ()); diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h index c46fd60da85..410bfb99841 100644 --- a/gcc/config/arm/arm.h +++ b/gcc/config/arm/arm.h @@ -1254,7 +1254,7 @@ enum reg_class couldn't convert a direct call into an indirect one. */ #define CALLER_INTERWORKING_SLOT_SIZE \ (TARGET_CALLER_INTERWORKING \ - && crtl->outgoing_args_size != 0 \ + && maybe_ne (crtl->outgoing_args_size, 0) \ ? UNITS_PER_WORD : 0) /* If we generate an insn to push BYTES bytes, diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c index e2db38d45de..b69d42e34a6 100644 --- a/gcc/config/avr/avr.c +++ b/gcc/config/avr/avr.c @@ -1151,7 +1151,8 @@ avr_accumulate_outgoing_args (void) static inline int avr_outgoing_args_size (void) { - return ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0; + return (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0); } diff --git a/gcc/config/cr16/cr16.c b/gcc/config/cr16/cr16.c index 364fdf49e7e..ddadab2ca7b 100644 --- a/gcc/config/cr16/cr16.c +++ b/gcc/config/cr16/cr16.c @@ -253,10 +253,8 @@ cr16_class_likely_spilled_p (reg_class_t rclass) return false; } -static int -cr16_return_pops_args (tree fundecl ATTRIBUTE_UNUSED, - tree funtype ATTRIBUTE_UNUSED, - int size ATTRIBUTE_UNUSED) +static poly_int64 +cr16_return_pops_args (tree, tree, poly_int64) { return 0; } @@ -433,9 +431,10 @@ cr16_compute_frame (void) padding_locals = stack_alignment - padding_locals; current_frame_info.var_size += padding_locals; - current_frame_info.total_size = current_frame_info.var_size - + (ACCUMULATE_OUTGOING_ARGS - ? crtl->outgoing_args_size : 0); + current_frame_info.total_size + = (current_frame_info.var_size + + (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0)); } /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */ @@ -449,12 +448,14 @@ cr16_initial_elimination_offset (int from, int to) cr16_compute_frame (); if (((from) == FRAME_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM)) - return (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0); + return (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0); else if (((from) == ARG_POINTER_REGNUM) && ((to) == FRAME_POINTER_REGNUM)) return (current_frame_info.reg_size + current_frame_info.var_size); else if (((from) == ARG_POINTER_REGNUM) && ((to) == STACK_POINTER_REGNUM)) return (current_frame_info.reg_size + current_frame_info.var_size - + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0)); + + (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0)); else gcc_unreachable (); } diff --git a/gcc/config/ft32/ft32.c b/gcc/config/ft32/ft32.c index bc49963ed54..a298e64510f 100644 --- a/gcc/config/ft32/ft32.c +++ b/gcc/config/ft32/ft32.c @@ -417,7 +417,8 @@ ft32_compute_frame (void) cfun->machine->size_for_adjusting_sp = 0 // crtl->args.pretend_args_size + cfun->machine->local_vars_size - + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0); + + (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0); } // Must use LINK/UNLINK when... diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ef321d32c0b..5e3a2cdcd79 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -6735,8 +6735,8 @@ ix86_keep_aggregate_return_pointer (tree fntype) The attribute stdcall is equivalent to RTD on a per module basis. */ -static int -ix86_return_pops_args (tree fundecl, tree funtype, int size) +static poly_int64 +ix86_return_pops_args (tree fundecl, tree funtype, poly_int64 size) { unsigned int ccvt; @@ -14507,7 +14507,7 @@ ix86_expand_split_stack_prologue (void) anyhow. In 64-bit mode we pass the parameters in r10 and r11. */ allocate_rtx = GEN_INT (allocate); - args_size = crtl->args.size >= 0 ? crtl->args.size : 0; + args_size = crtl->args.size >= 0 ? (HOST_WIDE_INT) crtl->args.size : 0; call_fusage = NULL_RTX; rtx pop = NULL_RTX; if (TARGET_64BIT) diff --git a/gcc/config/m68k/m68k.c b/gcc/config/m68k/m68k.c index a0fab4c0bb4..10c78153e64 100644 --- a/gcc/config/m68k/m68k.c +++ b/gcc/config/m68k/m68k.c @@ -178,7 +178,7 @@ static bool m68k_return_in_memory (const_tree, const_tree); #endif static void m68k_output_dwarf_dtprel (FILE *, int, rtx) ATTRIBUTE_UNUSED; static void m68k_trampoline_init (rtx, tree, rtx); -static int m68k_return_pops_args (tree, tree, int); +static poly_int64 m68k_return_pops_args (tree, tree, poly_int64); static rtx m68k_delegitimize_address (rtx); static void m68k_function_arg_advance (cumulative_args_t, machine_mode, const_tree, bool); @@ -6531,14 +6531,14 @@ m68k_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) standard Unix calling sequences. If the option is not selected, the caller must always pop the args. */ -static int -m68k_return_pops_args (tree fundecl, tree funtype, int size) +static poly_int64 +m68k_return_pops_args (tree fundecl, tree funtype, poly_int64 size) { return ((TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE) && (!stdarg_p (funtype))) - ? size : 0); + ? (HOST_WIDE_INT) size : 0); } /* Make sure everything's fine if we *don't* have a given processor. diff --git a/gcc/config/microblaze/microblaze.c b/gcc/config/microblaze/microblaze.c index acebb52d6cb..8d7ca3c52a9 100644 --- a/gcc/config/microblaze/microblaze.c +++ b/gcc/config/microblaze/microblaze.c @@ -2723,7 +2723,7 @@ microblaze_function_prologue (FILE * file) STACK_POINTER_REGNUM]), fsiz, reg_names[MB_ABI_SUB_RETURN_ADDR_REGNUM + GP_REG_FIRST], current_frame_info.var_size, current_frame_info.num_gp, - crtl->outgoing_args_size); + (int) crtl->outgoing_args_size); fprintf (file, "\t.mask\t0x%08lx\n", current_frame_info.mask); } } diff --git a/gcc/config/moxie/moxie.c b/gcc/config/moxie/moxie.c index f570c06b55d..4c9c5818fc9 100644 --- a/gcc/config/moxie/moxie.c +++ b/gcc/config/moxie/moxie.c @@ -270,7 +270,8 @@ moxie_compute_frame (void) cfun->machine->size_for_adjusting_sp = crtl->args.pretend_args_size + cfun->machine->local_vars_size - + (ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0); + + (ACCUMULATE_OUTGOING_ARGS + ? (HOST_WIDE_INT) crtl->outgoing_args_size : 0); } void diff --git a/gcc/config/pa/pa.h b/gcc/config/pa/pa.h index 044f65ea168..757dc890553 100644 --- a/gcc/config/pa/pa.h +++ b/gcc/config/pa/pa.h @@ -535,7 +535,7 @@ extern rtx hppa_pic_save_rtx (void); marker, although the runtime documentation only describes a 16 byte marker. For compatibility, we allocate 48 bytes. */ #define STACK_POINTER_OFFSET \ - (TARGET_64BIT ? -(crtl->outgoing_args_size + 48): -32) + (TARGET_64BIT ? -(crtl->outgoing_args_size + 48) : poly_int64 (-32)) #define STACK_DYNAMIC_OFFSET(FNDECL) \ (TARGET_64BIT \ @@ -692,7 +692,7 @@ extern int may_call_alloca; #define EXIT_IGNORE_STACK \ (maybe_ne (get_frame_size (), 0) \ - || cfun->calls_alloca || crtl->outgoing_args_size) + || cfun->calls_alloca || maybe_ne (crtl->outgoing_args_size, 0)) /* Length in units of the trampoline for entering a nested function. */ diff --git a/gcc/config/powerpcspe/aix.h b/gcc/config/powerpcspe/aix.h index 607b42c0a40..dc7fc44b044 100644 --- a/gcc/config/powerpcspe/aix.h +++ b/gcc/config/powerpcspe/aix.h @@ -71,7 +71,8 @@ `emit-rtl.c'). */ #undef STACK_DYNAMIC_OFFSET #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, 16) + RS6000_ALIGN (crtl->outgoing_args_size.to_constant () \ + + STACK_POINTER_OFFSET, 16) #undef TARGET_IEEEQUAD #define TARGET_IEEEQUAD 0 diff --git a/gcc/config/powerpcspe/darwin.h b/gcc/config/powerpcspe/darwin.h index ac268dcab23..a454049c130 100644 --- a/gcc/config/powerpcspe/darwin.h +++ b/gcc/config/powerpcspe/darwin.h @@ -155,7 +155,7 @@ extern int darwin_emit_branch_islands; #undef STACK_DYNAMIC_OFFSET #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - (RS6000_ALIGN (crtl->outgoing_args_size, 16) \ + (RS6000_ALIGN (crtl->outgoing_args_size.to_constant (), 16) \ + (STACK_POINTER_OFFSET)) /* Darwin uses a function call if everything needs to be saved/restored. */ diff --git a/gcc/config/powerpcspe/powerpcspe.h b/gcc/config/powerpcspe/powerpcspe.h index bc37c6f17e5..45edc35f39a 100644 --- a/gcc/config/powerpcspe/powerpcspe.h +++ b/gcc/config/powerpcspe/powerpcspe.h @@ -1666,7 +1666,8 @@ extern enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX]; This value must be a multiple of STACK_BOUNDARY (hard coded in `emit-rtl.c'). */ #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, \ + RS6000_ALIGN (crtl->outgoing_args_size.to_constant () \ + + STACK_POINTER_OFFSET, \ (TARGET_ALTIVEC || TARGET_VSX) ? 16 : 8) /* If we generate an insn to push BYTES bytes, diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h index 73541819fde..31fda583c2c 100644 --- a/gcc/config/rs6000/aix.h +++ b/gcc/config/rs6000/aix.h @@ -71,7 +71,8 @@ `emit-rtl.c'). */ #undef STACK_DYNAMIC_OFFSET #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, 16) + RS6000_ALIGN (crtl->outgoing_args_size.to_constant () \ + + STACK_POINTER_OFFSET, 16) #undef TARGET_IEEEQUAD #define TARGET_IEEEQUAD 0 diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index a6a7b2c554c..5f03fa5f206 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -155,7 +155,7 @@ extern int darwin_emit_branch_islands; #undef STACK_DYNAMIC_OFFSET #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - (RS6000_ALIGN (crtl->outgoing_args_size, 16) \ + (RS6000_ALIGN (crtl->outgoing_args_size.to_constant (), 16) \ + (STACK_POINTER_OFFSET)) /* Darwin uses a function call if everything needs to be saved/restored. */ diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h index fa4e42b0793..658c6e0bcd2 100644 --- a/gcc/config/rs6000/rs6000.h +++ b/gcc/config/rs6000/rs6000.h @@ -1565,7 +1565,8 @@ extern enum reg_class rs6000_constraints[RS6000_CONSTRAINT_MAX]; This value must be a multiple of STACK_BOUNDARY (hard coded in `emit-rtl.c'). */ #define STACK_DYNAMIC_OFFSET(FUNDECL) \ - RS6000_ALIGN (crtl->outgoing_args_size + STACK_POINTER_OFFSET, \ + RS6000_ALIGN (crtl->outgoing_args_size.to_constant () \ + + STACK_POINTER_OFFSET, \ (TARGET_ALTIVEC || TARGET_VSX) ? 16 : 8) /* If we generate an insn to push BYTES bytes, diff --git a/gcc/config/vax/vax.c b/gcc/config/vax/vax.c index f739c6fe9b9..c08460a0ef3 100644 --- a/gcc/config/vax/vax.c +++ b/gcc/config/vax/vax.c @@ -62,7 +62,7 @@ static rtx vax_struct_value_rtx (tree, int); static rtx vax_builtin_setjmp_frame_value (void); static void vax_asm_trampoline_template (FILE *); static void vax_trampoline_init (rtx, tree, rtx); -static int vax_return_pops_args (tree, tree, int); +static poly_int64 vax_return_pops_args (tree, tree, poly_int64); static bool vax_mode_dependent_address_p (const_rtx, addr_space_t); static HOST_WIDE_INT vax_starting_frame_offset (void); @@ -2140,11 +2140,11 @@ vax_trampoline_init (rtx m_tramp, tree fndecl, rtx cxt) On the VAX, the RET insn pops a maximum of 255 args for any function. */ -static int +static poly_int64 vax_return_pops_args (tree fundecl ATTRIBUTE_UNUSED, - tree funtype ATTRIBUTE_UNUSED, int size) + tree funtype ATTRIBUTE_UNUSED, poly_int64 size) { - return size > 255 * 4 ? 0 : size; + return size > 255 * 4 ? 0 : (HOST_WIDE_INT) size; } /* Define where to put the arguments to a function. diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 434c42a4ca9..3a4229f3c6f 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -3819,7 +3819,7 @@ suppresses this behavior and causes the parameter to be passed on the stack in its natural location. @end defmac -@deftypefn {Target Hook} int TARGET_RETURN_POPS_ARGS (tree @var{fundecl}, tree @var{funtype}, int @var{size}) +@deftypefn {Target Hook} poly_int64 TARGET_RETURN_POPS_ARGS (tree @var{fundecl}, tree @var{funtype}, poly_int64 @var{size}) This target hook returns the number of bytes of its own arguments that a function pops on returning, or 0 if the function pops no arguments and the caller must therefore pop them all after the function returns. diff --git a/gcc/dojump.c b/gcc/dojump.c index 256d02b14dd..261e13bd56a 100644 --- a/gcc/dojump.c +++ b/gcc/dojump.c @@ -89,8 +89,8 @@ do_pending_stack_adjust (void) { if (inhibit_defer_pop == 0) { - if (pending_stack_adjust != 0) - adjust_stack (GEN_INT (pending_stack_adjust)); + if (maybe_ne (pending_stack_adjust, 0)) + adjust_stack (gen_int_mode (pending_stack_adjust, Pmode)); pending_stack_adjust = 0; } } diff --git a/gcc/dojump.h b/gcc/dojump.h index ca6df449f74..ba404024be2 100644 --- a/gcc/dojump.h +++ b/gcc/dojump.h @@ -40,10 +40,10 @@ extern void do_pending_stack_adjust (void); struct saved_pending_stack_adjust { /* Saved value of pending_stack_adjust. */ - int x_pending_stack_adjust; + poly_int64 x_pending_stack_adjust; /* Saved value of stack_pointer_delta. */ - int x_stack_pointer_delta; + poly_int64 x_stack_pointer_delta; }; /* Remember pending_stack_adjust/stack_pointer_delta. diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h index c46ebb458f7..b219762d279 100644 --- a/gcc/emit-rtl.h +++ b/gcc/emit-rtl.h @@ -28,12 +28,12 @@ struct GTY(()) incoming_args { /* Number of bytes of args popped by function being compiled on its return. Zero if no bytes are to be popped. May affect compilation of return insn or of function epilogue. */ - int pops_args; + poly_int64_pod pops_args; /* If function's args have a fixed size, this is that size, in bytes. Otherwise, it is -1. May affect compilation of return insn or of function epilogue. */ - int size; + poly_int64_pod size; /* # bytes the prologue should push and pretend that the caller pushed them. The prologue must do this, but only if parms can be passed in @@ -68,7 +68,7 @@ struct GTY(()) rtl_data { /* # of bytes of outgoing arguments. If ACCUMULATE_OUTGOING_ARGS is defined, the needed space is pushed by the prologue. */ - int outgoing_args_size; + poly_int64_pod outgoing_args_size; /* If nonzero, an RTL expression for the location at which the current function returns its result. If the current function returns its diff --git a/gcc/explow.c b/gcc/explow.c index 38a95075133..dce61374cfd 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -1475,8 +1475,8 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, /* We ought to be called always on the toplevel and stack ought to be aligned properly. */ - gcc_assert (!(stack_pointer_delta - % (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT))); + gcc_assert (multiple_p (stack_pointer_delta, + PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)); /* If needed, check that we have the required amount of stack. Take into account what has already been checked. */ @@ -1506,7 +1506,7 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, } else { - int saved_stack_pointer_delta; + poly_int64 saved_stack_pointer_delta; if (!STACK_GROWS_DOWNWARD) emit_move_insn (target, virtual_stack_dynamic_rtx); diff --git a/gcc/function.c b/gcc/function.c index e479b1e5686..c752062b579 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -1407,7 +1407,7 @@ static poly_int64 cfa_offset; : 0) + (STACK_POINTER_OFFSET)) #else #define STACK_DYNAMIC_OFFSET(FNDECL) \ -((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : 0) \ + ((ACCUMULATE_OUTGOING_ARGS ? crtl->outgoing_args_size : poly_int64 (0)) \ + (STACK_POINTER_OFFSET)) #endif #endif @@ -2727,12 +2727,15 @@ assign_parm_find_stack_rtl (tree parm, struct assign_parm_data_one *data) 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. */ + poly_int64 offset; if (data->locate.where_pad != PAD_DOWNWARD || data->entry_parm) align = boundary; - else if (CONST_INT_P (offset_rtx)) + else if (poly_int_rtx_p (offset_rtx, &offset)) { - align = INTVAL (offset_rtx) * BITS_PER_UNIT | boundary; - align = least_bit_hwi (align); + align = least_bit_hwi (boundary); + unsigned int offset_align = known_alignment (offset) * BITS_PER_UNIT; + if (offset_align != 0) + align = MIN (align, offset_align); } set_mem_align (stack_parm, align); @@ -3894,14 +3897,15 @@ assign_parms (tree fndecl) /* Adjust function incoming argument size for alignment and minimum length. */ - crtl->args.size = MAX (crtl->args.size, all.reg_parm_stack_space); - crtl->args.size = CEIL_ROUND (crtl->args.size, - PARM_BOUNDARY / BITS_PER_UNIT); + crtl->args.size = upper_bound (crtl->args.size, all.reg_parm_stack_space); + crtl->args.size = aligned_upper_bound (crtl->args.size, + PARM_BOUNDARY / BITS_PER_UNIT); if (ARGS_GROW_DOWNWARD) { crtl->args.arg_offset_rtx - = (all.stack_args_size.var == 0 ? GEN_INT (-all.stack_args_size.constant) + = (all.stack_args_size.var == 0 + ? gen_int_mode (-all.stack_args_size.constant, Pmode) : expand_expr (size_diffop (all.stack_args_size.var, size_int (-all.stack_args_size.constant)), NULL_RTX, VOIDmode, EXPAND_NORMAL)); @@ -4141,15 +4145,19 @@ locate_and_pad_parm (machine_mode passed_mode, tree type, int in_regs, { if (reg_parm_stack_space > 0) { - if (initial_offset_ptr->var) + if (initial_offset_ptr->var + || !ordered_p (initial_offset_ptr->constant, + reg_parm_stack_space)) { initial_offset_ptr->var = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), ssize_int (reg_parm_stack_space)); initial_offset_ptr->constant = 0; } - else if (initial_offset_ptr->constant < reg_parm_stack_space) - initial_offset_ptr->constant = reg_parm_stack_space; + else + initial_offset_ptr->constant + = ordered_max (initial_offset_ptr->constant, + reg_parm_stack_space); } } @@ -4276,9 +4284,9 @@ pad_to_arg_alignment (struct args_size *offset_ptr, int boundary, struct args_size *alignment_pad) { tree save_var = NULL_TREE; - HOST_WIDE_INT save_constant = 0; + poly_int64 save_constant = 0; int boundary_in_bytes = boundary / BITS_PER_UNIT; - HOST_WIDE_INT sp_offset = STACK_POINTER_OFFSET; + poly_int64 sp_offset = STACK_POINTER_OFFSET; #ifdef SPARC_STACK_BOUNDARY_HACK /* ??? The SPARC port may claim a STACK_BOUNDARY higher than @@ -4299,7 +4307,10 @@ pad_to_arg_alignment (struct args_size *offset_ptr, int boundary, if (boundary > BITS_PER_UNIT) { - if (offset_ptr->var) + int misalign; + if (offset_ptr->var + || !known_misalignment (offset_ptr->constant + sp_offset, + boundary_in_bytes, &misalign)) { tree sp_offset_tree = ssize_int (sp_offset); tree offset = size_binop (PLUS_EXPR, @@ -4320,13 +4331,13 @@ pad_to_arg_alignment (struct args_size *offset_ptr, int boundary, } else { - offset_ptr->constant = -sp_offset + - (ARGS_GROW_DOWNWARD - ? FLOOR_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes) - : CEIL_ROUND (offset_ptr->constant + sp_offset, boundary_in_bytes)); + if (ARGS_GROW_DOWNWARD) + offset_ptr->constant -= misalign; + else + offset_ptr->constant += -misalign & (boundary_in_bytes - 1); - if (boundary > PARM_BOUNDARY) - alignment_pad->constant = offset_ptr->constant - save_constant; + if (boundary > PARM_BOUNDARY) + alignment_pad->constant = offset_ptr->constant - save_constant; } } } diff --git a/gcc/function.h b/gcc/function.h index 95cb2bdc43a..b64f28e526a 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -94,7 +94,7 @@ extern GTY ((length ("crtl->emit.x_reg_rtx_no"))) rtx * regno_reg_rtx; struct GTY(()) expr_status { /* Number of units that we should eventually pop off the stack. These are the arguments to function calls that have already returned. */ - int x_pending_stack_adjust; + poly_int64_pod x_pending_stack_adjust; /* Under some ABIs, it is the caller's responsibility to pop arguments pushed for function calls. A naive implementation would simply pop @@ -117,7 +117,7 @@ struct GTY(()) expr_status { boundary can be momentarily unaligned while pushing the arguments. Record the delta since last aligned boundary here in order to get stack alignment in the nested function calls working right. */ - int x_stack_pointer_delta; + poly_int64_pod x_stack_pointer_delta; /* Nonzero means __builtin_saveregs has already been done in this function. The value is the pseudoreg containing the value __builtin_saveregs @@ -200,9 +200,10 @@ struct GTY(()) stack_usage meaningful only if has_unbounded_dynamic_stack_size is zero. */ HOST_WIDE_INT dynamic_stack_size; - /* # of bytes of space pushed onto the stack after the prologue. If - !ACCUMULATE_OUTGOING_ARGS, it contains the outgoing arguments. */ - int pushed_stack_size; + /* Upper bound on the number of bytes pushed onto the stack after the + prologue. If !ACCUMULATE_OUTGOING_ARGS, it contains the outgoing + arguments. */ + poly_int64 pushed_stack_size; /* Nonzero if the amount of stack space allocated dynamically cannot be bounded at compile-time. */ @@ -480,7 +481,7 @@ extern struct machine_function * (*init_machine_status) (void); struct args_size { - HOST_WIDE_INT constant; + poly_int64_pod constant; tree var; }; @@ -542,7 +543,7 @@ do { \ /* Convert the implicit sum in a `struct args_size' into an rtx. */ #define ARGS_SIZE_RTX(SIZE) \ -((SIZE).var == 0 ? GEN_INT ((SIZE).constant) \ +((SIZE).var == 0 ? gen_int_mode ((SIZE).constant, Pmode) \ : expand_normal (ARGS_SIZE_TREE (SIZE))) #define ASLK_REDUCE_ALIGN 1 diff --git a/gcc/target.def b/gcc/target.def index 5296b25f25c..27bfcfc070f 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -5055,7 +5055,7 @@ arguments pop them but other functions (such as @code{printf}) pop\n\ nothing (the caller pops all). When this convention is in use,\n\ @var{funtype} is examined to determine whether a function takes a fixed\n\ number of arguments.", - int, (tree fundecl, tree funtype, int size), + poly_int64, (tree fundecl, tree funtype, poly_int64 size), default_return_pops_args) /* Return a mode wide enough to copy any function value that might be diff --git a/gcc/targhooks.c b/gcc/targhooks.c index d02fca99497..653567cab3e 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1045,10 +1045,8 @@ default_trampoline_init (rtx ARG_UNUSED (m_tramp), tree ARG_UNUSED (t_func), sorry ("nested function trampolines not supported on this target"); } -int -default_return_pops_args (tree fundecl ATTRIBUTE_UNUSED, - tree funtype ATTRIBUTE_UNUSED, - int size ATTRIBUTE_UNUSED) +poly_int64 +default_return_pops_args (tree, tree, poly_int64) { return 0; } diff --git a/gcc/targhooks.h b/gcc/targhooks.h index 05635975dda..e753e58f3d2 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -158,7 +158,7 @@ extern bool default_function_value_regno_p (const unsigned int); extern rtx default_internal_arg_pointer (void); extern rtx default_static_chain (const_tree, bool); extern void default_trampoline_init (rtx, tree, rtx); -extern int default_return_pops_args (tree, tree, int); +extern poly_int64 default_return_pops_args (tree, tree, poly_int64); extern reg_class_t default_branch_target_register_class (void); extern reg_class_t default_ira_change_pseudo_allocno_class (int, reg_class_t, reg_class_t); diff --git a/gcc/toplev.c b/gcc/toplev.c index b6e038d2f89..95d3f194942 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -956,19 +956,32 @@ output_stack_usage (void) stack_usage_kind = STATIC; /* Add the maximum amount of space pushed onto the stack. */ - if (current_function_pushed_stack_size > 0) + if (maybe_ne (current_function_pushed_stack_size, 0)) { - stack_usage += current_function_pushed_stack_size; - stack_usage_kind = DYNAMIC_BOUNDED; + HOST_WIDE_INT extra; + if (current_function_pushed_stack_size.is_constant (&extra)) + { + stack_usage += extra; + stack_usage_kind = DYNAMIC_BOUNDED; + } + else + { + extra = constant_lower_bound (current_function_pushed_stack_size); + stack_usage += extra; + stack_usage_kind = DYNAMIC; + } } /* Now on to the tricky part: dynamic stack allocation. */ if (current_function_allocates_dynamic_stack_space) { - if (current_function_has_unbounded_dynamic_stack_size) - stack_usage_kind = DYNAMIC; - else - stack_usage_kind = DYNAMIC_BOUNDED; + if (stack_usage_kind != DYNAMIC) + { + if (current_function_has_unbounded_dynamic_stack_size) + stack_usage_kind = DYNAMIC; + else + stack_usage_kind = DYNAMIC_BOUNDED; + } /* Add the size even in the unbounded case, this can't hurt. */ stack_usage += current_function_dynamic_stack_size;