summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorElias Aebi <elias.aebi@student.kit.edu>2018-05-15 10:55:25 +0200
committerJohannes Bucher <johannes.bucher2@student.kit.edu>2019-01-24 17:42:00 +0100
commit208b4a611a5a733b7ffc28e7296b4a362b82c854 (patch)
tree713302bda17a76a77727a9f13d8ac56c69786cf2
parent6a552d5df5a103b46b27113af1bb7863b311837f (diff)
implement a simple heuristic to determine the unroll factor
-rw-r--r--ir/opt/loop2.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/ir/opt/loop2.c b/ir/opt/loop2.c
index b3fad94..ee48197 100644
--- a/ir/opt/loop2.c
+++ b/ir/opt/loop2.c
@@ -99,8 +99,8 @@ static void rewire_successor_block(ir_node *const block, int n)
add_edge(block, new_node);
// rewire phis inside the block
- unsigned int const n_outs = get_irn_n_outs(block);
- for (unsigned int i = 0; i < n_outs; ++i) {
+ unsigned const n_outs = get_irn_n_outs(block);
+ for (unsigned i = 0; i < n_outs; ++i) {
ir_node *const phi = get_irn_out(block, i);
if (is_Phi(phi)) {
ir_node *const pred = get_irn_n(phi, n);
@@ -120,8 +120,8 @@ static void rewire_node(ir_node *const node, ir_node *const header)
assert(get_irn_arity(node) == get_irn_arity(new_node));
// rewire the successors outside the loop
- unsigned int const n_outs = get_irn_n_outs(node);
- for (unsigned int i = 0; i < n_outs; ++i) {
+ unsigned const n_outs = get_irn_n_outs(node);
+ for (unsigned i = 0; i < n_outs; ++i) {
int n;
ir_node *const succ = get_irn_out_ex(node, i, &n);
if (get_irn_link(succ) == NULL && is_Block(succ)) {
@@ -200,8 +200,8 @@ static void duplicate_block(ir_node *const block)
{
ir_node *const new_block = duplicate_node(block, NULL);
- unsigned int const n_outs = get_irn_n_outs(block);
- for (unsigned int i = 0; i < n_outs; ++i) {
+ unsigned const n_outs = get_irn_n_outs(block);
+ for (unsigned 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)
@@ -213,8 +213,8 @@ static void duplicate_block(ir_node *const block)
static void rewire_block(ir_node *const block, ir_node *const header)
{
rewire_node(block, header);
- unsigned int const n_outs = get_irn_n_outs(block);
- for (unsigned int i = 0; i < n_outs; ++i) {
+ unsigned const n_outs = get_irn_n_outs(block);
+ for (unsigned 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)
@@ -256,10 +256,24 @@ static void unroll_loop(ir_loop *const loop, unsigned factor)
}
}
+static size_t count_nodes(ir_loop *const loop)
+{
+ size_t n_nodes = 0;
+ size_t const n_elements = get_loop_n_elements(loop);
+ for (size_t i = 0; i < n_elements; ++i) {
+ loop_element const element = get_loop_element(loop, i);
+ if (*element.kind == k_ir_node) {
+ n_nodes += get_irn_n_outs(element.node);
+ } else if (*element.kind == k_ir_loop) {
+ n_nodes += count_nodes(element.son);
+ }
+ }
+ return n_nodes;
+}
+
static unsigned determine_unroll_factor(ir_loop *const loop)
{
- (void)loop;
- return 2;
+ return count_nodes(loop) < 32 ? 1 : 0;
}
static void duplicate_innermost_loops(ir_loop *const loop, bool const outermost)