OSDN Git Service

2000-08-10 Alexandre Petit-Bianco <apbianco@cygnus.com>
[pf3gnuchains/gcc-fork.git] / gcc / integrate.c
index adf03cc..2cf8813 100644 (file)
@@ -1,5 +1,6 @@
 /* Procedure integration for GNU CC.
-   Copyright (C) 1988, 91, 93-98, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1988, 1991, 1993, 1994, 1995, 1996, 1997, 1998,
+   1999, 2000 Free Software Foundation, Inc.
    Contributed by Michael Tiemann (tiemann@cygnus.com)
 
 This file is part of GNU CC.
@@ -61,24 +62,33 @@ extern struct obstack *function_maybepermanent_obstack;
    ? (1 + (3 * list_length (DECL_ARGUMENTS (DECL))) / 2) \
    : (8 * (8 + list_length (DECL_ARGUMENTS (DECL)))))
 #endif
+
+/* Decide whether a function with a target specific attribute 
+   attached can be inlined.  By default we disallow this.  */
+#ifndef FUNCTION_ATTRIBUTE_INLINABLE_P
+#define FUNCTION_ATTRIBUTE_INLINABLE_P(FNDECL) 0
+#endif
 \f
-static rtvec initialize_for_inline     PROTO((tree));
-static void note_modified_parmregs     PROTO((rtx, rtx, void *));
-static void integrate_parm_decls       PROTO((tree, struct inline_remap *,
-                                              rtvec));
-static tree integrate_decl_tree                PROTO((tree,
-                                              struct inline_remap *));
-static void subst_constants            PROTO((rtx *, rtx,
-                                              struct inline_remap *, int));
-static void set_block_origin_self      PROTO((tree));
-static void set_decl_origin_self       PROTO((tree));
-static void set_block_abstract_flags   PROTO((tree, int));
-static void process_reg_param          PROTO((struct inline_remap *, rtx,
-                                              rtx));
-void set_decl_abstract_flags           PROTO((tree, int));
-static tree copy_and_set_decl_abstract_origin PROTO((tree));
-static rtx expand_inline_function_eh_labelmap PROTO((rtx));
-static void mark_stores                 PROTO((rtx, rtx, void *));
+static rtvec initialize_for_inline     PARAMS ((tree));
+static void note_modified_parmregs     PARAMS ((rtx, rtx, void *));
+static void integrate_parm_decls       PARAMS ((tree, struct inline_remap *,
+                                                rtvec));
+static tree integrate_decl_tree                PARAMS ((tree,
+                                                struct inline_remap *));
+static void subst_constants            PARAMS ((rtx *, rtx,
+                                                struct inline_remap *, int));
+static void set_block_origin_self      PARAMS ((tree));
+static void set_block_abstract_flags   PARAMS ((tree, int));
+static void process_reg_param          PARAMS ((struct inline_remap *, rtx,
+                                                rtx));
+void set_decl_abstract_flags           PARAMS ((tree, int));
+static rtx expand_inline_function_eh_labelmap PARAMS ((rtx));
+static void mark_stores                 PARAMS ((rtx, rtx, void *));
+static void save_parm_insns            PARAMS ((rtx, rtx));
+static void copy_insn_list              PARAMS ((rtx, struct inline_remap *,
+                                                rtx));
+static int compare_blocks               PARAMS ((const PTR, const PTR));
+static int find_block                   PARAMS ((const PTR, const PTR));
 
 /* The maximum number of instructions accepted for inlining a
    function.  Increasing values mean more agressive inlining.
@@ -181,7 +191,8 @@ function_cannot_inline_p (fndecl)
     return N_("inline functions not supported for this return value type");
 
   /* We can't inline functions that return structures of varying size.  */
-  if (int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
+  if (TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE
+      && int_size_in_bytes (TREE_TYPE (TREE_TYPE (fndecl))) < 0)
     return N_("function with varying-size return value cannot be inline");
 
   /* Cannot inline a function with a varying size argument or one that
@@ -190,7 +201,8 @@ function_cannot_inline_p (fndecl)
     {
       if (int_size_in_bytes (TREE_TYPE (parms)) < 0)
        return N_("function with varying-size parameter cannot be inline");
-      else if (TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
+      else if (TREE_CODE (TREE_TYPE (parms)) == UNION_TYPE
+              && TYPE_TRANSPARENT_UNION (TREE_TYPE (parms)))
        return N_("function with transparent unit parameter cannot be inline");
     }
 
@@ -199,7 +211,7 @@ function_cannot_inline_p (fndecl)
       for (ninsns = 0, insn = get_first_nonparm_insn ();
           insn && ninsns < max_insns;
           insn = NEXT_INSN (insn))
-       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
+       if (INSN_P (insn))
          ninsns++;
 
       if (ninsns >= max_insns)
@@ -234,7 +246,14 @@ function_cannot_inline_p (fndecl)
   if (result && GET_CODE (result) == PARALLEL)
     return N_("inline functions not supported for this return value type");
 
-  return 0;
+  /* If the function has a target specific attribute attached to it,
+     then we assume that we should not inline it.  This can be overriden
+     by the target if it defines FUNCTION_ATTRIBUTE_INLINABLE_P.  */
+  if (DECL_MACHINE_ATTRIBUTES (fndecl)
+      && ! FUNCTION_ATTRIBUTE_INLINABLE_P (fndecl))
+    return N_("function with target specific attribute(s) cannot be inlined");
+
+  return NULL;
 }
 \f
 /* Map pseudo reg number into the PARM_DECL for the parm living in the reg.
@@ -296,23 +315,67 @@ initialize_for_inline (fndecl)
   return arg_vector;
 }
 
-/* Copy NODE (as with copy_node).  NODE must be a DECL.  Set the
-   DECL_ABSTRACT_ORIGIN for the new accordinly.  */
+/* Copy NODE (which must be a DECL, but not a PARM_DECL).  The DECL
+   originally was in the FROM_FN, but now it will be in the 
+   TO_FN.  */
 
-static tree
-copy_and_set_decl_abstract_origin (node)
-     tree node;
+tree
+copy_decl_for_inlining (decl, from_fn, to_fn)
+     tree decl;
+     tree from_fn;
+     tree to_fn;
 {
-  tree copy = copy_node (node);
-  if (DECL_ABSTRACT_ORIGIN (copy) != NULL_TREE)
-    /* That means that NODE already had a DECL_ABSTRACT_ORIGIN.  (This
-       situation occurs if we inline a function which itself made
-       calls to inline functions.)  Since DECL_ABSTRACT_ORIGIN is the
-       most distant ancestor, we don't have to do anything here.  */
+  tree copy;
+
+  /* Copy the declaration.  */
+  if (TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == RESULT_DECL)
+    {
+      /* For a parameter, we must make an equivalent VAR_DECL, not a
+        new PARM_DECL.  */
+      copy = build_decl (VAR_DECL, DECL_NAME (decl), TREE_TYPE (decl));
+      TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl);
+      TREE_READONLY (copy) = TREE_READONLY (decl);
+      TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl);
+    }
+  else
+    {
+      copy = copy_node (decl);
+      if (DECL_LANG_SPECIFIC (copy))
+       copy_lang_decl (copy);
+
+      /* TREE_ADDRESSABLE isn't used to indicate that a label's
+        address has been taken; it's for internal bookkeeping in
+        expand_goto_internal.  */
+      if (TREE_CODE (copy) == LABEL_DECL)
+       TREE_ADDRESSABLE (copy) = 0;
+    }
+
+  /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
+     declaration inspired this copy.  */
+  DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
+
+  /* The new variable/label has no RTL, yet.  */
+  DECL_RTL (copy) = NULL_RTX;
+
+  /* These args would always appear unused, if not for this.  */
+  TREE_USED (copy) = 1;
+
+  /* Set the context for the new declaration.  */
+  if (!DECL_CONTEXT (decl))
+    /* Globals stay global.  */
+       ;
+  else if (DECL_CONTEXT (decl) != from_fn)
+    /* Things that weren't in the scope of the function we're inlining
+       from aren't in the scope we're inlining too, either.  */
+    ;
+  else if (TREE_STATIC (decl))
+    /* Function-scoped static variables should say in the original
+       function.  */
     ;
   else
-    /* The most distant ancestor must be NODE.  */
-    DECL_ABSTRACT_ORIGIN (copy) = node;
+    /* Ordinary automatic local variables are now in the scope of the
+       new function.  */
+    DECL_CONTEXT (copy) = to_fn;
 
   return copy;
 }
@@ -380,15 +443,7 @@ save_for_inline_nocopy (fndecl)
      Otherwise, we have to copy its value into a new register and track
      the new register's life.  */
   in_nonparm_insns = 0;
-  for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
-    {
-      if (insn == first_nonparm_insn)
-       in_nonparm_insns = 1;
-
-      if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
-       /* Record what interesting things happen to our parameters.  */
-       note_stores (PATTERN (insn), note_modified_parmregs, NULL);
-    }
+  save_parm_insns (insn, first_nonparm_insn);
 
   /* We have now allocated all that needs to be allocated permanently
      on the rtx obstack.  Set our high-water mark, so that we
@@ -396,15 +451,55 @@ save_for_inline_nocopy (fndecl)
 
   preserve_data ();
 
-  current_function->inl_max_label_num = max_label_num ();
-  current_function->inl_last_parm_insn = current_function->x_last_parm_insn;
-  current_function->original_arg_vector = argvec;
-  current_function->original_decl_initial = DECL_INITIAL (fndecl);
-  DECL_SAVED_INSNS (fndecl) = current_function;
+  cfun->inl_max_label_num = max_label_num ();
+  cfun->inl_last_parm_insn = cfun->x_last_parm_insn;
+  cfun->original_arg_vector = argvec;
+  cfun->original_decl_initial = DECL_INITIAL (fndecl);
+  DECL_SAVED_INSNS (fndecl) = cfun;
 
   /* Clean up.  */
   free (parmdecl_map);
 }
+
+/* Scan the chain of insns to see what happens to our PARM_DECLs.  If a
+   PARM_DECL is used but never modified, we can substitute its rtl directly
+   when expanding inline (and perform constant folding when its incoming
+   value is constant). Otherwise, we have to copy its value into a new
+   register and track the new register's life.  */
+
+static void
+save_parm_insns (insn, first_nonparm_insn)
+    rtx insn;
+    rtx first_nonparm_insn;
+{
+  if (insn == NULL_RTX)
+    return;
+
+  for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn))
+    {
+      if (insn == first_nonparm_insn)
+       in_nonparm_insns = 1;
+
+      if (INSN_P (insn))
+       {
+         /* Record what interesting things happen to our parameters.  */
+         note_stores (PATTERN (insn), note_modified_parmregs, NULL);
+
+         /* If this is a CALL_PLACEHOLDER insn then we need to look into the
+            three attached sequences: normal call, sibling call and tail
+            recursion. */
+         if (GET_CODE (insn) == CALL_INSN
+             && GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
+           {
+             int i;
+
+             for (i = 0; i < 3; i++)
+               save_parm_insns (XEXP (PATTERN (insn), i),
+                                first_nonparm_insn);
+           }
+       }
+    }
+}
 \f
 /* Note whether a parameter is modified or not.  */
 
@@ -473,6 +568,35 @@ expand_inline_function_eh_labelmap (label)
   return get_label_from_map (eif_eh_map, index);
 }
 
+/* Compare two BLOCKs for qsort.  The key we sort on is the
+   BLOCK_ABSTRACT_ORIGIN of the blocks.  */
+
+static int
+compare_blocks (v1, v2)
+     const PTR v1;
+     const PTR v2;
+{
+  tree b1 = *((const tree *) v1);
+  tree b2 = *((const tree *) v2);
+
+  return ((char *) BLOCK_ABSTRACT_ORIGIN (b1) 
+         - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
+}
+
+/* Compare two BLOCKs for bsearch.  The first pointer corresponds to
+   an original block; the second to a remapped equivalent.  */
+
+static int
+find_block (v1, v2)
+     const PTR v1;
+     const PTR v2;
+{
+  const union tree_node *b1 = (const union tree_node *) v1;
+  tree b2 = *((const tree *) v2);
+
+  return ((const char *) b1 - (char *) BLOCK_ABSTRACT_ORIGIN (b2));
+}
+
 /* Integrate the procedure defined by FNDECL.  Note that this function
    may wind up calling itself.  Since the static variables are not
    reentrant, we do not assign them until after the possibility
@@ -504,13 +628,11 @@ expand_inline_function (fndecl, parms, target, ignore, type,
               : parm_insns);
   tree *arg_trees;
   rtx *arg_vals;
-  rtx insn;
   int max_regno;
   register int i;
   int min_labelno = inl_f->emit->x_first_label_num;
   int max_labelno = inl_f->inl_max_label_num;
   int nargs;
-  rtx local_return_label = 0;
   rtx loc;
   rtx stack_save = 0;
   rtx temp;
@@ -533,6 +655,9 @@ expand_inline_function (fndecl, parms, target, ignore, type,
 
   nargs = list_length (DECL_ARGUMENTS (fndecl));
 
+  if (cfun->preferred_stack_boundary < inl_f->preferred_stack_boundary)
+    cfun->preferred_stack_boundary = inl_f->preferred_stack_boundary;
+
   /* Check that the parms type match and that sufficient arguments were
      passed.  Since the appropriate conversions or default promotions have
      already been applied, the machine modes should match exactly.  */
@@ -646,8 +771,7 @@ expand_inline_function (fndecl, parms, target, ignore, type,
       if (arg_vals[i] != 0 && GET_CODE (arg_vals[i]) == REG
          && POINTER_TYPE_P (TREE_TYPE (formal)))
        mark_reg_pointer (arg_vals[i],
-                         (TYPE_ALIGN (TREE_TYPE (TREE_TYPE (formal)))
-                          / BITS_PER_UNIT));
+                         TYPE_ALIGN (TREE_TYPE (TREE_TYPE (formal))));
     }
        
   /* Allocate the structures we use to remap things.  */
@@ -655,6 +779,7 @@ expand_inline_function (fndecl, parms, target, ignore, type,
   map = (struct inline_remap *) xmalloc (sizeof (struct inline_remap));
   map->fndecl = fndecl;
 
+  VARRAY_TREE_INIT (map->block_map, 10, "block_map");
   map->reg_map = (rtx *) xcalloc (max_regno, sizeof (rtx));
 
   /* We used to use alloca here, but the size of what it would try to
@@ -725,11 +850,6 @@ expand_inline_function (fndecl, parms, target, ignore, type,
        RTX_INTEGRATED_P (note) = 1;
     }
 
-  /* Figure out where the blocks are if we're going to have to insert
-     new BLOCKs into the existing block tree.  */
-  if (current_function->x_whole_function_mode_p)
-    find_loop_tree_blocks ();
-
   /* Process each argument.  For each, set up things so that the function's
      reference to the argument will refer to the argument being passed.
      We only replace REG with REG here.  Any simplifications are done
@@ -974,15 +1094,32 @@ expand_inline_function (fndecl, parms, target, ignore, type,
   else
     abort ();
 
-  /* Make a fresh binding contour that we can easily remove.  Do this after
-     expanding our arguments so cleanups are properly scoped.  */
-  expand_start_bindings (0);
-
   /* Initialize label_map.  get_label_from_map will actually make
      the labels.  */
   bzero ((char *) &map->label_map [min_labelno],
         (max_labelno - min_labelno) * sizeof (rtx));
 
+  /* Make copies of the decls of the symbols in the inline function, so that
+     the copies of the variables get declared in the current function.  Set
+     up things so that lookup_static_chain knows that to interpret registers
+     in SAVE_EXPRs for TYPE_SIZEs as local.  */
+  inline_function_decl = fndecl;
+  integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
+  block = integrate_decl_tree (inl_f->original_decl_initial, map);
+  BLOCK_ABSTRACT_ORIGIN (block) = DECL_ORIGIN (fndecl);
+  inline_function_decl = 0;
+
+  /* Make a fresh binding contour that we can easily remove.  Do this after
+     expanding our arguments so cleanups are properly scoped.  */
+  expand_start_bindings_and_block (0, block);
+
+  /* Sort the block-map so that it will be easy to find remapped
+     blocks later.  */
+  qsort (&VARRAY_TREE (map->block_map, 0), 
+        map->block_map->elements_used,
+        sizeof (tree),
+        compare_blocks);
+
   /* Perform postincrements before actually calling the function.  */
   emit_queue ();
 
@@ -1000,7 +1137,100 @@ expand_inline_function (fndecl, parms, target, ignore, type,
   if (inl_f->calls_alloca)
     emit_stack_save (SAVE_BLOCK, &stack_save, NULL_RTX);
 
-  /* Now copy the insns one by one.  Do this in two passes, first the insns and
+  /* Now copy the insns one by one.  */
+  copy_insn_list (insns, map, static_chain_value);
+
+  /* Restore the stack pointer if we saved it above.  */
+  if (inl_f->calls_alloca)
+    emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
+
+  if (! cfun->x_whole_function_mode_p)
+    /* In statement-at-a-time mode, we just tell the front-end to add
+       this block to the list of blocks at this binding level.  We
+       can't do it the way it's done for function-at-a-time mode the
+       superblocks have not been created yet.  */
+    insert_block (block);
+  else
+    {
+      BLOCK_CHAIN (block) 
+       = BLOCK_CHAIN (DECL_INITIAL (current_function_decl));
+      BLOCK_CHAIN (DECL_INITIAL (current_function_decl)) = block;
+    }
+
+  /* End the scope containing the copied formal parameter variables
+     and copied LABEL_DECLs.  We pass NULL_TREE for the variables list
+     here so that expand_end_bindings will not check for unused
+     variables.  That's already been checked for when the inlined
+     function was defined.  */
+  expand_end_bindings (NULL_TREE, 1, 1);
+
+  /* Must mark the line number note after inlined functions as a repeat, so
+     that the test coverage code can avoid counting the call twice.  This
+     just tells the code to ignore the immediately following line note, since
+     there already exists a copy of this note before the expanded inline call.
+     This line number note is still needed for debugging though, so we can't
+     delete it.  */
+  if (flag_test_coverage)
+    emit_note (0, NOTE_INSN_REPEATED_LINE_NUMBER);
+
+  emit_line_note (input_filename, lineno);
+
+  /* If the function returns a BLKmode object in a register, copy it
+     out of the temp register into a BLKmode memory object. */
+  if (target 
+      && TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
+      && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
+    target = copy_blkmode_from_reg (0, target, TREE_TYPE (TREE_TYPE (fndecl)));
+  
+  if (structure_value_addr)
+    {
+      target = gen_rtx_MEM (TYPE_MODE (type),
+                           memory_address (TYPE_MODE (type),
+                                           structure_value_addr));
+      set_mem_attributes (target, type, 1);
+    }
+
+  /* Make sure we free the things we explicitly allocated with xmalloc.  */
+  if (real_label_map)
+    free (real_label_map);
+  VARRAY_FREE (map->const_equiv_varray);
+  free (map->reg_map);
+  VARRAY_FREE (map->block_map);
+  free (map->insn_map);
+  free (map);
+  free (arg_vals);
+  free (arg_trees);
+
+  inlining = inlining_previous;
+
+  return target;
+}
+
+/* Make copies of each insn in the given list using the mapping
+   computed in expand_inline_function. This function may call itself for
+   insns containing sequences.
+   
+   Copying is done in two passes, first the insns and then their REG_NOTES,
+   just like save_for_inline.
+
+   If static_chain_value is non-zero, it represents the context-pointer
+   register for the function. */
+
+static void
+copy_insn_list (insns, map, static_chain_value)
+    rtx insns;
+    struct inline_remap *map;
+    rtx static_chain_value;
+{
+  register int i;
+  rtx insn;
+  rtx temp;
+  rtx local_return_label = NULL_RTX;
+#ifdef HAVE_cc0
+  rtx cc0_insn = 0;
+#endif
+
+  /* Copy the insns one by one.  Do this in two passes, first the insns and
      then their REG_NOTES, just like save_for_inline.  */
 
   /* This loop is very similar to the loop in copy_loop_body in unroll.c.  */
@@ -1171,7 +1401,7 @@ expand_inline_function (fndecl, parms, target, ignore, type,
 
          /* If this used to be a conditional jump insn but whose branch
             direction is now know, we must do something special.  */
-         if (condjump_p (insn) && ! simplejump_p (insn) && map->last_pc_value)
+         if (any_condjump_p (insn) && onlyjump_p (insn) && map->last_pc_value)
            {
 #ifdef HAVE_cc0
              /* If the previous insn set cc0 for us, delete it.  */
@@ -1194,11 +1424,50 @@ expand_inline_function (fndecl, parms, target, ignore, type,
          break;
 
        case CALL_INSN:
+         /* If this is a CALL_PLACEHOLDER insn then we need to copy the
+            three attached sequences: normal call, sibling call and tail
+            recursion. */
+         if (GET_CODE (PATTERN (insn)) == CALL_PLACEHOLDER)
+           {
+             rtx sequence[3];
+             rtx tail_label;
+
+             for (i = 0; i < 3; i++)
+               {
+                 rtx seq;
+                 
+                 sequence[i] = NULL_RTX;
+                 seq = XEXP (PATTERN (insn), i);
+                 if (seq)
+                   {
+                     start_sequence ();
+                     copy_insn_list (seq, map, static_chain_value);
+                     sequence[i] = get_insns ();
+                     end_sequence ();
+                   }
+               }
+
+             /* Find the new tail recursion label.  
+                It will already be substituted into sequence[2].  */
+             tail_label = copy_rtx_and_substitute (XEXP (PATTERN (insn), 3),
+                                                   map, 0);
+
+             copy = emit_call_insn (gen_rtx_CALL_PLACEHOLDER (VOIDmode, 
+                                                       sequence[0],
+                                                       sequence[1],
+                                                       sequence[2],
+                                                       tail_label));
+             break;
+           }
+
          pattern = copy_rtx_and_substitute (PATTERN (insn), map, 0);
          copy = emit_call_insn (pattern);
 
+         SIBLING_CALL_P (copy) = SIBLING_CALL_P (insn);
+
          /* Because the USAGE information potentially contains objects other
             than hard registers, we need to copy it.  */
+
          CALL_INSN_FUNCTION_USAGE (copy)
            = copy_rtx_and_substitute (CALL_INSN_FUNCTION_USAGE (insn),
                                       map, 0);
@@ -1210,7 +1479,7 @@ expand_inline_function (fndecl, parms, target, ignore, type,
 #endif
          try_constants (copy, map);
 
-         /* Be lazy and assume CALL_INSNs clobber all hard registers.  */
+             /* Be lazy and assume CALL_INSNs clobber all hard registers.  */
          for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
            VARRAY_CONST_EQUIV (map->const_equiv_varray, i).rtx = 0;
          break;
@@ -1227,14 +1496,23 @@ expand_inline_function (fndecl, parms, target, ignore, type,
          break;
 
        case NOTE:
-         /* It is important to discard function-end and function-beg notes,
-            so we have only one of each in the current function.
-            Also, NOTE_INSN_DELETED notes aren't useful (save_for_inline
+         /* NOTE_INSN_FUNCTION_END and NOTE_INSN_FUNCTION_BEG are 
+            discarded because it is important to have only one of 
+            each in the current function.
+
+            NOTE_INSN_DELETED notes aren't useful (save_for_inline
             deleted these in the copy used for continuing compilation,
-            not the copy used for inlining).  */
+            not the copy used for inlining).
+
+            NOTE_INSN_BASIC_BLOCK is discarded because the saved bb
+            pointer (which will soon be dangling) confuses flow's
+            attempts to preserve bb structures during the compilation
+            of a function.  */
+
          if (NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_END
              && NOTE_LINE_NUMBER (insn) != NOTE_INSN_FUNCTION_BEG
-             && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED)
+             && NOTE_LINE_NUMBER (insn) != NOTE_INSN_DELETED
+             && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BASIC_BLOCK)
            {
              copy = emit_note (NOTE_SOURCE_FILE (insn),
                                NOTE_LINE_NUMBER (insn));
@@ -1260,6 +1538,25 @@ expand_inline_function (fndecl, parms, target, ignore, type,
                     region.  */
                  NOTE_EH_HANDLER (copy) = CODE_LABEL_NUMBER (label);
                }
+             else if (copy
+                      && (NOTE_LINE_NUMBER (copy) == NOTE_INSN_BLOCK_BEG
+                          || NOTE_LINE_NUMBER (copy) == NOTE_INSN_BLOCK_END)
+                      && NOTE_BLOCK (insn))
+               {
+                 tree *mapped_block_p;
+
+                 mapped_block_p
+                   = (tree *) bsearch (NOTE_BLOCK (insn), 
+                                       &VARRAY_TREE (map->block_map, 0),
+                                       map->block_map->elements_used,
+                                       sizeof (tree),
+                                       find_block);
+                 
+                 if (!mapped_block_p)
+                   abort ();
+                 else
+                   NOTE_BLOCK (copy) = *mapped_block_p;
+               }
            }
          else
            copy = 0;
@@ -1280,94 +1577,29 @@ expand_inline_function (fndecl, parms, target, ignore, type,
      are valid across the entire function.  */
   map->const_age++;
   for (insn = insns; insn; insn = NEXT_INSN (insn))
-    if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
+    if (INSN_P (insn)
        && map->insn_map[INSN_UID (insn)]
        && REG_NOTES (insn))
       {
-       rtx tem = copy_rtx_and_substitute (REG_NOTES (insn), map, 0);
+       rtx next, note = copy_rtx_and_substitute (REG_NOTES (insn), map, 0);
 
        /* We must also do subst_constants, in case one of our parameters
           has const type and constant value.  */
-       subst_constants (&tem, NULL_RTX, map, 0);
+       subst_constants (&note, NULL_RTX, map, 0);
        apply_change_group ();
-       REG_NOTES (map->insn_map[INSN_UID (insn)]) = tem;
+       REG_NOTES (map->insn_map[INSN_UID (insn)]) = note;
+
+       /* Finally, delete any REG_LABEL notes from the chain.  */                
+       for (; note; note = next)
+         {
+           next = XEXP (note, 1);
+           if (REG_NOTE_KIND (note) == REG_LABEL)
+             remove_note (map->insn_map[INSN_UID (insn)], note);
+         }
       }
 
   if (local_return_label)
     emit_label (local_return_label);
-
-  /* Restore the stack pointer if we saved it above.  */
-  if (inl_f->calls_alloca)
-    emit_stack_restore (SAVE_BLOCK, stack_save, NULL_RTX);
-
-  /* Make copies of the decls of the symbols in the inline function, so that
-     the copies of the variables get declared in the current function.  Set
-     up things so that lookup_static_chain knows that to interpret registers
-     in SAVE_EXPRs for TYPE_SIZEs as local.  */
-
-  inline_function_decl = fndecl;
-  integrate_parm_decls (DECL_ARGUMENTS (fndecl), map, arg_vector);
-  block = integrate_decl_tree (inl_f->original_decl_initial, map);
-  BLOCK_ABSTRACT_ORIGIN (block) = (DECL_ABSTRACT_ORIGIN (fndecl) == NULL
-                                  ? fndecl : DECL_ABSTRACT_ORIGIN (fndecl));
-  inline_function_decl = 0;
-
-  if (current_function->x_whole_function_mode_p)
-    /* Insert the block into the already existing block-tree.  */
-    retrofit_block (block, map->insns_at_start);
-  else
-    /* In statement-at-a-time mode, we just tell the front-end to add
-       this block to the list of blocks at this binding level.  We
-       can't do it the way it's done for function-at-a-time mode the
-       superblocks have not been created yet.  */
-    insert_block (block);
-
-  /* End the scope containing the copied formal parameter variables
-     and copied LABEL_DECLs.  We pass NULL_TREE for the variables list
-     here so that expand_end_bindings will not check for unused
-     variables.  That's already been checked for when the inlined
-     function was defined.  */
-  expand_end_bindings (NULL_TREE, 1, 1);
-
-  /* Must mark the line number note after inlined functions as a repeat, so
-     that the test coverage code can avoid counting the call twice.  This
-     just tells the code to ignore the immediately following line note, since
-     there already exists a copy of this note before the expanded inline call.
-     This line number note is still needed for debugging though, so we can't
-     delete it.  */
-  if (flag_test_coverage)
-    emit_note (0, NOTE_REPEATED_LINE_NUMBER);
-
-  emit_line_note (input_filename, lineno);
-
-  /* If the function returns a BLKmode object in a register, copy it
-     out of the temp register into a BLKmode memory object. */
-  if (target 
-      && TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == BLKmode
-      && ! aggregate_value_p (TREE_TYPE (TREE_TYPE (fndecl))))
-    target = copy_blkmode_from_reg (0, target, TREE_TYPE (TREE_TYPE (fndecl)));
-  
-  if (structure_value_addr)
-    {
-      target = gen_rtx_MEM (TYPE_MODE (type),
-                           memory_address (TYPE_MODE (type),
-                                           structure_value_addr));
-      MEM_SET_IN_STRUCT_P (target, 1);
-    }
-
-  /* Make sure we free the things we explicitly allocated with xmalloc.  */
-  if (real_label_map)
-    free (real_label_map);
-  VARRAY_FREE (map->const_equiv_varray);
-  free (map->reg_map);
-  free (map->insn_map);
-  free (map);
-  free (arg_vals);
-  free (arg_trees);
-
-  inlining = inlining_previous;
-
-  return target;
 }
 \f
 /* Given a chain of PARM_DECLs, ARGS, copy each decl into a VAR_DECL,
@@ -1384,20 +1616,14 @@ integrate_parm_decls (args, map, arg_vector)
 
   for (tail = args, i = 0; tail; tail = TREE_CHAIN (tail), i++)
     {
-      register tree decl = build_decl (VAR_DECL, DECL_NAME (tail),
-                                      TREE_TYPE (tail));
+      tree decl = copy_decl_for_inlining (tail, map->fndecl,
+                                         current_function_decl);
       rtx new_decl_rtl
        = copy_rtx_and_substitute (RTVEC_ELT (arg_vector, i), map, 1);
 
-      DECL_ARG_TYPE (decl) = DECL_ARG_TYPE (tail);
       /* We really should be setting DECL_INCOMING_RTL to something reasonable
         here, but that's going to require some more work.  */
       /* DECL_INCOMING_RTL (decl) = ?; */
-      /* These args would always appear unused, if not for this.  */
-      TREE_USED (decl) = 1;
-      /* Prevent warning for shadowing with these.  */
-      DECL_ABSTRACT_ORIGIN (decl) = DECL_ORIGIN (tail);
-      DECL_CONTEXT (decl) = current_function_decl;
       /* Fully instantiate the address with the equivalent form so that the
         debugging information contains the actual register, instead of the
         virtual register.   Do this by not passing an insn to
@@ -1425,6 +1651,7 @@ integrate_decl_tree (let, map)
   tree *next;
 
   new_block = make_node (BLOCK);
+  VARRAY_PUSH_TREE (map->block_map, new_block);
   next = &BLOCK_VARS (new_block);
 
   for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
@@ -1433,7 +1660,7 @@ integrate_decl_tree (let, map)
 
       push_obstacks_nochange ();
       saveable_allocation ();
-      d = copy_and_set_decl_abstract_origin (t);
+      d = copy_decl_for_inlining (t, map->fndecl, current_function_decl);
       pop_obstacks ();
 
       if (DECL_RTL (t) != 0)
@@ -1447,29 +1674,6 @@ integrate_decl_tree (let, map)
          subst_constants (&DECL_RTL (d), NULL_RTX, map, 1);
          apply_change_group ();
        }
-      /* These args would always appear unused, if not for this.  */
-      TREE_USED (d) = 1;
-
-      if (DECL_LANG_SPECIFIC (d))
-       copy_lang_decl (d);
-
-      /* Set the context for the new declaration.  */
-      if (!DECL_CONTEXT (t))
-       /* Globals stay global.  */
-       ;
-      else if (DECL_CONTEXT (t) != map->fndecl)
-       /* Things that weren't in the scope of the function we're
-          inlining from aren't in the scope we're inlining too,
-          either.  */
-       ;
-      else if (TREE_STATIC (t))
-       /* Function-scoped static variables should say in the original
-          function.  */
-       ;
-      else
-       /* Ordinary automatic local variables are now in the scope of
-          the new function.  */
-       DECL_CONTEXT (d) = current_function_decl;
 
       /* Add this declaration to the list of variables in the new
         block.  */
@@ -1554,13 +1758,17 @@ copy_rtx_and_substitute (orig, map, for_lhs)
            {
              rtx loc, seq;
              int size = get_func_frame_size (DECL_SAVED_INSNS (map->fndecl));
-
 #ifdef FRAME_GROWS_DOWNWARD
+             int alignment
+               = (DECL_SAVED_INSNS (map->fndecl)->stack_alignment_needed
+                  / BITS_PER_UNIT);
+
              /* In this case, virtual_stack_vars_rtx points to one byte
                 higher than the top of the frame area.  So make sure we
                 allocate a big enough chunk to keep the frame pointer
                 aligned like a real one.  */
-             size = CEIL_ROUND (size, BIGGEST_ALIGNMENT / BITS_PER_UNIT);
+             if (alignment)
+               size = CEIL_ROUND (size, alignment);
 #endif
              start_sequence ();
              loc = assign_stack_temp (BLKmode, size, 1);
@@ -1575,8 +1783,7 @@ copy_rtx_and_substitute (orig, map, for_lhs)
                = force_reg (Pmode, force_operand (loc, NULL_RTX));
 
 #ifdef STACK_BOUNDARY
-             mark_reg_pointer (map->reg_map[regno],
-                               STACK_BOUNDARY / BITS_PER_UNIT);
+             mark_reg_pointer (map->reg_map[regno], STACK_BOUNDARY);
 #endif
 
              SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
@@ -1609,8 +1816,7 @@ copy_rtx_and_substitute (orig, map, for_lhs)
                = force_reg (Pmode, force_operand (loc, NULL_RTX));
 
 #ifdef STACK_BOUNDARY
-             mark_reg_pointer (map->reg_map[regno],
-                               STACK_BOUNDARY / BITS_PER_UNIT);
+             mark_reg_pointer (map->reg_map[regno], STACK_BOUNDARY);
 #endif
 
              SET_CONST_EQUIV_DATA (map, temp, loc, CONST_AGE_PARM);
@@ -1714,6 +1920,13 @@ copy_rtx_and_substitute (orig, map, for_lhs)
        = LABEL_PRESERVE_P (orig);
       return get_label_from_map (map, CODE_LABEL_NUMBER (orig));
 
+    /* We need to handle "deleted" labels that appear in the DECL_RTL
+       of a LABEL_DECL.  */
+    case NOTE:
+      if (NOTE_LINE_NUMBER (orig) == NOTE_INSN_DELETED_LABEL)
+       return map->insn_map[INSN_UID (orig)];
+      break;
+
     case LABEL_REF:
       copy
        = gen_rtx_LABEL_REF
@@ -1751,7 +1964,7 @@ copy_rtx_and_substitute (orig, map, for_lhs)
         remapped label.  Otherwise, symbols are returned unchanged.  */
       if (CONSTANT_POOL_ADDRESS_P (orig))
        {
-         struct function *f = inlining ? inlining : current_function;
+         struct function *f = inlining ? inlining : cfun;
          rtx constant = get_pool_constant_for_function (f, orig);
          enum machine_mode const_mode = get_pool_mode_for_function (f, orig);
          if (inlining)
@@ -1926,8 +2139,6 @@ copy_rtx_and_substitute (orig, map, for_lhs)
       PUT_MODE (copy, mode);
       XEXP (copy, 0) = copy_rtx_and_substitute (XEXP (orig, 0), map, 0);
       MEM_COPY_ATTRIBUTES (copy, orig);
-      MEM_ALIAS_SET (copy) = MEM_ALIAS_SET (orig);
-      RTX_UNCHANGING_P (copy) = RTX_UNCHANGING_P (orig);
       return copy;
       
     default:
@@ -2272,6 +2483,7 @@ subst_constants (loc, insn, map, memonly)
        case 'i':
        case 's':
        case 'w':
+       case 'n':
        case 't':
          break;
 
@@ -2319,9 +2531,16 @@ subst_constants (loc, insn, map, memonly)
                                               XEXP (x, 0), XEXP (x, 1));
 #ifdef FLOAT_STORE_FLAG_VALUE
          if (new != 0 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
-         new = ((new == const0_rtx) ? CONST0_RTX (GET_MODE (x))
-                : CONST_DOUBLE_FROM_REAL_VALUE (FLOAT_STORE_FLAG_VALUE,
-                                                GET_MODE (x)));
+           {
+             enum machine_mode mode = GET_MODE (x);
+             if (new == const0_rtx)
+               new = CONST0_RTX (mode);
+             else
+               {
+                 REAL_VALUE_TYPE val = FLOAT_STORE_FLAG_VALUE (mode);
+                 new = CONST_DOUBLE_FROM_REAL_VALUE (val, mode);
+               }
+           }
 #endif
          break;
       }
@@ -2350,7 +2569,7 @@ subst_constants (loc, insn, map, memonly)
 /* Show that register modified no longer contain known constants.  We are
    called from note_stores with parts of the new insn.  */
 
-void
+static void
 mark_stores (dest, x, data)
      rtx dest;
      rtx x ATTRIBUTE_UNUSED;
@@ -2372,15 +2591,16 @@ mark_stores (dest, x, data)
 
   if (regno >= 0)
     {
-      int last_reg = (regno >= FIRST_PSEUDO_REGISTER ? regno
-                     : regno + HARD_REGNO_NREGS (regno, mode) - 1);
-      int i;
+      unsigned int uregno = regno;
+      unsigned int last_reg = (uregno >= FIRST_PSEUDO_REGISTER ? uregno
+                             : uregno + HARD_REGNO_NREGS (uregno, mode) - 1);
+      unsigned int i;
 
       /* Ignore virtual stack var or virtual arg register since those
         are handled separately.  */
-      if (regno != VIRTUAL_INCOMING_ARGS_REGNUM
-         && regno != VIRTUAL_STACK_VARS_REGNUM)
-       for (i = regno; i <= last_reg; i++)
+      if (uregno != VIRTUAL_INCOMING_ARGS_REGNUM
+         && uregno != VIRTUAL_STACK_VARS_REGNUM)
+       for (i = uregno; i <= last_reg; i++)
          if ((size_t) i < VARRAY_SIZE (global_const_equiv_varray))
            VARRAY_CONST_EQUIV (global_const_equiv_varray, i).rtx = 0;
     }
@@ -2435,7 +2655,7 @@ set_block_origin_self (stmt)
    set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
    point to themselves.  */
 
-static void
+void
 set_decl_origin_self (decl)
      register tree decl;
 {
@@ -2513,10 +2733,10 @@ void
 output_inline_function (fndecl)
      tree fndecl;
 {
-  struct function *curf = current_function;
+  struct function *old_cfun = cfun;
   struct function *f = DECL_SAVED_INSNS (fndecl);
 
-  current_function = f;
+  cfun = f;
   current_function_decl = fndecl;
   clear_emit_caches ();
 
@@ -2526,27 +2746,16 @@ output_inline_function (fndecl)
 
   set_new_last_label_num (f->inl_max_label_num);
 
-  /* We must have already output DWARF debugging information for the
-     original (abstract) inline function declaration/definition, so
-     we want to make sure that the debugging information we generate
-     for this special instance of the inline function refers back to
-     the information we already generated.  To make sure that happens,
-     we simply have to set the DECL_ABSTRACT_ORIGIN for the function
-     node (and for all of the local ..._DECL nodes which are its children)
-     so that they all point to themselves.  */
-
-  set_decl_origin_self (fndecl);
-
   /* We're not deferring this any longer.  */
   DECL_DEFER_OUTPUT (fndecl) = 0;
 
+  /* Compile this function all the way down to assembly code.  */
+  rest_of_compilation (fndecl);
+
   /* We can't inline this anymore.  */
   f->inlinable = 0;
   DECL_INLINE (fndecl) = 0;
 
-  /* Compile this function all the way down to assembly code.  */
-  rest_of_compilation (fndecl);
-
-  current_function = curf;
-  current_function_decl = curf ? curf->decl : 0;
+  cfun = old_cfun;
+  current_function_decl = old_cfun ? old_cfun->decl : 0;
 }