[0/3,v2] genmatch: Speed up recompilation after changes to match.pd

Message ID 20230802095527.100830-1-andrzej.turko@gmail.com
Headers
Series genmatch: Speed up recompilation after changes to match.pd |

Message

Andrzej Turko Aug. 2, 2023, 9:55 a.m. UTC
  The following reduces the number of object files that need to be rebuilt
after match.pd has been modified. Right now a change to match.pd which
adds/removes a line almost always forces recompilation of all files that
genmatch generates from it. This is because of unnecessary changes to
the generated .cc files:

1. Function names and ordering change as does the way the functions are
        distributed across multiple source files.
2. Code locations from match.pd are quoted directly (including line
        numbers) by logging fprintf calls.

This patch addresses the those issues without changing the behaviour
of the generated code. The first one is solved by making sure that minor
changes to match.pd do not influence the order in which functions are
generated. The second one by using a lookup table with line numbers.

Now a change to a single function will trigger a rebuild of 4 object
files (one with the function  and the one with the lookup table both for
gimple and generic) instead all of them (20 by default).
For reference, this decreased the rebuild time with 48 threads from 3.5
minutes to 1.5 minutes on my machine.

V2:
        * Placed the change in Makefile.in in the correct commit.
        * Used a separate logging function to reduce size of the
        executable.
        
As for Richard Biener's remarks on executable size:

1. The previous version of the change increased the sizes of executables
        by 8-12 kB.
2. The current version (with an extra indirection step) did so by
        around 150 kB (I suspect that the reason for it may be adding
        an additional functions and its overhead, in which case the
        actual number of instructions may be smaller in this case).


One can choose between those variants just by taking the third commit either
from this or the previous version of the patch series.

Note for reviewers: I do not have write access.

Andrzej Turko (3):
  Support get_or_insert in ordered_hash_map
  genmatch: Reduce variability of generated code
  genmatch: Log line numbers indirectly

 gcc/Makefile.in               |  4 +-
 gcc/genmatch.cc               | 91 +++++++++++++++++++++++++++++------
 gcc/ordered-hash-map-tests.cc | 19 ++++++--
 gcc/ordered-hash-map.h        | 26 ++++++++++
 4 files changed, 118 insertions(+), 22 deletions(-)