1 /* Expands front end tree to back end RTL for GNU C-Compiler 2 Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 4 5 This file is part of GCC. 6 7 GCC is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free 9 Software Foundation; either version 2, or (at your option) any later 10 version. 11 12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with GCC; see the file COPYING. If not, write to the Free 19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 20 02111-1307, USA. */ 21 22 /* This file handles the generation of rtl code from tree structure 23 at the level of the function as a whole. 24 It creates the rtl expressions for parameters and auto variables 25 and has full responsibility for allocating stack slots. 26 27 `expand_function_start' is called at the beginning of a function, 28 before the function body is parsed, and `expand_function_end' is 29 called after parsing the body. 30 31 Call `assign_stack_local' to allocate a stack slot for a local variable. 32 This is usually done during the RTL generation for the function body, 33 but it can also be done in the reload pass when a pseudo-register does 34 not get a hard register. 35 36 Call `put_var_into_stack' when you learn, belatedly, that a variable 37 previously given a pseudo-register must in fact go in the stack. 38 This function changes the DECL_RTL to be a stack slot instead of a reg 39 then scans all the RTL instructions so far generated to correct them. */ 40 41 #include "config.h" 42 #include "system.h" 43 #include "rtl.h" 44 #include "tree.h" 45 #include "flags.h" 46 #include "except.h" 47 #include "function.h" 48 #include "expr.h" 49 #include "libfuncs.h" 50 #include "regs.h" 51 #include "hard-reg-set.h" 52 #include "insn-config.h" 53 #include "recog.h" 54 #include "output.h" 55 #include "basic-block.h" 56 #include "obstack.h" 57 #include "toplev.h" 58 #include "hash.h" 59 #include "ggc.h" 60 #include "tm_p.h" 61 #include "integrate.h" 62 #include "langhooks.h" 63 64 #ifndef TRAMPOLINE_ALIGNMENT 65 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY 66 #endif 67 68 #ifndef LOCAL_ALIGNMENT 69 #define LOCAL_ALIGNMENT(TYPE, ALIGNMENT) ALIGNMENT 70 #endif 71 72 /* Some systems use __main in a way incompatible with its use in gcc, in these 73 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to 74 give the same symbol without quotes for an alternative entry point. You 75 must define both, or neither. */ 76 #ifndef NAME__MAIN 77 #define NAME__MAIN "__main" 78 #define SYMBOL__MAIN __main 79 #endif 80 81 /* Round a value to the lowest integer less than it that is a multiple of 82 the required alignment. Avoid using division in case the value is 83 negative. Assume the alignment is a power of two. */ 84 #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1)) 85 86 /* Similar, but round to the next highest integer that meets the 87 alignment. */ 88 #define CEIL_ROUND(VALUE,ALIGN) (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1)) 89 90 /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp 91 during rtl generation. If they are different register numbers, this is 92 always true. It may also be true if 93 FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl 94 generation. See fix_lexical_addr for details. */ 95 96 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM 97 #define NEED_SEPARATE_AP 98 #endif 99 100 /* Nonzero if function being compiled doesn't contain any calls 101 (ignoring the prologue and epilogue). This is set prior to 102 local register allocation and is valid for the remaining 103 compiler passes. */ 104 int current_function_is_leaf; 105 106 /* Nonzero if function being compiled doesn't contain any instructions 107 that can throw an exception. This is set prior to final. */ 108 109 int current_function_nothrow; 110 111 /* Nonzero if function being compiled doesn't modify the stack pointer 112 (ignoring the prologue and epilogue). This is only valid after 113 life_analysis has run. */ 114 int current_function_sp_is_unchanging; 115 116 /* Nonzero if the function being compiled is a leaf function which only 117 uses leaf registers. This is valid after reload (specifically after 118 sched2) and is useful only if the port defines LEAF_REGISTERS. */ 119 int current_function_uses_only_leaf_regs; 120 121 /* Nonzero once virtual register instantiation has been done. 122 assign_stack_local uses frame_pointer_rtx when this is nonzero. 123 calls.c:emit_library_call_value_1 uses it to set up 124 post-instantiation libcalls. */ 125 int virtuals_instantiated; 126 127 /* Assign unique numbers to labels generated for profiling. */ 128 static int profile_label_no; 129 130 /* These variables hold pointers to functions to create and destroy 131 target specific, per-function data structures. */ 132 void (*init_machine_status) PARAMS ((struct function *)); 133 void (*free_machine_status) PARAMS ((struct function *)); 134 /* This variable holds a pointer to a function to register any 135 data items in the target specific, per-function data structure 136 that will need garbage collection. */ 137 void (*mark_machine_status) PARAMS ((struct function *)); 138 139 /* Likewise, but for language-specific data. */ 140 void (*init_lang_status) PARAMS ((struct function *)); 141 void (*save_lang_status) PARAMS ((struct function *)); 142 void (*restore_lang_status) PARAMS ((struct function *)); 143 void (*mark_lang_status) PARAMS ((struct function *)); 144 void (*free_lang_status) PARAMS ((struct function *)); 145 146 /* The FUNCTION_DECL for an inline function currently being expanded. */ 147 tree inline_function_decl; 148 149 /* The currently compiled function. */ 150 struct function *cfun = 0; 151 152 /* These arrays record the INSN_UIDs of the prologue and epilogue insns. */ 153 static varray_type prologue; 154 static varray_type epilogue; 155 156 /* Array of INSN_UIDs to hold the INSN_UIDs for each sibcall epilogue 157 in this function. */ 158 static varray_type sibcall_epilogue; 159 160 /* In order to evaluate some expressions, such as function calls returning 161 structures in memory, we need to temporarily allocate stack locations. 162 We record each allocated temporary in the following structure. 163 164 Associated with each temporary slot is a nesting level. When we pop up 165 one level, all temporaries associated with the previous level are freed. 166 Normally, all temporaries are freed after the execution of the statement 167 in which they were created. However, if we are inside a ({...}) grouping, 168 the result may be in a temporary and hence must be preserved. If the 169 result could be in a temporary, we preserve it if we can determine which 170 one it is in. If we cannot determine which temporary may contain the 171 result, all temporaries are preserved. A temporary is preserved by 172 pretending it was allocated at the previous nesting level. 173 174 Automatic variables are also assigned temporary slots, at the nesting 175 level where they are defined. They are marked a "kept" so that 176 free_temp_slots will not free them. */ 177 178 struct temp_slot 179 { 180 /* Points to next temporary slot. */ 181 struct temp_slot *next; 182 /* The rtx to used to reference the slot. */ 183 rtx slot; 184 /* The rtx used to represent the address if not the address of the 185 slot above. May be an EXPR_LIST if multiple addresses exist. */ 186 rtx address; 187 /* The alignment (in bits) of the slot. */ 188 unsigned int align; 189 /* The size, in units, of the slot. */ 190 HOST_WIDE_INT size; 191 /* The type of the object in the slot, or zero if it doesn't correspond 192 to a type. We use this to determine whether a slot can be reused. 193 It can be reused if objects of the type of the new slot will always 194 conflict with objects of the type of the old slot. */ 195 tree type; 196 /* The value of `sequence_rtl_expr' when this temporary is allocated. */ 197 tree rtl_expr; 198 /* Non-zero if this temporary is currently in use. */ 199 char in_use; 200 /* Non-zero if this temporary has its address taken. */ 201 char addr_taken; 202 /* Nesting level at which this slot is being used. */ 203 int level; 204 /* Non-zero if this should survive a call to free_temp_slots. */ 205 int keep; 206 /* The offset of the slot from the frame_pointer, including extra space 207 for alignment. This info is for combine_temp_slots. */ 208 HOST_WIDE_INT base_offset; 209 /* The size of the slot, including extra space for alignment. This 210 info is for combine_temp_slots. */ 211 HOST_WIDE_INT full_size; 212 }; 213 214 /* This structure is used to record MEMs or pseudos used to replace VAR, any 215 SUBREGs of VAR, and any MEMs containing VAR as an address. We need to 216 maintain this list in case two operands of an insn were required to match; 217 in that case we must ensure we use the same replacement. */ 218 219 struct fixup_replacement 220 { 221 rtx old; 222 rtx new; 223 struct fixup_replacement *next; 224 }; 225 226 struct insns_for_mem_entry 227 { 228 /* The KEY in HE will be a MEM. */ 229 struct hash_entry he; 230 /* These are the INSNS which reference the MEM. */ 231 rtx insns; 232 }; 233 234 /* Forward declarations. */ 235 236 static rtx assign_stack_local_1 PARAMS ((enum machine_mode, HOST_WIDE_INT, 237 int, struct function *)); 238 static struct temp_slot *find_temp_slot_from_address PARAMS ((rtx)); 239 static void put_reg_into_stack PARAMS ((struct function *, rtx, tree, 240 enum machine_mode, enum machine_mode, 241 int, unsigned int, int, 242 struct hash_table *)); 243 static void schedule_fixup_var_refs PARAMS ((struct function *, rtx, tree, 244 enum machine_mode, 245 struct hash_table *)); 246 static void fixup_var_refs PARAMS ((rtx, enum machine_mode, int, rtx, 247 struct hash_table *)); 248 static struct fixup_replacement 249 *find_fixup_replacement PARAMS ((struct fixup_replacement **, rtx)); 250 static void fixup_var_refs_insns PARAMS ((rtx, rtx, enum machine_mode, 251 int, int, rtx)); 252 static void fixup_var_refs_insns_with_hash 253 PARAMS ((struct hash_table *, rtx, 254 enum machine_mode, int, rtx)); 255 static void fixup_var_refs_insn PARAMS ((rtx, rtx, enum machine_mode, 256 int, int, rtx)); 257 static void fixup_var_refs_1 PARAMS ((rtx, enum machine_mode, rtx *, rtx, 258 struct fixup_replacement **, rtx)); 259 static rtx fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, int)); 260 static rtx walk_fixup_memory_subreg PARAMS ((rtx, rtx, enum machine_mode, 261 int)); 262 static rtx fixup_stack_1 PARAMS ((rtx, rtx)); 263 static void optimize_bit_field PARAMS ((rtx, rtx, rtx *)); 264 static void instantiate_decls PARAMS ((tree, int)); 265 static void instantiate_decls_1 PARAMS ((tree, int)); 266 static void instantiate_decl PARAMS ((rtx, HOST_WIDE_INT, int)); 267 static rtx instantiate_new_reg PARAMS ((rtx, HOST_WIDE_INT *)); 268 static int instantiate_virtual_regs_1 PARAMS ((rtx *, rtx, int)); 269 static void delete_handlers PARAMS ((void)); 270 static void pad_to_arg_alignment PARAMS ((struct args_size *, int, 271 struct args_size *)); 272 #ifndef ARGS_GROW_DOWNWARD 273 static void pad_below PARAMS ((struct args_size *, enum machine_mode, 274 tree)); 275 #endif 276 static rtx round_trampoline_addr PARAMS ((rtx)); 277 static rtx adjust_trampoline_addr PARAMS ((rtx)); 278 static tree *identify_blocks_1 PARAMS ((rtx, tree *, tree *, tree *)); 279 static void reorder_blocks_0 PARAMS ((tree)); 280 static void reorder_blocks_1 PARAMS ((rtx, tree, varray_type *)); 281 static void reorder_fix_fragments PARAMS ((tree)); 282 static tree blocks_nreverse PARAMS ((tree)); 283 static int all_blocks PARAMS ((tree, tree *)); 284 static tree *get_block_vector PARAMS ((tree, int *)); 285 extern tree debug_find_var_in_block_tree PARAMS ((tree, tree)); 286 /* We always define `record_insns' even if its not used so that we 287 can always export `prologue_epilogue_contains'. */ 288 static void record_insns PARAMS ((rtx, varray_type *)) ATTRIBUTE_UNUSED; 289 static int contains PARAMS ((rtx, varray_type)); 290 #ifdef HAVE_return 291 static void emit_return_into_block PARAMS ((basic_block, rtx)); 292 #endif 293 static void put_addressof_into_stack PARAMS ((rtx, struct hash_table *)); 294 static bool purge_addressof_1 PARAMS ((rtx *, rtx, int, int, 295 struct hash_table *)); 296 static void purge_single_hard_subreg_set PARAMS ((rtx)); 297 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX) 298 static rtx keep_stack_depressed PARAMS ((rtx)); 299 #endif 300 static int is_addressof PARAMS ((rtx *, void *)); 301 static struct hash_entry *insns_for_mem_newfunc PARAMS ((struct hash_entry *, 302 struct hash_table *, 303 hash_table_key)); 304 static unsigned long insns_for_mem_hash PARAMS ((hash_table_key)); 305 static bool insns_for_mem_comp PARAMS ((hash_table_key, hash_table_key)); 306 static int insns_for_mem_walk PARAMS ((rtx *, void *)); 307 static void compute_insns_for_mem PARAMS ((rtx, rtx, struct hash_table *)); 308 static void mark_function_status PARAMS ((struct function *)); 309 static void maybe_mark_struct_function PARAMS ((void *)); 310 static void prepare_function_start PARAMS ((void)); 311 static void do_clobber_return_reg PARAMS ((rtx, void *)); 312 static void do_use_return_reg PARAMS ((rtx, void *)); 313 314 /* Pointer to chain of `struct function' for containing functions. */ 315 static struct function *outer_function_chain; 316 317 /* Given a function decl for a containing function, 318 return the `struct function' for it. */ 319 320 struct function * 321 find_function_data (decl) 322 tree decl; 323 { 324 struct function *p; 325 326 for (p = outer_function_chain; p; p = p->outer) 327 if (p->decl == decl) 328 return p; 329 330 abort (); 331 } 332 333 /* Save the current context for compilation of a nested function. 334 This is called from language-specific code. The caller should use 335 the save_lang_status callback to save any language-specific state, 336 since this function knows only about language-independent 337 variables. */ 338 339 void 340 push_function_context_to (context) 341 tree context; 342 { 343 struct function *p; 344 345 if (context) 346 { 347 if (context == current_function_decl) 348 cfun->contains_functions = 1; 349 else 350 { 351 struct function *containing = find_function_data (context); 352 containing->contains_functions = 1; 353 } 354 } 355 356 if (cfun == 0) 357 init_dummy_function_start (); 358 p = cfun; 359 360 p->outer = outer_function_chain; 361 outer_function_chain = p; 362 p->fixup_var_refs_queue = 0; 363 364 if (save_lang_status) 365 (*save_lang_status) (p); 366 367 cfun = 0; 368 } 369 370 void 371 push_function_context () 372 { 373 push_function_context_to (current_function_decl); 374 } 375 376 /* Restore the last saved context, at the end of a nested function. 377 This function is called from language-specific code. */ 378 379 void 380 pop_function_context_from (context) 381 tree context ATTRIBUTE_UNUSED; 382 { 383 struct function *p = outer_function_chain; 384 struct var_refs_queue *queue; 385 386 cfun = p; 387 outer_function_chain = p->outer; 388 389 current_function_decl = p->decl; 390 reg_renumber = 0; 391 392 restore_emit_status (p); 393 394 if (restore_lang_status) 395 (*restore_lang_status) (p); 396 397 /* Finish doing put_var_into_stack for any of our variables which became 398 addressable during the nested function. If only one entry has to be 399 fixed up, just do that one. Otherwise, first make a list of MEMs that 400 are not to be unshared. */ 401 if (p->fixup_var_refs_queue == 0) 402 ; 403 else if (p->fixup_var_refs_queue->next == 0) 404 fixup_var_refs (p->fixup_var_refs_queue->modified, 405 p->fixup_var_refs_queue->promoted_mode, 406 p->fixup_var_refs_queue->unsignedp, 407 p->fixup_var_refs_queue->modified, 0); 408 else 409 { 410 rtx list = 0; 411 412 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next) 413 list = gen_rtx_EXPR_LIST (VOIDmode, queue->modified, list); 414 415 for (queue = p->fixup_var_refs_queue; queue; queue = queue->next) 416 fixup_var_refs (queue->modified, queue->promoted_mode, 417 queue->unsignedp, list, 0); 418 419 } 420 421 p->fixup_var_refs_queue = 0; 422 423 /* Reset variables that have known state during rtx generation. */ 424 rtx_equal_function_value_matters = 1; 425 virtuals_instantiated = 0; 426 generating_concat_p = 1; 427 } 428 429 void 430 pop_function_context () 431 { 432 pop_function_context_from (current_function_decl); 433 } 434 435 /* Clear out all parts of the state in F that can safely be discarded 436 after the function has been parsed, but not compiled, to let 437 garbage collection reclaim the memory. */ 438 439 void 440 free_after_parsing (f) 441 struct function *f; 442 { 443 /* f->expr->forced_labels is used by code generation. */ 444 /* f->emit->regno_reg_rtx is used by code generation. */ 445 /* f->varasm is used by code generation. */ 446 /* f->eh->eh_return_stub_label is used by code generation. */ 447 448 if (free_lang_status) 449 (*free_lang_status) (f); 450 free_stmt_status (f); 451 } 452 453 /* Clear out all parts of the state in F that can safely be discarded 454 after the function has been compiled, to let garbage collection 455 reclaim the memory. */ 456 457 void 458 free_after_compilation (f) 459 struct function *f; 460 { 461 free_eh_status (f); 462 free_expr_status (f); 463 free_emit_status (f); 464 free_varasm_status (f); 465 466 if (free_machine_status) 467 (*free_machine_status) (f); 468 469 if (f->x_parm_reg_stack_loc) 470 free (f->x_parm_reg_stack_loc); 471 472 f->x_temp_slots = NULL; 473 f->arg_offset_rtx = NULL; 474 f->return_rtx = NULL; 475 f->internal_arg_pointer = NULL; 476 f->x_nonlocal_labels = NULL; 477 f->x_nonlocal_goto_handler_slots = NULL; 478 f->x_nonlocal_goto_handler_labels = NULL; 479 f->x_nonlocal_goto_stack_level = NULL; 480 f->x_cleanup_label = NULL; 481 f->x_return_label = NULL; 482 f->x_save_expr_regs = NULL; 483 f->x_stack_slot_list = NULL; 484 f->x_rtl_expr_chain = NULL; 485 f->x_tail_recursion_label = NULL; 486 f->x_tail_recursion_reentry = NULL; 487 f->x_arg_pointer_save_area = NULL; 488 f->x_clobber_return_insn = NULL; 489 f->x_context_display = NULL; 490 f->x_trampoline_list = NULL; 491 f->x_parm_birth_insn = NULL; 492 f->x_last_parm_insn = NULL; 493 f->x_parm_reg_stack_loc = NULL; 494 f->fixup_var_refs_queue = NULL; 495 f->original_arg_vector = NULL; 496 f->original_decl_initial = NULL; 497 f->inl_last_parm_insn = NULL; 498 f->epilogue_delay_list = NULL; 499 } 500 501 /* Allocate fixed slots in the stack frame of the current function. */ 502 503 /* Return size needed for stack frame based on slots so far allocated in 504 function F. 505 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY; 506 the caller may have to do that. */ 507 508 HOST_WIDE_INT 509 get_func_frame_size (f) 510 struct function *f; 511 { 512 #ifdef FRAME_GROWS_DOWNWARD 513 return -f->x_frame_offset; 514 #else 515 return f->x_frame_offset; 516 #endif 517 } 518 519 /* Return size needed for stack frame based on slots so far allocated. 520 This size counts from zero. It is not rounded to PREFERRED_STACK_BOUNDARY; 521 the caller may have to do that. */ 522 HOST_WIDE_INT 523 get_frame_size () 524 { 525 return get_func_frame_size (cfun); 526 } 527 528 /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it 529 with machine mode MODE. 530 531 ALIGN controls the amount of alignment for the address of the slot: 532 0 means according to MODE, 533 -1 means use BIGGEST_ALIGNMENT and round size to multiple of that, 534 positive specifies alignment boundary in bits. 535 536 We do not round to stack_boundary here. 537 538 FUNCTION specifies the function to allocate in. */ 539 540 static rtx 541 assign_stack_local_1 (mode, size, align, function) 542 enum machine_mode mode; 543 HOST_WIDE_INT size; 544 int align; 545 struct function *function; 546 { 547 rtx x, addr; 548 int bigend_correction = 0; 549 int alignment; 550 int frame_off, frame_alignment, frame_phase; 551 552 if (align == 0) 553 { 554 tree type; 555 556 if (mode == BLKmode) 557 alignment = BIGGEST_ALIGNMENT; 558 else 559 alignment = GET_MODE_ALIGNMENT (mode); 560 561 /* Allow the target to (possibly) increase the alignment of this 562 stack slot. */ 563 type = type_for_mode (mode, 0); 564 if (type) 565 alignment = LOCAL_ALIGNMENT (type, alignment); 566 567 alignment /= BITS_PER_UNIT; 568 } 569 else if (align == -1) 570 { 571 alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT; 572 size = CEIL_ROUND (size, alignment); 573 } 574 else 575 alignment = align / BITS_PER_UNIT; 576 577 #ifdef FRAME_GROWS_DOWNWARD 578 function->x_frame_offset -= size; 579 #endif 580 581 /* Ignore alignment we can't do with expected alignment of the boundary. */ 582 if (alignment * BITS_PER_UNIT > PREFERRED_STACK_BOUNDARY) 583 alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; 584 585 if (function->stack_alignment_needed < alignment * BITS_PER_UNIT) 586 function->stack_alignment_needed = alignment * BITS_PER_UNIT; 587 588 /* Calculate how many bytes the start of local variables is off from 589 stack alignment. */ 590 frame_alignment = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; 591 frame_off = STARTING_FRAME_OFFSET % frame_alignment; 592 frame_phase = frame_off ? frame_alignment - frame_off : 0; 593 594 /* Round frame offset to that alignment. 595 We must be careful here, since FRAME_OFFSET might be negative and 596 division with a negative dividend isn't as well defined as we might 597 like. So we instead assume that ALIGNMENT is a power of two and 598 use logical operations which are unambiguous. */ 599 #ifdef FRAME_GROWS_DOWNWARD 600 function->x_frame_offset = FLOOR_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase; 601 #else 602 function->x_frame_offset = CEIL_ROUND (function->x_frame_offset - frame_phase, alignment) + frame_phase; 603 #endif 604 605 /* On a big-endian machine, if we are allocating more space than we will use, 606 use the least significant bytes of those that are allocated. */ 607 if (BYTES_BIG_ENDIAN && mode != BLKmode) 608 bigend_correction = size - GET_MODE_SIZE (mode); 609 610 /* If we have already instantiated virtual registers, return the actual 611 address relative to the frame pointer. */ 612 if (function == cfun && virtuals_instantiated) 613 addr = plus_constant (frame_pointer_rtx, 614 (frame_offset + bigend_correction 615 + STARTING_FRAME_OFFSET)); 616 else 617 addr = plus_constant (virtual_stack_vars_rtx, 618 function->x_frame_offset + bigend_correction); 619 620 #ifndef FRAME_GROWS_DOWNWARD 621 function->x_frame_offset += size; 622 #endif 623 624 x = gen_rtx_MEM (mode, addr); 625 626 function->x_stack_slot_list 627 = gen_rtx_EXPR_LIST (VOIDmode, x, function->x_stack_slot_list); 628 629 return x; 630 } 631 632 /* Wrapper around assign_stack_local_1; assign a local stack slot for the 633 current function. */ 634 635 rtx 636 assign_stack_local (mode, size, align) 637 enum machine_mode mode; 638 HOST_WIDE_INT size; 639 int align; 640 { 641 return assign_stack_local_1 (mode, size, align, cfun); 642 } 643 644 /* Allocate a temporary stack slot and record it for possible later 645 reuse. 646 647 MODE is the machine mode to be given to the returned rtx. 648 649 SIZE is the size in units of the space required. We do no rounding here 650 since assign_stack_local will do any required rounding. 651 652 KEEP is 1 if this slot is to be retained after a call to 653 free_temp_slots. Automatic variables for a block are allocated 654 with this flag. KEEP is 2 if we allocate a longer term temporary, 655 whose lifetime is controlled by CLEANUP_POINT_EXPRs. KEEP is 3 656 if we are to allocate something at an inner level to be treated as 657 a variable in the block (e.g., a SAVE_EXPR). 658 659 TYPE is the type that will be used for the stack slot. */ 660 661 rtx 662 assign_stack_temp_for_type (mode, size, keep, type) 663 enum machine_mode mode; 664 HOST_WIDE_INT size; 665 int keep; 666 tree type; 667 { 668 unsigned int align; 669 struct temp_slot *p, *best_p = 0; 670 rtx slot; 671 672 /* If SIZE is -1 it means that somebody tried to allocate a temporary 673 of a variable size. */ 674 if (size == -1) 675 abort (); 676 677 if (mode == BLKmode) 678 align = BIGGEST_ALIGNMENT; 679 else 680 align = GET_MODE_ALIGNMENT (mode); 681 682 if (! type) 683 type = type_for_mode (mode, 0); 684 685 if (type) 686 align = LOCAL_ALIGNMENT (type, align); 687 688 /* Try to find an available, already-allocated temporary of the proper 689 mode which meets the size and alignment requirements. Choose the 690 smallest one with the closest alignment. */ 691 for (p = temp_slots; p; p = p->next) 692 if (p->align >= align && p->size >= size && GET_MODE (p->slot) == mode 693 && ! p->in_use 694 && objects_must_conflict_p (p->type, type) 695 && (best_p == 0 || best_p->size > p->size 696 || (best_p->size == p->size && best_p->align > p->align))) 697 { 698 if (p->align == align && p->size == size) 699 { 700 best_p = 0; 701 break; 702 } 703 best_p = p; 704 } 705 706 /* Make our best, if any, the one to use. */ 707 if (best_p) 708 { 709 /* If there are enough aligned bytes left over, make them into a new 710 temp_slot so that the extra bytes don't get wasted. Do this only 711 for BLKmode slots, so that we can be sure of the alignment. */ 712 if (GET_MODE (best_p->slot) == BLKmode) 713 { 714 int alignment = best_p->align / BITS_PER_UNIT; 715 HOST_WIDE_INT rounded_size = CEIL_ROUND (size, alignment); 716 717 if (best_p->size - rounded_size >= alignment) 718 { 719 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot)); 720 p->in_use = p->addr_taken = 0; 721 p->size = best_p->size - rounded_size; 722 p->base_offset = best_p->base_offset + rounded_size; 723 p->full_size = best_p->full_size - rounded_size; 724 p->slot = gen_rtx_MEM (BLKmode, 725 plus_constant (XEXP (best_p->slot, 0), 726 rounded_size)); 727 p->align = best_p->align; 728 p->address = 0; 729 p->rtl_expr = 0; 730 p->type = best_p->type; 731 p->next = temp_slots; 732 temp_slots = p; 733 734 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, p->slot, 735 stack_slot_list); 736 737 best_p->size = rounded_size; 738 best_p->full_size = rounded_size; 739 } 740 } 741 742 p = best_p; 743 } 744 745 /* If we still didn't find one, make a new temporary. */ 746 if (p == 0) 747 { 748 HOST_WIDE_INT frame_offset_old = frame_offset; 749 750 p = (struct temp_slot *) ggc_alloc (sizeof (struct temp_slot)); 751 752 /* We are passing an explicit alignment request to assign_stack_local. 753 One side effect of that is assign_stack_local will not round SIZE 754 to ensure the frame offset remains suitably aligned. 755 756 So for requests which depended on the rounding of SIZE, we go ahead 757 and round it now. We also make sure ALIGNMENT is at least 758 BIGGEST_ALIGNMENT. */ 759 if (mode == BLKmode && align < BIGGEST_ALIGNMENT) 760 abort (); 761 p->slot = assign_stack_local (mode, 762 (mode == BLKmode 763 ? CEIL_ROUND (size, align / BITS_PER_UNIT) 764 : size), 765 align); 766 767 p->align = align; 768 769 /* The following slot size computation is necessary because we don't 770 know the actual size of the temporary slot until assign_stack_local 771 has performed all the frame alignment and size rounding for the 772 requested temporary. Note that extra space added for alignment 773 can be either above or below this stack slot depending on which 774 way the frame grows. We include the extra space if and only if it 775 is above this slot. */ 776 #ifdef FRAME_GROWS_DOWNWARD 777 p->size = frame_offset_old - frame_offset; 778 #else 779 p->size = size; 780 #endif 781 782 /* Now define the fields used by combine_temp_slots. */ 783 #ifdef FRAME_GROWS_DOWNWARD 784 p->base_offset = frame_offset; 785 p->full_size = frame_offset_old - frame_offset; 786 #else 787 p->base_offset = frame_offset_old; 788 p->full_size = frame_offset - frame_offset_old; 789 #endif 790 p->address = 0; 791 p->next = temp_slots; 792 temp_slots = p; 793 } 794 795 p->in_use = 1; 796 p->addr_taken = 0; 797 p->rtl_expr = seq_rtl_expr; 798 p->type = type; 799 800 if (keep == 2) 801 { 802 p->level = target_temp_slot_level; 803 p->keep = 0; 804 } 805 else if (keep == 3) 806 { 807 p->level = var_temp_slot_level; 808 p->keep = 0; 809 } 810 else 811 { 812 p->level = temp_slot_level; 813 p->keep = keep; 814 } 815 816 817 /* Create a new MEM rtx to avoid clobbering MEM flags of old slots. */ 818 slot = gen_rtx_MEM (mode, XEXP (p->slot, 0)); 819 stack_slot_list = gen_rtx_EXPR_LIST (VOIDmode, slot, stack_slot_list); 820 821 /* If we know the alias set for the memory that will be used, use 822 it. If there's no TYPE, then we don't know anything about the 823 alias set for the memory. */ 824 set_mem_alias_set (slot, type ? get_alias_set (type) : 0); 825 set_mem_align (slot, align); 826 827 /* If a type is specified, set the relevant flags. */ 828 if (type != 0) 829 { 830 RTX_UNCHANGING_P (slot) = (lang_hooks.honor_readonly 831 && TYPE_READONLY (type)); 832 MEM_VOLATILE_P (slot) = TYPE_VOLATILE (type); 833 MEM_SET_IN_STRUCT_P (slot, AGGREGATE_TYPE_P (type)); 834 } 835 836 return slot; 837 } 838 839 /* Allocate a temporary stack slot and record it for possible later 840 reuse. First three arguments are same as in preceding function. */ 841 842 rtx 843 assign_stack_temp (mode, size, keep) 844 enum machine_mode mode; 845 HOST_WIDE_INT size; 846 int keep; 847 { 848 return assign_stack_temp_for_type (mode, size, keep, NULL_TREE); 849 } 850 851 /* Assign a temporary. 852 If TYPE_OR_DECL is a decl, then we are doing it on behalf of the decl 853 and so that should be used in error messages. In either case, we 854 allocate of the given type. 855 KEEP is as for assign_stack_temp. 856 MEMORY_REQUIRED is 1 if the result must be addressable stack memory; 857 it is 0 if a register is OK. 858 DONT_PROMOTE is 1 if we should not promote values in register 859 to wider modes. */ 860 861 rtx 862 assign_temp (type_or_decl, keep, memory_required, dont_promote) 863 tree type_or_decl; 864 int keep; 865 int memory_required; 866 int dont_promote ATTRIBUTE_UNUSED; 867 { 868 tree type, decl; 869 enum machine_mode mode; 870 #ifndef PROMOTE_FOR_CALL_ONLY 871 int unsignedp; 872 #endif 873 874 if (DECL_P (type_or_decl)) 875 decl = type_or_decl, type = TREE_TYPE (decl); 876 else 877 decl = NULL, type = type_or_decl; 878 879 mode = TYPE_MODE (type); 880 #ifndef PROMOTE_FOR_CALL_ONLY 881 unsignedp = TREE_UNSIGNED (type); 882 #endif 883 884 if (mode == BLKmode || memory_required) 885 { 886 HOST_WIDE_INT size = int_size_in_bytes (type); 887 rtx tmp; 888 889 /* Zero sized arrays are GNU C extension. Set size to 1 to avoid 890 problems with allocating the stack space. */ 891 if (size == 0) 892 size = 1; 893 894 /* Unfortunately, we don't yet know how to allocate variable-sized 895 temporaries. However, sometimes we have a fixed upper limit on 896 the size (which is stored in TYPE_ARRAY_MAX_SIZE) and can use that 897 instead. This is the case for Chill variable-sized strings. */ 898 if (size == -1 && TREE_CODE (type) == ARRAY_TYPE 899 && TYPE_ARRAY_MAX_SIZE (type) != NULL_TREE 900 && host_integerp (TYPE_ARRAY_MAX_SIZE (type), 1)) 901 size = tree_low_cst (TYPE_ARRAY_MAX_SIZE (type), 1); 902 903 /* The size of the temporary may be too large to fit into an integer. */ 904 /* ??? Not sure this should happen except for user silliness, so limit 905 this to things that aren't compiler-generated temporaries. The 906 rest of the time we'll abort in assign_stack_temp_for_type. */ 907 if (decl && size == -1 908 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST) 909 { 910 error_with_decl (decl, "size of variable `%s' is too large"); 911 size = 1; 912 } 913 914 tmp = assign_stack_temp_for_type (mode, size, keep, type); 915 return tmp; 916 } 917 918 #ifndef PROMOTE_FOR_CALL_ONLY 919 if (! dont_promote) 920 mode = promote_mode (type, mode, &unsignedp, 0); 921 #endif 922 923 return gen_reg_rtx (mode); 924 } 925 926 /* Combine temporary stack slots which are adjacent on the stack. 927 928 This allows for better use of already allocated stack space. This is only 929 done for BLKmode slots because we can be sure that we won't have alignment 930 problems in this case. */ 931 932 void 933 combine_temp_slots () 934 { 935 struct temp_slot *p, *q; 936 struct temp_slot *prev_p, *prev_q; 937 int num_slots; 938 939 /* We can't combine slots, because the information about which slot 940 is in which alias set will be lost. */ 941 if (flag_strict_aliasing) 942 return; 943 944 /* If there are a lot of temp slots, don't do anything unless 945 high levels of optimization. */ 946 if (! flag_expensive_optimizations) 947 for (p = temp_slots, num_slots = 0; p; p = p->next, num_slots++) 948 if (num_slots > 100 || (num_slots > 10 && optimize == 0)) 949 return; 950 951 for (p = temp_slots, prev_p = 0; p; p = prev_p ? prev_p->next : temp_slots) 952 { 953 int delete_p = 0; 954 955 if (! p->in_use && GET_MODE (p->slot) == BLKmode) 956 for (q = p->next, prev_q = p; q; q = prev_q->next) 957 { 958 int delete_q = 0; 959 if (! q->in_use && GET_MODE (q->slot) == BLKmode) 960 { 961 if (p->base_offset + p->full_size == q->base_offset) 962 { 963 /* Q comes after P; combine Q into P. */ 964 p->size += q->size; 965 p->full_size += q->full_size; 966 delete_q = 1; 967 } 968 else if (q->base_offset + q->full_size == p->base_offset) 969 { 970 /* P comes after Q; combine P into Q. */ 971 q->size += p->size; 972 q->full_size += p->full_size; 973 delete_p = 1; 974 break; 975 } 976 } 977 /* Either delete Q or advance past it. */ 978 if (delete_q) 979 prev_q->next = q->next; 980 else 981 prev_q = q; 982 } 983 /* Either delete P or advance past it. */ 984 if (delete_p) 985 { 986 if (prev_p) 987 prev_p->next = p->next; 988 else 989 temp_slots = p->next; 990 } 991 else 992 prev_p = p; 993 } 994 } 995 996 /* Find the temp slot corresponding to the object at address X. */ 997 998 static struct temp_slot * 999 find_temp_slot_from_address (x) 1000 rtx x; 1001 { 1002 struct temp_slot *p; 1003 rtx next; 1004 1005 for (p = temp_slots; p; p = p->next) 1006 { 1007 if (! p->in_use) 1008 continue; 1009 1010 else if (XEXP (p->slot, 0) == x 1011 || p->address == x 1012 || (GET_CODE (x) == PLUS 1013 && XEXP (x, 0) == virtual_stack_vars_rtx 1014 && GET_CODE (XEXP (x, 1)) == CONST_INT 1015 && INTVAL (XEXP (x, 1)) >= p->base_offset 1016 && INTVAL (XEXP (x, 1)) < p->base_offset + p->full_size)) 1017 return p; 1018 1019 else if (p->address != 0 && GET_CODE (p->address) == EXPR_LIST) 1020 for (next = p->address; next; next = XEXP (next, 1)) 1021 if (XEXP (next, 0) == x) 1022 return p; 1023 } 1024 1025 /* If we have a sum involving a register, see if it points to a temp 1026 slot. */ 1027 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG 1028 && (p = find_temp_slot_from_address (XEXP (x, 0))) != 0) 1029 return p; 1030 else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == REG 1031 && (p = find_temp_slot_from_address (XEXP (x, 1))) != 0) 1032 return p; 1033 1034 return 0; 1035 } 1036 1037 /* Indicate that NEW is an alternate way of referring to the temp slot 1038 that previously was known by OLD. */ 1039 1040 void 1041 update_temp_slot_address (old, new) 1042 rtx old, new; 1043 { 1044 struct temp_slot *p; 1045 1046 if (rtx_equal_p (old, new)) 1047 return; 1048 1049 p = find_temp_slot_from_address (old); 1050 1051 /* If we didn't find one, see if both OLD is a PLUS. If so, and NEW 1052 is a register, see if one operand of the PLUS is a temporary 1053 location. If so, NEW points into it. Otherwise, if both OLD and 1054 NEW are a PLUS and if there is a register in common between them. 1055 If so, try a recursive call on those values. */ 1056 if (p == 0) 1057 { 1058 if (GET_CODE (old) != PLUS) 1059 return; 1060 1061 if (GET_CODE (new) == REG) 1062 { 1063 update_temp_slot_address (XEXP (old, 0), new); 1064 update_temp_slot_address (XEXP (old, 1), new); 1065 return; 1066 } 1067 else if (GET_CODE (new) != PLUS) 1068 return; 1069 1070 if (rtx_equal_p (XEXP (old, 0), XEXP (new, 0))) 1071 update_temp_slot_address (XEXP (old, 1), XEXP (new, 1)); 1072 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 0))) 1073 update_temp_slot_address (XEXP (old, 0), XEXP (new, 1)); 1074 else if (rtx_equal_p (XEXP (old, 0), XEXP (new, 1))) 1075 update_temp_slot_address (XEXP (old, 1), XEXP (new, 0)); 1076 else if (rtx_equal_p (XEXP (old, 1), XEXP (new, 1))) 1077 update_temp_slot_address (XEXP (old, 0), XEXP (new, 0)); 1078 1079 return; 1080 } 1081 1082 /* Otherwise add an alias for the temp's address. */ 1083 else if (p->address == 0) 1084 p->address = new; 1085 else 1086 { 1087 if (GET_CODE (p->address) != EXPR_LIST) 1088 p->address = gen_rtx_EXPR_LIST (VOIDmode, p->address, NULL_RTX); 1089 1090 p->address = gen_rtx_EXPR_LIST (VOIDmode, new, p->address); 1091 } 1092 } 1093 1094 /* If X could be a reference to a temporary slot, mark the fact that its 1095 address was taken. */ 1096 1097 void 1098 mark_temp_addr_taken (x) 1099 rtx x; 1100 { 1101 struct temp_slot *p; 1102 1103 if (x == 0) 1104 return; 1105 1106 /* If X is not in memory or is at a constant address, it cannot be in 1107 a temporary slot. */ 1108 if (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) 1109 return; 1110 1111 p = find_temp_slot_from_address (XEXP (x, 0)); 1112 if (p != 0) 1113 p->addr_taken = 1; 1114 } 1115 1116 /* If X could be a reference to a temporary slot, mark that slot as 1117 belonging to the to one level higher than the current level. If X 1118 matched one of our slots, just mark that one. Otherwise, we can't 1119 easily predict which it is, so upgrade all of them. Kept slots 1120 need not be touched. 1121 1122 This is called when an ({...}) construct occurs and a statement 1123 returns a value in memory. */ 1124 1125 void 1126 preserve_temp_slots (x) 1127 rtx x; 1128 { 1129 struct temp_slot *p = 0; 1130 1131 /* If there is no result, we still might have some objects whose address 1132 were taken, so we need to make sure they stay around. */ 1133 if (x == 0) 1134 { 1135 for (p = temp_slots; p; p = p->next) 1136 if (p->in_use && p->level == temp_slot_level && p->addr_taken) 1137 p->level--; 1138 1139 return; 1140 } 1141 1142 /* If X is a register that is being used as a pointer, see if we have 1143 a temporary slot we know it points to. To be consistent with 1144 the code below, we really should preserve all non-kept slots 1145 if we can't find a match, but that seems to be much too costly. */ 1146 if (GET_CODE (x) == REG && REG_POINTER (x)) 1147 p = find_temp_slot_from_address (x); 1148 1149 /* If X is not in memory or is at a constant address, it cannot be in 1150 a temporary slot, but it can contain something whose address was 1151 taken. */ 1152 if (p == 0 && (GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))) 1153 { 1154 for (p = temp_slots; p; p = p->next) 1155 if (p->in_use && p->level == temp_slot_level && p->addr_taken) 1156 p->level--; 1157 1158 return; 1159 } 1160 1161 /* First see if we can find a match. */ 1162 if (p == 0) 1163 p = find_temp_slot_from_address (XEXP (x, 0)); 1164 1165 if (p != 0) 1166 { 1167 /* Move everything at our level whose address was taken to our new 1168 level in case we used its address. */ 1169 struct temp_slot *q; 1170 1171 if (p->level == temp_slot_level) 1172 { 1173 for (q = temp_slots; q; q = q->next) 1174 if (q != p && q->addr_taken && q->level == p->level) 1175 q->level--; 1176 1177 p->level--; 1178 p->addr_taken = 0; 1179 } 1180 return; 1181 } 1182 1183 /* Otherwise, preserve all non-kept slots at this level. */ 1184 for (p = temp_slots; p; p = p->next) 1185 if (p->in_use && p->level == temp_slot_level && ! p->keep) 1186 p->level--; 1187 } 1188 1189 /* X is the result of an RTL_EXPR. If it is a temporary slot associated 1190 with that RTL_EXPR, promote it into a temporary slot at the present 1191 level so it will not be freed when we free slots made in the 1192 RTL_EXPR. */ 1193 1194 void 1195 preserve_rtl_expr_result (x) 1196 rtx x; 1197 { 1198 struct temp_slot *p; 1199 1200 /* If X is not in memory or is at a constant address, it cannot be in 1201 a temporary slot. */ 1202 if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0))) 1203 return; 1204 1205 /* If we can find a match, move it to our level unless it is already at 1206 an upper level. */ 1207 p = find_temp_slot_from_address (XEXP (x, 0)); 1208 if (p != 0) 1209 { 1210 p->level = MIN (p->level, temp_slot_level); 1211 p->rtl_expr = 0; 1212 } 1213 1214 return; 1215 } 1216 1217 /* Free all temporaries used so far. This is normally called at the end 1218 of generating code for a statement. Don't free any temporaries 1219 currently in use for an RTL_EXPR that hasn't yet been emitted. 1220 We could eventually do better than this since it can be reused while 1221 generating the same RTL_EXPR, but this is complex and probably not 1222 worthwhile. */ 1223 1224 void 1225 free_temp_slots () 1226 { 1227 struct temp_slot *p; 1228 1229 for (p = temp_slots; p; p = p->next) 1230 if (p->in_use && p->level == temp_slot_level && ! p->keep 1231 && p->rtl_expr == 0) 1232 p->in_use = 0; 1233 1234 combine_temp_slots (); 1235 } 1236 1237 /* Free all temporary slots used in T, an RTL_EXPR node. */ 1238 1239 void 1240 free_temps_for_rtl_expr (t) 1241 tree t; 1242 { 1243 struct temp_slot *p; 1244 1245 for (p = temp_slots; p; p = p->next) 1246 if (p->rtl_expr == t) 1247 { 1248 /* If this slot is below the current TEMP_SLOT_LEVEL, then it 1249 needs to be preserved. This can happen if a temporary in 1250 the RTL_EXPR was addressed; preserve_temp_slots will move 1251 the temporary into a higher level. */ 1252 if (temp_slot_level <= p->level) 1253 p->in_use = 0; 1254 else 1255 p->rtl_expr = NULL_TREE; 1256 } 1257 1258 combine_temp_slots (); 1259 } 1260 1261 /* Mark all temporaries ever allocated in this function as not suitable 1262 for reuse until the current level is exited. */ 1263 1264 void 1265 mark_all_temps_used () 1266 { 1267 struct temp_slot *p; 1268 1269 for (p = temp_slots; p; p = p->next) 1270 { 1271 p->in_use = p->keep = 1; 1272 p->level = MIN (p->level, temp_slot_level); 1273 } 1274 } 1275 1276 /* Push deeper into the nesting level for stack temporaries. */ 1277 1278 void 1279 push_temp_slots () 1280 { 1281 temp_slot_level++; 1282 } 1283 1284 /* Likewise, but save the new level as the place to allocate variables 1285 for blocks. */ 1286 1287 #if 0 1288 void 1289 push_temp_slots_for_block () 1290 { 1291 push_temp_slots (); 1292 1293 var_temp_slot_level = temp_slot_level; 1294 } 1295 1296 /* Likewise, but save the new level as the place to allocate temporaries 1297 for TARGET_EXPRs. */ 1298 1299 void 1300 push_temp_slots_for_target () 1301 { 1302 push_temp_slots (); 1303 1304 target_temp_slot_level = temp_slot_level; 1305 } 1306 1307 /* Set and get the value of target_temp_slot_level. The only 1308 permitted use of these functions is to save and restore this value. */ 1309 1310 int 1311 get_target_temp_slot_level () 1312 { 1313 return target_temp_slot_level; 1314 } 1315 1316 void 1317 set_target_temp_slot_level (level) 1318 int level; 1319 { 1320 target_temp_slot_level = level; 1321 } 1322 #endif 1323 1324 /* Pop a temporary nesting level. All slots in use in the current level 1325 are freed. */ 1326 1327 void 1328 pop_temp_slots () 1329 { 1330 struct temp_slot *p; 1331 1332 for (p = temp_slots; p; p = p->next) 1333 if (p->in_use && p->level == temp_slot_level && p->rtl_expr == 0) 1334 p->in_use = 0; 1335 1336 combine_temp_slots (); 1337 1338 temp_slot_level--; 1339 } 1340 1341 /* Initialize temporary slots. */ 1342 1343 void 1344 init_temp_slots () 1345 { 1346 /* We have not allocated any temporaries yet. */ 1347 temp_slots = 0; 1348 temp_slot_level = 0; 1349 var_temp_slot_level = 0; 1350 target_temp_slot_level = 0; 1351 } 1352 1353 /* Retroactively move an auto variable from a register to a stack slot. 1354 This is done when an address-reference to the variable is seen. */ 1355 1356 void 1357 put_var_into_stack (decl) 1358 tree decl; 1359 { 1360 rtx reg; 1361 enum machine_mode promoted_mode, decl_mode; 1362 struct function *function = 0; 1363 tree context; 1364 int can_use_addressof; 1365 int volatilep = TREE_CODE (decl) != SAVE_EXPR && TREE_THIS_VOLATILE (decl); 1366 int usedp = (TREE_USED (decl) 1367 || (TREE_CODE (decl) != SAVE_EXPR && DECL_INITIAL (decl) != 0)); 1368 1369 context = decl_function_context (decl); 1370 1371 /* Get the current rtl used for this object and its original mode. */ 1372 reg = (TREE_CODE (decl) == SAVE_EXPR 1373 ? SAVE_EXPR_RTL (decl) 1374 : DECL_RTL_IF_SET (decl)); 1375 1376 /* No need to do anything if decl has no rtx yet 1377 since in that case caller is setting TREE_ADDRESSABLE 1378 and a stack slot will be assigned when the rtl is made. */ 1379 if (reg == 0) 1380 return; 1381 1382 /* Get the declared mode for this object. */ 1383 decl_mode = (TREE_CODE (decl) == SAVE_EXPR ? TYPE_MODE (TREE_TYPE (decl)) 1384 : DECL_MODE (decl)); 1385 /* Get the mode it's actually stored in. */ 1386 promoted_mode = GET_MODE (reg); 1387 1388 /* If this variable comes from an outer function, find that 1389 function's saved context. Don't use find_function_data here, 1390 because it might not be in any active function. 1391 FIXME: Is that really supposed to happen? 1392 It does in ObjC at least. */ 1393 if (context != current_function_decl && context != inline_function_decl) 1394 for (function = outer_function_chain; function; function = function->outer) 1395 if (function->decl == context) 1396 break; 1397 1398 /* If this is a variable-size object with a pseudo to address it, 1399 put that pseudo into the stack, if the var is nonlocal. */ 1400 if (TREE_CODE (decl) != SAVE_EXPR && DECL_NONLOCAL (decl) 1401 && GET_CODE (reg) == MEM 1402 && GET_CODE (XEXP (reg, 0)) == REG 1403 && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER) 1404 { 1405 reg = XEXP (reg, 0); 1406 decl_mode = promoted_mode = GET_MODE (reg); 1407 } 1408 1409 can_use_addressof 1410 = (function == 0 1411 && optimize > 0 1412 /* FIXME make it work for promoted modes too */ 1413 && decl_mode == promoted_mode 1414 #ifdef NON_SAVING_SETJMP 1415 && ! (NON_SAVING_SETJMP && current_function_calls_setjmp) 1416 #endif 1417 ); 1418 1419 /* If we can't use ADDRESSOF, make sure we see through one we already 1420 generated. */ 1421 if (! can_use_addressof && GET_CODE (reg) == MEM 1422 && GET_CODE (XEXP (reg, 0)) == ADDRESSOF) 1423 reg = XEXP (XEXP (reg, 0), 0); 1424 1425 /* Now we should have a value that resides in one or more pseudo regs. */ 1426 1427 if (GET_CODE (reg) == REG) 1428 { 1429 /* If this variable lives in the current function and we don't need 1430 to put things in the stack for the sake of setjmp, try to keep it 1431 in a register until we know we actually need the address. */ 1432 if (can_use_addressof) 1433 gen_mem_addressof (reg, decl); 1434 else 1435 put_reg_into_stack (function, reg, TREE_TYPE (decl), promoted_mode, 1436 decl_mode, volatilep, 0, usedp, 0); 1437 } 1438 else if (GET_CODE (reg) == CONCAT) 1439 { 1440 /* A CONCAT contains two pseudos; put them both in the stack. 1441 We do it so they end up consecutive. 1442 We fixup references to the parts only after we fixup references 1443 to the whole CONCAT, lest we do double fixups for the latter 1444 references. */ 1445 enum machine_mode part_mode = GET_MODE (XEXP (reg, 0)); 1446 tree part_type = type_for_mode (part_mode, 0); 1447 rtx lopart = XEXP (reg, 0); 1448 rtx hipart = XEXP (reg, 1); 1449 #ifdef FRAME_GROWS_DOWNWARD 1450 /* Since part 0 should have a lower address, do it second. */ 1451 put_reg_into_stack (function, hipart, part_type, part_mode, 1452 part_mode, volatilep, 0, 0, 0); 1453 put_reg_into_stack (function, lopart, part_type, part_mode, 1454 part_mode, volatilep, 0, 0, 0); 1455 #else 1456 put_reg_into_stack (function, lopart, part_type, part_mode, 1457 part_mode, volatilep, 0, 0, 0); 1458 put_reg_into_stack (function, hipart, part_type, part_mode, 1459 part_mode, volatilep, 0, 0, 0); 1460 #endif 1461 1462 /* Change the CONCAT into a combined MEM for both parts. */ 1463 PUT_CODE (reg, MEM); 1464 MEM_ATTRS (reg) = 0; 1465 1466 /* set_mem_attributes uses DECL_RTL to avoid re-generating of 1467 already computed alias sets. Here we want to re-generate. */ 1468 if (DECL_P (decl)) 1469 SET_DECL_RTL (decl, NULL); 1470 set_mem_attributes (reg, decl, 1); 1471 if (DECL_P (decl)) 1472 SET_DECL_RTL (decl, reg); 1473 1474 /* The two parts are in memory order already. 1475 Use the lower parts address as ours. */ 1476 XEXP (reg, 0) = XEXP (XEXP (reg, 0), 0); 1477 /* Prevent sharing of rtl that might lose. */ 1478 if (GET_CODE (XEXP (reg, 0)) == PLUS) 1479 XEXP (reg, 0) = copy_rtx (XEXP (reg, 0)); 1480 if (usedp) 1481 { 1482 schedule_fixup_var_refs (function, reg, TREE_TYPE (decl), 1483 promoted_mode, 0); 1484 schedule_fixup_var_refs (function, lopart, part_type, part_mode, 0); 1485 schedule_fixup_var_refs (function, hipart, part_type, part_mode, 0); 1486 } 1487 } 1488 else 1489 return; 1490 } 1491 1492 /* Subroutine of put_var_into_stack. This puts a single pseudo reg REG 1493 into the stack frame of FUNCTION (0 means the current function). 1494 DECL_MODE is the machine mode of the user-level data type. 1495 PROMOTED_MODE is the machine mode of the register. 1496 VOLATILE_P is nonzero if this is for a "volatile" decl. 1497 USED_P is nonzero if this reg might have already been used in an insn. */ 1498 1499 static void 1500 put_reg_into_stack (function, reg, type, promoted_mode, decl_mode, volatile_p, 1501 original_regno, used_p, ht) 1502 struct function *function; 1503 rtx reg; 1504 tree type; 1505 enum machine_mode promoted_mode, decl_mode; 1506 int volatile_p; 1507 unsigned int original_regno; 1508 int used_p; 1509 struct hash_table *ht; 1510 { 1511 struct function *func = function ? function : cfun; 1512 rtx new = 0; 1513 unsigned int regno = original_regno; 1514 1515 if (regno == 0) 1516 regno = REGNO (reg); 1517 1518 if (regno < func->x_max_parm_reg) 1519 new = func->x_parm_reg_stack_loc[regno]; 1520 1521 if (new == 0) 1522 new = assign_stack_local_1 (decl_mode, GET_MODE_SIZE (decl_mode), 0, func); 1523 1524 PUT_CODE (reg, MEM); 1525 PUT_MODE (reg, decl_mode); 1526 XEXP (reg, 0) = XEXP (new, 0); 1527 MEM_ATTRS (reg) = 0; 1528 /* `volatil' bit means one thing for MEMs, another entirely for REGs. */ 1529 MEM_VOLATILE_P (reg) = volatile_p; 1530 1531 /* If this is a memory ref that contains aggregate components, 1532 mark it as such for cse and loop optimize. If we are reusing a 1533 previously generated stack slot, then we need to copy the bit in 1534 case it was set for other reasons. For instance, it is set for 1535 __builtin_va_alist. */ 1536 if (type) 1537 { 1538 MEM_SET_IN_STRUCT_P (reg, 1539 AGGREGATE_TYPE_P (type) || MEM_IN_STRUCT_P (new)); 1540 set_mem_alias_set (reg, get_alias_set (type)); 1541 } 1542 1543 if (used_p) 1544 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht); 1545 } 1546 1547 /* Make sure that all refs to the variable, previously made 1548 when it was a register, are fixed up to be valid again. 1549 See function above for meaning of arguments. */ 1550 1551 static void 1552 schedule_fixup_var_refs (function, reg, type, promoted_mode, ht) 1553 struct function *function; 1554 rtx reg; 1555 tree type; 1556 enum machine_mode promoted_mode; 1557 struct hash_table *ht; 1558 { 1559 int unsigned_p = type ? TREE_UNSIGNED (type) : 0; 1560 1561 if (function != 0) 1562 { 1563 struct var_refs_queue *temp; 1564 1565 temp 1566 = (struct var_refs_queue *) ggc_alloc (sizeof (struct var_refs_queue)); 1567 temp->modified = reg; 1568 temp->promoted_mode = promoted_mode; 1569 temp->unsignedp = unsigned_p; 1570 temp->next = function->fixup_var_refs_queue; 1571 function->fixup_var_refs_queue = temp; 1572 } 1573 else 1574 /* Variable is local; fix it up now. */ 1575 fixup_var_refs (reg, promoted_mode, unsigned_p, reg, ht); 1576 } 1577 1578 static void 1579 fixup_var_refs (var, promoted_mode, unsignedp, may_share, ht) 1580 rtx var; 1581 enum machine_mode promoted_mode; 1582 int unsignedp; 1583 struct hash_table *ht; 1584 rtx may_share; 1585 { 1586 tree pending; 1587 rtx first_insn = get_insns (); 1588 struct sequence_stack *stack = seq_stack; 1589 tree rtl_exps = rtl_expr_chain; 1590 1591 /* If there's a hash table, it must record all uses of VAR. */ 1592 if (ht) 1593 { 1594 if (stack != 0) 1595 abort (); 1596 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, 1597 may_share); 1598 return; 1599 } 1600 1601 fixup_var_refs_insns (first_insn, var, promoted_mode, unsignedp, 1602 stack == 0, may_share); 1603 1604 /* Scan all pending sequences too. */ 1605 for (; stack; stack = stack->next) 1606 { 1607 push_to_full_sequence (stack->first, stack->last); 1608 fixup_var_refs_insns (stack->first, var, promoted_mode, unsignedp, 1609 stack->next != 0, may_share); 1610 /* Update remembered end of sequence 1611 in case we added an insn at the end. */ 1612 stack->last = get_last_insn (); 1613 end_sequence (); 1614 } 1615 1616 /* Scan all waiting RTL_EXPRs too. */ 1617 for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending)) 1618 { 1619 rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending)); 1620 if (seq != const0_rtx && seq != 0) 1621 { 1622 push_to_sequence (seq); 1623 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0, 1624 may_share); 1625 end_sequence (); 1626 } 1627 } 1628 } 1629 1630 /* REPLACEMENTS is a pointer to a list of the struct fixup_replacement and X is 1631 some part of an insn. Return a struct fixup_replacement whose OLD 1632 value is equal to X. Allocate a new structure if no such entry exists. */ 1633 1634 static struct fixup_replacement * 1635 find_fixup_replacement (replacements, x) 1636 struct fixup_replacement **replacements; 1637 rtx x; 1638 { 1639 struct fixup_replacement *p; 1640 1641 /* See if we have already replaced this. */ 1642 for (p = *replacements; p != 0 && ! rtx_equal_p (p->old, x); p = p->next) 1643 ; 1644 1645 if (p == 0) 1646 { 1647 p = (struct fixup_replacement *) xmalloc (sizeof (struct fixup_replacement)); 1648 p->old = x; 1649 p->new = 0; 1650 p->next = *replacements; 1651 *replacements = p; 1652 } 1653 1654 return p; 1655 } 1656 1657 /* Scan the insn-chain starting with INSN for refs to VAR and fix them 1658 up. TOPLEVEL is nonzero if this chain is the main chain of insns 1659 for the current function. MAY_SHARE is either a MEM that is not 1660 to be unshared or a list of them. */ 1661 1662 static void 1663 fixup_var_refs_insns (insn, var, promoted_mode, unsignedp, toplevel, may_share) 1664 rtx insn; 1665 rtx var; 1666 enum machine_mode promoted_mode; 1667 int unsignedp; 1668 int toplevel; 1669 rtx may_share; 1670 { 1671 while (insn) 1672 { 1673 /* fixup_var_refs_insn might modify insn, so save its next 1674 pointer now. */ 1675 rtx next = NEXT_INSN (insn); 1676 1677 /* CALL_PLACEHOLDERs are special; we have to switch into each of 1678 the three sequences they (potentially) contain, and process 1679 them recursively. The CALL_INSN itself is not interesting. */ 1680 1681 if (GET_CODE (insn) == CALL_INSN 1682 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER) 1683 { 1684 int i; 1685 1686 /* Look at the Normal call, sibling call and tail recursion 1687 sequences attached to the CALL_PLACEHOLDER. */ 1688 for (i = 0; i < 3; i++) 1689 { 1690 rtx seq = XEXP (PATTERN (insn), i); 1691 if (seq) 1692 { 1693 push_to_sequence (seq); 1694 fixup_var_refs_insns (seq, var, promoted_mode, unsignedp, 0, 1695 may_share); 1696 XEXP (PATTERN (insn), i) = get_insns (); 1697 end_sequence (); 1698 } 1699 } 1700 } 1701 1702 else if (INSN_P (insn)) 1703 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, 1704 may_share); 1705 1706 insn = next; 1707 } 1708 } 1709 1710 /* Look up the insns which reference VAR in HT and fix them up. Other 1711 arguments are the same as fixup_var_refs_insns. 1712 1713 N.B. No need for special processing of CALL_PLACEHOLDERs here, 1714 because the hash table will point straight to the interesting insn 1715 (inside the CALL_PLACEHOLDER). */ 1716 1717 static void 1718 fixup_var_refs_insns_with_hash (ht, var, promoted_mode, unsignedp, may_share) 1719 struct hash_table *ht; 1720 rtx var; 1721 enum machine_mode promoted_mode; 1722 int unsignedp; 1723 rtx may_share; 1724 { 1725 struct insns_for_mem_entry *ime 1726 = (struct insns_for_mem_entry *) hash_lookup (ht, var, 1727 /*create=*/0, /*copy=*/0); 1728 rtx insn_list; 1729 1730 for (insn_list = ime->insns; insn_list != 0; insn_list = XEXP (insn_list, 1)) 1731 if (INSN_P (XEXP (insn_list, 0))) 1732 fixup_var_refs_insn (XEXP (insn_list, 0), var, promoted_mode, 1733 unsignedp, 1, may_share); 1734 } 1735 1736 1737 /* Per-insn processing by fixup_var_refs_insns(_with_hash). INSN is 1738 the insn under examination, VAR is the variable to fix up 1739 references to, PROMOTED_MODE and UNSIGNEDP describe VAR, and 1740 TOPLEVEL is nonzero if this is the main insn chain for this 1741 function. */ 1742 1743 static void 1744 fixup_var_refs_insn (insn, var, promoted_mode, unsignedp, toplevel, no_share) 1745 rtx insn; 1746 rtx var; 1747 enum machine_mode promoted_mode; 1748 int unsignedp; 1749 int toplevel; 1750 rtx no_share; 1751 { 1752 rtx call_dest = 0; 1753 rtx set, prev, prev_set; 1754 rtx note; 1755 1756 /* Remember the notes in case we delete the insn. */ 1757 note = REG_NOTES (insn); 1758 1759 /* If this is a CLOBBER of VAR, delete it. 1760 1761 If it has a REG_LIBCALL note, delete the REG_LIBCALL 1762 and REG_RETVAL notes too. */ 1763 if (GET_CODE (PATTERN (insn)) == CLOBBER 1764 && (XEXP (PATTERN (insn), 0) == var 1765 || (GET_CODE (XEXP (PATTERN (insn), 0)) == CONCAT 1766 && (XEXP (XEXP (PATTERN (insn), 0), 0) == var 1767 || XEXP (XEXP (PATTERN (insn), 0), 1) == var)))) 1768 { 1769 if ((note = find_reg_note (insn, REG_LIBCALL, NULL_RTX)) != 0) 1770 /* The REG_LIBCALL note will go away since we are going to 1771 turn INSN into a NOTE, so just delete the 1772 corresponding REG_RETVAL note. */ 1773 remove_note (XEXP (note, 0), 1774 find_reg_note (XEXP (note, 0), REG_RETVAL, 1775 NULL_RTX)); 1776 1777 delete_insn (insn); 1778 } 1779 1780 /* The insn to load VAR from a home in the arglist 1781 is now a no-op. When we see it, just delete it. 1782 Similarly if this is storing VAR from a register from which 1783 it was loaded in the previous insn. This will occur 1784 when an ADDRESSOF was made for an arglist slot. */ 1785 else if (toplevel 1786 && (set = single_set (insn)) != 0 1787 && SET_DEST (set) == var 1788 /* If this represents the result of an insn group, 1789 don't delete the insn. */ 1790 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == 0 1791 && (rtx_equal_p (SET_SRC (set), var) 1792 || (GET_CODE (SET_SRC (set)) == REG 1793 && (prev = prev_nonnote_insn (insn)) != 0 1794 && (prev_set = single_set (prev)) != 0 1795 && SET_DEST (prev_set) == SET_SRC (set) 1796 && rtx_equal_p (SET_SRC (prev_set), var)))) 1797 { 1798 delete_insn (insn); 1799 } 1800 else 1801 { 1802 struct fixup_replacement *replacements = 0; 1803 rtx next_insn = NEXT_INSN (insn); 1804 1805 if (SMALL_REGISTER_CLASSES) 1806 { 1807 /* If the insn that copies the results of a CALL_INSN 1808 into a pseudo now references VAR, we have to use an 1809 intermediate pseudo since we want the life of the 1810 return value register to be only a single insn. 1811 1812 If we don't use an intermediate pseudo, such things as 1813 address computations to make the address of VAR valid 1814 if it is not can be placed between the CALL_INSN and INSN. 1815 1816 To make sure this doesn't happen, we record the destination 1817 of the CALL_INSN and see if the next insn uses both that 1818 and VAR. */ 1819 1820 if (call_dest != 0 && GET_CODE (insn) == INSN 1821 && reg_mentioned_p (var, PATTERN (insn)) 1822 && reg_mentioned_p (call_dest, PATTERN (insn))) 1823 { 1824 rtx temp = gen_reg_rtx (GET_MODE (call_dest)); 1825 1826 emit_insn_before (gen_move_insn (temp, call_dest), insn); 1827 1828 PATTERN (insn) = replace_rtx (PATTERN (insn), 1829 call_dest, temp); 1830 } 1831 1832 if (GET_CODE (insn) == CALL_INSN 1833 && GET_CODE (PATTERN (insn)) == SET) 1834 call_dest = SET_DEST (PATTERN (insn)); 1835 else if (GET_CODE (insn) == CALL_INSN 1836 && GET_CODE (PATTERN (insn)) == PARALLEL 1837 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET) 1838 call_dest = SET_DEST (XVECEXP (PATTERN (insn), 0, 0)); 1839 else 1840 call_dest = 0; 1841 } 1842 1843 /* See if we have to do anything to INSN now that VAR is in 1844 memory. If it needs to be loaded into a pseudo, use a single 1845 pseudo for the entire insn in case there is a MATCH_DUP 1846 between two operands. We pass a pointer to the head of 1847 a list of struct fixup_replacements. If fixup_var_refs_1 1848 needs to allocate pseudos or replacement MEMs (for SUBREGs), 1849 it will record them in this list. 1850 1851 If it allocated a pseudo for any replacement, we copy into 1852 it here. */ 1853 1854 fixup_var_refs_1 (var, promoted_mode, &PATTERN (insn), insn, 1855 &replacements, no_share); 1856 1857 /* If this is last_parm_insn, and any instructions were output 1858 after it to fix it up, then we must set last_parm_insn to 1859 the last such instruction emitted. */ 1860 if (insn == last_parm_insn) 1861 last_parm_insn = PREV_INSN (next_insn); 1862 1863 while (replacements) 1864 { 1865 struct fixup_replacement *next; 1866 1867 if (GET_CODE (replacements->new) == REG) 1868 { 1869 rtx insert_before; 1870 rtx seq; 1871 1872 /* OLD might be a (subreg (mem)). */ 1873 if (GET_CODE (replacements->old) == SUBREG) 1874 replacements->old 1875 = fixup_memory_subreg (replacements->old, insn, 1876 promoted_mode, 0); 1877 else 1878 replacements->old 1879 = fixup_stack_1 (replacements->old, insn); 1880 1881 insert_before = insn; 1882 1883 /* If we are changing the mode, do a conversion. 1884 This might be wasteful, but combine.c will 1885 eliminate much of the waste. */ 1886 1887 if (GET_MODE (replacements->new) 1888 != GET_MODE (replacements->old)) 1889 { 1890 start_sequence (); 1891 convert_move (replacements->new, 1892 replacements->old, unsignedp); 1893 seq = gen_sequence (); 1894 end_sequence (); 1895 } 1896 else 1897 seq = gen_move_insn (replacements->new, 1898 replacements->old); 1899 1900 emit_insn_before (seq, insert_before); 1901 } 1902 1903 next = replacements->next; 1904 free (replacements); 1905 replacements = next; 1906 } 1907 } 1908 1909 /* Also fix up any invalid exprs in the REG_NOTES of this insn. 1910 But don't touch other insns referred to by reg-notes; 1911 we will get them elsewhere. */ 1912 while (note) 1913 { 1914 if (GET_CODE (note) != INSN_LIST) 1915 XEXP (note, 0) 1916 = walk_fixup_memory_subreg (XEXP (note, 0), insn, 1917 promoted_mode, 1); 1918 note = XEXP (note, 1); 1919 } 1920 } 1921 1922 /* VAR is a MEM that used to be a pseudo register with mode PROMOTED_MODE. 1923 See if the rtx expression at *LOC in INSN needs to be changed. 1924 1925 REPLACEMENTS is a pointer to a list head that starts out zero, but may 1926 contain a list of original rtx's and replacements. If we find that we need 1927 to modify this insn by replacing a memory reference with a pseudo or by 1928 making a new MEM to implement a SUBREG, we consult that list to see if 1929 we have already chosen a replacement. If none has already been allocated, 1930 we allocate it and update the list. fixup_var_refs_insn will copy VAR 1931 or the SUBREG, as appropriate, to the pseudo. */ 1932 1933 static void 1934 fixup_var_refs_1 (var, promoted_mode, loc, insn, replacements, no_share) 1935 rtx var; 1936 enum machine_mode promoted_mode; 1937 rtx *loc; 1938 rtx insn; 1939 struct fixup_replacement **replacements; 1940 rtx no_share; 1941 { 1942 int i; 1943 rtx x = *loc; 1944 RTX_CODE code = GET_CODE (x); 1945 const char *fmt; 1946 rtx tem, tem1; 1947 struct fixup_replacement *replacement; 1948 1949 switch (code) 1950 { 1951 case ADDRESSOF: 1952 if (XEXP (x, 0) == var) 1953 { 1954 /* Prevent sharing of rtl that might lose. */ 1955 rtx sub = copy_rtx (XEXP (var, 0)); 1956 1957 if (! validate_change (insn, loc, sub, 0)) 1958 { 1959 rtx y = gen_reg_rtx (GET_MODE (sub)); 1960 rtx seq, new_insn; 1961 1962 /* We should be able to replace with a register or all is lost. 1963 Note that we can't use validate_change to verify this, since 1964 we're not caring for replacing all dups simultaneously. */ 1965 if (! validate_replace_rtx (*loc, y, insn)) 1966 abort (); 1967 1968 /* Careful! First try to recognize a direct move of the 1969 value, mimicking how things are done in gen_reload wrt 1970 PLUS. Consider what happens when insn is a conditional 1971 move instruction and addsi3 clobbers flags. */ 1972 1973 start_sequence (); 1974 new_insn = emit_insn (gen_rtx_SET (VOIDmode, y, sub)); 1975 seq = gen_sequence (); 1976 end_sequence (); 1977 1978 if (recog_memoized (new_insn) < 0) 1979 { 1980 /* That failed. Fall back on force_operand and hope. */ 1981 1982 start_sequence (); 1983 sub = force_operand (sub, y); 1984 if (sub != y) 1985 emit_insn (gen_move_insn (y, sub)); 1986 seq = gen_sequence (); 1987 end_sequence (); 1988 } 1989 1990 #ifdef HAVE_cc0 1991 /* Don't separate setter from user. */ 1992 if (PREV_INSN (insn) && sets_cc0_p (PREV_INSN (insn))) 1993 insn = PREV_INSN (insn); 1994 #endif 1995 1996 emit_insn_before (seq, insn); 1997 } 1998 } 1999 return; 2000 2001 case MEM: 2002 if (var == x) 2003 { 2004 /* If we already have a replacement, use it. Otherwise, 2005 try to fix up this address in case it is invalid. */ 2006 2007 replacement = find_fixup_replacement (replacements, var); 2008 if (replacement->new) 2009 { 2010 *loc = replacement->new; 2011 return; 2012 } 2013 2014 *loc = replacement->new = x = fixup_stack_1 (x, insn); 2015 2016 /* Unless we are forcing memory to register or we changed the mode, 2017 we can leave things the way they are if the insn is valid. */ 2018 2019 INSN_CODE (insn) = -1; 2020 if (! flag_force_mem && GET_MODE (x) == promoted_mode 2021 && recog_memoized (insn) >= 0) 2022 return; 2023 2024 *loc = replacement->new = gen_reg_rtx (promoted_mode); 2025 return; 2026 } 2027 2028 /* If X contains VAR, we need to unshare it here so that we update 2029 each occurrence separately. But all identical MEMs in one insn 2030 must be replaced with the same rtx because of the possibility of 2031 MATCH_DUPs. */ 2032 2033 if (reg_mentioned_p (var, x)) 2034 { 2035 replacement = find_fixup_replacement (replacements, x); 2036 if (replacement->new == 0) 2037 replacement->new = copy_most_rtx (x, no_share); 2038 2039 *loc = x = replacement->new; 2040 code = GET_CODE (x); 2041 } 2042 break; 2043 2044 case REG: 2045 case CC0: 2046 case PC: 2047 case CONST_INT: 2048 case CONST: 2049 case SYMBOL_REF: 2050 case LABEL_REF: 2051 case CONST_DOUBLE: 2052 case CONST_VECTOR: 2053 return; 2054 2055 case SIGN_EXTRACT: 2056 case ZERO_EXTRACT: 2057 /* Note that in some cases those types of expressions are altered 2058 by optimize_bit_field, and do not survive to get here. */ 2059 if (XEXP (x, 0) == var 2060 || (GET_CODE (XEXP (x, 0)) == SUBREG 2061 && SUBREG_REG (XEXP (x, 0)) == var)) 2062 { 2063 /* Get TEM as a valid MEM in the mode presently in the insn. 2064 2065 We don't worry about the possibility of MATCH_DUP here; it 2066 is highly unlikely and would be tricky to handle. */ 2067 2068 tem = XEXP (x, 0); 2069 if (GET_CODE (tem) == SUBREG) 2070 { 2071 if (GET_MODE_BITSIZE (GET_MODE (tem)) 2072 > GET_MODE_BITSIZE (GET_MODE (var))) 2073 { 2074 replacement = find_fixup_replacement (replacements, var); 2075 if (replacement->new == 0) 2076 replacement->new = gen_reg_rtx (GET_MODE (var)); 2077 SUBREG_REG (tem) = replacement->new; 2078 2079 /* The following code works only if we have a MEM, so we 2080 need to handle the subreg here. We directly substitute 2081 it assuming that a subreg must be OK here. We already 2082 scheduled a replacement to copy the mem into the 2083 subreg. */ 2084 XEXP (x, 0) = tem; 2085 return; 2086 } 2087 else 2088 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0); 2089 } 2090 else 2091 tem = fixup_stack_1 (tem, insn); 2092 2093 /* Unless we want to load from memory, get TEM into the proper mode 2094 for an extract from memory. This can only be done if the 2095 extract is at a constant position and length. */ 2096 2097 if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT 2098 && GET_CODE (XEXP (x, 2)) == CONST_INT 2099 && ! mode_dependent_address_p (XEXP (tem, 0)) 2100 && ! MEM_VOLATILE_P (tem)) 2101 { 2102 enum machine_mode wanted_mode = VOIDmode; 2103 enum machine_mode is_mode = GET_MODE (tem); 2104 HOST_WIDE_INT pos = INTVAL (XEXP (x, 2)); 2105 2106 if (GET_CODE (x) == ZERO_EXTRACT) 2107 { 2108 enum machine_mode new_mode 2109 = mode_for_extraction (EP_extzv, 1); 2110 if (new_mode != MAX_MACHINE_MODE) 2111 wanted_mode = new_mode; 2112 } 2113 else if (GET_CODE (x) == SIGN_EXTRACT) 2114 { 2115 enum machine_mode new_mode 2116 = mode_for_extraction (EP_extv, 1); 2117 if (new_mode != MAX_MACHINE_MODE) 2118 wanted_mode = new_mode; 2119 } 2120 2121 /* If we have a narrower mode, we can do something. */ 2122 if (wanted_mode != VOIDmode 2123 && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) 2124 { 2125 HOST_WIDE_INT offset = pos / BITS_PER_UNIT; 2126 rtx old_pos = XEXP (x, 2); 2127 rtx newmem; 2128 2129 /* If the bytes and bits are counted differently, we 2130 must adjust the offset. */ 2131 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) 2132 offset = (GET_MODE_SIZE (is_mode) 2133 - GET_MODE_SIZE (wanted_mode) - offset); 2134 2135 pos %= GET_MODE_BITSIZE (wanted_mode); 2136 2137 newmem = adjust_address_nv (tem, wanted_mode, offset); 2138 2139 /* Make the change and see if the insn remains valid. */ 2140 INSN_CODE (insn) = -1; 2141 XEXP (x, 0) = newmem; 2142 XEXP (x, 2) = GEN_INT (pos); 2143 2144 if (recog_memoized (insn) >= 0) 2145 return; 2146 2147 /* Otherwise, restore old position. XEXP (x, 0) will be 2148 restored later. */ 2149 XEXP (x, 2) = old_pos; 2150 } 2151 } 2152 2153 /* If we get here, the bitfield extract insn can't accept a memory 2154 reference. Copy the input into a register. */ 2155 2156 tem1 = gen_reg_rtx (GET_MODE (tem)); 2157 emit_insn_before (gen_move_insn (tem1, tem), insn); 2158 XEXP (x, 0) = tem1; 2159 return; 2160 } 2161 break; 2162 2163 case SUBREG: 2164 if (SUBREG_REG (x) == var) 2165 { 2166 /* If this is a special SUBREG made because VAR was promoted 2167 from a wider mode, replace it with VAR and call ourself 2168 recursively, this time saying that the object previously 2169 had its current mode (by virtue of the SUBREG). */ 2170 2171 if (SUBREG_PROMOTED_VAR_P (x)) 2172 { 2173 *loc = var; 2174 fixup_var_refs_1 (var, GET_MODE (var), loc, insn, replacements, 2175 no_share); 2176 return; 2177 } 2178 2179 /* If this SUBREG makes VAR wider, it has become a paradoxical 2180 SUBREG with VAR in memory, but these aren't allowed at this 2181 stage of the compilation. So load VAR into a pseudo and take 2182 a SUBREG of that pseudo. */ 2183 if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var))) 2184 { 2185 replacement = find_fixup_replacement (replacements, var); 2186 if (replacement->new == 0) 2187 replacement->new = gen_reg_rtx (promoted_mode); 2188 SUBREG_REG (x) = replacement->new; 2189 return; 2190 } 2191 2192 /* See if we have already found a replacement for this SUBREG. 2193 If so, use it. Otherwise, make a MEM and see if the insn 2194 is recognized. If not, or if we should force MEM into a register, 2195 make a pseudo for this SUBREG. */ 2196 replacement = find_fixup_replacement (replacements, x); 2197 if (replacement->new) 2198 { 2199 *loc = replacement->new; 2200 return; 2201 } 2202 2203 replacement->new = *loc = fixup_memory_subreg (x, insn, 2204 promoted_mode, 0); 2205 2206 INSN_CODE (insn) = -1; 2207 if (! flag_force_mem && recog_memoized (insn) >= 0) 2208 return; 2209 2210 *loc = replacement->new = gen_reg_rtx (GET_MODE (x)); 2211 return; 2212 } 2213 break; 2214 2215 case SET: 2216 /* First do special simplification of bit-field references. */ 2217 if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT 2218 || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT) 2219 optimize_bit_field (x, insn, 0); 2220 if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT 2221 || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT) 2222 optimize_bit_field (x, insn, 0); 2223 2224 /* For a paradoxical SUBREG inside a ZERO_EXTRACT, load the object 2225 into a register and then store it back out. */ 2226 if (GET_CODE (SET_DEST (x)) == ZERO_EXTRACT 2227 && GET_CODE (XEXP (SET_DEST (x), 0)) == SUBREG 2228 && SUBREG_REG (XEXP (SET_DEST (x), 0)) == var 2229 && (GET_MODE_SIZE (GET_MODE (XEXP (SET_DEST (x), 0))) 2230 > GET_MODE_SIZE (GET_MODE (var)))) 2231 { 2232 replacement = find_fixup_replacement (replacements, var); 2233 if (replacement->new == 0) 2234 replacement->new = gen_reg_rtx (GET_MODE (var)); 2235 2236 SUBREG_REG (XEXP (SET_DEST (x), 0)) = replacement->new; 2237 emit_insn_after (gen_move_insn (var, replacement->new), insn); 2238 } 2239 2240 /* If SET_DEST is now a paradoxical SUBREG, put the result of this 2241 insn into a pseudo and store the low part of the pseudo into VAR. */ 2242 if (GET_CODE (SET_DEST (x)) == SUBREG 2243 && SUBREG_REG (SET_DEST (x)) == var 2244 && (GET_MODE_SIZE (GET_MODE (SET_DEST (x))) 2245 > GET_MODE_SIZE (GET_MODE (var)))) 2246 { 2247 SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x))); 2248 emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var), 2249 tem)), 2250 insn); 2251 break; 2252 } 2253 2254 { 2255 rtx dest = SET_DEST (x); 2256 rtx src = SET_SRC (x); 2257 rtx outerdest = dest; 2258 2259 while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART 2260 || GET_CODE (dest) == SIGN_EXTRACT 2261 || GET_CODE (dest) == ZERO_EXTRACT) 2262 dest = XEXP (dest, 0); 2263 2264 if (GET_CODE (src) == SUBREG) 2265 src = SUBREG_REG (src); 2266 2267 /* If VAR does not appear at the top level of the SET 2268 just scan the lower levels of the tree. */ 2269 2270 if (src != var && dest != var) 2271 break; 2272 2273 /* We will need to rerecognize this insn. */ 2274 INSN_CODE (insn) = -1; 2275 2276 if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var 2277 && mode_for_extraction (EP_insv, -1) != MAX_MACHINE_MODE) 2278 { 2279 /* Since this case will return, ensure we fixup all the 2280 operands here. */ 2281 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 1), 2282 insn, replacements, no_share); 2283 fixup_var_refs_1 (var, promoted_mode, &XEXP (outerdest, 2), 2284 insn, replacements, no_share); 2285 fixup_var_refs_1 (var, promoted_mode, &SET_SRC (x), 2286 insn, replacements, no_share); 2287 2288 tem = XEXP (outerdest, 0); 2289 2290 /* Clean up (SUBREG:SI (MEM:mode ...) 0) 2291 that may appear inside a ZERO_EXTRACT. 2292 This was legitimate when the MEM was a REG. */ 2293 if (GET_CODE (tem) == SUBREG 2294 && SUBREG_REG (tem) == var) 2295 tem = fixup_memory_subreg (tem, insn, promoted_mode, 0); 2296 else 2297 tem = fixup_stack_1 (tem, insn); 2298 2299 if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT 2300 && GET_CODE (XEXP (outerdest, 2)) == CONST_INT 2301 && ! mode_dependent_address_p (XEXP (tem, 0)) 2302 && ! MEM_VOLATILE_P (tem)) 2303 { 2304 enum machine_mode wanted_mode; 2305 enum machine_mode is_mode = GET_MODE (tem); 2306 HOST_WIDE_INT pos = INTVAL (XEXP (outerdest, 2)); 2307 2308 wanted_mode = mode_for_extraction (EP_insv, 0); 2309 2310 /* If we have a narrower mode, we can do something. */ 2311 if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode)) 2312 { 2313 HOST_WIDE_INT offset = pos / BITS_PER_UNIT; 2314 rtx old_pos = XEXP (outerdest, 2); 2315 rtx newmem; 2316 2317 if (BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN) 2318 offset = (GET_MODE_SIZE (is_mode) 2319 - GET_MODE_SIZE (wanted_mode) - offset); 2320 2321 pos %= GET_MODE_BITSIZE (wanted_mode); 2322 2323 newmem = adjust_address_nv (tem, wanted_mode, offset); 2324 2325 /* Make the change and see if the insn remains valid. */ 2326 INSN_CODE (insn) = -1; 2327 XEXP (outerdest, 0) = newmem; 2328 XEXP (outerdest, 2) = GEN_INT (pos); 2329 2330 if (recog_memoized (insn) >= 0) 2331 return; 2332 2333 /* Otherwise, restore old position. XEXP (x, 0) will be 2334 restored later. */ 2335 XEXP (outerdest, 2) = old_pos; 2336 } 2337 } 2338 2339 /* If we get here, the bit-field store doesn't allow memory 2340 or isn't located at a constant position. Load the value into 2341 a register, do the store, and put it back into memory. */ 2342 2343 tem1 = gen_reg_rtx (GET_MODE (tem)); 2344 emit_insn_before (gen_move_insn (tem1, tem), insn); 2345 emit_insn_after (gen_move_insn (tem, tem1), insn); 2346 XEXP (outerdest, 0) = tem1; 2347 return; 2348 } 2349 2350 /* STRICT_LOW_PART is a no-op on memory references 2351 and it can cause combinations to be unrecognizable, 2352 so eliminate it. */ 2353 2354 if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART) 2355 SET_DEST (x) = XEXP (SET_DEST (x), 0); 2356 2357 /* A valid insn to copy VAR into or out of a register 2358 must be left alone, to avoid an infinite loop here. 2359 If the reference to VAR is by a subreg, fix that up, 2360 since SUBREG is not valid for a memref. 2361 Also fix up the address of the stack slot. 2362 2363 Note that we must not try to recognize the insn until 2364 after we know that we have valid addresses and no 2365 (subreg (mem ...) ...) constructs, since these interfere 2366 with determining the validity of the insn. */ 2367 2368 if ((SET_SRC (x) == var 2369 || (GET_CODE (SET_SRC (x)) == SUBREG 2370 && SUBREG_REG (SET_SRC (x)) == var)) 2371 && (GET_CODE (SET_DEST (x)) == REG 2372 || (GET_CODE (SET_DEST (x)) == SUBREG 2373 && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG)) 2374 && GET_MODE (var) == promoted_mode 2375 && x == single_set (insn)) 2376 { 2377 rtx pat, last; 2378 2379 if (GET_CODE (SET_SRC (x)) == SUBREG 2380 && (GET_MODE_SIZE (GET_MODE (SET_SRC (x))) 2381 > GET_MODE_SIZE (GET_MODE (var)))) 2382 { 2383 /* This (subreg VAR) is now a paradoxical subreg. We need 2384 to replace VAR instead of the subreg. */ 2385 replacement = find_fixup_replacement (replacements, var); 2386 if (replacement->new == NULL_RTX) 2387 replacement->new = gen_reg_rtx (GET_MODE (var)); 2388 SUBREG_REG (SET_SRC (x)) = replacement->new; 2389 } 2390 else 2391 { 2392 replacement = find_fixup_replacement (replacements, SET_SRC (x)); 2393 if (replacement->new) 2394 SET_SRC (x) = replacement->new; 2395 else if (GET_CODE (SET_SRC (x)) == SUBREG) 2396 SET_SRC (x) = replacement->new 2397 = fixup_memory_subreg (SET_SRC (x), insn, promoted_mode, 2398 0); 2399 else 2400 SET_SRC (x) = replacement->new 2401 = fixup_stack_1 (SET_SRC (x), insn); 2402 } 2403 2404 if (recog_memoized (insn) >= 0) 2405 return; 2406 2407 /* INSN is not valid, but we know that we want to 2408 copy SET_SRC (x) to SET_DEST (x) in some way. So 2409 we generate the move and see whether it requires more 2410 than one insn. If it does, we emit those insns and 2411 delete INSN. Otherwise, we an just replace the pattern 2412 of INSN; we have already verified above that INSN has 2413 no other function that to do X. */ 2414 2415 pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); 2416 if (GET_CODE (pat) == SEQUENCE) 2417 { 2418 last = emit_insn_before (pat, insn); 2419 2420 /* INSN might have REG_RETVAL or other important notes, so 2421 we need to store the pattern of the last insn in the 2422 sequence into INSN similarly to the normal case. LAST 2423 should not have REG_NOTES, but we allow them if INSN has 2424 no REG_NOTES. */ 2425 if (REG_NOTES (last) && REG_NOTES (insn)) 2426 abort (); 2427 if (REG_NOTES (last)) 2428 REG_NOTES (insn) = REG_NOTES (last); 2429 PATTERN (insn) = PATTERN (last); 2430 2431 delete_insn (last); 2432 } 2433 else 2434 PATTERN (insn) = pat; 2435 2436 return; 2437 } 2438 2439 if ((SET_DEST (x) == var 2440 || (GET_CODE (SET_DEST (x)) == SUBREG 2441 && SUBREG_REG (SET_DEST (x)) == var)) 2442 && (GET_CODE (SET_SRC (x)) == REG 2443 || (GET_CODE (SET_SRC (x)) == SUBREG 2444 && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)) 2445 && GET_MODE (var) == promoted_mode 2446 && x == single_set (insn)) 2447 { 2448 rtx pat, last; 2449 2450 if (GET_CODE (SET_DEST (x)) == SUBREG) 2451 SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn, 2452 promoted_mode, 0); 2453 else 2454 SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn); 2455 2456 if (recog_memoized (insn) >= 0) 2457 return; 2458 2459 pat = gen_move_insn (SET_DEST (x), SET_SRC (x)); 2460 if (GET_CODE (pat) == SEQUENCE) 2461 { 2462 last = emit_insn_before (pat, insn); 2463 2464 /* INSN might have REG_RETVAL or other important notes, so 2465 we need to store the pattern of the last insn in the 2466 sequence into INSN similarly to the normal case. LAST 2467 should not have REG_NOTES, but we allow them if INSN has 2468 no REG_NOTES. */ 2469 if (REG_NOTES (last) && REG_NOTES (insn)) 2470 abort (); 2471 if (REG_NOTES (last)) 2472 REG_NOTES (insn) = REG_NOTES (last); 2473 PATTERN (insn) = PATTERN (last); 2474 2475 delete_insn (last); 2476 } 2477 else 2478 PATTERN (insn) = pat; 2479 2480 return; 2481 } 2482 2483 /* Otherwise, storing into VAR must be handled specially 2484 by storing into a temporary and copying that into VAR 2485 with a new insn after this one. Note that this case 2486 will be used when storing into a promoted scalar since 2487 the insn will now have different modes on the input 2488 and output and hence will be invalid (except for the case 2489 of setting it to a constant, which does not need any 2490 change if it is valid). We generate extra code in that case, 2491 but combine.c will eliminate it. */ 2492 2493 if (dest == var) 2494 { 2495 rtx temp; 2496 rtx fixeddest = SET_DEST (x); 2497 enum machine_mode temp_mode; 2498 2499 /* STRICT_LOW_PART can be discarded, around a MEM. */ 2500 if (GET_CODE (fixeddest) == STRICT_LOW_PART) 2501 fixeddest = XEXP (fixeddest, 0); 2502 /* Convert (SUBREG (MEM)) to a MEM in a changed mode. */ 2503 if (GET_CODE (fixeddest) == SUBREG) 2504 { 2505 fixeddest = fixup_memory_subreg (fixeddest, insn, 2506 promoted_mode, 0); 2507 temp_mode = GET_MODE (fixeddest); 2508 } 2509 else 2510 { 2511 fixeddest = fixup_stack_1 (fixeddest, insn); 2512 temp_mode = promoted_mode; 2513 } 2514 2515 temp = gen_reg_rtx (temp_mode); 2516 2517 emit_insn_after (gen_move_insn (fixeddest, 2518 gen_lowpart (GET_MODE (fixeddest), 2519 temp)), 2520 insn); 2521 2522 SET_DEST (x) = temp; 2523 } 2524 } 2525 2526 default: 2527 break; 2528 } 2529 2530 /* Nothing special about this RTX; fix its operands. */ 2531 2532 fmt = GET_RTX_FORMAT (code); 2533 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 2534 { 2535 if (fmt[i] == 'e') 2536 fixup_var_refs_1 (var, promoted_mode, &XEXP (x, i), insn, replacements, 2537 no_share); 2538 else if (fmt[i] == 'E') 2539 { 2540 int j; 2541 for (j = 0; j < XVECLEN (x, i); j++) 2542 fixup_var_refs_1 (var, promoted_mode, &XVECEXP (x, i, j), 2543 insn, replacements, no_share); 2544 } 2545 } 2546 } 2547 2548 /* Previously, X had the form (SUBREG:m1 (REG:PROMOTED_MODE ...)). 2549 The REG was placed on the stack, so X now has the form (SUBREG:m1 2550 (MEM:m2 ...)). 2551 2552 Return an rtx (MEM:m1 newaddr) which is equivalent. If any insns 2553 must be emitted to compute NEWADDR, put them before INSN. 2554 2555 UNCRITICAL nonzero means accept paradoxical subregs. 2556 This is used for subregs found inside REG_NOTES. */ 2557 2558 static rtx 2559 fixup_memory_subreg (x, insn, promoted_mode, uncritical) 2560 rtx x; 2561 rtx insn; 2562 enum machine_mode promoted_mode; 2563 int uncritical; 2564 { 2565 int offset; 2566 rtx mem = SUBREG_REG (x); 2567 rtx addr = XEXP (mem, 0); 2568 enum machine_mode mode = GET_MODE (x); 2569 rtx result; 2570 2571 /* Paradoxical SUBREGs are usually invalid during RTL generation. */ 2572 if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (mem)) && ! uncritical) 2573 abort (); 2574 2575 offset = SUBREG_BYTE (x); 2576 if (BYTES_BIG_ENDIAN) 2577 /* If the PROMOTED_MODE is wider than the mode of the MEM, adjust 2578 the offset so that it points to the right location within the 2579 MEM. */ 2580 offset -= (GET_MODE_SIZE (promoted_mode) - GET_MODE_SIZE (GET_MODE (mem))); 2581 2582 if (!flag_force_addr 2583 && memory_address_p (mode, plus_constant (addr, offset))) 2584 /* Shortcut if no insns need be emitted. */ 2585 return adjust_address (mem, mode, offset); 2586 2587 start_sequence (); 2588 result = adjust_address (mem, mode, offset); 2589 emit_insn_before (gen_sequence (), insn); 2590 end_sequence (); 2591 return result; 2592 } 2593 2594 /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X. 2595 Replace subexpressions of X in place. 2596 If X itself is a (SUBREG (MEM ...) ...), return the replacement expression. 2597 Otherwise return X, with its contents possibly altered. 2598 2599 INSN, PROMOTED_MODE and UNCRITICAL are as for 2600 fixup_memory_subreg. */ 2601 2602 static rtx 2603 walk_fixup_memory_subreg (x, insn, promoted_mode, uncritical) 2604 rtx x; 2605 rtx insn; 2606 enum machine_mode promoted_mode; 2607 int uncritical; 2608 { 2609 enum rtx_code code; 2610 const char *fmt; 2611 int i; 2612 2613 if (x == 0) 2614 return 0; 2615 2616 code = GET_CODE (x); 2617 2618 if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM) 2619 return fixup_memory_subreg (x, insn, promoted_mode, uncritical); 2620 2621 /* Nothing special about this RTX; fix its operands. */ 2622 2623 fmt = GET_RTX_FORMAT (code); 2624 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 2625 { 2626 if (fmt[i] == 'e') 2627 XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn, 2628 promoted_mode, uncritical); 2629 else if (fmt[i] == 'E') 2630 { 2631 int j; 2632 for (j = 0; j < XVECLEN (x, i); j++) 2633 XVECEXP (x, i, j) 2634 = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn, 2635 promoted_mode, uncritical); 2636 } 2637 } 2638 return x; 2639 } 2640 2641 /* For each memory ref within X, if it refers to a stack slot 2642 with an out of range displacement, put the address in a temp register 2643 (emitting new insns before INSN to load these registers) 2644 and alter the memory ref to use that register. 2645 Replace each such MEM rtx with a copy, to avoid clobberage. */ 2646 2647 static rtx 2648 fixup_stack_1 (x, insn) 2649 rtx x; 2650 rtx insn; 2651 { 2652 int i; 2653 RTX_CODE code = GET_CODE (x); 2654 const char *fmt; 2655 2656 if (code == MEM) 2657 { 2658 rtx ad = XEXP (x, 0); 2659 /* If we have address of a stack slot but it's not valid 2660 (displacement is too large), compute the sum in a register. */ 2661 if (GET_CODE (ad) == PLUS 2662 && GET_CODE (XEXP (ad, 0)) == REG 2663 && ((REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER 2664 && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER) 2665 || REGNO (XEXP (ad, 0)) == FRAME_POINTER_REGNUM 2666 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 2667 || REGNO (XEXP (ad, 0)) == HARD_FRAME_POINTER_REGNUM 2668 #endif 2669 || REGNO (XEXP (ad, 0)) == STACK_POINTER_REGNUM 2670 || REGNO (XEXP (ad, 0)) == ARG_POINTER_REGNUM 2671 || XEXP (ad, 0) == current_function_internal_arg_pointer) 2672 && GET_CODE (XEXP (ad, 1)) == CONST_INT) 2673 { 2674 rtx temp, seq; 2675 if (memory_address_p (GET_MODE (x), ad)) 2676 return x; 2677 2678 start_sequence (); 2679 temp = copy_to_reg (ad); 2680 seq = gen_sequence (); 2681 end_sequence (); 2682 emit_insn_before (seq, insn); 2683 return replace_equiv_address (x, temp); 2684 } 2685 return x; 2686 } 2687 2688 fmt = GET_RTX_FORMAT (code); 2689 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 2690 { 2691 if (fmt[i] == 'e') 2692 XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn); 2693 else if (fmt[i] == 'E') 2694 { 2695 int j; 2696 for (j = 0; j < XVECLEN (x, i); j++) 2697 XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn); 2698 } 2699 } 2700 return x; 2701 } 2702 2703 /* Optimization: a bit-field instruction whose field 2704 happens to be a byte or halfword in memory 2705 can be changed to a move instruction. 2706 2707 We call here when INSN is an insn to examine or store into a bit-field. 2708 BODY is the SET-rtx to be altered. 2709 2710 EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0. 2711 (Currently this is called only from function.c, and EQUIV_MEM 2712 is always 0.) */ 2713 2714 static void 2715 optimize_bit_field (body, insn, equiv_mem) 2716 rtx body; 2717 rtx insn; 2718 rtx *equiv_mem; 2719 { 2720 rtx bitfield; 2721 int destflag; 2722 rtx seq = 0; 2723 enum machine_mode mode; 2724 2725 if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT 2726 || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT) 2727 bitfield = SET_DEST (body), destflag = 1; 2728 else 2729 bitfield = SET_SRC (body), destflag = 0; 2730 2731 /* First check that the field being stored has constant size and position 2732 and is in fact a byte or halfword suitably aligned. */ 2733 2734 if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT 2735 && GET_CODE (XEXP (bitfield, 2)) == CONST_INT 2736 && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1)) 2737 != BLKmode) 2738 && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0) 2739 { 2740 rtx memref = 0; 2741 2742 /* Now check that the containing word is memory, not a register, 2743 and that it is safe to change the machine mode. */ 2744 2745 if (GET_CODE (XEXP (bitfield, 0)) == MEM) 2746 memref = XEXP (bitfield, 0); 2747 else if (GET_CODE (XEXP (bitfield, 0)) == REG 2748 && equiv_mem != 0) 2749 memref = equiv_mem[REGNO (XEXP (bitfield, 0))]; 2750 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG 2751 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM) 2752 memref = SUBREG_REG (XEXP (bitfield, 0)); 2753 else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG 2754 && equiv_mem != 0 2755 && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG) 2756 memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))]; 2757 2758 if (memref 2759 && ! mode_dependent_address_p (XEXP (memref, 0)) 2760 && ! MEM_VOLATILE_P (memref)) 2761 { 2762 /* Now adjust the address, first for any subreg'ing 2763 that we are now getting rid of, 2764 and then for which byte of the word is wanted. */ 2765 2766 HOST_WIDE_INT offset = INTVAL (XEXP (bitfield, 2)); 2767 rtx insns; 2768 2769 /* Adjust OFFSET to count bits from low-address byte. */ 2770 if (BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN) 2771 offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0))) 2772 - offset - INTVAL (XEXP (bitfield, 1))); 2773 2774 /* Adjust OFFSET to count bytes from low-address byte. */ 2775 offset /= BITS_PER_UNIT; 2776 if (GET_CODE (XEXP (bitfield, 0)) == SUBREG) 2777 { 2778 offset += (SUBREG_BYTE (XEXP (bitfield, 0)) 2779 / UNITS_PER_WORD) * UNITS_PER_WORD; 2780 if (BYTES_BIG_ENDIAN) 2781 offset -= (MIN (UNITS_PER_WORD, 2782 GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0)))) 2783 - MIN (UNITS_PER_WORD, 2784 GET_MODE_SIZE (GET_MODE (memref)))); 2785 } 2786 2787 start_sequence (); 2788 memref = adjust_address (memref, mode, offset); 2789 insns = get_insns (); 2790 end_sequence (); 2791 emit_insns_before (insns, insn); 2792 2793 /* Store this memory reference where 2794 we found the bit field reference. */ 2795 2796 if (destflag) 2797 { 2798 validate_change (insn, &SET_DEST (body), memref, 1); 2799 if (! CONSTANT_ADDRESS_P (SET_SRC (body))) 2800 { 2801 rtx src = SET_SRC (body); 2802 while (GET_CODE (src) == SUBREG 2803 && SUBREG_BYTE (src) == 0) 2804 src = SUBREG_REG (src); 2805 if (GET_MODE (src) != GET_MODE (memref)) 2806 src = gen_lowpart (GET_MODE (memref), SET_SRC (body)); 2807 validate_change (insn, &SET_SRC (body), src, 1); 2808 } 2809 else if (GET_MODE (SET_SRC (body)) != VOIDmode 2810 && GET_MODE (SET_SRC (body)) != GET_MODE (memref)) 2811 /* This shouldn't happen because anything that didn't have 2812 one of these modes should have got converted explicitly 2813 and then referenced through a subreg. 2814 This is so because the original bit-field was 2815 handled by agg_mode and so its tree structure had 2816 the same mode that memref now has. */ 2817 abort (); 2818 } 2819 else 2820 { 2821 rtx dest = SET_DEST (body); 2822 2823 while (GET_CODE (dest) == SUBREG 2824 && SUBREG_BYTE (dest) == 0 2825 && (GET_MODE_CLASS (GET_MODE (dest)) 2826 == GET_MODE_CLASS (GET_MODE (SUBREG_REG (dest)))) 2827 && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) 2828 <= UNITS_PER_WORD)) 2829 dest = SUBREG_REG (dest); 2830 2831 validate_change (insn, &SET_DEST (body), dest, 1); 2832 2833 if (GET_MODE (dest) == GET_MODE (memref)) 2834 validate_change (insn, &SET_SRC (body), memref, 1); 2835 else 2836 { 2837 /* Convert the mem ref to the destination mode. */ 2838 rtx newreg = gen_reg_rtx (GET_MODE (dest)); 2839 2840 start_sequence (); 2841 convert_move (newreg, memref, 2842 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT); 2843 seq = get_insns (); 2844 end_sequence (); 2845 2846 validate_change (insn, &SET_SRC (body), newreg, 1); 2847 } 2848 } 2849 2850 /* See if we can convert this extraction or insertion into 2851 a simple move insn. We might not be able to do so if this 2852 was, for example, part of a PARALLEL. 2853 2854 If we succeed, write out any needed conversions. If we fail, 2855 it is hard to guess why we failed, so don't do anything 2856 special; just let the optimization be suppressed. */ 2857 2858 if (apply_change_group () && seq) 2859 emit_insns_before (seq, insn); 2860 } 2861 } 2862 } 2863 2864 /* These routines are responsible for converting virtual register references 2865 to the actual hard register references once RTL generation is complete. 2866 2867 The following four variables are used for communication between the 2868 routines. They contain the offsets of the virtual registers from their 2869 respective hard registers. */ 2870 2871 static int in_arg_offset; 2872 static int var_offset; 2873 static int dynamic_offset; 2874 static int out_arg_offset; 2875 static int cfa_offset; 2876 2877 /* In most machines, the stack pointer register is equivalent to the bottom 2878 of the stack. */ 2879 2880 #ifndef STACK_POINTER_OFFSET 2881 #define STACK_POINTER_OFFSET 0 2882 #endif 2883 2884 /* If not defined, pick an appropriate default for the offset of dynamically 2885 allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS, 2886 REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE. */ 2887 2888 #ifndef STACK_DYNAMIC_OFFSET 2889 2890 /* The bottom of the stack points to the actual arguments. If 2891 REG_PARM_STACK_SPACE is defined, this includes the space for the register 2892 parameters. However, if OUTGOING_REG_PARM_STACK space is not defined, 2893 stack space for register parameters is not pushed by the caller, but 2894 rather part of the fixed stack areas and hence not included in 2895 `current_function_outgoing_args_size'. Nevertheless, we must allow 2896 for it when allocating stack dynamic objects. */ 2897 2898 #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE) 2899 #define STACK_DYNAMIC_OFFSET(FNDECL) \ 2900 ((ACCUMULATE_OUTGOING_ARGS \ 2901 ? (current_function_outgoing_args_size + REG_PARM_STACK_SPACE (FNDECL)) : 0)\ 2902 + (STACK_POINTER_OFFSET)) \ 2903 2904 #else 2905 #define STACK_DYNAMIC_OFFSET(FNDECL) \ 2906 ((ACCUMULATE_OUTGOING_ARGS ? current_function_outgoing_args_size : 0) \ 2907 + (STACK_POINTER_OFFSET)) 2908 #endif 2909 #endif 2910 2911 /* On most machines, the CFA coincides with the first incoming parm. */ 2912 2913 #ifndef ARG_POINTER_CFA_OFFSET 2914 #define ARG_POINTER_CFA_OFFSET(FNDECL) FIRST_PARM_OFFSET (FNDECL) 2915 #endif 2916 2917 /* Build up a (MEM (ADDRESSOF (REG))) rtx for a register REG that just had its 2918 address taken. DECL is the decl or SAVE_EXPR for the object stored in the 2919 register, for later use if we do need to force REG into the stack. REG is 2920 overwritten by the MEM like in put_reg_into_stack. */ 2921 2922 rtx 2923 gen_mem_addressof (reg, decl) 2924 rtx reg; 2925 tree decl; 2926 { 2927 rtx r = gen_rtx_ADDRESSOF (Pmode, gen_reg_rtx (GET_MODE (reg)), 2928 REGNO (reg), decl); 2929 2930 /* Calculate this before we start messing with decl's RTL. */ 2931 HOST_WIDE_INT set = decl ? get_alias_set (decl) : 0; 2932 2933 /* If the original REG was a user-variable, then so is the REG whose 2934 address is being taken. Likewise for unchanging. */ 2935 REG_USERVAR_P (XEXP (r, 0)) = REG_USERVAR_P (reg); 2936 RTX_UNCHANGING_P (XEXP (r, 0)) = RTX_UNCHANGING_P (reg); 2937 2938 PUT_CODE (reg, MEM); 2939 MEM_ATTRS (reg) = 0; 2940 XEXP (reg, 0) = r; 2941 2942 if (decl) 2943 { 2944 tree type = TREE_TYPE (decl); 2945 enum machine_mode decl_mode 2946 = (DECL_P (decl) ? DECL_MODE (decl) : TYPE_MODE (TREE_TYPE (decl))); 2947 rtx decl_rtl = (TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) 2948 : DECL_RTL_IF_SET (decl)); 2949 2950 PUT_MODE (reg, decl_mode); 2951 2952 /* Clear DECL_RTL momentarily so functions below will work 2953 properly, then set it again. */ 2954 if (DECL_P (decl) && decl_rtl == reg) 2955 SET_DECL_RTL (decl, 0); 2956 2957 set_mem_attributes (reg, decl, 1); 2958 set_mem_alias_set (reg, set); 2959 2960 if (DECL_P (decl) && decl_rtl == reg) 2961 SET_DECL_RTL (decl, reg); 2962 2963 if (TREE_USED (decl) || (DECL_P (decl) && DECL_INITIAL (decl) != 0)) 2964 fixup_var_refs (reg, GET_MODE (reg), TREE_UNSIGNED (type), reg, 0); 2965 } 2966 else 2967 fixup_var_refs (reg, GET_MODE (reg), 0, reg, 0); 2968 2969 return reg; 2970 } 2971 2972 /* If DECL has an RTL that is an ADDRESSOF rtx, put it into the stack. */ 2973 2974 void 2975 flush_addressof (decl) 2976 tree decl; 2977 { 2978 if ((TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == VAR_DECL) 2979 && DECL_RTL (decl) != 0 2980 && GET_CODE (DECL_RTL (decl)) == MEM 2981 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF 2982 && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG) 2983 put_addressof_into_stack (XEXP (DECL_RTL (decl), 0), 0); 2984 } 2985 2986 /* Force the register pointed to by R, an ADDRESSOF rtx, into the stack. */ 2987 2988 static void 2989 put_addressof_into_stack (r, ht) 2990 rtx r; 2991 struct hash_table *ht; 2992 { 2993 tree decl, type; 2994 int volatile_p, used_p; 2995 2996 rtx reg = XEXP (r, 0); 2997 2998 if (GET_CODE (reg) != REG) 2999 abort (); 3000 3001 decl = ADDRESSOF_DECL (r); 3002 if (decl) 3003 { 3004 type = TREE_TYPE (decl); 3005 volatile_p = (TREE_CODE (decl) != SAVE_EXPR 3006 && TREE_THIS_VOLATILE (decl)); 3007 used_p = (TREE_USED (decl) 3008 || (DECL_P (decl) && DECL_INITIAL (decl) != 0)); 3009 } 3010 else 3011 { 3012 type = NULL_TREE; 3013 volatile_p = 0; 3014 used_p = 1; 3015 } 3016 3017 put_reg_into_stack (0, reg, type, GET_MODE (reg), GET_MODE (reg), 3018 volatile_p, ADDRESSOF_REGNO (r), used_p, ht); 3019 } 3020 3021 /* List of replacements made below in purge_addressof_1 when creating 3022 bitfield insertions. */ 3023 static rtx purge_bitfield_addressof_replacements; 3024 3025 /* List of replacements made below in purge_addressof_1 for patterns 3026 (MEM (ADDRESSOF (REG ...))). The key of the list entry is the 3027 corresponding (ADDRESSOF (REG ...)) and value is a substitution for 3028 the all pattern. List PURGE_BITFIELD_ADDRESSOF_REPLACEMENTS is not 3029 enough in complex cases, e.g. when some field values can be 3030 extracted by usage MEM with narrower mode. */ 3031 static rtx purge_addressof_replacements; 3032 3033 /* Helper function for purge_addressof. See if the rtx expression at *LOC 3034 in INSN needs to be changed. If FORCE, always put any ADDRESSOFs into 3035 the stack. If the function returns FALSE then the replacement could not 3036 be made. */ 3037 3038 static bool 3039 purge_addressof_1 (loc, insn, force, store, ht) 3040 rtx *loc; 3041 rtx insn; 3042 int force, store; 3043 struct hash_table *ht; 3044 { 3045 rtx x; 3046 RTX_CODE code; 3047 int i, j; 3048 const char *fmt; 3049 bool result = true; 3050 3051 /* Re-start here to avoid recursion in common cases. */ 3052 restart: 3053 3054 x = *loc; 3055 if (x == 0) 3056 return true; 3057 3058 code = GET_CODE (x); 3059 3060 /* If we don't return in any of the cases below, we will recurse inside 3061 the RTX, which will normally result in any ADDRESSOF being forced into 3062 memory. */ 3063 if (code == SET) 3064 { 3065 result = purge_addressof_1 (&SET_DEST (x), insn, force, 1, ht); 3066 result &= purge_addressof_1 (&SET_SRC (x), insn, force, 0, ht); 3067 return result; 3068 } 3069 else if (code == ADDRESSOF) 3070 { 3071 rtx sub, insns; 3072 3073 if (GET_CODE (XEXP (x, 0)) != MEM) 3074 { 3075 put_addressof_into_stack (x, ht); 3076 return true; 3077 } 3078 3079 /* We must create a copy of the rtx because it was created by 3080 overwriting a REG rtx which is always shared. */ 3081 sub = copy_rtx (XEXP (XEXP (x, 0), 0)); 3082 if (validate_change (insn, loc, sub, 0) 3083 || validate_replace_rtx (x, sub, insn)) 3084 return true; 3085 3086 start_sequence (); 3087 sub = force_operand (sub, NULL_RTX); 3088 if (! validate_change (insn, loc, sub, 0) 3089 && ! validate_replace_rtx (x, sub, insn)) 3090 abort (); 3091 3092 insns = gen_sequence (); 3093 end_sequence (); 3094 emit_insn_before (insns, insn); 3095 return true; 3096 } 3097 3098 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force) 3099 { 3100 rtx sub = XEXP (XEXP (x, 0), 0); 3101 3102 if (GET_CODE (sub) == MEM) 3103 sub = adjust_address_nv (sub, GET_MODE (x), 0); 3104 else if (GET_CODE (sub) == REG 3105 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)) 3106 ; 3107 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub)) 3108 { 3109 int size_x, size_sub; 3110 3111 if (!insn) 3112 { 3113 /* When processing REG_NOTES look at the list of 3114 replacements done on the insn to find the register that X 3115 was replaced by. */ 3116 rtx tem; 3117 3118 for (tem = purge_bitfield_addressof_replacements; 3119 tem != NULL_RTX; 3120 tem = XEXP (XEXP (tem, 1), 1)) 3121 if (rtx_equal_p (x, XEXP (tem, 0))) 3122 { 3123 *loc = XEXP (XEXP (tem, 1), 0); 3124 return true; 3125 } 3126 3127 /* See comment for purge_addressof_replacements. */ 3128 for (tem = purge_addressof_replacements; 3129 tem != NULL_RTX; 3130 tem = XEXP (XEXP (tem, 1), 1)) 3131 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) 3132 { 3133 rtx z = XEXP (XEXP (tem, 1), 0); 3134 3135 if (GET_MODE (x) == GET_MODE (z) 3136 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG 3137 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG)) 3138 abort (); 3139 3140 /* It can happen that the note may speak of things 3141 in a wider (or just different) mode than the 3142 code did. This is especially true of 3143 REG_RETVAL. */ 3144 3145 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0) 3146 z = SUBREG_REG (z); 3147 3148 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD 3149 && (GET_MODE_SIZE (GET_MODE (x)) 3150 > GET_MODE_SIZE (GET_MODE (z)))) 3151 { 3152 /* This can occur as a result in invalid 3153 pointer casts, e.g. float f; ... 3154 *(long long int *)&f. 3155 ??? We could emit a warning here, but 3156 without a line number that wouldn't be 3157 very helpful. */ 3158 z = gen_rtx_SUBREG (GET_MODE (x), z, 0); 3159 } 3160 else 3161 z = gen_lowpart (GET_MODE (x), z); 3162 3163 *loc = z; 3164 return true; 3165 } 3166 3167 /* Sometimes we may not be able to find the replacement. For 3168 example when the original insn was a MEM in a wider mode, 3169 and the note is part of a sign extension of a narrowed 3170 version of that MEM. Gcc testcase compile/990829-1.c can 3171 generate an example of this situation. Rather than complain 3172 we return false, which will prompt our caller to remove the 3173 offending note. */ 3174 return false; 3175 } 3176 3177 size_x = GET_MODE_BITSIZE (GET_MODE (x)); 3178 size_sub = GET_MODE_BITSIZE (GET_MODE (sub)); 3179 3180 /* Don't even consider working with paradoxical subregs, 3181 or the moral equivalent seen here. */ 3182 if (size_x <= size_sub 3183 && int_mode_for_mode (GET_MODE (sub)) != BLKmode) 3184 { 3185 /* Do a bitfield insertion to mirror what would happen 3186 in memory. */ 3187 3188 rtx val, seq; 3189 3190 if (store) 3191 { 3192 rtx p = PREV_INSN (insn); 3193 3194 start_sequence (); 3195 val = gen_reg_rtx (GET_MODE (x)); 3196 if (! validate_change (insn, loc, val, 0)) 3197 { 3198 /* Discard the current sequence and put the 3199 ADDRESSOF on stack. */ 3200 end_sequence (); 3201 goto give_up; 3202 } 3203 seq = gen_sequence (); 3204 end_sequence (); 3205 emit_insn_before (seq, insn); 3206 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), 3207 insn, ht); 3208 3209 start_sequence (); 3210 store_bit_field (sub, size_x, 0, GET_MODE (x), 3211 val, GET_MODE_SIZE (GET_MODE (sub))); 3212 3213 /* Make sure to unshare any shared rtl that store_bit_field 3214 might have created. */ 3215 unshare_all_rtl_again (get_insns ()); 3216 3217 seq = gen_sequence (); 3218 end_sequence (); 3219 p = emit_insn_after (seq, insn); 3220 if (NEXT_INSN (insn)) 3221 compute_insns_for_mem (NEXT_INSN (insn), 3222 p ? NEXT_INSN (p) : NULL_RTX, 3223 ht); 3224 } 3225 else 3226 { 3227 rtx p = PREV_INSN (insn); 3228 3229 start_sequence (); 3230 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX, 3231 GET_MODE (x), GET_MODE (x), 3232 GET_MODE_SIZE (GET_MODE (sub))); 3233 3234 if (! validate_change (insn, loc, val, 0)) 3235 { 3236 /* Discard the current sequence and put the 3237 ADDRESSOF on stack. */ 3238 end_sequence (); 3239 goto give_up; 3240 } 3241 3242 seq = gen_sequence (); 3243 end_sequence (); 3244 emit_insn_before (seq, insn); 3245 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), 3246 insn, ht); 3247 } 3248 3249 /* Remember the replacement so that the same one can be done 3250 on the REG_NOTES. */ 3251 purge_bitfield_addressof_replacements 3252 = gen_rtx_EXPR_LIST (VOIDmode, x, 3253 gen_rtx_EXPR_LIST 3254 (VOIDmode, val, 3255 purge_bitfield_addressof_replacements)); 3256 3257 /* We replaced with a reg -- all done. */ 3258 return true; 3259 } 3260 } 3261 3262 else if (validate_change (insn, loc, sub, 0)) 3263 { 3264 /* Remember the replacement so that the same one can be done 3265 on the REG_NOTES. */ 3266 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG) 3267 { 3268 rtx tem; 3269 3270 for (tem = purge_addressof_replacements; 3271 tem != NULL_RTX; 3272 tem = XEXP (XEXP (tem, 1), 1)) 3273 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) 3274 { 3275 XEXP (XEXP (tem, 1), 0) = sub; 3276 return true; 3277 } 3278 purge_addressof_replacements 3279 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0), 3280 gen_rtx_EXPR_LIST (VOIDmode, sub, 3281 purge_addressof_replacements)); 3282 return true; 3283 } 3284 goto restart; 3285 } 3286 } 3287 3288 give_up: 3289 /* Scan all subexpressions. */ 3290 fmt = GET_RTX_FORMAT (code); 3291 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) 3292 { 3293 if (*fmt == 'e') 3294 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht); 3295 else if (*fmt == 'E') 3296 for (j = 0; j < XVECLEN (x, i); j++) 3297 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht); 3298 } 3299 3300 return result; 3301 } 3302 3303 /* Return a new hash table entry in HT. */ 3304 3305 static struct hash_entry * 3306 insns_for_mem_newfunc (he, ht, k) 3307 struct hash_entry *he; 3308 struct hash_table *ht; 3309 hash_table_key k ATTRIBUTE_UNUSED; 3310 { 3311 struct insns_for_mem_entry *ifmhe; 3312 if (he) 3313 return he; 3314 3315 ifmhe = ((struct insns_for_mem_entry *) 3316 hash_allocate (ht, sizeof (struct insns_for_mem_entry))); 3317 ifmhe->insns = NULL_RTX; 3318 3319 return &ifmhe->he; 3320 } 3321 3322 /* Return a hash value for K, a REG. */ 3323 3324 static unsigned long 3325 insns_for_mem_hash (k) 3326 hash_table_key k; 3327 { 3328 /* K is really a RTX. Just use the address as the hash value. */ 3329 return (unsigned long) k; 3330 } 3331 3332 /* Return non-zero if K1 and K2 (two REGs) are the same. */ 3333 3334 static bool 3335 insns_for_mem_comp (k1, k2) 3336 hash_table_key k1; 3337 hash_table_key k2; 3338 { 3339 return k1 == k2; 3340 } 3341 3342 struct insns_for_mem_walk_info 3343 { 3344 /* The hash table that we are using to record which INSNs use which 3345 MEMs. */ 3346 struct hash_table *ht; 3347 3348 /* The INSN we are currently processing. */ 3349 rtx insn; 3350 3351 /* Zero if we are walking to find ADDRESSOFs, one if we are walking 3352 to find the insns that use the REGs in the ADDRESSOFs. */ 3353 int pass; 3354 }; 3355 3356 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG 3357 that might be used in an ADDRESSOF expression, record this INSN in 3358 the hash table given by DATA (which is really a pointer to an 3359 insns_for_mem_walk_info structure). */ 3360 3361 static int 3362 insns_for_mem_walk (r, data) 3363 rtx *r; 3364 void *data; 3365 { 3366 struct insns_for_mem_walk_info *ifmwi 3367 = (struct insns_for_mem_walk_info *) data; 3368 3369 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF 3370 && GET_CODE (XEXP (*r, 0)) == REG) 3371 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0); 3372 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG) 3373 { 3374 /* Lookup this MEM in the hashtable, creating it if necessary. */ 3375 struct insns_for_mem_entry *ifme 3376 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht, 3377 *r, 3378 /*create=*/0, 3379 /*copy=*/0); 3380 3381 /* If we have not already recorded this INSN, do so now. Since 3382 we process the INSNs in order, we know that if we have 3383 recorded it it must be at the front of the list. */ 3384 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn)) 3385 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn, 3386 ifme->insns); 3387 } 3388 3389 return 0; 3390 } 3391 3392 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use 3393 which REGs in HT. */ 3394 3395 static void 3396 compute_insns_for_mem (insns, last_insn, ht) 3397 rtx insns; 3398 rtx last_insn; 3399 struct hash_table *ht; 3400 { 3401 rtx insn; 3402 struct insns_for_mem_walk_info ifmwi; 3403 ifmwi.ht = ht; 3404 3405 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass) 3406 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn)) 3407 if (INSN_P (insn)) 3408 { 3409 ifmwi.insn = insn; 3410 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi); 3411 } 3412 } 3413 3414 /* Helper function for purge_addressof called through for_each_rtx. 3415 Returns true iff the rtl is an ADDRESSOF. */ 3416 3417 static int 3418 is_addressof (rtl, data) 3419 rtx *rtl; 3420 void *data ATTRIBUTE_UNUSED; 3421 { 3422 return GET_CODE (*rtl) == ADDRESSOF; 3423 } 3424 3425 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining 3426 (MEM (ADDRESSOF)) patterns, and force any needed registers into the 3427 stack. */ 3428 3429 void 3430 purge_addressof (insns) 3431 rtx insns; 3432 { 3433 rtx insn; 3434 struct hash_table ht; 3435 3436 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That 3437 requires a fixup pass over the instruction stream to correct 3438 INSNs that depended on the REG being a REG, and not a MEM. But, 3439 these fixup passes are slow. Furthermore, most MEMs are not 3440 mentioned in very many instructions. So, we speed up the process 3441 by pre-calculating which REGs occur in which INSNs; that allows 3442 us to perform the fixup passes much more quickly. */ 3443 hash_table_init (&ht, 3444 insns_for_mem_newfunc, 3445 insns_for_mem_hash, 3446 insns_for_mem_comp); 3447 compute_insns_for_mem (insns, NULL_RTX, &ht); 3448 3449 for (insn = insns; insn; insn = NEXT_INSN (insn)) 3450 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN 3451 || GET_CODE (insn) == CALL_INSN) 3452 { 3453 if (! purge_addressof_1 (&PATTERN (insn), insn, 3454 asm_noperands (PATTERN (insn)) > 0, 0, &ht)) 3455 /* If we could not replace the ADDRESSOFs in the insn, 3456 something is wrong. */ 3457 abort (); 3458 3459 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht)) 3460 { 3461 /* If we could not replace the ADDRESSOFs in the insn's notes, 3462 we can just remove the offending notes instead. */ 3463 rtx note; 3464 3465 for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) 3466 { 3467 /* If we find a REG_RETVAL note then the insn is a libcall. 3468 Such insns must have REG_EQUAL notes as well, in order 3469 for later passes of the compiler to work. So it is not 3470 safe to delete the notes here, and instead we abort. */ 3471 if (REG_NOTE_KIND (note) == REG_RETVAL) 3472 abort (); 3473 if (for_each_rtx (¬e, is_addressof, NULL)) 3474 remove_note (insn, note); 3475 } 3476 } 3477 } 3478 3479 /* Clean up. */ 3480 hash_table_free (&ht); 3481 purge_bitfield_addressof_replacements = 0; 3482 purge_addressof_replacements = 0; 3483 3484 /* REGs are shared. purge_addressof will destructively replace a REG 3485 with a MEM, which creates shared MEMs. 3486 3487 Unfortunately, the children of put_reg_into_stack assume that MEMs 3488 referring to the same stack slot are shared (fixup_var_refs and 3489 the associated hash table code). 3490 3491 So, we have to do another unsharing pass after we have flushed any 3492 REGs that had their address taken into the stack. 3493 3494 It may be worth tracking whether or not we converted any REGs into 3495 MEMs to avoid this overhead when it is not needed. */ 3496 unshare_all_rtl_again (get_insns ()); 3497 } 3498 3499 /* Convert a SET of a hard subreg to a set of the appropriate hard 3500 register. A subroutine of purge_hard_subreg_sets. */ 3501 3502 static void 3503 purge_single_hard_subreg_set (pattern) 3504 rtx pattern; 3505 { 3506 rtx reg = SET_DEST (pattern); 3507 enum machine_mode mode = GET_MODE (SET_DEST (pattern)); 3508 int offset = 0; 3509 3510 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG 3511 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER) 3512 { 3513 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)), 3514 GET_MODE (SUBREG_REG (reg)), 3515 SUBREG_BYTE (reg), 3516 GET_MODE (reg)); 3517 reg = SUBREG_REG (reg); 3518 } 3519 3520 3521 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER) 3522 { 3523 reg = gen_rtx_REG (mode, REGNO (reg) + offset); 3524 SET_DEST (pattern) = reg; 3525 } 3526 } 3527 3528 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The 3529 only such SETs that we expect to see are those left in because 3530 integrate can't handle sets of parts of a return value register. 3531 3532 We don't use alter_subreg because we only want to eliminate subregs 3533 of hard registers. */ 3534 3535 void 3536 purge_hard_subreg_sets (insn) 3537 rtx insn; 3538 { 3539 for (; insn; insn = NEXT_INSN (insn)) 3540 { 3541 if (INSN_P (insn)) 3542 { 3543 rtx pattern = PATTERN (insn); 3544 switch (GET_CODE (pattern)) 3545 { 3546 case SET: 3547 if (GET_CODE (SET_DEST (pattern)) == SUBREG) 3548 purge_single_hard_subreg_set (pattern); 3549 break; 3550 case PARALLEL: 3551 { 3552 int j; 3553 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--) 3554 { 3555 rtx inner_pattern = XVECEXP (pattern, 0, j); 3556 if (GET_CODE (inner_pattern) == SET 3557 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG) 3558 purge_single_hard_subreg_set (inner_pattern); 3559 } 3560 } 3561 break; 3562 default: 3563 break; 3564 } 3565 } 3566 } 3567 } 3568 3569 /* Pass through the INSNS of function FNDECL and convert virtual register 3570 references to hard register references. */ 3571 3572 void 3573 instantiate_virtual_regs (fndecl, insns) 3574 tree fndecl; 3575 rtx insns; 3576 { 3577 rtx insn; 3578 unsigned int i; 3579 3580 /* Compute the offsets to use for this function. */ 3581 in_arg_offset = FIRST_PARM_OFFSET (fndecl); 3582 var_offset = STARTING_FRAME_OFFSET; 3583 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl); 3584 out_arg_offset = STACK_POINTER_OFFSET; 3585 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl); 3586 3587 /* Scan all variables and parameters of this function. For each that is 3588 in memory, instantiate all virtual registers if the result is a valid 3589 address. If not, we do it later. That will handle most uses of virtual 3590 regs on many machines. */ 3591 instantiate_decls (fndecl, 1); 3592 3593 /* Initialize recognition, indicating that volatile is OK. */ 3594 init_recog (); 3595 3596 /* Scan through all the insns, instantiating every virtual register still 3597 present. */ 3598 for (insn = insns; insn; insn = NEXT_INSN (insn)) 3599 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN 3600 || GET_CODE (insn) == CALL_INSN) 3601 { 3602 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1); 3603 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0); 3604 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */ 3605 if (GET_CODE (insn) == CALL_INSN) 3606 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn), 3607 NULL_RTX, 0); 3608 } 3609 3610 /* Instantiate the stack slots for the parm registers, for later use in 3611 addressof elimination. */ 3612 for (i = 0; i < max_parm_reg; ++i) 3613 if (parm_reg_stack_loc[i]) 3614 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0); 3615 3616 /* Now instantiate the remaining register equivalences for debugging info. 3617 These will not be valid addresses. */ 3618 instantiate_decls (fndecl, 0); 3619 3620 /* Indicate that, from now on, assign_stack_local should use 3621 frame_pointer_rtx. */ 3622 virtuals_instantiated = 1; 3623 } 3624 3625 /* Scan all decls in FNDECL (both variables and parameters) and instantiate 3626 all virtual registers in their DECL_RTL's. 3627 3628 If VALID_ONLY, do this only if the resulting address is still valid. 3629 Otherwise, always do it. */ 3630 3631 static void 3632 instantiate_decls (fndecl, valid_only) 3633 tree fndecl; 3634 int valid_only; 3635 { 3636 tree decl; 3637 3638 /* Process all parameters of the function. */ 3639 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) 3640 { 3641 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); 3642 HOST_WIDE_INT size_rtl; 3643 3644 instantiate_decl (DECL_RTL (decl), size, valid_only); 3645 3646 /* If the parameter was promoted, then the incoming RTL mode may be 3647 larger than the declared type size. We must use the larger of 3648 the two sizes. */ 3649 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))); 3650 size = MAX (size_rtl, size); 3651 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only); 3652 } 3653 3654 /* Now process all variables defined in the function or its subblocks. */ 3655 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only); 3656 } 3657 3658 /* Subroutine of instantiate_decls: Process all decls in the given 3659 BLOCK node and all its subblocks. */ 3660 3661 static void 3662 instantiate_decls_1 (let, valid_only) 3663 tree let; 3664 int valid_only; 3665 { 3666 tree t; 3667 3668 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) 3669 if (DECL_RTL_SET_P (t)) 3670 instantiate_decl (DECL_RTL (t), 3671 int_size_in_bytes (TREE_TYPE (t)), 3672 valid_only); 3673 3674 /* Process all subblocks. */ 3675 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t)) 3676 instantiate_decls_1 (t, valid_only); 3677 } 3678 3679 /* Subroutine of the preceding procedures: Given RTL representing a 3680 decl and the size of the object, do any instantiation required. 3681 3682 If VALID_ONLY is non-zero, it means that the RTL should only be 3683 changed if the new address is valid. */ 3684 3685 static void 3686 instantiate_decl (x, size, valid_only) 3687 rtx x; 3688 HOST_WIDE_INT size; 3689 int valid_only; 3690 { 3691 enum machine_mode mode; 3692 rtx addr; 3693 3694 /* If this is not a MEM, no need to do anything. Similarly if the 3695 address is a constant or a register that is not a virtual register. */ 3696 3697 if (x == 0 || GET_CODE (x) != MEM) 3698 return; 3699 3700 addr = XEXP (x, 0); 3701 if (CONSTANT_P (addr) 3702 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG) 3703 || (GET_CODE (addr) == REG 3704 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER 3705 || REGNO (addr) > LAST_VIRTUAL_REGISTER))) 3706 return; 3707 3708 /* If we should only do this if the address is valid, copy the address. 3709 We need to do this so we can undo any changes that might make the 3710 address invalid. This copy is unfortunate, but probably can't be 3711 avoided. */ 3712 3713 if (valid_only) 3714 addr = copy_rtx (addr); 3715 3716 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0); 3717 3718 if (valid_only && size >= 0) 3719 { 3720 unsigned HOST_WIDE_INT decl_size = size; 3721 3722 /* Now verify that the resulting address is valid for every integer or 3723 floating-point mode up to and including SIZE bytes long. We do this 3724 since the object might be accessed in any mode and frame addresses 3725 are shared. */ 3726 3727 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); 3728 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size; 3729 mode = GET_MODE_WIDER_MODE (mode)) 3730 if (! memory_address_p (mode, addr)) 3731 return; 3732 3733 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); 3734 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size; 3735 mode = GET_MODE_WIDER_MODE (mode)) 3736 if (! memory_address_p (mode, addr)) 3737 return; 3738 } 3739 3740 /* Put back the address now that we have updated it and we either know 3741 it is valid or we don't care whether it is valid. */ 3742 3743 XEXP (x, 0) = addr; 3744 } 3745 3746 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX 3747 is a virtual register, return the equivalent hard register and set the 3748 offset indirectly through the pointer. Otherwise, return 0. */ 3749 3750 static rtx 3751 instantiate_new_reg (x, poffset) 3752 rtx x; 3753 HOST_WIDE_INT *poffset; 3754 { 3755 rtx new; 3756 HOST_WIDE_INT offset; 3757 3758 if (x == virtual_incoming_args_rtx) 3759 new = arg_pointer_rtx, offset = in_arg_offset; 3760 else if (x == virtual_stack_vars_rtx) 3761 new = frame_pointer_rtx, offset = var_offset; 3762 else if (x == virtual_stack_dynamic_rtx) 3763 new = stack_pointer_rtx, offset = dynamic_offset; 3764 else if (x == virtual_outgoing_args_rtx) 3765 new = stack_pointer_rtx, offset = out_arg_offset; 3766 else if (x == virtual_cfa_rtx) 3767 new = arg_pointer_rtx, offset = cfa_offset; 3768 else 3769 return 0; 3770 3771 *poffset = offset; 3772 return new; 3773 } 3774 3775 /* Given a pointer to a piece of rtx and an optional pointer to the 3776 containing object, instantiate any virtual registers present in it. 3777 3778 If EXTRA_INSNS, we always do the replacement and generate 3779 any extra insns before OBJECT. If it zero, we do nothing if replacement 3780 is not valid. 3781 3782 Return 1 if we either had nothing to do or if we were able to do the 3783 needed replacement. Return 0 otherwise; we only return zero if 3784 EXTRA_INSNS is zero. 3785 3786 We first try some simple transformations to avoid the creation of extra 3787 pseudos. */ 3788 3789 static int 3790 instantiate_virtual_regs_1 (loc, object, extra_insns) 3791 rtx *loc; 3792 rtx object; 3793 int extra_insns; 3794 { 3795 rtx x; 3796 RTX_CODE code; 3797 rtx new = 0; 3798 HOST_WIDE_INT offset = 0; 3799 rtx temp; 3800 rtx seq; 3801 int i, j; 3802 const char *fmt; 3803 3804 /* Re-start here to avoid recursion in common cases. */ 3805 restart: 3806 3807 x = *loc; 3808 if (x == 0) 3809 return 1; 3810 3811 code = GET_CODE (x); 3812 3813 /* Check for some special cases. */ 3814 switch (code) 3815 { 3816 case CONST_INT: 3817 case CONST_DOUBLE: 3818 case CONST_VECTOR: 3819 case CONST: 3820 case SYMBOL_REF: 3821 case CODE_LABEL: 3822 case PC: 3823 case CC0: 3824 case ASM_INPUT: 3825 case ADDR_VEC: 3826 case ADDR_DIFF_VEC: 3827 case RETURN: 3828 return 1; 3829 3830 case SET: 3831 /* We are allowed to set the virtual registers. This means that 3832 the actual register should receive the source minus the 3833 appropriate offset. This is used, for example, in the handling 3834 of non-local gotos. */ 3835 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0) 3836 { 3837 rtx src = SET_SRC (x); 3838 3839 /* We are setting the register, not using it, so the relevant 3840 offset is the negative of the offset to use were we using 3841 the register. */ 3842 offset = - offset; 3843 instantiate_virtual_regs_1 (&src, NULL_RTX, 0); 3844 3845 /* The only valid sources here are PLUS or REG. Just do 3846 the simplest possible thing to handle them. */ 3847 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS) 3848 abort (); 3849 3850 start_sequence (); 3851 if (GET_CODE (src) != REG) 3852 temp = force_operand (src, NULL_RTX); 3853 else 3854 temp = src; 3855 temp = force_operand (plus_constant (temp, offset), NULL_RTX); 3856 seq = get_insns (); 3857 end_sequence (); 3858 3859 emit_insns_before (seq, object); 3860 SET_DEST (x) = new; 3861 3862 if (! validate_change (object, &SET_SRC (x), temp, 0) 3863 || ! extra_insns) 3864 abort (); 3865 3866 return 1; 3867 } 3868 3869 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns); 3870 loc = &SET_SRC (x); 3871 goto restart; 3872 3873 case PLUS: 3874 /* Handle special case of virtual register plus constant. */ 3875 if (CONSTANT_P (XEXP (x, 1))) 3876 { 3877 rtx old, new_offset; 3878 3879 /* Check for (plus (plus VIRT foo) (const_int)) first. */ 3880 if (GET_CODE (XEXP (x, 0)) == PLUS) 3881 { 3882 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset))) 3883 { 3884 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object, 3885 extra_insns); 3886 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1)); 3887 } 3888 else 3889 { 3890 loc = &XEXP (x, 0); 3891 goto restart; 3892 } 3893 } 3894 3895 #ifdef POINTERS_EXTEND_UNSIGNED 3896 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know 3897 we can commute the PLUS and SUBREG because pointers into the 3898 frame are well-behaved. */ 3899 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode 3900 && GET_CODE (XEXP (x, 1)) == CONST_INT 3901 && 0 != (new 3902 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)), 3903 &offset)) 3904 && validate_change (object, loc, 3905 plus_constant (gen_lowpart (ptr_mode, 3906 new), 3907 offset 3908 + INTVAL (XEXP (x, 1))), 3909 0)) 3910 return 1; 3911 #endif 3912 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0) 3913 { 3914 /* We know the second operand is a constant. Unless the 3915 first operand is a REG (which has been already checked), 3916 it needs to be checked. */ 3917 if (GET_CODE (XEXP (x, 0)) != REG) 3918 { 3919 loc = &XEXP (x, 0); 3920 goto restart; 3921 } 3922 return 1; 3923 } 3924 3925 new_offset = plus_constant (XEXP (x, 1), offset); 3926 3927 /* If the new constant is zero, try to replace the sum with just 3928 the register. */ 3929 if (new_offset == const0_rtx 3930 && validate_change (object, loc, new, 0)) 3931 return 1; 3932 3933 /* Next try to replace the register and new offset. 3934 There are two changes to validate here and we can't assume that 3935 in the case of old offset equals new just changing the register 3936 will yield a valid insn. In the interests of a little efficiency, 3937 however, we only call validate change once (we don't queue up the 3938 changes and then call apply_change_group). */ 3939 3940 old = XEXP (x, 0); 3941 if (offset == 0 3942 ? ! validate_change (object, &XEXP (x, 0), new, 0) 3943 : (XEXP (x, 0) = new, 3944 ! validate_change (object, &XEXP (x, 1), new_offset, 0))) 3945 { 3946 if (! extra_insns) 3947 { 3948 XEXP (x, 0) = old; 3949 return 0; 3950 } 3951 3952 /* Otherwise copy the new constant into a register and replace 3953 constant with that register. */ 3954 temp = gen_reg_rtx (Pmode); 3955 XEXP (x, 0) = new; 3956 if (validate_change (object, &XEXP (x, 1), temp, 0)) 3957 emit_insn_before (gen_move_insn (temp, new_offset), object); 3958 else 3959 { 3960 /* If that didn't work, replace this expression with a 3961 register containing the sum. */ 3962 3963 XEXP (x, 0) = old; 3964 new = gen_rtx_PLUS (Pmode, new, new_offset); 3965 3966 start_sequence (); 3967 temp = force_operand (new, NULL_RTX); 3968 seq = get_insns (); 3969 end_sequence (); 3970 3971 emit_insns_before (seq, object); 3972 if (! validate_change (object, loc, temp, 0) 3973 && ! validate_replace_rtx (x, temp, object)) 3974 abort (); 3975 } 3976 } 3977 3978 return 1; 3979 } 3980 3981 /* Fall through to generic two-operand expression case. */ 3982 case EXPR_LIST: 3983 case CALL: 3984 case COMPARE: 3985 case MINUS: 3986 case MULT: 3987 case DIV: case UDIV: 3988 case MOD: case UMOD: 3989 case AND: case IOR: case XOR: 3990 case ROTATERT: case ROTATE: 3991 case ASHIFTRT: case LSHIFTRT: case ASHIFT: 3992 case NE: case EQ: 3993 case GE: case GT: case GEU: case GTU: 3994 case LE: case LT: case LEU: case LTU: 3995 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1))) 3996 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns); 3997 loc = &XEXP (x, 0); 3998 goto restart; 3999 4000 case MEM: 4001 /* Most cases of MEM that convert to valid addresses have already been 4002 handled by our scan of decls. The only special handling we 4003 need here is to make a copy of the rtx to ensure it isn't being 4004 shared if we have to change it to a pseudo. 4005 4006 If the rtx is a simple reference to an address via a virtual register, 4007 it can potentially be shared. In such cases, first try to make it 4008 a valid address, which can also be shared. Otherwise, copy it and 4009 proceed normally. 4010 4011 First check for common cases that need no processing. These are 4012 usually due to instantiation already being done on a previous instance 4013 of a shared rtx. */ 4014 4015 temp = XEXP (x, 0); 4016 if (CONSTANT_ADDRESS_P (temp) 4017 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4018 || temp == arg_pointer_rtx 4019 #endif 4020 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 4021 || temp == hard_frame_pointer_rtx 4022 #endif 4023 || temp == frame_pointer_rtx) 4024 return 1; 4025 4026 if (GET_CODE (temp) == PLUS 4027 && CONSTANT_ADDRESS_P (XEXP (temp, 1)) 4028 && (XEXP (temp, 0) == frame_pointer_rtx 4029 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 4030 || XEXP (temp, 0) == hard_frame_pointer_rtx 4031 #endif 4032 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4033 || XEXP (temp, 0) == arg_pointer_rtx 4034 #endif 4035 )) 4036 return 1; 4037 4038 if (temp == virtual_stack_vars_rtx 4039 || temp == virtual_incoming_args_rtx 4040 || (GET_CODE (temp) == PLUS 4041 && CONSTANT_ADDRESS_P (XEXP (temp, 1)) 4042 && (XEXP (temp, 0) == virtual_stack_vars_rtx 4043 || XEXP (temp, 0) == virtual_incoming_args_rtx))) 4044 { 4045 /* This MEM may be shared. If the substitution can be done without 4046 the need to generate new pseudos, we want to do it in place 4047 so all copies of the shared rtx benefit. The call below will 4048 only make substitutions if the resulting address is still 4049 valid. 4050 4051 Note that we cannot pass X as the object in the recursive call 4052 since the insn being processed may not allow all valid 4053 addresses. However, if we were not passed on object, we can 4054 only modify X without copying it if X will have a valid 4055 address. 4056 4057 ??? Also note that this can still lose if OBJECT is an insn that 4058 has less restrictions on an address that some other insn. 4059 In that case, we will modify the shared address. This case 4060 doesn't seem very likely, though. One case where this could 4061 happen is in the case of a USE or CLOBBER reference, but we 4062 take care of that below. */ 4063 4064 if (instantiate_virtual_regs_1 (&XEXP (x, 0), 4065 object ? object : x, 0)) 4066 return 1; 4067 4068 /* Otherwise make a copy and process that copy. We copy the entire 4069 RTL expression since it might be a PLUS which could also be 4070 shared. */ 4071 *loc = x = copy_rtx (x); 4072 } 4073 4074 /* Fall through to generic unary operation case. */ 4075 case PREFETCH: 4076 case SUBREG: 4077 case STRICT_LOW_PART: 4078 case NEG: case NOT: 4079 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC: 4080 case SIGN_EXTEND: case ZERO_EXTEND: 4081 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: 4082 case FLOAT: case FIX: 4083 case UNSIGNED_FIX: case UNSIGNED_FLOAT: 4084 case ABS: 4085 case SQRT: 4086 case FFS: 4087 /* These case either have just one operand or we know that we need not 4088 check the rest of the operands. */ 4089 loc = &XEXP (x, 0); 4090 goto restart; 4091 4092 case USE: 4093 case CLOBBER: 4094 /* If the operand is a MEM, see if the change is a valid MEM. If not, 4095 go ahead and make the invalid one, but do it to a copy. For a REG, 4096 just make the recursive call, since there's no chance of a problem. */ 4097 4098 if ((GET_CODE (XEXP (x, 0)) == MEM 4099 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0), 4100 0)) 4101 || (GET_CODE (XEXP (x, 0)) == REG 4102 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0))) 4103 return 1; 4104 4105 XEXP (x, 0) = copy_rtx (XEXP (x, 0)); 4106 loc = &XEXP (x, 0); 4107 goto restart; 4108 4109 case REG: 4110 /* Try to replace with a PLUS. If that doesn't work, compute the sum 4111 in front of this insn and substitute the temporary. */ 4112 if ((new = instantiate_new_reg (x, &offset)) != 0) 4113 { 4114 temp = plus_constant (new, offset); 4115 if (!validate_change (object, loc, temp, 0)) 4116 { 4117 if (! extra_insns) 4118 return 0; 4119 4120 start_sequence (); 4121 temp = force_operand (temp, NULL_RTX); 4122 seq = get_insns (); 4123 end_sequence (); 4124 4125 emit_insns_before (seq, object); 4126 if (! validate_change (object, loc, temp, 0) 4127 && ! validate_replace_rtx (x, temp, object)) 4128 abort (); 4129 } 4130 } 4131 4132 return 1; 4133 4134 case ADDRESSOF: 4135 if (GET_CODE (XEXP (x, 0)) == REG) 4136 return 1; 4137 4138 else if (GET_CODE (XEXP (x, 0)) == MEM) 4139 { 4140 /* If we have a (addressof (mem ..)), do any instantiation inside 4141 since we know we'll be making the inside valid when we finally 4142 remove the ADDRESSOF. */ 4143 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0); 4144 return 1; 4145 } 4146 break; 4147 4148 default: 4149 break; 4150 } 4151 4152 /* Scan all subexpressions. */ 4153 fmt = GET_RTX_FORMAT (code); 4154 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) 4155 if (*fmt == 'e') 4156 { 4157 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns)) 4158 return 0; 4159 } 4160 else if (*fmt == 'E') 4161 for (j = 0; j < XVECLEN (x, i); j++) 4162 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object, 4163 extra_insns)) 4164 return 0; 4165 4166 return 1; 4167 } 4168 4169 /* Optimization: assuming this function does not receive nonlocal gotos, 4170 delete the handlers for such, as well as the insns to establish 4171 and disestablish them. */ 4172 4173 static void 4174 delete_handlers () 4175 { 4176 rtx insn; 4177 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 4178 { 4179 /* Delete the handler by turning off the flag that would 4180 prevent jump_optimize from deleting it. 4181 Also permit deletion of the nonlocal labels themselves 4182 if nothing local refers to them. */ 4183 if (GET_CODE (insn) == CODE_LABEL) 4184 { 4185 tree t, last_t; 4186 4187 LABEL_PRESERVE_P (insn) = 0; 4188 4189 /* Remove it from the nonlocal_label list, to avoid confusing 4190 flow. */ 4191 for (t = nonlocal_labels, last_t = 0; t; 4192 last_t = t, t = TREE_CHAIN (t)) 4193 if (DECL_RTL (TREE_VALUE (t)) == insn) 4194 break; 4195 if (t) 4196 { 4197 if (! last_t) 4198 nonlocal_labels = TREE_CHAIN (nonlocal_labels); 4199 else 4200 TREE_CHAIN (last_t) = TREE_CHAIN (t); 4201 } 4202 } 4203 if (GET_CODE (insn) == INSN) 4204 { 4205 int can_delete = 0; 4206 rtx t; 4207 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1)) 4208 if (reg_mentioned_p (t, PATTERN (insn))) 4209 { 4210 can_delete = 1; 4211 break; 4212 } 4213 if (can_delete 4214 || (nonlocal_goto_stack_level != 0 4215 && reg_mentioned_p (nonlocal_goto_stack_level, 4216 PATTERN (insn)))) 4217 delete_related_insns (insn); 4218 } 4219 } 4220 } 4221 4222 int 4223 max_parm_reg_num () 4224 { 4225 return max_parm_reg; 4226 } 4227 4228 /* Return the first insn following those generated by `assign_parms'. */ 4229 4230 rtx 4231 get_first_nonparm_insn () 4232 { 4233 if (last_parm_insn) 4234 return NEXT_INSN (last_parm_insn); 4235 return get_insns (); 4236 } 4237 4238 /* Return the first NOTE_INSN_BLOCK_BEG note in the function. 4239 Crash if there is none. */ 4240 4241 rtx 4242 get_first_block_beg () 4243 { 4244 rtx searcher; 4245 rtx insn = get_first_nonparm_insn (); 4246 4247 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher)) 4248 if (GET_CODE (searcher) == NOTE 4249 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG) 4250 return searcher; 4251 4252 abort (); /* Invalid call to this function. (See comments above.) */ 4253 return NULL_RTX; 4254 } 4255 4256 /* Return 1 if EXP is an aggregate type (or a value with aggregate type). 4257 This means a type for which function calls must pass an address to the 4258 function or get an address back from the function. 4259 EXP may be a type node or an expression (whose type is tested). */ 4260 4261 int 4262 aggregate_value_p (exp) 4263 tree exp; 4264 { 4265 int i, regno, nregs; 4266 rtx reg; 4267 4268 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp); 4269 4270 if (TREE_CODE (type) == VOID_TYPE) 4271 return 0; 4272 if (RETURN_IN_MEMORY (type)) 4273 return 1; 4274 /* Types that are TREE_ADDRESSABLE must be constructed in memory, 4275 and thus can't be returned in registers. */ 4276 if (TREE_ADDRESSABLE (type)) 4277 return 1; 4278 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type)) 4279 return 1; 4280 /* Make sure we have suitable call-clobbered regs to return 4281 the value in; if not, we must return it in memory. */ 4282 reg = hard_function_value (type, 0, 0); 4283 4284 /* If we have something other than a REG (e.g. a PARALLEL), then assume 4285 it is OK. */ 4286 if (GET_CODE (reg) != REG) 4287 return 0; 4288 4289 regno = REGNO (reg); 4290 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type)); 4291 for (i = 0; i < nregs; i++) 4292 if (! call_used_regs[regno + i]) 4293 return 1; 4294 return 0; 4295 } 4296 4297 /* Assign RTL expressions to the function's parameters. 4298 This may involve copying them into registers and using 4299 those registers as the RTL for them. */ 4300 4301 void 4302 assign_parms (fndecl) 4303 tree fndecl; 4304 { 4305 tree parm; 4306 rtx entry_parm = 0; 4307 rtx stack_parm = 0; 4308 CUMULATIVE_ARGS args_so_far; 4309 enum machine_mode promoted_mode, passed_mode; 4310 enum machine_mode nominal_mode, promoted_nominal_mode; 4311 int unsignedp; 4312 /* Total space needed so far for args on the stack, 4313 given as a constant and a tree-expression. */ 4314 struct args_size stack_args_size; 4315 tree fntype = TREE_TYPE (fndecl); 4316 tree fnargs = DECL_ARGUMENTS (fndecl); 4317 /* This is used for the arg pointer when referring to stack args. */ 4318 rtx internal_arg_pointer; 4319 /* This is a dummy PARM_DECL that we used for the function result if 4320 the function returns a structure. */ 4321 tree function_result_decl = 0; 4322 #ifdef SETUP_INCOMING_VARARGS 4323 int varargs_setup = 0; 4324 #endif 4325 rtx conversion_insns = 0; 4326 struct args_size alignment_pad; 4327 4328 /* Nonzero if the last arg is named `__builtin_va_alist', 4329 which is used on some machines for old-fashioned non-ANSI varargs.h; 4330 this should be stuck onto the stack as if it had arrived there. */ 4331 int hide_last_arg 4332 = (current_function_varargs 4333 && fnargs 4334 && (parm = tree_last (fnargs)) != 0 4335 && DECL_NAME (parm) 4336 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), 4337 "__builtin_va_alist"))); 4338 4339 /* Nonzero if function takes extra anonymous args. 4340 This means the last named arg must be on the stack 4341 right before the anonymous ones. */ 4342 int stdarg 4343 = (TYPE_ARG_TYPES (fntype) != 0 4344 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) 4345 != void_type_node)); 4346 4347 current_function_stdarg = stdarg; 4348 4349 /* If the reg that the virtual arg pointer will be translated into is 4350 not a fixed reg or is the stack pointer, make a copy of the virtual 4351 arg pointer, and address parms via the copy. The frame pointer is 4352 considered fixed even though it is not marked as such. 4353 4354 The second time through, simply use ap to avoid generating rtx. */ 4355 4356 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM 4357 || ! (fixed_regs[ARG_POINTER_REGNUM] 4358 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))) 4359 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); 4360 else 4361 internal_arg_pointer = virtual_incoming_args_rtx; 4362 current_function_internal_arg_pointer = internal_arg_pointer; 4363 4364 stack_args_size.constant = 0; 4365 stack_args_size.var = 0; 4366 4367 /* If struct value address is treated as the first argument, make it so. */ 4368 if (aggregate_value_p (DECL_RESULT (fndecl)) 4369 && ! current_function_returns_pcc_struct 4370 && struct_value_incoming_rtx == 0) 4371 { 4372 tree type = build_pointer_type (TREE_TYPE (fntype)); 4373 4374 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type); 4375 4376 DECL_ARG_TYPE (function_result_decl) = type; 4377 TREE_CHAIN (function_result_decl) = fnargs; 4378 fnargs = function_result_decl; 4379 } 4380 4381 max_parm_reg = LAST_VIRTUAL_REGISTER + 1; 4382 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx)); 4383 4384 #ifdef INIT_CUMULATIVE_INCOMING_ARGS 4385 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX); 4386 #else 4387 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0); 4388 #endif 4389 4390 /* We haven't yet found an argument that we must push and pretend the 4391 caller did. */ 4392 current_function_pretend_args_size = 0; 4393 4394 for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) 4395 { 4396 struct args_size stack_offset; 4397 struct args_size arg_size; 4398 int passed_pointer = 0; 4399 int did_conversion = 0; 4400 tree passed_type = DECL_ARG_TYPE (parm); 4401 tree nominal_type = TREE_TYPE (parm); 4402 int pretend_named; 4403 int last_named = 0, named_arg; 4404 4405 /* Set LAST_NAMED if this is last named arg before last 4406 anonymous args. */ 4407 if (stdarg || current_function_varargs) 4408 { 4409 tree tem; 4410 4411 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem)) 4412 if (DECL_NAME (tem)) 4413 break; 4414 4415 if (tem == 0) 4416 last_named = 1; 4417 } 4418 /* Set NAMED_ARG if this arg should be treated as a named arg. For 4419 most machines, if this is a varargs/stdarg function, then we treat 4420 the last named arg as if it were anonymous too. */ 4421 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named; 4422 4423 if (TREE_TYPE (parm) == error_mark_node 4424 /* This can happen after weird syntax errors 4425 or if an enum type is defined among the parms. */ 4426 || TREE_CODE (parm) != PARM_DECL 4427 || passed_type == NULL) 4428 { 4429 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx)); 4430 DECL_INCOMING_RTL (parm) = DECL_RTL (parm); 4431 TREE_USED (parm) = 1; 4432 continue; 4433 } 4434 4435 /* For varargs.h function, save info about regs and stack space 4436 used by the individual args, not including the va_alist arg. */ 4437 if (hide_last_arg && last_named) 4438 current_function_args_info = args_so_far; 4439 4440 /* Find mode of arg as it is passed, and mode of arg 4441 as it should be during execution of this function. */ 4442 passed_mode = TYPE_MODE (passed_type); 4443 nominal_mode = TYPE_MODE (nominal_type); 4444 4445 /* If the parm's mode is VOID, its value doesn't matter, 4446 and avoid the usual things like emit_move_insn that could crash. */ 4447 if (nominal_mode == VOIDmode) 4448 { 4449 SET_DECL_RTL (parm, const0_rtx); 4450 DECL_INCOMING_RTL (parm) = DECL_RTL (parm); 4451 continue; 4452 } 4453 4454 /* If the parm is to be passed as a transparent union, use the 4455 type of the first field for the tests below. We have already 4456 verified that the modes are the same. */ 4457 if (DECL_TRANSPARENT_UNION (parm) 4458 || (TREE_CODE (passed_type) == UNION_TYPE 4459 && TYPE_TRANSPARENT_UNION (passed_type))) 4460 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type)); 4461 4462 /* See if this arg was passed by invisible reference. It is if 4463 it is an object whose size depends on the contents of the 4464 object itself or if the machine requires these objects be passed 4465 that way. */ 4466 4467 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST 4468 && contains_placeholder_p (TYPE_SIZE (passed_type))) 4469 || TREE_ADDRESSABLE (passed_type) 4470 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE 4471 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode, 4472 passed_type, named_arg) 4473 #endif 4474 ) 4475 { 4476 passed_type = nominal_type = build_pointer_type (passed_type); 4477 passed_pointer = 1; 4478 passed_mode = nominal_mode = Pmode; 4479 } 4480 4481 promoted_mode = passed_mode; 4482 4483 #ifdef PROMOTE_FUNCTION_ARGS 4484 /* Compute the mode in which the arg is actually extended to. */ 4485 unsignedp = TREE_UNSIGNED (passed_type); 4486 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1); 4487 #endif 4488 4489 /* Let machine desc say which reg (if any) the parm arrives in. 4490 0 means it arrives on the stack. */ 4491 #ifdef FUNCTION_INCOMING_ARG 4492 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, 4493 passed_type, named_arg); 4494 #else 4495 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode, 4496 passed_type, named_arg); 4497 #endif 4498 4499 if (entry_parm == 0) 4500 promoted_mode = passed_mode; 4501 4502 #ifdef SETUP_INCOMING_VARARGS 4503 /* If this is the last named parameter, do any required setup for 4504 varargs or stdargs. We need to know about the case of this being an 4505 addressable type, in which case we skip the registers it 4506 would have arrived in. 4507 4508 For stdargs, LAST_NAMED will be set for two parameters, the one that 4509 is actually the last named, and the dummy parameter. We only 4510 want to do this action once. 4511 4512 Also, indicate when RTL generation is to be suppressed. */ 4513 if (last_named && !varargs_setup) 4514 { 4515 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type, 4516 current_function_pretend_args_size, 0); 4517 varargs_setup = 1; 4518 } 4519 #endif 4520 4521 /* Determine parm's home in the stack, 4522 in case it arrives in the stack or we should pretend it did. 4523 4524 Compute the stack position and rtx where the argument arrives 4525 and its size. 4526 4527 There is one complexity here: If this was a parameter that would 4528 have been passed in registers, but wasn't only because it is 4529 __builtin_va_alist, we want locate_and_pad_parm to treat it as if 4530 it came in a register so that REG_PARM_STACK_SPACE isn't skipped. 4531 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 4532 0 as it was the previous time. */ 4533 4534 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED; 4535 locate_and_pad_parm (promoted_mode, passed_type, 4536 #ifdef STACK_PARMS_IN_REG_PARM_AREA 4537 1, 4538 #else 4539 #ifdef FUNCTION_INCOMING_ARG 4540 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, 4541 passed_type, 4542 pretend_named) != 0, 4543 #else 4544 FUNCTION_ARG (args_so_far, promoted_mode, 4545 passed_type, 4546 pretend_named) != 0, 4547 #endif 4548 #endif 4549 fndecl, &stack_args_size, &stack_offset, &arg_size, 4550 &alignment_pad); 4551 4552 { 4553 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); 4554 4555 if (offset_rtx == const0_rtx) 4556 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer); 4557 else 4558 stack_parm = gen_rtx_MEM (promoted_mode, 4559 gen_rtx_PLUS (Pmode, 4560 internal_arg_pointer, 4561 offset_rtx)); 4562 4563 set_mem_attributes (stack_parm, parm, 1); 4564 } 4565 4566 /* If this parameter was passed both in registers and in the stack, 4567 use the copy on the stack. */ 4568 if (MUST_PASS_IN_STACK (promoted_mode, passed_type)) 4569 entry_parm = 0; 4570 4571 #ifdef FUNCTION_ARG_PARTIAL_NREGS 4572 /* If this parm was passed part in regs and part in memory, 4573 pretend it arrived entirely in memory 4574 by pushing the register-part onto the stack. 4575 4576 In the special case of a DImode or DFmode that is split, 4577 we could put it together in a pseudoreg directly, 4578 but for now that's not worth bothering with. */ 4579 4580 if (entry_parm) 4581 { 4582 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode, 4583 passed_type, named_arg); 4584 4585 if (nregs > 0) 4586 { 4587 current_function_pretend_args_size 4588 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) 4589 / (PARM_BOUNDARY / BITS_PER_UNIT) 4590 * (PARM_BOUNDARY / BITS_PER_UNIT)); 4591 4592 /* Handle calls that pass values in multiple non-contiguous 4593 locations. The Irix 6 ABI has examples of this. */ 4594 if (GET_CODE (entry_parm) == PARALLEL) 4595 emit_group_store (validize_mem (stack_parm), entry_parm, 4596 int_size_in_bytes (TREE_TYPE (parm))); 4597 4598 else 4599 move_block_from_reg (REGNO (entry_parm), 4600 validize_mem (stack_parm), nregs, 4601 int_size_in_bytes (TREE_TYPE (parm))); 4602 4603 entry_parm = stack_parm; 4604 } 4605 } 4606 #endif 4607 4608 /* If we didn't decide this parm came in a register, 4609 by default it came on the stack. */ 4610 if (entry_parm == 0) 4611 entry_parm = stack_parm; 4612 4613 /* Record permanently how this parm was passed. */ 4614 DECL_INCOMING_RTL (parm) = entry_parm; 4615 4616 /* If there is actually space on the stack for this parm, 4617 count it in stack_args_size; otherwise set stack_parm to 0 4618 to indicate there is no preallocated stack slot for the parm. */ 4619 4620 if (entry_parm == stack_parm 4621 || (GET_CODE (entry_parm) == PARALLEL 4622 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX) 4623 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE) 4624 /* On some machines, even if a parm value arrives in a register 4625 there is still an (uninitialized) stack slot allocated for it. 4626 4627 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell 4628 whether this parameter already has a stack slot allocated, 4629 because an arg block exists only if current_function_args_size 4630 is larger than some threshold, and we haven't calculated that 4631 yet. So, for now, we just assume that stack slots never exist 4632 in this case. */ 4633 || REG_PARM_STACK_SPACE (fndecl) > 0 4634 #endif 4635 ) 4636 { 4637 stack_args_size.constant += arg_size.constant; 4638 if (arg_size.var) 4639 ADD_PARM_SIZE (stack_args_size, arg_size.var); 4640 } 4641 else 4642 /* No stack slot was pushed for this parm. */ 4643 stack_parm = 0; 4644 4645 /* Update info on where next arg arrives in registers. */ 4646 4647 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode, 4648 passed_type, named_arg); 4649 4650 /* If we can't trust the parm stack slot to be aligned enough 4651 for its ultimate type, don't use that slot after entry. 4652 We'll make another stack slot, if we need one. */ 4653 { 4654 unsigned int thisparm_boundary 4655 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type); 4656 4657 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary) 4658 stack_parm = 0; 4659 } 4660 4661 /* If parm was passed in memory, and we need to convert it on entry, 4662 don't store it back in that same slot. */ 4663 if (entry_parm != 0 4664 && nominal_mode != BLKmode && nominal_mode != passed_mode) 4665 stack_parm = 0; 4666 4667 /* When an argument is passed in multiple locations, we can't 4668 make use of this information, but we can save some copying if 4669 the whole argument is passed in a single register. */ 4670 if (GET_CODE (entry_parm) == PARALLEL 4671 && nominal_mode != BLKmode && passed_mode != BLKmode) 4672 { 4673 int i, len = XVECLEN (entry_parm, 0); 4674 4675 for (i = 0; i < len; i++) 4676 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX 4677 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG 4678 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) 4679 == passed_mode) 4680 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0) 4681 { 4682 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0); 4683 DECL_INCOMING_RTL (parm) = entry_parm; 4684 break; 4685 } 4686 } 4687 4688 /* ENTRY_PARM is an RTX for the parameter as it arrives, 4689 in the mode in which it arrives. 4690 STACK_PARM is an RTX for a stack slot where the parameter can live 4691 during the function (in case we want to put it there). 4692 STACK_PARM is 0 if no stack slot was pushed for it. 4693 4694 Now output code if necessary to convert ENTRY_PARM to 4695 the type in which this function declares it, 4696 and store that result in an appropriate place, 4697 which may be a pseudo reg, may be STACK_PARM, 4698 or may be a local stack slot if STACK_PARM is 0. 4699 4700 Set DECL_RTL to that place. */ 4701 4702 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL) 4703 { 4704 /* If a BLKmode arrives in registers, copy it to a stack slot. 4705 Handle calls that pass values in multiple non-contiguous 4706 locations. The Irix 6 ABI has examples of this. */ 4707 if (GET_CODE (entry_parm) == REG 4708 || GET_CODE (entry_parm) == PARALLEL) 4709 { 4710 int size_stored 4711 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)), 4712 UNITS_PER_WORD); 4713 4714 /* Note that we will be storing an integral number of words. 4715 So we have to be careful to ensure that we allocate an 4716 integral number of words. We do this below in the 4717 assign_stack_local if space was not allocated in the argument 4718 list. If it was, this will not work if PARM_BOUNDARY is not 4719 a multiple of BITS_PER_WORD. It isn't clear how to fix this 4720 if it becomes a problem. */ 4721 4722 if (stack_parm == 0) 4723 { 4724 stack_parm 4725 = assign_stack_local (GET_MODE (entry_parm), 4726 size_stored, 0); 4727 set_mem_attributes (stack_parm, parm, 1); 4728 } 4729 4730 else if (PARM_BOUNDARY % BITS_PER_WORD != 0) 4731 abort (); 4732 4733 /* Handle calls that pass values in multiple non-contiguous 4734 locations. The Irix 6 ABI has examples of this. */ 4735 if (GET_CODE (entry_parm) == PARALLEL) 4736 emit_group_store (validize_mem (stack_parm), entry_parm, 4737 int_size_in_bytes (TREE_TYPE (parm))); 4738 else 4739 move_block_from_reg (REGNO (entry_parm), 4740 validize_mem (stack_parm), 4741 size_stored / UNITS_PER_WORD, 4742 int_size_in_bytes (TREE_TYPE (parm))); 4743 } 4744 SET_DECL_RTL (parm, stack_parm); 4745 } 4746 else if (! ((! optimize 4747 && ! DECL_REGISTER (parm)) 4748 || TREE_SIDE_EFFECTS (parm) 4749 /* If -ffloat-store specified, don't put explicit 4750 float variables into registers. */ 4751 || (flag_float_store 4752 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)) 4753 /* Always assign pseudo to structure return or item passed 4754 by invisible reference. */ 4755 || passed_pointer || parm == function_result_decl) 4756 { 4757 /* Store the parm in a pseudoregister during the function, but we 4758 may need to do it in a wider mode. */ 4759 4760 rtx parmreg; 4761 unsigned int regno, regnoi = 0, regnor = 0; 4762 4763 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm)); 4764 4765 promoted_nominal_mode 4766 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0); 4767 4768 parmreg = gen_reg_rtx (promoted_nominal_mode); 4769 mark_user_reg (parmreg); 4770 4771 /* If this was an item that we received a pointer to, set DECL_RTL 4772 appropriately. */ 4773 if (passed_pointer) 4774 { 4775 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), 4776 parmreg); 4777 set_mem_attributes (x, parm, 1); 4778 SET_DECL_RTL (parm, x); 4779 } 4780 else 4781 { 4782 SET_DECL_RTL (parm, parmreg); 4783 maybe_set_unchanging (DECL_RTL (parm), parm); 4784 } 4785 4786 /* Copy the value into the register. */ 4787 if (nominal_mode != passed_mode 4788 || promoted_nominal_mode != promoted_mode) 4789 { 4790 int save_tree_used; 4791 /* ENTRY_PARM has been converted to PROMOTED_MODE, its 4792 mode, by the caller. We now have to convert it to 4793 NOMINAL_MODE, if different. However, PARMREG may be in 4794 a different mode than NOMINAL_MODE if it is being stored 4795 promoted. 4796 4797 If ENTRY_PARM is a hard register, it might be in a register 4798 not valid for operating in its mode (e.g., an odd-numbered 4799 register for a DFmode). In that case, moves are the only 4800 thing valid, so we can't do a convert from there. This 4801 occurs when the calling sequence allow such misaligned 4802 usages. 4803 4804 In addition, the conversion may involve a call, which could 4805 clobber parameters which haven't been copied to pseudo 4806 registers yet. Therefore, we must first copy the parm to 4807 a pseudo reg here, and save the conversion until after all 4808 parameters have been moved. */ 4809 4810 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); 4811 4812 emit_move_insn (tempreg, validize_mem (entry_parm)); 4813 4814 push_to_sequence (conversion_insns); 4815 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp); 4816 4817 if (GET_CODE (tempreg) == SUBREG 4818 && GET_MODE (tempreg) == nominal_mode 4819 && GET_CODE (SUBREG_REG (tempreg)) == REG 4820 && nominal_mode == passed_mode 4821 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm) 4822 && GET_MODE_SIZE (GET_MODE (tempreg)) 4823 < GET_MODE_SIZE (GET_MODE (entry_parm))) 4824 { 4825 /* The argument is already sign/zero extended, so note it 4826 into the subreg. */ 4827 SUBREG_PROMOTED_VAR_P (tempreg) = 1; 4828 SUBREG_PROMOTED_UNSIGNED_P (tempreg) = unsignedp; 4829 } 4830 4831 /* TREE_USED gets set erroneously during expand_assignment. */ 4832 save_tree_used = TREE_USED (parm); 4833 expand_assignment (parm, 4834 make_tree (nominal_type, tempreg), 0, 0); 4835 TREE_USED (parm) = save_tree_used; 4836 conversion_insns = get_insns (); 4837 did_conversion = 1; 4838 end_sequence (); 4839 } 4840 else 4841 emit_move_insn (parmreg, validize_mem (entry_parm)); 4842 4843 /* If we were passed a pointer but the actual value 4844 can safely live in a register, put it in one. */ 4845 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode 4846 /* If by-reference argument was promoted, demote it. */ 4847 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm)) 4848 || ! ((! optimize 4849 && ! DECL_REGISTER (parm)) 4850 || TREE_SIDE_EFFECTS (parm) 4851 /* If -ffloat-store specified, don't put explicit 4852 float variables into registers. */ 4853 || (flag_float_store 4854 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))) 4855 { 4856 /* We can't use nominal_mode, because it will have been set to 4857 Pmode above. We must use the actual mode of the parm. */ 4858 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); 4859 mark_user_reg (parmreg); 4860 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm))) 4861 { 4862 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm))); 4863 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm)); 4864 push_to_sequence (conversion_insns); 4865 emit_move_insn (tempreg, DECL_RTL (parm)); 4866 SET_DECL_RTL (parm, 4867 convert_to_mode (GET_MODE (parmreg), 4868 tempreg, 4869 unsigned_p)); 4870 emit_move_insn (parmreg, DECL_RTL (parm)); 4871 conversion_insns = get_insns(); 4872 did_conversion = 1; 4873 end_sequence (); 4874 } 4875 else 4876 emit_move_insn (parmreg, DECL_RTL (parm)); 4877 SET_DECL_RTL (parm, parmreg); 4878 /* STACK_PARM is the pointer, not the parm, and PARMREG is 4879 now the parm. */ 4880 stack_parm = 0; 4881 } 4882 #ifdef FUNCTION_ARG_CALLEE_COPIES 4883 /* If we are passed an arg by reference and it is our responsibility 4884 to make a copy, do it now. 4885 PASSED_TYPE and PASSED mode now refer to the pointer, not the 4886 original argument, so we must recreate them in the call to 4887 FUNCTION_ARG_CALLEE_COPIES. */ 4888 /* ??? Later add code to handle the case that if the argument isn't 4889 modified, don't do the copy. */ 4890 4891 else if (passed_pointer 4892 && FUNCTION_ARG_CALLEE_COPIES (args_so_far, 4893 TYPE_MODE (DECL_ARG_TYPE (parm)), 4894 DECL_ARG_TYPE (parm), 4895 named_arg) 4896 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) 4897 { 4898 rtx copy; 4899 tree type = DECL_ARG_TYPE (parm); 4900 4901 /* This sequence may involve a library call perhaps clobbering 4902 registers that haven't been copied to pseudos yet. */ 4903 4904 push_to_sequence (conversion_insns); 4905 4906 if (!COMPLETE_TYPE_P (type) 4907 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) 4908 /* This is a variable sized object. */ 4909 copy = gen_rtx_MEM (BLKmode, 4910 allocate_dynamic_stack_space 4911 (expr_size (parm), NULL_RTX, 4912 TYPE_ALIGN (type))); 4913 else 4914 copy = assign_stack_temp (TYPE_MODE (type), 4915 int_size_in_bytes (type), 1); 4916 set_mem_attributes (copy, parm, 1); 4917 4918 store_expr (parm, copy, 0); 4919 emit_move_insn (parmreg, XEXP (copy, 0)); 4920 conversion_insns = get_insns (); 4921 did_conversion = 1; 4922 end_sequence (); 4923 } 4924 #endif /* FUNCTION_ARG_CALLEE_COPIES */ 4925 4926 /* In any case, record the parm's desired stack location 4927 in case we later discover it must live in the stack. 4928 4929 If it is a COMPLEX value, store the stack location for both 4930 halves. */ 4931 4932 if (GET_CODE (parmreg) == CONCAT) 4933 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1))); 4934 else 4935 regno = REGNO (parmreg); 4936 4937 if (regno >= max_parm_reg) 4938 { 4939 rtx *new; 4940 int old_max_parm_reg = max_parm_reg; 4941 4942 /* It's slow to expand this one register at a time, 4943 but it's also rare and we need max_parm_reg to be 4944 precisely correct. */ 4945 max_parm_reg = regno + 1; 4946 new = (rtx *) xrealloc (parm_reg_stack_loc, 4947 max_parm_reg * sizeof (rtx)); 4948 memset ((char *) (new + old_max_parm_reg), 0, 4949 (max_parm_reg - old_max_parm_reg) * sizeof (rtx)); 4950 parm_reg_stack_loc = new; 4951 } 4952 4953 if (GET_CODE (parmreg) == CONCAT) 4954 { 4955 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0)); 4956 4957 regnor = REGNO (gen_realpart (submode, parmreg)); 4958 regnoi = REGNO (gen_imagpart (submode, parmreg)); 4959 4960 if (stack_parm != 0) 4961 { 4962 parm_reg_stack_loc[regnor] 4963 = gen_realpart (submode, stack_parm); 4964 parm_reg_stack_loc[regnoi] 4965 = gen_imagpart (submode, stack_parm); 4966 } 4967 else 4968 { 4969 parm_reg_stack_loc[regnor] = 0; 4970 parm_reg_stack_loc[regnoi] = 0; 4971 } 4972 } 4973 else 4974 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; 4975 4976 /* Mark the register as eliminable if we did no conversion 4977 and it was copied from memory at a fixed offset, 4978 and the arg pointer was not copied to a pseudo-reg. 4979 If the arg pointer is a pseudo reg or the offset formed 4980 an invalid address, such memory-equivalences 4981 as we make here would screw up life analysis for it. */ 4982 if (nominal_mode == passed_mode 4983 && ! did_conversion 4984 && stack_parm != 0 4985 && GET_CODE (stack_parm) == MEM 4986 && stack_offset.var == 0 4987 && reg_mentioned_p (virtual_incoming_args_rtx, 4988 XEXP (stack_parm, 0))) 4989 { 4990 rtx linsn = get_last_insn (); 4991 rtx sinsn, set; 4992 4993 /* Mark complex types separately. */ 4994 if (GET_CODE (parmreg) == CONCAT) 4995 /* Scan backwards for the set of the real and 4996 imaginary parts. */ 4997 for (sinsn = linsn; sinsn != 0; 4998 sinsn = prev_nonnote_insn (sinsn)) 4999 { 5000 set = single_set (sinsn); 5001 if (set != 0 5002 && SET_DEST (set) == regno_reg_rtx [regnoi]) 5003 REG_NOTES (sinsn) 5004 = gen_rtx_EXPR_LIST (REG_EQUIV, 5005 parm_reg_stack_loc[regnoi], 5006 REG_NOTES (sinsn)); 5007 else if (set != 0 5008 && SET_DEST (set) == regno_reg_rtx [regnor]) 5009 REG_NOTES (sinsn) 5010 = gen_rtx_EXPR_LIST (REG_EQUIV, 5011 parm_reg_stack_loc[regnor], 5012 REG_NOTES (sinsn)); 5013 } 5014 else if ((set = single_set (linsn)) != 0 5015 && SET_DEST (set) == parmreg) 5016 REG_NOTES (linsn) 5017 = gen_rtx_EXPR_LIST (REG_EQUIV, 5018 stack_parm, REG_NOTES (linsn)); 5019 } 5020 5021 /* For pointer data type, suggest pointer register. */ 5022 if (POINTER_TYPE_P (TREE_TYPE (parm))) 5023 mark_reg_pointer (parmreg, 5024 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))); 5025 5026 /* If something wants our address, try to use ADDRESSOF. */ 5027 if (TREE_ADDRESSABLE (parm)) 5028 { 5029 /* If we end up putting something into the stack, 5030 fixup_var_refs_insns will need to make a pass over 5031 all the instructions. It looks through the pending 5032 sequences -- but it can't see the ones in the 5033 CONVERSION_INSNS, if they're not on the sequence 5034 stack. So, we go back to that sequence, just so that 5035 the fixups will happen. */ 5036 push_to_sequence (conversion_insns); 5037 put_var_into_stack (parm); 5038 conversion_insns = get_insns (); 5039 end_sequence (); 5040 } 5041 } 5042 else 5043 { 5044 /* Value must be stored in the stack slot STACK_PARM 5045 during function execution. */ 5046 5047 if (promoted_mode != nominal_mode) 5048 { 5049 /* Conversion is required. */ 5050 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); 5051 5052 emit_move_insn (tempreg, validize_mem (entry_parm)); 5053 5054 push_to_sequence (conversion_insns); 5055 entry_parm = convert_to_mode (nominal_mode, tempreg, 5056 TREE_UNSIGNED (TREE_TYPE (parm))); 5057 if (stack_parm) 5058 /* ??? This may need a big-endian conversion on sparc64. */ 5059 stack_parm = adjust_address (stack_parm, nominal_mode, 0); 5060 5061 conversion_insns = get_insns (); 5062 did_conversion = 1; 5063 end_sequence (); 5064 } 5065 5066 if (entry_parm != stack_parm) 5067 { 5068 if (stack_parm == 0) 5069 { 5070 stack_parm 5071 = assign_stack_local (GET_MODE (entry_parm), 5072 GET_MODE_SIZE (GET_MODE (entry_parm)), 0); 5073 set_mem_attributes (stack_parm, parm, 1); 5074 } 5075 5076 if (promoted_mode != nominal_mode) 5077 { 5078 push_to_sequence (conversion_insns); 5079 emit_move_insn (validize_mem (stack_parm), 5080 validize_mem (entry_parm)); 5081 conversion_insns = get_insns (); 5082 end_sequence (); 5083 } 5084 else 5085 emit_move_insn (validize_mem (stack_parm), 5086 validize_mem (entry_parm)); 5087 } 5088 5089 SET_DECL_RTL (parm, stack_parm); 5090 } 5091 5092 /* If this "parameter" was the place where we are receiving the 5093 function's incoming structure pointer, set up the result. */ 5094 if (parm == function_result_decl) 5095 { 5096 tree result = DECL_RESULT (fndecl); 5097 rtx addr = DECL_RTL (parm); 5098 rtx x; 5099 5100 #ifdef POINTERS_EXTEND_UNSIGNED 5101 if (GET_MODE (addr) != Pmode) 5102 addr = convert_memory_address (Pmode, addr); 5103 #endif 5104 5105 x = gen_rtx_MEM (DECL_MODE (result), addr); 5106 set_mem_attributes (x, result, 1); 5107 SET_DECL_RTL (result, x); 5108 } 5109 5110 if (GET_CODE (DECL_RTL (parm)) == REG) 5111 REGNO_DECL (REGNO (DECL_RTL (parm))) = parm; 5112 else if (GET_CODE (DECL_RTL (parm)) == CONCAT) 5113 { 5114 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 0))) = parm; 5115 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 1))) = parm; 5116 } 5117 5118 } 5119 5120 /* Output all parameter conversion instructions (possibly including calls) 5121 now that all parameters have been copied out of hard registers. */ 5122 emit_insns (conversion_insns); 5123 5124 last_parm_insn = get_last_insn (); 5125 5126 current_function_args_size = stack_args_size.constant; 5127 5128 /* Adjust function incoming argument size for alignment and 5129 minimum length. */ 5130 5131 #ifdef REG_PARM_STACK_SPACE 5132 #ifndef MAYBE_REG_PARM_STACK_SPACE 5133 current_function_args_size = MAX (current_function_args_size, 5134 REG_PARM_STACK_SPACE (fndecl)); 5135 #endif 5136 #endif 5137 5138 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) 5139 5140 current_function_args_size 5141 = ((current_function_args_size + STACK_BYTES - 1) 5142 / STACK_BYTES) * STACK_BYTES; 5143 5144 #ifdef ARGS_GROW_DOWNWARD 5145 current_function_arg_offset_rtx 5146 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant) 5147 : expand_expr (size_diffop (stack_args_size.var, 5148 size_int (-stack_args_size.constant)), 5149 NULL_RTX, VOIDmode, 0)); 5150 #else 5151 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size); 5152 #endif 5153 5154 /* See how many bytes, if any, of its args a function should try to pop 5155 on return. */ 5156 5157 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl), 5158 current_function_args_size); 5159 5160 /* For stdarg.h function, save info about 5161 regs and stack space used by the named args. */ 5162 5163 if (!hide_last_arg) 5164 current_function_args_info = args_so_far; 5165 5166 /* Set the rtx used for the function return value. Put this in its 5167 own variable so any optimizers that need this information don't have 5168 to include tree.h. Do this here so it gets done when an inlined 5169 function gets output. */ 5170 5171 current_function_return_rtx 5172 = (DECL_RTL_SET_P (DECL_RESULT (fndecl)) 5173 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX); 5174 5175 /* If scalar return value was computed in a pseudo-reg, or was a named 5176 return value that got dumped to the stack, copy that to the hard 5177 return register. */ 5178 if (DECL_RTL_SET_P (DECL_RESULT (fndecl))) 5179 { 5180 tree decl_result = DECL_RESULT (fndecl); 5181 rtx decl_rtl = DECL_RTL (decl_result); 5182 5183 if (REG_P (decl_rtl) 5184 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER 5185 : DECL_REGISTER (decl_result)) 5186 { 5187 rtx real_decl_rtl; 5188 5189 #ifdef FUNCTION_OUTGOING_VALUE 5190 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result), 5191 fndecl); 5192 #else 5193 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result), 5194 fndecl); 5195 #endif 5196 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1; 5197 /* The delay slot scheduler assumes that current_function_return_rtx 5198 holds the hard register containing the return value, not a 5199 temporary pseudo. */ 5200 current_function_return_rtx = real_decl_rtl; 5201 } 5202 } 5203 } 5204 5205 /* Indicate whether REGNO is an incoming argument to the current function 5206 that was promoted to a wider mode. If so, return the RTX for the 5207 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode 5208 that REGNO is promoted from and whether the promotion was signed or 5209 unsigned. */ 5210 5211 #ifdef PROMOTE_FUNCTION_ARGS 5212 5213 rtx 5214 promoted_input_arg (regno, pmode, punsignedp) 5215 unsigned int regno; 5216 enum machine_mode *pmode; 5217 int *punsignedp; 5218 { 5219 tree arg; 5220 5221 for (arg = DECL_ARGUMENTS (current_function_decl); arg; 5222 arg = TREE_CHAIN (arg)) 5223 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG 5224 && REGNO (DECL_INCOMING_RTL (arg)) == regno 5225 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg))) 5226 { 5227 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg)); 5228 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg)); 5229 5230 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1); 5231 if (mode == GET_MODE (DECL_INCOMING_RTL (arg)) 5232 && mode != DECL_MODE (arg)) 5233 { 5234 *pmode = DECL_MODE (arg); 5235 *punsignedp = unsignedp; 5236 return DECL_INCOMING_RTL (arg); 5237 } 5238 } 5239 5240 return 0; 5241 } 5242 5243 #endif 5244 5245 /* Compute the size and offset from the start of the stacked arguments for a 5246 parm passed in mode PASSED_MODE and with type TYPE. 5247 5248 INITIAL_OFFSET_PTR points to the current offset into the stacked 5249 arguments. 5250 5251 The starting offset and size for this parm are returned in *OFFSET_PTR 5252 and *ARG_SIZE_PTR, respectively. 5253 5254 IN_REGS is non-zero if the argument will be passed in registers. It will 5255 never be set if REG_PARM_STACK_SPACE is not defined. 5256 5257 FNDECL is the function in which the argument was defined. 5258 5259 There are two types of rounding that are done. The first, controlled by 5260 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument 5261 list to be aligned to the specific boundary (in bits). This rounding 5262 affects the initial and starting offsets, but not the argument size. 5263 5264 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, 5265 optionally rounds the size of the parm to PARM_BOUNDARY. The 5266 initial offset is not affected by this rounding, while the size always 5267 is and the starting offset may be. */ 5268 5269 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case; 5270 initial_offset_ptr is positive because locate_and_pad_parm's 5271 callers pass in the total size of args so far as 5272 initial_offset_ptr. arg_size_ptr is always positive. */ 5273 5274 void 5275 locate_and_pad_parm (passed_mode, type, in_regs, fndecl, 5276 initial_offset_ptr, offset_ptr, arg_size_ptr, 5277 alignment_pad) 5278 enum machine_mode passed_mode; 5279 tree type; 5280 int in_regs ATTRIBUTE_UNUSED; 5281 tree fndecl ATTRIBUTE_UNUSED; 5282 struct args_size *initial_offset_ptr; 5283 struct args_size *offset_ptr; 5284 struct args_size *arg_size_ptr; 5285 struct args_size *alignment_pad; 5286 5287 { 5288 tree sizetree 5289 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); 5290 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type); 5291 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); 5292 5293 #ifdef REG_PARM_STACK_SPACE 5294 /* If we have found a stack parm before we reach the end of the 5295 area reserved for registers, skip that area. */ 5296 if (! in_regs) 5297 { 5298 int reg_parm_stack_space = 0; 5299 5300 #ifdef MAYBE_REG_PARM_STACK_SPACE 5301 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; 5302 #else 5303 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); 5304 #endif 5305 if (reg_parm_stack_space > 0) 5306 { 5307 if (initial_offset_ptr->var) 5308 { 5309 initial_offset_ptr->var 5310 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), 5311 ssize_int (reg_parm_stack_space)); 5312 initial_offset_ptr->constant = 0; 5313 } 5314 else if (initial_offset_ptr->constant < reg_parm_stack_space) 5315 initial_offset_ptr->constant = reg_parm_stack_space; 5316 } 5317 } 5318 #endif /* REG_PARM_STACK_SPACE */ 5319 5320 arg_size_ptr->var = 0; 5321 arg_size_ptr->constant = 0; 5322 alignment_pad->var = 0; 5323 alignment_pad->constant = 0; 5324 5325 #ifdef ARGS_GROW_DOWNWARD 5326 if (initial_offset_ptr->var) 5327 { 5328 offset_ptr->constant = 0; 5329 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0), 5330 initial_offset_ptr->var); 5331 } 5332 else 5333 { 5334 offset_ptr->constant = -initial_offset_ptr->constant; 5335 offset_ptr->var = 0; 5336 } 5337 if (where_pad != none 5338 && (!host_integerp (sizetree, 1) 5339 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY)) 5340 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5341 SUB_PARM_SIZE (*offset_ptr, sizetree); 5342 if (where_pad != downward) 5343 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad); 5344 if (initial_offset_ptr->var) 5345 arg_size_ptr->var = size_binop (MINUS_EXPR, 5346 size_binop (MINUS_EXPR, 5347 ssize_int (0), 5348 initial_offset_ptr->var), 5349 offset_ptr->var); 5350 5351 else 5352 arg_size_ptr->constant = (-initial_offset_ptr->constant 5353 - offset_ptr->constant); 5354 5355 #else /* !ARGS_GROW_DOWNWARD */ 5356 if (!in_regs 5357 #ifdef REG_PARM_STACK_SPACE 5358 || REG_PARM_STACK_SPACE (fndecl) > 0 5359 #endif 5360 ) 5361 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad); 5362 *offset_ptr = *initial_offset_ptr; 5363 5364 #ifdef PUSH_ROUNDING 5365 if (passed_mode != BLKmode) 5366 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree))); 5367 #endif 5368 5369 /* Pad_below needs the pre-rounded size to know how much to pad below 5370 so this must be done before rounding up. */ 5371 if (where_pad == downward 5372 /* However, BLKmode args passed in regs have their padding done elsewhere. 5373 The stack slot must be able to hold the entire register. */ 5374 && !(in_regs && passed_mode == BLKmode)) 5375 pad_below (offset_ptr, passed_mode, sizetree); 5376 5377 if (where_pad != none 5378 && (!host_integerp (sizetree, 1) 5379 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY)) 5380 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5381 5382 ADD_PARM_SIZE (*arg_size_ptr, sizetree); 5383 #endif /* ARGS_GROW_DOWNWARD */ 5384 } 5385 5386 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. 5387 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */ 5388 5389 static void 5390 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad) 5391 struct args_size *offset_ptr; 5392 int boundary; 5393 struct args_size *alignment_pad; 5394 { 5395 tree save_var = NULL_TREE; 5396 HOST_WIDE_INT save_constant = 0; 5397 5398 int boundary_in_bytes = boundary / BITS_PER_UNIT; 5399 5400 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5401 { 5402 save_var = offset_ptr->var; 5403 save_constant = offset_ptr->constant; 5404 } 5405 5406 alignment_pad->var = NULL_TREE; 5407 alignment_pad->constant = 0; 5408 5409 if (boundary > BITS_PER_UNIT) 5410 { 5411 if (offset_ptr->var) 5412 { 5413 offset_ptr->var = 5414 #ifdef ARGS_GROW_DOWNWARD 5415 round_down 5416 #else 5417 round_up 5418 #endif 5419 (ARGS_SIZE_TREE (*offset_ptr), 5420 boundary / BITS_PER_UNIT); 5421 offset_ptr->constant = 0; /*?*/ 5422 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5423 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var, 5424 save_var); 5425 } 5426 else 5427 { 5428 offset_ptr->constant = 5429 #ifdef ARGS_GROW_DOWNWARD 5430 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes); 5431 #else 5432 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes); 5433 #endif 5434 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5435 alignment_pad->constant = offset_ptr->constant - save_constant; 5436 } 5437 } 5438 } 5439 5440 #ifndef ARGS_GROW_DOWNWARD 5441 static void 5442 pad_below (offset_ptr, passed_mode, sizetree) 5443 struct args_size *offset_ptr; 5444 enum machine_mode passed_mode; 5445 tree sizetree; 5446 { 5447 if (passed_mode != BLKmode) 5448 { 5449 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) 5450 offset_ptr->constant 5451 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) 5452 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) 5453 - GET_MODE_SIZE (passed_mode)); 5454 } 5455 else 5456 { 5457 if (TREE_CODE (sizetree) != INTEGER_CST 5458 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY) 5459 { 5460 /* Round the size up to multiple of PARM_BOUNDARY bits. */ 5461 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5462 /* Add it in. */ 5463 ADD_PARM_SIZE (*offset_ptr, s2); 5464 SUB_PARM_SIZE (*offset_ptr, sizetree); 5465 } 5466 } 5467 } 5468 #endif 5469 5470 /* Walk the tree of blocks describing the binding levels within a function 5471 and warn about uninitialized variables. 5472 This is done after calling flow_analysis and before global_alloc 5473 clobbers the pseudo-regs to hard regs. */ 5474 5475 void 5476 uninitialized_vars_warning (block) 5477 tree block; 5478 { 5479 tree decl, sub; 5480 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) 5481 { 5482 if (warn_uninitialized 5483 && TREE_CODE (decl) == VAR_DECL 5484 /* These warnings are unreliable for and aggregates 5485 because assigning the fields one by one can fail to convince 5486 flow.c that the entire aggregate was initialized. 5487 Unions are troublesome because members may be shorter. */ 5488 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl)) 5489 && DECL_RTL (decl) != 0 5490 && GET_CODE (DECL_RTL (decl)) == REG 5491 /* Global optimizations can make it difficult to determine if a 5492 particular variable has been initialized. However, a VAR_DECL 5493 with a nonzero DECL_INITIAL had an initializer, so do not 5494 claim it is potentially uninitialized. 5495 5496 We do not care about the actual value in DECL_INITIAL, so we do 5497 not worry that it may be a dangling pointer. */ 5498 && DECL_INITIAL (decl) == NULL_TREE 5499 && regno_uninitialized (REGNO (DECL_RTL (decl)))) 5500 warning_with_decl (decl, 5501 "`%s' might be used uninitialized in this function"); 5502 if (extra_warnings 5503 && TREE_CODE (decl) == VAR_DECL 5504 && DECL_RTL (decl) != 0 5505 && GET_CODE (DECL_RTL (decl)) == REG 5506 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) 5507 warning_with_decl (decl, 5508 "variable `%s' might be clobbered by `longjmp' or `vfork'"); 5509 } 5510 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) 5511 uninitialized_vars_warning (sub); 5512 } 5513 5514 /* Do the appropriate part of uninitialized_vars_warning 5515 but for arguments instead of local variables. */ 5516 5517 void 5518 setjmp_args_warning () 5519 { 5520 tree decl; 5521 for (decl = DECL_ARGUMENTS (current_function_decl); 5522 decl; decl = TREE_CHAIN (decl)) 5523 if (DECL_RTL (decl) != 0 5524 && GET_CODE (DECL_RTL (decl)) == REG 5525 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) 5526 warning_with_decl (decl, 5527 "argument `%s' might be clobbered by `longjmp' or `vfork'"); 5528 } 5529 5530 /* If this function call setjmp, put all vars into the stack 5531 unless they were declared `register'. */ 5532 5533 void 5534 setjmp_protect (block) 5535 tree block; 5536 { 5537 tree decl, sub; 5538 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) 5539 if ((TREE_CODE (decl) == VAR_DECL 5540 || TREE_CODE (decl) == PARM_DECL) 5541 && DECL_RTL (decl) != 0 5542 && (GET_CODE (DECL_RTL (decl)) == REG 5543 || (GET_CODE (DECL_RTL (decl)) == MEM 5544 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) 5545 /* If this variable came from an inline function, it must be 5546 that its life doesn't overlap the setjmp. If there was a 5547 setjmp in the function, it would already be in memory. We 5548 must exclude such variable because their DECL_RTL might be 5549 set to strange things such as virtual_stack_vars_rtx. */ 5550 && ! DECL_FROM_INLINE (decl) 5551 && ( 5552 #ifdef NON_SAVING_SETJMP 5553 /* If longjmp doesn't restore the registers, 5554 don't put anything in them. */ 5555 NON_SAVING_SETJMP 5556 || 5557 #endif 5558 ! DECL_REGISTER (decl))) 5559 put_var_into_stack (decl); 5560 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) 5561 setjmp_protect (sub); 5562 } 5563 5564 /* Like the previous function, but for args instead of local variables. */ 5565 5566 void 5567 setjmp_protect_args () 5568 { 5569 tree decl; 5570 for (decl = DECL_ARGUMENTS (current_function_decl); 5571 decl; decl = TREE_CHAIN (decl)) 5572 if ((TREE_CODE (decl) == VAR_DECL 5573 || TREE_CODE (decl) == PARM_DECL) 5574 && DECL_RTL (decl) != 0 5575 && (GET_CODE (DECL_RTL (decl)) == REG 5576 || (GET_CODE (DECL_RTL (decl)) == MEM 5577 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) 5578 && ( 5579 /* If longjmp doesn't restore the registers, 5580 don't put anything in them. */ 5581 #ifdef NON_SAVING_SETJMP 5582 NON_SAVING_SETJMP 5583 || 5584 #endif 5585 ! DECL_REGISTER (decl))) 5586 put_var_into_stack (decl); 5587 } 5588 5589 /* Return the context-pointer register corresponding to DECL, 5590 or 0 if it does not need one. */ 5591 5592 rtx 5593 lookup_static_chain (decl) 5594 tree decl; 5595 { 5596 tree context = decl_function_context (decl); 5597 tree link; 5598 5599 if (context == 0 5600 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl))) 5601 return 0; 5602 5603 /* We treat inline_function_decl as an alias for the current function 5604 because that is the inline function whose vars, types, etc. 5605 are being merged into the current function. 5606 See expand_inline_function. */ 5607 if (context == current_function_decl || context == inline_function_decl) 5608 return virtual_stack_vars_rtx; 5609 5610 for (link = context_display; link; link = TREE_CHAIN (link)) 5611 if (TREE_PURPOSE (link) == context) 5612 return RTL_EXPR_RTL (TREE_VALUE (link)); 5613 5614 abort (); 5615 } 5616 5617 /* Convert a stack slot address ADDR for variable VAR 5618 (from a containing function) 5619 into an address valid in this function (using a static chain). */ 5620 5621 rtx 5622 fix_lexical_addr (addr, var) 5623 rtx addr; 5624 tree var; 5625 { 5626 rtx basereg; 5627 HOST_WIDE_INT displacement; 5628 tree context = decl_function_context (var); 5629 struct function *fp; 5630 rtx base = 0; 5631 5632 /* If this is the present function, we need not do anything. */ 5633 if (context == current_function_decl || context == inline_function_decl) 5634 return addr; 5635 5636 fp = find_function_data (context); 5637 5638 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM) 5639 addr = XEXP (XEXP (addr, 0), 0); 5640 5641 /* Decode given address as base reg plus displacement. */ 5642 if (GET_CODE (addr) == REG) 5643 basereg = addr, displacement = 0; 5644 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) 5645 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1)); 5646 else 5647 abort (); 5648 5649 /* We accept vars reached via the containing function's 5650 incoming arg pointer and via its stack variables pointer. */ 5651 if (basereg == fp->internal_arg_pointer) 5652 { 5653 /* If reached via arg pointer, get the arg pointer value 5654 out of that function's stack frame. 5655 5656 There are two cases: If a separate ap is needed, allocate a 5657 slot in the outer function for it and dereference it that way. 5658 This is correct even if the real ap is actually a pseudo. 5659 Otherwise, just adjust the offset from the frame pointer to 5660 compensate. */ 5661 5662 #ifdef NEED_SEPARATE_AP 5663 rtx addr; 5664 5665 addr = get_arg_pointer_save_area (fp); 5666 addr = fix_lexical_addr (XEXP (addr, 0), var); 5667 addr = memory_address (Pmode, addr); 5668 5669 base = gen_rtx_MEM (Pmode, addr); 5670 set_mem_alias_set (base, get_frame_alias_set ()); 5671 base = copy_to_reg (base); 5672 #else 5673 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET); 5674 base = lookup_static_chain (var); 5675 #endif 5676 } 5677 5678 else if (basereg == virtual_stack_vars_rtx) 5679 { 5680 /* This is the same code as lookup_static_chain, duplicated here to 5681 avoid an extra call to decl_function_context. */ 5682 tree link; 5683 5684 for (link = context_display; link; link = TREE_CHAIN (link)) 5685 if (TREE_PURPOSE (link) == context) 5686 { 5687 base = RTL_EXPR_RTL (TREE_VALUE (link)); 5688 break; 5689 } 5690 } 5691 5692 if (base == 0) 5693 abort (); 5694 5695 /* Use same offset, relative to appropriate static chain or argument 5696 pointer. */ 5697 return plus_constant (base, displacement); 5698 } 5699 5700 /* Return the address of the trampoline for entering nested fn FUNCTION. 5701 If necessary, allocate a trampoline (in the stack frame) 5702 and emit rtl to initialize its contents (at entry to this function). */ 5703 5704 rtx 5705 trampoline_address (function) 5706 tree function; 5707 { 5708 tree link; 5709 tree rtlexp; 5710 rtx tramp; 5711 struct function *fp; 5712 tree fn_context; 5713 5714 /* Find an existing trampoline and return it. */ 5715 for (link = trampoline_list; link; link = TREE_CHAIN (link)) 5716 if (TREE_PURPOSE (link) == function) 5717 return 5718 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0)); 5719 5720 for (fp = outer_function_chain; fp; fp = fp->outer) 5721 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link)) 5722 if (TREE_PURPOSE (link) == function) 5723 { 5724 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0), 5725 function); 5726 return adjust_trampoline_addr (tramp); 5727 } 5728 5729 /* None exists; we must make one. */ 5730 5731 /* Find the `struct function' for the function containing FUNCTION. */ 5732 fp = 0; 5733 fn_context = decl_function_context (function); 5734 if (fn_context != current_function_decl 5735 && fn_context != inline_function_decl) 5736 fp = find_function_data (fn_context); 5737 5738 /* Allocate run-time space for this trampoline 5739 (usually in the defining function's stack frame). */ 5740 #ifdef ALLOCATE_TRAMPOLINE 5741 tramp = ALLOCATE_TRAMPOLINE (fp); 5742 #else 5743 /* If rounding needed, allocate extra space 5744 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */ 5745 #ifdef TRAMPOLINE_ALIGNMENT 5746 #define TRAMPOLINE_REAL_SIZE \ 5747 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1) 5748 #else 5749 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE) 5750 #endif 5751 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0, 5752 fp ? fp : cfun); 5753 #endif 5754 5755 /* Record the trampoline for reuse and note it for later initialization 5756 by expand_function_end. */ 5757 if (fp != 0) 5758 { 5759 rtlexp = make_node (RTL_EXPR); 5760 RTL_EXPR_RTL (rtlexp) = tramp; 5761 fp->x_trampoline_list = tree_cons (function, rtlexp, 5762 fp->x_trampoline_list); 5763 } 5764 else 5765 { 5766 /* Make the RTL_EXPR node temporary, not momentary, so that the 5767 trampoline_list doesn't become garbage. */ 5768 rtlexp = make_node (RTL_EXPR); 5769 5770 RTL_EXPR_RTL (rtlexp) = tramp; 5771 trampoline_list = tree_cons (function, rtlexp, trampoline_list); 5772 } 5773 5774 tramp = fix_lexical_addr (XEXP (tramp, 0), function); 5775 return adjust_trampoline_addr (tramp); 5776 } 5777 5778 /* Given a trampoline address, 5779 round it to multiple of TRAMPOLINE_ALIGNMENT. */ 5780 5781 static rtx 5782 round_trampoline_addr (tramp) 5783 rtx tramp; 5784 { 5785 #ifdef TRAMPOLINE_ALIGNMENT 5786 /* Round address up to desired boundary. */ 5787 rtx temp = gen_reg_rtx (Pmode); 5788 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1); 5789 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); 5790 5791 temp = expand_simple_binop (Pmode, PLUS, tramp, addend, 5792 temp, 0, OPTAB_LIB_WIDEN); 5793 tramp = expand_simple_binop (Pmode, AND, temp, mask, 5794 temp, 0, OPTAB_LIB_WIDEN); 5795 #endif 5796 return tramp; 5797 } 5798 5799 /* Given a trampoline address, round it then apply any 5800 platform-specific adjustments so that the result can be used for a 5801 function call . */ 5802 5803 static rtx 5804 adjust_trampoline_addr (tramp) 5805 rtx tramp; 5806 { 5807 tramp = round_trampoline_addr (tramp); 5808 #ifdef TRAMPOLINE_ADJUST_ADDRESS 5809 TRAMPOLINE_ADJUST_ADDRESS (tramp); 5810 #endif 5811 return tramp; 5812 } 5813 5814 /* Put all this function's BLOCK nodes including those that are chained 5815 onto the first block into a vector, and return it. 5816 Also store in each NOTE for the beginning or end of a block 5817 the index of that block in the vector. 5818 The arguments are BLOCK, the chain of top-level blocks of the function, 5819 and INSNS, the insn chain of the function. */ 5820 5821 void 5822 identify_blocks () 5823 { 5824 int n_blocks; 5825 tree *block_vector, *last_block_vector; 5826 tree *block_stack; 5827 tree block = DECL_INITIAL (current_function_decl); 5828 5829 if (block == 0) 5830 return; 5831 5832 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in 5833 depth-first order. */ 5834 block_vector = get_block_vector (block, &n_blocks); 5835 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree)); 5836 5837 last_block_vector = identify_blocks_1 (get_insns (), 5838 block_vector + 1, 5839 block_vector + n_blocks, 5840 block_stack); 5841 5842 /* If we didn't use all of the subblocks, we've misplaced block notes. */ 5843 /* ??? This appears to happen all the time. Latent bugs elsewhere? */ 5844 if (0 && last_block_vector != block_vector + n_blocks) 5845 abort (); 5846 5847 free (block_vector); 5848 free (block_stack); 5849 } 5850 5851 /* Subroutine of identify_blocks. Do the block substitution on the 5852 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains. 5853 5854 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair. 5855 BLOCK_VECTOR is incremented for each block seen. */ 5856 5857 static tree * 5858 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack) 5859 rtx insns; 5860 tree *block_vector; 5861 tree *end_block_vector; 5862 tree *orig_block_stack; 5863 { 5864 rtx insn; 5865 tree *block_stack = orig_block_stack; 5866 5867 for (insn = insns; insn; insn = NEXT_INSN (insn)) 5868 { 5869 if (GET_CODE (insn) == NOTE) 5870 { 5871 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) 5872 { 5873 tree b; 5874 5875 /* If there are more block notes than BLOCKs, something 5876 is badly wrong. */ 5877 if (block_vector == end_block_vector) 5878 abort (); 5879 5880 b = *block_vector++; 5881 NOTE_BLOCK (insn) = b; 5882 *block_stack++ = b; 5883 } 5884 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) 5885 { 5886 /* If there are more NOTE_INSN_BLOCK_ENDs than 5887 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */ 5888 if (block_stack == orig_block_stack) 5889 abort (); 5890 5891 NOTE_BLOCK (insn) = *--block_stack; 5892 } 5893 } 5894 else if (GET_CODE (insn) == CALL_INSN 5895 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER) 5896 { 5897 rtx cp = PATTERN (insn); 5898 5899 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector, 5900 end_block_vector, block_stack); 5901 if (XEXP (cp, 1)) 5902 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector, 5903 end_block_vector, block_stack); 5904 if (XEXP (cp, 2)) 5905 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector, 5906 end_block_vector, block_stack); 5907 } 5908 } 5909 5910 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs, 5911 something is badly wrong. */ 5912 if (block_stack != orig_block_stack) 5913 abort (); 5914 5915 return block_vector; 5916 } 5917 5918 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END}, 5919 and create duplicate blocks. */ 5920 /* ??? Need an option to either create block fragments or to create 5921 abstract origin duplicates of a source block. It really depends 5922 on what optimization has been performed. */ 5923 5924 void 5925 reorder_blocks () 5926 { 5927 tree block = DECL_INITIAL (current_function_decl); 5928 varray_type block_stack; 5929 5930 if (block == NULL_TREE) 5931 return; 5932 5933 VARRAY_TREE_INIT (block_stack, 10, "block_stack"); 5934 5935 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */ 5936 reorder_blocks_0 (block); 5937 5938 /* Prune the old trees away, so that they don't get in the way. */ 5939 BLOCK_SUBBLOCKS (block) = NULL_TREE; 5940 BLOCK_CHAIN (block) = NULL_TREE; 5941 5942 /* Recreate the block tree from the note nesting. */ 5943 reorder_blocks_1 (get_insns (), block, &block_stack); 5944 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block)); 5945 5946 /* Remove deleted blocks from the block fragment chains. */ 5947 reorder_fix_fragments (block); 5948 5949 VARRAY_FREE (block_stack); 5950 } 5951 5952 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */ 5953 5954 static void 5955 reorder_blocks_0 (block) 5956 tree block; 5957 { 5958 while (block) 5959 { 5960 TREE_ASM_WRITTEN (block) = 0; 5961 reorder_blocks_0 (BLOCK_SUBBLOCKS (block)); 5962 block = BLOCK_CHAIN (block); 5963 } 5964 } 5965 5966 static void 5967 reorder_blocks_1 (insns, current_block, p_block_stack) 5968 rtx insns; 5969 tree current_block; 5970 varray_type *p_block_stack; 5971 { 5972 rtx insn; 5973 5974 for (insn = insns; insn; insn = NEXT_INSN (insn)) 5975 { 5976 if (GET_CODE (insn) == NOTE) 5977 { 5978 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) 5979 { 5980 tree block = NOTE_BLOCK (insn); 5981 5982 /* If we have seen this block before, that means it now 5983 spans multiple address regions. Create a new fragment. */ 5984 if (TREE_ASM_WRITTEN (block)) 5985 { 5986 tree new_block = copy_node (block); 5987 tree origin; 5988 5989 origin = (BLOCK_FRAGMENT_ORIGIN (block) 5990 ? BLOCK_FRAGMENT_ORIGIN (block) 5991 : block); 5992 BLOCK_FRAGMENT_ORIGIN (new_block) = origin; 5993 BLOCK_FRAGMENT_CHAIN (new_block) 5994 = BLOCK_FRAGMENT_CHAIN (origin); 5995 BLOCK_FRAGMENT_CHAIN (origin) = new_block; 5996 5997 NOTE_BLOCK (insn) = new_block; 5998 block = new_block; 5999 } 6000 6001 BLOCK_SUBBLOCKS (block) = 0; 6002 TREE_ASM_WRITTEN (block) = 1; 6003 BLOCK_SUPERCONTEXT (block) = current_block; 6004 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block); 6005 BLOCK_SUBBLOCKS (current_block) = block; 6006 current_block = block; 6007 VARRAY_PUSH_TREE (*p_block_stack, block); 6008 } 6009 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) 6010 { 6011 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack); 6012 VARRAY_POP (*p_block_stack); 6013 BLOCK_SUBBLOCKS (current_block) 6014 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); 6015 current_block = BLOCK_SUPERCONTEXT (current_block); 6016 } 6017 } 6018 else if (GET_CODE (insn) == CALL_INSN 6019 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER) 6020 { 6021 rtx cp = PATTERN (insn); 6022 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack); 6023 if (XEXP (cp, 1)) 6024 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack); 6025 if (XEXP (cp, 2)) 6026 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack); 6027 } 6028 } 6029 } 6030 6031 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer 6032 appears in the block tree, select one of the fragments to become 6033 the new origin block. */ 6034 6035 static void 6036 reorder_fix_fragments (block) 6037 tree block; 6038 { 6039 while (block) 6040 { 6041 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block); 6042 tree new_origin = NULL_TREE; 6043 6044 if (dup_origin) 6045 { 6046 if (! TREE_ASM_WRITTEN (dup_origin)) 6047 { 6048 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin); 6049 6050 /* Find the first of the remaining fragments. There must 6051 be at least one -- the current block. */ 6052 while (! TREE_ASM_WRITTEN (new_origin)) 6053 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin); 6054 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE; 6055 } 6056 } 6057 else if (! dup_origin) 6058 new_origin = block; 6059 6060 /* Re-root the rest of the fragments to the new origin. In the 6061 case that DUP_ORIGIN was null, that means BLOCK was the origin 6062 of a chain of fragments and we want to remove those fragments 6063 that didn't make it to the output. */ 6064 if (new_origin) 6065 { 6066 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin); 6067 tree chain = *pp; 6068 6069 while (chain) 6070 { 6071 if (TREE_ASM_WRITTEN (chain)) 6072 { 6073 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin; 6074 *pp = chain; 6075 pp = &BLOCK_FRAGMENT_CHAIN (chain); 6076 } 6077 chain = BLOCK_FRAGMENT_CHAIN (chain); 6078 } 6079 *pp = NULL_TREE; 6080 } 6081 6082 reorder_fix_fragments (BLOCK_SUBBLOCKS (block)); 6083 block = BLOCK_CHAIN (block); 6084 } 6085 } 6086 6087 /* Reverse the order of elements in the chain T of blocks, 6088 and return the new head of the chain (old last element). */ 6089 6090 static tree 6091 blocks_nreverse (t) 6092 tree t; 6093 { 6094 tree prev = 0, decl, next; 6095 for (decl = t; decl; decl = next) 6096 { 6097 next = BLOCK_CHAIN (decl); 6098 BLOCK_CHAIN (decl) = prev; 6099 prev = decl; 6100 } 6101 return prev; 6102 } 6103 6104 /* Count the subblocks of the list starting with BLOCK. If VECTOR is 6105 non-NULL, list them all into VECTOR, in a depth-first preorder 6106 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all 6107 blocks. */ 6108 6109 static int 6110 all_blocks (block, vector) 6111 tree block; 6112 tree *vector; 6113 { 6114 int n_blocks = 0; 6115 6116 while (block) 6117 { 6118 TREE_ASM_WRITTEN (block) = 0; 6119 6120 /* Record this block. */ 6121 if (vector) 6122 vector[n_blocks] = block; 6123 6124 ++n_blocks; 6125 6126 /* Record the subblocks, and their subblocks... */ 6127 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block), 6128 vector ? vector + n_blocks : 0); 6129 block = BLOCK_CHAIN (block); 6130 } 6131 6132 return n_blocks; 6133 } 6134 6135 /* Return a vector containing all the blocks rooted at BLOCK. The 6136 number of elements in the vector is stored in N_BLOCKS_P. The 6137 vector is dynamically allocated; it is the caller's responsibility 6138 to call `free' on the pointer returned. */ 6139 6140 static tree * 6141 get_block_vector (block, n_blocks_p) 6142 tree block; 6143 int *n_blocks_p; 6144 { 6145 tree *block_vector; 6146 6147 *n_blocks_p = all_blocks (block, NULL); 6148 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree)); 6149 all_blocks (block, block_vector); 6150 6151 return block_vector; 6152 } 6153 6154 static int next_block_index = 2; 6155 6156 /* Set BLOCK_NUMBER for all the blocks in FN. */ 6157 6158 void 6159 number_blocks (fn) 6160 tree fn; 6161 { 6162 int i; 6163 int n_blocks; 6164 tree *block_vector; 6165 6166 /* For SDB and XCOFF debugging output, we start numbering the blocks 6167 from 1 within each function, rather than keeping a running 6168 count. */ 6169 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) 6170 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG) 6171 next_block_index = 1; 6172 #endif 6173 6174 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks); 6175 6176 /* The top-level BLOCK isn't numbered at all. */ 6177 for (i = 1; i < n_blocks; ++i) 6178 /* We number the blocks from two. */ 6179 BLOCK_NUMBER (block_vector[i]) = next_block_index++; 6180 6181 free (block_vector); 6182 6183 return; 6184 } 6185 6186 /* If VAR is present in a subblock of BLOCK, return the subblock. */ 6187 6188 tree 6189 debug_find_var_in_block_tree (var, block) 6190 tree var; 6191 tree block; 6192 { 6193 tree t; 6194 6195 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t)) 6196 if (t == var) 6197 return block; 6198 6199 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t)) 6200 { 6201 tree ret = debug_find_var_in_block_tree (var, t); 6202 if (ret) 6203 return ret; 6204 } 6205 6206 return NULL_TREE; 6207 } 6208 6209 /* Allocate a function structure and reset its contents to the defaults. */ 6210 6211 static void 6212 prepare_function_start () 6213 { 6214 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function)); 6215 6216 init_stmt_for_function (); 6217 init_eh_for_function (); 6218 6219 cse_not_expected = ! optimize; 6220 6221 /* Caller save not needed yet. */ 6222 caller_save_needed = 0; 6223 6224 /* No stack slots have been made yet. */ 6225 stack_slot_list = 0; 6226 6227 current_function_has_nonlocal_label = 0; 6228 current_function_has_nonlocal_goto = 0; 6229 6230 /* There is no stack slot for handling nonlocal gotos. */ 6231 nonlocal_goto_handler_slots = 0; 6232 nonlocal_goto_stack_level = 0; 6233 6234 /* No labels have been declared for nonlocal use. */ 6235 nonlocal_labels = 0; 6236 nonlocal_goto_handler_labels = 0; 6237 6238 /* No function calls so far in this function. */ 6239 function_call_count = 0; 6240 6241 /* No parm regs have been allocated. 6242 (This is important for output_inline_function.) */ 6243 max_parm_reg = LAST_VIRTUAL_REGISTER + 1; 6244 6245 /* Initialize the RTL mechanism. */ 6246 init_emit (); 6247 6248 /* Initialize the queue of pending postincrement and postdecrements, 6249 and some other info in expr.c. */ 6250 init_expr (); 6251 6252 /* We haven't done register allocation yet. */ 6253 reg_renumber = 0; 6254 6255 init_varasm_status (cfun); 6256 6257 /* Clear out data used for inlining. */ 6258 cfun->inlinable = 0; 6259 cfun->original_decl_initial = 0; 6260 cfun->original_arg_vector = 0; 6261 6262 cfun->stack_alignment_needed = STACK_BOUNDARY; 6263 cfun->preferred_stack_boundary = STACK_BOUNDARY; 6264 6265 /* Set if a call to setjmp is seen. */ 6266 current_function_calls_setjmp = 0; 6267 6268 /* Set if a call to longjmp is seen. */ 6269 current_function_calls_longjmp = 0; 6270 6271 current_function_calls_alloca = 0; 6272 current_function_contains_functions = 0; 6273 current_function_is_leaf = 0; 6274 current_function_nothrow = 0; 6275 current_function_sp_is_unchanging = 0; 6276 current_function_uses_only_leaf_regs = 0; 6277 current_function_has_computed_jump = 0; 6278 current_function_is_thunk = 0; 6279 6280 current_function_returns_pcc_struct = 0; 6281 current_function_returns_struct = 0; 6282 current_function_epilogue_delay_list = 0; 6283 current_function_uses_const_pool = 0; 6284 current_function_uses_pic_offset_table = 0; 6285 current_function_cannot_inline = 0; 6286 6287 /* We have not yet needed to make a label to jump to for tail-recursion. */ 6288 tail_recursion_label = 0; 6289 6290 /* We haven't had a need to make a save area for ap yet. */ 6291 arg_pointer_save_area = 0; 6292 6293 /* No stack slots allocated yet. */ 6294 frame_offset = 0; 6295 6296 /* No SAVE_EXPRs in this function yet. */ 6297 save_expr_regs = 0; 6298 6299 /* No RTL_EXPRs in this function yet. */ 6300 rtl_expr_chain = 0; 6301 6302 /* Set up to allocate temporaries. */ 6303 init_temp_slots (); 6304 6305 /* Indicate that we need to distinguish between the return value of the 6306 present function and the return value of a function being called. */ 6307 rtx_equal_function_value_matters = 1; 6308 6309 /* Indicate that we have not instantiated virtual registers yet. */ 6310 virtuals_instantiated = 0; 6311 6312 /* Indicate that we want CONCATs now. */ 6313 generating_concat_p = 1; 6314 6315 /* Indicate we have no need of a frame pointer yet. */ 6316 frame_pointer_needed = 0; 6317 6318 /* By default assume not varargs or stdarg. */ 6319 current_function_varargs = 0; 6320 current_function_stdarg = 0; 6321 6322 /* We haven't made any trampolines for this function yet. */ 6323 trampoline_list = 0; 6324 6325 init_pending_stack_adjust (); 6326 inhibit_defer_pop = 0; 6327 6328 current_function_outgoing_args_size = 0; 6329 6330 if (init_lang_status) 6331 (*init_lang_status) (cfun); 6332 if (init_machine_status) 6333 (*init_machine_status) (cfun); 6334 } 6335 6336 /* Initialize the rtl expansion mechanism so that we can do simple things 6337 like generate sequences. This is used to provide a context during global 6338 initialization of some passes. */ 6339 void 6340 init_dummy_function_start () 6341 { 6342 prepare_function_start (); 6343 } 6344 6345 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node) 6346 and initialize static variables for generating RTL for the statements 6347 of the function. */ 6348 6349 void 6350 init_function_start (subr, filename, line) 6351 tree subr; 6352 const char *filename; 6353 int line; 6354 { 6355 prepare_function_start (); 6356 6357 current_function_name = (*decl_printable_name) (subr, 2); 6358 cfun->decl = subr; 6359 6360 /* Nonzero if this is a nested function that uses a static chain. */ 6361 6362 current_function_needs_context 6363 = (decl_function_context (current_function_decl) != 0 6364 && ! DECL_NO_STATIC_CHAIN (current_function_decl)); 6365 6366 /* Within function body, compute a type's size as soon it is laid out. */ 6367 immediate_size_expand++; 6368 6369 /* Prevent ever trying to delete the first instruction of a function. 6370 Also tell final how to output a linenum before the function prologue. 6371 Note linenums could be missing, e.g. when compiling a Java .class file. */ 6372 if (line > 0) 6373 emit_line_note (filename, line); 6374 6375 /* Make sure first insn is a note even if we don't want linenums. 6376 This makes sure the first insn will never be deleted. 6377 Also, final expects a note to appear there. */ 6378 emit_note (NULL, NOTE_INSN_DELETED); 6379 6380 /* Set flags used by final.c. */ 6381 if (aggregate_value_p (DECL_RESULT (subr))) 6382 { 6383 #ifdef PCC_STATIC_STRUCT_RETURN 6384 current_function_returns_pcc_struct = 1; 6385 #endif 6386 current_function_returns_struct = 1; 6387 } 6388 6389 /* Warn if this value is an aggregate type, 6390 regardless of which calling convention we are using for it. */ 6391 if (warn_aggregate_return 6392 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)))) 6393 warning ("function returns an aggregate"); 6394 6395 current_function_returns_pointer 6396 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr))); 6397 } 6398 6399 /* Make sure all values used by the optimization passes have sane 6400 defaults. */ 6401 void 6402 init_function_for_compilation () 6403 { 6404 reg_renumber = 0; 6405 6406 /* No prologue/epilogue insns yet. */ 6407 VARRAY_GROW (prologue, 0); 6408 VARRAY_GROW (epilogue, 0); 6409 VARRAY_GROW (sibcall_epilogue, 0); 6410 } 6411 6412 /* Indicate that the current function uses extra args 6413 not explicitly mentioned in the argument list in any fashion. */ 6414 6415 void 6416 mark_varargs () 6417 { 6418 current_function_varargs = 1; 6419 } 6420 6421 /* Expand a call to __main at the beginning of a possible main function. */ 6422 6423 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main) 6424 #undef HAS_INIT_SECTION 6425 #define HAS_INIT_SECTION 6426 #endif 6427 6428 void 6429 expand_main_function () 6430 { 6431 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN 6432 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN) 6433 { 6434 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; 6435 rtx tmp, seq; 6436 6437 start_sequence (); 6438 /* Forcibly align the stack. */ 6439 #ifdef STACK_GROWS_DOWNWARD 6440 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align), 6441 stack_pointer_rtx, 1, OPTAB_WIDEN); 6442 #else 6443 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx, 6444 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN); 6445 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align), 6446 stack_pointer_rtx, 1, OPTAB_WIDEN); 6447 #endif 6448 if (tmp != stack_pointer_rtx) 6449 emit_move_insn (stack_pointer_rtx, tmp); 6450 6451 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */ 6452 tmp = force_reg (Pmode, const0_rtx); 6453 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT); 6454 seq = gen_sequence (); 6455 end_sequence (); 6456 6457 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp)) 6458 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG) 6459 break; 6460 if (tmp) 6461 emit_insn_before (seq, tmp); 6462 else 6463 emit_insn (seq); 6464 } 6465 #endif 6466 6467 #ifndef HAS_INIT_SECTION 6468 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL, 6469 VOIDmode, 0); 6470 #endif 6471 } 6472 6473 extern struct obstack permanent_obstack; 6474 6475 /* The PENDING_SIZES represent the sizes of variable-sized types. 6476 Create RTL for the various sizes now (using temporary variables), 6477 so that we can refer to the sizes from the RTL we are generating 6478 for the current function. The PENDING_SIZES are a TREE_LIST. The 6479 TREE_VALUE of each node is a SAVE_EXPR. */ 6480 6481 void 6482 expand_pending_sizes (pending_sizes) 6483 tree pending_sizes; 6484 { 6485 tree tem; 6486 6487 /* Evaluate now the sizes of any types declared among the arguments. */ 6488 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem)) 6489 { 6490 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0); 6491 /* Flush the queue in case this parameter declaration has 6492 side-effects. */ 6493 emit_queue (); 6494 } 6495 } 6496 6497 /* Start the RTL for a new function, and set variables used for 6498 emitting RTL. 6499 SUBR is the FUNCTION_DECL node. 6500 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with 6501 the function's parameters, which must be run at any return statement. */ 6502 6503 void 6504 expand_function_start (subr, parms_have_cleanups) 6505 tree subr; 6506 int parms_have_cleanups; 6507 { 6508 tree tem; 6509 rtx last_ptr = NULL_RTX; 6510 6511 /* Make sure volatile mem refs aren't considered 6512 valid operands of arithmetic insns. */ 6513 init_recog_no_volatile (); 6514 6515 current_function_instrument_entry_exit 6516 = (flag_instrument_function_entry_exit 6517 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); 6518 6519 current_function_profile 6520 = (profile_flag 6521 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); 6522 6523 current_function_limit_stack 6524 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr)); 6525 6526 /* If function gets a static chain arg, store it in the stack frame. 6527 Do this first, so it gets the first stack slot offset. */ 6528 if (current_function_needs_context) 6529 { 6530 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); 6531 6532 /* Delay copying static chain if it is not a register to avoid 6533 conflicts with regs used for parameters. */ 6534 if (! SMALL_REGISTER_CLASSES 6535 || GET_CODE (static_chain_incoming_rtx) == REG) 6536 emit_move_insn (last_ptr, static_chain_incoming_rtx); 6537 } 6538 6539 /* If the parameters of this function need cleaning up, get a label 6540 for the beginning of the code which executes those cleanups. This must 6541 be done before doing anything with return_label. */ 6542 if (parms_have_cleanups) 6543 cleanup_label = gen_label_rtx (); 6544 else 6545 cleanup_label = 0; 6546 6547 /* Make the label for return statements to jump to. Do not special 6548 case machines with special return instructions -- they will be 6549 handled later during jump, ifcvt, or epilogue creation. */ 6550 return_label = gen_label_rtx (); 6551 6552 /* Initialize rtx used to return the value. */ 6553 /* Do this before assign_parms so that we copy the struct value address 6554 before any library calls that assign parms might generate. */ 6555 6556 /* Decide whether to return the value in memory or in a register. */ 6557 if (aggregate_value_p (DECL_RESULT (subr))) 6558 { 6559 /* Returning something that won't go in a register. */ 6560 rtx value_address = 0; 6561 6562 #ifdef PCC_STATIC_STRUCT_RETURN 6563 if (current_function_returns_pcc_struct) 6564 { 6565 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); 6566 value_address = assemble_static_space (size); 6567 } 6568 else 6569 #endif 6570 { 6571 /* Expect to be passed the address of a place to store the value. 6572 If it is passed as an argument, assign_parms will take care of 6573 it. */ 6574 if (struct_value_incoming_rtx) 6575 { 6576 value_address = gen_reg_rtx (Pmode); 6577 emit_move_insn (value_address, struct_value_incoming_rtx); 6578 } 6579 } 6580 if (value_address) 6581 { 6582 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address); 6583 set_mem_attributes (x, DECL_RESULT (subr), 1); 6584 SET_DECL_RTL (DECL_RESULT (subr), x); 6585 } 6586 } 6587 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) 6588 /* If return mode is void, this decl rtl should not be used. */ 6589 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX); 6590 else 6591 { 6592 /* Compute the return values into a pseudo reg, which we will copy 6593 into the true return register after the cleanups are done. */ 6594 6595 /* In order to figure out what mode to use for the pseudo, we 6596 figure out what the mode of the eventual return register will 6597 actually be, and use that. */ 6598 rtx hard_reg 6599 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)), 6600 subr, 1); 6601 6602 /* Structures that are returned in registers are not aggregate_value_p, 6603 so we may see a PARALLEL. Don't play pseudo games with this. */ 6604 if (! REG_P (hard_reg)) 6605 SET_DECL_RTL (DECL_RESULT (subr), hard_reg); 6606 else 6607 { 6608 /* Create the pseudo. */ 6609 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg))); 6610 6611 /* Needed because we may need to move this to memory 6612 in case it's a named return value whose address is taken. */ 6613 DECL_REGISTER (DECL_RESULT (subr)) = 1; 6614 } 6615 } 6616 6617 /* Initialize rtx for parameters and local variables. 6618 In some cases this requires emitting insns. */ 6619 6620 assign_parms (subr); 6621 6622 /* Copy the static chain now if it wasn't a register. The delay is to 6623 avoid conflicts with the parameter passing registers. */ 6624 6625 if (SMALL_REGISTER_CLASSES && current_function_needs_context) 6626 if (GET_CODE (static_chain_incoming_rtx) != REG) 6627 emit_move_insn (last_ptr, static_chain_incoming_rtx); 6628 6629 /* The following was moved from init_function_start. 6630 The move is supposed to make sdb output more accurate. */ 6631 /* Indicate the beginning of the function body, 6632 as opposed to parm setup. */ 6633 emit_note (NULL, NOTE_INSN_FUNCTION_BEG); 6634 6635 if (GET_CODE (get_last_insn ()) != NOTE) 6636 emit_note (NULL, NOTE_INSN_DELETED); 6637 parm_birth_insn = get_last_insn (); 6638 6639 context_display = 0; 6640 if (current_function_needs_context) 6641 { 6642 /* Fetch static chain values for containing functions. */ 6643 tem = decl_function_context (current_function_decl); 6644 /* Copy the static chain pointer into a pseudo. If we have 6645 small register classes, copy the value from memory if 6646 static_chain_incoming_rtx is a REG. */ 6647 if (tem) 6648 { 6649 /* If the static chain originally came in a register, put it back 6650 there, then move it out in the next insn. The reason for 6651 this peculiar code is to satisfy function integration. */ 6652 if (SMALL_REGISTER_CLASSES 6653 && GET_CODE (static_chain_incoming_rtx) == REG) 6654 emit_move_insn (static_chain_incoming_rtx, last_ptr); 6655 last_ptr = copy_to_reg (static_chain_incoming_rtx); 6656 } 6657 6658 while (tem) 6659 { 6660 tree rtlexp = make_node (RTL_EXPR); 6661 6662 RTL_EXPR_RTL (rtlexp) = last_ptr; 6663 context_display = tree_cons (tem, rtlexp, context_display); 6664 tem = decl_function_context (tem); 6665 if (tem == 0) 6666 break; 6667 /* Chain thru stack frames, assuming pointer to next lexical frame 6668 is found at the place we always store it. */ 6669 #ifdef FRAME_GROWS_DOWNWARD 6670 last_ptr = plus_constant (last_ptr, 6671 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode)); 6672 #endif 6673 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr)); 6674 set_mem_alias_set (last_ptr, get_frame_alias_set ()); 6675 last_ptr = copy_to_reg (last_ptr); 6676 6677 /* If we are not optimizing, ensure that we know that this 6678 piece of context is live over the entire function. */ 6679 if (! optimize) 6680 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr, 6681 save_expr_regs); 6682 } 6683 } 6684 6685 if (current_function_instrument_entry_exit) 6686 { 6687 rtx fun = DECL_RTL (current_function_decl); 6688 if (GET_CODE (fun) == MEM) 6689 fun = XEXP (fun, 0); 6690 else 6691 abort (); 6692 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode, 6693 2, fun, Pmode, 6694 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 6695 0, 6696 hard_frame_pointer_rtx), 6697 Pmode); 6698 } 6699 6700 if (current_function_profile) 6701 { 6702 current_function_profile_label_no = profile_label_no++; 6703 #ifdef PROFILE_HOOK 6704 PROFILE_HOOK (current_function_profile_label_no); 6705 #endif 6706 } 6707 6708 /* After the display initializations is where the tail-recursion label 6709 should go, if we end up needing one. Ensure we have a NOTE here 6710 since some things (like trampolines) get placed before this. */ 6711 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED); 6712 6713 /* Evaluate now the sizes of any types declared among the arguments. */ 6714 expand_pending_sizes (nreverse (get_pending_sizes ())); 6715 6716 /* Make sure there is a line number after the function entry setup code. */ 6717 force_next_line_note (); 6718 } 6719 6720 /* Undo the effects of init_dummy_function_start. */ 6721 void 6722 expand_dummy_function_end () 6723 { 6724 /* End any sequences that failed to be closed due to syntax errors. */ 6725 while (in_sequence_p ()) 6726 end_sequence (); 6727 6728 /* Outside function body, can't compute type's actual size 6729 until next function's body starts. */ 6730 6731 free_after_parsing (cfun); 6732 free_after_compilation (cfun); 6733 cfun = 0; 6734 } 6735 6736 /* Call DOIT for each hard register used as a return value from 6737 the current function. */ 6738 6739 void 6740 diddle_return_value (doit, arg) 6741 void (*doit) PARAMS ((rtx, void *)); 6742 void *arg; 6743 { 6744 rtx outgoing = current_function_return_rtx; 6745 6746 if (! outgoing) 6747 return; 6748 6749 if (GET_CODE (outgoing) == REG) 6750 (*doit) (outgoing, arg); 6751 else if (GET_CODE (outgoing) == PARALLEL) 6752 { 6753 int i; 6754 6755 for (i = 0; i < XVECLEN (outgoing, 0); i++) 6756 { 6757 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0); 6758 6759 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER) 6760 (*doit) (x, arg); 6761 } 6762 } 6763 } 6764 6765 static void 6766 do_clobber_return_reg (reg, arg) 6767 rtx reg; 6768 void *arg ATTRIBUTE_UNUSED; 6769 { 6770 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg)); 6771 } 6772 6773 void 6774 clobber_return_register () 6775 { 6776 diddle_return_value (do_clobber_return_reg, NULL); 6777 6778 /* In case we do use pseudo to return value, clobber it too. */ 6779 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) 6780 { 6781 tree decl_result = DECL_RESULT (current_function_decl); 6782 rtx decl_rtl = DECL_RTL (decl_result); 6783 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER) 6784 { 6785 do_clobber_return_reg (decl_rtl, NULL); 6786 } 6787 } 6788 } 6789 6790 static void 6791 do_use_return_reg (reg, arg) 6792 rtx reg; 6793 void *arg ATTRIBUTE_UNUSED; 6794 { 6795 emit_insn (gen_rtx_USE (VOIDmode, reg)); 6796 } 6797 6798 void 6799 use_return_register () 6800 { 6801 diddle_return_value (do_use_return_reg, NULL); 6802 } 6803 6804 /* Generate RTL for the end of the current function. 6805 FILENAME and LINE are the current position in the source file. 6806 6807 It is up to language-specific callers to do cleanups for parameters-- 6808 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */ 6809 6810 void 6811 expand_function_end (filename, line, end_bindings) 6812 const char *filename; 6813 int line; 6814 int end_bindings; 6815 { 6816 tree link; 6817 rtx clobber_after; 6818 6819 #ifdef TRAMPOLINE_TEMPLATE 6820 static rtx initial_trampoline; 6821 #endif 6822 6823 finish_expr_for_function (); 6824 6825 /* If arg_pointer_save_area was referenced only from a nested 6826 function, we will not have initialized it yet. Do that now. */ 6827 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init) 6828 get_arg_pointer_save_area (cfun); 6829 6830 #ifdef NON_SAVING_SETJMP 6831 /* Don't put any variables in registers if we call setjmp 6832 on a machine that fails to restore the registers. */ 6833 if (NON_SAVING_SETJMP && current_function_calls_setjmp) 6834 { 6835 if (DECL_INITIAL (current_function_decl) != error_mark_node) 6836 setjmp_protect (DECL_INITIAL (current_function_decl)); 6837 6838 setjmp_protect_args (); 6839 } 6840 #endif 6841 6842 /* Initialize any trampolines required by this function. */ 6843 for (link = trampoline_list; link; link = TREE_CHAIN (link)) 6844 { 6845 tree function = TREE_PURPOSE (link); 6846 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function); 6847 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link)); 6848 #ifdef TRAMPOLINE_TEMPLATE 6849 rtx blktramp; 6850 #endif 6851 rtx seq; 6852 6853 #ifdef TRAMPOLINE_TEMPLATE 6854 /* First make sure this compilation has a template for 6855 initializing trampolines. */ 6856 if (initial_trampoline == 0) 6857 { 6858 initial_trampoline 6859 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ()); 6860 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); 6861 6862 ggc_add_rtx_root (&initial_trampoline, 1); 6863 } 6864 #endif 6865 6866 /* Generate insns to initialize the trampoline. */ 6867 start_sequence (); 6868 tramp = round_trampoline_addr (XEXP (tramp, 0)); 6869 #ifdef TRAMPOLINE_TEMPLATE 6870 blktramp = replace_equiv_address (initial_trampoline, tramp); 6871 emit_block_move (blktramp, initial_trampoline, 6872 GEN_INT (TRAMPOLINE_SIZE)); 6873 #endif 6874 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context); 6875 seq = get_insns (); 6876 end_sequence (); 6877 6878 /* Put those insns at entry to the containing function (this one). */ 6879 emit_insns_before (seq, tail_recursion_reentry); 6880 } 6881 6882 /* If we are doing stack checking and this function makes calls, 6883 do a stack probe at the start of the function to ensure we have enough 6884 space for another stack frame. */ 6885 if (flag_stack_check && ! STACK_CHECK_BUILTIN) 6886 { 6887 rtx insn, seq; 6888 6889 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 6890 if (GET_CODE (insn) == CALL_INSN) 6891 { 6892 start_sequence (); 6893 probe_stack_range (STACK_CHECK_PROTECT, 6894 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE)); 6895 seq = get_insns (); 6896 end_sequence (); 6897 emit_insns_before (seq, tail_recursion_reentry); 6898 break; 6899 } 6900 } 6901 6902 /* Warn about unused parms if extra warnings were specified. */ 6903 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this 6904 warning. WARN_UNUSED_PARAMETER is negative when set by 6905 -Wunused. */ 6906 if (warn_unused_parameter > 0 6907 || (warn_unused_parameter < 0 && extra_warnings)) 6908 { 6909 tree decl; 6910 6911 for (decl = DECL_ARGUMENTS (current_function_decl); 6912 decl; decl = TREE_CHAIN (decl)) 6913 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL 6914 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) 6915 warning_with_decl (decl, "unused parameter `%s'"); 6916 } 6917 6918 /* Delete handlers for nonlocal gotos if nothing uses them. */ 6919 if (nonlocal_goto_handler_slots != 0 6920 && ! current_function_has_nonlocal_label) 6921 delete_handlers (); 6922 6923 /* End any sequences that failed to be closed due to syntax errors. */ 6924 while (in_sequence_p ()) 6925 end_sequence (); 6926 6927 /* Outside function body, can't compute type's actual size 6928 until next function's body starts. */ 6929 immediate_size_expand--; 6930 6931 clear_pending_stack_adjust (); 6932 do_pending_stack_adjust (); 6933 6934 /* Mark the end of the function body. 6935 If control reaches this insn, the function can drop through 6936 without returning a value. */ 6937 emit_note (NULL, NOTE_INSN_FUNCTION_END); 6938 6939 /* Must mark the last line number note in the function, so that the test 6940 coverage code can avoid counting the last line twice. This just tells 6941 the code to ignore the immediately following line note, since there 6942 already exists a copy of this note somewhere above. This line number 6943 note is still needed for debugging though, so we can't delete it. */ 6944 if (flag_test_coverage) 6945 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER); 6946 6947 /* Output a linenumber for the end of the function. 6948 SDB depends on this. */ 6949 emit_line_note_force (filename, line); 6950 6951 /* Before the return label (if any), clobber the return 6952 registers so that they are not propagated live to the rest of 6953 the function. This can only happen with functions that drop 6954 through; if there had been a return statement, there would 6955 have either been a return rtx, or a jump to the return label. 6956 6957 We delay actual code generation after the current_function_value_rtx 6958 is computed. */ 6959 clobber_after = get_last_insn (); 6960 6961 /* Output the label for the actual return from the function, 6962 if one is expected. This happens either because a function epilogue 6963 is used instead of a return instruction, or because a return was done 6964 with a goto in order to run local cleanups, or because of pcc-style 6965 structure returning. */ 6966 if (return_label) 6967 emit_label (return_label); 6968 6969 /* C++ uses this. */ 6970 if (end_bindings) 6971 expand_end_bindings (0, 0, 0); 6972 6973 if (current_function_instrument_entry_exit) 6974 { 6975 rtx fun = DECL_RTL (current_function_decl); 6976 if (GET_CODE (fun) == MEM) 6977 fun = XEXP (fun, 0); 6978 else 6979 abort (); 6980 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode, 6981 2, fun, Pmode, 6982 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 6983 0, 6984 hard_frame_pointer_rtx), 6985 Pmode); 6986 } 6987 6988 /* Let except.c know where it should emit the call to unregister 6989 the function context for sjlj exceptions. */ 6990 if (flag_exceptions && USING_SJLJ_EXCEPTIONS) 6991 sjlj_emit_function_exit_after (get_last_insn ()); 6992 6993 /* If we had calls to alloca, and this machine needs 6994 an accurate stack pointer to exit the function, 6995 insert some code to save and restore the stack pointer. */ 6996 #ifdef EXIT_IGNORE_STACK 6997 if (! EXIT_IGNORE_STACK) 6998 #endif 6999 if (current_function_calls_alloca) 7000 { 7001 rtx tem = 0; 7002 7003 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); 7004 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); 7005 } 7006 7007 /* If scalar return value was computed in a pseudo-reg, or was a named 7008 return value that got dumped to the stack, copy that to the hard 7009 return register. */ 7010 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) 7011 { 7012 tree decl_result = DECL_RESULT (current_function_decl); 7013 rtx decl_rtl = DECL_RTL (decl_result); 7014 7015 if (REG_P (decl_rtl) 7016 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER 7017 : DECL_REGISTER (decl_result)) 7018 { 7019 rtx real_decl_rtl = current_function_return_rtx; 7020 7021 /* This should be set in assign_parms. */ 7022 if (! REG_FUNCTION_VALUE_P (real_decl_rtl)) 7023 abort (); 7024 7025 /* If this is a BLKmode structure being returned in registers, 7026 then use the mode computed in expand_return. Note that if 7027 decl_rtl is memory, then its mode may have been changed, 7028 but that current_function_return_rtx has not. */ 7029 if (GET_MODE (real_decl_rtl) == BLKmode) 7030 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl)); 7031 7032 /* If a named return value dumped decl_return to memory, then 7033 we may need to re-do the PROMOTE_MODE signed/unsigned 7034 extension. */ 7035 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl)) 7036 { 7037 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result)); 7038 7039 #ifdef PROMOTE_FUNCTION_RETURN 7040 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl), 7041 &unsignedp, 1); 7042 #endif 7043 7044 convert_move (real_decl_rtl, decl_rtl, unsignedp); 7045 } 7046 else if (GET_CODE (real_decl_rtl) == PARALLEL) 7047 emit_group_load (real_decl_rtl, decl_rtl, 7048 int_size_in_bytes (TREE_TYPE (decl_result))); 7049 else 7050 emit_move_insn (real_decl_rtl, decl_rtl); 7051 } 7052 } 7053 7054 /* If returning a structure, arrange to return the address of the value 7055 in a place where debuggers expect to find it. 7056 7057 If returning a structure PCC style, 7058 the caller also depends on this value. 7059 And current_function_returns_pcc_struct is not necessarily set. */ 7060 if (current_function_returns_struct 7061 || current_function_returns_pcc_struct) 7062 { 7063 rtx value_address 7064 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); 7065 tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); 7066 #ifdef FUNCTION_OUTGOING_VALUE 7067 rtx outgoing 7068 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type), 7069 current_function_decl); 7070 #else 7071 rtx outgoing 7072 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl); 7073 #endif 7074 7075 /* Mark this as a function return value so integrate will delete the 7076 assignment and USE below when inlining this function. */ 7077 REG_FUNCTION_VALUE_P (outgoing) = 1; 7078 7079 #ifdef POINTERS_EXTEND_UNSIGNED 7080 /* The address may be ptr_mode and OUTGOING may be Pmode. */ 7081 if (GET_MODE (outgoing) != GET_MODE (value_address)) 7082 value_address = convert_memory_address (GET_MODE (outgoing), 7083 value_address); 7084 #endif 7085 7086 emit_move_insn (outgoing, value_address); 7087 7088 /* Show return register used to hold result (in this case the address 7089 of the result. */ 7090 current_function_return_rtx = outgoing; 7091 } 7092 7093 /* If this is an implementation of throw, do what's necessary to 7094 communicate between __builtin_eh_return and the epilogue. */ 7095 expand_eh_return (); 7096 7097 /* Emit the actual code to clobber return register. */ 7098 { 7099 rtx seq, after; 7100 7101 start_sequence (); 7102 clobber_return_register (); 7103 seq = gen_sequence (); 7104 end_sequence (); 7105 7106 after = emit_insn_after (seq, clobber_after); 7107 7108 if (clobber_after != after) 7109 cfun->x_clobber_return_insn = after; 7110 } 7111 7112 /* ??? This should no longer be necessary since stupid is no longer with 7113 us, but there are some parts of the compiler (eg reload_combine, and 7114 sh mach_dep_reorg) that still try and compute their own lifetime info 7115 instead of using the general framework. */ 7116 use_return_register (); 7117 7118 /* Fix up any gotos that jumped out to the outermost 7119 binding level of the function. 7120 Must follow emitting RETURN_LABEL. */ 7121 7122 /* If you have any cleanups to do at this point, 7123 and they need to create temporary variables, 7124 then you will lose. */ 7125 expand_fixups (get_insns ()); 7126 } 7127 7128 rtx 7129 get_arg_pointer_save_area (f) 7130 struct function *f; 7131 { 7132 rtx ret = f->x_arg_pointer_save_area; 7133 7134 if (! ret) 7135 { 7136 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f); 7137 f->x_arg_pointer_save_area = ret; 7138 } 7139 7140 if (f == cfun && ! f->arg_pointer_save_area_init) 7141 { 7142 rtx seq; 7143 7144 /* Save the arg pointer at the beginning of the function. The 7145 generated stack slot may not be a valid memory address, so we 7146 have to check it and fix it if necessary. */ 7147 start_sequence (); 7148 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx); 7149 seq = gen_sequence (); 7150 end_sequence (); 7151 7152 push_topmost_sequence (); 7153 emit_insn_after (seq, get_insns ()); 7154 pop_topmost_sequence (); 7155 } 7156 7157 return ret; 7158 } 7159 7160 /* Extend a vector that records the INSN_UIDs of INSNS (either a 7161 sequence or a single insn). */ 7162 7163 static void 7164 record_insns (insns, vecp) 7165 rtx insns; 7166 varray_type *vecp; 7167 { 7168 if (GET_CODE (insns) == SEQUENCE) 7169 { 7170 int len = XVECLEN (insns, 0); 7171 int i = VARRAY_SIZE (*vecp); 7172 7173 VARRAY_GROW (*vecp, i + len); 7174 while (--len >= 0) 7175 { 7176 VARRAY_INT (*vecp, i) = INSN_UID (XVECEXP (insns, 0, len)); 7177 ++i; 7178 } 7179 } 7180 else 7181 { 7182 int i = VARRAY_SIZE (*vecp); 7183 VARRAY_GROW (*vecp, i + 1); 7184 VARRAY_INT (*vecp, i) = INSN_UID (insns); 7185 } 7186 } 7187 7188 /* Determine how many INSN_UIDs in VEC are part of INSN. */ 7189 7190 static int 7191 contains (insn, vec) 7192 rtx insn; 7193 varray_type vec; 7194 { 7195 int i, j; 7196 7197 if (GET_CODE (insn) == INSN 7198 && GET_CODE (PATTERN (insn)) == SEQUENCE) 7199 { 7200 int count = 0; 7201 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) 7202 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j) 7203 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j)) 7204 count++; 7205 return count; 7206 } 7207 else 7208 { 7209 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j) 7210 if (INSN_UID (insn) == VARRAY_INT (vec, j)) 7211 return 1; 7212 } 7213 return 0; 7214 } 7215 7216 int 7217 prologue_epilogue_contains (insn) 7218 rtx insn; 7219 { 7220 if (contains (insn, prologue)) 7221 return 1; 7222 if (contains (insn, epilogue)) 7223 return 1; 7224 return 0; 7225 } 7226 7227 int 7228 sibcall_epilogue_contains (insn) 7229 rtx insn; 7230 { 7231 if (sibcall_epilogue) 7232 return contains (insn, sibcall_epilogue); 7233 return 0; 7234 } 7235 7236 #ifdef HAVE_return 7237 /* Insert gen_return at the end of block BB. This also means updating 7238 block_for_insn appropriately. */ 7239 7240 static void 7241 emit_return_into_block (bb, line_note) 7242 basic_block bb; 7243 rtx line_note; 7244 { 7245 rtx p, end; 7246 7247 p = NEXT_INSN (bb->end); 7248 end = emit_jump_insn_after (gen_return (), bb->end); 7249 if (line_note) 7250 emit_line_note_after (NOTE_SOURCE_FILE (line_note), 7251 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end)); 7252 } 7253 #endif /* HAVE_return */ 7254 7255 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX) 7256 7257 /* These functions convert the epilogue into a variant that does not modify the 7258 stack pointer. This is used in cases where a function returns an object 7259 whose size is not known until it is computed. The called function leaves the 7260 object on the stack, leaves the stack depressed, and returns a pointer to 7261 the object. 7262 7263 What we need to do is track all modifications and references to the stack 7264 pointer, deleting the modifications and changing the references to point to 7265 the location the stack pointer would have pointed to had the modifications 7266 taken place. 7267 7268 These functions need to be portable so we need to make as few assumptions 7269 about the epilogue as we can. However, the epilogue basically contains 7270 three things: instructions to reset the stack pointer, instructions to 7271 reload registers, possibly including the frame pointer, and an 7272 instruction to return to the caller. 7273 7274 If we can't be sure of what a relevant epilogue insn is doing, we abort. 7275 We also make no attempt to validate the insns we make since if they are 7276 invalid, we probably can't do anything valid. The intent is that these 7277 routines get "smarter" as more and more machines start to use them and 7278 they try operating on different epilogues. 7279 7280 We use the following structure to track what the part of the epilogue that 7281 we've already processed has done. We keep two copies of the SP equivalence, 7282 one for use during the insn we are processing and one for use in the next 7283 insn. The difference is because one part of a PARALLEL may adjust SP 7284 and the other may use it. */ 7285 7286 struct epi_info 7287 { 7288 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */ 7289 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */ 7290 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */ 7291 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */ 7292 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG 7293 should be set to once we no longer need 7294 its value. */ 7295 }; 7296 7297 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *)); 7298 static void emit_equiv_load PARAMS ((struct epi_info *)); 7299 7300 /* Modify SEQ, a SEQUENCE that is part of the epilogue, to no modifications 7301 to the stack pointer. Return the new sequence. */ 7302 7303 static rtx 7304 keep_stack_depressed (seq) 7305 rtx seq; 7306 { 7307 int i, j; 7308 struct epi_info info; 7309 7310 /* If the epilogue is just a single instruction, it ust be OK as is. */ 7311 7312 if (GET_CODE (seq) != SEQUENCE) 7313 return seq; 7314 7315 /* Otherwise, start a sequence, initialize the information we have, and 7316 process all the insns we were given. */ 7317 start_sequence (); 7318 7319 info.sp_equiv_reg = stack_pointer_rtx; 7320 info.sp_offset = 0; 7321 info.equiv_reg_src = 0; 7322 7323 for (i = 0; i < XVECLEN (seq, 0); i++) 7324 { 7325 rtx insn = XVECEXP (seq, 0, i); 7326 7327 if (!INSN_P (insn)) 7328 { 7329 add_insn (insn); 7330 continue; 7331 } 7332 7333 /* If this insn references the register that SP is equivalent to and 7334 we have a pending load to that register, we must force out the load 7335 first and then indicate we no longer know what SP's equivalent is. */ 7336 if (info.equiv_reg_src != 0 7337 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn))) 7338 { 7339 emit_equiv_load (&info); 7340 info.sp_equiv_reg = 0; 7341 } 7342 7343 info.new_sp_equiv_reg = info.sp_equiv_reg; 7344 info.new_sp_offset = info.sp_offset; 7345 7346 /* If this is a (RETURN) and the return address is on the stack, 7347 update the address and change to an indirect jump. */ 7348 if (GET_CODE (PATTERN (insn)) == RETURN 7349 || (GET_CODE (PATTERN (insn)) == PARALLEL 7350 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN)) 7351 { 7352 rtx retaddr = INCOMING_RETURN_ADDR_RTX; 7353 rtx base = 0; 7354 HOST_WIDE_INT offset = 0; 7355 rtx jump_insn, jump_set; 7356 7357 /* If the return address is in a register, we can emit the insn 7358 unchanged. Otherwise, it must be a MEM and we see what the 7359 base register and offset are. In any case, we have to emit any 7360 pending load to the equivalent reg of SP, if any. */ 7361 if (GET_CODE (retaddr) == REG) 7362 { 7363 emit_equiv_load (&info); 7364 add_insn (insn); 7365 continue; 7366 } 7367 else if (GET_CODE (retaddr) == MEM 7368 && GET_CODE (XEXP (retaddr, 0)) == REG) 7369 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0; 7370 else if (GET_CODE (retaddr) == MEM 7371 && GET_CODE (XEXP (retaddr, 0)) == PLUS 7372 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG 7373 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT) 7374 { 7375 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0))); 7376 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1)); 7377 } 7378 else 7379 abort (); 7380 7381 /* If the base of the location containing the return pointer 7382 is SP, we must update it with the replacement address. Otherwise, 7383 just build the necessary MEM. */ 7384 retaddr = plus_constant (base, offset); 7385 if (base == stack_pointer_rtx) 7386 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx, 7387 plus_constant (info.sp_equiv_reg, 7388 info.sp_offset)); 7389 7390 retaddr = gen_rtx_MEM (Pmode, retaddr); 7391 7392 /* If there is a pending load to the equivalent register for SP 7393 and we reference that register, we must load our address into 7394 a scratch register and then do that load. */ 7395 if (info.equiv_reg_src 7396 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr)) 7397 { 7398 unsigned int regno; 7399 rtx reg; 7400 7401 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) 7402 if (HARD_REGNO_MODE_OK (regno, Pmode) 7403 && !fixed_regs[regno] 7404 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno) 7405 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start, 7406 regno) 7407 && !refers_to_regno_p (regno, 7408 regno + HARD_REGNO_NREGS (regno, 7409 Pmode), 7410 info.equiv_reg_src, NULL)) 7411 break; 7412 7413 if (regno == FIRST_PSEUDO_REGISTER) 7414 abort (); 7415 7416 reg = gen_rtx_REG (Pmode, regno); 7417 emit_move_insn (reg, retaddr); 7418 retaddr = reg; 7419 } 7420 7421 emit_equiv_load (&info); 7422 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr)); 7423 7424 /* Show the SET in the above insn is a RETURN. */ 7425 jump_set = single_set (jump_insn); 7426 if (jump_set == 0) 7427 abort (); 7428 else 7429 SET_IS_RETURN_P (jump_set) = 1; 7430 } 7431 7432 /* If SP is not mentioned in the pattern and its equivalent register, if 7433 any, is not modified, just emit it. Otherwise, if neither is set, 7434 replace the reference to SP and emit the insn. If none of those are 7435 true, handle each SET individually. */ 7436 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)) 7437 && (info.sp_equiv_reg == stack_pointer_rtx 7438 || !reg_set_p (info.sp_equiv_reg, insn))) 7439 add_insn (insn); 7440 else if (! reg_set_p (stack_pointer_rtx, insn) 7441 && (info.sp_equiv_reg == stack_pointer_rtx 7442 || !reg_set_p (info.sp_equiv_reg, insn))) 7443 { 7444 if (! validate_replace_rtx (stack_pointer_rtx, 7445 plus_constant (info.sp_equiv_reg, 7446 info.sp_offset), 7447 insn)) 7448 abort (); 7449 7450 add_insn (insn); 7451 } 7452 else if (GET_CODE (PATTERN (insn)) == SET) 7453 handle_epilogue_set (PATTERN (insn), &info); 7454 else if (GET_CODE (PATTERN (insn)) == PARALLEL) 7455 { 7456 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++) 7457 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET) 7458 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info); 7459 } 7460 else 7461 add_insn (insn); 7462 7463 info.sp_equiv_reg = info.new_sp_equiv_reg; 7464 info.sp_offset = info.new_sp_offset; 7465 } 7466 7467 seq = gen_sequence (); 7468 end_sequence (); 7469 return seq; 7470 } 7471 7472 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info 7473 structure that contains information about what we've seen so far. We 7474 process this SET by either updating that data or by emitting one or 7475 more insns. */ 7476 7477 static void 7478 handle_epilogue_set (set, p) 7479 rtx set; 7480 struct epi_info *p; 7481 { 7482 /* First handle the case where we are setting SP. Record what it is being 7483 set from. If unknown, abort. */ 7484 if (reg_set_p (stack_pointer_rtx, set)) 7485 { 7486 if (SET_DEST (set) != stack_pointer_rtx) 7487 abort (); 7488 7489 if (GET_CODE (SET_SRC (set)) == PLUS 7490 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT) 7491 { 7492 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0); 7493 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1)); 7494 } 7495 else 7496 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0; 7497 7498 /* If we are adjusting SP, we adjust from the old data. */ 7499 if (p->new_sp_equiv_reg == stack_pointer_rtx) 7500 { 7501 p->new_sp_equiv_reg = p->sp_equiv_reg; 7502 p->new_sp_offset += p->sp_offset; 7503 } 7504 7505 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG) 7506 abort (); 7507 7508 return; 7509 } 7510 7511 /* Next handle the case where we are setting SP's equivalent register. 7512 If we already have a value to set it to, abort. We could update, but 7513 there seems little point in handling that case. Note that we have 7514 to allow for the case where we are setting the register set in 7515 the previous part of a PARALLEL inside a single insn. But use the 7516 old offset for any updates within this insn. */ 7517 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set)) 7518 { 7519 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set)) 7520 || p->equiv_reg_src != 0) 7521 abort (); 7522 else 7523 p->equiv_reg_src 7524 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx, 7525 plus_constant (p->sp_equiv_reg, 7526 p->sp_offset)); 7527 } 7528 7529 /* Otherwise, replace any references to SP in the insn to its new value 7530 and emit the insn. */ 7531 else 7532 { 7533 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx, 7534 plus_constant (p->sp_equiv_reg, 7535 p->sp_offset)); 7536 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx, 7537 plus_constant (p->sp_equiv_reg, 7538 p->sp_offset)); 7539 emit_insn (set); 7540 } 7541 } 7542 7543 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */ 7544 7545 static void 7546 emit_equiv_load (p) 7547 struct epi_info *p; 7548 { 7549 if (p->equiv_reg_src != 0) 7550 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src); 7551 7552 p->equiv_reg_src = 0; 7553 } 7554 #endif 7555 7556 /* Generate the prologue and epilogue RTL if the machine supports it. Thread 7557 this into place with notes indicating where the prologue ends and where 7558 the epilogue begins. Update the basic block information when possible. */ 7559 7560 void 7561 thread_prologue_and_epilogue_insns (f) 7562 rtx f ATTRIBUTE_UNUSED; 7563 { 7564 int inserted = 0; 7565 edge e; 7566 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue) 7567 rtx seq; 7568 #endif 7569 #ifdef HAVE_prologue 7570 rtx prologue_end = NULL_RTX; 7571 #endif 7572 #if defined (HAVE_epilogue) || defined(HAVE_return) 7573 rtx epilogue_end = NULL_RTX; 7574 #endif 7575 7576 #ifdef HAVE_prologue 7577 if (HAVE_prologue) 7578 { 7579 start_sequence (); 7580 seq = gen_prologue (); 7581 emit_insn (seq); 7582 7583 /* Retain a map of the prologue insns. */ 7584 if (GET_CODE (seq) != SEQUENCE) 7585 seq = get_insns (); 7586 record_insns (seq, &prologue); 7587 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END); 7588 7589 seq = gen_sequence (); 7590 end_sequence (); 7591 7592 /* Can't deal with multiple successors of the entry block 7593 at the moment. Function should always have at least one 7594 entry point. */ 7595 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next) 7596 abort (); 7597 7598 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ); 7599 inserted = 1; 7600 } 7601 #endif 7602 7603 /* If the exit block has no non-fake predecessors, we don't need 7604 an epilogue. */ 7605 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7606 if ((e->flags & EDGE_FAKE) == 0) 7607 break; 7608 if (e == NULL) 7609 goto epilogue_done; 7610 7611 #ifdef HAVE_return 7612 if (optimize && HAVE_return) 7613 { 7614 /* If we're allowed to generate a simple return instruction, 7615 then by definition we don't need a full epilogue. Examine 7616 the block that falls through to EXIT. If it does not 7617 contain any code, examine its predecessors and try to 7618 emit (conditional) return instructions. */ 7619 7620 basic_block last; 7621 edge e_next; 7622 rtx label; 7623 7624 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7625 if (e->flags & EDGE_FALLTHRU) 7626 break; 7627 if (e == NULL) 7628 goto epilogue_done; 7629 last = e->src; 7630 7631 /* Verify that there are no active instructions in the last block. */ 7632 label = last->end; 7633 while (label && GET_CODE (label) != CODE_LABEL) 7634 { 7635 if (active_insn_p (label)) 7636 break; 7637 label = PREV_INSN (label); 7638 } 7639 7640 if (last->head == label && GET_CODE (label) == CODE_LABEL) 7641 { 7642 rtx epilogue_line_note = NULL_RTX; 7643 7644 /* Locate the line number associated with the closing brace, 7645 if we can find one. */ 7646 for (seq = get_last_insn (); 7647 seq && ! active_insn_p (seq); 7648 seq = PREV_INSN (seq)) 7649 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0) 7650 { 7651 epilogue_line_note = seq; 7652 break; 7653 } 7654 7655 for (e = last->pred; e; e = e_next) 7656 { 7657 basic_block bb = e->src; 7658 rtx jump; 7659 7660 e_next = e->pred_next; 7661 if (bb == ENTRY_BLOCK_PTR) 7662 continue; 7663 7664 jump = bb->end; 7665 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label) 7666 continue; 7667 7668 /* If we have an unconditional jump, we can replace that 7669 with a simple return instruction. */ 7670 if (simplejump_p (jump)) 7671 { 7672 emit_return_into_block (bb, epilogue_line_note); 7673 delete_insn (jump); 7674 } 7675 7676 /* If we have a conditional jump, we can try to replace 7677 that with a conditional return instruction. */ 7678 else if (condjump_p (jump)) 7679 { 7680 rtx ret, *loc; 7681 7682 ret = SET_SRC (PATTERN (jump)); 7683 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF) 7684 loc = &XEXP (ret, 1); 7685 else 7686 loc = &XEXP (ret, 2); 7687 ret = gen_rtx_RETURN (VOIDmode); 7688 7689 if (! validate_change (jump, loc, ret, 0)) 7690 continue; 7691 if (JUMP_LABEL (jump)) 7692 LABEL_NUSES (JUMP_LABEL (jump))--; 7693 7694 /* If this block has only one successor, it both jumps 7695 and falls through to the fallthru block, so we can't 7696 delete the edge. */ 7697 if (bb->succ->succ_next == NULL) 7698 continue; 7699 } 7700 else 7701 continue; 7702 7703 /* Fix up the CFG for the successful change we just made. */ 7704 redirect_edge_succ (e, EXIT_BLOCK_PTR); 7705 } 7706 7707 /* Emit a return insn for the exit fallthru block. Whether 7708 this is still reachable will be determined later. */ 7709 7710 emit_barrier_after (last->end); 7711 emit_return_into_block (last, epilogue_line_note); 7712 epilogue_end = last->end; 7713 last->succ->flags &= ~EDGE_FALLTHRU; 7714 goto epilogue_done; 7715 } 7716 } 7717 #endif 7718 #ifdef HAVE_epilogue 7719 if (HAVE_epilogue) 7720 { 7721 /* Find the edge that falls through to EXIT. Other edges may exist 7722 due to RETURN instructions, but those don't need epilogues. 7723 There really shouldn't be a mixture -- either all should have 7724 been converted or none, however... */ 7725 7726 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7727 if (e->flags & EDGE_FALLTHRU) 7728 break; 7729 if (e == NULL) 7730 goto epilogue_done; 7731 7732 start_sequence (); 7733 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG); 7734 7735 seq = gen_epilogue (); 7736 7737 #ifdef INCOMING_RETURN_ADDR_RTX 7738 /* If this function returns with the stack depressed and we can support 7739 it, massage the epilogue to actually do that. */ 7740 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE 7741 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl))) 7742 seq = keep_stack_depressed (seq); 7743 #endif 7744 7745 emit_jump_insn (seq); 7746 7747 /* Retain a map of the epilogue insns. */ 7748 if (GET_CODE (seq) != SEQUENCE) 7749 seq = get_insns (); 7750 record_insns (seq, &epilogue); 7751 7752 seq = gen_sequence (); 7753 end_sequence (); 7754 7755 insert_insn_on_edge (seq, e); 7756 inserted = 1; 7757 } 7758 #endif 7759 epilogue_done: 7760 7761 if (inserted) 7762 commit_edge_insertions (); 7763 7764 #ifdef HAVE_sibcall_epilogue 7765 /* Emit sibling epilogues before any sibling call sites. */ 7766 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7767 { 7768 basic_block bb = e->src; 7769 rtx insn = bb->end; 7770 rtx i; 7771 rtx newinsn; 7772 7773 if (GET_CODE (insn) != CALL_INSN 7774 || ! SIBLING_CALL_P (insn)) 7775 continue; 7776 7777 start_sequence (); 7778 seq = gen_sibcall_epilogue (); 7779 end_sequence (); 7780 7781 i = PREV_INSN (insn); 7782 newinsn = emit_insn_before (seq, insn); 7783 7784 /* Retain a map of the epilogue insns. Used in life analysis to 7785 avoid getting rid of sibcall epilogue insns. */ 7786 record_insns (GET_CODE (seq) == SEQUENCE 7787 ? seq : newinsn, &sibcall_epilogue); 7788 } 7789 #endif 7790 7791 #ifdef HAVE_prologue 7792 if (prologue_end) 7793 { 7794 rtx insn, prev; 7795 7796 /* GDB handles `break f' by setting a breakpoint on the first 7797 line note after the prologue. Which means (1) that if 7798 there are line number notes before where we inserted the 7799 prologue we should move them, and (2) we should generate a 7800 note before the end of the first basic block, if there isn't 7801 one already there. 7802 7803 ??? This behaviour is completely broken when dealing with 7804 multiple entry functions. We simply place the note always 7805 into first basic block and let alternate entry points 7806 to be missed. 7807 */ 7808 7809 for (insn = prologue_end; insn; insn = prev) 7810 { 7811 prev = PREV_INSN (insn); 7812 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7813 { 7814 /* Note that we cannot reorder the first insn in the 7815 chain, since rest_of_compilation relies on that 7816 remaining constant. */ 7817 if (prev == NULL) 7818 break; 7819 reorder_insns (insn, insn, prologue_end); 7820 } 7821 } 7822 7823 /* Find the last line number note in the first block. */ 7824 for (insn = BASIC_BLOCK (0)->end; 7825 insn != prologue_end && insn; 7826 insn = PREV_INSN (insn)) 7827 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7828 break; 7829 7830 /* If we didn't find one, make a copy of the first line number 7831 we run across. */ 7832 if (! insn) 7833 { 7834 for (insn = next_active_insn (prologue_end); 7835 insn; 7836 insn = PREV_INSN (insn)) 7837 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7838 { 7839 emit_line_note_after (NOTE_SOURCE_FILE (insn), 7840 NOTE_LINE_NUMBER (insn), 7841 prologue_end); 7842 break; 7843 } 7844 } 7845 } 7846 #endif 7847 #ifdef HAVE_epilogue 7848 if (epilogue_end) 7849 { 7850 rtx insn, next; 7851 7852 /* Similarly, move any line notes that appear after the epilogue. 7853 There is no need, however, to be quite so anal about the existence 7854 of such a note. */ 7855 for (insn = epilogue_end; insn; insn = next) 7856 { 7857 next = NEXT_INSN (insn); 7858 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7859 reorder_insns (insn, insn, PREV_INSN (epilogue_end)); 7860 } 7861 } 7862 #endif 7863 } 7864 7865 /* Reposition the prologue-end and epilogue-begin notes after instruction 7866 scheduling and delayed branch scheduling. */ 7867 7868 void 7869 reposition_prologue_and_epilogue_notes (f) 7870 rtx f ATTRIBUTE_UNUSED; 7871 { 7872 #if defined (HAVE_prologue) || defined (HAVE_epilogue) 7873 rtx insn, last, note; 7874 int len; 7875 7876 if ((len = VARRAY_SIZE (prologue)) > 0) 7877 { 7878 last = 0, note = 0; 7879 7880 /* Scan from the beginning until we reach the last prologue insn. 7881 We apparently can't depend on basic_block_{head,end} after 7882 reorg has run. */ 7883 for (insn = f; insn; insn = NEXT_INSN (insn)) 7884 { 7885 if (GET_CODE (insn) == NOTE) 7886 { 7887 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END) 7888 note = insn; 7889 } 7890 else if (contains (insn, prologue)) 7891 { 7892 last = insn; 7893 if (--len == 0) 7894 break; 7895 } 7896 } 7897 7898 if (last) 7899 { 7900 rtx next; 7901 7902 /* Find the prologue-end note if we haven't already, and 7903 move it to just after the last prologue insn. */ 7904 if (note == 0) 7905 { 7906 for (note = last; (note = NEXT_INSN (note));) 7907 if (GET_CODE (note) == NOTE 7908 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END) 7909 break; 7910 } 7911 7912 next = NEXT_INSN (note); 7913 7914 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */ 7915 if (GET_CODE (last) == CODE_LABEL) 7916 last = NEXT_INSN (last); 7917 reorder_insns (note, note, last); 7918 } 7919 } 7920 7921 if ((len = VARRAY_SIZE (epilogue)) > 0) 7922 { 7923 last = 0, note = 0; 7924 7925 /* Scan from the end until we reach the first epilogue insn. 7926 We apparently can't depend on basic_block_{head,end} after 7927 reorg has run. */ 7928 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn)) 7929 { 7930 if (GET_CODE (insn) == NOTE) 7931 { 7932 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG) 7933 note = insn; 7934 } 7935 else if (contains (insn, epilogue)) 7936 { 7937 last = insn; 7938 if (--len == 0) 7939 break; 7940 } 7941 } 7942 7943 if (last) 7944 { 7945 /* Find the epilogue-begin note if we haven't already, and 7946 move it to just before the first epilogue insn. */ 7947 if (note == 0) 7948 { 7949 for (note = insn; (note = PREV_INSN (note));) 7950 if (GET_CODE (note) == NOTE 7951 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG) 7952 break; 7953 } 7954 7955 if (PREV_INSN (last) != note) 7956 reorder_insns (note, note, PREV_INSN (last)); 7957 } 7958 } 7959 #endif /* HAVE_prologue or HAVE_epilogue */ 7960 } 7961 7962 /* Mark P for GC. */ 7963 7964 static void 7965 mark_function_status (p) 7966 struct function *p; 7967 { 7968 struct var_refs_queue *q; 7969 struct temp_slot *t; 7970 int i; 7971 rtx *r; 7972 7973 if (p == 0) 7974 return; 7975 7976 ggc_mark_rtx (p->arg_offset_rtx); 7977 7978 if (p->x_parm_reg_stack_loc) 7979 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc; 7980 i > 0; --i, ++r) 7981 ggc_mark_rtx (*r); 7982 7983 ggc_mark_rtx (p->return_rtx); 7984 ggc_mark_rtx (p->x_cleanup_label); 7985 ggc_mark_rtx (p->x_return_label); 7986 ggc_mark_rtx (p->x_save_expr_regs); 7987 ggc_mark_rtx (p->x_stack_slot_list); 7988 ggc_mark_rtx (p->x_parm_birth_insn); 7989 ggc_mark_rtx (p->x_tail_recursion_label); 7990 ggc_mark_rtx (p->x_tail_recursion_reentry); 7991 ggc_mark_rtx (p->internal_arg_pointer); 7992 ggc_mark_rtx (p->x_arg_pointer_save_area); 7993 ggc_mark_tree (p->x_rtl_expr_chain); 7994 ggc_mark_rtx (p->x_last_parm_insn); 7995 ggc_mark_tree (p->x_context_display); 7996 ggc_mark_tree (p->x_trampoline_list); 7997 ggc_mark_rtx (p->epilogue_delay_list); 7998 ggc_mark_rtx (p->x_clobber_return_insn); 7999 8000 for (t = p->x_temp_slots; t != 0; t = t->next) 8001 { 8002 ggc_mark (t); 8003 ggc_mark_rtx (t->slot); 8004 ggc_mark_rtx (t->address); 8005 ggc_mark_tree (t->rtl_expr); 8006 ggc_mark_tree (t->type); 8007 } 8008 8009 for (q = p->fixup_var_refs_queue; q != 0; q = q->next) 8010 { 8011 ggc_mark (q); 8012 ggc_mark_rtx (q->modified); 8013 } 8014 8015 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots); 8016 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels); 8017 ggc_mark_rtx (p->x_nonlocal_goto_stack_level); 8018 ggc_mark_tree (p->x_nonlocal_labels); 8019 8020 mark_hard_reg_initial_vals (p); 8021 } 8022 8023 /* Mark the struct function pointed to by *ARG for GC, if it is not 8024 NULL. This is used to mark the current function and the outer 8025 function chain. */ 8026 8027 static void 8028 maybe_mark_struct_function (arg) 8029 void *arg; 8030 { 8031 struct function *f = *(struct function **) arg; 8032 8033 if (f == 0) 8034 return; 8035 8036 ggc_mark_struct_function (f); 8037 } 8038 8039 /* Mark a struct function * for GC. This is called from ggc-common.c. */ 8040 8041 void 8042 ggc_mark_struct_function (f) 8043 struct function *f; 8044 { 8045 ggc_mark (f); 8046 ggc_mark_tree (f->decl); 8047 8048 mark_function_status (f); 8049 mark_eh_status (f->eh); 8050 mark_stmt_status (f->stmt); 8051 mark_expr_status (f->expr); 8052 mark_emit_status (f->emit); 8053 mark_varasm_status (f->varasm); 8054 8055 if (mark_machine_status) 8056 (*mark_machine_status) (f); 8057 if (mark_lang_status) 8058 (*mark_lang_status) (f); 8059 8060 if (f->original_arg_vector) 8061 ggc_mark_rtvec ((rtvec) f->original_arg_vector); 8062 if (f->original_decl_initial) 8063 ggc_mark_tree (f->original_decl_initial); 8064 if (f->outer) 8065 ggc_mark_struct_function (f->outer); 8066 } 8067 8068 /* Called once, at initialization, to initialize function.c. */ 8069 8070 void 8071 init_function_once () 8072 { 8073 ggc_add_root (&cfun, 1, sizeof cfun, maybe_mark_struct_function); 8074 ggc_add_root (&outer_function_chain, 1, sizeof outer_function_chain, 8075 maybe_mark_struct_function); 8076 8077 VARRAY_INT_INIT (prologue, 0, "prologue"); 8078 VARRAY_INT_INIT (epilogue, 0, "epilogue"); 8079 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue"); 8080 } 8081