On 25/08/18 16:43, Luc Van Oostenryck wrote: > Quite a bit of code needs to know, in a way or another, if a s/in a way/in one way/ > given instruction produce a result (insn->target) or not. s/produce/produces/ > > However, this information not explicit and when need it must s/not/is not/ s/need/needed/ > be retrieved with correct switch/case statements which all s/statements which/statements. These statements/ > need to be updated when a new instruction is added. > > Now that there is a table containing some of the instructions > properties, add to this table a flag telling if the instruction > produce a resut or not. s/produce/produces/ s/resut/result/ ATB, Ramsay Jones > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> > --- > opcode.c | 3 +- > opcode.def | 164 ++++++++++++++++++++++++++--------------------------- > opcode.h | 5 +- > 3 files changed, 88 insertions(+), 84 deletions(-) > > diff --git a/opcode.c b/opcode.c > index 0e41bc068..98ad768f8 100644 > --- a/opcode.c > +++ b/opcode.c > @@ -23,12 +23,13 @@ > #include "opcode.h" > > const struct opcode_table opcode_table[OP_LAST] = { > -#define OPCODE(OP,NG,SW,TF,N) \ > +#define OPCODE(OP,NG,SW,TF,N,FL) \ > [OP_##OP] = { \ > .negate = OP_##NG, \ > .swap = OP_##SW, \ > .to_float = OP_##TF, \ > .arity = N, \ > + .flags = FL, \ > }, > #define OPCODE_RANGE(OP,S,E) > #include "opcode.def" > diff --git a/opcode.def b/opcode.def > index 9a668bb34..5e3664a5d 100644 > --- a/opcode.def > +++ b/opcode.def > @@ -1,114 +1,114 @@ > -// OPCODE negated swaped float > +// OPCODE negated swaped float arity, flags > > -OPCODE(BADOP, BADOP, BADOP, BADOP, 0) > +OPCODE(BADOP, BADOP, BADOP, BADOP, 0, OPF_NONE) > > /* Entry */ > -OPCODE(ENTRY, BADOP, BADOP, BADOP, 0) > +OPCODE(ENTRY, BADOP, BADOP, BADOP, 0, OPF_NONE) > > /* Terminator */ > -OPCODE(RET, BADOP, BADOP, BADOP, 1) > -OPCODE(BR, BADOP, BADOP, BADOP, 0) > -OPCODE(CBR, BADOP, BADOP, BADOP, 1) > -OPCODE(SWITCH, BADOP, BADOP, BADOP, 1) > -OPCODE(COMPUTEDGOTO, BADOP, BADOP, BADOP, 1) > +OPCODE(RET, BADOP, BADOP, BADOP, 1, OPF_NONE) > +OPCODE(BR, BADOP, BADOP, BADOP, 0, OPF_NONE) > +OPCODE(CBR, BADOP, BADOP, BADOP, 1, OPF_NONE) > +OPCODE(SWITCH, BADOP, BADOP, BADOP, 1, OPF_NONE) > +OPCODE(COMPUTEDGOTO, BADOP, BADOP, BADOP, 1, OPF_NONE) > OPCODE_RANGE(TERMINATOR, RET, COMPUTEDGOTO) > > /* Binary */ > -OPCODE(ADD, BADOP, BADOP, FADD, 2) > -OPCODE(SUB, BADOP, BADOP, FSUB, 2) > -OPCODE(MUL, BADOP, BADOP, FMUL, 2) > -OPCODE(DIVU, BADOP, BADOP, FDIV, 2) > -OPCODE(DIVS, BADOP, BADOP, FDIV, 2) > -OPCODE(MODU, BADOP, BADOP, BADOP, 2) > -OPCODE(MODS, BADOP, BADOP, BADOP, 2) > -OPCODE(SHL, BADOP, BADOP, BADOP, 2) > -OPCODE(LSR, BADOP, BADOP, BADOP, 2) > -OPCODE(ASR, BADOP, BADOP, BADOP, 2) > +OPCODE(ADD, BADOP, BADOP, FADD, 2, OPF_TARGET) > +OPCODE(SUB, BADOP, BADOP, FSUB, 2, OPF_TARGET) > +OPCODE(MUL, BADOP, BADOP, FMUL, 2, OPF_TARGET) > +OPCODE(DIVU, BADOP, BADOP, FDIV, 2, OPF_TARGET) > +OPCODE(DIVS, BADOP, BADOP, FDIV, 2, OPF_TARGET) > +OPCODE(MODU, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(MODS, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(SHL, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(LSR, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(ASR, BADOP, BADOP, BADOP, 2, OPF_TARGET) > > /* Floating-point binops */ > -OPCODE(FADD, BADOP, BADOP, BADOP, 2) > -OPCODE(FSUB, BADOP, BADOP, BADOP, 2) > -OPCODE(FMUL, BADOP, BADOP, BADOP, 2) > -OPCODE(FDIV, BADOP, BADOP, BADOP, 2) > +OPCODE(FADD, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(FSUB, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(FMUL, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(FDIV, BADOP, BADOP, BADOP, 2, OPF_TARGET) > > /* Logical */ > -OPCODE(AND_BOOL, BADOP, BADOP, BADOP, 2) > -OPCODE(OR_BOOL, BADOP, BADOP, BADOP, 2) > -OPCODE(AND, BADOP, BADOP, BADOP, 2) > -OPCODE(OR, BADOP, BADOP, BADOP, 2) > -OPCODE(XOR, BADOP, BADOP, BADOP, 2) > +OPCODE(AND_BOOL, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(OR_BOOL, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(AND, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(OR, BADOP, BADOP, BADOP, 2, OPF_TARGET) > +OPCODE(XOR, BADOP, BADOP, BADOP, 2, OPF_TARGET) > OPCODE_RANGE(BINARY, ADD, XOR) > > /* floating-point comparison */ > -OPCODE(FCMP_ORD, FCMP_UNO, FCMP_ORD, BADOP, 2) > -OPCODE(FCMP_OEQ, FCMP_UNE, FCMP_OEQ, BADOP, 2) > -OPCODE(FCMP_ONE, FCMP_UEQ, FCMP_ONE, BADOP, 2) > -OPCODE(FCMP_UEQ, FCMP_ONE, FCMP_UEQ, BADOP, 2) > -OPCODE(FCMP_UNE, FCMP_OEQ, FCMP_UNE, BADOP, 2) > -OPCODE(FCMP_OLT, FCMP_UGE, FCMP_OGT, BADOP, 2) > -OPCODE(FCMP_OLE, FCMP_UGT, FCMP_OGE, BADOP, 2) > -OPCODE(FCMP_OGE, FCMP_ULT, FCMP_OLE, BADOP, 2) > -OPCODE(FCMP_OGT, FCMP_ULE, FCMP_OLT, BADOP, 2) > -OPCODE(FCMP_ULT, FCMP_OGE, FCMP_UGT, BADOP, 2) > -OPCODE(FCMP_ULE, FCMP_OGT, FCMP_UGE, BADOP, 2) > -OPCODE(FCMP_UGE, FCMP_OLT, FCMP_ULE, BADOP, 2) > -OPCODE(FCMP_UGT, FCMP_OLE, FCMP_ULT, BADOP, 2) > -OPCODE(FCMP_UNO, FCMP_ORD, FCMP_UNO, BADOP, 2) > +OPCODE(FCMP_ORD, FCMP_UNO, FCMP_ORD, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_OEQ, FCMP_UNE, FCMP_OEQ, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_ONE, FCMP_UEQ, FCMP_ONE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_UEQ, FCMP_ONE, FCMP_UEQ, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_UNE, FCMP_OEQ, FCMP_UNE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_OLT, FCMP_UGE, FCMP_OGT, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_OLE, FCMP_UGT, FCMP_OGE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_OGE, FCMP_ULT, FCMP_OLE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_OGT, FCMP_ULE, FCMP_OLT, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_ULT, FCMP_OGE, FCMP_UGT, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_ULE, FCMP_OGT, FCMP_UGE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_UGE, FCMP_OLT, FCMP_ULE, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_UGT, FCMP_OLE, FCMP_ULT, BADOP, 2, OPF_TARGET) > +OPCODE(FCMP_UNO, FCMP_ORD, FCMP_UNO, BADOP, 2, OPF_TARGET) > OPCODE_RANGE(FPCMP, FCMP_ORD, FCMP_UNO) > > /* Binary comparison */ > -OPCODE(SET_EQ, SET_NE, SET_EQ, FCMP_OEQ, 2) > -OPCODE(SET_LT, SET_GE, SET_GT, FCMP_OLT, 2) > -OPCODE(SET_LE, SET_GT, SET_GE, FCMP_OLE, 2) > -OPCODE(SET_GE, SET_LT, SET_LE, FCMP_OGE, 2) > -OPCODE(SET_GT, SET_LE, SET_LT, FCMP_OGT, 2) > -OPCODE(SET_B, SET_AE, SET_A, FCMP_OLT, 2) > -OPCODE(SET_BE, SET_A, SET_AE, FCMP_OLE, 2) > -OPCODE(SET_AE, SET_B, SET_BE, FCMP_OGE, 2) > -OPCODE(SET_A, SET_BE, SET_B, FCMP_OGT, 2) > -OPCODE(SET_NE, SET_EQ, SET_NE, FCMP_UNE, 2) > +OPCODE(SET_EQ, SET_NE, SET_EQ, FCMP_OEQ, 2, OPF_TARGET) > +OPCODE(SET_LT, SET_GE, SET_GT, FCMP_OLT, 2, OPF_TARGET) > +OPCODE(SET_LE, SET_GT, SET_GE, FCMP_OLE, 2, OPF_TARGET) > +OPCODE(SET_GE, SET_LT, SET_LE, FCMP_OGE, 2, OPF_TARGET) > +OPCODE(SET_GT, SET_LE, SET_LT, FCMP_OGT, 2, OPF_TARGET) > +OPCODE(SET_B, SET_AE, SET_A, FCMP_OLT, 2, OPF_TARGET) > +OPCODE(SET_BE, SET_A, SET_AE, FCMP_OLE, 2, OPF_TARGET) > +OPCODE(SET_AE, SET_B, SET_BE, FCMP_OGE, 2, OPF_TARGET) > +OPCODE(SET_A, SET_BE, SET_B, FCMP_OGT, 2, OPF_TARGET) > +OPCODE(SET_NE, SET_EQ, SET_NE, FCMP_UNE, 2, OPF_TARGET) > OPCODE_RANGE(BINCMP, SET_EQ, SET_NE) > > /* Uni */ > -OPCODE(NOT, BADOP, BADOP, BADOP, 1) > -OPCODE(NEG, BADOP, BADOP, FNEG, 1) > -OPCODE(FNEG, BADOP, BADOP, BADOP, 1) > -OPCODE(TRUNC, BADOP, BADOP, BADOP, 1) > -OPCODE(ZEXT, BADOP, BADOP, BADOP, 1) > -OPCODE(SEXT, BADOP, BADOP, BADOP, 1) > -OPCODE(FCVTU, BADOP, BADOP, BADOP, 1) > -OPCODE(FCVTS, BADOP, BADOP, BADOP, 1) > -OPCODE(UCVTF, BADOP, BADOP, BADOP, 1) > -OPCODE(SCVTF, BADOP, BADOP, BADOP, 1) > -OPCODE(FCVTF, BADOP, BADOP, BADOP, 1) > -OPCODE(UTPTR, BADOP, BADOP, BADOP, 1) > -OPCODE(PTRTU, BADOP, BADOP, BADOP, 1) > -OPCODE(PTRCAST, BADOP, BADOP, BADOP, 1) > +OPCODE(NOT, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(NEG, BADOP, BADOP, FNEG, 1, OPF_TARGET) > +OPCODE(FNEG, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(TRUNC, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(ZEXT, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(SEXT, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(FCVTU, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(FCVTS, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(UCVTF, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(SCVTF, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(FCVTF, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(UTPTR, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(PTRTU, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(PTRCAST, BADOP, BADOP, BADOP, 1, OPF_TARGET) > OPCODE_RANGE(UNOP, NOT, PTRCAST) > -OPCODE(SYMADDR, BADOP, BADOP, BADOP, 1) > -OPCODE(SLICE, BADOP, BADOP, BADOP, 1) > +OPCODE(SYMADDR, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(SLICE, BADOP, BADOP, BADOP, 1, OPF_TARGET) > > /* Select - three input values */ > -OPCODE(SEL, BADOP, BADOP, BADOP, 3) > +OPCODE(SEL, BADOP, BADOP, BADOP, 3, OPF_TARGET) > > /* Memory */ > -OPCODE(LOAD, BADOP, BADOP, BADOP, 1) > -OPCODE(STORE, BADOP, BADOP, BADOP, 1) > +OPCODE(LOAD, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(STORE, BADOP, BADOP, BADOP, 1, OPF_NONE) > > /* Other */ > -OPCODE(PHISOURCE, BADOP, BADOP, BADOP, 1) > -OPCODE(PHI, BADOP, BADOP, BADOP, 0) > -OPCODE(SETVAL, BADOP, BADOP, BADOP, 0) > -OPCODE(SETFVAL, BADOP, BADOP, BADOP, 0) > -OPCODE(CALL, BADOP, BADOP, BADOP, 1) > -OPCODE(INLINED_CALL, BADOP, BADOP, BADOP, 0) > -OPCODE(NOP, BADOP, BADOP, BADOP, 0) > -OPCODE(DEATHNOTE, BADOP, BADOP, BADOP, 0) > -OPCODE(ASM, BADOP, BADOP, BADOP, 0) > +OPCODE(PHISOURCE, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(PHI, BADOP, BADOP, BADOP, 0, OPF_TARGET) > +OPCODE(SETVAL, BADOP, BADOP, BADOP, 0, OPF_TARGET) > +OPCODE(SETFVAL, BADOP, BADOP, BADOP, 0, OPF_TARGET) > +OPCODE(CALL, BADOP, BADOP, BADOP, 1, OPF_TARGET) > +OPCODE(INLINED_CALL, BADOP, BADOP, BADOP, 0, OPF_NONE) > +OPCODE(NOP, BADOP, BADOP, BADOP, 0, OPF_NONE) > +OPCODE(DEATHNOTE, BADOP, BADOP, BADOP, 0, OPF_NONE) > +OPCODE(ASM, BADOP, BADOP, BADOP, 0, OPF_NONE) > > /* Sparse tagging (line numbers, context, whatever) */ > -OPCODE(CONTEXT, BADOP, BADOP, BADOP, 0) > -OPCODE(RANGE, BADOP, BADOP, BADOP, 3) > +OPCODE(CONTEXT, BADOP, BADOP, BADOP, 0, OPF_NONE) > +OPCODE(RANGE, BADOP, BADOP, BADOP, 3, OPF_NONE) > > /* Needed to translate SSA back to normal form */ > -OPCODE(COPY, BADOP, BADOP, BADOP, 1) > +OPCODE(COPY, BADOP, BADOP, BADOP, 1, OPF_TARGET) > diff --git a/opcode.h b/opcode.h > index 14ac2ffcc..e426bed4f 100644 > --- a/opcode.h > +++ b/opcode.h > @@ -4,7 +4,7 @@ > #include "symbol.h" > > enum opcode { > -#define OPCODE(OP,NG,SW,TF,N) OP_##OP, > +#define OPCODE(OP,NG,SW,TF,N,FL) OP_##OP, > #define OPCODE_RANGE(OP,S,E) OP_##OP = OP_##S, OP_##OP##_END = OP_##E, > #include "opcode.def" > #undef OPCODE > @@ -17,6 +17,9 @@ extern const struct opcode_table { > int swap:8; > int to_float:8; > unsigned int arity:2; > + unsigned int flags:6; > +#define OPF_NONE 0 > +#define OPF_TARGET (1 << 0) > } opcode_table[]; > > >