isl_schedule.c: extract out merge_edge
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 1 Jan 2013 16:39:55 +0000 (1 17:39 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Wed, 18 Sep 2013 11:09:59 +0000 (18 13:09 +0200)
Merging edges will become more complicated when we add support
for conditional validity constraints.  It is therefore best
to extract this functionality into a separate function.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
isl_schedule.c

index 2d23969..f640c35 100644 (file)
@@ -698,6 +698,23 @@ struct isl_extract_edge_data {
        struct isl_sched_graph *graph;
 };
 
+/* Merge edge2 into edge1, freeing the contents of edge2.
+ * "type" is the type of the schedule constraint from which edge2 was
+ * extracted.
+ * Return 0 on success and -1 on failure.
+ *
+ * edge1 and edge2 are assumed to have the same value for the map field.
+ */
+static int merge_edge(enum isl_edge_type type, struct isl_sched_edge *edge1,
+       struct isl_sched_edge *edge2)
+{
+       edge1->validity |= edge2->validity;
+       edge1->proximity |= edge2->proximity;
+       isl_map_free(edge2->map);
+
+       return 0;
+}
+
 /* Add a new edge to the graph based on the given map
  * and add it to data->graph->edge_table[data->type].
  * If a dependence relation of a given type happens to be identical
@@ -752,9 +769,8 @@ static int extract_edge(__isl_take isl_map *map, void *user)
                                    &graph->edge[graph->n_edge - 1]);
 
        graph->n_edge--;
-       edge->validity |= graph->edge[graph->n_edge].validity;
-       edge->proximity |= graph->edge[graph->n_edge].proximity;
-       isl_map_free(map);
+       if (merge_edge(data->type, edge, &graph->edge[graph->n_edge]) < 0)
+               return -1;
 
        return graph_edge_table_add(ctx, graph, data->type, edge);
 }