]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/graphite-poly.h
Specify the type of scop->region
[thirdparty/gcc.git] / gcc / graphite-poly.h
1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #ifndef GCC_GRAPHITE_POLY_H
23 #define GCC_GRAPHITE_POLY_H
24
25 #include "sese.h"
26
27 #ifndef HAVE_ISL_OPTIONS_SET_SCHEDULE_SERIALIZE_SCCS
28 # define isl_stat int
29 # define isl_stat_ok 0
30 #endif
31
32 typedef struct poly_dr *poly_dr_p;
33
34 typedef struct poly_bb *poly_bb_p;
35
36 typedef struct scop *scop_p;
37
38 typedef unsigned graphite_dim_t;
39
40 static inline graphite_dim_t pbb_dim_iter_domain (const struct poly_bb *);
41 static inline graphite_dim_t pbb_nb_params (const struct poly_bb *);
42 static inline graphite_dim_t scop_nb_params (scop_p);
43
44 /* A data reference can write or read some memory or we
45 just know it may write some memory. */
46 enum poly_dr_type
47 {
48 PDR_READ,
49 /* PDR_MAY_READs are represented using PDR_READS. This does not
50 limit the expressiveness. */
51 PDR_WRITE,
52 PDR_MAY_WRITE
53 };
54
55 struct poly_dr
56 {
57 /* An identifier for this PDR. */
58 int id;
59
60 /* The number of data refs identical to this one in the PBB. */
61 int nb_refs;
62
63 /* A pointer to compiler's data reference description. */
64 void *compiler_dr;
65
66 /* A pointer to the PBB that contains this data reference. */
67 poly_bb_p pbb;
68
69 enum poly_dr_type type;
70
71 /* The access polyhedron contains the polyhedral space this data
72 reference will access.
73
74 The polyhedron contains these dimensions:
75
76 - The alias set (a):
77 Every memory access is classified in at least one alias set.
78
79 - The subscripts (s_0, ..., s_n):
80 The memory is accessed using zero or more subscript dimensions.
81
82 - The iteration domain (variables and parameters)
83
84 Do not hardcode the dimensions. Use the following accessor functions:
85 - pdr_alias_set_dim
86 - pdr_subscript_dim
87 - pdr_iterator_dim
88 - pdr_parameter_dim
89
90 Example:
91
92 | int A[1335][123];
93 | int *p = malloc ();
94 |
95 | k = ...
96 | for i
97 | {
98 | if (unknown_function ())
99 | p = A;
100 | ... = p[?][?];
101 | for j
102 | A[i][j+k] = m;
103 | }
104
105 The data access A[i][j+k] in alias set "5" is described like this:
106
107 | i j k a s0 s1 1
108 | 0 0 0 1 0 0 -5 = 0
109 |-1 0 0 0 1 0 0 = 0
110 | 0 -1 -1 0 0 1 0 = 0
111 | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
112 | 0 0 0 0 0 1 0 >= 0 # array size.
113 | 0 0 0 0 -1 0 1335 >= 0
114 | 0 0 0 0 0 -1 123 >= 0
115
116 The pointer "*p" in alias set "5" and "7" is described as a union of
117 polyhedron:
118
119
120 | i k a s0 1
121 | 0 0 1 0 -5 = 0
122 | 0 0 0 1 0 >= 0
123
124 "or"
125
126 | i k a s0 1
127 | 0 0 1 0 -7 = 0
128 | 0 0 0 1 0 >= 0
129
130 "*p" accesses all of the object allocated with 'malloc'.
131
132 The scalar data access "m" is represented as an array with zero subscript
133 dimensions.
134
135 | i j k a 1
136 | 0 0 0 -1 15 = 0
137
138 The difference between the graphite internal format for access data and
139 the OpenSop format is in the order of columns.
140 Instead of having:
141
142 | i j k a s0 s1 1
143 | 0 0 0 1 0 0 -5 = 0
144 |-1 0 0 0 1 0 0 = 0
145 | 0 -1 -1 0 0 1 0 = 0
146 | 0 0 0 0 1 0 0 >= 0 # The last four lines describe the
147 | 0 0 0 0 0 1 0 >= 0 # array size.
148 | 0 0 0 0 -1 0 1335 >= 0
149 | 0 0 0 0 0 -1 123 >= 0
150
151 In OpenScop we have:
152
153 | a s0 s1 i j k 1
154 | 1 0 0 0 0 0 -5 = 0
155 | 0 1 0 -1 0 0 0 = 0
156 | 0 0 1 0 -1 -1 0 = 0
157 | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
158 | 0 0 1 0 0 0 0 >= 0 # array size.
159 | 0 -1 0 0 0 0 1335 >= 0
160 | 0 0 -1 0 0 0 123 >= 0
161
162 The OpenScop access function is printed as follows:
163
164 | 1 # The number of disjunct components in a union of access functions.
165 | R C O I L P # Described bellow.
166 | a s0 s1 i j k 1
167 | 1 0 0 0 0 0 -5 = 0
168 | 0 1 0 -1 0 0 0 = 0
169 | 0 0 1 0 -1 -1 0 = 0
170 | 0 1 0 0 0 0 0 >= 0 # The last four lines describe the
171 | 0 0 1 0 0 0 0 >= 0 # array size.
172 | 0 -1 0 0 0 0 1335 >= 0
173 | 0 0 -1 0 0 0 123 >= 0
174
175 Where:
176 - R: Number of rows.
177 - C: Number of columns.
178 - O: Number of output dimensions = alias set + number of subscripts.
179 - I: Number of input dimensions (iterators).
180 - L: Number of local (existentially quantified) dimensions.
181 - P: Number of parameters.
182
183 In the example, the vector "R C O I L P" is "7 7 3 2 0 1". */
184 isl_map *accesses;
185 isl_set *subscript_sizes;
186
187 /* Data reference's base object set number, we must assure 2 pdrs are in the
188 same base object set before dependency checking. */
189 int dr_base_object_set;
190
191 /* The number of subscripts. */
192 graphite_dim_t nb_subscripts;
193 };
194
195 #define PDR_ID(PDR) (PDR->id)
196 #define PDR_NB_REFS(PDR) (PDR->nb_refs)
197 #define PDR_CDR(PDR) (PDR->compiler_dr)
198 #define PDR_PBB(PDR) (PDR->pbb)
199 #define PDR_TYPE(PDR) (PDR->type)
200 #define PDR_ACCESSES(PDR) (NULL)
201 #define PDR_BASE_OBJECT_SET(PDR) (PDR->dr_base_object_set)
202 #define PDR_NB_SUBSCRIPTS(PDR) (PDR->nb_subscripts)
203
204 void new_poly_dr (poly_bb_p, int, enum poly_dr_type, void *,
205 graphite_dim_t, isl_map *, isl_set *);
206 void free_poly_dr (poly_dr_p);
207 void debug_pdr (poly_dr_p, int);
208 void print_pdr (FILE *, poly_dr_p, int);
209 static inline scop_p pdr_scop (poly_dr_p pdr);
210
211 /* The dimension of the iteration domain of the scop of PDR. */
212
213 static inline graphite_dim_t
214 pdr_dim_iter_domain (poly_dr_p pdr)
215 {
216 return pbb_dim_iter_domain (PDR_PBB (pdr));
217 }
218
219 /* The number of parameters of the scop of PDR. */
220
221 static inline graphite_dim_t
222 pdr_nb_params (poly_dr_p pdr)
223 {
224 return scop_nb_params (pdr_scop (pdr));
225 }
226
227 /* The dimension of the alias set in PDR. */
228
229 static inline graphite_dim_t
230 pdr_alias_set_dim (poly_dr_p pdr)
231 {
232 poly_bb_p pbb = PDR_PBB (pdr);
233
234 return pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb);
235 }
236
237 /* The dimension in PDR containing subscript S. */
238
239 static inline graphite_dim_t
240 pdr_subscript_dim (poly_dr_p pdr, graphite_dim_t s)
241 {
242 poly_bb_p pbb = PDR_PBB (pdr);
243
244 return pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb) + 1 + s;
245 }
246
247 /* The dimension in PDR containing the loop iterator ITER. */
248
249 static inline graphite_dim_t
250 pdr_iterator_dim (poly_dr_p pdr ATTRIBUTE_UNUSED, graphite_dim_t iter)
251 {
252 return iter;
253 }
254
255 /* The dimension in PDR containing parameter PARAM. */
256
257 static inline graphite_dim_t
258 pdr_parameter_dim (poly_dr_p pdr, graphite_dim_t param)
259 {
260 poly_bb_p pbb = PDR_PBB (pdr);
261
262 return pbb_dim_iter_domain (pbb) + param;
263 }
264
265 /* Returns true when PDR is a "read". */
266
267 static inline bool
268 pdr_read_p (poly_dr_p pdr)
269 {
270 return PDR_TYPE (pdr) == PDR_READ;
271 }
272
273 /* Returns true when PDR is a "write". */
274
275 static inline bool
276 pdr_write_p (poly_dr_p pdr)
277 {
278 return PDR_TYPE (pdr) == PDR_WRITE;
279 }
280
281 /* Returns true when PDR is a "may write". */
282
283 static inline bool
284 pdr_may_write_p (poly_dr_p pdr)
285 {
286 return PDR_TYPE (pdr) == PDR_MAY_WRITE;
287 }
288
289 /* Return true when PDR1 and PDR2 are similar data accesses: they have
290 the same base array, and the same access functions. */
291
292 static inline bool
293 same_pdr_p (poly_dr_p pdr1, poly_dr_p pdr2)
294 {
295 return PDR_NB_SUBSCRIPTS (pdr1) == PDR_NB_SUBSCRIPTS (pdr2)
296 && PDR_BASE_OBJECT_SET (pdr1) == PDR_BASE_OBJECT_SET (pdr2);
297 }
298
299 typedef struct poly_scattering *poly_scattering_p;
300
301 struct poly_scattering
302 {
303 /* The number of local variables. */
304 int nb_local_variables;
305
306 /* The number of scattering dimensions. */
307 int nb_scattering;
308 };
309
310 /* POLY_BB represents a blackbox in the polyhedral model. */
311
312 struct poly_bb
313 {
314 /* Pointer to a basic block or a statement in the compiler. */
315 void *black_box;
316
317 /* Pointer to the SCOP containing this PBB. */
318 scop_p scop;
319
320 /* The iteration domain of this bb. The layout of this polyhedron
321 is I|G with I the iteration domain, G the context parameters.
322
323 Example:
324
325 for (i = a - 7*b + 8; i <= 3*a + 13*b + 20; i++)
326 for (j = 2; j <= 2*i + 5; j++)
327 for (k = 0; k <= 5; k++)
328 S (i,j,k)
329
330 Loop iterators: i, j, k
331 Parameters: a, b
332
333 | i >= a - 7b + 8
334 | i <= 3a + 13b + 20
335 | j >= 2
336 | j <= 2i + 5
337 | k >= 0
338 | k <= 5
339
340 The number of variables in the DOMAIN may change and is not
341 related to the number of loops in the original code. */
342 isl_set *domain;
343
344 /* The data references we access. */
345 vec<poly_dr_p> drs;
346
347 /* The original scattering. */
348 poly_scattering_p _original;
349 isl_map *schedule;
350
351 /* The transformed scattering. */
352 poly_scattering_p _transformed;
353 isl_map *transformed;
354
355 /* A copy of the transformed scattering. */
356 poly_scattering_p _saved;
357 isl_map *saved;
358
359 /* For tiling, the map for computing the separating class. */
360 isl_map *map_sepclass;
361
362 /* True when this PBB contains only a reduction statement. */
363 bool is_reduction;
364 };
365
366 #define PBB_BLACK_BOX(PBB) ((gimple_bb_p) PBB->black_box)
367 #define PBB_SCOP(PBB) (PBB->scop)
368 #define PBB_DOMAIN(PBB) (NULL)
369 #define PBB_DRS(PBB) (PBB->drs)
370 #define PBB_ORIGINAL(PBB) (PBB->_original)
371 #define PBB_ORIGINAL_SCATTERING(PBB) (NULL)
372 #define PBB_TRANSFORMED(PBB) (PBB->_transformed)
373 #define PBB_TRANSFORMED_SCATTERING(PBB) (NULL)
374 #define PBB_SAVED(PBB) (PBB->_saved)
375 /* XXX isl if we ever need local vars in the scatter, we can't use the
376 out dimension of transformed to count the scatterting transform dimension.
377 */
378 #define PBB_NB_LOCAL_VARIABLES(PBB) (0)
379 #define PBB_NB_SCATTERING_TRANSFORM(PBB) (isl_map_n_out (PBB->transformed))
380 #define PBB_IS_REDUCTION(PBB) (PBB->is_reduction)
381
382 extern poly_bb_p new_poly_bb (scop_p, void *);
383 extern void free_poly_bb (poly_bb_p);
384 extern void debug_loop_vec (poly_bb_p);
385 extern void schedule_to_scattering (poly_bb_p, int);
386 extern void print_pbb_domain (FILE *, poly_bb_p, int);
387 extern void print_pbb (FILE *, poly_bb_p, int);
388 extern void print_scop_context (FILE *, scop_p, int);
389 extern void print_scop (FILE *, scop_p, int);
390 extern void debug_pbb_domain (poly_bb_p, int);
391 extern void debug_pbb (poly_bb_p, int);
392 extern void print_pdrs (FILE *, poly_bb_p, int);
393 extern void debug_pdrs (poly_bb_p, int);
394 extern void debug_scop_context (scop_p, int);
395 extern void debug_scop (scop_p, int);
396 extern void print_scop_params (FILE *, scop_p, int);
397 extern void debug_scop_params (scop_p, int);
398 extern void print_iteration_domain (FILE *, poly_bb_p, int);
399 extern void print_iteration_domains (FILE *, scop_p, int);
400 extern void debug_iteration_domain (poly_bb_p, int);
401 extern void debug_iteration_domains (scop_p, int);
402 extern void print_isl_set (FILE *, isl_set *);
403 extern void print_isl_map (FILE *, isl_map *);
404 extern void print_isl_aff (FILE *, isl_aff *);
405 extern void print_isl_constraint (FILE *, isl_constraint *);
406 extern void debug_isl_set (isl_set *);
407 extern void debug_isl_map (isl_map *);
408 extern void debug_isl_aff (isl_aff *);
409 extern void debug_isl_constraint (isl_constraint *);
410 extern int scop_do_interchange (scop_p);
411 extern int scop_do_strip_mine (scop_p, int);
412 extern bool scop_do_block (scop_p);
413 extern bool flatten_all_loops (scop_p);
414 extern bool optimize_isl (scop_p);
415 extern void pbb_number_of_iterations_at_time (poly_bb_p, graphite_dim_t, mpz_t);
416 extern void debug_gmp_value (mpz_t);
417
418 /* Return the number of write data references in PBB. */
419
420 static inline int
421 number_of_write_pdrs (poly_bb_p pbb)
422 {
423 int res = 0;
424 int i;
425 poly_dr_p pdr;
426
427 for (i = 0; PBB_DRS (pbb).iterate (i, &pdr); i++)
428 if (PDR_TYPE (pdr) == PDR_WRITE)
429 res++;
430
431 return res;
432 }
433
434 /* Returns a gimple_bb from BB. */
435
436 static inline gimple_bb_p
437 gbb_from_bb (basic_block bb)
438 {
439 return (gimple_bb_p) bb->aux;
440 }
441
442 /* The poly_bb of the BB. */
443
444 static inline poly_bb_p
445 pbb_from_bb (basic_block bb)
446 {
447 return GBB_PBB (gbb_from_bb (bb));
448 }
449
450 /* The basic block of the PBB. */
451
452 static inline basic_block
453 pbb_bb (poly_bb_p pbb)
454 {
455 return GBB_BB (PBB_BLACK_BOX (pbb));
456 }
457
458 /* The index of the PBB. */
459
460 static inline int
461 pbb_index (poly_bb_p pbb)
462 {
463 return pbb_bb (pbb)->index;
464 }
465
466 /* The loop of the PBB. */
467
468 static inline loop_p
469 pbb_loop (poly_bb_p pbb)
470 {
471 return gbb_loop (PBB_BLACK_BOX (pbb));
472 }
473
474 /* The scop that contains the PDR. */
475
476 static inline scop_p
477 pdr_scop (poly_dr_p pdr)
478 {
479 return PBB_SCOP (PDR_PBB (pdr));
480 }
481
482 /* Set black box of PBB to BLACKBOX. */
483
484 static inline void
485 pbb_set_black_box (poly_bb_p pbb, void *black_box)
486 {
487 pbb->black_box = black_box;
488 }
489
490 /* The number of loops around PBB: the dimension of the iteration
491 domain. */
492
493 static inline graphite_dim_t
494 pbb_dim_iter_domain (const struct poly_bb *pbb)
495 {
496 return isl_set_dim (pbb->domain, isl_dim_set);
497 }
498
499 /* The number of params defined in PBB. */
500
501 static inline graphite_dim_t
502 pbb_nb_params (const struct poly_bb *pbb)
503 {
504 scop_p scop = PBB_SCOP (pbb);
505
506 return scop_nb_params (scop);
507 }
508
509 /* The number of scattering dimensions in the SCATTERING polyhedron
510 of a PBB for a given SCOP. */
511
512 static inline graphite_dim_t
513 pbb_nb_scattering_orig (const struct poly_bb *pbb)
514 {
515 return 2 * pbb_dim_iter_domain (pbb) + 1;
516 }
517
518 /* The number of scattering dimensions in PBB. */
519
520 static inline graphite_dim_t
521 pbb_nb_scattering_transform (const struct poly_bb *pbb)
522 {
523 return PBB_NB_SCATTERING_TRANSFORM (pbb);
524 }
525
526 /* The number of dynamic scattering dimensions in PBB. */
527
528 static inline graphite_dim_t
529 pbb_nb_dynamic_scattering_transform (const struct poly_bb *pbb)
530 {
531 /* This function requires the 2d + 1 scattering format to be
532 invariant during all transformations. */
533 gcc_assert (PBB_NB_SCATTERING_TRANSFORM (pbb) % 2);
534 return PBB_NB_SCATTERING_TRANSFORM (pbb) / 2;
535 }
536
537 /* Returns the number of local variables used in the transformed
538 scattering polyhedron of PBB. */
539
540 static inline graphite_dim_t
541 pbb_nb_local_vars (const struct poly_bb *pbb ATTRIBUTE_UNUSED)
542 {
543 /* For now we do not have any local variables, as we do not do strip
544 mining for example. */
545 return PBB_NB_LOCAL_VARIABLES (pbb);
546 }
547
548 /* The dimension in the domain of PBB containing the iterator ITER. */
549
550 static inline graphite_dim_t
551 pbb_iterator_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t iter)
552 {
553 return iter;
554 }
555
556 /* The dimension in the domain of PBB containing the iterator ITER. */
557
558 static inline graphite_dim_t
559 pbb_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
560 {
561 return param
562 + pbb_dim_iter_domain (pbb);
563 }
564
565 /* The dimension in the original scattering polyhedron of PBB
566 containing the scattering iterator SCATTER. */
567
568 static inline graphite_dim_t
569 psco_scattering_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t scatter)
570 {
571 gcc_assert (scatter < pbb_nb_scattering_orig (pbb));
572 return scatter;
573 }
574
575 /* The dimension in the transformed scattering polyhedron of PBB
576 containing the scattering iterator SCATTER. */
577
578 static inline graphite_dim_t
579 psct_scattering_dim (poly_bb_p pbb ATTRIBUTE_UNUSED, graphite_dim_t scatter)
580 {
581 gcc_assert (scatter <= pbb_nb_scattering_transform (pbb));
582 return scatter;
583 }
584
585 /* The dimension in the transformed scattering polyhedron of PBB of
586 the local variable LV. */
587
588 static inline graphite_dim_t
589 psct_local_var_dim (poly_bb_p pbb, graphite_dim_t lv)
590 {
591 gcc_assert (lv <= pbb_nb_local_vars (pbb));
592 return lv + pbb_nb_scattering_transform (pbb);
593 }
594
595 /* The dimension in the original scattering polyhedron of PBB
596 containing the loop iterator ITER. */
597
598 static inline graphite_dim_t
599 psco_iterator_dim (poly_bb_p pbb, graphite_dim_t iter)
600 {
601 gcc_assert (iter < pbb_dim_iter_domain (pbb));
602 return iter + pbb_nb_scattering_orig (pbb);
603 }
604
605 /* The dimension in the transformed scattering polyhedron of PBB
606 containing the loop iterator ITER. */
607
608 static inline graphite_dim_t
609 psct_iterator_dim (poly_bb_p pbb, graphite_dim_t iter)
610 {
611 gcc_assert (iter < pbb_dim_iter_domain (pbb));
612 return iter
613 + pbb_nb_scattering_transform (pbb)
614 + pbb_nb_local_vars (pbb);
615 }
616
617 /* The dimension in the original scattering polyhedron of PBB
618 containing parameter PARAM. */
619
620 static inline graphite_dim_t
621 psco_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
622 {
623 gcc_assert (param < pbb_nb_params (pbb));
624 return param
625 + pbb_nb_scattering_orig (pbb)
626 + pbb_dim_iter_domain (pbb);
627 }
628
629 /* The dimension in the transformed scattering polyhedron of PBB
630 containing parameter PARAM. */
631
632 static inline graphite_dim_t
633 psct_parameter_dim (poly_bb_p pbb, graphite_dim_t param)
634 {
635 gcc_assert (param < pbb_nb_params (pbb));
636 return param
637 + pbb_nb_scattering_transform (pbb)
638 + pbb_nb_local_vars (pbb)
639 + pbb_dim_iter_domain (pbb);
640 }
641
642 /* The scattering dimension of PBB corresponding to the dynamic level
643 LEVEL. */
644
645 static inline graphite_dim_t
646 psct_dynamic_dim (poly_bb_p pbb, graphite_dim_t level)
647 {
648 graphite_dim_t result = 1 + 2 * level;
649
650 gcc_assert (result < pbb_nb_scattering_transform (pbb));
651 return result;
652 }
653
654 /* The scattering dimension of PBB corresponding to the static
655 sequence of the loop level LEVEL. */
656
657 static inline graphite_dim_t
658 psct_static_dim (poly_bb_p pbb, graphite_dim_t level)
659 {
660 graphite_dim_t result = 2 * level;
661
662 gcc_assert (result < pbb_nb_scattering_transform (pbb));
663 return result;
664 }
665
666 /* Adds to the transformed scattering polyhedron of PBB a new local
667 variable and returns its index. */
668
669 static inline graphite_dim_t
670 psct_add_local_variable (poly_bb_p pbb ATTRIBUTE_UNUSED)
671 {
672 gcc_unreachable ();
673 return 0;
674 }
675
676 typedef struct lst *lst_p;
677
678 /* Loops and Statements Tree. */
679 struct lst {
680
681 /* LOOP_P is true when an LST node is a loop. */
682 bool loop_p;
683
684 /* A pointer to the loop that contains this node. */
685 lst_p loop_father;
686
687 /* The sum of all the memory strides for an LST loop. */
688 mpz_t memory_strides;
689
690 /* Loop nodes contain a sequence SEQ of LST nodes, statements
691 contain a pointer to their polyhedral representation PBB. */
692 union {
693 poly_bb_p pbb;
694 vec<lst_p> seq;
695 } node;
696 };
697
698 #define LST_LOOP_P(LST) ((LST)->loop_p)
699 #define LST_LOOP_FATHER(LST) ((LST)->loop_father)
700 #define LST_PBB(LST) ((LST)->node.pbb)
701 #define LST_SEQ(LST) ((LST)->node.seq)
702 #define LST_LOOP_MEMORY_STRIDES(LST) ((LST)->memory_strides)
703
704 void scop_to_lst (scop_p);
705 void print_lst (FILE *, lst_p, int);
706 void debug_lst (lst_p);
707 void dot_lst (lst_p);
708
709 /* Creates a new LST loop with SEQ. */
710
711 static inline lst_p
712 new_lst_loop (vec<lst_p> seq)
713 {
714 lst_p lst = XNEW (struct lst);
715 int i;
716 lst_p l;
717
718 LST_LOOP_P (lst) = true;
719 LST_SEQ (lst) = seq;
720 LST_LOOP_FATHER (lst) = NULL;
721 mpz_init (LST_LOOP_MEMORY_STRIDES (lst));
722 mpz_set_si (LST_LOOP_MEMORY_STRIDES (lst), -1);
723
724 for (i = 0; seq.iterate (i, &l); i++)
725 LST_LOOP_FATHER (l) = lst;
726
727 return lst;
728 }
729
730 /* Creates a new LST statement with PBB. */
731
732 static inline lst_p
733 new_lst_stmt (poly_bb_p pbb)
734 {
735 lst_p lst = XNEW (struct lst);
736
737 LST_LOOP_P (lst) = false;
738 LST_PBB (lst) = pbb;
739 LST_LOOP_FATHER (lst) = NULL;
740 return lst;
741 }
742
743 /* Frees the memory used by LST. */
744
745 static inline void
746 free_lst (lst_p lst)
747 {
748 if (!lst)
749 return;
750
751 if (LST_LOOP_P (lst))
752 {
753 int i;
754 lst_p l;
755
756 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
757 free_lst (l);
758
759 mpz_clear (LST_LOOP_MEMORY_STRIDES (lst));
760 LST_SEQ (lst).release ();
761 }
762
763 free (lst);
764 }
765
766 /* Returns a copy of LST. */
767
768 static inline lst_p
769 copy_lst (lst_p lst)
770 {
771 if (!lst)
772 return NULL;
773
774 if (LST_LOOP_P (lst))
775 {
776 int i;
777 lst_p l;
778 vec<lst_p> seq;
779 seq.create (5);
780
781 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
782 seq.safe_push (copy_lst (l));
783
784 return new_lst_loop (seq);
785 }
786
787 return new_lst_stmt (LST_PBB (lst));
788 }
789
790 /* Adds a new loop under the loop LST. */
791
792 static inline void
793 lst_add_loop_under_loop (lst_p lst)
794 {
795 vec<lst_p> seq;
796 seq.create (1);
797 lst_p l = new_lst_loop (LST_SEQ (lst));
798
799 gcc_assert (LST_LOOP_P (lst));
800
801 LST_LOOP_FATHER (l) = lst;
802 seq.quick_push (l);
803 LST_SEQ (lst) = seq;
804 }
805
806 /* Returns the loop depth of LST. */
807
808 static inline int
809 lst_depth (lst_p lst)
810 {
811 if (!lst)
812 return -2;
813
814 /* The depth of the outermost "fake" loop is -1. This outermost
815 loop does not have a loop father and it is just a container, as
816 in the loop representation of GCC. */
817 if (!LST_LOOP_FATHER (lst))
818 return -1;
819
820 return lst_depth (LST_LOOP_FATHER (lst)) + 1;
821 }
822
823 /* Returns the Dewey number for LST. */
824
825 static inline int
826 lst_dewey_number (lst_p lst)
827 {
828 int i;
829 lst_p l;
830
831 if (!lst)
832 return -1;
833
834 if (!LST_LOOP_FATHER (lst))
835 return 0;
836
837 FOR_EACH_VEC_ELT (LST_SEQ (LST_LOOP_FATHER (lst)), i, l)
838 if (l == lst)
839 return i;
840
841 return -1;
842 }
843
844 /* Returns the Dewey number of LST at depth DEPTH. */
845
846 static inline int
847 lst_dewey_number_at_depth (lst_p lst, int depth)
848 {
849 gcc_assert (lst && depth >= 0 && lst_depth (lst) <= depth);
850
851 if (lst_depth (lst) == depth)
852 return lst_dewey_number (lst);
853
854 return lst_dewey_number_at_depth (LST_LOOP_FATHER (lst), depth);
855 }
856
857 /* Returns the predecessor of LST in the sequence of its loop father.
858 Returns NULL if LST is the first statement in the sequence. */
859
860 static inline lst_p
861 lst_pred (lst_p lst)
862 {
863 int dewey;
864 lst_p father;
865
866 if (!lst || !LST_LOOP_FATHER (lst))
867 return NULL;
868
869 dewey = lst_dewey_number (lst);
870 if (dewey == 0)
871 return NULL;
872
873 father = LST_LOOP_FATHER (lst);
874 return LST_SEQ (father)[dewey - 1];
875 }
876
877 /* Returns the successor of LST in the sequence of its loop father.
878 Returns NULL if there is none. */
879
880 static inline lst_p
881 lst_succ (lst_p lst)
882 {
883 int dewey;
884 lst_p father;
885
886 if (!lst || !LST_LOOP_FATHER (lst))
887 return NULL;
888
889 dewey = lst_dewey_number (lst);
890 father = LST_LOOP_FATHER (lst);
891
892 if (LST_SEQ (father).length () == (unsigned) dewey + 1)
893 return NULL;
894
895 return LST_SEQ (father)[dewey + 1];
896 }
897
898
899 /* Return the LST node corresponding to PBB. */
900
901 static inline lst_p
902 lst_find_pbb (lst_p lst, poly_bb_p pbb)
903 {
904 int i;
905 lst_p l;
906
907 if (!lst)
908 return NULL;
909
910 if (!LST_LOOP_P (lst))
911 return (pbb == LST_PBB (lst)) ? lst : NULL;
912
913 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
914 {
915 lst_p res = lst_find_pbb (l, pbb);
916 if (res)
917 return res;
918 }
919
920 return NULL;
921 }
922
923 /* Return the LST node corresponding to the loop around STMT at depth
924 LOOP_DEPTH. */
925
926 static inline lst_p
927 find_lst_loop (lst_p stmt, int loop_depth)
928 {
929 lst_p loop = LST_LOOP_FATHER (stmt);
930
931 gcc_assert (loop_depth >= 0);
932
933 while (loop_depth < lst_depth (loop))
934 loop = LST_LOOP_FATHER (loop);
935
936 return loop;
937 }
938
939 /* Return the first LST representing a PBB statement in LST. */
940
941 static inline lst_p
942 lst_find_first_pbb (lst_p lst)
943 {
944 int i;
945 lst_p l;
946
947 if (!lst)
948 return NULL;
949
950 if (!LST_LOOP_P (lst))
951 return lst;
952
953 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
954 {
955 lst_p res = lst_find_first_pbb (l);
956 if (res)
957 return res;
958 }
959
960 return NULL;
961 }
962
963 /* Returns true when LST is a loop that does not contain
964 statements. */
965
966 static inline bool
967 lst_empty_p (lst_p lst)
968 {
969 return !lst_find_first_pbb (lst);
970 }
971
972 /* Return the last LST representing a PBB statement in LST. */
973
974 static inline lst_p
975 lst_find_last_pbb (lst_p lst)
976 {
977 int i;
978 lst_p l, res = NULL;
979
980 if (!lst)
981 return NULL;
982
983 if (!LST_LOOP_P (lst))
984 return lst;
985
986 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
987 {
988 lst_p last = lst_find_last_pbb (l);
989
990 if (last)
991 res = last;
992 }
993
994 gcc_assert (res);
995 return res;
996 }
997
998 /* Returns true if LOOP contains LST, in other words, if LST is nested
999 in LOOP. */
1000
1001 static inline bool
1002 lst_contains_p (lst_p loop, lst_p lst)
1003 {
1004 if (!loop || !lst || !LST_LOOP_P (loop))
1005 return false;
1006
1007 if (loop == lst)
1008 return true;
1009
1010 return lst_contains_p (loop, LST_LOOP_FATHER (lst));
1011 }
1012
1013 /* Returns true if LOOP contains PBB, in other words, if PBB is nested
1014 in LOOP. */
1015
1016 static inline bool
1017 lst_contains_pbb (lst_p loop, poly_bb_p pbb)
1018 {
1019 return lst_find_pbb (loop, pbb) ? true : false;
1020 }
1021
1022 /* Creates a loop nest of depth NB_LOOPS containing LST. */
1023
1024 static inline lst_p
1025 lst_create_nest (int nb_loops, lst_p lst)
1026 {
1027 lst_p res, loop;
1028 vec<lst_p> seq;
1029
1030 if (nb_loops == 0)
1031 return lst;
1032
1033 seq.create (1);
1034 loop = lst_create_nest (nb_loops - 1, lst);
1035 seq.quick_push (loop);
1036 res = new_lst_loop (seq);
1037 LST_LOOP_FATHER (loop) = res;
1038
1039 return res;
1040 }
1041
1042 /* Removes LST from the sequence of statements of its loop father. */
1043
1044 static inline void
1045 lst_remove_from_sequence (lst_p lst)
1046 {
1047 lst_p father = LST_LOOP_FATHER (lst);
1048 int dewey = lst_dewey_number (lst);
1049
1050 gcc_assert (lst && father && dewey >= 0);
1051
1052 LST_SEQ (father).ordered_remove (dewey);
1053 LST_LOOP_FATHER (lst) = NULL;
1054 }
1055
1056 /* Removes the loop LST and inline its body in the father loop. */
1057
1058 static inline void
1059 lst_remove_loop_and_inline_stmts_in_loop_father (lst_p lst)
1060 {
1061 lst_p l, father = LST_LOOP_FATHER (lst);
1062 int i, dewey = lst_dewey_number (lst);
1063
1064 gcc_assert (lst && father && dewey >= 0);
1065
1066 LST_SEQ (father).ordered_remove (dewey);
1067 LST_LOOP_FATHER (lst) = NULL;
1068
1069 FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l)
1070 {
1071 LST_SEQ (father).safe_insert (dewey + i, l);
1072 LST_LOOP_FATHER (l) = father;
1073 }
1074 }
1075
1076 /* Sets NITER to the upper bound approximation of the number of
1077 iterations of loop LST. */
1078
1079 static inline void
1080 lst_niter_for_loop (lst_p lst, mpz_t niter)
1081 {
1082 int depth = lst_depth (lst);
1083 poly_bb_p pbb = LST_PBB (lst_find_first_pbb (lst));
1084
1085 gcc_assert (LST_LOOP_P (lst));
1086 pbb_number_of_iterations_at_time (pbb, psct_dynamic_dim (pbb, depth), niter);
1087 }
1088
1089 /* Updates the scattering of PBB to be at the DEWEY number in the loop
1090 at depth LEVEL. */
1091
1092 static inline void
1093 pbb_update_scattering (poly_bb_p pbb, graphite_dim_t level, int dewey)
1094 {
1095 graphite_dim_t sched = psct_static_dim (pbb, level);
1096 isl_space *d = isl_map_get_space (pbb->transformed);
1097 isl_space *d1 = isl_space_range (d);
1098 unsigned i, n = isl_space_dim (d1, isl_dim_out);
1099 isl_space *d2 = isl_space_add_dims (d1, isl_dim_in, n);
1100 isl_map *x = isl_map_universe (d2);
1101
1102 x = isl_map_fix_si (x, isl_dim_out, sched, dewey);
1103
1104 for (i = 0; i < n; i++)
1105 if (i != sched)
1106 x = isl_map_equate (x, isl_dim_in, i, isl_dim_out, i);
1107
1108 pbb->transformed = isl_map_apply_range (pbb->transformed, x);
1109 }
1110
1111 /* Updates the scattering of all the PBBs under LST to be at the DEWEY
1112 number in the loop at depth LEVEL. */
1113
1114 static inline void
1115 lst_update_scattering_under (lst_p lst, int level, int dewey)
1116 {
1117 int i;
1118 lst_p l;
1119
1120 gcc_assert (lst && level >= 0 && dewey >= 0);
1121
1122 if (LST_LOOP_P (lst))
1123 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
1124 lst_update_scattering_under (l, level, dewey);
1125 else
1126 pbb_update_scattering (LST_PBB (lst), level, dewey);
1127 }
1128
1129 /* Updates the all the scattering levels of all the PBBs under
1130 LST. */
1131
1132 static inline void
1133 lst_update_scattering (lst_p lst)
1134 {
1135 int i;
1136 lst_p l;
1137
1138 if (!lst)
1139 return;
1140
1141 if (LST_LOOP_FATHER (lst))
1142 {
1143 lst_p father = LST_LOOP_FATHER (lst);
1144 int dewey = lst_dewey_number (lst);
1145 int level = lst_depth (lst);
1146
1147 gcc_assert (lst && father && dewey >= 0 && level >= 0);
1148
1149 for (i = dewey; LST_SEQ (father).iterate (i, &l); i++)
1150 lst_update_scattering_under (l, level, i);
1151 }
1152
1153 if (LST_LOOP_P (lst))
1154 for (i = 0; LST_SEQ (lst).iterate (i, &l); i++)
1155 lst_update_scattering (l);
1156 }
1157
1158 /* Inserts LST1 before LST2 if BEFORE is true; inserts LST1 after LST2
1159 if BEFORE is false. */
1160
1161 static inline void
1162 lst_insert_in_sequence (lst_p lst1, lst_p lst2, bool before)
1163 {
1164 lst_p father;
1165 int dewey;
1166
1167 /* Do not insert empty loops. */
1168 if (!lst1 || lst_empty_p (lst1))
1169 return;
1170
1171 father = LST_LOOP_FATHER (lst2);
1172 dewey = lst_dewey_number (lst2);
1173
1174 gcc_assert (lst2 && father && dewey >= 0);
1175
1176 LST_SEQ (father).safe_insert (before ? dewey : dewey + 1, lst1);
1177 LST_LOOP_FATHER (lst1) = father;
1178 }
1179
1180 /* Replaces LST1 with LST2. */
1181
1182 static inline void
1183 lst_replace (lst_p lst1, lst_p lst2)
1184 {
1185 lst_p father;
1186 int dewey;
1187
1188 if (!lst2 || lst_empty_p (lst2))
1189 return;
1190
1191 father = LST_LOOP_FATHER (lst1);
1192 dewey = lst_dewey_number (lst1);
1193 LST_LOOP_FATHER (lst2) = father;
1194 LST_SEQ (father)[dewey] = lst2;
1195 }
1196
1197 /* Returns a copy of ROOT where LST has been replaced by a copy of the
1198 LSTs A B C in this sequence. */
1199
1200 static inline lst_p
1201 lst_substitute_3 (lst_p root, lst_p lst, lst_p a, lst_p b, lst_p c)
1202 {
1203 int i;
1204 lst_p l;
1205 vec<lst_p> seq;
1206
1207 if (!root)
1208 return NULL;
1209
1210 gcc_assert (lst && root != lst);
1211
1212 if (!LST_LOOP_P (root))
1213 return new_lst_stmt (LST_PBB (root));
1214
1215 seq.create (5);
1216
1217 for (i = 0; LST_SEQ (root).iterate (i, &l); i++)
1218 if (l != lst)
1219 seq.safe_push (lst_substitute_3 (l, lst, a, b, c));
1220 else
1221 {
1222 if (!lst_empty_p (a))
1223 seq.safe_push (copy_lst (a));
1224 if (!lst_empty_p (b))
1225 seq.safe_push (copy_lst (b));
1226 if (!lst_empty_p (c))
1227 seq.safe_push (copy_lst (c));
1228 }
1229
1230 return new_lst_loop (seq);
1231 }
1232
1233 /* Moves LST before LOOP if BEFORE is true, and after the LOOP if
1234 BEFORE is false. */
1235
1236 static inline void
1237 lst_distribute_lst (lst_p loop, lst_p lst, bool before)
1238 {
1239 int loop_depth = lst_depth (loop);
1240 int depth = lst_depth (lst);
1241 int nb_loops = depth - loop_depth;
1242
1243 gcc_assert (lst && loop && LST_LOOP_P (loop) && nb_loops > 0);
1244
1245 lst_remove_from_sequence (lst);
1246 lst_insert_in_sequence (lst_create_nest (nb_loops, lst), loop, before);
1247 }
1248
1249 /* Removes from LOOP all the statements before/after and including PBB
1250 if BEFORE is true/false. Returns the negation of BEFORE when the
1251 statement PBB has been found. */
1252
1253 static inline bool
1254 lst_remove_all_before_including_pbb (lst_p loop, poly_bb_p pbb, bool before)
1255 {
1256 int i;
1257 lst_p l;
1258
1259 if (!loop || !LST_LOOP_P (loop))
1260 return before;
1261
1262 for (i = 0; LST_SEQ (loop).iterate (i, &l);)
1263 if (LST_LOOP_P (l))
1264 {
1265 before = lst_remove_all_before_including_pbb (l, pbb, before);
1266
1267 if (LST_SEQ (l).length () == 0)
1268 {
1269 LST_SEQ (loop).ordered_remove (i);
1270 free_lst (l);
1271 }
1272 else
1273 i++;
1274 }
1275 else
1276 {
1277 if (before)
1278 {
1279 if (LST_PBB (l) == pbb)
1280 before = false;
1281
1282 LST_SEQ (loop).ordered_remove (i);
1283 free_lst (l);
1284 }
1285 else if (LST_PBB (l) == pbb)
1286 {
1287 before = true;
1288 LST_SEQ (loop).ordered_remove (i);
1289 free_lst (l);
1290 }
1291 else
1292 i++;
1293 }
1294
1295 return before;
1296 }
1297
1298 /* Removes from LOOP all the statements before/after and excluding PBB
1299 if BEFORE is true/false; Returns the negation of BEFORE when the
1300 statement PBB has been found. */
1301
1302 static inline bool
1303 lst_remove_all_before_excluding_pbb (lst_p loop, poly_bb_p pbb, bool before)
1304 {
1305 int i;
1306 lst_p l;
1307
1308 if (!loop || !LST_LOOP_P (loop))
1309 return before;
1310
1311 for (i = 0; LST_SEQ (loop).iterate (i, &l);)
1312 if (LST_LOOP_P (l))
1313 {
1314 before = lst_remove_all_before_excluding_pbb (l, pbb, before);
1315
1316 if (LST_SEQ (l).length () == 0)
1317 {
1318 LST_SEQ (loop).ordered_remove (i);
1319 free_lst (l);
1320 continue;
1321 }
1322
1323 i++;
1324 }
1325 else
1326 {
1327 if (before && LST_PBB (l) != pbb)
1328 {
1329 LST_SEQ (loop).ordered_remove (i);
1330 free_lst (l);
1331 continue;
1332 }
1333
1334 i++;
1335
1336 if (LST_PBB (l) == pbb)
1337 before = before ? false : true;
1338 }
1339
1340 return before;
1341 }
1342
1343 /* A SCOP is a Static Control Part of the program, simple enough to be
1344 represented in polyhedral form. */
1345 struct scop
1346 {
1347 /* A SCOP is defined as a SESE region. */
1348 sese region;
1349
1350 /* Number of parameters in SCoP. */
1351 graphite_dim_t nb_params;
1352
1353 /* All the basic blocks in this scop that contain memory references
1354 and that will be represented as statements in the polyhedral
1355 representation. */
1356 vec<poly_bb_p> bbs;
1357
1358 /* Original, transformed and saved schedules. */
1359 lst_p original_schedule, transformed_schedule, saved_schedule;
1360
1361 /* The context describes known restrictions concerning the parameters
1362 and relations in between the parameters.
1363
1364 void f (int8_t a, uint_16_t b) {
1365 c = 2 a + b;
1366 ...
1367 }
1368
1369 Here we can add these restrictions to the context:
1370
1371 -128 >= a >= 127
1372 0 >= b >= 65,535
1373 c = 2a + b */
1374 isl_set *context;
1375
1376 /* The context used internally by ISL. */
1377 isl_ctx *ctx;
1378
1379 /* The original dependence relations:
1380 RAW are read after write dependences,
1381 WAR are write after read dependences,
1382 WAW are write after write dependences. */
1383 isl_union_map *must_raw, *may_raw, *must_raw_no_source, *may_raw_no_source,
1384 *must_war, *may_war, *must_war_no_source, *may_war_no_source,
1385 *must_waw, *may_waw, *must_waw_no_source, *may_waw_no_source;
1386
1387 /* True when the scop has been converted to its polyhedral
1388 representation. */
1389 bool poly_scop_p;
1390 };
1391
1392 #define SCOP_BBS(S) (S->bbs)
1393 #define SCOP_REGION(S) (S->region)
1394 #define SCOP_CONTEXT(S) (NULL)
1395 #define SCOP_ORIGINAL_SCHEDULE(S) (S->original_schedule)
1396 #define SCOP_TRANSFORMED_SCHEDULE(S) (S->transformed_schedule)
1397 #define SCOP_SAVED_SCHEDULE(S) (S->saved_schedule)
1398 #define POLY_SCOP_P(S) (S->poly_scop_p)
1399
1400 extern scop_p new_scop (sese);
1401 extern void free_scop (scop_p);
1402 extern void free_scops (vec<scop_p> );
1403 extern void print_generated_program (FILE *, scop_p);
1404 extern void debug_generated_program (scop_p);
1405 extern void print_scattering_function (FILE *, poly_bb_p, int);
1406 extern void print_scattering_functions (FILE *, scop_p, int);
1407 extern void debug_scattering_function (poly_bb_p, int);
1408 extern void debug_scattering_functions (scop_p, int);
1409 extern int scop_max_loop_depth (scop_p);
1410 extern int unify_scattering_dimensions (scop_p);
1411 extern bool apply_poly_transforms (scop_p);
1412 extern bool graphite_legal_transform (scop_p);
1413
1414 /* Set the region of SCOP to REGION. */
1415
1416 static inline void
1417 scop_set_region (scop_p scop, sese region)
1418 {
1419 scop->region = region;
1420 }
1421
1422 /* Returns the number of parameters for SCOP. */
1423
1424 static inline graphite_dim_t
1425 scop_nb_params (scop_p scop)
1426 {
1427 return scop->nb_params;
1428 }
1429
1430 /* Set the number of params of SCOP to NB_PARAMS. */
1431
1432 static inline void
1433 scop_set_nb_params (scop_p scop, graphite_dim_t nb_params)
1434 {
1435 scop->nb_params = nb_params;
1436 }
1437
1438 /* Allocates a new empty poly_scattering structure. */
1439
1440 static inline poly_scattering_p
1441 poly_scattering_new (void)
1442 {
1443 poly_scattering_p res = XNEW (struct poly_scattering);
1444
1445 res->nb_local_variables = 0;
1446 res->nb_scattering = 0;
1447 return res;
1448 }
1449
1450 /* Free a poly_scattering structure. */
1451
1452 static inline void
1453 poly_scattering_free (poly_scattering_p s)
1454 {
1455 free (s);
1456 }
1457
1458 /* Copies S and return a new scattering. */
1459
1460 static inline poly_scattering_p
1461 poly_scattering_copy (poly_scattering_p s)
1462 {
1463 poly_scattering_p res = poly_scattering_new ();
1464
1465 res->nb_local_variables = s->nb_local_variables;
1466 res->nb_scattering = s->nb_scattering;
1467 return res;
1468 }
1469
1470 /* Saves the transformed scattering of PBB. */
1471
1472 static inline void
1473 store_scattering_pbb (poly_bb_p pbb)
1474 {
1475 isl_map_free (pbb->saved);
1476 pbb->saved = isl_map_copy (pbb->transformed);
1477 }
1478
1479 /* Stores the SCOP_TRANSFORMED_SCHEDULE to SCOP_SAVED_SCHEDULE. */
1480
1481 static inline void
1482 store_lst_schedule (scop_p scop)
1483 {
1484 if (SCOP_SAVED_SCHEDULE (scop))
1485 free_lst (SCOP_SAVED_SCHEDULE (scop));
1486
1487 SCOP_SAVED_SCHEDULE (scop) = copy_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
1488 }
1489
1490 /* Restores the SCOP_TRANSFORMED_SCHEDULE from SCOP_SAVED_SCHEDULE. */
1491
1492 static inline void
1493 restore_lst_schedule (scop_p scop)
1494 {
1495 if (SCOP_TRANSFORMED_SCHEDULE (scop))
1496 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
1497
1498 SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (SCOP_SAVED_SCHEDULE (scop));
1499 }
1500
1501 /* Saves the scattering for all the pbbs in the SCOP. */
1502
1503 static inline void
1504 store_scattering (scop_p scop)
1505 {
1506 int i;
1507 poly_bb_p pbb;
1508
1509 for (i = 0; SCOP_BBS (scop).iterate (i, &pbb); i++)
1510 store_scattering_pbb (pbb);
1511
1512 store_lst_schedule (scop);
1513 }
1514
1515 /* Restores the scattering of PBB. */
1516
1517 static inline void
1518 restore_scattering_pbb (poly_bb_p pbb)
1519 {
1520 gcc_assert (pbb->saved);
1521
1522 isl_map_free (pbb->transformed);
1523 pbb->transformed = isl_map_copy (pbb->saved);
1524 }
1525
1526 /* Restores the scattering for all the pbbs in the SCOP. */
1527
1528 static inline void
1529 restore_scattering (scop_p scop)
1530 {
1531 int i;
1532 poly_bb_p pbb;
1533
1534 for (i = 0; SCOP_BBS (scop).iterate (i, &pbb); i++)
1535 restore_scattering_pbb (pbb);
1536
1537 restore_lst_schedule (scop);
1538 }
1539
1540 bool graphite_legal_transform (scop_p);
1541 isl_map *reverse_loop_at_level (poly_bb_p, int);
1542 isl_union_map *reverse_loop_for_pbbs (scop_p, vec<poly_bb_p> , int);
1543 __isl_give isl_union_map *extend_schedule (__isl_take isl_union_map *);
1544
1545
1546 void
1547 compute_deps (scop_p scop, vec<poly_bb_p> pbbs,
1548 isl_union_map **must_raw,
1549 isl_union_map **may_raw,
1550 isl_union_map **must_raw_no_source,
1551 isl_union_map **may_raw_no_source,
1552 isl_union_map **must_war,
1553 isl_union_map **may_war,
1554 isl_union_map **must_war_no_source,
1555 isl_union_map **may_war_no_source,
1556 isl_union_map **must_waw,
1557 isl_union_map **may_waw,
1558 isl_union_map **must_waw_no_source,
1559 isl_union_map **may_waw_no_source);
1560
1561 isl_union_map *
1562 scop_get_dependences (scop_p scop);
1563
1564 bool
1565 carries_deps (__isl_keep isl_union_map *schedule,
1566 __isl_keep isl_union_map *deps,
1567 int depth);
1568
1569 #endif