]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/df-scan.c
backport: As described in http://gcc.gnu.org/ml/gcc/2012-08/msg00015.html...
[thirdparty/gcc.git] / gcc / df-scan.c
index 7179051f0b85684aa4973749e46d3a45257166a0..55492fa81417deddd14a364de6ec9f62f720e158 100644 (file)
@@ -1,6 +1,6 @@
 /* Scanning of rtl for dataflow analysis.
    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-   2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
    Originally contributed by Michael P. Hayes
              (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
    Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
@@ -32,19 +32,17 @@ along with GCC; see the file COPYING3.  If not see
 #include "recog.h"
 #include "function.h"
 #include "regs.h"
-#include "output.h"
 #include "alloc-pool.h"
 #include "flags.h"
 #include "hard-reg-set.h"
 #include "basic-block.h"
 #include "sbitmap.h"
 #include "bitmap.h"
-#include "timevar.h"
+#include "dumpfile.h"
 #include "tree.h"
 #include "target.h"
 #include "target-def.h"
 #include "df.h"
-#include "tree-pass.h"
 #include "emit-rtl.h"  /* FIXME: Can go away once crtl is moved to rtl.h.  */
 
 DEF_VEC_P(df_ref);
@@ -111,7 +109,7 @@ static void df_ref_record (enum df_ref_class, struct df_collection_rec *,
                           rtx, rtx *,
                           basic_block, struct df_insn_info *,
                           enum df_ref_type, int ref_flags);
-static void df_def_record_1 (struct df_collection_rec *, rtx,
+static void df_def_record_1 (struct df_collection_rec *, rtx *,
                             basic_block, struct df_insn_info *,
                             int ref_flags);
 static void df_defs_record (struct df_collection_rec *, rtx,
@@ -318,7 +316,7 @@ df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
 {
   struct df_scan_problem_data *problem_data;
   unsigned int insn_num = get_max_uid () + 1;
-  unsigned int block_size = 400;
+  unsigned int block_size = 512;
   basic_block bb;
 
   /* Given the number of pools, this is really faster than tearing
@@ -347,7 +345,7 @@ df_scan_alloc (bitmap all_blocks ATTRIBUTE_UNUSED)
                         sizeof (struct df_reg_info), block_size);
   problem_data->mw_reg_pool
     = create_alloc_pool ("df_scan mw_reg",
-                        sizeof (struct df_mw_hardreg), block_size);
+                        sizeof (struct df_mw_hardreg), block_size / 16);
 
   bitmap_obstack_initialize (&problem_data->reg_bitmaps);
   bitmap_obstack_initialize (&problem_data->insn_bitmaps);
@@ -2794,8 +2792,9 @@ df_ref_create_structure (enum df_ref_class cl,
   DF_REF_FLAGS_CLEAR (this_ref, DF_HARD_REG_LIVE);
 
   /* See if this ref needs to have DF_HARD_REG_LIVE bit set.  */
-  if ((regno < FIRST_PSEUDO_REGISTER)
-      && (!DF_REF_IS_ARTIFICIAL (this_ref)))
+  if (regno < FIRST_PSEUDO_REGISTER
+      && !DF_REF_IS_ARTIFICIAL (this_ref)
+      && !DEBUG_INSN_P (DF_REF_INSN (this_ref)))
     {
       if (DF_REF_REG_DEF_P (this_ref))
        {
@@ -2916,40 +2915,27 @@ df_read_modify_subreg_p (rtx x)
 }
 
 
-/* Process all the registers defined in the rtx, X.
-   Autoincrement/decrement definitions will be picked up by
-   df_uses_record.  */
+/* Process all the registers defined in the rtx pointed by LOC.
+   Autoincrement/decrement definitions will be picked up by df_uses_record.
+   Any change here has to be matched in df_find_hard_reg_defs_1.  */
 
 static void
 df_def_record_1 (struct df_collection_rec *collection_rec,
-                 rtx x, basic_block bb, struct df_insn_info *insn_info,
+                 rtx *loc, basic_block bb, struct df_insn_info *insn_info,
                 int flags)
 {
-  rtx *loc;
-  rtx dst;
-
- /* We may recursively call ourselves on EXPR_LIST when dealing with PARALLEL
-     construct.  */
-  if (GET_CODE (x) == EXPR_LIST || GET_CODE (x) == CLOBBER)
-    loc = &XEXP (x, 0);
-  else
-    loc = &SET_DEST (x);
-  dst = *loc;
+  rtx dst = *loc;
 
   /* It is legal to have a set destination be a parallel. */
   if (GET_CODE (dst) == PARALLEL)
     {
       int i;
-
       for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
        {
          rtx temp = XVECEXP (dst, 0, i);
-         if (GET_CODE (temp) == EXPR_LIST || GET_CODE (temp) == CLOBBER
-             || GET_CODE (temp) == SET)
-           df_def_record_1 (collection_rec,
-                             temp, bb, insn_info,
-                            GET_CODE (temp) == CLOBBER
-                            ? flags | DF_REF_MUST_CLOBBER : flags);
+         gcc_assert (GET_CODE (temp) == EXPR_LIST);
+         df_def_record_1 (collection_rec, &XEXP (temp, 0),
+                          bb, insn_info, flags);
        }
       return;
     }
@@ -2995,7 +2981,8 @@ df_def_record_1 (struct df_collection_rec *collection_rec,
 }
 
 
-/* Process all the registers defined in the pattern rtx, X.  */
+/* Process all the registers defined in the pattern rtx, X.  Any change
+   here has to be matched in df_find_hard_reg_defs.  */
 
 static void
 df_defs_record (struct df_collection_rec *collection_rec,
@@ -3003,26 +2990,99 @@ df_defs_record (struct df_collection_rec *collection_rec,
                int flags)
 {
   RTX_CODE code = GET_CODE (x);
+  int i;
 
-  if (code == SET || code == CLOBBER)
-    {
-      /* Mark the single def within the pattern.  */
-      int clobber_flags = flags;
-      clobber_flags |= (code == CLOBBER) ? DF_REF_MUST_CLOBBER : 0;
-      df_def_record_1 (collection_rec, x, bb, insn_info, clobber_flags);
-    }
-  else if (code == COND_EXEC)
+  switch (code)
     {
+    case SET:
+      df_def_record_1 (collection_rec, &SET_DEST (x), bb, insn_info, flags);
+      break;
+
+    case CLOBBER:
+      flags |= DF_REF_MUST_CLOBBER;
+      df_def_record_1 (collection_rec, &XEXP (x, 0), bb, insn_info, flags);
+      break;
+
+    case COND_EXEC:
       df_defs_record (collection_rec, COND_EXEC_CODE (x),
                      bb, insn_info, DF_REF_CONDITIONAL);
+      break;
+
+    case PARALLEL:
+      for (i = 0; i < XVECLEN (x, 0); i++)
+       df_defs_record (collection_rec, XVECEXP (x, 0, i),
+                       bb, insn_info, flags);
+      break;
+    default:
+      /* No DEFs to record in other cases */
+      break;
     }
-  else if (code == PARALLEL)
+}
+
+/* Set bits in *DEFS for hard registers found in the rtx DST, which is the
+   destination of a set or clobber.  This has to match the logic in
+   df_defs_record_1.  */
+
+static void
+df_find_hard_reg_defs_1 (rtx dst, HARD_REG_SET *defs)
+{
+  /* It is legal to have a set destination be a parallel. */
+  if (GET_CODE (dst) == PARALLEL)
     {
       int i;
+      for (i = XVECLEN (dst, 0) - 1; i >= 0; i--)
+       {
+         rtx temp = XVECEXP (dst, 0, i);
+         gcc_assert (GET_CODE (temp) == EXPR_LIST);
+         df_find_hard_reg_defs_1 (XEXP (temp, 0), defs);
+       }
+      return;
+    }
+
+  if (GET_CODE (dst) == STRICT_LOW_PART)
+      dst = XEXP (dst, 0);
+
+  if (GET_CODE (dst) == ZERO_EXTRACT)
+      dst = XEXP (dst, 0);
+
+  /* At this point if we do not have a reg or a subreg, just return.  */
+  if (REG_P (dst) && HARD_REGISTER_P (dst))
+    SET_HARD_REG_BIT (*defs, REGNO (dst));
+  else if (GET_CODE (dst) == SUBREG
+          && REG_P (SUBREG_REG (dst)) && HARD_REGISTER_P (dst))
+    SET_HARD_REG_BIT (*defs, REGNO (SUBREG_REG (dst)));
+}
+
+/* Set bits in *DEFS for hard registers defined in the pattern X.  This
+   has to match the logic in df_defs_record.  */
+
+static void
+df_find_hard_reg_defs (rtx x, HARD_REG_SET *defs)
+{
+  RTX_CODE code = GET_CODE (x);
+  int i;
+
+  switch (code)
+    {
+    case SET:
+      df_find_hard_reg_defs_1 (SET_DEST (x), defs);
+      break;
+
+    case CLOBBER:
+      df_find_hard_reg_defs_1 (XEXP (x, 0), defs);
+      break;
 
-      /* Mark the multiple defs within the pattern.  */
-      for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
-       df_defs_record (collection_rec, XVECEXP (x, 0, i), bb, insn_info, flags);
+    case COND_EXEC:
+      df_find_hard_reg_defs (COND_EXEC_CODE (x), defs);
+      break;
+
+    case PARALLEL:
+      for (i = 0; i < XVECLEN (x, 0); i++)
+       df_find_hard_reg_defs (XVECEXP (x, 0, i), defs);
+      break;
+    default:
+      /* No DEFs to record in other cases */
+      break;
     }
 }
 
@@ -3181,6 +3241,7 @@ df_uses_record (struct df_collection_rec *collection_rec,
       }
 
     case RETURN:
+    case SIMPLE_RETURN:
       break;
 
     case ASM_OPERANDS:
@@ -3308,29 +3369,56 @@ df_get_conditional_uses (struct df_collection_rec *collection_rec)
 }
 
 
-/* Get call's extra defs and uses. */
+/* Get call's extra defs and uses (track caller-saved registers). */
 
 static void
-df_get_call_refs (struct df_collection_rec * collection_rec,
+df_get_call_refs (struct df_collection_rec *collection_rec,
                   basic_block bb,
                   struct df_insn_info *insn_info,
                   int flags)
 {
   rtx note;
-  bitmap_iterator bi;
-  unsigned int ui;
   bool is_sibling_call;
   unsigned int i;
-  df_ref def;
-  bitmap_head defs_generated;
+  HARD_REG_SET defs_generated;
 
-  bitmap_initialize (&defs_generated, &df_bitmap_obstack);
+  CLEAR_HARD_REG_SET (defs_generated);
+  df_find_hard_reg_defs (PATTERN (insn_info->insn), &defs_generated);
+  is_sibling_call = SIBLING_CALL_P (insn_info->insn);
 
-  /* Do not generate clobbers for registers that are the result of the
-     call.  This causes ordering problems in the chain building code
-     depending on which def is seen first.  */
-  FOR_EACH_VEC_ELT (df_ref, collection_rec->def_vec, i, def)
-    bitmap_set_bit (&defs_generated, DF_REF_REGNO (def));
+  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
+    {
+      if (i == STACK_POINTER_REGNUM)
+       /* The stack ptr is used (honorarily) by a CALL insn.  */
+       df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
+                      NULL, bb, insn_info, DF_REF_REG_USE,
+                      DF_REF_CALL_STACK_USAGE | flags);
+      else if (global_regs[i])
+       {
+         /* Calls to const functions cannot access any global registers and
+            calls to pure functions cannot set them.  All other calls may
+            reference any of the global registers, so they are recorded as
+            used. */
+         if (!RTL_CONST_CALL_P (insn_info->insn))
+           {
+             df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
+                            NULL, bb, insn_info, DF_REF_REG_USE, flags);
+             if (!RTL_PURE_CALL_P (insn_info->insn))
+               df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
+                              NULL, bb, insn_info, DF_REF_REG_DEF, flags);
+           }
+       }
+      else if (TEST_HARD_REG_BIT (regs_invalidated_by_call, i)
+              /* no clobbers for regs that are the result of the call */
+              && !TEST_HARD_REG_BIT (defs_generated, i)
+              && (!is_sibling_call
+                  || !bitmap_bit_p (df->exit_block_uses, i)
+                  || refers_to_regno_p (i, i+1,
+                                        crtl->return_rtx, NULL)))
+         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
+                        NULL, bb, insn_info, DF_REF_REG_DEF,
+                        DF_REF_MAY_CLOBBER | flags);
+    }
 
   /* Record the registers used to pass arguments, and explicitly
      noted as clobbered.  */
@@ -3345,7 +3433,7 @@ df_get_call_refs (struct df_collection_rec * collection_rec,
          if (REG_P (XEXP (XEXP (note, 0), 0)))
            {
              unsigned int regno = REGNO (XEXP (XEXP (note, 0), 0));
-             if (!bitmap_bit_p (&defs_generated, regno))
+             if (!TEST_HARD_REG_BIT (defs_generated, regno))
                df_defs_record (collection_rec, XEXP (note, 0), bb,
                                insn_info, flags);
            }
@@ -3355,40 +3443,6 @@ df_get_call_refs (struct df_collection_rec * collection_rec,
        }
     }
 
-  /* The stack ptr is used (honorarily) by a CALL insn.  */
-  df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[STACK_POINTER_REGNUM],
-                NULL, bb, insn_info, DF_REF_REG_USE,
-                DF_REF_CALL_STACK_USAGE | flags);
-
-  /* Calls to const functions cannot access any global registers and calls to
-     pure functions cannot set them.  All other calls may reference any of the
-     global registers, so they are recorded as used.  */
-  if (!RTL_CONST_CALL_P (insn_info->insn))
-    for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-      if (global_regs[i])
-       {
-         df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
-                        NULL, bb, insn_info, DF_REF_REG_USE, flags);
-         if (!RTL_PURE_CALL_P (insn_info->insn))
-           df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[i],
-                          NULL, bb, insn_info, DF_REF_REG_DEF, flags);
-       }
-
-  is_sibling_call = SIBLING_CALL_P (insn_info->insn);
-  EXECUTE_IF_SET_IN_BITMAP (regs_invalidated_by_call_regset, 0, ui, bi)
-    {
-      if (!global_regs[ui]
-         && (!bitmap_bit_p (&defs_generated, ui))
-         && (!is_sibling_call
-             || !bitmap_bit_p (df->exit_block_uses, ui)
-             || refers_to_regno_p (ui, ui+1,
-                                   crtl->return_rtx, NULL)))
-        df_ref_record (DF_REF_BASE, collection_rec, regno_reg_rtx[ui],
-                      NULL, bb, insn_info, DF_REF_REG_DEF,
-                      DF_REF_MAY_CLOBBER | flags);
-    }
-
-  bitmap_clear (&defs_generated);
   return;
 }
 
@@ -3398,7 +3452,7 @@ df_get_call_refs (struct df_collection_rec * collection_rec,
    and reg chains. */
 
 static void
-df_insn_refs_collect (struct df_collection_reccollection_rec,
+df_insn_refs_collect (struct df_collection_rec *collection_rec,
                      basic_block bb, struct df_insn_info *insn_info)
 {
   rtx note;
@@ -3410,9 +3464,6 @@ df_insn_refs_collect (struct df_collection_rec* collection_rec,
   VEC_truncate (df_ref, collection_rec->eq_use_vec, 0);
   VEC_truncate (df_mw_hardreg_ptr, collection_rec->mw_vec, 0);
 
-  /* Record register defs.  */
-  df_defs_record (collection_rec, PATTERN (insn_info->insn), bb, insn_info, 0);
-
   /* Process REG_EQUIV/REG_EQUAL notes.  */
   for (note = REG_NOTES (insn_info->insn); note;
        note = XEXP (note, 1))
@@ -3443,10 +3494,17 @@ df_insn_refs_collect (struct df_collection_rec* collection_rec,
         }
     }
 
+  /* For CALL_INSNs, first record DF_REF_BASE register defs, as well as
+     uses from CALL_INSN_FUNCTION_USAGE. */
   if (CALL_P (insn_info->insn))
     df_get_call_refs (collection_rec, bb, insn_info,
                      (is_cond_exec) ? DF_REF_CONDITIONAL : 0);
 
+  /* Record other defs.  These should be mostly for DF_REF_REGULAR, so
+     that a qsort on the defs is unnecessary in most cases.  */
+  df_defs_record (collection_rec,
+                 PATTERN (insn_info->insn), bb, insn_info, 0);
+
   /* Record the register uses.  */
   df_uses_record (collection_rec,
                  &PATTERN (insn_info->insn), DF_REF_REG_USE, bb, insn_info, 0);
@@ -3674,7 +3732,7 @@ df_get_eh_block_artificial_uses (bitmap eh_block_artificial_uses)
 {
   bitmap_clear (eh_block_artificial_uses);
 
-  /* The following code (down thru the arg_pointer setting APPEARS
+  /* The following code (down through the arg_pointer setting APPEARS
      to be necessary because there is nothing that actually
      describes what the exception handling code may actually need
      to keep alive.  */
@@ -3733,14 +3791,8 @@ df_get_entry_block_def_set (bitmap entry_block_defs)
   bitmap_clear (entry_block_defs);
 
   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-    {
-      if (FUNCTION_ARG_REGNO_P (i))
-#ifdef INCOMING_REGNO
-       bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
-#else
-       bitmap_set_bit (entry_block_defs, i);
-#endif
-    }
+    if (FUNCTION_ARG_REGNO_P (i))
+      bitmap_set_bit (entry_block_defs, INCOMING_REGNO (i));
 
   /* The always important stack pointer.  */
   bitmap_set_bit (entry_block_defs, STACK_POINTER_REGNUM);
@@ -4396,7 +4448,6 @@ df_bb_verify (basic_block bb)
       if (!INSN_P (insn))
         continue;
       df_insn_refs_verify (&collection_rec, bb, insn, true);
-      df_free_collection_rec (&collection_rec);
     }
 
   /* Do the artificial defs and uses.  */
@@ -4425,7 +4476,6 @@ df_entry_block_bitmap_verify (bool abort_if_fail)
 
   if (!is_eq && abort_if_fail)
     {
-      print_current_pass (stderr);
       fprintf (stderr, "entry_block_defs = ");
       df_print_regset (stderr, &entry_block_defs);
       fprintf (stderr, "df->entry_block_defs = ");
@@ -4455,7 +4505,6 @@ df_exit_block_bitmap_verify (bool abort_if_fail)
 
   if (!is_eq && abort_if_fail)
     {
-      print_current_pass (stderr);
       fprintf (stderr, "exit_block_uses = ");
       df_print_regset (stderr, &exit_block_uses);
       fprintf (stderr, "df->exit_block_uses = ");
@@ -4485,7 +4534,7 @@ df_scan_verify (void)
 
   /* Verification is a 4 step process. */
 
-  /* (1) All of the refs are marked by going thru the reg chains.  */
+  /* (1) All of the refs are marked by going through the reg chains.  */
   for (i = 0; i < DF_REG_SIZE (df); i++)
     {
       gcc_assert (df_reg_chain_mark (DF_REG_DEF_CHAIN (i), i, true, false)