2 * This file is part of libFirm.
3 * Copyright (C) 2012 Universitaet Karlsruhe
11 #include "iredges_t.h"
14 * Check dominance of two nodes in the same block.
15 * @param a The first node.
16 * @param b The second node.
17 * @return 1 if a comes before b in the same block or if a == b, 0 else.
19 static inline int _value_dominates_intrablock(const ir_node *a, const ir_node *b)
21 sched_timestep_t const as = sched_get_time_step(a);
22 sched_timestep_t const bs = sched_get_time_step(b);
27 * Check strict dominance of two nodes in the same block.
28 * @param a The first node.
29 * @param b The second node.
30 * @return 1 if a comes before b in the same block, 0 else.
32 static inline int _value_strictly_dominates_intrablock(const ir_node *a, const ir_node *b)
34 sched_timestep_t const as = sched_get_time_step(a);
35 sched_timestep_t const bs = sched_get_time_step(b);
40 * Check, if one value dominates the other.
41 * The dominance is not strict here.
42 * @param a The first node.
43 * @param b The second node.
44 * @return 1 if a dominates b or if a == b, 0 else.
46 static inline int value_dominates(const ir_node *a, const ir_node *b)
48 const ir_node *block_a = get_block_const(a);
49 const ir_node *block_b = get_block_const(b);
52 * a and b are not in the same block,
53 * so dominance is determined by the dominance of the blocks.
55 if(block_a != block_b) {
56 return block_dominates(block_a, block_b);
60 * Dominance is determined by the time steps of the schedule.
62 return _value_dominates_intrablock(a, b);
66 * Check, if two values interfere.
67 * @param lv Liveness information
68 * @param a The first value.
69 * @param b The second value.
70 * @return true, if a and b interfere, false if not.
72 static inline bool be_values_interfere(be_lv_t const *lv, ir_node const *a, ir_node const *b)
74 if (value_dominates(b, a)) {
75 /* Adjust a and b so, that a dominates b if
76 * a dominates b or vice versa. */
77 ir_node const *const t = a;
80 } else if (!value_dominates(a, b)) {
81 /* If there is no dominance relation, they do not interfere. */
85 ir_node *const bb = get_nodes_block(b);
87 /* If a is live end in b's block it is
88 * live at b's definition (a dominates b) */
89 if (be_is_live_end(lv, bb, a))
92 /* Look at all usages of a.
93 * If there's one usage of a in the block of b, then
94 * we check, if this use is dominated by b, if that's true
95 * a and b interfere. Note that b must strictly dominate the user,
96 * since if b is the last user of in the block, b and a do not
98 * Uses of a not in b's block can be disobeyed, because the
99 * check for a being live at the end of b's block is already
101 foreach_out_edge(a, edge) {
102 ir_node const *const user = get_edge_src_irn(edge);
103 if (get_nodes_block(user) == bb && !is_Phi(user) && _value_strictly_dominates_intrablock(b, user))