re PR fortran/54107 ([F03] Memory hog with abstract interface)
[gcc.git] / gcc / graphds.c
index 1496e09a0281206a21cf2823d2922693c2baf45d..3d64d8988cd40327d11c1fb7ca28f35301f6ffcb 100644 (file)
@@ -1,12 +1,11 @@
 /* Graph representation and manipulation functions.
-   Copyright (C) 2007
-   Free Software Foundation, Inc.
+   Copyright (C) 2007-2013 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -15,9 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #include "config.h"
 #include "system.h"
@@ -25,7 +23,6 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 #include "obstack.h"
 #include "bitmap.h"
 #include "vec.h"
-#include "vecprim.h"
 #include "graphds.h"
 
 /* Dumps graph G into F.  */
@@ -34,7 +31,7 @@ void
 dump_graph (FILE *f, struct graph *g)
 {
   int i;
-  struct edge *e;
+  struct graph_edge *e;
 
   for (i = 0; i < g->n_vertices; i++)
     {
@@ -69,10 +66,10 @@ new_graph (int n_vertices)
 
 /* Adds an edge from F to T to graph G.  The new edge is returned.  */
 
-struct edge *
+struct graph_edge *
 add_edge (struct graph *g, int f, int t)
 {
-  struct edge *e = XNEW (struct edge);
+  struct graph_edge *e = XNEW (struct graph_edge);
   struct vertex *vf = &g->vertices[f], *vt = &g->vertices[t];
 
 
@@ -95,7 +92,7 @@ identify_vertices (struct graph *g, int v, int u)
 {
   struct vertex *vv = &g->vertices[v];
   struct vertex *uu = &g->vertices[u];
-  struct edge *e, *next;
+  struct graph_edge *e, *next;
 
   for (e = uu->succ; e; e = next)
     {
@@ -122,7 +119,7 @@ identify_vertices (struct graph *g, int v, int u)
    direction given by FORWARD.  */
 
 static inline int
-dfs_edge_src (struct edge *e, bool forward)
+dfs_edge_src (struct graph_edge *e, bool forward)
 {
   return forward ? e->src : e->dest;
 }
@@ -131,7 +128,7 @@ dfs_edge_src (struct edge *e, bool forward)
    the direction given by FORWARD.  */
 
 static inline int
-dfs_edge_dest (struct edge *e, bool forward)
+dfs_edge_dest (struct graph_edge *e, bool forward)
 {
   return forward ? e->dest : e->src;
 }
@@ -139,8 +136,8 @@ dfs_edge_dest (struct edge *e, bool forward)
 /* Helper function for graphds_dfs.  Returns the first edge after E (including
    E), in the graph direction given by FORWARD, that belongs to SUBGRAPH.  */
 
-static inline struct edge *
-foll_in_subgraph (struct edge *e, bool forward, bitmap subgraph)
+static inline struct graph_edge *
+foll_in_subgraph (struct graph_edge *e, bool forward, bitmap subgraph)
 {
   int d;
 
@@ -162,10 +159,10 @@ foll_in_subgraph (struct edge *e, bool forward, bitmap subgraph)
 /* Helper function for graphds_dfs.  Select the first edge from V in G, in the
    direction given by FORWARD, that belongs to SUBGRAPH.  */
 
-static inline struct edge *
+static inline struct graph_edge *
 dfs_fst_edge (struct graph *g, int v, bool forward, bitmap subgraph)
 {
-  struct edge *e;
+  struct graph_edge *e;
 
   e = (forward ? g->vertices[v].succ : g->vertices[v].pred);
   return foll_in_subgraph (e, forward, subgraph);
@@ -174,8 +171,8 @@ dfs_fst_edge (struct graph *g, int v, bool forward, bitmap subgraph)
 /* Helper function for graphds_dfs.  Returns the next edge after E, in the
    graph direction given by FORWARD, that belongs to SUBGRAPH.  */
 
-static inline struct edge *
-dfs_next_edge (struct edge *e, bool forward, bitmap subgraph)
+static inline struct graph_edge *
+dfs_next_edge (struct graph_edge *e, bool forward, bitmap subgraph)
 {
   return foll_in_subgraph (forward ? e->succ_next : e->pred_next,
                           forward, subgraph);
@@ -188,12 +185,12 @@ dfs_next_edge (struct edge *e, bool forward, bitmap subgraph)
    of the graph (number of the restarts of DFS).  */
 
 int
-graphds_dfs (struct graph *g, int *qs, int nq, VEC (int, heap) **qt,
+graphds_dfs (struct graph *g, int *qs, int nq, vec<int> *qt,
             bool forward, bitmap subgraph)
 {
   int i, tick = 0, v, comp = 0, top;
-  struct edge *e;
-  struct edge **stack = XNEWVEC (struct edge *, g->n_vertices);
+  struct graph_edge *e;
+  struct graph_edge **stack = XNEWVEC (struct graph_edge *, g->n_vertices);
   bitmap_iterator bi;
   unsigned av;
 
@@ -237,7 +234,7 @@ graphds_dfs (struct graph *g, int *qs, int nq, VEC (int, heap) **qt,
          if (!e)
            {
              if (qt)
-               VEC_safe_push (int, heap, *qt, v);
+               qt->safe_push (v);
              g->vertices[v].post = tick++;
 
              if (!top)
@@ -267,7 +264,7 @@ graphds_dfs (struct graph *g, int *qs, int nq, VEC (int, heap) **qt,
    numbers assigned by the previous pass.  If SUBGRAPH is not NULL, it
    specifies the subgraph of G whose strongly connected components we want
    to determine.
-   
+
    After running this function, v->component is the number of the strongly
    connected component for each vertex of G.  Returns the number of the
    sccs of G.  */
@@ -276,7 +273,7 @@ int
 graphds_scc (struct graph *g, bitmap subgraph)
 {
   int *queue = XNEWVEC (int, g->n_vertices);
-  VEC (int, heap) *postorder = NULL;
+  vec<int> postorder = vNULL;
   int nq, i, comp;
   unsigned v;
   bitmap_iterator bi;
@@ -297,14 +294,14 @@ graphds_scc (struct graph *g, bitmap subgraph)
     }
 
   graphds_dfs (g, queue, nq, &postorder, false, subgraph);
-  gcc_assert (VEC_length (int, postorder) == (unsigned) nq);
+  gcc_assert (postorder.length () == (unsigned) nq);
 
   for (i = 0; i < nq; i++)
-    queue[i] = VEC_index (int, postorder, nq - i - 1);
+    queue[i] = postorder[nq - i - 1];
   comp = graphds_dfs (g, queue, nq, NULL, true, subgraph);
 
   free (queue);
-  VEC_free (int, heap, postorder);
+  postorder.release ();
 
   return comp;
 }
@@ -314,7 +311,7 @@ graphds_scc (struct graph *g, bitmap subgraph)
 void
 for_each_edge (struct graph *g, graphds_edge_callback callback)
 {
-  struct edge *e;
+  struct graph_edge *e;
   int i;
 
   for (i = 0; i < g->n_vertices; i++)
@@ -327,7 +324,7 @@ for_each_edge (struct graph *g, graphds_edge_callback callback)
 void
 free_graph (struct graph *g)
 {
-  struct edge *e, *n;
+  struct graph_edge *e, *n;
   struct vertex *v;
   int i;
 
@@ -402,15 +399,15 @@ void
 graphds_domtree (struct graph *g, int entry,
                 int *parent, int *son, int *brother)
 {
-  VEC (int, heap) *postorder = NULL;
+  vec<int> postorder = vNULL;
   int *marks = XCNEWVEC (int, g->n_vertices);
   int mark = 1, i, v, idom;
   bool changed = true;
-  struct edge *e;
+  struct graph_edge *e;
 
   /* We use a slight modification of the standard iterative algorithm, as
      described in
-     
+
      K. D. Cooper, T. J. Harvey and K. Kennedy: A Simple, Fast Dominance
        Algorithm
 
@@ -433,8 +430,8 @@ graphds_domtree (struct graph *g, int entry,
       brother[i] = -1;
     }
   graphds_dfs (g, &entry, 1, &postorder, true, NULL);
-  gcc_assert (VEC_length (int, postorder) == (unsigned) g->n_vertices);
-  gcc_assert (VEC_index (int, postorder, g->n_vertices - 1) == entry);
+  gcc_assert (postorder.length () == (unsigned) g->n_vertices);
+  gcc_assert (postorder[g->n_vertices - 1] == entry);
 
   while (changed)
     {
@@ -442,7 +439,7 @@ graphds_domtree (struct graph *g, int entry,
 
       for (i = g->n_vertices - 2; i >= 0; i--)
        {
-         v = VEC_index (int, postorder, i);
+         v = postorder[i];
          idom = -1;
          for (e = g->vertices[v].pred; e; e = e->pred_next)
            {
@@ -462,7 +459,7 @@ graphds_domtree (struct graph *g, int entry,
     }
 
   free (marks);
-  VEC_free (int, heap, postorder);
+  postorder.release ();
 
   for (i = 0; i < g->n_vertices; i++)
     if (parent[i] != -1)