graphds.h 2.1 KB

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