Commit c6e113f5 authored by Fabrice Bellard's avatar Fabrice Bellard
Browse files

added 'pure' function attribute - fixed indirect function calls

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4469 c046a42c-6fe2-441c-8c8c-71466251a162
parent 0b6ce4cf
Loading
Loading
Loading
Loading
+42 −23
Original line number Diff line number Diff line
@@ -946,11 +946,28 @@ void tcg_liveness_analysis(TCGContext *s)
        def = &tcg_op_defs[op];
        switch(op) {
        case INDEX_op_call:
            {
                int call_flags;

                nb_args = args[-1];
                args -= nb_args;
                nb_iargs = args[0] & 0xffff;
                nb_oargs = args[0] >> 16;
                args++;
                call_flags = args[nb_oargs + nb_iargs];

                /* pure functions can be removed if their result is not
                   used */
                if (call_flags & TCG_CALL_PURE) {
                    for(i = 0; i < nb_oargs; i++) {
                        arg = args[i];
                        if (!dead_temps[arg])
                            goto do_not_remove_call;
                    }
                    tcg_set_nop(s, gen_opc_buf + op_index, 
                                args - 1, nb_args);
                } else {
                do_not_remove_call:

                    /* output args are dead */
                    for(i = 0; i < nb_oargs; i++) {
@@ -971,7 +988,9 @@ void tcg_liveness_analysis(TCGContext *s)
                        dead_temps[arg] = 0;
                    }
                    s->op_dead_iargs[op_index] = dead_iargs;
                }
                args--;
            }
            break;
        case INDEX_op_set_label:
            args--;
@@ -1640,7 +1659,7 @@ static int tcg_reg_alloc_call(TCGContext *s, const TCGOpDef *def,
    }
    
    /* mark dead temporaries and free the associated registers */
    for(i = 0; i < nb_params; i++) {
    for(i = 0; i < nb_iargs; i++) {
        arg = args[nb_oargs + i];
        if (IS_DEAD_IARG(i)) {
            ts = &s->temps[arg];
+4 −0
Original line number Diff line number Diff line
@@ -148,6 +148,10 @@ typedef int TCGv;
#define TCG_CALL_TYPE_REGPARM_1 0x0001 /* i386 style regparm call (1 reg) */
#define TCG_CALL_TYPE_REGPARM_2 0x0002 /* i386 style regparm call (2 regs) */
#define TCG_CALL_TYPE_REGPARM   0x0003 /* i386 style regparm call (3 regs) */
/* A pure function only reads its arguments and globals variables and
   cannot raise exceptions. Hence a call to a pure function can be
   safely suppressed if the return value is not used. */
#define TCG_CALL_PURE           0x0010 

typedef enum {
    TCG_COND_EQ,