Switch from guaranteed-contiguous DR_REG_ enum ranges to function interfaces
Xref various discussions in PR #3497 such as https://github.com/DynamoRIO/dynamorio/pull/3497#discussion_r273321446
Having a public, exposed DR_REG_ enum list and trying to guarantee that classes of registers remain single, contiguous blocks throughout ISA extensions simply does not work. E.g., with AVX-512 we have 16 more XMM and YMM registers added. Placing them adjacent to the existing XMM and YMM enum values breaks compatibility: this is an interface num, not a private one that can be freely reordered.
The clean solution is to remove the START and STOP range values and replace them with function accessors for the count of registers in each class and for the integer offset of a particular register within a class.
So we'd change this drreg code:
#define GPR_IDX(reg) ((reg)-DR_REG_START_GPR)
...
reg_id_t reg = opnd_get_reg_used(opnd, i);
pt->reg[GPR_IDX(reg)].app_uses++;
...
for (reg = DR_REG_START_GPR; reg <= DR_REG_STOP_GPR; reg++) {
if (pt->reg[GPR_IDX(reg)].in_use) {
into something like this, removing the macro which was only there because of the kind of ugly method of computing the index:
reg_id_t reg = opnd_get_reg_used(opnd, i);
pt->reg[reg_index(reg)].app_uses++;
...
for (idx = 0; idx <= reg_count_gpr(); idx++) {
if (pt->reg[idx].in_use) {
We'd also need a function to go from a 0-based index to a reg_Id_t value.
This divorces the register classes from the enum, which becomes simply a list where all that's important is to have an entry somewhere: where does not matter, letting us append to the end on ISA extensions.