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
+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
2013-05-02 Teresa Johnson <tejohnson@google.com>
* loop-unswitch.c (unswitch_loop): Use helper routines with rounding
{
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);
struct graph_edge *
add_edge (struct graph *g, int f, int t)
{
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];
struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
void
free_graph (struct graph *g)
{
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);
- 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);
};
struct graph *new_graph (int);