Add binary emitter for setcc.
[libfirm] / ir / be / ia32 / ia32_finish.c
index 1eeb66f..a44732c 100644 (file)
@@ -34,9 +34,9 @@
 #include "pdeq.h"
 #include "error.h"
 
-#include "../bearch_t.h"
-#include "../besched_t.h"
-#include "../benode_t.h"
+#include "../bearch.h"
+#include "../besched.h"
+#include "../benode.h"
 
 #include "bearch_ia32_t.h"
 #include "ia32_finish.h"
@@ -218,7 +218,7 @@ static inline int need_constraint_copy(ir_node *irn)
                case iro_ia32_Lea:
                case iro_ia32_Conv_I2I:
                case iro_ia32_Conv_I2I8Bit:
-               case iro_ia32_CMov:
+               case iro_ia32_CMovcc:
                        return 0;
 
                default:
@@ -242,21 +242,27 @@ static int get_first_same(const arch_register_req_t* req)
        return 32;
 }
 
+static inline bool is_unknown_reg(const arch_register_t *reg)
+{
+       if(reg == &ia32_gp_regs[REG_GP_UKNWN]
+                       || reg == &ia32_xmm_regs[REG_XMM_UKNWN]
+                       || reg == &ia32_vfp_regs[REG_VFP_UKNWN])
+               return true;
+
+       return false;
+}
+
 /**
  * Insert copies for all ia32 nodes where the should_be_same requirement
  * is not fulfilled.
  * Transform Sub into Neg -- Add if IN2 == OUT
  */
-static void assure_should_be_same_requirements(ia32_code_gen_t *cg,
-                                               ir_node *node)
+static void assure_should_be_same_requirements(ir_node *node)
 {
-       ir_graph                   *irg      = cg->irg;
-       const arch_register_req_t **reqs;
        const arch_register_t      *out_reg, *in_reg;
        int                         n_res, i;
        ir_node                    *in_node, *block;
 
-       reqs  = get_ia32_out_req_all(node);
        n_res = arch_irn_get_n_outs(node);
        block = get_nodes_block(node);
 
@@ -269,7 +275,7 @@ static void assure_should_be_same_requirements(ia32_code_gen_t *cg,
                ir_node                     *perm_proj0;
                ir_node                     *perm_proj1;
                ir_node                     *uses_out_reg;
-               const arch_register_req_t   *req = reqs[i];
+               const arch_register_req_t   *req = arch_get_out_register_req(node, i);
                const arch_register_class_t *cls;
                int                         uses_out_reg_pos;
 
@@ -279,9 +285,9 @@ static void assure_should_be_same_requirements(ia32_code_gen_t *cg,
                same_pos = get_first_same(req);
 
                /* get in and out register */
-               out_reg  = arch_irn_get_register(node, i);
-               in_node  = get_irn_n(node, same_pos);
-               in_reg   = arch_get_irn_register(in_node);
+               out_reg = arch_irn_get_register(node, i);
+               in_node = get_irn_n(node, same_pos);
+               in_reg  = arch_get_irn_register(in_node);
 
                /* requirement already fulfilled? */
                if (in_reg == out_reg)
@@ -394,7 +400,6 @@ static void assure_should_be_same_requirements(ia32_code_gen_t *cg,
  */
 static void fix_am_source(ir_node *irn)
 {
-       const arch_register_req_t **reqs;
        int                         n_res, i;
 
        /* check only ia32 nodes with source address mode */
@@ -404,22 +409,22 @@ static void fix_am_source(ir_node *irn)
        if (get_ia32_am_support(irn) != ia32_am_binary)
                return;
 
-       reqs  = get_ia32_out_req_all(irn);
        n_res = arch_irn_get_n_outs(irn);
 
        for (i = 0; i < n_res; i++) {
-               const arch_register_t *out_reg;
-               int                    same_pos;
-               ir_node               *same_node;
-               const arch_register_t *same_reg;
-               ir_node               *load_res;
+               const arch_register_req_t *req = arch_get_out_register_req(irn, i);
+               const arch_register_t     *out_reg;
+               int                        same_pos;
+               ir_node                   *same_node;
+               const arch_register_t     *same_reg;
+               ir_node                   *load_res;
 
-               if (!arch_register_req_is(reqs[i], should_be_same))
+               if (!arch_register_req_is(req, should_be_same))
                        continue;
 
                /* get in and out register */
                out_reg   = arch_irn_get_register(irn, i);
-               same_pos  = get_first_same(reqs[i]);
+               same_pos  = get_first_same(req);
                same_node = get_irn_n(irn, same_pos);
                same_reg  = arch_get_irn_register(same_node);
 
@@ -458,8 +463,6 @@ static void ia32_finish_irg_walker(ir_node *block, void *env)
        }
 
        for (irn = sched_first(block); ! sched_is_end(irn); irn = next) {
-               ia32_code_gen_t *cg = env;
-
                next = sched_next(irn);
 
                /* check if there is a sub which need to be transformed */
@@ -475,7 +478,7 @@ static void ia32_finish_irg_walker(ir_node *block, void *env)
                        /* some nodes are just a bit less efficient, but need no fixing if the
                         * should be same requirement is not fulfilled */
                        if (need_constraint_copy(irn))
-                               assure_should_be_same_requirements(cg, irn);
+                               assure_should_be_same_requirements(irn);
                }
        }
 }