[PATCH] New attribute to create target clones

Bernd Schmidt bernds_cb1@t-online.de
Mon Sep 21 13:43:00 GMT 2015


On 08/27/2015 01:18 PM, Evgeny Stupachenko wrote:
> Based on RFC:
> https://gcc.gnu.org/ml/gcc-patches/2015-08/msg01322.html
>
> The patch implement an extension to Function Multiversioning that
> allows to clone a function for multiple targets.
> __attribute__((target_clones("avx","arch=slm","default")))
> int foo ()
> ...
>
> Will create 3 clones of foo(). One optimized with -mavx, one optimized
> with -march=slm, and one with default optimizations.
> And will create ifunc resolver that calls appropriate clone (same as
> in Function Multiversioning).

The general question is - do we want this, given that it seems to 
introduce no functionality that can't be had with the existing 
multiversioning? You could always compile the same source file to 
multiple objects with different defines for the target optimization, or 
include a file containing the multiversioned function multiple times 
with changing #defines.

Some comments on the patch itself:

 > diff --git a/gcc/testsuite/gcc.dg/mvc1.c b/gcc/testsuite/gcc.dg/mvc1.c
 > new file mode 100644
 > index 0000000..ab1e0f5
 > --- /dev/null
 > +++ b/gcc/testsuite/gcc.dg/mvc1.c
 > @@ -0,0 +1,27 @@
 > +/* { dg-do run { target i?86-*-* x86_64-*-* } } */
 > +/* { dg-options "-O2" } */

Target-specific tests should go into gcc.target/i386.

> +      else if (lookup_attribute ("target_clones", DECL_ATTRIBUTES (*node)))
> +	{
> +	  warning (OPT_Wattributes,
> +		   "%qE attribute ignored as it conflict with target_clones",
> +		   name);
> +	  *no_add_attrs = true;
> +	}

Bad grammar ("conflicts"), and apparently you're supposed to use %qs 
even for known attribute names. Look at the code immediately before this 
and copy it. Similar issues throughout.

> +  for (e = node->callers; e ;e = (e == NULL) ? e_next : e->next_caller)

It looks like this could be simplified if you immediately assign
   e_next = e->next_caller
and then always use e_next.

Trying to test it, I get (compiling with -O2 on x86_64-linux):

mvc1.c: In function ‘main’:
mvc1.c:18:1: error: virtual definition of statement not up-to-date
  main ()
  ^
_2 = foo.ifunc ();
mvc1.c:18:1: internal compiler error: verify_ssa failed


Bernd



More information about the Gcc-patches mailing list