From f18eca824c676b77605701ef51abb0bdd21af682 Mon Sep 17 00:00:00 2001 From: Ziemowit Laski Date: Wed, 24 Mar 2004 00:13:33 +0000 Subject: [PATCH] hooks.c (hook_constcharptr_tree_null): New hook. [gcc/ChangeLog] 2004-03-23 Ziemowit Laski * hooks.c (hook_constcharptr_tree_null): New hook. * hooks.h (hook_constcharptr_tree_null): New prototype. * target-def.h (TARGET_MANGLE_FUNDAMENTAL_TYPE): New target hook. * target.h (mangle_fundamental_type): New target hook. * config/rs6000/rs6000.c (TARGET_MANGLE_FUNDAMENTAL_TYPE): Point target hook at rs6000_mangle_fundamental_type. (rs6000_mangle_fundamental_type): New function. * doc/tm.texi (TARGET_MANGLE_FUNDAMENTAL_TYPE): Document. [gcc/cp/ChangeLog] 2004-03-23 Ziemowit Laski * Make-lang.in (cp/mangle.o): Depend on $(TARGET_H). * mangle.c (write_type): Add call to 'mangle_fundamental_type' target hook. [gcc/testsuite/ChangeLog] 2004-03-23 Ziemowit Laski * g++.dg/ext/altivec-7.C: New test. From-SVN: r79885 --- gcc/ChangeLog | 11 +++++++++ gcc/config/rs6000/rs6000.c | 19 +++++++++++++++ gcc/cp/ChangeLog | 6 +++++ gcc/cp/Make-lang.in | 3 ++- gcc/cp/mangle.c | 13 +++++++++++ gcc/doc/tm.texi | 28 ++++++++++++++++++++++ gcc/hooks.c | 7 ++++++ gcc/hooks.h | 2 +- gcc/target-def.h | 2 ++ gcc/target.h | 5 ++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/ext/altivec-7.C | 35 ++++++++++++++++++++++++++++ 12 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/altivec-7.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a16e70cb6c02..e38cf9c0e4a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2004-03-23 Ziemowit Laski + + * hooks.c (hook_constcharptr_tree_null): New hook. + * hooks.h (hook_constcharptr_tree_null): New prototype. + * target-def.h (TARGET_MANGLE_FUNDAMENTAL_TYPE): New target hook. + * target.h (mangle_fundamental_type): New target hook. + * config/rs6000/rs6000.c (TARGET_MANGLE_FUNDAMENTAL_TYPE): Point + target hook at rs6000_mangle_fundamental_type. + (rs6000_mangle_fundamental_type): New function. + * doc/tm.texi (TARGET_MANGLE_FUNDAMENTAL_TYPE): Document. + 2004-03-23 Zack Weinberg PR 12267, 12391, 12560, 13129, 14114, 14133 diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 8fa0ae6ab035..09bc1b9606ca 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -309,6 +309,7 @@ static void rs6000_assemble_visibility (tree, int); static int rs6000_ra_ever_killed (void); static tree rs6000_handle_longcall_attribute (tree *, tree, tree, int, bool *); static tree rs6000_handle_altivec_attribute (tree *, tree, tree, int, bool *); +static const char *rs6000_mangle_fundamental_type (tree); extern const struct attribute_spec rs6000_attribute_table[]; static void rs6000_set_default_type_attributes (tree); static void rs6000_output_function_prologue (FILE *, HOST_WIDE_INT); @@ -582,6 +583,9 @@ static const char alt_reg_names[][8] = #undef TARGET_EXPAND_BUILTIN #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin +#undef TARGET_MANGLE_FUNDAMENTAL_TYPE +#define TARGET_MANGLE_FUNDAMENTAL_TYPE rs6000_mangle_fundamental_type + #undef TARGET_INIT_LIBFUNCS #define TARGET_INIT_LIBFUNCS rs6000_init_libfuncs @@ -14903,6 +14907,21 @@ rs6000_handle_altivec_attribute (tree *node, tree name, tree args, return NULL_TREE; } +/* AltiVec defines four built-in scalar types that serve as vector + elements; we must teach the compiler how to mangle them. */ + +static const char * +rs6000_mangle_fundamental_type (tree type) +{ + if (type == bool_char_type_node) return "U6__boolc"; + if (type == bool_short_type_node) return "U6__bools"; + if (type == pixel_type_node) return "u7__pixel"; + if (type == bool_int_type_node) return "U6__booli"; + + /* For all other types, use normal C++ mangling. */ + return NULL; +} + /* Handle a "longcall" or "shortcall" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6ccd4b0e3f49..a1a6d6829af2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2004-03-23 Ziemowit Laski + + * Make-lang.in (cp/mangle.o): Depend on $(TARGET_H). + * mangle.c (write_type): Add call to 'mangle_fundamental_type' + target hook. + 2004-03-23 Zack Weinberg PR 12267, 12391, 12560, 13129, 14114, 14133 diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 1d4d918be2d8..0f934f225a34 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -258,7 +258,8 @@ cp/semantics.o: cp/semantics.c $(CXX_TREE_H) $(TM_H) cp/lex.h except.h toplev.h cp/dump.o: cp/dump.c $(CXX_TREE_H) $(TM_H) tree-dump.h cp/optimize.o: cp/optimize.c $(CXX_TREE_H) $(TM_H) rtl.h integrate.h insn-config.h \ input.h $(PARAMS_H) debug.h tree-inline.h -cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h real.h gt-cp-mangle.h $(TM_P_H) +cp/mangle.o: cp/mangle.c $(CXX_TREE_H) $(TM_H) toplev.h real.h gt-cp-mangle.h \ + $(TARGET_H) $(TM_P_H) cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) diagnostic.h gt-cp-parser.h \ output.h diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index 2580d39866fa..d8c615b78487 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -59,6 +59,7 @@ #include "toplev.h" #include "varray.h" #include "flags.h" +#include "target.h" /* Debugging support. */ @@ -1501,12 +1502,24 @@ write_type (tree type) case BOOLEAN_TYPE: case INTEGER_TYPE: /* Includes wchar_t. */ case REAL_TYPE: + { + /* Handle any target-specific fundamental types. */ + const char *target_mangling + = targetm.mangle_fundamental_type (type); + + if (target_mangling) + { + write_string (target_mangling); + return; + } + /* If this is a typedef, TYPE may not be one of the standard builtin type nodes, but an alias of one. Use TYPE_MAIN_VARIANT to get to the underlying builtin type. */ write_builtin_type (TYPE_MAIN_VARIANT (type)); ++is_builtin_type; break; + } case COMPLEX_TYPE: write_char ('C'); diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index f78b9621c1fa..e8b6d9dacfda 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1514,6 +1514,34 @@ precedence for that field, but the alignment of the rest of the structure may affect its placement. @end deftypefn +@deftypefn {Target Hook} {const char *} TARGET_MANGLE_FUNDAMENTAL_TYPE (tree @var{type}) +If your target defines any fundamental types, define this hook to +return the appropriate encoding for these types as part of a C++ +mangled name. The @var{type} argument is the tree structure +representing the type to be mangled. The hook may be applied to trees +which are not target-specific fundamental types; it should return +@code{NULL} for all such types, as well as arguments it does not +recognize. If the return value is not @code{NULL}, it must point to +a statically-allocated string constant. + +Target-specific fundamental types might be new fundamental types or +qualified versions of ordinary fundamental types. Encode new +fundamental types as @samp{@w{u @var{n} @var{name}}}, where @var{name} +is the name used for the type in source code, and @var{n} is the +length of @var{name} in decimal. Encode qualified versions of +ordinary types as @samp{@w{U @var{n} @var{name} @var{code}}}, where +@var{name} is the name used for the type qualifier in source code, +@var{n} is the length of @var{name} as above, and @var{code} is the +code used to represent the unqualified version of this type. (See +@code{write_builtin_type} in @file{cp/mangle.c} for the list of +codes.) In both cases the spaces are for clarity; do not include any +spaces in your string. + +The default version of this hook always returns @code{NULL}, which is +appropriate for a target that does not define any new fundamental +types. +@end deftypefn + @node Type Layout @section Layout of Source Language Data Types diff --git a/gcc/hooks.c b/gcc/hooks.c index 5b9bb653996b..e37d58e97237 100644 --- a/gcc/hooks.c +++ b/gcc/hooks.c @@ -211,3 +211,10 @@ hook_tree_tree_identity (tree a) { return a; } + +/* Generic hook that takes a tree and returns a NULL string. */ +const char * +hook_constcharptr_tree_null (tree t ATTRIBUTE_UNUSED) +{ + return NULL; +} diff --git a/gcc/hooks.h b/gcc/hooks.h index 824683b4cf4e..aab83a816206 100644 --- a/gcc/hooks.h +++ b/gcc/hooks.h @@ -58,5 +58,5 @@ extern rtx hook_rtx_rtx_identity (rtx); extern rtx hook_rtx_rtx_null (rtx); extern rtx hook_rtx_tree_int_null (tree, int); extern tree hook_tree_tree_identity (tree a); - +extern const char *hook_constcharptr_tree_null (tree); #endif diff --git a/gcc/target-def.h b/gcc/target-def.h index 930fba64b109..62060abebf20 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -311,6 +311,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_tree_false #define TARGET_MS_BITFIELD_LAYOUT_P hook_bool_tree_false #define TARGET_RTX_COSTS hook_bool_rtx_int_int_intp_false +#define TARGET_MANGLE_FUNDAMENTAL_TYPE hook_constcharptr_tree_null #ifndef TARGET_INIT_LIBFUNCS #define TARGET_INIT_LIBFUNCS hook_void_void @@ -385,6 +386,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TARGET_MS_BITFIELD_LAYOUT_P, \ TARGET_INIT_BUILTINS, \ TARGET_EXPAND_BUILTIN, \ + TARGET_MANGLE_FUNDAMENTAL_TYPE, \ TARGET_INIT_LIBFUNCS, \ TARGET_SECTION_TYPE_FLAGS, \ TARGET_CANNOT_MODIFY_JUMPS_P, \ diff --git a/gcc/target.h b/gcc/target.h index 5dea29a8204b..c122adbcdfaa 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -314,6 +314,11 @@ struct gcc_target rtx (* expand_builtin) (tree exp, rtx target, rtx subtarget, enum machine_mode mode, int ignore); + /* For a vendor-specific fundamental TYPE, return a pointer to + a statically-allocated string containing the C++ mangling for + TYPE. In all other cases, return NULL. */ + const char * (* mangle_fundamental_type) (tree type); + /* Make any adjustments to libfunc names needed for this target. */ void (* init_libfuncs) (void); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8fb6722e5678..8fcef8326645 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-03-23 Ziemowit Laski + + * g++.dg/ext/altivec-7.C: New test. + 2004-03-23 Zack Weinberg PR 12267, 12391, 12560, 13129, 14114, 14133 diff --git a/gcc/testsuite/g++.dg/ext/altivec-7.C b/gcc/testsuite/g++.dg/ext/altivec-7.C new file mode 100644 index 000000000000..b09593e3e492 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/altivec-7.C @@ -0,0 +1,35 @@ +/* Test for AltiVec type overloading and name mangling. */ +/* { dg-do compile { target powerpc*-*-* } } */ +/* { dg-options "-maltivec" } */ + +#include + +void foo(vector unsigned char) { } +void foo(vector signed char) { } +void foo(vector bool char) { } +void foo(vector unsigned short) { } +void foo(vector signed short) { } +void foo(vector bool short) { } +void foo(vector unsigned long) { } /* { dg-warning "use of .long. in AltiVec types is deprecated. use .int." } */ +void foo(vector signed long) { } /* { dg-warning "use of .long. in AltiVec types is deprecated. use .int." } */ +void foo(vector bool long) { } /* { dg-warning "use of .long. in AltiVec types is deprecated. use .int." } */ +void foo(vector float) { } +void foo(vector pixel) { } +void foo(int) { } +void foo(unsigned int) { } +void foo(float) { } + +/* { dg-final { scan-assembler "_Z3fooU8__vectorh" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectora" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectorU6__boolc" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectort" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectors" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectorU6__bools" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectorj" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectori" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectorU6__booli" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectorf" } } */ +/* { dg-final { scan-assembler "_Z3fooU8__vectoru7__pixel" } } */ +/* { dg-final { scan-assembler "_Z3fooi" } } */ +/* { dg-final { scan-assembler "_Z3fooj" } } */ +/* { dg-final { scan-assembler "_Z3foof" } } */ -- 2.43.5