ddg.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* DDG - Data Dependence Graph - interface.
  2. Copyright (C) 2004-2015 Free Software Foundation, Inc.
  3. Contributed by Ayal Zaks and Mustafa Hagog <zaks,mustafa@il.ibm.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_DDG_H
  17. #define GCC_DDG_H
  18. /* For sbitmap. */
  19. typedef struct ddg_node *ddg_node_ptr;
  20. typedef struct ddg_edge *ddg_edge_ptr;
  21. typedef struct ddg *ddg_ptr;
  22. typedef struct ddg_scc *ddg_scc_ptr;
  23. typedef struct ddg_all_sccs *ddg_all_sccs_ptr;
  24. enum dep_type {TRUE_DEP, OUTPUT_DEP, ANTI_DEP};
  25. enum dep_data_type {REG_OR_MEM_DEP, REG_DEP, MEM_DEP, REG_AND_MEM_DEP};
  26. /* The following two macros enables direct access to the successors and
  27. predecessors bitmaps held in each ddg_node. Do not make changes to
  28. these bitmaps, unless you want to change the DDG. */
  29. #define NODE_SUCCESSORS(x) ((x)->successors)
  30. #define NODE_PREDECESSORS(x) ((x)->predecessors)
  31. /* A structure that represents a node in the DDG. */
  32. struct ddg_node
  33. {
  34. /* Each node has a unique CUID index. These indices increase monotonically
  35. (according to the order of the corresponding INSN in the BB), starting
  36. from 0 with no gaps. */
  37. int cuid;
  38. /* The insn represented by the node. */
  39. rtx_insn *insn;
  40. /* A note preceding INSN (or INSN itself), such that all insns linked
  41. from FIRST_NOTE until INSN (inclusive of both) are moved together
  42. when reordering the insns. This takes care of notes that should
  43. continue to precede INSN. */
  44. rtx_insn *first_note;
  45. /* Incoming and outgoing dependency edges. */
  46. ddg_edge_ptr in;
  47. ddg_edge_ptr out;
  48. /* Each bit corresponds to a ddg_node according to its cuid, and is
  49. set iff the node is a successor/predecessor of "this" node. */
  50. sbitmap successors;
  51. sbitmap predecessors;
  52. /* For general use by algorithms manipulating the ddg. */
  53. union {
  54. int count;
  55. void *info;
  56. } aux;
  57. };
  58. /* A structure that represents an edge in the DDG. */
  59. struct ddg_edge
  60. {
  61. /* The source and destination nodes of the dependency edge. */
  62. ddg_node_ptr src;
  63. ddg_node_ptr dest;
  64. /* TRUE, OUTPUT or ANTI dependency. */
  65. dep_type type;
  66. /* REG or MEM dependency. */
  67. dep_data_type data_type;
  68. /* Latency of the dependency. */
  69. int latency;
  70. /* The distance: number of loop iterations the dependency crosses. */
  71. int distance;
  72. /* The following two fields are used to form a linked list of the in/out
  73. going edges to/from each node. */
  74. ddg_edge_ptr next_in;
  75. ddg_edge_ptr next_out;
  76. /* For general use by algorithms manipulating the ddg. */
  77. union {
  78. int count;
  79. void *info;
  80. } aux;
  81. };
  82. /* This structure holds the Data Dependence Graph for a basic block. */
  83. struct ddg
  84. {
  85. /* The basic block for which this DDG is built. */
  86. basic_block bb;
  87. /* Number of instructions in the basic block. */
  88. int num_nodes;
  89. /* Number of load/store instructions in the BB - statistics. */
  90. int num_loads;
  91. int num_stores;
  92. /* Number of debug instructions in the BB. */
  93. int num_debug;
  94. /* This array holds the nodes in the graph; it is indexed by the node
  95. cuid, which follows the order of the instructions in the BB. */
  96. ddg_node_ptr nodes;
  97. /* The branch closing the loop. */
  98. ddg_node_ptr closing_branch;
  99. /* Build dependence edges for closing_branch, when set. In certain cases,
  100. the closing branch can be dealt with separately from the insns of the
  101. loop, and then no such deps are needed. */
  102. int closing_branch_deps;
  103. /* Array and number of backarcs (edges with distance > 0) in the DDG. */
  104. int num_backarcs;
  105. ddg_edge_ptr *backarcs;
  106. };
  107. /* Holds information on an SCC (Strongly Connected Component) of the DDG. */
  108. struct ddg_scc
  109. {
  110. /* A bitmap that represents the nodes of the DDG that are in the SCC. */
  111. sbitmap nodes;
  112. /* Array and number of backarcs (edges with distance > 0) in the SCC. */
  113. ddg_edge_ptr *backarcs;
  114. int num_backarcs;
  115. /* The maximum of (total_latency/total_distance) over all cycles in SCC. */
  116. int recurrence_length;
  117. };
  118. /* This structure holds the SCCs of the DDG. */
  119. struct ddg_all_sccs
  120. {
  121. /* Array that holds the SCCs in the DDG, and their number. */
  122. ddg_scc_ptr *sccs;
  123. int num_sccs;
  124. ddg_ptr ddg;
  125. };
  126. ddg_ptr create_ddg (basic_block, int closing_branch_deps);
  127. void free_ddg (ddg_ptr);
  128. void print_ddg (FILE *, ddg_ptr);
  129. void vcg_print_ddg (FILE *, ddg_ptr);
  130. void print_ddg_edge (FILE *, ddg_edge_ptr);
  131. void print_sccs (FILE *, ddg_all_sccs_ptr, ddg_ptr);
  132. ddg_node_ptr get_node_of_insn (ddg_ptr, rtx_insn *);
  133. void find_successors (sbitmap result, ddg_ptr, sbitmap);
  134. void find_predecessors (sbitmap result, ddg_ptr, sbitmap);
  135. ddg_all_sccs_ptr create_ddg_all_sccs (ddg_ptr);
  136. void free_ddg_all_sccs (ddg_all_sccs_ptr);
  137. int find_nodes_on_paths (sbitmap result, ddg_ptr, sbitmap from, sbitmap to);
  138. int longest_simple_path (ddg_ptr, int from, int to, sbitmap via);
  139. bool autoinc_var_is_used_p (rtx_insn *, rtx_insn *);
  140. #endif /* GCC_DDG_H */