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 to update builtins.c:builtin_mathfn_code()


With the recent addition of many new math builtins, the function
builtin_mathfn_code needs to be updated to handle the new cases.

The current implementation considers a builtin to be a "math" builtin
if it's signature has exactly one argument of REAL_TYPE, or exactly
two arguments both of REAL_TYPE if it happens to be POW or ATAN2.

However now the math builtins framework now has dozens of functions
with about 20 different signatures, so we don't want to enumerate all
combinations, essentially duplicating the info in builtins.def in a
seperate unmaintainable location.

Instead I changed builtin_mathfn_code to consider a builtin a "math"
builtin if any of it's arguments is a REAL_TYPE or COMPLEX_TYPE.
(Roger, let me know what you think of this approach.)  It should be
sufficient to extend detection to all the math builtins except perhaps
builtin nan or inf which don't have REAL or COMPLEX args.  This isn't
a loss because they aren't detected right now anyway.

If at some point someone needs builtin_mathfn_code to detect these
remaining functions, they can further extend it to check that the
return type is a REAL_TYPE, but I have no need for it right now and
this patch is a step forward in functionality and maintainability.

Bootstrapped on sparc-sun-solaris2.7 (minus C++ cause it won't build
as noted in several PRs) no regressions.  I also manually fed the
function several builtins, it correctly rejected builtin printf and
memcmp, but accepted builtins cabs.

Ok for mainline?

		Thanks,
		--Kaveh


2003-09-08  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtins.c (builtin_mathfn_code): Generalize to process builtins
	with any REAL_TYPE or COMPLEX_TYPE arguments.

diff -rup orig/egcc-CVS20030907/gcc/builtins.c egcc-CVS20030907/gcc/builtins.c
--- orig/egcc-CVS20030907/gcc/builtins.c	2003-09-04 20:02:32.000000000 -0400
+++ egcc-CVS20030907/gcc/builtins.c	2003-09-08 13:53:33.188239000 -0400
@@ -5390,11 +5390,11 @@ expand_builtin (tree exp, rtx target, rt
   return expand_call (exp, target, ignore);
 }
 
-/* Determine whether a tree node represents a call to a built-in
-   math function.  If the tree T is a call to a built-in function
-   taking a single real argument, then the return value is the
-   DECL_FUNCTION_CODE of the call, e.g. BUILT_IN_SQRT.  Otherwise
-   the return value is END_BUILTINS.  */
+/* Determine whether a tree node represents a call to a built-in math
+   function.  If the tree T is a call to a built-in function and any
+   one of it's arguments is a real or complex type, then the return
+   value is the DECL_FUNCTION_CODE of the call, e.g. BUILT_IN_SQRT.
+   Otherwise the return value is END_BUILTINS.  */
 
 enum built_in_function
 builtin_mathfn_code (tree t)
@@ -5411,33 +5411,13 @@ builtin_mathfn_code (tree t)
       || DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_MD)
     return END_BUILTINS;
 
-  arglist = TREE_OPERAND (t, 1);
-  if (! arglist
-      || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != REAL_TYPE)
-    return END_BUILTINS;
-
-  arglist = TREE_CHAIN (arglist);
-  switch (DECL_FUNCTION_CODE (fndecl))
-    {
-    case BUILT_IN_POW:
-    case BUILT_IN_POWF:
-    case BUILT_IN_POWL:
-    case BUILT_IN_ATAN2:
-    case BUILT_IN_ATAN2F:
-    case BUILT_IN_ATAN2L:
-      if (! arglist
-	  || TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) != REAL_TYPE
-	  || TREE_CHAIN (arglist))
-	return END_BUILTINS;
-      break;
-
-    default:
-      if (arglist)
-	return END_BUILTINS;
-      break;
-    }
-
-  return DECL_FUNCTION_CODE (fndecl);
+  /* Search for any one argument of REAL_TYPE or COMPLEX_TYPE.  */
+  for (arglist = TREE_OPERAND (t, 1); arglist; arglist = TREE_CHAIN (arglist))
+    if (TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == REAL_TYPE
+	|| TREE_CODE (TREE_TYPE (TREE_VALUE (arglist))) == COMPLEX_TYPE)
+      return DECL_FUNCTION_CODE (fndecl);
+ 
+  return END_BUILTINS;
 }
 
 /* Fold a call to __builtin_constant_p, if we know it will evaluate to a


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