return state->depth;
}
+static st_entry *x87_get_entry(x87_state *const state, int const pos)
+{
+ assert(0 <= pos && pos < state->depth);
+ return &state->st[MASK_TOS(state->tos + pos)];
+}
+
/**
* Return the virtual register index at st(pos).
*
*/
static int x87_get_st_reg(const x87_state *state, int pos)
{
- assert(pos < state->depth);
- return state->st[MASK_TOS(state->tos + pos)].reg_idx;
+ return x87_get_entry((x87_state*)state, pos)->reg_idx;
}
#ifdef DEBUG_libfirm
-/**
- * Return the node at st(pos).
- *
- * @param state the x87 state
- * @param pos a stack position
- *
- * @return the IR node that produced the value at st(pos)
- */
-static ir_node *x87_get_st_node(const x87_state *state, int pos)
-{
- assert(pos < state->depth);
- return state->st[MASK_TOS(state->tos + pos)].node;
-}
-
/**
* Dump the stack for debugging.
*
*/
static void x87_dump_stack(const x87_state *state)
{
- int i;
-
- for (i = state->depth - 1; i >= 0; --i) {
- DB((dbg, LEVEL_2, "vf%d(%+F) ", x87_get_st_reg(state, i),
- x87_get_st_node(state, i)));
+ for (int i = state->depth; i-- != 0;) {
+ st_entry const *const entry = x87_get_entry((x87_state*)state, i);
+ DB((dbg, LEVEL_2, "vf%d(%+F) ", entry->reg_idx, entry->node));
}
DB((dbg, LEVEL_2, "<-- TOS\n"));
}
*/
static void x87_set_st(x87_state *state, int reg_idx, ir_node *node, int pos)
{
- assert(0 < state->depth);
- state->st[MASK_TOS(state->tos + pos)].reg_idx = reg_idx;
- state->st[MASK_TOS(state->tos + pos)].node = node;
+ st_entry *const entry = x87_get_entry(state, pos);
+ entry->reg_idx = reg_idx;
+ entry->node = node;
DB((dbg, LEVEL_2, "After SET_REG: "));
DEBUG_ONLY(x87_dump_stack(state);)
*/
static void x87_fxch(x87_state *state, int pos)
{
- st_entry entry;
- assert(pos < state->depth);
-
- entry = state->st[MASK_TOS(state->tos + pos)];
- state->st[MASK_TOS(state->tos + pos)] = state->st[MASK_TOS(state->tos)];
- state->st[MASK_TOS(state->tos)] = entry;
+ st_entry *const a = x87_get_entry(state, pos);
+ st_entry *const b = x87_get_entry(state, 0);
+ st_entry const t = *a;
+ *a = *b;
+ *b = t;
DB((dbg, LEVEL_2, "After FXCH: "));
DEBUG_ONLY(x87_dump_stack(state);)
*/
static int x87_on_stack(const x87_state *state, int reg_idx)
{
- int i, tos = state->tos;
-
- for (i = 0; i < state->depth; ++i)
- if (state->st[MASK_TOS(tos + i)].reg_idx == reg_idx)
+ for (int i = 0; i < state->depth; ++i) {
+ if (x87_get_st_reg(state, i) == reg_idx)
return i;
+ }
return -1;
}
++state->depth;
state->tos = MASK_TOS(state->tos - 1);
- state->st[state->tos].reg_idx = reg_idx;
- state->st[state->tos].node = node;
+ st_entry *const entry = x87_get_entry(state, 0);
+ entry->reg_idx = reg_idx;
+ entry->node = node;
DB((dbg, LEVEL_2, "After PUSH: ")); DEBUG_ONLY(x87_dump_stack(state);)
}
*/
static int sim_Return(x87_state *state, ir_node *n)
{
- int n_res = be_Return_get_n_rets(n);
- int i, n_float_res = 0;
-
+#ifdef DEBUG_libfirm
/* only floating point return values must reside on stack */
- for (i = 0; i < n_res; ++i) {
- ir_node *res = get_irn_n(n, n_be_Return_val + i);
-
+ int n_float_res = 0;
+ int const n_res = be_Return_get_n_rets(n);
+ for (int i = 0; i < n_res; ++i) {
+ ir_node *const res = get_irn_n(n, n_be_Return_val + i);
if (mode_is_float(get_irn_mode(res)))
++n_float_res;
}
assert(x87_get_depth(state) == n_float_res);
+#endif
/* pop them virtually */
- for (i = n_float_res - 1; i >= 0; --i)
- x87_pop(state);
-
+ x87_emms(state);
return NO_NODE_ADDED;
}
/**
* Kill any dead registers at block start by popping them from the stack.
*
- * @param sim the simulator handle
- * @param block the current block
- * @param start_state the x87 state at the begin of the block
- *
- * @return the x87 state after dead register killed
+ * @param sim the simulator handle
+ * @param block the current block
+ * @param state the x87 state at the begin of the block
*/
-static x87_state *x87_kill_deads(x87_simulator *sim, ir_node *block, x87_state *start_state)
+static void x87_kill_deads(x87_simulator *const sim, ir_node *const block, x87_state *const state)
{
- x87_state *state = start_state;
ir_node *first_insn = sched_first(block);
ir_node *keep = NULL;
unsigned live = vfp_live_args_after(sim, block, 0);
}
if (kill_mask) {
- /* create a new state, will be changed */
- state = x87_clone_state(sim, state);
-
DB((dbg, LEVEL_1, "Killing deads:\n"));
DEBUG_ONLY(vfp_dump_live(live);)
DEBUG_ONLY(x87_dump_stack(state);)
sched_add_before(first_insn, keep);
keep_alive(keep);
x87_emms(state);
- return state;
+ return;
}
}
/* now kill registers */
}
keep_alive(keep);
}
- return state;
}
/**
DB((dbg, LEVEL_2, "State at Block begin:\n "));
DEBUG_ONLY(x87_dump_stack(state);)
- /* at block begin, kill all dead registers */
- state = x87_kill_deads(sim, block, state);
/* create a new state, will be changed */
state = x87_clone_state(sim, state);
+ /* at block begin, kill all dead registers */
+ x87_kill_deads(sim, block, state);
/* beware, n might change */
for (n = sched_first(block); !sched_is_end(n); n = next) {