Skip to content

Commit

Permalink
i#1569 AArch64: Rename members of callee_info_t.
Browse files Browse the repository at this point in the history
This is to make the names also applicable to AArch64, in preparation
for moving some of x86/clean_call_opt.c into clean_call_opt_shared.c.

This is search-and-replace with a few adjustments to spaces and comments.

Review-URL: https://codereview.appspot.com/315880043
  • Loading branch information
egrimley-arm committed Nov 22, 2016
1 parent 23a236e commit 4a5189e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
8 changes: 4 additions & 4 deletions core/arch/aarch64/clean_call_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ callee_info_init(callee_info_t *ci)
memset(ci, 0, sizeof(*ci));
ci->bailout = true;
/* to be conservative */
ci->has_locals = true;
ci->write_aflags = true;
ci->read_aflags = true;
ci->tls_used = true;
ci->has_locals = true;
ci->write_flags = true;
ci->read_flags = true;
ci->tls_used = true;
}

void
Expand Down
10 changes: 5 additions & 5 deletions core/arch/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,16 +1252,16 @@ typedef struct _callee_info_t {
app_pc start; /* entry point of a function */
app_pc bwd_tgt; /* earliest backward branch target */
app_pc fwd_tgt; /* last forward branch target */
int num_xmms_used; /* number of xmms used by callee */
bool xmm_used[NUM_SIMD_REGS]; /* xmm/ymm registers usage */
int num_simd_used; /* number of SIMD registers (xmms) used by callee */
bool simd_used[NUM_SIMD_REGS]; /* SIMD (xmm/ymm) registers usage */
bool reg_used[NUM_GP_REGS]; /* general purpose registers usage */
int num_callee_save_regs; /* number of regs callee saved */
bool callee_save_regs[NUM_GP_REGS]; /* callee-save registers */
bool has_locals; /* if reference local via stack */
bool xbp_is_fp; /* if xbp is used as frame pointer */
bool standard_fp; /* if standard reg (xbp/x29) is used as frame pointer */
bool opt_inline; /* can be inlined or not */
bool write_aflags; /* if the function changes aflags */
bool read_aflags; /* if the function reads aflags from caller */
bool write_flags; /* if the function changes flags */
bool read_flags; /* if the function reads flags from caller */
bool tls_used; /* application accesses TLS (errno, etc.) */
reg_id_t spill_reg; /* base register for spill slots */
uint slots_used; /* scratch slots needed after analysis */
Expand Down
8 changes: 4 additions & 4 deletions core/arch/arm/clean_call_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ callee_info_init(callee_info_t *ci)
memset(ci, 0, sizeof(*ci));
ci->bailout = true;
/* to be conservative */
ci->has_locals = true;
ci->write_aflags = true;
ci->read_aflags = true;
ci->tls_used = true;
ci->has_locals = true;
ci->write_flags = true;
ci->read_flags = true;
ci->tls_used = true;
}

void
Expand Down
64 changes: 32 additions & 32 deletions core/arch/x86/clean_call_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ callee_info_init(callee_info_t *ci)
memset(ci, 0, sizeof(*ci));
ci->bailout = true;
/* to be conservative */
ci->has_locals = true;
ci->write_aflags = true;
ci->read_aflags = true;
ci->tls_used = true;
ci->has_locals = true;
ci->write_flags = true;
ci->read_flags = true;
ci->tls_used = true;
/* We use loop here and memset in analyze_callee_regs_usage later.
* We could reverse the logic and use memset to set the value below,
* but then later in analyze_callee_regs_usage, we have to use the loop.
*/
/* assuming all xmm registers are used */
ci->num_xmms_used = NUM_SIMD_REGS;
ci->num_simd_used = NUM_SIMD_REGS;
for (i = 0; i < NUM_SIMD_REGS; i++)
ci->xmm_used[i] = true;
ci->simd_used[i] = true;
for (i = 0; i < NUM_GP_REGS; i++)
ci->reg_used[i] = true;
ci->spill_reg = DR_REG_INVALID;
Expand Down Expand Up @@ -452,10 +452,10 @@ analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
instr_t *instr;
uint i, num_regparm;

ci->num_xmms_used = 0;
memset(ci->xmm_used, 0, sizeof(bool) * NUM_SIMD_REGS);
ci->num_simd_used = 0;
memset(ci->simd_used, 0, sizeof(bool) * NUM_SIMD_REGS);
memset(ci->reg_used, 0, sizeof(bool) * NUM_GP_REGS);
ci->write_aflags = false;
ci->write_flags = false;
for (instr = instrlist_first(ilist);
instr != NULL;
instr = instr_get_next(instr)) {
Expand All @@ -467,13 +467,13 @@ analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
*/
/* XMM registers usage */
for (i = 0; i < NUM_SIMD_REGS; i++) {
if (!ci->xmm_used[i] &&
if (!ci->simd_used[i] &&
instr_uses_reg(instr, (DR_REG_XMM0 + (reg_id_t)i))) {
LOG(THREAD, LOG_CLEANCALL, 2,
"CLEANCALL: callee "PFX" uses XMM%d at "PFX"\n",
ci->start, i, instr_get_app_pc(instr));
ci->xmm_used[i] = true;
ci->num_xmms_used++;
ci->simd_used[i] = true;
ci->num_simd_used++;
}
}
/* General purpose registers */
Expand All @@ -482,7 +482,7 @@ analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
if (!ci->reg_used[i] &&
/* Later we'll rewrite stack accesses to not use XSP or XBP. */
reg != DR_REG_XSP &&
(reg != DR_REG_XBP || !ci->xbp_is_fp) &&
(reg != DR_REG_XBP || !ci->standard_fp) &&
instr_uses_reg(instr, reg)) {
LOG(THREAD, LOG_CLEANCALL, 2,
"CLEANCALL: callee "PFX" uses REG %s at "PFX"\n",
Expand All @@ -493,37 +493,37 @@ analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
}
}
/* callee update aflags */
if (!ci->write_aflags) {
if (!ci->write_flags) {
if (TESTANY(EFLAGS_WRITE_6,
instr_get_arith_flags(instr, DR_QUERY_INCLUDE_ALL))) {
LOG(THREAD, LOG_CLEANCALL, 2,
"CLEANCALL: callee "PFX" updates aflags\n", ci->start);
ci->write_aflags = true;
ci->write_flags = true;
}
}
}

/* check if callee read aflags from caller */
/* set it false for the case of empty callee. */
ci->read_aflags = false;
ci->read_flags = false;
for (instr = instrlist_first(ilist);
instr != NULL;
instr = instr_get_next(instr)) {
uint flags = instr_get_arith_flags(instr, DR_QUERY_DEFAULT);
if (TESTANY(EFLAGS_READ_6, flags)) {
ci->read_aflags = true;
ci->read_flags = true;
break;
}
if (TESTALL(EFLAGS_WRITE_6, flags))
break;
if (instr_is_return(instr))
break;
if (instr_is_cti(instr)) {
ci->read_aflags = true;
ci->read_flags = true;
break;
}
}
if (ci->read_aflags) {
if (ci->read_flags) {
LOG(THREAD, LOG_CLEANCALL, 2,
"CLEANCALL: callee "PFX" reads aflags from caller\n", ci->start);
}
Expand All @@ -532,7 +532,7 @@ analyze_callee_regs_usage(dcontext_t *dcontext, callee_info_t *ci)
* We may or may not use the slot at the call site, but it needs to be
* reserved just in case.
*/
if (ci->read_aflags || ci->write_aflags) {
if (ci->read_flags || ci->write_flags) {
/* XXX: We can optimize away the flags spill to memory if the callee
* does not use xax.
*/
Expand Down Expand Up @@ -616,7 +616,7 @@ analyze_callee_save_reg(dcontext_t *dcontext, callee_info_t *ci)
(ci->fwd_tgt == NULL || instr_get_app_pc(leave) >= ci->fwd_tgt)) {
/* check if xbp is fp */
if (instr_get_opcode(enter) == OP_enter) {
ci->xbp_is_fp = true;
ci->standard_fp = true;
} else {
/* i#392-c#2: mov xsp => xbp might not be right after push_xbp */
for (instr = instr_get_next(enter);
Expand All @@ -634,15 +634,15 @@ analyze_callee_save_reg(dcontext_t *dcontext, callee_info_t *ci)
opnd_is_reg(instr_get_dst(instr, 0)) &&
opnd_get_reg(instr_get_dst(instr, 0)) == DR_REG_XBP) {
/* found mov xsp => xbp */
ci->xbp_is_fp = true;
ci->standard_fp = true;
/* remove it */
instrlist_remove(ilist, instr);
instr_destroy(GLOBAL_DCONTEXT, instr);
break;
}
}
}
if (ci->xbp_is_fp) {
if (ci->standard_fp) {
LOG(THREAD, LOG_CLEANCALL, 2,
"CLEANCALL: callee "PFX" use XBP as frame pointer\n", ci->start);
} else {
Expand Down Expand Up @@ -795,7 +795,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
ci->start);
opt_inline = false;
}
if (ci->num_xmms_used != 0) {
if (ci->num_simd_used != 0) {
LOG(THREAD, LOG_CLEANCALL, 1,
"CLEANCALL: callee "PFX" cannot be inlined: uses XMM.\n",
ci->start);
Expand Down Expand Up @@ -836,7 +836,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
next_instr = instr_get_next(instr);
/* sanity checks on stack usage */
if (instr_writes_to_reg(instr, DR_REG_XBP, DR_QUERY_INCLUDE_ALL) &&
ci->xbp_is_fp) {
ci->standard_fp) {
/* xbp must not be changed if xbp is used for frame pointer */
LOG(THREAD, LOG_CLEANCALL, 1,
"CLEANCALL: callee "PFX" cannot be inlined: XBP is updated.\n",
Expand Down Expand Up @@ -883,7 +883,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
break;
}
} else if (instr_reg_in_src(instr, DR_REG_XSP) ||
(instr_reg_in_src(instr, DR_REG_XBP) && ci->xbp_is_fp)) {
(instr_reg_in_src(instr, DR_REG_XBP) && ci->standard_fp)) {
/* Detect stack address leakage */
/* lea [xsp/xbp] */
if (opc == OP_lea)
Expand All @@ -893,7 +893,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
opnd_t src = instr_get_src(instr, i);
if (opnd_is_reg(src) &&
(reg_overlap(REG_XSP, opnd_get_reg(src)) ||
(reg_overlap(REG_XBP, opnd_get_reg(src)) && ci->xbp_is_fp)))
(reg_overlap(REG_XBP, opnd_get_reg(src)) && ci->standard_fp)))
break;
}
if (i != instr_num_srcs(instr))
Expand All @@ -915,7 +915,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
if (!opnd_is_base_disp(opnd))
continue;
if (opnd_get_base(opnd) != DR_REG_XSP &&
(opnd_get_base(opnd) != DR_REG_XBP || !ci->xbp_is_fp))
(opnd_get_base(opnd) != DR_REG_XBP || !ci->standard_fp))
continue;
if (!ci->has_locals) {
/* We see the first one, remember it. */
Expand Down Expand Up @@ -955,7 +955,7 @@ analyze_callee_inline(dcontext_t *dcontext, callee_info_t *ci)
if (!opnd_is_base_disp(opnd))
continue;
if (opnd_get_base(opnd) != DR_REG_XSP &&
(opnd_get_base(opnd) != DR_REG_XBP || !ci->xbp_is_fp))
(opnd_get_base(opnd) != DR_REG_XBP || !ci->standard_fp))
continue;
if (!ci->has_locals) {
mem_ref = opnd;
Expand Down Expand Up @@ -1028,8 +1028,8 @@ analyze_clean_call_aflags(dcontext_t *dcontext,

/* If there's a flags read, we clear the flags. If there's a write or read,
* we save them, because a read creates a clear which is a write. */
cci->skip_clear_flags = !ci->read_aflags;
cci->skip_save_flags = !(ci->write_aflags || ci->read_aflags);
cci->skip_clear_flags = !ci->read_flags;
cci->skip_save_flags = !(ci->write_flags || ci->read_flags);
/* XXX: this is a more aggressive optimization by analyzing the ilist
* to be instrumented. The client may change the ilist, which violate
* the analysis result. For example,
Expand Down Expand Up @@ -1061,7 +1061,7 @@ analyze_clean_call_regs(dcontext_t *dcontext, clean_call_info_t *cci)

/* 1. xmm registers */
for (i = 0; i < NUM_SIMD_REGS; i++) {
if (info->xmm_used[i]) {
if (info->simd_used[i]) {
cci->simd_skip[i] = false;
} else {
LOG(THREAD, LOG_CLEANCALL, 3,
Expand Down

0 comments on commit 4a5189e

Please sign in to comment.