summaryrefslogtreecommitdiffhomepage
path: root/ir/opt
diff options
context:
space:
mode:
authorElias Aebi <elias.aebi@student.kit.edu>2018-04-02 12:57:09 +0200
committerJohannes Bucher <johannes.bucher2@student.kit.edu>2019-01-24 17:42:00 +0100
commit4c37cb7a962f0fb0e65544593ac91f5343970ab2 (patch)
treeaa37e4c0a39df9cad150da032b71844678da4db5 /ir/opt
parentfbdd1bb4b89b9e89bcc49fb7c17ed699f19993d7 (diff)
pass the loop header to the rewire functions
Diffstat (limited to 'ir/opt')
-rw-r--r--ir/opt/loop2.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/ir/opt/loop2.c b/ir/opt/loop2.c
index b0ee0d8..27b7d8d 100644
--- a/ir/opt/loop2.c
+++ b/ir/opt/loop2.c
@@ -89,7 +89,7 @@ static void duplicate_node(ir_node *const node, ir_node *const new_block)
//printf("new node %ld\n", get_irn_node_nr(new_node));
}
-static void rewire_node(ir_node *const node)
+static void rewire_node(ir_node *const node, ir_node *const header)
{
ir_node *const new_node = get_irn_link(node);
assert(new_node);
@@ -125,7 +125,7 @@ static void rewire_node(ir_node *const node)
}
// loop header block
- if (has_backedges(node)) {
+ if (node == header) {
assert(is_Block(node));
assert(get_irn_arity(node) == 2);
assert(is_backedge(node, 1));
@@ -142,8 +142,7 @@ static void rewire_node(ir_node *const node)
}
// phi node inside loop header
- if (is_Phi(node) && has_backedges(get_nodes_block(node))) {
- //printf("candidate: %ld\n", get_irn_node_nr(node));
+ if (is_Phi(node) && get_nodes_block(node) == header) {
assert(get_irn_arity(get_nodes_block(node)) == 2);
assert(is_backedge(get_nodes_block(node), 1));
ir_node *const pred = get_irn_n(node, 1);
@@ -183,22 +182,24 @@ static void duplicate_block(ir_node *const block)
}
}
-static void rewire_block(ir_node *const block)
+static void rewire_block(ir_node *const block, ir_node *const header)
{
- rewire_node(block);
+ rewire_node(block, header);
unsigned int const n_outs = get_irn_n_outs(block);
for (unsigned int i = 0; i < n_outs; ++i) {
ir_node *const node = get_irn_out(block, i);
assert(!is_Block(node));
if (get_nodes_block(node) != block)
continue;
- rewire_node(node);
+ rewire_node(node, header);
}
}
static void duplicate_loop(ir_loop *const loop)
{
- //printf("duplicating loop\n");
+ ir_node *const header = get_loop_header(loop);
+ if (header == NULL)
+ return;
size_t const n_elements = get_loop_n_elements(loop);
// step 1: duplicate blocks
for (size_t i = 0; i < n_elements; ++i) {
@@ -213,7 +214,7 @@ static void duplicate_loop(ir_loop *const loop)
loop_element const element = get_loop_element(loop, i);
if (*element.kind == k_ir_node) {
assert(is_Block(element.node));
- rewire_block(element.node);
+ rewire_block(element.node, header);
}
}
}