graphds.h (struct graph): Add obstack member.

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.

From-SVN: r198539
This commit is contained in:
Richard Biener 2013-05-02 13:59:38 +00:00 committed by Richard Biener
parent 8b47039cde
commit 2c41c19d5d
3 changed files with 17 additions and 20 deletions

View File

@ -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> 2013-05-02 Teresa Johnson <tejohnson@google.com>
* loop-unswitch.c (unswitch_loop): Use helper routines with rounding * loop-unswitch.c (unswitch_loop): Use helper routines with rounding

View File

@ -58,8 +58,10 @@ new_graph (int n_vertices)
{ {
struct graph *g = XNEW (struct graph); struct graph *g = XNEW (struct graph);
gcc_obstack_init (&g->ob);
g->n_vertices = n_vertices; 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; return g;
} }
@ -69,10 +71,9 @@ new_graph (int n_vertices)
struct graph_edge * struct graph_edge *
add_edge (struct graph *g, int f, int t) 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]; struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
e->src = f; e->src = f;
e->dest = t; e->dest = t;
@ -324,20 +325,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback)
void void
free_graph (struct graph *g) free_graph (struct graph *g)
{ {
struct graph_edge *e, *n; obstack_free (&g->ob, NULL);
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);
free (g); free (g);
} }

View File

@ -43,9 +43,9 @@ struct vertex
struct graph struct graph
{ {
int n_vertices; /* Number of vertices. */ int n_vertices; /* Number of vertices. */
struct vertex *vertices; struct vertex *vertices; /* The vertices. */
/* The vertices. */ struct obstack ob; /* Obstack for vertex and edge allocation. */
}; };
struct graph *new_graph (int); struct graph *new_graph (int);