x86: generate template sets data at build time

Speed up gas startup by avoiding runtime allocation of the instances of
type "templates". At the same time cut the memory requirement to just
very little over half (not even accounting for any overhead
notes_alloc() may incur) by reusing the "end" slot of a preceding entry
for the "start" slot of the subsequent one.
This commit is contained in:
Jan Beulich
2022-12-12 08:49:26 +01:00
parent daf15e3e96
commit 65f440c8fb
3 changed files with 2359 additions and 15 deletions

View File

@ -2973,21 +2973,16 @@ md_begin (void)
op_hash = str_htab_create ();
{
const insn_template *optab = i386_optab;
const insn_template *end = optab + ARRAY_SIZE (i386_optab);
const insn_template *const *sets = i386_op_sets;
const insn_template *const *end = sets + ARRAY_SIZE (i386_op_sets) - 1;
while (optab < end)
{
templates *core_optab = notes_alloc (sizeof (*core_optab));
core_optab->start = optab;
while (++optab < end)
if (strcmp (optab->name, optab[-1].name) != 0)
break;
core_optab->end = optab;
if (str_hash_insert (op_hash, optab[-1].name, core_optab, 0))
as_fatal (_("duplicate %s"), optab[-1].name);
}
/* Type checks to compensate for the conversion through void * which
occurs during hash table insertion / lookup. */
(void)(sets == &current_templates->start);
(void)(end == &current_templates->end);
for (; sets < end; ++sets)
if (str_hash_insert (op_hash, (*sets)->name, sets, 0))
as_fatal (_("duplicate %s"), (*sets)->name);
}
/* Initialize reg_hash hash table. */

View File

@ -1703,7 +1703,7 @@ process_i386_opcodes (FILE *table)
{
FILE *fp;
char buf[2048];
unsigned int i, j;
unsigned int i, j, nr;
char *str, *p, *last, *name;
htab_t opcode_hash_table;
struct opcode_hash_entry **opcode_array = NULL;
@ -1819,6 +1819,26 @@ process_i386_opcodes (FILE *table)
fclose (fp);
fprintf (table, "};\n");
/* Generate opcode sets array. */
fprintf (table, "\n/* i386 opcode sets table. */\n\n");
fprintf (table, "static const insn_template *const i386_op_sets[] =\n{\n");
fprintf (table, " i386_optab,\n");
for (nr = j = 0; j < i; j++)
{
struct opcode_hash_entry *next = opcode_array[j];
do
{
++nr;
next = next->next;
}
while (next);
fprintf (table, " i386_optab + %u,\n", nr);
}
fprintf (table, "};\n");
}
static void

File diff suppressed because it is too large Load Diff