backport: re PR target/81193 (PowerPC GCC __builtin_cpu_is and __builtin_cpu_supports should warn about old libraries)

[gcc]
2017-07-19  Michael Meissner  <meissner@linux.vnet.ibm.com>

	Back port from trunk
	2017-07-12  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR target/81193
	* config/rs6000/rs6000-c.c (rs6000_cpu_cpp_builtins): If GLIBC
	provides the hardware capability bits, define the macro
	__BUILTIN_CPU_SUPPORTS__.
	* config/rs6000/rs6000.c (cpu_expand_builtin): Generate a warning
	if GLIBC does not provide the hardware capability bits.  Add a
	gcc_unreachable call if the built-in cpu function is neither
	__builtin_cpu_is nor __builtin_cpu_supports.
	* doc/extend.texi (PowerPC built-in functions): Document that
	GLIBC 2.23 or newer is needed by __builtin_cpu_is and
	__builtin_cpu_supports.  Document the macros defined by GCC if the
	newer GLIBC is available.

[gcc/testsuite]
2017-07-19  Michael Meissner  <meissner@linux.vnet.ibm.com>

	Back port from trunk
	2017-07-12  Michael Meissner  <meissner@linux.vnet.ibm.com>

	PR target/81193
	* gcc.target/powerpc/cpu-builtin-1.c: Change test to use #ifdef
	__BUILTIN_CPU_SUPPORTS to see if the GLIBC is new enough that
	__builtin_cpu_is and __builtin_cpu_supports are supported.

From-SVN: r250368
This commit is contained in:
Michael Meissner 2017-07-19 20:31:53 +00:00 committed by Michael Meissner
parent fd8e5aa174
commit 4aae5594ac
6 changed files with 97 additions and 19 deletions

View File

@ -1,3 +1,21 @@
2017-07-19 Michael Meissner <meissner@linux.vnet.ibm.com>
Back port from trunk
2017-07-12 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/81193
* config/rs6000/rs6000-c.c (rs6000_cpu_cpp_builtins): If GLIBC
provides the hardware capability bits, define the macro
__BUILTIN_CPU_SUPPORTS__.
* config/rs6000/rs6000.c (cpu_expand_builtin): Generate a warning
if GLIBC does not provide the hardware capability bits. Add a
gcc_unreachable call if the built-in cpu function is neither
__builtin_cpu_is nor __builtin_cpu_supports.
* doc/extend.texi (PowerPC built-in functions): Document that
GLIBC 2.23 or newer is needed by __builtin_cpu_is and
__builtin_cpu_supports. Document the macros defined by GCC if the
newer GLIBC is available.
2017-07-18 Uros Bizjak <ubizjak@gmail.com>
PR target/81471

View File

@ -648,6 +648,9 @@ rs6000_cpu_cpp_builtins (cpp_reader *pfile)
builtin_define ("__FLOAT128_HARDWARE__");
if (TARGET_LONG_DOUBLE_128 && FLOAT128_IBM_P (TFmode))
builtin_define ("__ibm128=long double");
#ifdef TARGET_LIBC_PROVIDES_HWCAP_IN_TCB
builtin_define ("__BUILTIN_CPU_SUPPORTS__");
#endif
/* We needed to create a keyword if -mfloat128-type was used but not -mfloat,
so we used __ieee128. If -mfloat128 was used, create a #define back to

View File

@ -15584,6 +15584,8 @@ cpu_expand_builtin (enum rs6000_builtins fcode, tree exp ATTRIBUTE_UNUSED,
emit_insn (gen_eqsi3 (scratch2, scratch1, const0_rtx));
emit_insn (gen_rtx_SET (target, gen_rtx_XOR (SImode, scratch2, const1_rtx)));
}
else
gcc_unreachable ();
/* Record that we have expanded a CPU builtin, so that we can later
emit a reference to the special symbol exported by LIBC to ensure we
@ -15591,6 +15593,9 @@ cpu_expand_builtin (enum rs6000_builtins fcode, tree exp ATTRIBUTE_UNUSED,
cpu_builtin_p = true;
#else
warning (0, "%s needs GLIBC (2.23 and newer) that exports hardware "
"capability bits", rs6000_builtin_info[(size_t) fcode].name);
/* For old LIBCs, always return FALSE. */
emit_move_insn (target, GEN_INT (0));
#endif /* TARGET_LIBC_PROVIDES_HWCAP_IN_TCB */

View File

@ -14894,10 +14894,25 @@ This function is a @code{nop} on the PowerPC platform and is included solely
to maintain API compatibility with the x86 builtins.
@end deftypefn
@deftypefn {Built-in Function} void __builtin_cpu_init (void)
This function is a @code{nop} on the PowerPC platform and is included solely
to maintain API compatibility with the x86 builtins.
@end deftypefn
@deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname})
This function returns a value of @code{1} if the run-time CPU is of type
@var{cpuname} and returns @code{0} otherwise. The following CPU names can be
detected:
@var{cpuname} and returns @code{0} otherwise
The @code{__builtin_cpu_is} function requires GLIBC 2.23 or newer
which exports the hardware capability bits. GCC defines the macro
@code{__BUILTIN_CPU_SUPPORTS__} if the @code{__builtin_cpu_supports}
built-in function is fully supported.
If GCC was configured to use a GLIBC before 2.23, the built-in
function @code{__builtin_cpu_is} always returns a 0 and the compiler
issues a warning.
The following CPU names can be detected:
@table @samp
@item power9
@ -14934,20 +14949,33 @@ IBM PowerPC Cell Broadband Engine Architecture CPU.
Here is an example:
@smallexample
if (__builtin_cpu_is ("power8"))
@{
do_power8 (); // POWER8 specific implementation.
@}
else
@{
do_generic (); // Generic implementation.
@}
#ifdef __BUILTIN_CPU_SUPPORTS__
if (__builtin_cpu_is ("power8"))
@{
do_power8 (); // POWER8 specific implementation.
@}
else
#endif
@{
do_generic (); // Generic implementation.
@}
@end smallexample
@end deftypefn
@deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature})
This function returns a value of @code{1} if the run-time CPU supports the HWCAP
feature @var{feature} and returns @code{0} otherwise. The following features can be
feature @var{feature} and returns @code{0} otherwise.
The @code{__builtin_cpu_supports} function requires GLIBC 2.23 or
newer which exports the hardware capability bits. GCC defines the
macro @code{__BUILTIN_CPU_SUPPORTS__} if the
@code{__builtin_cpu_supports} built-in function is fully supported.
If GCC was configured to use a GLIBC before 2.23, the built-in
function @code{__builtin_cpu_suports} always returns a 0 and the
compiler issues a warning.
The following features can be
detected:
@table @samp
@ -15031,14 +15059,16 @@ CPU supports the vector-scalar extension.
Here is an example:
@smallexample
if (__builtin_cpu_supports ("fpu"))
@{
asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
@}
else
@{
dst = __fadd (src1, src2); // Software FP addition function.
@}
#ifdef __BUILTIN_CPU_SUPPORTS__
if (__builtin_cpu_supports ("fpu"))
@{
asm("fadd %0,%1,%2" : "=d"(dst) : "d"(src1), "d"(src2));
@}
else
#endif
@{
dst = __fadd (src1, src2); // Software FP addition function.
@}
@end smallexample
@end deftypefn

View File

@ -1,3 +1,13 @@
2017-07-19 Michael Meissner <meissner@linux.vnet.ibm.com>
Back port from trunk
2017-07-12 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/81193
* gcc.target/powerpc/cpu-builtin-1.c: Change test to use #ifdef
__BUILTIN_CPU_SUPPORTS to see if the GLIBC is new enough that
__builtin_cpu_is and __builtin_cpu_supports are supported.
2017-07-18 Uros Bizjak <ubizjak@gmail.com>
PR target/81471

View File

@ -4,6 +4,11 @@
void
use_cpu_is_builtins (unsigned int *p)
{
/* If GCC was configured to use an old GLIBC (before 2.23), the
__builtin_cpu_is and __builtin_cpu_supports built-in functions return 0,
and the compiler issues a warning that you need a newer glibc to use them.
Use #ifdef to avoid the warning. */
#ifdef __BUILTIN_CPU_SUPPORTS__
p[0] = __builtin_cpu_is ("power9");
p[1] = __builtin_cpu_is ("power8");
p[2] = __builtin_cpu_is ("power7");
@ -19,11 +24,15 @@ use_cpu_is_builtins (unsigned int *p)
p[12] = __builtin_cpu_is ("ppc440");
p[13] = __builtin_cpu_is ("ppc405");
p[14] = __builtin_cpu_is ("ppc-cell-be");
#else
p[0] = 0;
#endif
}
void
use_cpu_supports_builtins (unsigned int *p)
{
#ifdef __BUILTIN_CPU_SUPPORTS__
p[0] = __builtin_cpu_supports ("4xxmac");
p[1] = __builtin_cpu_supports ("altivec");
p[2] = __builtin_cpu_supports ("arch_2_05");
@ -62,4 +71,7 @@ use_cpu_supports_builtins (unsigned int *p)
p[35] = __builtin_cpu_supports ("ucache");
p[36] = __builtin_cpu_supports ("vcrypto");
p[37] = __builtin_cpu_supports ("vsx");
#else
p[0] = 0;
#endif
}