Commit 158d9d39 authored by Christoph Mallon's avatar Christoph Mallon
Browse files

Code for emitting cmov for Psi nodes by chriswue

parent e6bd37b3
......@@ -967,6 +967,23 @@ static void emit_ia32_x87CondJmp(ir_node *irn, ia32_emit_env_t *env) {
finish_CondJmp(F, irn, mode_Is);
}
static void emit_ia32_CMov(ir_node *irn, ia32_emit_env_t *env) {
FILE *F = env->out;
char cmd_buf[SNPRINTF_BUF_LEN];
char cmnt_buf[SNPRINTF_BUF_LEN];
const lc_arg_env_t *arg_env = ia32_get_arg_env();
lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmp %1S, %2S", irn, irn);
lc_esnprintf(arg_env, cmnt_buf, SNPRINTF_BUF_LEN, "/* Psi condition */" );
IA32_DO_EMIT(irn);
lc_esnprintf(arg_env, cmd_buf, SNPRINTF_BUF_LEN, "cmov%s %1D, %3S",
get_cmp_suffix(get_ia32_pncode(irn), ! mode_is_signed(get_irn_mode(get_irn_n(irn, 0)))),
irn, irn);
lc_esnprintf(arg_env, cmnt_buf, SNPRINTF_BUF_LEN, "/* condition is true case */" );
IA32_DO_EMIT(irn);
}
/*********************************************************
* _ _ _
* (_) | (_)
......@@ -1549,6 +1566,7 @@ static void ia32_register_emitters(void) {
IA32_EMIT(TestJmp);
IA32_EMIT(CJmp);
IA32_EMIT(CJmpAM);
IA32_EMIT(CMov);
IA32_EMIT(SwitchJmp);
IA32_EMIT(CopyB);
IA32_EMIT(CopyB_i);
......
......@@ -273,11 +273,7 @@ $comment_string = "/*";
"CMov" => {
"irn_flags" => "R",
"comment" => "construct Mux: Mux(sel, a, b) == sel ? a : b",
"reg_req" => { "in" => [ "gp", "gp", "gp" ], "out" => [ "in_r2" ] },
"emit" =>
'. cmp %S1, 0 /* compare Sel for CMov (%A2, %A3) */
. cmovne %D1, %S3 /* sel == true -> return %S3 */
'
"reg_req" => { "in" => [ "gp", "gp", "gp", "gp" ], "out" => [ "in_r4" ] }
},
# not commutative operations
......
......@@ -1570,12 +1570,44 @@ static ir_node *gen_CopyB(ia32_transform_env_t *env) {
* @return The transformed node.
*/
static ir_node *gen_Mux(ia32_transform_env_t *env) {
#if 0
ir_node *node = env->irn;
ir_node *new_op = new_rd_ia32_CMov(env->dbg, env->irg, env->block, \
get_Mux_sel(node), get_Mux_false(node), get_Mux_true(node), env->mode);
SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, env->irn));
return new_op;
#endif
return NULL;
}
/**
* Transforms a Psi node into CMov.
*
* @param env The transformation environment
* @return The transformed node.
*/
static ir_node *gen_Psi(ia32_transform_env_t *env) {
ir_node *node = env->irn;
ir_node *cmp_proj = get_Mux_sel(node);
ir_node *cmp, *cmp_a, *cmp_b, *new_op;
assert(get_irn_mode(cmp_proj) == mode_b && "Condition for Psi must have mode_b");
cmp = get_Proj_pred(cmp_proj);
cmp_a = get_Cmp_left(cmp);
cmp_b = get_Cmp_right(cmp);
new_op = new_rd_ia32_CMov(env->dbg, env->irg, env->block, \
cmp_a, cmp_b, get_Psi_val(node, 0), get_Psi_default(node), env->mode);
set_ia32_pncode(new_op, get_Proj_proj(cmp_proj));
SET_IA32_ORIG_NODE(new_op, ia32_get_old_node_name(env->cg, env->irn));
return new_op;
}
......@@ -2241,6 +2273,7 @@ void ia32_register_transformers(void) {
GEN(CopyB);
GEN(Mux);
GEN(Psi);
IGN(Call);
IGN(Alloc);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment