removed #if 0'ed functions
[r13461]
static x87_state _empty = { { {0, NULL}, }, 0, 0 };
static x87_state *empty = (x87_state *)&_empty;
static x87_state _empty = { { {0, NULL}, }, 0, 0 };
static x87_state *empty = (x87_state *)&_empty;
-/** The type of an instruction simulator function. */
+enum {
+ NO_NODE_ADDED = 0, /**< No node was added. */
+ NODE_ADDED = 1 /**< A node was added by the simulator in the schedule. */
+};
+
+/**
+ * The type of an instruction simulator function.
+ *
+ * @param state the x87 state
+ * @param n the node to be simulated
+ *
+ * @return NODE_ADDED if a node was added AFTER n in schedule,
+ * NO_NODE_ADDED else
+ */
typedef int (*sim_func)(x87_state *state, ir_node *n);
/**
typedef int (*sim_func)(x87_state *state, ir_node *n);
/**
be_lv_t *lv; /**< intrablock liveness. */
vfp_liveness *live; /**< Liveness information. */
unsigned n_idx; /**< The cached get_irg_last_idx() result. */
be_lv_t *lv; /**< intrablock liveness. */
vfp_liveness *live; /**< Liveness information. */
unsigned n_idx; /**< The cached get_irg_last_idx() result. */
- waitq *worklist; /**< list of blocks to process. */
+ waitq *worklist; /**< Worklist of blocks that must be processed. */
*/
static int x87_get_depth(const x87_state *state) {
return state->depth;
*/
static int x87_get_depth(const x87_state *state) {
return state->depth;
-}
-
-#if 0
-/**
- * Check if the state is empty.
- *
- * @param state the x87 state
- *
- * returns non-zero if the x87 stack is empty
- */
-static int x87_state_is_empty(const x87_state *state) {
- return state->depth == 0;
-}
-#endif
/**
* Return the virtual register index at st(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;
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 the node at st(pos).
/**
* Return the node at st(pos).
x87_set_st(state, reg_idx, node, 0);
} /* x87_set_tos */
x87_set_st(state, reg_idx, node, 0);
} /* x87_set_tos */
-#if 0
-/**
- * Flush the x87 stack.
- *
- * @param state the x87 state
- */
-static void x87_flush(x87_state *state) {
- state->depth = 0;
- state->tos = 0;
-} /* x87_flush */
-#endif
-
/**
* Swap st(0) with st(pos).
*
/**
* Swap st(0) with st(pos).
*
- * Push a virtual Register onto the stack, double pushes are NOT allowed..
+ * Push a virtual Register onto the stack, double pushes are NOT allowed.
*
* @param state the x87 state
* @param reg_idx the register vfp index
*
* @param state the x87 state
* @param reg_idx the register vfp index
/**
* Pop a virtual Register from the stack.
/**
* Pop a virtual Register from the stack.
+ *
+ * @param state the x87 state
*/
static void x87_pop(x87_state *state) {
assert(state->depth > 0 && "stack underrun");
*/
static void x87_pop(x87_state *state) {
assert(state->depth > 0 && "stack underrun");
return res;
} /* x87_alloc_state */
return res;
} /* x87_alloc_state */
-#if 0
-/**
- * Create a new empty x87 state.
- *
- * @param sim the x87 simulator handle
- *
- * @return a new empty x87 state
- */
-static x87_state *x87_alloc_empty_state(x87_simulator *sim) {
- x87_state *res = x87_alloc_state(sim);
-
- x87_flush(res);
- return res;
-} /* x87_alloc_empty_state */
-#endif
-
/**
* Clone a x87 state.
*
/**
* Clone a x87 state.
*
/**
* Patch a virtual instruction into a x87 one and return
/**
* Patch a virtual instruction into a x87 one and return
+ * the node representing the result value.
*
* @param n the IR node to patch
* @param op the x87 opcode to patch in
*
* @param n the IR node to patch
* @param op the x87 opcode to patch in
- }
- else if (mode_is_float(mode))
+ } else if (mode_is_float(mode))
set_irn_mode(n, mode_E);
return res;
} /* x87_patch_insn */
set_irn_mode(n, mode_E);
return res;
} /* x87_patch_insn */
res = arch_get_irn_register(sim->arch_env, irn);
assert(res->reg_class->regs == ia32_vfp_regs);
return res;
res = arch_get_irn_register(sim->arch_env, irn);
assert(res->reg_class->regs == ia32_vfp_regs);
return res;
+} /* x87_get_irn_register */
/* -------------- x87 perm --------------- */
/* -------------- x87 perm --------------- */
*
* @return the fxch node
*/
*
* @return the fxch node
*/
-static ir_node *x87_fxch_shuffle(x87_state *state, int pos, ir_node *block)
-{
+static ir_node *x87_fxch_shuffle(x87_state *state, int pos, ir_node *block) {
ir_node *fxch;
ia32_attr_t *attr;
ir_node *fxch;
ia32_attr_t *attr;
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param tmpl the template containing the 4 possible x87 opcodes
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param tmpl the template containing the 4 possible x87 opcodes
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_binop(x87_state *state, ir_node *n, const exchange_tmpl *tmpl) {
int op2_idx = 0, op1_idx;
*/
static int sim_binop(x87_state *state, ir_node *n, const exchange_tmpl *tmpl) {
int op2_idx = 0, op1_idx;
arch_register_get_name(out)));
}
arch_register_get_name(out)));
}
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param op the x87 opcode that will replace n's opcode
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param op the x87 opcode that will replace n's opcode
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_unop(x87_state *state, ir_node *n, ir_op *op) {
int op1_idx, out_idx;
*/
static int sim_unop(x87_state *state, ir_node *n, ir_op *op) {
int op1_idx, out_idx;
attr->x87[2] = out = &ia32_st_regs[0];
DB((dbg, LEVEL_1, "<<< %s -> %s\n", get_irn_opname(n), out->name));
attr->x87[2] = out = &ia32_st_regs[0];
DB((dbg, LEVEL_1, "<<< %s -> %s\n", get_irn_opname(n), out->name));
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param op the x87 opcode that will replace n's opcode
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param op the x87 opcode that will replace n's opcode
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_load(x87_state *state, ir_node *n, ir_op *op) {
const arch_register_t *out = x87_get_irn_register(state->sim, n);
*/
static int sim_load(x87_state *state, ir_node *n, ir_op *op) {
const arch_register_t *out = x87_get_irn_register(state->sim, n);
attr->x87[2] = out = &ia32_st_regs[0];
DB((dbg, LEVEL_1, "<<< %s -> %s\n", get_irn_opname(n), arch_register_get_name(out)));
attr->x87[2] = out = &ia32_st_regs[0];
DB((dbg, LEVEL_1, "<<< %s -> %s\n", get_irn_opname(n), arch_register_get_name(out)));
ir_node *val = get_irn_n(n, STORE_VAL_IDX);
const arch_register_t *op2 = x87_get_irn_register(sim, val);
unsigned live = vfp_live_args_after(sim, n, 0);
ir_node *val = get_irn_n(n, STORE_VAL_IDX);
const arch_register_t *op2 = x87_get_irn_register(sim, val);
unsigned live = vfp_live_args_after(sim, n, 0);
+ int insn = NO_NODE_ADDED;
ia32_attr_t *attr;
int op2_reg_idx, op2_idx, depth;
int live_after_node;
ia32_attr_t *attr;
int op2_reg_idx, op2_idx, depth;
int live_after_node;
op2_reg_idx = arch_register_get_index(op2);
if (op2_reg_idx == REG_VFP_UKNWN) {
op2_reg_idx = arch_register_get_index(op2);
if (op2_reg_idx == REG_VFP_UKNWN) {
- // just take any value from stack
+ /* just take any value from stack */
if(state->depth > 0) {
op2_idx = 0;
DEBUG_ONLY(op2 = NULL);
live_after_node = 1;
} else {
if(state->depth > 0) {
op2_idx = 0;
DEBUG_ONLY(op2 = NULL);
live_after_node = 1;
} else {
- // produce a new value which we will consume imediately
+ /* produce a new value which we will consume immediately */
x87_create_fldz(state, n, op2_reg_idx);
live_after_node = 0;
op2_idx = x87_on_stack(state, op2_reg_idx);
x87_create_fldz(state, n, op2_reg_idx);
live_after_node = 0;
op2_idx = x87_on_stack(state, op2_reg_idx);
x87_create_fpush(state, n, op2_idx, STORE_VAL_IDX);
x87_pop(state);
x87_patch_insn(n, op_p);
x87_create_fpush(state, n, op2_idx, STORE_VAL_IDX);
x87_pop(state);
x87_patch_insn(n, op_p);
ir_node *vfld, *mem, *block, *rproj, *mproj;
ir_graph *irg;
ir_node *vfld, *mem, *block, *rproj, *mproj;
ir_graph *irg;
/* rewire all users, scheduled after the store, to the loaded value */
collect_and_rewire_users(n, val, rproj);
/* rewire all users, scheduled after the store, to the loaded value */
collect_and_rewire_users(n, val, rproj);
/* we can only store the tos to memory */
/* we can only store the tos to memory */
x87_create_fxch(state, n, op2_idx, STORE_VAL_IDX);
/* mode != mode_E -> use normal fst */
x87_patch_insn(n, op);
}
x87_create_fxch(state, n, op2_idx, STORE_VAL_IDX);
/* mode != mode_E -> use normal fst */
x87_patch_insn(n, op);
}
/* we can only store the tos to memory */
/* we can only store the tos to memory */
x87_create_fxch(state, n, op2_idx, STORE_VAL_IDX);
x87_pop(state);
x87_create_fxch(state, n, op2_idx, STORE_VAL_IDX);
x87_pop(state);
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param arch_env the architecture environment
* @param state the x87 state
* @param n the node that should be simulated (and patched)
* @param arch_env the architecture environment
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_Phi(x87_state *state, ir_node *n, const arch_env_t *arch_env) {
ir_mode *mode = get_irn_mode(n);
*/
static int sim_Phi(x87_state *state, ir_node *n, const arch_env_t *arch_env) {
ir_mode *mode = get_irn_mode(n);
if (mode_is_float(mode))
set_irn_mode(n, mode_E);
if (mode_is_float(mode))
set_irn_mode(n, mode_E);
} /* sim_Phi */
#define _GEN_BINOP(op, rev) \
} /* sim_Phi */
#define _GEN_BINOP(op, rev) \
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_fCondJmp(x87_state *state, ir_node *n) {
int op1_idx;
*/
static int sim_fCondJmp(x87_state *state, ir_node *n) {
int op1_idx;
DB((dbg, LEVEL_1, "<<< %s %s, [AM]\n", get_irn_opname(n),
arch_register_get_name(op1)));
DB((dbg, LEVEL_1, "<<< %s %s, [AM]\n", get_irn_opname(n),
arch_register_get_name(op1)));
+/**
+ * Create a copy of a node. Recreate the node if it's a constant.
+ *
+ * @param state the x87 state
+ * @param n the node to be copied
+ *
+ * @return the copy of n
+ */
static ir_node *create_Copy(x87_state *state, ir_node *n) {
x87_simulator *sim = state->sim;
ir_graph *irg = get_irn_irg(n);
static ir_node *create_Copy(x87_state *state, ir_node *n) {
x87_simulator *sim = state->sim;
ir_graph *irg = get_irn_irg(n);
case iro_ia32_fldln2:
cnstr = new_rd_ia32_fldln2;
break;
case iro_ia32_fldln2:
cnstr = new_rd_ia32_fldln2;
break;
}
out = x87_get_irn_register(sim, n);
op1 = x87_get_irn_register(sim, pred);
}
out = x87_get_irn_register(sim, n);
op1 = x87_get_irn_register(sim, pred);
/* copy a constant */
res = (*cnstr)(n_dbg, irg, block, mode);
/* copy a constant */
res = (*cnstr)(n_dbg, irg, block, mode);
arch_set_irn_register(sim->arch_env, res, out);
return res;
arch_set_irn_register(sim->arch_env, res, out);
return res;
/**
* Simulate a be_Copy.
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
/**
* Simulate a be_Copy.
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_Copy(x87_state *state, ir_node *n) {
x87_simulator *sim;
*/
static int sim_Copy(x87_state *state, ir_node *n) {
x87_simulator *sim;
DB((dbg, LEVEL_1, "<<< %+F %s -> %s\n", node, op1->name,
arch_get_irn_register(sim->arch_env, node)->name));
DB((dbg, LEVEL_1, "<<< %+F %s -> %s\n", node, op1->name,
arch_get_irn_register(sim->arch_env, node)->name));
}
op1_idx = x87_on_stack(state, arch_register_get_index(op1));
}
op1_idx = x87_on_stack(state, arch_register_get_index(op1));
} /* sim_Copy */
/**
* Returns the result proj of the call, or NULL if the result is not used
*/
} /* sim_Copy */
/**
* Returns the result proj of the call, or NULL if the result is not used
*/
-static ir_node *get_call_result_proj(ir_node *call)
-{
+static ir_node *get_call_result_proj(ir_node *call) {
const ir_edge_t *edge;
ir_node *resproj = NULL;
const ir_edge_t *edge;
ir_node *resproj = NULL;
ir_node *proj = get_edge_src_irn(edge);
long pn = get_Proj_proj(proj);
ir_node *proj = get_edge_src_irn(edge);
long pn = get_Proj_proj(proj);
- if(pn == pn_be_Call_first_res) {
+ if (pn == pn_be_Call_first_res) {
resproj = proj;
break;
}
}
resproj = proj;
break;
}
}
return NULL;
}
/* the result proj is connected to a Keep and maybe other nodes */
foreach_out_edge(resproj, edge) {
ir_node *pred = get_edge_src_irn(edge);
return NULL;
}
/* the result proj is connected to a Keep and maybe other nodes */
foreach_out_edge(resproj, edge) {
ir_node *pred = get_edge_src_irn(edge);
- if(!be_is_Keep(pred)) {
+ if (!be_is_Keep(pred)) {
return resproj;
}
}
/* only be_Keep found, so result is not used */
return NULL;
return resproj;
}
}
/* only be_Keep found, so result is not used */
return NULL;
+} /* get_call_result_proj */
/**
* Simulate a be_Call.
/**
* Simulate a be_Call.
* @param state the x87 state
* @param n the node that should be simulated
* @param arch_env the architecture environment
* @param state the x87 state
* @param n the node that should be simulated
* @param arch_env the architecture environment
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_Call(x87_state *state, ir_node *n, const arch_env_t *arch_env) {
ir_type *call_tp = be_Call_get_type(n);
*/
static int sim_Call(x87_state *state, ir_node *n, const arch_env_t *arch_env) {
ir_type *call_tp = be_Call_get_type(n);
assert(state->depth == 0 && "stack not empty before call");
if (get_method_n_ress(call_tp) <= 0)
assert(state->depth == 0 && "stack not empty before call");
if (get_method_n_ress(call_tp) <= 0)
/*
* If the called function returns a float, it is returned in st(0).
/*
* If the called function returns a float, it is returned in st(0).
mode = get_type_mode(res_type);
if (mode == NULL || !mode_is_float(mode))
mode = get_type_mode(res_type);
if (mode == NULL || !mode_is_float(mode))
resproj = get_call_result_proj(n);
if (resproj == NULL)
resproj = get_call_result_proj(n);
if (resproj == NULL)
reg = x87_get_irn_register(state->sim, resproj);
x87_push(state, arch_register_get_index(reg), resproj);
reg = x87_get_irn_register(state->sim, resproj);
x87_push(state, arch_register_get_index(reg), resproj);
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
*
* @param state the x87 state
* @param n the node that should be simulated (and patched)
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_Return(x87_state *state, ir_node *n) {
int n_res = be_Return_get_n_rets(n);
*/
static int sim_Return(x87_state *state, ir_node *n) {
int n_res = be_Return_get_n_rets(n);
for (i = n_float_res - 1; i >= 0; --i)
x87_pop(state);
for (i = n_float_res - 1; i >= 0; --i)
x87_pop(state);
} /* sim_Return */
typedef struct _perm_data_t {
} /* sim_Return */
typedef struct _perm_data_t {
*
* @param state the x87 state
* @param irn the node that should be simulated (and patched)
*
* @param state the x87 state
* @param irn the node that should be simulated (and patched)
+ *
+ * @return NO_NODE_ADDED
*/
static int sim_Perm(x87_state *state, ir_node *irn) {
int i, n;
*/
static int sim_Perm(x87_state *state, ir_node *irn) {
int i, n;
/* handle only floating point Perms */
if (! mode_is_float(get_irn_mode(pred)))
/* handle only floating point Perms */
if (! mode_is_float(get_irn_mode(pred)))
DB((dbg, LEVEL_1, ">>> %+F\n", irn));
DB((dbg, LEVEL_1, ">>> %+F\n", irn));
}
DB((dbg, LEVEL_1, "<<< %+F\n", irn));
}
DB((dbg, LEVEL_1, "<<< %+F\n", irn));
- return 0;
-} /* be_Perm */
+ return NO_NODE_ADDED;
+} /* sim_Perm */
/**
* Kill any dead registers at block start by popping them from the stack.
/**
* 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
* @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
*/
static x87_state *x87_kill_deads(x87_simulator *sim, ir_node *block, x87_state *start_state) {
x87_state *state = start_state;
*/
static x87_state *x87_kill_deads(x87_simulator *sim, ir_node *block, x87_state *start_state) {
x87_state *state = start_state;
*
* @param sim the simulator handle
* @param block the current block
*
* @param sim the simulator handle
* @param block the current block
- *
- * @return non-zero if simulation is complete,
- * zero if the simulation must be rerun
*/
static void x87_simulate_block(x87_simulator *sim, ir_node *block) {
ir_node *n, *next;
*/
static void x87_simulate_block(x87_simulator *sim, ir_node *block) {
ir_node *n, *next;
ir_node *start_block;
assert(state != NULL);
ir_node *start_block;
assert(state != NULL);
- // already processed?
- if(bl_state->end != NULL)
+ /* already processed? */
+ if (bl_state->end != NULL)
- //update_liveness(sim, block);
-
DB((dbg, LEVEL_1, "Simulate %+F\n", block));
DB((dbg, LEVEL_2, "State at Block begin:\n "));
DEBUG_ONLY(x87_dump_stack(state));
DB((dbg, LEVEL_1, "Simulate %+F\n", block));
DB((dbg, LEVEL_2, "State at Block begin:\n "));
DEBUG_ONLY(x87_dump_stack(state));
node_inserted = (*func)(state, n);
/*
node_inserted = (*func)(state, n);
/*
- sim_func might have added additional nodes after n,
+ sim_func might have added an additional node after n,
so update next node
beware: n must not be changed by sim_func
(i.e. removed from schedule) in this case
*/
so update next node
beware: n must not be changed by sim_func
(i.e. removed from schedule) in this case
*/
+ if (node_inserted != NO_NODE_ADDED)
ir_node *succ = get_edge_src_irn(edge);
blk_state *succ_state;
ir_node *succ = get_edge_src_irn(edge);
blk_state *succ_state;
- if(succ == start_block)
+ if (succ == start_block)
continue;
succ_state = x87_get_bl_state(sim, succ);
continue;
succ_state = x87_get_bl_state(sim, succ);
} else {
/* There is already a begin state for the successor, bad.
Do the necessary permutations.
} else {
/* There is already a begin state for the successor, bad.
Do the necessary permutations.
- Note that critical edges are removed, so this is always possible. */
+ Note that critical edges are removed, so this is always possible:
+ If the successor has more than one possible input, then it must
+ be the only one.
+ */
x87_shuffle(sim, block, state, succ, succ_state->begin);
}
}
x87_shuffle(sim, block, state, succ, succ_state->begin);
}
}
DB((dbg, LEVEL_1, "x87 Simulator stopped\n\n"));
} /* x87_destroy_simulator */
DB((dbg, LEVEL_1, "x87 Simulator stopped\n\n"));
} /* x87_destroy_simulator */
-static void update_liveness_walker(ir_node *block, void *data)
-{
+/**
+ * Pre-block walker: calculate the liveness information for the block
+ * and store it into the sim->live cache.
+ */
+static void update_liveness_walker(ir_node *block, void *data) {
x87_simulator *sim = data;
update_liveness(sim, block);
x87_simulator *sim = data;
update_liveness(sim, block);
+} /* update_liveness_walker */
/**
* Run a simulation and fix all virtual instructions for a graph.
/**
* Run a simulation and fix all virtual instructions for a graph.
do {
block = waitq_get(sim.worklist);
x87_simulate_block(&sim, block);
do {
block = waitq_get(sim.worklist);
x87_simulate_block(&sim, block);
- } while (! pdeq_empty(sim.worklist));
+ } while (! waitq_empty(sim.worklist));
/* kill it */
del_waitq(sim.worklist);
x87_destroy_simulator(&sim);
} /* x87_simulate_graph */
/* kill it */
del_waitq(sim.worklist);
x87_destroy_simulator(&sim);
} /* x87_simulate_graph */
-void ia32_init_x87(void)
-{
+void ia32_init_x87(void) {
FIRM_DBG_REGISTER(dbg, "firm.be.ia32.x87");
FIRM_DBG_REGISTER(dbg, "firm.be.ia32.x87");