OSDN Git Service

2004-06-28 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / flow.c
index acf375a..1a6546d 100644 (file)
@@ -192,10 +192,6 @@ regset regs_live_at_setjmp;
    are another pair, etc.  */
 rtx regs_may_share;
 
-/* Callback that determines if it's ok for a function to have no
-   noreturn attribute.  */
-int (*lang_missing_noreturn_ok_p) (tree);
-
 /* Set of registers that may be eliminable.  These are handled specially
    in updating regs_ever_live.  */
 
@@ -295,7 +291,7 @@ static int verify_wide_reg_1 (rtx *, void *);
 static void verify_wide_reg (int, basic_block);
 static void verify_local_live_at_start (regset, basic_block);
 static void notice_stack_pointer_modification_1 (rtx, rtx, void *);
-static void notice_stack_pointer_modification (rtx);
+static void notice_stack_pointer_modification (void);
 static void mark_reg (rtx, void *);
 static void mark_regs_live_at_end (regset);
 static void calculate_global_regs_live (sbitmap, sbitmap, int);
@@ -334,48 +330,6 @@ static void invalidate_mems_from_set (struct propagate_block_info *, rtx);
 static void clear_log_links (sbitmap);
 static int count_or_remove_death_notes_bb (basic_block, int);
 \f
-
-void
-check_function_return_warnings (void)
-{
-  if (warn_missing_noreturn
-      && !TREE_THIS_VOLATILE (cfun->decl)
-      && EXIT_BLOCK_PTR->pred == NULL
-      && (lang_missing_noreturn_ok_p
-         && !lang_missing_noreturn_ok_p (cfun->decl)))
-    warning ("function might be possible candidate for attribute `noreturn'");
-
-  /* If we have a path to EXIT, then we do return.  */
-  if (TREE_THIS_VOLATILE (cfun->decl)
-      && EXIT_BLOCK_PTR->pred != NULL)
-    warning ("`noreturn' function does return");
-
-  /* If the clobber_return_insn appears in some basic block, then we
-     do reach the end without returning a value.  */
-  else if (warn_return_type
-          && cfun->x_clobber_return_insn != NULL
-          && EXIT_BLOCK_PTR->pred != NULL)
-    {
-      int max_uid = get_max_uid ();
-
-      /* If clobber_return_insn was excised by jump1, then renumber_insns
-        can make max_uid smaller than the number still recorded in our rtx.
-        That's fine, since this is a quick way of verifying that the insn
-        is no longer in the chain.  */
-      if (INSN_UID (cfun->x_clobber_return_insn) < max_uid)
-       {
-         rtx insn;
-
-         for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
-           if (insn == cfun->x_clobber_return_insn)
-             {
-               warning ("control reaches end of non-void function");
-               break;
-             }
-       }
-    }
-}
-\f
 /* Return the INSN immediately following the NOTE_INSN_BASIC_BLOCK
    note associated with the BLOCK.  */
 
@@ -397,12 +351,11 @@ first_insn_after_basic_block_note (basic_block block)
   return NEXT_INSN (insn);
 }
 \f
-/* Perform data flow analysis.
-   F is the first insn of the function; FLAGS is a set of PROP_* flags
-   to be used in accumulating flow info.  */
+/* Perform data flow analysis for the whole control flow graph.
+   FLAGS is a set of PROP_* flags to be used in accumulating flow info.  */
 
 void
-life_analysis (rtx f, FILE *file, int flags)
+life_analysis (FILE *file, int flags)
 {
 #ifdef ELIMINABLE_REGS
   int i;
@@ -449,13 +402,13 @@ life_analysis (rtx f, FILE *file, int flags)
 
   /* Always remove no-op moves.  Do this before other processing so
      that we don't have to keep re-scanning them.  */
-  delete_noop_moves (f);
+  delete_noop_moves ();
 
   /* Some targets can emit simpler epilogues if they know that sp was
      not ever modified during the function.  After reload, of course,
      we've already emitted the epilogue so there's no sense searching.  */
   if (! reload_completed)
-    notice_stack_pointer_modification (f);
+    notice_stack_pointer_modification ();
 
   /* Allocate and zero out data structures that will record the
      data from lifetime analysis.  */
@@ -488,8 +441,6 @@ life_analysis (rtx f, FILE *file, int flags)
   if (file)
     dump_flow_info (file);
 
-  free_basic_block_vars (1);
-
   /* Removing dead insns should have made jumptables really dead.  */
   delete_dead_jumptables ();
 }
@@ -504,7 +455,7 @@ verify_wide_reg_1 (rtx *px, void *pregno)
   rtx x = *px;
   unsigned int regno = *(int *) pregno;
 
-  if (GET_CODE (x) == REG && REGNO (x) == regno)
+  if (REG_P (x) && REGNO (x) == regno)
     {
       if (GET_MODE_BITSIZE (GET_MODE (x)) <= BITS_PER_WORD)
        return 2;
@@ -685,8 +636,7 @@ update_life_info (sbitmap blocks, enum update_life_extent extent, int prop_flags
 
          /* Zap the life information from the last round.  If we don't
             do this, we can wind up with registers that no longer appear
-            in the code being marked live at entry, which twiggs bogus
-            warnings from regno_uninitialized.  */
+            in the code being marked live at entry.  */
          FOR_EACH_BB (bb)
            {
              CLEAR_REG_SET (bb->global_live_at_start);
@@ -809,34 +759,29 @@ update_life_info_in_dirty_blocks (enum update_life_extent extent, int prop_flags
   return retval;
 }
 
-/* Free the variables allocated by find_basic_blocks.
-
-   KEEP_HEAD_END_P is nonzero if basic_block_info is not to be freed.  */
+/* Free the variables allocated by find_basic_blocks.  */
 
 void
-free_basic_block_vars (int keep_head_end_p)
+free_basic_block_vars (void)
 {
-  if (! keep_head_end_p)
+  if (basic_block_info)
     {
-      if (basic_block_info)
-       {
-         clear_edges ();
-         VARRAY_FREE (basic_block_info);
-       }
-      n_basic_blocks = 0;
-      last_basic_block = 0;
-
-      ENTRY_BLOCK_PTR->aux = NULL;
-      ENTRY_BLOCK_PTR->global_live_at_end = NULL;
-      EXIT_BLOCK_PTR->aux = NULL;
-      EXIT_BLOCK_PTR->global_live_at_start = NULL;
+      clear_edges ();
+      basic_block_info = NULL;
     }
+  n_basic_blocks = 0;
+  last_basic_block = 0;
+
+  ENTRY_BLOCK_PTR->aux = NULL;
+  ENTRY_BLOCK_PTR->global_live_at_end = NULL;
+  EXIT_BLOCK_PTR->aux = NULL;
+  EXIT_BLOCK_PTR->global_live_at_start = NULL;
 }
 
 /* Delete any insns that copy a register to itself.  */
 
 int
-delete_noop_moves (rtx f ATTRIBUTE_UNUSED)
+delete_noop_moves (void)
 {
   rtx insn, next;
   basic_block bb;
@@ -914,14 +859,15 @@ notice_stack_pointer_modification_1 (rtx x, rtx pat ATTRIBUTE_UNUSED,
         of a push until later in flow.  See the comments in rtl.texi
         regarding Embedded Side-Effects on Addresses.  */
       || (GET_CODE (x) == MEM
-         && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == 'a'
+         && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == RTX_AUTOINC
          && XEXP (XEXP (x, 0), 0) == stack_pointer_rtx))
     current_function_sp_is_unchanging = 0;
 }
 
 static void
-notice_stack_pointer_modification (rtx f)
+notice_stack_pointer_modification (void)
 {
+  basic_block bb;
   rtx insn;
 
   /* Assume that the stack pointer is unchanging if alloca hasn't
@@ -930,17 +876,19 @@ notice_stack_pointer_modification (rtx f)
   if (! current_function_sp_is_unchanging)
     return;
 
-  for (insn = f; insn; insn = NEXT_INSN (insn))
-    {
-      if (INSN_P (insn))
-       {
-         /* Check if insn modifies the stack pointer.  */
-         note_stores (PATTERN (insn), notice_stack_pointer_modification_1,
-                      NULL);
-         if (! current_function_sp_is_unchanging)
-           return;
-       }
-    }
+  FOR_EACH_BB (bb)
+    FOR_BB_INSNS (bb, insn)
+      {
+       if (INSN_P (insn))
+         {
+           /* Check if insn modifies the stack pointer.  */
+           note_stores (PATTERN (insn),
+                        notice_stack_pointer_modification_1,
+                        NULL);
+           if (! current_function_sp_is_unchanging)
+             return;
+         }
+      }
 }
 
 /* Mark a register in SET.  Hard registers in large modes get all
@@ -1382,7 +1330,7 @@ find_regno_partial (rtx *ptr, void *data)
     case ZERO_EXTRACT:
     case SIGN_EXTRACT:
     case STRICT_LOW_PART:
-      if (GET_CODE (XEXP (*ptr, 0)) == REG && REGNO (XEXP (*ptr, 0)) == reg)
+      if (REG_P (XEXP (*ptr, 0)) && REGNO (XEXP (*ptr, 0)) == reg)
        {
          param->retval = XEXP (*ptr, 0);
          return 1;
@@ -1390,7 +1338,7 @@ find_regno_partial (rtx *ptr, void *data)
       break;
 
     case SUBREG:
-      if (GET_CODE (SUBREG_REG (*ptr)) == REG
+      if (REG_P (SUBREG_REG (*ptr))
          && REGNO (SUBREG_REG (*ptr)) == reg)
        {
          param->retval = SUBREG_REG (*ptr);
@@ -1675,7 +1623,7 @@ propagate_one_insn (struct propagate_block_info *pbi, rtx insn)
     /* Does this instruction increment or decrement a register?  */
     if ((flags & PROP_AUTOINC)
        && x != 0
-       && GET_CODE (SET_DEST (x)) == REG
+       && REG_P (SET_DEST (x))
        && (GET_CODE (SET_SRC (x)) == PLUS
            || GET_CODE (SET_SRC (x)) == MINUS)
        && XEXP (SET_SRC (x), 0) == SET_DEST (x)
@@ -1707,12 +1655,18 @@ propagate_one_insn (struct propagate_block_info *pbi, rtx insn)
           && GET_CODE (SET_SRC (PATTERN (insn))) == PLUS
           && XEXP (SET_SRC (PATTERN (insn)), 0) == stack_pointer_rtx
           && GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == CONST_INT)
-    /* We have an insn to pop a constant amount off the stack.
-       (Such insns use PLUS regardless of the direction of the stack,
-       and any insn to adjust the stack by a constant is always a pop.)
-       These insns, if not dead stores, have no effect on life, though
-       they do have an effect on the memory stores we are tracking.  */
-    invalidate_mems_from_set (pbi, stack_pointer_rtx);
+    {
+      /* We have an insn to pop a constant amount off the stack.
+         (Such insns use PLUS regardless of the direction of the stack,
+         and any insn to adjust the stack by a constant is always a pop
+        or part of a push.)
+         These insns, if not dead stores, have no effect on life, though
+         they do have an effect on the memory stores we are tracking.  */
+      invalidate_mems_from_set (pbi, stack_pointer_rtx);
+      /* Still, we need to update local_set, lest ifcvt.c:dead_or_predicable
+        concludes that the stack pointer is not modified.  */
+      mark_set_regs (pbi, PATTERN (insn), insn);
+    }
   else
     {
       rtx note;
@@ -1772,8 +1726,9 @@ propagate_one_insn (struct propagate_block_info *pbi, rtx insn)
                                              current_function_return_rtx,
                                              (rtx *) 0)))
              {
+               enum rtx_code code = global_regs[i] ? SET : CLOBBER;
                /* We do not want REG_UNUSED notes for these registers.  */
-               mark_set_1 (pbi, CLOBBER, regno_reg_rtx[i], cond, insn,
+               mark_set_1 (pbi, code, regno_reg_rtx[i], cond, insn,
                            pbi->flags & ~(PROP_DEATH_NOTES | PROP_REG_INFO));
              }
        }
@@ -1918,7 +1873,7 @@ init_propagate_block_info (basic_block bb, regset live, regset local_set,
             in the form of a comparison of a register against zero.  
             If the condition is more complex than that, then it is safe
             not to record any information.  */
-         if (GET_CODE (reg) == REG
+         if (REG_P (reg)
              && XEXP (cond_true, 1) == const0_rtx)
            {
              rtx cond_false
@@ -2194,7 +2149,7 @@ insn_dead_p (struct propagate_block_info *pbi, rtx x, int call_ok,
                 || GET_CODE (r) == ZERO_EXTRACT)
            r = XEXP (r, 0);
 
-         if (GET_CODE (r) == REG)
+         if (REG_P (r))
            {
              int regno = REGNO (r);
 
@@ -2270,7 +2225,7 @@ insn_dead_p (struct propagate_block_info *pbi, rtx x, int call_ok,
      is not necessarily true for hard registers until after reload.  */
   else if (code == CLOBBER)
     {
-      if (GET_CODE (XEXP (x, 0)) == REG
+      if (REG_P (XEXP (x, 0))
          && (REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER
              || reload_completed)
          && ! REGNO_REG_SET_P (pbi->reg_live, REGNO (XEXP (x, 0))))
@@ -2310,7 +2265,7 @@ libcall_dead_p (struct propagate_block_info *pbi, rtx note, rtx insn)
     {
       rtx r = SET_SRC (x);
 
-      if (GET_CODE (r) == REG)
+      if (REG_P (r))
        {
          rtx call = XEXP (note, 0);
          rtx call_pat;
@@ -2350,24 +2305,6 @@ libcall_dead_p (struct propagate_block_info *pbi, rtx note, rtx insn)
   return 1;
 }
 
-/* Return 1 if register REGNO was used before it was set, i.e. if it is
-   live at function entry.  Don't count global register variables, variables
-   in registers that can be used for function arg passing, or variables in
-   fixed hard registers.  */
-
-int
-regno_uninitialized (unsigned int regno)
-{
-  if (n_basic_blocks == 0
-      || (regno < FIRST_PSEUDO_REGISTER
-         && (global_regs[regno]
-             || fixed_regs[regno]
-             || FUNCTION_ARG_REGNO_P (regno))))
-    return 0;
-
-  return REGNO_REG_SET_P (ENTRY_BLOCK_PTR->global_live_at_end, regno);
-}
-
 /* 1 if register REGNO was alive at a place where `setjmp' was called
    and was set more than once or is an argument.
    Such regs may be clobbered by `longjmp'.  */
@@ -2438,7 +2375,7 @@ invalidate_mems_from_autoinc (rtx *px, void *data)
   rtx x = *px;
   struct propagate_block_info *pbi = data;
 
-  if (GET_RTX_CLASS (GET_CODE (x)) == 'a')
+  if (GET_RTX_CLASS (GET_CODE (x)) == RTX_AUTOINC)
     {
       invalidate_mems_from_set (pbi, XEXP (x, 0));
       return -1;
@@ -2615,7 +2552,7 @@ mark_set_1 (struct propagate_block_info *pbi, enum rtx_code code, rtx reg, rtx c
       break;
 
     case SUBREG:
-      if (GET_CODE (SUBREG_REG (reg)) == REG)
+      if (REG_P (SUBREG_REG (reg)))
        {
          enum machine_mode outer_mode = GET_MODE (reg);
          enum machine_mode inner_mode = GET_MODE (SUBREG_REG (reg));
@@ -2668,7 +2605,7 @@ mark_set_1 (struct propagate_block_info *pbi, enum rtx_code code, rtx reg, rtx c
      If this set is a REG, then it kills any MEMs which use the reg.  */
   if (optimize && (flags & PROP_SCAN_DEAD_STORES))
     {
-      if (GET_CODE (reg) == REG)
+      if (REG_P (reg))
        invalidate_mems_from_set (pbi, reg);
 
       /* If the memory reference had embedded side effects (autoincrement
@@ -2683,7 +2620,7 @@ mark_set_1 (struct propagate_block_info *pbi, enum rtx_code code, rtx reg, rtx c
        add_to_mem_set_list (pbi, canon_rtx (reg));
     }
 
-  if (GET_CODE (reg) == REG
+  if (REG_P (reg)
       && ! (regno_first == FRAME_POINTER_REGNUM
            && (! reload_completed || frame_pointer_needed))
 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
@@ -2799,10 +2736,18 @@ mark_set_1 (struct propagate_block_info *pbi, enum rtx_code code, rtx reg, rtx c
                     in ASM_OPERANDs.  If these registers get replaced,
                     we might wind up changing the semantics of the insn,
                     even if reload can make what appear to be valid
-                    assignments later.  */
+                    assignments later.
+
+                    We don't build a LOG_LINK for global registers to
+                    or from a function call.  We don't want to let
+                    combine think that it knows what is going on with
+                    global registers.  */
                  if (y && (BLOCK_NUM (y) == blocknum)
                      && (regno_first >= FIRST_PSEUDO_REGISTER
-                         || asm_noperands (PATTERN (y)) < 0))
+                         || (asm_noperands (PATTERN (y)) < 0
+                             && ! ((GET_CODE (insn) == CALL_INSN
+                                    || GET_CODE (y) == CALL_INSN)
+                                   && global_regs[regno_first]))))
                    LOG_LINKS (y) = alloc_INSN_LIST (insn, LOG_LINKS (y));
                }
            }
@@ -2865,7 +2810,7 @@ mark_set_1 (struct propagate_block_info *pbi, enum rtx_code code, rtx reg, rtx c
              }
        }
     }
-  else if (GET_CODE (reg) == REG)
+  else if (REG_P (reg))
     {
       if (flags & (PROP_LOG_LINKS | PROP_AUTOINC))
        pbi->reg_next_use[regno_first] = 0;
@@ -3045,9 +2990,9 @@ ior_reg_cond (rtx old, rtx x, int add)
 {
   rtx op0, op1;
 
-  if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+  if (COMPARISON_P (old))
     {
-      if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+      if (COMPARISON_P (x)
          && REVERSE_CONDEXEC_PREDICATES_P (GET_CODE (x), GET_CODE (old))
          && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
        return const1_rtx;
@@ -3140,8 +3085,8 @@ not_reg_cond (rtx x)
   x_code = GET_CODE (x);
   if (x_code == NOT)
     return XEXP (x, 0);
-  if (GET_RTX_CLASS (x_code) == '<'
-      && GET_CODE (XEXP (x, 0)) == REG)
+  if (COMPARISON_P (x)
+      && REG_P (XEXP (x, 0)))
     {
       if (XEXP (x, 1) != const0_rtx)
        abort ();
@@ -3157,9 +3102,9 @@ and_reg_cond (rtx old, rtx x, int add)
 {
   rtx op0, op1;
 
-  if (GET_RTX_CLASS (GET_CODE (old)) == '<')
+  if (COMPARISON_P (old))
     {
-      if (GET_RTX_CLASS (GET_CODE (x)) == '<'
+      if (COMPARISON_P (x)
          && GET_CODE (x) == reverse_condition (GET_CODE (old))
          && REGNO (XEXP (x, 0)) == REGNO (XEXP (old, 0)))
        return const0_rtx;
@@ -3250,7 +3195,7 @@ elim_reg_cond (rtx x, unsigned int regno)
 {
   rtx op0, op1;
 
-  if (GET_RTX_CLASS (GET_CODE (x)) == '<')
+  if (COMPARISON_P (x))
     {
       if (REGNO (XEXP (x, 0)) == regno)
        return const0_rtx;
@@ -3334,7 +3279,7 @@ attempt_auto_inc (struct propagate_block_info *pbi, rtx inc, rtx insn,
       if (! validate_change (insn, &XEXP (mem, 0), inc, 0))
        return;
     }
-  else if (GET_CODE (q) == REG
+  else if (REG_P (q)
           /* PREV_INSN used here to check the semi-open interval
              [insn,incr).  */
           && ! reg_used_between_p (q,  PREV_INSN (insn), incr)
@@ -3484,7 +3429,7 @@ find_auto_inc (struct propagate_block_info *pbi, rtx x, rtx insn)
   if (GET_CODE (addr) == PLUS && GET_CODE (XEXP (addr, 1)) == CONST_INT)
     offset = INTVAL (XEXP (addr, 1)), addr = XEXP (addr, 0);
 
-  if (GET_CODE (addr) != REG)
+  if (!REG_P (addr))
     return;
 
   regno = REGNO (addr);
@@ -3539,7 +3484,7 @@ find_auto_inc (struct propagate_block_info *pbi, rtx x, rtx insn)
                                                                  inc_val)),
                          insn, x, incr, addr);
     }
-  else if (GET_CODE (inc_val) == REG
+  else if (REG_P (inc_val)
           && ! reg_set_between_p (inc_val, PREV_INSN (insn),
                                   NEXT_INSN (incr)))
 
@@ -3842,7 +3787,7 @@ mark_used_regs (struct propagate_block_info *pbi, rtx x, rtx cond, rtx insn)
     case SUBREG:
 #ifdef CANNOT_CHANGE_MODE_CLASS
       if ((flags & PROP_REG_INFO)
-         && GET_CODE (SUBREG_REG (x)) == REG
+         && REG_P (SUBREG_REG (x))
          && REGNO (SUBREG_REG (x)) >= FIRST_PSEUDO_REGISTER)
        bitmap_set_bit (&subregs_of_mode, REGNO (SUBREG_REG (x))
                                          * MAX_MACHINE_MODE
@@ -3851,7 +3796,7 @@ mark_used_regs (struct propagate_block_info *pbi, rtx x, rtx cond, rtx insn)
 
       /* While we're here, optimize this case.  */
       x = SUBREG_REG (x);
-      if (GET_CODE (x) != REG)
+      if (!REG_P (x))
        goto retry;
       /* Fall through.  */
 
@@ -3893,7 +3838,7 @@ mark_used_regs (struct propagate_block_info *pbi, rtx x, rtx cond, rtx insn)
 #ifdef CANNOT_CHANGE_MODE_CLASS
            if ((flags & PROP_REG_INFO)
                && GET_CODE (testreg) == SUBREG
-               && GET_CODE (SUBREG_REG (testreg)) == REG
+               && REG_P (SUBREG_REG (testreg))
                && REGNO (SUBREG_REG (testreg)) >= FIRST_PSEUDO_REGISTER)
              bitmap_set_bit (&subregs_of_mode, REGNO (SUBREG_REG (testreg))
                                                * MAX_MACHINE_MODE
@@ -3920,7 +3865,7 @@ mark_used_regs (struct propagate_block_info *pbi, rtx x, rtx cond, rtx insn)
 
        if ((GET_CODE (testreg) == PARALLEL
             && GET_MODE (testreg) == BLKmode)
-           || (GET_CODE (testreg) == REG
+           || (REG_P (testreg)
                && (regno = REGNO (testreg),
                    ! (regno == FRAME_POINTER_REGNUM
                       && (! reload_completed || frame_pointer_needed)))
@@ -4277,7 +4222,6 @@ count_or_remove_death_notes (sbitmap blocks, int kill)
   int i;
   basic_block bb;
 
-  
   /* This used to be a loop over all the blocks with a membership test
      inside the loop.  That can be amazingly expensive on a large CFG
      when only a small number of bits are set in BLOCKs (for example,
@@ -4324,7 +4268,7 @@ count_or_remove_death_notes_bb (basic_block bb, int kill)
              switch (REG_NOTE_KIND (link))
                {
                case REG_DEAD:
-                 if (GET_CODE (XEXP (link, 0)) == REG)
+                 if (REG_P (XEXP (link, 0)))
                    {
                      rtx reg = XEXP (link, 0);
                      int n;