home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / function.c < prev    next >
C/C++ Source or Header  |  1992-03-17  |  121KB  |  3,779 lines

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file handles the generation of rtl code from tree structure
  22.    at the level of the function as a whole.
  23.    It creates the rtl expressions for parameters and auto variables
  24.    and has full responsibility for allocating stack slots.
  25.  
  26.    `expand_function_start' is called at the beginning of a function,
  27.    before the function body is parsed, and `expand_function_end' is
  28.    called after parsing the body.
  29.  
  30.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  31.    This is usually done during the RTL generation for the function body,
  32.    but it can also be done in the reload pass when a pseudo-register does
  33.    not get a hard register.
  34.  
  35.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  36.    previously given a pseudo-register must in fact go in the stack.
  37.    This function changes the DECL_RTL to be a stack slot instead of a reg
  38.    then scans all the RTL instructions so far generated to correct them.  */
  39.  
  40. #include "config.h"
  41.  
  42. #include <stdio.h>
  43.  
  44. #include "rtl.h"
  45. #include "tree.h"
  46. #include "flags.h"
  47. #include "function.h"
  48. #include "insn-flags.h"
  49. #include "expr.h"
  50. #include "insn-codes.h"
  51. #include "regs.h"
  52. #include "hard-reg-set.h"
  53. #include "insn-config.h"
  54. #include "recog.h"
  55. #include "output.h"
  56.  
  57. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  58. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  59.  
  60. /* Round a value to the lowest integer less than it that is a multiple of
  61.    the required alignment.  Avoid using division in case the value is
  62.    negative.  Assume the alignment is a power of two.  */
  63. #define FLOOR_ROUND(VALUE,ALIGN) ((VALUE) & ~((ALIGN) - 1))
  64.  
  65. /* Similar, but round to the next highest integer that meets the
  66.    alignment.  */
  67. #define CEIL_ROUND(VALUE,ALIGN)    (((VALUE) + (ALIGN) - 1) & ~((ALIGN)- 1))
  68.  
  69. /* NEED_SEPARATE_AP means that we cannot derive ap from the value of fp
  70.    during rtl generation.  If they are different register numbers, this is
  71.    always true.  It may also be true if
  72.    FIRST_PARM_OFFSET - STARTING_FRAME_OFFSET is not a constant during rtl
  73.    generation.  See fix_lexical_addr for details.  */
  74.  
  75. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  76. #define NEED_SEPARATE_AP
  77. #endif
  78.  
  79. /* Number of bytes of args popped by function being compiled on its return.
  80.    Zero if no bytes are to be popped.
  81.    May affect compilation of return insn or of function epilogue.  */
  82.  
  83. int current_function_pops_args;
  84.  
  85. /* Nonzero if function being compiled needs to be given an address
  86.    where the value should be stored.  */
  87.  
  88. int current_function_returns_struct;
  89.  
  90. /* Nonzero if function being compiled needs to
  91.    return the address of where it has put a structure value.  */
  92.  
  93. int current_function_returns_pcc_struct;
  94.  
  95. /* Nonzero if function being compiled needs to be passed a static chain.  */
  96.  
  97. int current_function_needs_context;
  98.  
  99. /* Nonzero if function being compiled can call setjmp.  */
  100.  
  101. int current_function_calls_setjmp;
  102.  
  103. /* Nonzero if function being compiled receives nonlocal gotos
  104.    from nested functions.  */
  105.  
  106. int current_function_has_nonlocal_label;
  107.  
  108. /* Nonzero if function being compiled contains nested functions.  */
  109.  
  110. int current_function_contains_functions;
  111.  
  112. /* Nonzero if function being compiled can call alloca,
  113.    either as a subroutine or builtin.  */
  114.  
  115. int current_function_calls_alloca;
  116.  
  117. /* Nonzero if the current function returns a pointer type */
  118.  
  119. int current_function_returns_pointer;
  120.  
  121. /* If some insns can be deferred to the delay slots of the epilogue, the
  122.    delay list for them is recorded here.  */
  123.  
  124. rtx current_function_epilogue_delay_list;
  125.  
  126. /* If function's args have a fixed size, this is that size, in bytes.
  127.    Otherwise, it is -1.
  128.    May affect compilation of return insn or of function epilogue.  */
  129.  
  130. int current_function_args_size;
  131.  
  132. /* # bytes the prologue should push and pretend that the caller pushed them.
  133.    The prologue must do this, but only if parms can be passed in registers.  */
  134.  
  135. int current_function_pretend_args_size;
  136.  
  137. /* # of bytes of outgoing arguments required to be pushed by the prologue.
  138.    If this is non-zero, it means that ACCUMULATE_OUTGOING_ARGS was defined
  139.    and no stack adjusts will be done on function calls.  */
  140.  
  141. int current_function_outgoing_args_size;
  142.  
  143. /* This is the offset from the arg pointer to the place where the first
  144.    anonymous arg can be found, if there is one.  */
  145.  
  146. rtx current_function_arg_offset_rtx;
  147.  
  148. /* Nonzero if current function uses varargs.h or equivalent.
  149.    Zero for functions that use stdarg.h.  */
  150.  
  151. int current_function_varargs;
  152.  
  153. /* Name of function now being compiled.  */
  154.  
  155. char *current_function_name;
  156.  
  157. /* If non-zero, an RTL expression for that location at which the current
  158.    function returns its result.  Usually equal to
  159.    DECL_RTL (DECL_RESULT (current_function_decl)).  */
  160.  
  161. rtx current_function_return_rtx;
  162.  
  163. /* Nonzero if the current function uses the constant pool.  */
  164.  
  165. int current_function_uses_const_pool;
  166.  
  167. /* Number of function calls seen so far in current function.  */
  168.  
  169. int function_call_count;
  170.  
  171. /* List (chain of TREE_LIST) of LABEL_DECLs for all nonlocal labels
  172.    (labels to which there can be nonlocal gotos from nested functions)
  173.    in this function.  */
  174.  
  175. tree nonlocal_labels;
  176.  
  177. /* RTX for stack slot that holds the current handler for nonlocal gotos.
  178.    Zero when function does not have nonlocal labels.  */
  179.  
  180. rtx nonlocal_goto_handler_slot;
  181.  
  182. /* RTX for stack slot that holds the stack pointer value to restore
  183.    for a nonlocal goto.
  184.    Zero when function does not have nonlocal labels.  */
  185.  
  186. rtx nonlocal_goto_stack_level;
  187.  
  188. /* Label that will go on parm cleanup code, if any.
  189.    Jumping to this label runs cleanup code for parameters, if
  190.    such code must be run.  Following this code is the logical return label.  */
  191.  
  192. rtx cleanup_label;
  193.  
  194. /* Label that will go on function epilogue.
  195.    Jumping to this label serves as a "return" instruction
  196.    on machines which require execution of the epilogue on all returns.  */
  197.  
  198. rtx return_label;
  199.  
  200. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  201.    So we can mark them all live at the end of the function, if nonopt.  */
  202. rtx save_expr_regs;
  203.  
  204. /* List (chain of EXPR_LISTs) of all stack slots in this function.
  205.    Made for the sake of unshare_all_rtl.  */
  206. rtx stack_slot_list;
  207.  
  208. /* Chain of all RTL_EXPRs that have insns in them.  */
  209. tree rtl_expr_chain;
  210.  
  211. /* Label to jump back to for tail recursion, or 0 if we have
  212.    not yet needed one for this function.  */
  213. rtx tail_recursion_label;
  214.  
  215. /* Place after which to insert the tail_recursion_label if we need one.  */
  216. rtx tail_recursion_reentry;
  217.  
  218. /* Location at which to save the argument pointer if it will need to be
  219.    referenced.  There are two cases where this is done: if nonlocal gotos
  220.    exist, or if vars stored at an offset from the argument pointer will be
  221.    needed by inner routines.  */
  222.  
  223. rtx arg_pointer_save_area;
  224.  
  225. /* Offset to end of allocated area of stack frame.
  226.    If stack grows down, this is the address of the last stack slot allocated.
  227.    If stack grows up, this is the address for the next slot.  */
  228. int frame_offset;
  229.  
  230. /* List (chain of EXPR_LISTs) of static chains for containing functions.
  231.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  232.    in an RTL_EXPR in the TREE_VALUE.  */
  233. static tree context_display;
  234.  
  235. /* List (chain of EXPR_LISTs) of trampolines for nested functions.
  236.    The trampoline sets up the static chain and jumps to the function.
  237.    We supply the trampoline's address when the function's address is requested.
  238.  
  239.    Each link has a FUNCTION_DECL in the TREE_PURPOSE and a reg rtx
  240.    in an RTL_EXPR in the TREE_VALUE.  */
  241. static tree trampoline_list;
  242.  
  243. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  244. static rtx parm_birth_insn;
  245.  
  246. #if 0
  247. /* Nonzero if a stack slot has been generated whose address is not
  248.    actually valid.  It means that the generated rtl must all be scanned
  249.    to detect and correct the invalid addresses where they occur.  */
  250. static int invalid_stack_slot;
  251. #endif
  252.  
  253. /* Last insn of those whose job was to put parms into their nominal homes.  */
  254. static rtx last_parm_insn;
  255.  
  256. /* 1 + last pseudo register number used for loading a copy
  257.    of a parameter of this function.  */
  258. static int max_parm_reg;
  259.  
  260. /* Vector indexed by REGNO, containing location on stack in which
  261.    to put the parm which is nominally in pseudo register REGNO,
  262.    if we discover that that parm must go in the stack.  */
  263. static rtx *parm_reg_stack_loc;
  264.  
  265. #if 0  /* Turned off because 0 seems to work just as well.  */
  266. /* Cleanup lists are required for binding levels regardless of whether
  267.    that binding level has cleanups or not.  This node serves as the
  268.    cleanup list whenever an empty list is required.  */
  269. static tree empty_cleanup_list;
  270. #endif
  271.  
  272. /* Nonzero once virtual register instantiation has been done.
  273.    assign_stack_local uses frame_pointer_rtx when this is nonzero.  */
  274. static int virtuals_instantiated;
  275.  
  276. /* Nonzero if we need to distinguish between the return value of this function
  277.    and the return value of a function called by this function.  This helps
  278.    integrate.c  */
  279.  
  280. extern int rtx_equal_function_value_matters;
  281.  
  282. void fixup_gotos ();
  283.  
  284. static rtx round_trampoline_addr ();
  285. static rtx fixup_stack_1 ();
  286. static void fixup_var_refs ();
  287. static void fixup_var_refs_insns ();
  288. static void fixup_var_refs_1 ();
  289. static void optimize_bit_field ();
  290. static void instantiate_decls ();
  291. static void instantiate_decls_1 ();
  292. static void instantiate_virtual_regs_1 ();
  293. static rtx fixup_memory_subreg ();
  294. static rtx walk_fixup_memory_subreg ();
  295.  
  296. /* In order to evaluate some expressions, such as function calls returning
  297.    structures in memory, we need to temporarily allocate stack locations.
  298.    We record each allocated temporary in the following structure.
  299.  
  300.    Associated with each temporary slot is a nesting level.  When we pop up
  301.    one level, all temporaries associated with the previous level are freed.
  302.    Normally, all temporaries are freed after the execution of the statement
  303.    in which they were created.  However, if we are inside a ({...}) grouping,
  304.    the result may be in a temporary and hence must be preserved.  If the
  305.    result could be in a temporary, we preserve it if we can determine which
  306.    one it is in.  If we cannot determine which temporary may contain the
  307.    result, all temporaries are preserved.  A temporary is preserved by
  308.    pretending it was allocated at the previous nesting level.
  309.  
  310.    Automatic variables are also assigned temporary slots, at the nesting
  311.    level where they are defined.  They are marked a "kept" so that
  312.    free_temp_slots will not free them.  */
  313.  
  314. struct temp_slot
  315. {
  316.   /* Points to next temporary slot.  */
  317.   struct temp_slot *next;
  318.   /* The rtx to used to reference the slot. */
  319.   rtx slot;
  320.   /* The size, in units, of the slot.  */
  321.   int size;
  322.   /* Non-zero if this temporary is currently in use.  */
  323.   char in_use;
  324.   /* Nesting level at which this slot is being used.  */
  325.   int level;
  326.   /* Non-zero if this should survive a call to free_temp_slots.  */
  327.   int keep;
  328. };
  329.  
  330. /* List of all temporaries allocated, both available and in use.  */
  331.  
  332. struct temp_slot *temp_slots;
  333.  
  334. /* Current nesting level for temporaries.  */
  335.  
  336. int temp_slot_level;
  337.  
  338. /* Pointer to chain of `struct function' for containing functions.  */
  339. struct function *outer_function_chain;
  340.  
  341. /* Given a function decl for a containing function,
  342.    return the `struct function' for it.  */
  343.  
  344. struct function *
  345. find_function_data (decl)
  346.      tree decl;
  347. {
  348.   struct function *p;
  349.   for (p = outer_function_chain; p; p = p->next)
  350.     if (p->decl == decl)
  351.       return p;
  352.   abort ();
  353. }
  354.  
  355. /* Save the current context for compilation of a nested function.
  356.    This is called from language-specific code.
  357.    The caller is responsible for saving any language-specific status,
  358.    since this function knows only about language-indepedent variables.  */
  359.  
  360. void
  361. push_function_context ()
  362. {
  363.   struct function *p = (struct function *) xmalloc (sizeof (struct function));
  364.  
  365.   p->next = outer_function_chain;
  366.   outer_function_chain = p;
  367.  
  368.   p->name = current_function_name;
  369.   p->decl = current_function_decl;
  370.   p->pops_args = current_function_pops_args;
  371.   p->returns_struct = current_function_returns_struct;
  372.   p->returns_pcc_struct = current_function_returns_pcc_struct;
  373.   p->needs_context = current_function_needs_context;
  374.   p->calls_setjmp = current_function_calls_setjmp;
  375.   p->calls_alloca = current_function_calls_alloca;
  376.   p->has_nonlocal_label = current_function_has_nonlocal_label;
  377.   p->args_size = current_function_args_size;
  378.   p->pretend_args_size = current_function_pretend_args_size;
  379.   p->max_parm_reg = max_parm_reg;
  380.   p->arg_offset_rtx = current_function_arg_offset_rtx;
  381.   p->parm_reg_stack_loc = parm_reg_stack_loc;
  382.   p->outgoing_args_size = current_function_outgoing_args_size;
  383.   p->return_rtx = current_function_return_rtx;
  384.   p->nonlocal_goto_handler_slot = nonlocal_goto_handler_slot;
  385.   p->nonlocal_goto_stack_level = nonlocal_goto_stack_level;
  386.   p->nonlocal_labels = nonlocal_labels;
  387.   p->cleanup_label = cleanup_label;
  388.   p->return_label = return_label;
  389.   p->save_expr_regs = save_expr_regs;
  390.   p->stack_slot_list = stack_slot_list;
  391.   p->parm_birth_insn = parm_birth_insn;
  392.   p->frame_offset = frame_offset;
  393.   p->tail_recursion_label = tail_recursion_label;
  394.   p->tail_recursion_reentry = tail_recursion_reentry;
  395.   p->arg_pointer_save_area = arg_pointer_save_area;
  396.   p->rtl_expr_chain = rtl_expr_chain;
  397.   p->last_parm_insn = last_parm_insn;
  398.   p->context_display = context_display;
  399.   p->trampoline_list = trampoline_list;
  400.   p->function_call_count = function_call_count;
  401.   p->temp_slots = temp_slots;
  402.   p->temp_slot_level = temp_slot_level;
  403.   p->fixup_var_refs_queue = 0;
  404.   p->uses_const_pool = current_function_uses_const_pool;
  405.  
  406.   save_tree_status (p);
  407.   save_storage_status (p);
  408.   save_emit_status (p);
  409.   init_emit ();
  410.   save_expr_status (p);
  411.   save_stmt_status (p);
  412. }
  413.  
  414. /* Restore the last saved context, at the end of a nested function.
  415.    This function is called from language-specific code.  */
  416.  
  417. void
  418. pop_function_context ()
  419. {
  420.   struct function *p = outer_function_chain;
  421.  
  422.   outer_function_chain = p->next;
  423.  
  424.   current_function_name = p->name;
  425.   current_function_decl = p->decl;
  426.   current_function_pops_args = p->pops_args;
  427.   current_function_returns_struct = p->returns_struct;
  428.   current_function_returns_pcc_struct = p->returns_pcc_struct;
  429.   current_function_needs_context = p->needs_context;
  430.   current_function_calls_setjmp = p->calls_setjmp;
  431.   current_function_calls_alloca = p->calls_alloca;
  432.   current_function_has_nonlocal_label = p->has_nonlocal_label;
  433.   current_function_contains_functions = 1;
  434.   current_function_args_size = p->args_size;
  435.   current_function_pretend_args_size = p->pretend_args_size;
  436.   current_function_arg_offset_rtx = p->arg_offset_rtx;
  437.   current_function_uses_const_pool = p->uses_const_pool;
  438.   max_parm_reg = p->max_parm_reg;
  439.   parm_reg_stack_loc = p->parm_reg_stack_loc;
  440.   current_function_outgoing_args_size = p->outgoing_args_size;
  441.   current_function_return_rtx = p->return_rtx;
  442.   nonlocal_goto_handler_slot = p->nonlocal_goto_handler_slot;
  443.   nonlocal_goto_stack_level = p->nonlocal_goto_stack_level;
  444.   nonlocal_labels = p->nonlocal_labels;
  445.   cleanup_label = p->cleanup_label;
  446.   return_label = p->return_label;
  447.   save_expr_regs = p->save_expr_regs;
  448.   stack_slot_list = p->stack_slot_list;
  449.   parm_birth_insn = p->parm_birth_insn;
  450.   frame_offset = p->frame_offset;
  451.   tail_recursion_label = p->tail_recursion_label;
  452.   tail_recursion_reentry = p->tail_recursion_reentry;
  453.   arg_pointer_save_area = p->arg_pointer_save_area;
  454.   rtl_expr_chain = p->rtl_expr_chain;
  455.   last_parm_insn = p->last_parm_insn;
  456.   context_display = p->context_display;
  457.   trampoline_list = p->trampoline_list;
  458.   function_call_count = p->function_call_count;
  459.   temp_slots = p->temp_slots;
  460.   temp_slot_level = p->temp_slot_level;
  461.  
  462.   restore_tree_status (p);
  463.   restore_storage_status (p);
  464.   restore_expr_status (p);
  465.   restore_emit_status (p);
  466.   restore_stmt_status (p);
  467.  
  468.   /* Finish doing put_var_into_stack for any of our variables
  469.      which became addressable during the nested function.  */
  470.   {
  471.     struct var_refs_queue *queue = p->fixup_var_refs_queue;
  472.     for (; queue; queue = queue->next)
  473.       fixup_var_refs (queue->modified);
  474.   }
  475.  
  476.   free (p);
  477.  
  478.   /* Reset variables that have known state during rtx generation.  */
  479.   rtx_equal_function_value_matters = 1;
  480.   virtuals_instantiated = 0;
  481. }
  482.  
  483. /* Allocate fixed slots in the stack frame of the current function.  */
  484.  
  485. /* Return size needed for stack frame based on slots so far allocated.
  486.    This size counts from zero.  It is not rounded to STACK_BOUNDARY;
  487.    the caller may have to do that.  */
  488.  
  489. int
  490. get_frame_size ()
  491. {
  492. #ifdef FRAME_GROWS_DOWNWARD
  493.   return -frame_offset;
  494. #else
  495.   return frame_offset;
  496. #endif
  497. }
  498.  
  499. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  500.    with machine mode MODE.
  501.    
  502.    ALIGN controls the amount of alignment for the address of the slot:
  503.    0 means according to MODE,
  504.    -1 means use BIGGEST_ALIGNMENT and round size to multiple of that,
  505.    positive specifies alignment boundary in bits.
  506.  
  507.    We do not round to stack_boundary here.  */
  508.  
  509. rtx
  510. assign_stack_local (mode, size, align)
  511.      enum machine_mode mode;
  512.      int size;
  513.      int align;
  514. {
  515.   register rtx x, addr;
  516.   int bigend_correction = 0;
  517.   int alignment;
  518.  
  519.   if (align == 0)
  520.     {
  521.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  522.       if (mode == BLKmode)
  523.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  524.     }
  525.   else if (align == -1)
  526.     {
  527.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  528.       size = CEIL_ROUND (size, alignment);
  529.     }
  530.   else
  531.     alignment = align / BITS_PER_UNIT;
  532.  
  533. #if 0 /* Let's see if this is really needed--rms.  */
  534. #ifdef STRICT_ALIGNMENT
  535.   /* Supposedly sub-word sized units may later be accessed
  536.      with word intructions.  It's not certain this is really true.  */
  537.   if (mode != BLKmode && align == 0 && alignment < UNITS_PER_WORD)
  538.     alignment = UNITS_PER_WORD;
  539.  
  540.   /* This is in case we just made the alignment bigger than the size.  */
  541.   size = CEIL_ROUND (size, alignment);
  542. #endif
  543. #endif
  544.  
  545.   /* Round frame offset to that alignment.
  546.      We must be careful here, since FRAME_OFFSET might be negative and
  547.      division with a negative dividend isn't as well defined as we might
  548.      like.  So we instead assume that ALIGNMENT is a power of two and
  549.      use logical operations which are unambiguous.  */
  550. #ifdef FRAME_GROWS_DOWNWARD
  551.   frame_offset = FLOOR_ROUND (frame_offset, alignment);
  552. #else
  553.   frame_offset = CEIL_ROUND (frame_offset, alignment);
  554. #endif
  555.  
  556.   /* On a big-endian machine, if we are allocating more space than we will use,
  557.      use the least significant bytes of those that are allocated.  */
  558. #if BYTES_BIG_ENDIAN
  559.   if (mode != BLKmode)
  560.     bigend_correction = size - GET_MODE_SIZE (mode);
  561. #endif
  562.  
  563. #ifdef FRAME_GROWS_DOWNWARD
  564.   frame_offset -= size;
  565. #endif
  566.  
  567.   /* If we have already instantiated virtual registers, return the actual
  568.      address relative to the frame pointer.  */
  569.   if (virtuals_instantiated)
  570.     addr = plus_constant (frame_pointer_rtx,
  571.               (frame_offset + bigend_correction
  572.                + STARTING_FRAME_OFFSET));
  573.   else
  574.     addr = plus_constant (virtual_stack_vars_rtx,
  575.               frame_offset + bigend_correction);
  576.  
  577. #ifndef FRAME_GROWS_DOWNWARD
  578.   frame_offset += size;
  579. #endif
  580.  
  581.   x = gen_rtx (MEM, mode, addr);
  582.  
  583.   stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
  584.  
  585.   return x;
  586. }
  587.  
  588. /* Assign a stack slot in a containing function.
  589.    First three arguments are same as in preceding function.
  590.    The last argument specifies the function to allocate in.  */
  591.  
  592. rtx
  593. assign_outer_stack_local (mode, size, align, function)
  594.      enum machine_mode mode;
  595.      int size;
  596.      int align;
  597.      struct function *function;
  598. {
  599.   register rtx x, addr;
  600.   int bigend_correction = 0;
  601.   int alignment;
  602.  
  603.   /* Allocate in the memory associated with the function in whose frame
  604.      we are assigning.  */
  605.   push_obstacks (function->function_obstack,
  606.          function->function_maybepermanent_obstack);
  607.  
  608.   if (align == 0)
  609.     {
  610.       alignment = GET_MODE_ALIGNMENT (mode) / BITS_PER_UNIT;
  611.       if (mode == BLKmode)
  612.     alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  613.     }
  614.   else if (align == -1)
  615.     {
  616.       alignment = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  617.       size = CEIL_ROUND (size, alignment);
  618.     }
  619.   else
  620.     alignment = align / BITS_PER_UNIT;
  621.  
  622. #if 0 /* Let's see if this is really needed--rms.  */
  623. #ifdef STRICT_ALIGNMENT
  624.   /* Sub-word sized units may later be accessed with word intructions.
  625.      This results from (SUBREG (MEM ...) ...).  */
  626.   if (mode != BLKmode && align == 0 && alignment < UNITS_PER_WORD)
  627.     alignment = UNITS_PER_WORD;
  628.  
  629.   /* This is in case we just made the alignment bigger than the size.  */
  630.   size = CEIL_ROUND (size, alignment);
  631. #endif
  632. #endif
  633.  
  634.   /* Round frame offset to that alignment.  */
  635. #ifdef FRAME_GROWS_DOWNWARD
  636.   frame_offset = FLOOR_ROUND (frame_offset, alignment);
  637. #else
  638.   frame_offset = CEIL_ROUND (frame_offset, alignment);
  639. #endif
  640.  
  641.   /* On a big-endian machine, if we are allocating more space than we will use,
  642.      use the least significant bytes of those that are allocated.  */
  643. #if BYTES_BIG_ENDIAN
  644.   if (mode != BLKmode)
  645.     bigend_correction = size - GET_MODE_SIZE (mode);
  646. #endif
  647.  
  648. #ifdef FRAME_GROWS_DOWNWARD
  649.   function->frame_offset -= size;
  650. #endif
  651.   addr = plus_constant (virtual_stack_vars_rtx,
  652.             function->frame_offset + bigend_correction);
  653. #ifndef FRAME_GROWS_DOWNWARD
  654.   function->frame_offset += size;
  655. #endif
  656.  
  657.   x = gen_rtx (MEM, mode, addr);
  658.  
  659.   function->stack_slot_list
  660.     = gen_rtx (EXPR_LIST, VOIDmode, x, function->stack_slot_list);
  661.  
  662.   pop_obstacks ();
  663.  
  664.   return x;
  665. }
  666.  
  667. /* Allocate a temporary stack slot and record it for possible later
  668.    reuse.
  669.  
  670.    MODE is the machine mode to be given to the returned rtx.
  671.  
  672.    SIZE is the size in units of the space required.  We do no rounding here
  673.    since assign_stack_local will do any required rounding.
  674.  
  675.    KEEP is non-zero if this slot is to be retained after a call to
  676.    free_temp_slots.  Automatic variables for a block are allocated with this
  677.    flag.  */
  678.  
  679. rtx
  680. assign_stack_temp (mode, size, keep)
  681.      enum machine_mode mode;
  682.      int size;
  683.      int keep;
  684. {
  685.   struct temp_slot *p, *best_p = 0;
  686.  
  687.   /* First try to find an available, already-allocated temporary that is the
  688.      exact size we require.  */
  689.   for (p = temp_slots; p; p = p->next)
  690.     if (p->size == size && GET_MODE (p->slot) == mode && ! p->in_use)
  691.       break;
  692.  
  693.   /* If we didn't find, one, try one that is larger than what we want.  We
  694.      find the smallest such.  */
  695.   if (p == 0)
  696.     for (p = temp_slots; p; p = p->next)
  697.       if (p->size > size && GET_MODE (p->slot) == mode && ! p->in_use
  698.       && (best_p == 0 || best_p->size > p->size))
  699.     best_p = p;
  700.  
  701.   /* Make our best, if any, the one to use.  */
  702.   if (best_p)
  703.     p = best_p;
  704.  
  705.   /* If we still didn't find one, make a new temporary.  */
  706.   if (p == 0)
  707.     {
  708.       p = (struct temp_slot *) oballoc (sizeof (struct temp_slot));
  709.       p->size = size;
  710.       /* If the temp slot mode doesn't indicate the alignment,
  711.      use the largest possible, so no one will be disappointed.  */
  712.       p->slot = assign_stack_local (mode, size, mode == BLKmode ? -1 : 0); 
  713.       p->next = temp_slots;
  714.       temp_slots = p;
  715.     }
  716.  
  717.   p->in_use = 1;
  718.   p->level = temp_slot_level;
  719.   p->keep = keep;
  720.   return p->slot;
  721. }
  722.  
  723. /* If X could be a reference to a temporary slot, mark that slot as belonging
  724.    to the to one level higher.  If X matched one of our slots, just mark that
  725.    one.  Otherwise, we can't easily predict which it is, so upgrade all of
  726.    them.  Kept slots need not be touched.
  727.  
  728.    This is called when an ({...}) construct occurs and a statement
  729.    returns a value in memory.  */
  730.  
  731. void
  732. preserve_temp_slots (x)
  733.      rtx x;
  734. {
  735.   struct temp_slot *p;
  736.  
  737.   /* If X is not in memory or is at a constant address, it cannot be in
  738.      a temporary slot.  */
  739.   if (x == 0 || GET_CODE (x) != MEM || CONSTANT_P (XEXP (x, 0)))
  740.     return;
  741.  
  742.   /* First see if we can find a match.  */
  743.   for (p = temp_slots; p; p = p->next)
  744.     if (p->in_use && x == p->slot)
  745.       {
  746.     p->level--;
  747.     return;
  748.       }
  749.  
  750.   /* Otherwise, preserve all non-kept slots at this level.  */
  751.   for (p = temp_slots; p; p = p->next)
  752.     if (p->in_use && p->level == temp_slot_level && ! p->keep)
  753.       p->level--;
  754. }
  755.  
  756. /* Free all temporaries used so far.  This is normally called at the end
  757.    of generating code for a statement.  */
  758.  
  759. void
  760. free_temp_slots ()
  761. {
  762.   struct temp_slot *p;
  763.  
  764.   for (p = temp_slots; p; p = p->next)
  765.     if (p->in_use && p->level == temp_slot_level && ! p->keep)
  766.       p->in_use = 0;
  767. }
  768.  
  769. /* Push deeper into the nesting level for stack temporaries.  */
  770.  
  771. void
  772. push_temp_slots ()
  773. {
  774.   /* For GNU C++, we must allow a sequence to be emitted anywhere in
  775.      the level where the sequence was started.  By not changing levels
  776.      when the compiler is inside a sequence, the temporaries for the
  777.      sequence and the temporaries will not unwittingly conflict with
  778.      the temporaries for other sequences and/or code at that level.  */
  779.   if (in_sequence_p ())
  780.     return;
  781.  
  782.   temp_slot_level++;
  783. }
  784.  
  785. /* Pop a temporary nesting level.  All slots in use in the current level
  786.    are freed.  */
  787.  
  788. void
  789. pop_temp_slots ()
  790. {
  791.   struct temp_slot *p;
  792.  
  793.   /* See comment in push_temp_slots about why we don't change levels
  794.      in sequences.  */
  795.   if (in_sequence_p ())
  796.     return;
  797.  
  798.   for (p = temp_slots; p; p = p->next)
  799.     if (p->in_use && p->level == temp_slot_level)
  800.       p->in_use = 0;
  801.  
  802.   temp_slot_level--;
  803. }
  804.  
  805. /* Retroactively move an auto variable from a register to a stack slot.
  806.    This is done when an address-reference to the variable is seen.  */
  807.  
  808. void
  809. put_var_into_stack (decl)
  810.      tree decl;
  811. {
  812.   register rtx reg;
  813.   register rtx new = 0;
  814.   struct function *function = 0;
  815.   tree context = decl_function_context (decl);
  816.  
  817.   /* Get the current rtl used for this object.  */
  818.   reg = TREE_CODE (decl) == SAVE_EXPR ? SAVE_EXPR_RTL (decl) : DECL_RTL (decl);
  819.  
  820.   /* If this variable comes from an outer function,
  821.      find that function's saved context.  */
  822.   if (context != current_function_decl)
  823.     for (function = outer_function_chain; function; function = function->next)
  824.       if (function->decl == context)
  825.     break;
  826.  
  827.   /* No need to do anything if decl has no rtx yet
  828.      since in that case caller is setting TREE_ADDRESSABLE
  829.      and a stack slot will be assigned when the rtl is made.  */
  830.   if (reg == 0)
  831.     return;
  832.  
  833.   /* If this is a variable-size object with a pseudo to address it,
  834.      put that pseudo into the stack, if the var is nonlocal.  */
  835.   if (TREE_NONLOCAL (decl)
  836.       && GET_CODE (reg) == MEM
  837.       && GET_CODE (XEXP (reg, 0)) == REG
  838.       && REGNO (XEXP (reg, 0)) > LAST_VIRTUAL_REGISTER)
  839.     reg = XEXP (reg, 0);
  840.   if (GET_CODE (reg) != REG)
  841.     return;
  842.  
  843.   if (function)
  844.     {
  845.       if (REGNO (reg) < function->max_parm_reg)
  846.     new = function->parm_reg_stack_loc[REGNO (reg)];
  847.       if (new == 0)
  848.     new = assign_outer_stack_local (GET_MODE (reg),
  849.                     GET_MODE_SIZE (GET_MODE (reg)),
  850.                     0, function);
  851.     }
  852.   else
  853.     {
  854.       if (REGNO (reg) < max_parm_reg)
  855.     new = parm_reg_stack_loc[REGNO (reg)];
  856.       if (new == 0)
  857.     new = assign_stack_local (GET_MODE (reg),
  858.                   GET_MODE_SIZE (GET_MODE (reg)),
  859.                   0);
  860.     }
  861.  
  862.   XEXP (reg, 0) = XEXP (new, 0);
  863.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  864.   REG_USERVAR_P (reg) = 0;
  865.   PUT_CODE (reg, MEM);
  866.  
  867.   /* If this is a memory ref that contains aggregate components,
  868.      mark it as such for cse and loop optimize.  */
  869.   MEM_IN_STRUCT_P (reg)
  870.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  871.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  872.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  873.  
  874.   /* Now make sure that all refs to the variable, previously made
  875.      when it was a register, are fixed up to be valid again.  */
  876.   if (function)
  877.     {
  878.       struct var_refs_queue *temp;
  879.  
  880.       /* Variable is inherited; fix it up when we get back to its function.  */
  881.       push_obstacks (function->function_obstack,
  882.              function->function_maybepermanent_obstack);
  883.       temp
  884.     = (struct var_refs_queue *) oballoc (sizeof (struct var_refs_queue));
  885.       temp->modified = reg;
  886.       temp->next = function->fixup_var_refs_queue;
  887.       function->fixup_var_refs_queue = temp;
  888.       pop_obstacks ();
  889.     }
  890.   else
  891.     /* Variable is local; fix it up now.  */
  892.     fixup_var_refs (reg);
  893. }
  894.  
  895. static void
  896. fixup_var_refs (var)
  897.      rtx var;
  898. {
  899.   tree pending;
  900.   rtx first_insn = get_insns ();
  901.   struct sequence_stack *stack = sequence_stack;
  902.   tree rtl_exps = rtl_expr_chain;
  903.  
  904.   /* Must scan all insns for stack-refs that exceed the limit.  */
  905.   fixup_var_refs_insns (var, first_insn, stack == 0);
  906.  
  907.   /* Scan all pending sequences too.  */
  908.   for (; stack; stack = stack->next)
  909.     {
  910.       push_to_sequence (stack->first);
  911.       fixup_var_refs_insns (var, stack->first, stack->next != 0);
  912.       /* Update remembered end of sequence
  913.      in case we added an insn at the end.  */
  914.       stack->last = get_last_insn ();
  915.       end_sequence ();
  916.     }
  917.  
  918.   /* Scan all waiting RTL_EXPRs too.  */
  919.   for (pending = rtl_exps; pending; pending = TREE_CHAIN (pending))
  920.     {
  921.       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
  922.       if (seq != const0_rtx && seq != 0)
  923.     {
  924.       push_to_sequence (seq);
  925.       fixup_var_refs_insns (var, seq, 0);
  926.       end_sequence ();
  927.     }
  928.     }
  929. }
  930.  
  931. /* This structure is used by the following two functions to record MEMs or
  932.    pseudos used to replace VAR, any SUBREGs of VAR, and any MEMs containing
  933.    VAR as an address.  We need to maintain this list in case two operands of
  934.    an insn were required to match; in that case we must ensure we use the
  935.    same replacement.  */
  936.  
  937. struct fixup_replacement
  938. {
  939.   rtx old;
  940.   rtx new;
  941.   struct fixup_replacement *next;
  942. };
  943.    
  944. /* REPLACEMENTS is a pointer to a list of the above structures and X is
  945.    some part of an insn.  Return a struct fixup_replacement whose OLD
  946.    value is equal to X.  Allocate a new structure if no such entry exists. */
  947.  
  948. static struct fixup_replacement *
  949. find_replacement (replacements, x)
  950.      struct fixup_replacement **replacements;
  951.      rtx x;
  952. {
  953.   struct fixup_replacement *p;
  954.  
  955.   /* See if we have already replaced this.  */
  956.   for (p = *replacements; p && p->old != x; p = p->next)
  957.     ;
  958.  
  959.   if (p == 0)
  960.     {
  961.       p = (struct fixup_replacement *) oballoc (sizeof (struct fixup_replacement));
  962.       p->old = x;
  963.       p->new = 0;
  964.       p->next = *replacements;
  965.       *replacements = p;
  966.     }
  967.  
  968.   return p;
  969. }
  970.  
  971. /* Scan the insn-chain starting with INSN for refs to VAR
  972.    and fix them up.  TOPLEVEL is nonzero if this chain is the
  973.    main chain of insns for the current function.  */
  974.  
  975. static void
  976. fixup_var_refs_insns (var, insn, toplevel)
  977.      rtx var;
  978.      rtx insn;
  979.      int toplevel;
  980. {
  981.   while (insn)
  982.     {
  983.       rtx next = NEXT_INSN (insn);
  984.       rtx note;
  985.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  986.       || GET_CODE (insn) == JUMP_INSN)
  987.     {
  988.       /* The insn to load VAR from a home in the arglist
  989.          is now a no-op.  When we see it, just delete it.  */
  990.       if (toplevel
  991.           && GET_CODE (PATTERN (insn)) == SET
  992.           && SET_DEST (PATTERN (insn)) == var
  993.           && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  994.         {
  995.           next = delete_insn (insn);
  996.           if (insn == last_parm_insn)
  997.         last_parm_insn = PREV_INSN (next);
  998.         }
  999.       else
  1000.         {
  1001.           /* See if we have to do anything to INSN now that VAR is in
  1002.          memory.  If it needs to be loaded into a pseudo, use a single
  1003.          pseudo for the entire insn in case there is a MATCH_DUP
  1004.          between two operands.  We pass a pointer to the head of
  1005.          a list of struct fixup_replacements.  If fixup_var_refs_1
  1006.          needs to allocate pseudos or replacement MEMs (for SUBREGs),
  1007.          it will record them in this list.
  1008.          
  1009.          If it allocated a pseudo for any replacement, we copy into
  1010.          it here.  */
  1011.  
  1012.           struct fixup_replacement *replacements = 0;
  1013.  
  1014.           fixup_var_refs_1 (var, &PATTERN (insn), insn, &replacements);
  1015.  
  1016.           while (replacements)
  1017.         {
  1018.           if (GET_CODE (replacements->new) == REG)
  1019.             {
  1020.               /* OLD might be a (subreg (mem)).  */
  1021.               if (GET_CODE (replacements->old) == SUBREG)
  1022.             replacements->old
  1023.               = fixup_memory_subreg (replacements->old, insn);
  1024.               else
  1025.             replacements->old
  1026.               = fixup_stack_1 (replacements->old, insn);
  1027.  
  1028.               emit_insn_before (gen_move_insn (replacements->new,
  1029.                                replacements->old),
  1030.                     insn);
  1031.             }
  1032.  
  1033.           replacements = replacements->next;
  1034.         }
  1035.         }
  1036.  
  1037.       /* Also fix up any invalid exprs in the REG_NOTES of this insn.
  1038.          But don't touch other insns referred to by reg-notes;
  1039.          we will get them elsewhere.  */
  1040.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  1041.         if (GET_CODE (note) != INSN_LIST)
  1042.           XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn);
  1043.     }
  1044.       insn = next;
  1045.     }
  1046. }
  1047.  
  1048. /* VAR is a MEM that used to be a pseudo register.  See if the rtx expression
  1049.    at *LOC in INSN needs to be changed.
  1050.  
  1051.    REPLACEMENTS is a pointer to a list head that starts out zero, but may
  1052.    contain a list of original rtx's and replacements. If we find that we need
  1053.    to modify this insn by replacing a memory reference with a pseudo or by
  1054.    making a new MEM to implement a SUBREG, we consult that list to see if
  1055.    we have already chosen a replacement. If none has already been allocated,
  1056.    we allocate it and update the list.  fixup_var_refs_insns will copy VAR
  1057.    or the SUBREG, as appropriate, to the pseudo.  */
  1058.  
  1059. static void
  1060. fixup_var_refs_1 (var, loc, insn, replacements)
  1061.      register rtx var;
  1062.      register rtx *loc;
  1063.      rtx insn;
  1064.      struct fixup_replacement **replacements;
  1065. {
  1066.   register int i;
  1067.   register rtx x = *loc;
  1068.   RTX_CODE code = GET_CODE (x);
  1069.   register char *fmt;
  1070.   register rtx tem, tem1;
  1071.   struct fixup_replacement *replacement;
  1072.  
  1073.   switch (code)
  1074.     {
  1075.     case MEM:
  1076.       if (var == x)
  1077.     {
  1078.       /* If we already have a replacement, use it.  Otherwise, 
  1079.          try to fix up this address in case it is invalid.  */
  1080.  
  1081.       replacement = find_replacement (replacements, var);
  1082.       if (replacement->new)
  1083.         {
  1084.           *loc = replacement->new;
  1085.           return;
  1086.         }
  1087.  
  1088.       *loc = replacement->new = x = fixup_stack_1 (x, insn);
  1089.  
  1090.       /* Unless we are forcing memory to register, we can leave things
  1091.          the way they are if the insn is valid.  */
  1092.          
  1093.       INSN_CODE (insn) = -1;
  1094.       if (! flag_force_mem && recog_memoized (insn) >= 0)
  1095.         return;
  1096.  
  1097.       *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
  1098.       return;
  1099.     }
  1100.  
  1101.       /* If X contains VAR, we need to unshare it here so that we update
  1102.      each occurrence separately.  But all identical MEMs in one insn
  1103.      must be replaced with the same rtx because of the possibility of
  1104.      MATCH_DUPs.  */
  1105.  
  1106.       if (reg_mentioned_p (var, x))
  1107.     {
  1108.       replacement = find_replacement (replacements, x);
  1109.       if (replacement->new == 0)
  1110.         replacement->new = copy_most_rtx (x, var);
  1111.  
  1112.       *loc = x = replacement->new;
  1113.     }
  1114.       break;
  1115.  
  1116.     case REG:
  1117.     case CC0:
  1118.     case PC:
  1119.     case CONST_INT:
  1120.     case CONST:
  1121.     case SYMBOL_REF:
  1122.     case LABEL_REF:
  1123.     case CONST_DOUBLE:
  1124.       return;
  1125.  
  1126.     case SIGN_EXTRACT:
  1127.     case ZERO_EXTRACT:
  1128.       /* Note that in some cases those types of expressions are altered
  1129.      by optimize_bit_field, and do not survive to get here.  */
  1130.       if (XEXP (x, 0) == var
  1131.       || (GET_CODE (XEXP (x, 0)) == SUBREG
  1132.           && SUBREG_REG (XEXP (x, 0)) == var))
  1133.     {
  1134.       /* Get TEM as a valid MEM in the mode presently in the insn.
  1135.  
  1136.          We don't worry about the possibility of MATCH_DUP here; it
  1137.          is highly unlikely and would be tricky to handle.  */
  1138.  
  1139.       tem = XEXP (x, 0);
  1140.       if (GET_CODE (tem) == SUBREG)
  1141.         tem = fixup_memory_subreg (tem, insn);
  1142.       tem = fixup_stack_1 (tem, insn);
  1143.  
  1144.       /* Unless we want to load from memory, get TEM into the proper mode
  1145.          for an extract from memory.  This can only be done if the
  1146.          extract is at a constant position and length.  */
  1147.  
  1148.       if (! flag_force_mem && GET_CODE (XEXP (x, 1)) == CONST_INT
  1149.           && GET_CODE (XEXP (x, 2)) == CONST_INT
  1150.           && ! mode_dependent_address_p (XEXP (tem, 0)))
  1151.         {
  1152.           enum machine_mode wanted_mode = VOIDmode;
  1153.           enum machine_mode is_mode = GET_MODE (tem);
  1154.           int width = INTVAL (XEXP (x, 1));
  1155.           int pos = INTVAL (XEXP (x, 2));
  1156.  
  1157. #ifdef HAVE_extzv
  1158.           if (GET_CODE (x) == ZERO_EXTRACT)
  1159.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extzv][1];
  1160. #endif
  1161. #ifdef HAVE_extv
  1162.           if (GET_CODE (x) == SIGN_EXTRACT)
  1163.         wanted_mode = insn_operand_mode[(int) CODE_FOR_extv][1];
  1164. #endif
  1165.           /* If we have a narrower mode, we can do someting.  */
  1166.           if (wanted_mode != VOIDmode
  1167.           && GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1168.         {
  1169.           int offset = pos / BITS_PER_UNIT;
  1170.           rtx old_pos = XEXP (x, 2);
  1171.           rtx newmem;
  1172.  
  1173.           /* If the bytes and bits are counted differently, we
  1174.              must adjust the offset.  */
  1175. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1176.           offset = (GET_MODE_SIZE (is_mode)
  1177.                 - GET_MODE_SIZE (wanted_mode) - offset);
  1178. #endif
  1179.  
  1180.           pos %= GET_MODE_BITSIZE (wanted_mode);
  1181.  
  1182.           newmem = gen_rtx (MEM, wanted_mode,
  1183.                     plus_constant (XEXP (tem, 0), offset));
  1184.           RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1185.           MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1186.           MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1187.  
  1188.           /* Make the change and see if the insn remains valid.  */
  1189.           INSN_CODE (insn) = -1;
  1190.           XEXP (x, 0) = newmem;
  1191.           XEXP (x, 2) = gen_rtx (CONST_INT, VOIDmode, pos);
  1192.  
  1193.           if (recog_memoized (insn) >= 0)
  1194.             return;
  1195.  
  1196.           /* Otherwise, restore old position.  XEXP (x, 0) will be
  1197.              restored later.  */
  1198.           XEXP (x, 2) = old_pos;
  1199.         }
  1200.         }
  1201.  
  1202.       /* If we get here, the bitfield extract insn can't accept a memory
  1203.          reference.  Copy the input into a register.  */
  1204.  
  1205.       tem1 = gen_reg_rtx (GET_MODE (tem));
  1206.       emit_insn_before (gen_move_insn (tem1, tem), insn);
  1207.       XEXP (x, 0) = tem1;
  1208.       return;
  1209.     }
  1210.       break;
  1211.           
  1212.     case SUBREG:
  1213.       if (SUBREG_REG (x) == var)
  1214.     {
  1215.       /* If this SUBREG makes VAR wider, it has become a paradoxical
  1216.          SUBREG with VAR in memory, but these aren't allowed at this 
  1217.          stage of the compilation.  So load VAR into a pseudo and take
  1218.          a SUBREG of that pseudo.  */
  1219.       if (GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (var)))
  1220.         {
  1221.           replacement = find_replacement (replacements, var);
  1222.           if (replacement->new == 0)
  1223.         replacement->new = gen_reg_rtx (GET_MODE (var));
  1224.           SUBREG_REG (x) = replacement->new;
  1225.           return;
  1226.         }
  1227.  
  1228.       /* See if we have already found a replacement for this SUBREG.
  1229.          If so, use it.  Otherwise, make a MEM and see if the insn
  1230.          is recognized.  If not, or if we should force MEM into a register,
  1231.          make a pseudo for this SUBREG.  */
  1232.       replacement = find_replacement (replacements, x);
  1233.       if (replacement->new)
  1234.         {
  1235.           *loc = replacement->new;
  1236.           return;
  1237.         }
  1238.       
  1239.       replacement->new = *loc = fixup_memory_subreg (x, insn);
  1240.  
  1241.       if (! flag_force_mem && recog_memoized (insn) >= 0)
  1242.         return;
  1243.  
  1244.       *loc = replacement->new = gen_reg_rtx (GET_MODE (x));
  1245.       return;
  1246.     }
  1247.       break;
  1248.  
  1249.     case SET:
  1250.       /* First do special simplification of bit-field references.  */
  1251.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  1252.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  1253.     optimize_bit_field (x, insn, 0);
  1254.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  1255.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  1256.     optimize_bit_field (x, insn, 0);
  1257.  
  1258.       /* If SET_DEST is now a paradoxical SUBREG, put the result of this
  1259.      insn into a pseudo and store the low part of the pseudo into VAR. */
  1260.       if (GET_CODE (SET_DEST (x)) == SUBREG
  1261.       && SUBREG_REG (SET_DEST (x)) == var
  1262.       && (GET_MODE_SIZE (GET_MODE (SET_DEST (x)))
  1263.           > GET_MODE_SIZE (GET_MODE (var))))
  1264.     {
  1265.       SET_DEST (x) = tem = gen_reg_rtx (GET_MODE (SET_DEST (x)));
  1266.       emit_insn_after (gen_move_insn (var, gen_lowpart (GET_MODE (var),
  1267.                                 tem)),
  1268.                insn);
  1269.       break;
  1270.     }
  1271.       
  1272.       {
  1273.     rtx dest = SET_DEST (x);
  1274.     rtx src = SET_SRC (x);
  1275.     rtx outerdest = dest;
  1276.  
  1277.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  1278.            || GET_CODE (dest) == SIGN_EXTRACT
  1279.            || GET_CODE (dest) == ZERO_EXTRACT)
  1280.       dest = XEXP (dest, 0);
  1281.  
  1282.     if (GET_CODE (src) == SUBREG)
  1283.       src = XEXP (src, 0);
  1284.  
  1285.     /* If VAR does not appear at the top level of the SET
  1286.        just scan the lower levels of the tree.  */
  1287.  
  1288.         if (src != var && dest != var)
  1289.       break;
  1290.  
  1291.     /* We will need to rerecognize this insn.  */
  1292.     INSN_CODE (insn) = -1;
  1293.  
  1294. #ifdef HAVE_insv
  1295.     if (GET_CODE (outerdest) == ZERO_EXTRACT && dest == var)
  1296.       {
  1297.         /* Since this case will return, ensure we fixup all the
  1298.            operands here.  */
  1299.         fixup_var_refs_1 (var, &XEXP (outerdest, 1), insn, replacements);
  1300.         fixup_var_refs_1 (var, &XEXP (outerdest, 2), insn, replacements);
  1301.         fixup_var_refs_1 (var, &SET_SRC (x), insn, replacements);
  1302.  
  1303.         tem = XEXP (outerdest, 0);
  1304.  
  1305.         /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  1306.            that may appear inside a ZERO_EXTRACT.
  1307.            This was legitimate when the MEM was a REG.  */
  1308.         if (GET_CODE (tem) == SUBREG
  1309.         && SUBREG_REG (tem) == var)
  1310.           tem = fixup_memory_subreg (tem, insn);
  1311.         else
  1312.           tem = fixup_stack_1 (tem, insn);
  1313.  
  1314.         if (GET_CODE (XEXP (outerdest, 1)) == CONST_INT
  1315.         && GET_CODE (XEXP (outerdest, 2)) == CONST_INT
  1316.         && ! mode_dependent_address_p (XEXP (tem, 0)))
  1317.           {
  1318.         enum machine_mode wanted_mode
  1319.           = insn_operand_mode[(int) CODE_FOR_insv][0];
  1320.         enum machine_mode is_mode = GET_MODE (tem);
  1321.         int width = INTVAL (XEXP (outerdest, 1));
  1322.         int pos = INTVAL (XEXP (outerdest, 2));
  1323.  
  1324.         /* If we have a narrower mode, we can do someting.  */
  1325.         if (GET_MODE_SIZE (wanted_mode) < GET_MODE_SIZE (is_mode))
  1326.           {
  1327.             int offset = pos / BITS_PER_UNIT;
  1328.             rtx old_pos = XEXP (outerdest, 2);
  1329.             rtx newmem;
  1330.  
  1331. #if BYTES_BIG_ENDIAN != BITS_BIG_ENDIAN
  1332.             offset = (GET_MODE_SIZE (is_mode)
  1333.                   - GET_MODE_SIZE (wanted_mode) - offset);
  1334. #endif
  1335.  
  1336.             pos %= GET_MODE_BITSIZE (wanted_mode);
  1337.  
  1338.             newmem = gen_rtx (MEM, wanted_mode,
  1339.                       plus_constant (XEXP (tem, 0), offset));
  1340.             RTX_UNCHANGING_P (newmem) = RTX_UNCHANGING_P (tem);
  1341.             MEM_VOLATILE_P (newmem) = MEM_VOLATILE_P (tem);
  1342.             MEM_IN_STRUCT_P (newmem) = MEM_IN_STRUCT_P (tem);
  1343.  
  1344.             /* Make the change and see if the insn remains valid.  */
  1345.             INSN_CODE (insn) = -1;
  1346.             XEXP (outerdest, 0) = newmem;
  1347.             XEXP (outerdest, 2) = gen_rtx (CONST_INT, VOIDmode, pos);
  1348.             
  1349.             if (recog_memoized (insn) >= 0)
  1350.               return;
  1351.             
  1352.             /* Otherwise, restore old position.  XEXP (x, 0) will be
  1353.                restored later.  */
  1354.             XEXP (outerdest, 2) = old_pos;
  1355.           }
  1356.           }
  1357.  
  1358.         /* If we get here, the bit-field store doesn't allow memory
  1359.            or isn't located at a constant position.  Load the value into
  1360.            a register, do the store, and put it back into memory.  */
  1361.  
  1362.         tem1 = gen_reg_rtx (GET_MODE (tem));
  1363.         emit_insn_before (gen_move_insn (tem1, tem), insn);
  1364.         emit_insn_after (gen_move_insn (tem, tem1), insn);
  1365.         XEXP (outerdest, 0) = tem1;
  1366.         return;
  1367.       }
  1368. #endif
  1369.  
  1370.     /* STRICT_LOW_PART is a no-op on memory references
  1371.        and it can cause combinations to be unrecognizable,
  1372.        so eliminate it.  */
  1373.  
  1374.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  1375.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  1376.  
  1377.     /* A valid insn to copy VAR into or out of a register
  1378.        must be left alone, to avoid an infinite loop here.
  1379.        If the reference to VAR is by a subreg, fix that up,
  1380.        since SUBREG is not valid for a memref.
  1381.        Also fix up the address of the stack slot.  */
  1382.  
  1383.     if ((SET_SRC (x) == var
  1384.          || (GET_CODE (SET_SRC (x)) == SUBREG
  1385.          && SUBREG_REG (SET_SRC (x)) == var))
  1386.         && (GET_CODE (SET_DEST (x)) == REG
  1387.         || (GET_CODE (SET_DEST (x)) == SUBREG
  1388.             && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  1389.         && recog_memoized (insn) >= 0)
  1390.       {
  1391.         replacement = find_replacement (replacements, SET_SRC (x));
  1392.         if (replacement->new)
  1393.           {
  1394.           SET_SRC (x) = replacement->new;
  1395.           return;
  1396.         }
  1397.         else if (GET_CODE (SET_SRC (x)) == SUBREG)
  1398.           SET_SRC (x) = replacement->new
  1399.         = fixup_memory_subreg (SET_SRC (x), insn);
  1400.         else
  1401.           SET_SRC (x) = replacement->new
  1402.         = fixup_stack_1 (SET_SRC (x), insn);
  1403.         return;
  1404.       }
  1405.  
  1406.     if ((SET_DEST (x) == var
  1407.          || (GET_CODE (SET_DEST (x)) == SUBREG
  1408.          && SUBREG_REG (SET_DEST (x)) == var))
  1409.         && (GET_CODE (SET_SRC (x)) == REG
  1410.         || (GET_CODE (SET_SRC (x)) == SUBREG
  1411.             && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG))
  1412.         && recog_memoized (insn) >= 0)
  1413.       {
  1414.         if (GET_CODE (SET_DEST (x)) == SUBREG)
  1415.           SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn);
  1416.         else
  1417.           SET_DEST (x) = fixup_stack_1 (SET_DEST (x), insn);
  1418.         return;
  1419.       }
  1420.  
  1421.     /* Otherwise, storing into VAR must be handled specially
  1422.        by storing into a temporary and copying that into VAR
  1423.        with a new insn after this one.  */
  1424.  
  1425.     if (dest == var)
  1426.       {
  1427.         rtx temp;
  1428.         rtx fixeddest;
  1429.         tem = SET_DEST (x);
  1430.         /* STRICT_LOW_PART can be discarded, around a MEM.  */
  1431.         if (GET_CODE (tem) == STRICT_LOW_PART)
  1432.           tem = XEXP (tem, 0);
  1433.         /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
  1434.         if (GET_CODE (tem) == SUBREG)
  1435.           fixeddest = fixup_memory_subreg (tem, insn);
  1436.         else
  1437.           fixeddest = fixup_stack_1 (tem, insn);
  1438.  
  1439.         temp = gen_reg_rtx (GET_MODE (tem));
  1440.         emit_insn_after (gen_move_insn (fixeddest, temp), insn);
  1441.         SET_DEST (x) = temp;
  1442.       }
  1443.       }
  1444.     }
  1445.  
  1446.   /* Nothing special about this RTX; fix its operands.  */
  1447.  
  1448.   fmt = GET_RTX_FORMAT (code);
  1449.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1450.     {
  1451.       if (fmt[i] == 'e')
  1452.     fixup_var_refs_1 (var, &XEXP (x, i), insn, replacements);
  1453.       if (fmt[i] == 'E')
  1454.     {
  1455.       register int j;
  1456.       for (j = 0; j < XVECLEN (x, i); j++)
  1457.         fixup_var_refs_1 (var, &XVECEXP (x, i, j), insn, replacements);
  1458.     }
  1459.     }
  1460. }
  1461.  
  1462. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  1463.    return an rtx (MEM:m1 newaddr) which is equivalent.
  1464.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  1465.  
  1466. static rtx
  1467. fixup_memory_subreg (x, insn)
  1468.      rtx x;
  1469.      rtx insn;
  1470. {
  1471.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  1472.   rtx addr = XEXP (SUBREG_REG (x), 0);
  1473.   enum machine_mode mode = GET_MODE (x);
  1474.   rtx saved, result;
  1475.  
  1476.   /* Paradoxical SUBREGs aren't valid at this stage of the compilation.  */
  1477.   if (GET_MODE_SIZE (mode) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  1478.     abort ();
  1479.  
  1480. #if BYTES_BIG_ENDIAN
  1481.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  1482.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  1483. #endif
  1484.   addr = plus_constant (addr, offset);
  1485.   if (!flag_force_addr && memory_address_p (mode, addr))
  1486.     /* Shortcut if no insns need be emitted.  */
  1487.     return change_address (SUBREG_REG (x), mode, addr);
  1488.   start_sequence ();
  1489.   result = change_address (SUBREG_REG (x), mode, addr);
  1490.   emit_insn_before (gen_sequence (), insn);
  1491.   end_sequence ();
  1492.   return result;
  1493. }
  1494.  
  1495. /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
  1496.    Replace subexpressions of X in place.
  1497.    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
  1498.    Otherwise return X, with its contents possibly altered.
  1499.  
  1500.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  1501.  
  1502. static rtx
  1503. walk_fixup_memory_subreg (x, insn)
  1504.      register rtx x;
  1505.      rtx insn;
  1506. {
  1507.   register enum rtx_code code;
  1508.   register char *fmt;
  1509.   register int i;
  1510.  
  1511.   if (x == 0)
  1512.     return 0;
  1513.  
  1514.   code = GET_CODE (x);
  1515.  
  1516.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  1517.     return fixup_memory_subreg (x, insn);
  1518.  
  1519.   /* Nothing special about this RTX; fix its operands.  */
  1520.  
  1521.   fmt = GET_RTX_FORMAT (code);
  1522.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1523.     {
  1524.       if (fmt[i] == 'e')
  1525.     XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn);
  1526.       if (fmt[i] == 'E')
  1527.     {
  1528.       register int j;
  1529.       for (j = 0; j < XVECLEN (x, i); j++)
  1530.         XVECEXP (x, i, j)
  1531.           = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn);
  1532.     }
  1533.     }
  1534.   return x;
  1535. }
  1536.  
  1537. #if 0
  1538. /* Fix up any references to stack slots that are invalid memory addresses
  1539.    because they exceed the maximum range of a displacement.  */
  1540.  
  1541. void
  1542. fixup_stack_slots ()
  1543. {
  1544.   register rtx insn;
  1545.  
  1546.   /* Did we generate a stack slot that is out of range
  1547.      or otherwise has an invalid address?  */
  1548.   if (invalid_stack_slot)
  1549.     {
  1550.       /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  1551.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  1552.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  1553.         || GET_CODE (insn) == JUMP_INSN)
  1554.       fixup_stack_1 (PATTERN (insn), insn);
  1555.     }
  1556. }
  1557. #endif
  1558.  
  1559. /* For each memory ref within X, if it refers to a stack slot
  1560.    with an out of range displacement, put the address in a temp register
  1561.    (emitting new insns before INSN to load these registers)
  1562.    and alter the memory ref to use that register.
  1563.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  1564.  
  1565. static rtx
  1566. fixup_stack_1 (x, insn)
  1567.      rtx x;
  1568.      rtx insn;
  1569. {
  1570.   register int i;
  1571.   register RTX_CODE code = GET_CODE (x);
  1572.   register char *fmt;
  1573.  
  1574.   if (code == MEM)
  1575.     {
  1576.       register rtx ad = XEXP (x, 0);
  1577.       /* If we have address of a stack slot but it's not valid
  1578.      (displacement is too large), compute the sum in a register.  */
  1579.       if (GET_CODE (ad) == PLUS
  1580.       && GET_CODE (XEXP (ad, 0)) == REG
  1581.       && REGNO (XEXP (ad, 0)) >= FIRST_VIRTUAL_REGISTER
  1582.       && REGNO (XEXP (ad, 0)) <= LAST_VIRTUAL_REGISTER
  1583.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  1584.     {
  1585.       rtx temp, seq;
  1586.       if (memory_address_p (GET_MODE (x), ad))
  1587.         return x;
  1588.  
  1589.       start_sequence ();
  1590.       temp = copy_to_reg (ad);
  1591.       seq = gen_sequence ();
  1592.       end_sequence ();
  1593.       emit_insn_before (seq, insn);
  1594.       return change_address (x, VOIDmode, temp);
  1595.     }
  1596.       return x;
  1597.     }
  1598.  
  1599.   fmt = GET_RTX_FORMAT (code);
  1600.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1601.     {
  1602.       if (fmt[i] == 'e')
  1603.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  1604.       if (fmt[i] == 'E')
  1605.     {
  1606.       register int j;
  1607.       for (j = 0; j < XVECLEN (x, i); j++)
  1608.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  1609.     }
  1610.     }
  1611.   return x;
  1612. }
  1613.  
  1614. /* Optimization: a bit-field instruction whose field
  1615.    happens to be a byte or halfword in memory
  1616.    can be changed to a move instruction.
  1617.  
  1618.    We call here when INSN is an insn to examine or store into a bit-field.
  1619.    BODY is the SET-rtx to be altered.
  1620.  
  1621.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  1622.    (Currently this is called only from function.c, and EQUIV_MEM
  1623.    is always 0.)  */
  1624.  
  1625. static void
  1626. optimize_bit_field (body, insn, equiv_mem)
  1627.      rtx body;
  1628.      rtx insn;
  1629.      rtx *equiv_mem;
  1630. {
  1631.   register rtx bitfield;
  1632.   int destflag;
  1633.   rtx seq = 0;
  1634.   enum machine_mode mode;
  1635.  
  1636.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  1637.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  1638.     bitfield = SET_DEST (body), destflag = 1;
  1639.   else
  1640.     bitfield = SET_SRC (body), destflag = 0;
  1641.  
  1642.   /* First check that the field being stored has constant size and position
  1643.      and is in fact a byte or halfword suitably aligned.  */
  1644.  
  1645.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  1646.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  1647.       && ((mode = mode_for_size (INTVAL (XEXP (bitfield, 1)), MODE_INT, 1))
  1648.       != BLKmode)
  1649.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  1650.     {
  1651.       register rtx memref = 0;
  1652.  
  1653.       /* Now check that the containing word is memory, not a register,
  1654.      and that it is safe to change the machine mode.  */
  1655.  
  1656.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  1657.     memref = XEXP (bitfield, 0);
  1658.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  1659.            && equiv_mem != 0)
  1660.     memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
  1661.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1662.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  1663.     memref = SUBREG_REG (XEXP (bitfield, 0));
  1664.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  1665.            && equiv_mem != 0
  1666.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
  1667.     memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
  1668.  
  1669.       if (memref
  1670.       && ! mode_dependent_address_p (XEXP (memref, 0)))
  1671.     {
  1672.       /* Now adjust the address, first for any subreg'ing
  1673.          that we are now getting rid of,
  1674.          and then for which byte of the word is wanted.  */
  1675.  
  1676.       register int offset = INTVAL (XEXP (bitfield, 2));
  1677.       /* Adjust OFFSET to count bits from low-address byte.  */
  1678. #if BITS_BIG_ENDIAN != BYTES_BIG_ENDIAN
  1679.       offset = (GET_MODE_BITSIZE (GET_MODE (XEXP (bitfield, 0)))
  1680.             - offset - INTVAL (XEXP (bitfield, 1)));
  1681. #endif
  1682.       /* Adjust OFFSET to count bytes from low-address byte.  */
  1683.       offset /= BITS_PER_UNIT;
  1684.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  1685.         {
  1686.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  1687. #if BYTES_BIG_ENDIAN
  1688.           offset -= (MIN (UNITS_PER_WORD,
  1689.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  1690.              - MIN (UNITS_PER_WORD,
  1691.                 GET_MODE_SIZE (GET_MODE (memref))));
  1692. #endif
  1693.         }
  1694.  
  1695.       memref = change_address (memref, mode, 
  1696.                    plus_constant (XEXP (memref, 0), offset));
  1697.  
  1698.       /* Store this memory reference where
  1699.          we found the bit field reference.  */
  1700.  
  1701.       if (destflag)
  1702.         {
  1703.           validate_change (insn, &SET_DEST (body), memref, 1);
  1704.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  1705.         {
  1706.           rtx src = SET_SRC (body);
  1707.           while (GET_CODE (src) == SUBREG
  1708.              && SUBREG_WORD (src) == 0)
  1709.             src = SUBREG_REG (src);
  1710.           if (GET_MODE (src) != GET_MODE (memref))
  1711.             src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
  1712.           validate_change (insn, &SET_SRC (body), src, 1);
  1713.         }
  1714.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  1715.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  1716.         /* This shouldn't happen because anything that didn't have
  1717.            one of these modes should have got converted explicitly
  1718.            and then referenced through a subreg.
  1719.            This is so because the original bit-field was
  1720.            handled by agg_mode and so its tree structure had
  1721.            the same mode that memref now has.  */
  1722.         abort ();
  1723.         }
  1724.       else
  1725.         {
  1726.           rtx dest = SET_DEST (body);
  1727.  
  1728.           while (GET_CODE (dest) == SUBREG
  1729.              && SUBREG_WORD (dest) == 0)
  1730.         dest = SUBREG_REG (dest);
  1731.  
  1732.           validate_change (insn, &SET_DEST (body), dest, 1);
  1733.  
  1734.           if (GET_MODE (dest) == GET_MODE (memref))
  1735.         validate_change (insn, &SET_SRC (body), memref, 1);
  1736.           else
  1737.         {
  1738.           /* Convert the mem ref to the destination mode.  */
  1739.           rtx newreg = gen_reg_rtx (GET_MODE (dest));
  1740.  
  1741.           start_sequence ();
  1742.           convert_move (newreg, memref,
  1743.                 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
  1744.           seq = get_insns ();
  1745.           end_sequence ();
  1746.  
  1747.           validate_change (insn, &SET_SRC (body), newreg, 1);
  1748.         }
  1749.         }
  1750.  
  1751.       /* See if we can convert this extraction or insertion into
  1752.          a simple move insn.  We might not be able to do so if this
  1753.          was, for example, part of a PARALLEL.
  1754.  
  1755.          If we succeed, write out any needed conversions.  If we fail,
  1756.          it is hard to guess why we failed, so don't do anything
  1757.          special; just let the optimization be suppressed.  */
  1758.  
  1759.       if (apply_change_group () && seq)
  1760.         emit_insns_before (seq, insn);
  1761.     }
  1762.     }
  1763. }
  1764.  
  1765. /* These routines are responsible for converting virtual register references
  1766.    to the actual hard register references once RTL generation is complete.
  1767.  
  1768.    The following four variables are used for communication between the
  1769.    routines.  They contain the offsets of the virtual registers from their
  1770.    respective hard registers.  */
  1771.  
  1772. static int in_arg_offset;
  1773. static int var_offset;
  1774. static int dynamic_offset;
  1775. static int out_arg_offset;
  1776.  
  1777. /* In most machines, the stack pointer register is equivalent to the bottom
  1778.    of the stack.  */
  1779.  
  1780. #ifndef STACK_POINTER_OFFSET
  1781. #define STACK_POINTER_OFFSET    0
  1782. #endif
  1783.  
  1784. /* If not defined, pick an appropriate default for the offset of dynamically
  1785.    allocated memory depending on the value of ACCUMULATE_OUTGOING_ARGS,
  1786.    REG_PARM_STACK_SPACE, and OUTGOING_REG_PARM_STACK_SPACE.  */
  1787.  
  1788. #ifndef STACK_DYNAMIC_OFFSET
  1789.  
  1790. #ifdef ACCUMULATE_OUTGOING_ARGS
  1791. /* The bottom of the stack points to the actual arguments.  If
  1792.    REG_PARM_STACK_SPACE is defined, this includes the space for the register
  1793.    parameters.  However, if OUTGOING_REG_PARM_STACK space is not defined,
  1794.    stack space for register parameters is not pushed by the caller, but 
  1795.    rather part of the fixed stack areas and hence not included in
  1796.    `current_function_outgoing_args_size'.  Nevertheless, we must allow
  1797.    for it when allocating stack dynamic objects.  */
  1798.  
  1799. #if defined(REG_PARM_STACK_SPACE) && ! defined(OUTGOING_REG_PARM_STACK_SPACE)
  1800. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  1801. (current_function_outgoing_args_size    \
  1802.  + REG_PARM_STACK_SPACE (FNDECL) + (STACK_POINTER_OFFSET))
  1803.  
  1804. #else
  1805. #define STACK_DYNAMIC_OFFSET(FNDECL)    \
  1806. (current_function_outgoing_args_size + (STACK_POINTER_OFFSET))
  1807. #endif
  1808.  
  1809. #else
  1810. #define STACK_DYNAMIC_OFFSET(FNDECL) STACK_POINTER_OFFSET
  1811. #endif
  1812. #endif
  1813.  
  1814. /* Pass through the INSNS of function FNDECL and convert virtual register
  1815.    references to hard register references.  */
  1816.  
  1817. void
  1818. instantiate_virtual_regs (fndecl, insns)
  1819.      tree fndecl;
  1820.      rtx insns;
  1821. {
  1822.   rtx insn;
  1823.  
  1824.   /* Compute the offsets to use for this function.  */
  1825.   in_arg_offset = FIRST_PARM_OFFSET (fndecl);
  1826.   var_offset = STARTING_FRAME_OFFSET;
  1827.   dynamic_offset = STACK_DYNAMIC_OFFSET (fndecl);
  1828.   out_arg_offset = STACK_POINTER_OFFSET;
  1829.  
  1830.   /* Scan all variables and parameters of this function.  For each that is
  1831.      in memory, instantiate all virtual registers if the result is a valid
  1832.      address.  If not, we do it later.  That will handle most uses of virtual
  1833.      regs on many machines.  */
  1834.   instantiate_decls (fndecl, 1);
  1835.  
  1836.   /* Initialize recognition, indicating that volatile is OK.  */
  1837.   init_recog ();
  1838.  
  1839.   /* Scan through all the insns, instantiating every virtual register still
  1840.      present.  */
  1841.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  1842.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  1843.     || GET_CODE (insn) == CALL_INSN)
  1844.       {
  1845.     instantiate_virtual_regs_1 (&PATTERN (insn), insn);
  1846.     instantiate_virtual_regs_1 (®_NOTES (insn), 0);
  1847.       }
  1848.  
  1849.   /* Now instantiate the remaining register equivalences for debugging info.
  1850.      These will not be valid addresses.  */
  1851.   instantiate_decls (fndecl, 0);
  1852.  
  1853.   /* Indicate that, from now on, assign_stack_local should use
  1854.      frame_pointer_rtx.  */
  1855.   virtuals_instantiated = 1;
  1856. }
  1857.  
  1858. /* Scan all decls in FNDECL (both variables and parameters) and instantiate
  1859.    all virtual registers in their DECL_RTL's.
  1860.  
  1861.    If VALID_ONLY, do this only if the resulting address is still valid.
  1862.    Otherwise, always do it.  */
  1863.  
  1864. static void
  1865. instantiate_decls (fndecl, valid_only)
  1866.      tree fndecl;
  1867.      int valid_only;
  1868. {
  1869.   tree decl;
  1870.  
  1871.   if (TREE_INLINE (fndecl))
  1872.     /* When compiling an inline function, the obstack used for
  1873.        rtl allocation is the maybepermanent_obstack.  Calling
  1874.        `resume_temporary_allocation' switches us back to that
  1875.        obstack while we process this function's parameters.  */
  1876.     resume_temporary_allocation ();
  1877.  
  1878.   /* Process all parameters of the function.  */
  1879.   for (decl = DECL_ARGUMENTS (fndecl); decl; decl = TREE_CHAIN (decl))
  1880.     if (DECL_RTL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
  1881.       instantiate_virtual_regs_1 (&XEXP (DECL_RTL (decl), 0),
  1882.                   valid_only ? DECL_RTL (decl) : 0);
  1883.  
  1884.   /* Now process all variables defined in the function or its subblocks. */
  1885.   instantiate_decls_1 (DECL_INITIAL (fndecl), valid_only);
  1886.  
  1887.   if (TREE_INLINE (fndecl))
  1888.     {
  1889.       /* Save all rtl allocated for this function by raising the
  1890.      high-water mark on the maybepermanent_obstack.  */
  1891.       preserve_data ();
  1892.       /* All further rtl allocation is now done in the current_obstack.  */
  1893.       rtl_in_current_obstack ();
  1894.     }
  1895. }
  1896.  
  1897. /* Subroutine of instantiate_decls: Process all decls in the given
  1898.    BLOCK node and all its subblocks.  */
  1899.  
  1900. static void
  1901. instantiate_decls_1 (let, valid_only)
  1902.      tree let;
  1903.      int valid_only;
  1904. {
  1905.   tree t;
  1906.  
  1907.   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
  1908.     if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
  1909.       instantiate_virtual_regs_1 (& XEXP (DECL_RTL (t), 0),
  1910.                   valid_only ? DECL_RTL (t) : 0);
  1911.  
  1912.   /* Process all subblocks.  */
  1913.   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
  1914.     instantiate_decls_1 (t, valid_only);
  1915. }
  1916.  
  1917. /* Given a pointer to a piece of rtx and an optional pointer to the
  1918.    containing object, instantiate any virtual registers present in it.
  1919.  
  1920.    If OBJECT is an insn, we always do the replacement and generate
  1921.    any extra insns before OBJECT.  If it is a MEM, do nothing if replacement
  1922.    is not valid.
  1923.  
  1924.    We try some simple transformations to avoid the creation of extra
  1925.    pseudos.  */
  1926.  
  1927. static void
  1928. instantiate_virtual_regs_1 (loc, object)
  1929.      rtx *loc;
  1930.      rtx object;
  1931. {
  1932.   rtx x;
  1933.   RTX_CODE code;
  1934.   rtx new = 0;
  1935.   int offset;
  1936.   rtx temp;
  1937.   rtx seq;
  1938.   int i, j;
  1939.   char *fmt;
  1940.  
  1941.   /* Re-start here to avoid recursion in common cases.  */
  1942.  restart:
  1943.  
  1944.   x = *loc;
  1945.   if (x == 0)
  1946.     return;
  1947.  
  1948.   code = GET_CODE (x);
  1949.  
  1950.   /* Check for some special cases.  */
  1951.   switch (code)
  1952.     {
  1953.     case CONST_INT:
  1954.     case CONST_DOUBLE:
  1955.     case CONST:
  1956.     case SYMBOL_REF:
  1957.     case CODE_LABEL:
  1958.     case PC:
  1959.     case CC0:
  1960.     case ASM_INPUT:
  1961.     case ADDR_VEC:
  1962.     case ADDR_DIFF_VEC:
  1963.     case RETURN:
  1964.       return;
  1965.  
  1966.     case SET:
  1967.       /* We are allowed to set the virtual registers.  This means that
  1968.      that the actual register should receive the source minus the
  1969.      appropriate offset.  This is used, for example, in the handling
  1970.      of non-local gotos.  */
  1971.       if (SET_DEST (x) == virtual_incoming_args_rtx)
  1972.     new = arg_pointer_rtx, offset = - in_arg_offset;
  1973.       else if (SET_DEST (x) == virtual_stack_vars_rtx)
  1974.     new = frame_pointer_rtx, offset = - var_offset;
  1975.       else if (SET_DEST (x) == virtual_stack_dynamic_rtx)
  1976.     new = stack_pointer_rtx, offset = - dynamic_offset;
  1977.       else if (SET_DEST (x) == virtual_outgoing_args_rtx)
  1978.     new = stack_pointer_rtx, offset = - out_arg_offset;
  1979.  
  1980.       if (new)
  1981.     {
  1982.       /* The only valid sources here are PLUS or REG.  Just do
  1983.          the simplest possible thing to handle them.  */
  1984.       if (GET_CODE (SET_SRC (x)) != REG
  1985.           && GET_CODE (SET_SRC (x)) != PLUS)
  1986.         abort ();
  1987.  
  1988.       start_sequence ();
  1989.       if (GET_CODE (SET_SRC (x)) != REG)
  1990.         temp = force_operand (SET_SRC (x), 0);
  1991.       else
  1992.         temp = SET_SRC (x);
  1993.       temp = force_operand (plus_constant (temp, offset), 0);
  1994.       seq = get_insns ();
  1995.       end_sequence ();
  1996.  
  1997.       emit_insns_before (seq, object);
  1998.       SET_DEST (x) = new;
  1999.       if (!validate_change (object, &SET_SRC (x), temp, 0))
  2000.         abort ();
  2001.       return;
  2002.     }
  2003.  
  2004.       instantiate_virtual_regs_1 (&SET_DEST (x), object);
  2005.       loc = &SET_SRC (x);
  2006.       goto restart;
  2007.  
  2008.     case PLUS:
  2009.       /* Handle special case of virtual register plus constant.  */
  2010.       if (CONSTANT_P (XEXP (x, 1)))
  2011.     {
  2012.       /* Check for (plus (plus VIRT foo) (const_int)) first.  */
  2013.       if (GET_CODE (XEXP (x, 0)) == PLUS)
  2014.         {
  2015.           rtx inner = XEXP (XEXP (x, 0), 0);
  2016.  
  2017.           if (inner == virtual_incoming_args_rtx)
  2018.         new = arg_pointer_rtx, offset = in_arg_offset;
  2019.           else if (inner == virtual_stack_vars_rtx)
  2020.         new = frame_pointer_rtx, offset = var_offset;
  2021.           else if (inner == virtual_stack_dynamic_rtx)
  2022.         new = stack_pointer_rtx, offset = dynamic_offset;
  2023.           else if (inner == virtual_outgoing_args_rtx)
  2024.         new = stack_pointer_rtx, offset = out_arg_offset;
  2025.           else
  2026.         {
  2027.           loc = &XEXP (x, 0);
  2028.           goto restart;
  2029.         }
  2030.  
  2031.           instantiate_virtual_regs_1 (&XEXP (XEXP (x, 0), 1), object);
  2032.           new = gen_rtx (PLUS, Pmode, new, XEXP (XEXP (x, 0), 1));
  2033.         }
  2034.  
  2035.       else if (XEXP (x, 0) == virtual_incoming_args_rtx)
  2036.         new = arg_pointer_rtx, offset = in_arg_offset;
  2037.       else if (XEXP (x, 0) == virtual_stack_vars_rtx)
  2038.         new = frame_pointer_rtx, offset = var_offset;
  2039.       else if (XEXP (x, 0) == virtual_stack_dynamic_rtx)
  2040.         new = stack_pointer_rtx, offset = dynamic_offset;
  2041.       else if (XEXP (x, 0) == virtual_outgoing_args_rtx)
  2042.         new = stack_pointer_rtx, offset = out_arg_offset;
  2043.       else
  2044.         {
  2045.           /* We know the second operand is a constant.  Unless the
  2046.          first operand is a REG (which has been already checked),
  2047.          it needs to be checked.  */
  2048.           if (GET_CODE (XEXP (x, 0)) != REG)
  2049.         {
  2050.           loc = &XEXP (x, 0);
  2051.           goto restart;
  2052.         }
  2053.           return;
  2054.         }
  2055.  
  2056.       XEXP (x, 0) = new;
  2057.       new = plus_constant (XEXP (x, 1), offset);
  2058.  
  2059.       /* If the new constant is zero, try to replace the sum with its
  2060.          first operand.  */
  2061.       if (new == const0_rtx
  2062.           && validate_change (object, loc, XEXP (x, 0), 0))
  2063.         return;
  2064.  
  2065.       /* Next try to replace constant with new one.  */
  2066.       if (!validate_change (object, &XEXP (x, 1), new, 0))
  2067.         {
  2068.           /* If this is not an INSN, forget it.  */
  2069.           if (GET_CODE (object) == MEM)
  2070.         return;
  2071.  
  2072.           /* Otherwise copy the new constant into a register and replace
  2073.          constant with that register.  */
  2074.           temp = gen_reg_rtx (Pmode);
  2075.           if (validate_change (object, &XEXP (x, 1), temp, 0))
  2076.         emit_insn_before (gen_move_insn (temp, new), object);
  2077.           else
  2078.         {
  2079.           /* If that didn't work, replace this expression with a
  2080.              register containing the sum.  */
  2081.           start_sequence ();
  2082.           temp = force_operand (plus_constant (XEXP (x, 0), new), 0);
  2083.           seq = get_insns ();
  2084.           end_sequence ();
  2085.  
  2086.           emit_insns_before (seq, object);
  2087.           if (!validate_change (object, loc, temp, 0))
  2088.             abort ();
  2089.         }
  2090.         }
  2091.  
  2092.       return;
  2093.     }
  2094.  
  2095.       /* Fall through to generic two-operand expression case.  */
  2096.     case EXPR_LIST:
  2097.     case CALL:
  2098.     case COMPARE:
  2099.     case MINUS:
  2100.     case MULT:
  2101.     case DIV:      case UDIV:
  2102.     case MOD:      case UMOD:
  2103.     case AND:      case IOR:      case XOR:
  2104.     case LSHIFT:   case ASHIFT:   case ROTATE:
  2105.     case ASHIFTRT: case LSHIFTRT: case ROTATERT:
  2106.     case NE:       case EQ:
  2107.     case GE:       case GT:       case GEU:    case GTU:
  2108.     case LE:       case LT:       case LEU:    case LTU:
  2109.       if (XEXP (x, 1) && ! CONSTANT_P (XEXP (x, 1)))
  2110.     instantiate_virtual_regs_1 (&XEXP (x, 1), object);
  2111.       loc = &XEXP (x, 0);
  2112.       goto restart;
  2113.  
  2114.     case MEM:
  2115.       /* Most cases of MEM that convert to valid addresses have already been
  2116.      handled by our scan of regno_reg_rtx.  The only special handling we
  2117.      need here is to make a copy of the rtx to ensure it isn't being
  2118.      shared if we have to change it to a psuedo. 
  2119.  
  2120.      If the rtx is a simple reference to an address via a virtual register,
  2121.      it can potentially be shared.  In such cases, first try to make it
  2122.      a valid address, which can also be shared.  Otherwise, copy it and
  2123.      proceed normally. 
  2124.  
  2125.      First check for common cases that need no processing.  These are
  2126.      usually due to instantiation already being done on a previous instance
  2127.      of a shared rtx.  */
  2128.  
  2129.       temp = XEXP (x, 0);
  2130.       if (CONSTANT_ADDRESS_P (temp)
  2131. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2132.       || temp == arg_pointer_rtx
  2133. #endif
  2134.       || temp == frame_pointer_rtx)
  2135.     return;
  2136.  
  2137.       if (GET_CODE (temp) == PLUS
  2138.       && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2139.       && (XEXP (temp, 0) == frame_pointer_rtx
  2140. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2141.           || XEXP (temp, 0) == arg_pointer_rtx
  2142. #endif
  2143.           ))
  2144.     return;
  2145.  
  2146.       if (temp == virtual_stack_vars_rtx
  2147.       || temp == virtual_incoming_args_rtx
  2148.       || (GET_CODE (temp) == PLUS
  2149.           && CONSTANT_ADDRESS_P (XEXP (temp, 1))
  2150.           && (XEXP (temp, 0) == virtual_stack_vars_rtx
  2151.           || XEXP (temp, 0) == virtual_incoming_args_rtx)))
  2152.     {
  2153.       /* This MEM may be shared.  If the substitution can be done without
  2154.          the need to generate new pseudos, we want to do it in place
  2155.          so all copies of the shared rtx benefit.  The call below will
  2156.          only make substitutions if the resulting address is still
  2157.          valid.
  2158.  
  2159.          Note that we cannot pass X as the object in the recursive call
  2160.          since the insn being processed may not allow all valid
  2161.          addresses.  */
  2162.  
  2163.       instantiate_virtual_regs_1 (&XEXP (x, 0), object);
  2164.  
  2165.       /* If no longer has a virtual register reference, we were able to
  2166.          do the instantiation without making new pseudos.  So we are
  2167.          done.  */
  2168.       if (! reg_mentioned_p (virtual_stack_vars_rtx, XEXP (x, 0))
  2169.           && ! reg_mentioned_p (virtual_incoming_args_rtx, XEXP (x, 0)))
  2170.         return;
  2171.  
  2172.       /* Otherwise make a copy and process that copy.  We copy the entire
  2173.          RTL expression since it might be a PLUS which could also be
  2174.          shared.  */
  2175.       *loc = x = copy_rtx (x);
  2176.     }
  2177.  
  2178.       /* Fall through to generic unary operation case.  */
  2179.     case USE:
  2180.     case CLOBBER:
  2181.     case SUBREG:
  2182.     case STRICT_LOW_PART:
  2183.     case IF_THEN_ELSE:
  2184.     case NEG:          case NOT:
  2185.     case PRE_DEC:      case PRE_INC:      case POST_DEC:    case POST_INC:
  2186.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2187.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2188.     case FLOAT:        case FIX:
  2189.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2190.     case ABS:
  2191.     case SQRT:
  2192.     case FFS:
  2193.       /* These case either have just one operand or we know that we need not
  2194.      check the rest of the operands.  */
  2195.       loc = &XEXP (x, 0);
  2196.       goto restart;
  2197.  
  2198.     case REG:
  2199.       /* Try to replace with a PLUS.  If that doesn't work, compute the sum
  2200.      in front of this insn and substitute the temporary.  */
  2201.       if (x == virtual_incoming_args_rtx)
  2202.     new = arg_pointer_rtx, offset = in_arg_offset;
  2203.       else if (x == virtual_stack_vars_rtx)
  2204.     new = frame_pointer_rtx, offset = var_offset;
  2205.       else if (x == virtual_stack_dynamic_rtx)
  2206.     new = stack_pointer_rtx, offset = dynamic_offset;
  2207.       else if (x == virtual_outgoing_args_rtx)
  2208.     new = stack_pointer_rtx, offset = out_arg_offset;
  2209.  
  2210.       if (new)
  2211.     {
  2212.       temp = plus_constant (new, offset);
  2213.       if (!validate_change (object, loc, temp, 0))
  2214.         {
  2215.           /* Ignore this instantiation if not insn.  */
  2216.           if (GET_CODE (object) == MEM)
  2217.         return;
  2218.  
  2219.           start_sequence ();
  2220.           temp = force_operand (temp, 0);
  2221.           seq = get_insns ();
  2222.           end_sequence ();
  2223.  
  2224.           emit_insns_before (seq, object);
  2225.           if (! validate_change (object, loc, temp, 0)
  2226.           && ! validate_replace_rtx (x, temp, object))
  2227.         abort ();
  2228.         }
  2229.     }
  2230.  
  2231.       return;
  2232.     }
  2233.  
  2234.   /* Scan all subexpressions.  */
  2235.   fmt = GET_RTX_FORMAT (code);
  2236.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  2237.     if (*fmt == 'e')
  2238.       instantiate_virtual_regs_1 (&XEXP (x, i), object);
  2239.     else if (*fmt == 'E')
  2240.       for (j = 0; j < XVECLEN (x, i); j++)
  2241.     instantiate_virtual_regs_1 (&XVECEXP (x, i, j), object);
  2242. }
  2243.  
  2244. /* Optimization: assuming this function does not receive nonlocal gotos,
  2245.    delete the handlers for such, as well as the insns to establish
  2246.    and disestablish them.  */
  2247.  
  2248. static void
  2249. delete_handlers ()
  2250. {
  2251.   rtx insn;
  2252.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  2253.     {
  2254.       /* Delete the handler by turning off the flag that would
  2255.      prevent jump_optimize from deleting it.
  2256.      Also permit deletion of the nonlocal labels themselves
  2257.      if nothing local refers to them.  */
  2258.       if (GET_CODE (insn) == CODE_LABEL)
  2259.     LABEL_PRESERVE_P (insn) = 0;
  2260.       if (GET_CODE (insn) == INSN
  2261.       && GET_CODE (PATTERN (insn)) == SET
  2262.       && (SET_DEST (PATTERN (insn)) == nonlocal_goto_handler_slot
  2263.           || SET_SRC (PATTERN (insn)) == nonlocal_goto_handler_slot
  2264.           || SET_DEST (PATTERN (insn)) == nonlocal_goto_stack_level
  2265.           || SET_SRC (PATTERN (insn)) == nonlocal_goto_stack_level))
  2266.     delete_insn (insn);
  2267.     }
  2268. }
  2269.  
  2270. /* Output a USE for any register use in RTL.
  2271.    This is used with -noreg to mark the extent of lifespan
  2272.    of any registers used in a user-visible variable's DECL_RTL.  */
  2273.  
  2274. void
  2275. use_variable (rtl)
  2276.      rtx rtl;
  2277. {
  2278.   if (GET_CODE (rtl) == REG)
  2279.     /* This is a register variable.  */
  2280.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  2281.   else if (GET_CODE (rtl) == MEM
  2282.        && GET_CODE (XEXP (rtl, 0)) == REG
  2283.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2284.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER))
  2285.     /* This is a variable-sized structure.  */
  2286.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  2287. }
  2288.  
  2289. /* Like use_variable except that it outputs the USEs after INSN
  2290.    instead of at the end of the insn-chain.  */
  2291.  
  2292. void
  2293. use_variable_after (rtl, insn)
  2294.      rtx rtl, insn;
  2295. {
  2296.   if (GET_CODE (rtl) == REG)
  2297.     /* This is a register variable.  */
  2298.     emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
  2299.   else if (GET_CODE (rtl) == MEM
  2300.        && GET_CODE (XEXP (rtl, 0)) == REG
  2301.        && (REGNO (XEXP (rtl, 0)) < FIRST_VIRTUAL_REGISTER
  2302.            || REGNO (XEXP (rtl, 0)) > LAST_VIRTUAL_REGISTER))
  2303.     /* This is a variable-sized structure.  */
  2304.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
  2305. }
  2306.  
  2307. int
  2308. max_parm_reg_num ()
  2309. {
  2310.   return max_parm_reg;
  2311. }
  2312.  
  2313. /* Return the first insn following those generated by `assign_parms'.  */
  2314.  
  2315. rtx
  2316. get_first_nonparm_insn ()
  2317. {
  2318.   if (last_parm_insn)
  2319.     return NEXT_INSN (last_parm_insn);
  2320.   return get_insns ();
  2321. }
  2322.  
  2323. /* Return 1 if EXP returns an aggregate value, for which an address
  2324.    must be passed to the function or returned by the function.  */
  2325.  
  2326. int
  2327. aggregate_value_p (exp)
  2328.      tree exp;
  2329. {
  2330.   if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
  2331.     return 1;
  2332.   if (RETURN_IN_MEMORY (TREE_TYPE (exp)))
  2333.     return 1;
  2334.   if (flag_pcc_struct_return
  2335.       && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
  2336.       || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE))
  2337.     return 1;
  2338.   return 0;
  2339. }
  2340.  
  2341. /* Assign RTL expressions to the function's parameters.
  2342.    This may involve copying them into registers and using
  2343.    those registers as the RTL for them.
  2344.  
  2345.    If SECOND_TIME is non-zero it means that this function is being
  2346.    called a second time.  This is done by integrate.c when a function's
  2347.    compilation is deferred.  We need to come back here in case the
  2348.    FUNCTION_ARG macro computes items needed for the rest of the compilation
  2349.    (such as changing which registers are fixed or caller-saved).  But suppress
  2350.    writing any insns or setting DECL_RTL of anything in this case.  */
  2351.  
  2352. void
  2353. assign_parms (fndecl, second_time)
  2354.      tree fndecl;
  2355.      int second_time;
  2356. {
  2357.   register tree parm;
  2358.   register rtx entry_parm = 0;
  2359.   register rtx stack_parm = 0;
  2360.   CUMULATIVE_ARGS args_so_far;
  2361.   enum machine_mode passed_mode, nominal_mode;
  2362.   /* Total space needed so far for args on the stack,
  2363.      given as a constant and a tree-expression.  */
  2364.   struct args_size stack_args_size;
  2365.   tree fntype = TREE_TYPE (fndecl);
  2366.   tree fnargs = DECL_ARGUMENTS (fndecl);
  2367.   /* This is used for the arg pointer when referring to stack args.  */
  2368.   rtx internal_arg_pointer;
  2369.   /* This is a dummy PARM_DECL that we used for the function result if 
  2370.      the function returns a structure.  */
  2371.   tree function_result_decl = 0;
  2372.   int nparmregs = list_length (fnargs) + LAST_VIRTUAL_REGISTER + 1;
  2373.   int varargs_setup = 0;
  2374.  
  2375.   /* Nonzero if the last arg is named `__builtin_va_alist',
  2376.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  2377.      this should be stuck onto the stack as if it had arrived there.  */
  2378.   int vararg
  2379.     = (fnargs
  2380.        && (parm = tree_last (fnargs)) != 0
  2381.        && DECL_NAME (parm)
  2382.        && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)),
  2383.              "__builtin_va_alist")));
  2384.  
  2385.   /* Nonzero if function takes extra anonymous args.
  2386.      This means the last named arg must be on the stack
  2387.      right before the anonymous ones. */
  2388.   int stdarg
  2389.     = (TYPE_ARG_TYPES (fntype) != 0
  2390.        && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  2391.        != void_type_node));
  2392.  
  2393.   /* If the reg that the virtual arg pointer will be translated into is
  2394.      not a fixed reg or is the stack pointer, make a copy of the virtual
  2395.      arg pointer, and address parms via the copy.  The frame pointer is
  2396.      considered fixed even though it is not marked as such.
  2397.  
  2398.      The second time through, simply use ap to avoid generating rtx.  */
  2399.  
  2400.   if ((ARG_POINTER_REGNUM == STACK_POINTER_REGNUM
  2401.        || ! (fixed_regs[ARG_POINTER_REGNUM]
  2402.          || ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM))
  2403.       && ! second_time)
  2404.     internal_arg_pointer = copy_to_reg (virtual_incoming_args_rtx);
  2405.   else
  2406.     internal_arg_pointer = virtual_incoming_args_rtx;
  2407.  
  2408.   stack_args_size.constant = 0;
  2409.   stack_args_size.var = 0;
  2410.  
  2411.   /* If struct value address is treated as the first argument, make it so.  */
  2412.   if (aggregate_value_p (DECL_RESULT (fndecl))
  2413.       && ! current_function_returns_pcc_struct
  2414.       && struct_value_incoming_rtx == 0)
  2415.     {
  2416.       tree type = build_pointer_type (fntype);
  2417.  
  2418.       function_result_decl = build_decl (PARM_DECL, 0, type);
  2419.  
  2420.       DECL_ARG_TYPE (function_result_decl) = type;
  2421.       TREE_CHAIN (function_result_decl) = fnargs;
  2422.       fnargs = function_result_decl;
  2423.     }
  2424.                    
  2425.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2426.   bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  2427.  
  2428. #ifdef INIT_CUMULATIVE_INCOMING_ARGS
  2429.   INIT_CUMULATIVE_INCOMING_ARGS (args_so_far, fntype, 0);
  2430. #else
  2431.   INIT_CUMULATIVE_ARGS (args_so_far, fntype, 0);
  2432. #endif
  2433.  
  2434.   /* We haven't yet found an argument that we must push and pretend the
  2435.      caller did.  */
  2436.   current_function_pretend_args_size = 0;
  2437.  
  2438.   for (parm = fnargs; parm; parm = TREE_CHAIN (parm))
  2439.     {
  2440.       int aggregate
  2441.     = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  2442.        || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  2443.        || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  2444.       struct args_size stack_offset;
  2445.       struct args_size arg_size;
  2446.       int passed_pointer = 0;
  2447.       tree passed_type = DECL_ARG_TYPE (parm);
  2448.  
  2449.       /* Set LAST_NAMED if this is last named arg before some
  2450.      anonymous args.  We treat it as if it were anonymous too.  */
  2451.       int last_named = ((TREE_CHAIN (parm) == 0
  2452.              || DECL_NAME (TREE_CHAIN (parm)) == 0)
  2453.             && (vararg || stdarg));
  2454.  
  2455.       if (TREE_TYPE (parm) == error_mark_node
  2456.       /* This can happen after weird syntax errors
  2457.          or if an enum type is defined among the parms.  */
  2458.       || TREE_CODE (parm) != PARM_DECL
  2459.       || passed_type == NULL)
  2460.     {
  2461.       DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx);
  2462.       TREE_USED (parm) = 1;
  2463.       continue;
  2464.     }
  2465.  
  2466.       /* Find mode of arg as it is passed, and mode of arg
  2467.      as it should be during execution of this function.  */
  2468.       passed_mode = TYPE_MODE (passed_type);
  2469.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  2470.  
  2471. #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
  2472.       /* See if this arg was passed by invisible reference.  */
  2473.       if (FUNCTION_ARG_PASS_BY_REFERENCE (args_so_far, passed_mode,
  2474.                       passed_type, ! last_named))
  2475.     {
  2476.       passed_type = build_pointer_type (passed_type);
  2477.       passed_pointer = 1;
  2478.       passed_mode = nominal_mode = Pmode;
  2479.     }
  2480. #endif
  2481.  
  2482.       /* Let machine desc say which reg (if any) the parm arrives in.
  2483.      0 means it arrives on the stack.  */
  2484. #ifdef FUNCTION_INCOMING_ARG
  2485.       entry_parm = FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  2486.                       passed_type, ! last_named);
  2487. #else
  2488.       entry_parm = FUNCTION_ARG (args_so_far, passed_mode,
  2489.                  passed_type, ! last_named);
  2490. #endif
  2491.  
  2492. #ifdef SETUP_INCOMING_VARARGS
  2493.       /* If this is the last named parameter, do any required setup for
  2494.      varargs or stdargs.  We need to know about the case of this being an
  2495.      addressable type, in which case we skip the registers it
  2496.      would have arrived in.
  2497.  
  2498.      For stdargs, LAST_NAMED will be set for two parameters, the one that
  2499.      is actually the last named, and the dummy parameter.  We only
  2500.      want to do this action once.
  2501.  
  2502.      Also, indicate when RTL generation is to be suppressed.  */
  2503.       if (last_named && !varargs_setup)
  2504.     {
  2505.       SETUP_INCOMING_VARARGS (args_so_far, passed_mode, passed_type,
  2506.                   current_function_pretend_args_size,
  2507.                   second_time);
  2508.       varargs_setup = 1;
  2509.     }
  2510. #endif
  2511.  
  2512.       /* Determine parm's home in the stack,
  2513.      in case it arrives in the stack or we should pretend it did.
  2514.  
  2515.      Compute the stack position and rtx where the argument arrives
  2516.      and its size.
  2517.  
  2518.      There is one complexity here:  If this was a parameter that would
  2519.      have been passed in registers, but wasn't only because it is
  2520.      __builtin_va_alist, we want locate_and_pad_parm to treat it as if
  2521.      it came in a register so that REG_PARM_STACK_SPACE isn't skipped.
  2522.      In this case, we call FUNCTION_ARG with NAMED set to 1 instead of
  2523.      0 as it was the previous time.  */
  2524.  
  2525.       locate_and_pad_parm (passed_mode, passed_type,
  2526. #ifdef STACK_PARMS_IN_REG_PARM_AREA
  2527.                1,
  2528. #else
  2529. #ifdef FUNCTION_INCOMING_ARG
  2530.                FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  2531.                           passed_type,
  2532.                           (! last_named
  2533.                            || varargs_setup)) != 0,
  2534. #else
  2535.                FUNCTION_ARG (args_so_far, passed_mode,
  2536.                      passed_type,
  2537.                      ! last_named || varargs_setup) != 0,
  2538. #endif
  2539. #endif
  2540.                fndecl, &stack_args_size, &stack_offset, &arg_size);
  2541.  
  2542.       if (! second_time)
  2543.     {
  2544.       rtx offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2545.  
  2546.       if (offset_rtx == const0_rtx)
  2547.         stack_parm = gen_rtx (MEM, passed_mode, internal_arg_pointer);
  2548.       else
  2549.         stack_parm = gen_rtx (MEM, passed_mode,
  2550.                   gen_rtx (PLUS, Pmode,
  2551.                        internal_arg_pointer, offset_rtx));
  2552.  
  2553.       /* If this is a memory ref that contains aggregate components,
  2554.          mark it as such for cse and loop optimize.  */
  2555.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  2556.     }
  2557.  
  2558.       /* If this parameter was passed both in registers and in the stack,
  2559.      use the copy on the stack.  */
  2560.       if (MUST_PASS_IN_STACK (passed_mode, passed_type))
  2561.     entry_parm = 0;
  2562.  
  2563.       /* If this parm was passed part in regs and part in memory,
  2564.      pretend it arrived entirely in memory
  2565.      by pushing the register-part onto the stack.
  2566.  
  2567.      In the special case of a DImode or DFmode that is split,
  2568.      we could put it together in a pseudoreg directly,
  2569.      but for now that's not worth bothering with.  */
  2570.  
  2571.       if (entry_parm)
  2572.     {
  2573.       int nregs = 0;
  2574. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  2575.       nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  2576.                           passed_type, ! last_named);
  2577. #endif
  2578.  
  2579.       if (nregs > 0)
  2580.         {
  2581.           current_function_pretend_args_size
  2582.         = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  2583.            / (PARM_BOUNDARY / BITS_PER_UNIT)
  2584.            * (PARM_BOUNDARY / BITS_PER_UNIT));
  2585.  
  2586.           if (! second_time)
  2587.         move_block_from_reg (REGNO (entry_parm),
  2588.                      validize_mem (stack_parm), nregs);
  2589.           entry_parm = stack_parm;
  2590.         }
  2591.     }
  2592.  
  2593.       /* If we didn't decide this parm came in a register,
  2594.      by default it came on the stack.  */
  2595.       if (entry_parm == 0)
  2596.     entry_parm = stack_parm;
  2597.  
  2598.       /* Record permanently how this parm was passed.  */
  2599.       if (! second_time)
  2600.     DECL_INCOMING_RTL (parm) = entry_parm;
  2601.  
  2602.       /* If there is actually space on the stack for this parm,
  2603.      count it in stack_args_size; otherwise set stack_parm to 0
  2604.      to indicate there is no preallocated stack slot for the parm.  */
  2605.  
  2606.       if (entry_parm == stack_parm
  2607. #ifdef REG_PARM_STACK_SPACE
  2608.       /* On some machines, even if a parm value arrives in a register
  2609.          there is still an (uninitialized) stack slot allocated for it.  */
  2610.       || REG_PARM_STACK_SPACE (fndecl) > 0
  2611. #endif
  2612.       )
  2613.     {
  2614.       stack_args_size.constant += arg_size.constant;
  2615.       if (arg_size.var)
  2616.         ADD_PARM_SIZE (stack_args_size, arg_size.var);
  2617.     }
  2618.       else
  2619.     /* No stack slot was pushed for this parm.  */
  2620.     stack_parm = 0;
  2621.  
  2622.       /* Update info on where next arg arrives in registers.  */
  2623.  
  2624.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode,
  2625.                 passed_type, ! last_named);
  2626.  
  2627.       /* If this is our second time through, we are done with this parm. */
  2628.       if (second_time)
  2629.     continue;
  2630.  
  2631.       /* Now adjust STACK_PARM to the mode and precise location
  2632.      where this parameter should live during execution,
  2633.      if we discover that it must live in the stack during execution.
  2634.      To make debuggers happier on big-endian machines, we store
  2635.      the value in the last bytes of the space available.  */
  2636.  
  2637.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  2638.       && stack_parm != 0)
  2639.     {
  2640.       rtx offset_rtx;
  2641.  
  2642. #if BYTES_BIG_ENDIAN
  2643.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  2644.         stack_offset.constant += (GET_MODE_SIZE (passed_mode)
  2645.                       - GET_MODE_SIZE (nominal_mode));
  2646. #endif
  2647.  
  2648.       offset_rtx = ARGS_SIZE_RTX (stack_offset);
  2649.       if (offset_rtx == const0_rtx)
  2650.         stack_parm = gen_rtx (MEM, nominal_mode, internal_arg_pointer);
  2651.       else
  2652.         stack_parm = gen_rtx (MEM, nominal_mode,
  2653.                   gen_rtx (PLUS, Pmode,
  2654.                        internal_arg_pointer, offset_rtx));
  2655.  
  2656.       /* If this is a memory ref that contains aggregate components,
  2657.          mark it as such for cse and loop optimize.  */
  2658.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  2659.     }
  2660.  
  2661.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  2662.      in the mode in which it arrives.
  2663.      STACK_PARM is an RTX for a stack slot where the parameter can live
  2664.      during the function (in case we want to put it there).
  2665.      STACK_PARM is 0 if no stack slot was pushed for it.
  2666.  
  2667.      Now output code if necessary to convert ENTRY_PARM to
  2668.      the type in which this function declares it,
  2669.      and store that result in an appropriate place,
  2670.      which may be a pseudo reg, may be STACK_PARM,
  2671.      or may be a local stack slot if STACK_PARM is 0.
  2672.  
  2673.      Set DECL_RTL to that place.  */
  2674.  
  2675.       if (nominal_mode == BLKmode)
  2676.     {
  2677.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  2678.       if (GET_CODE (entry_parm) == REG)
  2679.         {
  2680.           int size_stored = CEIL_ROUND (int_size_in_bytes (TREE_TYPE (parm)),
  2681.                         UNITS_PER_WORD);
  2682.  
  2683.           /* Note that we will be storing an integral number of words.
  2684.          So we have to be careful to ensure that we allocate an
  2685.          integral number of words.  We do this below in the
  2686.          assign_stack_local if space was not allocated in the argument
  2687.          list.  If it was, this will not work if PARM_BOUNDARY is not
  2688.          a multiple of BITS_PER_WORD.  It isn't clear how to fix this
  2689.          if it becomes a problem.  */
  2690.  
  2691.           if (stack_parm == 0)
  2692.         stack_parm
  2693.           = assign_stack_local (GET_MODE (entry_parm), size_stored, 0);
  2694.           else if (PARM_BOUNDARY % BITS_PER_WORD != 0)
  2695.         abort ();
  2696.  
  2697.           move_block_from_reg (REGNO (entry_parm),
  2698.                    validize_mem (stack_parm),
  2699.                    size_stored / UNITS_PER_WORD);
  2700.         }
  2701.       DECL_RTL (parm) = stack_parm;
  2702.     }
  2703.       else if (! (
  2704. #if 0 /* This change was turned off because it makes compilation bigger.  */
  2705.           !optimize
  2706. #else /* It's not clear why the following was replaced.  */
  2707.           /* Obsoleted by preceeding line. */
  2708.           (obey_regdecls && ! TREE_REGDECL (parm)
  2709.            && ! TREE_INLINE (fndecl))
  2710. #endif
  2711.           /* layout_decl may set this.  */
  2712.           || TREE_ADDRESSABLE (parm)
  2713.           || TREE_SIDE_EFFECTS (parm)
  2714.           /* If -ffloat-store specified, don't put explicit
  2715.              float variables into registers.  */
  2716.           || (flag_float_store
  2717.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE))
  2718.            /* Always assign pseudo to structure return or item passed
  2719.           by invisible reference.  */
  2720.            || passed_pointer || parm == function_result_decl)
  2721.     {
  2722.       /* Store the parm in a pseudoregister during the function.  */
  2723.       register rtx parmreg = gen_reg_rtx (nominal_mode);
  2724.  
  2725.       REG_USERVAR_P (parmreg) = 1;
  2726.  
  2727.       /* If this was an item that we received a pointer to, set DECL_RTL
  2728.          appropriately.  */
  2729.       if (passed_pointer)
  2730.         DECL_RTL (parm) = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (passed_type)), parmreg);
  2731.       else
  2732.         DECL_RTL (parm) = parmreg;
  2733.  
  2734.       /* Copy the value into the register.  */
  2735.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  2736.         convert_move (parmreg, validize_mem (entry_parm), 0);
  2737.       else
  2738.         emit_move_insn (parmreg, validize_mem (entry_parm));
  2739.  
  2740.       /* In any case, record the parm's desired stack location
  2741.          in case we later discover it must live in the stack.  */
  2742.       if (REGNO (parmreg) >= nparmregs)
  2743.         {
  2744.           rtx *new;
  2745.           nparmregs = REGNO (parmreg) + 5;
  2746.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  2747.           bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  2748.           parm_reg_stack_loc = new;
  2749.         }
  2750.       parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  2751.  
  2752.       /* Mark the register as eliminable if we did no conversion
  2753.          and it was copied from memory at a fixed offset,
  2754.          and the arg pointer was not copied to a pseudo-reg.
  2755.          If the arg pointer is a pseudo reg or the offset formed
  2756.          an invalid address, such memory-equivalences
  2757.          as we make here would screw up life analysis for it.  */
  2758.       if (nominal_mode == passed_mode
  2759.           && GET_CODE (entry_parm) == MEM
  2760.           && stack_offset.var == 0
  2761.           && reg_mentioned_p (virtual_incoming_args_rtx,
  2762.                   XEXP (entry_parm, 0)))
  2763.         REG_NOTES (get_last_insn ())
  2764.           = gen_rtx (EXPR_LIST, REG_EQUIV,
  2765.              entry_parm, REG_NOTES (get_last_insn ()));
  2766.  
  2767.       /* For pointer data type, suggest pointer register.  */
  2768.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  2769.         mark_reg_pointer (parmreg);
  2770.     }
  2771.       else
  2772.     {
  2773.       /* Value must be stored in the stack slot STACK_PARM
  2774.          during function execution.  */
  2775.  
  2776.       if (passed_mode != nominal_mode)
  2777.         /* Conversion is required.  */
  2778.         entry_parm = convert_to_mode (nominal_mode, entry_parm, 0);
  2779.  
  2780.       if (entry_parm != stack_parm)
  2781.         {
  2782.           if (stack_parm == 0)
  2783.         stack_parm = assign_stack_local (GET_MODE (entry_parm),
  2784.                          GET_MODE_SIZE (GET_MODE (entry_parm)), 0);
  2785.           emit_move_insn (validize_mem (stack_parm),
  2786.                   validize_mem (entry_parm));
  2787.         }
  2788.  
  2789.       DECL_RTL (parm) = stack_parm;
  2790.     }
  2791.       
  2792.       /* If this "parameter" was the place where we are receiving the
  2793.      function's incoming structure pointer, set up the result.  */
  2794.       if (parm == function_result_decl)
  2795.     current_function_return_rtx = DECL_RTL (DECL_RESULT (fndecl))
  2796.       = gen_rtx (MEM, DECL_MODE (DECL_RESULT (fndecl)), DECL_RTL (parm));
  2797.  
  2798.       if (TREE_THIS_VOLATILE (parm))
  2799.     MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
  2800.       if (TREE_READONLY (parm))
  2801.     RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
  2802.     }
  2803.  
  2804.   max_parm_reg = max_reg_num ();
  2805.   last_parm_insn = get_last_insn ();
  2806.  
  2807.   current_function_args_size = stack_args_size.constant;
  2808.  
  2809.   /* Adjust function incoming argument size for alignment and
  2810.      minimum length.  */
  2811.  
  2812. #ifdef REG_PARM_STACK_SPACE
  2813.   current_function_args_size = MAX (current_function_args_size,
  2814.                     REG_PARM_STACK_SPACE (fndecl));
  2815. #endif
  2816.  
  2817. #ifdef STACK_BOUNDARY
  2818. #define STACK_BYTES (STACK_BOUNDARY / BITS_PER_UNIT)
  2819.  
  2820.   current_function_args_size
  2821.     = ((current_function_args_size + STACK_BYTES - 1)
  2822.        / STACK_BYTES) * STACK_BYTES;
  2823. #endif  
  2824.  
  2825.   current_function_arg_offset_rtx = ARGS_SIZE_RTX (stack_args_size);
  2826.  
  2827.   /* See how many bytes, if any, of its args a function should try to pop
  2828.      on return.  */
  2829.  
  2830.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (fndecl),
  2831.                          current_function_args_size);
  2832. }
  2833.  
  2834. /* Compute the size and offset from the start of the stacked arguments for a
  2835.    parm passed in mode PASSED_MODE and with type TYPE.
  2836.  
  2837.    INITIAL_OFFSET_PTR points to the current offset into the stacked
  2838.    arguments.
  2839.  
  2840.    The starting offset and size for this parm are returned in *OFFSET_PTR
  2841.    and *ARG_SIZE_PTR, respectively.
  2842.  
  2843.    IN_REGS is non-zero if the argument will be passed in registers.  It will
  2844.    never be set if REG_PARM_STACK_SPACE is not defined.
  2845.  
  2846.    FNDECL is the function in which the argument was defined.
  2847.  
  2848.    There are two types of rounding that are done.  The first, controlled by
  2849.    FUNCTION_ARG_BOUNDARY, forces the offset from the start of the argument
  2850.    list to be aligned to the specific boundary (in bits).  This rounding
  2851.    affects the initial and starting offsets, but not the argument size.
  2852.  
  2853.    The second, controlled by FUNCTION_ARG_PADDING and PARM_BOUNDARY,
  2854.    optionally rounds the size of the parm to PARM_BOUNDARY.  The
  2855.    initial offset is not affected by this rounding, while the size always
  2856.    is and the starting offset may be.  */
  2857.  
  2858. void
  2859. locate_and_pad_parm (passed_mode, type, in_regs, fndecl,
  2860.              initial_offset_ptr, offset_ptr, arg_size_ptr)
  2861.      enum machine_mode passed_mode;
  2862.      tree type;
  2863.      int in_regs;
  2864.      tree fndecl;
  2865.      struct args_size *initial_offset_ptr;
  2866.      struct args_size *offset_ptr;
  2867.      struct args_size *arg_size_ptr;
  2868. {
  2869.   tree sizetree
  2870.     = type ? size_in_bytes (type) : size_int (GET_MODE_SIZE (passed_mode));
  2871.   enum direction where_pad = FUNCTION_ARG_PADDING (passed_mode, type);
  2872.   int boundary = FUNCTION_ARG_BOUNDARY (passed_mode, type);
  2873.   int boundary_in_bytes = boundary / BITS_PER_UNIT;
  2874.   int reg_parm_stack_space = 0;
  2875.  
  2876. #ifdef REG_PARM_STACK_SPACE
  2877.   /* If we have found a stack parm before we reach the end of the
  2878.      area reserved for registers, skip that area.  */
  2879.   if (! in_regs)
  2880.     {
  2881.       reg_parm_stack_space = REG_PARM_STACK_SPACE (fndecl);
  2882.       if (reg_parm_stack_space > 0)
  2883.     {
  2884.       if (initial_offset_ptr->var)
  2885.         {
  2886.           initial_offset_ptr->var
  2887.         = size_binop (MAX_EXPR, ARGS_SIZE_TREE (*initial_offset_ptr),
  2888.                   size_int (reg_parm_stack_space));
  2889.           initial_offset_ptr->constant = 0;
  2890.         }
  2891.       else if (initial_offset_ptr->constant < reg_parm_stack_space)
  2892.         initial_offset_ptr->constant = reg_parm_stack_space;
  2893.     }
  2894.     }
  2895. #endif
  2896.  
  2897.   /* If this argument needs more than the usual parm alignment, do
  2898.      extrinsic padding to reach that alignment.  */
  2899.   if (boundary > BITS_PER_UNIT)
  2900.     {
  2901.       if (initial_offset_ptr->var)
  2902.     {
  2903.       initial_offset_ptr->var
  2904.         = round_up (ARGS_SIZE_TREE (*initial_offset_ptr), 
  2905.             boundary / BITS_PER_UNIT);
  2906.       initial_offset_ptr->constant = 0;
  2907.     }
  2908.       else
  2909.     initial_offset_ptr->constant
  2910.       = CEIL_ROUND (initial_offset_ptr->constant, boundary_in_bytes);
  2911.     }
  2912.  
  2913.   *offset_ptr = *initial_offset_ptr;
  2914.  
  2915.   /* If arg should be padded below, adjust the stack address upward.
  2916.      This padding is considered part of the space occupied by the
  2917.      argument.  It pads only up to PARM_BOUNDARY, and it does not
  2918.      depend on the previous arguments, since they are assumed to
  2919.      occupy a multiple of PARM_BOUNDARY.  */
  2920.  
  2921.   if (where_pad == downward)
  2922.     {
  2923.       if (passed_mode != BLKmode)
  2924.     {
  2925.       if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  2926.         offset_ptr->constant
  2927.           += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  2928.            / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  2929.           - GET_MODE_SIZE (passed_mode));
  2930.     }
  2931.       else
  2932.     {
  2933.       if (TREE_CODE (sizetree) != INTEGER_CST
  2934.           || (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)
  2935.         {
  2936.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  2937.           tree s2 = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  2938.           /* Add it in.  */
  2939.           ADD_PARM_SIZE (*offset_ptr, s2);
  2940.           SUB_PARM_SIZE (*offset_ptr, sizetree);
  2941.         }
  2942.     }
  2943.     }
  2944.  
  2945.   /* Finally, compute the size of the parm on the stack.
  2946.  
  2947.      First adjust for possible PUSH_ROUNDING.  Then, if needed, round to
  2948.      PARM_BOUNDARY.  */
  2949.  
  2950.   arg_size_ptr->var = 0;
  2951.   arg_size_ptr->constant = 0;
  2952.  
  2953. #ifdef PUSH_ROUNDING
  2954.   if (passed_mode != BLKmode)
  2955.     sizetree = size_int (PUSH_ROUNDING (TREE_INT_CST_LOW (sizetree)));
  2956. #endif
  2957.  
  2958.   if (where_pad != none
  2959.       && (TREE_CODE (sizetree) != INTEGER_CST
  2960.       || ((TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT) % PARM_BOUNDARY)))
  2961.     sizetree = round_up (sizetree, PARM_BOUNDARY / BITS_PER_UNIT);
  2962.  
  2963.   ADD_PARM_SIZE (*arg_size_ptr, sizetree);
  2964. }
  2965.  
  2966. /* Walk the tree of blocks describing the binding levels within a function
  2967.    and warn about uninitialized variables.
  2968.    This is done after calling flow_analysis and before global_alloc
  2969.    clobbers the pseudo-regs to hard regs.  */
  2970.  
  2971. void
  2972. uninitialized_vars_warning (block)
  2973.      tree block;
  2974. {
  2975.   register tree decl, sub;
  2976.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  2977.     {
  2978.       if (TREE_CODE (decl) == VAR_DECL
  2979.       /* These warnings are unreliable for and aggregates
  2980.          because assigning the fields one by one can fail to convince
  2981.          flow.c that the entire aggregate was initialized.
  2982.          Unions are troublesome because members may be shorter.  */
  2983.       && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  2984.       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  2985.       && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  2986.       && DECL_RTL (decl) != 0
  2987.       && GET_CODE (DECL_RTL (decl)) == REG
  2988.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  2989.     warning_with_decl (decl,
  2990.                "`%s' may be used uninitialized in this function");
  2991.       if (TREE_CODE (decl) == VAR_DECL
  2992.       && DECL_RTL (decl) != 0
  2993.       && GET_CODE (DECL_RTL (decl)) == REG
  2994.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  2995.     warning_with_decl (decl,
  2996.                "variable `%s' may be clobbered by `longjmp'");
  2997.     }
  2998.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  2999.     uninitialized_vars_warning (sub);
  3000. }
  3001.  
  3002. /* Do the appropriate part of uninitialized_vars_warning
  3003.    but for arguments instead of local variables.  */
  3004.  
  3005. void
  3006. setjmp_args_warning (block)
  3007.      tree block;
  3008. {
  3009.   register tree decl;
  3010.   for (decl = DECL_ARGUMENTS (current_function_decl);
  3011.        decl; decl = TREE_CHAIN (decl))
  3012.     if (DECL_RTL (decl) != 0
  3013.     && GET_CODE (DECL_RTL (decl)) == REG
  3014.     && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  3015.       warning_with_decl (decl, "argument `%s' may be clobbered by `longjmp'");
  3016. }
  3017.  
  3018. /* If this function call setjmp, put all vars into the stack
  3019.    unless they were declared `register'.  */
  3020.  
  3021. void
  3022. setjmp_protect (block)
  3023.      tree block;
  3024. {
  3025.   register tree decl, sub;
  3026.   for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl))
  3027.     if ((TREE_CODE (decl) == VAR_DECL
  3028.      || TREE_CODE (decl) == PARM_DECL)
  3029.     && DECL_RTL (decl) != 0
  3030.     && GET_CODE (DECL_RTL (decl)) == REG
  3031. #ifdef NeXT
  3032.     /* If this variable came from an inline function, it must be
  3033.         that it's life doesn't overlap the setjmp.  If there was a
  3034.         setjmp in the function, it would already be in memory.  We
  3035.         must exclude such variable because their DECL_RTL might be
  3036.         set to strange things such as virtual_stack_vars_rtx.  */
  3037.     && ! TREE_INLINE (decl)
  3038. #endif /* NeXT */
  3039.     && (
  3040. #ifdef NON_SAVING_SETJMP
  3041.         /* If longjmp doesn't restore the registers,
  3042.            don't put anything in them.  */
  3043.         NON_SAVING_SETJMP
  3044.         ||
  3045. #endif
  3046.         ! TREE_REGDECL (decl)))
  3047.       put_var_into_stack (decl);
  3048.   for (sub = BLOCK_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  3049.     setjmp_protect (sub);
  3050. }
  3051.  
  3052. /* Like the previous function, but for args instead of local variables.  */
  3053.  
  3054. void
  3055. setjmp_protect_args ()
  3056. {
  3057.   register tree decl, sub;
  3058.   for (decl = DECL_ARGUMENTS (current_function_decl);
  3059.        decl; decl = TREE_CHAIN (decl))
  3060.     if ((TREE_CODE (decl) == VAR_DECL
  3061.      || TREE_CODE (decl) == PARM_DECL)
  3062.     && DECL_RTL (decl) != 0
  3063.     && GET_CODE (DECL_RTL (decl)) == REG
  3064.     && (
  3065.         /* If longjmp doesn't restore the registers,
  3066.            don't put anything in them.  */
  3067. #ifdef NON_SAVING_SETJMP
  3068.         NON_SAVING_SETJMP
  3069.         ||
  3070. #endif
  3071.         ! TREE_REGDECL (decl)))
  3072.       put_var_into_stack (decl);
  3073. }
  3074.  
  3075. /* Return the context-pointer register corresponding to DECL,
  3076.    or 0 if it does not need one.  */
  3077.  
  3078. rtx
  3079. lookup_static_chain (decl)
  3080.      tree decl;
  3081. {
  3082.   tree context = decl_function_context (decl);
  3083.   tree link;
  3084.   
  3085.   if (context == current_function_decl)
  3086.     return virtual_stack_vars_rtx;
  3087.  
  3088.   if (context == 0)
  3089.     return 0;
  3090.  
  3091.   for (link = context_display; link; link = TREE_CHAIN (link))
  3092.     if (TREE_PURPOSE (link) == context)
  3093.       return RTL_EXPR_RTL (TREE_VALUE (link));
  3094.  
  3095.   abort ();
  3096. }
  3097.  
  3098. /* Convert a stack slot address ADDR for variable VAR
  3099.    (from a containing function)
  3100.    into an address valid in this function (using a static chain).  */
  3101.  
  3102. rtx
  3103. fix_lexical_addr (addr, var)
  3104.      rtx addr;
  3105.      tree var;
  3106. {
  3107.   rtx basereg;
  3108.   int displacement;
  3109.   rtx base;
  3110.  
  3111.   base = lookup_static_chain (var);
  3112.  
  3113.   /* Decode given address as base reg plus displacement.  */
  3114.   if (GET_CODE (addr) == REG)
  3115.     basereg = addr, displacement = 0;
  3116.   else if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
  3117.     basereg = XEXP (addr, 0), displacement = INTVAL (XEXP (addr, 1));
  3118.   else
  3119.     abort ();
  3120.  
  3121.   /* We accept vars reached via the containing function's
  3122.      incoming arg pointer and via its stack variables pointer.  */
  3123.   if (basereg == arg_pointer_rtx || basereg == virtual_incoming_args_rtx)
  3124.     {
  3125.       /* If reached via arg pointer, get the arg pointer value
  3126.      out of that function's stack frame.
  3127.  
  3128.      There are two cases:  If a separate ap is needed, allocate a
  3129.      slot in the outer function for it and dereference it that way.
  3130.      Otherwise, just adjust the offset from the frame pointer to
  3131.      compensate.  */
  3132. #ifdef NEED_SEPARATE_AP
  3133.       tree context = decl_function_context (var);
  3134.       struct function *fp;
  3135.       rtx addr;
  3136.  
  3137.       for (fp = outer_function_chain; fp; fp = fp->next)
  3138.     if (fp->decl == context)
  3139.       break;
  3140.  
  3141.       if (fp == 0)
  3142.     abort ();
  3143.  
  3144.       if (fp->arg_pointer_save_area == 0)
  3145.     fp->arg_pointer_save_area
  3146.       = assign_outer_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0, fp);
  3147.  
  3148.       addr = memory_address (Pmode, 
  3149.                  fix_lexical_addr (fp->arg_pointer_save_area,
  3150.                            var));
  3151.       base = copy_to_reg (gen_rtx (MEM, Pmode,addr));
  3152. #else
  3153.       displacement += (FIRST_PARM_OFFSET (decl_function_context (var))
  3154.                - STARTING_FRAME_OFFSET);
  3155. #endif
  3156.     }
  3157.   else if (basereg != virtual_stack_vars_rtx)
  3158.     abort ();
  3159.  
  3160.   /* Use same offset, relative to appropriate static chain.  */
  3161.   return plus_constant (base, displacement);
  3162. }
  3163.  
  3164. /* Return the address of the trampoline for entering nested fn FUNCTION.
  3165.    If necessary, allocate a trampoline (in the stack frame)
  3166.    and emit rtl to initialize its contents (at entry to this function).  */
  3167.  
  3168. rtx
  3169. trampoline_address (function)
  3170.      tree function;
  3171. {
  3172.   tree link;
  3173.   tree rtlexp;
  3174.   rtx tramp;
  3175.   struct function *fp;
  3176.   tree fn_context;
  3177.  
  3178.   /* Find an existing trampoline and return it.  */
  3179.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  3180.     if (TREE_PURPOSE (link) == function)
  3181.       return XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0);
  3182.   for (fp = outer_function_chain; fp; fp = fp->next)
  3183.     for (link = fp->trampoline_list; link; link = TREE_CHAIN (link))
  3184.       if (TREE_PURPOSE (link) == function)
  3185.     {
  3186.       tramp = fix_lexical_addr (XEXP (RTL_EXPR_RTL (TREE_VALUE (link)), 0),
  3187.                     function);
  3188.       return round_trampoline_addr (tramp);
  3189.     }
  3190.  
  3191.   /* None exists; we must make one.  */
  3192.  
  3193.   /* Find the `struct function' for the function containing FUNCTION.  */
  3194.   fp = 0;
  3195.   fn_context = decl_function_context (function);
  3196.   if (fn_context != current_function_decl)
  3197.     for (fp = outer_function_chain; fp; fp = fp->next)
  3198.       if (fp->decl == fn_context)
  3199.     break;
  3200.  
  3201.   /* Allocate run-time space for this trampoline
  3202.      (usually in the defining function's stack frame).  */
  3203. #ifdef ALLOCATE_TRAMPOLINE
  3204.   tramp = ALLOCATE_TRAMPOLINE (fp);
  3205. #else
  3206.   /* If rounding needed, allocate extra space
  3207.      to ensure we have TRAMPOLINE_SIZE bytes left after rounding up.  */
  3208. #ifdef TRAMPOLINE_ALIGNMENT
  3209. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE + TRAMPOLINE_ALIGNMENT - 1)
  3210. #else
  3211. #define TRAMPOLINE_REAL_SIZE (TRAMPOLINE_SIZE)
  3212. #endif
  3213.   if (fp != 0)
  3214.     tramp = assign_outer_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0, fp);
  3215.   else
  3216.     tramp = assign_stack_local (BLKmode, TRAMPOLINE_REAL_SIZE, 0);
  3217. #endif
  3218.  
  3219.   /* Record the trampoline for reuse and note it for later initialization
  3220.      by expand_function_end.  */
  3221.   if (fp != 0)
  3222.     {
  3223.       push_obstacks (fp->current_obstack, fp->function_maybepermanent_obstack);
  3224.       rtlexp = make_node (RTL_EXPR);
  3225.       RTL_EXPR_RTL (rtlexp) = tramp;
  3226.       fp->trampoline_list = tree_cons (function, rtlexp, fp->trampoline_list);
  3227.       pop_obstacks ();
  3228.     }
  3229.   else
  3230.     {
  3231.       rtlexp = make_node (RTL_EXPR);
  3232.       RTL_EXPR_RTL (rtlexp) = tramp;
  3233.       trampoline_list = tree_cons (function, rtlexp, trampoline_list);
  3234.     }
  3235.  
  3236.   tramp = fix_lexical_addr (XEXP (tramp, 0), function);
  3237.   return round_trampoline_addr (tramp);
  3238. }
  3239.  
  3240. /* Given a trampoline address,
  3241.    round it to multiple of TRAMPOLINE_ALIGNMENT.  */
  3242.  
  3243. static rtx
  3244. round_trampoline_addr (tramp)
  3245.      rtx tramp;
  3246. {
  3247. #ifdef TRAMPOLINE_ALIGNMENT
  3248.   /* Round address up to desired boundary.  */
  3249.   rtx temp = gen_reg_rtx (Pmode);
  3250.   temp = expand_binop (Pmode, add_optab, tramp,
  3251.                gen_rtx (CONST_INT, VOIDmode, TRAMPOLINE_ALIGNMENT - 1),
  3252.                temp, 0, OPTAB_LIB_WIDEN);
  3253.   tramp = expand_binop (Pmode, and_optab, temp,
  3254.             gen_rtx (CONST_INT, VOIDmode, - TRAMPOLINE_ALIGNMENT),
  3255.             temp, 0, OPTAB_LIB_WIDEN);
  3256. #endif
  3257.   return tramp;
  3258. }
  3259.  
  3260. /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
  3261.    and initialize static variables for generating RTL for the statements
  3262.    of the function.  */
  3263.  
  3264. void
  3265. init_function_start (subr, filename, line)
  3266.      tree subr;
  3267.      char *filename;
  3268.      int line;
  3269. {
  3270.   init_stmt_for_function ();
  3271.  
  3272.   cse_not_expected = ! optimize;
  3273.  
  3274.   /* Caller save not needed yet.  */
  3275.   caller_save_needed = 0;
  3276.  
  3277.   /* No stack slots have been made yet.  */
  3278.   stack_slot_list = 0;
  3279.  
  3280.   /* There is no stack slot for handling nonlocal gotos.  */
  3281.   nonlocal_goto_handler_slot = 0;
  3282.   nonlocal_goto_stack_level = 0;
  3283.  
  3284.   /* No labels have been declared for nonlocal use.  */
  3285.   nonlocal_labels = 0;
  3286.  
  3287.   /* No function calls so far in this function.  */
  3288.   function_call_count = 0;
  3289.  
  3290.   /* No parm regs have been allocated.
  3291.      (This is important for output_inline_function.)  */
  3292.   max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
  3293.  
  3294.   /* Initialize the RTL mechanism.  */
  3295.   init_emit ();
  3296.  
  3297.   /* Initialize the queue of pending postincrement and postdecrements,
  3298.      and some other info in expr.c.  */
  3299.   init_expr ();
  3300.  
  3301.   /* We haven't done register allocation yet.  */
  3302.   reg_renumber = 0;
  3303.  
  3304.   init_const_rtx_hash_table ();
  3305.  
  3306.   current_function_name = (*decl_printable_name) (subr);
  3307.  
  3308.   /* Nonzero if this is a nested function that uses a static chain.  */
  3309.  
  3310.   current_function_needs_context
  3311.     = (decl_function_context (current_function_decl) != 0);
  3312.  
  3313.   /* Set if a call to setjmp is seen.  */
  3314.   current_function_calls_setjmp = 0;
  3315.  
  3316.   current_function_calls_alloca = 0;
  3317.   current_function_has_nonlocal_label = 0;
  3318.   current_function_contains_functions = 0;
  3319.  
  3320.   current_function_returns_pcc_struct = 0;
  3321.   current_function_returns_struct = 0;
  3322.   current_function_epilogue_delay_list = 0;
  3323.   current_function_uses_const_pool = 0;
  3324.  
  3325.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  3326.   tail_recursion_label = 0;
  3327.  
  3328.   /* We haven't had a need to make a save area for ap yet.  */
  3329.  
  3330.   arg_pointer_save_area = 0;
  3331.  
  3332.   /* No stack slots allocated yet.  */
  3333.   frame_offset = 0;
  3334.  
  3335.   /* No SAVE_EXPRs in this function yet.  */
  3336.   save_expr_regs = 0;
  3337.  
  3338.   /* No RTL_EXPRs in this function yet.  */
  3339.   rtl_expr_chain = 0;
  3340.  
  3341.   /* We have not allocated any temporaries yet.  */
  3342.   temp_slots = 0;
  3343.   temp_slot_level = 0;
  3344.  
  3345.   /* Within function body, compute a type's size as soon it is laid out.  */
  3346.   immediate_size_expand++;
  3347.  
  3348.   init_pending_stack_adjust ();
  3349.   inhibit_defer_pop = 0;
  3350.  
  3351.   current_function_outgoing_args_size = 0;
  3352.  
  3353.   /* Initialize the insn lengths.  */
  3354.   init_insn_lengths ();
  3355.  
  3356.   /* Prevent ever trying to delete the first instruction of a function.
  3357.      Also tell final how to output a linenum before the function prologue.  */
  3358.   emit_line_note (filename, line);
  3359.  
  3360.   /* Make sure first insn is a note even if we don't want linenums.
  3361.      This makes sure the first insn will never be deleted.
  3362.      Also, final expects a note to appear there.  */
  3363.   emit_note (0, NOTE_INSN_DELETED);
  3364.  
  3365.   /* Set flags used by final.c.  */
  3366.   if (aggregate_value_p (DECL_RESULT (subr)))
  3367.     {
  3368. #ifdef PCC_STATIC_STRUCT_RETURN
  3369.       if (flag_pcc_struct_return)
  3370.     current_function_returns_pcc_struct = 1;
  3371.       else
  3372. #endif
  3373.     current_function_returns_struct = 1;
  3374.     }
  3375.  
  3376.  
  3377.   current_function_returns_pointer
  3378.     = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
  3379.  
  3380.   /* Indicate that we need to distinguish between the return value of the
  3381.      present function and the return value of a function being called.  */
  3382.   rtx_equal_function_value_matters = 1;
  3383.  
  3384.   /* Indicate that we have not instantiated virtual registers yet.  */
  3385.   virtuals_instantiated = 0;
  3386.  
  3387.   /* Indicate we have no need of a frame pointer yet.  */
  3388.   frame_pointer_needed = 0;
  3389.  
  3390.   /* By default assume not varargs.  */
  3391.   current_function_varargs = 0;
  3392. }
  3393.  
  3394. /* Indicate that the current function uses extra args
  3395.    not explicitly mentioned in the argument list in any fashion.  */
  3396.  
  3397. void
  3398. mark_varargs ()
  3399. {
  3400.   current_function_varargs = 1;
  3401. }
  3402.  
  3403. /* Start the RTL for a new function, and set variables used for
  3404.    emitting RTL.
  3405.    SUBR is the FUNCTION_DECL node.
  3406.    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
  3407.    the function's parameters, which must be run at any return statement.  */
  3408.  
  3409. void
  3410. expand_function_start (subr, parms_have_cleanups)
  3411.      tree subr;
  3412.      int parms_have_cleanups;
  3413. {
  3414.   register int i;
  3415.   tree tem;
  3416.   rtx last_ptr;
  3417.  
  3418.   /* Make sure volatile mem refs aren't considered
  3419.      valid operands of arithmetic insns.  */
  3420.   init_recog_no_volatile ();
  3421.  
  3422.   /* If function gets a static chain arg, store it in the stack frame.
  3423.      Do this first, so it gets the first stack slot offset.  */
  3424.   if (current_function_needs_context)
  3425.     emit_move_insn (assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0),
  3426.             static_chain_incoming_rtx);
  3427.  
  3428.   /* If the parameters of this function need cleaning up, get a label
  3429.      for the beginning of the code which executes those cleanups.  This must
  3430.      be done before doing anything with return_label.  */
  3431.   if (parms_have_cleanups)
  3432.     cleanup_label = gen_label_rtx ();
  3433.   else
  3434.     cleanup_label = 0;
  3435.  
  3436.   /* Make the label for return statements to jump to, if this machine
  3437.      does not have a one-instruction return and uses an epilogue,
  3438.      or if it returns a structure, or if it has parm cleanups.  */
  3439. #ifdef HAVE_return
  3440.   if (cleanup_label == 0 && HAVE_return
  3441.       && ! current_function_returns_pcc_struct
  3442.       && ! (current_function_returns_struct && ! optimize))
  3443.     return_label = 0;
  3444.   else
  3445.     return_label = gen_label_rtx ();
  3446. #else
  3447.   return_label = gen_label_rtx ();
  3448. #endif
  3449.  
  3450.   /* Initialize rtx used to return the value.  */
  3451.   /* Do this before assign_parms so that we copy the struct value address
  3452.      before any library calls that assign parms might generate.  */
  3453.  
  3454.   /* Decide whether to return the value in memory or in a register.  */
  3455.   if (aggregate_value_p (DECL_RESULT (subr)))
  3456.     {
  3457.       /* Returning something that won't go in a register.  */
  3458.       register rtx value_address;
  3459.  
  3460. #ifdef PCC_STATIC_STRUCT_RETURN
  3461.       if (current_function_returns_pcc_struct)
  3462.     {
  3463.       int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  3464.       value_address = assemble_static_space (size);
  3465.     }
  3466.       else
  3467. #endif
  3468.     {
  3469.       /* Expect to be passed the address of a place to store the value.
  3470.          If it is passed as an argument, assign_parms will take care of
  3471.          it.  */
  3472.       if (struct_value_incoming_rtx)
  3473.         {
  3474.           value_address = gen_reg_rtx (Pmode);
  3475.           emit_move_insn (value_address, struct_value_incoming_rtx);
  3476.         }
  3477.     }
  3478.       if (value_address)
  3479.     current_function_return_rtx = DECL_RTL (DECL_RESULT (subr))
  3480.       = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  3481.              value_address);
  3482.     }
  3483.   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
  3484.     /* If return mode is void, this decl rtl should not be used.  */
  3485.     current_function_return_rtx = DECL_RTL (DECL_RESULT (subr)) = 0;
  3486.   else if (parms_have_cleanups)
  3487.     /* If function will end with cleanup code for parms,
  3488.        compute the return values into a pseudo reg,
  3489.        which we will copy into the true return register
  3490.        after the cleanups are done.  */
  3491.     current_function_return_rtx = DECL_RTL (DECL_RESULT (subr))
  3492.       = gen_reg_rtx (DECL_MODE (DECL_RESULT (subr)));
  3493.   else
  3494.     /* Scalar, returned in a register.  */
  3495.     {
  3496. #ifdef FUNCTION_OUTGOING_VALUE
  3497.       current_function_return_rtx = DECL_RTL (DECL_RESULT (subr))
  3498.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  3499. #else
  3500.       current_function_return_rtx = DECL_RTL (DECL_RESULT (subr))
  3501.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  3502. #endif
  3503.  
  3504.       /* Mark this reg as the function's return value.  */
  3505.       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  3506.     REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  3507.     }
  3508.  
  3509.   /* Initialize rtx for parameters and local variables.
  3510.      In some cases this requires emitting insns.  */
  3511.  
  3512.   assign_parms (subr, 0);
  3513.  
  3514.   /* The following was moved from init_function_start.
  3515.      The move is supposed to make sdb output more accurate.  */
  3516.   /* Indicate the beginning of the function body,
  3517.      as opposed to parm setup.  */
  3518.   emit_note (0, NOTE_INSN_FUNCTION_BEG);
  3519.  
  3520.   /* If doing stupid allocation, mark parms as born here.  */
  3521.  
  3522.   if (GET_CODE (get_last_insn ()) != NOTE)
  3523.     emit_note (0, NOTE_INSN_DELETED);
  3524.   parm_birth_insn = get_last_insn ();
  3525.  
  3526.   if (obey_regdecls)
  3527.     {
  3528.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  3529.     use_variable (regno_reg_rtx[i]);
  3530.     }
  3531.  
  3532.   /* Fetch static chain values for containing functions.  */
  3533.   tem = decl_function_context (current_function_decl);
  3534.   if (tem)
  3535.     last_ptr = copy_to_reg (static_chain_incoming_rtx);
  3536.   context_display = 0;
  3537.   while (tem)
  3538.     {
  3539.       tree rtlexp = make_node (RTL_EXPR);
  3540.  
  3541.       RTL_EXPR_RTL (rtlexp) = last_ptr;
  3542.       context_display = tree_cons (tem, rtlexp, context_display);
  3543.       tem = decl_function_context (tem);
  3544.       if (tem == 0)
  3545.     break;
  3546.       /* Chain thru stack frames, assuming pointer to next lexical frame
  3547.      is found at the place we always store it.  */
  3548. #ifdef FRAME_GROWS_DOWNWARD
  3549.       last_ptr = plus_constant (last_ptr, - GET_MODE_SIZE (Pmode));
  3550. #endif
  3551.       last_ptr = copy_to_reg (gen_rtx (MEM, Pmode,
  3552.                        memory_address (Pmode, last_ptr)));
  3553.     }
  3554.  
  3555.   /* After the display initializations is where the tail-recursion label
  3556.      should go, if we end up needing one.   Ensure we have a NOTE here
  3557.      since some things (like trampolines) get placed before this.  */
  3558.   tail_recursion_reentry = emit_note (0, NOTE_INSN_DELETED);
  3559.  
  3560.   /* Evaluate now the sizes of any types declared among the arguments.  */
  3561.   for (tem = get_pending_sizes (); tem; tem = TREE_CHAIN (tem))
  3562.     expand_expr (TREE_VALUE (tem), 0, VOIDmode, 0);
  3563.  
  3564.   /* Make sure there is a line number after the function entry setup code.  */
  3565.   force_next_line_note ();
  3566. }
  3567.  
  3568. /* Generate RTL for the end of the current function.
  3569.    FILENAME and LINE are the current position in the source file.  */
  3570.  
  3571. /* It is up to language-specific callers to do cleanups for parameters.  */
  3572.  
  3573. void
  3574. expand_function_end (filename, line)
  3575.      char *filename;
  3576.      int line;
  3577. {
  3578.   register int i;
  3579.   tree link;
  3580.  
  3581.   static rtx initial_trampoline;
  3582.  
  3583. #ifdef NON_SAVING_SETJMP
  3584.   /* Don't put any variables in registers if we call setjmp
  3585.      on a machine that fails to restore the registers.  */
  3586.   if (NON_SAVING_SETJMP && current_function_calls_setjmp)
  3587.     {
  3588.       setjmp_protect (DECL_INITIAL (fndecl));
  3589.       setjmp_protect_args ();
  3590.     }
  3591. #endif
  3592.  
  3593.   /* Save the argument pointer if a save area was made for it.  */
  3594.   if (arg_pointer_save_area)
  3595.     emit_move_insn (arg_pointer_save_area, virtual_incoming_args_rtx);
  3596.  
  3597.   /* Initialize any trampolines required by this function.  */
  3598.   for (link = trampoline_list; link; link = TREE_CHAIN (link))
  3599.     {
  3600.       tree function = TREE_PURPOSE (link);
  3601.       rtx context = lookup_static_chain (function);
  3602.       rtx tramp = RTL_EXPR_RTL (TREE_VALUE (link));
  3603.       rtx seq;
  3604.  
  3605.       /* First make sure this compilation has a template for
  3606.      initializing trampolines.  */
  3607.       if (initial_trampoline == 0)
  3608.     initial_trampoline
  3609.       = gen_rtx (MEM, BLKmode, assemble_trampoline_template ());
  3610.  
  3611.       /* Generate insns to initialize the trampoline.  */
  3612.       start_sequence ();
  3613.       tramp = change_address (initial_trampoline, BLKmode,
  3614.                   round_trampoline_addr (XEXP (tramp, 0)));
  3615.       emit_block_move (tramp, initial_trampoline,
  3616.                gen_rtx (CONST_INT, VOIDmode, TRAMPOLINE_SIZE),
  3617.                FUNCTION_BOUNDARY / BITS_PER_UNIT);
  3618.       INITIALIZE_TRAMPOLINE (XEXP (tramp, 0),
  3619.                  XEXP (DECL_RTL (function), 0), context);
  3620.       seq = get_insns ();
  3621.       end_sequence ();
  3622.  
  3623.       /* Put those insns at entry to the containing function (this one).  */
  3624.       emit_insns_before (seq, tail_recursion_reentry);
  3625.     }
  3626.  
  3627. #if 0  /* I think unused parms are legitimate enough.  */
  3628.   /* Warn about unused parms.  */
  3629.   if (warn_unused)
  3630.     {
  3631.       rtx decl;
  3632.  
  3633.       for (decl = DECL_ARGUMENTS (current_function_decl);
  3634.        decl; decl = TREE_CHAIN (decl))
  3635.     if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  3636.       warning_with_decl (decl, "unused parameter `%s'");
  3637.     }
  3638. #endif
  3639.  
  3640.   /* Delete handlers for nonlocal gotos if nothing uses them.  */
  3641.   if (nonlocal_goto_handler_slot != 0 && !current_function_has_nonlocal_label)
  3642.     delete_handlers ();
  3643.  
  3644.   /* End any sequences that failed to be closed due to syntax errors.  */
  3645.   while (in_sequence_p ())
  3646.     end_sequence (0);
  3647.  
  3648.   /* Outside function body, can't compute type's actual size
  3649.      until next function's body starts.  */
  3650.   immediate_size_expand--;
  3651.  
  3652.   /* If doing stupid register allocation,
  3653.      mark register parms as dying here.  */
  3654.  
  3655.   if (obey_regdecls)
  3656.     {
  3657.       rtx tem;
  3658.       for (i = LAST_VIRTUAL_REGISTER + 1; i < max_parm_reg; i++)
  3659.     use_variable (regno_reg_rtx[i]);
  3660.  
  3661.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  3662.  
  3663.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  3664.     {
  3665.       use_variable (XEXP (tem, 0));
  3666.       use_variable_after (XEXP (tem, 0), parm_birth_insn);
  3667.     }
  3668.     }
  3669.  
  3670.   clear_pending_stack_adjust ();
  3671.   do_pending_stack_adjust ();
  3672.  
  3673.   /* Mark the end of the function body.
  3674.      If control reaches this insn, the function can drop through
  3675.      without returning a value.  */
  3676.   emit_note (0, NOTE_INSN_FUNCTION_END);
  3677.  
  3678.   /* Output a linenumber for the end of the function.
  3679.      SDB depends on this.  */
  3680.   emit_line_note_force (filename, line);
  3681.  
  3682.   /* Output the label for the actual return from the function,
  3683.      if one is expected.  This happens either because a function epilogue
  3684.      is used instead of a return instruction, or because a return was done
  3685.      with a goto in order to run local cleanups, or because of pcc-style
  3686.      structure returning.  */
  3687.  
  3688.   if (return_label)
  3689.     emit_label (return_label);
  3690.  
  3691.   /* If we had calls to alloca, and this machine needs
  3692.      an accurate stack pointer to exit the function,
  3693.      insert some code to save and restore the stack pointer.  */
  3694. #ifdef EXIT_IGNORE_STACK
  3695.   if (! EXIT_IGNORE_STACK)
  3696. #endif
  3697.     if (current_function_calls_alloca)
  3698.       {
  3699.     rtx tem = gen_reg_rtx (Pmode);
  3700.     emit_insn_after (gen_rtx (SET, VOIDmode, tem, stack_pointer_rtx),
  3701.              parm_birth_insn);
  3702.     emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx, tem));
  3703.       }
  3704.  
  3705.   /* If scalar return value was computed in a pseudo-reg,
  3706.      copy that to the hard return register.  */
  3707.   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
  3708.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
  3709.       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
  3710.       >= FIRST_PSEUDO_REGISTER))
  3711.     {
  3712.       rtx real_decl_result;
  3713.  
  3714. #ifdef FUNCTION_OUTGOING_VALUE
  3715.       real_decl_result
  3716.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  3717.                    current_function_decl);
  3718. #else
  3719.       real_decl_result
  3720.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  3721.               current_function_decl);
  3722. #endif
  3723.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  3724.       emit_move_insn (real_decl_result,
  3725.               DECL_RTL (DECL_RESULT (current_function_decl)));
  3726.       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
  3727.     }
  3728.  
  3729.   /* If returning a structure, arrange to return the address of the value
  3730.      in a place where debuggers expect to find it.
  3731.  
  3732.      If returning a structure PCC style,
  3733.      the caller also depends on this value.
  3734.      And current_function_returns_pcc_struct is not necessarily set.  */
  3735.   if (current_function_returns_struct
  3736.       || current_function_returns_pcc_struct)
  3737.     {
  3738.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  3739.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  3740. #ifdef FUNCTION_OUTGOING_VALUE
  3741.       rtx outgoing
  3742.     = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
  3743.                    current_function_decl);
  3744. #else
  3745.       rtx outgoing
  3746.     = FUNCTION_VALUE (build_pointer_type (type),
  3747.               current_function_decl);
  3748. #endif
  3749.  
  3750.       /* Mark this as a function return value so integrate will delete the
  3751.      assignment and USE below when inlining this function.  */
  3752.       REG_FUNCTION_VALUE_P (outgoing) = 1;
  3753.  
  3754.       emit_move_insn (outgoing, value_address);
  3755.       use_variable (outgoing);
  3756.     }
  3757.  
  3758.   /* Output a return insn if we are using one.
  3759.      Otherwise, let the rtl chain end here, to drop through
  3760.      into the epilogue.  */
  3761.  
  3762. #ifdef HAVE_return
  3763.   if (HAVE_return)
  3764.     {
  3765.       emit_jump_insn (gen_return ());
  3766.       emit_barrier ();
  3767.     }
  3768. #endif
  3769.  
  3770.   /* Fix up any gotos that jumped out to the outermost
  3771.      binding level of the function.
  3772.      Must follow emitting RETURN_LABEL.  */
  3773.  
  3774.   /* If you have any cleanups to do at this point,
  3775.      and they need to create temporary variables,
  3776.      then you will lose.  */
  3777.   fixup_gotos (0, 0, 0, get_insns (), 0);
  3778. }
  3779.