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++ scalars


This is yet another fallout from my earlier AltiVec activity. Initially,
I had a hook for custom-mangling of entire VECTOR_TYPEs, but Mark convinced
me to custom-handle only the elements of vectors. So here goes.


Bootstrapped, with no regressions. OK to commit?

--Zem

[gcc/ChangeLog]
2004-03-02  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_SCALAR_TYPE): New target hook.
* target.h (mangle_scalar_type): New target hook.
* config/rs6000/rs6000-c.c: #include target.h.
(rs6000_cpu_cpp_builtins): In AltiVec mode, enable target-specific
C++ scalar-mangling hook.
* config/rs6000/rs6000-protos.h (rs6000_mangle_scalar_type): New
prototype.
* config/rs6000/rs6000.c (rs6000_mangle_scalar_type): New function.
* config/rs6000/t-rs6000 (rs6000-c.o): Depend on $(TARGET_H).
* doc/tm.texi (TARGET_MANGLE_SCALAR_TYPE): Document.


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

        * Make-lang.in (cp/mangle.o): Depend on $(TARGET_H).
        * mangle.c (write_type): Add call to 'mangle_scalar_type'
        target hook.

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

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



Index: gcc/hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/hooks.c,v
retrieving revision 1.24
diff -u -3 -p -r1.24 hooks.c
--- gcc/hooks.c 19 Feb 2004 11:06:26 -0000      1.24
+++ gcc/hooks.c 2 Mar 2004 00:48:14 -0000
@@ -209,3 +209,10 @@ hook_bool_voidp_size_t_false (void * a A
 {
   return false;
 }
+
+/* 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.25
diff -u -3 -p -r1.25 hooks.h
--- gcc/hooks.h 19 Feb 2004 11:06:26 -0000      1.25
+++ gcc/hooks.h 2 Mar 2004 00:48:14 -0000
@@ -57,5 +57,6 @@ extern rtx hook_rtx_rtx_null (rtx);
 extern rtx hook_rtx_tree_int_null (tree, int);
 extern void * hook_voidp_size_t_null (size_t);
 extern bool hook_bool_voidp_size_t_false (void *, size_t);
+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.70
diff -u -3 -p -r1.70 target-def.h
--- gcc/target-def.h    24 Feb 2004 17:28:28 -0000      1.70
+++ gcc/target-def.h    2 Mar 2004 00:48:14 -0000
@@ -305,6 +305,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_SCALAR_TYPE hook_constcharptr_tree_null

 #ifndef TARGET_INIT_LIBFUNCS
 #define TARGET_INIT_LIBFUNCS hook_void_void
@@ -372,6 +373,7 @@ Foundation, 59 Temple Place - Suite 330,
   TARGET_MS_BITFIELD_LAYOUT_P,                 \
   TARGET_INIT_BUILTINS,                                \
   TARGET_EXPAND_BUILTIN,                       \
+  TARGET_MANGLE_SCALAR_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.79
diff -u -3 -p -r1.79 target.h
--- gcc/target.h        24 Feb 2004 17:28:28 -0000      1.79
+++ gcc/target.h        2 Mar 2004 00:48:14 -0000
@@ -308,6 +308,11 @@ struct gcc_target
   rtx (* expand_builtin) (tree exp, rtx target, rtx subtarget,
                          enum machine_mode mode, int ignore);

+  /* Return a vendor-specific C++ mangling for TYPE, or NULL if
+     default C++ mangling for TYPE should be used instead.  Only
+     scalar types may have vendor-specific mangling.  */
+  const char * (* mangle_scalar_type) (tree type);
+
   /* Make any adjustments to libfunc names needed for this target.  */
   void (* init_libfuncs) (void);

Index: gcc/config/rs6000/rs6000-c.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000-c.c,v
retrieving revision 1.12
diff -u -3 -p -r1.12 rs6000-c.c
--- gcc/config/rs6000/rs6000-c.c 23 Feb 2004 17:02:51 -0000 1.12
+++ gcc/config/rs6000/rs6000-c.c 2 Mar 2004 00:48:14 -0000
@@ -30,6 +30,7 @@
#include "c-pragma.h"
#include "errors.h"
#include "tm_p.h"
+#include "target.h"


/* Handle the machine specific pragma longcall. Its syntax is

@@ -100,6 +101,9 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfi
builtin_define ("__vector=__attribute__((altivec(vector__)))");
builtin_define ("__pixel=__attribute__((altivec(pixel__))) unsigned short");
builtin_define ("__bool=__attribute__((altivec(bool__))) unsigned");
+
+ /* Enable AltiVec-specific name-mangling. */
+ targetm.mangle_scalar_type = rs6000_mangle_scalar_type;
}
if (TARGET_SPE)
builtin_define ("__SPE__");
Index: gcc/config/rs6000/rs6000-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000-protos.h,v
retrieving revision 1.74
diff -u -3 -p -r1.74 rs6000-protos.h
--- gcc/config/rs6000/rs6000-protos.h 6 Feb 2004 06:18:19 -0000 1.74
+++ gcc/config/rs6000/rs6000-protos.h 2 Mar 2004 00:48:14 -0000
@@ -203,6 +203,7 @@ extern int rs6000_tls_symbol_ref (rtx, e


 extern void rs6000_pragma_longcall (struct cpp_reader *);
 extern void rs6000_cpu_cpp_builtins (struct cpp_reader *);
+extern const char *rs6000_mangle_scalar_type (tree);

 #if TARGET_MACHO
 char *output_call (rtx, rtx *, int, int);
Index: gcc/config/rs6000/rs6000.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/rs6000.c,v
retrieving revision 1.598
diff -u -3 -p -r1.598 rs6000.c
--- gcc/config/rs6000/rs6000.c  23 Feb 2004 18:40:46 -0000      1.598
+++ gcc/config/rs6000/rs6000.c  2 Mar 2004 00:48:15 -0000
@@ -14757,6 +14757,21 @@ rs6000_handle_altivec_attribute (tree *n
   return NULL_TREE;
 }

+/* AltiVec defines four built-in scalar types that serve as vector
+   elements; we must teach the compiler how to mangle them.  */
+
+const char *
+rs6000_mangle_scalar_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 scalars, use normal C++ mangling.  */
+  return NULL;
+}
+
 /* Handle a "longcall" or "shortcall" attribute; arguments as in
    struct attribute_spec.handler.  */

Index: gcc/config/rs6000/t-rs6000
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/rs6000/t-rs6000,v
retrieving revision 1.10
diff -u -3 -p -r1.10 t-rs6000
--- gcc/config/rs6000/t-rs6000  15 Jun 2003 18:01:55 -0000      1.10
+++ gcc/config/rs6000/t-rs6000  2 Mar 2004 00:48:15 -0000
@@ -11,7 +11,7 @@ rs6000.o: $(CONFIG_H) $(SYSTEM_H) corety
   cfglayout.h

rs6000-c.o: $(srcdir)/config/rs6000/rs6000-c.c \
- $(srcdir)/config/rs6000/rs6000-protos.h \
+ $(srcdir)/config/rs6000/rs6000-protos.h $(TARGET_H) \
$(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(CPPLIB_H) \
$(TM_P_H) c-pragma.h errors.h coretypes.h $(TM_H)
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $(srcdir)/config/rs6000/rs6000-c.c
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 2 Mar 2004 00:48:15 -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 2 Mar 2004 00:48:15 -0000
@@ -59,6 +59,7 @@
#include "toplev.h"
#include "varray.h"
#include "flags.h"
+#include "target.h"


/* Debugging support. */

@@ -1468,6 +1469,7 @@ write_type (tree type)
   /* This gets set to nonzero if TYPE turns out to be a (possibly
      CV-qualified) builtin type.  */
   int is_builtin_type = 0;
+  const char *vendor_scalar_mangling;

MANGLE_TRACE_TREE ("type", type);

@@ -1501,6 +1503,13 @@ write_type (tree type)
case BOOLEAN_TYPE:
case INTEGER_TYPE: /* Includes wchar_t. */
case REAL_TYPE:
+ /* Handle any target-specific scalar types. */
+ if ((vendor_scalar_mangling = (*targetm.mangle_scalar_type)(type)))
+ {
+ write_string (vendor_scalar_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. */
Index: gcc/doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.305
diff -u -3 -p -r1.305 tm.texi
--- gcc/doc/tm.texi 28 Feb 2004 21:44:22 -0000 1.305
+++ gcc/doc/tm.texi 2 Mar 2004 00:48:20 -0000
@@ -1514,6 +1514,17 @@ precedence for that field, but the align
may affect its placement.
@end deftypefn


+@deftypefn {Target Hook} const char * TARGET_MANGLE_SCALAR_TYPE (tree @var{type})
+This target hook should return a string denoting a vendor-specific C++
+mangling for the given scalar @var{type}. Only vendor-specific scalar
+types should have vendor-specific manglings supplied for them. For all
+other scalar types (including built-in types such as @code{int} or
+@code{float}), the target hook should return @code{NULL}, indicating that
+the default C++ mangling scheme should be used. The default target hook
+will return @code{NULL} for all values of @var{type}. This target hook
+will not be used for non-scalar types.
+@end deftypefn
+
@node Type Layout
@section Layout of Source Language Data Types


Index: gcc/testsuite/g++.dg/ext/altivec-4.C
===================================================================
RCS file: gcc/testsuite/g++.dg/ext/altivec-4.C
diff -N gcc/testsuite/g++.dg/ext/altivec-4.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/ext/altivec-4.C 2 Mar 2004 00:48:25 -0000
@@ -0,0 +1,33 @@
+/* Test for AltiVec type overloading and name mangling. */
+/* { dg-do compile { target powerpc*-*-darwin* } } */
+/* { dg-options "-faltivec -Waltivec-long-deprecated" } */
+
+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]