adapted (some parts) to abi changes
[libfirm] / ir / be / belower.c
index 45ea686..ac713af 100644 (file)
@@ -464,48 +464,61 @@ static void lower_perm_node(ir_node *irn, void *walk_env) {
 
 
 /**
- * Calls the backend code generator functions to lower Spill and
- * Reload nodes into Store and Load. The backend is fully responsible
- * for creating the new nodes and setting their input correct.
- * Note: The caller of this has to make sure that irn is a Spill
- *       or Reload!
+ * Checks if node has a should_be_different constraint in output
+ * and adds a Keep then to assure the constraint.
+ */
+static void assure_different_constraint(ir_node *irn, be_irg_t *birg) {
+       const arch_env_t          *arch_env = birg->main_env->arch_env;
+       const arch_register_req_t *req;
+       arch_register_req_t        req_temp;
+       ir_node                   *in[2], *keep;
+       firm_dbg_module_t         *mod = firm_dbg_register("firm.be.lower");
+
+       req = arch_get_register_req(arch_env, &req_temp, irn, -1);
+
+       if (req && arch_register_req_is(req, should_be_different)) {
+               /* We found a should_be_different constraint. */
+               assert(req->other_different && "missing irn for constraint");
+
+               in[0] = irn;
+               in[1] = req->other_different;
+
+               keep = be_new_Keep(req->cls, birg->irg, get_nodes_block(irn), 2, in);
+               DBG((mod, LEVEL_1, "created %+F for %+F to assure should_be_different\n", keep, irn));
+       }
+}
+
+
+
+/**
+ * Calls the functions to assure register constraints.
  *
- * @param irn      The Spill/Reload node
+ * @param irn      The node to be checked for lowering
  * @param walk_env The walker environment
  */
-static void lower_spill_reload(ir_node *irn, void *walk_env) {
-       lower_env_t           *env  = walk_env;
-       arch_code_generator_t *cg   = env->chord_env->birg->cg;
-       const arch_env_t      *aenv = env->chord_env->birg->main_env->arch_env;
-       ir_node               *res  = NULL;
-       ir_node               *sched_point;
-
-       if (be_is_Spill(irn) && cg->impl->lower_spill) {
-               res = cg->impl->lower_spill(cg, irn);
-       }
-       else if (be_is_Reload(irn) && cg->impl->lower_reload) {
-               res = cg->impl->lower_reload(cg, irn);
-               if (res && res != irn) {
-                       /* copy the result register from the reload to the load */
-                       arch_set_irn_register(aenv, res, arch_get_irn_register(aenv, irn));
-               }
-       }
+static void assure_constraints_walker(ir_node *irn, void *walk_env) {
+       if (is_Block(irn))
+               return;
 
-       if (res && res != irn) {
-               sched_point = sched_prev(irn);
-               sched_remove(irn);
-               exchange(irn, res);
-               sched_add_after(sched_point, res);
-       }
-       else {
-               DBG((env->dbg_module, LEVEL_1, "node %+F not lowered\n", irn));
-       }
+       if (mode_is_datab(get_irn_mode(irn)))
+               assure_different_constraint(irn, walk_env);
 
        return;
 }
 
 
 
+/**
+ * Walks over all nodes to assure register constraints.
+ *
+ * @param birg  The birg structure containing the irg
+ */
+void assure_constraints(be_irg_t *birg) {
+       irg_walk_blkwise_graph(birg->irg, NULL, assure_constraints_walker, birg);
+}
+
+
+
 /**
  * Calls the corresponding lowering function for the node.
  *
@@ -520,9 +533,6 @@ static void lower_nodes_after_ra_walker(ir_node *irn, void *walk_env) {
                if (is_Perm(arch_env, irn)) {
                        lower_perm_node(irn, walk_env);
                }
-               else if (be_is_Spill(irn) || be_is_Reload(irn)) {
-                       lower_spill_reload(irn, walk_env);
-               }
        }
 
        return;
@@ -532,7 +542,7 @@ static void lower_nodes_after_ra_walker(ir_node *irn, void *walk_env) {
 
 /**
  * Walks over all blocks in an irg and performs lowering need to be
- * done after register allocation (e.g. perm and spill/reload lowering).
+ * done after register allocation (e.g. perm lowering).
  *
  * @param chord_env The chordal environment containing the irg
  * @param do_copy   1 == resolve cycles with a free reg if available