1/* Convert function calls to rtl insns, for GNU C compiler. 2 Copyright (C) 1989-2015 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License 17along with GCC; see the file COPYING3. If not see 18<http://www.gnu.org/licenses/>. */ 19 20#include "config.h" 21#include "system.h" 22#include "coretypes.h" 23#include "tm.h" 24#include "rtl.h" 25#include "hash-set.h" 26#include "machmode.h" 27#include "vec.h" 28#include "double-int.h" 29#include "input.h" 30#include "alias.h" 31#include "symtab.h" 32#include "wide-int.h" 33#include "inchash.h" 34#include "tree.h" 35#include "fold-const.h" 36#include "stor-layout.h" 37#include "varasm.h" 38#include "stringpool.h" 39#include "attribs.h" 40#include "predict.h" 41#include "hashtab.h" 42#include "hard-reg-set.h" 43#include "function.h" 44#include "basic-block.h" 45#include "tree-ssa-alias.h" 46#include "internal-fn.h" 47#include "gimple-expr.h" 48#include "is-a.h" 49#include "gimple.h" 50#include "flags.h" 51#include "statistics.h" 52#include "real.h" 53#include "fixed-value.h" 54#include "insn-config.h" 55#include "expmed.h" 56#include "dojump.h" 57#include "explow.h" 58#include "calls.h" 59#include "emit-rtl.h" 60#include "stmt.h" 61#include "expr.h" 62#include "insn-codes.h" 63#include "optabs.h" 64#include "libfuncs.h" 65#include "regs.h" 66#include "diagnostic-core.h" 67#include "output.h" 68#include "tm_p.h" 69#include "timevar.h" 70#include "sbitmap.h" 71#include "bitmap.h" 72#include "langhooks.h" 73#include "target.h" 74#include "hash-map.h" 75#include "plugin-api.h" 76#include "ipa-ref.h" 77#include "cgraph.h" 78#include "except.h" 79#include "dbgcnt.h" 80#include "rtl-iter.h" 81#include "tree-chkp.h" 82#include "rtl-chkp.h" 83 84/* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */ 85#define STACK_BYTES (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT) 86 87/* Data structure and subroutines used within expand_call. */ 88 89struct arg_data 90{ 91 /* Tree node for this argument. */ 92 tree tree_value; 93 /* Mode for value; TYPE_MODE unless promoted. */ 94 machine_mode mode; 95 /* Current RTL value for argument, or 0 if it isn't precomputed. */ 96 rtx value; 97 /* Initially-compute RTL value for argument; only for const functions. */ 98 rtx initial_value; 99 /* Register to pass this argument in, 0 if passed on stack, or an 100 PARALLEL if the arg is to be copied into multiple non-contiguous 101 registers. */ 102 rtx reg; 103 /* Register to pass this argument in when generating tail call sequence. 104 This is not the same register as for normal calls on machines with 105 register windows. */ 106 rtx tail_call_reg; 107 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct 108 form for emit_group_move. */ 109 rtx parallel_value; 110 /* If value is passed in neither reg nor stack, this field holds a number 111 of a special slot to be used. */ 112 rtx special_slot; 113 /* For pointer bounds hold an index of parm bounds are bound to. -1 if 114 there is no such pointer. */ 115 int pointer_arg; 116 /* If pointer_arg refers a structure, then pointer_offset holds an offset 117 of a pointer in this structure. */ 118 int pointer_offset; 119 /* If REG was promoted from the actual mode of the argument expression, 120 indicates whether the promotion is sign- or zero-extended. */ 121 int unsignedp; 122 /* Number of bytes to put in registers. 0 means put the whole arg 123 in registers. Also 0 if not passed in registers. */ 124 int partial; 125 /* Nonzero if argument must be passed on stack. 126 Note that some arguments may be passed on the stack 127 even though pass_on_stack is zero, just because FUNCTION_ARG says so. 128 pass_on_stack identifies arguments that *cannot* go in registers. */ 129 int pass_on_stack; 130 /* Some fields packaged up for locate_and_pad_parm. */ 131 struct locate_and_pad_arg_data locate; 132 /* Location on the stack at which parameter should be stored. The store 133 has already been done if STACK == VALUE. */ 134 rtx stack; 135 /* Location on the stack of the start of this argument slot. This can 136 differ from STACK if this arg pads downward. This location is known 137 to be aligned to TARGET_FUNCTION_ARG_BOUNDARY. */ 138 rtx stack_slot; 139 /* Place that this stack area has been saved, if needed. */ 140 rtx save_area; 141 /* If an argument's alignment does not permit direct copying into registers, 142 copy in smaller-sized pieces into pseudos. These are stored in a 143 block pointed to by this field. The next field says how many 144 word-sized pseudos we made. */ 145 rtx *aligned_regs; 146 int n_aligned_regs; 147}; 148 149/* A vector of one char per byte of stack space. A byte if nonzero if 150 the corresponding stack location has been used. 151 This vector is used to prevent a function call within an argument from 152 clobbering any stack already set up. */ 153static char *stack_usage_map; 154 155/* Size of STACK_USAGE_MAP. */ 156static int highest_outgoing_arg_in_use; 157 158/* A bitmap of virtual-incoming stack space. Bit is set if the corresponding 159 stack location's tail call argument has been already stored into the stack. 160 This bitmap is used to prevent sibling call optimization if function tries 161 to use parent's incoming argument slots when they have been already 162 overwritten with tail call arguments. */ 163static sbitmap stored_args_map; 164 165/* stack_arg_under_construction is nonzero when an argument may be 166 initialized with a constructor call (including a C function that 167 returns a BLKmode struct) and expand_call must take special action 168 to make sure the object being constructed does not overlap the 169 argument list for the constructor call. */ 170static int stack_arg_under_construction; 171 172static void emit_call_1 (rtx, tree, tree, tree, HOST_WIDE_INT, HOST_WIDE_INT, 173 HOST_WIDE_INT, rtx, rtx, int, rtx, int, 174 cumulative_args_t); 175static void precompute_register_parameters (int, struct arg_data *, int *); 176static void store_bounds (struct arg_data *, struct arg_data *); 177static int store_one_arg (struct arg_data *, rtx, int, int, int); 178static void store_unaligned_arguments_into_pseudos (struct arg_data *, int); 179static int finalize_must_preallocate (int, int, struct arg_data *, 180 struct args_size *); 181static void precompute_arguments (int, struct arg_data *); 182static int compute_argument_block_size (int, struct args_size *, tree, tree, int); 183static void initialize_argument_information (int, struct arg_data *, 184 struct args_size *, int, 185 tree, tree, 186 tree, tree, cumulative_args_t, int, 187 rtx *, int *, int *, int *, 188 bool *, bool); 189static void compute_argument_addresses (struct arg_data *, rtx, int); 190static rtx rtx_for_function_call (tree, tree); 191static void load_register_parameters (struct arg_data *, int, rtx *, int, 192 int, int *); 193static rtx emit_library_call_value_1 (int, rtx, rtx, enum libcall_type, 194 machine_mode, int, va_list); 195static int special_function_p (const_tree, int); 196static int check_sibcall_argument_overlap_1 (rtx); 197static int check_sibcall_argument_overlap (rtx_insn *, struct arg_data *, int); 198 199static int combine_pending_stack_adjustment_and_call (int, struct args_size *, 200 unsigned int); 201static tree split_complex_types (tree); 202 203#ifdef REG_PARM_STACK_SPACE 204static rtx save_fixed_argument_area (int, rtx, int *, int *); 205static void restore_fixed_argument_area (rtx, rtx, int, int); 206#endif 207 208/* Force FUNEXP into a form suitable for the address of a CALL, 209 and return that as an rtx. Also load the static chain register 210 if FNDECL is a nested function. 211 212 CALL_FUSAGE points to a variable holding the prospective 213 CALL_INSN_FUNCTION_USAGE information. */ 214 215rtx 216prepare_call_address (tree fndecl_or_type, rtx funexp, rtx static_chain_value, 217 rtx *call_fusage, int reg_parm_seen, int sibcallp) 218{ 219 /* Make a valid memory address and copy constants through pseudo-regs, 220 but not for a constant address if -fno-function-cse. */ 221 if (GET_CODE (funexp) != SYMBOL_REF) 222 /* If we are using registers for parameters, force the 223 function address into a register now. */ 224 funexp = ((reg_parm_seen 225 && targetm.small_register_classes_for_mode_p (FUNCTION_MODE)) 226 ? force_not_mem (memory_address (FUNCTION_MODE, funexp)) 227 : memory_address (FUNCTION_MODE, funexp)); 228 else if (! sibcallp) 229 { 230#ifndef NO_FUNCTION_CSE 231 if (optimize && ! flag_no_function_cse) 232 funexp = force_reg (Pmode, funexp); 233#endif 234 } 235 236 if (static_chain_value != 0 237 && (TREE_CODE (fndecl_or_type) != FUNCTION_DECL 238 || DECL_STATIC_CHAIN (fndecl_or_type))) 239 { 240 rtx chain; 241 242 chain = targetm.calls.static_chain (fndecl_or_type, false); 243 static_chain_value = convert_memory_address (Pmode, static_chain_value); 244 245 emit_move_insn (chain, static_chain_value); 246 if (REG_P (chain)) 247 use_reg (call_fusage, chain); 248 } 249 250 return funexp; 251} 252 253/* Generate instructions to call function FUNEXP, 254 and optionally pop the results. 255 The CALL_INSN is the first insn generated. 256 257 FNDECL is the declaration node of the function. This is given to the 258 hook TARGET_RETURN_POPS_ARGS to determine whether this function pops 259 its own args. 260 261 FUNTYPE is the data type of the function. This is given to the hook 262 TARGET_RETURN_POPS_ARGS to determine whether this function pops its 263 own args. We used to allow an identifier for library functions, but 264 that doesn't work when the return type is an aggregate type and the 265 calling convention says that the pointer to this aggregate is to be 266 popped by the callee. 267 268 STACK_SIZE is the number of bytes of arguments on the stack, 269 ROUNDED_STACK_SIZE is that number rounded up to 270 PREFERRED_STACK_BOUNDARY; zero if the size is variable. This is 271 both to put into the call insn and to generate explicit popping 272 code if necessary. 273 274 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value. 275 It is zero if this call doesn't want a structure value. 276 277 NEXT_ARG_REG is the rtx that results from executing 278 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true) 279 just after all the args have had their registers assigned. 280 This could be whatever you like, but normally it is the first 281 arg-register beyond those used for args in this call, 282 or 0 if all the arg-registers are used in this call. 283 It is passed on to `gen_call' so you can put this info in the call insn. 284 285 VALREG is a hard register in which a value is returned, 286 or 0 if the call does not return a value. 287 288 OLD_INHIBIT_DEFER_POP is the value that `inhibit_defer_pop' had before 289 the args to this call were processed. 290 We restore `inhibit_defer_pop' to that value. 291 292 CALL_FUSAGE is either empty or an EXPR_LIST of USE expressions that 293 denote registers used by the called function. */ 294 295static void 296emit_call_1 (rtx funexp, tree fntree ATTRIBUTE_UNUSED, tree fndecl ATTRIBUTE_UNUSED, 297 tree funtype ATTRIBUTE_UNUSED, 298 HOST_WIDE_INT stack_size ATTRIBUTE_UNUSED, 299 HOST_WIDE_INT rounded_stack_size, 300 HOST_WIDE_INT struct_value_size ATTRIBUTE_UNUSED, 301 rtx next_arg_reg ATTRIBUTE_UNUSED, rtx valreg, 302 int old_inhibit_defer_pop, rtx call_fusage, int ecf_flags, 303 cumulative_args_t args_so_far ATTRIBUTE_UNUSED) 304{ 305 rtx rounded_stack_size_rtx = GEN_INT (rounded_stack_size); 306 rtx_insn *call_insn; 307 rtx call, funmem; 308 int already_popped = 0; 309 HOST_WIDE_INT n_popped 310 = targetm.calls.return_pops_args (fndecl, funtype, stack_size); 311 312#ifdef CALL_POPS_ARGS 313 n_popped += CALL_POPS_ARGS (*get_cumulative_args (args_so_far)); 314#endif 315 316 /* Ensure address is valid. SYMBOL_REF is already valid, so no need, 317 and we don't want to load it into a register as an optimization, 318 because prepare_call_address already did it if it should be done. */ 319 if (GET_CODE (funexp) != SYMBOL_REF) 320 funexp = memory_address (FUNCTION_MODE, funexp); 321 322 funmem = gen_rtx_MEM (FUNCTION_MODE, funexp); 323 if (fndecl && TREE_CODE (fndecl) == FUNCTION_DECL) 324 { 325 tree t = fndecl; 326 327 /* Although a built-in FUNCTION_DECL and its non-__builtin 328 counterpart compare equal and get a shared mem_attrs, they 329 produce different dump output in compare-debug compilations, 330 if an entry gets garbage collected in one compilation, then 331 adds a different (but equivalent) entry, while the other 332 doesn't run the garbage collector at the same spot and then 333 shares the mem_attr with the equivalent entry. */ 334 if (DECL_BUILT_IN_CLASS (t) == BUILT_IN_NORMAL) 335 { 336 tree t2 = builtin_decl_explicit (DECL_FUNCTION_CODE (t)); 337 if (t2) 338 t = t2; 339 } 340 341 set_mem_expr (funmem, t); 342 } 343 else if (fntree) 344 set_mem_expr (funmem, build_simple_mem_ref (CALL_EXPR_FN (fntree))); 345 346#if defined (HAVE_sibcall_pop) && defined (HAVE_sibcall_value_pop) 347 if ((ecf_flags & ECF_SIBCALL) 348 && HAVE_sibcall_pop && HAVE_sibcall_value_pop 349 && (n_popped > 0 || stack_size == 0)) 350 { 351 rtx n_pop = GEN_INT (n_popped); 352 rtx pat; 353 354 /* If this subroutine pops its own args, record that in the call insn 355 if possible, for the sake of frame pointer elimination. */ 356 357 if (valreg) 358 pat = GEN_SIBCALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx, 359 next_arg_reg, n_pop); 360 else 361 pat = GEN_SIBCALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg, 362 n_pop); 363 364 emit_call_insn (pat); 365 already_popped = 1; 366 } 367 else 368#endif 369 370#if defined (HAVE_call_pop) && defined (HAVE_call_value_pop) 371 /* If the target has "call" or "call_value" insns, then prefer them 372 if no arguments are actually popped. If the target does not have 373 "call" or "call_value" insns, then we must use the popping versions 374 even if the call has no arguments to pop. */ 375#if defined (HAVE_call) && defined (HAVE_call_value) 376 if (HAVE_call && HAVE_call_value && HAVE_call_pop && HAVE_call_value_pop 377 && n_popped > 0) 378#else 379 if (HAVE_call_pop && HAVE_call_value_pop) 380#endif 381 { 382 rtx n_pop = GEN_INT (n_popped); 383 rtx pat; 384 385 /* If this subroutine pops its own args, record that in the call insn 386 if possible, for the sake of frame pointer elimination. */ 387 388 if (valreg) 389 pat = GEN_CALL_VALUE_POP (valreg, funmem, rounded_stack_size_rtx, 390 next_arg_reg, n_pop); 391 else 392 pat = GEN_CALL_POP (funmem, rounded_stack_size_rtx, next_arg_reg, 393 n_pop); 394 395 emit_call_insn (pat); 396 already_popped = 1; 397 } 398 else 399#endif 400 401#if defined (HAVE_sibcall) && defined (HAVE_sibcall_value) 402 if ((ecf_flags & ECF_SIBCALL) 403 && HAVE_sibcall && HAVE_sibcall_value) 404 { 405 if (valreg) 406 emit_call_insn (GEN_SIBCALL_VALUE (valreg, funmem, 407 rounded_stack_size_rtx, 408 next_arg_reg, NULL_RTX)); 409 else 410 emit_call_insn (GEN_SIBCALL (funmem, rounded_stack_size_rtx, 411 next_arg_reg, 412 GEN_INT (struct_value_size))); 413 } 414 else 415#endif 416 417#if defined (HAVE_call) && defined (HAVE_call_value) 418 if (HAVE_call && HAVE_call_value) 419 { 420 if (valreg) 421 emit_call_insn (GEN_CALL_VALUE (valreg, funmem, rounded_stack_size_rtx, 422 next_arg_reg, NULL_RTX)); 423 else 424 emit_call_insn (GEN_CALL (funmem, rounded_stack_size_rtx, next_arg_reg, 425 GEN_INT (struct_value_size))); 426 } 427 else 428#endif 429 gcc_unreachable (); 430 431 /* Find the call we just emitted. */ 432 call_insn = last_call_insn (); 433 434 /* Some target create a fresh MEM instead of reusing the one provided 435 above. Set its MEM_EXPR. */ 436 call = get_call_rtx_from (call_insn); 437 if (call 438 && MEM_EXPR (XEXP (call, 0)) == NULL_TREE 439 && MEM_EXPR (funmem) != NULL_TREE) 440 set_mem_expr (XEXP (call, 0), MEM_EXPR (funmem)); 441 442 /* Mark instrumented calls. */ 443 if (call && fntree) 444 CALL_EXPR_WITH_BOUNDS_P (call) = CALL_WITH_BOUNDS_P (fntree); 445 446 /* Put the register usage information there. */ 447 add_function_usage_to (call_insn, call_fusage); 448 449 /* If this is a const call, then set the insn's unchanging bit. */ 450 if (ecf_flags & ECF_CONST) 451 RTL_CONST_CALL_P (call_insn) = 1; 452 453 /* If this is a pure call, then set the insn's unchanging bit. */ 454 if (ecf_flags & ECF_PURE) 455 RTL_PURE_CALL_P (call_insn) = 1; 456 457 /* If this is a const call, then set the insn's unchanging bit. */ 458 if (ecf_flags & ECF_LOOPING_CONST_OR_PURE) 459 RTL_LOOPING_CONST_OR_PURE_CALL_P (call_insn) = 1; 460 461 /* Create a nothrow REG_EH_REGION note, if needed. */ 462 make_reg_eh_region_note (call_insn, ecf_flags, 0); 463 464 if (ecf_flags & ECF_NORETURN) 465 add_reg_note (call_insn, REG_NORETURN, const0_rtx); 466 467 if (ecf_flags & ECF_RETURNS_TWICE) 468 { 469 add_reg_note (call_insn, REG_SETJMP, const0_rtx); 470 cfun->calls_setjmp = 1; 471 } 472 473 SIBLING_CALL_P (call_insn) = ((ecf_flags & ECF_SIBCALL) != 0); 474 475 /* Restore this now, so that we do defer pops for this call's args 476 if the context of the call as a whole permits. */ 477 inhibit_defer_pop = old_inhibit_defer_pop; 478 479 if (n_popped > 0) 480 { 481 if (!already_popped) 482 CALL_INSN_FUNCTION_USAGE (call_insn) 483 = gen_rtx_EXPR_LIST (VOIDmode, 484 gen_rtx_CLOBBER (VOIDmode, stack_pointer_rtx), 485 CALL_INSN_FUNCTION_USAGE (call_insn)); 486 rounded_stack_size -= n_popped; 487 rounded_stack_size_rtx = GEN_INT (rounded_stack_size); 488 stack_pointer_delta -= n_popped; 489 490 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta)); 491 492 /* If popup is needed, stack realign must use DRAP */ 493 if (SUPPORTS_STACK_ALIGNMENT) 494 crtl->need_drap = true; 495 } 496 /* For noreturn calls when not accumulating outgoing args force 497 REG_ARGS_SIZE note to prevent crossjumping of calls with different 498 args sizes. */ 499 else if (!ACCUMULATE_OUTGOING_ARGS && (ecf_flags & ECF_NORETURN) != 0) 500 add_reg_note (call_insn, REG_ARGS_SIZE, GEN_INT (stack_pointer_delta)); 501 502 if (!ACCUMULATE_OUTGOING_ARGS) 503 { 504 /* If returning from the subroutine does not automatically pop the args, 505 we need an instruction to pop them sooner or later. 506 Perhaps do it now; perhaps just record how much space to pop later. 507 508 If returning from the subroutine does pop the args, indicate that the 509 stack pointer will be changed. */ 510 511 if (rounded_stack_size != 0) 512 { 513 if (ecf_flags & ECF_NORETURN) 514 /* Just pretend we did the pop. */ 515 stack_pointer_delta -= rounded_stack_size; 516 else if (flag_defer_pop && inhibit_defer_pop == 0 517 && ! (ecf_flags & (ECF_CONST | ECF_PURE))) 518 pending_stack_adjust += rounded_stack_size; 519 else 520 adjust_stack (rounded_stack_size_rtx); 521 } 522 } 523 /* When we accumulate outgoing args, we must avoid any stack manipulations. 524 Restore the stack pointer to its original value now. Usually 525 ACCUMULATE_OUTGOING_ARGS targets don't get here, but there are exceptions. 526 On i386 ACCUMULATE_OUTGOING_ARGS can be enabled on demand, and 527 popping variants of functions exist as well. 528 529 ??? We may optimize similar to defer_pop above, but it is 530 probably not worthwhile. 531 532 ??? It will be worthwhile to enable combine_stack_adjustments even for 533 such machines. */ 534 else if (n_popped) 535 anti_adjust_stack (GEN_INT (n_popped)); 536} 537 538/* Determine if the function identified by NAME and FNDECL is one with 539 special properties we wish to know about. 540 541 For example, if the function might return more than one time (setjmp), then 542 set RETURNS_TWICE to a nonzero value. 543 544 Similarly set NORETURN if the function is in the longjmp family. 545 546 Set MAY_BE_ALLOCA for any memory allocation function that might allocate 547 space from the stack such as alloca. */ 548 549static int 550special_function_p (const_tree fndecl, int flags) 551{ 552 tree name_decl = DECL_NAME (fndecl); 553 554 /* For instrumentation clones we want to derive flags 555 from the original name. */ 556 if (cgraph_node::get (fndecl) 557 && cgraph_node::get (fndecl)->instrumentation_clone) 558 name_decl = DECL_NAME (cgraph_node::get (fndecl)->orig_decl); 559 560 if (fndecl && name_decl 561 && IDENTIFIER_LENGTH (name_decl) <= 17 562 /* Exclude functions not at the file scope, or not `extern', 563 since they are not the magic functions we would otherwise 564 think they are. 565 FIXME: this should be handled with attributes, not with this 566 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong 567 because you can declare fork() inside a function if you 568 wish. */ 569 && (DECL_CONTEXT (fndecl) == NULL_TREE 570 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL) 571 && TREE_PUBLIC (fndecl)) 572 { 573 const char *name = IDENTIFIER_POINTER (name_decl); 574 const char *tname = name; 575 576 /* We assume that alloca will always be called by name. It 577 makes no sense to pass it as a pointer-to-function to 578 anything that does not understand its behavior. */ 579 if (IDENTIFIER_LENGTH (name_decl) == 6 580 && name[0] == 'a' 581 && ! strcmp (name, "alloca")) 582 flags |= ECF_MAY_BE_ALLOCA; 583 584 /* Disregard prefix _, __, __x or __builtin_. */ 585 if (name[0] == '_') 586 { 587 if (name[1] == '_' 588 && name[2] == 'b' 589 && !strncmp (name + 3, "uiltin_", 7)) 590 tname += 10; 591 else if (name[1] == '_' && name[2] == 'x') 592 tname += 3; 593 else if (name[1] == '_') 594 tname += 2; 595 else 596 tname += 1; 597 } 598 599 if (tname[0] == 's') 600 { 601 if ((tname[1] == 'e' 602 && (! strcmp (tname, "setjmp") 603 || ! strcmp (tname, "setjmp_syscall"))) 604 || (tname[1] == 'i' 605 && ! strcmp (tname, "sigsetjmp")) 606 || (tname[1] == 'a' 607 && ! strcmp (tname, "savectx"))) 608 flags |= ECF_RETURNS_TWICE | ECF_LEAF; 609 610 if (tname[1] == 'i' 611 && ! strcmp (tname, "siglongjmp")) 612 flags |= ECF_NORETURN; 613 } 614 else if ((tname[0] == 'q' && tname[1] == 's' 615 && ! strcmp (tname, "qsetjmp")) 616 || (tname[0] == 'v' && tname[1] == 'f' 617 && ! strcmp (tname, "vfork")) 618 || (tname[0] == 'g' && tname[1] == 'e' 619 && !strcmp (tname, "getcontext"))) 620 flags |= ECF_RETURNS_TWICE | ECF_LEAF; 621 622 else if (tname[0] == 'l' && tname[1] == 'o' 623 && ! strcmp (tname, "longjmp")) 624 flags |= ECF_NORETURN; 625 } 626 627 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) 628 switch (DECL_FUNCTION_CODE (fndecl)) 629 { 630 case BUILT_IN_ALLOCA: 631 case BUILT_IN_ALLOCA_WITH_ALIGN: 632 flags |= ECF_MAY_BE_ALLOCA; 633 break; 634 default: 635 break; 636 } 637 638 return flags; 639} 640 641/* Similar to special_function_p; return a set of ERF_ flags for the 642 function FNDECL. */ 643static int 644decl_return_flags (tree fndecl) 645{ 646 tree attr; 647 tree type = TREE_TYPE (fndecl); 648 if (!type) 649 return 0; 650 651 attr = lookup_attribute ("fn spec", TYPE_ATTRIBUTES (type)); 652 if (!attr) 653 return 0; 654 655 attr = TREE_VALUE (TREE_VALUE (attr)); 656 if (!attr || TREE_STRING_LENGTH (attr) < 1) 657 return 0; 658 659 switch (TREE_STRING_POINTER (attr)[0]) 660 { 661 case '1': 662 case '2': 663 case '3': 664 case '4': 665 return ERF_RETURNS_ARG | (TREE_STRING_POINTER (attr)[0] - '1'); 666 667 case 'm': 668 return ERF_NOALIAS; 669 670 case '.': 671 default: 672 return 0; 673 } 674} 675 676/* Return nonzero when FNDECL represents a call to setjmp. */ 677 678int 679setjmp_call_p (const_tree fndecl) 680{ 681 if (DECL_IS_RETURNS_TWICE (fndecl)) 682 return ECF_RETURNS_TWICE; 683 return special_function_p (fndecl, 0) & ECF_RETURNS_TWICE; 684} 685 686 687/* Return true if STMT is an alloca call. */ 688 689bool 690gimple_alloca_call_p (const_gimple stmt) 691{ 692 tree fndecl; 693 694 if (!is_gimple_call (stmt)) 695 return false; 696 697 fndecl = gimple_call_fndecl (stmt); 698 if (fndecl && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA)) 699 return true; 700 701 return false; 702} 703 704/* Return true when exp contains alloca call. */ 705 706bool 707alloca_call_p (const_tree exp) 708{ 709 tree fndecl; 710 if (TREE_CODE (exp) == CALL_EXPR 711 && (fndecl = get_callee_fndecl (exp)) 712 && (special_function_p (fndecl, 0) & ECF_MAY_BE_ALLOCA)) 713 return true; 714 return false; 715} 716 717/* Return TRUE if FNDECL is either a TM builtin or a TM cloned 718 function. Return FALSE otherwise. */ 719 720static bool 721is_tm_builtin (const_tree fndecl) 722{ 723 if (fndecl == NULL) 724 return false; 725 726 if (decl_is_tm_clone (fndecl)) 727 return true; 728 729 if (DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL) 730 { 731 switch (DECL_FUNCTION_CODE (fndecl)) 732 { 733 case BUILT_IN_TM_COMMIT: 734 case BUILT_IN_TM_COMMIT_EH: 735 case BUILT_IN_TM_ABORT: 736 case BUILT_IN_TM_IRREVOCABLE: 737 case BUILT_IN_TM_GETTMCLONE_IRR: 738 case BUILT_IN_TM_MEMCPY: 739 case BUILT_IN_TM_MEMMOVE: 740 case BUILT_IN_TM_MEMSET: 741 CASE_BUILT_IN_TM_STORE (1): 742 CASE_BUILT_IN_TM_STORE (2): 743 CASE_BUILT_IN_TM_STORE (4): 744 CASE_BUILT_IN_TM_STORE (8): 745 CASE_BUILT_IN_TM_STORE (FLOAT): 746 CASE_BUILT_IN_TM_STORE (DOUBLE): 747 CASE_BUILT_IN_TM_STORE (LDOUBLE): 748 CASE_BUILT_IN_TM_STORE (M64): 749 CASE_BUILT_IN_TM_STORE (M128): 750 CASE_BUILT_IN_TM_STORE (M256): 751 CASE_BUILT_IN_TM_LOAD (1): 752 CASE_BUILT_IN_TM_LOAD (2): 753 CASE_BUILT_IN_TM_LOAD (4): 754 CASE_BUILT_IN_TM_LOAD (8): 755 CASE_BUILT_IN_TM_LOAD (FLOAT): 756 CASE_BUILT_IN_TM_LOAD (DOUBLE): 757 CASE_BUILT_IN_TM_LOAD (LDOUBLE): 758 CASE_BUILT_IN_TM_LOAD (M64): 759 CASE_BUILT_IN_TM_LOAD (M128): 760 CASE_BUILT_IN_TM_LOAD (M256): 761 case BUILT_IN_TM_LOG: 762 case BUILT_IN_TM_LOG_1: 763 case BUILT_IN_TM_LOG_2: 764 case BUILT_IN_TM_LOG_4: 765 case BUILT_IN_TM_LOG_8: 766 case BUILT_IN_TM_LOG_FLOAT: 767 case BUILT_IN_TM_LOG_DOUBLE: 768 case BUILT_IN_TM_LOG_LDOUBLE: 769 case BUILT_IN_TM_LOG_M64: 770 case BUILT_IN_TM_LOG_M128: 771 case BUILT_IN_TM_LOG_M256: 772 return true; 773 default: 774 break; 775 } 776 } 777 return false; 778} 779 780/* Detect flags (function attributes) from the function decl or type node. */ 781 782int 783flags_from_decl_or_type (const_tree exp) 784{ 785 int flags = 0; 786 787 if (DECL_P (exp)) 788 { 789 /* The function exp may have the `malloc' attribute. */ 790 if (DECL_IS_MALLOC (exp)) 791 flags |= ECF_MALLOC; 792 793 /* The function exp may have the `returns_twice' attribute. */ 794 if (DECL_IS_RETURNS_TWICE (exp)) 795 flags |= ECF_RETURNS_TWICE; 796 797 /* Process the pure and const attributes. */ 798 if (TREE_READONLY (exp)) 799 flags |= ECF_CONST; 800 if (DECL_PURE_P (exp)) 801 flags |= ECF_PURE; 802 if (DECL_LOOPING_CONST_OR_PURE_P (exp)) 803 flags |= ECF_LOOPING_CONST_OR_PURE; 804 805 if (DECL_IS_NOVOPS (exp)) 806 flags |= ECF_NOVOPS; 807 if (lookup_attribute ("leaf", DECL_ATTRIBUTES (exp))) 808 flags |= ECF_LEAF; 809 810 if (TREE_NOTHROW (exp)) 811 flags |= ECF_NOTHROW; 812 813 if (flag_tm) 814 { 815 if (is_tm_builtin (exp)) 816 flags |= ECF_TM_BUILTIN; 817 else if ((flags & (ECF_CONST|ECF_NOVOPS)) != 0 818 || lookup_attribute ("transaction_pure", 819 TYPE_ATTRIBUTES (TREE_TYPE (exp)))) 820 flags |= ECF_TM_PURE; 821 } 822 823 flags = special_function_p (exp, flags); 824 } 825 else if (TYPE_P (exp)) 826 { 827 if (TYPE_READONLY (exp)) 828 flags |= ECF_CONST; 829 830 if (flag_tm 831 && ((flags & ECF_CONST) != 0 832 || lookup_attribute ("transaction_pure", TYPE_ATTRIBUTES (exp)))) 833 flags |= ECF_TM_PURE; 834 } 835 else 836 gcc_unreachable (); 837 838 if (TREE_THIS_VOLATILE (exp)) 839 { 840 flags |= ECF_NORETURN; 841 if (flags & (ECF_CONST|ECF_PURE)) 842 flags |= ECF_LOOPING_CONST_OR_PURE; 843 } 844 845 return flags; 846} 847 848/* Detect flags from a CALL_EXPR. */ 849 850int 851call_expr_flags (const_tree t) 852{ 853 int flags; 854 tree decl = get_callee_fndecl (t); 855 856 if (decl) 857 flags = flags_from_decl_or_type (decl); 858 else 859 { 860 t = TREE_TYPE (CALL_EXPR_FN (t)); 861 if (t && TREE_CODE (t) == POINTER_TYPE) 862 flags = flags_from_decl_or_type (TREE_TYPE (t)); 863 else 864 flags = 0; 865 } 866 867 return flags; 868} 869 870/* Precompute all register parameters as described by ARGS, storing values 871 into fields within the ARGS array. 872 873 NUM_ACTUALS indicates the total number elements in the ARGS array. 874 875 Set REG_PARM_SEEN if we encounter a register parameter. */ 876 877static void 878precompute_register_parameters (int num_actuals, struct arg_data *args, 879 int *reg_parm_seen) 880{ 881 int i; 882 883 *reg_parm_seen = 0; 884 885 for (i = 0; i < num_actuals; i++) 886 if (args[i].reg != 0 && ! args[i].pass_on_stack) 887 { 888 *reg_parm_seen = 1; 889 890 if (args[i].value == 0) 891 { 892 push_temp_slots (); 893 args[i].value = expand_normal (args[i].tree_value); 894 preserve_temp_slots (args[i].value); 895 pop_temp_slots (); 896 } 897 898 /* If we are to promote the function arg to a wider mode, 899 do it now. */ 900 901 if (args[i].mode != TYPE_MODE (TREE_TYPE (args[i].tree_value))) 902 args[i].value 903 = convert_modes (args[i].mode, 904 TYPE_MODE (TREE_TYPE (args[i].tree_value)), 905 args[i].value, args[i].unsignedp); 906 907 /* If the value is a non-legitimate constant, force it into a 908 pseudo now. TLS symbols sometimes need a call to resolve. */ 909 if (CONSTANT_P (args[i].value) 910 && !targetm.legitimate_constant_p (args[i].mode, args[i].value)) 911 args[i].value = force_reg (args[i].mode, args[i].value); 912 913 /* If we're going to have to load the value by parts, pull the 914 parts into pseudos. The part extraction process can involve 915 non-trivial computation. */ 916 if (GET_CODE (args[i].reg) == PARALLEL) 917 { 918 tree type = TREE_TYPE (args[i].tree_value); 919 args[i].parallel_value 920 = emit_group_load_into_temps (args[i].reg, args[i].value, 921 type, int_size_in_bytes (type)); 922 } 923 924 /* If the value is expensive, and we are inside an appropriately 925 short loop, put the value into a pseudo and then put the pseudo 926 into the hard reg. 927 928 For small register classes, also do this if this call uses 929 register parameters. This is to avoid reload conflicts while 930 loading the parameters registers. */ 931 932 else if ((! (REG_P (args[i].value) 933 || (GET_CODE (args[i].value) == SUBREG 934 && REG_P (SUBREG_REG (args[i].value))))) 935 && args[i].mode != BLKmode 936 && set_src_cost (args[i].value, optimize_insn_for_speed_p ()) 937 > COSTS_N_INSNS (1) 938 && ((*reg_parm_seen 939 && targetm.small_register_classes_for_mode_p (args[i].mode)) 940 || optimize)) 941 args[i].value = copy_to_mode_reg (args[i].mode, args[i].value); 942 } 943} 944 945#ifdef REG_PARM_STACK_SPACE 946 947 /* The argument list is the property of the called routine and it 948 may clobber it. If the fixed area has been used for previous 949 parameters, we must save and restore it. */ 950 951static rtx 952save_fixed_argument_area (int reg_parm_stack_space, rtx argblock, int *low_to_save, int *high_to_save) 953{ 954 int low; 955 int high; 956 957 /* Compute the boundary of the area that needs to be saved, if any. */ 958 high = reg_parm_stack_space; 959#ifdef ARGS_GROW_DOWNWARD 960 high += 1; 961#endif 962 if (high > highest_outgoing_arg_in_use) 963 high = highest_outgoing_arg_in_use; 964 965 for (low = 0; low < high; low++) 966 if (stack_usage_map[low] != 0) 967 { 968 int num_to_save; 969 machine_mode save_mode; 970 int delta; 971 rtx addr; 972 rtx stack_area; 973 rtx save_area; 974 975 while (stack_usage_map[--high] == 0) 976 ; 977 978 *low_to_save = low; 979 *high_to_save = high; 980 981 num_to_save = high - low + 1; 982 save_mode = mode_for_size (num_to_save * BITS_PER_UNIT, MODE_INT, 1); 983 984 /* If we don't have the required alignment, must do this 985 in BLKmode. */ 986 if ((low & (MIN (GET_MODE_SIZE (save_mode), 987 BIGGEST_ALIGNMENT / UNITS_PER_WORD) - 1))) 988 save_mode = BLKmode; 989 990#ifdef ARGS_GROW_DOWNWARD 991 delta = -high; 992#else 993 delta = low; 994#endif 995 addr = plus_constant (Pmode, argblock, delta); 996 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr)); 997 998 set_mem_align (stack_area, PARM_BOUNDARY); 999 if (save_mode == BLKmode) 1000 { 1001 save_area = assign_stack_temp (BLKmode, num_to_save); 1002 emit_block_move (validize_mem (save_area), stack_area, 1003 GEN_INT (num_to_save), BLOCK_OP_CALL_PARM); 1004 } 1005 else 1006 { 1007 save_area = gen_reg_rtx (save_mode); 1008 emit_move_insn (save_area, stack_area); 1009 } 1010 1011 return save_area; 1012 } 1013 1014 return NULL_RTX; 1015} 1016 1017static void 1018restore_fixed_argument_area (rtx save_area, rtx argblock, int high_to_save, int low_to_save) 1019{ 1020 machine_mode save_mode = GET_MODE (save_area); 1021 int delta; 1022 rtx addr, stack_area; 1023 1024#ifdef ARGS_GROW_DOWNWARD 1025 delta = -high_to_save; 1026#else 1027 delta = low_to_save; 1028#endif 1029 addr = plus_constant (Pmode, argblock, delta); 1030 stack_area = gen_rtx_MEM (save_mode, memory_address (save_mode, addr)); 1031 set_mem_align (stack_area, PARM_BOUNDARY); 1032 1033 if (save_mode != BLKmode) 1034 emit_move_insn (stack_area, save_area); 1035 else 1036 emit_block_move (stack_area, validize_mem (save_area), 1037 GEN_INT (high_to_save - low_to_save + 1), 1038 BLOCK_OP_CALL_PARM); 1039} 1040#endif /* REG_PARM_STACK_SPACE */ 1041 1042/* If any elements in ARGS refer to parameters that are to be passed in 1043 registers, but not in memory, and whose alignment does not permit a 1044 direct copy into registers. Copy the values into a group of pseudos 1045 which we will later copy into the appropriate hard registers. 1046 1047 Pseudos for each unaligned argument will be stored into the array 1048 args[argnum].aligned_regs. The caller is responsible for deallocating 1049 the aligned_regs array if it is nonzero. */ 1050 1051static void 1052store_unaligned_arguments_into_pseudos (struct arg_data *args, int num_actuals) 1053{ 1054 int i, j; 1055 1056 for (i = 0; i < num_actuals; i++) 1057 if (args[i].reg != 0 && ! args[i].pass_on_stack 1058 && GET_CODE (args[i].reg) != PARALLEL 1059 && args[i].mode == BLKmode 1060 && MEM_P (args[i].value) 1061 && (MEM_ALIGN (args[i].value) 1062 < (unsigned int) MIN (BIGGEST_ALIGNMENT, BITS_PER_WORD))) 1063 { 1064 int bytes = int_size_in_bytes (TREE_TYPE (args[i].tree_value)); 1065 int endian_correction = 0; 1066 1067 if (args[i].partial) 1068 { 1069 gcc_assert (args[i].partial % UNITS_PER_WORD == 0); 1070 args[i].n_aligned_regs = args[i].partial / UNITS_PER_WORD; 1071 } 1072 else 1073 { 1074 args[i].n_aligned_regs 1075 = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; 1076 } 1077 1078 args[i].aligned_regs = XNEWVEC (rtx, args[i].n_aligned_regs); 1079 1080 /* Structures smaller than a word are normally aligned to the 1081 least significant byte. On a BYTES_BIG_ENDIAN machine, 1082 this means we must skip the empty high order bytes when 1083 calculating the bit offset. */ 1084 if (bytes < UNITS_PER_WORD 1085#ifdef BLOCK_REG_PADDING 1086 && (BLOCK_REG_PADDING (args[i].mode, 1087 TREE_TYPE (args[i].tree_value), 1) 1088 == downward) 1089#else 1090 && BYTES_BIG_ENDIAN 1091#endif 1092 ) 1093 endian_correction = BITS_PER_WORD - bytes * BITS_PER_UNIT; 1094 1095 for (j = 0; j < args[i].n_aligned_regs; j++) 1096 { 1097 rtx reg = gen_reg_rtx (word_mode); 1098 rtx word = operand_subword_force (args[i].value, j, BLKmode); 1099 int bitsize = MIN (bytes * BITS_PER_UNIT, BITS_PER_WORD); 1100 1101 args[i].aligned_regs[j] = reg; 1102 word = extract_bit_field (word, bitsize, 0, 1, NULL_RTX, 1103 word_mode, word_mode); 1104 1105 /* There is no need to restrict this code to loading items 1106 in TYPE_ALIGN sized hunks. The bitfield instructions can 1107 load up entire word sized registers efficiently. 1108 1109 ??? This may not be needed anymore. 1110 We use to emit a clobber here but that doesn't let later 1111 passes optimize the instructions we emit. By storing 0 into 1112 the register later passes know the first AND to zero out the 1113 bitfield being set in the register is unnecessary. The store 1114 of 0 will be deleted as will at least the first AND. */ 1115 1116 emit_move_insn (reg, const0_rtx); 1117 1118 bytes -= bitsize / BITS_PER_UNIT; 1119 store_bit_field (reg, bitsize, endian_correction, 0, 0, 1120 word_mode, word); 1121 } 1122 } 1123} 1124 1125/* Fill in ARGS_SIZE and ARGS array based on the parameters found in 1126 CALL_EXPR EXP. 1127 1128 NUM_ACTUALS is the total number of parameters. 1129 1130 N_NAMED_ARGS is the total number of named arguments. 1131 1132 STRUCT_VALUE_ADDR_VALUE is the implicit argument for a struct return 1133 value, or null. 1134 1135 FNDECL is the tree code for the target of this call (if known) 1136 1137 ARGS_SO_FAR holds state needed by the target to know where to place 1138 the next argument. 1139 1140 REG_PARM_STACK_SPACE is the number of bytes of stack space reserved 1141 for arguments which are passed in registers. 1142 1143 OLD_STACK_LEVEL is a pointer to an rtx which olds the old stack level 1144 and may be modified by this routine. 1145 1146 OLD_PENDING_ADJ, MUST_PREALLOCATE and FLAGS are pointers to integer 1147 flags which may may be modified by this routine. 1148 1149 MAY_TAILCALL is cleared if we encounter an invisible pass-by-reference 1150 that requires allocation of stack space. 1151 1152 CALL_FROM_THUNK_P is true if this call is the jump from a thunk to 1153 the thunked-to function. */ 1154 1155static void 1156initialize_argument_information (int num_actuals ATTRIBUTE_UNUSED, 1157 struct arg_data *args, 1158 struct args_size *args_size, 1159 int n_named_args ATTRIBUTE_UNUSED, 1160 tree exp, tree struct_value_addr_value, 1161 tree fndecl, tree fntype, 1162 cumulative_args_t args_so_far, 1163 int reg_parm_stack_space, 1164 rtx *old_stack_level, int *old_pending_adj, 1165 int *must_preallocate, int *ecf_flags, 1166 bool *may_tailcall, bool call_from_thunk_p) 1167{ 1168 CUMULATIVE_ARGS *args_so_far_pnt = get_cumulative_args (args_so_far); 1169 location_t loc = EXPR_LOCATION (exp); 1170 1171 /* Count arg position in order args appear. */ 1172 int argpos; 1173 1174 int i; 1175 1176 args_size->constant = 0; 1177 args_size->var = 0; 1178 1179 bitmap_obstack_initialize (NULL); 1180 1181 /* In this loop, we consider args in the order they are written. 1182 We fill up ARGS from the back. */ 1183 1184 i = num_actuals - 1; 1185 { 1186 int j = i, ptr_arg = -1; 1187 call_expr_arg_iterator iter; 1188 tree arg; 1189 bitmap slots = NULL; 1190 1191 if (struct_value_addr_value) 1192 { 1193 args[j].tree_value = struct_value_addr_value; 1194 j--; 1195 1196 /* If we pass structure address then we need to 1197 create bounds for it. Since created bounds is 1198 a call statement, we expand it right here to avoid 1199 fixing all other places where it may be expanded. */ 1200 if (CALL_WITH_BOUNDS_P (exp)) 1201 { 1202 args[j].value = gen_reg_rtx (targetm.chkp_bound_mode ()); 1203 args[j].tree_value 1204 = chkp_make_bounds_for_struct_addr (struct_value_addr_value); 1205 expand_expr_real (args[j].tree_value, args[j].value, VOIDmode, 1206 EXPAND_NORMAL, 0, false); 1207 args[j].pointer_arg = j + 1; 1208 j--; 1209 } 1210 } 1211 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) 1212 { 1213 tree argtype = TREE_TYPE (arg); 1214 1215 /* Remember last param with pointer and associate it 1216 with following pointer bounds. */ 1217 if (CALL_WITH_BOUNDS_P (exp) 1218 && chkp_type_has_pointer (argtype)) 1219 { 1220 if (slots) 1221 BITMAP_FREE (slots); 1222 ptr_arg = j; 1223 if (!BOUNDED_TYPE_P (argtype)) 1224 { 1225 slots = BITMAP_ALLOC (NULL); 1226 chkp_find_bound_slots (argtype, slots); 1227 } 1228 } 1229 else if (POINTER_BOUNDS_TYPE_P (argtype)) 1230 { 1231 /* We expect bounds in instrumented calls only. 1232 Otherwise it is a sign we lost flag due to some optimization 1233 and may emit call args incorrectly. */ 1234 gcc_assert (CALL_WITH_BOUNDS_P (exp)); 1235 1236 /* For structures look for the next available pointer. */ 1237 if (ptr_arg != -1 && slots) 1238 { 1239 unsigned bnd_no = bitmap_first_set_bit (slots); 1240 args[j].pointer_offset = 1241 bnd_no * POINTER_SIZE / BITS_PER_UNIT; 1242 1243 bitmap_clear_bit (slots, bnd_no); 1244 1245 /* Check we have no more pointers in the structure. */ 1246 if (bitmap_empty_p (slots)) 1247 BITMAP_FREE (slots); 1248 } 1249 args[j].pointer_arg = ptr_arg; 1250 1251 /* Check we covered all pointers in the previous 1252 non bounds arg. */ 1253 if (!slots) 1254 ptr_arg = -1; 1255 } 1256 else 1257 ptr_arg = -1; 1258 1259 if (targetm.calls.split_complex_arg 1260 && argtype 1261 && TREE_CODE (argtype) == COMPLEX_TYPE 1262 && targetm.calls.split_complex_arg (argtype)) 1263 { 1264 tree subtype = TREE_TYPE (argtype); 1265 args[j].tree_value = build1 (REALPART_EXPR, subtype, arg); 1266 j--; 1267 args[j].tree_value = build1 (IMAGPART_EXPR, subtype, arg); 1268 } 1269 else 1270 args[j].tree_value = arg; 1271 j--; 1272 } 1273 1274 if (slots) 1275 BITMAP_FREE (slots); 1276 } 1277 1278 bitmap_obstack_release (NULL); 1279 1280 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */ 1281 for (argpos = 0; argpos < num_actuals; i--, argpos++) 1282 { 1283 tree type = TREE_TYPE (args[i].tree_value); 1284 int unsignedp; 1285 machine_mode mode; 1286 1287 /* Replace erroneous argument with constant zero. */ 1288 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) 1289 args[i].tree_value = integer_zero_node, type = integer_type_node; 1290 1291 /* If TYPE is a transparent union or record, pass things the way 1292 we would pass the first field of the union or record. We have 1293 already verified that the modes are the same. */ 1294 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE) 1295 && TYPE_TRANSPARENT_AGGR (type)) 1296 type = TREE_TYPE (first_field (type)); 1297 1298 /* Decide where to pass this arg. 1299 1300 args[i].reg is nonzero if all or part is passed in registers. 1301 1302 args[i].partial is nonzero if part but not all is passed in registers, 1303 and the exact value says how many bytes are passed in registers. 1304 1305 args[i].pass_on_stack is nonzero if the argument must at least be 1306 computed on the stack. It may then be loaded back into registers 1307 if args[i].reg is nonzero. 1308 1309 These decisions are driven by the FUNCTION_... macros and must agree 1310 with those made by function.c. */ 1311 1312 /* See if this argument should be passed by invisible reference. */ 1313 if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type), 1314 type, argpos < n_named_args)) 1315 { 1316 bool callee_copies; 1317 tree base = NULL_TREE; 1318 1319 callee_copies 1320 = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type), 1321 type, argpos < n_named_args); 1322 1323 /* If we're compiling a thunk, pass through invisible references 1324 instead of making a copy. */ 1325 if (call_from_thunk_p 1326 || (callee_copies 1327 && !TREE_ADDRESSABLE (type) 1328 && (base = get_base_address (args[i].tree_value)) 1329 && TREE_CODE (base) != SSA_NAME 1330 && (!DECL_P (base) || MEM_P (DECL_RTL (base))))) 1331 { 1332 /* We may have turned the parameter value into an SSA name. 1333 Go back to the original parameter so we can take the 1334 address. */ 1335 if (TREE_CODE (args[i].tree_value) == SSA_NAME) 1336 { 1337 gcc_assert (SSA_NAME_IS_DEFAULT_DEF (args[i].tree_value)); 1338 args[i].tree_value = SSA_NAME_VAR (args[i].tree_value); 1339 gcc_assert (TREE_CODE (args[i].tree_value) == PARM_DECL); 1340 } 1341 /* Argument setup code may have copied the value to register. We 1342 revert that optimization now because the tail call code must 1343 use the original location. */ 1344 if (TREE_CODE (args[i].tree_value) == PARM_DECL 1345 && !MEM_P (DECL_RTL (args[i].tree_value)) 1346 && DECL_INCOMING_RTL (args[i].tree_value) 1347 && MEM_P (DECL_INCOMING_RTL (args[i].tree_value))) 1348 set_decl_rtl (args[i].tree_value, 1349 DECL_INCOMING_RTL (args[i].tree_value)); 1350 1351 mark_addressable (args[i].tree_value); 1352 1353 /* We can't use sibcalls if a callee-copied argument is 1354 stored in the current function's frame. */ 1355 if (!call_from_thunk_p && DECL_P (base) && !TREE_STATIC (base)) 1356 *may_tailcall = false; 1357 1358 args[i].tree_value = build_fold_addr_expr_loc (loc, 1359 args[i].tree_value); 1360 type = TREE_TYPE (args[i].tree_value); 1361 1362 if (*ecf_flags & ECF_CONST) 1363 *ecf_flags &= ~(ECF_CONST | ECF_LOOPING_CONST_OR_PURE); 1364 } 1365 else 1366 { 1367 /* We make a copy of the object and pass the address to the 1368 function being called. */ 1369 rtx copy; 1370 1371 if (!COMPLETE_TYPE_P (type) 1372 || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST 1373 || (flag_stack_check == GENERIC_STACK_CHECK 1374 && compare_tree_int (TYPE_SIZE_UNIT (type), 1375 STACK_CHECK_MAX_VAR_SIZE) > 0)) 1376 { 1377 /* This is a variable-sized object. Make space on the stack 1378 for it. */ 1379 rtx size_rtx = expr_size (args[i].tree_value); 1380 1381 if (*old_stack_level == 0) 1382 { 1383 emit_stack_save (SAVE_BLOCK, old_stack_level); 1384 *old_pending_adj = pending_stack_adjust; 1385 pending_stack_adjust = 0; 1386 } 1387 1388 /* We can pass TRUE as the 4th argument because we just 1389 saved the stack pointer and will restore it right after 1390 the call. */ 1391 copy = allocate_dynamic_stack_space (size_rtx, 1392 TYPE_ALIGN (type), 1393 TYPE_ALIGN (type), 1394 true); 1395 copy = gen_rtx_MEM (BLKmode, copy); 1396 set_mem_attributes (copy, type, 1); 1397 } 1398 else 1399 copy = assign_temp (type, 1, 0); 1400 1401 store_expr (args[i].tree_value, copy, 0, false); 1402 1403 /* Just change the const function to pure and then let 1404 the next test clear the pure based on 1405 callee_copies. */ 1406 if (*ecf_flags & ECF_CONST) 1407 { 1408 *ecf_flags &= ~ECF_CONST; 1409 *ecf_flags |= ECF_PURE; 1410 } 1411 1412 if (!callee_copies && *ecf_flags & ECF_PURE) 1413 *ecf_flags &= ~(ECF_PURE | ECF_LOOPING_CONST_OR_PURE); 1414 1415 args[i].tree_value 1416 = build_fold_addr_expr_loc (loc, make_tree (type, copy)); 1417 type = TREE_TYPE (args[i].tree_value); 1418 *may_tailcall = false; 1419 } 1420 } 1421 1422 unsignedp = TYPE_UNSIGNED (type); 1423 mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp, 1424 fndecl ? TREE_TYPE (fndecl) : fntype, 0); 1425 1426 args[i].unsignedp = unsignedp; 1427 args[i].mode = mode; 1428 1429 args[i].reg = targetm.calls.function_arg (args_so_far, mode, type, 1430 argpos < n_named_args); 1431 1432 if (args[i].reg && CONST_INT_P (args[i].reg)) 1433 { 1434 args[i].special_slot = args[i].reg; 1435 args[i].reg = NULL; 1436 } 1437 1438 /* If this is a sibling call and the machine has register windows, the 1439 register window has to be unwinded before calling the routine, so 1440 arguments have to go into the incoming registers. */ 1441 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg) 1442 args[i].tail_call_reg 1443 = targetm.calls.function_incoming_arg (args_so_far, mode, type, 1444 argpos < n_named_args); 1445 else 1446 args[i].tail_call_reg = args[i].reg; 1447 1448 if (args[i].reg) 1449 args[i].partial 1450 = targetm.calls.arg_partial_bytes (args_so_far, mode, type, 1451 argpos < n_named_args); 1452 1453 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type); 1454 1455 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]), 1456 it means that we are to pass this arg in the register(s) designated 1457 by the PARALLEL, but also to pass it in the stack. */ 1458 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL 1459 && XEXP (XVECEXP (args[i].reg, 0, 0), 0) == 0) 1460 args[i].pass_on_stack = 1; 1461 1462 /* If this is an addressable type, we must preallocate the stack 1463 since we must evaluate the object into its final location. 1464 1465 If this is to be passed in both registers and the stack, it is simpler 1466 to preallocate. */ 1467 if (TREE_ADDRESSABLE (type) 1468 || (args[i].pass_on_stack && args[i].reg != 0)) 1469 *must_preallocate = 1; 1470 1471 /* No stack allocation and padding for bounds. */ 1472 if (POINTER_BOUNDS_P (args[i].tree_value)) 1473 ; 1474 /* Compute the stack-size of this argument. */ 1475 else if (args[i].reg == 0 || args[i].partial != 0 1476 || reg_parm_stack_space > 0 1477 || args[i].pass_on_stack) 1478 locate_and_pad_parm (mode, type, 1479#ifdef STACK_PARMS_IN_REG_PARM_AREA 1480 1, 1481#else 1482 args[i].reg != 0, 1483#endif 1484 reg_parm_stack_space, 1485 args[i].pass_on_stack ? 0 : args[i].partial, 1486 fndecl, args_size, &args[i].locate); 1487#ifdef BLOCK_REG_PADDING 1488 else 1489 /* The argument is passed entirely in registers. See at which 1490 end it should be padded. */ 1491 args[i].locate.where_pad = 1492 BLOCK_REG_PADDING (mode, type, 1493 int_size_in_bytes (type) <= UNITS_PER_WORD); 1494#endif 1495 1496 /* Update ARGS_SIZE, the total stack space for args so far. */ 1497 1498 args_size->constant += args[i].locate.size.constant; 1499 if (args[i].locate.size.var) 1500 ADD_PARM_SIZE (*args_size, args[i].locate.size.var); 1501 1502 /* Increment ARGS_SO_FAR, which has info about which arg-registers 1503 have been used, etc. */ 1504 1505 targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type), 1506 type, argpos < n_named_args); 1507 } 1508} 1509 1510/* Update ARGS_SIZE to contain the total size for the argument block. 1511 Return the original constant component of the argument block's size. 1512 1513 REG_PARM_STACK_SPACE holds the number of bytes of stack space reserved 1514 for arguments passed in registers. */ 1515 1516static int 1517compute_argument_block_size (int reg_parm_stack_space, 1518 struct args_size *args_size, 1519 tree fndecl ATTRIBUTE_UNUSED, 1520 tree fntype ATTRIBUTE_UNUSED, 1521 int preferred_stack_boundary ATTRIBUTE_UNUSED) 1522{ 1523 int unadjusted_args_size = args_size->constant; 1524 1525 /* For accumulate outgoing args mode we don't need to align, since the frame 1526 will be already aligned. Align to STACK_BOUNDARY in order to prevent 1527 backends from generating misaligned frame sizes. */ 1528 if (ACCUMULATE_OUTGOING_ARGS && preferred_stack_boundary > STACK_BOUNDARY) 1529 preferred_stack_boundary = STACK_BOUNDARY; 1530 1531 /* Compute the actual size of the argument block required. The variable 1532 and constant sizes must be combined, the size may have to be rounded, 1533 and there may be a minimum required size. */ 1534 1535 if (args_size->var) 1536 { 1537 args_size->var = ARGS_SIZE_TREE (*args_size); 1538 args_size->constant = 0; 1539 1540 preferred_stack_boundary /= BITS_PER_UNIT; 1541 if (preferred_stack_boundary > 1) 1542 { 1543 /* We don't handle this case yet. To handle it correctly we have 1544 to add the delta, round and subtract the delta. 1545 Currently no machine description requires this support. */ 1546 gcc_assert (!(stack_pointer_delta & (preferred_stack_boundary - 1))); 1547 args_size->var = round_up (args_size->var, preferred_stack_boundary); 1548 } 1549 1550 if (reg_parm_stack_space > 0) 1551 { 1552 args_size->var 1553 = size_binop (MAX_EXPR, args_size->var, 1554 ssize_int (reg_parm_stack_space)); 1555 1556 /* The area corresponding to register parameters is not to count in 1557 the size of the block we need. So make the adjustment. */ 1558 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) 1559 args_size->var 1560 = size_binop (MINUS_EXPR, args_size->var, 1561 ssize_int (reg_parm_stack_space)); 1562 } 1563 } 1564 else 1565 { 1566 preferred_stack_boundary /= BITS_PER_UNIT; 1567 if (preferred_stack_boundary < 1) 1568 preferred_stack_boundary = 1; 1569 args_size->constant = (((args_size->constant 1570 + stack_pointer_delta 1571 + preferred_stack_boundary - 1) 1572 / preferred_stack_boundary 1573 * preferred_stack_boundary) 1574 - stack_pointer_delta); 1575 1576 args_size->constant = MAX (args_size->constant, 1577 reg_parm_stack_space); 1578 1579 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) 1580 args_size->constant -= reg_parm_stack_space; 1581 } 1582 return unadjusted_args_size; 1583} 1584 1585/* Precompute parameters as needed for a function call. 1586 1587 FLAGS is mask of ECF_* constants. 1588 1589 NUM_ACTUALS is the number of arguments. 1590 1591 ARGS is an array containing information for each argument; this 1592 routine fills in the INITIAL_VALUE and VALUE fields for each 1593 precomputed argument. */ 1594 1595static void 1596precompute_arguments (int num_actuals, struct arg_data *args) 1597{ 1598 int i; 1599 1600 /* If this is a libcall, then precompute all arguments so that we do not 1601 get extraneous instructions emitted as part of the libcall sequence. */ 1602 1603 /* If we preallocated the stack space, and some arguments must be passed 1604 on the stack, then we must precompute any parameter which contains a 1605 function call which will store arguments on the stack. 1606 Otherwise, evaluating the parameter may clobber previous parameters 1607 which have already been stored into the stack. (we have code to avoid 1608 such case by saving the outgoing stack arguments, but it results in 1609 worse code) */ 1610 if (!ACCUMULATE_OUTGOING_ARGS) 1611 return; 1612 1613 for (i = 0; i < num_actuals; i++) 1614 { 1615 tree type; 1616 machine_mode mode; 1617 1618 if (TREE_CODE (args[i].tree_value) != CALL_EXPR) 1619 continue; 1620 1621 /* If this is an addressable type, we cannot pre-evaluate it. */ 1622 type = TREE_TYPE (args[i].tree_value); 1623 gcc_assert (!TREE_ADDRESSABLE (type)); 1624 1625 args[i].initial_value = args[i].value 1626 = expand_normal (args[i].tree_value); 1627 1628 mode = TYPE_MODE (type); 1629 if (mode != args[i].mode) 1630 { 1631 int unsignedp = args[i].unsignedp; 1632 args[i].value 1633 = convert_modes (args[i].mode, mode, 1634 args[i].value, args[i].unsignedp); 1635 1636 /* CSE will replace this only if it contains args[i].value 1637 pseudo, so convert it down to the declared mode using 1638 a SUBREG. */ 1639 if (REG_P (args[i].value) 1640 && GET_MODE_CLASS (args[i].mode) == MODE_INT 1641 && promote_mode (type, mode, &unsignedp) != args[i].mode) 1642 { 1643 args[i].initial_value 1644 = gen_lowpart_SUBREG (mode, args[i].value); 1645 SUBREG_PROMOTED_VAR_P (args[i].initial_value) = 1; 1646 SUBREG_PROMOTED_SET (args[i].initial_value, args[i].unsignedp); 1647 } 1648 } 1649 } 1650} 1651 1652/* Given the current state of MUST_PREALLOCATE and information about 1653 arguments to a function call in NUM_ACTUALS, ARGS and ARGS_SIZE, 1654 compute and return the final value for MUST_PREALLOCATE. */ 1655 1656static int 1657finalize_must_preallocate (int must_preallocate, int num_actuals, 1658 struct arg_data *args, struct args_size *args_size) 1659{ 1660 /* See if we have or want to preallocate stack space. 1661 1662 If we would have to push a partially-in-regs parm 1663 before other stack parms, preallocate stack space instead. 1664 1665 If the size of some parm is not a multiple of the required stack 1666 alignment, we must preallocate. 1667 1668 If the total size of arguments that would otherwise create a copy in 1669 a temporary (such as a CALL) is more than half the total argument list 1670 size, preallocation is faster. 1671 1672 Another reason to preallocate is if we have a machine (like the m88k) 1673 where stack alignment is required to be maintained between every 1674 pair of insns, not just when the call is made. However, we assume here 1675 that such machines either do not have push insns (and hence preallocation 1676 would occur anyway) or the problem is taken care of with 1677 PUSH_ROUNDING. */ 1678 1679 if (! must_preallocate) 1680 { 1681 int partial_seen = 0; 1682 int copy_to_evaluate_size = 0; 1683 int i; 1684 1685 for (i = 0; i < num_actuals && ! must_preallocate; i++) 1686 { 1687 if (args[i].partial > 0 && ! args[i].pass_on_stack) 1688 partial_seen = 1; 1689 else if (partial_seen && args[i].reg == 0) 1690 must_preallocate = 1; 1691 /* We preallocate in case there are bounds passed 1692 in the bounds table to have precomputed address 1693 for bounds association. */ 1694 else if (POINTER_BOUNDS_P (args[i].tree_value) 1695 && !args[i].reg) 1696 must_preallocate = 1; 1697 1698 if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode 1699 && (TREE_CODE (args[i].tree_value) == CALL_EXPR 1700 || TREE_CODE (args[i].tree_value) == TARGET_EXPR 1701 || TREE_CODE (args[i].tree_value) == COND_EXPR 1702 || TREE_ADDRESSABLE (TREE_TYPE (args[i].tree_value)))) 1703 copy_to_evaluate_size 1704 += int_size_in_bytes (TREE_TYPE (args[i].tree_value)); 1705 } 1706 1707 if (copy_to_evaluate_size * 2 >= args_size->constant 1708 && args_size->constant > 0) 1709 must_preallocate = 1; 1710 } 1711 return must_preallocate; 1712} 1713 1714/* If we preallocated stack space, compute the address of each argument 1715 and store it into the ARGS array. 1716 1717 We need not ensure it is a valid memory address here; it will be 1718 validized when it is used. 1719 1720 ARGBLOCK is an rtx for the address of the outgoing arguments. */ 1721 1722static void 1723compute_argument_addresses (struct arg_data *args, rtx argblock, int num_actuals) 1724{ 1725 if (argblock) 1726 { 1727 rtx arg_reg = argblock; 1728 int i, arg_offset = 0; 1729 1730 if (GET_CODE (argblock) == PLUS) 1731 arg_reg = XEXP (argblock, 0), arg_offset = INTVAL (XEXP (argblock, 1)); 1732 1733 for (i = 0; i < num_actuals; i++) 1734 { 1735 rtx offset = ARGS_SIZE_RTX (args[i].locate.offset); 1736 rtx slot_offset = ARGS_SIZE_RTX (args[i].locate.slot_offset); 1737 rtx addr; 1738 unsigned int align, boundary; 1739 unsigned int units_on_stack = 0; 1740 machine_mode partial_mode = VOIDmode; 1741 1742 /* Skip this parm if it will not be passed on the stack. */ 1743 if (! args[i].pass_on_stack 1744 && args[i].reg != 0 1745 && args[i].partial == 0) 1746 continue; 1747 1748 /* Pointer Bounds are never passed on the stack. */ 1749 if (POINTER_BOUNDS_P (args[i].tree_value)) 1750 continue; 1751 1752 if (CONST_INT_P (offset)) 1753 addr = plus_constant (Pmode, arg_reg, INTVAL (offset)); 1754 else 1755 addr = gen_rtx_PLUS (Pmode, arg_reg, offset); 1756 1757 addr = plus_constant (Pmode, addr, arg_offset); 1758 1759 if (args[i].partial != 0) 1760 { 1761 /* Only part of the parameter is being passed on the stack. 1762 Generate a simple memory reference of the correct size. */ 1763 units_on_stack = args[i].locate.size.constant; 1764 partial_mode = mode_for_size (units_on_stack * BITS_PER_UNIT, 1765 MODE_INT, 1); 1766 args[i].stack = gen_rtx_MEM (partial_mode, addr); 1767 set_mem_size (args[i].stack, units_on_stack); 1768 } 1769 else 1770 { 1771 args[i].stack = gen_rtx_MEM (args[i].mode, addr); 1772 set_mem_attributes (args[i].stack, 1773 TREE_TYPE (args[i].tree_value), 1); 1774 } 1775 align = BITS_PER_UNIT; 1776 boundary = args[i].locate.boundary; 1777 if (args[i].locate.where_pad != downward) 1778 align = boundary; 1779 else if (CONST_INT_P (offset)) 1780 { 1781 align = INTVAL (offset) * BITS_PER_UNIT | boundary; 1782 align = align & -align; 1783 } 1784 set_mem_align (args[i].stack, align); 1785 1786 if (CONST_INT_P (slot_offset)) 1787 addr = plus_constant (Pmode, arg_reg, INTVAL (slot_offset)); 1788 else 1789 addr = gen_rtx_PLUS (Pmode, arg_reg, slot_offset); 1790 1791 addr = plus_constant (Pmode, addr, arg_offset); 1792 1793 if (args[i].partial != 0) 1794 { 1795 /* Only part of the parameter is being passed on the stack. 1796 Generate a simple memory reference of the correct size. 1797 */ 1798 args[i].stack_slot = gen_rtx_MEM (partial_mode, addr); 1799 set_mem_size (args[i].stack_slot, units_on_stack); 1800 } 1801 else 1802 { 1803 args[i].stack_slot = gen_rtx_MEM (args[i].mode, addr); 1804 set_mem_attributes (args[i].stack_slot, 1805 TREE_TYPE (args[i].tree_value), 1); 1806 } 1807 set_mem_align (args[i].stack_slot, args[i].locate.boundary); 1808 1809 /* Function incoming arguments may overlap with sibling call 1810 outgoing arguments and we cannot allow reordering of reads 1811 from function arguments with stores to outgoing arguments 1812 of sibling calls. */ 1813 set_mem_alias_set (args[i].stack, 0); 1814 set_mem_alias_set (args[i].stack_slot, 0); 1815 } 1816 } 1817} 1818 1819/* Given a FNDECL and EXP, return an rtx suitable for use as a target address 1820 in a call instruction. 1821 1822 FNDECL is the tree node for the target function. For an indirect call 1823 FNDECL will be NULL_TREE. 1824 1825 ADDR is the operand 0 of CALL_EXPR for this call. */ 1826 1827static rtx 1828rtx_for_function_call (tree fndecl, tree addr) 1829{ 1830 rtx funexp; 1831 1832 /* Get the function to call, in the form of RTL. */ 1833 if (fndecl) 1834 { 1835 if (!TREE_USED (fndecl) && fndecl != current_function_decl) 1836 TREE_USED (fndecl) = 1; 1837 1838 /* Get a SYMBOL_REF rtx for the function address. */ 1839 funexp = XEXP (DECL_RTL (fndecl), 0); 1840 } 1841 else 1842 /* Generate an rtx (probably a pseudo-register) for the address. */ 1843 { 1844 push_temp_slots (); 1845 funexp = expand_normal (addr); 1846 pop_temp_slots (); /* FUNEXP can't be BLKmode. */ 1847 } 1848 return funexp; 1849} 1850 1851/* Internal state for internal_arg_pointer_based_exp and its helpers. */ 1852static struct 1853{ 1854 /* Last insn that has been scanned by internal_arg_pointer_based_exp_scan, 1855 or NULL_RTX if none has been scanned yet. */ 1856 rtx_insn *scan_start; 1857 /* Vector indexed by REGNO - FIRST_PSEUDO_REGISTER, recording if a pseudo is 1858 based on crtl->args.internal_arg_pointer. The element is NULL_RTX if the 1859 pseudo isn't based on it, a CONST_INT offset if the pseudo is based on it 1860 with fixed offset, or PC if this is with variable or unknown offset. */ 1861 vec<rtx> cache; 1862} internal_arg_pointer_exp_state; 1863 1864static rtx internal_arg_pointer_based_exp (const_rtx, bool); 1865 1866/* Helper function for internal_arg_pointer_based_exp. Scan insns in 1867 the tail call sequence, starting with first insn that hasn't been 1868 scanned yet, and note for each pseudo on the LHS whether it is based 1869 on crtl->args.internal_arg_pointer or not, and what offset from that 1870 that pointer it has. */ 1871 1872static void 1873internal_arg_pointer_based_exp_scan (void) 1874{ 1875 rtx_insn *insn, *scan_start = internal_arg_pointer_exp_state.scan_start; 1876 1877 if (scan_start == NULL_RTX) 1878 insn = get_insns (); 1879 else 1880 insn = NEXT_INSN (scan_start); 1881 1882 while (insn) 1883 { 1884 rtx set = single_set (insn); 1885 if (set && REG_P (SET_DEST (set)) && !HARD_REGISTER_P (SET_DEST (set))) 1886 { 1887 rtx val = NULL_RTX; 1888 unsigned int idx = REGNO (SET_DEST (set)) - FIRST_PSEUDO_REGISTER; 1889 /* Punt on pseudos set multiple times. */ 1890 if (idx < internal_arg_pointer_exp_state.cache.length () 1891 && (internal_arg_pointer_exp_state.cache[idx] 1892 != NULL_RTX)) 1893 val = pc_rtx; 1894 else 1895 val = internal_arg_pointer_based_exp (SET_SRC (set), false); 1896 if (val != NULL_RTX) 1897 { 1898 if (idx >= internal_arg_pointer_exp_state.cache.length ()) 1899 internal_arg_pointer_exp_state.cache 1900 .safe_grow_cleared (idx + 1); 1901 internal_arg_pointer_exp_state.cache[idx] = val; 1902 } 1903 } 1904 if (NEXT_INSN (insn) == NULL_RTX) 1905 scan_start = insn; 1906 insn = NEXT_INSN (insn); 1907 } 1908 1909 internal_arg_pointer_exp_state.scan_start = scan_start; 1910} 1911 1912/* Compute whether RTL is based on crtl->args.internal_arg_pointer. Return 1913 NULL_RTX if RTL isn't based on it, a CONST_INT offset if RTL is based on 1914 it with fixed offset, or PC if this is with variable or unknown offset. 1915 TOPLEVEL is true if the function is invoked at the topmost level. */ 1916 1917static rtx 1918internal_arg_pointer_based_exp (const_rtx rtl, bool toplevel) 1919{ 1920 if (CONSTANT_P (rtl)) 1921 return NULL_RTX; 1922 1923 if (rtl == crtl->args.internal_arg_pointer) 1924 return const0_rtx; 1925 1926 if (REG_P (rtl) && HARD_REGISTER_P (rtl)) 1927 return NULL_RTX; 1928 1929 if (GET_CODE (rtl) == PLUS && CONST_INT_P (XEXP (rtl, 1))) 1930 { 1931 rtx val = internal_arg_pointer_based_exp (XEXP (rtl, 0), toplevel); 1932 if (val == NULL_RTX || val == pc_rtx) 1933 return val; 1934 return plus_constant (Pmode, val, INTVAL (XEXP (rtl, 1))); 1935 } 1936 1937 /* When called at the topmost level, scan pseudo assignments in between the 1938 last scanned instruction in the tail call sequence and the latest insn 1939 in that sequence. */ 1940 if (toplevel) 1941 internal_arg_pointer_based_exp_scan (); 1942 1943 if (REG_P (rtl)) 1944 { 1945 unsigned int idx = REGNO (rtl) - FIRST_PSEUDO_REGISTER; 1946 if (idx < internal_arg_pointer_exp_state.cache.length ()) 1947 return internal_arg_pointer_exp_state.cache[idx]; 1948 1949 return NULL_RTX; 1950 } 1951 1952 subrtx_iterator::array_type array; 1953 FOR_EACH_SUBRTX (iter, array, rtl, NONCONST) 1954 { 1955 const_rtx x = *iter; 1956 if (REG_P (x) && internal_arg_pointer_based_exp (x, false) != NULL_RTX) 1957 return pc_rtx; 1958 if (MEM_P (x)) 1959 iter.skip_subrtxes (); 1960 } 1961 1962 return NULL_RTX; 1963} 1964 1965/* Return true if and only if SIZE storage units (usually bytes) 1966 starting from address ADDR overlap with already clobbered argument 1967 area. This function is used to determine if we should give up a 1968 sibcall. */ 1969 1970static bool 1971mem_overlaps_already_clobbered_arg_p (rtx addr, unsigned HOST_WIDE_INT size) 1972{ 1973 HOST_WIDE_INT i; 1974 rtx val; 1975 1976 if (bitmap_empty_p (stored_args_map)) 1977 return false; 1978 val = internal_arg_pointer_based_exp (addr, true); 1979 if (val == NULL_RTX) 1980 return false; 1981 else if (val == pc_rtx) 1982 return true; 1983 else 1984 i = INTVAL (val); 1985#ifdef STACK_GROWS_DOWNWARD 1986 i -= crtl->args.pretend_args_size; 1987#else 1988 i += crtl->args.pretend_args_size; 1989#endif 1990 1991#ifdef ARGS_GROW_DOWNWARD 1992 i = -i - size; 1993#endif 1994 if (size > 0) 1995 { 1996 unsigned HOST_WIDE_INT k; 1997 1998 for (k = 0; k < size; k++) 1999 if (i + k < SBITMAP_SIZE (stored_args_map) 2000 && bitmap_bit_p (stored_args_map, i + k)) 2001 return true; 2002 } 2003 2004 return false; 2005} 2006 2007/* Do the register loads required for any wholly-register parms or any 2008 parms which are passed both on the stack and in a register. Their 2009 expressions were already evaluated. 2010 2011 Mark all register-parms as living through the call, putting these USE 2012 insns in the CALL_INSN_FUNCTION_USAGE field. 2013 2014 When IS_SIBCALL, perform the check_sibcall_argument_overlap 2015 checking, setting *SIBCALL_FAILURE if appropriate. */ 2016 2017static void 2018load_register_parameters (struct arg_data *args, int num_actuals, 2019 rtx *call_fusage, int flags, int is_sibcall, 2020 int *sibcall_failure) 2021{ 2022 int i, j; 2023 2024 for (i = 0; i < num_actuals; i++) 2025 { 2026 rtx reg = ((flags & ECF_SIBCALL) 2027 ? args[i].tail_call_reg : args[i].reg); 2028 if (reg) 2029 { 2030 int partial = args[i].partial; 2031 int nregs; 2032 int size = 0; 2033 rtx_insn *before_arg = get_last_insn (); 2034 /* Set non-negative if we must move a word at a time, even if 2035 just one word (e.g, partial == 4 && mode == DFmode). Set 2036 to -1 if we just use a normal move insn. This value can be 2037 zero if the argument is a zero size structure. */ 2038 nregs = -1; 2039 if (GET_CODE (reg) == PARALLEL) 2040 ; 2041 else if (partial) 2042 { 2043 gcc_assert (partial % UNITS_PER_WORD == 0); 2044 nregs = partial / UNITS_PER_WORD; 2045 } 2046 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode) 2047 { 2048 size = int_size_in_bytes (TREE_TYPE (args[i].tree_value)); 2049 nregs = (size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD; 2050 } 2051 else 2052 size = GET_MODE_SIZE (args[i].mode); 2053 2054 /* Handle calls that pass values in multiple non-contiguous 2055 locations. The Irix 6 ABI has examples of this. */ 2056 2057 if (GET_CODE (reg) == PARALLEL) 2058 emit_group_move (reg, args[i].parallel_value); 2059 2060 /* If simple case, just do move. If normal partial, store_one_arg 2061 has already loaded the register for us. In all other cases, 2062 load the register(s) from memory. */ 2063 2064 else if (nregs == -1) 2065 { 2066 emit_move_insn (reg, args[i].value); 2067#ifdef BLOCK_REG_PADDING 2068 /* Handle case where we have a value that needs shifting 2069 up to the msb. eg. a QImode value and we're padding 2070 upward on a BYTES_BIG_ENDIAN machine. */ 2071 if (size < UNITS_PER_WORD 2072 && (args[i].locate.where_pad 2073 == (BYTES_BIG_ENDIAN ? upward : downward))) 2074 { 2075 rtx x; 2076 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT; 2077 2078 /* Assigning REG here rather than a temp makes CALL_FUSAGE 2079 report the whole reg as used. Strictly speaking, the 2080 call only uses SIZE bytes at the msb end, but it doesn't 2081 seem worth generating rtl to say that. */ 2082 reg = gen_rtx_REG (word_mode, REGNO (reg)); 2083 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1); 2084 if (x != reg) 2085 emit_move_insn (reg, x); 2086 } 2087#endif 2088 } 2089 2090 /* If we have pre-computed the values to put in the registers in 2091 the case of non-aligned structures, copy them in now. */ 2092 2093 else if (args[i].n_aligned_regs != 0) 2094 for (j = 0; j < args[i].n_aligned_regs; j++) 2095 emit_move_insn (gen_rtx_REG (word_mode, REGNO (reg) + j), 2096 args[i].aligned_regs[j]); 2097 2098 else if (partial == 0 || args[i].pass_on_stack) 2099 { 2100 rtx mem = validize_mem (copy_rtx (args[i].value)); 2101 2102 /* Check for overlap with already clobbered argument area, 2103 providing that this has non-zero size. */ 2104 if (is_sibcall 2105 && (size == 0 2106 || mem_overlaps_already_clobbered_arg_p 2107 (XEXP (args[i].value, 0), size))) 2108 *sibcall_failure = 1; 2109 2110 if (size % UNITS_PER_WORD == 0 2111 || MEM_ALIGN (mem) % BITS_PER_WORD == 0) 2112 move_block_to_reg (REGNO (reg), mem, nregs, args[i].mode); 2113 else 2114 { 2115 if (nregs > 1) 2116 move_block_to_reg (REGNO (reg), mem, nregs - 1, 2117 args[i].mode); 2118 rtx dest = gen_rtx_REG (word_mode, REGNO (reg) + nregs - 1); 2119 unsigned int bitoff = (nregs - 1) * BITS_PER_WORD; 2120 unsigned int bitsize = size * BITS_PER_UNIT - bitoff; 2121 rtx x = extract_bit_field (mem, bitsize, bitoff, 1, 2122 dest, word_mode, word_mode); 2123 if (BYTES_BIG_ENDIAN) 2124 x = expand_shift (LSHIFT_EXPR, word_mode, x, 2125 BITS_PER_WORD - bitsize, dest, 1); 2126 if (x != dest) 2127 emit_move_insn (dest, x); 2128 } 2129 2130 /* Handle a BLKmode that needs shifting. */ 2131 if (nregs == 1 && size < UNITS_PER_WORD 2132#ifdef BLOCK_REG_PADDING 2133 && args[i].locate.where_pad == downward 2134#else 2135 && BYTES_BIG_ENDIAN 2136#endif 2137 ) 2138 { 2139 rtx dest = gen_rtx_REG (word_mode, REGNO (reg)); 2140 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT; 2141 enum tree_code dir = (BYTES_BIG_ENDIAN 2142 ? RSHIFT_EXPR : LSHIFT_EXPR); 2143 rtx x; 2144 2145 x = expand_shift (dir, word_mode, dest, shift, dest, 1); 2146 if (x != dest) 2147 emit_move_insn (dest, x); 2148 } 2149 } 2150 2151 /* When a parameter is a block, and perhaps in other cases, it is 2152 possible that it did a load from an argument slot that was 2153 already clobbered. */ 2154 if (is_sibcall 2155 && check_sibcall_argument_overlap (before_arg, &args[i], 0)) 2156 *sibcall_failure = 1; 2157 2158 /* Handle calls that pass values in multiple non-contiguous 2159 locations. The Irix 6 ABI has examples of this. */ 2160 if (GET_CODE (reg) == PARALLEL) 2161 use_group_regs (call_fusage, reg); 2162 else if (nregs == -1) 2163 use_reg_mode (call_fusage, reg, 2164 TYPE_MODE (TREE_TYPE (args[i].tree_value))); 2165 else if (nregs > 0) 2166 use_regs (call_fusage, REGNO (reg), nregs); 2167 } 2168 } 2169} 2170 2171/* We need to pop PENDING_STACK_ADJUST bytes. But, if the arguments 2172 wouldn't fill up an even multiple of PREFERRED_UNIT_STACK_BOUNDARY 2173 bytes, then we would need to push some additional bytes to pad the 2174 arguments. So, we compute an adjust to the stack pointer for an 2175 amount that will leave the stack under-aligned by UNADJUSTED_ARGS_SIZE 2176 bytes. Then, when the arguments are pushed the stack will be perfectly 2177 aligned. ARGS_SIZE->CONSTANT is set to the number of bytes that should 2178 be popped after the call. Returns the adjustment. */ 2179 2180static int 2181combine_pending_stack_adjustment_and_call (int unadjusted_args_size, 2182 struct args_size *args_size, 2183 unsigned int preferred_unit_stack_boundary) 2184{ 2185 /* The number of bytes to pop so that the stack will be 2186 under-aligned by UNADJUSTED_ARGS_SIZE bytes. */ 2187 HOST_WIDE_INT adjustment; 2188 /* The alignment of the stack after the arguments are pushed, if we 2189 just pushed the arguments without adjust the stack here. */ 2190 unsigned HOST_WIDE_INT unadjusted_alignment; 2191 2192 unadjusted_alignment 2193 = ((stack_pointer_delta + unadjusted_args_size) 2194 % preferred_unit_stack_boundary); 2195 2196 /* We want to get rid of as many of the PENDING_STACK_ADJUST bytes 2197 as possible -- leaving just enough left to cancel out the 2198 UNADJUSTED_ALIGNMENT. In other words, we want to ensure that the 2199 PENDING_STACK_ADJUST is non-negative, and congruent to 2200 -UNADJUSTED_ALIGNMENT modulo the PREFERRED_UNIT_STACK_BOUNDARY. */ 2201 2202 /* Begin by trying to pop all the bytes. */ 2203 unadjusted_alignment 2204 = (unadjusted_alignment 2205 - (pending_stack_adjust % preferred_unit_stack_boundary)); 2206 adjustment = pending_stack_adjust; 2207 /* Push enough additional bytes that the stack will be aligned 2208 after the arguments are pushed. */ 2209 if (preferred_unit_stack_boundary > 1) 2210 { 2211 if (unadjusted_alignment > 0) 2212 adjustment -= preferred_unit_stack_boundary - unadjusted_alignment; 2213 else 2214 adjustment += unadjusted_alignment; 2215 } 2216 2217 /* Now, sets ARGS_SIZE->CONSTANT so that we pop the right number of 2218 bytes after the call. The right number is the entire 2219 PENDING_STACK_ADJUST less our ADJUSTMENT plus the amount required 2220 by the arguments in the first place. */ 2221 args_size->constant 2222 = pending_stack_adjust - adjustment + unadjusted_args_size; 2223 2224 return adjustment; 2225} 2226 2227/* Scan X expression if it does not dereference any argument slots 2228 we already clobbered by tail call arguments (as noted in stored_args_map 2229 bitmap). 2230 Return nonzero if X expression dereferences such argument slots, 2231 zero otherwise. */ 2232 2233static int 2234check_sibcall_argument_overlap_1 (rtx x) 2235{ 2236 RTX_CODE code; 2237 int i, j; 2238 const char *fmt; 2239 2240 if (x == NULL_RTX) 2241 return 0; 2242 2243 code = GET_CODE (x); 2244 2245 /* We need not check the operands of the CALL expression itself. */ 2246 if (code == CALL) 2247 return 0; 2248 2249 if (code == MEM) 2250 return mem_overlaps_already_clobbered_arg_p (XEXP (x, 0), 2251 GET_MODE_SIZE (GET_MODE (x))); 2252 2253 /* Scan all subexpressions. */ 2254 fmt = GET_RTX_FORMAT (code); 2255 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) 2256 { 2257 if (*fmt == 'e') 2258 { 2259 if (check_sibcall_argument_overlap_1 (XEXP (x, i))) 2260 return 1; 2261 } 2262 else if (*fmt == 'E') 2263 { 2264 for (j = 0; j < XVECLEN (x, i); j++) 2265 if (check_sibcall_argument_overlap_1 (XVECEXP (x, i, j))) 2266 return 1; 2267 } 2268 } 2269 return 0; 2270} 2271 2272/* Scan sequence after INSN if it does not dereference any argument slots 2273 we already clobbered by tail call arguments (as noted in stored_args_map 2274 bitmap). If MARK_STORED_ARGS_MAP, add stack slots for ARG to 2275 stored_args_map bitmap afterwards (when ARG is a register MARK_STORED_ARGS_MAP 2276 should be 0). Return nonzero if sequence after INSN dereferences such argument 2277 slots, zero otherwise. */ 2278 2279static int 2280check_sibcall_argument_overlap (rtx_insn *insn, struct arg_data *arg, 2281 int mark_stored_args_map) 2282{ 2283 int low, high; 2284 2285 if (insn == NULL_RTX) 2286 insn = get_insns (); 2287 else 2288 insn = NEXT_INSN (insn); 2289 2290 for (; insn; insn = NEXT_INSN (insn)) 2291 if (INSN_P (insn) 2292 && check_sibcall_argument_overlap_1 (PATTERN (insn))) 2293 break; 2294 2295 if (mark_stored_args_map) 2296 { 2297#ifdef ARGS_GROW_DOWNWARD 2298 low = -arg->locate.slot_offset.constant - arg->locate.size.constant; 2299#else 2300 low = arg->locate.slot_offset.constant; 2301#endif 2302 2303 for (high = low + arg->locate.size.constant; low < high; low++) 2304 bitmap_set_bit (stored_args_map, low); 2305 } 2306 return insn != NULL_RTX; 2307} 2308 2309/* Given that a function returns a value of mode MODE at the most 2310 significant end of hard register VALUE, shift VALUE left or right 2311 as specified by LEFT_P. Return true if some action was needed. */ 2312 2313bool 2314shift_return_value (machine_mode mode, bool left_p, rtx value) 2315{ 2316 HOST_WIDE_INT shift; 2317 2318 gcc_assert (REG_P (value) && HARD_REGISTER_P (value)); 2319 shift = GET_MODE_BITSIZE (GET_MODE (value)) - GET_MODE_BITSIZE (mode); 2320 if (shift == 0) 2321 return false; 2322 2323 /* Use ashr rather than lshr for right shifts. This is for the benefit 2324 of the MIPS port, which requires SImode values to be sign-extended 2325 when stored in 64-bit registers. */ 2326 if (!force_expand_binop (GET_MODE (value), left_p ? ashl_optab : ashr_optab, 2327 value, GEN_INT (shift), value, 1, OPTAB_WIDEN)) 2328 gcc_unreachable (); 2329 return true; 2330} 2331 2332/* If X is a likely-spilled register value, copy it to a pseudo 2333 register and return that register. Return X otherwise. */ 2334 2335static rtx 2336avoid_likely_spilled_reg (rtx x) 2337{ 2338 rtx new_rtx; 2339 2340 if (REG_P (x) 2341 && HARD_REGISTER_P (x) 2342 && targetm.class_likely_spilled_p (REGNO_REG_CLASS (REGNO (x)))) 2343 { 2344 /* Make sure that we generate a REG rather than a CONCAT. 2345 Moves into CONCATs can need nontrivial instructions, 2346 and the whole point of this function is to avoid 2347 using the hard register directly in such a situation. */ 2348 generating_concat_p = 0; 2349 new_rtx = gen_reg_rtx (GET_MODE (x)); 2350 generating_concat_p = 1; 2351 emit_move_insn (new_rtx, x); 2352 return new_rtx; 2353 } 2354 return x; 2355} 2356 2357/* Generate all the code for a CALL_EXPR exp 2358 and return an rtx for its value. 2359 Store the value in TARGET (specified as an rtx) if convenient. 2360 If the value is stored in TARGET then TARGET is returned. 2361 If IGNORE is nonzero, then we ignore the value of the function call. */ 2362 2363rtx 2364expand_call (tree exp, rtx target, int ignore) 2365{ 2366 /* Nonzero if we are currently expanding a call. */ 2367 static int currently_expanding_call = 0; 2368 2369 /* RTX for the function to be called. */ 2370 rtx funexp; 2371 /* Sequence of insns to perform a normal "call". */ 2372 rtx_insn *normal_call_insns = NULL; 2373 /* Sequence of insns to perform a tail "call". */ 2374 rtx_insn *tail_call_insns = NULL; 2375 /* Data type of the function. */ 2376 tree funtype; 2377 tree type_arg_types; 2378 tree rettype; 2379 /* Declaration of the function being called, 2380 or 0 if the function is computed (not known by name). */ 2381 tree fndecl = 0; 2382 /* The type of the function being called. */ 2383 tree fntype; 2384 bool try_tail_call = CALL_EXPR_TAILCALL (exp); 2385 int pass; 2386 2387 /* Register in which non-BLKmode value will be returned, 2388 or 0 if no value or if value is BLKmode. */ 2389 rtx valreg; 2390 /* Register(s) in which bounds are returned. */ 2391 rtx valbnd = NULL; 2392 /* Address where we should return a BLKmode value; 2393 0 if value not BLKmode. */ 2394 rtx structure_value_addr = 0; 2395 /* Nonzero if that address is being passed by treating it as 2396 an extra, implicit first parameter. Otherwise, 2397 it is passed by being copied directly into struct_value_rtx. */ 2398 int structure_value_addr_parm = 0; 2399 /* Holds the value of implicit argument for the struct value. */ 2400 tree structure_value_addr_value = NULL_TREE; 2401 /* Size of aggregate value wanted, or zero if none wanted 2402 or if we are using the non-reentrant PCC calling convention 2403 or expecting the value in registers. */ 2404 HOST_WIDE_INT struct_value_size = 0; 2405 /* Nonzero if called function returns an aggregate in memory PCC style, 2406 by returning the address of where to find it. */ 2407 int pcc_struct_value = 0; 2408 rtx struct_value = 0; 2409 2410 /* Number of actual parameters in this call, including struct value addr. */ 2411 int num_actuals; 2412 /* Number of named args. Args after this are anonymous ones 2413 and they must all go on the stack. */ 2414 int n_named_args; 2415 /* Number of complex actual arguments that need to be split. */ 2416 int num_complex_actuals = 0; 2417 2418 /* Vector of information about each argument. 2419 Arguments are numbered in the order they will be pushed, 2420 not the order they are written. */ 2421 struct arg_data *args; 2422 2423 /* Total size in bytes of all the stack-parms scanned so far. */ 2424 struct args_size args_size; 2425 struct args_size adjusted_args_size; 2426 /* Size of arguments before any adjustments (such as rounding). */ 2427 int unadjusted_args_size; 2428 /* Data on reg parms scanned so far. */ 2429 CUMULATIVE_ARGS args_so_far_v; 2430 cumulative_args_t args_so_far; 2431 /* Nonzero if a reg parm has been scanned. */ 2432 int reg_parm_seen; 2433 /* Nonzero if this is an indirect function call. */ 2434 2435 /* Nonzero if we must avoid push-insns in the args for this call. 2436 If stack space is allocated for register parameters, but not by the 2437 caller, then it is preallocated in the fixed part of the stack frame. 2438 So the entire argument block must then be preallocated (i.e., we 2439 ignore PUSH_ROUNDING in that case). */ 2440 2441 int must_preallocate = !PUSH_ARGS; 2442 2443 /* Size of the stack reserved for parameter registers. */ 2444 int reg_parm_stack_space = 0; 2445 2446 /* Address of space preallocated for stack parms 2447 (on machines that lack push insns), or 0 if space not preallocated. */ 2448 rtx argblock = 0; 2449 2450 /* Mask of ECF_ and ERF_ flags. */ 2451 int flags = 0; 2452 int return_flags = 0; 2453#ifdef REG_PARM_STACK_SPACE 2454 /* Define the boundary of the register parm stack space that needs to be 2455 saved, if any. */ 2456 int low_to_save, high_to_save; 2457 rtx save_area = 0; /* Place that it is saved */ 2458#endif 2459 2460 int initial_highest_arg_in_use = highest_outgoing_arg_in_use; 2461 char *initial_stack_usage_map = stack_usage_map; 2462 char *stack_usage_map_buf = NULL; 2463 2464 int old_stack_allocated; 2465 2466 /* State variables to track stack modifications. */ 2467 rtx old_stack_level = 0; 2468 int old_stack_arg_under_construction = 0; 2469 int old_pending_adj = 0; 2470 int old_inhibit_defer_pop = inhibit_defer_pop; 2471 2472 /* Some stack pointer alterations we make are performed via 2473 allocate_dynamic_stack_space. This modifies the stack_pointer_delta, 2474 which we then also need to save/restore along the way. */ 2475 int old_stack_pointer_delta = 0; 2476 2477 rtx call_fusage; 2478 tree addr = CALL_EXPR_FN (exp); 2479 int i; 2480 /* The alignment of the stack, in bits. */ 2481 unsigned HOST_WIDE_INT preferred_stack_boundary; 2482 /* The alignment of the stack, in bytes. */ 2483 unsigned HOST_WIDE_INT preferred_unit_stack_boundary; 2484 /* The static chain value to use for this call. */ 2485 rtx static_chain_value; 2486 /* See if this is "nothrow" function call. */ 2487 if (TREE_NOTHROW (exp)) 2488 flags |= ECF_NOTHROW; 2489 2490 /* See if we can find a DECL-node for the actual function, and get the 2491 function attributes (flags) from the function decl or type node. */ 2492 fndecl = get_callee_fndecl (exp); 2493 if (fndecl) 2494 { 2495 fntype = TREE_TYPE (fndecl); 2496 flags |= flags_from_decl_or_type (fndecl); 2497 return_flags |= decl_return_flags (fndecl); 2498 } 2499 else 2500 { 2501 fntype = TREE_TYPE (TREE_TYPE (addr)); 2502 flags |= flags_from_decl_or_type (fntype); 2503 } 2504 rettype = TREE_TYPE (exp); 2505 2506 struct_value = targetm.calls.struct_value_rtx (fntype, 0); 2507 2508 /* Warn if this value is an aggregate type, 2509 regardless of which calling convention we are using for it. */ 2510 if (AGGREGATE_TYPE_P (rettype)) 2511 warning (OPT_Waggregate_return, "function call has aggregate value"); 2512 2513 /* If the result of a non looping pure or const function call is 2514 ignored (or void), and none of its arguments are volatile, we can 2515 avoid expanding the call and just evaluate the arguments for 2516 side-effects. */ 2517 if ((flags & (ECF_CONST | ECF_PURE)) 2518 && (!(flags & ECF_LOOPING_CONST_OR_PURE)) 2519 && (ignore || target == const0_rtx 2520 || TYPE_MODE (rettype) == VOIDmode)) 2521 { 2522 bool volatilep = false; 2523 tree arg; 2524 call_expr_arg_iterator iter; 2525 2526 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) 2527 if (TREE_THIS_VOLATILE (arg)) 2528 { 2529 volatilep = true; 2530 break; 2531 } 2532 2533 if (! volatilep) 2534 { 2535 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) 2536 expand_expr (arg, const0_rtx, VOIDmode, EXPAND_NORMAL); 2537 return const0_rtx; 2538 } 2539 } 2540 2541#ifdef REG_PARM_STACK_SPACE 2542 reg_parm_stack_space = REG_PARM_STACK_SPACE (!fndecl ? fntype : fndecl); 2543#endif 2544 2545 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))) 2546 && reg_parm_stack_space > 0 && PUSH_ARGS) 2547 must_preallocate = 1; 2548 2549 /* Set up a place to return a structure. */ 2550 2551 /* Cater to broken compilers. */ 2552 if (aggregate_value_p (exp, fntype)) 2553 { 2554 /* This call returns a big structure. */ 2555 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE); 2556 2557#ifdef PCC_STATIC_STRUCT_RETURN 2558 { 2559 pcc_struct_value = 1; 2560 } 2561#else /* not PCC_STATIC_STRUCT_RETURN */ 2562 { 2563 struct_value_size = int_size_in_bytes (rettype); 2564 2565 /* Even if it is semantically safe to use the target as the return 2566 slot, it may be not sufficiently aligned for the return type. */ 2567 if (CALL_EXPR_RETURN_SLOT_OPT (exp) 2568 && target 2569 && MEM_P (target) 2570 && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype) 2571 && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype), 2572 MEM_ALIGN (target)))) 2573 structure_value_addr = XEXP (target, 0); 2574 else 2575 { 2576 /* For variable-sized objects, we must be called with a target 2577 specified. If we were to allocate space on the stack here, 2578 we would have no way of knowing when to free it. */ 2579 rtx d = assign_temp (rettype, 1, 1); 2580 structure_value_addr = XEXP (d, 0); 2581 target = 0; 2582 } 2583 } 2584#endif /* not PCC_STATIC_STRUCT_RETURN */ 2585 } 2586 2587 /* Figure out the amount to which the stack should be aligned. */ 2588 preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; 2589 if (fndecl) 2590 { 2591 struct cgraph_rtl_info *i = cgraph_node::rtl_info (fndecl); 2592 /* Without automatic stack alignment, we can't increase preferred 2593 stack boundary. With automatic stack alignment, it is 2594 unnecessary since unless we can guarantee that all callers will 2595 align the outgoing stack properly, callee has to align its 2596 stack anyway. */ 2597 if (i 2598 && i->preferred_incoming_stack_boundary 2599 && i->preferred_incoming_stack_boundary < preferred_stack_boundary) 2600 preferred_stack_boundary = i->preferred_incoming_stack_boundary; 2601 } 2602 2603 /* Operand 0 is a pointer-to-function; get the type of the function. */ 2604 funtype = TREE_TYPE (addr); 2605 gcc_assert (POINTER_TYPE_P (funtype)); 2606 funtype = TREE_TYPE (funtype); 2607 2608 /* Count whether there are actual complex arguments that need to be split 2609 into their real and imaginary parts. Munge the type_arg_types 2610 appropriately here as well. */ 2611 if (targetm.calls.split_complex_arg) 2612 { 2613 call_expr_arg_iterator iter; 2614 tree arg; 2615 FOR_EACH_CALL_EXPR_ARG (arg, iter, exp) 2616 { 2617 tree type = TREE_TYPE (arg); 2618 if (type && TREE_CODE (type) == COMPLEX_TYPE 2619 && targetm.calls.split_complex_arg (type)) 2620 num_complex_actuals++; 2621 } 2622 type_arg_types = split_complex_types (TYPE_ARG_TYPES (funtype)); 2623 } 2624 else 2625 type_arg_types = TYPE_ARG_TYPES (funtype); 2626 2627 if (flags & ECF_MAY_BE_ALLOCA) 2628 cfun->calls_alloca = 1; 2629 2630 /* If struct_value_rtx is 0, it means pass the address 2631 as if it were an extra parameter. Put the argument expression 2632 in structure_value_addr_value. */ 2633 if (structure_value_addr && struct_value == 0) 2634 { 2635 /* If structure_value_addr is a REG other than 2636 virtual_outgoing_args_rtx, we can use always use it. If it 2637 is not a REG, we must always copy it into a register. 2638 If it is virtual_outgoing_args_rtx, we must copy it to another 2639 register in some cases. */ 2640 rtx temp = (!REG_P (structure_value_addr) 2641 || (ACCUMULATE_OUTGOING_ARGS 2642 && stack_arg_under_construction 2643 && structure_value_addr == virtual_outgoing_args_rtx) 2644 ? copy_addr_to_reg (convert_memory_address 2645 (Pmode, structure_value_addr)) 2646 : structure_value_addr); 2647 2648 structure_value_addr_value = 2649 make_tree (build_pointer_type (TREE_TYPE (funtype)), temp); 2650 structure_value_addr_parm = CALL_WITH_BOUNDS_P (exp) ? 2 : 1; 2651 } 2652 2653 /* Count the arguments and set NUM_ACTUALS. */ 2654 num_actuals = 2655 call_expr_nargs (exp) + num_complex_actuals + structure_value_addr_parm; 2656 2657 /* Compute number of named args. 2658 First, do a raw count of the args for INIT_CUMULATIVE_ARGS. */ 2659 2660 if (type_arg_types != 0) 2661 n_named_args 2662 = (list_length (type_arg_types) 2663 /* Count the struct value address, if it is passed as a parm. */ 2664 + structure_value_addr_parm); 2665 else 2666 /* If we know nothing, treat all args as named. */ 2667 n_named_args = num_actuals; 2668 2669 /* Start updating where the next arg would go. 2670 2671 On some machines (such as the PA) indirect calls have a different 2672 calling convention than normal calls. The fourth argument in 2673 INIT_CUMULATIVE_ARGS tells the backend if this is an indirect call 2674 or not. */ 2675 INIT_CUMULATIVE_ARGS (args_so_far_v, funtype, NULL_RTX, fndecl, n_named_args); 2676 args_so_far = pack_cumulative_args (&args_so_far_v); 2677 2678 /* Now possibly adjust the number of named args. 2679 Normally, don't include the last named arg if anonymous args follow. 2680 We do include the last named arg if 2681 targetm.calls.strict_argument_naming() returns nonzero. 2682 (If no anonymous args follow, the result of list_length is actually 2683 one too large. This is harmless.) 2684 2685 If targetm.calls.pretend_outgoing_varargs_named() returns 2686 nonzero, and targetm.calls.strict_argument_naming() returns zero, 2687 this machine will be able to place unnamed args that were passed 2688 in registers into the stack. So treat all args as named. This 2689 allows the insns emitting for a specific argument list to be 2690 independent of the function declaration. 2691 2692 If targetm.calls.pretend_outgoing_varargs_named() returns zero, 2693 we do not have any reliable way to pass unnamed args in 2694 registers, so we must force them into memory. */ 2695 2696 if (type_arg_types != 0 2697 && targetm.calls.strict_argument_naming (args_so_far)) 2698 ; 2699 else if (type_arg_types != 0 2700 && ! targetm.calls.pretend_outgoing_varargs_named (args_so_far)) 2701 /* Don't include the last named arg. */ 2702 --n_named_args; 2703 else 2704 /* Treat all args as named. */ 2705 n_named_args = num_actuals; 2706 2707 /* Make a vector to hold all the information about each arg. */ 2708 args = XALLOCAVEC (struct arg_data, num_actuals); 2709 memset (args, 0, num_actuals * sizeof (struct arg_data)); 2710 2711 /* Build up entries in the ARGS array, compute the size of the 2712 arguments into ARGS_SIZE, etc. */ 2713 initialize_argument_information (num_actuals, args, &args_size, 2714 n_named_args, exp, 2715 structure_value_addr_value, fndecl, fntype, 2716 args_so_far, reg_parm_stack_space, 2717 &old_stack_level, &old_pending_adj, 2718 &must_preallocate, &flags, 2719 &try_tail_call, CALL_FROM_THUNK_P (exp)); 2720 2721 if (args_size.var) 2722 must_preallocate = 1; 2723 2724 /* Now make final decision about preallocating stack space. */ 2725 must_preallocate = finalize_must_preallocate (must_preallocate, 2726 num_actuals, args, 2727 &args_size); 2728 2729 /* If the structure value address will reference the stack pointer, we 2730 must stabilize it. We don't need to do this if we know that we are 2731 not going to adjust the stack pointer in processing this call. */ 2732 2733 if (structure_value_addr 2734 && (reg_mentioned_p (virtual_stack_dynamic_rtx, structure_value_addr) 2735 || reg_mentioned_p (virtual_outgoing_args_rtx, 2736 structure_value_addr)) 2737 && (args_size.var 2738 || (!ACCUMULATE_OUTGOING_ARGS && args_size.constant))) 2739 structure_value_addr = copy_to_reg (structure_value_addr); 2740 2741 /* Tail calls can make things harder to debug, and we've traditionally 2742 pushed these optimizations into -O2. Don't try if we're already 2743 expanding a call, as that means we're an argument. Don't try if 2744 there's cleanups, as we know there's code to follow the call. */ 2745 2746 if (currently_expanding_call++ != 0 2747 || !flag_optimize_sibling_calls 2748 || args_size.var 2749 || dbg_cnt (tail_call) == false) 2750 try_tail_call = 0; 2751 2752 /* Rest of purposes for tail call optimizations to fail. */ 2753 if ( 2754#ifdef HAVE_sibcall_epilogue 2755 !HAVE_sibcall_epilogue 2756#else 2757 1 2758#endif 2759 || !try_tail_call 2760 /* Doing sibling call optimization needs some work, since 2761 structure_value_addr can be allocated on the stack. 2762 It does not seem worth the effort since few optimizable 2763 sibling calls will return a structure. */ 2764 || structure_value_addr != NULL_RTX 2765#ifdef REG_PARM_STACK_SPACE 2766 /* If outgoing reg parm stack space changes, we can not do sibcall. */ 2767 || (OUTGOING_REG_PARM_STACK_SPACE (funtype) 2768 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl))) 2769 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl)) 2770#endif 2771 /* Check whether the target is able to optimize the call 2772 into a sibcall. */ 2773 || !targetm.function_ok_for_sibcall (fndecl, exp) 2774 /* Functions that do not return exactly once may not be sibcall 2775 optimized. */ 2776 || (flags & (ECF_RETURNS_TWICE | ECF_NORETURN)) 2777 || TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (addr))) 2778 /* If the called function is nested in the current one, it might access 2779 some of the caller's arguments, but could clobber them beforehand if 2780 the argument areas are shared. */ 2781 || (fndecl && decl_function_context (fndecl) == current_function_decl) 2782 /* If this function requires more stack slots than the current 2783 function, we cannot change it into a sibling call. 2784 crtl->args.pretend_args_size is not part of the 2785 stack allocated by our caller. */ 2786 || args_size.constant > (crtl->args.size 2787 - crtl->args.pretend_args_size) 2788 /* If the callee pops its own arguments, then it must pop exactly 2789 the same number of arguments as the current function. */ 2790 || (targetm.calls.return_pops_args (fndecl, funtype, args_size.constant) 2791 != targetm.calls.return_pops_args (current_function_decl, 2792 TREE_TYPE (current_function_decl), 2793 crtl->args.size)) 2794 || !lang_hooks.decls.ok_for_sibcall (fndecl)) 2795 try_tail_call = 0; 2796 2797 /* Check if caller and callee disagree in promotion of function 2798 return value. */ 2799 if (try_tail_call) 2800 { 2801 machine_mode caller_mode, caller_promoted_mode; 2802 machine_mode callee_mode, callee_promoted_mode; 2803 int caller_unsignedp, callee_unsignedp; 2804 tree caller_res = DECL_RESULT (current_function_decl); 2805 2806 caller_unsignedp = TYPE_UNSIGNED (TREE_TYPE (caller_res)); 2807 caller_mode = DECL_MODE (caller_res); 2808 callee_unsignedp = TYPE_UNSIGNED (TREE_TYPE (funtype)); 2809 callee_mode = TYPE_MODE (TREE_TYPE (funtype)); 2810 caller_promoted_mode 2811 = promote_function_mode (TREE_TYPE (caller_res), caller_mode, 2812 &caller_unsignedp, 2813 TREE_TYPE (current_function_decl), 1); 2814 callee_promoted_mode 2815 = promote_function_mode (TREE_TYPE (funtype), callee_mode, 2816 &callee_unsignedp, 2817 funtype, 1); 2818 if (caller_mode != VOIDmode 2819 && (caller_promoted_mode != callee_promoted_mode 2820 || ((caller_mode != caller_promoted_mode 2821 || callee_mode != callee_promoted_mode) 2822 && (caller_unsignedp != callee_unsignedp 2823 || GET_MODE_BITSIZE (caller_mode) 2824 < GET_MODE_BITSIZE (callee_mode))))) 2825 try_tail_call = 0; 2826 } 2827 2828 /* Ensure current function's preferred stack boundary is at least 2829 what we need. Stack alignment may also increase preferred stack 2830 boundary. */ 2831 if (crtl->preferred_stack_boundary < preferred_stack_boundary) 2832 crtl->preferred_stack_boundary = preferred_stack_boundary; 2833 else 2834 preferred_stack_boundary = crtl->preferred_stack_boundary; 2835 2836 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT; 2837 2838 /* We want to make two insn chains; one for a sibling call, the other 2839 for a normal call. We will select one of the two chains after 2840 initial RTL generation is complete. */ 2841 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++) 2842 { 2843 int sibcall_failure = 0; 2844 /* We want to emit any pending stack adjustments before the tail 2845 recursion "call". That way we know any adjustment after the tail 2846 recursion call can be ignored if we indeed use the tail 2847 call expansion. */ 2848 saved_pending_stack_adjust save; 2849 rtx_insn *insns, *before_call, *after_args; 2850 rtx next_arg_reg; 2851 2852 if (pass == 0) 2853 { 2854 /* State variables we need to save and restore between 2855 iterations. */ 2856 save_pending_stack_adjust (&save); 2857 } 2858 if (pass) 2859 flags &= ~ECF_SIBCALL; 2860 else 2861 flags |= ECF_SIBCALL; 2862 2863 /* Other state variables that we must reinitialize each time 2864 through the loop (that are not initialized by the loop itself). */ 2865 argblock = 0; 2866 call_fusage = 0; 2867 2868 /* Start a new sequence for the normal call case. 2869 2870 From this point on, if the sibling call fails, we want to set 2871 sibcall_failure instead of continuing the loop. */ 2872 start_sequence (); 2873 2874 /* Don't let pending stack adjusts add up to too much. 2875 Also, do all pending adjustments now if there is any chance 2876 this might be a call to alloca or if we are expanding a sibling 2877 call sequence. 2878 Also do the adjustments before a throwing call, otherwise 2879 exception handling can fail; PR 19225. */ 2880 if (pending_stack_adjust >= 32 2881 || (pending_stack_adjust > 0 2882 && (flags & ECF_MAY_BE_ALLOCA)) 2883 || (pending_stack_adjust > 0 2884 && flag_exceptions && !(flags & ECF_NOTHROW)) 2885 || pass == 0) 2886 do_pending_stack_adjust (); 2887 2888 /* Precompute any arguments as needed. */ 2889 if (pass) 2890 precompute_arguments (num_actuals, args); 2891 2892 /* Now we are about to start emitting insns that can be deleted 2893 if a libcall is deleted. */ 2894 if (pass && (flags & ECF_MALLOC)) 2895 start_sequence (); 2896 2897 if (pass == 0 && crtl->stack_protect_guard) 2898 stack_protect_epilogue (); 2899 2900 adjusted_args_size = args_size; 2901 /* Compute the actual size of the argument block required. The variable 2902 and constant sizes must be combined, the size may have to be rounded, 2903 and there may be a minimum required size. When generating a sibcall 2904 pattern, do not round up, since we'll be re-using whatever space our 2905 caller provided. */ 2906 unadjusted_args_size 2907 = compute_argument_block_size (reg_parm_stack_space, 2908 &adjusted_args_size, 2909 fndecl, fntype, 2910 (pass == 0 ? 0 2911 : preferred_stack_boundary)); 2912 2913 old_stack_allocated = stack_pointer_delta - pending_stack_adjust; 2914 2915 /* The argument block when performing a sibling call is the 2916 incoming argument block. */ 2917 if (pass == 0) 2918 { 2919 argblock = crtl->args.internal_arg_pointer; 2920 argblock 2921#ifdef STACK_GROWS_DOWNWARD 2922 = plus_constant (Pmode, argblock, crtl->args.pretend_args_size); 2923#else 2924 = plus_constant (Pmode, argblock, -crtl->args.pretend_args_size); 2925#endif 2926 stored_args_map = sbitmap_alloc (args_size.constant); 2927 bitmap_clear (stored_args_map); 2928 } 2929 2930 /* If we have no actual push instructions, or shouldn't use them, 2931 make space for all args right now. */ 2932 else if (adjusted_args_size.var != 0) 2933 { 2934 if (old_stack_level == 0) 2935 { 2936 emit_stack_save (SAVE_BLOCK, &old_stack_level); 2937 old_stack_pointer_delta = stack_pointer_delta; 2938 old_pending_adj = pending_stack_adjust; 2939 pending_stack_adjust = 0; 2940 /* stack_arg_under_construction says whether a stack arg is 2941 being constructed at the old stack level. Pushing the stack 2942 gets a clean outgoing argument block. */ 2943 old_stack_arg_under_construction = stack_arg_under_construction; 2944 stack_arg_under_construction = 0; 2945 } 2946 argblock = push_block (ARGS_SIZE_RTX (adjusted_args_size), 0, 0); 2947 if (flag_stack_usage_info) 2948 current_function_has_unbounded_dynamic_stack_size = 1; 2949 } 2950 else 2951 { 2952 /* Note that we must go through the motions of allocating an argument 2953 block even if the size is zero because we may be storing args 2954 in the area reserved for register arguments, which may be part of 2955 the stack frame. */ 2956 2957 int needed = adjusted_args_size.constant; 2958 2959 /* Store the maximum argument space used. It will be pushed by 2960 the prologue (if ACCUMULATE_OUTGOING_ARGS, or stack overflow 2961 checking). */ 2962 2963 if (needed > crtl->outgoing_args_size) 2964 crtl->outgoing_args_size = needed; 2965 2966 if (must_preallocate) 2967 { 2968 if (ACCUMULATE_OUTGOING_ARGS) 2969 { 2970 /* Since the stack pointer will never be pushed, it is 2971 possible for the evaluation of a parm to clobber 2972 something we have already written to the stack. 2973 Since most function calls on RISC machines do not use 2974 the stack, this is uncommon, but must work correctly. 2975 2976 Therefore, we save any area of the stack that was already 2977 written and that we are using. Here we set up to do this 2978 by making a new stack usage map from the old one. The 2979 actual save will be done by store_one_arg. 2980 2981 Another approach might be to try to reorder the argument 2982 evaluations to avoid this conflicting stack usage. */ 2983 2984 /* Since we will be writing into the entire argument area, 2985 the map must be allocated for its entire size, not just 2986 the part that is the responsibility of the caller. */ 2987 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) 2988 needed += reg_parm_stack_space; 2989 2990#ifdef ARGS_GROW_DOWNWARD 2991 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, 2992 needed + 1); 2993#else 2994 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, 2995 needed); 2996#endif 2997 free (stack_usage_map_buf); 2998 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use); 2999 stack_usage_map = stack_usage_map_buf; 3000 3001 if (initial_highest_arg_in_use) 3002 memcpy (stack_usage_map, initial_stack_usage_map, 3003 initial_highest_arg_in_use); 3004 3005 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use) 3006 memset (&stack_usage_map[initial_highest_arg_in_use], 0, 3007 (highest_outgoing_arg_in_use 3008 - initial_highest_arg_in_use)); 3009 needed = 0; 3010 3011 /* The address of the outgoing argument list must not be 3012 copied to a register here, because argblock would be left 3013 pointing to the wrong place after the call to 3014 allocate_dynamic_stack_space below. */ 3015 3016 argblock = virtual_outgoing_args_rtx; 3017 } 3018 else 3019 { 3020 if (inhibit_defer_pop == 0) 3021 { 3022 /* Try to reuse some or all of the pending_stack_adjust 3023 to get this space. */ 3024 needed 3025 = (combine_pending_stack_adjustment_and_call 3026 (unadjusted_args_size, 3027 &adjusted_args_size, 3028 preferred_unit_stack_boundary)); 3029 3030 /* combine_pending_stack_adjustment_and_call computes 3031 an adjustment before the arguments are allocated. 3032 Account for them and see whether or not the stack 3033 needs to go up or down. */ 3034 needed = unadjusted_args_size - needed; 3035 3036 if (needed < 0) 3037 { 3038 /* We're releasing stack space. */ 3039 /* ??? We can avoid any adjustment at all if we're 3040 already aligned. FIXME. */ 3041 pending_stack_adjust = -needed; 3042 do_pending_stack_adjust (); 3043 needed = 0; 3044 } 3045 else 3046 /* We need to allocate space. We'll do that in 3047 push_block below. */ 3048 pending_stack_adjust = 0; 3049 } 3050 3051 /* Special case this because overhead of `push_block' in 3052 this case is non-trivial. */ 3053 if (needed == 0) 3054 argblock = virtual_outgoing_args_rtx; 3055 else 3056 { 3057 argblock = push_block (GEN_INT (needed), 0, 0); 3058#ifdef ARGS_GROW_DOWNWARD 3059 argblock = plus_constant (Pmode, argblock, needed); 3060#endif 3061 } 3062 3063 /* We only really need to call `copy_to_reg' in the case 3064 where push insns are going to be used to pass ARGBLOCK 3065 to a function call in ARGS. In that case, the stack 3066 pointer changes value from the allocation point to the 3067 call point, and hence the value of 3068 VIRTUAL_OUTGOING_ARGS_RTX changes as well. But might 3069 as well always do it. */ 3070 argblock = copy_to_reg (argblock); 3071 } 3072 } 3073 } 3074 3075 if (ACCUMULATE_OUTGOING_ARGS) 3076 { 3077 /* The save/restore code in store_one_arg handles all 3078 cases except one: a constructor call (including a C 3079 function returning a BLKmode struct) to initialize 3080 an argument. */ 3081 if (stack_arg_under_construction) 3082 { 3083 rtx push_size 3084 = GEN_INT (adjusted_args_size.constant 3085 + (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype 3086 : TREE_TYPE (fndecl))) ? 0 3087 : reg_parm_stack_space)); 3088 if (old_stack_level == 0) 3089 { 3090 emit_stack_save (SAVE_BLOCK, &old_stack_level); 3091 old_stack_pointer_delta = stack_pointer_delta; 3092 old_pending_adj = pending_stack_adjust; 3093 pending_stack_adjust = 0; 3094 /* stack_arg_under_construction says whether a stack 3095 arg is being constructed at the old stack level. 3096 Pushing the stack gets a clean outgoing argument 3097 block. */ 3098 old_stack_arg_under_construction 3099 = stack_arg_under_construction; 3100 stack_arg_under_construction = 0; 3101 /* Make a new map for the new argument list. */ 3102 free (stack_usage_map_buf); 3103 stack_usage_map_buf = XCNEWVEC (char, highest_outgoing_arg_in_use); 3104 stack_usage_map = stack_usage_map_buf; 3105 highest_outgoing_arg_in_use = 0; 3106 } 3107 /* We can pass TRUE as the 4th argument because we just 3108 saved the stack pointer and will restore it right after 3109 the call. */ 3110 allocate_dynamic_stack_space (push_size, 0, 3111 BIGGEST_ALIGNMENT, true); 3112 } 3113 3114 /* If argument evaluation might modify the stack pointer, 3115 copy the address of the argument list to a register. */ 3116 for (i = 0; i < num_actuals; i++) 3117 if (args[i].pass_on_stack) 3118 { 3119 argblock = copy_addr_to_reg (argblock); 3120 break; 3121 } 3122 } 3123 3124 compute_argument_addresses (args, argblock, num_actuals); 3125 3126 /* Stack is properly aligned, pops can't safely be deferred during 3127 the evaluation of the arguments. */ 3128 NO_DEFER_POP; 3129 3130 /* Precompute all register parameters. It isn't safe to compute 3131 anything once we have started filling any specific hard regs. 3132 TLS symbols sometimes need a call to resolve. Precompute 3133 register parameters before any stack pointer manipulation 3134 to avoid unaligned stack in the called function. */ 3135 precompute_register_parameters (num_actuals, args, ®_parm_seen); 3136 3137 OK_DEFER_POP; 3138 3139 /* Perform stack alignment before the first push (the last arg). */ 3140 if (argblock == 0 3141 && adjusted_args_size.constant > reg_parm_stack_space 3142 && adjusted_args_size.constant != unadjusted_args_size) 3143 { 3144 /* When the stack adjustment is pending, we get better code 3145 by combining the adjustments. */ 3146 if (pending_stack_adjust 3147 && ! inhibit_defer_pop) 3148 { 3149 pending_stack_adjust 3150 = (combine_pending_stack_adjustment_and_call 3151 (unadjusted_args_size, 3152 &adjusted_args_size, 3153 preferred_unit_stack_boundary)); 3154 do_pending_stack_adjust (); 3155 } 3156 else if (argblock == 0) 3157 anti_adjust_stack (GEN_INT (adjusted_args_size.constant 3158 - unadjusted_args_size)); 3159 } 3160 /* Now that the stack is properly aligned, pops can't safely 3161 be deferred during the evaluation of the arguments. */ 3162 NO_DEFER_POP; 3163 3164 /* Record the maximum pushed stack space size. We need to delay 3165 doing it this far to take into account the optimization done 3166 by combine_pending_stack_adjustment_and_call. */ 3167 if (flag_stack_usage_info 3168 && !ACCUMULATE_OUTGOING_ARGS 3169 && pass 3170 && adjusted_args_size.var == 0) 3171 { 3172 int pushed = adjusted_args_size.constant + pending_stack_adjust; 3173 if (pushed > current_function_pushed_stack_size) 3174 current_function_pushed_stack_size = pushed; 3175 } 3176 3177 funexp = rtx_for_function_call (fndecl, addr); 3178 3179 if (CALL_EXPR_STATIC_CHAIN (exp)) 3180 static_chain_value = expand_normal (CALL_EXPR_STATIC_CHAIN (exp)); 3181 else 3182 static_chain_value = 0; 3183 3184#ifdef REG_PARM_STACK_SPACE 3185 /* Save the fixed argument area if it's part of the caller's frame and 3186 is clobbered by argument setup for this call. */ 3187 if (ACCUMULATE_OUTGOING_ARGS && pass) 3188 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock, 3189 &low_to_save, &high_to_save); 3190#endif 3191 3192 /* Now store (and compute if necessary) all non-register parms. 3193 These come before register parms, since they can require block-moves, 3194 which could clobber the registers used for register parms. 3195 Parms which have partial registers are not stored here, 3196 but we do preallocate space here if they want that. */ 3197 3198 for (i = 0; i < num_actuals; i++) 3199 { 3200 /* Delay bounds until all other args are stored. */ 3201 if (POINTER_BOUNDS_P (args[i].tree_value)) 3202 continue; 3203 else if (args[i].reg == 0 || args[i].pass_on_stack) 3204 { 3205 rtx_insn *before_arg = get_last_insn (); 3206 3207 /* We don't allow passing huge (> 2^30 B) arguments 3208 by value. It would cause an overflow later on. */ 3209 if (adjusted_args_size.constant 3210 >= (1 << (HOST_BITS_PER_INT - 2))) 3211 { 3212 sorry ("passing too large argument on stack"); 3213 continue; 3214 } 3215 3216 if (store_one_arg (&args[i], argblock, flags, 3217 adjusted_args_size.var != 0, 3218 reg_parm_stack_space) 3219 || (pass == 0 3220 && check_sibcall_argument_overlap (before_arg, 3221 &args[i], 1))) 3222 sibcall_failure = 1; 3223 } 3224 3225 if (args[i].stack) 3226 call_fusage 3227 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[i].tree_value)), 3228 gen_rtx_USE (VOIDmode, args[i].stack), 3229 call_fusage); 3230 } 3231 3232 /* If we have a parm that is passed in registers but not in memory 3233 and whose alignment does not permit a direct copy into registers, 3234 make a group of pseudos that correspond to each register that we 3235 will later fill. */ 3236 if (STRICT_ALIGNMENT) 3237 store_unaligned_arguments_into_pseudos (args, num_actuals); 3238 3239 /* Now store any partially-in-registers parm. 3240 This is the last place a block-move can happen. */ 3241 if (reg_parm_seen) 3242 for (i = 0; i < num_actuals; i++) 3243 if (args[i].partial != 0 && ! args[i].pass_on_stack) 3244 { 3245 rtx_insn *before_arg = get_last_insn (); 3246 3247 if (store_one_arg (&args[i], argblock, flags, 3248 adjusted_args_size.var != 0, 3249 reg_parm_stack_space) 3250 || (pass == 0 3251 && check_sibcall_argument_overlap (before_arg, 3252 &args[i], 1))) 3253 sibcall_failure = 1; 3254 } 3255 3256 bool any_regs = false; 3257 for (i = 0; i < num_actuals; i++) 3258 if (args[i].reg != NULL_RTX) 3259 { 3260 any_regs = true; 3261 targetm.calls.call_args (args[i].reg, funtype); 3262 } 3263 if (!any_regs) 3264 targetm.calls.call_args (pc_rtx, funtype); 3265 3266 /* Figure out the register where the value, if any, will come back. */ 3267 valreg = 0; 3268 valbnd = 0; 3269 if (TYPE_MODE (rettype) != VOIDmode 3270 && ! structure_value_addr) 3271 { 3272 if (pcc_struct_value) 3273 { 3274 valreg = hard_function_value (build_pointer_type (rettype), 3275 fndecl, NULL, (pass == 0)); 3276 if (CALL_WITH_BOUNDS_P (exp)) 3277 valbnd = targetm.calls. 3278 chkp_function_value_bounds (build_pointer_type (rettype), 3279 fndecl, (pass == 0)); 3280 } 3281 else 3282 { 3283 valreg = hard_function_value (rettype, fndecl, fntype, 3284 (pass == 0)); 3285 if (CALL_WITH_BOUNDS_P (exp)) 3286 valbnd = targetm.calls.chkp_function_value_bounds (rettype, 3287 fndecl, 3288 (pass == 0)); 3289 } 3290 3291 /* If VALREG is a PARALLEL whose first member has a zero 3292 offset, use that. This is for targets such as m68k that 3293 return the same value in multiple places. */ 3294 if (GET_CODE (valreg) == PARALLEL) 3295 { 3296 rtx elem = XVECEXP (valreg, 0, 0); 3297 rtx where = XEXP (elem, 0); 3298 rtx offset = XEXP (elem, 1); 3299 if (offset == const0_rtx 3300 && GET_MODE (where) == GET_MODE (valreg)) 3301 valreg = where; 3302 } 3303 } 3304 3305 /* Store all bounds not passed in registers. */ 3306 for (i = 0; i < num_actuals; i++) 3307 { 3308 if (POINTER_BOUNDS_P (args[i].tree_value) 3309 && !args[i].reg) 3310 store_bounds (&args[i], 3311 args[i].pointer_arg == -1 3312 ? NULL 3313 : &args[args[i].pointer_arg]); 3314 } 3315 3316 /* If register arguments require space on the stack and stack space 3317 was not preallocated, allocate stack space here for arguments 3318 passed in registers. */ 3319 if (OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl))) 3320 && !ACCUMULATE_OUTGOING_ARGS 3321 && must_preallocate == 0 && reg_parm_stack_space > 0) 3322 anti_adjust_stack (GEN_INT (reg_parm_stack_space)); 3323 3324 /* Pass the function the address in which to return a 3325 structure value. */ 3326 if (pass != 0 && structure_value_addr && ! structure_value_addr_parm) 3327 { 3328 structure_value_addr 3329 = convert_memory_address (Pmode, structure_value_addr); 3330 emit_move_insn (struct_value, 3331 force_reg (Pmode, 3332 force_operand (structure_value_addr, 3333 NULL_RTX))); 3334 3335 if (REG_P (struct_value)) 3336 use_reg (&call_fusage, struct_value); 3337 } 3338 3339 after_args = get_last_insn (); 3340 funexp = prepare_call_address (fndecl ? fndecl : fntype, funexp, 3341 static_chain_value, &call_fusage, 3342 reg_parm_seen, pass == 0); 3343 3344 load_register_parameters (args, num_actuals, &call_fusage, flags, 3345 pass == 0, &sibcall_failure); 3346 3347 /* Save a pointer to the last insn before the call, so that we can 3348 later safely search backwards to find the CALL_INSN. */ 3349 before_call = get_last_insn (); 3350 3351 /* Set up next argument register. For sibling calls on machines 3352 with register windows this should be the incoming register. */ 3353 if (pass == 0) 3354 next_arg_reg = targetm.calls.function_incoming_arg (args_so_far, 3355 VOIDmode, 3356 void_type_node, 3357 true); 3358 else 3359 next_arg_reg = targetm.calls.function_arg (args_so_far, 3360 VOIDmode, void_type_node, 3361 true); 3362 3363 if (pass == 1 && (return_flags & ERF_RETURNS_ARG)) 3364 { 3365 int arg_nr = return_flags & ERF_RETURN_ARG_MASK; 3366 arg_nr = num_actuals - arg_nr - 1; 3367 if (arg_nr >= 0 3368 && arg_nr < num_actuals 3369 && args[arg_nr].reg 3370 && valreg 3371 && REG_P (valreg) 3372 && GET_MODE (args[arg_nr].reg) == GET_MODE (valreg)) 3373 call_fusage 3374 = gen_rtx_EXPR_LIST (TYPE_MODE (TREE_TYPE (args[arg_nr].tree_value)), 3375 gen_rtx_SET (VOIDmode, valreg, args[arg_nr].reg), 3376 call_fusage); 3377 } 3378 /* All arguments and registers used for the call must be set up by 3379 now! */ 3380 3381 /* Stack must be properly aligned now. */ 3382 gcc_assert (!pass 3383 || !(stack_pointer_delta % preferred_unit_stack_boundary)); 3384 3385 /* Generate the actual call instruction. */ 3386 emit_call_1 (funexp, exp, fndecl, funtype, unadjusted_args_size, 3387 adjusted_args_size.constant, struct_value_size, 3388 next_arg_reg, valreg, old_inhibit_defer_pop, call_fusage, 3389 flags, args_so_far); 3390 3391 if (flag_ipa_ra) 3392 { 3393 rtx_call_insn *last; 3394 rtx datum = NULL_RTX; 3395 if (fndecl != NULL_TREE) 3396 { 3397 datum = XEXP (DECL_RTL (fndecl), 0); 3398 gcc_assert (datum != NULL_RTX 3399 && GET_CODE (datum) == SYMBOL_REF); 3400 } 3401 last = last_call_insn (); 3402 add_reg_note (last, REG_CALL_DECL, datum); 3403 } 3404 3405 /* If the call setup or the call itself overlaps with anything 3406 of the argument setup we probably clobbered our call address. 3407 In that case we can't do sibcalls. */ 3408 if (pass == 0 3409 && check_sibcall_argument_overlap (after_args, 0, 0)) 3410 sibcall_failure = 1; 3411 3412 /* If a non-BLKmode value is returned at the most significant end 3413 of a register, shift the register right by the appropriate amount 3414 and update VALREG accordingly. BLKmode values are handled by the 3415 group load/store machinery below. */ 3416 if (!structure_value_addr 3417 && !pcc_struct_value 3418 && TYPE_MODE (rettype) != VOIDmode 3419 && TYPE_MODE (rettype) != BLKmode 3420 && REG_P (valreg) 3421 && targetm.calls.return_in_msb (rettype)) 3422 { 3423 if (shift_return_value (TYPE_MODE (rettype), false, valreg)) 3424 sibcall_failure = 1; 3425 valreg = gen_rtx_REG (TYPE_MODE (rettype), REGNO (valreg)); 3426 } 3427 3428 if (pass && (flags & ECF_MALLOC)) 3429 { 3430 rtx temp = gen_reg_rtx (GET_MODE (valreg)); 3431 rtx_insn *last, *insns; 3432 3433 /* The return value from a malloc-like function is a pointer. */ 3434 if (TREE_CODE (rettype) == POINTER_TYPE) 3435 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT); 3436 3437 emit_move_insn (temp, valreg); 3438 3439 /* The return value from a malloc-like function can not alias 3440 anything else. */ 3441 last = get_last_insn (); 3442 add_reg_note (last, REG_NOALIAS, temp); 3443 3444 /* Write out the sequence. */ 3445 insns = get_insns (); 3446 end_sequence (); 3447 emit_insn (insns); 3448 valreg = temp; 3449 } 3450 3451 /* For calls to `setjmp', etc., inform 3452 function.c:setjmp_warnings that it should complain if 3453 nonvolatile values are live. For functions that cannot 3454 return, inform flow that control does not fall through. */ 3455 3456 if ((flags & ECF_NORETURN) || pass == 0) 3457 { 3458 /* The barrier must be emitted 3459 immediately after the CALL_INSN. Some ports emit more 3460 than just a CALL_INSN above, so we must search for it here. */ 3461 3462 rtx_insn *last = get_last_insn (); 3463 while (!CALL_P (last)) 3464 { 3465 last = PREV_INSN (last); 3466 /* There was no CALL_INSN? */ 3467 gcc_assert (last != before_call); 3468 } 3469 3470 emit_barrier_after (last); 3471 3472 /* Stack adjustments after a noreturn call are dead code. 3473 However when NO_DEFER_POP is in effect, we must preserve 3474 stack_pointer_delta. */ 3475 if (inhibit_defer_pop == 0) 3476 { 3477 stack_pointer_delta = old_stack_allocated; 3478 pending_stack_adjust = 0; 3479 } 3480 } 3481 3482 /* If value type not void, return an rtx for the value. */ 3483 3484 if (TYPE_MODE (rettype) == VOIDmode 3485 || ignore) 3486 target = const0_rtx; 3487 else if (structure_value_addr) 3488 { 3489 if (target == 0 || !MEM_P (target)) 3490 { 3491 target 3492 = gen_rtx_MEM (TYPE_MODE (rettype), 3493 memory_address (TYPE_MODE (rettype), 3494 structure_value_addr)); 3495 set_mem_attributes (target, rettype, 1); 3496 } 3497 } 3498 else if (pcc_struct_value) 3499 { 3500 /* This is the special C++ case where we need to 3501 know what the true target was. We take care to 3502 never use this value more than once in one expression. */ 3503 target = gen_rtx_MEM (TYPE_MODE (rettype), 3504 copy_to_reg (valreg)); 3505 set_mem_attributes (target, rettype, 1); 3506 } 3507 /* Handle calls that return values in multiple non-contiguous locations. 3508 The Irix 6 ABI has examples of this. */ 3509 else if (GET_CODE (valreg) == PARALLEL) 3510 { 3511 if (target == 0) 3512 target = emit_group_move_into_temps (valreg); 3513 else if (rtx_equal_p (target, valreg)) 3514 ; 3515 else if (GET_CODE (target) == PARALLEL) 3516 /* Handle the result of a emit_group_move_into_temps 3517 call in the previous pass. */ 3518 emit_group_move (target, valreg); 3519 else 3520 emit_group_store (target, valreg, rettype, 3521 int_size_in_bytes (rettype)); 3522 } 3523 else if (target 3524 && GET_MODE (target) == TYPE_MODE (rettype) 3525 && GET_MODE (target) == GET_MODE (valreg)) 3526 { 3527 bool may_overlap = false; 3528 3529 /* We have to copy a return value in a CLASS_LIKELY_SPILLED hard 3530 reg to a plain register. */ 3531 if (!REG_P (target) || HARD_REGISTER_P (target)) 3532 valreg = avoid_likely_spilled_reg (valreg); 3533 3534 /* If TARGET is a MEM in the argument area, and we have 3535 saved part of the argument area, then we can't store 3536 directly into TARGET as it may get overwritten when we 3537 restore the argument save area below. Don't work too 3538 hard though and simply force TARGET to a register if it 3539 is a MEM; the optimizer is quite likely to sort it out. */ 3540 if (ACCUMULATE_OUTGOING_ARGS && pass && MEM_P (target)) 3541 for (i = 0; i < num_actuals; i++) 3542 if (args[i].save_area) 3543 { 3544 may_overlap = true; 3545 break; 3546 } 3547 3548 if (may_overlap) 3549 target = copy_to_reg (valreg); 3550 else 3551 { 3552 /* TARGET and VALREG cannot be equal at this point 3553 because the latter would not have 3554 REG_FUNCTION_VALUE_P true, while the former would if 3555 it were referring to the same register. 3556 3557 If they refer to the same register, this move will be 3558 a no-op, except when function inlining is being 3559 done. */ 3560 emit_move_insn (target, valreg); 3561 3562 /* If we are setting a MEM, this code must be executed. 3563 Since it is emitted after the call insn, sibcall 3564 optimization cannot be performed in that case. */ 3565 if (MEM_P (target)) 3566 sibcall_failure = 1; 3567 } 3568 } 3569 else 3570 target = copy_to_reg (avoid_likely_spilled_reg (valreg)); 3571 3572 /* If we promoted this return value, make the proper SUBREG. 3573 TARGET might be const0_rtx here, so be careful. */ 3574 if (REG_P (target) 3575 && TYPE_MODE (rettype) != BLKmode 3576 && GET_MODE (target) != TYPE_MODE (rettype)) 3577 { 3578 tree type = rettype; 3579 int unsignedp = TYPE_UNSIGNED (type); 3580 int offset = 0; 3581 machine_mode pmode; 3582 3583 /* Ensure we promote as expected, and get the new unsignedness. */ 3584 pmode = promote_function_mode (type, TYPE_MODE (type), &unsignedp, 3585 funtype, 1); 3586 gcc_assert (GET_MODE (target) == pmode); 3587 3588 if ((WORDS_BIG_ENDIAN || BYTES_BIG_ENDIAN) 3589 && (GET_MODE_SIZE (GET_MODE (target)) 3590 > GET_MODE_SIZE (TYPE_MODE (type)))) 3591 { 3592 offset = GET_MODE_SIZE (GET_MODE (target)) 3593 - GET_MODE_SIZE (TYPE_MODE (type)); 3594 if (! BYTES_BIG_ENDIAN) 3595 offset = (offset / UNITS_PER_WORD) * UNITS_PER_WORD; 3596 else if (! WORDS_BIG_ENDIAN) 3597 offset %= UNITS_PER_WORD; 3598 } 3599 3600 target = gen_rtx_SUBREG (TYPE_MODE (type), target, offset); 3601 SUBREG_PROMOTED_VAR_P (target) = 1; 3602 SUBREG_PROMOTED_SET (target, unsignedp); 3603 } 3604 3605 /* If size of args is variable or this was a constructor call for a stack 3606 argument, restore saved stack-pointer value. */ 3607 3608 if (old_stack_level) 3609 { 3610 rtx_insn *prev = get_last_insn (); 3611 3612 emit_stack_restore (SAVE_BLOCK, old_stack_level); 3613 stack_pointer_delta = old_stack_pointer_delta; 3614 3615 fixup_args_size_notes (prev, get_last_insn (), stack_pointer_delta); 3616 3617 pending_stack_adjust = old_pending_adj; 3618 old_stack_allocated = stack_pointer_delta - pending_stack_adjust; 3619 stack_arg_under_construction = old_stack_arg_under_construction; 3620 highest_outgoing_arg_in_use = initial_highest_arg_in_use; 3621 stack_usage_map = initial_stack_usage_map; 3622 sibcall_failure = 1; 3623 } 3624 else if (ACCUMULATE_OUTGOING_ARGS && pass) 3625 { 3626#ifdef REG_PARM_STACK_SPACE 3627 if (save_area) 3628 restore_fixed_argument_area (save_area, argblock, 3629 high_to_save, low_to_save); 3630#endif 3631 3632 /* If we saved any argument areas, restore them. */ 3633 for (i = 0; i < num_actuals; i++) 3634 if (args[i].save_area) 3635 { 3636 machine_mode save_mode = GET_MODE (args[i].save_area); 3637 rtx stack_area 3638 = gen_rtx_MEM (save_mode, 3639 memory_address (save_mode, 3640 XEXP (args[i].stack_slot, 0))); 3641 3642 if (save_mode != BLKmode) 3643 emit_move_insn (stack_area, args[i].save_area); 3644 else 3645 emit_block_move (stack_area, args[i].save_area, 3646 GEN_INT (args[i].locate.size.constant), 3647 BLOCK_OP_CALL_PARM); 3648 } 3649 3650 highest_outgoing_arg_in_use = initial_highest_arg_in_use; 3651 stack_usage_map = initial_stack_usage_map; 3652 } 3653 3654 /* If this was alloca, record the new stack level for nonlocal gotos. 3655 Check for the handler slots since we might not have a save area 3656 for non-local gotos. */ 3657 3658 if ((flags & ECF_MAY_BE_ALLOCA) && cfun->nonlocal_goto_save_area != 0) 3659 update_nonlocal_goto_save_area (); 3660 3661 /* Free up storage we no longer need. */ 3662 for (i = 0; i < num_actuals; ++i) 3663 free (args[i].aligned_regs); 3664 3665 targetm.calls.end_call_args (); 3666 3667 insns = get_insns (); 3668 end_sequence (); 3669 3670 if (pass == 0) 3671 { 3672 tail_call_insns = insns; 3673 3674 /* Restore the pending stack adjustment now that we have 3675 finished generating the sibling call sequence. */ 3676 3677 restore_pending_stack_adjust (&save); 3678 3679 /* Prepare arg structure for next iteration. */ 3680 for (i = 0; i < num_actuals; i++) 3681 { 3682 args[i].value = 0; 3683 args[i].aligned_regs = 0; 3684 args[i].stack = 0; 3685 } 3686 3687 sbitmap_free (stored_args_map); 3688 internal_arg_pointer_exp_state.scan_start = NULL; 3689 internal_arg_pointer_exp_state.cache.release (); 3690 } 3691 else 3692 { 3693 normal_call_insns = insns; 3694 3695 /* Verify that we've deallocated all the stack we used. */ 3696 gcc_assert ((flags & ECF_NORETURN) 3697 || (old_stack_allocated 3698 == stack_pointer_delta - pending_stack_adjust)); 3699 } 3700 3701 /* If something prevents making this a sibling call, 3702 zero out the sequence. */ 3703 if (sibcall_failure) 3704 tail_call_insns = NULL; 3705 else 3706 break; 3707 } 3708 3709 /* If tail call production succeeded, we need to remove REG_EQUIV notes on 3710 arguments too, as argument area is now clobbered by the call. */ 3711 if (tail_call_insns) 3712 { 3713 emit_insn (tail_call_insns); 3714 crtl->tail_call_emit = true; 3715 } 3716 else 3717 emit_insn (normal_call_insns); 3718 3719 currently_expanding_call--; 3720 3721 free (stack_usage_map_buf); 3722 3723 /* Join result with returned bounds so caller may use them if needed. */ 3724 target = chkp_join_splitted_slot (target, valbnd); 3725 3726 return target; 3727} 3728 3729/* A sibling call sequence invalidates any REG_EQUIV notes made for 3730 this function's incoming arguments. 3731 3732 At the start of RTL generation we know the only REG_EQUIV notes 3733 in the rtl chain are those for incoming arguments, so we can look 3734 for REG_EQUIV notes between the start of the function and the 3735 NOTE_INSN_FUNCTION_BEG. 3736 3737 This is (slight) overkill. We could keep track of the highest 3738 argument we clobber and be more selective in removing notes, but it 3739 does not seem to be worth the effort. */ 3740 3741void 3742fixup_tail_calls (void) 3743{ 3744 rtx_insn *insn; 3745 3746 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 3747 { 3748 rtx note; 3749 3750 /* There are never REG_EQUIV notes for the incoming arguments 3751 after the NOTE_INSN_FUNCTION_BEG note, so stop if we see it. */ 3752 if (NOTE_P (insn) 3753 && NOTE_KIND (insn) == NOTE_INSN_FUNCTION_BEG) 3754 break; 3755 3756 note = find_reg_note (insn, REG_EQUIV, 0); 3757 if (note) 3758 remove_note (insn, note); 3759 note = find_reg_note (insn, REG_EQUIV, 0); 3760 gcc_assert (!note); 3761 } 3762} 3763 3764/* Traverse a list of TYPES and expand all complex types into their 3765 components. */ 3766static tree 3767split_complex_types (tree types) 3768{ 3769 tree p; 3770 3771 /* Before allocating memory, check for the common case of no complex. */ 3772 for (p = types; p; p = TREE_CHAIN (p)) 3773 { 3774 tree type = TREE_VALUE (p); 3775 if (TREE_CODE (type) == COMPLEX_TYPE 3776 && targetm.calls.split_complex_arg (type)) 3777 goto found; 3778 } 3779 return types; 3780 3781 found: 3782 types = copy_list (types); 3783 3784 for (p = types; p; p = TREE_CHAIN (p)) 3785 { 3786 tree complex_type = TREE_VALUE (p); 3787 3788 if (TREE_CODE (complex_type) == COMPLEX_TYPE 3789 && targetm.calls.split_complex_arg (complex_type)) 3790 { 3791 tree next, imag; 3792 3793 /* Rewrite complex type with component type. */ 3794 TREE_VALUE (p) = TREE_TYPE (complex_type); 3795 next = TREE_CHAIN (p); 3796 3797 /* Add another component type for the imaginary part. */ 3798 imag = build_tree_list (NULL_TREE, TREE_VALUE (p)); 3799 TREE_CHAIN (p) = imag; 3800 TREE_CHAIN (imag) = next; 3801 3802 /* Skip the newly created node. */ 3803 p = TREE_CHAIN (p); 3804 } 3805 } 3806 3807 return types; 3808} 3809 3810/* Output a library call to function FUN (a SYMBOL_REF rtx). 3811 The RETVAL parameter specifies whether return value needs to be saved, other 3812 parameters are documented in the emit_library_call function below. */ 3813 3814static rtx 3815emit_library_call_value_1 (int retval, rtx orgfun, rtx value, 3816 enum libcall_type fn_type, 3817 machine_mode outmode, int nargs, va_list p) 3818{ 3819 /* Total size in bytes of all the stack-parms scanned so far. */ 3820 struct args_size args_size; 3821 /* Size of arguments before any adjustments (such as rounding). */ 3822 struct args_size original_args_size; 3823 int argnum; 3824 rtx fun; 3825 /* Todo, choose the correct decl type of orgfun. Sadly this information 3826 isn't present here, so we default to native calling abi here. */ 3827 tree fndecl ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */ 3828 tree fntype ATTRIBUTE_UNUSED = NULL_TREE; /* library calls default to host calling abi ? */ 3829 int count; 3830 rtx argblock = 0; 3831 CUMULATIVE_ARGS args_so_far_v; 3832 cumulative_args_t args_so_far; 3833 struct arg 3834 { 3835 rtx value; 3836 machine_mode mode; 3837 rtx reg; 3838 int partial; 3839 struct locate_and_pad_arg_data locate; 3840 rtx save_area; 3841 }; 3842 struct arg *argvec; 3843 int old_inhibit_defer_pop = inhibit_defer_pop; 3844 rtx call_fusage = 0; 3845 rtx mem_value = 0; 3846 rtx valreg; 3847 int pcc_struct_value = 0; 3848 int struct_value_size = 0; 3849 int flags; 3850 int reg_parm_stack_space = 0; 3851 int needed; 3852 rtx_insn *before_call; 3853 bool have_push_fusage; 3854 tree tfom; /* type_for_mode (outmode, 0) */ 3855 3856#ifdef REG_PARM_STACK_SPACE 3857 /* Define the boundary of the register parm stack space that needs to be 3858 save, if any. */ 3859 int low_to_save = 0, high_to_save = 0; 3860 rtx save_area = 0; /* Place that it is saved. */ 3861#endif 3862 3863 /* Size of the stack reserved for parameter registers. */ 3864 int initial_highest_arg_in_use = highest_outgoing_arg_in_use; 3865 char *initial_stack_usage_map = stack_usage_map; 3866 char *stack_usage_map_buf = NULL; 3867 3868 rtx struct_value = targetm.calls.struct_value_rtx (0, 0); 3869 3870#ifdef REG_PARM_STACK_SPACE 3871 reg_parm_stack_space = REG_PARM_STACK_SPACE ((tree) 0); 3872#endif 3873 3874 /* By default, library functions can not throw. */ 3875 flags = ECF_NOTHROW; 3876 3877 switch (fn_type) 3878 { 3879 case LCT_NORMAL: 3880 break; 3881 case LCT_CONST: 3882 flags |= ECF_CONST; 3883 break; 3884 case LCT_PURE: 3885 flags |= ECF_PURE; 3886 break; 3887 case LCT_NORETURN: 3888 flags |= ECF_NORETURN; 3889 break; 3890 case LCT_THROW: 3891 flags = ECF_NORETURN; 3892 break; 3893 case LCT_RETURNS_TWICE: 3894 flags = ECF_RETURNS_TWICE; 3895 break; 3896 } 3897 fun = orgfun; 3898 3899 /* Ensure current function's preferred stack boundary is at least 3900 what we need. */ 3901 if (crtl->preferred_stack_boundary < PREFERRED_STACK_BOUNDARY) 3902 crtl->preferred_stack_boundary = PREFERRED_STACK_BOUNDARY; 3903 3904 /* If this kind of value comes back in memory, 3905 decide where in memory it should come back. */ 3906 if (outmode != VOIDmode) 3907 { 3908 tfom = lang_hooks.types.type_for_mode (outmode, 0); 3909 if (aggregate_value_p (tfom, 0)) 3910 { 3911#ifdef PCC_STATIC_STRUCT_RETURN 3912 rtx pointer_reg 3913 = hard_function_value (build_pointer_type (tfom), 0, 0, 0); 3914 mem_value = gen_rtx_MEM (outmode, pointer_reg); 3915 pcc_struct_value = 1; 3916 if (value == 0) 3917 value = gen_reg_rtx (outmode); 3918#else /* not PCC_STATIC_STRUCT_RETURN */ 3919 struct_value_size = GET_MODE_SIZE (outmode); 3920 if (value != 0 && MEM_P (value)) 3921 mem_value = value; 3922 else 3923 mem_value = assign_temp (tfom, 1, 1); 3924#endif 3925 /* This call returns a big structure. */ 3926 flags &= ~(ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE); 3927 } 3928 } 3929 else 3930 tfom = void_type_node; 3931 3932 /* ??? Unfinished: must pass the memory address as an argument. */ 3933 3934 /* Copy all the libcall-arguments out of the varargs data 3935 and into a vector ARGVEC. 3936 3937 Compute how to pass each argument. We only support a very small subset 3938 of the full argument passing conventions to limit complexity here since 3939 library functions shouldn't have many args. */ 3940 3941 argvec = XALLOCAVEC (struct arg, nargs + 1); 3942 memset (argvec, 0, (nargs + 1) * sizeof (struct arg)); 3943 3944#ifdef INIT_CUMULATIVE_LIBCALL_ARGS 3945 INIT_CUMULATIVE_LIBCALL_ARGS (args_so_far_v, outmode, fun); 3946#else 3947 INIT_CUMULATIVE_ARGS (args_so_far_v, NULL_TREE, fun, 0, nargs); 3948#endif 3949 args_so_far = pack_cumulative_args (&args_so_far_v); 3950 3951 args_size.constant = 0; 3952 args_size.var = 0; 3953 3954 count = 0; 3955 3956 push_temp_slots (); 3957 3958 /* If there's a structure value address to be passed, 3959 either pass it in the special place, or pass it as an extra argument. */ 3960 if (mem_value && struct_value == 0 && ! pcc_struct_value) 3961 { 3962 rtx addr = XEXP (mem_value, 0); 3963 3964 nargs++; 3965 3966 /* Make sure it is a reasonable operand for a move or push insn. */ 3967 if (!REG_P (addr) && !MEM_P (addr) 3968 && !(CONSTANT_P (addr) 3969 && targetm.legitimate_constant_p (Pmode, addr))) 3970 addr = force_operand (addr, NULL_RTX); 3971 3972 argvec[count].value = addr; 3973 argvec[count].mode = Pmode; 3974 argvec[count].partial = 0; 3975 3976 argvec[count].reg = targetm.calls.function_arg (args_so_far, 3977 Pmode, NULL_TREE, true); 3978 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode, 3979 NULL_TREE, 1) == 0); 3980 3981 locate_and_pad_parm (Pmode, NULL_TREE, 3982#ifdef STACK_PARMS_IN_REG_PARM_AREA 3983 1, 3984#else 3985 argvec[count].reg != 0, 3986#endif 3987 reg_parm_stack_space, 0, 3988 NULL_TREE, &args_size, &argvec[count].locate); 3989 3990 if (argvec[count].reg == 0 || argvec[count].partial != 0 3991 || reg_parm_stack_space > 0) 3992 args_size.constant += argvec[count].locate.size.constant; 3993 3994 targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true); 3995 3996 count++; 3997 } 3998 3999 for (; count < nargs; count++) 4000 { 4001 rtx val = va_arg (p, rtx); 4002 machine_mode mode = (machine_mode) va_arg (p, int); 4003 int unsigned_p = 0; 4004 4005 /* We cannot convert the arg value to the mode the library wants here; 4006 must do it earlier where we know the signedness of the arg. */ 4007 gcc_assert (mode != BLKmode 4008 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode)); 4009 4010 /* Make sure it is a reasonable operand for a move or push insn. */ 4011 if (!REG_P (val) && !MEM_P (val) 4012 && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val))) 4013 val = force_operand (val, NULL_RTX); 4014 4015 if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1)) 4016 { 4017 rtx slot; 4018 int must_copy 4019 = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1); 4020 4021 /* If this was a CONST function, it is now PURE since it now 4022 reads memory. */ 4023 if (flags & ECF_CONST) 4024 { 4025 flags &= ~ECF_CONST; 4026 flags |= ECF_PURE; 4027 } 4028 4029 if (MEM_P (val) && !must_copy) 4030 { 4031 tree val_expr = MEM_EXPR (val); 4032 if (val_expr) 4033 mark_addressable (val_expr); 4034 slot = val; 4035 } 4036 else 4037 { 4038 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0), 4039 1, 1); 4040 emit_move_insn (slot, val); 4041 } 4042 4043 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, 4044 gen_rtx_USE (VOIDmode, slot), 4045 call_fusage); 4046 if (must_copy) 4047 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, 4048 gen_rtx_CLOBBER (VOIDmode, 4049 slot), 4050 call_fusage); 4051 4052 mode = Pmode; 4053 val = force_operand (XEXP (slot, 0), NULL_RTX); 4054 } 4055 4056 mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0); 4057 argvec[count].mode = mode; 4058 argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p); 4059 argvec[count].reg = targetm.calls.function_arg (args_so_far, mode, 4060 NULL_TREE, true); 4061 4062 argvec[count].partial 4063 = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1); 4064 4065 if (argvec[count].reg == 0 4066 || argvec[count].partial != 0 4067 || reg_parm_stack_space > 0) 4068 { 4069 locate_and_pad_parm (mode, NULL_TREE, 4070#ifdef STACK_PARMS_IN_REG_PARM_AREA 4071 1, 4072#else 4073 argvec[count].reg != 0, 4074#endif 4075 reg_parm_stack_space, argvec[count].partial, 4076 NULL_TREE, &args_size, &argvec[count].locate); 4077 args_size.constant += argvec[count].locate.size.constant; 4078 gcc_assert (!argvec[count].locate.size.var); 4079 } 4080#ifdef BLOCK_REG_PADDING 4081 else 4082 /* The argument is passed entirely in registers. See at which 4083 end it should be padded. */ 4084 argvec[count].locate.where_pad = 4085 BLOCK_REG_PADDING (mode, NULL_TREE, 4086 GET_MODE_SIZE (mode) <= UNITS_PER_WORD); 4087#endif 4088 4089 targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true); 4090 } 4091 4092 /* If this machine requires an external definition for library 4093 functions, write one out. */ 4094 assemble_external_libcall (fun); 4095 4096 original_args_size = args_size; 4097 args_size.constant = (((args_size.constant 4098 + stack_pointer_delta 4099 + STACK_BYTES - 1) 4100 / STACK_BYTES 4101 * STACK_BYTES) 4102 - stack_pointer_delta); 4103 4104 args_size.constant = MAX (args_size.constant, 4105 reg_parm_stack_space); 4106 4107 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) 4108 args_size.constant -= reg_parm_stack_space; 4109 4110 if (args_size.constant > crtl->outgoing_args_size) 4111 crtl->outgoing_args_size = args_size.constant; 4112 4113 if (flag_stack_usage_info && !ACCUMULATE_OUTGOING_ARGS) 4114 { 4115 int pushed = args_size.constant + pending_stack_adjust; 4116 if (pushed > current_function_pushed_stack_size) 4117 current_function_pushed_stack_size = pushed; 4118 } 4119 4120 if (ACCUMULATE_OUTGOING_ARGS) 4121 { 4122 /* Since the stack pointer will never be pushed, it is possible for 4123 the evaluation of a parm to clobber something we have already 4124 written to the stack. Since most function calls on RISC machines 4125 do not use the stack, this is uncommon, but must work correctly. 4126 4127 Therefore, we save any area of the stack that was already written 4128 and that we are using. Here we set up to do this by making a new 4129 stack usage map from the old one. 4130 4131 Another approach might be to try to reorder the argument 4132 evaluations to avoid this conflicting stack usage. */ 4133 4134 needed = args_size.constant; 4135 4136 /* Since we will be writing into the entire argument area, the 4137 map must be allocated for its entire size, not just the part that 4138 is the responsibility of the caller. */ 4139 if (! OUTGOING_REG_PARM_STACK_SPACE ((!fndecl ? fntype : TREE_TYPE (fndecl)))) 4140 needed += reg_parm_stack_space; 4141 4142#ifdef ARGS_GROW_DOWNWARD 4143 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, 4144 needed + 1); 4145#else 4146 highest_outgoing_arg_in_use = MAX (initial_highest_arg_in_use, 4147 needed); 4148#endif 4149 stack_usage_map_buf = XNEWVEC (char, highest_outgoing_arg_in_use); 4150 stack_usage_map = stack_usage_map_buf; 4151 4152 if (initial_highest_arg_in_use) 4153 memcpy (stack_usage_map, initial_stack_usage_map, 4154 initial_highest_arg_in_use); 4155 4156 if (initial_highest_arg_in_use != highest_outgoing_arg_in_use) 4157 memset (&stack_usage_map[initial_highest_arg_in_use], 0, 4158 highest_outgoing_arg_in_use - initial_highest_arg_in_use); 4159 needed = 0; 4160 4161 /* We must be careful to use virtual regs before they're instantiated, 4162 and real regs afterwards. Loop optimization, for example, can create 4163 new libcalls after we've instantiated the virtual regs, and if we 4164 use virtuals anyway, they won't match the rtl patterns. */ 4165 4166 if (virtuals_instantiated) 4167 argblock = plus_constant (Pmode, stack_pointer_rtx, 4168 STACK_POINTER_OFFSET); 4169 else 4170 argblock = virtual_outgoing_args_rtx; 4171 } 4172 else 4173 { 4174 if (!PUSH_ARGS) 4175 argblock = push_block (GEN_INT (args_size.constant), 0, 0); 4176 } 4177 4178 /* We push args individually in reverse order, perform stack alignment 4179 before the first push (the last arg). */ 4180 if (argblock == 0) 4181 anti_adjust_stack (GEN_INT (args_size.constant 4182 - original_args_size.constant)); 4183 4184 argnum = nargs - 1; 4185 4186#ifdef REG_PARM_STACK_SPACE 4187 if (ACCUMULATE_OUTGOING_ARGS) 4188 { 4189 /* The argument list is the property of the called routine and it 4190 may clobber it. If the fixed area has been used for previous 4191 parameters, we must save and restore it. */ 4192 save_area = save_fixed_argument_area (reg_parm_stack_space, argblock, 4193 &low_to_save, &high_to_save); 4194 } 4195#endif 4196 4197 /* When expanding a normal call, args are stored in push order, 4198 which is the reverse of what we have here. */ 4199 bool any_regs = false; 4200 for (int i = nargs; i-- > 0; ) 4201 if (argvec[i].reg != NULL_RTX) 4202 { 4203 targetm.calls.call_args (argvec[i].reg, NULL_TREE); 4204 any_regs = true; 4205 } 4206 if (!any_regs) 4207 targetm.calls.call_args (pc_rtx, NULL_TREE); 4208 4209 /* Push the args that need to be pushed. */ 4210 4211 have_push_fusage = false; 4212 4213 /* ARGNUM indexes the ARGVEC array in the order in which the arguments 4214 are to be pushed. */ 4215 for (count = 0; count < nargs; count++, argnum--) 4216 { 4217 machine_mode mode = argvec[argnum].mode; 4218 rtx val = argvec[argnum].value; 4219 rtx reg = argvec[argnum].reg; 4220 int partial = argvec[argnum].partial; 4221 unsigned int parm_align = argvec[argnum].locate.boundary; 4222 int lower_bound = 0, upper_bound = 0, i; 4223 4224 if (! (reg != 0 && partial == 0)) 4225 { 4226 rtx use; 4227 4228 if (ACCUMULATE_OUTGOING_ARGS) 4229 { 4230 /* If this is being stored into a pre-allocated, fixed-size, 4231 stack area, save any previous data at that location. */ 4232 4233#ifdef ARGS_GROW_DOWNWARD 4234 /* stack_slot is negative, but we want to index stack_usage_map 4235 with positive values. */ 4236 upper_bound = -argvec[argnum].locate.slot_offset.constant + 1; 4237 lower_bound = upper_bound - argvec[argnum].locate.size.constant; 4238#else 4239 lower_bound = argvec[argnum].locate.slot_offset.constant; 4240 upper_bound = lower_bound + argvec[argnum].locate.size.constant; 4241#endif 4242 4243 i = lower_bound; 4244 /* Don't worry about things in the fixed argument area; 4245 it has already been saved. */ 4246 if (i < reg_parm_stack_space) 4247 i = reg_parm_stack_space; 4248 while (i < upper_bound && stack_usage_map[i] == 0) 4249 i++; 4250 4251 if (i < upper_bound) 4252 { 4253 /* We need to make a save area. */ 4254 unsigned int size 4255 = argvec[argnum].locate.size.constant * BITS_PER_UNIT; 4256 machine_mode save_mode 4257 = mode_for_size (size, MODE_INT, 1); 4258 rtx adr 4259 = plus_constant (Pmode, argblock, 4260 argvec[argnum].locate.offset.constant); 4261 rtx stack_area 4262 = gen_rtx_MEM (save_mode, memory_address (save_mode, adr)); 4263 4264 if (save_mode == BLKmode) 4265 { 4266 argvec[argnum].save_area 4267 = assign_stack_temp (BLKmode, 4268 argvec[argnum].locate.size.constant 4269 ); 4270 4271 emit_block_move (validize_mem 4272 (copy_rtx (argvec[argnum].save_area)), 4273 stack_area, 4274 GEN_INT (argvec[argnum].locate.size.constant), 4275 BLOCK_OP_CALL_PARM); 4276 } 4277 else 4278 { 4279 argvec[argnum].save_area = gen_reg_rtx (save_mode); 4280 4281 emit_move_insn (argvec[argnum].save_area, stack_area); 4282 } 4283 } 4284 } 4285 4286 emit_push_insn (val, mode, NULL_TREE, NULL_RTX, parm_align, 4287 partial, reg, 0, argblock, 4288 GEN_INT (argvec[argnum].locate.offset.constant), 4289 reg_parm_stack_space, 4290 ARGS_SIZE_RTX (argvec[argnum].locate.alignment_pad)); 4291 4292 /* Now mark the segment we just used. */ 4293 if (ACCUMULATE_OUTGOING_ARGS) 4294 for (i = lower_bound; i < upper_bound; i++) 4295 stack_usage_map[i] = 1; 4296 4297 NO_DEFER_POP; 4298 4299 /* Indicate argument access so that alias.c knows that these 4300 values are live. */ 4301 if (argblock) 4302 use = plus_constant (Pmode, argblock, 4303 argvec[argnum].locate.offset.constant); 4304 else if (have_push_fusage) 4305 continue; 4306 else 4307 { 4308 /* When arguments are pushed, trying to tell alias.c where 4309 exactly this argument is won't work, because the 4310 auto-increment causes confusion. So we merely indicate 4311 that we access something with a known mode somewhere on 4312 the stack. */ 4313 use = gen_rtx_PLUS (Pmode, stack_pointer_rtx, 4314 gen_rtx_SCRATCH (Pmode)); 4315 have_push_fusage = true; 4316 } 4317 use = gen_rtx_MEM (argvec[argnum].mode, use); 4318 use = gen_rtx_USE (VOIDmode, use); 4319 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, use, call_fusage); 4320 } 4321 } 4322 4323 argnum = nargs - 1; 4324 4325 fun = prepare_call_address (NULL, fun, NULL, &call_fusage, 0, 0); 4326 4327 /* Now load any reg parms into their regs. */ 4328 4329 /* ARGNUM indexes the ARGVEC array in the order in which the arguments 4330 are to be pushed. */ 4331 for (count = 0; count < nargs; count++, argnum--) 4332 { 4333 machine_mode mode = argvec[argnum].mode; 4334 rtx val = argvec[argnum].value; 4335 rtx reg = argvec[argnum].reg; 4336 int partial = argvec[argnum].partial; 4337#ifdef BLOCK_REG_PADDING 4338 int size = 0; 4339#endif 4340 4341 /* Handle calls that pass values in multiple non-contiguous 4342 locations. The PA64 has examples of this for library calls. */ 4343 if (reg != 0 && GET_CODE (reg) == PARALLEL) 4344 emit_group_load (reg, val, NULL_TREE, GET_MODE_SIZE (mode)); 4345 else if (reg != 0 && partial == 0) 4346 { 4347 emit_move_insn (reg, val); 4348#ifdef BLOCK_REG_PADDING 4349 size = GET_MODE_SIZE (argvec[argnum].mode); 4350 4351 /* Copied from load_register_parameters. */ 4352 4353 /* Handle case where we have a value that needs shifting 4354 up to the msb. eg. a QImode value and we're padding 4355 upward on a BYTES_BIG_ENDIAN machine. */ 4356 if (size < UNITS_PER_WORD 4357 && (argvec[argnum].locate.where_pad 4358 == (BYTES_BIG_ENDIAN ? upward : downward))) 4359 { 4360 rtx x; 4361 int shift = (UNITS_PER_WORD - size) * BITS_PER_UNIT; 4362 4363 /* Assigning REG here rather than a temp makes CALL_FUSAGE 4364 report the whole reg as used. Strictly speaking, the 4365 call only uses SIZE bytes at the msb end, but it doesn't 4366 seem worth generating rtl to say that. */ 4367 reg = gen_rtx_REG (word_mode, REGNO (reg)); 4368 x = expand_shift (LSHIFT_EXPR, word_mode, reg, shift, reg, 1); 4369 if (x != reg) 4370 emit_move_insn (reg, x); 4371 } 4372#endif 4373 } 4374 4375 NO_DEFER_POP; 4376 } 4377 4378 /* Any regs containing parms remain in use through the call. */ 4379 for (count = 0; count < nargs; count++) 4380 { 4381 rtx reg = argvec[count].reg; 4382 if (reg != 0 && GET_CODE (reg) == PARALLEL) 4383 use_group_regs (&call_fusage, reg); 4384 else if (reg != 0) 4385 { 4386 int partial = argvec[count].partial; 4387 if (partial) 4388 { 4389 int nregs; 4390 gcc_assert (partial % UNITS_PER_WORD == 0); 4391 nregs = partial / UNITS_PER_WORD; 4392 use_regs (&call_fusage, REGNO (reg), nregs); 4393 } 4394 else 4395 use_reg (&call_fusage, reg); 4396 } 4397 } 4398 4399 /* Pass the function the address in which to return a structure value. */ 4400 if (mem_value != 0 && struct_value != 0 && ! pcc_struct_value) 4401 { 4402 emit_move_insn (struct_value, 4403 force_reg (Pmode, 4404 force_operand (XEXP (mem_value, 0), 4405 NULL_RTX))); 4406 if (REG_P (struct_value)) 4407 use_reg (&call_fusage, struct_value); 4408 } 4409 4410 /* Don't allow popping to be deferred, since then 4411 cse'ing of library calls could delete a call and leave the pop. */ 4412 NO_DEFER_POP; 4413 valreg = (mem_value == 0 && outmode != VOIDmode 4414 ? hard_libcall_value (outmode, orgfun) : NULL_RTX); 4415 4416 /* Stack must be properly aligned now. */ 4417 gcc_assert (!(stack_pointer_delta 4418 & (PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT - 1))); 4419 4420 before_call = get_last_insn (); 4421 4422 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which 4423 will set inhibit_defer_pop to that value. */ 4424 /* The return type is needed to decide how many bytes the function pops. 4425 Signedness plays no role in that, so for simplicity, we pretend it's 4426 always signed. We also assume that the list of arguments passed has 4427 no impact, so we pretend it is unknown. */ 4428 4429 emit_call_1 (fun, NULL, 4430 get_identifier (XSTR (orgfun, 0)), 4431 build_function_type (tfom, NULL_TREE), 4432 original_args_size.constant, args_size.constant, 4433 struct_value_size, 4434 targetm.calls.function_arg (args_so_far, 4435 VOIDmode, void_type_node, true), 4436 valreg, 4437 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far); 4438 4439 if (flag_ipa_ra) 4440 { 4441 rtx last, datum = orgfun; 4442 gcc_assert (GET_CODE (datum) == SYMBOL_REF); 4443 last = last_call_insn (); 4444 add_reg_note (last, REG_CALL_DECL, datum); 4445 } 4446 4447 /* Right-shift returned value if necessary. */ 4448 if (!pcc_struct_value 4449 && TYPE_MODE (tfom) != BLKmode 4450 && targetm.calls.return_in_msb (tfom)) 4451 { 4452 shift_return_value (TYPE_MODE (tfom), false, valreg); 4453 valreg = gen_rtx_REG (TYPE_MODE (tfom), REGNO (valreg)); 4454 } 4455 4456 targetm.calls.end_call_args (); 4457 4458 /* For calls to `setjmp', etc., inform function.c:setjmp_warnings 4459 that it should complain if nonvolatile values are live. For 4460 functions that cannot return, inform flow that control does not 4461 fall through. */ 4462 if (flags & ECF_NORETURN) 4463 { 4464 /* The barrier note must be emitted 4465 immediately after the CALL_INSN. Some ports emit more than 4466 just a CALL_INSN above, so we must search for it here. */ 4467 rtx_insn *last = get_last_insn (); 4468 while (!CALL_P (last)) 4469 { 4470 last = PREV_INSN (last); 4471 /* There was no CALL_INSN? */ 4472 gcc_assert (last != before_call); 4473 } 4474 4475 emit_barrier_after (last); 4476 } 4477 4478 /* Consider that "regular" libcalls, i.e. all of them except for LCT_THROW 4479 and LCT_RETURNS_TWICE, cannot perform non-local gotos. */ 4480 if (flags & ECF_NOTHROW) 4481 { 4482 rtx_insn *last = get_last_insn (); 4483 while (!CALL_P (last)) 4484 { 4485 last = PREV_INSN (last); 4486 /* There was no CALL_INSN? */ 4487 gcc_assert (last != before_call); 4488 } 4489 4490 make_reg_eh_region_note_nothrow_nononlocal (last); 4491 } 4492 4493 /* Now restore inhibit_defer_pop to its actual original value. */ 4494 OK_DEFER_POP; 4495 4496 pop_temp_slots (); 4497 4498 /* Copy the value to the right place. */ 4499 if (outmode != VOIDmode && retval) 4500 { 4501 if (mem_value) 4502 { 4503 if (value == 0) 4504 value = mem_value; 4505 if (value != mem_value) 4506 emit_move_insn (value, mem_value); 4507 } 4508 else if (GET_CODE (valreg) == PARALLEL) 4509 { 4510 if (value == 0) 4511 value = gen_reg_rtx (outmode); 4512 emit_group_store (value, valreg, NULL_TREE, GET_MODE_SIZE (outmode)); 4513 } 4514 else 4515 { 4516 /* Convert to the proper mode if a promotion has been active. */ 4517 if (GET_MODE (valreg) != outmode) 4518 { 4519 int unsignedp = TYPE_UNSIGNED (tfom); 4520 4521 gcc_assert (promote_function_mode (tfom, outmode, &unsignedp, 4522 fndecl ? TREE_TYPE (fndecl) : fntype, 1) 4523 == GET_MODE (valreg)); 4524 valreg = convert_modes (outmode, GET_MODE (valreg), valreg, 0); 4525 } 4526 4527 if (value != 0) 4528 emit_move_insn (value, valreg); 4529 else 4530 value = valreg; 4531 } 4532 } 4533 4534 if (ACCUMULATE_OUTGOING_ARGS) 4535 { 4536#ifdef REG_PARM_STACK_SPACE 4537 if (save_area) 4538 restore_fixed_argument_area (save_area, argblock, 4539 high_to_save, low_to_save); 4540#endif 4541 4542 /* If we saved any argument areas, restore them. */ 4543 for (count = 0; count < nargs; count++) 4544 if (argvec[count].save_area) 4545 { 4546 machine_mode save_mode = GET_MODE (argvec[count].save_area); 4547 rtx adr = plus_constant (Pmode, argblock, 4548 argvec[count].locate.offset.constant); 4549 rtx stack_area = gen_rtx_MEM (save_mode, 4550 memory_address (save_mode, adr)); 4551 4552 if (save_mode == BLKmode) 4553 emit_block_move (stack_area, 4554 validize_mem 4555 (copy_rtx (argvec[count].save_area)), 4556 GEN_INT (argvec[count].locate.size.constant), 4557 BLOCK_OP_CALL_PARM); 4558 else 4559 emit_move_insn (stack_area, argvec[count].save_area); 4560 } 4561 4562 highest_outgoing_arg_in_use = initial_highest_arg_in_use; 4563 stack_usage_map = initial_stack_usage_map; 4564 } 4565 4566 free (stack_usage_map_buf); 4567 4568 return value; 4569 4570} 4571 4572/* Output a library call to function FUN (a SYMBOL_REF rtx) 4573 (emitting the queue unless NO_QUEUE is nonzero), 4574 for a value of mode OUTMODE, 4575 with NARGS different arguments, passed as alternating rtx values 4576 and machine_modes to convert them to. 4577 4578 FN_TYPE should be LCT_NORMAL for `normal' calls, LCT_CONST for 4579 `const' calls, LCT_PURE for `pure' calls, or other LCT_ value for 4580 other types of library calls. */ 4581 4582void 4583emit_library_call (rtx orgfun, enum libcall_type fn_type, 4584 machine_mode outmode, int nargs, ...) 4585{ 4586 va_list p; 4587 4588 va_start (p, nargs); 4589 emit_library_call_value_1 (0, orgfun, NULL_RTX, fn_type, outmode, nargs, p); 4590 va_end (p); 4591} 4592 4593/* Like emit_library_call except that an extra argument, VALUE, 4594 comes second and says where to store the result. 4595 (If VALUE is zero, this function chooses a convenient way 4596 to return the value. 4597 4598 This function returns an rtx for where the value is to be found. 4599 If VALUE is nonzero, VALUE is returned. */ 4600 4601rtx 4602emit_library_call_value (rtx orgfun, rtx value, 4603 enum libcall_type fn_type, 4604 machine_mode outmode, int nargs, ...) 4605{ 4606 rtx result; 4607 va_list p; 4608 4609 va_start (p, nargs); 4610 result = emit_library_call_value_1 (1, orgfun, value, fn_type, outmode, 4611 nargs, p); 4612 va_end (p); 4613 4614 return result; 4615} 4616 4617 4618/* Store pointer bounds argument ARG into Bounds Table entry 4619 associated with PARM. */ 4620static void 4621store_bounds (struct arg_data *arg, struct arg_data *parm) 4622{ 4623 rtx slot = NULL, ptr = NULL, addr = NULL; 4624 4625 /* We may pass bounds not associated with any pointer. */ 4626 if (!parm) 4627 { 4628 gcc_assert (arg->special_slot); 4629 slot = arg->special_slot; 4630 ptr = const0_rtx; 4631 } 4632 /* Find pointer associated with bounds and where it is 4633 passed. */ 4634 else 4635 { 4636 if (!parm->reg) 4637 { 4638 gcc_assert (!arg->special_slot); 4639 4640 addr = adjust_address (parm->stack, Pmode, arg->pointer_offset); 4641 } 4642 else if (REG_P (parm->reg)) 4643 { 4644 gcc_assert (arg->special_slot); 4645 slot = arg->special_slot; 4646 4647 if (MEM_P (parm->value)) 4648 addr = adjust_address (parm->value, Pmode, arg->pointer_offset); 4649 else if (REG_P (parm->value)) 4650 ptr = gen_rtx_SUBREG (Pmode, parm->value, arg->pointer_offset); 4651 else 4652 { 4653 gcc_assert (!arg->pointer_offset); 4654 ptr = parm->value; 4655 } 4656 } 4657 else 4658 { 4659 gcc_assert (GET_CODE (parm->reg) == PARALLEL); 4660 4661 gcc_assert (arg->special_slot); 4662 slot = arg->special_slot; 4663 4664 if (parm->parallel_value) 4665 ptr = chkp_get_value_with_offs (parm->parallel_value, 4666 GEN_INT (arg->pointer_offset)); 4667 else 4668 gcc_unreachable (); 4669 } 4670 } 4671 4672 /* Expand bounds. */ 4673 if (!arg->value) 4674 arg->value = expand_normal (arg->tree_value); 4675 4676 targetm.calls.store_bounds_for_arg (ptr, addr, arg->value, slot); 4677} 4678 4679/* Store a single argument for a function call 4680 into the register or memory area where it must be passed. 4681 *ARG describes the argument value and where to pass it. 4682 4683 ARGBLOCK is the address of the stack-block for all the arguments, 4684 or 0 on a machine where arguments are pushed individually. 4685 4686 MAY_BE_ALLOCA nonzero says this could be a call to `alloca' 4687 so must be careful about how the stack is used. 4688 4689 VARIABLE_SIZE nonzero says that this was a variable-sized outgoing 4690 argument stack. This is used if ACCUMULATE_OUTGOING_ARGS to indicate 4691 that we need not worry about saving and restoring the stack. 4692 4693 FNDECL is the declaration of the function we are calling. 4694 4695 Return nonzero if this arg should cause sibcall failure, 4696 zero otherwise. */ 4697 4698static int 4699store_one_arg (struct arg_data *arg, rtx argblock, int flags, 4700 int variable_size ATTRIBUTE_UNUSED, int reg_parm_stack_space) 4701{ 4702 tree pval = arg->tree_value; 4703 rtx reg = 0; 4704 int partial = 0; 4705 int used = 0; 4706 int i, lower_bound = 0, upper_bound = 0; 4707 int sibcall_failure = 0; 4708 4709 if (TREE_CODE (pval) == ERROR_MARK) 4710 return 1; 4711 4712 /* Push a new temporary level for any temporaries we make for 4713 this argument. */ 4714 push_temp_slots (); 4715 4716 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL)) 4717 { 4718 /* If this is being stored into a pre-allocated, fixed-size, stack area, 4719 save any previous data at that location. */ 4720 if (argblock && ! variable_size && arg->stack) 4721 { 4722#ifdef ARGS_GROW_DOWNWARD 4723 /* stack_slot is negative, but we want to index stack_usage_map 4724 with positive values. */ 4725 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) 4726 upper_bound = -INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)) + 1; 4727 else 4728 upper_bound = 0; 4729 4730 lower_bound = upper_bound - arg->locate.size.constant; 4731#else 4732 if (GET_CODE (XEXP (arg->stack_slot, 0)) == PLUS) 4733 lower_bound = INTVAL (XEXP (XEXP (arg->stack_slot, 0), 1)); 4734 else 4735 lower_bound = 0; 4736 4737 upper_bound = lower_bound + arg->locate.size.constant; 4738#endif 4739 4740 i = lower_bound; 4741 /* Don't worry about things in the fixed argument area; 4742 it has already been saved. */ 4743 if (i < reg_parm_stack_space) 4744 i = reg_parm_stack_space; 4745 while (i < upper_bound && stack_usage_map[i] == 0) 4746 i++; 4747 4748 if (i < upper_bound) 4749 { 4750 /* We need to make a save area. */ 4751 unsigned int size = arg->locate.size.constant * BITS_PER_UNIT; 4752 machine_mode save_mode = mode_for_size (size, MODE_INT, 1); 4753 rtx adr = memory_address (save_mode, XEXP (arg->stack_slot, 0)); 4754 rtx stack_area = gen_rtx_MEM (save_mode, adr); 4755 4756 if (save_mode == BLKmode) 4757 { 4758 arg->save_area 4759 = assign_temp (TREE_TYPE (arg->tree_value), 1, 1); 4760 preserve_temp_slots (arg->save_area); 4761 emit_block_move (validize_mem (copy_rtx (arg->save_area)), 4762 stack_area, 4763 GEN_INT (arg->locate.size.constant), 4764 BLOCK_OP_CALL_PARM); 4765 } 4766 else 4767 { 4768 arg->save_area = gen_reg_rtx (save_mode); 4769 emit_move_insn (arg->save_area, stack_area); 4770 } 4771 } 4772 } 4773 } 4774 4775 /* If this isn't going to be placed on both the stack and in registers, 4776 set up the register and number of words. */ 4777 if (! arg->pass_on_stack) 4778 { 4779 if (flags & ECF_SIBCALL) 4780 reg = arg->tail_call_reg; 4781 else 4782 reg = arg->reg; 4783 partial = arg->partial; 4784 } 4785 4786 /* Being passed entirely in a register. We shouldn't be called in 4787 this case. */ 4788 gcc_assert (reg == 0 || partial != 0); 4789 4790 /* If this arg needs special alignment, don't load the registers 4791 here. */ 4792 if (arg->n_aligned_regs != 0) 4793 reg = 0; 4794 4795 /* If this is being passed partially in a register, we can't evaluate 4796 it directly into its stack slot. Otherwise, we can. */ 4797 if (arg->value == 0) 4798 { 4799 /* stack_arg_under_construction is nonzero if a function argument is 4800 being evaluated directly into the outgoing argument list and 4801 expand_call must take special action to preserve the argument list 4802 if it is called recursively. 4803 4804 For scalar function arguments stack_usage_map is sufficient to 4805 determine which stack slots must be saved and restored. Scalar 4806 arguments in general have pass_on_stack == 0. 4807 4808 If this argument is initialized by a function which takes the 4809 address of the argument (a C++ constructor or a C function 4810 returning a BLKmode structure), then stack_usage_map is 4811 insufficient and expand_call must push the stack around the 4812 function call. Such arguments have pass_on_stack == 1. 4813 4814 Note that it is always safe to set stack_arg_under_construction, 4815 but this generates suboptimal code if set when not needed. */ 4816 4817 if (arg->pass_on_stack) 4818 stack_arg_under_construction++; 4819 4820 arg->value = expand_expr (pval, 4821 (partial 4822 || TYPE_MODE (TREE_TYPE (pval)) != arg->mode) 4823 ? NULL_RTX : arg->stack, 4824 VOIDmode, EXPAND_STACK_PARM); 4825 4826 /* If we are promoting object (or for any other reason) the mode 4827 doesn't agree, convert the mode. */ 4828 4829 if (arg->mode != TYPE_MODE (TREE_TYPE (pval))) 4830 arg->value = convert_modes (arg->mode, TYPE_MODE (TREE_TYPE (pval)), 4831 arg->value, arg->unsignedp); 4832 4833 if (arg->pass_on_stack) 4834 stack_arg_under_construction--; 4835 } 4836 4837 /* Check for overlap with already clobbered argument area. */ 4838 if ((flags & ECF_SIBCALL) 4839 && MEM_P (arg->value) 4840 && mem_overlaps_already_clobbered_arg_p (XEXP (arg->value, 0), 4841 arg->locate.size.constant)) 4842 sibcall_failure = 1; 4843 4844 /* Don't allow anything left on stack from computation 4845 of argument to alloca. */ 4846 if (flags & ECF_MAY_BE_ALLOCA) 4847 do_pending_stack_adjust (); 4848 4849 if (arg->value == arg->stack) 4850 /* If the value is already in the stack slot, we are done. */ 4851 ; 4852 else if (arg->mode != BLKmode) 4853 { 4854 int size; 4855 unsigned int parm_align; 4856 4857 /* Argument is a scalar, not entirely passed in registers. 4858 (If part is passed in registers, arg->partial says how much 4859 and emit_push_insn will take care of putting it there.) 4860 4861 Push it, and if its size is less than the 4862 amount of space allocated to it, 4863 also bump stack pointer by the additional space. 4864 Note that in C the default argument promotions 4865 will prevent such mismatches. */ 4866 4867 size = GET_MODE_SIZE (arg->mode); 4868 /* Compute how much space the push instruction will push. 4869 On many machines, pushing a byte will advance the stack 4870 pointer by a halfword. */ 4871#ifdef PUSH_ROUNDING 4872 size = PUSH_ROUNDING (size); 4873#endif 4874 used = size; 4875 4876 /* Compute how much space the argument should get: 4877 round up to a multiple of the alignment for arguments. */ 4878 if (none != FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval))) 4879 used = (((size + PARM_BOUNDARY / BITS_PER_UNIT - 1) 4880 / (PARM_BOUNDARY / BITS_PER_UNIT)) 4881 * (PARM_BOUNDARY / BITS_PER_UNIT)); 4882 4883 /* Compute the alignment of the pushed argument. */ 4884 parm_align = arg->locate.boundary; 4885 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward) 4886 { 4887 int pad = used - size; 4888 if (pad) 4889 { 4890 unsigned int pad_align = (pad & -pad) * BITS_PER_UNIT; 4891 parm_align = MIN (parm_align, pad_align); 4892 } 4893 } 4894 4895 /* This isn't already where we want it on the stack, so put it there. 4896 This can either be done with push or copy insns. */ 4897 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), NULL_RTX, 4898 parm_align, partial, reg, used - size, argblock, 4899 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space, 4900 ARGS_SIZE_RTX (arg->locate.alignment_pad)); 4901 4902 /* Unless this is a partially-in-register argument, the argument is now 4903 in the stack. */ 4904 if (partial == 0) 4905 arg->value = arg->stack; 4906 } 4907 else 4908 { 4909 /* BLKmode, at least partly to be pushed. */ 4910 4911 unsigned int parm_align; 4912 int excess; 4913 rtx size_rtx; 4914 4915 /* Pushing a nonscalar. 4916 If part is passed in registers, PARTIAL says how much 4917 and emit_push_insn will take care of putting it there. */ 4918 4919 /* Round its size up to a multiple 4920 of the allocation unit for arguments. */ 4921 4922 if (arg->locate.size.var != 0) 4923 { 4924 excess = 0; 4925 size_rtx = ARGS_SIZE_RTX (arg->locate.size); 4926 } 4927 else 4928 { 4929 /* PUSH_ROUNDING has no effect on us, because emit_push_insn 4930 for BLKmode is careful to avoid it. */ 4931 excess = (arg->locate.size.constant 4932 - int_size_in_bytes (TREE_TYPE (pval)) 4933 + partial); 4934 size_rtx = expand_expr (size_in_bytes (TREE_TYPE (pval)), 4935 NULL_RTX, TYPE_MODE (sizetype), 4936 EXPAND_NORMAL); 4937 } 4938 4939 parm_align = arg->locate.boundary; 4940 4941 /* When an argument is padded down, the block is aligned to 4942 PARM_BOUNDARY, but the actual argument isn't. */ 4943 if (FUNCTION_ARG_PADDING (arg->mode, TREE_TYPE (pval)) == downward) 4944 { 4945 if (arg->locate.size.var) 4946 parm_align = BITS_PER_UNIT; 4947 else if (excess) 4948 { 4949 unsigned int excess_align = (excess & -excess) * BITS_PER_UNIT; 4950 parm_align = MIN (parm_align, excess_align); 4951 } 4952 } 4953 4954 if ((flags & ECF_SIBCALL) && MEM_P (arg->value)) 4955 { 4956 /* emit_push_insn might not work properly if arg->value and 4957 argblock + arg->locate.offset areas overlap. */ 4958 rtx x = arg->value; 4959 int i = 0; 4960 4961 if (XEXP (x, 0) == crtl->args.internal_arg_pointer 4962 || (GET_CODE (XEXP (x, 0)) == PLUS 4963 && XEXP (XEXP (x, 0), 0) == 4964 crtl->args.internal_arg_pointer 4965 && CONST_INT_P (XEXP (XEXP (x, 0), 1)))) 4966 { 4967 if (XEXP (x, 0) != crtl->args.internal_arg_pointer) 4968 i = INTVAL (XEXP (XEXP (x, 0), 1)); 4969 4970 /* arg.locate doesn't contain the pretend_args_size offset, 4971 it's part of argblock. Ensure we don't count it in I. */ 4972#ifdef STACK_GROWS_DOWNWARD 4973 i -= crtl->args.pretend_args_size; 4974#else 4975 i += crtl->args.pretend_args_size; 4976#endif 4977 /* expand_call should ensure this. */ 4978 gcc_assert (!arg->locate.offset.var 4979 && arg->locate.size.var == 0 4980 && CONST_INT_P (size_rtx)); 4981 4982 if (arg->locate.offset.constant > i) 4983 { 4984 if (arg->locate.offset.constant < i + INTVAL (size_rtx)) 4985 sibcall_failure = 1; 4986 } 4987 else if (arg->locate.offset.constant < i) 4988 { 4989 /* Use arg->locate.size.constant instead of size_rtx 4990 because we only care about the part of the argument 4991 on the stack. */ 4992 if (i < (arg->locate.offset.constant 4993 + arg->locate.size.constant)) 4994 sibcall_failure = 1; 4995 } 4996 else 4997 { 4998 /* Even though they appear to be at the same location, 4999 if part of the outgoing argument is in registers, 5000 they aren't really at the same location. Check for 5001 this by making sure that the incoming size is the 5002 same as the outgoing size. */ 5003 if (arg->locate.size.constant != INTVAL (size_rtx)) 5004 sibcall_failure = 1; 5005 } 5006 } 5007 } 5008 5009 emit_push_insn (arg->value, arg->mode, TREE_TYPE (pval), size_rtx, 5010 parm_align, partial, reg, excess, argblock, 5011 ARGS_SIZE_RTX (arg->locate.offset), reg_parm_stack_space, 5012 ARGS_SIZE_RTX (arg->locate.alignment_pad)); 5013 5014 /* Unless this is a partially-in-register argument, the argument is now 5015 in the stack. 5016 5017 ??? Unlike the case above, in which we want the actual 5018 address of the data, so that we can load it directly into a 5019 register, here we want the address of the stack slot, so that 5020 it's properly aligned for word-by-word copying or something 5021 like that. It's not clear that this is always correct. */ 5022 if (partial == 0) 5023 arg->value = arg->stack_slot; 5024 } 5025 5026 if (arg->reg && GET_CODE (arg->reg) == PARALLEL) 5027 { 5028 tree type = TREE_TYPE (arg->tree_value); 5029 arg->parallel_value 5030 = emit_group_load_into_temps (arg->reg, arg->value, type, 5031 int_size_in_bytes (type)); 5032 } 5033 5034 /* Mark all slots this store used. */ 5035 if (ACCUMULATE_OUTGOING_ARGS && !(flags & ECF_SIBCALL) 5036 && argblock && ! variable_size && arg->stack) 5037 for (i = lower_bound; i < upper_bound; i++) 5038 stack_usage_map[i] = 1; 5039 5040 /* Once we have pushed something, pops can't safely 5041 be deferred during the rest of the arguments. */ 5042 NO_DEFER_POP; 5043 5044 /* Free any temporary slots made in processing this argument. */ 5045 pop_temp_slots (); 5046 5047 return sibcall_failure; 5048} 5049 5050/* Nonzero if we do not know how to pass TYPE solely in registers. */ 5051 5052bool 5053must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED, 5054 const_tree type) 5055{ 5056 if (!type) 5057 return false; 5058 5059 /* If the type has variable size... */ 5060 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) 5061 return true; 5062 5063 /* If the type is marked as addressable (it is required 5064 to be constructed into the stack)... */ 5065 if (TREE_ADDRESSABLE (type)) 5066 return true; 5067 5068 return false; 5069} 5070 5071/* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one 5072 takes trailing padding of a structure into account. */ 5073/* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */ 5074 5075bool 5076must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type) 5077{ 5078 if (!type) 5079 return false; 5080 5081 /* If the type has variable size... */ 5082 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) 5083 return true; 5084 5085 /* If the type is marked as addressable (it is required 5086 to be constructed into the stack)... */ 5087 if (TREE_ADDRESSABLE (type)) 5088 return true; 5089 5090 /* If the padding and mode of the type is such that a copy into 5091 a register would put it into the wrong part of the register. */ 5092 if (mode == BLKmode 5093 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT) 5094 && (FUNCTION_ARG_PADDING (mode, type) 5095 == (BYTES_BIG_ENDIAN ? upward : downward))) 5096 return true; 5097 5098 return false; 5099} 5100