You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RISC-V: Reorganize disassembler state initialization
The current disassembler repeatedly checks current state per instruction:
- Whether riscv_gpr_names is initialized to a non-NULL value
- Whether the Zfinx extension is available
- Whether the hash table is initialized
... but they are not frequently changed.
riscv_gpr_names is initialized to a non-NULL value when
- The first disassembler option is specified, or
- Not initialized with disassembler options
(in the first print_insn_riscv function call).
We can safely initialize the default disassembler options prior to the
print_insn_riscv function call and this per-instruction checking of
riscv_gpr_names can be safely removed.
The opcode hash table initialization will be taken care with a later commit.
To group disassembler state initialization, this commit utilizes the
disassemble_init_for_target function. As a side effect, this will also fix
a potential issue when disassembler options is set and then unset on GDB.
This idea is based on opcodes/ppc-dis.c and opcodes/wasm32-dis.c.
New callback function init_riscv_dis_state_for_arch_and_options is called
when either the architecture string or an option is possibly changed.
We can now group the disassembler state initialization together.
It makes state initialization clearer and makes further changes easier.
In performance perspective, this commit has various effects (-5% to 6%).
However, this commit makes implementing large optimizations easier
as well as "RISC-V: Split match/print steps on disassembler".
include/ChangeLog:
* dis-asm.h (disassemble_init_riscv): Add declaration of
disassemble_init_riscv.
opcodes/ChangeLog:
* disassemble.c (disassemble_init_for_target): Call
disassemble_init_riscv to group state initialization together.
* riscv-dis.c
(xlen_by_mach, xlen_by_elf): New variables to store
environment-inferred XLEN.
(is_numeric): New. Instead of directly setting
riscv_{gpr,fpr}_names, use this to store an option.
(update_riscv_dis_xlen): New function to set actual XLEN from
xlen_by_mach and xlen_by_elf variables.
(init_riscv_dis_state_for_arch_and_options): New callback function
called when either the architecture or an option is changed. Set
riscv_{gpr,fpr}_names here.
(set_default_riscv_dis_options): Initialize is_numeric instead of
riscv_gpr_names and riscv_fpr_names.
(parse_riscv_dis_option_without_args): When the "numeric" option
is specified, write to is_numeric instead of register names.
(parse_riscv_dis_options): Suppress setting the default options
here and let disassemble_init_riscv to initialize them.
(riscv_disassemble_insn): Move probing Zfinx and setting XLEN
portions to init_riscv_dis_state_for_arch_and_options and
update_riscv_dis_xlen.
(riscv_get_map_state): If a mapping symbol with ISA string is
suitable, call init_riscv_dis_state_for_arch_and_options function
to update disassembler state.
(print_insn_riscv): Update XLEN only if we haven't guessed correct
XLEN for the disassembler. Stop checking disassembler options for
every instruction and let disassemble_init_riscv to parse options.
(riscv_get_disassembler): Call
init_riscv_dis_state_for_arch_and_options because the architecture
string is possibly updated here.
(disassemble_init_riscv): New function to initialize the
structure, reset/guess correct XLEN and reset/parse disassembler
options.
0 commit comments