Xianmiao Qu <cooper...@linux.alibaba.com> writes: > With the increase in the number of modes and patterns for some > backend architectures, the place_operands function becomes a > bottleneck int the speed of genoutput, and may even become a > bottleneck int the overall speed of building the GCC project. > This patch aims to accelerate the place_operands function, > the optimizations it includes are: > 1. Use a hash table to store operand information, > improving the lookup time for the first operand. > 2. Move mode comparison to the beginning to avoid the scenarios of most > strcmp. > > I tested the speed improvements for the following backends, > Improvement Ratio > x86_64 197.9% > aarch64 954.5% > riscv 2578.6% > If the build machine is slow, then this improvement can save a lot of time. > > I tested the genoutput output for x86_64/aarch64/riscv backends, > and there was no difference compared to before the optimization, > so this shouldn't introduce any functional issues. > > gcc/ > * genoutput.cc (struct operand_data): Add member 'eq_next' to > point to the next member with the same hash value in the > hash table. > (compare_operands): Move the comparison of the mode to the very > beginning to accelerate the comparison of the two operands. > (struct operand_data_hasher): New, a class that takes into account > the necessary elements for comparing the equality of two operands > in its hash value. > (operand_data_hasher::hash): New. > (operand_data_hasher::equal): New. > (operand_datas): New, hash table of konwn pattern operands. > (place_operands): Use a hash table instead of traversing the array > to find the same operand. > (main): Add initialization of the hash table 'operand_datas'. > --- > gcc/genoutput.cc | 105 ++++++++++++++++++++++++++++++++++++++--------- > 1 file changed, 85 insertions(+), 20 deletions(-) > > diff --git a/gcc/genoutput.cc b/gcc/genoutput.cc > index efd81766bb5b..cca1b6622d47 100644 > --- a/gcc/genoutput.cc > +++ b/gcc/genoutput.cc > @@ -91,6 +91,7 @@ along with GCC; see the file COPYING3. If not see > #include "errors.h" > #include "read-md.h" > #include "gensupport.h" > +#include "hash-table.h" > > /* No instruction can have more operands than this. Sorry for this > arbitrary limit, but what machine will have an instruction with > @@ -112,6 +113,8 @@ static int next_operand_number = 1; > struct operand_data > { > struct operand_data *next; > + /* Point to the next member with the same hash value in the hash table. */ > + struct operand_data *eq_next; > int index; > const char *predicate; > const char *constraint; > @@ -127,7 +130,7 @@ struct operand_data > > static struct operand_data null_operand = > { > - 0, 0, "", "", E_VOIDmode, 0, 0, 0, 0, 0 > + 0, 0, 0, "", "", E_VOIDmode, 0, 0, 0, 0, 0 > }; > > static struct operand_data *odata = &null_operand; > @@ -532,6 +535,13 @@ compare_operands (struct operand_data *d0, struct > operand_data *d1) > {
Did the const change Richard suggested not work? (Also, note that he said it's fine to commit once his suggested changes are made.) > [...] thanks, samOA