From 3c5eabdfd21b76e64ff4bb0943eb364e77d723e9 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Tue, 5 Apr 2016 11:19:48 +0200 Subject: [PATCH] isl_scheduler.c: setup_lp: extract out add_sum_constraint This reduces the size of setup_lp. Signed-off-by: Sven Verdoolaege --- isl_scheduler.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/isl_scheduler.c b/isl_scheduler.c index 371d82b6..31c74479 100644 --- a/isl_scheduler.c +++ b/isl_scheduler.c @@ -2436,6 +2436,28 @@ static int add_bound_coefficient_constraints(isl_ctx *ctx, return 0; } +/* Add a constraint to graph->lp that equates the value at position + * "sum_pos" to the sum of the "n" values starting at "first". + */ +static isl_stat add_sum_constraint(struct isl_sched_graph *graph, + int sum_pos, int first, int n) +{ + int i, k; + int total; + + total = isl_basic_set_dim(graph->lp, isl_dim_set); + + k = isl_basic_set_alloc_equality(graph->lp); + if (k < 0) + return isl_stat_error; + isl_seq_clr(graph->lp->eq[k], 1 + total); + isl_int_set_si(graph->lp->eq[k][1 + sum_pos], -1); + for (i = 0; i < n; ++i) + isl_int_set_si(graph->lp->eq[k][1 + first + i], 1); + + return isl_stat_ok; +} + /* Construct an ILP problem for finding schedule coefficients * that result in non-negative, but small dependence distances * over all dependences. @@ -2507,13 +2529,8 @@ static isl_stat setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph, graph->lp = isl_basic_set_alloc_space(space, 0, n_eq, n_ineq); - k = isl_basic_set_alloc_equality(graph->lp); - if (k < 0) + if (add_sum_constraint(graph, 0, param_pos, 2 * nparam) < 0) return isl_stat_error; - isl_seq_clr(graph->lp->eq[k], 1 + total); - isl_int_set_si(graph->lp->eq[k][1], -1); - for (i = 0; i < 2 * nparam; ++i) - isl_int_set_si(graph->lp->eq[k][1 + param_pos + i], 1); if (parametric) { k = isl_basic_set_alloc_equality(graph->lp); -- 2.11.4.GIT