-/**
- * Checks if the irn uses or defines values of the
- * current register class (raenv->cls)
- */
-static INLINE int is_sth_in_reg_class(be_raext_env_t *raenv, const ir_node *irn) {
- int max, i;
-
- /* check arguments */
- for (i=0, max=get_irn_arity(irn); i<max; ++i)
- if (arch_irn_has_reg_class(raenv->aenv, get_irn_n(irn, i), -1, raenv->cls))
- return 1;
-
- /* check result(s) */
- if (get_irn_mode(irn) == mode_T) {
- ir_node *proj;
- for (proj = sched_next(irn); is_Proj(proj); proj = sched_next(proj))
- if (arch_irn_has_reg_class(raenv->aenv, proj, -1, raenv->cls))
- return 1;
- return 0;
- } else {
- return arch_irn_has_reg_class(raenv->aenv, irn, -1, raenv->cls);
+ pset_foreach(s, irn)
+ if (!is_Phi(irn)) {
+ pset_break(s);
+ return irn;
+ }
+
+ assert(0 && "There must be a non-phi-irn in this");
+ return NULL;
+}
+
+static INLINE ir_node *get_first_phi(pset *s) {
+ ir_node *irn;
+
+ pset_foreach(s, irn)
+ if (is_Phi(irn)) {
+ pset_break(s);
+ return irn;
+ }
+
+ assert(0 && "There must be a phi in this");
+ return NULL;
+}
+
+static int get_loop_weight(ir_node *irn) {
+ int cost = 0;
+ ir_loop *loop = get_irn_loop(get_nodes_block(irn));
+
+ if (loop) {
+ int d = get_loop_depth(loop);
+ cost = d*d;
+ }
+ return cost+1;
+}
+
+#define get_const_weight(irn) (1)
+
+#define get_spill_weight(irn) get_loop_weight(irn)
+#define get_reload_weight(irn) get_loop_weight(irn)
+#define get_affinity_weight(irn) get_loop_weight(irn)
+
+/******************************************************************************
+ _____ _ _____ _
+ / ____| | | / ____| (_)
+ | | ___ _ __ ___| |_ _ __ | | ___ _ __ _ ___ ___
+ | | / _ \| '_ \/ __| __| '__| | | / _ \| '_ \| |/ _ \/ __|
+ | |___| (_) | | | \__ \ |_| | | |___| (_) | |_) | | __/\__ \
+ \_____\___/|_| |_|___/\__|_| \_____\___/| .__/|_|\___||___/
+ | |
+ |_|
+ *****************************************************************************/
+
+static void handle_constraints_walker(ir_node *irn, void *env) {
+ be_raext_env_t *raenv = env;
+ arch_register_req_t req;
+ int pos, max;
+
+ /* handle output constraints
+ * user -> irn becomes user -> cpy -> irn
+ */
+ arch_get_register_req(raenv->aenv, &req, irn, -1);
+ if (arch_register_req_is(&req, limited)) {
+ ir_node *cpy = be_new_Copy(req.cls, raenv->irg, get_nodes_block(irn), irn);
+ const ir_edge_t *edge;
+
+ /* all users of the irn use the copy instead */
+ sched_add_after(irn, cpy);
+ foreach_out_edge(irn, edge)
+ set_irn_n(edge->src, edge->pos, cpy);
+ }
+
+
+ /* handle input constraints by converting them into output constraints
+ * of copies of the former argument
+ * irn -> arg becomes irn -> copy -> arg
+ */
+ for (pos = 0, max = get_irn_arity(irn); pos<max; ++pos) {
+ arch_get_register_req(raenv->aenv, &req, irn, pos);
+ if (arch_register_req_is(&req, limited)) {
+ ir_node *arg = get_irn_n(irn, pos);
+ ir_node *cpy = be_new_Copy(req.cls, raenv->irg, get_nodes_block(irn), arg);
+
+ /* use the copy instead */
+ sched_add_before(irn, cpy);
+ set_irn_n(irn, pos, cpy);
+
+ /* set an out constraint for the copy */
+ be_set_constr_limited(cpy, -1, &req);
+ }