This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFC: PATCHes to SIMD vector mangling (more c++/12909)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>, Mark Mitchell <mark at codesourcery dot com>, Richard Henderson <rth at redhat dot com>, Ulrich Drepper <drepper at redhat dot com>
- Date: Wed, 24 Feb 2010 14:24:47 -0500
- Subject: RFC: PATCHes to SIMD vector mangling (more c++/12909)
These two patches implement some measures to try and do better with
vector mangling short of bumping up the ABI version:
The first patch changes the x86/x64 and rs6000 ports to use the old
mangling only for 128-bit vectors (SSE/altivec), and the new mangling
for other sizes. This ought to have limited impact on existing code, as
support for larger vectors is fairly new (-mavx was added in 4.4). If
it does cause trouble, people can revert to the old mangling in all
cases with -fold-vector-mangling.
The second patch improves forward-compatibility by creating an alias
with the new mangling for any decl that uses the old mangling. This
means that calls in code built with ABI v4 can link against definitions
built now, but not vice-versa; current code will still call the symbol
with the old mangling in order to keep backward compatibility with
existing libraries. This seems pretty safe, as the old mangling can't
collide with the new.
The two patches are independent of one another; we could apply either,
both, none, or something else.
Another possibility would be to use the old mangling whenever there
isn't a conflict within the same translation unit, but that could lead
to incompatibilities within a project if not all declarations are
visible within all translation units.
Another possibility would be to additionally emit aliases with the old
mangling when we use the new mangling. This would improve backwards
compatibility somewhat, but could result in wrong code if there are
overloads on vectors of different sizes and the linker chooses the
"wrong" one.
Opinions?
Jason
commit 9157af1e784c73719072c24d4ee87a8214668121
Author: Jason Merrill <jason@redhat.com>
Date: Thu Feb 4 14:26:54 2010 -0500
PR c++/12909
* c.opt (fold-vector-mangling): New.
* config/i386/i386.h (TARGET_VECTOR_LEGACY_SIZE): Define.
* config/rs6000/rs6000.h: Likewise.
* cp/mangle.c (write_type) [VECTOR_TYPE]: Also enable new mangling if
the target defines TARGET_VECTOR_LEGACY_SIZE and this type has a
different size.
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6eb392c..64da09a 100644
diff --git a/gcc/c.opt b/gcc/c.opt
index 82dee8d..f34dcba 100644
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -713,6 +713,10 @@ fobjc-sjlj-exceptions
ObjC ObjC++ Var(flag_objc_sjlj_exceptions) Init(-1)
Enable Objective-C setjmp exception handling runtime
+fold-vector-mangling
+C++ ObjC++ Var(flag_old_vector_mangling)
+In ABI version 2 or 3, revert to the old mangling for SIMD vector types
+
fopenmp
C ObjC C++ ObjC++ Var(flag_openmp)
Enable OpenMP (implies -frecursive in Fortran)
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 962a14c..f8d203b 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1025,6 +1025,9 @@ enum target_cpu_default
|| (MODE) == V2SImode || (MODE) == SImode \
|| (MODE) == V4HImode || (MODE) == V8QImode)
+/* Use the legacy mangling for SSE vectors. */
+#define TARGET_VECTOR_LEGACY_SIZE 16
+
/* ??? No autovectorization into MMX or 3DNOW until we can reliably
place emms and femms instructions.
FIXME: AVX has 32byte floating point vector operations and 16byte
diff --git a/gcc/config/rs6000/rs6000.h b/gcc/config/rs6000/rs6000.h
index a0c2ad7..27a9a54 100644
--- a/gcc/config/rs6000/rs6000.h
+++ b/gcc/config/rs6000/rs6000.h
@@ -1065,6 +1065,9 @@ extern unsigned rs6000_pointer_size;
|| (MODE) == V4SFmode \
|| (MODE) == V4SImode)
+/* Use the legacy mangling for Altivec vectors. */
+#define TARGET_VECTOR_LEGACY_SIZE 16
+
#define SPE_VECTOR_MODE(MODE) \
((MODE) == V4HImode \
|| (MODE) == V2SFmode \
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a3b7e52..be794e9 100644
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index e6d7934..65b0bdc 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1808,6 +1808,7 @@ write_type (tree type)
/* Handle any target-specific fundamental types. */
const char *target_mangling
= targetm.mangle_type (type_orig);
+ bool std_vector_mangling = false;
if (target_mangling)
{
@@ -1896,6 +1897,15 @@ write_type (tree type)
case VECTOR_TYPE:
if (abi_version_at_least (4))
+ std_vector_mangling = true;
+#ifdef TARGET_VECTOR_LEGACY_SIZE
+ else if (abi_version_at_least (2)
+ && !flag_old_vector_mangling
+ && (int_cst_value (TYPE_SIZE_UNIT (type))
+ != TARGET_VECTOR_LEGACY_SIZE))
+ std_vector_mangling = true;
+#endif
+ if (std_vector_mangling)
{
write_string ("Dv");
/* Non-constant vector size would be encoded with
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 36b3568..cd88c3b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -1787,6 +1787,15 @@ Version 4 implements a standard mangling for vector types.
See also @option{-Wabi}.
+@item -fold-vector-mangling
+@opindex fold-vector-mangling
+G++ 4.5 introduces a standard mangling for some vector types on
+targets that support vectors of varying size, in order to support
+overloading on different vector types. If this introduces a binary
+incompatibility, you can use this option to revert to the previous
+mangling in all cases. Only effective with @option{-fabi-version=2}
+or @option{-fabi-version=3}.
+
@item -fno-access-control
@opindex fno-access-control
Turn off all access checking. This switch is mainly useful for working
@@ -2123,7 +2132,8 @@ SIMD vector types declared using @code{__attribute ((vector_size))} are
mangled in a non-standard way that does not allow for overloading of
functions taking vectors of different sizes.
-The mangling is changed in @option{-fabi-version=4}.
+The mangling is changed in @option{-fabi-version=4}. See also
+@option{-fold-vector-mangling}.
@end itemize
The known incompatibilities in @option{-fabi-version=1} include:
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 7d65954..8d88ffb 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -4352,6 +4352,13 @@ insns involving vector mode @var{mode}. At the very least, it
must have move patterns for this mode.
@end deftypefn
+@defmac TARGET_VECTOR_LEGACY_SIZE
+If defined, a C expression that gives a vector size (in bytes) which
+in the default C++ ABI will use the legacy @code{__vector} mangling.
+If this macro is not defined, the C++ compiler will default to using
+the legacy mangling for all vector types.
+@end defmac
+
@node Scalar Return
@subsection How Scalar Function Values Are Returned
@cindex return values in registers
commit a12ba14d9045cc5d28b17d05849944e6f63b958d
Author: Jason Merrill <jason@redhat.com>
Date: Tue Feb 23 18:03:21 2010 -0500
PR c++/12909
* mangle.c: Include cgraph.h.
(mangle_decl): If the mangled name will change in a later
ABI version, make the later mangled name an alias.
* Make-lang.in (mangle.o): Depend on cgraph.h.
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index be794e9..03a085a 100644
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in
index f6cb70f..1484063 100644
--- a/gcc/cp/Make-lang.in
+++ b/gcc/cp/Make-lang.in
@@ -308,7 +308,7 @@ 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) $(GIMPLE_H) \
$(TARGET_H) tree-iterator.h $(CGRAPH_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)
+ gt-cp-mangle.h $(TARGET_H) $(TM_P_H) $(CGRAPH_H)
cp/parser.o: cp/parser.c $(CXX_TREE_H) $(TM_H) $(DIAGNOSTIC_H) gt-cp-parser.h \
output.h $(TARGET_H) $(PLUGIN_H) intl.h
cp/cp-gimplify.o: cp/cp-gimplify.c $(CXX_TREE_H) toplev.h $(C_COMMON_H) \
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 65b0bdc..7d09bdf 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. If not see
#include "varray.h"
#include "flags.h"
#include "target.h"
+#include "cgraph.h"
/* Debugging support. */
@@ -3041,6 +3042,22 @@ mangle_decl (const tree decl)
tree id = mangle_decl_string (decl);
id = targetm.mangle_decl_assembler_name (decl, id);
SET_DECL_ASSEMBLER_NAME (decl, id);
+
+ if (G.need_abi_warning)
+ {
+ /* If the mangling will change in the future, emit an alias with the
+ future mangled name for forward-compatibility. */
+ int save_ver = flag_abi_version;
+ tree id2, alias;
+ flag_abi_version = 0;
+ id2 = mangle_decl_string (decl);
+ id2 = targetm.mangle_decl_assembler_name (decl, id2);
+ flag_abi_version = save_ver;
+
+ alias = make_alias_for (decl, id2);
+ TREE_PUBLIC (alias) = 1;
+ cgraph_same_body_alias (alias, decl);
+ }
}
/* Generate the mangled representation of TYPE. */