home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / integrate.c < prev    next >
C/C++ Source or Header  |  1991-08-12  |  77KB  |  2,397 lines

  1. /* Procedure integration for GNU CC.
  2.    Copyright (C) 1988-1991 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@cygnus.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. #include <stdio.h>
  23.  
  24. #include "config.h"
  25. #include "rtl.h"
  26. #include "tree.h"
  27. #include "flags.h"
  28. #include "insn-config.h"
  29. #include "insn-flags.h"
  30. #include "expr.h"
  31. #include "output.h"
  32. #include "integrate.h"
  33. #include "real.h"
  34.  
  35. #include "obstack.h"
  36. #define    obstack_chunk_alloc    xmalloc
  37. #define    obstack_chunk_free    free
  38. extern int xmalloc ();
  39. extern void free ();
  40.  
  41. extern struct obstack *function_maybepermanent_obstack;
  42.  
  43. extern rtx stack_slot_list;
  44.  
  45. #define MIN(x,y) ((x < y) ? x : y)
  46.  
  47. extern tree pushdecl ();
  48. extern tree poplevel ();
  49.  
  50. /* Default max number of insns a function can have and still be inline.
  51.    This is overridden on RISC machines.  */
  52. #ifndef INTEGRATE_THRESHOLD
  53. #define INTEGRATE_THRESHOLD(DECL) \
  54.   (8 * (8 + list_length (DECL_ARGUMENTS (DECL))))
  55. #endif
  56.  
  57. /* Save any constant pool constants in an insn.  */
  58. static void save_constants ();
  59.  
  60. /* Note when parameter registers are the destination of a SET.  */
  61. static void note_modified_parmregs ();
  62.  
  63. /* Copy an rtx for save_for_inline_copying.  */
  64. static rtx copy_for_inline ();
  65.  
  66. /* Make copies of MEMs in DECL_RTLs.  */
  67. static void copy_decl_rtls ();
  68.  
  69. static tree copy_decl_tree ();
  70.  
  71. /* Return the constant equivalent of a given rtx, or 0 if none.  */
  72. static rtx const_equiv ();
  73.  
  74. static void integrate_parm_decls ();
  75. static void integrate_decl_tree ();
  76.  
  77. static void subst_constants ();
  78. static rtx fold_out_const_cc0 ();
  79.  
  80. /* Zero if the current function (whose FUNCTION_DECL is FNDECL)
  81.    is safe and reasonable to integrate into other functions.
  82.    Nonzero means value is a warning message with a single %s
  83.    for the function's name.  */
  84.  
  85. char *
  86. function_cannot_inline_p (fndecl)
  87.      register tree fndecl;
  88. {
  89.   register rtx insn;
  90.   tree last = tree_last (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
  91.   int max_insns = INTEGRATE_THRESHOLD (fndecl);
  92.   register int ninsns = 0;
  93.   register tree parms;
  94.  
  95.   /* No inlines with varargs.  `grokdeclarator' gives a warning
  96.      message about that if `inline' is specified.  This code
  97.      it put in to catch the volunteers.  */
  98.   if ((last && TREE_VALUE (last) != void_type_node)
  99.       || (DECL_ARGUMENTS (fndecl) && DECL_NAME (DECL_ARGUMENTS (fndecl))
  100.       && ! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
  101.                "__builtin_va_alist")))
  102.     return "varargs function cannot be inline";
  103.  
  104.   if (current_function_calls_alloca)
  105.     return "function using alloca cannot be inline";
  106.  
  107.   if (current_function_contains_functions)
  108.     return "function with nested functions cannot be inline";
  109.  
  110.   /* This restriction may be eliminated sometime soon.  But for now, don't
  111.      worry about remapping the static chain.  */
  112.   if (current_function_needs_context)
  113.     return "nested function cannot be inline";
  114.  
  115.   /* If its not even close, don't even look.  */
  116.   if (!TREE_INLINE (fndecl) && get_max_uid () > 3 * max_insns)
  117.     return "function too large to be inline";
  118.  
  119. #if 0
  120.   /* Large stacks are OK now that inlined functions can share them.  */
  121.   /* Don't inline functions with large stack usage,
  122.      since they can make other recursive functions burn up stack.  */
  123.   if (!TREE_INLINE (fndecl) && get_frame_size () > 100)
  124.     return "function stack frame for inlining";
  125. #endif
  126.  
  127. #if 0
  128.   /* Don't inline functions which do not specify a function prototype and
  129.      have BLKmode argument or take the address of a parameter.  */
  130.   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  131.     {
  132.       if (TYPE_MODE (TREE_TYPE (parms)) == BLKmode)
  133.     TREE_ADDRESSABLE (parms) = 1;
  134.       if (last == NULL_TREE && TREE_ADDRESSABLE (parms))
  135.     return "no prototype, and parameter address used; cannot be inline";
  136.     }
  137. #endif
  138.  
  139.   /* We can't inline functions that return structures
  140.      the old-fashioned PCC way, copying into a static block.  */
  141.   if (current_function_returns_pcc_struct)
  142.     return "inline functions not supported for this return value type";
  143.  
  144.   /* We can't inline functions that return structures of varying size.  */
  145.   if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
  146.     return "function with varying-size return value cannot be inline";
  147.  
  148.   /* Cannot inline a function with a varying size argument.  */
  149.   for (parms = DECL_ARGUMENTS (fndecl); parms; parms = TREE_CHAIN (parms))
  150.     if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
  151.       return "function with varying-size parameter cannot be inline";
  152.  
  153.   if (!TREE_INLINE (fndecl) && get_max_uid () > max_insns)
  154.     {
  155.       for (ninsns = 0, insn = get_first_nonparm_insn (); insn && ninsns < max_insns;
  156.        insn = NEXT_INSN (insn))
  157.     {
  158.       if (GET_CODE (insn) == INSN
  159.           || GET_CODE (insn) == JUMP_INSN
  160.           || GET_CODE (insn) == CALL_INSN)
  161.         ninsns++;
  162.     }
  163.  
  164.       if (ninsns >= max_insns)
  165.     return "function too large to be inline";
  166.     }
  167.  
  168.   return 0;
  169. }
  170.  
  171. /* Variables used within save_for_inline.  */
  172.  
  173. /* Mapping from old pseudo-register to new pseudo-registers.
  174.    The first element of this map is reg_map[FIRST_PSEUDO_REGISTER].
  175.    It is allocated in `save_for_inline' and `expand_inline_function',
  176.    and deallocated on exit from each of those routines.  */
  177. static rtx *reg_map;
  178.  
  179. /* Mapping from old code-labels to new code-labels.
  180.    The first element of this map is label_map[min_labelno].
  181.    It is allocated in `save_for_inline' and `expand_inline_function',
  182.    and deallocated on exit from each of those routines.  */
  183. static rtx *label_map;
  184.  
  185. /* Mapping from old insn uid's to copied insns.
  186.    It is allocated in `save_for_inline' and `expand_inline_function',
  187.    and deallocated on exit from each of those routines.  */
  188. static rtx *insn_map;
  189.  
  190. /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
  191.    Zero for a reg that isn't a parm's home.
  192.    Only reg numbers less than max_parm_reg are mapped here.  */
  193. static tree *parmdecl_map;
  194.  
  195. /* Keep track of first pseudo-register beyond those that are parms.  */
  196. static int max_parm_reg;
  197.  
  198. /* When an insn is being copied by copy_for_inline,
  199.    this is nonzero if we have copied an ASM_OPERANDS.
  200.    In that case, it is the original input-operand vector.  */
  201. static rtvec orig_asm_operands_vector;
  202.  
  203. /* When an insn is being copied by copy_for_inline,
  204.    this is nonzero if we have copied an ASM_OPERANDS.
  205.    In that case, it is the copied input-operand vector.  */
  206. static rtvec copy_asm_operands_vector;
  207.  
  208. /* Likewise, this is the copied constraints vector.  */
  209. static rtvec copy_asm_constraints_vector;
  210.  
  211. /* In save_for_inline, nonzero if past the parm-initialization insns.  */
  212. static int in_nonparm_insns;
  213.  
  214. /* On machines that perform a function return with a single
  215.    instruction, such as the VAX, these return insns must be
  216.    mapped into branch statements.  */
  217. extern rtx return_label;
  218.  
  219. /* Subroutine for `save_for_inline{copying,nocopy}'.  Performs initialization
  220.    needed to save FNDECL's insns and info for future inline expansion.  */
  221.    
  222. static rtx
  223. initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, copy)
  224.      tree fndecl;
  225.      int min_labelno;
  226.      int max_labelno;
  227.      int max_reg;
  228.      int copy;
  229. {
  230.   int function_flags, i;
  231.   rtvec arg_vector;
  232.   tree parms;
  233.  
  234.   /* Compute the values of any flags we must restore when inlining this.  */
  235.  
  236.   function_flags
  237.     = (current_function_calls_alloca * FUNCTION_FLAGS_CALLS_ALLOCA
  238.        + current_function_calls_setjmp * FUNCTION_FLAGS_CALLS_SETJMP
  239.        + current_function_returns_struct * FUNCTION_FLAGS_RETURNS_STRUCT
  240.        + current_function_returns_pcc_struct * FUNCTION_FLAGS_RETURNS_PCC_STRUCT
  241.        + current_function_needs_context * FUNCTION_FLAGS_NEEDS_CONTEXT
  242.        + current_function_has_nonlocal_label * FUNCTION_FLAGS_HAS_NONLOCAL_LABEL
  243.        + current_function_returns_pointer * FUNCTION_FLAGS_RETURNS_POINTER
  244.        + current_function_uses_const_pool * FUNCTION_FLAGS_USES_CONST_POOL);
  245.  
  246.   /* Clear out PARMDECL_MAP.  It was allocated in the caller's frame.  */
  247.   bzero (parmdecl_map, max_parm_reg * sizeof (tree));
  248.   arg_vector = rtvec_alloc (list_length (DECL_ARGUMENTS (fndecl)));
  249.  
  250.   for (parms = DECL_ARGUMENTS (fndecl), i = 0;
  251.        parms;
  252.        parms = TREE_CHAIN (parms), i++)
  253.     {
  254.       rtx p = DECL_RTL (parms);
  255.  
  256.       if (GET_CODE (p) == MEM && copy)
  257.     /* Copy the rtl so that modifications of the address
  258.        later in compilation won't affect this arg_vector.
  259.        Virtual register instantiation can screw the address
  260.        of the rtl.  */
  261.     DECL_RTL (parms) = copy_rtx (p);
  262.  
  263.       RTVEC_ELT (arg_vector, i) = p;
  264.  
  265.       if (GET_CODE (p) == REG)
  266.     parmdecl_map[REGNO (p)] = parms;
  267.       TREE_READONLY (parms) = 1;
  268.     }
  269.  
  270.   /* Assume we start out in the insns that set up the parameters.  */
  271.   in_nonparm_insns = 0;
  272.  
  273.   /* The list of DECL_SAVED_INSNS, starts off with a header which
  274.      contains the following information:
  275.  
  276.      the first insn of the function (not including the insns that copy
  277.      parameters into registers).
  278.      the first parameter insn of the function,
  279.      the first label used by that function,
  280.      the last label used by that function,
  281.      the highest register number used for parameters,
  282.      the total number of registers used,
  283.      the size of the incoming stack area for parameters,
  284.      the number of bytes popped on return,
  285.      the stack slot list,
  286.      some flags that are used to restore compiler globals,
  287.      the value of current_function_outgoing_args_size,
  288.      the original argument vector,
  289.      and the original DECL_INITIAL.  */
  290.  
  291.   return gen_inline_header_rtx (NULL, NULL, min_labelno, max_labelno,
  292.                 max_parm_reg, max_reg,
  293.                 current_function_args_size,
  294.                 current_function_pops_args,
  295.                 stack_slot_list, function_flags,
  296.                 current_function_outgoing_args_size,
  297.                 arg_vector, (rtx) DECL_INITIAL (fndecl));
  298. }
  299.  
  300. /* Subroutine for `save_for_inline{copying,nocopy}'.  Finishes up the
  301.    things that must be done to make FNDECL expandable as an inline function.
  302.    HEAD contains the chain of insns to which FNDECL will expand.  */
  303.    
  304. static void
  305. finish_inline (fndecl, head)
  306.      tree fndecl;
  307.      rtx head;
  308. {
  309.   NEXT_INSN (head) = get_first_nonparm_insn ();
  310.   FIRST_PARM_INSN (head) = get_insns ();
  311.   DECL_SAVED_INSNS (fndecl) = head;
  312.   DECL_FRAME_SIZE (fndecl) = get_frame_size ();
  313.   TREE_INLINE (fndecl) = 1;
  314. }
  315.  
  316. /* Make the insns and PARM_DECLs of the current function permanent
  317.    and record other information in DECL_SAVED_INSNS to allow inlining
  318.    of this function in subsequent calls.
  319.  
  320.    This function is called when we are going to immediately compile
  321.    the insns for FNDECL.  The insns in maybepermanent_obstack cannot be
  322.    modified by the compilation process, so we copy all of them to
  323.    new storage and consider the new insns to be the insn chain to be
  324.    compiled.  */
  325.  
  326. void
  327. save_for_inline_copying (fndecl)
  328.      tree fndecl;
  329. {
  330.   extern rtx *regno_reg_rtx;    /* in emit-rtl.c.  */
  331.  
  332.   rtx first_insn, last_insn, insn;
  333.   rtx head, copy;
  334.   int max_labelno, min_labelno, i, len;
  335.   int max_reg;
  336.   int max_uid;
  337.   rtx first_nonparm_insn;
  338.  
  339.   /* Make and emit a return-label if we have not already done so. 
  340.      Do this before recording the bounds on label numbers. */
  341.  
  342.   if (return_label == 0)
  343.     {
  344.       return_label = gen_label_rtx ();
  345.       emit_label (return_label);
  346.     }
  347.  
  348.   /* Get some bounds on the labels and registers used.  */
  349.  
  350.   max_labelno = max_label_num ();
  351.   min_labelno = get_first_label_num ();
  352.   max_reg = max_reg_num ();
  353.  
  354.   /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
  355.      Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
  356.      Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
  357.      for the parms, prior to elimination of virtual registers.
  358.      These values are needed for substituting parms properly.  */
  359.  
  360.   max_parm_reg = max_parm_reg_num ();
  361.   parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
  362.  
  363.   head = initialize_for_inline (fndecl, min_labelno, max_labelno, max_reg, 1);
  364.  
  365.   if (current_function_uses_const_pool)
  366.     {
  367.       /* Replace any constant pool references with the actual constant.  We
  368.      will put the constants back in the copy made below.  */
  369.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  370.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  371.         || GET_CODE (insn) == CALL_INSN)
  372.       {
  373.         save_constants (&PATTERN (insn));
  374.         if (REG_NOTES (insn))
  375.           save_constants (®_NOTES (insn));
  376.       }
  377.  
  378.       /* Clear out the constant pool so that we can recreate it with the
  379.      copied constants below.  */
  380.       init_const_rtx_hash_table ();
  381.     }
  382.  
  383.   max_uid = INSN_UID (head);
  384.  
  385.   /* We have now allocated all that needs to be allocated permanently
  386.      on the rtx obstack.  Set our high-water mark, so that we
  387.      can free the rest of this when the time comes.  */
  388.  
  389.   preserve_data ();
  390.  
  391.   /* Copy the chain insns of this function.
  392.      Install the copied chain as the insns of this function,
  393.      for continued compilation;
  394.      the original chain is recorded as the DECL_SAVED_INSNS
  395.      for inlining future calls.  */
  396.  
  397.   /* If there are insns that copy parms from the stack into pseudo registers,
  398.      those insns are not copied.  `expand_inline_function' must
  399.      emit the correct code to handle such things.  */
  400.  
  401.   insn = get_insns ();
  402.   if (GET_CODE (insn) != NOTE)
  403.     abort ();
  404.   first_insn = rtx_alloc (NOTE);
  405.   NOTE_SOURCE_FILE (first_insn) = NOTE_SOURCE_FILE (insn);
  406.   NOTE_LINE_NUMBER (first_insn) = NOTE_LINE_NUMBER (insn);
  407.   INSN_UID (first_insn) = INSN_UID (insn);
  408.   PREV_INSN (first_insn) = NULL;
  409.   NEXT_INSN (first_insn) = NULL;
  410.   last_insn = first_insn;
  411.  
  412.   /* Each pseudo-reg in the old insn chain must have a unique rtx in the copy.
  413.      Make these new rtx's now, and install them in regno_reg_rtx, so they
  414.      will be the official pseudo-reg rtx's for the rest of compilation.  */
  415.  
  416.   reg_map = (rtx *) alloca ((max_reg + 1) * sizeof (rtx));
  417.  
  418.   len = sizeof (struct rtx_def) + (GET_RTX_LENGTH (REG) - 1) * sizeof (rtunion);
  419.   for (i = max_reg - 1; i > LAST_VIRTUAL_REGISTER; i--)
  420.     reg_map[i] = (rtx)obstack_copy (function_maybepermanent_obstack,
  421.                     regno_reg_rtx[i], len);
  422.  
  423.   bcopy (reg_map + LAST_VIRTUAL_REGISTER + 1,
  424.      regno_reg_rtx + LAST_VIRTUAL_REGISTER + 1,
  425.      (max_reg - (LAST_VIRTUAL_REGISTER + 1)) * sizeof (rtx));
  426.  
  427.   /* Likewise each label rtx must have a unique rtx as its copy.  */
  428.  
  429.   label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  430.   label_map -= min_labelno;
  431.  
  432.   for (i = min_labelno; i < max_labelno; i++)
  433.     label_map[i] = gen_label_rtx ();
  434.  
  435.   /* Record the mapping of old insns to copied insns.  */
  436.  
  437.   insn_map = (rtx *) alloca (max_uid * sizeof (rtx));
  438.   bzero (insn_map, max_uid * sizeof (rtx));
  439.  
  440.   /* Get the insn which signals the end of parameter setup code.  */
  441.   first_nonparm_insn = get_first_nonparm_insn ();
  442.  
  443.   /* Copy any entries in regno_reg_rtx or DECL_RTLs that reference MEM
  444.      (the former occurs when a variable has its address taken)
  445.      since these may be shared and can be changed by virtual
  446.      register instantiation.  DECL_RTL values for our arguments
  447.      have already been copied by initialize_for_inline.  */
  448.   for (i = LAST_VIRTUAL_REGISTER + 1; i < max_reg; i++)
  449.     if (GET_CODE (regno_reg_rtx[i]) == MEM)
  450.       XEXP (regno_reg_rtx[i], 0)
  451.     = copy_for_inline (XEXP (regno_reg_rtx[i], 0));
  452.  
  453.   /* Copy the tree of subblocks of the function, and the decls in them.
  454.      We will use the copy for compiling this function, then restore the original
  455.      subblocks and decls for use when inlining this function.
  456.  
  457.      Several parts of the compiler modify BLOCK trees.  In particular,
  458.      instantiate_virtual_regs will instantiate any virtual regs
  459.      mentioned in the DECL_RTLs of the decls, and loop
  460.      unrolling will replicate any BLOCK trees inside an unrolled loop.
  461.  
  462.      The modified subblocks or DECL_RTLs would be incorrect for the original rtl
  463.      which we will use for inlining.  The rtl might even contain pseudoregs
  464.      whose space has been freed.  */
  465.  
  466.   DECL_INITIAL (fndecl) = copy_decl_tree (DECL_INITIAL (fndecl));
  467.  
  468.   /* Now copy each DECL_RTL which is a MEM,
  469.      so it is safe to modify their addresses.  */
  470.   copy_decl_rtls (DECL_INITIAL (fndecl));
  471.  
  472.   /* Now copy the chain of insns.  Do this twice.  The first copy the insn
  473.      itself and its body.  The second time copy of REG_NOTES.  This is because
  474.      a REG_NOTE may have a forward pointer to another insn.  */
  475.  
  476.   for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
  477.     {
  478.       orig_asm_operands_vector = 0;
  479.  
  480.       if (insn == first_nonparm_insn)
  481.     in_nonparm_insns = 1;
  482.  
  483.       switch (GET_CODE (insn))
  484.     {
  485.     case NOTE:
  486.       /* No need to keep these.  */
  487.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  488.         continue;
  489.  
  490.       copy = rtx_alloc (NOTE);
  491.       NOTE_SOURCE_FILE (copy) = NOTE_SOURCE_FILE (insn);
  492.       NOTE_LINE_NUMBER (copy) = NOTE_LINE_NUMBER (insn);
  493.       break;
  494.  
  495.     case INSN:
  496.     case CALL_INSN:
  497.     case JUMP_INSN:
  498.       copy = rtx_alloc (GET_CODE (insn));
  499.       PATTERN (copy) = copy_for_inline (PATTERN (insn));
  500.       INSN_CODE (copy) = -1;
  501.       LOG_LINKS (copy) = NULL;
  502.       RTX_INTEGRATED_P (copy) = RTX_INTEGRATED_P (insn);
  503.       break;
  504.  
  505.     case CODE_LABEL:
  506.       copy = label_map[CODE_LABEL_NUMBER (insn)];
  507.       break;
  508.  
  509.     case BARRIER:
  510.       copy = rtx_alloc (BARRIER);
  511.       break;
  512.  
  513.     default:
  514.       abort ();
  515.     }
  516.       INSN_UID (copy) = INSN_UID (insn);
  517.       insn_map[INSN_UID (insn)] = copy;
  518.       NEXT_INSN (last_insn) = copy;
  519.       PREV_INSN (copy) = last_insn;
  520.       last_insn = copy;
  521.     }
  522.  
  523.   /* Now copy the REG_NOTES.  */
  524.   for (insn = NEXT_INSN (get_insns ()); insn; insn = NEXT_INSN (insn))
  525.     if ((GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  526.      || GET_CODE (insn) == CALL_INSN)
  527.     && insn_map[INSN_UID(insn)])
  528.       REG_NOTES (insn_map[INSN_UID (insn)])
  529.     = copy_for_inline (REG_NOTES (insn));
  530.  
  531.   NEXT_INSN (last_insn) = NULL;
  532.  
  533.   finish_inline (fndecl, head);
  534.  
  535.   set_new_first_and_last_insn (first_insn, last_insn);
  536. }
  537.  
  538. /* Make a copy of the entire tree of blocks BLOCK, and return it.  */
  539.  
  540. static tree
  541. copy_decl_tree (block)
  542.      tree block;
  543. {
  544.   tree t, vars, subblocks;
  545.  
  546.   vars = copy_list (BLOCK_VARS (block));
  547.   subblocks = 0;
  548.  
  549.   /* Process all subblocks.  */
  550.   for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
  551.     {
  552.       tree copy = copy_decl_tree (t);
  553.       TREE_CHAIN (copy) = subblocks;
  554.       subblocks = copy;
  555.     }
  556.  
  557.   t = copy_node (block);
  558.   BLOCK_VARS (t) = vars;
  559.   BLOCK_SUBBLOCKS (t) = nreverse (subblocks);
  560.   return t;
  561. }
  562.  
  563. /* Copy DECL_RTLs in all decls in the given BLOCK node.  */
  564.  
  565. static void
  566. copy_decl_rtls (block)
  567.      tree block;
  568. {
  569.   tree t;
  570.  
  571.   for (t = BLOCK_VARS (block); t; t = TREE_CHAIN (t))
  572.     if (DECL_RTL (t) && GET_CODE (DECL_RTL (t)) == MEM)
  573.       DECL_RTL (t) = copy_for_inline (DECL_RTL (t));
  574.  
  575.   /* Process all subblocks.  */
  576.   for (t = BLOCK_SUBBLOCKS (block); t; t = TREE_CHAIN (t))
  577.     copy_decl_rtls (t);
  578. }
  579.  
  580. /* Make the insns and PARM_DECLs of the current function permanent
  581.    and record other information in DECL_SAVED_INSNS to allow inlining
  582.    of this function in subsequent calls.
  583.  
  584.    This routine need not copy any insns because we are not going
  585.    to immediately compile the insns in the insn chain.  There
  586.    are two cases when we would compile the insns for FNDECL:
  587.    (1) when FNDECL is expanded inline, and (2) when FNDECL needs to
  588.    be output at the end of other compilation, because somebody took
  589.    its address.  In the first case, the insns of FNDECL are copied
  590.    as it is expanded inline, so FNDECL's saved insns are not
  591.    modified.  In the second case, FNDECL is used for the last time,
  592.    so modifying the rtl is not a problem.
  593.  
  594.    ??? Actually, we do not verify that FNDECL is not inline expanded
  595.    by other functions which must also be written down at the end
  596.    of compilation.  We could set flag_no_inline to nonzero when
  597.    the time comes to write down such functions.  */
  598.  
  599. void
  600. save_for_inline_nocopy (fndecl)
  601.      tree fndecl;
  602. {
  603.   rtx insn;
  604.   rtx head, copy;
  605.   tree parms;
  606.   int max_labelno, min_labelno, i, len;
  607.   int max_reg;
  608.   int max_uid;
  609.   rtx first_nonparm_insn;
  610.   int function_flags;
  611.  
  612.   /* Set up PARMDECL_MAP which maps pseudo-reg number to its PARM_DECL.
  613.      Later we set TREE_READONLY to 0 if the parm is modified inside the fn.
  614.      Also set up ARG_VECTOR, which holds the unmodified DECL_RTX values
  615.      for the parms, prior to elimination of virtual registers.
  616.      These values are needed for substituting parms properly.  */
  617.  
  618.   max_parm_reg = max_parm_reg_num ();
  619.   parmdecl_map = (tree *) alloca (max_parm_reg * sizeof (tree));
  620.  
  621.   /* Make and emit a return-label if we have not already done so.  */
  622.  
  623.   if (return_label == 0)
  624.     {
  625.       return_label = gen_label_rtx ();
  626.       emit_label (return_label);
  627.     }
  628.  
  629.   head = initialize_for_inline (fndecl, get_first_label_num (),
  630.                 max_label_num (), max_reg_num (), 0);
  631.  
  632.   /* If there are insns that copy parms from the stack into pseudo registers,
  633.      those insns are not copied.  `expand_inline_function' must
  634.      emit the correct code to handle such things.  */
  635.  
  636.   insn = get_insns ();
  637.   if (GET_CODE (insn) != NOTE)
  638.     abort ();
  639.  
  640.   /* Get the insn which signals the end of parameter setup code.  */
  641.   first_nonparm_insn = get_first_nonparm_insn ();
  642.  
  643.   /* Now just scan the chain of insns to see what happens to our
  644.      PARM_DECLs.  If a PARM_DECL is used but never modified, we
  645.      can substitute its rtl directly when expanding inline (and
  646.      perform constant folding when its incoming value is constant).
  647.      Otherwise, we have to copy its value into a new register and track
  648.      the new register's life.  */
  649.  
  650.   for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
  651.     {
  652.       if (insn == first_nonparm_insn)
  653.     in_nonparm_insns = 1;
  654.  
  655.       if (GET_CODE (insn) == INSN
  656.       || GET_CODE (insn) == CALL_INSN
  657.       || GET_CODE (insn) == JUMP_INSN)
  658.     {
  659.       if (current_function_uses_const_pool)
  660.         {
  661.           /* Replace any constant pool references with the actual constant.
  662.          We will put the constant back if we need to write the
  663.          function out after all.  */
  664.           save_constants (&PATTERN (insn));
  665.           if (REG_NOTES (insn))
  666.         save_constants (®_NOTES (insn));
  667.         }
  668.  
  669.       /* Record what interesting things happen to our parameters.  */
  670.       note_stores (PATTERN (insn), note_modified_parmregs);
  671.     }
  672.     }
  673.  
  674.   /* We have now allocated all that needs to be allocated permanently
  675.      on the rtx obstack.  Set our high-water mark, so that we
  676.      can free the rest of this when the time comes.  */
  677.  
  678.   preserve_data ();
  679.  
  680.   finish_inline (fndecl, head);
  681. }
  682.  
  683. /* Given PX, a pointer into an insn, search for references to the constant
  684.    pool.  Replace each with a CONST that has the mode of the original
  685.    constant, contains the constant, and has RTX_INTEGRATED_P set.
  686.    Similarly, constant pool addresses not enclosed in a MEM are replaced
  687.    with an ADDRESS rtx which also gives the constant, mode, and has
  688.    RTX_INTEGRATD_P set.  */
  689.  
  690. static void
  691. save_constants (px)
  692.      rtx *px;
  693. {
  694.   rtx x;
  695.   int i, j;
  696.  
  697.  again:
  698.   x = *px;
  699.  
  700.   /* If this is a CONST_DOUBLE, don't try to fix things up in 
  701.      CONST_DOUBLE_MEM, because this is an infinite recursion.  */
  702.   if (GET_CODE (x) == CONST_DOUBLE)
  703.     return;
  704.   else if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
  705.        && CONSTANT_POOL_ADDRESS_P (XEXP (x,0)))
  706.     {
  707.       *px = gen_rtx (CONST, get_pool_mode (XEXP (x, 0)),
  708.              get_pool_constant (XEXP (x, 0)));
  709.       RTX_INTEGRATED_P (*px) = 1;
  710.       save_constants (&XEXP (*px, 0));
  711.     }
  712.   else if (GET_CODE (x) == SYMBOL_REF
  713.        && CONSTANT_POOL_ADDRESS_P (x))
  714.     {
  715.       *px = gen_rtx (ADDRESS, get_pool_mode (x), get_pool_constant (x));
  716.       save_constants (&XEXP (*px, 0));
  717.       RTX_INTEGRATED_P (*px) = 1;
  718.     }
  719.  
  720.   else
  721.     {
  722.       char *fmt = GET_RTX_FORMAT (GET_CODE (x));
  723.       int len = GET_RTX_LENGTH (GET_CODE (x));
  724.  
  725.       for (i = len-1; i >= 0; i--)
  726.     {
  727.       switch (fmt[i])
  728.         {
  729.         case 'E':
  730.           for (j = 0; j < XVECLEN (x, i); j++)
  731.         save_constants (&XVECEXP (x, i, j));
  732.           break;
  733.  
  734.         case 'e':
  735.           if (XEXP (x, i) == 0)
  736.         continue;
  737.           if (i == 0)
  738.         {
  739.           /* Hack tail-recursion here.  */
  740.           px = &XEXP (x, 0);
  741.           goto again;
  742.         }
  743.           save_constants (&XEXP (x, i));
  744.           break;
  745.         }
  746.     }
  747.     }
  748. }
  749.  
  750. /* Note whether a parameter is modified or not.  */
  751.  
  752. static void
  753. note_modified_parmregs (reg, x)
  754.      rtx reg;
  755.      rtx x;
  756. {
  757.   if (GET_CODE (reg) == REG && in_nonparm_insns
  758.       && REGNO (reg) < max_parm_reg
  759.       && REGNO (reg) >= FIRST_PSEUDO_REGISTER
  760.       && parmdecl_map[REGNO (reg)] != 0)
  761.     TREE_READONLY (parmdecl_map[REGNO (reg)]) = 0;
  762. }
  763.  
  764. /* Copy the rtx ORIG recursively, replacing pseudo-regs and labels
  765.    according to `reg_map' and `label_map'.  The original rtl insns
  766.    will be saved for inlining; this is used to make a copy
  767.    which is used to finish compiling the inline function itself.
  768.  
  769.    If we find a "saved" constant pool entry, one which was replaced with
  770.    the value of the constant, convert it back to a constant pool entry.
  771.    Since the pool wasn't touched, this should simply restore the old
  772.    address.
  773.  
  774.    All other kinds of rtx are copied except those that can never be
  775.    changed during compilation.  */
  776.  
  777. static rtx
  778. copy_for_inline (orig)
  779.      rtx orig;
  780. {
  781.   register rtx x = orig;
  782.   register int i;
  783.   register enum rtx_code code;
  784.   register char *format_ptr;
  785.  
  786.   if (x == 0)
  787.     return x;
  788.  
  789.   code = GET_CODE (x);
  790.  
  791.   /* These types may be freely shared.  */
  792.  
  793.   switch (code)
  794.     {
  795.     case QUEUED:
  796.     case CONST_INT:
  797.     case SYMBOL_REF:
  798.     case PC:
  799.     case CC0:
  800.       return x;
  801.  
  802.     case CONST_DOUBLE:
  803.       /* We have to make a new CONST_DOUBLE to ensure that we account for
  804.      it correctly.  Using the old CONST_DOUBLE_MEM data is wrong.  */
  805.       {
  806.     double d;
  807.     REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  808.     return immed_real_const_1 (d, GET_MODE (x));
  809.       }
  810.  
  811.     case CONST:
  812.       /* Get constant pool entry for constant in the pool.  */
  813.       if (RTX_INTEGRATED_P (x))
  814.     return validize_mem (force_const_mem (GET_MODE (x),
  815.                           copy_for_inline (XEXP (x, 0))));
  816.       break;
  817.  
  818.     case ADDRESS:
  819.       /* If not special for constant pool error.  Else get constant pool
  820.      address.  */
  821.       if (! RTX_INTEGRATED_P (x))
  822.     abort ();
  823.  
  824.       return XEXP (force_const_mem (GET_MODE (x),
  825.                     copy_for_inline (XEXP (x, 0))), 0);
  826.  
  827.     case ASM_OPERANDS:
  828.       /* If a single asm insn contains multiple output operands
  829.      then it contains multiple ASM_OPERANDS rtx's that share operand 3.
  830.      We must make sure that the copied insn continues to share it.  */
  831.       if (orig_asm_operands_vector == XVEC (orig, 3))
  832.     {
  833.       x = rtx_alloc (ASM_OPERANDS);
  834.       XSTR (x, 0) = XSTR (orig, 0);
  835.       XSTR (x, 1) = XSTR (orig, 1);
  836.       XINT (x, 2) = XINT (orig, 2);
  837.       XVEC (x, 3) = copy_asm_operands_vector;
  838.       XVEC (x, 4) = copy_asm_constraints_vector;
  839.       XSTR (x, 5) = XSTR (orig, 5);
  840.       XINT (x, 6) = XINT (orig, 6);
  841.       return x;
  842.     }
  843.       break;
  844.  
  845.     case MEM:
  846.       /* A MEM is allowed to be shared if its address is constant
  847.      or is a constant plus one of the special registers.  */
  848.       if (CONSTANT_ADDRESS_P (XEXP (x, 0)))
  849.     return x;
  850. #if 0 /* This is turned off because it is possible for
  851.      unshare_all_rtl to copy the address, into memory that won't be saved.
  852.      Although the MEM can safely be shared, and won't be copied there,
  853.      the address itself cannot be shared, and may need to be copied.  */
  854.       if (GET_CODE (XEXP (x, 0)) == PLUS
  855.       && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  856.       && (REGNO (XEXP (XEXP (x, 0), 0)) == FRAME_POINTER_REGNUM
  857.           || REGNO (XEXP (XEXP (x, 0), 0)) == ARG_POINTER_REGNUM)
  858.       && CONSTANT_ADDRESS_P (XEXP (XEXP (x, 0), 1)))
  859.     return x;
  860.       if (GET_CODE (XEXP (x, 0)) == REG
  861.       && (REGNO (XEXP (x, 0)) == FRAME_POINTER_REGNUM
  862.           || REGNO (XEXP (x, 0)) == ARG_POINTER_REGNUM)
  863.       && CONSTANT_ADDRESS_P (XEXP (x, 1)))
  864.     return x;
  865. #endif /* 0 */
  866.       break;
  867.  
  868.     case LABEL_REF:
  869.       {
  870.     /* Must point to the new insn.  */
  871.     return gen_rtx (LABEL_REF, GET_MODE (orig),
  872.             label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))]);
  873.       }
  874.  
  875.     case REG:
  876.       if (REGNO (x) > LAST_VIRTUAL_REGISTER)
  877.     return reg_map [REGNO (x)];
  878.       else
  879.     return x;
  880.  
  881.     case SET:
  882.       /* If a parm that gets modified lives in a pseudo-reg,
  883.      clear its TREE_READONLY to prevent certain optimizations.  */
  884.       {
  885.     rtx dest = SET_DEST (x);
  886.  
  887.     while (GET_CODE (dest) == STRICT_LOW_PART
  888.            || GET_CODE (dest) == ZERO_EXTRACT
  889.            || GET_CODE (dest) == SUBREG)
  890.       dest = XEXP (dest, 0);
  891.  
  892.     if (GET_CODE (dest) == REG
  893.         && REGNO (dest) < max_parm_reg
  894.         && REGNO (dest) >= FIRST_PSEUDO_REGISTER
  895.         && parmdecl_map[REGNO (dest)] != 0
  896.         /* The insn to load an arg pseudo from a stack slot
  897.            does not count as modifying it.  */
  898.         && in_nonparm_insns)
  899.       TREE_READONLY (parmdecl_map[REGNO (dest)]) = 0;
  900.       }
  901.       break;
  902.  
  903. #if 0 /* This is a good idea, but here is the wrong place for it.  */
  904.       /* Arrange that CONST_INTs always appear as the second operand
  905.      if they appear, and that `frame_pointer_rtx' or `arg_pointer_rtx'
  906.      always appear as the first.  */
  907.     case PLUS:
  908.       if (GET_CODE (XEXP (x, 0)) == CONST_INT
  909.       || (XEXP (x, 1) == frame_pointer_rtx
  910.           || (ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  911.           && XEXP (x, 1) == arg_pointer_rtx)))
  912.     {
  913.       rtx t = XEXP (x, 0);
  914.       XEXP (x, 0) = XEXP (x, 1);
  915.       XEXP (x, 1) = t;
  916.     }
  917.       break;
  918. #endif
  919.     }
  920.  
  921.   /* Replace this rtx with a copy of itself.  */
  922.  
  923.   x = rtx_alloc (code);
  924.   bcopy (orig, x, (sizeof (*x) - sizeof (x->fld)
  925.            + sizeof (x->fld[0]) * GET_RTX_LENGTH (code)));
  926.  
  927.   /* Now scan the subexpressions recursively.
  928.      We can store any replaced subexpressions directly into X
  929.      since we know X is not shared!  Any vectors in X
  930.      must be copied if X was copied.  */
  931.  
  932.   format_ptr = GET_RTX_FORMAT (code);
  933.  
  934.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  935.     {
  936.       switch (*format_ptr++)
  937.     {
  938.     case 'e':
  939.       XEXP (x, i) = copy_for_inline (XEXP (x, i));
  940.       break;
  941.  
  942.     case 'u':
  943.       /* Change any references to old-insns to point to the
  944.          corresponding copied insns.  */
  945.       XEXP (x, i) = insn_map[INSN_UID (XEXP (x, i))];
  946.       break;
  947.  
  948.     case 'E':
  949.       if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
  950.         {
  951.           register int j;
  952.  
  953.           XVEC (x, i) = gen_rtvec_v (XVECLEN (x, i), &XVECEXP (x, i, 0));
  954.           for (j = 0; j < XVECLEN (x, i); j++)
  955.         XVECEXP (x, i, j)
  956.           = copy_for_inline (XVECEXP (x, i, j));
  957.         }
  958.       break;
  959.     }
  960.     }
  961.  
  962.   if (code == ASM_OPERANDS && orig_asm_operands_vector == 0)
  963.     {
  964.       orig_asm_operands_vector = XVEC (orig, 3);
  965.       copy_asm_operands_vector = XVEC (x, 3);
  966.       copy_asm_constraints_vector = XVEC (x, 4);
  967.     }
  968.  
  969.   return x;
  970. }
  971.  
  972. /* Unfortunately, we need a global copy of const_equiv map for communication
  973.    with a function called from note_stores.  Be *very* careful that this
  974.    is used properly in the presence of recursion.  */
  975.  
  976. rtx *global_const_equiv_map;
  977.  
  978. #define FIXED_BASE_PLUS_P(X) \
  979.   (GET_CODE (X) == PLUS && GET_CODE (XEXP (X, 1)) == CONST_INT    \
  980.    && GET_CODE (XEXP (X, 0)) == REG                \
  981.    && REGNO (XEXP (X, 0)) >= FIRST_VIRTUAL_REGISTER        \
  982.    && REGNO (XEXP (X, 0)) < LAST_VIRTUAL_REGISTER)
  983.  
  984. /* Integrate the procedure defined by FNDECL.  Note that this function
  985.    may wind up calling itself.  Since the static variables are not
  986.    reentrant, we do not assign them until after the possibility
  987.    or recursion is eliminated.
  988.  
  989.    If IGNORE is nonzero, do not produce a value.
  990.    Otherwise store the value in TARGET if it is nonzero and that is convenient.
  991.  
  992.    Value is:
  993.    (rtx)-1 if we could not substitute the function
  994.    0 if we substituted it and it does not produce a value
  995.    else an rtx for where the value is stored.  */
  996.  
  997. rtx
  998. expand_inline_function (fndecl, parms, target, ignore, type, structure_value_addr)
  999.      tree fndecl, parms;
  1000.      rtx target;
  1001.      int ignore;
  1002.      tree type;
  1003.      rtx structure_value_addr;
  1004. {
  1005.   tree formal, actual;
  1006.   rtx header = DECL_SAVED_INSNS (fndecl);
  1007.   rtx insns = FIRST_FUNCTION_INSN (header);
  1008.   rtx parm_insns = FIRST_PARM_INSN (header);
  1009.   tree *arg_trees;
  1010.   rtx *arg_vals;
  1011.   rtx insn;
  1012.   int max_regno;
  1013.   int equiv_map_size;
  1014.   register int i;
  1015.   int min_labelno = FIRST_LABELNO (header);
  1016.   int max_labelno = LAST_LABELNO (header);
  1017.   int nargs;
  1018.   rtx local_return_label = 0;
  1019.   rtx loc;
  1020.   rtx temp;
  1021.   struct inline_remap *map;
  1022.   rtx cc0_insn = 0;
  1023.   rtvec arg_vector = ORIGINAL_ARG_VECTOR (header);
  1024.  
  1025.   /* Allow for equivalences of the pseudos we make for virtual fp and ap.  */
  1026.   max_regno = MAX_REGNUM (header) + 3;
  1027.   if (max_regno < FIRST_PSEUDO_REGISTER)
  1028.     abort ();
  1029.  
  1030.   nargs = list_length (DECL_ARGUMENTS (fndecl));
  1031.  
  1032.   /* We expect PARMS to have the right length; don't crash if not.  */
  1033.   if (list_length (parms) != nargs)
  1034.     return (rtx)-1;
  1035.   /* Also check that the parms type match.  Since the appropriate
  1036.      conversions or default promotions have already been applied,
  1037.      the machine modes should match exactly.  */
  1038.   for (formal = DECL_ARGUMENTS (fndecl),
  1039.        actual = parms;
  1040.        formal;
  1041.        formal = TREE_CHAIN (formal),
  1042.        actual = TREE_CHAIN (actual))
  1043.     {
  1044.       tree arg = TREE_VALUE (actual);
  1045.       enum machine_mode mode = TYPE_MODE (DECL_ARG_TYPE (formal));
  1046.       if (mode != TYPE_MODE (TREE_TYPE (arg)))
  1047.     return (rtx)-1;
  1048.       /* If they are block mode, the types should match exactly.
  1049.          They don't match exactly if TREE_TYPE (FORMAL) == ERROR_MARK_NODE,
  1050.      which could happen if the parameter has incomplete type.  */
  1051.       if (mode == BLKmode && TREE_TYPE (arg) != TREE_TYPE (formal))
  1052.     return (rtx)-1;
  1053.     }
  1054.  
  1055.   /* Make a binding contour to keep inline cleanups called at
  1056.      outer function-scope level from looking like they are shadowing
  1057.      parameter declarations.  */
  1058.   pushlevel (0);
  1059.  
  1060.   /* Make a fresh binding contour that we can easily remove.  */
  1061.   pushlevel (0);
  1062.   expand_start_bindings (0);
  1063.   if (GET_CODE (parm_insns) == NOTE
  1064.       && NOTE_LINE_NUMBER (parm_insns) > 0)
  1065.     emit_note (NOTE_SOURCE_FILE (parm_insns), NOTE_LINE_NUMBER (parm_insns));
  1066.  
  1067.   /* Expand the function arguments.  Do this first so that any
  1068.      new registers get created before we allocate the maps.  */
  1069.  
  1070.   arg_vals = (rtx *) alloca (nargs * sizeof (rtx));
  1071.   arg_trees = (tree *) alloca (nargs * sizeof (tree));
  1072.  
  1073.   for (formal = DECL_ARGUMENTS (fndecl), actual = parms, i = 0;
  1074.        formal;
  1075.        formal = TREE_CHAIN (formal), actual = TREE_CHAIN (actual), i++)
  1076.     {
  1077.       /* Actual parameter, converted to the type of the argument within the
  1078.      function.  */
  1079.       tree arg = convert (TREE_TYPE (formal), TREE_VALUE (actual));
  1080.       /* Mode of the variable used within the function.  */
  1081.       enum machine_mode mode = TYPE_MODE (TREE_TYPE (formal));
  1082.       /* Where parameter is located in the function.  */
  1083.       rtx copy;
  1084.  
  1085.       emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
  1086.  
  1087.       arg_trees[i] = arg;
  1088.       loc = RTVEC_ELT (arg_vector, i);
  1089.  
  1090.       /* If this is an object passed by invisible reference, we compute
  1091.      the address of the object.  If this will go into memory, we do
  1092.      nothing now.  Otherwise, we just expand the argument.  */
  1093.       if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
  1094.       && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
  1095.     arg_vals[i]
  1096.       = XEXP (expand_expr (arg, 0, VOIDmode, EXPAND_CONST_ADDRESS), 0);
  1097.       else if (GET_CODE (loc) != MEM)
  1098.     arg_vals[i] = expand_expr (arg, 0, mode, EXPAND_SUM);
  1099.       else
  1100.     arg_vals[i] = 0;
  1101.  
  1102.       if (arg_vals[i] != 0
  1103.       && (! TREE_READONLY (formal)
  1104.           /* If the parameter is not read-only, copy our argument through
  1105.          a register.  Also, we cannot use ARG_VALS[I] if it overlaps
  1106.          TARGET in any way.  In the inline function, they will likely
  1107.          be two different pseudos, and `safe_from_p' will make all
  1108.          sorts of smart assumptions about their not conflicting.
  1109.          But if ARG_VALS[I] overlaps TARGET, these assumptions are
  1110.          wrong, so put ARG_VALS[I] into a fresh register.  */
  1111.           || (target != 0
  1112.           && (GET_CODE (arg_vals[i]) == REG
  1113.               || GET_CODE (arg_vals[i]) == SUBREG
  1114.               || GET_CODE (arg_vals[i]) == MEM)
  1115.           && reg_overlap_mentioned_p (arg_vals[i], target))))
  1116.     arg_vals[i] = copy_to_mode_reg (mode, arg_vals[i]);
  1117.     }
  1118.     
  1119.   /* Allocate the structures we use to remap things.  */
  1120.  
  1121.   map = (struct inline_remap *) alloca (sizeof (struct inline_remap));
  1122.   map->fndecl = fndecl;
  1123.  
  1124.   map->reg_map = (rtx *) alloca (max_regno * sizeof (rtx));
  1125.   bzero (map->reg_map, max_regno * sizeof (rtx));
  1126.  
  1127.   map->label_map = (rtx *)alloca ((max_labelno - min_labelno) * sizeof (rtx));
  1128.   map->label_map -= min_labelno;
  1129.  
  1130.   map->insn_map = (rtx *) alloca (INSN_UID (header) * sizeof (rtx));
  1131.   bzero (map->insn_map, INSN_UID (header) * sizeof (rtx));
  1132.   map->min_insnno = 0;
  1133.   map->max_insnno = INSN_UID (header);
  1134.  
  1135.   /* const_equiv_map maps pseudos in our routine to constants, so it needs to
  1136.      be large enough for all our pseudos.  This is the number we are currently
  1137.      using plus the number in the called routine, plus one for each arg and
  1138.      one for the return value.  */
  1139.   equiv_map_size
  1140.     = max_reg_num () + (max_regno - FIRST_PSEUDO_REGISTER) + nargs + 1;
  1141.  
  1142.   map->const_equiv_map = (rtx *)alloca (equiv_map_size * sizeof (rtx));
  1143.   bzero (map->const_equiv_map, equiv_map_size * sizeof (rtx));
  1144.  
  1145.   map->const_age_map = (unsigned *)alloca (equiv_map_size * sizeof (unsigned));
  1146.   bzero (map->const_age_map, equiv_map_size * sizeof (unsigned));
  1147.   map->const_age = 0;
  1148.  
  1149.   /* Record the current insn in case we have to set up pointers to frame
  1150.      and argument memory blocks.  */
  1151.   map->insns_at_start = get_last_insn ();
  1152.  
  1153.   /* Update the outgoing argument size to allow for those in the inlined
  1154.      function.  */
  1155.   if (OUTGOING_ARGS_SIZE (header) > current_function_outgoing_args_size)
  1156.     current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (header);
  1157.  
  1158.   /* Process each argument.  For each, set up things so that the function's
  1159.      reference to the argument will refer to the argument being passed.
  1160.      We only replace REG with REG here.  Any simplifications are done
  1161.      via const_equiv_map.
  1162.  
  1163.      We make two passes:  In the first, we deal with parameters that will
  1164.      be placed into registers, since we need to ensure that the allocated
  1165.      register number fits in const_equiv_map.  Then we store all non-register
  1166.      parameters into their memory location.  */
  1167.  
  1168.   for (i = 0; i < nargs; i++)
  1169.     {
  1170.       rtx copy = arg_vals[i];
  1171.  
  1172.       loc = RTVEC_ELT (arg_vector, i);
  1173.  
  1174.       /* There are three cases, each handled separately.  */
  1175.       if (GET_CODE (loc) == MEM && GET_CODE (XEXP (loc, 0)) == REG
  1176.       && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER)
  1177.     {
  1178.       /* This must be an object passed by invisible reference (it could
  1179.          also be a variable-sized object, but we forbid inlining functions
  1180.          with variable-sized arguments).  COPY is the address of the
  1181.          actual value (this computation will cause it to be copied).  We
  1182.          map that address for the register, noting the actual address as
  1183.          an equivalent in case it can be substituted into the insns.  */
  1184.  
  1185.       if (GET_CODE (copy) != REG)
  1186.         {
  1187.           temp = copy_addr_to_reg (copy);
  1188.           if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
  1189.         {
  1190.           map->const_equiv_map[REGNO (temp)] = copy;
  1191.           map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
  1192.         }
  1193.           copy = temp;
  1194.         }
  1195.       map->reg_map[REGNO (XEXP (loc, 0))] = copy;
  1196.     }
  1197.       else if (GET_CODE (loc) == MEM)
  1198.     {
  1199.       /* This is the case of a parameter that lives in memory.
  1200.          It will live in the block we allocate in the called routine's
  1201.          frame that simulates the incoming argument area.  Do nothing
  1202.          now; we will call store_expr later.  */
  1203.       ;
  1204.     }
  1205.       else if (GET_CODE (loc) == REG)
  1206.     {
  1207.       /* This is the good case where the parameter is in a register.
  1208.          If it is read-only and our argument is a constant, set up the
  1209.          constant equivalence.  */
  1210.       if (GET_CODE (copy) != REG && GET_CODE (copy) != SUBREG)
  1211.         {
  1212.           temp = copy_to_mode_reg (GET_MODE (loc), copy);
  1213.           if (CONSTANT_P (copy) || FIXED_BASE_PLUS_P (copy))
  1214.         {
  1215.           map->const_equiv_map[REGNO (temp)] = copy;
  1216.           map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
  1217.         }
  1218.           copy = temp;
  1219.         }
  1220.       map->reg_map[REGNO (loc)] = copy;
  1221.     }
  1222.       else
  1223.     abort ();
  1224.  
  1225.       /* Free any temporaries we made setting up this parameter.  */
  1226.       free_temp_slots ();
  1227.     }
  1228.  
  1229.   /* Now do the parameters that will be placed in memory.  */
  1230.  
  1231.   for (formal = DECL_ARGUMENTS (fndecl), i = 0;
  1232.        formal; formal = TREE_CHAIN (formal), i++)
  1233.     {
  1234.       rtx copy = arg_vals[i];
  1235.  
  1236.       loc = RTVEC_ELT (arg_vector, i);
  1237.  
  1238.       if (GET_CODE (loc) == MEM
  1239.       /* Exclude case handled above.  */
  1240.       && ! (GET_CODE (XEXP (loc, 0)) == REG
  1241.         && REGNO (XEXP (loc, 0)) > LAST_VIRTUAL_REGISTER))
  1242.     {
  1243.       emit_note (DECL_SOURCE_FILE (formal), DECL_SOURCE_LINE (formal));
  1244.  
  1245.       /* Compute the address in the area we reserved and store the
  1246.          value there.  */
  1247.       temp = copy_rtx_and_substitute (loc, map);
  1248.       subst_constants (&temp, 0, map);
  1249.       apply_change_group ();
  1250.       if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
  1251.         temp = change_address (temp, VOIDmode, XEXP (temp, 0));
  1252.       store_expr (arg_trees[i], temp, 0);
  1253.     }
  1254.  
  1255.       /* Free any temporaries we made setting up this parameter.  */
  1256.       free_temp_slots ();
  1257.     }
  1258.  
  1259.   /* Deal with the places that the function puts its result.
  1260.      We are driven by what is placed into DECL_RESULT.
  1261.  
  1262.      Initially, we assume that we don't have anything special handling for
  1263.      REG_FUNCTION_RETURN_VALUE_P.  */
  1264.  
  1265.   map->inline_target = 0;
  1266.   loc = DECL_RTL (DECL_RESULT (fndecl));
  1267.   if (ignore || TYPE_MODE (type) == VOIDmode)
  1268.     /* We will ignore the result value, so don't look at its structure.  */
  1269.     ;
  1270.   else if (GET_CODE (loc) == MEM)
  1271.     {
  1272.       if (! structure_value_addr || ! aggregate_value_p (DECL_RESULT (fndecl)))
  1273.     abort ();
  1274.   
  1275.       /* Pass the function the address in which to return a structure value.
  1276.      Note that a constructor can cause someone to call us with
  1277.      STRUCTURE_VALUE_ADDR, but the initialization takes place
  1278.      via the first parameter, rather than the struct return address.
  1279.  
  1280.      We have two cases:  If the address is a simple register indirect,
  1281.      use the mapping mechanism to point that register to our structure
  1282.      return address.  Otherwise, store the structure return value into
  1283.      the place that it will be referenced from.  */
  1284.  
  1285.       if (GET_CODE (XEXP (loc, 0)) == REG)
  1286.     {
  1287.       temp = force_reg (Pmode, structure_value_addr);
  1288.       map->reg_map[REGNO (XEXP (loc, 0))] = temp;
  1289.       if (CONSTANT_P (structure_value_addr)
  1290.           || (GET_CODE (structure_value_addr) == PLUS
  1291.           && XEXP (structure_value_addr, 0) == virtual_stack_vars_rtx
  1292.           && GET_CODE (XEXP (structure_value_addr, 1)) == CONST_INT))
  1293.         {
  1294.           map->const_equiv_map[REGNO (temp)] = structure_value_addr;
  1295.           map->const_age_map[REGNO (temp)] = CONST_AGE_PARM;
  1296.         }
  1297.     }
  1298.       else
  1299.     {
  1300.       temp = copy_rtx_and_substitute (loc, map);
  1301.       subst_constants (&temp, 0, map);
  1302.       apply_change_group ();
  1303.       emit_move_insn (temp, structure_value_addr);
  1304.     }
  1305.     }
  1306.   else if (GET_CODE (loc) == REG)
  1307.     {
  1308.       /* The function returns an object in a register and we use the return
  1309.      value.  Set up our target for remapping.  */
  1310.  
  1311.       /* Machine mode function was declared to return.   */
  1312.       enum machine_mode departing_mode = TYPE_MODE (type);
  1313.       /* (Possibly wider) machine mode it actually computes
  1314.      (for the sake of callers that fail to declare it right).  */
  1315.       enum machine_mode arriving_mode
  1316.     = TYPE_MODE (TREE_TYPE (DECL_RESULT (fndecl)));
  1317.       rtx reg_to_map;
  1318.  
  1319.       /* Don't use MEMs as direct targets because on some machines
  1320.      substituting a MEM for a REG makes invalid insns.
  1321.      Let the combiner substitute the MEM if that is valid.  */
  1322.       if (target == 0 || GET_CODE (target) != REG
  1323.       || GET_MODE (target) != departing_mode)
  1324.     target = gen_reg_rtx (departing_mode);
  1325.  
  1326.       /* If function's value was promoted before return,
  1327.      avoid machine mode mismatch when we substitute INLINE_TARGET.
  1328.      But TARGET is what we will return to the caller.  */
  1329.       if (arriving_mode != departing_mode)
  1330.     reg_to_map = gen_rtx (SUBREG, arriving_mode, target, 0);
  1331.       else
  1332.     reg_to_map = target;
  1333.  
  1334.       /* Usually, the result value is the machine's return register.
  1335.      Sometimes it may be a pseudo. Handle both cases.  */
  1336.       if (REG_FUNCTION_VALUE_P (loc))
  1337.     map->inline_target = reg_to_map;
  1338.       else
  1339.     map->reg_map[REGNO (loc)] = reg_to_map;
  1340.     }
  1341.  
  1342.   /* Make new label equivalences for the labels in the called function.  */
  1343.   for (i = min_labelno; i < max_labelno; i++)
  1344.     map->label_map[i] = gen_label_rtx ();
  1345.  
  1346.   /* Perform postincrements before actually calling the function.  */
  1347.   emit_queue ();
  1348.  
  1349.   /* Clean up stack so that variables might have smaller offsets.  */
  1350.   do_pending_stack_adjust ();
  1351.  
  1352.   /* Save a copy of the location of const_equiv_map for mark_stores, called
  1353.      via note_stores.  */
  1354.   global_const_equiv_map = map->const_equiv_map;
  1355.  
  1356.   /* Now copy the insns one by one.  Do this in two passes, first the insns and
  1357.      then their REG_NOTES, just like save_for_inline.  */
  1358.  
  1359.   /* This loop is very similar to the loop in copy_loop_body in unroll.c.  */
  1360.  
  1361.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  1362.     {
  1363.       rtx copy, pattern;
  1364.  
  1365.       map->orig_asm_operands_vector = 0;
  1366.  
  1367.       switch (GET_CODE (insn))
  1368.     {
  1369.     case INSN:
  1370.       pattern = PATTERN (insn);
  1371.       copy = 0;
  1372.       if (GET_CODE (pattern) == USE
  1373.           && GET_CODE (XEXP (pattern, 0)) == REG
  1374.           && REG_FUNCTION_VALUE_P (XEXP (pattern, 0)))
  1375.         /* The (USE (REG n)) at return from the function should
  1376.            be ignored since we are changing (REG n) into
  1377.            inline_target.  */
  1378.         break;
  1379.  
  1380.       /* Ignore setting a function value that we don't want to use.  */
  1381.       if (map->inline_target == 0
  1382.           && GET_CODE (pattern) == SET
  1383.           && GET_CODE (SET_DEST (pattern)) == REG
  1384.           && REG_FUNCTION_VALUE_P (SET_DEST (pattern)))
  1385.         break;
  1386.  
  1387.       copy = emit_insn (copy_rtx_and_substitute (pattern, map));
  1388.       /* REG_NOTES will be copied later.  */
  1389.  
  1390. #ifdef HAVE_cc0
  1391.       /* If this insn is setting CC0, it may need to look at
  1392.          the insn that uses CC0 to see what type of insn it is.
  1393.          In that case, the call to recog via validate_change will
  1394.          fail.  So don't substitute constants here.  Instead,
  1395.          do it when we emit the following insn.
  1396.  
  1397.          For example, see the pyr.md file.  That machine has signed and
  1398.          unsigned compares.  The compare patterns must check the
  1399.          following branch insn to see which what kind of compare to
  1400.          emit.
  1401.  
  1402.          If the previous insn set CC0, substitute constants on it as
  1403.          well.  */
  1404.       if (sets_cc0_p (PATTERN (copy)) != 0)
  1405.         cc0_insn = copy;
  1406.       else
  1407.         {
  1408.           if (cc0_insn)
  1409.         try_constants (cc0_insn, map);
  1410.           cc0_insn = 0;
  1411.           try_constants (copy, map);
  1412.         }
  1413. #else
  1414.       try_constants (copy, map);
  1415. #endif
  1416.       break;
  1417.  
  1418.     case JUMP_INSN:
  1419.       if (GET_CODE (PATTERN (insn)) == RETURN)
  1420.         {
  1421.           if (local_return_label == 0)
  1422.         local_return_label = gen_label_rtx ();
  1423.           pattern = gen_jump (local_return_label);
  1424.         }
  1425.       else
  1426.         pattern = copy_rtx_and_substitute (PATTERN (insn), map);
  1427.  
  1428.       copy = emit_jump_insn (pattern);
  1429.  
  1430. #ifdef HAVE_cc0
  1431.       if (cc0_insn)
  1432.         try_constants (cc0_insn, map);
  1433.       cc0_insn = 0;
  1434. #endif
  1435.       try_constants (copy, map);
  1436.  
  1437.       /* If this used to be a conditional jump insn but whose branch
  1438.          direction is now know, we must do something special.  */
  1439.       if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
  1440.         {
  1441. #ifdef HAVE_cc0
  1442.           /* The previous insn set cc0 for us.  So delete it.  */
  1443.           delete_insn (PREV_INSN (copy));
  1444. #endif
  1445.  
  1446.           /* If this is now a no-op, delete it.  */
  1447.           if (map->last_pc_value == pc_rtx)
  1448.         {
  1449.           delete_insn (copy);
  1450.           copy = 0;
  1451.         }
  1452.           else
  1453.         /* Otherwise, this is unconditional jump so we must put a
  1454.            BARRIER after it.  We could do some dead code elimination
  1455.            here, but jump.c will do it just as well.  */
  1456.         emit_barrier ();
  1457.         }
  1458.       break;
  1459.  
  1460.     case CALL_INSN:
  1461.       pattern = copy_rtx_and_substitute (PATTERN (insn), map);
  1462.       copy = emit_call_insn (pattern);
  1463.  
  1464. #ifdef HAVE_cc0
  1465.       if (cc0_insn)
  1466.         try_constants (cc0_insn, map);
  1467.       cc0_insn = 0;
  1468. #endif
  1469.       try_constants (copy, map);
  1470.  
  1471.       /* Be lazy and assume CALL_INSNs clobber all hard registers.  */
  1472.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1473.         map->const_equiv_map[i] = 0;
  1474.       break;
  1475.  
  1476.     case CODE_LABEL:
  1477.       copy = emit_label (map->label_map[CODE_LABEL_NUMBER (insn)]);
  1478.       map->const_age++;
  1479.       break;
  1480.  
  1481.     case BARRIER:
  1482.       copy = emit_barrier ();
  1483.       break;
  1484.  
  1485.     case NOTE:
  1486.       /* It is important to discard function-end and function-beg notes,
  1487.          so we have only one of each in the current function.
  1488.          Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
  1489.          deleted these in the copy used for continuing compilation,
  1490.          not the copy used for inlining).  */
  1491.       if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
  1492.           && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
  1493.           && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
  1494.         copy = emit_note (NOTE_SOURCE_FILE (insn), NOTE_LINE_NUMBER (insn));
  1495.       else
  1496.         copy = 0;
  1497.       break;
  1498.  
  1499.     default:
  1500.       abort ();
  1501.       break;
  1502.     }
  1503.  
  1504.       if (copy)
  1505.     RTX_INTEGRATED_P (copy) = 1;
  1506.  
  1507.       map->insn_map[INSN_UID (insn)] = copy;
  1508.     }
  1509.  
  1510.   /* Now copy the REG_NOTES.  */
  1511.   for (insn = insns; insn; insn = NEXT_INSN (insn))
  1512.     if ((GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  1513.      || GET_CODE (insn) == CALL_INSN)
  1514.     && map->insn_map[INSN_UID (insn)])
  1515.       REG_NOTES (map->insn_map[INSN_UID (insn)])
  1516.     = copy_rtx_and_substitute (REG_NOTES (insn), map);
  1517.  
  1518.   if (local_return_label)
  1519.     emit_label (local_return_label);
  1520.  
  1521.   /* Make copies of the decls of the symbols in the inline function, so that
  1522.      the copies of the variables get declared in the current function.  */
  1523.   integrate_decl_tree ((tree) ORIGINAL_DECL_INITIAL (header), 0, map, 0);
  1524.   integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
  1525.  
  1526.   /* End the scope containing the copied formal parameter variables.  */
  1527.  
  1528.   expand_end_bindings (getdecls (), 1, 1);
  1529.   poplevel (1, 1, 0);
  1530.   poplevel (0, 0, 0);
  1531.   emit_line_note (input_filename, lineno);
  1532.  
  1533.   if (structure_value_addr)
  1534.     return gen_rtx (MEM, TYPE_MODE (type),
  1535.             memory_address (TYPE_MODE (type), structure_value_addr));
  1536.   return target;
  1537. }
  1538.  
  1539. /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
  1540.    push all of those decls and give each one the corresponding home.  */
  1541.  
  1542. static void
  1543. integrate_parm_decls (args, map, arg_vector)
  1544.      tree args;
  1545.      struct inline_remap *map;
  1546.      rtvec arg_vector;
  1547. {
  1548.   register tree tail;
  1549.   register int i;
  1550.  
  1551.   for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
  1552.     {
  1553.       register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
  1554.                        TREE_TYPE (tail));
  1555.       rtx new_decl_rtl
  1556.     = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map);
  1557.  
  1558.       /* These args would always appear unused, if not for this.  */
  1559.       TREE_USED (decl) = 1;
  1560.       /* Prevent warning for shadowing with these.  */
  1561.       TREE_INLINE (decl) = 1;
  1562.       pushdecl (decl);
  1563.       /* Fully instantiate the address with the equivalent form so that the
  1564.      debugging information contains the actual register, instead of the
  1565.      virtual register.   Do this by not passing an insn to
  1566.      subst_constants.  */
  1567.       subst_constants (&new_decl_rtl, 0, map);
  1568.       apply_change_group ();
  1569.       DECL_RTL (decl) = new_decl_rtl;
  1570.     }
  1571. }
  1572.  
  1573. /* Given a BLOCK node LET, push decls and levels so as to construct in the
  1574.    current function a tree of contexts isomorphic to the one that is given.
  1575.  
  1576.    LEVEL indicates how far down into the BLOCK tree is the node we are
  1577.    currently traversing.  It is always zero for the initial call.
  1578.  
  1579.    MAP, if nonzero, is a pointer to a inline_remap map which indicates how
  1580.    registers used in the DECL_RTL field should be remapped.  If it is zero,
  1581.    no mapping is necessary.
  1582.  
  1583.    FUNCTIONBODY indicates whether the top level block tree corresponds to
  1584.    a function body.  This is identical in meaning to the functionbody
  1585.    argument of poplevel.  */
  1586.  
  1587. static void
  1588. integrate_decl_tree (let, level, map, functionbody)
  1589.      tree let;
  1590.      int level;
  1591.      struct inline_remap *map;
  1592.      int functionbody;
  1593. {
  1594.   tree t, node;
  1595.  
  1596.   pushlevel (0);
  1597.   
  1598.   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
  1599.     {
  1600.       tree d = build_decl (TREE_CODE (t), DECL_NAME (t), TREE_TYPE (t));
  1601.       DECL_SOURCE_LINE (d) = DECL_SOURCE_LINE (t);
  1602.       DECL_SOURCE_FILE (d) = DECL_SOURCE_FILE (t);
  1603.       if (! functionbody && DECL_RTL (t) != 0)
  1604.     {
  1605.       DECL_RTL (d) = copy_rtx_and_substitute (DECL_RTL (t), map);
  1606.       /* Fully instantiate the address with the equivalent form so that the
  1607.          debugging information contains the actual register, instead of the
  1608.          virtual register.   Do this by not passing an insn to
  1609.          subst_constants.  */
  1610.       subst_constants (&DECL_RTL (d), 0, map);
  1611.       apply_change_group ();
  1612.     }
  1613.       else if (DECL_RTL (t))
  1614.     DECL_RTL (d) = copy_rtx (DECL_RTL (t));
  1615.       TREE_EXTERNAL (d) = TREE_EXTERNAL (t);
  1616.       TREE_STATIC (d) = TREE_STATIC (t);
  1617.       TREE_PUBLIC (d) = TREE_PUBLIC (t);
  1618.       TREE_CONSTANT (d) = TREE_CONSTANT (t);
  1619.       TREE_ADDRESSABLE (d) = TREE_ADDRESSABLE (t);
  1620.       TREE_READONLY (d) = TREE_READONLY (t);
  1621.       TREE_SIDE_EFFECTS (d) = TREE_SIDE_EFFECTS (t);
  1622.       /* These args would always appear unused, if not for this.  */
  1623.       TREE_USED (d) = 1;
  1624.       /* Prevent warning for shadowing with these.  */
  1625.       TREE_INLINE (d) = 1;
  1626.       pushdecl (d);
  1627.     }
  1628.  
  1629.   for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
  1630.     integrate_decl_tree (t, level + 1, map, functionbody);
  1631.  
  1632.   node = poplevel (level > 0, 0, level == 0 && functionbody);
  1633.   if (node)
  1634.     TREE_USED (node) = TREE_USED (let);
  1635. }
  1636.  
  1637. /* Create a new copy of an rtx.
  1638.    Recursively copies the operands of the rtx,
  1639.    except for those few rtx codes that are sharable.
  1640.  
  1641.    We always return an rtx that is similar to that incoming rtx, with the
  1642.    exception of possibly changing a REG to a SUBREG or vice versa.  No
  1643.    rtl is ever emitted.
  1644.  
  1645.    Handle constants that need to be placed in the constant pool by
  1646.    calling `force_const_mem'.  */
  1647.  
  1648. rtx
  1649. copy_rtx_and_substitute (orig, map)
  1650.      register rtx orig;
  1651.      struct inline_remap *map;
  1652. {
  1653.   register rtx copy, temp;
  1654.   register int i, j;
  1655.   register RTX_CODE code;
  1656.   register enum machine_mode mode;
  1657.   register char *format_ptr;
  1658.   int regno;
  1659.  
  1660.   if (orig == 0)
  1661.     return 0;
  1662.  
  1663.   code = GET_CODE (orig);
  1664.   mode = GET_MODE (orig);
  1665.  
  1666.   switch (code)
  1667.     {
  1668.     case REG:
  1669.       /* If the stack pointer register shows up, it must be part of
  1670.      stack-adjustments (*not* because we eliminated the frame pointer!).
  1671.      Small hard registers are returned as-is.  Pseudo-registers
  1672.      go through their `reg_map'.  */
  1673.       regno = REGNO (orig);
  1674.       if (regno <= LAST_VIRTUAL_REGISTER)
  1675.     {
  1676.       /* Some hard registers are also mapped,
  1677.          but others are not translated.  */
  1678.       if (map->reg_map[regno] != 0)
  1679.         return map->reg_map[regno];
  1680.  
  1681.       /* If this is the virtual frame pointer, make space in current
  1682.          function's stack frame for the stack frame of the inline function.
  1683.  
  1684.          Copy the address of this area into a pseudo.  Map
  1685.          virtual_stack_vars_rtx to this pseudo and set up a constant
  1686.          equivalence for it to be the address.  This will substitute the
  1687.          address into insns where it can be substituted and use the new
  1688.          pseudo where it can't.  */
  1689.       if (regno == VIRTUAL_STACK_VARS_REGNUM)
  1690.         {
  1691.           rtx loc, seq;
  1692.           int size = DECL_FRAME_SIZE (map->fndecl);
  1693.  
  1694.           start_sequence ();
  1695.           loc = assign_stack_temp (BLKmode, size, 1);
  1696.           loc = XEXP (loc, 0);
  1697. #ifdef FRAME_GROWS_DOWNWARD
  1698.           /* In this case, virtual_stack_vars_rtx points to one byte
  1699.          higher than the top of the frame area.  So compute the offset
  1700.          to one byte higher than our substitute frame.  */
  1701.           loc = plus_constant (loc, size);
  1702. #endif
  1703.           map->reg_map[regno] = force_operand (loc, 0);
  1704.           map->const_equiv_map[regno] = loc;
  1705.           map->const_age_map[regno] = CONST_AGE_PARM;
  1706.  
  1707.           seq = gen_sequence ();
  1708.           end_sequence ();
  1709.           emit_insn_after (seq, map->insns_at_start);
  1710.           return map->reg_map[regno];
  1711.         }
  1712.       else if (regno == VIRTUAL_INCOMING_ARGS_REGNUM)
  1713.         {
  1714.           /* Do the same for a block to contain any arguments referenced
  1715.          in memory. */
  1716.           rtx loc, seq;
  1717.           int size = FUNCTION_ARGS_SIZE (DECL_SAVED_INSNS (map->fndecl));
  1718.  
  1719.           start_sequence ();
  1720.           loc = assign_stack_temp (BLKmode, size, 1);
  1721.           loc = XEXP (loc, 0);
  1722.           map->reg_map[regno] = force_operand (loc, 0);
  1723.           map->const_equiv_map[regno] = loc;
  1724.           map->const_age_map[regno] = CONST_AGE_PARM;
  1725.  
  1726.           seq = gen_sequence ();
  1727.           end_sequence ();
  1728.           emit_insn_after (seq, map->insns_at_start);
  1729.           return map->reg_map[regno];
  1730.         }
  1731.       else if (REG_FUNCTION_VALUE_P (orig))
  1732.         {
  1733.           /* This is a reference to the function return value.  If
  1734.          the function doesn't have a return value, error.  If the
  1735.          mode doesn't agree, make a SUBREG.  */
  1736.           if (map->inline_target == 0)
  1737.         /* Must be unrolling loops or replicating code if we
  1738.            reach here, so return the register unchanged.  */
  1739.         return orig;
  1740.           else if (mode != GET_MODE (map->inline_target))
  1741.         return gen_rtx (SUBREG, mode, map->inline_target, 0);
  1742.           else
  1743.         return map->inline_target;
  1744.         }
  1745.       return orig;
  1746.     }
  1747.       if (map->reg_map[regno] == NULL)
  1748.     {
  1749.       map->reg_map[regno] = gen_reg_rtx (mode);
  1750.       REG_USERVAR_P (map->reg_map[regno]) = REG_USERVAR_P (orig);
  1751.     }
  1752.       return map->reg_map[regno];
  1753.  
  1754.     case SUBREG:
  1755.       copy = copy_rtx_and_substitute (SUBREG_REG (orig), map);
  1756.       /* SUBREG is ordinary, but don't make nested SUBREGs.  */
  1757.       if (GET_CODE (copy) == SUBREG)
  1758.     return gen_rtx (SUBREG, GET_MODE (orig), SUBREG_REG (copy),
  1759.             SUBREG_WORD (orig) + SUBREG_WORD (copy));
  1760.       else
  1761.     return gen_rtx (SUBREG, GET_MODE (orig), copy,
  1762.             SUBREG_WORD (orig));
  1763.  
  1764.     case USE:
  1765.     case CLOBBER:
  1766.       /* USE and CLOBBER are ordinary, but we convert (use (subreg foo))
  1767.      to (use foo).  */
  1768.       copy = copy_rtx_and_substitute (XEXP (orig, 0), map);
  1769.       if (GET_CODE (copy) == SUBREG)
  1770.     copy = SUBREG_REG (copy);
  1771.       return gen_rtx (code, VOIDmode, copy);
  1772.  
  1773.     case CODE_LABEL:
  1774.       return map->label_map[CODE_LABEL_NUMBER (orig)];
  1775.  
  1776.     case LABEL_REF:
  1777.       copy = rtx_alloc (LABEL_REF);
  1778.       PUT_MODE (copy, mode);
  1779.       XEXP (copy, 0) = map->label_map[CODE_LABEL_NUMBER (XEXP (orig, 0))];
  1780.       return copy;
  1781.  
  1782.     case PC:
  1783.     case CC0:
  1784.     case CONST_INT:
  1785.     case SYMBOL_REF:
  1786.       return orig;
  1787.  
  1788.     case CONST_DOUBLE:
  1789.       /* We have to make a new copy of this CONST_DOUBLE because don't want
  1790.      to use the old value of CONST_DOUBLE_MEM.  Also, this may be a
  1791.      duplicate of a CONST_DOUBLE we have already seen.  */
  1792.       {
  1793.     double d;
  1794.     REAL_VALUE_FROM_CONST_DOUBLE (d, orig);
  1795.     return immed_real_const_1 (d, GET_MODE (orig));
  1796.       }
  1797.  
  1798.     case CONST:
  1799.       /* Make new constant pool entry for a constant
  1800.      that was in the pool of the inline function.  */
  1801.       if (RTX_INTEGRATED_P (orig))
  1802.     {
  1803.       /* If this was an address of a constant pool entry that itself
  1804.          had to be placed in the constant pool, it might not be a
  1805.          valid address.  So the recursive call below might turn it
  1806.          into a register.  In that case, it isn't a constant any
  1807.          more, so return it.  This has the potential of changing a
  1808.          MEM into a REG, but we'll assume that it safe.  */
  1809.       temp = copy_rtx_and_substitute (XEXP (orig, 0), map);
  1810.       if (! CONSTANT_P (temp))
  1811.         return temp;
  1812.       return validize_mem (force_const_mem (GET_MODE (orig), temp));
  1813.     }
  1814.       break;
  1815.  
  1816.     case ADDRESS:
  1817.       /* If from constant pool address, make new constant pool entry and
  1818.      return its address.  */
  1819.       if (! RTX_INTEGRATED_P (orig))
  1820.     abort ();
  1821.  
  1822.       temp = force_const_mem (GET_MODE (orig),
  1823.                   copy_rtx_and_substitute (XEXP (orig, 0), map));
  1824.  
  1825.       if (! memory_address_p (GET_MODE (temp), XEXP (temp, 0)))
  1826.     temp = change_address (temp, GET_MODE (temp), XEXP (temp, 0));
  1827.  
  1828.       return XEXP (temp, 0);
  1829.  
  1830.     case ASM_OPERANDS:
  1831.       /* If a single asm insn contains multiple output operands
  1832.      then it contains multiple ASM_OPERANDS rtx's that share operand 3.
  1833.      We must make sure that the copied insn continues to share it.  */
  1834.       if (map->orig_asm_operands_vector == XVEC (orig, 3))
  1835.     {
  1836.       copy = rtx_alloc (ASM_OPERANDS);
  1837.       XSTR (copy, 0) = XSTR (orig, 0);
  1838.       XSTR (copy, 1) = XSTR (orig, 1);
  1839.       XINT (copy, 2) = XINT (orig, 2);
  1840.       XVEC (copy, 3) = map->copy_asm_operands_vector;
  1841.       XVEC (copy, 4) = map->copy_asm_constraints_vector;
  1842.       XSTR (copy, 5) = XSTR (orig, 5);
  1843.       XINT (copy, 6) = XINT (orig, 6);
  1844.       return copy;
  1845.     }
  1846.       break;
  1847.  
  1848.     case CALL:
  1849.       /* This is given special treatment because the first
  1850.      operand of a CALL is a (MEM ...) which may get
  1851.      forced into a register for cse.  This is undesirable
  1852.      if function-address cse isn't wanted or if we won't do cse.  */
  1853. #ifndef NO_FUNCTION_CSE
  1854.       if (! (optimize && ! flag_no_function_cse))
  1855. #endif
  1856.     return gen_rtx (CALL, GET_MODE (orig),
  1857.             gen_rtx (MEM, GET_MODE (XEXP (orig, 0)),
  1858.                  copy_rtx_and_substitute (XEXP (XEXP (orig, 0), 0), map)),
  1859.             copy_rtx_and_substitute (XEXP (orig, 1), map));
  1860.       break;
  1861.  
  1862. #if 0
  1863.       /* Must be ifdefed out for loop unrolling to work.  */
  1864.     case RETURN:
  1865.       abort ();
  1866. #endif
  1867.  
  1868.     case SET:
  1869.       /* If this is setting fp or ap, it means that we have a nonlocal goto.
  1870.      Don't alter that.
  1871.      If the nonlocal goto is into the current function,
  1872.      this will result in unnecessarily bad code, but should work.  */
  1873.       if (SET_DEST (orig) == virtual_stack_vars_rtx
  1874.       || SET_DEST (orig) == virtual_incoming_args_rtx)
  1875.     return gen_rtx (SET, VOIDmode, SET_DEST (orig),
  1876.             copy_rtx_and_substitute (SET_SRC (orig), map));
  1877.       break;
  1878.  
  1879.     case MEM:
  1880.       /* Allocate MEM specially, since we don't want to copy the
  1881.      unchanging bit until GCC can deal with consts which alias
  1882.      non-consts properly.  */
  1883.       copy = rtx_alloc (MEM);
  1884.       PUT_MODE (copy, mode);
  1885.       XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map);
  1886.       copy->in_struct = orig->in_struct;
  1887.       copy->volatil = orig->volatil;
  1888.       return copy;
  1889.     }
  1890.  
  1891.   copy = rtx_alloc (code);
  1892.   PUT_MODE (copy, mode);
  1893.   copy->in_struct = orig->in_struct;
  1894.   copy->volatil = orig->volatil;
  1895.   copy->unchanging = orig->unchanging;
  1896.  
  1897.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  1898.  
  1899.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  1900.     {
  1901.       switch (*format_ptr++)
  1902.     {
  1903.     case '0':
  1904.       break;
  1905.  
  1906.     case 'e':
  1907.       XEXP (copy, i) = copy_rtx_and_substitute (XEXP (orig, i), map);
  1908.       break;
  1909.  
  1910.     case 'u':
  1911.       /* Change any references to old-insns to point to the
  1912.          corresponding copied insns.  */
  1913.       XEXP (copy, i) = map->insn_map[INSN_UID (XEXP (orig, i))];
  1914.       break;
  1915.  
  1916.     case 'E':
  1917.       XVEC (copy, i) = XVEC (orig, i);
  1918.       if (XVEC (orig, i) != NULL && XVECLEN (orig, i) != 0)
  1919.         {
  1920.           XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  1921.           for (j = 0; j < XVECLEN (copy, i); j++)
  1922.         XVECEXP (copy, i, j)
  1923.           = copy_rtx_and_substitute (XVECEXP (orig, i, j), map);
  1924.         }
  1925.       break;
  1926.  
  1927.     case 'i':
  1928.       XINT (copy, i) = XINT (orig, i);
  1929.       break;
  1930.  
  1931.     case 's':
  1932.       XSTR (copy, i) = XSTR (orig, i);
  1933.       break;
  1934.  
  1935.     default:
  1936.       abort ();
  1937.     }
  1938.     }
  1939.  
  1940.   if (code == ASM_OPERANDS && map->orig_asm_operands_vector == 0)
  1941.     {
  1942.       map->orig_asm_operands_vector = XVEC (orig, 3);
  1943.       map->copy_asm_operands_vector = XVEC (copy, 3);
  1944.       map->copy_asm_constraints_vector = XVEC (copy, 4);
  1945.     }
  1946.  
  1947.   return copy;
  1948. }
  1949.  
  1950. /* Substitute known constant values into INSN, if that is valid.  */
  1951.  
  1952. void
  1953. try_constants (insn, map)
  1954.      rtx insn;
  1955.      struct inline_remap *map;
  1956. {
  1957.   int i;
  1958.  
  1959.   map->num_sets = 0;
  1960.   subst_constants (&PATTERN (insn), insn, map);
  1961.  
  1962.   /* Apply the changes if they are valid; otherwise discard them.  */
  1963.   apply_change_group ();
  1964.  
  1965.   /* Show we don't know the value of anything stored or clobbered.  */
  1966.   note_stores (PATTERN (insn), mark_stores);
  1967.   map->last_pc_value = 0;
  1968. #ifdef HAVE_cc0
  1969.   map->last_cc0_value = 0;
  1970. #endif
  1971.  
  1972.   /* Set up any constant equivalences made in this insn.  */
  1973.   for (i = 0; i < map->num_sets; i++)
  1974.     {
  1975.       if (GET_CODE (map->equiv_sets[i].dest) == REG)
  1976.     {
  1977.       int regno = REGNO (map->equiv_sets[i].dest);
  1978.  
  1979.       if (map->const_equiv_map[regno] == 0
  1980.           /* Following clause is a hack to make case work where GNU C++
  1981.          reassigns a variable to make cse work right.  */
  1982.           || ! rtx_equal_p (map->const_equiv_map[regno],
  1983.                 map->equiv_sets[i].equiv))
  1984.         {
  1985.           map->const_equiv_map[regno] = map->equiv_sets[i].equiv;
  1986.           map->const_age_map[regno] = map->const_age;
  1987.         }
  1988.     }
  1989.       else if (map->equiv_sets[i].dest == pc_rtx)
  1990.     map->last_pc_value = map->equiv_sets[i].equiv;
  1991. #ifdef HAVE_cc0
  1992.       else if (map->equiv_sets[i].dest == cc0_rtx)
  1993.     map->last_cc0_value = map->equiv_sets[i].equiv;
  1994. #endif
  1995.     }
  1996. }
  1997.  
  1998. /* Substitute known constants for pseudo regs in the contents of LOC,
  1999.    which are part of INSN.
  2000.    If INSN is zero, the substition should always be done (this is used to
  2001.    update DECL_RTL).
  2002.    These changes are taken out by try_constants if the result is not valid.
  2003.  
  2004.    Note that we are more concerned with determining when the result of a SET
  2005.    is a constant, for further propagation, than actually inserting constants
  2006.    into insns; cse will do the latter task better.
  2007.  
  2008.    This function is also used to adjust address of items previously addressed
  2009.    via the virtual stack variable or virtual incoming arguments registers.  */
  2010.  
  2011. static void
  2012. subst_constants (loc, insn, map)
  2013.      rtx *loc;
  2014.      rtx insn;
  2015.      struct inline_remap *map;
  2016. {
  2017.   rtx x = *loc;
  2018.   register int i;
  2019.   register enum rtx_code code;
  2020.   register char *format_ptr;
  2021.   int num_changes = num_validated_changes ();
  2022.   rtx new = 0;
  2023.   enum machine_mode op0_mode;
  2024.  
  2025.   code = GET_CODE (x);
  2026.  
  2027.   switch (code)
  2028.     {
  2029.     case PC:
  2030.     case CONST_INT:
  2031.     case CONST_DOUBLE:
  2032.     case SYMBOL_REF:
  2033.     case CONST:
  2034.     case LABEL_REF:
  2035.     case ADDRESS:
  2036.       return;
  2037.  
  2038. #ifdef HAVE_cc0
  2039.     case CC0:
  2040.       validate_change (insn, loc, map->last_cc0_value, 1);
  2041.       return;
  2042. #endif
  2043.  
  2044.     case USE:
  2045.     case CLOBBER:
  2046.       /* The only thing we can do with a USE or CLOBBER is possibly do
  2047.      some substitutions in a MEM within it.  */
  2048.       if (GET_CODE (XEXP (x, 0)) == MEM)
  2049.     subst_constants (&XEXP (XEXP (x, 0), 0), insn, map);
  2050.       return;
  2051.  
  2052.     case REG:
  2053.       /* Substitute for parms and known constants.  */
  2054.       {
  2055.     int regno = REGNO (x);
  2056.     if (map->const_equiv_map[regno] != 0
  2057.         && map->const_age_map[regno] >= map->const_age)
  2058.       validate_change (insn, loc, map->const_equiv_map[regno], 1);
  2059.     return;
  2060.       }
  2061.  
  2062.     case SUBREG:
  2063.       /* SUBREG is ordinary, but don't make nested SUBREGs and try to simplify
  2064.      constants.  */
  2065.       {
  2066.     rtx inner = SUBREG_REG (x);
  2067.     rtx new = 0;
  2068.  
  2069.     /* We can't call subst_constants on &SUBREG_REG (x) because any
  2070.        constant or SUBREG wouldn't be valid inside our SUBEG.  Instead,
  2071.        see what is inside, try to form the new SUBREG and see if that is
  2072.        valid.  We handle two cases: extracting a full word in an 
  2073.        integral mode and extracting the low part.  */
  2074.     subst_constants (&inner, 0, map);
  2075.  
  2076.     if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT
  2077.         && GET_MODE_SIZE (GET_MODE (x)) == UNITS_PER_WORD
  2078.         && GET_MODE (SUBREG_REG (x)) != VOIDmode)
  2079.       new = operand_subword (inner, SUBREG_WORD (x), 0,
  2080.                  GET_MODE (SUBREG_REG (x)));
  2081.  
  2082.     if (new == 0 && subreg_lowpart_p (x))
  2083.       new = gen_lowpart_common (GET_MODE (x), inner);
  2084.  
  2085.     if (new)
  2086.       validate_change (insn, loc, new, 1);
  2087.  
  2088.     return;
  2089.       }
  2090.  
  2091.     case MEM:
  2092.       subst_constants (&XEXP (x, 0), insn, map);
  2093.  
  2094.       /* If a memory address got spoiled, change it back.  */
  2095.       if (insn != 0 && num_validated_changes () != num_changes
  2096.       && !memory_address_p (GET_MODE (x), XEXP (x, 0)))
  2097.     cancel_changes (num_changes);
  2098.       return;
  2099.  
  2100.     case SET:
  2101.       {
  2102.     /* Substitute constants in our source, and in any arguments to a
  2103.        complex (e..g, ZERO_EXTRACT) destination, but not in the destination
  2104.        itself.  */
  2105.     rtx *dest_loc = &SET_DEST (x);
  2106.     rtx dest = *dest_loc;
  2107.     rtx src, tem;
  2108.  
  2109.     subst_constants (&SET_SRC (x), insn, map);
  2110.     src = SET_SRC (x);
  2111.  
  2112.     while (GET_CODE (*dest_loc) == ZERO_EXTRACT
  2113.            || GET_CODE (*dest_loc) == SIGN_EXTRACT
  2114.            || GET_CODE (*dest_loc) == SUBREG
  2115.            || GET_CODE (*dest_loc) == STRICT_LOW_PART)
  2116.       {
  2117.         if (GET_CODE (*dest_loc) == ZERO_EXTRACT)
  2118.           {
  2119.         subst_constants (&XEXP (*dest_loc, 1), insn, map);
  2120.         subst_constants (&XEXP (*dest_loc, 2), insn, map);
  2121.           }
  2122.         dest_loc = &XEXP (*dest_loc, 0);
  2123.       }
  2124.  
  2125.     /* Check for the case of DEST a SUBREG, both it and the underlying
  2126.        register are less than one word, and the SUBREG has the wider mode.
  2127.        In the case, we are really setting the underlying register to the
  2128.        source converted to the mode of DEST.  So indicate that.  */
  2129.     if (GET_CODE (dest) == SUBREG
  2130.         && GET_MODE_SIZE (GET_MODE (dest)) <= UNITS_PER_WORD
  2131.         && GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest))) <= UNITS_PER_WORD
  2132.         && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (dest)))
  2133.               <= GET_MODE_SIZE (GET_MODE (dest)))
  2134.         && (tem = gen_lowpart_if_possible (GET_MODE (dest), src)))
  2135.       src = tem, dest = SUBREG_REG (dest);
  2136.  
  2137.     /* If storing a recognizable value save it for later recording.  */
  2138.     if ((map->num_sets < MAX_RECOG_OPERANDS)
  2139.         && (CONSTANT_P (src)
  2140.         || (GET_CODE (src) == PLUS
  2141.             && GET_CODE (XEXP (src, 0)) == REG
  2142.             && REGNO (XEXP (src, 0)) >= FIRST_VIRTUAL_REGISTER
  2143.             && REGNO (XEXP (src, 0)) <= LAST_VIRTUAL_REGISTER
  2144.             && CONSTANT_P (XEXP (src, 1)))
  2145.         || GET_CODE (src) == COMPARE
  2146. #ifdef HAVE_cc0
  2147.         || dest == cc0_rtx
  2148. #endif
  2149.         || (dest == pc_rtx
  2150.             && (src == pc_rtx || GET_CODE (src) == RETURN
  2151.             || GET_CODE (src) == LABEL_REF))))
  2152.       {
  2153.         /* Normally, this copy won't do anything.  But, if SRC is a COMPARE
  2154.            it will cause us to save the COMPARE with any constants
  2155.            substituted, which is what we want for later.  */
  2156.         map->equiv_sets[map->num_sets].equiv = copy_rtx (src);
  2157.         map->equiv_sets[map->num_sets++].dest = dest;
  2158.       }
  2159.  
  2160.     return;
  2161.       }
  2162.     }
  2163.  
  2164.   format_ptr = GET_RTX_FORMAT (code);
  2165.   
  2166.   /* If the first operand is an expression, save its mode for later.  */
  2167.   if (*format_ptr == 'e')
  2168.     op0_mode = GET_MODE (XEXP (x, 0));
  2169.  
  2170.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  2171.     {
  2172.       switch (*format_ptr++)
  2173.     {
  2174.     case '0':
  2175.       break;
  2176.  
  2177.     case 'e':
  2178.       if (XEXP (x, i))
  2179.         subst_constants (&XEXP (x, i), insn, map);
  2180.       break;
  2181.  
  2182.     case 'u':
  2183.     case 'i':
  2184.     case 's':
  2185.       break;
  2186.  
  2187.     case 'E':
  2188.       if (XVEC (x, i) != NULL && XVECLEN (x, i) != 0)
  2189.         {
  2190.           int j;
  2191.           for (j = 0; j < XVECLEN (x, i); j++)
  2192.         subst_constants (&XVECEXP (x, i, j), insn, map);
  2193.         }
  2194.       break;
  2195.  
  2196.     default:
  2197.       abort ();
  2198.     }
  2199.     }
  2200.  
  2201.   /* If this is a commutative operation, move a constant to the second
  2202.      operand unless the second operand is already a CONST_INT.  */
  2203.   if ((GET_RTX_CLASS (code) == 'c' || code == NE || code == EQ)
  2204.       && CONSTANT_P (XEXP (x, 0)) && GET_CODE (XEXP (x, 1)) != CONST_INT)
  2205.     {
  2206.       rtx tem = XEXP (x, 0);
  2207.       validate_change (insn, &XEXP (x, 0), XEXP (x, 1), 1);
  2208.       validate_change (insn, &XEXP (x, 1), tem, 1);
  2209.     }
  2210.  
  2211.   /* Simplify the expression in case we put in some constants.  */
  2212.   switch (GET_RTX_CLASS (code))
  2213.     {
  2214.     case '1':
  2215.       new = simplify_unary_operation (code, GET_MODE (x),
  2216.                       XEXP (x, 0), op0_mode);
  2217.       break;
  2218.  
  2219.     case '<':
  2220.     case '2':
  2221.     case 'c':
  2222.       new = simplify_binary_operation (code, GET_MODE (x),
  2223.                        XEXP (x, 0), XEXP (x, 1));
  2224.       break;
  2225.  
  2226.     case 'b':
  2227.     case '3':
  2228.       new = simplify_ternary_operation (code, GET_MODE (x), op0_mode,
  2229.                     XEXP (x, 0), XEXP (x, 1), XEXP (x, 2));
  2230.       break;
  2231.     }
  2232.  
  2233.   if (new)
  2234.     validate_change (insn, loc, new, 1);
  2235. }
  2236.  
  2237. /* Show that register modified no longer contain known constants.  We are
  2238.    called from note_stores with parts of the new insn.  */
  2239.  
  2240. void
  2241. mark_stores (dest, x)
  2242.      rtx dest;
  2243.      rtx x;
  2244. {
  2245.   if (GET_CODE (dest) == SUBREG)
  2246.     dest = SUBREG_REG (dest);
  2247.  
  2248.   if (GET_CODE (dest) == REG)
  2249.     global_const_equiv_map[REGNO (dest)] = 0;
  2250. }
  2251.  
  2252. /* If any CONST expressions with RTX_INTEGRATED_P are present in the rtx
  2253.    pointed to by PX, they represent constants in the constant pool.
  2254.    Replace these with a new memory reference obtained from force_const_mem.
  2255.    Similarly, ADDRESS expressions with RTX_INTEGRATED_P represent the
  2256.    address of a constant pool entry.  Replace them with the address of
  2257.    a new constant pool entry obtained from force_const_mem.  */
  2258.  
  2259. static void
  2260. restore_constants (px)
  2261.      rtx *px;
  2262. {
  2263.   rtx x = *px;
  2264.   int i, j;
  2265.   char *fmt;
  2266.  
  2267.   if (x == 0)
  2268.     return;
  2269.  
  2270.   if (GET_CODE (x) == CONST_DOUBLE)
  2271.     {
  2272.       /* We have to make a new CONST_DOUBLE to ensure that we account for
  2273.      it correctly.  Using the old CONST_DOUBLE_MEM data is wrong.  */
  2274.       if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
  2275.     {
  2276.       double d;
  2277.       REAL_VALUE_FROM_CONST_DOUBLE (d, x);
  2278.       *px = immed_real_const_1 (d, GET_MODE (x));
  2279.     }
  2280.       else
  2281.     *px = immed_double_const (CONST_DOUBLE_LOW (x), CONST_DOUBLE_HIGH (x),
  2282.                   VOIDmode);
  2283.     }
  2284.   else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == CONST)
  2285.     {
  2286.       restore_constants (&XEXP (x, 0));
  2287.       *px = validize_mem (force_const_mem (GET_MODE (x), XEXP (x, 0)));
  2288.     }
  2289.   else if (RTX_INTEGRATED_P (x) && GET_CODE (x) == ADDRESS)
  2290.     {
  2291.       restore_constants (&XEXP (x, 0));
  2292.       *px = XEXP (force_const_mem (GET_MODE (x), XEXP (x, 0)), 0);
  2293.     }
  2294.   else
  2295.     {
  2296.       fmt = GET_RTX_FORMAT (GET_CODE (x));
  2297.       for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
  2298.     {
  2299.       switch (*fmt++)
  2300.         {
  2301.         case 'E':
  2302.           for (j = 0; j < XVECLEN (x, i); j++)
  2303.         restore_constants (&XVECEXP (x, i, j));
  2304.           break;
  2305.  
  2306.         case 'e':
  2307.           restore_constants (&XEXP (x, i));
  2308.           break;
  2309.         }
  2310.     }
  2311.     }
  2312. }
  2313.  
  2314. /* Output the assembly language code for the function FNDECL
  2315.    from its DECL_SAVED_INSNS.  Used for inline functions that are output
  2316.    at end of compilation instead of where they came in the source.  */
  2317.  
  2318. void
  2319. output_inline_function (fndecl)
  2320.      tree fndecl;
  2321. {
  2322.   rtx head = DECL_SAVED_INSNS (fndecl);
  2323.   rtx last;
  2324.   extern rtx stack_slot_list;
  2325.  
  2326.   temporary_allocation ();
  2327.  
  2328.   current_function_decl = fndecl;
  2329.  
  2330.   /* This call is only used to initialize global variables.  */
  2331.   init_function_start (fndecl, "lossage", 1);
  2332.  
  2333.   /* Redo parameter determinations in case the FUNCTION_...
  2334.      macros took machine-specific actions that need to be redone.  */
  2335.   assign_parms (fndecl, 1);
  2336.  
  2337.   /* Set stack frame size.  */
  2338.   assign_stack_local (BLKmode, DECL_FRAME_SIZE (fndecl), 0);
  2339.  
  2340.   restore_reg_data (FIRST_PARM_INSN (head));
  2341.  
  2342.   stack_slot_list = STACK_SLOT_LIST (head);
  2343.  
  2344.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_ALLOCA)
  2345.     current_function_calls_alloca = 1;
  2346.  
  2347.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_CALLS_SETJMP)
  2348.     current_function_calls_setjmp = 1;
  2349.  
  2350.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_STRUCT)
  2351.     current_function_returns_struct = 1;
  2352.  
  2353.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_PCC_STRUCT)
  2354.     current_function_returns_pcc_struct = 1;
  2355.  
  2356.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_NEEDS_CONTEXT)
  2357.     current_function_needs_context = 1;
  2358.  
  2359.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_HAS_NONLOCAL_LABEL)
  2360.     current_function_has_nonlocal_label = 1;
  2361.  
  2362.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_RETURNS_POINTER)
  2363.     current_function_returns_pointer = 1;
  2364.  
  2365.   if (FUNCTION_FLAGS (head) & FUNCTION_FLAGS_USES_CONST_POOL)
  2366.     current_function_uses_const_pool = 1;
  2367.  
  2368.   current_function_outgoing_args_size = OUTGOING_ARGS_SIZE (head);
  2369.   current_function_pops_args = POPS_ARGS (head);
  2370.  
  2371.   /* There is no need to output a return label again.  */
  2372.   return_label = 0;
  2373.  
  2374.   expand_function_end (DECL_SOURCE_FILE (fndecl), DECL_SOURCE_LINE (fndecl));
  2375.  
  2376.   /* Find last insn and rebuild the constant pool.  */
  2377.   for (last = FIRST_PARM_INSN (head);
  2378.        NEXT_INSN (last); last = NEXT_INSN (last))
  2379.     {
  2380.       if (GET_CODE (last) == INSN || GET_CODE (last) == JUMP_INSN
  2381.       || GET_CODE (last) == CALL_INSN)
  2382.     {
  2383.       restore_constants (&PATTERN (last));
  2384.       restore_constants (®_NOTES (last));
  2385.     }
  2386.     }
  2387.  
  2388.   set_new_first_and_last_insn (FIRST_PARM_INSN (head), last);
  2389.  
  2390.   /* Compile this function all the way down to assembly code.  */
  2391.   rest_of_compilation (fndecl);
  2392.  
  2393.   current_function_decl = 0;
  2394.  
  2395.   permanent_allocation ();
  2396. }
  2397.