use custom value_interfere function in verifiers (which is slower but doesn't rely...
[libfirm] / ir / be / bera.c
1 /**
2  * Base routines for register allocation.
3  * @author Sebastian Hack
4  * @date 22.11.2004
5  */
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include "pset.h"
11 #include "impl.h"
12
13 #include "irnode.h"
14 #include "irmode.h"
15 #include "irdom.h"
16
17 #include "beutil.h"
18 #include "besched_t.h"
19 #include "belive_t.h"
20
21 int value_dominates(const ir_node *a, const ir_node *b)
22 {
23         int res = 0;
24         const ir_node *ba = get_block(a);
25         const ir_node *bb = get_block(b);
26
27         /*
28          * a and b are not in the same block,
29          * so dominance is determined by the dominance of the blocks.
30          */
31         if(ba != bb) {
32                 res = block_dominates(ba, bb);
33
34         /*
35          * Dominance is determined by the time steps of the schedule.
36          */
37         } else {
38                 sched_timestep_t as = sched_get_time_step(a);
39                 sched_timestep_t bs = sched_get_time_step(b);
40                 res = as <= bs;
41         }
42
43         return res;
44 }
45
46 /**
47  * Check, if two values interfere.
48  * @param a The first value.
49  * @param b The second value.
50  * @return 1, if a and b interfere, 0 if not.
51  */
52 int values_interfere(const be_lv_t *lv, const ir_node *a, const ir_node *b)
53 {
54         int a2b = value_dominates(a, b);
55         int b2a = value_dominates(b, a);
56
57         /* If there is no dominance relation, they do not interfere. */
58         if((a2b | b2a) > 0) {
59                 const ir_edge_t *edge;
60                 ir_node *bb;
61
62                 /*
63                  * Adjust a and b so, that a dominates b if
64                  * a dominates b or vice versa.
65                  */
66                 if(b2a) {
67                         const ir_node *t = a;
68                         a = b;
69                         b = t;
70                 }
71
72                 bb = get_nodes_block(b);
73
74                 /*
75                  * If a is live end in b's block it is
76                  * live at b's definition (a dominates b)
77                  */
78                 if(be_is_live_end(lv, bb, a))
79                         return 1;
80
81                 /*
82                  * Look at all usages of a.
83                  * If there's one usage of a in the block of b, then
84                  * we check, if this use is dominated by b, if that's true
85                  * a and b interfere. Note that b must strictly dominate the user,
86                  * since if b is the last user of in the block, b and a do not
87                  * interfere.
88                  * Uses of a not in b's block can be disobeyed, because the
89                  * check for a being live at the end of b's block is already
90                  * performed.
91                  */
92                 foreach_out_edge(a, edge) {
93                         const ir_node *user = edge->src;
94                         if(get_nodes_block(user) == bb && !is_Phi(user) && b != user && value_dominates(b, user))
95                                 return 1;
96                 }
97   }
98   return 0;
99 }