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] fold-const.c: Reorganize fold - Part 18/n (Take 2)


Hi,

Attached is part 18 of my patch to reorganize fold.

This patch has been revised to update the comment above fold_ternary.

Other than that, the original description still applies.

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

Roger Sayle suggested offline that I should retain a call to
get_callee_fndecl in the CALL_EXPR case of fold_ternary, but I don't
think we need that.  If we "inline" get_callee_fndecl into the
following piece of code and optimize away useless code,

  if (TREE_CODE (op0) == ADDR_EXPR
      && TREE_CODE (TREE_OPERAND (op0, 0)) == FUNCTION_DECL
      && DECL_BUILT_IN (TREE_OPERAND (op0, 0)))
    {
      tree fndecl = get_callee_fndecl (t);

we would get

  if (TREE_CODE (op0) == ADDR_EXPR
      && TREE_CODE (TREE_OPERAND (op0, 0)) == FUNCTION_DECL
      && DECL_BUILT_IN (TREE_OPERAND (op0, 0)))
    {
      tree fndecl = TREE_OPERAND (op0, 0);

That is, we don't any benefit of propagating DECL_INITIAL into a call
site, etc.  The Java front end does define
LANG_HOOKS_GET_CALLEE_FNDECL, but it's currently disabled.  That is,
it always returns NULL_TREE.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

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

	* fold-const.c (fold_ternary): Take decomposed arguments of
	CALL_EXPR.
	(fold): Update a call to fold_ternary.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.547
diff -u -d -p -r1.547 fold-const.c
--- fold-const.c	22 Mar 2005 06:01:05 -0000	1.547
+++ fold-const.c	22 Mar 2005 15:09:19 -0000
@@ -9693,28 +9693,20 @@ fold_binary (enum tree_code code, tree t
     } /* switch (code) */
 }
 
-/* Fold a ternary expression EXPR.  Return the folded expression if
-   folding is successful.  Otherwise, return the original
-   expression.  */
+/* Fold a ternary expression of code CODE and type TYPE with operands
+   OP0, OP1, and OP2.  Return the folded expression if folding is
+   successful.  Otherwise, return NULL_TREE.  */
 
 static tree
-fold_ternary (tree expr)
+fold_ternary (enum tree_code code, tree type, tree op0, tree op1, tree op2)
 {
-  const tree t = expr;
-  const tree type = TREE_TYPE (expr);
   tree tem;
-  tree op0, op1, op2;
   tree arg0 = NULL_TREE, arg1 = NULL_TREE;
-  enum tree_code code = TREE_CODE (t);
   enum tree_code_class kind = TREE_CODE_CLASS (code);
 
   gcc_assert (IS_EXPR_CODE_CLASS (kind)
 	      && TREE_CODE_LENGTH (code) == 3);
 
-  op0 = TREE_OPERAND (t, 0);
-  op1 = TREE_OPERAND (t, 1);
-  op2 = TREE_OPERAND (t, 2);
-
   /* Strip any conversions that don't change the mode.  This is safe
      for every expression, except for a comparison expression because
      its signedness is derived from its operands.  So, in the latter
@@ -9909,8 +9901,8 @@ fold_ternary (tree expr)
 	  && TREE_CODE (TREE_OPERAND (op0, 0)) == FUNCTION_DECL
 	  && DECL_BUILT_IN (TREE_OPERAND (op0, 0)))
 	{
-	  tree fndecl = get_callee_fndecl (t);
-	  tree arglist = TREE_OPERAND (t, 1);
+	  tree fndecl = TREE_OPERAND (op0, 0);
+	  tree arglist = op1;
 	  tree tmp = fold_builtin (fndecl, arglist, false);
 	  if (tmp)
 	    return tmp;
@@ -9950,7 +9942,7 @@ fold (tree expr)
   if (IS_EXPR_CODE_CLASS (kind))
     {
       tree type = TREE_TYPE (t);
-      tree op0, op1;
+      tree op0, op1, op2;
 
       switch (TREE_CODE_LENGTH (code))
 	{
@@ -9964,7 +9956,10 @@ fold (tree expr)
 	  tem = fold_binary (code, type, op0, op1);
 	  return tem ? tem : expr;
 	case 3:
-	  tem = fold_ternary (expr);
+	  op0 = TREE_OPERAND (t, 0);
+	  op1 = TREE_OPERAND (t, 1);
+	  op2 = TREE_OPERAND (t, 2);
+	  tem = fold_ternary (code, type, op0, op1, op2);
 	  return tem ? tem : expr;
 	default:
 	  break;


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