bescripts: Remove unused execution unit specification.
[libfirm] / ir / be / beintlive_t.h
1 /**
2  * @file   beintlive_t.h
3  * @date   10.05.2007
4  * @author Sebastian Hack
5  *
6  * Principal routines for liveness and interference checks.
7  *
8  * Copyright (C) 2007 Universitaet Karlsruhe
9  * Released under the GPL
10  */
11
12 #ifndef _BELIVECHK_T_H
13 #define _BELIVECHK_T_H
14
15 #include "besched.h"
16 #include "belive_t.h"
17 #include "beutil.h"
18 #include "iredges_t.h"
19
20 /**
21  * Check dominance of two nodes in the same block.
22  * @param a The first node.
23  * @param b The second node.
24  * @return 1 if a comes before b in the same block or if a == b, 0 else.
25  */
26 static inline int _value_dominates_intrablock(const ir_node *a, const ir_node *b)
27 {
28         sched_timestep_t const as = sched_get_time_step(a);
29         sched_timestep_t const bs = sched_get_time_step(b);
30         return as <= bs;
31 }
32
33 /**
34  * Check strict dominance of two nodes in the same block.
35  * @param a The first node.
36  * @param b The second node.
37  * @return 1 if a comes before b in the same block, 0 else.
38  */
39 static inline int _value_strictly_dominates_intrablock(const ir_node *a, const ir_node *b)
40 {
41         sched_timestep_t const as = sched_get_time_step(a);
42         sched_timestep_t const bs = sched_get_time_step(b);
43         return as < bs;
44 }
45
46 /**
47  * Check, if one value dominates the other.
48  * The dominance is not strict here.
49  * @param a The first node.
50  * @param b The second node.
51  * @return 1 if a dominates b or if a == b, 0 else.
52  */
53 static inline int value_dominates(const ir_node *a, const ir_node *b)
54 {
55         const ir_node *block_a = get_block_const(a);
56         const ir_node *block_b = get_block_const(b);
57
58         /*
59          * a and b are not in the same block,
60          * so dominance is determined by the dominance of the blocks.
61          */
62         if(block_a != block_b) {
63                 return block_dominates(block_a, block_b);
64         }
65
66         /*
67          * Dominance is determined by the time steps of the schedule.
68          */
69         return _value_dominates_intrablock(a, b);
70 }
71
72 /**
73  * Check, if two values interfere.
74  * @param lv Liveness information
75  * @param a The first value.
76  * @param b The second value.
77  * @return true, if a and b interfere, false if not.
78  */
79 static inline bool be_values_interfere(be_lv_t const *lv, ir_node const *a, ir_node const *b)
80 {
81         if (value_dominates(b, a)) {
82                 /* Adjust a and b so, that a dominates b if
83                  * a dominates b or vice versa. */
84                 ir_node const *const t = a;
85                 a = b;
86                 b = t;
87         } else if (!value_dominates(a, b)) {
88                 /* If there is no dominance relation, they do not interfere. */
89                 return false;
90         }
91
92         ir_node *const bb = get_nodes_block(b);
93
94         /* If a is live end in b's block it is
95          * live at b's definition (a dominates b) */
96         if (be_is_live_end(lv, bb, a))
97                 return true;
98
99         /* Look at all usages of a.
100          * If there's one usage of a in the block of b, then
101          * we check, if this use is dominated by b, if that's true
102          * a and b interfere. Note that b must strictly dominate the user,
103          * since if b is the last user of in the block, b and a do not
104          * interfere.
105          * Uses of a not in b's block can be disobeyed, because the
106          * check for a being live at the end of b's block is already
107          * performed. */
108         foreach_out_edge(a, edge) {
109                 ir_node const *const user = get_edge_src_irn(edge);
110                 if (get_nodes_block(user) == bb && !is_Phi(user) && _value_strictly_dominates_intrablock(b, user))
111                         return true;
112         }
113
114         return false;
115 }
116
117 #endif