rtl.def (CONSTANT_P_RTX): New.
authorRichard Henderson <rth@cygnus.com>
Tue, 30 Jun 1998 16:19:11 +0000 (09:19 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Tue, 30 Jun 1998 16:19:11 +0000 (09:19 -0700)
        * rtl.def (CONSTANT_P_RTX): New.
        * rtl.h (CONSTANT_P): Recognize it.
        * cse.c (fold_rtx): Eliminate it.
        * expr.c (can_handle_constant_p): New variable.
        (init_expr_once): Initialize it.
        (expand_builtin): Generate CONSTANT_P_RTX if the expression is not
        immediately recognizable as a constant.

From-SVN: r20846

gcc/ChangeLog
gcc/cse.c
gcc/expr.c
gcc/rtl.def
gcc/rtl.h

index c2308f687e6ce3c3cc3e76bdb82c22925a092fd3..59396a032a4de439f49faf7d4719d61361e9f4a7 100644 (file)
@@ -1,3 +1,19 @@
+Tue Jun 30 16:01:01 1998  Richard Henderson  <rth@cygnus.com>
+
+       * rtl.def (CONSTANT_P_RTX): New.
+       * rtl.h (CONSTANT_P): Recognize it.
+       * cse.c (fold_rtx): Eliminate it.
+       * expr.c (can_handle_constant_p): New variable.
+       (init_expr_once): Initialize it.
+       (expand_builtin): Generate CONSTANT_P_RTX if the expression is not
+       immediately recognizable as a constant.
+
+       * alpha.c (reg_or_6bit_operand): Recognize CONSTANT_P_RTX.
+       (reg_or_8bit_operand, cint8_operand, add_operand): Likewise.
+       (sext_add_operand, and_operand, or_operand): Likewise.
+       (reg_or_cint_operand, some_operand, input_operand): Likewise.
+       * alpha.h (PREDICATE_CODES): Add CONSTANT_P_RTX where needed.
+
 1998-06-30  Benjamin Kosnik  <bkoz@bliss.nabi.net>
 
         * dbxout.c (dbxout_type_methods): Remove warn_template_debugging.
index 868b7de33985204fafd573f79e309216bcd27661..bd2aa567d23a0098de5bab111f222a97dbea4f92 100644 (file)
--- a/gcc/cse.c
+++ b/gcc/cse.c
@@ -5715,6 +5715,12 @@ fold_rtx (x, insn)
                                        const_arg1 ? const_arg1 : folded_arg1,
                                        const_arg2 ? const_arg2 : XEXP (x, 2));
       break;
+
+    case 'x':
+      /* Always eliminate CONSTANT_P_RTX at this stage. */
+      if (code == CONSTANT_P_RTX)
+       return (const_arg0 ? const1_rtx : const0_rtx);
+      break;
     }
 
   return new ? new : x;
index 666d1ccc403148bf5654673b6de4a6632edc316f..79c1f9257bd463e6b7c547ad7795410c861d812b 100644 (file)
@@ -104,6 +104,11 @@ static rtx saveregs_value;
 /* Similarly for __builtin_apply_args.  */
 static rtx apply_args_value;
 
+/* Nonzero if the machine description has been fixed to accept
+   CONSTANT_P_RTX patterns.  We will emit a warning and continue
+   if we find we must actually use such a beast.  */
+static int can_handle_constant_p;
+
 /* Don't check memory usage, since code is being emitted to check a memory
    usage.  Used when flag_check_memory_usage is true, to avoid infinite
    recursion.  */
@@ -239,6 +244,7 @@ init_expr_once ()
 {
   rtx insn, pat;
   enum machine_mode mode;
+  int num_clobbers;
   rtx mem, mem1;
   char *free_point;
 
@@ -263,7 +269,6 @@ init_expr_once ()
     {
       int regno;
       rtx reg;
-      int num_clobbers;
 
       direct_load[(int) mode] = direct_store[(int) mode] = 0;
       PUT_MODE (mem, mode);
@@ -304,10 +309,18 @@ init_expr_once ()
          }
     }
 
+  /* Find out if CONSTANT_P_RTX is accepted.  */
+  SET_DEST (pat) = gen_rtx_REG (TYPE_MODE (integer_type_node),
+                               FIRST_PSEUDO_REGISTER);
+  SET_SRC (pat) = gen_rtx_CONSTANT_P_RTX (TYPE_MODE (integer_type_node),
+                                         SET_DEST (pat));
+  if (recog (pat, insn, &num_clobbers) >= 0)
+    can_handle_constant_p = 1;
+
   end_sequence ();
   obfree (free_point);
 }
-      
+
 /* This is run at the start of compiling a function.  */
 
 void
@@ -8566,10 +8579,34 @@ expand_builtin (exp, target, subtarget, mode, ignore)
          tree arg = TREE_VALUE (arglist);
 
          STRIP_NOPS (arg);
-         return (TREE_CODE_CLASS (TREE_CODE (arg)) == 'c'
-                 || (TREE_CODE (arg) == ADDR_EXPR
-                     && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST)
-                 ? const1_rtx : const0_rtx);
+         if (really_constant_p (arg)
+             || (TREE_CODE (arg) == ADDR_EXPR
+                 && TREE_CODE (TREE_OPERAND (arg, 0)) == STRING_CST))
+           return const1_rtx;
+
+         /* Only emit CONSTANT_P_RTX if CSE will be run. 
+            Moreover, we don't want to expand trees that have side effects,
+            as the original __builtin_constant_p did not evaluate its      
+            argument at all, and we would break existing usage by changing 
+            this.  This quirk was generally useful, eliminating a bit of hair
+            in the writing of the macros that use this function.  Now the    
+            same thing can be better accomplished in an inline function.  */
+
+         if (! cse_not_expected && ! TREE_SIDE_EFFECTS (arg))
+           {
+             /* Lazy fixup of old code: issue a warning and fail the test.  */
+             if (! can_handle_constant_p)
+               {
+                 warning ("Delayed evaluation of __builtin_constant_p not supported on this target.");
+                 warning ("Please report this as a bug to egcs-bugs@cygnus.com.");
+                 return const0_rtx;
+               }
+             return gen_rtx_CONSTANT_P_RTX (TYPE_MODE (integer_type_node),
+                                            expand_expr (arg, NULL_RTX,
+                                                         VOIDmode, 0));
+           }
+
+         return const0_rtx;
        }
 
     case BUILT_IN_FRAME_ADDRESS:
index a00d3f1d7c57adcd9bfd5616f3aeba9fea71e6e1..1e45157b450da3d14e6171e7725566bcb7bfa15b 100644 (file)
@@ -842,6 +842,11 @@ DEF_RTL_EXPR(RANGE_VAR, "range_var", "eti", 'x')
    0 is the live bitmap.  Operand 1 is the original block number.  */
 DEF_RTL_EXPR(RANGE_LIVE, "range_live", "bi", 'x')
 
+/* A unary `__builtin_constant_p' expression.  These are only emitted
+   during RTL generation, and then only if optimize > 0.  They are
+   eliminated by the first CSE pass. */
+DEF_RTL_EXPR(CONSTANT_P_RTX, "constant_p", "e", 'x')
+
 /*
 Local variables:
 mode:c
index a7eaaf8244d11d0a88df806d3a3ce14c698cdc5f..94a8360b3143dd9d888700f70b66afbb2ffc18d3 100644 (file)
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -219,7 +219,8 @@ typedef struct rtvec_def{
 #define CONSTANT_P(X)   \
   (GET_CODE (X) == LABEL_REF || GET_CODE (X) == SYMBOL_REF             \
    || GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE                \
-   || GET_CODE (X) == CONST || GET_CODE (X) == HIGH)
+   || GET_CODE (X) == CONST || GET_CODE (X) == HIGH                    \
+   || GET_CODE (X) == CONSTANT_P_RTX)
 
 /* General accessor macros for accessing the fields of an rtx.  */