aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/graphds.c22
-rw-r--r--gcc/graphds.h6
3 files changed, 17 insertions, 20 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 023c6b9..cf3c3e3 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2013-05-02 Richard Biener <rguenther@suse.de>
+
+ * graphds.h (struct graph): Add obstack member.
+ * graphds.c (new_graph): Initialize obstack and allocate
+ vertices from it.
+ (add_edge): Allocate edge from the obstack.
+ (free_graph): Free the obstack instead of all edges and
+ vertices.
+
2013-05-02 Teresa Johnson <tejohnson@google.com>
* loop-unswitch.c (unswitch_loop): Use helper routines with rounding
diff --git a/gcc/graphds.c b/gcc/graphds.c
index 3d64d89..d009c13 100644
--- a/gcc/graphds.c
+++ b/gcc/graphds.c
@@ -58,8 +58,10 @@ new_graph (int n_vertices)
{
struct graph *g = XNEW (struct graph);
+ gcc_obstack_init (&g->ob);
g->n_vertices = n_vertices;
- g->vertices = XCNEWVEC (struct vertex, n_vertices);
+ g->vertices = XOBNEWVEC (&g->ob, struct vertex, n_vertices);
+ memset (g->vertices, 0, sizeof (struct vertex) * n_vertices);
return g;
}
@@ -69,10 +71,9 @@ new_graph (int n_vertices)
struct graph_edge *
add_edge (struct graph *g, int f, int t)
{
- struct graph_edge *e = XNEW (struct graph_edge);
+ struct graph_edge *e = XOBNEW (&g->ob, struct graph_edge);
struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
-
e->src = f;
e->dest = t;
@@ -324,20 +325,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback)
void
free_graph (struct graph *g)
{
- struct graph_edge *e, *n;
- struct vertex *v;
- int i;
-
- for (i = 0; i < g->n_vertices; i++)
- {
- v = &g->vertices[i];
- for (e = v->succ; e; e = n)
- {
- n = e->succ_next;
- free (e);
- }
- }
- free (g->vertices);
+ obstack_free (&g->ob, NULL);
free (g);
}
diff --git a/gcc/graphds.h b/gcc/graphds.h
index f6d9c36..d9de5ae 100644
--- a/gcc/graphds.h
+++ b/gcc/graphds.h
@@ -43,9 +43,9 @@ struct vertex
struct graph
{
- int n_vertices; /* Number of vertices. */
- struct vertex *vertices;
- /* The vertices. */
+ int n_vertices; /* Number of vertices. */
+ struct vertex *vertices; /* The vertices. */
+ struct obstack ob; /* Obstack for vertex and edge allocation. */
};
struct graph *new_graph (int);