x86: Speed up target attribute handling by using a cache
authorJakub Jelinek <jakub@redhat.com>
Fri, 3 Dec 2021 10:07:44 +0000 (11:07 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 3 Dec 2021 10:07:44 +0000 (11:07 +0100)
commit7e71909af2cf3aeec9bed4f6a3cc42c1d17cd661
tree98b6eeac5f6de3c59e6d120b19dd7f858a875500
parentfe7c3ecff1f9c0520090a77fa824d8c5d9dbec12
x86: Speed up target attribute handling by using a cache

The target attribute handling is very expensive and for the common case
from x86intrin.h where many functions get implicitly the same target
attribute, we can speed up compilation a lot by caching it.

The following patches both create a single entry cache, where they cache
for a particular target attribute argument list the resulting
DECL_FUNCTION_SPECIFIC_TARGET and DECL_FUNCTION_SPECIFIC_OPTIMIZATION
values from ix86_valid_target_attribute_p and use the cache if the
args are the same as last time and we start either from NULL values
of those, or from the recorded values for those from last time.

Compiling a simple:
 #include <x86intrin.h>

 int i;
testcase with ./cc1 -quiet -O2 -isystem include/ test.c
takes on my WS without the patches ~0.392s and with either of the
patches ~0.182s, i.e. roughly half the time as before.
For ./cc1plus -quiet -O2 -isystem include/ test.c
it is slightly worse, the speed up is from ~0.613s to ~0.403s.

The difference between the 2 patches is that the first one uses copy_list
while the second one uses a vec, so I think the second one has the advantage
of creating less GC garbage.
I've verified both patches achieve the same content of those
DECL_FUNCTION_SPECIFIC_TARGET and DECL_FUNCTION_SPECIFIC_OPTIMIZATION
nodes as before on x86intrin.h by doing debug_tree on those and comparing
the stderr from without these patches to with these patches.

2021-12-03  Jakub Jelinek  <jakub@redhat.com>

* attribs.h (simple_cst_list_equal): Declare.
* attribs.c (simple_cst_list_equal): No longer static.
* config/i386/i386-options.c (target_attribute_cache): New variable.
(ix86_valid_target_attribute_p): Cache DECL_FUNCTION_SPECIFIC_TARGET
and DECL_FUNCTION_SPECIFIC_OPTIMIZATION based on args.
gcc/attribs.c
gcc/attribs.h
gcc/config/i386/i386-options.c