您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

311 行
7.4KB

  1. /* Single entry single exit control flow regions.
  2. Copyright (C) 2008-2020 Free Software Foundation, Inc.
  3. Contributed by Jan Sjodin <jan.sjodin@amd.com> and
  4. Sebastian Pop <sebastian.pop@amd.com>.
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. GCC is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef GCC_SESE_H
  18. #define GCC_SESE_H
  19. typedef struct ifsese_s *ifsese;
  20. /* A Single Entry, Single Exit region is a part of the CFG delimited
  21. by two edges. */
  22. class sese_l
  23. {
  24. public:
  25. sese_l (edge e, edge x) : entry (e), exit (x) {}
  26. operator bool () const { return entry && exit; }
  27. edge entry;
  28. edge exit;
  29. };
  30. void print_edge (FILE *file, const_edge e);
  31. void print_sese (FILE *file, const sese_l &s);
  32. void dump_edge (const_edge e);
  33. void dump_sese (const sese_l &);
  34. /* Get the entry of an sese S. */
  35. static inline basic_block
  36. get_entry_bb (sese_l &s)
  37. {
  38. return s.entry->dest;
  39. }
  40. /* Get the exit of an sese S. */
  41. static inline basic_block
  42. get_exit_bb (sese_l &s)
  43. {
  44. return s.exit->src;
  45. }
  46. /* Returns the index of V where ELEM can be found. -1 Otherwise. */
  47. template<typename T>
  48. int
  49. vec_find (const vec<T> &v, const T &elem)
  50. {
  51. int i;
  52. T t;
  53. FOR_EACH_VEC_ELT (v, i, t)
  54. if (elem == t)
  55. return i;
  56. return -1;
  57. }
  58. /* A helper structure for bookkeeping information about a scop in graphite. */
  59. typedef class sese_info_t
  60. {
  61. public:
  62. /* The SESE region. */
  63. sese_l region;
  64. /* Liveout vars. */
  65. bitmap liveout;
  66. /* Liveout in debug stmts. */
  67. bitmap debug_liveout;
  68. /* Parameters used within the SCOP. */
  69. vec<tree> params;
  70. /* Maps an old name to a new decl. */
  71. hash_map<tree, tree> *rename_map;
  72. /* Basic blocks contained in this SESE. */
  73. vec<basic_block> bbs;
  74. /* The condition region generated for this sese. */
  75. ifsese if_region;
  76. } *sese_info_p;
  77. extern sese_info_p new_sese_info (edge, edge);
  78. extern void free_sese_info (sese_info_p);
  79. extern void sese_insert_phis_for_liveouts (sese_info_p, basic_block, edge, edge);
  80. extern class loop *outermost_loop_in_sese (sese_l &, basic_block);
  81. extern tree scalar_evolution_in_region (const sese_l &, loop_p, tree);
  82. extern bool scev_analyzable_p (tree, sese_l &);
  83. extern bool invariant_in_sese_p_rec (tree, const sese_l &, bool *);
  84. extern void sese_build_liveouts (sese_info_p);
  85. extern bool sese_trivially_empty_bb_p (basic_block);
  86. /* The number of parameters in REGION. */
  87. static inline unsigned
  88. sese_nb_params (sese_info_p region)
  89. {
  90. return region->params.length ();
  91. }
  92. /* Checks whether BB is contained in the region delimited by ENTRY and
  93. EXIT blocks. */
  94. static inline bool
  95. bb_in_region (const_basic_block bb, const_basic_block entry, const_basic_block exit)
  96. {
  97. return dominated_by_p (CDI_DOMINATORS, bb, entry)
  98. && !(dominated_by_p (CDI_DOMINATORS, bb, exit)
  99. && !dominated_by_p (CDI_DOMINATORS, entry, exit));
  100. }
  101. /* Checks whether BB is contained in the region delimited by ENTRY and
  102. EXIT blocks. */
  103. static inline bool
  104. bb_in_sese_p (basic_block bb, const sese_l &r)
  105. {
  106. return bb_in_region (bb, r.entry->dest, r.exit->dest);
  107. }
  108. /* Returns true when STMT is defined in REGION. */
  109. static inline bool
  110. stmt_in_sese_p (gimple *stmt, const sese_l &r)
  111. {
  112. basic_block bb = gimple_bb (stmt);
  113. return bb && bb_in_sese_p (bb, r);
  114. }
  115. /* Returns true when NAME is defined in REGION. */
  116. static inline bool
  117. defined_in_sese_p (tree name, const sese_l &r)
  118. {
  119. return stmt_in_sese_p (SSA_NAME_DEF_STMT (name), r);
  120. }
  121. /* Returns true when LOOP is in REGION. */
  122. static inline bool
  123. loop_in_sese_p (class loop *loop, const sese_l &region)
  124. {
  125. return (bb_in_sese_p (loop->header, region)
  126. && bb_in_sese_p (loop->latch, region));
  127. }
  128. /* Returns the loop depth of LOOP in REGION. The loop depth
  129. is the same as the normal loop depth, but limited by a region.
  130. Example:
  131. loop_0
  132. loop_1
  133. {
  134. S0
  135. <- region start
  136. S1
  137. loop_2
  138. S2
  139. S3
  140. <- region end
  141. }
  142. loop_0 does not exist in the region -> invalid
  143. loop_1 exists, but is not completely contained in the region -> depth 0
  144. loop_2 is completely contained -> depth 1 */
  145. static inline unsigned int
  146. sese_loop_depth (const sese_l &region, loop_p loop)
  147. {
  148. unsigned int depth = 0;
  149. while (loop_in_sese_p (loop, region))
  150. {
  151. depth++;
  152. loop = loop_outer (loop);
  153. }
  154. return depth;
  155. }
  156. /* A single entry single exit specialized for conditions. */
  157. typedef struct ifsese_s {
  158. sese_info_p region;
  159. sese_info_p true_region;
  160. sese_info_p false_region;
  161. } *ifsese;
  162. extern ifsese move_sese_in_condition (sese_info_p);
  163. extern void set_ifsese_condition (ifsese, tree);
  164. extern edge get_true_edge_from_guard_bb (basic_block);
  165. extern edge get_false_edge_from_guard_bb (basic_block);
  166. static inline edge
  167. if_region_entry (ifsese if_region)
  168. {
  169. return if_region->region->region.entry;
  170. }
  171. static inline edge
  172. if_region_exit (ifsese if_region)
  173. {
  174. return if_region->region->region.exit;
  175. }
  176. static inline basic_block
  177. if_region_get_condition_block (ifsese if_region)
  178. {
  179. return if_region_entry (if_region)->dest;
  180. }
  181. typedef std::pair <gimple *, tree> scalar_use;
  182. typedef struct gimple_poly_bb
  183. {
  184. basic_block bb;
  185. struct poly_bb *pbb;
  186. /* Lists containing the restrictions of the conditional statements
  187. dominating this bb. This bb can only be executed, if all conditions
  188. are true.
  189. Example:
  190. for (i = 0; i <= 20; i++)
  191. {
  192. A
  193. if (2i <= 8)
  194. B
  195. }
  196. So for B there is an additional condition (2i <= 8).
  197. List of COND_EXPR and SWITCH_EXPR. A COND_EXPR is true only if the
  198. corresponding element in CONDITION_CASES is not NULL_TREE. For a
  199. SWITCH_EXPR the corresponding element in CONDITION_CASES is a
  200. CASE_LABEL_EXPR. */
  201. vec<gimple *> conditions;
  202. vec<gimple *> condition_cases;
  203. vec<data_reference_p> data_refs;
  204. vec<scalar_use> read_scalar_refs;
  205. vec<tree> write_scalar_refs;
  206. } *gimple_poly_bb_p;
  207. #define GBB_BB(GBB) (GBB)->bb
  208. #define GBB_PBB(GBB) (GBB)->pbb
  209. #define GBB_DATA_REFS(GBB) (GBB)->data_refs
  210. #define GBB_CONDITIONS(GBB) (GBB)->conditions
  211. #define GBB_CONDITION_CASES(GBB) (GBB)->condition_cases
  212. /* Return the innermost loop that contains the basic block GBB. */
  213. static inline class loop *
  214. gbb_loop (gimple_poly_bb_p gbb)
  215. {
  216. return GBB_BB (gbb)->loop_father;
  217. }
  218. /* Returns the gimple loop, that corresponds to the loop_iterator_INDEX.
  219. If there is no corresponding gimple loop, we return NULL. */
  220. static inline loop_p
  221. gbb_loop_at_index (gimple_poly_bb_p gbb, sese_l &region, int index)
  222. {
  223. loop_p loop = gbb_loop (gbb);
  224. int depth = sese_loop_depth (region, loop);
  225. while (--depth > index)
  226. loop = loop_outer (loop);
  227. gcc_assert (loop_in_sese_p (loop, region));
  228. return loop;
  229. }
  230. /* The number of common loops in REGION for GBB1 and GBB2. */
  231. static inline int
  232. nb_common_loops (sese_l &region, gimple_poly_bb_p gbb1, gimple_poly_bb_p gbb2)
  233. {
  234. loop_p l1 = gbb_loop (gbb1);
  235. loop_p l2 = gbb_loop (gbb2);
  236. loop_p common = find_common_loop (l1, l2);
  237. return sese_loop_depth (region, common);
  238. }
  239. #endif