4 * @author Sebastian Hack
6 * Principal routines for liveness and interference checks.
8 * Copyright (C) 2007 Universitaet Karlsruhe
9 * Released under the GPL
12 #ifndef _BELIVECHK_T_H
13 #define _BELIVECHK_T_H
18 #include "iredges_t.h"
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.
26 static inline int _value_dominates_intrablock(const ir_node *a, const ir_node *b)
28 sched_timestep_t const as = sched_get_time_step(a);
29 sched_timestep_t const bs = sched_get_time_step(b);
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.
39 static inline int _value_strictly_dominates_intrablock(const ir_node *a, const ir_node *b)
41 sched_timestep_t const as = sched_get_time_step(a);
42 sched_timestep_t const bs = sched_get_time_step(b);
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.
53 static inline int value_dominates(const ir_node *a, const ir_node *b)
55 const ir_node *block_a = get_block_const(a);
56 const ir_node *block_b = get_block_const(b);
59 * a and b are not in the same block,
60 * so dominance is determined by the dominance of the blocks.
62 if(block_a != block_b) {
63 return block_dominates(block_a, block_b);
67 * Dominance is determined by the time steps of the schedule.
69 return _value_dominates_intrablock(a, b);
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.
79 static inline bool be_values_interfere(be_lv_t const *lv, ir_node const *a, ir_node const *b)
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;
87 } else if (!value_dominates(a, b)) {
88 /* If there is no dominance relation, they do not interfere. */
92 ir_node *const bb = get_nodes_block(b);
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))
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
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
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))