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: New hook for custom-mangling of C++ fundamental types -- TAKE 2


Ok, here is the revised version.  I've renamed 'scalars' to
'fundamental types', and everything else pretty much follows
what Zack suggested.  The only possible sticking point may
be the doc :-) -- please let me know if I misrepresented
anything.

OK to commit if there are no regressions?


[gcc/ChangeLog] 2004-03-22 Ziemowit Laski <zlaski@apple.com>

       * 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-22  Ziemowit Laski  <zlaski@apple.com>

       * 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-22  Ziemowit Laski  <zlaski@apple.com>

* g++.dg/ext/altivec-7.C: New test.


Index: gcc/hooks.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/hooks.c,v retrieving revision 1.27 diff -u -3 -p -r1.27 hooks.c --- gcc/hooks.c 11 Mar 2004 03:19:03 -0000 1.27 +++ gcc/hooks.c 22 Mar 2004 23:52:01 -0000 @@ -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; +} Index: gcc/hooks.h =================================================================== RCS file: /cvs/gcc/gcc/gcc/hooks.h,v retrieving revision 1.28 diff -u -3 -p -r1.28 hooks.h --- gcc/hooks.h 11 Mar 2004 03:19:03 -0000 1.28 +++ gcc/hooks.h 22 Mar 2004 23:52:01 -0000 @@ -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 Index: gcc/target-def.h =================================================================== RCS file: /cvs/gcc/gcc/gcc/target-def.h,v retrieving revision 1.76 diff -u -3 -p -r1.76 target-def.h --- gcc/target-def.h 12 Mar 2004 17:08:56 -0000 1.76 +++ gcc/target-def.h 22 Mar 2004 23:52:01 -0000 @@ -311,6 +311,7 @@ Foundation, 59 Temple Place - Suite 330, #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,
   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,                        \
Index: gcc/target.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target.h,v
retrieving revision 1.84
diff -u -3 -p -r1.84 target.h
--- gcc/target.h        12 Mar 2004 17:08:57 -0000      1.84
+++ gcc/target.h        22 Mar 2004 23:52:01 -0000
@@ -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
+     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);

Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.614
diff -u -3 -p -r1.614 rs6000.c
--- gcc/config/rs6000/rs6000.c 22 Mar 2004 15:04:27 -0000 1.614
+++ gcc/config/rs6000/rs6000.c 22 Mar 2004 23:52:02 -0000
@@ -309,6 +309,7 @@ static void rs6000_assemble_visibility (
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

@@ -14901,6 +14905,21 @@ rs6000_handle_altivec_attribute (tree *n
     *node = reconstruct_complex_type (*node, result);

   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
Index: gcc/cp/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Make-lang.in,v
retrieving revision 1.179
diff -u -3 -p -r1.179 Make-lang.in
--- gcc/cp/Make-lang.in 6 Feb 2004 01:02:30 -0000 1.179
+++ gcc/cp/Make-lang.in 22 Mar 2004 23:52:02 -0000
@@ -258,7 +258,8 @@ cp/semantics.o: cp/semantics.c $(CXX_TRE
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
Index: gcc/cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.99
diff -u -3 -p -r1.99 mangle.c
--- gcc/cp/mangle.c 26 Feb 2004 02:17:26 -0000 1.99
+++ gcc/cp/mangle.c 22 Mar 2004 23:52:02 -0000
@@ -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');
Index: gcc/doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.315
diff -u -3 -p -r1.315 tm.texi
--- gcc/doc/tm.texi     14 Mar 2004 22:29:38 -0000      1.315
+++ gcc/doc/tm.texi     22 Mar 2004 23:52:03 -0000
@@ -1514,6 +1514,32 @@ precedence for that field, but the align
 may affect its placement.
 @end deftypefn

+@deftypefn {Target Hook} {const char *} TARGET_MANGLE_FUNDAMENTAL_TYPE (tree @var{type})
+If your target defines additional 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 for arguments it does not recognize. If the return
+value is not @code{NULL}, it should point to a statically-allocated string
+constant.
+
+Target-specific fundamental types should have manglings that are distinct
+from those of other types (whether target-specific or not). Furthermore,
+the demangling of their mangled names should produce the original, human-
+readable names. To this end, the @code{'U'} and @code{'u'} mangling codes
+should be used, possibly in conjunction with codes for built-in fundamental
+types. (See @code{write_builtin_type} in @file{cp/mangle.c} for the list
+of codes.) For example, if your target defines a fundamental type called
+@code{__targettype}, it should be mangled as @code{"U12__targettype"};
+a type called @code{__target} @code{__type} should be mangled as
+@code{"U8__targetu6__type"}; and a type called @code{__akindof int} may be
+mangled as either @code{"U9__akindofi"} or @code{"U9__akindofu3int"}.
+
+The default version of this hook always returns @code{NULL}, which is
+appropriate for a target that does not define any additional fundamental
+types.
+@end deftypefn
+
@node Type Layout
@section Layout of Source Language Data Types


Index: gcc/testsuite/g++.dg/ext/altivec-7.C
===================================================================
RCS file: gcc/testsuite/g++.dg/ext/altivec-7.C
diff -N gcc/testsuite/g++.dg/ext/altivec-7.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/ext/altivec-7.C 22 Mar 2004 23:52:11 -0000
@@ -0,0 +1,35 @@
+/* Test for AltiVec type overloading and name mangling. */
+/* { dg-do compile { target powerpc*-*-* } } */
+/* { dg-options "-maltivec" } */
+
+#include <altivec.h>
+
+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" } } */


--------------------------------------------------------------
Ziemowit Laski                 1 Infinite Loop, MS 301-2K
Mac OS X Compiler Group        Cupertino, CA USA  95014-2083
Apple Computer, Inc.           +1.408.974.6229  Fax .5477


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