diff mbox

centralize builtin function type building

Message ID 20110422185831.GB10567@hungry-tiger.westford.ibm.com
State New
Headers show

Commit Message

Michael Meissner April 22, 2011, 6:58 p.m. UTC
On Thu, Apr 21, 2011 at 11:04:47AM -0400, Nathan Froyd wrote:
> This patch does two things:
> 
> - centralizes some infrastructure for defining builtin function types
>   for frontends by providing a common function that
>   DEF_FUNCTION_TYPE_FOO macros can call; and
> 
> - in order to do that well, it also introduces
>   build{,_varargs}_function_type_array for cases when
>   build_function_type_list's interface doesn't work so well.
> 
> build_function_type_list could have been used instead, but it would lose
> the error_mark_node handling provided in the C/C++/Ada/LTO frontends.
> This new interface will be necessary for eliminating other uses of
> build_function_type anyway.
> 
> It would have been easier to move all of the builtin-types stuff into
> the middle-end, but Fortran doesn't use builtin-types.def.  Even if it
> did, I suppose it's possible that some new front-end could have its own
> set of builtin types, so I'm leaving things as they are.
> 
> The new functions can eliminate some of the games that were played with
> the recent backend changes to use build_function_type_list; if this
> patch is approved, I'll make the (currently uncommitted) patches that
> could use build_function_type_array do so.
> 
> Bootstrap and testing in progress on x86_64-unknown-linux-gnu.  OK to
> commit if successful?

Now that I've looked at the patch, a couple of things jump out:

1) For the DEF_FUNCTION_* replacements, the lines exceed the normal 79
   character limits we use as coding guidelines.

2) I'm not a fan of having a varargs function with an explicit count.  I tend
   to prefer a marker element (like NULL_TREE) as the last element.  In this
   case, since it is being used in macros that do have fixed elements, it isn't
   a problem.

3) I'm also not a fan of passing the index into the type array, instead of a
   tree value to the call.  If you pass a tree, then it allows MD builtins to
   call it before we switch to having the MD and front end builtins share the
   bultin index.

I'm enclosing the beginnings of the patch that I was working on to allow the MD
to specify *.def files to be included in the master builtin list.  Obviously we
need to tie in the front end builtins into the scheme.  I've been waiting to
see what Kenny Z was doing in his patches before continuing out.

Comments

Nathan Froyd April 22, 2011, 7:26 p.m. UTC | #1
On Fri, Apr 22, 2011 at 02:58:31PM -0400, Michael Meissner wrote:
> On Thu, Apr 21, 2011 at 11:04:47AM -0400, Nathan Froyd wrote:
> > - centralizes some infrastructure for defining builtin function types
> >   for frontends by providing a common function that
> >   DEF_FUNCTION_TYPE_FOO macros can call; and
> > 
> > - in order to do that well, it also introduces
> >   build{,_varargs}_function_type_array for cases when
> >   build_function_type_list's interface doesn't work so well.
> 
> 1) For the DEF_FUNCTION_* replacements, the lines exceed the normal 79
>    character limits we use as coding guidelines.

Will fix.

> 2) I'm not a fan of having a varargs function with an explicit count.  I tend
>    to prefer a marker element (like NULL_TREE) as the last element.  In this
>    case, since it is being used in macros that do have fixed elements, it isn't
>    a problem.

We have both kinds of varargs usage in-tree; I think the explicit count
version ought to be preferred, as it makes sharing code between the
takes-varargs version and the takes-count-and-pointer (or the takes-VEC
or takes-std::vector) version easier.  (The explicit count version makes
future function overloading with takes-count-and-pointer more difficult,
though, and of course there's __attribute__((sentinel)) support for
varargs-with-marker functions.)

I suppose you could just write the macros to use
build_function_type_list instead, but it seems nice to delegate all the
accesses to someplace else.

> 3) I'm also not a fan of passing the index into the type array, instead of a
>    tree value to the call.  If you pass a tree, then it allows MD builtins to
>    call it before we switch to having the MD and front end builtins share the
>    bultin index.

Yes, I suppose so.

-Nathan
diff mbox

Patch

Index: gcc/tree.h
===================================================================
--- gcc/tree.h	(revision 171948)
+++ gcc/tree.h	(working copy)
@@ -1,6 +1,6 @@ 
 /* Front-end tree definitions for GNU compiler.
    Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -226,7 +226,7 @@  extern const char *const built_in_class_
 #define DEF_BUILTIN(ENUM, N, C, T, LT, B, F, NA, AT, IM, COND) ENUM,
 enum built_in_function
 {
-#include "builtins.def"
+#include "builtin-md.h"
 
   /* Complex division routines in libgcc.  These are done via builtins
      because emit_library_call_value can't handle complex values.  */
Index: gcc/builtins.c
===================================================================
--- gcc/builtins.c	(revision 171947)
+++ gcc/builtins.c	(working copy)
@@ -69,7 +69,7 @@  const char *const built_in_class_names[4
 #define DEF_BUILTIN(X, N, C, T, LT, B, F, NA, AT, IM, COND) #X,
 const char * built_in_names[(int) END_BUILTINS] =
 {
-#include "builtins.def"
+#include "builtins_md.h"
 };
 #undef DEF_BUILTIN
 
Index: gcc/configure.ac
===================================================================
--- gcc/configure.ac	(revision 171947)
+++ gcc/configure.ac	(working copy)
@@ -4786,6 +4786,9 @@  AC_SUBST(c_target_objs)
 AC_SUBST(cxx_target_objs)
 AC_SUBST(fortran_target_objs)
 AC_SUBST(target_cpu_default)
+AC_SUBST(extra_builtin_attrs)
+AC_SUBST(extra_builtin_types)
+AC_SUBST(extra_builtin_md)
 
 AC_SUBST_FILE(language_hooks)
 
Index: gcc/config.gcc
===================================================================
--- gcc/config.gcc	(revision 171947)
+++ gcc/config.gcc	(working copy)
@@ -111,6 +111,12 @@ 
 #  extra_headers	List of used header files from the directory
 #			config/${cpu_type}.
 #
+#  extra_builtin_attrs	List of extra builtin attributes include files.
+#
+#  extra_builtin_types	List of extra builtin types include files.
+#
+#  extra_builtin_md	List of extra machine dependent builtin include files.
+#
 #  user_headers_inc_next_pre
 #			List of header file names of internal gcc header
 #			files, which should be prefixed by an include_next.
Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	(revision 171947)
+++ gcc/Makefile.in	(working copy)
@@ -484,6 +484,9 @@  host_xm_defines=@host_xm_defines@
 xm_file_list=@xm_file_list@
 xm_include_list=@xm_include_list@
 xm_defines=@xm_defines@
+extra_builtin_attrs=@extra_builtin_attrs@
+extra_builtin_types=@extra_builtin_types@
+extra_builtin_md=@extra_builtin_md@
 lang_checks=check-gcc
 lang_checks_parallelized=check-gcc
 # This lists a couple of test files that take most time during check-gcc.
@@ -887,9 +890,11 @@  RTL_H = $(RTL_BASE_H) genrtl.h vecir.h
 RTL_ERROR_H = $(RTL_H) $(DIAGNOSTIC_CORE_H)
 READ_MD_H = $(OBSTACK_H) $(HASHTAB_H) read-md.h
 PARAMS_H = params.h params.def
-BUILTINS_DEF = builtins.def sync-builtins.def omp-builtins.def
+BUILTIN_MD_H = builtin-md.h builtins.def sync-builtins.def omp-builtins.def $(extra_builtin_md)
+BUILTIN_TYPES_H = builtin-types.h builtin-types.def $(extra_builtin_types)
+BUILTIN_ATTRS_H = builtin-attrs.h builtin-attrs.def $(extra_builtin_attrs)
 TREE_H = tree.h all-tree.def tree.def c-family/c-common.def \
-	$(lang_tree_files) $(MACHMODE_H) tree-check.h $(BUILTINS_DEF) \
+	$(lang_tree_files) $(MACHMODE_H) tree-check.h $(BUILTIN_MD_H) \
 	$(INPUT_H) statistics.h $(VEC_H) treestruct.def $(HASHTAB_H) \
 	double-int.h alias.h $(SYMTAB_H) $(FLAGS_H) vecir.h \
 	$(REAL_H) $(FIXED_VALUE_H)
@@ -1667,6 +1672,9 @@  bconfig.h: cs-bconfig.h ; @true
 tconfig.h: cs-tconfig.h ; @true
 tm.h: cs-tm.h ; @true
 tm_p.h: cs-tm_p.h ; @true
+builtin-types.h: cs-builtin-types.h ; @true
+builtin-attrs.h: cs-builtin-attrs.h ; @true
+builtin-md.h: cs-builtin-md.h ; @true
 
 cs-config.h: Makefile
 	TARGET_CPU_DEFAULT="" \
@@ -1693,6 +1701,27 @@  cs-tm_p.h: Makefile
 	HEADERS="$(tm_p_include_list)" DEFINES="" \
 	$(SHELL) $(srcdir)/mkconfig.sh tm_p.h
 
+cs-builtin-attrs.h: Makefile
+	for inc in builtin-attrs.def $(extra_builtin_attrs); do \
+		echo "#include \"$$inc\""; \
+	done > tmp-builtin-attrs.h \
+	&& $(srcdir)/../move-if-change tmp-builtin-attrs.h builtin-attrs.h
+	touch cs-builtins-attrs.h
+
+cs-builtin-md.h: Makefile
+	for inc in builtins.def $(extra_builtin_md); do \
+		echo "#include \"$$inc\""; \
+	done > tmp-builtin-md.h \
+	&& $(srcdir)/../move-if-change tmp-builtin-md.h builtin-md.h
+	touch cs-builtin-md.h
+
+cs-builtin-types.h: Makefile
+	for inc in builtin-types.def $(extra_builtin_types); do \
+		echo "#include \"$$inc\""; \
+	done > tmp-builtin-types.h \
+	&& $(srcdir)/../move-if-change tmp-builtin-types.h builtin-types.h
+	touch cs-builtin-types.h
+
 # Don't automatically run autoconf, since configure.ac might be accidentally
 # newer than configure.  Also, this writes into the source directory which
 # might be on a read-only file system.  If configured for maintainer mode
@@ -2090,11 +2119,11 @@  lto-wrapper.o: lto-wrapper.c $(CONFIG_H)
 c-family/c-common.o : c-family/c-common.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
 	$(TM_H) $(TREE_H) \
 	$(OBSTACK_H) $(C_COMMON_H) $(FLAGS_H) toplev.h output.h $(C_PRAGMA_H) \
-	$(GGC_H) builtin-types.def builtin-attrs.def \
+	$(GGC_H) $(BUILTIN_TYPES_H) $(BUILTIN_ATTRS_H) \
 	$(DIAGNOSTIC_H) langhooks.h c-family/c-objc.h \
 	$(TARGET_H) tree-iterator.h langhooks.h tree-mudflap.h \
 	intl.h $(OPTS_H) $(CPPLIB_H) $(TREE_INLINE_H) $(HASHTAB_H) \
-	$(BUILTINS_DEF) $(CGRAPH_H) $(BASIC_BLOCK_H) $(TARGET_DEF_H) \
+	$(BUILTIN_MD_H) $(CGRAPH_H) $(BASIC_BLOCK_H) $(TARGET_DEF_H) \
 	$(LIBFUNCS_H) \
 	gt-c-family-c-common.h
 
@@ -2898,7 +2927,7 @@  builtins.o : builtins.c $(CONFIG_H) $(SY
    $(EXPR_H) $(OPTABS_H) insn-config.h $(RECOG_H) output.h typeclass.h \
    hard-reg-set.h $(DIAGNOSTIC_CORE_H) hard-reg-set.h $(EXCEPT_H) \
    $(TM_P_H) $(PREDICT_H) $(LIBFUNCS_H) langhooks.h $(BASIC_BLOCK_H) \
-   tree-mudflap.h realmpfr.h $(BUILTINS_DEF) $(MACHMODE_H) \
+   tree-mudflap.h realmpfr.h $(BUILTIN_MD_H) $(MACHMODE_H) \
    $(DIAGNOSTIC_CORE_H) $(TREE_FLOW_H) value-prof.h
 calls.o : calls.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \
    $(TREE_H) $(FLAGS_H) $(EXPR_H) $(OPTABS_H) langhooks.h $(TARGET_H) \
@@ -4411,6 +4440,7 @@  clean: mostlyclean lang.clean
 	-rm -f libgcc_s*
 	-rm -f libunwind*
 	-rm -f config.h tconfig.h bconfig.h tm_p.h tm.h
+	-rm -f builtin-types.h builtin-attrs.h builtin-md.h
 	-rm -f options.c options.h optionlist
 	-rm -f cs-*
 	-rm -f doc/*.dvi
Index: gcc/configure
===================================================================
--- gcc/configure	(revision 171947)
+++ gcc/configure	(working copy)
@@ -608,6 +608,9 @@  PPLINC
 PPLLIBS
 GMPINC
 GMPLIBS
+extra_builtin_md
+extra_builtin_types
+extra_builtin_attrs
 target_cpu_default
 fortran_target_objs
 cxx_target_objs
@@ -17505,7 +17508,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17508 "configure"
+#line 17511 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17611,7 +17614,7 @@  else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 17614 "configure"
+#line 17617 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -26226,6 +26229,9 @@  fi
 
 
 
+
+
+
 # Echo link setup.
 if test x${build} = x${host} ; then
   if test x${host} = x${target} ; then
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 171947)
+++ gcc/c-family/c-common.c	(working copy)
@@ -4333,7 +4333,7 @@  enum built_in_attribute
 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
-#include "builtin-attrs.def"
+#include "builtin-attrs.h"
 #undef DEF_ATTR_NULL_TREE
 #undef DEF_ATTR_INT
 #undef DEF_ATTR_IDENT
@@ -4364,7 +4364,7 @@  enum c_builtin_type
 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
   NAME,
 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
-#include "builtin-types.def"
+#include "builtin-types.h"
 #undef DEF_PRIMITIVE_TYPE
 #undef DEF_FUNCTION_TYPE_0
 #undef DEF_FUNCTION_TYPE_1
@@ -4472,7 +4472,7 @@  c_define_builtins (tree va_list_ref_type
 #define DEF_POINTER_TYPE(ENUM, TYPE) \
   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
 
-#include "builtin-types.def"
+#include "builtin-types.h"
 
 #undef DEF_PRIMITIVE_TYPE
 #undef DEF_FUNCTION_TYPE_1
@@ -4500,7 +4500,7 @@  c_define_builtins (tree va_list_ref_type
 		   builtin_types[(int) LIBTYPE],                        \
 		   BOTH_P, FALLBACK_P, NONANSI_P,                       \
 		   built_in_attributes[(int) ATTRS], IMPLICIT);
-#include "builtins.def"
+#include "builtin-md.h"
 #undef DEF_BUILTIN
 
   targetm.init_builtins ();
@@ -5668,7 +5668,7 @@  c_init_attributes (void)
     = tree_cons (built_in_attributes[(int) PURPOSE],	\
 		 built_in_attributes[(int) VALUE],	\
 		 built_in_attributes[(int) CHAIN]);
-#include "builtin-attrs.def"
+#include "builtin-attrs.h"
 #undef DEF_ATTR_NULL_TREE
 #undef DEF_ATTR_INT
 #undef DEF_ATTR_IDENT
Index: gcc/lto/lto-lang.c
===================================================================
--- gcc/lto/lto-lang.c	(revision 171948)
+++ gcc/lto/lto-lang.c	(working copy)
@@ -1,5 +1,5 @@ 
 /* Language-dependent hooks for LTO.
-   Copyright 2009, 2010 Free Software Foundation, Inc.
+   Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
    Contributed by CodeSourcery, Inc.
 
 This file is part of GCC.
@@ -98,7 +98,7 @@  enum built_in_attribute
 #define DEF_ATTR_INT(ENUM, VALUE) ENUM,
 #define DEF_ATTR_IDENT(ENUM, STRING) ENUM,
 #define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM,
-#include "builtin-attrs.def"
+#include "builtin-attrs.h"
 #undef DEF_ATTR_NULL_TREE
 #undef DEF_ATTR_INT
 #undef DEF_ATTR_IDENT
@@ -129,7 +129,7 @@  enum lto_builtin_type
 #define DEF_FUNCTION_TYPE_VAR_5(NAME, RETURN, ARG1, ARG2, ARG3, ARG4, ARG6) \
   NAME,
 #define DEF_POINTER_TYPE(NAME, TYPE) NAME,
-#include "builtin-types.def"
+#include "builtin-types.h"
 #undef DEF_PRIMITIVE_TYPE
 #undef DEF_FUNCTION_TYPE_0
 #undef DEF_FUNCTION_TYPE_1
@@ -160,7 +160,7 @@  static GTY(()) tree intmax_type_node;
 static GTY(()) tree uintmax_type_node;
 static GTY(()) tree signed_size_type_node;
 
-/* Flags needed to process builtins.def.  */
+/* Flags needed to process builtin-md.h.  */
 int flag_isoc94;
 int flag_isoc99;
 
@@ -474,7 +474,7 @@  def_fn_type (builtin_type def, builtin_t
   va_end (list);
 }
 
-/* Used to help initialize the builtin-types.def table.  When a type of
+/* Used to help initialize the builtin-types.h table.  When a type of
    the correct size doesn't exist, use error_mark_node instead of NULL.
    The later results in segfaults even when a decl using the type doesn't
    get invoked.  */
@@ -534,7 +534,7 @@  lto_init_attributes (void)
     = tree_cons (built_in_attributes[(int) PURPOSE],	\
 		 built_in_attributes[(int) VALUE],	\
 		 built_in_attributes[(int) CHAIN]);
-#include "builtin-attrs.def"
+#include "builtin-attrs.h"
 #undef DEF_ATTR_NULL_TREE
 #undef DEF_ATTR_INT
 #undef DEF_ATTR_IDENT
@@ -542,7 +542,7 @@  lto_init_attributes (void)
 }
 
 /* Create builtin types and functions.  VA_LIST_REF_TYPE_NODE and
-   VA_LIST_ARG_TYPE_NODE are used in builtin-types.def.  */
+   VA_LIST_ARG_TYPE_NODE are used in builtin-types.h.  */
 
 static void
 lto_define_builtins (tree va_list_ref_type_node ATTRIBUTE_UNUSED,
@@ -583,7 +583,7 @@  lto_define_builtins (tree va_list_ref_ty
 #define DEF_POINTER_TYPE(ENUM, TYPE) \
   builtin_types[(int) ENUM] = build_pointer_type (builtin_types[(int) TYPE]);
 
-#include "builtin-types.def"
+#include "builtin-types.h"
 
 #undef DEF_PRIMITIVE_TYPE
 #undef DEF_FUNCTION_TYPE_1
@@ -609,7 +609,7 @@  lto_define_builtins (tree va_list_ref_ty
       def_builtin_1 (ENUM, NAME, CLASS, builtin_types[(int) TYPE],	\
 		     builtin_types[(int) LIBTYPE], BOTH_P, FALLBACK_P,	\
 		     NONANSI_P, built_in_attributes[(int) ATTRS], IMPLICIT);
-#include "builtins.def"
+#include "builtin-md.h"
 #undef DEF_BUILTIN
 }
 
@@ -1025,7 +1025,7 @@  lto_register_builtin_type (tree type, co
 }
 
 /* Build nodes that would have be created by the C front-end; necessary
-   for including builtin-types.def and ultimately builtins.def.  */
+   for including builtin-types.h and ultimately builtin-md.h.  */
 
 static void
 lto_build_c_type_nodes (void)
Index: gcc/lto/Make-lang.in
===================================================================
--- gcc/lto/Make-lang.in	(revision 171947)
+++ gcc/lto/Make-lang.in	(working copy)
@@ -1,5 +1,5 @@ 
 # Top level -*- makefile -*- fragment for LTO
-#   Copyright (C) 2009, 2010
+#   Copyright (C) 2009, 2010, 2011
 #   Free Software Foundation, Inc.
 
 #This file is part of GCC.
@@ -79,7 +79,8 @@  $(LTO_EXE): $(LTO_OBJS) $(BACKEND) $(LIB
 lto/lto-lang.o: lto/lto-lang.c $(CONFIG_H) coretypes.h debug.h \
 	flags.h $(GGC_H) langhooks.h $(LANGHOOKS_DEF_H) $(SYSTEM_H) \
 	$(TARGET_H) $(LTO_H) $(GIMPLE_H) gtype-lto.h gt-lto-lto-lang.h \
-	$(EXPR_H) $(LTO_STREAMER_H)
+	$(EXPR_H) $(LTO_STREAMER_H) $(BUILTIN_ATTRS_H) $(BUILTIN_TYPES_H) \
+	$(BUILTIN_MD_H)
 lto/lto.o: lto/lto.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(OPTS_H) \
 	toplev.h $(TREE_H) $(DIAGNOSTIC_CORE_H) $(TM_H) \
 	$(CGRAPH_H) $(GGC_H) tree-ssa-operands.h $(TREE_PASS_H) \