core/kernel_linux/clients/umbra/optimize.c
/* this function to optimize some register stealing code away 
 * for case like below:
 * 
 *  restore %reg
 *  ...
 *  save %reg
 *  
 *  if the %reg is not updated in between, the save %reg can be 
 * optimized out
 */
this function to optimize some register stealing code away
for case like below.

restore %reg

save %reg

if the %reg is not updated in between, the save %reg can be
optimized out
this function to optimize some register stealing code away for case like below . restore %reg save %reg if the %reg is not updated in between the save %reg can be optimized out
static void
optimize_register_stealing(void *drcontext, 
                           umbra_info_t *umbra_info,
                           void *tag,
                           instrlist_t *ilist)
{
    instr_t *instr, *nexti;
    instr_t *reg_restore[NUM_SPILL_REGS];
    reg_id_t regs[NUM_SPILL_REGS];
    int i;
    for (i = 1; i < NUM_SPILL_REGS; i++) {
        reg_restore[i] = NULL;
        regs[i] = REG_SPILL_START + i;
    }
    for (instr = instrlist_first(ilist); instr != NULL; instr = nexti) {
        nexti = instr_get_next(instr);
        if (instr_get_app_pc(instr) != NULL && 
            !instr_is_meta_may_fault(instr)) {
            for (i = 1; i < NUM_SPILL_REGS; i++) {
                if (register_is_updated(instr, regs[i])) 
                    reg_restore[i] = NULL;
            }
        } else {
            for (i = 1; i < NUM_SPILL_REGS; i++) {
                if (instr_is_reg_restore(instr, regs[i], umbra_info)) {
                    reg_restore[i] = instr;
                    break; 
                } else if (instr_is_reg_save(instr, regs[i], umbra_info) &&
                           reg_restore[i] != NULL) {
                    instrlist_remove(ilist, instr);
                    instr_destroy(drcontext, instr);
                    break;
                }
            }
        }
    }
}
static void optimize_register_stealing ( void * drcontext , umbra_info_t * umbra_info , void * tag , instrlist_t * ilist ) { instr_t * instr , * nexti ; instr_t * reg_restore [ NUM_SPILL_REGS ] ; reg_id_t regs [ NUM_SPILL_REGS ] ; int i ; for ( i = 1 ; i < NUM_SPILL_REGS ; i ++ ) { reg_restore [ i ] = NULL ; regs [ i ] = REG_SPILL_START + i ; } for ( instr = instrlist_first ( ilist ) ; instr != NULL ; instr = nexti ) { nexti = instr_get_next ( instr ) ; if ( instr_get_app_pc ( instr ) != NULL && ! instr_is_meta_may_fault ( instr ) ) { for ( i = 1 ; i < NUM_SPILL_REGS ; i ++ ) { if ( register_is_updated ( instr , regs [ i ] ) ) reg_restore [ i ] = NULL ; } } else { for ( i = 1 ; i < NUM_SPILL_REGS ; i ++ ) { if ( instr_is_reg_restore ( instr , regs [ i ] , umbra_info ) ) { reg_restore [ i ] = instr ; break ; } else if ( instr_is_reg_save ( instr , regs [ i ] , umbra_info ) && reg_restore [ i ] != NULL ) { instrlist_remove ( ilist , instr ) ; instr_destroy ( drcontext , instr ) ; break ; } } } } }
this function to optimize some register stealing code away
 for case like below:
this function to optimize some register stealing code away for case like below :
/* skip reg eax */ /* check if app code update register */