PageRenderTime 58ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/mingw-w64-v2.0.999/gcc/src/gcc/graphite-poly.h

#
C Header | 1569 lines | 917 code | 320 blank | 332 comment | 120 complexity | b7d9d8db1d32668f70228eb161820646 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, LGPL-3.0, Unlicense, GPL-2.0, LGPL-2.0, BSD-3-Clause, GPL-3.0
  1. /* Graphite polyhedral representation.
  2. Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
  3. Contributed by Sebastian Pop <sebastian.pop@amd.com> and
  4. Tobias Grosser <grosser@fim.uni-passau.de>.
  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_GRAPHITE_POLY_H
  18. #define GCC_GRAPHITE_POLY_H
  19. typedef struct poly_dr *poly_dr_p;
  20. DEF_VEC_P(poly_dr_p);
  21. DEF_VEC_ALLOC_P (poly_dr_p, heap);
  22. typedef struct poly_bb *poly_bb_p;
  23. DEF_VEC_P(poly_bb_p);
  24. DEF_VEC_ALLOC_P (poly_bb_p, heap);
  25. typedef struct scop *scop_p;
  26. DEF_VEC_P(scop_p);
  27. DEF_VEC_ALLOC_P (scop_p, heap);
  28. typedef unsigned graphite_dim_t;
  29. static inline graphite_dim_t pbb_dim_iter_domain (const struct poly_bb *);
  30. static inline graphite_dim_t pbb_nb_params (const struct poly_bb *);
  31. static inline graphite_dim_t scop_nb_params (scop_p);
  32. /* A data reference can write or read some memory or we
  33. just know it may write some memory. */
  34. enum poly_dr_type
  35. {
  36. PDR_READ,
  37. /* PDR_MAY_READs are represented using PDR_READS. This does not
  38. limit the expressiveness. */
  39. PDR_WRITE,
  40. PDR_MAY_WRITE
  41. };
  42. struct poly_dr
  43. {
  44. /* An identifier for this PDR. */
  45. int id;
  46. /* The number of data refs identical to this one in the PBB. */
  47. int nb_refs;
  48. /* A pointer to compiler's data reference description. */
  49. void *compiler_dr;
  50. /* A pointer to the PBB that contains this data reference. */
  51. poly_bb_p pbb;
  52. enum poly_dr_type type;
  53. /* The access polyhedron contains the polyhedral space this data
  54. reference will access.
  55. The polyhedron contains these dimensions:
  56. - The alias set (a):
  57. Every memory access is classified in at least one alias set.
  58. - The subscripts (s_0, ..., s_n):
  59. The memory is accessed using zero or more subscript dimensions.
  60. - The iteration domain (variables and parameters)
  61. Do not hardcode the dimensions. Use the following accessor functions:
  62. - pdr_alias_set_dim
  63. - pdr_subscript_dim
  64. - pdr_iterator_dim
  65. - pdr_parameter_dim
  66. Example:
  67. | int A[1335][123];
  68. | int *p = malloc ();
  69. |
  70. | k = ...
  71. | for i
  72. | {
  73. | if (unknown_function ())
  74. | p = A;
  75. | ... = p[?][?];
  76. | for j
  77. | A[i][j+k] = m;
  78. | }
  79. The data access A[i][j+k] in alias set "5" is described like this:
  80. | i j k a s0 s1 1
  81. | 0 0 0 1 0 0 -5 = 0
  82. |-1 0 0 0 1 0 0 = 0
  83. | 0 -1 -1 0 0 1 0 = 0
  84. | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
  85. | 0 0 0 0 0 1 0 >= 0 # array size.
  86. | 0 0 0 0 -1 0 1335 >= 0
  87. | 0 0 0 0 0 -1 123 >= 0
  88. The pointer "*p" in alias set "5" and "7" is described as a union of
  89. polyhedron:
  90. | i k a s0 1
  91. | 0 0 1 0 -5 = 0
  92. | 0 0 0 1 0 >= 0
  93. "or"
  94. | i k a s0 1
  95. | 0 0 1 0 -7 = 0
  96. | 0 0 0 1 0 >= 0
  97. "*p" accesses all of the object allocated with 'malloc'.
  98. The scalar data access "m" is represented as an array with zero subscript
  99. dimensions.
  100. | i j k a 1
  101. | 0 0 0 -1 15 = 0
  102. The difference between the graphite internal format for access data and
  103. the OpenSop format is in the order of columns.
  104. Instead of having:
  105. | i j k a s0 s1 1
  106. | 0 0 0 1 0 0 -5 = 0
  107. |-1 0 0 0 1 0 0 = 0
  108. | 0 -1 -1 0 0 1 0 = 0
  109. | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
  110. | 0 0 0 0 0 1 0 >= 0 # array size.
  111. | 0 0 0 0 -1 0 1335 >= 0
  112. | 0 0 0 0 0 -1 123 >= 0
  113. In OpenScop we have:
  114. | a s0 s1 i j k 1
  115. | 1 0 0 0 0 0 -5 = 0
  116. | 0 1 0 -1 0 0 0 = 0
  117. | 0 0 1 0 -1 -1 0 = 0
  118. | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
  119. | 0 0 1 0 0 0 0 >= 0 # array size.
  120. | 0 -1 0 0 0 0 1335 >= 0
  121. | 0 0 -1 0 0 0 123 >= 0
  122. The OpenScop access function is printed as follows:
  123. | 1 # The number of disjunct components in a union of access functions.
  124. | R C O I L P # Described bellow.
  125. | a s0 s1 i j k 1
  126. | 1 0 0 0 0 0 -5 = 0
  127. | 0 1 0 -1 0 0 0 = 0
  128. | 0 0 1 0 -1 -1 0 = 0
  129. | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
  130. | 0 0 1 0 0 0 0 >= 0 # array size.
  131. | 0 -1 0 0 0 0 1335 >= 0
  132. | 0 0 -1 0 0 0 123 >= 0
  133. Where:
  134. - R: Number of rows.
  135. - C: Number of columns.
  136. - O: Number of output dimensions = alias set + number of subscripts.
  137. - I: Number of input dimensions (iterators).
  138. - L: Number of local (existentially quantified) dimensions.
  139. - P: Number of parameters.
  140. In the example, the vector "R C O I L P" is "7 7 3 2 0 1". */
  141. isl_map *accesses;
  142. isl_set *extent;
  143. /* Data reference's base object set number, we must assure 2 pdrs are in the
  144. same base object set before dependency checking. */
  145. int dr_base_object_set;
  146. /* The number of subscripts. */
  147. graphite_dim_t nb_subscripts;
  148. };
  149. #define PDR_ID(PDR) (PDR->id)
  150. #define PDR_NB_REFS(PDR) (PDR->nb_refs)
  151. #define PDR_CDR(PDR) (PDR->compiler_dr)
  152. #define PDR_PBB(PDR) (PDR->pbb)
  153. #define PDR_TYPE(PDR) (PDR->type)
  154. #define PDR_ACCESSES(PDR) (NULL)
  155. #define PDR_BASE_OBJECT_SET(PDR) (PDR->dr_base_object_set)
  156. #define PDR_NB_SUBSCRIPTS(PDR) (PDR->nb_subscripts)
  157. void new_poly_dr (poly_bb_p, int, enum poly_dr_type, void *,
  158. graphite_dim_t, isl_map *, isl_set *);
  159. void free_poly_dr (poly_dr_p);
  160. void debug_pdr (poly_dr_p, int);
  161. void print_pdr (FILE *, poly_dr_p, int);
  162. static inline scop_p pdr_scop (poly_dr_p pdr);
  163. /* The dimension of the iteration domain of the scop of PDR. */
  164. static inline graphite_dim_t
  165. pdr_dim_iter_domain (poly_dr_p pdr)
  166. {
  167. return pbb_dim_iter_domain (PDR_PBB (pdr));
  168. }
  169. /* The number of parameters of the scop of PDR. */
  170. static inline graphite_dim_t
  171. pdr_nb_params (poly_dr_p pdr)
  172. {
  173. return scop_nb_params (pdr_scop (pdr));
  174. }
  175. /* The dimension of the alias set in PDR. */
  176. static inline graphite_dim_t
  177. pdr_alias_set_dim (poly_dr_p pdr)
  178. {
  179. poly_bb_p pbb = PDR_PBB (pdr);
  180. return pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb);
  181. }
  182. /* The dimension in PDR containing subscript S. */
  183. static inline graphite_dim_t
  184. pdr_subscript_dim (poly_dr_p pdr, graphite_dim_t s)
  185. {
  186. poly_bb_p pbb = PDR_PBB (pdr);
  187. return pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb) + 1 + s;
  188. }
  189. /* The dimension in PDR containing the loop iterator ITER. */
  190. static inline graphite_dim_t
  191. pdr_iterator_dim (poly_dr_p pdr ATTRIBUTE_UNUSED, graphite_dim_t iter)
  192. {
  193. return iter;
  194. }
  195. /* The dimension in PDR containing parameter PARAM. */
  196. static inline graphite_dim_t
  197. pdr_parameter_dim (poly_dr_p pdr, graphite_dim_t param)
  198. {
  199. poly_bb_p pbb = PDR_PBB (pdr);
  200. return pbb_dim_iter_domain (pbb) + param;
  201. }
  202. /* Returns true when PDR is a "read". */
  203. static inline bool
  204. pdr_read_p (poly_dr_p pdr)
  205. {
  206. return PDR_TYPE (pdr) == PDR_READ;
  207. }
  208. /* Returns true when PDR is a "write". */
  209. static inline bool
  210. pdr_write_p (poly_dr_p pdr)
  211. {
  212. return PDR_TYPE (pdr) == PDR_WRITE;
  213. }
  214. /* Returns true when PDR is a "may write". */
  215. static inline bool
  216. pdr_may_write_p (poly_dr_p pdr)
  217. {
  218. return PDR_TYPE (pdr) == PDR_MAY_WRITE;
  219. }
  220. /* Return true when PDR1 and PDR2 are similar data accesses: they have
  221. the same base array, and the same access functions. */
  222. static inline bool
  223. same_pdr_p (poly_dr_p pdr1, poly_dr_p pdr2)
  224. {
  225. return PDR_NB_SUBSCRIPTS (pdr1) == PDR_NB_SUBSCRIPTS (pdr2)
  226. && PDR_BASE_OBJECT_SET (pdr1) == PDR_BASE_OBJECT_SET (pdr2);
  227. }
  228. typedef struct poly_scattering *poly_scattering_p;
  229. struct poly_scattering
  230. {
  231. /* The number of local variables. */
  232. int nb_local_variables;
  233. /* The number of scattering dimensions. */
  234. int nb_scattering;
  235. };
  236. /* POLY_BB represents a blackbox in the polyhedral model. */
  237. struct poly_bb
  238. {
  239. /* Pointer to a basic block or a statement in the compiler. */
  240. void *black_box;
  241. /* Pointer to the SCOP containing this PBB. */
  242. scop_p scop;
  243. /* The iteration domain of this bb. The layout of this polyhedron
  244. is I|G with I the iteration domain, G the context parameters.
  245. Example:
  246. for (i = a - 7*b + 8; i <= 3*a + 13*b + 20; i++)
  247. for (j = 2; j <= 2*i + 5; j++)
  248. for (k = 0; k <= 5; k++)
  249. S (i,j,k)
  250. Loop iterators: i, j, k
  251. Parameters: a, b
  252. | i >= a - 7b + 8
  253. | i <= 3a + 13b + 20
  254. | j >= 2
  255. | j <= 2i + 5
  256. | k >= 0
  257. | k <= 5
  258. The number of variables in the DOMAIN may change and is not
  259. related to the number of loops in the original code. */
  260. isl_set *domain;
  261. /* The data references we access. */
  262. VEC (poly_dr_p, heap) *drs;
  263. /* The original scattering. */
  264. poly_scattering_p _original;
  265. isl_map *schedule;
  266. /* The transformed scattering. */
  267. poly_scattering_p _transformed;
  268. isl_map *transformed;
  269. /* A copy of the transformed scattering. */
  270. poly_scattering_p _saved;
  271. isl_map *saved;
  272. /* True when this PBB contains only a reduction statement. */
  273. bool is_reduction;
  274. };
  275. #define PBB_BLACK_BOX(PBB) ((gimple_bb_p) PBB->black_box)
  276. #define PBB_SCOP(PBB) (PBB->scop)
  277. #define PBB_DOMAIN(PBB) (NULL)
  278. #define PBB_DRS(PBB) (PBB->drs)
  279. #define PBB_ORIGINAL(PBB) (PBB->_original)
  280. #define PBB_ORIGINAL_SCATTERING(PBB) (NULL)
  281. #define PBB_TRANSFORMED(PBB) (PBB->_transformed)
  282. #define PBB_TRANSFORMED_SCATTERING(PBB) (NULL)
  283. #define PBB_SAVED(PBB) (PBB->_saved)
  284. /* XXX isl if we ever need local vars in the scatter, we can't use the
  285. out dimension of transformed to count the scatterting transform dimension.
  286. */
  287. #define PBB_NB_LOCAL_VARIABLES(PBB) (0)
  288. #define PBB_NB_SCATTERING_TRANSFORM(PBB) (isl_map_n_out (PBB->transformed))
  289. #define PBB_IS_REDUCTION(PBB) (PBB->is_reduction)
  290. extern poly_bb_p new_poly_bb (scop_p, void *);
  291. extern void free_poly_bb (poly_bb_p);
  292. extern void debug_loop_vec (poly_bb_p);
  293. extern void schedule_to_scattering (poly_bb_p, int);
  294. extern void print_pbb_domain (FILE *, poly_bb_p, int);
  295. extern void print_pbb (FILE *, poly_bb_p, int);
  296. extern void print_scop_context (FILE *, scop_p, int);
  297. extern void print_scop (FILE *, scop_p, int);
  298. extern void print_cloog (FILE *, scop_p, int);
  299. extern void debug_pbb_domain (poly_bb_p, int);
  300. extern void debug_pbb (poly_bb_p, int);
  301. extern void print_pdrs (FILE *, poly_bb_p, int);
  302. extern void debug_pdrs (poly_bb_p, int);
  303. extern void debug_scop_context (scop_p, int);
  304. extern void debug_scop (scop_p, int);
  305. extern void debug_cloog (scop_p, int);
  306. extern void print_scop_params (FILE *, scop_p, int);
  307. extern void debug_scop_params (scop_p, int);
  308. extern void print_iteration_domain (FILE *, poly_bb_p, int);
  309. extern void print_iteration_domains (FILE *, scop_p, int);
  310. extern void debug_iteration_domain (poly_bb_p, int);
  311. extern void debug_iteration_domains (scop_p, int);
  312. extern void print_isl_set (FILE *, isl_set *);
  313. extern void print_isl_map (FILE *, isl_map *);
  314. extern void print_isl_aff (FILE *, isl_aff *);
  315. extern void print_isl_constraint (FILE *, isl_constraint *);
  316. extern void debug_isl_set (isl_set *);
  317. extern void debug_isl_map (isl_map *);
  318. extern void debug_isl_aff (isl_aff *);
  319. extern void debug_isl_constraint (isl_constraint *);
  320. extern int scop_do_interchange (scop_p);
  321. extern int scop_do_strip_mine (scop_p, int);
  322. extern bool scop_do_block (scop_p);
  323. extern bool flatten_all_loops (scop_p);
  324. extern bool optimize_isl(scop_p);
  325. extern void pbb_number_of_iterations_at_time (poly_bb_p, graphite_dim_t, mpz_t);
  326. extern void debug_gmp_value (mpz_t);
  327. /* Return the number of write data references in PBB. */
  328. static inline int
  329. number_of_write_pdrs (poly_bb_p pbb)
  330. {
  331. int res = 0;
  332. int i;
  333. poly_dr_p pdr;
  334. for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
  335. if (PDR_TYPE (pdr) == PDR_WRITE)
  336. res++;
  337. return res;
  338. }
  339. /* Returns a gimple_bb from BB. */
  340. static inline gimple_bb_p
  341. gbb_from_bb (basic_block bb)
  342. {
  343. return (gimple_bb_p) bb->aux;
  344. }
  345. /* The poly_bb of the BB. */
  346. static inline poly_bb_p
  347. pbb_from_bb (basic_block bb)
  348. {
  349. return GBB_PBB (gbb_from_bb (bb));
  350. }
  351. /* The basic block of the PBB. */
  352. static inline basic_block
  353. pbb_bb (poly_bb_p pbb)
  354. {
  355. return GBB_BB (PBB_BLACK_BOX (pbb));
  356. }
  357. /* The index of the PBB. */
  358. static inline int
  359. pbb_index (poly_bb_p pbb)
  360. {
  361. return pbb_bb (pbb)->index;
  362. }
  363. /* The loop of the PBB. */
  364. static inline loop_p
  365. pbb_loop (poly_bb_p pbb)
  366. {
  367. return gbb_loop (PBB_BLACK_BOX (pbb));
  368. }
  369. /* The scop that contains the PDR. */
  370. static inline scop_p
  371. pdr_scop (poly_dr_p pdr)
  372. {
  373. return PBB_SCOP (PDR_PBB (pdr));
  374. }
  375. /* Set black box of PBB to BLACKBOX. */
  376. static inline void
  377. pbb_set_black_box (poly_bb_p pbb, void *black_box)
  378. {
  379. pbb->black_box = black_box;
  380. }
  381. /* The number of loops around PBB: the dimension of the iteration
  382. domain. */
  383. static inline graphite_dim_t
  384. pbb_dim_iter_domain (const struct poly_bb *pbb)
  385. {
  386. return isl_set_dim (pbb->domain, isl_dim_set);
  387. }
  388. /* The number of params defined in PBB. */
  389. static inline graphite_dim_t
  390. pbb_nb_params (const struct poly_bb *pbb)
  391. {
  392. scop_p scop = PBB_SCOP (pbb);
  393. return scop_nb_params (scop);
  394. }
  395. /* The number of scattering dimensions in the SCATTERING polyhedron
  396. of a PBB for a given SCOP. */
  397. static inline graphite_dim_t
  398. pbb_nb_scattering_orig (const struct poly_bb *pbb)
  399. {
  400. return 2 * pbb_dim_iter_domain (pbb) + 1;
  401. }
  402. /* The number of scattering dimensions in PBB. */
  403. static inline graphite_dim_t
  404. pbb_nb_scattering_transform (const struct poly_bb *pbb)
  405. {
  406. return PBB_NB_SCATTERING_TRANSFORM (pbb);
  407. }
  408. /* The number of dynamic scattering dimensions in PBB. */
  409. static inline graphite_dim_t
  410. pbb_nb_dynamic_scattering_transform (const struct poly_bb *pbb)
  411. {
  412. /* This function requires the 2d + 1 scattering format to be
  413. invariant during all transformations. */
  414. gcc_assert (PBB_NB_SCATTERING_TRANSFORM (pbb) % 2);
  415. return PBB_NB_SCATTERING_TRANSFORM (pbb) / 2;
  416. }
  417. /* Returns the number of local variables used in the transformed
  418. scattering polyhedron of PBB. */
  419. static inline graphite_dim_t
  420. pbb_nb_local_vars (const struct poly_bb *pbb ATTRIBUTE_UNUSED)
  421. {
  422. /* For now we do not have any local variables, as we do not do strip
  423. mining for example. */
  424. return PBB_NB_LOCAL_VARIABLES (pbb);
  425. }
  426. /* The dimension in the domain of PBB containing the iterator ITER. */
  427. static inline graphite_dim_t
  428. pbb_iterator_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t iter)
  429. {
  430. return iter;
  431. }
  432. /* The dimension in the domain of PBB containing the iterator ITER. */
  433. static inline graphite_dim_t
  434. pbb_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
  435. {
  436. return param
  437. + pbb_dim_iter_domain (pbb);
  438. }
  439. /* The dimension in the original scattering polyhedron of PBB
  440. containing the scattering iterator SCATTER. */
  441. static inline graphite_dim_t
  442. psco_scattering_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t scatter)
  443. {
  444. gcc_assert (scatter < pbb_nb_scattering_orig (pbb));
  445. return scatter;
  446. }
  447. /* The dimension in the transformed scattering polyhedron of PBB
  448. containing the scattering iterator SCATTER. */
  449. static inline graphite_dim_t
  450. psct_scattering_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t scatter)
  451. {
  452. gcc_assert (scatter <= pbb_nb_scattering_transform (pbb));
  453. return scatter;
  454. }
  455. /* The dimension in the transformed scattering polyhedron of PBB of
  456. the local variable LV. */
  457. static inline graphite_dim_t
  458. psct_local_var_dim (poly_bb_p pbb, graphite_dim_t lv)
  459. {
  460. gcc_assert (lv <= pbb_nb_local_vars (pbb));
  461. return lv + pbb_nb_scattering_transform (pbb);
  462. }
  463. /* The dimension in the original scattering polyhedron of PBB
  464. containing the loop iterator ITER. */
  465. static inline graphite_dim_t
  466. psco_iterator_dim (poly_bb_p pbb, graphite_dim_t iter)
  467. {
  468. gcc_assert (iter < pbb_dim_iter_domain (pbb));
  469. return iter + pbb_nb_scattering_orig (pbb);
  470. }
  471. /* The dimension in the transformed scattering polyhedron of PBB
  472. containing the loop iterator ITER. */
  473. static inline graphite_dim_t
  474. psct_iterator_dim (poly_bb_p pbb, graphite_dim_t iter)
  475. {
  476. gcc_assert (iter < pbb_dim_iter_domain (pbb));
  477. return iter
  478. + pbb_nb_scattering_transform (pbb)
  479. + pbb_nb_local_vars (pbb);
  480. }
  481. /* The dimension in the original scattering polyhedron of PBB
  482. containing parameter PARAM. */
  483. static inline graphite_dim_t
  484. psco_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
  485. {
  486. gcc_assert (param < pbb_nb_params (pbb));
  487. return param
  488. + pbb_nb_scattering_orig (pbb)
  489. + pbb_dim_iter_domain (pbb);
  490. }
  491. /* The dimension in the transformed scattering polyhedron of PBB
  492. containing parameter PARAM. */
  493. static inline graphite_dim_t
  494. psct_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
  495. {
  496. gcc_assert (param < pbb_nb_params (pbb));
  497. return param
  498. + pbb_nb_scattering_transform (pbb)
  499. + pbb_nb_local_vars (pbb)
  500. + pbb_dim_iter_domain (pbb);
  501. }
  502. /* The scattering dimension of PBB corresponding to the dynamic level
  503. LEVEL. */
  504. static inline graphite_dim_t
  505. psct_dynamic_dim (poly_bb_p pbb, graphite_dim_t level)
  506. {
  507. graphite_dim_t result = 1 + 2 * level;
  508. gcc_assert (result < pbb_nb_scattering_transform (pbb));
  509. return result;
  510. }
  511. /* The scattering dimension of PBB corresponding to the static
  512. sequence of the loop level LEVEL. */
  513. static inline graphite_dim_t
  514. psct_static_dim (poly_bb_p pbb, graphite_dim_t level)
  515. {
  516. graphite_dim_t result = 2 * level;
  517. gcc_assert (result < pbb_nb_scattering_transform (pbb));
  518. return result;
  519. }
  520. /* Adds to the transformed scattering polyhedron of PBB a new local
  521. variable and returns its index. */
  522. static inline graphite_dim_t
  523. psct_add_local_variable (poly_bb_p pbb ATTRIBUTE_UNUSED)
  524. {
  525. gcc_unreachable ();
  526. return 0;
  527. }
  528. typedef struct lst *lst_p;
  529. DEF_VEC_P(lst_p);
  530. DEF_VEC_ALLOC_P (lst_p, heap);
  531. /* Loops and Statements Tree. */
  532. struct lst {
  533. /* LOOP_P is true when an LST node is a loop. */
  534. bool loop_p;
  535. /* A pointer to the loop that contains this node. */
  536. lst_p loop_father;
  537. /* The sum of all the memory strides for an LST loop. */
  538. mpz_t memory_strides;
  539. /* Loop nodes contain a sequence SEQ of LST nodes, statements
  540. contain a pointer to their polyhedral representation PBB. */
  541. union {
  542. poly_bb_p pbb;
  543. VEC (lst_p, heap) *seq;
  544. } node;
  545. };
  546. #define LST_LOOP_P(LST) ((LST)->loop_p)
  547. #define LST_LOOP_FATHER(LST) ((LST)->loop_father)
  548. #define LST_PBB(LST) ((LST)->node.pbb)
  549. #define LST_SEQ(LST) ((LST)->node.seq)
  550. #define LST_LOOP_MEMORY_STRIDES(LST) ((LST)->memory_strides)
  551. void scop_to_lst (scop_p);
  552. void print_lst (FILE *, lst_p, int);
  553. void debug_lst (lst_p);
  554. void dot_lst (lst_p);
  555. /* Creates a new LST loop with SEQ. */
  556. static inline lst_p
  557. new_lst_loop (VEC (lst_p, heap) *seq)
  558. {
  559. lst_p lst = XNEW (struct lst);
  560. int i;
  561. lst_p l;
  562. LST_LOOP_P (lst) = true;
  563. LST_SEQ (lst) = seq;
  564. LST_LOOP_FATHER (lst) = NULL;
  565. mpz_init (LST_LOOP_MEMORY_STRIDES (lst));
  566. mpz_set_si (LST_LOOP_MEMORY_STRIDES (lst), -1);
  567. for (i = 0; VEC_iterate (lst_p, seq, i, l); i++)
  568. LST_LOOP_FATHER (l) = lst;
  569. return lst;
  570. }
  571. /* Creates a new LST statement with PBB. */
  572. static inline lst_p
  573. new_lst_stmt (poly_bb_p pbb)
  574. {
  575. lst_p lst = XNEW (struct lst);
  576. LST_LOOP_P (lst) = false;
  577. LST_PBB (lst) = pbb;
  578. LST_LOOP_FATHER (lst) = NULL;
  579. return lst;
  580. }
  581. /* Frees the memory used by LST. */
  582. static inline void
  583. free_lst (lst_p lst)
  584. {
  585. if (!lst)
  586. return;
  587. if (LST_LOOP_P (lst))
  588. {
  589. int i;
  590. lst_p l;
  591. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  592. free_lst (l);
  593. mpz_clear (LST_LOOP_MEMORY_STRIDES (lst));
  594. VEC_free (lst_p, heap, LST_SEQ (lst));
  595. }
  596. free (lst);
  597. }
  598. /* Returns a copy of LST. */
  599. static inline lst_p
  600. copy_lst (lst_p lst)
  601. {
  602. if (!lst)
  603. return NULL;
  604. if (LST_LOOP_P (lst))
  605. {
  606. int i;
  607. lst_p l;
  608. VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
  609. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  610. VEC_safe_push (lst_p, heap, seq, copy_lst (l));
  611. return new_lst_loop (seq);
  612. }
  613. return new_lst_stmt (LST_PBB (lst));
  614. }
  615. /* Adds a new loop under the loop LST. */
  616. static inline void
  617. lst_add_loop_under_loop (lst_p lst)
  618. {
  619. VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 1);
  620. lst_p l = new_lst_loop (LST_SEQ (lst));
  621. gcc_assert (LST_LOOP_P (lst));
  622. LST_LOOP_FATHER (l) = lst;
  623. VEC_quick_push (lst_p, seq, l);
  624. LST_SEQ (lst) = seq;
  625. }
  626. /* Returns the loop depth of LST. */
  627. static inline int
  628. lst_depth (lst_p lst)
  629. {
  630. if (!lst)
  631. return -2;
  632. /* The depth of the outermost "fake" loop is -1. This outermost
  633. loop does not have a loop father and it is just a container, as
  634. in the loop representation of GCC. */
  635. if (!LST_LOOP_FATHER (lst))
  636. return -1;
  637. return lst_depth (LST_LOOP_FATHER (lst)) + 1;
  638. }
  639. /* Returns the Dewey number for LST. */
  640. static inline int
  641. lst_dewey_number (lst_p lst)
  642. {
  643. int i;
  644. lst_p l;
  645. if (!lst)
  646. return -1;
  647. if (!LST_LOOP_FATHER (lst))
  648. return 0;
  649. FOR_EACH_VEC_ELT (lst_p, LST_SEQ (LST_LOOP_FATHER (lst)), i, l)
  650. if (l == lst)
  651. return i;
  652. return -1;
  653. }
  654. /* Returns the Dewey number of LST at depth DEPTH. */
  655. static inline int
  656. lst_dewey_number_at_depth (lst_p lst, int depth)
  657. {
  658. gcc_assert (lst && depth >= 0 && lst_depth (lst) <= depth);
  659. if (lst_depth (lst) == depth)
  660. return lst_dewey_number (lst);
  661. return lst_dewey_number_at_depth (LST_LOOP_FATHER (lst), depth);
  662. }
  663. /* Returns the predecessor of LST in the sequence of its loop father.
  664. Returns NULL if LST is the first statement in the sequence. */
  665. static inline lst_p
  666. lst_pred (lst_p lst)
  667. {
  668. int dewey;
  669. lst_p father;
  670. if (!lst || !LST_LOOP_FATHER (lst))
  671. return NULL;
  672. dewey = lst_dewey_number (lst);
  673. if (dewey == 0)
  674. return NULL;
  675. father = LST_LOOP_FATHER (lst);
  676. return VEC_index (lst_p, LST_SEQ (father), dewey - 1);
  677. }
  678. /* Returns the successor of LST in the sequence of its loop father.
  679. Returns NULL if there is none. */
  680. static inline lst_p
  681. lst_succ (lst_p lst)
  682. {
  683. int dewey;
  684. lst_p father;
  685. if (!lst || !LST_LOOP_FATHER (lst))
  686. return NULL;
  687. dewey = lst_dewey_number (lst);
  688. father = LST_LOOP_FATHER (lst);
  689. if (VEC_length (lst_p, LST_SEQ (father)) == (unsigned) dewey + 1)
  690. return NULL;
  691. return VEC_index (lst_p, LST_SEQ (father), dewey + 1);
  692. }
  693. /* Return the LST node corresponding to PBB. */
  694. static inline lst_p
  695. lst_find_pbb (lst_p lst, poly_bb_p pbb)
  696. {
  697. int i;
  698. lst_p l;
  699. if (!lst)
  700. return NULL;
  701. if (!LST_LOOP_P (lst))
  702. return (pbb == LST_PBB (lst)) ? lst : NULL;
  703. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  704. {
  705. lst_p res = lst_find_pbb (l, pbb);
  706. if (res)
  707. return res;
  708. }
  709. return NULL;
  710. }
  711. /* Return the LST node corresponding to the loop around STMT at depth
  712. LOOP_DEPTH. */
  713. static inline lst_p
  714. find_lst_loop (lst_p stmt, int loop_depth)
  715. {
  716. lst_p loop = LST_LOOP_FATHER (stmt);
  717. gcc_assert (loop_depth >= 0);
  718. while (loop_depth < lst_depth (loop))
  719. loop = LST_LOOP_FATHER (loop);
  720. return loop;
  721. }
  722. /* Return the first LST representing a PBB statement in LST. */
  723. static inline lst_p
  724. lst_find_first_pbb (lst_p lst)
  725. {
  726. int i;
  727. lst_p l;
  728. if (!lst)
  729. return NULL;
  730. if (!LST_LOOP_P (lst))
  731. return lst;
  732. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  733. {
  734. lst_p res = lst_find_first_pbb (l);
  735. if (res)
  736. return res;
  737. }
  738. return NULL;
  739. }
  740. /* Returns true when LST is a loop that does not contain
  741. statements. */
  742. static inline bool
  743. lst_empty_p (lst_p lst)
  744. {
  745. return !lst_find_first_pbb (lst);
  746. }
  747. /* Return the last LST representing a PBB statement in LST. */
  748. static inline lst_p
  749. lst_find_last_pbb (lst_p lst)
  750. {
  751. int i;
  752. lst_p l, res = NULL;
  753. if (!lst)
  754. return NULL;
  755. if (!LST_LOOP_P (lst))
  756. return lst;
  757. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  758. {
  759. lst_p last = lst_find_last_pbb (l);
  760. if (last)
  761. res = last;
  762. }
  763. gcc_assert (res);
  764. return res;
  765. }
  766. /* Returns true if LOOP contains LST, in other words, if LST is nested
  767. in LOOP. */
  768. static inline bool
  769. lst_contains_p (lst_p loop, lst_p lst)
  770. {
  771. if (!loop || !lst || !LST_LOOP_P (loop))
  772. return false;
  773. if (loop == lst)
  774. return true;
  775. return lst_contains_p (loop, LST_LOOP_FATHER (lst));
  776. }
  777. /* Returns true if LOOP contains PBB, in other words, if PBB is nested
  778. in LOOP. */
  779. static inline bool
  780. lst_contains_pbb (lst_p loop, poly_bb_p pbb)
  781. {
  782. return lst_find_pbb (loop, pbb) ? true : false;
  783. }
  784. /* Creates a loop nest of depth NB_LOOPS containing LST. */
  785. static inline lst_p
  786. lst_create_nest (int nb_loops, lst_p lst)
  787. {
  788. lst_p res, loop;
  789. VEC (lst_p, heap) *seq;
  790. if (nb_loops == 0)
  791. return lst;
  792. seq = VEC_alloc (lst_p, heap, 1);
  793. loop = lst_create_nest (nb_loops - 1, lst);
  794. VEC_quick_push (lst_p, seq, loop);
  795. res = new_lst_loop (seq);
  796. LST_LOOP_FATHER (loop) = res;
  797. return res;
  798. }
  799. /* Removes LST from the sequence of statements of its loop father. */
  800. static inline void
  801. lst_remove_from_sequence (lst_p lst)
  802. {
  803. lst_p father = LST_LOOP_FATHER (lst);
  804. int dewey = lst_dewey_number (lst);
  805. gcc_assert (lst && father && dewey >= 0);
  806. VEC_ordered_remove (lst_p, LST_SEQ (father), dewey);
  807. LST_LOOP_FATHER (lst) = NULL;
  808. }
  809. /* Removes the loop LST and inline its body in the father loop. */
  810. static inline void
  811. lst_remove_loop_and_inline_stmts_in_loop_father (lst_p lst)
  812. {
  813. lst_p l, father = LST_LOOP_FATHER (lst);
  814. int i, dewey = lst_dewey_number (lst);
  815. gcc_assert (lst && father && dewey >= 0);
  816. VEC_ordered_remove (lst_p, LST_SEQ (father), dewey);
  817. LST_LOOP_FATHER (lst) = NULL;
  818. FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
  819. {
  820. VEC_safe_insert (lst_p, heap, LST_SEQ (father), dewey + i, l);
  821. LST_LOOP_FATHER (l) = father;
  822. }
  823. }
  824. /* Sets NITER to the upper bound approximation of the number of
  825. iterations of loop LST. */
  826. static inline void
  827. lst_niter_for_loop (lst_p lst, mpz_t niter)
  828. {
  829. int depth = lst_depth (lst);
  830. poly_bb_p pbb = LST_PBB (lst_find_first_pbb (lst));
  831. gcc_assert (LST_LOOP_P (lst));
  832. pbb_number_of_iterations_at_time (pbb, psct_dynamic_dim (pbb, depth), niter);
  833. }
  834. /* Updates the scattering of PBB to be at the DEWEY number in the loop
  835. at depth LEVEL. */
  836. static inline void
  837. pbb_update_scattering (poly_bb_p pbb, graphite_dim_t level, int dewey)
  838. {
  839. graphite_dim_t sched = psct_static_dim (pbb, level);
  840. isl_space *d = isl_map_get_space (pbb->transformed);
  841. isl_space *d1 = isl_space_range (d);
  842. unsigned i, n = isl_space_dim (d1, isl_dim_out);
  843. isl_space *d2 = isl_space_add_dims (d1, isl_dim_in, n);
  844. isl_map *x = isl_map_universe (d2);
  845. x = isl_map_fix_si (x, isl_dim_out, sched, dewey);
  846. for (i = 0; i < n; i++)
  847. if (i != sched)
  848. x = isl_map_equate (x, isl_dim_in, i, isl_dim_out, i);
  849. pbb->transformed = isl_map_apply_range (pbb->transformed, x);
  850. }
  851. /* Updates the scattering of all the PBBs under LST to be at the DEWEY
  852. number in the loop at depth LEVEL. */
  853. static inline void
  854. lst_update_scattering_under (lst_p lst, int level, int dewey)
  855. {
  856. int i;
  857. lst_p l;
  858. gcc_assert (lst && level >= 0 && dewey >= 0);
  859. if (LST_LOOP_P (lst))
  860. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  861. lst_update_scattering_under (l, level, dewey);
  862. else
  863. pbb_update_scattering (LST_PBB (lst), level, dewey);
  864. }
  865. /* Updates the all the scattering levels of all the PBBs under
  866. LST. */
  867. static inline void
  868. lst_update_scattering (lst_p lst)
  869. {
  870. int i;
  871. lst_p l;
  872. if (!lst)
  873. return;
  874. if (LST_LOOP_FATHER (lst))
  875. {
  876. lst_p father = LST_LOOP_FATHER (lst);
  877. int dewey = lst_dewey_number (lst);
  878. int level = lst_depth (lst);
  879. gcc_assert (lst && father && dewey >= 0 && level >= 0);
  880. for (i = dewey; VEC_iterate (lst_p, LST_SEQ (father), i, l); i++)
  881. lst_update_scattering_under (l, level, i);
  882. }
  883. if (LST_LOOP_P (lst))
  884. for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
  885. lst_update_scattering (l);
  886. }
  887. /* Inserts LST1 before LST2 if BEFORE is true; inserts LST1 after LST2
  888. if BEFORE is false. */
  889. static inline void
  890. lst_insert_in_sequence (lst_p lst1, lst_p lst2, bool before)
  891. {
  892. lst_p father;
  893. int dewey;
  894. /* Do not insert empty loops. */
  895. if (!lst1 || lst_empty_p (lst1))
  896. return;
  897. father = LST_LOOP_FATHER (lst2);
  898. dewey = lst_dewey_number (lst2);
  899. gcc_assert (lst2 && father && dewey >= 0);
  900. VEC_safe_insert (lst_p, heap, LST_SEQ (father), before ? dewey : dewey + 1,
  901. lst1);
  902. LST_LOOP_FATHER (lst1) = father;
  903. }
  904. /* Replaces LST1 with LST2. */
  905. static inline void
  906. lst_replace (lst_p lst1, lst_p lst2)
  907. {
  908. lst_p father;
  909. int dewey;
  910. if (!lst2 || lst_empty_p (lst2))
  911. return;
  912. father = LST_LOOP_FATHER (lst1);
  913. dewey = lst_dewey_number (lst1);
  914. LST_LOOP_FATHER (lst2) = father;
  915. VEC_replace (lst_p, LST_SEQ (father), dewey, lst2);
  916. }
  917. /* Returns a copy of ROOT where LST has been replaced by a copy of the
  918. LSTs A B C in this sequence. */
  919. static inline lst_p
  920. lst_substitute_3 (lst_p root, lst_p lst, lst_p a, lst_p b, lst_p c)
  921. {
  922. int i;
  923. lst_p l;
  924. VEC (lst_p, heap) *seq;
  925. if (!root)
  926. return NULL;
  927. gcc_assert (lst && root != lst);
  928. if (!LST_LOOP_P (root))
  929. return new_lst_stmt (LST_PBB (root));
  930. seq = VEC_alloc (lst_p, heap, 5);
  931. for (i = 0; VEC_iterate (lst_p, LST_SEQ (root), i, l); i++)
  932. if (l != lst)
  933. VEC_safe_push (lst_p, heap, seq, lst_substitute_3 (l, lst, a, b, c));
  934. else
  935. {
  936. if (!lst_empty_p (a))
  937. VEC_safe_push (lst_p, heap, seq, copy_lst (a));
  938. if (!lst_empty_p (b))
  939. VEC_safe_push (lst_p, heap, seq, copy_lst (b));
  940. if (!lst_empty_p (c))
  941. VEC_safe_push (lst_p, heap, seq, copy_lst (c));
  942. }
  943. return new_lst_loop (seq);
  944. }
  945. /* Moves LST before LOOP if BEFORE is true, and after the LOOP if
  946. BEFORE is false. */
  947. static inline void
  948. lst_distribute_lst (lst_p loop, lst_p lst, bool before)
  949. {
  950. int loop_depth = lst_depth (loop);
  951. int depth = lst_depth (lst);
  952. int nb_loops = depth - loop_depth;
  953. gcc_assert (lst && loop && LST_LOOP_P (loop) && nb_loops > 0);
  954. lst_remove_from_sequence (lst);
  955. lst_insert_in_sequence (lst_create_nest (nb_loops, lst), loop, before);
  956. }
  957. /* Removes from LOOP all the statements before/after and including PBB
  958. if BEFORE is true/false. Returns the negation of BEFORE when the
  959. statement PBB has been found. */
  960. static inline bool
  961. lst_remove_all_before_including_pbb (lst_p loop, poly_bb_p pbb, bool before)
  962. {
  963. int i;
  964. lst_p l;
  965. if (!loop || !LST_LOOP_P (loop))
  966. return before;
  967. for (i = 0; VEC_iterate (lst_p, LST_SEQ (loop), i, l);)
  968. if (LST_LOOP_P (l))
  969. {
  970. before = lst_remove_all_before_including_pbb (l, pbb, before);
  971. if (VEC_length (lst_p, LST_SEQ (l)) == 0)
  972. {
  973. VEC_ordered_remove (lst_p, LST_SEQ (loop), i);
  974. free_lst (l);
  975. }
  976. else
  977. i++;
  978. }
  979. else
  980. {
  981. if (before)
  982. {
  983. if (LST_PBB (l) == pbb)
  984. before = false;
  985. VEC_ordered_remove (lst_p, LST_SEQ (loop), i);
  986. free_lst (l);
  987. }
  988. else if (LST_PBB (l) == pbb)
  989. {
  990. before = true;
  991. VEC_ordered_remove (lst_p, LST_SEQ (loop), i);
  992. free_lst (l);
  993. }
  994. else
  995. i++;
  996. }
  997. return before;
  998. }
  999. /* Removes from LOOP all the statements before/after and excluding PBB
  1000. if BEFORE is true/false; Returns the negation of BEFORE when the
  1001. statement PBB has been found. */
  1002. static inline bool
  1003. lst_remove_all_before_excluding_pbb (lst_p loop, poly_bb_p pbb, bool before)
  1004. {
  1005. int i;
  1006. lst_p l;
  1007. if (!loop || !LST_LOOP_P (loop))
  1008. return before;
  1009. for (i = 0; VEC_iterate (lst_p, LST_SEQ (loop), i, l);)
  1010. if (LST_LOOP_P (l))
  1011. {
  1012. before = lst_remove_all_before_excluding_pbb (l, pbb, before);
  1013. if (VEC_length (lst_p, LST_SEQ (l)) == 0)
  1014. {
  1015. VEC_ordered_remove (lst_p, LST_SEQ (loop), i);
  1016. free_lst (l);
  1017. continue;
  1018. }
  1019. i++;
  1020. }
  1021. else
  1022. {
  1023. if (before && LST_PBB (l) != pbb)
  1024. {
  1025. VEC_ordered_remove (lst_p, LST_SEQ (loop), i);
  1026. free_lst (l);
  1027. continue;
  1028. }
  1029. i++;
  1030. if (LST_PBB (l) == pbb)
  1031. before = before ? false : true;
  1032. }
  1033. return before;
  1034. }
  1035. /* A SCOP is a Static Control Part of the program, simple enough to be
  1036. represented in polyhedral form. */
  1037. struct scop
  1038. {
  1039. /* A SCOP is defined as a SESE region. */
  1040. void *region;
  1041. /* Number of parameters in SCoP. */
  1042. graphite_dim_t nb_params;
  1043. /* All the basic blocks in this scop that contain memory references
  1044. and that will be represented as statements in the polyhedral
  1045. representation. */
  1046. VEC (poly_bb_p, heap) *bbs;
  1047. /* Original, transformed and saved schedules. */
  1048. lst_p original_schedule, transformed_schedule, saved_schedule;
  1049. /* The context describes known restrictions concerning the parameters
  1050. and relations in between the parameters.
  1051. void f (int8_t a, uint_16_t b) {
  1052. c = 2 a + b;
  1053. ...
  1054. }
  1055. Here we can add these restrictions to the context:
  1056. -128 >= a >= 127
  1057. 0 >= b >= 65,535
  1058. c = 2a + b */
  1059. isl_set *context;
  1060. /* The context used internally by ISL. */
  1061. isl_ctx *ctx;
  1062. /* The original dependence relations:
  1063. RAW are read after write dependences,
  1064. WAR are write after read dependences,
  1065. WAW are write after write dependences. */
  1066. isl_union_map *must_raw, *may_raw, *must_raw_no_source, *may_raw_no_source,
  1067. *must_war, *may_war, *must_war_no_source, *may_war_no_source,
  1068. *must_waw, *may_waw, *must_waw_no_source, *may_waw_no_source;
  1069. /* A hashtable of the data dependence relations for the original
  1070. scattering. */
  1071. htab_t original_pddrs;
  1072. /* True when the scop has been converted to its polyhedral
  1073. representation. */
  1074. bool poly_scop_p;
  1075. };
  1076. #define SCOP_BBS(S) (S->bbs)
  1077. #define SCOP_REGION(S) ((sese) S->region)
  1078. #define SCOP_CONTEXT(S) (NULL)
  1079. #define SCOP_ORIGINAL_PDDRS(S) (S->original_pddrs)
  1080. #define SCOP_ORIGINAL_SCHEDULE(S) (S->original_schedule)
  1081. #define SCOP_TRANSFORMED_SCHEDULE(S) (S->transformed_schedule)
  1082. #define SCOP_SAVED_SCHEDULE(S) (S->saved_schedule)
  1083. #define POLY_SCOP_P(S) (S->poly_scop_p)
  1084. extern scop_p new_scop (void *);
  1085. extern void free_scop (scop_p);
  1086. extern void free_scops (VEC (scop_p, heap) *);
  1087. extern void print_generated_program (FILE *, scop_p);
  1088. extern void debug_generated_program (scop_p);
  1089. extern void print_scattering_function (FILE *, poly_bb_p, int);
  1090. extern void print_scattering_functions (FILE *, scop_p, int);
  1091. extern void debug_scattering_function (poly_bb_p, int);
  1092. extern void debug_scattering_functions (scop_p, int);
  1093. extern int scop_max_loop_depth (scop_p);
  1094. extern int unify_scattering_dimensions (scop_p);
  1095. extern bool apply_poly_transforms (scop_p);
  1096. extern bool graphite_legal_transform (scop_p);
  1097. extern void cloog_checksum (scop_p);
  1098. /* Set the region of SCOP to REGION. */
  1099. static inline void
  1100. scop_set_region (scop_p scop, void *region)
  1101. {
  1102. scop->region = region;
  1103. }
  1104. /* Returns the number of parameters for SCOP. */
  1105. static inline graphite_dim_t
  1106. scop_nb_params (scop_p scop)
  1107. {
  1108. return scop->nb_params;
  1109. }
  1110. /* Set the number of params of SCOP to NB_PARAMS. */
  1111. static inline void
  1112. scop_set_nb_params (scop_p scop, graphite_dim_t nb_params)
  1113. {
  1114. scop->nb_params = nb_params;
  1115. }
  1116. /* Allocates a new empty poly_scattering structure. */
  1117. static inline poly_scattering_p
  1118. poly_scattering_new (void)
  1119. {
  1120. poly_scattering_p res = XNEW (struct poly_scattering);
  1121. res->nb_local_variables = 0;
  1122. res->nb_scattering = 0;
  1123. return res;
  1124. }
  1125. /* Free a poly_scattering structure. */
  1126. static inline void
  1127. poly_scattering_free (poly_scattering_p s)
  1128. {
  1129. free (s);
  1130. }
  1131. /* Copies S and return a new scattering. */
  1132. static inline poly_scattering_p
  1133. poly_scattering_copy (poly_scattering_p s)
  1134. {
  1135. poly_scattering_p res = poly_scattering_new ();
  1136. res->nb_local_variables = s->nb_local_variables;
  1137. res->nb_scattering = s->nb_scattering;
  1138. return res;
  1139. }
  1140. /* Saves the transformed scattering of PBB. */
  1141. static inline void
  1142. store_scattering_pbb (poly_bb_p pbb)
  1143. {
  1144. isl_map_free (pbb->saved);
  1145. pbb->saved = isl_map_copy (pbb->transformed);
  1146. }
  1147. /* Stores the SCOP_TRANSFORMED_SCHEDULE to SCOP_SAVED_SCHEDULE. */
  1148. static inline void
  1149. store_lst_schedule (scop_p scop)
  1150. {
  1151. if (SCOP_SAVED_SCHEDULE (scop))
  1152. free_lst (SCOP_SAVED_SCHEDULE (scop));
  1153. SCOP_SAVED_SCHEDULE (scop) = copy_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
  1154. }
  1155. /* Restores the SCOP_TRANSFORMED_SCHEDULE from SCOP_SAVED_SCHEDULE. */
  1156. static inline void
  1157. restore_lst_schedule (scop_p scop)
  1158. {
  1159. if (SCOP_TRANSFORMED_SCHEDULE (scop))
  1160. free_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
  1161. SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (SCOP_SAVED_SCHEDULE (scop));
  1162. }
  1163. /* Saves the scattering for all the pbbs in the SCOP. */
  1164. static inline void
  1165. store_scattering (scop_p scop)
  1166. {
  1167. int i;
  1168. poly_bb_p pbb;
  1169. for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
  1170. store_scattering_pbb (pbb);
  1171. store_lst_schedule (scop);
  1172. }
  1173. /* Restores the scattering of PBB. */
  1174. static inline void
  1175. restore_scattering_pbb (poly_bb_p pbb)
  1176. {
  1177. gcc_assert (pbb->saved);
  1178. isl_map_free (pbb->transformed);
  1179. pbb->transformed = isl_map_copy (pbb->saved);
  1180. }
  1181. /* Restores the scattering for all the pbbs in the SCOP. */
  1182. static inline void
  1183. restore_scattering (scop_p scop)
  1184. {
  1185. int i;
  1186. poly_bb_p pbb;
  1187. for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
  1188. restore_scattering_pbb (pbb);
  1189. restore_lst_schedule (scop);
  1190. }
  1191. bool graphite_legal_transform (scop_p);
  1192. poly_bb_p find_pbb_via_hash (htab_t, basic_block);
  1193. bool loop_is_parallel_p (loop_p, htab_t, int);
  1194. scop_p get_loop_body_pbbs (loop_p, htab_t, VEC (poly_bb_p, heap) **);
  1195. isl_map *reverse_loop_at_level (poly_bb_p, int);
  1196. isl_union_map *reverse_loop_for_pbbs (scop_p, VEC (poly_bb_p, heap) *, int);
  1197. __isl_give isl_union_map *extend_schedule (__isl_take isl_union_map *);
  1198. void
  1199. compute_deps (scop_p scop, VEC (poly_bb_p, heap) *pbbs,
  1200. isl_union_map **must_raw,
  1201. isl_union_map **may_raw,
  1202. isl_union_map **must_raw_no_source,
  1203. isl_union_map **may_raw_no_source,
  1204. isl_union_map **must_war,
  1205. isl_union_map **may_war,
  1206. isl_union_map **must_war_no_source,
  1207. isl_union_map **may_war_no_source,
  1208. isl_union_map **must_waw,
  1209. isl_union_map **may_waw,
  1210. isl_union_map **must_waw_no_source,
  1211. isl_union_map **may_waw_no_source);
  1212. #endif