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] built-in function infrastructure tweak


This patch makes a minor improvement in the way that built-in
functions are handled in the compiler.  The routine expand_builtin
in builtins.c is responsible for expanding builtin with a large
switch statement, either by inlining intrinsics or generating a
libcall to libc.  The current default behaviour of this switch
statement is to issue the error message "builtin not implemented".
The patch below changes this case to only generate an error if the
builtin was not defined with a fallback library function to call.
This allows many of the cases in the switch statement to be removed,
as they now have the new "default" behavior.

The major advantage of this approach is that its now possible to add
new builtins (recognized functions) to GCC by just adding an entry to
builtins.def (i.e. without changing any C code).   For example, the
standard C library routines "malloc" and "calloc" can now be marked
with __attribute__(malloc) [meaning the returned pointer doesn't alias
any other memory] with just a single change to builtins.def.


This patch has been tested with a complete bootstrap, all languages
except Ada and treelang, and "make -k check" on i686-pc-linux-gnu
with no new regressions.


Ok for mainline?


2002-07-27  Roger Sayle  <roger@eyesopen.com>

	* builtins.c (expand_builtin):  Change the default behavior to
	only issue an error if the builtin function doesn't have a
	fallback library call.  Remove several cases handled by the
	new default.


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.156
diff -c -3 -p -r1.156 builtins.c
*** builtins.c	23 Jul 2002 14:58:04 -0000	1.156
--- builtins.c	27 Jul 2002 16:29:32 -0000
*************** expand_builtin (exp, target, subtarget,
*** 3776,3784 ****
  	return target;
        break;

-     case BUILT_IN_FMOD:
-       break;
-
      case BUILT_IN_APPLY_ARGS:
        return expand_builtin_apply_args ();

--- 3776,3781 ----
*************** expand_builtin (exp, target, subtarget,
*** 3999,4013 ****
        expand_builtin_trap ();
        return const0_rtx;

-     case BUILT_IN_PUTCHAR:
-     case BUILT_IN_PUTS:
-     case BUILT_IN_FPUTC:
-     case BUILT_IN_FWRITE:
-     case BUILT_IN_PUTCHAR_UNLOCKED:
-     case BUILT_IN_PUTS_UNLOCKED:
-     case BUILT_IN_FPUTC_UNLOCKED:
-     case BUILT_IN_FWRITE_UNLOCKED:
-       break;
      case BUILT_IN_FPUTS:
        target = expand_builtin_fputs (arglist, ignore,/*unlocked=*/ 0);
        if (target)
--- 3996,4001 ----
*************** expand_builtin (exp, target, subtarget,
*** 4058,4066 ****
        return const0_rtx;


!     default:			/* just do library call, if unknown builtin */
!       error ("built-in function `%s' not currently supported",
! 	     IDENTIFIER_POINTER (DECL_NAME (fndecl)));
      }

    /* The switch statement above can drop through to cause the function
--- 4046,4055 ----
        return const0_rtx;


!     default:	/* just do library call, if unknown builtin */
!       if (!DECL_ASSEMBLER_NAME_SET_P (fndecl))
! 	error ("built-in function `%s' not currently supported",
! 	       IDENTIFIER_POINTER (DECL_NAME (fndecl)));
      }

    /* The switch statement above can drop through to cause the function

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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