OSDN Git Service

* simplify-rtx.c (simplify_binary_operation): Revert last change.
[pf3gnuchains/gcc-fork.git] / gcc / stmt.c
index c95db81..123c9d3 100644 (file)
@@ -2,22 +2,22 @@
    Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
    1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
 
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+along with GCC; see the file COPYING.  If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.  */
 
 /* This file handles the generation of rtl code from tree structure
    above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
@@ -44,6 +44,7 @@ Boston, MA 02111-1307, USA.  */
 #include "function.h"
 #include "insn-config.h"
 #include "expr.h"
+#include "libfuncs.h"
 #include "hard-reg-set.h"
 #include "obstack.h"
 #include "loop.h"
@@ -403,7 +404,7 @@ static void expand_nl_goto_receiver PARAMS ((void));
 static void expand_nl_goto_receivers   PARAMS ((struct nesting *));
 static void fixup_gotos                        PARAMS ((struct nesting *, rtx, tree,
                                               rtx, int));
-static void expand_null_return_1       PARAMS ((rtx, int));
+static void expand_null_return_1       PARAMS ((rtx));
 static void expand_value_return                PARAMS ((rtx));
 static int tail_recursion_args         PARAMS ((tree, tree));
 static void expand_cleanups            PARAMS ((tree, tree, int, int));
@@ -842,12 +843,17 @@ expand_goto (label)
 
       /* Search backwards to the jump insn and mark it as a 
         non-local goto.  */
-      for (insn = get_last_insn ();
-          GET_CODE (insn) != JUMP_INSN; 
-          insn = PREV_INSN (insn))
-       continue;
-      REG_NOTES (insn) = alloc_EXPR_LIST (REG_NON_LOCAL_GOTO, const0_rtx,
-                                         REG_NOTES (insn));
+      for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
+       {
+         if (GET_CODE (insn) == JUMP_INSN)
+           {
+             REG_NOTES (insn) = alloc_EXPR_LIST (REG_NON_LOCAL_GOTO,
+                                                 const0_rtx, REG_NOTES (insn));
+             break;
+           }
+         else if (GET_CODE (insn) == CALL_INSN)
+             break;
+       }
     }
   else
     expand_goto_internal (label, label_rtx (label), NULL_RTX);
@@ -2859,7 +2865,6 @@ expand_exit_something ()
 void
 expand_null_return ()
 {
-  struct nesting *block = block_stack;
   rtx last_insn = get_last_insn ();
 
   /* If this function was declared to return a value, but we
@@ -2867,13 +2872,7 @@ expand_null_return ()
      propogated live to the rest of the function.  */
   clobber_return_register ();
 
-  /* Does any pending block have cleanups?  */
-  while (block && block->data.block.cleanups == 0)
-    block = block->next;
-
-  /* If yes, use a goto to return, since that runs cleanups.  */
-
-  expand_null_return_1 (last_insn, block != 0);
+  expand_null_return_1 (last_insn);
 }
 
 /* Generate RTL to return from the current function, with value VAL.  */
@@ -2882,7 +2881,6 @@ static void
 expand_value_return (val)
      rtx val;
 {
-  struct nesting *block = block_stack;
   rtx last_insn = get_last_insn ();
   rtx return_reg = DECL_RTL (DECL_RESULT (current_function_decl));
 
@@ -2909,27 +2907,15 @@ expand_value_return (val)
        emit_move_insn (return_reg, val);
     }
 
-  /* Does any pending block have cleanups?  */
-
-  while (block && block->data.block.cleanups == 0)
-    block = block->next;
-
-  /* If yes, use a goto to return, since that runs cleanups.
-     Use LAST_INSN to put cleanups *before* the move insn emitted above.  */
-
-  expand_null_return_1 (last_insn, block != 0);
+  expand_null_return_1 (last_insn);
 }
 
 /* Output a return with no value.  If LAST_INSN is nonzero,
-   pretend that the return takes place after LAST_INSN.
-   If USE_GOTO is nonzero then don't use a return instruction;
-   go to the return label instead.  This causes any cleanups
-   of pending blocks to be executed normally.  */
+   pretend that the return takes place after LAST_INSN.  */
 
 static void
-expand_null_return_1 (last_insn, use_goto)
+expand_null_return_1 (last_insn)
      rtx last_insn;
-     int use_goto;
 {
   rtx end_label = cleanup_label ? cleanup_label : return_label;
 
@@ -2937,27 +2923,8 @@ expand_null_return_1 (last_insn, use_goto)
   do_pending_stack_adjust ();
   last_expr_type = 0;
 
-  /* PCC-struct return always uses an epilogue.  */
-  if (current_function_returns_pcc_struct || use_goto)
-    {
-      if (end_label == 0)
-       end_label = return_label = gen_label_rtx ();
-      expand_goto_internal (NULL_TREE, end_label, last_insn);
-      return;
-    }
-
-  /* Otherwise output a simple return-insn if one is available,
-     unless it won't do the job.  */
-#ifdef HAVE_return
-  if (HAVE_return && use_goto == 0 && cleanup_label == 0)
-    {
-      emit_jump_insn (gen_return ());
-      emit_barrier ();
-      return;
-    }
-#endif
-
-  /* Otherwise jump to the epilogue.  */
+  if (end_label == 0)
+     end_label = return_label = gen_label_rtx ();
   expand_goto_internal (NULL_TREE, end_label, last_insn);
 }
 \f
@@ -3523,16 +3490,9 @@ expand_nl_goto_receiver ()
 #endif
        {
          /* Now restore our arg pointer from the address at which it
-            was saved in our stack frame.
-            If there hasn't be space allocated for it yet, make
-            some now.  */
-         if (arg_pointer_save_area == 0)
-           arg_pointer_save_area
-             = assign_stack_local (Pmode, GET_MODE_SIZE (Pmode), 0);
+            was saved in our stack frame.  */
          emit_move_insn (virtual_incoming_args_rtx,
-                         /* We need a pseudo here, or else
-                            instantiate_virtual_regs_1 complains.  */
-                         copy_to_reg (arg_pointer_save_area));
+                         copy_to_reg (get_arg_pointer_save_area (cfun)));
        }
     }
 #endif
@@ -3842,15 +3802,17 @@ expand_decl (decl)
   else if (DECL_SIZE (decl) == 0)
     /* Variable with incomplete type.  */
     {
+      rtx x;
       if (DECL_INITIAL (decl) == 0)
        /* Error message was already done; now avoid a crash.  */
-       SET_DECL_RTL (decl, gen_rtx_MEM (BLKmode, const0_rtx));
+       x = gen_rtx_MEM (BLKmode, const0_rtx);
       else
        /* An initializer is going to decide the size of this array.
           Until we know the size, represent its address with a reg.  */
-       SET_DECL_RTL (decl, gen_rtx_MEM (BLKmode, gen_reg_rtx (Pmode)));
+       x = gen_rtx_MEM (BLKmode, gen_reg_rtx (Pmode));
 
-      set_mem_attributes (DECL_RTL (decl), decl, 1);
+      set_mem_attributes (x, decl, 1);
+      SET_DECL_RTL (decl, x);
     }
   else if (DECL_MODE (decl) != BLKmode
           /* If -ffloat-store, don't put explicit float vars
@@ -3920,7 +3882,7 @@ expand_decl (decl)
   else
     /* Dynamic-size object: must push space on the stack.  */
     {
-      rtx address, size;
+      rtx address, size, x;
 
       /* Record the stack pointer on entry to block, if have
         not already done so.  */
@@ -3945,9 +3907,10 @@ expand_decl (decl)
                                              TYPE_ALIGN (TREE_TYPE (decl)));
 
       /* Reference the variable indirect through that rtx.  */
-      SET_DECL_RTL (decl, gen_rtx_MEM (DECL_MODE (decl), address));
+      x = gen_rtx_MEM (DECL_MODE (decl), address);
+      set_mem_attributes (x, decl, 1);
+      SET_DECL_RTL (decl, x);
 
-      set_mem_attributes (DECL_RTL (decl), decl, 1);
 
       /* Indicate the alignment we actually gave this variable.  */
 #ifdef STACK_BOUNDARY
@@ -5050,10 +5013,6 @@ check_for_full_enumeration_handling (type)
 {
   register struct case_node *n;
   register tree chain;
-#if 0  /* variable used by 'if 0'ed  code below.  */
-  register struct case_node **l;
-  int all_values = 1;
-#endif
 
   /* True iff the selector type is a numbered set mode.  */
   int sparseness = 0;
@@ -5151,28 +5110,6 @@ check_for_full_enumeration_handling (type)
              }
          }
       }
-
-#if 0
-  /* ??? This optimization is disabled because it causes valid programs to
-     fail.  ANSI C does not guarantee that an expression with enum type
-     will have a value that is the same as one of the enumeration literals.  */
-
-  /* If all values were found as case labels, make one of them the default
-     label.  Thus, this switch will never fall through.  We arbitrarily pick
-     the last one to make the default since this is likely the most
-     efficient choice.  */
-
-  if (all_values)
-    {
-      for (l = &case_stack->data.case_stmt.case_list;
-          (*l)->right != 0;
-          l = &(*l)->right)
-       ;
-
-      case_stack->data.case_stmt.default_label = (*l)->code_label;
-      *l = 0;
-    }
-#endif /* 0 */
 }
 
 /* Free CN, and its children.  */
@@ -5190,6 +5127,7 @@ free_case_nodes (cn)
 }
 
 \f
+
 /* Terminate a case (Pascal) or switch (C) statement
    in which ORIG_INDEX is the expression to be tested.
    Generate the code to test it and jump to the right place.  */
@@ -5207,7 +5145,7 @@ expand_end_case (orig_index)
   int ncases;
   rtx *labelvec;
   register int i;
-  rtx before_case;
+  rtx before_case, end;
   register struct nesting *thiscase = case_stack;
   tree index_expr, index_type;
   int unsignedp;
@@ -5318,18 +5256,7 @@ expand_end_case (orig_index)
         If the switch-index is a constant, do it this way
         because we can optimize it.  */
 
-#ifndef CASE_VALUES_THRESHOLD
-#ifdef HAVE_casesi
-#define CASE_VALUES_THRESHOLD (HAVE_casesi ? 4 : 5)
-#else
-      /* If machine does not have a case insn that compares the
-        bounds, this means extra overhead for dispatch tables
-        which raises the threshold for using them.  */
-#define CASE_VALUES_THRESHOLD 5
-#endif /* HAVE_casesi */
-#endif /* CASE_VALUES_THRESHOLD */
-
-      else if (count < CASE_VALUES_THRESHOLD
+      else if (count < case_values_threshold ()
               || compare_tree_int (range, 10 * count) > 0
               /* RANGE may be signed, and really large ranges will show up
                  as negative numbers.  */
@@ -5338,12 +5265,6 @@ expand_end_case (orig_index)
               || flag_pic
 #endif
               || TREE_CODE (index_expr) == INTEGER_CST
-              /* These will reduce to a constant.  */
-              || (TREE_CODE (index_expr) == CALL_EXPR
-                  && TREE_CODE (TREE_OPERAND (index_expr, 0)) == ADDR_EXPR
-                  && TREE_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == FUNCTION_DECL
-                  && DECL_BUILT_IN_CLASS (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_NORMAL
-                  && DECL_FUNCTION_CODE (TREE_OPERAND (TREE_OPERAND (index_expr, 0), 0)) == BUILT_IN_CLASSIFY_TYPE)
               || (TREE_CODE (index_expr) == COMPOUND_EXPR
                   && TREE_CODE (TREE_OPERAND (index_expr, 1)) == INTEGER_CST))
        {
@@ -5355,14 +5276,12 @@ expand_end_case (orig_index)
             generate the conversion.  */
 
          if (GET_MODE_CLASS (GET_MODE (index)) == MODE_INT
-             && (cmp_optab->handlers[(int) GET_MODE (index)].insn_code
-                 == CODE_FOR_nothing))
+             && ! have_insn_for (COMPARE, GET_MODE (index)))
            {
              enum machine_mode wider_mode;
              for (wider_mode = GET_MODE (index); wider_mode != VOIDmode;
                   wider_mode = GET_MODE_WIDER_MODE (wider_mode))
-               if (cmp_optab->handlers[(int) wider_mode].insn_code
-                   != CODE_FOR_nothing)
+               if (have_insn_for (COMPARE, wider_mode))
                  {
                    index = convert_to_mode (wider_mode, index, unsignedp);
                    break;
@@ -5430,100 +5349,15 @@ expand_end_case (orig_index)
        }
       else
        {
-         int win = 0;
-#ifdef HAVE_casesi
-         if (HAVE_casesi)
-           {
-             enum machine_mode index_mode = SImode;
-             int index_bits = GET_MODE_BITSIZE (index_mode);
-             rtx op1, op2;
-             enum machine_mode op_mode;
-
-             /* Convert the index to SImode.  */
-             if (GET_MODE_BITSIZE (TYPE_MODE (index_type))
-                 > GET_MODE_BITSIZE (index_mode))
-               {
-                 enum machine_mode omode = TYPE_MODE (index_type);
-                 rtx rangertx = expand_expr (range, NULL_RTX, VOIDmode, 0);
-
-                 /* We must handle the endpoints in the original mode.  */
-                 index_expr = build (MINUS_EXPR, index_type,
-                                     index_expr, minval);
-                 minval = integer_zero_node;
-                 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
-                 emit_cmp_and_jump_insns (rangertx, index, LTU, NULL_RTX,
-                                          omode, 1, 0, default_label);
-                 /* Now we can safely truncate.  */
-                 index = convert_to_mode (index_mode, index, 0);
-               }
-             else
-               {
-                 if (TYPE_MODE (index_type) != index_mode)
-                   {
-                     index_expr = convert (type_for_size (index_bits, 0),
-                                           index_expr);
-                     index_type = TREE_TYPE (index_expr);
-                   }
-
-                 index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
-               }
-             emit_queue ();
-             index = protect_from_queue (index, 0);
-             do_pending_stack_adjust ();
-
-             op_mode = insn_data[(int) CODE_FOR_casesi].operand[0].mode;
-             if (! (*insn_data[(int) CODE_FOR_casesi].operand[0].predicate)
-                 (index, op_mode))
-               index = copy_to_mode_reg (op_mode, index);
-
-             op1 = expand_expr (minval, NULL_RTX, VOIDmode, 0);
-
-             op_mode = insn_data[(int) CODE_FOR_casesi].operand[1].mode;
-             op1 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (minval)),
-                                  op1, TREE_UNSIGNED (TREE_TYPE (minval)));
-             if (! (*insn_data[(int) CODE_FOR_casesi].operand[1].predicate)
-                 (op1, op_mode))
-               op1 = copy_to_mode_reg (op_mode, op1);
-
-             op2 = expand_expr (range, NULL_RTX, VOIDmode, 0);
-
-             op_mode = insn_data[(int) CODE_FOR_casesi].operand[2].mode;
-             op2 = convert_modes (op_mode, TYPE_MODE (TREE_TYPE (range)),
-                                  op2, TREE_UNSIGNED (TREE_TYPE (range)));
-             if (! (*insn_data[(int) CODE_FOR_casesi].operand[2].predicate)
-                 (op2, op_mode))
-               op2 = copy_to_mode_reg (op_mode, op2);
-
-             emit_jump_insn (gen_casesi (index, op1, op2,
-                                         table_label, default_label));
-             win = 1;
-           }
-#endif
-#ifdef HAVE_tablejump
-         if (! win && HAVE_tablejump)
+         if (! try_casesi (index_type, index_expr, minval, range,
+                           table_label, default_label))
            {
              index_type = thiscase->data.case_stmt.nominal_type;
-             index_expr = fold (build (MINUS_EXPR, index_type,
-                                       convert (index_type, index_expr),
-                                       convert (index_type, minval)));
-             index = expand_expr (index_expr, NULL_RTX, VOIDmode, 0);
-             emit_queue ();
-             index = protect_from_queue (index, 0);
-             do_pending_stack_adjust ();
-
-             do_tablejump (index, TYPE_MODE (index_type),
-                           convert_modes (TYPE_MODE (index_type),
-                                          TYPE_MODE (TREE_TYPE (range)),
-                                          expand_expr (range, NULL_RTX,
-                                                       VOIDmode, 0),
-                                          TREE_UNSIGNED (TREE_TYPE (range))),
-                           table_label, default_label);
-             win = 1;
+             if (! try_tablejump (index_type, index_expr, minval, range,
+                                  table_label, default_label))
+               abort ();
            }
-#endif
-         if (! win)
-           abort ();
-
+         
          /* Get table of labels to jump to, in order of case index.  */
 
          ncases = TREE_INT_CST_LOW (range) + 1;
@@ -5573,8 +5407,10 @@ expand_end_case (orig_index)
 #endif
        }
 
-      before_case = squeeze_notes (NEXT_INSN (before_case), get_last_insn ());
-      reorder_insns (before_case, get_last_insn (),
+      before_case = NEXT_INSN (before_case);
+      end = get_last_insn ();
+      squeeze_notes (&before_case, &end);
+      reorder_insns (before_case, end,
                     thiscase->data.case_stmt.start);
     }
   else
@@ -6164,20 +6000,6 @@ emit_case_nodes (index, node, default_label, index_type)
       else if (node->right == 0 && node->left != 0)
        {
          /* Just one subtree, on the left.  */
-
-#if 0 /* The following code and comment were formerly part
-        of the condition here, but they didn't work
-        and I don't understand what the idea was.  -- rms.  */
-         /* If our "most probable entry" is less probable
-            than the default label, emit a jump to
-            the default label using condition codes
-            already lying around.  With no right branch,
-            a branch-greater-than will get us to the default
-            label correctly.  */
-         if (use_cost_table
-             && COST_TABLE (TREE_INT_CST_LOW (node->high)) < 12)
-           ;
-#endif /* 0 */
          if (node->left->left || node->left->right
              || !tree_int_cst_equal (node->left->low, node->left->high))
            {
@@ -6374,13 +6196,14 @@ emit_case_nodes (index, node, default_label, index_type)
              tree type = type_for_mode (mode, unsignedp);
              tree low = build1 (CONVERT_EXPR, type, node->low);
              tree high = build1 (CONVERT_EXPR, type, node->high);
-             rtx new_index, new_bound;
+             rtx low_rtx, new_index, new_bound;
 
              /* Instead of doing two branches, emit one unsigned branch for
                 (index-low) > (high-low).  */
-             new_index = expand_binop (mode, sub_optab, index,
-                                       expand_expr (low, NULL_RTX, mode, 0),
-                                       NULL_RTX, unsignedp, OPTAB_WIDEN);
+             low_rtx = expand_expr (low, NULL_RTX, mode, 0);
+             new_index = expand_simple_binop (mode, MINUS, index, low_rtx,
+                                              NULL_RTX, unsignedp,
+                                              OPTAB_WIDEN);
              new_bound = expand_expr (fold (build (MINUS_EXPR, type,
                                                    high, low)),
                                       NULL_RTX, mode, 0);