core/kernel_linux/clients/umbra/instrument.c
/* Idea of register stealling 
 * 1. for dead register, use it directly
 * 2. for steal register, expand its range as large as possible
 */
Idea of register stealling
1. for dead register, use it directly
2. for steal register, expand its range as large as possible
Idea of register stealling 1 . for dead register use it directly 2 . for steal register expand its range as large as possible
static bool
should_insert_regs_stealing(ilist_info_t *ilist_info,
                            instr_t      *instr,
                            instr_t      *prev)
{
    int i;
    reg_status_t *regs = ilist_info->regs;
    for (i = 1; i < NUM_SPILL_REGS; i++) {
        if (regs[i].steal == false)
            continue;
        if (proc_info.options.opt_regs_stealing == false) {
            regs[i].save_now = true;
        }
        else {
            if (prev == NULL || register_is_used(prev, regs[i].reg) ||
                !proc_info.options.opt_unsafe_regs_stealing) {
                if (!regs[i].dead)
                    regs[i].save_now = true;
            }
        }
    }
    for (i = 1; i < NUM_SPILL_REGS; i++) {
        if (regs[i].save_now == true || regs[i].restore_now == true)
            return true;
    }
    return false;
}
static bool should_insert_regs_stealing ( ilist_info_t * ilist_info , instr_t * instr , instr_t * prev ) { int i ; reg_status_t * regs = ilist_info -> regs ; for ( i = 1 ; i < NUM_SPILL_REGS ; i ++ ) { if ( regs [ i ] . steal == false ) continue ; if ( proc_info . options . opt_regs_stealing == false ) { regs [ i ] . save_now = true ; } else { if ( prev == NULL || register_is_used ( prev , regs [ i ] . reg ) || ! proc_info . options . opt_unsafe_regs_stealing ) { if ( ! regs [ i ] . dead ) regs [ i ] . save_now = true ; } } } for ( i = 1 ; i < NUM_SPILL_REGS ; i ++ ) { if ( regs [ i ] . save_now == true || regs [ i ] . restore_now == true ) return true ; } return false ; }
Idea of register stealling
 1. for dead register, use it directly
 2. for steal register, expand its range as large as possible
Idea of register stealling 1 . for dead register use it directly 2 . for steal register expand its range as large as possible
/* naively, we save the register right before steal it */ /* however we can optimize the register stealing, 
             * by expanding the register stealing ragne
             * when steal a register, we push the reg save operation
             * as early as possible:
             * 1. no more prev instr 
             * 2. or reg will be used by app
             * in this way, the steal reg can hopefully used by several 
             * memory reference. 
             * In another word, we try to use one register stealling for 
             * more than one memory reference instruction.
             */ /* the restore_now is only updated */