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 put_addressof_into_stack (x, ht); 3075 3076 /* We must create a copy of the rtx because it was created by 3077 overwriting a REG rtx which is always shared. */ 3078 sub = copy_rtx (XEXP (XEXP (x, 0), 0)); 3079 if (validate_change (insn, loc, sub, 0) 3080 || validate_replace_rtx (x, sub, insn)) 3081 return true; 3082 3083 start_sequence (); 3084 sub = force_operand (sub, NULL_RTX); 3085 if (! validate_change (insn, loc, sub, 0) 3086 && ! validate_replace_rtx (x, sub, insn)) 3087 abort (); 3088 3089 insns = gen_sequence (); 3090 end_sequence (); 3091 emit_insn_before (insns, insn); 3092 return true; 3093 } 3094 3095 else if (code == MEM && GET_CODE (XEXP (x, 0)) == ADDRESSOF && ! force) 3096 { 3097 rtx sub = XEXP (XEXP (x, 0), 0); 3098 3099 if (GET_CODE (sub) == MEM) 3100 sub = adjust_address_nv (sub, GET_MODE (x), 0); 3101 else if (GET_CODE (sub) == REG 3102 && (MEM_VOLATILE_P (x) || GET_MODE (x) == BLKmode)) 3103 ; 3104 else if (GET_CODE (sub) == REG && GET_MODE (x) != GET_MODE (sub)) 3105 { 3106 int size_x, size_sub; 3107 3108 if (!insn) 3109 { 3110 /* When processing REG_NOTES look at the list of 3111 replacements done on the insn to find the register that X 3112 was replaced by. */ 3113 rtx tem; 3114 3115 for (tem = purge_bitfield_addressof_replacements; 3116 tem != NULL_RTX; 3117 tem = XEXP (XEXP (tem, 1), 1)) 3118 if (rtx_equal_p (x, XEXP (tem, 0))) 3119 { 3120 *loc = XEXP (XEXP (tem, 1), 0); 3121 return true; 3122 } 3123 3124 /* See comment for purge_addressof_replacements. */ 3125 for (tem = purge_addressof_replacements; 3126 tem != NULL_RTX; 3127 tem = XEXP (XEXP (tem, 1), 1)) 3128 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) 3129 { 3130 rtx z = XEXP (XEXP (tem, 1), 0); 3131 3132 if (GET_MODE (x) == GET_MODE (z) 3133 || (GET_CODE (XEXP (XEXP (tem, 1), 0)) != REG 3134 && GET_CODE (XEXP (XEXP (tem, 1), 0)) != SUBREG)) 3135 abort (); 3136 3137 /* It can happen that the note may speak of things 3138 in a wider (or just different) mode than the 3139 code did. This is especially true of 3140 REG_RETVAL. */ 3141 3142 if (GET_CODE (z) == SUBREG && SUBREG_BYTE (z) == 0) 3143 z = SUBREG_REG (z); 3144 3145 if (GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD 3146 && (GET_MODE_SIZE (GET_MODE (x)) 3147 > GET_MODE_SIZE (GET_MODE (z)))) 3148 { 3149 /* This can occur as a result in invalid 3150 pointer casts, e.g. float f; ... 3151 *(long long int *)&f. 3152 ??? We could emit a warning here, but 3153 without a line number that wouldn't be 3154 very helpful. */ 3155 z = gen_rtx_SUBREG (GET_MODE (x), z, 0); 3156 } 3157 else 3158 z = gen_lowpart (GET_MODE (x), z); 3159 3160 *loc = z; 3161 return true; 3162 } 3163 3164 /* Sometimes we may not be able to find the replacement. For 3165 example when the original insn was a MEM in a wider mode, 3166 and the note is part of a sign extension of a narrowed 3167 version of that MEM. Gcc testcase compile/990829-1.c can 3168 generate an example of this situation. Rather than complain 3169 we return false, which will prompt our caller to remove the 3170 offending note. */ 3171 return false; 3172 } 3173 3174 size_x = GET_MODE_BITSIZE (GET_MODE (x)); 3175 size_sub = GET_MODE_BITSIZE (GET_MODE (sub)); 3176 3177 /* Don't even consider working with paradoxical subregs, 3178 or the moral equivalent seen here. */ 3179 if (size_x <= size_sub 3180 && int_mode_for_mode (GET_MODE (sub)) != BLKmode) 3181 { 3182 /* Do a bitfield insertion to mirror what would happen 3183 in memory. */ 3184 3185 rtx val, seq; 3186 3187 if (store) 3188 { 3189 rtx p = PREV_INSN (insn); 3190 3191 start_sequence (); 3192 val = gen_reg_rtx (GET_MODE (x)); 3193 if (! validate_change (insn, loc, val, 0)) 3194 { 3195 /* Discard the current sequence and put the 3196 ADDRESSOF on stack. */ 3197 end_sequence (); 3198 goto give_up; 3199 } 3200 seq = gen_sequence (); 3201 end_sequence (); 3202 emit_insn_before (seq, insn); 3203 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), 3204 insn, ht); 3205 3206 start_sequence (); 3207 store_bit_field (sub, size_x, 0, GET_MODE (x), 3208 val, GET_MODE_SIZE (GET_MODE (sub))); 3209 3210 /* Make sure to unshare any shared rtl that store_bit_field 3211 might have created. */ 3212 unshare_all_rtl_again (get_insns ()); 3213 3214 seq = gen_sequence (); 3215 end_sequence (); 3216 p = emit_insn_after (seq, insn); 3217 if (NEXT_INSN (insn)) 3218 compute_insns_for_mem (NEXT_INSN (insn), 3219 p ? NEXT_INSN (p) : NULL_RTX, 3220 ht); 3221 } 3222 else 3223 { 3224 rtx p = PREV_INSN (insn); 3225 3226 start_sequence (); 3227 val = extract_bit_field (sub, size_x, 0, 1, NULL_RTX, 3228 GET_MODE (x), GET_MODE (x), 3229 GET_MODE_SIZE (GET_MODE (sub))); 3230 3231 if (! validate_change (insn, loc, val, 0)) 3232 { 3233 /* Discard the current sequence and put the 3234 ADDRESSOF on stack. */ 3235 end_sequence (); 3236 goto give_up; 3237 } 3238 3239 seq = gen_sequence (); 3240 end_sequence (); 3241 emit_insn_before (seq, insn); 3242 compute_insns_for_mem (p ? NEXT_INSN (p) : get_insns (), 3243 insn, ht); 3244 } 3245 3246 /* Remember the replacement so that the same one can be done 3247 on the REG_NOTES. */ 3248 purge_bitfield_addressof_replacements 3249 = gen_rtx_EXPR_LIST (VOIDmode, x, 3250 gen_rtx_EXPR_LIST 3251 (VOIDmode, val, 3252 purge_bitfield_addressof_replacements)); 3253 3254 /* We replaced with a reg -- all done. */ 3255 return true; 3256 } 3257 } 3258 3259 else if (validate_change (insn, loc, sub, 0)) 3260 { 3261 /* Remember the replacement so that the same one can be done 3262 on the REG_NOTES. */ 3263 if (GET_CODE (sub) == REG || GET_CODE (sub) == SUBREG) 3264 { 3265 rtx tem; 3266 3267 for (tem = purge_addressof_replacements; 3268 tem != NULL_RTX; 3269 tem = XEXP (XEXP (tem, 1), 1)) 3270 if (rtx_equal_p (XEXP (x, 0), XEXP (tem, 0))) 3271 { 3272 XEXP (XEXP (tem, 1), 0) = sub; 3273 return true; 3274 } 3275 purge_addressof_replacements 3276 = gen_rtx (EXPR_LIST, VOIDmode, XEXP (x, 0), 3277 gen_rtx_EXPR_LIST (VOIDmode, sub, 3278 purge_addressof_replacements)); 3279 return true; 3280 } 3281 goto restart; 3282 } 3283 } 3284 3285 give_up: 3286 /* Scan all subexpressions. */ 3287 fmt = GET_RTX_FORMAT (code); 3288 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) 3289 { 3290 if (*fmt == 'e') 3291 result &= purge_addressof_1 (&XEXP (x, i), insn, force, 0, ht); 3292 else if (*fmt == 'E') 3293 for (j = 0; j < XVECLEN (x, i); j++) 3294 result &= purge_addressof_1 (&XVECEXP (x, i, j), insn, force, 0, ht); 3295 } 3296 3297 return result; 3298 } 3299 3300 /* Return a new hash table entry in HT. */ 3301 3302 static struct hash_entry * 3303 insns_for_mem_newfunc (he, ht, k) 3304 struct hash_entry *he; 3305 struct hash_table *ht; 3306 hash_table_key k ATTRIBUTE_UNUSED; 3307 { 3308 struct insns_for_mem_entry *ifmhe; 3309 if (he) 3310 return he; 3311 3312 ifmhe = ((struct insns_for_mem_entry *) 3313 hash_allocate (ht, sizeof (struct insns_for_mem_entry))); 3314 ifmhe->insns = NULL_RTX; 3315 3316 return &ifmhe->he; 3317 } 3318 3319 /* Return a hash value for K, a REG. */ 3320 3321 static unsigned long 3322 insns_for_mem_hash (k) 3323 hash_table_key k; 3324 { 3325 /* K is really a RTX. Just use the address as the hash value. */ 3326 return (unsigned long) k; 3327 } 3328 3329 /* Return non-zero if K1 and K2 (two REGs) are the same. */ 3330 3331 static bool 3332 insns_for_mem_comp (k1, k2) 3333 hash_table_key k1; 3334 hash_table_key k2; 3335 { 3336 return k1 == k2; 3337 } 3338 3339 struct insns_for_mem_walk_info 3340 { 3341 /* The hash table that we are using to record which INSNs use which 3342 MEMs. */ 3343 struct hash_table *ht; 3344 3345 /* The INSN we are currently processing. */ 3346 rtx insn; 3347 3348 /* Zero if we are walking to find ADDRESSOFs, one if we are walking 3349 to find the insns that use the REGs in the ADDRESSOFs. */ 3350 int pass; 3351 }; 3352 3353 /* Called from compute_insns_for_mem via for_each_rtx. If R is a REG 3354 that might be used in an ADDRESSOF expression, record this INSN in 3355 the hash table given by DATA (which is really a pointer to an 3356 insns_for_mem_walk_info structure). */ 3357 3358 static int 3359 insns_for_mem_walk (r, data) 3360 rtx *r; 3361 void *data; 3362 { 3363 struct insns_for_mem_walk_info *ifmwi 3364 = (struct insns_for_mem_walk_info *) data; 3365 3366 if (ifmwi->pass == 0 && *r && GET_CODE (*r) == ADDRESSOF 3367 && GET_CODE (XEXP (*r, 0)) == REG) 3368 hash_lookup (ifmwi->ht, XEXP (*r, 0), /*create=*/1, /*copy=*/0); 3369 else if (ifmwi->pass == 1 && *r && GET_CODE (*r) == REG) 3370 { 3371 /* Lookup this MEM in the hashtable, creating it if necessary. */ 3372 struct insns_for_mem_entry *ifme 3373 = (struct insns_for_mem_entry *) hash_lookup (ifmwi->ht, 3374 *r, 3375 /*create=*/0, 3376 /*copy=*/0); 3377 3378 /* If we have not already recorded this INSN, do so now. Since 3379 we process the INSNs in order, we know that if we have 3380 recorded it it must be at the front of the list. */ 3381 if (ifme && (!ifme->insns || XEXP (ifme->insns, 0) != ifmwi->insn)) 3382 ifme->insns = gen_rtx_EXPR_LIST (VOIDmode, ifmwi->insn, 3383 ifme->insns); 3384 } 3385 3386 return 0; 3387 } 3388 3389 /* Walk the INSNS, until we reach LAST_INSN, recording which INSNs use 3390 which REGs in HT. */ 3391 3392 static void 3393 compute_insns_for_mem (insns, last_insn, ht) 3394 rtx insns; 3395 rtx last_insn; 3396 struct hash_table *ht; 3397 { 3398 rtx insn; 3399 struct insns_for_mem_walk_info ifmwi; 3400 ifmwi.ht = ht; 3401 3402 for (ifmwi.pass = 0; ifmwi.pass < 2; ++ifmwi.pass) 3403 for (insn = insns; insn != last_insn; insn = NEXT_INSN (insn)) 3404 if (INSN_P (insn)) 3405 { 3406 ifmwi.insn = insn; 3407 for_each_rtx (&insn, insns_for_mem_walk, &ifmwi); 3408 } 3409 } 3410 3411 /* Helper function for purge_addressof called through for_each_rtx. 3412 Returns true iff the rtl is an ADDRESSOF. */ 3413 3414 static int 3415 is_addressof (rtl, data) 3416 rtx *rtl; 3417 void *data ATTRIBUTE_UNUSED; 3418 { 3419 return GET_CODE (*rtl) == ADDRESSOF; 3420 } 3421 3422 /* Eliminate all occurrences of ADDRESSOF from INSNS. Elide any remaining 3423 (MEM (ADDRESSOF)) patterns, and force any needed registers into the 3424 stack. */ 3425 3426 void 3427 purge_addressof (insns) 3428 rtx insns; 3429 { 3430 rtx insn; 3431 struct hash_table ht; 3432 3433 /* When we actually purge ADDRESSOFs, we turn REGs into MEMs. That 3434 requires a fixup pass over the instruction stream to correct 3435 INSNs that depended on the REG being a REG, and not a MEM. But, 3436 these fixup passes are slow. Furthermore, most MEMs are not 3437 mentioned in very many instructions. So, we speed up the process 3438 by pre-calculating which REGs occur in which INSNs; that allows 3439 us to perform the fixup passes much more quickly. */ 3440 hash_table_init (&ht, 3441 insns_for_mem_newfunc, 3442 insns_for_mem_hash, 3443 insns_for_mem_comp); 3444 compute_insns_for_mem (insns, NULL_RTX, &ht); 3445 3446 for (insn = insns; insn; insn = NEXT_INSN (insn)) 3447 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN 3448 || GET_CODE (insn) == CALL_INSN) 3449 { 3450 if (! purge_addressof_1 (&PATTERN (insn), insn, 3451 asm_noperands (PATTERN (insn)) > 0, 0, &ht)) 3452 /* If we could not replace the ADDRESSOFs in the insn, 3453 something is wrong. */ 3454 abort (); 3455 3456 if (! purge_addressof_1 (®_NOTES (insn), NULL_RTX, 0, 0, &ht)) 3457 { 3458 /* If we could not replace the ADDRESSOFs in the insn's notes, 3459 we can just remove the offending notes instead. */ 3460 rtx note; 3461 3462 for (note = REG_NOTES (insn); note; note = XEXP (note, 1)) 3463 { 3464 /* If we find a REG_RETVAL note then the insn is a libcall. 3465 Such insns must have REG_EQUAL notes as well, in order 3466 for later passes of the compiler to work. So it is not 3467 safe to delete the notes here, and instead we abort. */ 3468 if (REG_NOTE_KIND (note) == REG_RETVAL) 3469 abort (); 3470 if (for_each_rtx (¬e, is_addressof, NULL)) 3471 remove_note (insn, note); 3472 } 3473 } 3474 } 3475 3476 /* Clean up. */ 3477 hash_table_free (&ht); 3478 purge_bitfield_addressof_replacements = 0; 3479 purge_addressof_replacements = 0; 3480 3481 /* REGs are shared. purge_addressof will destructively replace a REG 3482 with a MEM, which creates shared MEMs. 3483 3484 Unfortunately, the children of put_reg_into_stack assume that MEMs 3485 referring to the same stack slot are shared (fixup_var_refs and 3486 the associated hash table code). 3487 3488 So, we have to do another unsharing pass after we have flushed any 3489 REGs that had their address taken into the stack. 3490 3491 It may be worth tracking whether or not we converted any REGs into 3492 MEMs to avoid this overhead when it is not needed. */ 3493 unshare_all_rtl_again (get_insns ()); 3494 } 3495 3496 /* Convert a SET of a hard subreg to a set of the appropriate hard 3497 register. A subroutine of purge_hard_subreg_sets. */ 3498 3499 static void 3500 purge_single_hard_subreg_set (pattern) 3501 rtx pattern; 3502 { 3503 rtx reg = SET_DEST (pattern); 3504 enum machine_mode mode = GET_MODE (SET_DEST (pattern)); 3505 int offset = 0; 3506 3507 if (GET_CODE (reg) == SUBREG && GET_CODE (SUBREG_REG (reg)) == REG 3508 && REGNO (SUBREG_REG (reg)) < FIRST_PSEUDO_REGISTER) 3509 { 3510 offset = subreg_regno_offset (REGNO (SUBREG_REG (reg)), 3511 GET_MODE (SUBREG_REG (reg)), 3512 SUBREG_BYTE (reg), 3513 GET_MODE (reg)); 3514 reg = SUBREG_REG (reg); 3515 } 3516 3517 3518 if (GET_CODE (reg) == REG && REGNO (reg) < FIRST_PSEUDO_REGISTER) 3519 { 3520 reg = gen_rtx_REG (mode, REGNO (reg) + offset); 3521 SET_DEST (pattern) = reg; 3522 } 3523 } 3524 3525 /* Eliminate all occurrences of SETs of hard subregs from INSNS. The 3526 only such SETs that we expect to see are those left in because 3527 integrate can't handle sets of parts of a return value register. 3528 3529 We don't use alter_subreg because we only want to eliminate subregs 3530 of hard registers. */ 3531 3532 void 3533 purge_hard_subreg_sets (insn) 3534 rtx insn; 3535 { 3536 for (; insn; insn = NEXT_INSN (insn)) 3537 { 3538 if (INSN_P (insn)) 3539 { 3540 rtx pattern = PATTERN (insn); 3541 switch (GET_CODE (pattern)) 3542 { 3543 case SET: 3544 if (GET_CODE (SET_DEST (pattern)) == SUBREG) 3545 purge_single_hard_subreg_set (pattern); 3546 break; 3547 case PARALLEL: 3548 { 3549 int j; 3550 for (j = XVECLEN (pattern, 0) - 1; j >= 0; j--) 3551 { 3552 rtx inner_pattern = XVECEXP (pattern, 0, j); 3553 if (GET_CODE (inner_pattern) == SET 3554 && GET_CODE (SET_DEST (inner_pattern)) == SUBREG) 3555 purge_single_hard_subreg_set (inner_pattern); 3556 } 3557 } 3558 break; 3559 default: 3560 break; 3561 } 3562 } 3563 } 3564 } 3565 3566 /* Pass through the INSNS of function FNDECL and convert virtual register 3567 references to hard register references. */ 3568 3569 void 3570 instantiate_virtual_regs (fndecl, insns) 3571 tree fndecl; 3572 rtx insns; 3573 { 3574 rtx insn; 3575 unsigned int i; 3576 3577 /* Compute the offsets to use for this function. */ 3578 in_arg_offset = FIRST_PARM_OFFSET (fndecl); 3579 var_offset = STARTING_FRAME_OFFSET; 3580 dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl); 3581 out_arg_offset = STACK_POINTER_OFFSET; 3582 cfa_offset = ARG_POINTER_CFA_OFFSET (fndecl); 3583 3584 /* Scan all variables and parameters of this function. For each that is 3585 in memory, instantiate all virtual registers if the result is a valid 3586 address. If not, we do it later. That will handle most uses of virtual 3587 regs on many machines. */ 3588 instantiate_decls (fndecl, 1); 3589 3590 /* Initialize recognition, indicating that volatile is OK. */ 3591 init_recog (); 3592 3593 /* Scan through all the insns, instantiating every virtual register still 3594 present. */ 3595 for (insn = insns; insn; insn = NEXT_INSN (insn)) 3596 if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN 3597 || GET_CODE (insn) == CALL_INSN) 3598 { 3599 instantiate_virtual_regs_1 (&PATTERN (insn), insn, 1); 3600 instantiate_virtual_regs_1 (®_NOTES (insn), NULL_RTX, 0); 3601 /* Instantiate any virtual registers in CALL_INSN_FUNCTION_USAGE. */ 3602 if (GET_CODE (insn) == CALL_INSN) 3603 instantiate_virtual_regs_1 (&CALL_INSN_FUNCTION_USAGE (insn), 3604 NULL_RTX, 0); 3605 } 3606 3607 /* Instantiate the stack slots for the parm registers, for later use in 3608 addressof elimination. */ 3609 for (i = 0; i < max_parm_reg; ++i) 3610 if (parm_reg_stack_loc[i]) 3611 instantiate_virtual_regs_1 (&parm_reg_stack_loc[i], NULL_RTX, 0); 3612 3613 /* Now instantiate the remaining register equivalences for debugging info. 3614 These will not be valid addresses. */ 3615 instantiate_decls (fndecl, 0); 3616 3617 /* Indicate that, from now on, assign_stack_local should use 3618 frame_pointer_rtx. */ 3619 virtuals_instantiated = 1; 3620 } 3621 3622 /* Scan all decls in FNDECL (both variables and parameters) and instantiate 3623 all virtual registers in their DECL_RTL's. 3624 3625 If VALID_ONLY, do this only if the resulting address is still valid. 3626 Otherwise, always do it. */ 3627 3628 static void 3629 instantiate_decls (fndecl, valid_only) 3630 tree fndecl; 3631 int valid_only; 3632 { 3633 tree decl; 3634 3635 /* Process all parameters of the function. */ 3636 for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl)) 3637 { 3638 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl)); 3639 HOST_WIDE_INT size_rtl; 3640 3641 instantiate_decl (DECL_RTL (decl), size, valid_only); 3642 3643 /* If the parameter was promoted, then the incoming RTL mode may be 3644 larger than the declared type size. We must use the larger of 3645 the two sizes. */ 3646 size_rtl = GET_MODE_SIZE (GET_MODE (DECL_INCOMING_RTL (decl))); 3647 size = MAX (size_rtl, size); 3648 instantiate_decl (DECL_INCOMING_RTL (decl), size, valid_only); 3649 } 3650 3651 /* Now process all variables defined in the function or its subblocks. */ 3652 instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only); 3653 } 3654 3655 /* Subroutine of instantiate_decls: Process all decls in the given 3656 BLOCK node and all its subblocks. */ 3657 3658 static void 3659 instantiate_decls_1 (let, valid_only) 3660 tree let; 3661 int valid_only; 3662 { 3663 tree t; 3664 3665 for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t)) 3666 if (DECL_RTL_SET_P (t)) 3667 instantiate_decl (DECL_RTL (t), 3668 int_size_in_bytes (TREE_TYPE (t)), 3669 valid_only); 3670 3671 /* Process all subblocks. */ 3672 for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t)) 3673 instantiate_decls_1 (t, valid_only); 3674 } 3675 3676 /* Subroutine of the preceding procedures: Given RTL representing a 3677 decl and the size of the object, do any instantiation required. 3678 3679 If VALID_ONLY is non-zero, it means that the RTL should only be 3680 changed if the new address is valid. */ 3681 3682 static void 3683 instantiate_decl (x, size, valid_only) 3684 rtx x; 3685 HOST_WIDE_INT size; 3686 int valid_only; 3687 { 3688 enum machine_mode mode; 3689 rtx addr; 3690 3691 /* If this is not a MEM, no need to do anything. Similarly if the 3692 address is a constant or a register that is not a virtual register. */ 3693 3694 if (x == 0 || GET_CODE (x) != MEM) 3695 return; 3696 3697 addr = XEXP (x, 0); 3698 if (CONSTANT_P (addr) 3699 || (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == REG) 3700 || (GET_CODE (addr) == REG 3701 && (REGNO (addr) < FIRST_VIRTUAL_REGISTER 3702 || REGNO (addr) > LAST_VIRTUAL_REGISTER))) 3703 return; 3704 3705 /* If we should only do this if the address is valid, copy the address. 3706 We need to do this so we can undo any changes that might make the 3707 address invalid. This copy is unfortunate, but probably can't be 3708 avoided. */ 3709 3710 if (valid_only) 3711 addr = copy_rtx (addr); 3712 3713 instantiate_virtual_regs_1 (&addr, NULL_RTX, 0); 3714 3715 if (valid_only && size >= 0) 3716 { 3717 unsigned HOST_WIDE_INT decl_size = size; 3718 3719 /* Now verify that the resulting address is valid for every integer or 3720 floating-point mode up to and including SIZE bytes long. We do this 3721 since the object might be accessed in any mode and frame addresses 3722 are shared. */ 3723 3724 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); 3725 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size; 3726 mode = GET_MODE_WIDER_MODE (mode)) 3727 if (! memory_address_p (mode, addr)) 3728 return; 3729 3730 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); 3731 mode != VOIDmode && GET_MODE_SIZE (mode) <= decl_size; 3732 mode = GET_MODE_WIDER_MODE (mode)) 3733 if (! memory_address_p (mode, addr)) 3734 return; 3735 } 3736 3737 /* Put back the address now that we have updated it and we either know 3738 it is valid or we don't care whether it is valid. */ 3739 3740 XEXP (x, 0) = addr; 3741 } 3742 3743 /* Given a piece of RTX and a pointer to a HOST_WIDE_INT, if the RTX 3744 is a virtual register, return the equivalent hard register and set the 3745 offset indirectly through the pointer. Otherwise, return 0. */ 3746 3747 static rtx 3748 instantiate_new_reg (x, poffset) 3749 rtx x; 3750 HOST_WIDE_INT *poffset; 3751 { 3752 rtx new; 3753 HOST_WIDE_INT offset; 3754 3755 if (x == virtual_incoming_args_rtx) 3756 new = arg_pointer_rtx, offset = in_arg_offset; 3757 else if (x == virtual_stack_vars_rtx) 3758 new = frame_pointer_rtx, offset = var_offset; 3759 else if (x == virtual_stack_dynamic_rtx) 3760 new = stack_pointer_rtx, offset = dynamic_offset; 3761 else if (x == virtual_outgoing_args_rtx) 3762 new = stack_pointer_rtx, offset = out_arg_offset; 3763 else if (x == virtual_cfa_rtx) 3764 new = arg_pointer_rtx, offset = cfa_offset; 3765 else 3766 return 0; 3767 3768 *poffset = offset; 3769 return new; 3770 } 3771 3772 /* Given a pointer to a piece of rtx and an optional pointer to the 3773 containing object, instantiate any virtual registers present in it. 3774 3775 If EXTRA_INSNS, we always do the replacement and generate 3776 any extra insns before OBJECT. If it zero, we do nothing if replacement 3777 is not valid. 3778 3779 Return 1 if we either had nothing to do or if we were able to do the 3780 needed replacement. Return 0 otherwise; we only return zero if 3781 EXTRA_INSNS is zero. 3782 3783 We first try some simple transformations to avoid the creation of extra 3784 pseudos. */ 3785 3786 static int 3787 instantiate_virtual_regs_1 (loc, object, extra_insns) 3788 rtx *loc; 3789 rtx object; 3790 int extra_insns; 3791 { 3792 rtx x; 3793 RTX_CODE code; 3794 rtx new = 0; 3795 HOST_WIDE_INT offset = 0; 3796 rtx temp; 3797 rtx seq; 3798 int i, j; 3799 const char *fmt; 3800 3801 /* Re-start here to avoid recursion in common cases. */ 3802 restart: 3803 3804 x = *loc; 3805 if (x == 0) 3806 return 1; 3807 3808 code = GET_CODE (x); 3809 3810 /* Check for some special cases. */ 3811 switch (code) 3812 { 3813 case CONST_INT: 3814 case CONST_DOUBLE: 3815 case CONST_VECTOR: 3816 case CONST: 3817 case SYMBOL_REF: 3818 case CODE_LABEL: 3819 case PC: 3820 case CC0: 3821 case ASM_INPUT: 3822 case ADDR_VEC: 3823 case ADDR_DIFF_VEC: 3824 case RETURN: 3825 return 1; 3826 3827 case SET: 3828 /* We are allowed to set the virtual registers. This means that 3829 the actual register should receive the source minus the 3830 appropriate offset. This is used, for example, in the handling 3831 of non-local gotos. */ 3832 if ((new = instantiate_new_reg (SET_DEST (x), &offset)) != 0) 3833 { 3834 rtx src = SET_SRC (x); 3835 3836 /* We are setting the register, not using it, so the relevant 3837 offset is the negative of the offset to use were we using 3838 the register. */ 3839 offset = - offset; 3840 instantiate_virtual_regs_1 (&src, NULL_RTX, 0); 3841 3842 /* The only valid sources here are PLUS or REG. Just do 3843 the simplest possible thing to handle them. */ 3844 if (GET_CODE (src) != REG && GET_CODE (src) != PLUS) 3845 abort (); 3846 3847 start_sequence (); 3848 if (GET_CODE (src) != REG) 3849 temp = force_operand (src, NULL_RTX); 3850 else 3851 temp = src; 3852 temp = force_operand (plus_constant (temp, offset), NULL_RTX); 3853 seq = get_insns (); 3854 end_sequence (); 3855 3856 emit_insns_before (seq, object); 3857 SET_DEST (x) = new; 3858 3859 if (! validate_change (object, &SET_SRC (x), temp, 0) 3860 || ! extra_insns) 3861 abort (); 3862 3863 return 1; 3864 } 3865 3866 instantiate_virtual_regs_1 (&SET_DEST (x), object, extra_insns); 3867 loc = &SET_SRC (x); 3868 goto restart; 3869 3870 case PLUS: 3871 /* Handle special case of virtual register plus constant. */ 3872 if (CONSTANT_P (XEXP (x, 1))) 3873 { 3874 rtx old, new_offset; 3875 3876 /* Check for (plus (plus VIRT foo) (const_int)) first. */ 3877 if (GET_CODE (XEXP (x, 0)) == PLUS) 3878 { 3879 if ((new = instantiate_new_reg (XEXP (XEXP (x, 0), 0), &offset))) 3880 { 3881 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object, 3882 extra_insns); 3883 new = gen_rtx_PLUS (Pmode, new, XEXP (XEXP (x, 0), 1)); 3884 } 3885 else 3886 { 3887 loc = &XEXP (x, 0); 3888 goto restart; 3889 } 3890 } 3891 3892 #ifdef POINTERS_EXTEND_UNSIGNED 3893 /* If we have (plus (subreg (virtual-reg)) (const_int)), we know 3894 we can commute the PLUS and SUBREG because pointers into the 3895 frame are well-behaved. */ 3896 else if (GET_CODE (XEXP (x, 0)) == SUBREG && GET_MODE (x) == ptr_mode 3897 && GET_CODE (XEXP (x, 1)) == CONST_INT 3898 && 0 != (new 3899 = instantiate_new_reg (SUBREG_REG (XEXP (x, 0)), 3900 &offset)) 3901 && validate_change (object, loc, 3902 plus_constant (gen_lowpart (ptr_mode, 3903 new), 3904 offset 3905 + INTVAL (XEXP (x, 1))), 3906 0)) 3907 return 1; 3908 #endif 3909 else if ((new = instantiate_new_reg (XEXP (x, 0), &offset)) == 0) 3910 { 3911 /* We know the second operand is a constant. Unless the 3912 first operand is a REG (which has been already checked), 3913 it needs to be checked. */ 3914 if (GET_CODE (XEXP (x, 0)) != REG) 3915 { 3916 loc = &XEXP (x, 0); 3917 goto restart; 3918 } 3919 return 1; 3920 } 3921 3922 new_offset = plus_constant (XEXP (x, 1), offset); 3923 3924 /* If the new constant is zero, try to replace the sum with just 3925 the register. */ 3926 if (new_offset == const0_rtx 3927 && validate_change (object, loc, new, 0)) 3928 return 1; 3929 3930 /* Next try to replace the register and new offset. 3931 There are two changes to validate here and we can't assume that 3932 in the case of old offset equals new just changing the register 3933 will yield a valid insn. In the interests of a little efficiency, 3934 however, we only call validate change once (we don't queue up the 3935 changes and then call apply_change_group). */ 3936 3937 old = XEXP (x, 0); 3938 if (offset == 0 3939 ? ! validate_change (object, &XEXP (x, 0), new, 0) 3940 : (XEXP (x, 0) = new, 3941 ! validate_change (object, &XEXP (x, 1), new_offset, 0))) 3942 { 3943 if (! extra_insns) 3944 { 3945 XEXP (x, 0) = old; 3946 return 0; 3947 } 3948 3949 /* Otherwise copy the new constant into a register and replace 3950 constant with that register. */ 3951 temp = gen_reg_rtx (Pmode); 3952 XEXP (x, 0) = new; 3953 if (validate_change (object, &XEXP (x, 1), temp, 0)) 3954 emit_insn_before (gen_move_insn (temp, new_offset), object); 3955 else 3956 { 3957 /* If that didn't work, replace this expression with a 3958 register containing the sum. */ 3959 3960 XEXP (x, 0) = old; 3961 new = gen_rtx_PLUS (Pmode, new, new_offset); 3962 3963 start_sequence (); 3964 temp = force_operand (new, NULL_RTX); 3965 seq = get_insns (); 3966 end_sequence (); 3967 3968 emit_insns_before (seq, object); 3969 if (! validate_change (object, loc, temp, 0) 3970 && ! validate_replace_rtx (x, temp, object)) 3971 abort (); 3972 } 3973 } 3974 3975 return 1; 3976 } 3977 3978 /* Fall through to generic two-operand expression case. */ 3979 case EXPR_LIST: 3980 case CALL: 3981 case COMPARE: 3982 case MINUS: 3983 case MULT: 3984 case DIV: case UDIV: 3985 case MOD: case UMOD: 3986 case AND: case IOR: case XOR: 3987 case ROTATERT: case ROTATE: 3988 case ASHIFTRT: case LSHIFTRT: case ASHIFT: 3989 case NE: case EQ: 3990 case GE: case GT: case GEU: case GTU: 3991 case LE: case LT: case LEU: case LTU: 3992 if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1))) 3993 instantiate_virtual_regs_1 (&XEXP (x, 1), object, extra_insns); 3994 loc = &XEXP (x, 0); 3995 goto restart; 3996 3997 case MEM: 3998 /* Most cases of MEM that convert to valid addresses have already been 3999 handled by our scan of decls. The only special handling we 4000 need here is to make a copy of the rtx to ensure it isn't being 4001 shared if we have to change it to a pseudo. 4002 4003 If the rtx is a simple reference to an address via a virtual register, 4004 it can potentially be shared. In such cases, first try to make it 4005 a valid address, which can also be shared. Otherwise, copy it and 4006 proceed normally. 4007 4008 First check for common cases that need no processing. These are 4009 usually due to instantiation already being done on a previous instance 4010 of a shared rtx. */ 4011 4012 temp = XEXP (x, 0); 4013 if (CONSTANT_ADDRESS_P (temp) 4014 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4015 || temp == arg_pointer_rtx 4016 #endif 4017 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 4018 || temp == hard_frame_pointer_rtx 4019 #endif 4020 || temp == frame_pointer_rtx) 4021 return 1; 4022 4023 if (GET_CODE (temp) == PLUS 4024 && CONSTANT_ADDRESS_P (XEXP (temp, 1)) 4025 && (XEXP (temp, 0) == frame_pointer_rtx 4026 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 4027 || XEXP (temp, 0) == hard_frame_pointer_rtx 4028 #endif 4029 #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4030 || XEXP (temp, 0) == arg_pointer_rtx 4031 #endif 4032 )) 4033 return 1; 4034 4035 if (temp == virtual_stack_vars_rtx 4036 || temp == virtual_incoming_args_rtx 4037 || (GET_CODE (temp) == PLUS 4038 && CONSTANT_ADDRESS_P (XEXP (temp, 1)) 4039 && (XEXP (temp, 0) == virtual_stack_vars_rtx 4040 || XEXP (temp, 0) == virtual_incoming_args_rtx))) 4041 { 4042 /* This MEM may be shared. If the substitution can be done without 4043 the need to generate new pseudos, we want to do it in place 4044 so all copies of the shared rtx benefit. The call below will 4045 only make substitutions if the resulting address is still 4046 valid. 4047 4048 Note that we cannot pass X as the object in the recursive call 4049 since the insn being processed may not allow all valid 4050 addresses. However, if we were not passed on object, we can 4051 only modify X without copying it if X will have a valid 4052 address. 4053 4054 ??? Also note that this can still lose if OBJECT is an insn that 4055 has less restrictions on an address that some other insn. 4056 In that case, we will modify the shared address. This case 4057 doesn't seem very likely, though. One case where this could 4058 happen is in the case of a USE or CLOBBER reference, but we 4059 take care of that below. */ 4060 4061 if (instantiate_virtual_regs_1 (&XEXP (x, 0), 4062 object ? object : x, 0)) 4063 return 1; 4064 4065 /* Otherwise make a copy and process that copy. We copy the entire 4066 RTL expression since it might be a PLUS which could also be 4067 shared. */ 4068 *loc = x = copy_rtx (x); 4069 } 4070 4071 /* Fall through to generic unary operation case. */ 4072 case PREFETCH: 4073 case SUBREG: 4074 case STRICT_LOW_PART: 4075 case NEG: case NOT: 4076 case PRE_DEC: case PRE_INC: case POST_DEC: case POST_INC: 4077 case SIGN_EXTEND: case ZERO_EXTEND: 4078 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE: 4079 case FLOAT: case FIX: 4080 case UNSIGNED_FIX: case UNSIGNED_FLOAT: 4081 case ABS: 4082 case SQRT: 4083 case FFS: 4084 /* These case either have just one operand or we know that we need not 4085 check the rest of the operands. */ 4086 loc = &XEXP (x, 0); 4087 goto restart; 4088 4089 case USE: 4090 case CLOBBER: 4091 /* If the operand is a MEM, see if the change is a valid MEM. If not, 4092 go ahead and make the invalid one, but do it to a copy. For a REG, 4093 just make the recursive call, since there's no chance of a problem. */ 4094 4095 if ((GET_CODE (XEXP (x, 0)) == MEM 4096 && instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), XEXP (x, 0), 4097 0)) 4098 || (GET_CODE (XEXP (x, 0)) == REG 4099 && instantiate_virtual_regs_1 (&XEXP (x, 0), object, 0))) 4100 return 1; 4101 4102 XEXP (x, 0) = copy_rtx (XEXP (x, 0)); 4103 loc = &XEXP (x, 0); 4104 goto restart; 4105 4106 case REG: 4107 /* Try to replace with a PLUS. If that doesn't work, compute the sum 4108 in front of this insn and substitute the temporary. */ 4109 if ((new = instantiate_new_reg (x, &offset)) != 0) 4110 { 4111 temp = plus_constant (new, offset); 4112 if (!validate_change (object, loc, temp, 0)) 4113 { 4114 if (! extra_insns) 4115 return 0; 4116 4117 start_sequence (); 4118 temp = force_operand (temp, NULL_RTX); 4119 seq = get_insns (); 4120 end_sequence (); 4121 4122 emit_insns_before (seq, object); 4123 if (! validate_change (object, loc, temp, 0) 4124 && ! validate_replace_rtx (x, temp, object)) 4125 abort (); 4126 } 4127 } 4128 4129 return 1; 4130 4131 case ADDRESSOF: 4132 if (GET_CODE (XEXP (x, 0)) == REG) 4133 return 1; 4134 4135 else if (GET_CODE (XEXP (x, 0)) == MEM) 4136 { 4137 /* If we have a (addressof (mem ..)), do any instantiation inside 4138 since we know we'll be making the inside valid when we finally 4139 remove the ADDRESSOF. */ 4140 instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 0), NULL_RTX, 0); 4141 return 1; 4142 } 4143 break; 4144 4145 default: 4146 break; 4147 } 4148 4149 /* Scan all subexpressions. */ 4150 fmt = GET_RTX_FORMAT (code); 4151 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++) 4152 if (*fmt == 'e') 4153 { 4154 if (!instantiate_virtual_regs_1 (&XEXP (x, i), object, extra_insns)) 4155 return 0; 4156 } 4157 else if (*fmt == 'E') 4158 for (j = 0; j < XVECLEN (x, i); j++) 4159 if (! instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object, 4160 extra_insns)) 4161 return 0; 4162 4163 return 1; 4164 } 4165 4166 /* Optimization: assuming this function does not receive nonlocal gotos, 4167 delete the handlers for such, as well as the insns to establish 4168 and disestablish them. */ 4169 4170 static void 4171 delete_handlers () 4172 { 4173 rtx insn; 4174 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 4175 { 4176 /* Delete the handler by turning off the flag that would 4177 prevent jump_optimize from deleting it. 4178 Also permit deletion of the nonlocal labels themselves 4179 if nothing local refers to them. */ 4180 if (GET_CODE (insn) == CODE_LABEL) 4181 { 4182 tree t, last_t; 4183 4184 LABEL_PRESERVE_P (insn) = 0; 4185 4186 /* Remove it from the nonlocal_label list, to avoid confusing 4187 flow. */ 4188 for (t = nonlocal_labels, last_t = 0; t; 4189 last_t = t, t = TREE_CHAIN (t)) 4190 if (DECL_RTL (TREE_VALUE (t)) == insn) 4191 break; 4192 if (t) 4193 { 4194 if (! last_t) 4195 nonlocal_labels = TREE_CHAIN (nonlocal_labels); 4196 else 4197 TREE_CHAIN (last_t) = TREE_CHAIN (t); 4198 } 4199 } 4200 if (GET_CODE (insn) == INSN) 4201 { 4202 int can_delete = 0; 4203 rtx t; 4204 for (t = nonlocal_goto_handler_slots; t != 0; t = XEXP (t, 1)) 4205 if (reg_mentioned_p (t, PATTERN (insn))) 4206 { 4207 can_delete = 1; 4208 break; 4209 } 4210 if (can_delete 4211 || (nonlocal_goto_stack_level != 0 4212 && reg_mentioned_p (nonlocal_goto_stack_level, 4213 PATTERN (insn)))) 4214 delete_related_insns (insn); 4215 } 4216 } 4217 } 4218 4219 int 4220 max_parm_reg_num () 4221 { 4222 return max_parm_reg; 4223 } 4224 4225 /* Return the first insn following those generated by `assign_parms'. */ 4226 4227 rtx 4228 get_first_nonparm_insn () 4229 { 4230 if (last_parm_insn) 4231 return NEXT_INSN (last_parm_insn); 4232 return get_insns (); 4233 } 4234 4235 /* Return the first NOTE_INSN_BLOCK_BEG note in the function. 4236 Crash if there is none. */ 4237 4238 rtx 4239 get_first_block_beg () 4240 { 4241 rtx searcher; 4242 rtx insn = get_first_nonparm_insn (); 4243 4244 for (searcher = insn; searcher; searcher = NEXT_INSN (searcher)) 4245 if (GET_CODE (searcher) == NOTE 4246 && NOTE_LINE_NUMBER (searcher) == NOTE_INSN_BLOCK_BEG) 4247 return searcher; 4248 4249 abort (); /* Invalid call to this function. (See comments above.) */ 4250 return NULL_RTX; 4251 } 4252 4253 /* Return 1 if EXP is an aggregate type (or a value with aggregate type). 4254 This means a type for which function calls must pass an address to the 4255 function or get an address back from the function. 4256 EXP may be a type node or an expression (whose type is tested). */ 4257 4258 int 4259 aggregate_value_p (exp) 4260 tree exp; 4261 { 4262 int i, regno, nregs; 4263 rtx reg; 4264 4265 tree type = (TYPE_P (exp)) ? exp : TREE_TYPE (exp); 4266 4267 if (TREE_CODE (type) == VOID_TYPE) 4268 return 0; 4269 if (RETURN_IN_MEMORY (type)) 4270 return 1; 4271 /* Types that are TREE_ADDRESSABLE must be constructed in memory, 4272 and thus can't be returned in registers. */ 4273 if (TREE_ADDRESSABLE (type)) 4274 return 1; 4275 if (flag_pcc_struct_return && AGGREGATE_TYPE_P (type)) 4276 return 1; 4277 /* Make sure we have suitable call-clobbered regs to return 4278 the value in; if not, we must return it in memory. */ 4279 reg = hard_function_value (type, 0, 0); 4280 4281 /* If we have something other than a REG (e.g. a PARALLEL), then assume 4282 it is OK. */ 4283 if (GET_CODE (reg) != REG) 4284 return 0; 4285 4286 regno = REGNO (reg); 4287 nregs = HARD_REGNO_NREGS (regno, TYPE_MODE (type)); 4288 for (i = 0; i < nregs; i++) 4289 if (! call_used_regs[regno + i]) 4290 return 1; 4291 return 0; 4292 } 4293 4294 /* Assign RTL expressions to the function's parameters. 4295 This may involve copying them into registers and using 4296 those registers as the RTL for them. */ 4297 4298 void 4299 assign_parms (fndecl) 4300 tree fndecl; 4301 { 4302 tree parm; 4303 rtx entry_parm = 0; 4304 rtx stack_parm = 0; 4305 CUMULATIVE_ARGS args_so_far; 4306 enum machine_mode promoted_mode, passed_mode; 4307 enum machine_mode nominal_mode, promoted_nominal_mode; 4308 int unsignedp; 4309 /* Total space needed so far for args on the stack, 4310 given as a constant and a tree-expression. */ 4311 struct args_size stack_args_size; 4312 tree fntype = TREE_TYPE (fndecl); 4313 tree fnargs = DECL_ARGUMENTS (fndecl); 4314 /* This is used for the arg pointer when referring to stack args. */ 4315 rtx internal_arg_pointer; 4316 /* This is a dummy PARM_DECL that we used for the function result if 4317 the function returns a structure. */ 4318 tree function_result_decl = 0; 4319 #ifdef SETUP_INCOMING_VARARGS 4320 int varargs_setup = 0; 4321 #endif 4322 rtx conversion_insns = 0; 4323 struct args_size alignment_pad; 4324 4325 /* Nonzero if the last arg is named `__builtin_va_alist', 4326 which is used on some machines for old-fashioned non-ANSI varargs.h; 4327 this should be stuck onto the stack as if it had arrived there. */ 4328 int hide_last_arg 4329 = (current_function_varargs 4330 && fnargs 4331 && (parm = tree_last (fnargs)) != 0 4332 && DECL_NAME (parm) 4333 && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), 4334 "__builtin_va_alist"))); 4335 4336 /* Nonzero if function takes extra anonymous args. 4337 This means the last named arg must be on the stack 4338 right before the anonymous ones. */ 4339 int stdarg 4340 = (TYPE_ARG_TYPES (fntype) != 0 4341 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) 4342 != void_type_node)); 4343 4344 current_function_stdarg = stdarg; 4345 4346 /* If the reg that the virtual arg pointer will be translated into is 4347 not a fixed reg or is the stack pointer, make a copy of the virtual 4348 arg pointer, and address parms via the copy. The frame pointer is 4349 considered fixed even though it is not marked as such. 4350 4351 The second time through, simply use ap to avoid generating rtx. */ 4352 4353 if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM 4354 || ! (fixed_regs[ARG_POINTER_REGNUM] 4355 || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))) 4356 internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx); 4357 else 4358 internal_arg_pointer = virtual_incoming_args_rtx; 4359 current_function_internal_arg_pointer = internal_arg_pointer; 4360 4361 stack_args_size.constant = 0; 4362 stack_args_size.var = 0; 4363 4364 /* If struct value address is treated as the first argument, make it so. */ 4365 if (aggregate_value_p (DECL_RESULT (fndecl)) 4366 && ! current_function_returns_pcc_struct 4367 && struct_value_incoming_rtx == 0) 4368 { 4369 tree type = build_pointer_type (TREE_TYPE (fntype)); 4370 4371 function_result_decl = build_decl (PARM_DECL, NULL_TREE, type); 4372 4373 DECL_ARG_TYPE (function_result_decl) = type; 4374 TREE_CHAIN (function_result_decl) = fnargs; 4375 fnargs = function_result_decl; 4376 } 4377 4378 max_parm_reg = LAST_VIRTUAL_REGISTER + 1; 4379 parm_reg_stack_loc = (rtx *) xcalloc (max_parm_reg, sizeof (rtx)); 4380 4381 #ifdef INIT_CUMULATIVE_INCOMING_ARGS 4382 INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, NULL_RTX); 4383 #else 4384 INIT_CUMULATIVE_ARGS (args_so_far, fntype, NULL_RTX, 0); 4385 #endif 4386 4387 /* We haven't yet found an argument that we must push and pretend the 4388 caller did. */ 4389 current_function_pretend_args_size = 0; 4390 4391 for (parm = fnargs; parm; parm = TREE_CHAIN (parm)) 4392 { 4393 struct args_size stack_offset; 4394 struct args_size arg_size; 4395 int passed_pointer = 0; 4396 int did_conversion = 0; 4397 tree passed_type = DECL_ARG_TYPE (parm); 4398 tree nominal_type = TREE_TYPE (parm); 4399 int pretend_named; 4400 int last_named = 0, named_arg; 4401 4402 /* Set LAST_NAMED if this is last named arg before last 4403 anonymous args. */ 4404 if (stdarg || current_function_varargs) 4405 { 4406 tree tem; 4407 4408 for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem)) 4409 if (DECL_NAME (tem)) 4410 break; 4411 4412 if (tem == 0) 4413 last_named = 1; 4414 } 4415 /* Set NAMED_ARG if this arg should be treated as a named arg. For 4416 most machines, if this is a varargs/stdarg function, then we treat 4417 the last named arg as if it were anonymous too. */ 4418 named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named; 4419 4420 if (TREE_TYPE (parm) == error_mark_node 4421 /* This can happen after weird syntax errors 4422 or if an enum type is defined among the parms. */ 4423 || TREE_CODE (parm) != PARM_DECL 4424 || passed_type == NULL) 4425 { 4426 SET_DECL_RTL (parm, gen_rtx_MEM (BLKmode, const0_rtx)); 4427 DECL_INCOMING_RTL (parm) = DECL_RTL (parm); 4428 TREE_USED (parm) = 1; 4429 continue; 4430 } 4431 4432 /* For varargs.h function, save info about regs and stack space 4433 used by the individual args, not including the va_alist arg. */ 4434 if (hide_last_arg && last_named) 4435 current_function_args_info = args_so_far; 4436 4437 /* Find mode of arg as it is passed, and mode of arg 4438 as it should be during execution of this function. */ 4439 passed_mode = TYPE_MODE (passed_type); 4440 nominal_mode = TYPE_MODE (nominal_type); 4441 4442 /* If the parm's mode is VOID, its value doesn't matter, 4443 and avoid the usual things like emit_move_insn that could crash. */ 4444 if (nominal_mode == VOIDmode) 4445 { 4446 SET_DECL_RTL (parm, const0_rtx); 4447 DECL_INCOMING_RTL (parm) = DECL_RTL (parm); 4448 continue; 4449 } 4450 4451 /* If the parm is to be passed as a transparent union, use the 4452 type of the first field for the tests below. We have already 4453 verified that the modes are the same. */ 4454 if (DECL_TRANSPARENT_UNION (parm) 4455 || (TREE_CODE (passed_type) == UNION_TYPE 4456 && TYPE_TRANSPARENT_UNION (passed_type))) 4457 passed_type = TREE_TYPE (TYPE_FIELDS (passed_type)); 4458 4459 /* See if this arg was passed by invisible reference. It is if 4460 it is an object whose size depends on the contents of the 4461 object itself or if the machine requires these objects be passed 4462 that way. */ 4463 4464 if ((TREE_CODE (TYPE_SIZE (passed_type)) != INTEGER_CST 4465 && contains_placeholder_p (TYPE_SIZE (passed_type))) 4466 || TREE_ADDRESSABLE (passed_type) 4467 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE 4468 || FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode, 4469 passed_type, named_arg) 4470 #endif 4471 ) 4472 { 4473 passed_type = nominal_type = build_pointer_type (passed_type); 4474 passed_pointer = 1; 4475 passed_mode = nominal_mode = Pmode; 4476 } 4477 4478 promoted_mode = passed_mode; 4479 4480 #ifdef PROMOTE_FUNCTION_ARGS 4481 /* Compute the mode in which the arg is actually extended to. */ 4482 unsignedp = TREE_UNSIGNED (passed_type); 4483 promoted_mode = promote_mode (passed_type, promoted_mode, &unsignedp, 1); 4484 #endif 4485 4486 /* Let machine desc say which reg (if any) the parm arrives in. 4487 0 means it arrives on the stack. */ 4488 #ifdef FUNCTION_INCOMING_ARG 4489 entry_parm = FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, 4490 passed_type, named_arg); 4491 #else 4492 entry_parm = FUNCTION_ARG (args_so_far, promoted_mode, 4493 passed_type, named_arg); 4494 #endif 4495 4496 if (entry_parm == 0) 4497 promoted_mode = passed_mode; 4498 4499 #ifdef SETUP_INCOMING_VARARGS 4500 /* If this is the last named parameter, do any required setup for 4501 varargs or stdargs. We need to know about the case of this being an 4502 addressable type, in which case we skip the registers it 4503 would have arrived in. 4504 4505 For stdargs, LAST_NAMED will be set for two parameters, the one that 4506 is actually the last named, and the dummy parameter. We only 4507 want to do this action once. 4508 4509 Also, indicate when RTL generation is to be suppressed. */ 4510 if (last_named && !varargs_setup) 4511 { 4512 SETUP_INCOMING_VARARGS (args_so_far, promoted_mode, passed_type, 4513 current_function_pretend_args_size, 0); 4514 varargs_setup = 1; 4515 } 4516 #endif 4517 4518 /* Determine parm's home in the stack, 4519 in case it arrives in the stack or we should pretend it did. 4520 4521 Compute the stack position and rtx where the argument arrives 4522 and its size. 4523 4524 There is one complexity here: If this was a parameter that would 4525 have been passed in registers, but wasn't only because it is 4526 __builtin_va_alist, we want locate_and_pad_parm to treat it as if 4527 it came in a register so that REG_PARM_STACK_SPACE isn't skipped. 4528 In this case, we call FUNCTION_ARG with NAMED set to 1 instead of 4529 0 as it was the previous time. */ 4530 4531 pretend_named = named_arg || PRETEND_OUTGOING_VARARGS_NAMED; 4532 locate_and_pad_parm (promoted_mode, passed_type, 4533 #ifdef STACK_PARMS_IN_REG_PARM_AREA 4534 1, 4535 #else 4536 #ifdef FUNCTION_INCOMING_ARG 4537 FUNCTION_INCOMING_ARG (args_so_far, promoted_mode, 4538 passed_type, 4539 pretend_named) != 0, 4540 #else 4541 FUNCTION_ARG (args_so_far, promoted_mode, 4542 passed_type, 4543 pretend_named) != 0, 4544 #endif 4545 #endif 4546 fndecl, &stack_args_size, &stack_offset, &arg_size, 4547 &alignment_pad); 4548 4549 { 4550 rtx offset_rtx = ARGS_SIZE_RTX (stack_offset); 4551 4552 if (offset_rtx == const0_rtx) 4553 stack_parm = gen_rtx_MEM (promoted_mode, internal_arg_pointer); 4554 else 4555 stack_parm = gen_rtx_MEM (promoted_mode, 4556 gen_rtx_PLUS (Pmode, 4557 internal_arg_pointer, 4558 offset_rtx)); 4559 4560 set_mem_attributes (stack_parm, parm, 1); 4561 } 4562 4563 /* If this parameter was passed both in registers and in the stack, 4564 use the copy on the stack. */ 4565 if (MUST_PASS_IN_STACK (promoted_mode, passed_type)) 4566 entry_parm = 0; 4567 4568 #ifdef FUNCTION_ARG_PARTIAL_NREGS 4569 /* If this parm was passed part in regs and part in memory, 4570 pretend it arrived entirely in memory 4571 by pushing the register-part onto the stack. 4572 4573 In the special case of a DImode or DFmode that is split, 4574 we could put it together in a pseudoreg directly, 4575 but for now that's not worth bothering with. */ 4576 4577 if (entry_parm) 4578 { 4579 int nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, promoted_mode, 4580 passed_type, named_arg); 4581 4582 if (nregs > 0) 4583 { 4584 current_function_pretend_args_size 4585 = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1) 4586 / (PARM_BOUNDARY / BITS_PER_UNIT) 4587 * (PARM_BOUNDARY / BITS_PER_UNIT)); 4588 4589 /* Handle calls that pass values in multiple non-contiguous 4590 locations. The Irix 6 ABI has examples of this. */ 4591 if (GET_CODE (entry_parm) == PARALLEL) 4592 emit_group_store (validize_mem (stack_parm), entry_parm, 4593 int_size_in_bytes (TREE_TYPE (parm))); 4594 4595 else 4596 move_block_from_reg (REGNO (entry_parm), 4597 validize_mem (stack_parm), nregs, 4598 int_size_in_bytes (TREE_TYPE (parm))); 4599 4600 entry_parm = stack_parm; 4601 } 4602 } 4603 #endif 4604 4605 /* If we didn't decide this parm came in a register, 4606 by default it came on the stack. */ 4607 if (entry_parm == 0) 4608 entry_parm = stack_parm; 4609 4610 /* Record permanently how this parm was passed. */ 4611 DECL_INCOMING_RTL (parm) = entry_parm; 4612 4613 /* If there is actually space on the stack for this parm, 4614 count it in stack_args_size; otherwise set stack_parm to 0 4615 to indicate there is no preallocated stack slot for the parm. */ 4616 4617 if (entry_parm == stack_parm 4618 || (GET_CODE (entry_parm) == PARALLEL 4619 && XEXP (XVECEXP (entry_parm, 0, 0), 0) == NULL_RTX) 4620 #if defined (REG_PARM_STACK_SPACE) && ! defined (MAYBE_REG_PARM_STACK_SPACE) 4621 /* On some machines, even if a parm value arrives in a register 4622 there is still an (uninitialized) stack slot allocated for it. 4623 4624 ??? When MAYBE_REG_PARM_STACK_SPACE is defined, we can't tell 4625 whether this parameter already has a stack slot allocated, 4626 because an arg block exists only if current_function_args_size 4627 is larger than some threshold, and we haven't calculated that 4628 yet. So, for now, we just assume that stack slots never exist 4629 in this case. */ 4630 || REG_PARM_STACK_SPACE (fndecl) > 0 4631 #endif 4632 ) 4633 { 4634 stack_args_size.constant += arg_size.constant; 4635 if (arg_size.var) 4636 ADD_PARM_SIZE (stack_args_size, arg_size.var); 4637 } 4638 else 4639 /* No stack slot was pushed for this parm. */ 4640 stack_parm = 0; 4641 4642 /* Update info on where next arg arrives in registers. */ 4643 4644 FUNCTION_ARG_ADVANCE (args_so_far, promoted_mode, 4645 passed_type, named_arg); 4646 4647 /* If we can't trust the parm stack slot to be aligned enough 4648 for its ultimate type, don't use that slot after entry. 4649 We'll make another stack slot, if we need one. */ 4650 { 4651 unsigned int thisparm_boundary 4652 = FUNCTION_ARG_BOUNDARY (promoted_mode, passed_type); 4653 4654 if (GET_MODE_ALIGNMENT (nominal_mode) > thisparm_boundary) 4655 stack_parm = 0; 4656 } 4657 4658 /* If parm was passed in memory, and we need to convert it on entry, 4659 don't store it back in that same slot. */ 4660 if (entry_parm != 0 4661 && nominal_mode != BLKmode && nominal_mode != passed_mode) 4662 stack_parm = 0; 4663 4664 /* When an argument is passed in multiple locations, we can't 4665 make use of this information, but we can save some copying if 4666 the whole argument is passed in a single register. */ 4667 if (GET_CODE (entry_parm) == PARALLEL 4668 && nominal_mode != BLKmode && passed_mode != BLKmode) 4669 { 4670 int i, len = XVECLEN (entry_parm, 0); 4671 4672 for (i = 0; i < len; i++) 4673 if (XEXP (XVECEXP (entry_parm, 0, i), 0) != NULL_RTX 4674 && GET_CODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) == REG 4675 && (GET_MODE (XEXP (XVECEXP (entry_parm, 0, i), 0)) 4676 == passed_mode) 4677 && INTVAL (XEXP (XVECEXP (entry_parm, 0, i), 1)) == 0) 4678 { 4679 entry_parm = XEXP (XVECEXP (entry_parm, 0, i), 0); 4680 DECL_INCOMING_RTL (parm) = entry_parm; 4681 break; 4682 } 4683 } 4684 4685 /* ENTRY_PARM is an RTX for the parameter as it arrives, 4686 in the mode in which it arrives. 4687 STACK_PARM is an RTX for a stack slot where the parameter can live 4688 during the function (in case we want to put it there). 4689 STACK_PARM is 0 if no stack slot was pushed for it. 4690 4691 Now output code if necessary to convert ENTRY_PARM to 4692 the type in which this function declares it, 4693 and store that result in an appropriate place, 4694 which may be a pseudo reg, may be STACK_PARM, 4695 or may be a local stack slot if STACK_PARM is 0. 4696 4697 Set DECL_RTL to that place. */ 4698 4699 if (nominal_mode == BLKmode || GET_CODE (entry_parm) == PARALLEL) 4700 { 4701 /* If a BLKmode arrives in registers, copy it to a stack slot. 4702 Handle calls that pass values in multiple non-contiguous 4703 locations. The Irix 6 ABI has examples of this. */ 4704 if (GET_CODE (entry_parm) == REG 4705 || GET_CODE (entry_parm) == PARALLEL) 4706 { 4707 int size_stored 4708 = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)), 4709 UNITS_PER_WORD); 4710 4711 /* Note that we will be storing an integral number of words. 4712 So we have to be careful to ensure that we allocate an 4713 integral number of words. We do this below in the 4714 assign_stack_local if space was not allocated in the argument 4715 list. If it was, this will not work if PARM_BOUNDARY is not 4716 a multiple of BITS_PER_WORD. It isn't clear how to fix this 4717 if it becomes a problem. */ 4718 4719 if (stack_parm == 0) 4720 { 4721 stack_parm 4722 = assign_stack_local (GET_MODE (entry_parm), 4723 size_stored, 0); 4724 set_mem_attributes (stack_parm, parm, 1); 4725 } 4726 4727 else if (PARM_BOUNDARY % BITS_PER_WORD != 0) 4728 abort (); 4729 4730 /* Handle calls that pass values in multiple non-contiguous 4731 locations. The Irix 6 ABI has examples of this. */ 4732 if (GET_CODE (entry_parm) == PARALLEL) 4733 emit_group_store (validize_mem (stack_parm), entry_parm, 4734 int_size_in_bytes (TREE_TYPE (parm))); 4735 else 4736 move_block_from_reg (REGNO (entry_parm), 4737 validize_mem (stack_parm), 4738 size_stored / UNITS_PER_WORD, 4739 int_size_in_bytes (TREE_TYPE (parm))); 4740 } 4741 SET_DECL_RTL (parm, stack_parm); 4742 } 4743 else if (! ((! optimize 4744 && ! DECL_REGISTER (parm)) 4745 || TREE_SIDE_EFFECTS (parm) 4746 /* If -ffloat-store specified, don't put explicit 4747 float variables into registers. */ 4748 || (flag_float_store 4749 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)) 4750 /* Always assign pseudo to structure return or item passed 4751 by invisible reference. */ 4752 || passed_pointer || parm == function_result_decl) 4753 { 4754 /* Store the parm in a pseudoregister during the function, but we 4755 may need to do it in a wider mode. */ 4756 4757 rtx parmreg; 4758 unsigned int regno, regnoi = 0, regnor = 0; 4759 4760 unsignedp = TREE_UNSIGNED (TREE_TYPE (parm)); 4761 4762 promoted_nominal_mode 4763 = promote_mode (TREE_TYPE (parm), nominal_mode, &unsignedp, 0); 4764 4765 parmreg = gen_reg_rtx (promoted_nominal_mode); 4766 mark_user_reg (parmreg); 4767 4768 /* If this was an item that we received a pointer to, set DECL_RTL 4769 appropriately. */ 4770 if (passed_pointer) 4771 { 4772 rtx x = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (passed_type)), 4773 parmreg); 4774 set_mem_attributes (x, parm, 1); 4775 SET_DECL_RTL (parm, x); 4776 } 4777 else 4778 { 4779 SET_DECL_RTL (parm, parmreg); 4780 maybe_set_unchanging (DECL_RTL (parm), parm); 4781 } 4782 4783 /* Copy the value into the register. */ 4784 if (nominal_mode != passed_mode 4785 || promoted_nominal_mode != promoted_mode) 4786 { 4787 int save_tree_used; 4788 /* ENTRY_PARM has been converted to PROMOTED_MODE, its 4789 mode, by the caller. We now have to convert it to 4790 NOMINAL_MODE, if different. However, PARMREG may be in 4791 a different mode than NOMINAL_MODE if it is being stored 4792 promoted. 4793 4794 If ENTRY_PARM is a hard register, it might be in a register 4795 not valid for operating in its mode (e.g., an odd-numbered 4796 register for a DFmode). In that case, moves are the only 4797 thing valid, so we can't do a convert from there. This 4798 occurs when the calling sequence allow such misaligned 4799 usages. 4800 4801 In addition, the conversion may involve a call, which could 4802 clobber parameters which haven't been copied to pseudo 4803 registers yet. Therefore, we must first copy the parm to 4804 a pseudo reg here, and save the conversion until after all 4805 parameters have been moved. */ 4806 4807 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); 4808 4809 emit_move_insn (tempreg, validize_mem (entry_parm)); 4810 4811 push_to_sequence (conversion_insns); 4812 tempreg = convert_to_mode (nominal_mode, tempreg, unsignedp); 4813 4814 if (GET_CODE (tempreg) == SUBREG 4815 && GET_MODE (tempreg) == nominal_mode 4816 && GET_CODE (SUBREG_REG (tempreg)) == REG 4817 && nominal_mode == passed_mode 4818 && GET_MODE (SUBREG_REG (tempreg)) == GET_MODE (entry_parm) 4819 && GET_MODE_SIZE (GET_MODE (tempreg)) 4820 < GET_MODE_SIZE (GET_MODE (entry_parm))) 4821 { 4822 /* The argument is already sign/zero extended, so note it 4823 into the subreg. */ 4824 SUBREG_PROMOTED_VAR_P (tempreg) = 1; 4825 SUBREG_PROMOTED_UNSIGNED_P (tempreg) = unsignedp; 4826 } 4827 4828 /* TREE_USED gets set erroneously during expand_assignment. */ 4829 save_tree_used = TREE_USED (parm); 4830 expand_assignment (parm, 4831 make_tree (nominal_type, tempreg), 0, 0); 4832 TREE_USED (parm) = save_tree_used; 4833 conversion_insns = get_insns (); 4834 did_conversion = 1; 4835 end_sequence (); 4836 } 4837 else 4838 emit_move_insn (parmreg, validize_mem (entry_parm)); 4839 4840 /* If we were passed a pointer but the actual value 4841 can safely live in a register, put it in one. */ 4842 if (passed_pointer && TYPE_MODE (TREE_TYPE (parm)) != BLKmode 4843 /* If by-reference argument was promoted, demote it. */ 4844 && (TYPE_MODE (TREE_TYPE (parm)) != GET_MODE (DECL_RTL (parm)) 4845 || ! ((! optimize 4846 && ! DECL_REGISTER (parm)) 4847 || TREE_SIDE_EFFECTS (parm) 4848 /* If -ffloat-store specified, don't put explicit 4849 float variables into registers. */ 4850 || (flag_float_store 4851 && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))) 4852 { 4853 /* We can't use nominal_mode, because it will have been set to 4854 Pmode above. We must use the actual mode of the parm. */ 4855 parmreg = gen_reg_rtx (TYPE_MODE (TREE_TYPE (parm))); 4856 mark_user_reg (parmreg); 4857 if (GET_MODE (parmreg) != GET_MODE (DECL_RTL (parm))) 4858 { 4859 rtx tempreg = gen_reg_rtx (GET_MODE (DECL_RTL (parm))); 4860 int unsigned_p = TREE_UNSIGNED (TREE_TYPE (parm)); 4861 push_to_sequence (conversion_insns); 4862 emit_move_insn (tempreg, DECL_RTL (parm)); 4863 SET_DECL_RTL (parm, 4864 convert_to_mode (GET_MODE (parmreg), 4865 tempreg, 4866 unsigned_p)); 4867 emit_move_insn (parmreg, DECL_RTL (parm)); 4868 conversion_insns = get_insns(); 4869 did_conversion = 1; 4870 end_sequence (); 4871 } 4872 else 4873 emit_move_insn (parmreg, DECL_RTL (parm)); 4874 SET_DECL_RTL (parm, parmreg); 4875 /* STACK_PARM is the pointer, not the parm, and PARMREG is 4876 now the parm. */ 4877 stack_parm = 0; 4878 } 4879 #ifdef FUNCTION_ARG_CALLEE_COPIES 4880 /* If we are passed an arg by reference and it is our responsibility 4881 to make a copy, do it now. 4882 PASSED_TYPE and PASSED mode now refer to the pointer, not the 4883 original argument, so we must recreate them in the call to 4884 FUNCTION_ARG_CALLEE_COPIES. */ 4885 /* ??? Later add code to handle the case that if the argument isn't 4886 modified, don't do the copy. */ 4887 4888 else if (passed_pointer 4889 && FUNCTION_ARG_CALLEE_COPIES (args_so_far, 4890 TYPE_MODE (DECL_ARG_TYPE (parm)), 4891 DECL_ARG_TYPE (parm), 4892 named_arg) 4893 && ! TREE_ADDRESSABLE (DECL_ARG_TYPE (parm))) 4894 { 4895 rtx copy; 4896 tree type = DECL_ARG_TYPE (parm); 4897 4898 /* This sequence may involve a library call perhaps clobbering 4899 registers that haven't been copied to pseudos yet. */ 4900 4901 push_to_sequence (conversion_insns); 4902 4903 if (!COMPLETE_TYPE_P (type) 4904 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) 4905 /* This is a variable sized object. */ 4906 copy = gen_rtx_MEM (BLKmode, 4907 allocate_dynamic_stack_space 4908 (expr_size (parm), NULL_RTX, 4909 TYPE_ALIGN (type))); 4910 else 4911 copy = assign_stack_temp (TYPE_MODE (type), 4912 int_size_in_bytes (type), 1); 4913 set_mem_attributes (copy, parm, 1); 4914 4915 store_expr (parm, copy, 0); 4916 emit_move_insn (parmreg, XEXP (copy, 0)); 4917 conversion_insns = get_insns (); 4918 did_conversion = 1; 4919 end_sequence (); 4920 } 4921 #endif /* FUNCTION_ARG_CALLEE_COPIES */ 4922 4923 /* In any case, record the parm's desired stack location 4924 in case we later discover it must live in the stack. 4925 4926 If it is a COMPLEX value, store the stack location for both 4927 halves. */ 4928 4929 if (GET_CODE (parmreg) == CONCAT) 4930 regno = MAX (REGNO (XEXP (parmreg, 0)), REGNO (XEXP (parmreg, 1))); 4931 else 4932 regno = REGNO (parmreg); 4933 4934 if (regno >= max_parm_reg) 4935 { 4936 rtx *new; 4937 int old_max_parm_reg = max_parm_reg; 4938 4939 /* It's slow to expand this one register at a time, 4940 but it's also rare and we need max_parm_reg to be 4941 precisely correct. */ 4942 max_parm_reg = regno + 1; 4943 new = (rtx *) xrealloc (parm_reg_stack_loc, 4944 max_parm_reg * sizeof (rtx)); 4945 memset ((char *) (new + old_max_parm_reg), 0, 4946 (max_parm_reg - old_max_parm_reg) * sizeof (rtx)); 4947 parm_reg_stack_loc = new; 4948 } 4949 4950 if (GET_CODE (parmreg) == CONCAT) 4951 { 4952 enum machine_mode submode = GET_MODE (XEXP (parmreg, 0)); 4953 4954 regnor = REGNO (gen_realpart (submode, parmreg)); 4955 regnoi = REGNO (gen_imagpart (submode, parmreg)); 4956 4957 if (stack_parm != 0) 4958 { 4959 parm_reg_stack_loc[regnor] 4960 = gen_realpart (submode, stack_parm); 4961 parm_reg_stack_loc[regnoi] 4962 = gen_imagpart (submode, stack_parm); 4963 } 4964 else 4965 { 4966 parm_reg_stack_loc[regnor] = 0; 4967 parm_reg_stack_loc[regnoi] = 0; 4968 } 4969 } 4970 else 4971 parm_reg_stack_loc[REGNO (parmreg)] = stack_parm; 4972 4973 /* Mark the register as eliminable if we did no conversion 4974 and it was copied from memory at a fixed offset, 4975 and the arg pointer was not copied to a pseudo-reg. 4976 If the arg pointer is a pseudo reg or the offset formed 4977 an invalid address, such memory-equivalences 4978 as we make here would screw up life analysis for it. */ 4979 if (nominal_mode == passed_mode 4980 && ! did_conversion 4981 && stack_parm != 0 4982 && GET_CODE (stack_parm) == MEM 4983 && stack_offset.var == 0 4984 && reg_mentioned_p (virtual_incoming_args_rtx, 4985 XEXP (stack_parm, 0))) 4986 { 4987 rtx linsn = get_last_insn (); 4988 rtx sinsn, set; 4989 4990 /* Mark complex types separately. */ 4991 if (GET_CODE (parmreg) == CONCAT) 4992 /* Scan backwards for the set of the real and 4993 imaginary parts. */ 4994 for (sinsn = linsn; sinsn != 0; 4995 sinsn = prev_nonnote_insn (sinsn)) 4996 { 4997 set = single_set (sinsn); 4998 if (set != 0 4999 && SET_DEST (set) == regno_reg_rtx [regnoi]) 5000 REG_NOTES (sinsn) 5001 = gen_rtx_EXPR_LIST (REG_EQUIV, 5002 parm_reg_stack_loc[regnoi], 5003 REG_NOTES (sinsn)); 5004 else if (set != 0 5005 && SET_DEST (set) == regno_reg_rtx [regnor]) 5006 REG_NOTES (sinsn) 5007 = gen_rtx_EXPR_LIST (REG_EQUIV, 5008 parm_reg_stack_loc[regnor], 5009 REG_NOTES (sinsn)); 5010 } 5011 else if ((set = single_set (linsn)) != 0 5012 && SET_DEST (set) == parmreg) 5013 REG_NOTES (linsn) 5014 = gen_rtx_EXPR_LIST (REG_EQUIV, 5015 stack_parm, REG_NOTES (linsn)); 5016 } 5017 5018 /* For pointer data type, suggest pointer register. */ 5019 if (POINTER_TYPE_P (TREE_TYPE (parm))) 5020 mark_reg_pointer (parmreg, 5021 TYPE_ALIGN (TREE_TYPE (TREE_TYPE (parm)))); 5022 5023 /* If something wants our address, try to use ADDRESSOF. */ 5024 if (TREE_ADDRESSABLE (parm)) 5025 { 5026 /* If we end up putting something into the stack, 5027 fixup_var_refs_insns will need to make a pass over 5028 all the instructions. It looks through the pending 5029 sequences -- but it can't see the ones in the 5030 CONVERSION_INSNS, if they're not on the sequence 5031 stack. So, we go back to that sequence, just so that 5032 the fixups will happen. */ 5033 push_to_sequence (conversion_insns); 5034 put_var_into_stack (parm); 5035 conversion_insns = get_insns (); 5036 end_sequence (); 5037 } 5038 } 5039 else 5040 { 5041 /* Value must be stored in the stack slot STACK_PARM 5042 during function execution. */ 5043 5044 if (promoted_mode != nominal_mode) 5045 { 5046 /* Conversion is required. */ 5047 rtx tempreg = gen_reg_rtx (GET_MODE (entry_parm)); 5048 5049 emit_move_insn (tempreg, validize_mem (entry_parm)); 5050 5051 push_to_sequence (conversion_insns); 5052 entry_parm = convert_to_mode (nominal_mode, tempreg, 5053 TREE_UNSIGNED (TREE_TYPE (parm))); 5054 if (stack_parm) 5055 /* ??? This may need a big-endian conversion on sparc64. */ 5056 stack_parm = adjust_address (stack_parm, nominal_mode, 0); 5057 5058 conversion_insns = get_insns (); 5059 did_conversion = 1; 5060 end_sequence (); 5061 } 5062 5063 if (entry_parm != stack_parm) 5064 { 5065 if (stack_parm == 0) 5066 { 5067 stack_parm 5068 = assign_stack_local (GET_MODE (entry_parm), 5069 GET_MODE_SIZE (GET_MODE (entry_parm)), 0); 5070 set_mem_attributes (stack_parm, parm, 1); 5071 } 5072 5073 if (promoted_mode != nominal_mode) 5074 { 5075 push_to_sequence (conversion_insns); 5076 emit_move_insn (validize_mem (stack_parm), 5077 validize_mem (entry_parm)); 5078 conversion_insns = get_insns (); 5079 end_sequence (); 5080 } 5081 else 5082 emit_move_insn (validize_mem (stack_parm), 5083 validize_mem (entry_parm)); 5084 } 5085 5086 SET_DECL_RTL (parm, stack_parm); 5087 } 5088 5089 /* If this "parameter" was the place where we are receiving the 5090 function's incoming structure pointer, set up the result. */ 5091 if (parm == function_result_decl) 5092 { 5093 tree result = DECL_RESULT (fndecl); 5094 rtx addr = DECL_RTL (parm); 5095 rtx x; 5096 5097 #ifdef POINTERS_EXTEND_UNSIGNED 5098 if (GET_MODE (addr) != Pmode) 5099 addr = convert_memory_address (Pmode, addr); 5100 #endif 5101 5102 x = gen_rtx_MEM (DECL_MODE (result), addr); 5103 set_mem_attributes (x, result, 1); 5104 SET_DECL_RTL (result, x); 5105 } 5106 5107 if (GET_CODE (DECL_RTL (parm)) == REG) 5108 REGNO_DECL (REGNO (DECL_RTL (parm))) = parm; 5109 else if (GET_CODE (DECL_RTL (parm)) == CONCAT) 5110 { 5111 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 0))) = parm; 5112 REGNO_DECL (REGNO (XEXP (DECL_RTL (parm), 1))) = parm; 5113 } 5114 5115 } 5116 5117 /* Output all parameter conversion instructions (possibly including calls) 5118 now that all parameters have been copied out of hard registers. */ 5119 emit_insns (conversion_insns); 5120 5121 last_parm_insn = get_last_insn (); 5122 5123 current_function_args_size = stack_args_size.constant; 5124 5125 /* Adjust function incoming argument size for alignment and 5126 minimum length. */ 5127 5128 #ifdef REG_PARM_STACK_SPACE 5129 #ifndef MAYBE_REG_PARM_STACK_SPACE 5130 current_function_args_size = MAX (current_function_args_size, 5131 REG_PARM_STACK_SPACE (fndecl)); 5132 #endif 5133 #endif 5134 5135 #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT) 5136 5137 current_function_args_size 5138 = ((current_function_args_size + STACK_BYTES - 1) 5139 / STACK_BYTES) * STACK_BYTES; 5140 5141 #ifdef ARGS_GROW_DOWNWARD 5142 current_function_arg_offset_rtx 5143 = (stack_args_size.var == 0 ? GEN_INT (-stack_args_size.constant) 5144 : expand_expr (size_diffop (stack_args_size.var, 5145 size_int (-stack_args_size.constant)), 5146 NULL_RTX, VOIDmode, 0)); 5147 #else 5148 current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size); 5149 #endif 5150 5151 /* See how many bytes, if any, of its args a function should try to pop 5152 on return. */ 5153 5154 current_function_pops_args = RETURN_POPS_ARGS (fndecl, TREE_TYPE (fndecl), 5155 current_function_args_size); 5156 5157 /* For stdarg.h function, save info about 5158 regs and stack space used by the named args. */ 5159 5160 if (!hide_last_arg) 5161 current_function_args_info = args_so_far; 5162 5163 /* Set the rtx used for the function return value. Put this in its 5164 own variable so any optimizers that need this information don't have 5165 to include tree.h. Do this here so it gets done when an inlined 5166 function gets output. */ 5167 5168 current_function_return_rtx 5169 = (DECL_RTL_SET_P (DECL_RESULT (fndecl)) 5170 ? DECL_RTL (DECL_RESULT (fndecl)) : NULL_RTX); 5171 5172 /* If scalar return value was computed in a pseudo-reg, or was a named 5173 return value that got dumped to the stack, copy that to the hard 5174 return register. */ 5175 if (DECL_RTL_SET_P (DECL_RESULT (fndecl))) 5176 { 5177 tree decl_result = DECL_RESULT (fndecl); 5178 rtx decl_rtl = DECL_RTL (decl_result); 5179 5180 if (REG_P (decl_rtl) 5181 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER 5182 : DECL_REGISTER (decl_result)) 5183 { 5184 rtx real_decl_rtl; 5185 5186 #ifdef FUNCTION_OUTGOING_VALUE 5187 real_decl_rtl = FUNCTION_OUTGOING_VALUE (TREE_TYPE (decl_result), 5188 fndecl); 5189 #else 5190 real_decl_rtl = FUNCTION_VALUE (TREE_TYPE (decl_result), 5191 fndecl); 5192 #endif 5193 REG_FUNCTION_VALUE_P (real_decl_rtl) = 1; 5194 /* The delay slot scheduler assumes that current_function_return_rtx 5195 holds the hard register containing the return value, not a 5196 temporary pseudo. */ 5197 current_function_return_rtx = real_decl_rtl; 5198 } 5199 } 5200 } 5201 5202 /* Indicate whether REGNO is an incoming argument to the current function 5203 that was promoted to a wider mode. If so, return the RTX for the 5204 register (to get its mode). PMODE and PUNSIGNEDP are set to the mode 5205 that REGNO is promoted from and whether the promotion was signed or 5206 unsigned. */ 5207 5208 #ifdef PROMOTE_FUNCTION_ARGS 5209 5210 rtx 5211 promoted_input_arg (regno, pmode, punsignedp) 5212 unsigned int regno; 5213 enum machine_mode *pmode; 5214 int *punsignedp; 5215 { 5216 tree arg; 5217 5218 for (arg = DECL_ARGUMENTS (current_function_decl); arg; 5219 arg = TREE_CHAIN (arg)) 5220 if (GET_CODE (DECL_INCOMING_RTL (arg)) == REG 5221 && REGNO (DECL_INCOMING_RTL (arg)) == regno 5222 && TYPE_MODE (DECL_ARG_TYPE (arg)) == TYPE_MODE (TREE_TYPE (arg))) 5223 { 5224 enum machine_mode mode = TYPE_MODE (TREE_TYPE (arg)); 5225 int unsignedp = TREE_UNSIGNED (TREE_TYPE (arg)); 5226 5227 mode = promote_mode (TREE_TYPE (arg), mode, &unsignedp, 1); 5228 if (mode == GET_MODE (DECL_INCOMING_RTL (arg)) 5229 && mode != DECL_MODE (arg)) 5230 { 5231 *pmode = DECL_MODE (arg); 5232 *punsignedp = unsignedp; 5233 return DECL_INCOMING_RTL (arg); 5234 } 5235 } 5236 5237 return 0; 5238 } 5239 5240 #endif 5241 5242 /* Compute the size and offset from the start of the stacked arguments for a 5243 parm passed in mode PASSED_MODE and with type TYPE. 5244 5245 INITIAL_OFFSET_PTR points to the current offset into the stacked 5246 arguments. 5247 5248 The starting offset and size for this parm are returned in *OFFSET_PTR 5249 and *ARG_SIZE_PTR, respectively. 5250 5251 IN_REGS is non-zero if the argument will be passed in registers. It will 5252 never be set if REG_PARM_STACK_SPACE is not defined. 5253 5254 FNDECL is the function in which the argument was defined. 5255 5256 There are two types of rounding that are done. The first, controlled by 5257 FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument 5258 list to be aligned to the specific boundary (in bits). This rounding 5259 affects the initial and starting offsets, but not the argument size. 5260 5261 The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY, 5262 optionally rounds the size of the parm to PARM_BOUNDARY. The 5263 initial offset is not affected by this rounding, while the size always 5264 is and the starting offset may be. */ 5265 5266 /* offset_ptr will be negative for ARGS_GROW_DOWNWARD case; 5267 initial_offset_ptr is positive because locate_and_pad_parm's 5268 callers pass in the total size of args so far as 5269 initial_offset_ptr. arg_size_ptr is always positive. */ 5270 5271 void 5272 locate_and_pad_parm (passed_mode, type, in_regs, fndecl, 5273 initial_offset_ptr, offset_ptr, arg_size_ptr, 5274 alignment_pad) 5275 enum machine_mode passed_mode; 5276 tree type; 5277 int in_regs ATTRIBUTE_UNUSED; 5278 tree fndecl ATTRIBUTE_UNUSED; 5279 struct args_size *initial_offset_ptr; 5280 struct args_size *offset_ptr; 5281 struct args_size *arg_size_ptr; 5282 struct args_size *alignment_pad; 5283 5284 { 5285 tree sizetree 5286 = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode)); 5287 enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type); 5288 int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type); 5289 5290 #ifdef REG_PARM_STACK_SPACE 5291 /* If we have found a stack parm before we reach the end of the 5292 area reserved for registers, skip that area. */ 5293 if (! in_regs) 5294 { 5295 int reg_parm_stack_space = 0; 5296 5297 #ifdef MAYBE_REG_PARM_STACK_SPACE 5298 reg_parm_stack_space = MAYBE_REG_PARM_STACK_SPACE; 5299 #else 5300 reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl); 5301 #endif 5302 if (reg_parm_stack_space > 0) 5303 { 5304 if (initial_offset_ptr->var) 5305 { 5306 initial_offset_ptr->var 5307 = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr), 5308 ssize_int (reg_parm_stack_space)); 5309 initial_offset_ptr->constant = 0; 5310 } 5311 else if (initial_offset_ptr->constant < reg_parm_stack_space) 5312 initial_offset_ptr->constant = reg_parm_stack_space; 5313 } 5314 } 5315 #endif /* REG_PARM_STACK_SPACE */ 5316 5317 arg_size_ptr->var = 0; 5318 arg_size_ptr->constant = 0; 5319 alignment_pad->var = 0; 5320 alignment_pad->constant = 0; 5321 5322 #ifdef ARGS_GROW_DOWNWARD 5323 if (initial_offset_ptr->var) 5324 { 5325 offset_ptr->constant = 0; 5326 offset_ptr->var = size_binop (MINUS_EXPR, ssize_int (0), 5327 initial_offset_ptr->var); 5328 } 5329 else 5330 { 5331 offset_ptr->constant = -initial_offset_ptr->constant; 5332 offset_ptr->var = 0; 5333 } 5334 if (where_pad != none 5335 && (!host_integerp (sizetree, 1) 5336 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY)) 5337 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5338 SUB_PARM_SIZE (*offset_ptr, sizetree); 5339 if (where_pad != downward) 5340 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad); 5341 if (initial_offset_ptr->var) 5342 arg_size_ptr->var = size_binop (MINUS_EXPR, 5343 size_binop (MINUS_EXPR, 5344 ssize_int (0), 5345 initial_offset_ptr->var), 5346 offset_ptr->var); 5347 5348 else 5349 arg_size_ptr->constant = (-initial_offset_ptr->constant 5350 - offset_ptr->constant); 5351 5352 #else /* !ARGS_GROW_DOWNWARD */ 5353 if (!in_regs 5354 #ifdef REG_PARM_STACK_SPACE 5355 || REG_PARM_STACK_SPACE (fndecl) > 0 5356 #endif 5357 ) 5358 pad_to_arg_alignment (initial_offset_ptr, boundary, alignment_pad); 5359 *offset_ptr = *initial_offset_ptr; 5360 5361 #ifdef PUSH_ROUNDING 5362 if (passed_mode != BLKmode) 5363 sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree))); 5364 #endif 5365 5366 /* Pad_below needs the pre-rounded size to know how much to pad below 5367 so this must be done before rounding up. */ 5368 if (where_pad == downward 5369 /* However, BLKmode args passed in regs have their padding done elsewhere. 5370 The stack slot must be able to hold the entire register. */ 5371 && !(in_regs && passed_mode == BLKmode)) 5372 pad_below (offset_ptr, passed_mode, sizetree); 5373 5374 if (where_pad != none 5375 && (!host_integerp (sizetree, 1) 5376 || (tree_low_cst (sizetree, 1) * BITS_PER_UNIT) % PARM_BOUNDARY)) 5377 sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5378 5379 ADD_PARM_SIZE (*arg_size_ptr, sizetree); 5380 #endif /* ARGS_GROW_DOWNWARD */ 5381 } 5382 5383 /* Round the stack offset in *OFFSET_PTR up to a multiple of BOUNDARY. 5384 BOUNDARY is measured in bits, but must be a multiple of a storage unit. */ 5385 5386 static void 5387 pad_to_arg_alignment (offset_ptr, boundary, alignment_pad) 5388 struct args_size *offset_ptr; 5389 int boundary; 5390 struct args_size *alignment_pad; 5391 { 5392 tree save_var = NULL_TREE; 5393 HOST_WIDE_INT save_constant = 0; 5394 5395 int boundary_in_bytes = boundary / BITS_PER_UNIT; 5396 5397 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5398 { 5399 save_var = offset_ptr->var; 5400 save_constant = offset_ptr->constant; 5401 } 5402 5403 alignment_pad->var = NULL_TREE; 5404 alignment_pad->constant = 0; 5405 5406 if (boundary > BITS_PER_UNIT) 5407 { 5408 if (offset_ptr->var) 5409 { 5410 offset_ptr->var = 5411 #ifdef ARGS_GROW_DOWNWARD 5412 round_down 5413 #else 5414 round_up 5415 #endif 5416 (ARGS_SIZE_TREE (*offset_ptr), 5417 boundary / BITS_PER_UNIT); 5418 offset_ptr->constant = 0; /*?*/ 5419 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5420 alignment_pad->var = size_binop (MINUS_EXPR, offset_ptr->var, 5421 save_var); 5422 } 5423 else 5424 { 5425 offset_ptr->constant = 5426 #ifdef ARGS_GROW_DOWNWARD 5427 FLOOR_ROUND (offset_ptr->constant, boundary_in_bytes); 5428 #else 5429 CEIL_ROUND (offset_ptr->constant, boundary_in_bytes); 5430 #endif 5431 if (boundary > PARM_BOUNDARY && boundary > STACK_BOUNDARY) 5432 alignment_pad->constant = offset_ptr->constant - save_constant; 5433 } 5434 } 5435 } 5436 5437 #ifndef ARGS_GROW_DOWNWARD 5438 static void 5439 pad_below (offset_ptr, passed_mode, sizetree) 5440 struct args_size *offset_ptr; 5441 enum machine_mode passed_mode; 5442 tree sizetree; 5443 { 5444 if (passed_mode != BLKmode) 5445 { 5446 if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY) 5447 offset_ptr->constant 5448 += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1) 5449 / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT) 5450 - GET_MODE_SIZE (passed_mode)); 5451 } 5452 else 5453 { 5454 if (TREE_CODE (sizetree) != INTEGER_CST 5455 || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY) 5456 { 5457 /* Round the size up to multiple of PARM_BOUNDARY bits. */ 5458 tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT); 5459 /* Add it in. */ 5460 ADD_PARM_SIZE (*offset_ptr, s2); 5461 SUB_PARM_SIZE (*offset_ptr, sizetree); 5462 } 5463 } 5464 } 5465 #endif 5466 5467 /* Walk the tree of blocks describing the binding levels within a function 5468 and warn about uninitialized variables. 5469 This is done after calling flow_analysis and before global_alloc 5470 clobbers the pseudo-regs to hard regs. */ 5471 5472 void 5473 uninitialized_vars_warning (block) 5474 tree block; 5475 { 5476 tree decl, sub; 5477 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) 5478 { 5479 if (warn_uninitialized 5480 && TREE_CODE (decl) == VAR_DECL 5481 /* These warnings are unreliable for and aggregates 5482 because assigning the fields one by one can fail to convince 5483 flow.c that the entire aggregate was initialized. 5484 Unions are troublesome because members may be shorter. */ 5485 && ! AGGREGATE_TYPE_P (TREE_TYPE (decl)) 5486 && DECL_RTL (decl) != 0 5487 && GET_CODE (DECL_RTL (decl)) == REG 5488 /* Global optimizations can make it difficult to determine if a 5489 particular variable has been initialized. However, a VAR_DECL 5490 with a nonzero DECL_INITIAL had an initializer, so do not 5491 claim it is potentially uninitialized. 5492 5493 We do not care about the actual value in DECL_INITIAL, so we do 5494 not worry that it may be a dangling pointer. */ 5495 && DECL_INITIAL (decl) == NULL_TREE 5496 && regno_uninitialized (REGNO (DECL_RTL (decl)))) 5497 warning_with_decl (decl, 5498 "`%s' might be used uninitialized in this function"); 5499 if (extra_warnings 5500 && TREE_CODE (decl) == VAR_DECL 5501 && DECL_RTL (decl) != 0 5502 && GET_CODE (DECL_RTL (decl)) == REG 5503 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) 5504 warning_with_decl (decl, 5505 "variable `%s' might be clobbered by `longjmp' or `vfork'"); 5506 } 5507 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) 5508 uninitialized_vars_warning (sub); 5509 } 5510 5511 /* Do the appropriate part of uninitialized_vars_warning 5512 but for arguments instead of local variables. */ 5513 5514 void 5515 setjmp_args_warning () 5516 { 5517 tree decl; 5518 for (decl = DECL_ARGUMENTS (current_function_decl); 5519 decl; decl = TREE_CHAIN (decl)) 5520 if (DECL_RTL (decl) != 0 5521 && GET_CODE (DECL_RTL (decl)) == REG 5522 && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl)))) 5523 warning_with_decl (decl, 5524 "argument `%s' might be clobbered by `longjmp' or `vfork'"); 5525 } 5526 5527 /* If this function call setjmp, put all vars into the stack 5528 unless they were declared `register'. */ 5529 5530 void 5531 setjmp_protect (block) 5532 tree block; 5533 { 5534 tree decl, sub; 5535 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) 5536 if ((TREE_CODE (decl) == VAR_DECL 5537 || TREE_CODE (decl) == PARM_DECL) 5538 && DECL_RTL (decl) != 0 5539 && (GET_CODE (DECL_RTL (decl)) == REG 5540 || (GET_CODE (DECL_RTL (decl)) == MEM 5541 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) 5542 /* If this variable came from an inline function, it must be 5543 that its life doesn't overlap the setjmp. If there was a 5544 setjmp in the function, it would already be in memory. We 5545 must exclude such variable because their DECL_RTL might be 5546 set to strange things such as virtual_stack_vars_rtx. */ 5547 && ! DECL_FROM_INLINE (decl) 5548 && ( 5549 #ifdef NON_SAVING_SETJMP 5550 /* If longjmp doesn't restore the registers, 5551 don't put anything in them. */ 5552 NON_SAVING_SETJMP 5553 || 5554 #endif 5555 ! DECL_REGISTER (decl))) 5556 put_var_into_stack (decl); 5557 for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub)) 5558 setjmp_protect (sub); 5559 } 5560 5561 /* Like the previous function, but for args instead of local variables. */ 5562 5563 void 5564 setjmp_protect_args () 5565 { 5566 tree decl; 5567 for (decl = DECL_ARGUMENTS (current_function_decl); 5568 decl; decl = TREE_CHAIN (decl)) 5569 if ((TREE_CODE (decl) == VAR_DECL 5570 || TREE_CODE (decl) == PARM_DECL) 5571 && DECL_RTL (decl) != 0 5572 && (GET_CODE (DECL_RTL (decl)) == REG 5573 || (GET_CODE (DECL_RTL (decl)) == MEM 5574 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == ADDRESSOF)) 5575 && ( 5576 /* If longjmp doesn't restore the registers, 5577 don't put anything in them. */ 5578 #ifdef NON_SAVING_SETJMP 5579 NON_SAVING_SETJMP 5580 || 5581 #endif 5582 ! DECL_REGISTER (decl))) 5583 put_var_into_stack (decl); 5584 } 5585 5586 /* Return the context-pointer register corresponding to DECL, 5587 or 0 if it does not need one. */ 5588 5589 rtx 5590 lookup_static_chain (decl) 5591 tree decl; 5592 { 5593 tree context = decl_function_context (decl); 5594 tree link; 5595 5596 if (context == 0 5597 || (TREE_CODE (decl) == FUNCTION_DECL && DECL_NO_STATIC_CHAIN (decl))) 5598 return 0; 5599 5600 /* We treat inline_function_decl as an alias for the current function 5601 because that is the inline function whose vars, types, etc. 5602 are being merged into the current function. 5603 See expand_inline_function. */ 5604 if (context == current_function_decl || context == inline_function_decl) 5605 return virtual_stack_vars_rtx; 5606 5607 for (link = context_display; link; link = TREE_CHAIN (link)) 5608 if (TREE_PURPOSE (link) == context) 5609 return RTL_EXPR_RTL (TREE_VALUE (link)); 5610 5611 abort (); 5612 } 5613 5614 /* Convert a stack slot address ADDR for variable VAR 5615 (from a containing function) 5616 into an address valid in this function (using a static chain). */ 5617 5618 rtx 5619 fix_lexical_addr (addr, var) 5620 rtx addr; 5621 tree var; 5622 { 5623 rtx basereg; 5624 HOST_WIDE_INT displacement; 5625 tree context = decl_function_context (var); 5626 struct function *fp; 5627 rtx base = 0; 5628 5629 /* If this is the present function, we need not do anything. */ 5630 if (context == current_function_decl || context == inline_function_decl) 5631 return addr; 5632 5633 fp = find_function_data (context); 5634 5635 if (GET_CODE (addr) == ADDRESSOF && GET_CODE (XEXP (addr, 0)) == MEM) 5636 addr = XEXP (XEXP (addr, 0), 0); 5637 5638 /* Decode given address as base reg plus displacement. */ 5639 if (GET_CODE (addr) == REG) 5640 basereg = addr, displacement = 0; 5641 else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT) 5642 basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1)); 5643 else 5644 abort (); 5645 5646 /* We accept vars reached via the containing function's 5647 incoming arg pointer and via its stack variables pointer. */ 5648 if (basereg == fp->internal_arg_pointer) 5649 { 5650 /* If reached via arg pointer, get the arg pointer value 5651 out of that function's stack frame. 5652 5653 There are two cases: If a separate ap is needed, allocate a 5654 slot in the outer function for it and dereference it that way. 5655 This is correct even if the real ap is actually a pseudo. 5656 Otherwise, just adjust the offset from the frame pointer to 5657 compensate. */ 5658 5659 #ifdef NEED_SEPARATE_AP 5660 rtx addr; 5661 5662 addr = get_arg_pointer_save_area (fp); 5663 addr = fix_lexical_addr (XEXP (addr, 0), var); 5664 addr = memory_address (Pmode, addr); 5665 5666 base = gen_rtx_MEM (Pmode, addr); 5667 set_mem_alias_set (base, get_frame_alias_set ()); 5668 base = copy_to_reg (base); 5669 #else 5670 displacement += (FIRST_PARM_OFFSET (context) - STARTING_FRAME_OFFSET); 5671 base = lookup_static_chain (var); 5672 #endif 5673 } 5674 5675 else if (basereg == virtual_stack_vars_rtx) 5676 { 5677 /* This is the same code as lookup_static_chain, duplicated here to 5678 avoid an extra call to decl_function_context. */ 5679 tree link; 5680 5681 for (link = context_display; link; link = TREE_CHAIN (link)) 5682 if (TREE_PURPOSE (link) == context) 5683 { 5684 base = RTL_EXPR_RTL (TREE_VALUE (link)); 5685 break; 5686 } 5687 } 5688 5689 if (base == 0) 5690 abort (); 5691 5692 /* Use same offset, relative to appropriate static chain or argument 5693 pointer. */ 5694 return plus_constant (base, displacement); 5695 } 5696 5697 /* Return the address of the trampoline for entering nested fn FUNCTION. 5698 If necessary, allocate a trampoline (in the stack frame) 5699 and emit rtl to initialize its contents (at entry to this function). */ 5700 5701 rtx 5702 trampoline_address (function) 5703 tree function; 5704 { 5705 tree link; 5706 tree rtlexp; 5707 rtx tramp; 5708 struct function *fp; 5709 tree fn_context; 5710 5711 /* Find an existing trampoline and return it. */ 5712 for (link = trampoline_list; link; link = TREE_CHAIN (link)) 5713 if (TREE_PURPOSE (link) == function) 5714 return 5715 adjust_trampoline_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0)); 5716 5717 for (fp = outer_function_chain; fp; fp = fp->outer) 5718 for (link = fp->x_trampoline_list; link; link = TREE_CHAIN (link)) 5719 if (TREE_PURPOSE (link) == function) 5720 { 5721 tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0), 5722 function); 5723 return adjust_trampoline_addr (tramp); 5724 } 5725 5726 /* None exists; we must make one. */ 5727 5728 /* Find the `struct function' for the function containing FUNCTION. */ 5729 fp = 0; 5730 fn_context = decl_function_context (function); 5731 if (fn_context != current_function_decl 5732 && fn_context != inline_function_decl) 5733 fp = find_function_data (fn_context); 5734 5735 /* Allocate run-time space for this trampoline 5736 (usually in the defining function's stack frame). */ 5737 #ifdef ALLOCATE_TRAMPOLINE 5738 tramp = ALLOCATE_TRAMPOLINE (fp); 5739 #else 5740 /* If rounding needed, allocate extra space 5741 to ensure we have TRAMPOLINE_SIZE bytes left after rounding up. */ 5742 #ifdef TRAMPOLINE_ALIGNMENT 5743 #define TRAMPOLINE_REAL_SIZE \ 5744 (TRAMPOLINE_SIZE + (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT) - 1) 5745 #else 5746 #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE) 5747 #endif 5748 tramp = assign_stack_local_1 (BLKmode, TRAMPOLINE_REAL_SIZE, 0, 5749 fp ? fp : cfun); 5750 #endif 5751 5752 /* Record the trampoline for reuse and note it for later initialization 5753 by expand_function_end. */ 5754 if (fp != 0) 5755 { 5756 rtlexp = make_node (RTL_EXPR); 5757 RTL_EXPR_RTL (rtlexp) = tramp; 5758 fp->x_trampoline_list = tree_cons (function, rtlexp, 5759 fp->x_trampoline_list); 5760 } 5761 else 5762 { 5763 /* Make the RTL_EXPR node temporary, not momentary, so that the 5764 trampoline_list doesn't become garbage. */ 5765 rtlexp = make_node (RTL_EXPR); 5766 5767 RTL_EXPR_RTL (rtlexp) = tramp; 5768 trampoline_list = tree_cons (function, rtlexp, trampoline_list); 5769 } 5770 5771 tramp = fix_lexical_addr (XEXP (tramp, 0), function); 5772 return adjust_trampoline_addr (tramp); 5773 } 5774 5775 /* Given a trampoline address, 5776 round it to multiple of TRAMPOLINE_ALIGNMENT. */ 5777 5778 static rtx 5779 round_trampoline_addr (tramp) 5780 rtx tramp; 5781 { 5782 #ifdef TRAMPOLINE_ALIGNMENT 5783 /* Round address up to desired boundary. */ 5784 rtx temp = gen_reg_rtx (Pmode); 5785 rtx addend = GEN_INT (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT - 1); 5786 rtx mask = GEN_INT (-TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); 5787 5788 temp = expand_simple_binop (Pmode, PLUS, tramp, addend, 5789 temp, 0, OPTAB_LIB_WIDEN); 5790 tramp = expand_simple_binop (Pmode, AND, temp, mask, 5791 temp, 0, OPTAB_LIB_WIDEN); 5792 #endif 5793 return tramp; 5794 } 5795 5796 /* Given a trampoline address, round it then apply any 5797 platform-specific adjustments so that the result can be used for a 5798 function call . */ 5799 5800 static rtx 5801 adjust_trampoline_addr (tramp) 5802 rtx tramp; 5803 { 5804 tramp = round_trampoline_addr (tramp); 5805 #ifdef TRAMPOLINE_ADJUST_ADDRESS 5806 TRAMPOLINE_ADJUST_ADDRESS (tramp); 5807 #endif 5808 return tramp; 5809 } 5810 5811 /* Put all this function's BLOCK nodes including those that are chained 5812 onto the first block into a vector, and return it. 5813 Also store in each NOTE for the beginning or end of a block 5814 the index of that block in the vector. 5815 The arguments are BLOCK, the chain of top-level blocks of the function, 5816 and INSNS, the insn chain of the function. */ 5817 5818 void 5819 identify_blocks () 5820 { 5821 int n_blocks; 5822 tree *block_vector, *last_block_vector; 5823 tree *block_stack; 5824 tree block = DECL_INITIAL (current_function_decl); 5825 5826 if (block == 0) 5827 return; 5828 5829 /* Fill the BLOCK_VECTOR with all of the BLOCKs in this function, in 5830 depth-first order. */ 5831 block_vector = get_block_vector (block, &n_blocks); 5832 block_stack = (tree *) xmalloc (n_blocks * sizeof (tree)); 5833 5834 last_block_vector = identify_blocks_1 (get_insns (), 5835 block_vector + 1, 5836 block_vector + n_blocks, 5837 block_stack); 5838 5839 /* If we didn't use all of the subblocks, we've misplaced block notes. */ 5840 /* ??? This appears to happen all the time. Latent bugs elsewhere? */ 5841 if (0 && last_block_vector != block_vector + n_blocks) 5842 abort (); 5843 5844 free (block_vector); 5845 free (block_stack); 5846 } 5847 5848 /* Subroutine of identify_blocks. Do the block substitution on the 5849 insn chain beginning with INSNS. Recurse for CALL_PLACEHOLDER chains. 5850 5851 BLOCK_STACK is pushed and popped for each BLOCK_BEGIN/BLOCK_END pair. 5852 BLOCK_VECTOR is incremented for each block seen. */ 5853 5854 static tree * 5855 identify_blocks_1 (insns, block_vector, end_block_vector, orig_block_stack) 5856 rtx insns; 5857 tree *block_vector; 5858 tree *end_block_vector; 5859 tree *orig_block_stack; 5860 { 5861 rtx insn; 5862 tree *block_stack = orig_block_stack; 5863 5864 for (insn = insns; insn; insn = NEXT_INSN (insn)) 5865 { 5866 if (GET_CODE (insn) == NOTE) 5867 { 5868 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) 5869 { 5870 tree b; 5871 5872 /* If there are more block notes than BLOCKs, something 5873 is badly wrong. */ 5874 if (block_vector == end_block_vector) 5875 abort (); 5876 5877 b = *block_vector++; 5878 NOTE_BLOCK (insn) = b; 5879 *block_stack++ = b; 5880 } 5881 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) 5882 { 5883 /* If there are more NOTE_INSN_BLOCK_ENDs than 5884 NOTE_INSN_BLOCK_BEGs, something is badly wrong. */ 5885 if (block_stack == orig_block_stack) 5886 abort (); 5887 5888 NOTE_BLOCK (insn) = *--block_stack; 5889 } 5890 } 5891 else if (GET_CODE (insn) == CALL_INSN 5892 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER) 5893 { 5894 rtx cp = PATTERN (insn); 5895 5896 block_vector = identify_blocks_1 (XEXP (cp, 0), block_vector, 5897 end_block_vector, block_stack); 5898 if (XEXP (cp, 1)) 5899 block_vector = identify_blocks_1 (XEXP (cp, 1), block_vector, 5900 end_block_vector, block_stack); 5901 if (XEXP (cp, 2)) 5902 block_vector = identify_blocks_1 (XEXP (cp, 2), block_vector, 5903 end_block_vector, block_stack); 5904 } 5905 } 5906 5907 /* If there are more NOTE_INSN_BLOCK_BEGINs than NOTE_INSN_BLOCK_ENDs, 5908 something is badly wrong. */ 5909 if (block_stack != orig_block_stack) 5910 abort (); 5911 5912 return block_vector; 5913 } 5914 5915 /* Identify BLOCKs referenced by more than one NOTE_INSN_BLOCK_{BEG,END}, 5916 and create duplicate blocks. */ 5917 /* ??? Need an option to either create block fragments or to create 5918 abstract origin duplicates of a source block. It really depends 5919 on what optimization has been performed. */ 5920 5921 void 5922 reorder_blocks () 5923 { 5924 tree block = DECL_INITIAL (current_function_decl); 5925 varray_type block_stack; 5926 5927 if (block == NULL_TREE) 5928 return; 5929 5930 VARRAY_TREE_INIT (block_stack, 10, "block_stack"); 5931 5932 /* Reset the TREE_ASM_WRITTEN bit for all blocks. */ 5933 reorder_blocks_0 (block); 5934 5935 /* Prune the old trees away, so that they don't get in the way. */ 5936 BLOCK_SUBBLOCKS (block) = NULL_TREE; 5937 BLOCK_CHAIN (block) = NULL_TREE; 5938 5939 /* Recreate the block tree from the note nesting. */ 5940 reorder_blocks_1 (get_insns (), block, &block_stack); 5941 BLOCK_SUBBLOCKS (block) = blocks_nreverse (BLOCK_SUBBLOCKS (block)); 5942 5943 /* Remove deleted blocks from the block fragment chains. */ 5944 reorder_fix_fragments (block); 5945 5946 VARRAY_FREE (block_stack); 5947 } 5948 5949 /* Helper function for reorder_blocks. Reset TREE_ASM_WRITTEN. */ 5950 5951 static void 5952 reorder_blocks_0 (block) 5953 tree block; 5954 { 5955 while (block) 5956 { 5957 TREE_ASM_WRITTEN (block) = 0; 5958 reorder_blocks_0 (BLOCK_SUBBLOCKS (block)); 5959 block = BLOCK_CHAIN (block); 5960 } 5961 } 5962 5963 static void 5964 reorder_blocks_1 (insns, current_block, p_block_stack) 5965 rtx insns; 5966 tree current_block; 5967 varray_type *p_block_stack; 5968 { 5969 rtx insn; 5970 5971 for (insn = insns; insn; insn = NEXT_INSN (insn)) 5972 { 5973 if (GET_CODE (insn) == NOTE) 5974 { 5975 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_BEG) 5976 { 5977 tree block = NOTE_BLOCK (insn); 5978 5979 /* If we have seen this block before, that means it now 5980 spans multiple address regions. Create a new fragment. */ 5981 if (TREE_ASM_WRITTEN (block)) 5982 { 5983 tree new_block = copy_node (block); 5984 tree origin; 5985 5986 origin = (BLOCK_FRAGMENT_ORIGIN (block) 5987 ? BLOCK_FRAGMENT_ORIGIN (block) 5988 : block); 5989 BLOCK_FRAGMENT_ORIGIN (new_block) = origin; 5990 BLOCK_FRAGMENT_CHAIN (new_block) 5991 = BLOCK_FRAGMENT_CHAIN (origin); 5992 BLOCK_FRAGMENT_CHAIN (origin) = new_block; 5993 5994 NOTE_BLOCK (insn) = new_block; 5995 block = new_block; 5996 } 5997 5998 BLOCK_SUBBLOCKS (block) = 0; 5999 TREE_ASM_WRITTEN (block) = 1; 6000 BLOCK_SUPERCONTEXT (block) = current_block; 6001 BLOCK_CHAIN (block) = BLOCK_SUBBLOCKS (current_block); 6002 BLOCK_SUBBLOCKS (current_block) = block; 6003 current_block = block; 6004 VARRAY_PUSH_TREE (*p_block_stack, block); 6005 } 6006 else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_BLOCK_END) 6007 { 6008 NOTE_BLOCK (insn) = VARRAY_TOP_TREE (*p_block_stack); 6009 VARRAY_POP (*p_block_stack); 6010 BLOCK_SUBBLOCKS (current_block) 6011 = blocks_nreverse (BLOCK_SUBBLOCKS (current_block)); 6012 current_block = BLOCK_SUPERCONTEXT (current_block); 6013 } 6014 } 6015 else if (GET_CODE (insn) == CALL_INSN 6016 && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER) 6017 { 6018 rtx cp = PATTERN (insn); 6019 reorder_blocks_1 (XEXP (cp, 0), current_block, p_block_stack); 6020 if (XEXP (cp, 1)) 6021 reorder_blocks_1 (XEXP (cp, 1), current_block, p_block_stack); 6022 if (XEXP (cp, 2)) 6023 reorder_blocks_1 (XEXP (cp, 2), current_block, p_block_stack); 6024 } 6025 } 6026 } 6027 6028 /* Rationalize BLOCK_FRAGMENT_ORIGIN. If an origin block no longer 6029 appears in the block tree, select one of the fragments to become 6030 the new origin block. */ 6031 6032 static void 6033 reorder_fix_fragments (block) 6034 tree block; 6035 { 6036 while (block) 6037 { 6038 tree dup_origin = BLOCK_FRAGMENT_ORIGIN (block); 6039 tree new_origin = NULL_TREE; 6040 6041 if (dup_origin) 6042 { 6043 if (! TREE_ASM_WRITTEN (dup_origin)) 6044 { 6045 new_origin = BLOCK_FRAGMENT_CHAIN (dup_origin); 6046 6047 /* Find the first of the remaining fragments. There must 6048 be at least one -- the current block. */ 6049 while (! TREE_ASM_WRITTEN (new_origin)) 6050 new_origin = BLOCK_FRAGMENT_CHAIN (new_origin); 6051 BLOCK_FRAGMENT_ORIGIN (new_origin) = NULL_TREE; 6052 } 6053 } 6054 else if (! dup_origin) 6055 new_origin = block; 6056 6057 /* Re-root the rest of the fragments to the new origin. In the 6058 case that DUP_ORIGIN was null, that means BLOCK was the origin 6059 of a chain of fragments and we want to remove those fragments 6060 that didn't make it to the output. */ 6061 if (new_origin) 6062 { 6063 tree *pp = &BLOCK_FRAGMENT_CHAIN (new_origin); 6064 tree chain = *pp; 6065 6066 while (chain) 6067 { 6068 if (TREE_ASM_WRITTEN (chain)) 6069 { 6070 BLOCK_FRAGMENT_ORIGIN (chain) = new_origin; 6071 *pp = chain; 6072 pp = &BLOCK_FRAGMENT_CHAIN (chain); 6073 } 6074 chain = BLOCK_FRAGMENT_CHAIN (chain); 6075 } 6076 *pp = NULL_TREE; 6077 } 6078 6079 reorder_fix_fragments (BLOCK_SUBBLOCKS (block)); 6080 block = BLOCK_CHAIN (block); 6081 } 6082 } 6083 6084 /* Reverse the order of elements in the chain T of blocks, 6085 and return the new head of the chain (old last element). */ 6086 6087 static tree 6088 blocks_nreverse (t) 6089 tree t; 6090 { 6091 tree prev = 0, decl, next; 6092 for (decl = t; decl; decl = next) 6093 { 6094 next = BLOCK_CHAIN (decl); 6095 BLOCK_CHAIN (decl) = prev; 6096 prev = decl; 6097 } 6098 return prev; 6099 } 6100 6101 /* Count the subblocks of the list starting with BLOCK. If VECTOR is 6102 non-NULL, list them all into VECTOR, in a depth-first preorder 6103 traversal of the block tree. Also clear TREE_ASM_WRITTEN in all 6104 blocks. */ 6105 6106 static int 6107 all_blocks (block, vector) 6108 tree block; 6109 tree *vector; 6110 { 6111 int n_blocks = 0; 6112 6113 while (block) 6114 { 6115 TREE_ASM_WRITTEN (block) = 0; 6116 6117 /* Record this block. */ 6118 if (vector) 6119 vector[n_blocks] = block; 6120 6121 ++n_blocks; 6122 6123 /* Record the subblocks, and their subblocks... */ 6124 n_blocks += all_blocks (BLOCK_SUBBLOCKS (block), 6125 vector ? vector + n_blocks : 0); 6126 block = BLOCK_CHAIN (block); 6127 } 6128 6129 return n_blocks; 6130 } 6131 6132 /* Return a vector containing all the blocks rooted at BLOCK. The 6133 number of elements in the vector is stored in N_BLOCKS_P. The 6134 vector is dynamically allocated; it is the caller's responsibility 6135 to call `free' on the pointer returned. */ 6136 6137 static tree * 6138 get_block_vector (block, n_blocks_p) 6139 tree block; 6140 int *n_blocks_p; 6141 { 6142 tree *block_vector; 6143 6144 *n_blocks_p = all_blocks (block, NULL); 6145 block_vector = (tree *) xmalloc (*n_blocks_p * sizeof (tree)); 6146 all_blocks (block, block_vector); 6147 6148 return block_vector; 6149 } 6150 6151 static int next_block_index = 2; 6152 6153 /* Set BLOCK_NUMBER for all the blocks in FN. */ 6154 6155 void 6156 number_blocks (fn) 6157 tree fn; 6158 { 6159 int i; 6160 int n_blocks; 6161 tree *block_vector; 6162 6163 /* For SDB and XCOFF debugging output, we start numbering the blocks 6164 from 1 within each function, rather than keeping a running 6165 count. */ 6166 #if defined (SDB_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) 6167 if (write_symbols == SDB_DEBUG || write_symbols == XCOFF_DEBUG) 6168 next_block_index = 1; 6169 #endif 6170 6171 block_vector = get_block_vector (DECL_INITIAL (fn), &n_blocks); 6172 6173 /* The top-level BLOCK isn't numbered at all. */ 6174 for (i = 1; i < n_blocks; ++i) 6175 /* We number the blocks from two. */ 6176 BLOCK_NUMBER (block_vector[i]) = next_block_index++; 6177 6178 free (block_vector); 6179 6180 return; 6181 } 6182 6183 /* If VAR is present in a subblock of BLOCK, return the subblock. */ 6184 6185 tree 6186 debug_find_var_in_block_tree (var, block) 6187 tree var; 6188 tree block; 6189 { 6190 tree t; 6191 6192 for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t)) 6193 if (t == var) 6194 return block; 6195 6196 for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t)) 6197 { 6198 tree ret = debug_find_var_in_block_tree (var, t); 6199 if (ret) 6200 return ret; 6201 } 6202 6203 return NULL_TREE; 6204 } 6205 6206 /* Allocate a function structure and reset its contents to the defaults. */ 6207 6208 static void 6209 prepare_function_start () 6210 { 6211 cfun = (struct function *) ggc_alloc_cleared (sizeof (struct function)); 6212 6213 init_stmt_for_function (); 6214 init_eh_for_function (); 6215 6216 cse_not_expected = ! optimize; 6217 6218 /* Caller save not needed yet. */ 6219 caller_save_needed = 0; 6220 6221 /* No stack slots have been made yet. */ 6222 stack_slot_list = 0; 6223 6224 current_function_has_nonlocal_label = 0; 6225 current_function_has_nonlocal_goto = 0; 6226 6227 /* There is no stack slot for handling nonlocal gotos. */ 6228 nonlocal_goto_handler_slots = 0; 6229 nonlocal_goto_stack_level = 0; 6230 6231 /* No labels have been declared for nonlocal use. */ 6232 nonlocal_labels = 0; 6233 nonlocal_goto_handler_labels = 0; 6234 6235 /* No function calls so far in this function. */ 6236 function_call_count = 0; 6237 6238 /* No parm regs have been allocated. 6239 (This is important for output_inline_function.) */ 6240 max_parm_reg = LAST_VIRTUAL_REGISTER + 1; 6241 6242 /* Initialize the RTL mechanism. */ 6243 init_emit (); 6244 6245 /* Initialize the queue of pending postincrement and postdecrements, 6246 and some other info in expr.c. */ 6247 init_expr (); 6248 6249 /* We haven't done register allocation yet. */ 6250 reg_renumber = 0; 6251 6252 init_varasm_status (cfun); 6253 6254 /* Clear out data used for inlining. */ 6255 cfun->inlinable = 0; 6256 cfun->original_decl_initial = 0; 6257 cfun->original_arg_vector = 0; 6258 6259 cfun->stack_alignment_needed = STACK_BOUNDARY; 6260 cfun->preferred_stack_boundary = STACK_BOUNDARY; 6261 6262 /* Set if a call to setjmp is seen. */ 6263 current_function_calls_setjmp = 0; 6264 6265 /* Set if a call to longjmp is seen. */ 6266 current_function_calls_longjmp = 0; 6267 6268 current_function_calls_alloca = 0; 6269 current_function_contains_functions = 0; 6270 current_function_is_leaf = 0; 6271 current_function_nothrow = 0; 6272 current_function_sp_is_unchanging = 0; 6273 current_function_uses_only_leaf_regs = 0; 6274 current_function_has_computed_jump = 0; 6275 current_function_is_thunk = 0; 6276 6277 current_function_returns_pcc_struct = 0; 6278 current_function_returns_struct = 0; 6279 current_function_epilogue_delay_list = 0; 6280 current_function_uses_const_pool = 0; 6281 current_function_uses_pic_offset_table = 0; 6282 current_function_cannot_inline = 0; 6283 6284 /* We have not yet needed to make a label to jump to for tail-recursion. */ 6285 tail_recursion_label = 0; 6286 6287 /* We haven't had a need to make a save area for ap yet. */ 6288 arg_pointer_save_area = 0; 6289 6290 /* No stack slots allocated yet. */ 6291 frame_offset = 0; 6292 6293 /* No SAVE_EXPRs in this function yet. */ 6294 save_expr_regs = 0; 6295 6296 /* No RTL_EXPRs in this function yet. */ 6297 rtl_expr_chain = 0; 6298 6299 /* Set up to allocate temporaries. */ 6300 init_temp_slots (); 6301 6302 /* Indicate that we need to distinguish between the return value of the 6303 present function and the return value of a function being called. */ 6304 rtx_equal_function_value_matters = 1; 6305 6306 /* Indicate that we have not instantiated virtual registers yet. */ 6307 virtuals_instantiated = 0; 6308 6309 /* Indicate that we want CONCATs now. */ 6310 generating_concat_p = 1; 6311 6312 /* Indicate we have no need of a frame pointer yet. */ 6313 frame_pointer_needed = 0; 6314 6315 /* By default assume not varargs or stdarg. */ 6316 current_function_varargs = 0; 6317 current_function_stdarg = 0; 6318 6319 /* We haven't made any trampolines for this function yet. */ 6320 trampoline_list = 0; 6321 6322 init_pending_stack_adjust (); 6323 inhibit_defer_pop = 0; 6324 6325 current_function_outgoing_args_size = 0; 6326 6327 if (init_lang_status) 6328 (*init_lang_status) (cfun); 6329 if (init_machine_status) 6330 (*init_machine_status) (cfun); 6331 } 6332 6333 /* Initialize the rtl expansion mechanism so that we can do simple things 6334 like generate sequences. This is used to provide a context during global 6335 initialization of some passes. */ 6336 void 6337 init_dummy_function_start () 6338 { 6339 prepare_function_start (); 6340 } 6341 6342 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node) 6343 and initialize static variables for generating RTL for the statements 6344 of the function. */ 6345 6346 void 6347 init_function_start (subr, filename, line) 6348 tree subr; 6349 const char *filename; 6350 int line; 6351 { 6352 prepare_function_start (); 6353 6354 current_function_name = (*decl_printable_name) (subr, 2); 6355 cfun->decl = subr; 6356 6357 /* Nonzero if this is a nested function that uses a static chain. */ 6358 6359 current_function_needs_context 6360 = (decl_function_context (current_function_decl) != 0 6361 && ! DECL_NO_STATIC_CHAIN (current_function_decl)); 6362 6363 /* Within function body, compute a type's size as soon it is laid out. */ 6364 immediate_size_expand++; 6365 6366 /* Prevent ever trying to delete the first instruction of a function. 6367 Also tell final how to output a linenum before the function prologue. 6368 Note linenums could be missing, e.g. when compiling a Java .class file. */ 6369 if (line > 0) 6370 emit_line_note (filename, line); 6371 6372 /* Make sure first insn is a note even if we don't want linenums. 6373 This makes sure the first insn will never be deleted. 6374 Also, final expects a note to appear there. */ 6375 emit_note (NULL, NOTE_INSN_DELETED); 6376 6377 /* Set flags used by final.c. */ 6378 if (aggregate_value_p (DECL_RESULT (subr))) 6379 { 6380 #ifdef PCC_STATIC_STRUCT_RETURN 6381 current_function_returns_pcc_struct = 1; 6382 #endif 6383 current_function_returns_struct = 1; 6384 } 6385 6386 /* Warn if this value is an aggregate type, 6387 regardless of which calling convention we are using for it. */ 6388 if (warn_aggregate_return 6389 && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr)))) 6390 warning ("function returns an aggregate"); 6391 6392 current_function_returns_pointer 6393 = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr))); 6394 } 6395 6396 /* Make sure all values used by the optimization passes have sane 6397 defaults. */ 6398 void 6399 init_function_for_compilation () 6400 { 6401 reg_renumber = 0; 6402 6403 /* No prologue/epilogue insns yet. */ 6404 VARRAY_GROW (prologue, 0); 6405 VARRAY_GROW (epilogue, 0); 6406 VARRAY_GROW (sibcall_epilogue, 0); 6407 } 6408 6409 /* Indicate that the current function uses extra args 6410 not explicitly mentioned in the argument list in any fashion. */ 6411 6412 void 6413 mark_varargs () 6414 { 6415 current_function_varargs = 1; 6416 } 6417 6418 /* Expand a call to __main at the beginning of a possible main function. */ 6419 6420 #if defined(INIT_SECTION_ASM_OP) && !defined(INVOKE__main) 6421 #undef HAS_INIT_SECTION 6422 #define HAS_INIT_SECTION 6423 #endif 6424 6425 void 6426 expand_main_function () 6427 { 6428 #ifdef FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN 6429 if (FORCE_PREFERRED_STACK_BOUNDARY_IN_MAIN) 6430 { 6431 int align = PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT; 6432 rtx tmp, seq; 6433 6434 start_sequence (); 6435 /* Forcibly align the stack. */ 6436 #ifdef STACK_GROWS_DOWNWARD 6437 tmp = expand_simple_binop (Pmode, AND, stack_pointer_rtx, GEN_INT(-align), 6438 stack_pointer_rtx, 1, OPTAB_WIDEN); 6439 #else 6440 tmp = expand_simple_binop (Pmode, PLUS, stack_pointer_rtx, 6441 GEN_INT (align - 1), NULL_RTX, 1, OPTAB_WIDEN); 6442 tmp = expand_simple_binop (Pmode, AND, tmp, GEN_INT (-align), 6443 stack_pointer_rtx, 1, OPTAB_WIDEN); 6444 #endif 6445 if (tmp != stack_pointer_rtx) 6446 emit_move_insn (stack_pointer_rtx, tmp); 6447 6448 /* Enlist allocate_dynamic_stack_space to pick up the pieces. */ 6449 tmp = force_reg (Pmode, const0_rtx); 6450 allocate_dynamic_stack_space (tmp, NULL_RTX, BIGGEST_ALIGNMENT); 6451 seq = gen_sequence (); 6452 end_sequence (); 6453 6454 for (tmp = get_last_insn (); tmp; tmp = PREV_INSN (tmp)) 6455 if (NOTE_P (tmp) && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_FUNCTION_BEG) 6456 break; 6457 if (tmp) 6458 emit_insn_before (seq, tmp); 6459 else 6460 emit_insn (seq); 6461 } 6462 #endif 6463 6464 #ifndef HAS_INIT_SECTION 6465 emit_library_call (gen_rtx_SYMBOL_REF (Pmode, NAME__MAIN), LCT_NORMAL, 6466 VOIDmode, 0); 6467 #endif 6468 } 6469 6470 extern struct obstack permanent_obstack; 6471 6472 /* The PENDING_SIZES represent the sizes of variable-sized types. 6473 Create RTL for the various sizes now (using temporary variables), 6474 so that we can refer to the sizes from the RTL we are generating 6475 for the current function. The PENDING_SIZES are a TREE_LIST. The 6476 TREE_VALUE of each node is a SAVE_EXPR. */ 6477 6478 void 6479 expand_pending_sizes (pending_sizes) 6480 tree pending_sizes; 6481 { 6482 tree tem; 6483 6484 /* Evaluate now the sizes of any types declared among the arguments. */ 6485 for (tem = pending_sizes; tem; tem = TREE_CHAIN (tem)) 6486 { 6487 expand_expr (TREE_VALUE (tem), const0_rtx, VOIDmode, 0); 6488 /* Flush the queue in case this parameter declaration has 6489 side-effects. */ 6490 emit_queue (); 6491 } 6492 } 6493 6494 /* Start the RTL for a new function, and set variables used for 6495 emitting RTL. 6496 SUBR is the FUNCTION_DECL node. 6497 PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with 6498 the function's parameters, which must be run at any return statement. */ 6499 6500 void 6501 expand_function_start (subr, parms_have_cleanups) 6502 tree subr; 6503 int parms_have_cleanups; 6504 { 6505 tree tem; 6506 rtx last_ptr = NULL_RTX; 6507 6508 /* Make sure volatile mem refs aren't considered 6509 valid operands of arithmetic insns. */ 6510 init_recog_no_volatile (); 6511 6512 current_function_instrument_entry_exit 6513 = (flag_instrument_function_entry_exit 6514 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); 6515 6516 current_function_profile 6517 = (profile_flag 6518 && ! DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (subr)); 6519 6520 current_function_limit_stack 6521 = (stack_limit_rtx != NULL_RTX && ! DECL_NO_LIMIT_STACK (subr)); 6522 6523 /* If function gets a static chain arg, store it in the stack frame. 6524 Do this first, so it gets the first stack slot offset. */ 6525 if (current_function_needs_context) 6526 { 6527 last_ptr = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0); 6528 6529 /* Delay copying static chain if it is not a register to avoid 6530 conflicts with regs used for parameters. */ 6531 if (! SMALL_REGISTER_CLASSES 6532 || GET_CODE (static_chain_incoming_rtx) == REG) 6533 emit_move_insn (last_ptr, static_chain_incoming_rtx); 6534 } 6535 6536 /* If the parameters of this function need cleaning up, get a label 6537 for the beginning of the code which executes those cleanups. This must 6538 be done before doing anything with return_label. */ 6539 if (parms_have_cleanups) 6540 cleanup_label = gen_label_rtx (); 6541 else 6542 cleanup_label = 0; 6543 6544 /* Make the label for return statements to jump to. Do not special 6545 case machines with special return instructions -- they will be 6546 handled later during jump, ifcvt, or epilogue creation. */ 6547 return_label = gen_label_rtx (); 6548 6549 /* Initialize rtx used to return the value. */ 6550 /* Do this before assign_parms so that we copy the struct value address 6551 before any library calls that assign parms might generate. */ 6552 6553 /* Decide whether to return the value in memory or in a register. */ 6554 if (aggregate_value_p (DECL_RESULT (subr))) 6555 { 6556 /* Returning something that won't go in a register. */ 6557 rtx value_address = 0; 6558 6559 #ifdef PCC_STATIC_STRUCT_RETURN 6560 if (current_function_returns_pcc_struct) 6561 { 6562 int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr))); 6563 value_address = assemble_static_space (size); 6564 } 6565 else 6566 #endif 6567 { 6568 /* Expect to be passed the address of a place to store the value. 6569 If it is passed as an argument, assign_parms will take care of 6570 it. */ 6571 if (struct_value_incoming_rtx) 6572 { 6573 value_address = gen_reg_rtx (Pmode); 6574 emit_move_insn (value_address, struct_value_incoming_rtx); 6575 } 6576 } 6577 if (value_address) 6578 { 6579 rtx x = gen_rtx_MEM (DECL_MODE (DECL_RESULT (subr)), value_address); 6580 set_mem_attributes (x, DECL_RESULT (subr), 1); 6581 SET_DECL_RTL (DECL_RESULT (subr), x); 6582 } 6583 } 6584 else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode) 6585 /* If return mode is void, this decl rtl should not be used. */ 6586 SET_DECL_RTL (DECL_RESULT (subr), NULL_RTX); 6587 else 6588 { 6589 /* Compute the return values into a pseudo reg, which we will copy 6590 into the true return register after the cleanups are done. */ 6591 6592 /* In order to figure out what mode to use for the pseudo, we 6593 figure out what the mode of the eventual return register will 6594 actually be, and use that. */ 6595 rtx hard_reg 6596 = hard_function_value (TREE_TYPE (DECL_RESULT (subr)), 6597 subr, 1); 6598 6599 /* Structures that are returned in registers are not aggregate_value_p, 6600 so we may see a PARALLEL. Don't play pseudo games with this. */ 6601 if (! REG_P (hard_reg)) 6602 SET_DECL_RTL (DECL_RESULT (subr), hard_reg); 6603 else 6604 { 6605 /* Create the pseudo. */ 6606 SET_DECL_RTL (DECL_RESULT (subr), gen_reg_rtx (GET_MODE (hard_reg))); 6607 6608 /* Needed because we may need to move this to memory 6609 in case it's a named return value whose address is taken. */ 6610 DECL_REGISTER (DECL_RESULT (subr)) = 1; 6611 } 6612 } 6613 6614 /* Initialize rtx for parameters and local variables. 6615 In some cases this requires emitting insns. */ 6616 6617 assign_parms (subr); 6618 6619 /* Copy the static chain now if it wasn't a register. The delay is to 6620 avoid conflicts with the parameter passing registers. */ 6621 6622 if (SMALL_REGISTER_CLASSES && current_function_needs_context) 6623 if (GET_CODE (static_chain_incoming_rtx) != REG) 6624 emit_move_insn (last_ptr, static_chain_incoming_rtx); 6625 6626 /* The following was moved from init_function_start. 6627 The move is supposed to make sdb output more accurate. */ 6628 /* Indicate the beginning of the function body, 6629 as opposed to parm setup. */ 6630 emit_note (NULL, NOTE_INSN_FUNCTION_BEG); 6631 6632 if (GET_CODE (get_last_insn ()) != NOTE) 6633 emit_note (NULL, NOTE_INSN_DELETED); 6634 parm_birth_insn = get_last_insn (); 6635 6636 context_display = 0; 6637 if (current_function_needs_context) 6638 { 6639 /* Fetch static chain values for containing functions. */ 6640 tem = decl_function_context (current_function_decl); 6641 /* Copy the static chain pointer into a pseudo. If we have 6642 small register classes, copy the value from memory if 6643 static_chain_incoming_rtx is a REG. */ 6644 if (tem) 6645 { 6646 /* If the static chain originally came in a register, put it back 6647 there, then move it out in the next insn. The reason for 6648 this peculiar code is to satisfy function integration. */ 6649 if (SMALL_REGISTER_CLASSES 6650 && GET_CODE (static_chain_incoming_rtx) == REG) 6651 emit_move_insn (static_chain_incoming_rtx, last_ptr); 6652 last_ptr = copy_to_reg (static_chain_incoming_rtx); 6653 } 6654 6655 while (tem) 6656 { 6657 tree rtlexp = make_node (RTL_EXPR); 6658 6659 RTL_EXPR_RTL (rtlexp) = last_ptr; 6660 context_display = tree_cons (tem, rtlexp, context_display); 6661 tem = decl_function_context (tem); 6662 if (tem == 0) 6663 break; 6664 /* Chain thru stack frames, assuming pointer to next lexical frame 6665 is found at the place we always store it. */ 6666 #ifdef FRAME_GROWS_DOWNWARD 6667 last_ptr = plus_constant (last_ptr, 6668 -(HOST_WIDE_INT) GET_MODE_SIZE (Pmode)); 6669 #endif 6670 last_ptr = gen_rtx_MEM (Pmode, memory_address (Pmode, last_ptr)); 6671 set_mem_alias_set (last_ptr, get_frame_alias_set ()); 6672 last_ptr = copy_to_reg (last_ptr); 6673 6674 /* If we are not optimizing, ensure that we know that this 6675 piece of context is live over the entire function. */ 6676 if (! optimize) 6677 save_expr_regs = gen_rtx_EXPR_LIST (VOIDmode, last_ptr, 6678 save_expr_regs); 6679 } 6680 } 6681 6682 if (current_function_instrument_entry_exit) 6683 { 6684 rtx fun = DECL_RTL (current_function_decl); 6685 if (GET_CODE (fun) == MEM) 6686 fun = XEXP (fun, 0); 6687 else 6688 abort (); 6689 emit_library_call (profile_function_entry_libfunc, LCT_NORMAL, VOIDmode, 6690 2, fun, Pmode, 6691 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 6692 0, 6693 hard_frame_pointer_rtx), 6694 Pmode); 6695 } 6696 6697 if (current_function_profile) 6698 { 6699 current_function_profile_label_no = profile_label_no++; 6700 #ifdef PROFILE_HOOK 6701 PROFILE_HOOK (current_function_profile_label_no); 6702 #endif 6703 } 6704 6705 /* After the display initializations is where the tail-recursion label 6706 should go, if we end up needing one. Ensure we have a NOTE here 6707 since some things (like trampolines) get placed before this. */ 6708 tail_recursion_reentry = emit_note (NULL, NOTE_INSN_DELETED); 6709 6710 /* Evaluate now the sizes of any types declared among the arguments. */ 6711 expand_pending_sizes (nreverse (get_pending_sizes ())); 6712 6713 /* Make sure there is a line number after the function entry setup code. */ 6714 force_next_line_note (); 6715 } 6716 6717 /* Undo the effects of init_dummy_function_start. */ 6718 void 6719 expand_dummy_function_end () 6720 { 6721 /* End any sequences that failed to be closed due to syntax errors. */ 6722 while (in_sequence_p ()) 6723 end_sequence (); 6724 6725 /* Outside function body, can't compute type's actual size 6726 until next function's body starts. */ 6727 6728 free_after_parsing (cfun); 6729 free_after_compilation (cfun); 6730 cfun = 0; 6731 } 6732 6733 /* Call DOIT for each hard register used as a return value from 6734 the current function. */ 6735 6736 void 6737 diddle_return_value (doit, arg) 6738 void (*doit) PARAMS ((rtx, void *)); 6739 void *arg; 6740 { 6741 rtx outgoing = current_function_return_rtx; 6742 6743 if (! outgoing) 6744 return; 6745 6746 if (GET_CODE (outgoing) == REG) 6747 (*doit) (outgoing, arg); 6748 else if (GET_CODE (outgoing) == PARALLEL) 6749 { 6750 int i; 6751 6752 for (i = 0; i < XVECLEN (outgoing, 0); i++) 6753 { 6754 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0); 6755 6756 if (GET_CODE (x) == REG && REGNO (x) < FIRST_PSEUDO_REGISTER) 6757 (*doit) (x, arg); 6758 } 6759 } 6760 } 6761 6762 static void 6763 do_clobber_return_reg (reg, arg) 6764 rtx reg; 6765 void *arg ATTRIBUTE_UNUSED; 6766 { 6767 emit_insn (gen_rtx_CLOBBER (VOIDmode, reg)); 6768 } 6769 6770 void 6771 clobber_return_register () 6772 { 6773 diddle_return_value (do_clobber_return_reg, NULL); 6774 6775 /* In case we do use pseudo to return value, clobber it too. */ 6776 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) 6777 { 6778 tree decl_result = DECL_RESULT (current_function_decl); 6779 rtx decl_rtl = DECL_RTL (decl_result); 6780 if (REG_P (decl_rtl) && REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER) 6781 { 6782 do_clobber_return_reg (decl_rtl, NULL); 6783 } 6784 } 6785 } 6786 6787 static void 6788 do_use_return_reg (reg, arg) 6789 rtx reg; 6790 void *arg ATTRIBUTE_UNUSED; 6791 { 6792 emit_insn (gen_rtx_USE (VOIDmode, reg)); 6793 } 6794 6795 void 6796 use_return_register () 6797 { 6798 diddle_return_value (do_use_return_reg, NULL); 6799 } 6800 6801 /* Generate RTL for the end of the current function. 6802 FILENAME and LINE are the current position in the source file. 6803 6804 It is up to language-specific callers to do cleanups for parameters-- 6805 or else, supply 1 for END_BINDINGS and we will call expand_end_bindings. */ 6806 6807 void 6808 expand_function_end (filename, line, end_bindings) 6809 const char *filename; 6810 int line; 6811 int end_bindings; 6812 { 6813 tree link; 6814 rtx clobber_after; 6815 6816 #ifdef TRAMPOLINE_TEMPLATE 6817 static rtx initial_trampoline; 6818 #endif 6819 6820 finish_expr_for_function (); 6821 6822 /* If arg_pointer_save_area was referenced only from a nested 6823 function, we will not have initialized it yet. Do that now. */ 6824 if (arg_pointer_save_area && ! cfun->arg_pointer_save_area_init) 6825 get_arg_pointer_save_area (cfun); 6826 6827 #ifdef NON_SAVING_SETJMP 6828 /* Don't put any variables in registers if we call setjmp 6829 on a machine that fails to restore the registers. */ 6830 if (NON_SAVING_SETJMP && current_function_calls_setjmp) 6831 { 6832 if (DECL_INITIAL (current_function_decl) != error_mark_node) 6833 setjmp_protect (DECL_INITIAL (current_function_decl)); 6834 6835 setjmp_protect_args (); 6836 } 6837 #endif 6838 6839 /* Initialize any trampolines required by this function. */ 6840 for (link = trampoline_list; link; link = TREE_CHAIN (link)) 6841 { 6842 tree function = TREE_PURPOSE (link); 6843 rtx context ATTRIBUTE_UNUSED = lookup_static_chain (function); 6844 rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link)); 6845 #ifdef TRAMPOLINE_TEMPLATE 6846 rtx blktramp; 6847 #endif 6848 rtx seq; 6849 6850 #ifdef TRAMPOLINE_TEMPLATE 6851 /* First make sure this compilation has a template for 6852 initializing trampolines. */ 6853 if (initial_trampoline == 0) 6854 { 6855 initial_trampoline 6856 = gen_rtx_MEM (BLKmode, assemble_trampoline_template ()); 6857 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); 6858 6859 ggc_add_rtx_root (&initial_trampoline, 1); 6860 } 6861 #endif 6862 6863 /* Generate insns to initialize the trampoline. */ 6864 start_sequence (); 6865 tramp = round_trampoline_addr (XEXP (tramp, 0)); 6866 #ifdef TRAMPOLINE_TEMPLATE 6867 blktramp = replace_equiv_address (initial_trampoline, tramp); 6868 emit_block_move (blktramp, initial_trampoline, 6869 GEN_INT (TRAMPOLINE_SIZE)); 6870 #endif 6871 INITIALIZE_TRAMPOLINE (tramp, XEXP (DECL_RTL (function), 0), context); 6872 seq = get_insns (); 6873 end_sequence (); 6874 6875 /* Put those insns at entry to the containing function (this one). */ 6876 emit_insns_before (seq, tail_recursion_reentry); 6877 } 6878 6879 /* If we are doing stack checking and this function makes calls, 6880 do a stack probe at the start of the function to ensure we have enough 6881 space for another stack frame. */ 6882 if (flag_stack_check && ! STACK_CHECK_BUILTIN) 6883 { 6884 rtx insn, seq; 6885 6886 for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) 6887 if (GET_CODE (insn) == CALL_INSN) 6888 { 6889 start_sequence (); 6890 probe_stack_range (STACK_CHECK_PROTECT, 6891 GEN_INT (STACK_CHECK_MAX_FRAME_SIZE)); 6892 seq = get_insns (); 6893 end_sequence (); 6894 emit_insns_before (seq, tail_recursion_reentry); 6895 break; 6896 } 6897 } 6898 6899 /* Warn about unused parms if extra warnings were specified. */ 6900 /* Either ``-W -Wunused'' or ``-Wunused-parameter'' enables this 6901 warning. WARN_UNUSED_PARAMETER is negative when set by 6902 -Wunused. */ 6903 if (warn_unused_parameter > 0 6904 || (warn_unused_parameter < 0 && extra_warnings)) 6905 { 6906 tree decl; 6907 6908 for (decl = DECL_ARGUMENTS (current_function_decl); 6909 decl; decl = TREE_CHAIN (decl)) 6910 if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL 6911 && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) 6912 warning_with_decl (decl, "unused parameter `%s'"); 6913 } 6914 6915 /* Delete handlers for nonlocal gotos if nothing uses them. */ 6916 if (nonlocal_goto_handler_slots != 0 6917 && ! current_function_has_nonlocal_label) 6918 delete_handlers (); 6919 6920 /* End any sequences that failed to be closed due to syntax errors. */ 6921 while (in_sequence_p ()) 6922 end_sequence (); 6923 6924 /* Outside function body, can't compute type's actual size 6925 until next function's body starts. */ 6926 immediate_size_expand--; 6927 6928 clear_pending_stack_adjust (); 6929 do_pending_stack_adjust (); 6930 6931 /* Mark the end of the function body. 6932 If control reaches this insn, the function can drop through 6933 without returning a value. */ 6934 emit_note (NULL, NOTE_INSN_FUNCTION_END); 6935 6936 /* Must mark the last line number note in the function, so that the test 6937 coverage code can avoid counting the last line twice. This just tells 6938 the code to ignore the immediately following line note, since there 6939 already exists a copy of this note somewhere above. This line number 6940 note is still needed for debugging though, so we can't delete it. */ 6941 if (flag_test_coverage) 6942 emit_note (NULL, NOTE_INSN_REPEATED_LINE_NUMBER); 6943 6944 /* Output a linenumber for the end of the function. 6945 SDB depends on this. */ 6946 emit_line_note_force (filename, line); 6947 6948 /* Before the return label (if any), clobber the return 6949 registers so that they are not propagated live to the rest of 6950 the function. This can only happen with functions that drop 6951 through; if there had been a return statement, there would 6952 have either been a return rtx, or a jump to the return label. 6953 6954 We delay actual code generation after the current_function_value_rtx 6955 is computed. */ 6956 clobber_after = get_last_insn (); 6957 6958 /* Output the label for the actual return from the function, 6959 if one is expected. This happens either because a function epilogue 6960 is used instead of a return instruction, or because a return was done 6961 with a goto in order to run local cleanups, or because of pcc-style 6962 structure returning. */ 6963 if (return_label) 6964 emit_label (return_label); 6965 6966 /* C++ uses this. */ 6967 if (end_bindings) 6968 expand_end_bindings (0, 0, 0); 6969 6970 if (current_function_instrument_entry_exit) 6971 { 6972 rtx fun = DECL_RTL (current_function_decl); 6973 if (GET_CODE (fun) == MEM) 6974 fun = XEXP (fun, 0); 6975 else 6976 abort (); 6977 emit_library_call (profile_function_exit_libfunc, LCT_NORMAL, VOIDmode, 6978 2, fun, Pmode, 6979 expand_builtin_return_addr (BUILT_IN_RETURN_ADDRESS, 6980 0, 6981 hard_frame_pointer_rtx), 6982 Pmode); 6983 } 6984 6985 /* Let except.c know where it should emit the call to unregister 6986 the function context for sjlj exceptions. */ 6987 if (flag_exceptions && USING_SJLJ_EXCEPTIONS) 6988 sjlj_emit_function_exit_after (get_last_insn ()); 6989 6990 /* If we had calls to alloca, and this machine needs 6991 an accurate stack pointer to exit the function, 6992 insert some code to save and restore the stack pointer. */ 6993 #ifdef EXIT_IGNORE_STACK 6994 if (! EXIT_IGNORE_STACK) 6995 #endif 6996 if (current_function_calls_alloca) 6997 { 6998 rtx tem = 0; 6999 7000 emit_stack_save (SAVE_FUNCTION, &tem, parm_birth_insn); 7001 emit_stack_restore (SAVE_FUNCTION, tem, NULL_RTX); 7002 } 7003 7004 /* If scalar return value was computed in a pseudo-reg, or was a named 7005 return value that got dumped to the stack, copy that to the hard 7006 return register. */ 7007 if (DECL_RTL_SET_P (DECL_RESULT (current_function_decl))) 7008 { 7009 tree decl_result = DECL_RESULT (current_function_decl); 7010 rtx decl_rtl = DECL_RTL (decl_result); 7011 7012 if (REG_P (decl_rtl) 7013 ? REGNO (decl_rtl) >= FIRST_PSEUDO_REGISTER 7014 : DECL_REGISTER (decl_result)) 7015 { 7016 rtx real_decl_rtl = current_function_return_rtx; 7017 7018 /* This should be set in assign_parms. */ 7019 if (! REG_FUNCTION_VALUE_P (real_decl_rtl)) 7020 abort (); 7021 7022 /* If this is a BLKmode structure being returned in registers, 7023 then use the mode computed in expand_return. Note that if 7024 decl_rtl is memory, then its mode may have been changed, 7025 but that current_function_return_rtx has not. */ 7026 if (GET_MODE (real_decl_rtl) == BLKmode) 7027 PUT_MODE (real_decl_rtl, GET_MODE (decl_rtl)); 7028 7029 /* If a named return value dumped decl_return to memory, then 7030 we may need to re-do the PROMOTE_MODE signed/unsigned 7031 extension. */ 7032 if (GET_MODE (real_decl_rtl) != GET_MODE (decl_rtl)) 7033 { 7034 int unsignedp = TREE_UNSIGNED (TREE_TYPE (decl_result)); 7035 7036 #ifdef PROMOTE_FUNCTION_RETURN 7037 promote_mode (TREE_TYPE (decl_result), GET_MODE (decl_rtl), 7038 &unsignedp, 1); 7039 #endif 7040 7041 convert_move (real_decl_rtl, decl_rtl, unsignedp); 7042 } 7043 else if (GET_CODE (real_decl_rtl) == PARALLEL) 7044 emit_group_load (real_decl_rtl, decl_rtl, 7045 int_size_in_bytes (TREE_TYPE (decl_result))); 7046 else 7047 emit_move_insn (real_decl_rtl, decl_rtl); 7048 } 7049 } 7050 7051 /* If returning a structure, arrange to return the address of the value 7052 in a place where debuggers expect to find it. 7053 7054 If returning a structure PCC style, 7055 the caller also depends on this value. 7056 And current_function_returns_pcc_struct is not necessarily set. */ 7057 if (current_function_returns_struct 7058 || current_function_returns_pcc_struct) 7059 { 7060 rtx value_address 7061 = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0); 7062 tree type = TREE_TYPE (DECL_RESULT (current_function_decl)); 7063 #ifdef FUNCTION_OUTGOING_VALUE 7064 rtx outgoing 7065 = FUNCTION_OUTGOING_VALUE (build_pointer_type (type), 7066 current_function_decl); 7067 #else 7068 rtx outgoing 7069 = FUNCTION_VALUE (build_pointer_type (type), current_function_decl); 7070 #endif 7071 7072 /* Mark this as a function return value so integrate will delete the 7073 assignment and USE below when inlining this function. */ 7074 REG_FUNCTION_VALUE_P (outgoing) = 1; 7075 7076 #ifdef POINTERS_EXTEND_UNSIGNED 7077 /* The address may be ptr_mode and OUTGOING may be Pmode. */ 7078 if (GET_MODE (outgoing) != GET_MODE (value_address)) 7079 value_address = convert_memory_address (GET_MODE (outgoing), 7080 value_address); 7081 #endif 7082 7083 emit_move_insn (outgoing, value_address); 7084 7085 /* Show return register used to hold result (in this case the address 7086 of the result. */ 7087 current_function_return_rtx = outgoing; 7088 } 7089 7090 /* If this is an implementation of throw, do what's necessary to 7091 communicate between __builtin_eh_return and the epilogue. */ 7092 expand_eh_return (); 7093 7094 /* Emit the actual code to clobber return register. */ 7095 { 7096 rtx seq, after; 7097 7098 start_sequence (); 7099 clobber_return_register (); 7100 seq = gen_sequence (); 7101 end_sequence (); 7102 7103 after = emit_insn_after (seq, clobber_after); 7104 7105 if (clobber_after != after) 7106 cfun->x_clobber_return_insn = after; 7107 } 7108 7109 /* ??? This should no longer be necessary since stupid is no longer with 7110 us, but there are some parts of the compiler (eg reload_combine, and 7111 sh mach_dep_reorg) that still try and compute their own lifetime info 7112 instead of using the general framework. */ 7113 use_return_register (); 7114 7115 /* Fix up any gotos that jumped out to the outermost 7116 binding level of the function. 7117 Must follow emitting RETURN_LABEL. */ 7118 7119 /* If you have any cleanups to do at this point, 7120 and they need to create temporary variables, 7121 then you will lose. */ 7122 expand_fixups (get_insns ()); 7123 } 7124 7125 rtx 7126 get_arg_pointer_save_area (f) 7127 struct function *f; 7128 { 7129 rtx ret = f->x_arg_pointer_save_area; 7130 7131 if (! ret) 7132 { 7133 ret = assign_stack_local_1 (Pmode, GET_MODE_SIZE (Pmode), 0, f); 7134 f->x_arg_pointer_save_area = ret; 7135 } 7136 7137 if (f == cfun && ! f->arg_pointer_save_area_init) 7138 { 7139 rtx seq; 7140 7141 /* Save the arg pointer at the beginning of the function. The 7142 generated stack slot may not be a valid memory address, so we 7143 have to check it and fix it if necessary. */ 7144 start_sequence (); 7145 emit_move_insn (validize_mem (ret), virtual_incoming_args_rtx); 7146 seq = gen_sequence (); 7147 end_sequence (); 7148 7149 push_topmost_sequence (); 7150 emit_insn_after (seq, get_insns ()); 7151 pop_topmost_sequence (); 7152 } 7153 7154 return ret; 7155 } 7156 7157 /* Extend a vector that records the INSN_UIDs of INSNS (either a 7158 sequence or a single insn). */ 7159 7160 static void 7161 record_insns (insns, vecp) 7162 rtx insns; 7163 varray_type *vecp; 7164 { 7165 if (GET_CODE (insns) == SEQUENCE) 7166 { 7167 int len = XVECLEN (insns, 0); 7168 int i = VARRAY_SIZE (*vecp); 7169 7170 VARRAY_GROW (*vecp, i + len); 7171 while (--len >= 0) 7172 { 7173 VARRAY_INT (*vecp, i) = INSN_UID (XVECEXP (insns, 0, len)); 7174 ++i; 7175 } 7176 } 7177 else 7178 { 7179 int i = VARRAY_SIZE (*vecp); 7180 VARRAY_GROW (*vecp, i + 1); 7181 VARRAY_INT (*vecp, i) = INSN_UID (insns); 7182 } 7183 } 7184 7185 /* Determine how many INSN_UIDs in VEC are part of INSN. */ 7186 7187 static int 7188 contains (insn, vec) 7189 rtx insn; 7190 varray_type vec; 7191 { 7192 int i, j; 7193 7194 if (GET_CODE (insn) == INSN 7195 && GET_CODE (PATTERN (insn)) == SEQUENCE) 7196 { 7197 int count = 0; 7198 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) 7199 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j) 7200 if (INSN_UID (XVECEXP (PATTERN (insn), 0, i)) == VARRAY_INT (vec, j)) 7201 count++; 7202 return count; 7203 } 7204 else 7205 { 7206 for (j = VARRAY_SIZE (vec) - 1; j >= 0; --j) 7207 if (INSN_UID (insn) == VARRAY_INT (vec, j)) 7208 return 1; 7209 } 7210 return 0; 7211 } 7212 7213 int 7214 prologue_epilogue_contains (insn) 7215 rtx insn; 7216 { 7217 if (contains (insn, prologue)) 7218 return 1; 7219 if (contains (insn, epilogue)) 7220 return 1; 7221 return 0; 7222 } 7223 7224 int 7225 sibcall_epilogue_contains (insn) 7226 rtx insn; 7227 { 7228 if (sibcall_epilogue) 7229 return contains (insn, sibcall_epilogue); 7230 return 0; 7231 } 7232 7233 #ifdef HAVE_return 7234 /* Insert gen_return at the end of block BB. This also means updating 7235 block_for_insn appropriately. */ 7236 7237 static void 7238 emit_return_into_block (bb, line_note) 7239 basic_block bb; 7240 rtx line_note; 7241 { 7242 rtx p, end; 7243 7244 p = NEXT_INSN (bb->end); 7245 end = emit_jump_insn_after (gen_return (), bb->end); 7246 if (line_note) 7247 emit_line_note_after (NOTE_SOURCE_FILE (line_note), 7248 NOTE_LINE_NUMBER (line_note), PREV_INSN (bb->end)); 7249 } 7250 #endif /* HAVE_return */ 7251 7252 #if defined(HAVE_epilogue) && defined(INCOMING_RETURN_ADDR_RTX) 7253 7254 /* These functions convert the epilogue into a variant that does not modify the 7255 stack pointer. This is used in cases where a function returns an object 7256 whose size is not known until it is computed. The called function leaves the 7257 object on the stack, leaves the stack depressed, and returns a pointer to 7258 the object. 7259 7260 What we need to do is track all modifications and references to the stack 7261 pointer, deleting the modifications and changing the references to point to 7262 the location the stack pointer would have pointed to had the modifications 7263 taken place. 7264 7265 These functions need to be portable so we need to make as few assumptions 7266 about the epilogue as we can. However, the epilogue basically contains 7267 three things: instructions to reset the stack pointer, instructions to 7268 reload registers, possibly including the frame pointer, and an 7269 instruction to return to the caller. 7270 7271 If we can't be sure of what a relevant epilogue insn is doing, we abort. 7272 We also make no attempt to validate the insns we make since if they are 7273 invalid, we probably can't do anything valid. The intent is that these 7274 routines get "smarter" as more and more machines start to use them and 7275 they try operating on different epilogues. 7276 7277 We use the following structure to track what the part of the epilogue that 7278 we've already processed has done. We keep two copies of the SP equivalence, 7279 one for use during the insn we are processing and one for use in the next 7280 insn. The difference is because one part of a PARALLEL may adjust SP 7281 and the other may use it. */ 7282 7283 struct epi_info 7284 { 7285 rtx sp_equiv_reg; /* REG that SP is set from, perhaps SP. */ 7286 HOST_WIDE_INT sp_offset; /* Offset from SP_EQUIV_REG of present SP. */ 7287 rtx new_sp_equiv_reg; /* REG to be used at end of insn. */ 7288 HOST_WIDE_INT new_sp_offset; /* Offset to be used at end of insn. */ 7289 rtx equiv_reg_src; /* If nonzero, the value that SP_EQUIV_REG 7290 should be set to once we no longer need 7291 its value. */ 7292 }; 7293 7294 static void handle_epilogue_set PARAMS ((rtx, struct epi_info *)); 7295 static void emit_equiv_load PARAMS ((struct epi_info *)); 7296 7297 /* Modify SEQ, a SEQUENCE that is part of the epilogue, to no modifications 7298 to the stack pointer. Return the new sequence. */ 7299 7300 static rtx 7301 keep_stack_depressed (seq) 7302 rtx seq; 7303 { 7304 int i, j; 7305 struct epi_info info; 7306 7307 /* If the epilogue is just a single instruction, it ust be OK as is. */ 7308 7309 if (GET_CODE (seq) != SEQUENCE) 7310 return seq; 7311 7312 /* Otherwise, start a sequence, initialize the information we have, and 7313 process all the insns we were given. */ 7314 start_sequence (); 7315 7316 info.sp_equiv_reg = stack_pointer_rtx; 7317 info.sp_offset = 0; 7318 info.equiv_reg_src = 0; 7319 7320 for (i = 0; i < XVECLEN (seq, 0); i++) 7321 { 7322 rtx insn = XVECEXP (seq, 0, i); 7323 7324 if (!INSN_P (insn)) 7325 { 7326 add_insn (insn); 7327 continue; 7328 } 7329 7330 /* If this insn references the register that SP is equivalent to and 7331 we have a pending load to that register, we must force out the load 7332 first and then indicate we no longer know what SP's equivalent is. */ 7333 if (info.equiv_reg_src != 0 7334 && reg_referenced_p (info.sp_equiv_reg, PATTERN (insn))) 7335 { 7336 emit_equiv_load (&info); 7337 info.sp_equiv_reg = 0; 7338 } 7339 7340 info.new_sp_equiv_reg = info.sp_equiv_reg; 7341 info.new_sp_offset = info.sp_offset; 7342 7343 /* If this is a (RETURN) and the return address is on the stack, 7344 update the address and change to an indirect jump. */ 7345 if (GET_CODE (PATTERN (insn)) == RETURN 7346 || (GET_CODE (PATTERN (insn)) == PARALLEL 7347 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == RETURN)) 7348 { 7349 rtx retaddr = INCOMING_RETURN_ADDR_RTX; 7350 rtx base = 0; 7351 HOST_WIDE_INT offset = 0; 7352 rtx jump_insn, jump_set; 7353 7354 /* If the return address is in a register, we can emit the insn 7355 unchanged. Otherwise, it must be a MEM and we see what the 7356 base register and offset are. In any case, we have to emit any 7357 pending load to the equivalent reg of SP, if any. */ 7358 if (GET_CODE (retaddr) == REG) 7359 { 7360 emit_equiv_load (&info); 7361 add_insn (insn); 7362 continue; 7363 } 7364 else if (GET_CODE (retaddr) == MEM 7365 && GET_CODE (XEXP (retaddr, 0)) == REG) 7366 base = gen_rtx_REG (Pmode, REGNO (XEXP (retaddr, 0))), offset = 0; 7367 else if (GET_CODE (retaddr) == MEM 7368 && GET_CODE (XEXP (retaddr, 0)) == PLUS 7369 && GET_CODE (XEXP (XEXP (retaddr, 0), 0)) == REG 7370 && GET_CODE (XEXP (XEXP (retaddr, 0), 1)) == CONST_INT) 7371 { 7372 base = gen_rtx_REG (Pmode, REGNO (XEXP (XEXP (retaddr, 0), 0))); 7373 offset = INTVAL (XEXP (XEXP (retaddr, 0), 1)); 7374 } 7375 else 7376 abort (); 7377 7378 /* If the base of the location containing the return pointer 7379 is SP, we must update it with the replacement address. Otherwise, 7380 just build the necessary MEM. */ 7381 retaddr = plus_constant (base, offset); 7382 if (base == stack_pointer_rtx) 7383 retaddr = simplify_replace_rtx (retaddr, stack_pointer_rtx, 7384 plus_constant (info.sp_equiv_reg, 7385 info.sp_offset)); 7386 7387 retaddr = gen_rtx_MEM (Pmode, retaddr); 7388 7389 /* If there is a pending load to the equivalent register for SP 7390 and we reference that register, we must load our address into 7391 a scratch register and then do that load. */ 7392 if (info.equiv_reg_src 7393 && reg_overlap_mentioned_p (info.equiv_reg_src, retaddr)) 7394 { 7395 unsigned int regno; 7396 rtx reg; 7397 7398 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) 7399 if (HARD_REGNO_MODE_OK (regno, Pmode) 7400 && !fixed_regs[regno] 7401 && TEST_HARD_REG_BIT (regs_invalidated_by_call, regno) 7402 && !REGNO_REG_SET_P (EXIT_BLOCK_PTR->global_live_at_start, 7403 regno) 7404 && !refers_to_regno_p (regno, 7405 regno + HARD_REGNO_NREGS (regno, 7406 Pmode), 7407 info.equiv_reg_src, NULL)) 7408 break; 7409 7410 if (regno == FIRST_PSEUDO_REGISTER) 7411 abort (); 7412 7413 reg = gen_rtx_REG (Pmode, regno); 7414 emit_move_insn (reg, retaddr); 7415 retaddr = reg; 7416 } 7417 7418 emit_equiv_load (&info); 7419 jump_insn = emit_jump_insn (gen_indirect_jump (retaddr)); 7420 7421 /* Show the SET in the above insn is a RETURN. */ 7422 jump_set = single_set (jump_insn); 7423 if (jump_set == 0) 7424 abort (); 7425 else 7426 SET_IS_RETURN_P (jump_set) = 1; 7427 } 7428 7429 /* If SP is not mentioned in the pattern and its equivalent register, if 7430 any, is not modified, just emit it. Otherwise, if neither is set, 7431 replace the reference to SP and emit the insn. If none of those are 7432 true, handle each SET individually. */ 7433 else if (!reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)) 7434 && (info.sp_equiv_reg == stack_pointer_rtx 7435 || !reg_set_p (info.sp_equiv_reg, insn))) 7436 add_insn (insn); 7437 else if (! reg_set_p (stack_pointer_rtx, insn) 7438 && (info.sp_equiv_reg == stack_pointer_rtx 7439 || !reg_set_p (info.sp_equiv_reg, insn))) 7440 { 7441 if (! validate_replace_rtx (stack_pointer_rtx, 7442 plus_constant (info.sp_equiv_reg, 7443 info.sp_offset), 7444 insn)) 7445 abort (); 7446 7447 add_insn (insn); 7448 } 7449 else if (GET_CODE (PATTERN (insn)) == SET) 7450 handle_epilogue_set (PATTERN (insn), &info); 7451 else if (GET_CODE (PATTERN (insn)) == PARALLEL) 7452 { 7453 for (j = 0; j < XVECLEN (PATTERN (insn), 0); j++) 7454 if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET) 7455 handle_epilogue_set (XVECEXP (PATTERN (insn), 0, j), &info); 7456 } 7457 else 7458 add_insn (insn); 7459 7460 info.sp_equiv_reg = info.new_sp_equiv_reg; 7461 info.sp_offset = info.new_sp_offset; 7462 } 7463 7464 seq = gen_sequence (); 7465 end_sequence (); 7466 return seq; 7467 } 7468 7469 /* SET is a SET from an insn in the epilogue. P is a pointer to the epi_info 7470 structure that contains information about what we've seen so far. We 7471 process this SET by either updating that data or by emitting one or 7472 more insns. */ 7473 7474 static void 7475 handle_epilogue_set (set, p) 7476 rtx set; 7477 struct epi_info *p; 7478 { 7479 /* First handle the case where we are setting SP. Record what it is being 7480 set from. If unknown, abort. */ 7481 if (reg_set_p (stack_pointer_rtx, set)) 7482 { 7483 if (SET_DEST (set) != stack_pointer_rtx) 7484 abort (); 7485 7486 if (GET_CODE (SET_SRC (set)) == PLUS 7487 && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT) 7488 { 7489 p->new_sp_equiv_reg = XEXP (SET_SRC (set), 0); 7490 p->new_sp_offset = INTVAL (XEXP (SET_SRC (set), 1)); 7491 } 7492 else 7493 p->new_sp_equiv_reg = SET_SRC (set), p->new_sp_offset = 0; 7494 7495 /* If we are adjusting SP, we adjust from the old data. */ 7496 if (p->new_sp_equiv_reg == stack_pointer_rtx) 7497 { 7498 p->new_sp_equiv_reg = p->sp_equiv_reg; 7499 p->new_sp_offset += p->sp_offset; 7500 } 7501 7502 if (p->new_sp_equiv_reg == 0 || GET_CODE (p->new_sp_equiv_reg) != REG) 7503 abort (); 7504 7505 return; 7506 } 7507 7508 /* Next handle the case where we are setting SP's equivalent register. 7509 If we already have a value to set it to, abort. We could update, but 7510 there seems little point in handling that case. Note that we have 7511 to allow for the case where we are setting the register set in 7512 the previous part of a PARALLEL inside a single insn. But use the 7513 old offset for any updates within this insn. */ 7514 else if (p->new_sp_equiv_reg != 0 && reg_set_p (p->new_sp_equiv_reg, set)) 7515 { 7516 if (!rtx_equal_p (p->new_sp_equiv_reg, SET_DEST (set)) 7517 || p->equiv_reg_src != 0) 7518 abort (); 7519 else 7520 p->equiv_reg_src 7521 = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx, 7522 plus_constant (p->sp_equiv_reg, 7523 p->sp_offset)); 7524 } 7525 7526 /* Otherwise, replace any references to SP in the insn to its new value 7527 and emit the insn. */ 7528 else 7529 { 7530 SET_SRC (set) = simplify_replace_rtx (SET_SRC (set), stack_pointer_rtx, 7531 plus_constant (p->sp_equiv_reg, 7532 p->sp_offset)); 7533 SET_DEST (set) = simplify_replace_rtx (SET_DEST (set), stack_pointer_rtx, 7534 plus_constant (p->sp_equiv_reg, 7535 p->sp_offset)); 7536 emit_insn (set); 7537 } 7538 } 7539 7540 /* Emit an insn to do the load shown in p->equiv_reg_src, if needed. */ 7541 7542 static void 7543 emit_equiv_load (p) 7544 struct epi_info *p; 7545 { 7546 if (p->equiv_reg_src != 0) 7547 emit_move_insn (p->sp_equiv_reg, p->equiv_reg_src); 7548 7549 p->equiv_reg_src = 0; 7550 } 7551 #endif 7552 7553 /* Generate the prologue and epilogue RTL if the machine supports it. Thread 7554 this into place with notes indicating where the prologue ends and where 7555 the epilogue begins. Update the basic block information when possible. */ 7556 7557 void 7558 thread_prologue_and_epilogue_insns (f) 7559 rtx f ATTRIBUTE_UNUSED; 7560 { 7561 int inserted = 0; 7562 edge e; 7563 #if defined (HAVE_sibcall_epilogue) || defined (HAVE_epilogue) || defined (HAVE_return) || defined (HAVE_prologue) 7564 rtx seq; 7565 #endif 7566 #ifdef HAVE_prologue 7567 rtx prologue_end = NULL_RTX; 7568 #endif 7569 #if defined (HAVE_epilogue) || defined(HAVE_return) 7570 rtx epilogue_end = NULL_RTX; 7571 #endif 7572 7573 #ifdef HAVE_prologue 7574 if (HAVE_prologue) 7575 { 7576 start_sequence (); 7577 seq = gen_prologue (); 7578 emit_insn (seq); 7579 7580 /* Retain a map of the prologue insns. */ 7581 if (GET_CODE (seq) != SEQUENCE) 7582 seq = get_insns (); 7583 record_insns (seq, &prologue); 7584 prologue_end = emit_note (NULL, NOTE_INSN_PROLOGUE_END); 7585 7586 seq = gen_sequence (); 7587 end_sequence (); 7588 7589 /* Can't deal with multiple successors of the entry block 7590 at the moment. Function should always have at least one 7591 entry point. */ 7592 if (!ENTRY_BLOCK_PTR->succ || ENTRY_BLOCK_PTR->succ->succ_next) 7593 abort (); 7594 7595 insert_insn_on_edge (seq, ENTRY_BLOCK_PTR->succ); 7596 inserted = 1; 7597 } 7598 #endif 7599 7600 /* If the exit block has no non-fake predecessors, we don't need 7601 an epilogue. */ 7602 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7603 if ((e->flags & EDGE_FAKE) == 0) 7604 break; 7605 if (e == NULL) 7606 goto epilogue_done; 7607 7608 #ifdef HAVE_return 7609 if (optimize && HAVE_return) 7610 { 7611 /* If we're allowed to generate a simple return instruction, 7612 then by definition we don't need a full epilogue. Examine 7613 the block that falls through to EXIT. If it does not 7614 contain any code, examine its predecessors and try to 7615 emit (conditional) return instructions. */ 7616 7617 basic_block last; 7618 edge e_next; 7619 rtx label; 7620 7621 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7622 if (e->flags & EDGE_FALLTHRU) 7623 break; 7624 if (e == NULL) 7625 goto epilogue_done; 7626 last = e->src; 7627 7628 /* Verify that there are no active instructions in the last block. */ 7629 label = last->end; 7630 while (label && GET_CODE (label) != CODE_LABEL) 7631 { 7632 if (active_insn_p (label)) 7633 break; 7634 label = PREV_INSN (label); 7635 } 7636 7637 if (last->head == label && GET_CODE (label) == CODE_LABEL) 7638 { 7639 rtx epilogue_line_note = NULL_RTX; 7640 7641 /* Locate the line number associated with the closing brace, 7642 if we can find one. */ 7643 for (seq = get_last_insn (); 7644 seq && ! active_insn_p (seq); 7645 seq = PREV_INSN (seq)) 7646 if (GET_CODE (seq) == NOTE && NOTE_LINE_NUMBER (seq) > 0) 7647 { 7648 epilogue_line_note = seq; 7649 break; 7650 } 7651 7652 for (e = last->pred; e; e = e_next) 7653 { 7654 basic_block bb = e->src; 7655 rtx jump; 7656 7657 e_next = e->pred_next; 7658 if (bb == ENTRY_BLOCK_PTR) 7659 continue; 7660 7661 jump = bb->end; 7662 if ((GET_CODE (jump) != JUMP_INSN) || JUMP_LABEL (jump) != label) 7663 continue; 7664 7665 /* If we have an unconditional jump, we can replace that 7666 with a simple return instruction. */ 7667 if (simplejump_p (jump)) 7668 { 7669 emit_return_into_block (bb, epilogue_line_note); 7670 delete_insn (jump); 7671 } 7672 7673 /* If we have a conditional jump, we can try to replace 7674 that with a conditional return instruction. */ 7675 else if (condjump_p (jump)) 7676 { 7677 rtx ret, *loc; 7678 7679 ret = SET_SRC (PATTERN (jump)); 7680 if (GET_CODE (XEXP (ret, 1)) == LABEL_REF) 7681 loc = &XEXP (ret, 1); 7682 else 7683 loc = &XEXP (ret, 2); 7684 ret = gen_rtx_RETURN (VOIDmode); 7685 7686 if (! validate_change (jump, loc, ret, 0)) 7687 continue; 7688 if (JUMP_LABEL (jump)) 7689 LABEL_NUSES (JUMP_LABEL (jump))--; 7690 7691 /* If this block has only one successor, it both jumps 7692 and falls through to the fallthru block, so we can't 7693 delete the edge. */ 7694 if (bb->succ->succ_next == NULL) 7695 continue; 7696 } 7697 else 7698 continue; 7699 7700 /* Fix up the CFG for the successful change we just made. */ 7701 redirect_edge_succ (e, EXIT_BLOCK_PTR); 7702 } 7703 7704 /* Emit a return insn for the exit fallthru block. Whether 7705 this is still reachable will be determined later. */ 7706 7707 emit_barrier_after (last->end); 7708 emit_return_into_block (last, epilogue_line_note); 7709 epilogue_end = last->end; 7710 last->succ->flags &= ~EDGE_FALLTHRU; 7711 goto epilogue_done; 7712 } 7713 } 7714 #endif 7715 #ifdef HAVE_epilogue 7716 if (HAVE_epilogue) 7717 { 7718 /* Find the edge that falls through to EXIT. Other edges may exist 7719 due to RETURN instructions, but those don't need epilogues. 7720 There really shouldn't be a mixture -- either all should have 7721 been converted or none, however... */ 7722 7723 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7724 if (e->flags & EDGE_FALLTHRU) 7725 break; 7726 if (e == NULL) 7727 goto epilogue_done; 7728 7729 start_sequence (); 7730 epilogue_end = emit_note (NULL, NOTE_INSN_EPILOGUE_BEG); 7731 7732 seq = gen_epilogue (); 7733 7734 #ifdef INCOMING_RETURN_ADDR_RTX 7735 /* If this function returns with the stack depressed and we can support 7736 it, massage the epilogue to actually do that. */ 7737 if (TREE_CODE (TREE_TYPE (current_function_decl)) == FUNCTION_TYPE 7738 && TYPE_RETURNS_STACK_DEPRESSED (TREE_TYPE (current_function_decl))) 7739 seq = keep_stack_depressed (seq); 7740 #endif 7741 7742 emit_jump_insn (seq); 7743 7744 /* Retain a map of the epilogue insns. */ 7745 if (GET_CODE (seq) != SEQUENCE) 7746 seq = get_insns (); 7747 record_insns (seq, &epilogue); 7748 7749 seq = gen_sequence (); 7750 end_sequence (); 7751 7752 insert_insn_on_edge (seq, e); 7753 inserted = 1; 7754 } 7755 #endif 7756 epilogue_done: 7757 7758 if (inserted) 7759 commit_edge_insertions (); 7760 7761 #ifdef HAVE_sibcall_epilogue 7762 /* Emit sibling epilogues before any sibling call sites. */ 7763 for (e = EXIT_BLOCK_PTR->pred; e; e = e->pred_next) 7764 { 7765 basic_block bb = e->src; 7766 rtx insn = bb->end; 7767 rtx i; 7768 rtx newinsn; 7769 7770 if (GET_CODE (insn) != CALL_INSN 7771 || ! SIBLING_CALL_P (insn)) 7772 continue; 7773 7774 start_sequence (); 7775 seq = gen_sibcall_epilogue (); 7776 end_sequence (); 7777 7778 i = PREV_INSN (insn); 7779 newinsn = emit_insn_before (seq, insn); 7780 7781 /* Retain a map of the epilogue insns. Used in life analysis to 7782 avoid getting rid of sibcall epilogue insns. */ 7783 record_insns (GET_CODE (seq) == SEQUENCE 7784 ? seq : newinsn, &sibcall_epilogue); 7785 } 7786 #endif 7787 7788 #ifdef HAVE_prologue 7789 if (prologue_end) 7790 { 7791 rtx insn, prev; 7792 7793 /* GDB handles `break f' by setting a breakpoint on the first 7794 line note after the prologue. Which means (1) that if 7795 there are line number notes before where we inserted the 7796 prologue we should move them, and (2) we should generate a 7797 note before the end of the first basic block, if there isn't 7798 one already there. 7799 7800 ??? This behaviour is completely broken when dealing with 7801 multiple entry functions. We simply place the note always 7802 into first basic block and let alternate entry points 7803 to be missed. 7804 */ 7805 7806 for (insn = prologue_end; insn; insn = prev) 7807 { 7808 prev = PREV_INSN (insn); 7809 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7810 { 7811 /* Note that we cannot reorder the first insn in the 7812 chain, since rest_of_compilation relies on that 7813 remaining constant. */ 7814 if (prev == NULL) 7815 break; 7816 reorder_insns (insn, insn, prologue_end); 7817 } 7818 } 7819 7820 /* Find the last line number note in the first block. */ 7821 for (insn = BASIC_BLOCK (0)->end; 7822 insn != prologue_end && insn; 7823 insn = PREV_INSN (insn)) 7824 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7825 break; 7826 7827 /* If we didn't find one, make a copy of the first line number 7828 we run across. */ 7829 if (! insn) 7830 { 7831 for (insn = next_active_insn (prologue_end); 7832 insn; 7833 insn = PREV_INSN (insn)) 7834 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7835 { 7836 emit_line_note_after (NOTE_SOURCE_FILE (insn), 7837 NOTE_LINE_NUMBER (insn), 7838 prologue_end); 7839 break; 7840 } 7841 } 7842 } 7843 #endif 7844 #ifdef HAVE_epilogue 7845 if (epilogue_end) 7846 { 7847 rtx insn, next; 7848 7849 /* Similarly, move any line notes that appear after the epilogue. 7850 There is no need, however, to be quite so anal about the existence 7851 of such a note. */ 7852 for (insn = epilogue_end; insn; insn = next) 7853 { 7854 next = NEXT_INSN (insn); 7855 if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0) 7856 reorder_insns (insn, insn, PREV_INSN (epilogue_end)); 7857 } 7858 } 7859 #endif 7860 } 7861 7862 /* Reposition the prologue-end and epilogue-begin notes after instruction 7863 scheduling and delayed branch scheduling. */ 7864 7865 void 7866 reposition_prologue_and_epilogue_notes (f) 7867 rtx f ATTRIBUTE_UNUSED; 7868 { 7869 #if defined (HAVE_prologue) || defined (HAVE_epilogue) 7870 rtx insn, last, note; 7871 int len; 7872 7873 if ((len = VARRAY_SIZE (prologue)) > 0) 7874 { 7875 last = 0, note = 0; 7876 7877 /* Scan from the beginning until we reach the last prologue insn. 7878 We apparently can't depend on basic_block_{head,end} after 7879 reorg has run. */ 7880 for (insn = f; insn; insn = NEXT_INSN (insn)) 7881 { 7882 if (GET_CODE (insn) == NOTE) 7883 { 7884 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_PROLOGUE_END) 7885 note = insn; 7886 } 7887 else if (contains (insn, prologue)) 7888 { 7889 last = insn; 7890 if (--len == 0) 7891 break; 7892 } 7893 } 7894 7895 if (last) 7896 { 7897 rtx next; 7898 7899 /* Find the prologue-end note if we haven't already, and 7900 move it to just after the last prologue insn. */ 7901 if (note == 0) 7902 { 7903 for (note = last; (note = NEXT_INSN (note));) 7904 if (GET_CODE (note) == NOTE 7905 && NOTE_LINE_NUMBER (note) == NOTE_INSN_PROLOGUE_END) 7906 break; 7907 } 7908 7909 next = NEXT_INSN (note); 7910 7911 /* Avoid placing note between CODE_LABEL and BASIC_BLOCK note. */ 7912 if (GET_CODE (last) == CODE_LABEL) 7913 last = NEXT_INSN (last); 7914 reorder_insns (note, note, last); 7915 } 7916 } 7917 7918 if ((len = VARRAY_SIZE (epilogue)) > 0) 7919 { 7920 last = 0, note = 0; 7921 7922 /* Scan from the end until we reach the first epilogue insn. 7923 We apparently can't depend on basic_block_{head,end} after 7924 reorg has run. */ 7925 for (insn = get_last_insn (); insn; insn = PREV_INSN (insn)) 7926 { 7927 if (GET_CODE (insn) == NOTE) 7928 { 7929 if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG) 7930 note = insn; 7931 } 7932 else if (contains (insn, epilogue)) 7933 { 7934 last = insn; 7935 if (--len == 0) 7936 break; 7937 } 7938 } 7939 7940 if (last) 7941 { 7942 /* Find the epilogue-begin note if we haven't already, and 7943 move it to just before the first epilogue insn. */ 7944 if (note == 0) 7945 { 7946 for (note = insn; (note = PREV_INSN (note));) 7947 if (GET_CODE (note) == NOTE 7948 && NOTE_LINE_NUMBER (note) == NOTE_INSN_EPILOGUE_BEG) 7949 break; 7950 } 7951 7952 if (PREV_INSN (last) != note) 7953 reorder_insns (note, note, PREV_INSN (last)); 7954 } 7955 } 7956 #endif /* HAVE_prologue or HAVE_epilogue */ 7957 } 7958 7959 /* Mark P for GC. */ 7960 7961 static void 7962 mark_function_status (p) 7963 struct function *p; 7964 { 7965 struct var_refs_queue *q; 7966 struct temp_slot *t; 7967 int i; 7968 rtx *r; 7969 7970 if (p == 0) 7971 return; 7972 7973 ggc_mark_rtx (p->arg_offset_rtx); 7974 7975 if (p->x_parm_reg_stack_loc) 7976 for (i = p->x_max_parm_reg, r = p->x_parm_reg_stack_loc; 7977 i > 0; --i, ++r) 7978 ggc_mark_rtx (*r); 7979 7980 ggc_mark_rtx (p->return_rtx); 7981 ggc_mark_rtx (p->x_cleanup_label); 7982 ggc_mark_rtx (p->x_return_label); 7983 ggc_mark_rtx (p->x_save_expr_regs); 7984 ggc_mark_rtx (p->x_stack_slot_list); 7985 ggc_mark_rtx (p->x_parm_birth_insn); 7986 ggc_mark_rtx (p->x_tail_recursion_label); 7987 ggc_mark_rtx (p->x_tail_recursion_reentry); 7988 ggc_mark_rtx (p->internal_arg_pointer); 7989 ggc_mark_rtx (p->x_arg_pointer_save_area); 7990 ggc_mark_tree (p->x_rtl_expr_chain); 7991 ggc_mark_rtx (p->x_last_parm_insn); 7992 ggc_mark_tree (p->x_context_display); 7993 ggc_mark_tree (p->x_trampoline_list); 7994 ggc_mark_rtx (p->epilogue_delay_list); 7995 ggc_mark_rtx (p->x_clobber_return_insn); 7996 7997 for (t = p->x_temp_slots; t != 0; t = t->next) 7998 { 7999 ggc_mark (t); 8000 ggc_mark_rtx (t->slot); 8001 ggc_mark_rtx (t->address); 8002 ggc_mark_tree (t->rtl_expr); 8003 ggc_mark_tree (t->type); 8004 } 8005 8006 for (q = p->fixup_var_refs_queue; q != 0; q = q->next) 8007 { 8008 ggc_mark (q); 8009 ggc_mark_rtx (q->modified); 8010 } 8011 8012 ggc_mark_rtx (p->x_nonlocal_goto_handler_slots); 8013 ggc_mark_rtx (p->x_nonlocal_goto_handler_labels); 8014 ggc_mark_rtx (p->x_nonlocal_goto_stack_level); 8015 ggc_mark_tree (p->x_nonlocal_labels); 8016 8017 mark_hard_reg_initial_vals (p); 8018 } 8019 8020 /* Mark the struct function pointed to by *ARG for GC, if it is not 8021 NULL. This is used to mark the current function and the outer 8022 function chain. */ 8023 8024 static void 8025 maybe_mark_struct_function (arg) 8026 void *arg; 8027 { 8028 struct function *f = *(struct function **) arg; 8029 8030 if (f == 0) 8031 return; 8032 8033 ggc_mark_struct_function (f); 8034 } 8035 8036 /* Mark a struct function * for GC. This is called from ggc-common.c. */ 8037 8038 void 8039 ggc_mark_struct_function (f) 8040 struct function *f; 8041 { 8042 ggc_mark (f); 8043 ggc_mark_tree (f->decl); 8044 8045 mark_function_status (f); 8046 mark_eh_status (f->eh); 8047 mark_stmt_status (f->stmt); 8048 mark_expr_status (f->expr); 8049 mark_emit_status (f->emit); 8050 mark_varasm_status (f->varasm); 8051 8052 if (mark_machine_status) 8053 (*mark_machine_status) (f); 8054 if (mark_lang_status) 8055 (*mark_lang_status) (f); 8056 8057 if (f->original_arg_vector) 8058 ggc_mark_rtvec ((rtvec) f->original_arg_vector); 8059 if (f->original_decl_initial) 8060 ggc_mark_tree (f->original_decl_initial); 8061 if (f->outer) 8062 ggc_mark_struct_function (f->outer); 8063 } 8064 8065 /* Called once, at initialization, to initialize function.c. */ 8066 8067 void 8068 init_function_once () 8069 { 8070 ggc_add_root (&cfun, 1, sizeof cfun, maybe_mark_struct_function); 8071 ggc_add_root (&outer_function_chain, 1, sizeof outer_function_chain, 8072 maybe_mark_struct_function); 8073 8074 VARRAY_INT_INIT (prologue, 0, "prologue"); 8075 VARRAY_INT_INIT (epilogue, 0, "epilogue"); 8076 VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue"); 8077 } 8078