summaryrefslogtreecommitdiffhomepage
path: root/ir/be/bepeephole.c
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2011-10-17 15:39:28 +0200
committerMatthias Braun <matze@braunis.de>2011-10-17 18:30:05 +0200
commitc5b097020aab073264183bdcf76753907f682452 (patch)
tree4687491abe22f6d3ad4df26d1f1f0380b301d543 /ir/be/bepeephole.c
parent6da9f4a53cecb75224fc72978a5862085c88c01d (diff)
be: factor out can_move_to function from sparc_emitter
Diffstat (limited to 'ir/be/bepeephole.c')
-rw-r--r--ir/be/bepeephole.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/ir/be/bepeephole.c b/ir/be/bepeephole.c
index 6f971df..a3fa31d 100644
--- a/ir/be/bepeephole.c
+++ b/ir/be/bepeephole.c
@@ -248,6 +248,55 @@ bool be_has_only_one_user(ir_node *node)
return n_users == 1;
}
+bool be_can_move_before(const ir_node *node, const ir_node *before)
+{
+ int node_arity = get_irn_arity(node);
+ ir_node *schedpoint = sched_next(node);
+
+ while (schedpoint != before) {
+ int i;
+ int arity = get_irn_arity(schedpoint);
+ unsigned n_outs = arch_get_irn_n_outs(schedpoint);
+
+ /* the node must not use our computed values */
+ for (i = 0; i < arity; ++i) {
+ ir_node *in = get_irn_n(schedpoint, i);
+ if (skip_Proj(in) == node)
+ return false;
+ }
+
+ /* the node must not overwrite registers of our inputs */
+ for (i = 0; i < node_arity; ++i) {
+ ir_node *in = get_irn_n(node, i);
+ const arch_register_t *reg = arch_get_irn_register(in);
+ const arch_register_req_t *in_req
+ = arch_get_irn_register_req_in(node, i);
+ unsigned o;
+ if (reg == NULL)
+ continue;
+ for (o = 0; o < n_outs; ++o) {
+ const arch_register_t *outreg
+ = arch_get_irn_register_out(schedpoint, o);
+ const arch_register_req_t *outreq
+ = arch_get_irn_register_req_out(schedpoint, o);
+ if (outreg == NULL)
+ continue;
+ if (outreg->global_index >= reg->global_index
+ && outreg->global_index
+ < (unsigned)reg->global_index + in_req->width)
+ return false;
+ if (reg->global_index >= outreg->global_index
+ && reg->global_index
+ < (unsigned)outreg->global_index + outreq->width)
+ return false;
+ }
+ }
+
+ schedpoint = sched_next(schedpoint);
+ }
+ return true;
+}
+
/*
* Tries to optimize a beIncSP node with its previous IncSP node.
* Must be run from a be_peephole_opt() context.