diff options
Diffstat (limited to 'polly/lib/External/isl/isl_tarjan.c')
-rw-r--r-- | polly/lib/External/isl/isl_tarjan.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/polly/lib/External/isl/isl_tarjan.c b/polly/lib/External/isl/isl_tarjan.c index 414a2e09cc2..a958c016e0b 100644 --- a/polly/lib/External/isl/isl_tarjan.c +++ b/polly/lib/External/isl/isl_tarjan.c @@ -14,14 +14,15 @@ #include <isl/ctx.h> #include <isl_tarjan.h> -void isl_tarjan_graph_free(struct isl_tarjan_graph *g) +struct isl_tarjan_graph *isl_tarjan_graph_free(struct isl_tarjan_graph *g) { if (!g) - return; + return NULL; free(g->node); free(g->stack); free(g->order); free(g); + return NULL; } static struct isl_tarjan_graph *isl_tarjan_graph_alloc(isl_ctx *ctx, int len) @@ -128,11 +129,31 @@ struct isl_tarjan_graph *isl_tarjan_graph_init(isl_ctx *ctx, int len, if (g->node[i].index >= 0) continue; if (isl_tarjan_components(g, i, follows, user) < 0) - goto error; + return isl_tarjan_graph_free(g); } return g; -error: - isl_tarjan_graph_free(g); - return NULL; +} + +/* Decompose the graph with "len" nodes and edges defined by "follows" + * into the strongly connected component (SCC) that contains "node" + * as well as all SCCs that are followed by this SCC. + * follows(i, j, user) should return 1 if "i" follows "j" and 0 otherwise. + * It should return -1 on error. + * + * The SCC containing "node" will appear as the last component + * in g->order. + */ +struct isl_tarjan_graph *isl_tarjan_graph_component(isl_ctx *ctx, int len, + int node, isl_bool (*follows)(int i, int j, void *user), void *user) +{ + struct isl_tarjan_graph *g; + + g = isl_tarjan_graph_alloc(ctx, len); + if (!g) + return NULL; + if (isl_tarjan_components(g, node, follows, user) < 0) + return isl_tarjan_graph_free(g); + + return g; } |