xref: /dflybsd-src/contrib/gcc-8.0/gcc/graphds.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Graph representation.
2*38fd1498Szrj    Copyright (C) 2007-2018 Free Software Foundation, Inc.
3*38fd1498Szrj 
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj 
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj 
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj 
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
19*38fd1498Szrj 
20*38fd1498Szrj #ifndef GCC_GRAPHDS_H
21*38fd1498Szrj #define GCC_GRAPHDS_H
22*38fd1498Szrj 
23*38fd1498Szrj /* Structure representing edge of a graph.  */
24*38fd1498Szrj 
25*38fd1498Szrj struct graph_edge
26*38fd1498Szrj {
27*38fd1498Szrj   int src, dest;	/* Source and destination.  */
28*38fd1498Szrj   struct graph_edge *pred_next, *succ_next;
29*38fd1498Szrj 			/* Next edge in predecessor and successor lists.  */
30*38fd1498Szrj   void *data;		/* Data attached to the edge.  */
31*38fd1498Szrj };
32*38fd1498Szrj 
33*38fd1498Szrj /* Structure representing vertex of a graph.  */
34*38fd1498Szrj 
35*38fd1498Szrj struct vertex
36*38fd1498Szrj {
37*38fd1498Szrj   struct graph_edge *pred, *succ;
38*38fd1498Szrj 			/* Lists of predecessors and successors.  */
39*38fd1498Szrj   int component;	/* Number of dfs restarts before reaching the
40*38fd1498Szrj 			   vertex.  */
41*38fd1498Szrj   int post;		/* Postorder number.  */
42*38fd1498Szrj   void *data;		/* Data attached to the vertex.  */
43*38fd1498Szrj };
44*38fd1498Szrj 
45*38fd1498Szrj /* Structure representing a graph.  */
46*38fd1498Szrj 
47*38fd1498Szrj struct graph
48*38fd1498Szrj {
49*38fd1498Szrj   int n_vertices;	   /* Number of vertices.  */
50*38fd1498Szrj   struct vertex *vertices; /* The vertices.  */
51*38fd1498Szrj   struct obstack ob;	   /* Obstack for vertex and edge allocation.  */
52*38fd1498Szrj };
53*38fd1498Szrj 
54*38fd1498Szrj struct graph *new_graph (int);
55*38fd1498Szrj void dump_graph (FILE *, struct graph *);
56*38fd1498Szrj struct graph_edge *add_edge (struct graph *, int, int);
57*38fd1498Szrj void identify_vertices (struct graph *, int, int);
58*38fd1498Szrj typedef bool (*skip_edge_callback) (struct graph_edge *);
59*38fd1498Szrj int graphds_dfs (struct graph *, int *, int,
60*38fd1498Szrj 		 vec<int> *, bool, bitmap, skip_edge_callback = NULL);
61*38fd1498Szrj int graphds_scc (struct graph *, bitmap, skip_edge_callback = NULL);
62*38fd1498Szrj void graphds_domtree (struct graph *, int, int *, int *, int *);
63*38fd1498Szrj typedef void (*graphds_edge_callback) (struct graph *,
64*38fd1498Szrj 				       struct graph_edge *, void *);
65*38fd1498Szrj void for_each_edge (struct graph *, graphds_edge_callback, void *);
66*38fd1498Szrj void free_graph (struct graph *g);
67*38fd1498Szrj 
68*38fd1498Szrj #endif /* GCC_GRAPHDS_H */
69