graphds.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Graph representation.
  2. Copyright (C) 2007-2019 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. typedef bool (*skip_edge_callback) (struct graph_edge *);
  47. int graphds_dfs (struct graph *, int *, int,
  48. vec<int> *, bool, bitmap, skip_edge_callback = NULL);
  49. int graphds_scc (struct graph *, bitmap, skip_edge_callback = NULL);
  50. void graphds_domtree (struct graph *, int, int *, int *, int *);
  51. typedef void (*graphds_edge_callback) (struct graph *,
  52. struct graph_edge *, void *);
  53. void for_each_edge (struct graph *, graphds_edge_callback, void *);
  54. void free_graph (struct graph *g);
  55. #endif /* GCC_GRAPHDS_H */