This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] builtins.c: Change fold_builtin to take decomposedarguments of CALL_EXPR.


Hi,

Attached is a patch to change fold_builtin to take decomposed
arguments of CALL_EXPR.

This is probably the last patch to make builtins.c ready for
fold_builtN.

Tested on i686-pc-linux-gnu on top of

http://gcc.gnu.org/ml/gcc-patches/2005-03/msg01977.html

OK to apply?

Kazu Hirata

2005-03-21  Kazu Hirata  <kazu@cs.umass.edu>

	* builtins.c (fold_builtin): Take decomposed arguments of
	CALL_EXPR.
	* fold-const.c (fold_ternary): Update a call to fold_builtin.
	* gimplify.c (gimplify_call_expr): Likewise.
	* tree-ssa-ccp.c (ccp_fold, ccp_fold_builtin): Likewise.
	* tree.h: Update the prototype of fold_builtin.

diff -u builtins.c builtins.c
--- builtins.c	21 Mar 2005 03:44:38 -0000
+++ builtins.c	21 Mar 2005 03:42:27 -0000
@@ -8296,12 +8296,9 @@
    call node earlier than the warning is generated.  */
 
 tree
-fold_builtin (tree exp, bool ignore)
+fold_builtin (tree fndecl, tree arglist, bool ignore)
 {
-  tree fndecl = get_callee_fndecl (exp);
-  tree arglist = TREE_OPERAND (exp, 1);
-
-  exp = fold_builtin_1 (fndecl, arglist, ignore);
+  tree exp = fold_builtin_1 (fndecl, arglist, ignore);
   if (exp)
     {
       /* ??? Don't clobber shared nodes such as integer_zero_node.  */
only in patch2:
unchanged:
--- fold-const.c	19 Mar 2005 16:45:59 -0000	1.544
+++ fold-const.c	21 Mar 2005 03:42:29 -0000
@@ -9901,7 +9901,9 @@ fold_ternary (tree expr)
 	  && TREE_CODE (TREE_OPERAND (op0, 0)) == FUNCTION_DECL
 	  && DECL_BUILT_IN (TREE_OPERAND (op0, 0)))
 	{
-	  tree tmp = fold_builtin (t, false);
+	  tree fndecl = get_callee_fndecl (t);
+	  tree arglist = TREE_OPERAND (t, 1);
+	  tree tmp = fold_builtin (fndecl, arglist, false);
 	  if (tmp)
 	    return tmp;
 	}
only in patch2:
unchanged:
--- gimplify.c	14 Mar 2005 20:01:40 -0000	2.118
+++ gimplify.c	21 Mar 2005 03:42:30 -0000
@@ -1744,7 +1744,9 @@ gimplify_call_expr (tree *expr_p, tree *
   decl = get_callee_fndecl (*expr_p);
   if (decl && DECL_BUILT_IN (decl))
     {
-      tree new = fold_builtin (*expr_p, !want_value);
+      tree fndecl = get_callee_fndecl (*expr_p);
+      tree arglist = TREE_OPERAND (*expr_p, 1);
+      tree new = fold_builtin (fndecl, arglist, !want_value);
 
       if (new && new != *expr_p)
 	{
@@ -1758,8 +1760,6 @@ gimplify_call_expr (tree *expr_p, tree *
       if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
 	  && DECL_FUNCTION_CODE (decl) == BUILT_IN_VA_START)
         {
-	  tree arglist = TREE_OPERAND (*expr_p, 1);
-	  
 	  if (!arglist || !TREE_CHAIN (arglist))
 	    {
 	      error ("too few arguments to function %<va_start%>");
@@ -1802,7 +1802,9 @@ gimplify_call_expr (tree *expr_p, tree *
   /* Try this again in case gimplification exposed something.  */
   if (ret != GS_ERROR && decl && DECL_BUILT_IN (decl))
     {
-      tree new = fold_builtin (*expr_p, !want_value);
+      tree fndecl = get_callee_fndecl (*expr_p);
+      tree arglist = TREE_OPERAND (*expr_p, 1);
+      tree new = fold_builtin (fndecl, arglist, !want_value);
 
       if (new && new != *expr_p)
 	{
only in patch2:
unchanged:
--- tree-ssa-ccp.c	16 Mar 2005 14:45:14 -0000	2.59
+++ tree-ssa-ccp.c	21 Mar 2005 03:42:31 -0000
@@ -938,6 +938,7 @@ ccp_fold (tree stmt)
       if (NUM_USES (uses) != 0)
 	{
 	  tree *orig;
+	  tree fndecl, arglist;
 	  size_t i;
 
 	  /* Preserve the original values of every operand.  */
@@ -947,7 +948,9 @@ ccp_fold (tree stmt)
 
 	  /* Substitute operands with their values and try to fold.  */
 	  replace_uses_in (stmt, NULL);
-	  retval = fold_builtin (rhs, false);
+	  fndecl = get_callee_fndecl (rhs);
+	  arglist = TREE_OPERAND (rhs, 1);
+	  retval = fold_builtin (fndecl, arglist, false);
 
 	  /* Restore operands to their original form.  */
 	  for (i = 0; i < NUM_USES (uses); i++)
@@ -1929,7 +1932,9 @@ ccp_fold_builtin (tree stmt, tree fn)
 
   /* First try the generic builtin folder.  If that succeeds, return the
      result directly.  */
-  result = fold_builtin (fn, ignore);
+  callee = get_callee_fndecl (fn);
+  arglist = TREE_OPERAND (fn, 1);
+  result = fold_builtin (callee, arglist, ignore);
   if (result)
   {
     if (ignore)
@@ -1938,13 +1943,11 @@ ccp_fold_builtin (tree stmt, tree fn)
   }
 
   /* Ignore MD builtins.  */
-  callee = get_callee_fndecl (fn);
   if (DECL_BUILT_IN_CLASS (callee) == BUILT_IN_MD)
     return NULL_TREE;
 
   /* If the builtin could not be folded, and it has no argument list,
      we're done.  */
-  arglist = TREE_OPERAND (fn, 1);
   if (!arglist)
     return NULL_TREE;
 
only in patch2:
unchanged:
--- tree.h	16 Mar 2005 17:14:57 -0000	1.703
+++ tree.h	21 Mar 2005 03:42:31 -0000
@@ -3563,7 +3563,7 @@ extern enum tree_code swap_tree_comparis
 extern bool ptr_difference_const (tree, tree, HOST_WIDE_INT *);
 
 /* In builtins.c */
-extern tree fold_builtin (tree, bool);
+extern tree fold_builtin (tree, tree, bool);
 extern tree fold_builtin_fputs (tree, bool, bool, tree);
 extern tree fold_builtin_strcpy (tree, tree, tree);
 extern tree fold_builtin_strncpy (tree, tree, tree);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]