gnu/gcc/3d735adfba3217ee7e968f250eadf5f3f0a34ecd genextract: encode path steps as numbers rather than letters
The path that locates an operand is a string of steps down the pattern, and
a step used to be spelled as a character: a digit selected an XEXP, a
lower-case letter an XVECEXP, and an upper-case letter an XVECEXP whose
index had run past 'z'. Richard suggested using plain numbers
instead, which is what this does.
A step is now one byte, 2 * INDEX + 1 for XEXP (x, INDEX) and
2 * INDEX + 2 for XVECEXP (x, 0, INDEX). That leaves zero to terminate a
path and 255 to mark an operand number the pattern does not use, so the
walk loses its split ranges:
for (; *p; p++) for (; *p; p++)
if (ISDIGIT (*p)) {
loc = &XEXP (*loc, *p - '0'); unsigned int step = *p - 1;
else if (ISLOWER (*p)) -> if (step & 1)
loc = &XVECEXP (*loc, 0, loc = &XVECEXP (*loc, 0, step >> 1);
*p - 'a'); else
else loc = &XEXP (*loc, step >> 1);
loc = &XVECEXP (*loc, 0, }
*p - UPPER_OFFSET);
The table becomes an array of numbers rather than a string literal, so the
terminator no longer has to be written "\000" to stop the next step being
absorbed into the escape, and a zero in the table no longer looks like the
index 0.
It also removes a silent limit. The old spelling ran out of characters:
an XEXP index above 9 produced ':', which the reader took for an XVECEXP
step, and an XVECEXP index of 58 produced 'a', which it took for index 0.
Neither is reachable from today's machine descriptions, but nothing said
so. The encoder now asserts that an index fits.
The tables grow, because a number costs more source than a printable
character: insn-extract.cc goes from 124888 to 141866 bytes on aarch64,
251020 to 260479 on riscv64, 100542 to 117344 on x86_64 and 26639 to 28958
on avr. For scale, the file was 1.04MB on aarch64 before the table-driven
rewrite.
Bootstrapped on aarch64-none-linux-gnu.
gcc/ChangeLog:
* genextract.cc (locstr): Make it a string of bytes.
(UPPER_OFFSET, MISSING_OPERAND_CHAR): Remove.
(ENCODE_PATH_STEP, MISSING_OPERAND_STEP, MAX_PATH_INDEX): New macros.
(accum_extract::pathstr): Hold bytes.
(push_pathstr_operand): Encode the step as a number and check that
the index fits.
(VEC_safe_set_locstr, VEC_char_to_string, add_path, gen_insn): Update
for the byte paths.
(print_string_literal): Remove.
(print_extractions): Emit the paths as an array of numbers and walk
them without the character ranges.
Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>
1 file changed