[runtime] Add the MONO_INS_FOR_EACH_REG macro.
authorVladimir Kargov <kargov@gmail.com>
Sat, 4 Feb 2017 08:36:28 +0000 (00:36 -0800)
committerVladimir Kargov <kargov@gmail.com>
Mon, 6 Feb 2017 23:51:26 +0000 (15:51 -0800)
mono/mini/mini.h

index b3eb72a0d3f0ec7cc9a843113eaf48695b7c40c3..71adeb1d49457274f70a2331f7e727af1b74f4a2 100644 (file)
@@ -593,6 +593,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;
 };