Merge pull request #4327 from vkargov/vk-abcremedy
[mono.git] / mono / mini / mini.h
index e86b807375f7a0605c056cec4f41e56d24a59388..6eb32809205aa44af20d634bfaf7607a344fa0e3 100644 (file)
@@ -595,6 +595,20 @@ extern const gint8 ins_sreg_counts [];
 
 #define mono_bb_first_ins(bb) (bb)->code
 
+/*
+ * Iterate through all used registers in the instruction.
+ * Relies on the existing order of the MONO_INST enum: MONO_INST_{DREG,SREG1,SREG2,SREG3,LEN}
+ * INS is the instruction, IDX is the register index, REG is the pointer to a register.
+ */
+#define MONO_INS_FOR_EACH_REG(ins, idx, reg) for ((idx) = INS_INFO ((ins)->opcode)[MONO_INST_DEST] != ' ' ? MONO_INST_DEST : \
+                                                         (mono_inst_get_num_src_registers (ins) ? MONO_INST_SRC1 : MONO_INST_LEN); \
+                                                 (reg) = (idx) == MONO_INST_DEST ? &(ins)->dreg : \
+                                                         ((idx) == MONO_INST_SRC1 ? &(ins)->sreg1 : \
+                                                          ((idx) == MONO_INST_SRC2 ? &(ins)->sreg2 : \
+                                                           ((idx) == MONO_INST_SRC3 ? &(ins)->sreg3 : NULL))), \
+                                                         idx < MONO_INST_LEN; \
+                                                 (idx) = (idx) > mono_inst_get_num_src_registers (ins) + (INS_INFO ((ins)->opcode)[MONO_INST_DEST] != ' ') ? MONO_INST_LEN : (idx) + 1)
+
 struct MonoSpillInfo {
        int offset;
 };