Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new whole-instr register iterator #6717

Open
edeiana opened this issue Mar 23, 2024 · 0 comments
Open

Add new whole-instr register iterator #6717

edeiana opened this issue Mar 23, 2024 · 0 comments

Comments

@edeiana
Copy link
Contributor

edeiana commented Mar 23, 2024

Currently we don't have a way to iterate over the register operands of an instr_t directly.
To do so, we have to:

  1. obtain the number of src (instr_num_srcs()) and dst (instr_num_dsts()) operands;
  2. iterate over and obtain the operand (with instr_get_src() and instr_get_dst());
  3. obtain the number of registers of every operand with opnd_num_regs_used();
  4. iterate over and obtain the reg_id_t register with opnd_get_reg_used().

We find this operation common enough to warrant its own APIs in core/ir/instr_shared.c to avoid code duplication.

Since we still want to distinguish between source register operands and destination register operands of an instr_t, we'd want the following 4 APIs:

uint instr_num_src_reg(instr_t *instr);
uint instr_num_dst_reg(instr_t *instr);
reg_id_t instr_get_src_reg(instr_t *instr, uint index);
reg_id_t instr_get_dst_reg(instr_t *instr, uint index);

Note that registers in destination operands that are memory references are still being read, hence they should be counted among the source register operands of an instruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants