1 /* Data dependence analysis for Graphite.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Konrad Trifunovic <konrad.trifunovic@inria.fr>.
6 This file is part of GCC.
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)
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.
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/>. */
24 #include "coretypes.h"
29 #include "basic-block.h"
30 #include "diagnostic.h"
31 #include "tree-flow.h"
33 #include "tree-dump.h"
36 #include "tree-chrec.h"
37 #include "tree-data-ref.h"
38 #include "tree-scalar-evolution.h"
39 #include "tree-pass.h"
41 #include "pointer-set.h"
45 #include "cloog/cloog.h"
48 #include "graphite-ppl.h"
50 #include "graphite-poly.h"
51 #include "graphite-dependences.h"
53 /* Returns a new polyhedral Data Dependence Relation (DDR). SOURCE is
54 the source data reference, SINK is the sink data reference. SOURCE
55 and SINK define an edge in the Data Dependence Graph (DDG). */
58 new_poly_ddr (poly_dr_p source, poly_dr_p sink,
59 ppl_Pointset_Powerset_C_Polyhedron_t ddp)
63 pddr = XNEW (struct poly_ddr);
64 PDDR_SOURCE (pddr) = source;
65 PDDR_SINK (pddr) = sink;
66 PDDR_DDP (pddr) = ddp;
67 PDDR_KIND (pddr) = unknown_dependence;
72 /* Free the poly_ddr_p P. */
75 free_poly_ddr (void *p)
77 poly_ddr_p pddr = (poly_ddr_p) p;
78 ppl_delete_Pointset_Powerset_C_Polyhedron (PDDR_DDP (pddr));
82 /* Comparison function for poly_ddr hash table. */
85 eq_poly_ddr_p (const void *pddr1, const void *pddr2)
87 const struct poly_ddr *p1 = (const struct poly_ddr *) pddr1;
88 const struct poly_ddr *p2 = (const struct poly_ddr *) pddr2;
90 return (PDDR_SOURCE (p1) == PDDR_SOURCE (p2)
91 && PDDR_SINK (p1) == PDDR_SINK (p2));
94 /* Hash function for poly_ddr hashtable. */
97 hash_poly_ddr_p (const void *pddr)
99 const struct poly_ddr *p = (const struct poly_ddr *) pddr;
101 return (hashval_t) ((long) PDDR_SOURCE (p) + (long) PDDR_SINK (p));
104 /* Returns true when PDDR has no dependence. */
107 pddr_is_empty (poly_ddr_p pddr)
109 if (PDDR_KIND (pddr) != unknown_dependence)
110 return PDDR_KIND (pddr) == no_dependence ? true : false;
112 if (ppl_Pointset_Powerset_C_Polyhedron_is_empty (PDDR_DDP (pddr)))
114 PDDR_KIND (pddr) = no_dependence;
118 PDDR_KIND (pddr) = has_dependence;
122 /* Returns a polyhedron of dimension DIM.
124 Maps the dimensions [0, ..., cut - 1] of polyhedron P to OFFSET
125 and the dimensions [cut, ..., nb_dim] to DIM - GDIM. */
127 static ppl_Pointset_Powerset_C_Polyhedron_t
128 map_into_dep_poly (graphite_dim_t dim, graphite_dim_t gdim,
129 ppl_Pointset_Powerset_C_Polyhedron_t p,
131 graphite_dim_t offset)
133 ppl_Pointset_Powerset_C_Polyhedron_t res;
135 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
137 ppl_insert_dimensions_pointset (res, 0, offset);
138 ppl_insert_dimensions_pointset (res, offset + cut,
139 dim - offset - cut - gdim);
144 /* Swap [cut0, ..., cut1] to the end of DR: "a CUT0 b CUT1 c" is
145 transformed into "a CUT0 c CUT1' b"
147 Add NB0 zeros before "a": "00...0 a CUT0 c CUT1' b"
148 Add NB1 zeros between "a" and "c": "00...0 a 00...0 c CUT1' b"
149 Add DIM - NB0 - NB1 - PDIM zeros between "c" and "b":
150 "00...0 a 00...0 c 00...0 b". */
152 static ppl_Pointset_Powerset_C_Polyhedron_t
153 map_dr_into_dep_poly (graphite_dim_t dim,
154 ppl_Pointset_Powerset_C_Polyhedron_t dr,
155 graphite_dim_t cut0, graphite_dim_t cut1,
156 graphite_dim_t nb0, graphite_dim_t nb1)
158 ppl_dimension_type pdim;
159 ppl_dimension_type *map;
160 ppl_Pointset_Powerset_C_Polyhedron_t res;
161 ppl_dimension_type i;
163 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
165 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (res, &pdim);
167 map = (ppl_dimension_type *) XNEWVEC (ppl_dimension_type, pdim);
169 /* First mapping: move 'g' vector to right position. */
170 for (i = 0; i < cut0; i++)
173 for (i = cut0; i < cut1; i++)
174 map[i] = pdim - cut1 + i;
176 for (i = cut1; i < pdim; i++)
177 map[i] = cut0 + i - cut1;
179 ppl_Pointset_Powerset_C_Polyhedron_map_space_dimensions (res, map, pdim);
182 /* After swapping 's' and 'g' vectors, we have to update a new cut. */
183 cut1 = pdim - cut1 + cut0;
185 ppl_insert_dimensions_pointset (res, 0, nb0);
186 ppl_insert_dimensions_pointset (res, nb0 + cut0, nb1);
187 ppl_insert_dimensions_pointset (res, nb0 + nb1 + cut1,
188 dim - nb0 - nb1 - pdim);
193 /* Builds subscript equality constraints. */
195 static ppl_Pointset_Powerset_C_Polyhedron_t
196 dr_equality_constraints (graphite_dim_t dim,
197 graphite_dim_t pos, graphite_dim_t nb_subscripts)
199 ppl_Polyhedron_t eqs;
200 ppl_Pointset_Powerset_C_Polyhedron_t res;
203 ppl_new_C_Polyhedron_from_space_dimension (&eqs, dim, 0);
205 for (i = 0; i < nb_subscripts; i++)
207 ppl_Constraint_t cstr
208 = ppl_build_relation (dim, pos + i, pos + i + nb_subscripts,
209 0, PPL_CONSTRAINT_TYPE_EQUAL);
210 ppl_Polyhedron_add_constraint (eqs, cstr);
211 ppl_delete_Constraint (cstr);
214 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&res, eqs);
215 ppl_delete_Polyhedron (eqs);
219 /* Builds scheduling inequality constraints: when DIRECTION is
220 1 builds a GE constraint,
221 0 builds an EQ constraint,
222 -1 builds a LE constraint. */
224 static ppl_Pointset_Powerset_C_Polyhedron_t
225 build_pairwise_scheduling (graphite_dim_t dim,
227 graphite_dim_t offset,
230 ppl_Pointset_Powerset_C_Polyhedron_t res;
231 ppl_Polyhedron_t equalities;
232 ppl_Constraint_t cstr;
234 ppl_new_C_Polyhedron_from_space_dimension (&equalities, dim, 0);
239 cstr = ppl_build_relation (dim, pos, pos + offset, 1,
240 PPL_CONSTRAINT_TYPE_LESS_OR_EQUAL);
244 cstr = ppl_build_relation (dim, pos, pos + offset, 0,
245 PPL_CONSTRAINT_TYPE_EQUAL);
249 cstr = ppl_build_relation (dim, pos, pos + offset, -1,
250 PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL);
257 ppl_Polyhedron_add_constraint (equalities, cstr);
258 ppl_delete_Constraint (cstr);
260 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&res, equalities);
261 ppl_delete_Polyhedron (equalities);
265 /* Returns true when adding to the RES dependence polyhedron the
266 lexicographical constraint: "DIM compared to DIM + OFFSET" returns
267 an empty polyhedron. The comparison depends on DIRECTION as: if
268 DIRECTION is equal to -1, the first dimension DIM to be compared
269 comes before the second dimension DIM + OFFSET, equal to 0 when DIM
270 and DIM + OFFSET are equal, and DIRECTION is set to 1 when DIM
271 comes after DIM + OFFSET. */
274 lexicographically_gt_p (ppl_Pointset_Powerset_C_Polyhedron_t res,
276 graphite_dim_t offset,
277 int direction, graphite_dim_t i)
279 ppl_Pointset_Powerset_C_Polyhedron_t ineq;
282 ineq = build_pairwise_scheduling (dim, i, offset, direction);
283 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (ineq, res);
284 empty_p = ppl_Pointset_Powerset_C_Polyhedron_is_empty (ineq);
286 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, ineq);
287 ppl_delete_Pointset_Powerset_C_Polyhedron (ineq);
292 /* Add to a non empty polyhedron RES the precedence constraints for
293 the lexicographical comparison of time vectors in RES following the
294 lexicographical order. DIM is the dimension of the polyhedron RES.
295 TDIM is the number of loops common to the two statements that are
296 compared lexicographically, i.e. the number of loops containing
297 both statements. OFFSET is the number of dimensions needed to
298 represent the first statement, i.e. dimT1 + dimI1 in the layout of
299 the RES polyhedron: T1|I1|T2|I2|S1|S2|G. When DIRECTION is set to
300 1, compute the direct dependence from PDR1 to PDR2, and when
301 DIRECTION is -1, compute the reversed dependence relation, from
305 build_lexicographically_gt_constraint (ppl_Pointset_Powerset_C_Polyhedron_t *res,
308 graphite_dim_t offset,
313 if (lexicographically_gt_p (*res, dim, offset, direction, 0))
316 for (i = 0; i < tdim - 1; i++)
318 ppl_Pointset_Powerset_C_Polyhedron_t sceq;
320 /* All the dimensions up to I are equal, ... */
321 sceq = build_pairwise_scheduling (dim, i, offset, 0);
322 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (*res, sceq);
323 ppl_delete_Pointset_Powerset_C_Polyhedron (sceq);
325 /* ... and at depth I+1 they are not equal anymore. */
326 if (lexicographically_gt_p (*res, dim, offset, direction, i + 1))
332 ppl_delete_Pointset_Powerset_C_Polyhedron (*res);
333 ppl_new_Pointset_Powerset_C_Polyhedron_from_space_dimension (res, dim, 1);
337 /* Build the dependence polyhedron for data references PDR1 and PDR2.
338 The layout of the dependence polyhedron is:
343 | T1 and T2 the scattering dimensions for PDR1 and PDR2
344 | I1 and I2 the iteration domains
345 | S1 and S2 the subscripts
346 | G the global parameters.
348 D1 and D2 are the iteration domains of PDR1 and PDR2.
350 SCAT1 and SCAT2 are the scattering polyhedra for PDR1 and PDR2.
351 When ORIGINAL_SCATTERING_P is true, then the scattering polyhedra
352 SCAT1 and SCAT2 correspond to the original scattering of the
353 program, otherwise they correspond to the transformed scattering.
355 When DIRECTION is set to 1, compute the direct dependence from PDR1
356 to PDR2, and when DIRECTION is -1, compute the reversed dependence
357 relation, from PDR2 to PDR1. */
360 dependence_polyhedron_1 (poly_bb_p pbb1, poly_bb_p pbb2,
361 ppl_Pointset_Powerset_C_Polyhedron_t d1,
362 ppl_Pointset_Powerset_C_Polyhedron_t d2,
363 poly_dr_p pdr1, poly_dr_p pdr2,
364 ppl_Polyhedron_t scat1, ppl_Polyhedron_t scat2,
366 bool original_scattering_p)
368 scop_p scop = PBB_SCOP (pbb1);
369 graphite_dim_t tdim1 = original_scattering_p ?
370 pbb_nb_scattering_orig (pbb1) : pbb_nb_scattering_transform (pbb1);
371 graphite_dim_t tdim2 = original_scattering_p ?
372 pbb_nb_scattering_orig (pbb2) : pbb_nb_scattering_transform (pbb2);
373 graphite_dim_t ddim1 = pbb_dim_iter_domain (pbb1);
374 graphite_dim_t ddim2 = pbb_dim_iter_domain (pbb2);
375 graphite_dim_t sdim1 = PDR_NB_SUBSCRIPTS (pdr1) + 1;
376 graphite_dim_t gdim = scop_nb_params (scop);
377 graphite_dim_t dim1 = pdr_dim (pdr1);
378 graphite_dim_t dim2 = pdr_dim (pdr2);
379 graphite_dim_t dim = tdim1 + tdim2 + dim1 + dim2 - gdim;
380 ppl_Pointset_Powerset_C_Polyhedron_t res;
381 ppl_Pointset_Powerset_C_Polyhedron_t id1, id2, isc1, isc2, idr1, idr2;
382 ppl_Pointset_Powerset_C_Polyhedron_t sc1, sc2, dreq;
383 ppl_Pointset_Powerset_C_Polyhedron_t context;
385 gcc_assert (PBB_SCOP (pbb1) == PBB_SCOP (pbb2));
387 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
388 (&context, SCOP_CONTEXT (scop));
389 ppl_insert_dimensions_pointset (context, 0, dim - gdim);
391 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sc1, scat1);
392 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sc2, scat2);
394 id1 = map_into_dep_poly (dim, gdim, d1, ddim1, tdim1);
395 id2 = map_into_dep_poly (dim, gdim, d2, ddim2, tdim1 + ddim1 + tdim2);
396 isc1 = map_into_dep_poly (dim, gdim, sc1, ddim1 + tdim1, 0);
397 isc2 = map_into_dep_poly (dim, gdim, sc2, ddim2 + tdim2, tdim1 + ddim1);
399 idr1 = map_dr_into_dep_poly (dim, PDR_ACCESSES (pdr1), ddim1, ddim1 + gdim,
400 tdim1, tdim2 + ddim2);
401 idr2 = map_dr_into_dep_poly (dim, PDR_ACCESSES (pdr2), ddim2, ddim2 + gdim,
402 tdim1 + ddim1 + tdim2, sdim1);
404 /* Now add the subscript equalities. */
405 dreq = dr_equality_constraints (dim, tdim1 + ddim1 + tdim2 + ddim2, sdim1);
407 ppl_new_Pointset_Powerset_C_Polyhedron_from_space_dimension (&res, dim, 0);
408 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, context);
409 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, id1);
410 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, id2);
411 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, isc1);
412 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, isc2);
413 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, idr1);
414 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, idr2);
415 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (res, dreq);
416 ppl_delete_Pointset_Powerset_C_Polyhedron (context);
417 ppl_delete_Pointset_Powerset_C_Polyhedron (id1);
418 ppl_delete_Pointset_Powerset_C_Polyhedron (id2);
419 ppl_delete_Pointset_Powerset_C_Polyhedron (sc1);
420 ppl_delete_Pointset_Powerset_C_Polyhedron (sc2);
421 ppl_delete_Pointset_Powerset_C_Polyhedron (isc1);
422 ppl_delete_Pointset_Powerset_C_Polyhedron (isc2);
423 ppl_delete_Pointset_Powerset_C_Polyhedron (idr1);
424 ppl_delete_Pointset_Powerset_C_Polyhedron (idr2);
425 ppl_delete_Pointset_Powerset_C_Polyhedron (dreq);
427 if (!ppl_Pointset_Powerset_C_Polyhedron_is_empty (res))
428 build_lexicographically_gt_constraint (&res, dim, MIN (tdim1, tdim2),
429 tdim1 + ddim1, direction);
431 return new_poly_ddr (pdr1, pdr2, res);
434 /* Build the dependence polyhedron for data references PDR1 and PDR2.
435 If possible use already cached information.
437 D1 and D2 are the iteration domains of PDR1 and PDR2.
439 SCAT1 and SCAT2 are the scattering polyhedra for PDR1 and PDR2.
440 When ORIGINAL_SCATTERING_P is true, then the scattering polyhedra
441 SCAT1 and SCAT2 correspond to the original scattering of the
442 program, otherwise they correspond to the transformed scattering.
444 When DIRECTION is set to 1, compute the direct dependence from PDR1
445 to PDR2, and when DIRECTION is -1, compute the reversed dependence
446 relation, from PDR2 to PDR1. */
449 dependence_polyhedron (poly_bb_p pbb1, poly_bb_p pbb2,
450 ppl_Pointset_Powerset_C_Polyhedron_t d1,
451 ppl_Pointset_Powerset_C_Polyhedron_t d2,
452 poly_dr_p pdr1, poly_dr_p pdr2,
453 ppl_Polyhedron_t scat1, ppl_Polyhedron_t scat2,
455 bool original_scattering_p)
460 if (original_scattering_p)
466 x = htab_find_slot (SCOP_ORIGINAL_PDDRS (PBB_SCOP (pbb1)),
470 return (poly_ddr_p) *x;
473 res = dependence_polyhedron_1 (pbb1, pbb2, d1, d2, pdr1, pdr2,
474 scat1, scat2, direction, original_scattering_p);
476 if (original_scattering_p)
482 /* Returns the Polyhedral Data Dependence Relation (PDDR) between PDR1
483 contained in PBB1 and PDR2 contained in PBB2. When
484 ORIGINAL_SCATTERING_P is true, return the PDDR corresponding to the
485 original scattering, or NULL if the dependence relation is empty.
486 When ORIGINAL_SCATTERING_P is false, return the PDDR corresponding
487 to the transformed scattering. When DIRECTION is set to 1, compute
488 the direct dependence from PDR1 to PDR2, and when DIRECTION is -1,
489 compute the reversed dependence relation, from PDR2 to PDR1. */
492 build_pddr (poly_bb_p pbb1, poly_bb_p pbb2, poly_dr_p pdr1, poly_dr_p pdr2,
493 int direction, bool original_scattering_p)
496 ppl_Pointset_Powerset_C_Polyhedron_t d1 = PBB_DOMAIN (pbb1);
497 ppl_Pointset_Powerset_C_Polyhedron_t d2 = PBB_DOMAIN (pbb2);
498 ppl_Polyhedron_t scat1 = original_scattering_p ?
499 PBB_ORIGINAL_SCATTERING (pbb1) : PBB_TRANSFORMED_SCATTERING (pbb1);
500 ppl_Polyhedron_t scat2 = original_scattering_p ?
501 PBB_ORIGINAL_SCATTERING (pbb2) : PBB_TRANSFORMED_SCATTERING (pbb2);
503 if ((pdr_read_p (pdr1) && pdr_read_p (pdr2))
504 || PDR_BASE_OBJECT_SET (pdr1) != PDR_BASE_OBJECT_SET (pdr2)
505 || PDR_NB_SUBSCRIPTS (pdr1) != PDR_NB_SUBSCRIPTS (pdr2))
508 pddr = dependence_polyhedron (pbb1, pbb2, d1, d2, pdr1, pdr2, scat1, scat2,
509 direction, original_scattering_p);
510 if (pddr_is_empty (pddr))
516 /* Return true when the data dependence relation between the data
517 references PDR1 belonging to PBB1 and PDR2 is part of a
521 reduction_dr_1 (poly_bb_p pbb1, poly_dr_p pdr1, poly_dr_p pdr2)
526 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), i, pdr); i++)
527 if (PDR_TYPE (pdr) == PDR_WRITE)
530 return same_pdr_p (pdr, pdr1) && same_pdr_p (pdr, pdr2);
533 /* Return true when the data dependence relation between the data
534 references PDR1 belonging to PBB1 and PDR2 belonging to PBB2 is
535 part of a reduction. */
538 reduction_dr_p (poly_bb_p pbb1, poly_bb_p pbb2,
539 poly_dr_p pdr1, poly_dr_p pdr2)
541 if (PBB_IS_REDUCTION (pbb1))
542 return reduction_dr_1 (pbb1, pdr1, pdr2);
544 if (PBB_IS_REDUCTION (pbb2))
545 return reduction_dr_1 (pbb2, pdr2, pdr1);
550 /* Returns true when the PBB_TRANSFORMED_SCATTERING functions of PBB1
551 and PBB2 respect the data dependences of PBB_ORIGINAL_SCATTERING
555 graphite_legal_transform_dr (poly_bb_p pbb1, poly_bb_p pbb2,
556 poly_dr_p pdr1, poly_dr_p pdr2)
558 ppl_Polyhedron_t st1, st2;
559 ppl_Pointset_Powerset_C_Polyhedron_t po, pt;
560 graphite_dim_t ddim1, otdim1, otdim2, ttdim1, ttdim2;
561 ppl_Pointset_Powerset_C_Polyhedron_t temp;
562 ppl_dimension_type pdim;
566 if (reduction_dr_p (pbb1, pbb2, pdr1, pdr2))
569 pddr = build_pddr (pbb1, pbb2, pdr1, pdr2, 1, true);
571 /* There are no dependences between PDR1 and PDR2 in the original
572 version of the program, so the transform is legal. */
575 po = PDDR_DDP (pddr);
577 if (dump_file && (dump_flags & TDF_DETAILS))
578 fprintf (dump_file, "\nloop carries dependency.\n");
580 st1 = PBB_TRANSFORMED_SCATTERING (pbb1);
581 st2 = PBB_TRANSFORMED_SCATTERING (pbb2);
582 ddim1 = pbb_dim_iter_domain (pbb1);
583 otdim1 = pbb_nb_scattering_orig (pbb1);
584 otdim2 = pbb_nb_scattering_orig (pbb2);
585 ttdim1 = pbb_nb_scattering_transform (pbb1);
586 ttdim2 = pbb_nb_scattering_transform (pbb2);
588 /* Copy the PO polyhedron into the TEMP, so it is not destroyed.
589 Keep in mind, that PO polyhedron might be restored from the cache
590 and should not be modified! */
591 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (po, &pdim);
592 ppl_new_Pointset_Powerset_C_Polyhedron_from_space_dimension (&temp, pdim, 0);
593 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (temp, po);
595 /* We build the reverse dependence relation for the transformed
596 scattering, such that when we intersect it with the original PO,
597 we get an empty intersection when the transform is legal:
598 i.e. the transform should reverse no dependences, and so PT, the
599 reversed transformed PDDR, should have no constraint from PO. */
600 pddr = build_pddr (pbb1, pbb2, pdr1, pdr2, -1, false);
602 /* There are no dependences after the transform, so the transform
606 pt = PDDR_DDP (pddr);
608 /* Extend PO and PT to have the same dimensions. */
609 ppl_insert_dimensions_pointset (temp, otdim1, ttdim1);
610 ppl_insert_dimensions_pointset (temp, otdim1 + ttdim1 + ddim1 + otdim2, ttdim2);
611 ppl_insert_dimensions_pointset (pt, 0, otdim1);
612 ppl_insert_dimensions_pointset (pt, otdim1 + ttdim1 + ddim1, otdim2);
614 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (temp, pt);
615 is_empty_p = ppl_Pointset_Powerset_C_Polyhedron_is_empty (temp);
617 ppl_delete_Pointset_Powerset_C_Polyhedron (temp);
618 free_poly_ddr (pddr);
623 /* Return true when the data dependence relation for PBB1 and PBB2 is
624 part of a reduction. */
627 reduction_ddr_p (poly_bb_p pbb1, poly_bb_p pbb2)
629 return pbb1 == pbb2 && PBB_IS_REDUCTION (pbb1);
632 /* Iterates over the data references of PBB1 and PBB2 and detect
633 whether the transformed schedule is correct. */
636 graphite_legal_transform_bb (poly_bb_p pbb1, poly_bb_p pbb2)
639 poly_dr_p pdr1, pdr2;
641 if (!PBB_PDR_DUPLICATES_REMOVED (pbb1))
642 pbb_remove_duplicate_pdrs (pbb1);
644 if (!PBB_PDR_DUPLICATES_REMOVED (pbb2))
645 pbb_remove_duplicate_pdrs (pbb2);
647 if (reduction_ddr_p (pbb1, pbb2))
650 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), i, pdr1); i++)
651 for (j = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), j, pdr2); j++)
652 if (!graphite_legal_transform_dr (pbb1, pbb2, pdr1, pdr2))
658 /* Iterates over the SCOP and detect whether the transformed schedule
662 graphite_legal_transform (scop_p scop)
665 poly_bb_p pbb1, pbb2;
667 timevar_push (TV_GRAPHITE_DATA_DEPS);
669 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb1); i++)
670 for (j = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), j, pbb2); j++)
671 if (!graphite_legal_transform_bb (pbb1, pbb2))
673 timevar_pop (TV_GRAPHITE_DATA_DEPS);
677 timevar_pop (TV_GRAPHITE_DATA_DEPS);
681 /* Remove all the dimensions except alias information at dimension
685 build_alias_set_powerset (ppl_Pointset_Powerset_C_Polyhedron_t alias_powerset,
686 ppl_dimension_type alias_dim)
688 ppl_dimension_type *ds;
689 ppl_dimension_type access_dim;
692 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (alias_powerset,
694 ds = XNEWVEC (ppl_dimension_type, access_dim-1);
695 for (i = 0; i < access_dim; i++)
704 ppl_Pointset_Powerset_C_Polyhedron_remove_space_dimensions (alias_powerset,
710 /* Return true when PDR1 and PDR2 may alias. */
713 poly_drs_may_alias_p (poly_dr_p pdr1, poly_dr_p pdr2)
715 ppl_Pointset_Powerset_C_Polyhedron_t alias_powerset1, alias_powerset2;
716 ppl_Pointset_Powerset_C_Polyhedron_t accesses1 = PDR_ACCESSES (pdr1);
717 ppl_Pointset_Powerset_C_Polyhedron_t accesses2 = PDR_ACCESSES (pdr2);
718 ppl_dimension_type alias_dim1 = pdr_alias_set_dim (pdr1);
719 ppl_dimension_type alias_dim2 = pdr_alias_set_dim (pdr2);
722 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
723 (&alias_powerset1, accesses1);
724 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
725 (&alias_powerset2, accesses2);
727 build_alias_set_powerset (alias_powerset1, alias_dim1);
728 build_alias_set_powerset (alias_powerset2, alias_dim2);
730 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign
731 (alias_powerset1, alias_powerset2);
733 empty_p = ppl_Pointset_Powerset_C_Polyhedron_is_empty (alias_powerset1);
735 ppl_delete_Pointset_Powerset_C_Polyhedron (alias_powerset1);
736 ppl_delete_Pointset_Powerset_C_Polyhedron (alias_powerset2);
741 /* Returns TRUE when the dependence polyhedron between PDR1 and
742 PDR2 represents a loop carried dependence at level LEVEL. */
745 graphite_carried_dependence_level_k (poly_dr_p pdr1, poly_dr_p pdr2,
748 poly_bb_p pbb1 = PDR_PBB (pdr1);
749 poly_bb_p pbb2 = PDR_PBB (pdr2);
750 ppl_Pointset_Powerset_C_Polyhedron_t d1 = PBB_DOMAIN (pbb1);
751 ppl_Pointset_Powerset_C_Polyhedron_t d2 = PBB_DOMAIN (pbb2);
752 ppl_Polyhedron_t so1 = PBB_TRANSFORMED_SCATTERING (pbb1);
753 ppl_Polyhedron_t so2 = PBB_TRANSFORMED_SCATTERING (pbb2);
754 ppl_Pointset_Powerset_C_Polyhedron_t po;
755 ppl_Pointset_Powerset_C_Polyhedron_t eqpp;
756 graphite_dim_t tdim1 = pbb_nb_scattering_transform (pbb1);
757 graphite_dim_t ddim1 = pbb_dim_iter_domain (pbb1);
758 ppl_dimension_type dim;
761 int obj_base_set1 = PDR_BASE_OBJECT_SET (pdr1);
762 int obj_base_set2 = PDR_BASE_OBJECT_SET (pdr2);
764 if ((pdr_read_p (pdr1) && pdr_read_p (pdr2))
765 || !poly_drs_may_alias_p (pdr1, pdr2))
768 if (obj_base_set1 != obj_base_set2)
771 if (PDR_NB_SUBSCRIPTS (pdr1) != PDR_NB_SUBSCRIPTS (pdr2))
774 pddr = dependence_polyhedron (pbb1, pbb2, d1, d2, pdr1, pdr2, so1, so2,
777 if (pddr_is_empty (pddr))
780 po = PDDR_DDP (pddr);
781 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (po, &dim);
782 eqpp = build_pairwise_scheduling (dim, level, tdim1 + ddim1, 1);
784 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (eqpp, po);
785 empty_p = ppl_Pointset_Powerset_C_Polyhedron_is_empty (eqpp);
787 ppl_delete_Pointset_Powerset_C_Polyhedron (eqpp);
791 /* Check data dependency between PBB1 and PBB2 at level LEVEL. */
794 dependency_between_pbbs_p (poly_bb_p pbb1, poly_bb_p pbb2, int level)
797 poly_dr_p pdr1, pdr2;
799 timevar_push (TV_GRAPHITE_DATA_DEPS);
801 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), i, pdr1); i++)
802 for (j = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), j, pdr2); j++)
803 if (graphite_carried_dependence_level_k (pdr1, pdr2, level))
805 timevar_pop (TV_GRAPHITE_DATA_DEPS);
809 timevar_pop (TV_GRAPHITE_DATA_DEPS);
813 /* Pretty print to FILE all the original data dependences of SCoP in
817 dot_original_deps_stmt_1 (FILE *file, scop_p scop)
820 poly_bb_p pbb1, pbb2;
821 poly_dr_p pdr1, pdr2;
823 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb1); i++)
824 for (j = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), j, pbb2); j++)
826 for (k = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), k, pdr1); k++)
827 for (l = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), l, pdr2); l++)
828 if (build_pddr (pbb1, pbb2, pdr1, pdr2, 1, true))
830 fprintf (file, "OS%d -> OS%d\n",
831 pbb_index (pbb1), pbb_index (pbb2));
838 /* Pretty print to FILE all the transformed data dependences of SCoP in
842 dot_transformed_deps_stmt_1 (FILE *file, scop_p scop)
845 poly_bb_p pbb1, pbb2;
846 poly_dr_p pdr1, pdr2;
849 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb1); i++)
850 for (j = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), j, pbb2); j++)
852 for (k = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), k, pdr1); k++)
853 for (l = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), l, pdr2); l++)
854 if ((pddr = build_pddr (pbb1, pbb2, pdr1, pdr2, 1, false)))
856 fprintf (file, "TS%d -> TS%d\n",
857 pbb_index (pbb1), pbb_index (pbb2));
858 free_poly_ddr (pddr);
866 /* Pretty print to FILE all the data dependences of SCoP in DOT
870 dot_deps_stmt_1 (FILE *file, scop_p scop)
872 fputs ("digraph all {\n", file);
874 dot_original_deps_stmt_1 (file, scop);
875 dot_transformed_deps_stmt_1 (file, scop);
877 fputs ("}\n\n", file);
880 /* Pretty print to FILE all the original data dependences of SCoP in
884 dot_original_deps (FILE *file, scop_p scop)
887 poly_bb_p pbb1, pbb2;
888 poly_dr_p pdr1, pdr2;
890 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb1); i++)
891 for (j = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), j, pbb2); j++)
892 for (k = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), k, pdr1); k++)
893 for (l = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), l, pdr2); l++)
894 if (build_pddr (pbb1, pbb2, pdr1, pdr2, 1, true))
895 fprintf (file, "OS%d_D%d -> OS%d_D%d\n",
896 pbb_index (pbb1), PDR_ID (pdr1),
897 pbb_index (pbb2), PDR_ID (pdr2));
900 /* Pretty print to FILE all the transformed data dependences of SCoP in
904 dot_transformed_deps (FILE *file, scop_p scop)
907 poly_bb_p pbb1, pbb2;
908 poly_dr_p pdr1, pdr2;
911 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb1); i++)
912 for (j = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), j, pbb2); j++)
913 for (k = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb1), k, pdr1); k++)
914 for (l = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb2), l, pdr2); l++)
915 if ((pddr = build_pddr (pbb1, pbb2, pdr1, pdr2, 1, false)))
917 fprintf (file, "TS%d_D%d -> TS%d_D%d\n",
918 pbb_index (pbb1), PDR_ID (pdr1),
919 pbb_index (pbb2), PDR_ID (pdr2));
920 free_poly_ddr (pddr);
924 /* Pretty print to FILE all the data dependences of SCoP in DOT
928 dot_deps_1 (FILE *file, scop_p scop)
930 fputs ("digraph all {\n", file);
932 dot_original_deps (file, scop);
933 dot_transformed_deps (file, scop);
935 fputs ("}\n\n", file);
938 /* Display all the data dependences in SCoP using dotty. */
941 dot_deps (scop_p scop)
943 /* When debugging, enable the following code. This cannot be used
944 in production compilers because it calls "system". */
947 FILE *stream = fopen ("/tmp/scopdeps.dot", "w");
950 dot_deps_1 (stream, scop);
953 x = system ("dotty /tmp/scopdeps.dot");
955 dot_deps_1 (stderr, scop);
959 /* Display all the statement dependences in SCoP using dotty. */
962 dot_deps_stmt (scop_p scop)
964 /* When debugging, enable the following code. This cannot be used
965 in production compilers because it calls "system". */
968 FILE *stream = fopen ("/tmp/scopdeps.dot", "w");
971 dot_deps_stmt_1 (stream, scop);
974 x = system ("dotty /tmp/scopdeps.dot");
976 dot_deps_stmt_1 (stderr, scop);