1 /* Graphite polyhedral representation.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>.
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/>. */
23 #include "coretypes.h"
29 #include "basic-block.h"
30 #include "diagnostic.h"
31 #include "tree-pretty-print.h"
32 #include "gimple-pretty-print.h"
33 #include "tree-flow.h"
35 #include "tree-dump.h"
38 #include "tree-chrec.h"
39 #include "tree-data-ref.h"
40 #include "tree-scalar-evolution.h"
41 #include "tree-pass.h"
43 #include "value-prof.h"
44 #include "pointer-set.h"
51 #include "graphite-ppl.h"
53 #include "graphite-poly.h"
54 #include "graphite-dependences.h"
55 #include "graphite-cloog-util.h"
57 #define OPENSCOP_MAX_STRING 256
59 /* Return the maximal loop depth in SCOP. */
62 scop_max_loop_depth (scop_p scop)
68 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
70 int nb_loops = pbb_dim_iter_domain (pbb);
71 if (max_nb_loops < nb_loops)
72 max_nb_loops = nb_loops;
78 /* Extend the scattering matrix of PBB to MAX_SCATTERING scattering
82 extend_scattering (poly_bb_p pbb, int max_scattering)
84 ppl_dimension_type nb_old_dims, nb_new_dims;
86 ppl_Coefficient_t coef;
89 nb_added_dims = max_scattering - pbb_nb_scattering_transform (pbb);
92 ppl_new_Coefficient (&coef);
93 ppl_assign_Coefficient_from_mpz_t (coef, one);
95 gcc_assert (nb_added_dims >= 0);
97 nb_old_dims = pbb_nb_scattering_transform (pbb) + pbb_dim_iter_domain (pbb)
98 + scop_nb_params (PBB_SCOP (pbb));
99 nb_new_dims = nb_old_dims + nb_added_dims;
101 ppl_insert_dimensions (PBB_TRANSFORMED_SCATTERING (pbb),
102 pbb_nb_scattering_transform (pbb), nb_added_dims);
103 PBB_NB_SCATTERING_TRANSFORM (pbb) += nb_added_dims;
105 /* Add identity matrix for the added dimensions. */
106 for (i = max_scattering - nb_added_dims; i < max_scattering; i++)
108 ppl_Constraint_t cstr;
109 ppl_Linear_Expression_t expr;
111 ppl_new_Linear_Expression_with_dimension (&expr, nb_new_dims);
112 ppl_Linear_Expression_add_to_coefficient (expr, i, coef);
113 ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_EQUAL);
114 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb), cstr);
115 ppl_delete_Constraint (cstr);
116 ppl_delete_Linear_Expression (expr);
119 ppl_delete_Coefficient (coef);
123 /* All scattering matrices in SCOP will have the same number of scattering
127 unify_scattering_dimensions (scop_p scop)
131 graphite_dim_t max_scattering = 0;
133 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
134 max_scattering = MAX (pbb_nb_scattering_transform (pbb), max_scattering);
136 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
137 extend_scattering (pbb, max_scattering);
139 return max_scattering;
142 /* Print to FILE the pdr PH in OpenScop format. NB_SUBSCRIPTS is the number
143 of subscripts in PH, ALIAS_SET_DIM is the dimension of the alias set and
144 NB_PARAMS is the number of parameters in PH. */
147 openscop_print_pdr_polyhedron (FILE *file, ppl_const_Polyhedron_t ph,
148 int nb_subscripts, int alias_set_dimension,
151 int input, locals, output;
152 ppl_dimension_type alias_set_dim = (ppl_dimension_type) alias_set_dimension;
153 ppl_dimension_type sub_dim_last = alias_set_dim + nb_subscripts;
154 ppl_dimension_type *map, i, ph_space_dim = sub_dim_last + 1;
155 ppl_Polyhedron_t pph;
157 ppl_new_C_Polyhedron_from_C_Polyhedron (&pph, ph);
159 map = (ppl_dimension_type *) XNEWVEC (ppl_dimension_type, ph_space_dim);
161 for (i = 0; i < alias_set_dim - 1; i++)
162 map[i] = nb_subscripts + 1 + i;
164 for (i = alias_set_dim - 1; i < sub_dim_last; i++)
165 map[i] = i - alias_set_dim + 1;
167 ppl_Polyhedron_map_space_dimensions (pph, map, ph_space_dim - 1);
170 input = alias_set_dim - nb_params - 1;
172 /* According to OpenScop specification, the alias set column is a part of
173 the output columns. */
174 output = nb_subscripts + 1;
176 openscop_print_polyhedron_matrix (file, pph, output, input, locals, nb_params);
179 /* Print to FILE the powerset PDR. NB_SUBSCRIPTS is the number of subscripts
180 in PDR, ALIAS_SET_DIM is the dimension of the alias set in PDR and
181 NB_PARAMS is the number of parameters in PDR. */
184 openscop_print_pdr_powerset (FILE *file,
185 ppl_Pointset_Powerset_C_Polyhedron_t ps,
191 ppl_Pointset_Powerset_C_Polyhedron_iterator_t it, end;
193 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&it);
194 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&end);
196 ppl_Pointset_Powerset_C_Polyhedron_size (ps, &nb_disjuncts);
197 fprintf (file, "%d\n", (int) nb_disjuncts);
199 for (ppl_Pointset_Powerset_C_Polyhedron_iterator_begin (ps, it),
200 ppl_Pointset_Powerset_C_Polyhedron_iterator_end (ps, end);
201 !ppl_Pointset_Powerset_C_Polyhedron_iterator_equal_test (it, end);
202 ppl_Pointset_Powerset_C_Polyhedron_iterator_increment (it))
204 ppl_const_Polyhedron_t ph;
206 ppl_Pointset_Powerset_C_Polyhedron_iterator_dereference (it, &ph);
207 openscop_print_pdr_polyhedron (file, ph, nb_subscripts, alias_set_dim,
211 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (it);
212 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (end);
215 /* Print to FILE the powerset PS in its OpenScop matrix form. */
218 openscop_print_powerset_matrix (FILE *file,
219 ppl_Pointset_Powerset_C_Polyhedron_t ps,
220 int output, int input, int locals,
224 ppl_Pointset_Powerset_C_Polyhedron_iterator_t it, end;
226 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&it);
227 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&end);
229 ppl_Pointset_Powerset_C_Polyhedron_size (ps, &nb_disjuncts);
230 fprintf (file, "%d\n", (int) nb_disjuncts);
232 for (ppl_Pointset_Powerset_C_Polyhedron_iterator_begin (ps, it),
233 ppl_Pointset_Powerset_C_Polyhedron_iterator_end (ps, end);
234 !ppl_Pointset_Powerset_C_Polyhedron_iterator_equal_test (it, end);
235 ppl_Pointset_Powerset_C_Polyhedron_iterator_increment (it))
237 ppl_const_Polyhedron_t ph;
239 ppl_Pointset_Powerset_C_Polyhedron_iterator_dereference (it, &ph);
240 openscop_print_polyhedron_matrix (file, ph, output, input, locals,
244 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (it);
245 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (end);
248 /* Prints to FILE the scattering function of PBB in OpenScop format, at some
252 openscop_print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity)
255 ppl_const_Polyhedron_t ph;
259 fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb));
260 fprintf (file, "#eq");
262 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
263 fprintf (file, " s%d", (int) i);
265 for (i = 0; i < pbb_nb_local_vars (pbb); i++)
266 fprintf (file, " lv%d", (int) i);
268 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
269 fprintf (file, " i%d", (int) i);
271 for (i = 0; i < pbb_nb_params (pbb); i++)
272 fprintf (file, " p%d", (int) i);
274 fprintf (file, " cst\n");
277 /* Number of disjunct components. Remove this when
278 PBB_TRANSFORMED_SCATTERING will be a pointset_powerset. */
279 fprintf (file, "1\n");
281 ph = PBB_TRANSFORMED_SCATTERING (pbb)
282 ? PBB_TRANSFORMED_SCATTERING (pbb)
283 : PBB_ORIGINAL_SCATTERING (pbb);
285 openscop_print_polyhedron_matrix (file, ph,
286 pbb_nb_scattering_transform (pbb),
287 pbb_dim_iter_domain (pbb),
288 pbb_nb_local_vars (pbb),
289 pbb_nb_params (pbb));
292 fprintf (file, "#)\n");
295 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
299 print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity)
305 fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb));
306 fprintf (file, "#eq");
308 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
309 fprintf (file, " s%d", (int) i);
311 for (i = 0; i < pbb_nb_local_vars (pbb); i++)
312 fprintf (file, " lv%d", (int) i);
314 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
315 fprintf (file, " i%d", (int) i);
317 for (i = 0; i < pbb_nb_params (pbb); i++)
318 fprintf (file, " p%d", (int) i);
320 fprintf (file, " cst\n");
323 /* Number of disjunct components. Remove this when
324 PBB_TRANSFORMED_SCATTERING will be a pointset_powerset. */
325 fprintf (file, "1\n");
326 ppl_print_polyhedron_matrix (file, PBB_TRANSFORMED_SCATTERING (pbb)
327 ? PBB_TRANSFORMED_SCATTERING (pbb)
328 : PBB_ORIGINAL_SCATTERING (pbb));
331 fprintf (file, "#)\n");
334 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
338 print_scattering_function (FILE *file, poly_bb_p pbb, int verbosity)
340 if (!PBB_TRANSFORMED (pbb))
343 if (PBB_TRANSFORMED_SCATTERING (pbb)
344 || PBB_ORIGINAL_SCATTERING (pbb))
347 fprintf (file, "# Scattering function is provided\n");
349 fprintf (file, "1\n");
354 fprintf (file, "# Scattering function is not provided\n");
356 fprintf (file, "0\n");
360 openscop_print_scattering_function_1 (file, pbb, verbosity);
363 fprintf (file, "# Scattering names are not provided\n");
365 fprintf (file, "0\n");
369 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
373 print_iteration_domain (FILE *file, poly_bb_p pbb, int verbosity)
375 print_pbb_domain (file, pbb, verbosity);
378 /* Prints to FILE the scattering functions of every PBB of SCOP. */
381 print_scattering_functions (FILE *file, scop_p scop, int verbosity)
386 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
387 print_scattering_function (file, pbb, verbosity);
390 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
394 print_iteration_domains (FILE *file, scop_p scop, int verbosity)
399 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
400 print_iteration_domain (file, pbb, verbosity);
403 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
407 debug_scattering_function (poly_bb_p pbb, int verbosity)
409 print_scattering_function (stderr, pbb, verbosity);
412 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
416 debug_iteration_domain (poly_bb_p pbb, int verbosity)
418 print_iteration_domain (stderr, pbb, verbosity);
421 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
422 some VERBOSITY level. */
425 debug_scattering_functions (scop_p scop, int verbosity)
427 print_scattering_functions (stderr, scop, verbosity);
430 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
431 some VERBOSITY level. */
434 debug_iteration_domains (scop_p scop, int verbosity)
436 print_iteration_domains (stderr, scop, verbosity);
439 /* Read N integer from FILE. */
442 openscop_read_N_int (FILE *file, int N)
444 char s[OPENSCOP_MAX_STRING];
446 int i, *res = (int *) xmalloc (OPENSCOP_MAX_STRING * sizeof (int));
448 /* Skip blank and commented lines. */
449 while (fgets (s, sizeof s, file) == (char *) 0
456 for (i = 0; i < N; i++)
458 sscanf (str, "%d", &res[i]);
460 /* Jump the integer that was read. */
461 while ((*str) && !ISSPACE (*str) && (*str != '#'))
465 while ((*str) && ISSPACE (*str) && (*str != '#'))
472 /* Read one integer from FILE. */
475 openscop_read_one_int (FILE *file)
477 int *x = openscop_read_N_int (file, 1);
484 /* Read N string from FILE. */
487 openscop_read_N_string (FILE *file, int N)
490 char str[OPENSCOP_MAX_STRING];
491 char *tmp = (char *) xmalloc (sizeof (char) * OPENSCOP_MAX_STRING);
494 /* Skip blank and commented lines. */
495 while (fgets (str, sizeof str, file) == (char *) 0
503 for (i = 0; i < N; i++)
505 /* Read the first word. */
506 for (; (*s) && (!ISSPACE (*s)) && (*s != '#'); ++count)
513 while ((*s) && ISSPACE (*s) && (*s != '#'))
522 /* Read one string from FILE. */
525 openscop_read_one_string (FILE *file)
527 return openscop_read_N_string (file, 1);
530 /* Read from FILE the powerset PS in its OpenScop matrix form. OUTPUT is the
531 number of output dimensions, INPUT is the number of input dimensions,
532 LOCALS is the number of existentially quantified variables and PARAMS is
533 the number of parameters. */
536 openscop_read_powerset_matrix (FILE *file,
537 ppl_Pointset_Powerset_C_Polyhedron_t *ps,
538 int *output, int *input, int *locals,
543 nb_disjuncts = openscop_read_one_int (file);
545 for (i = 0; i < nb_disjuncts; i++)
549 openscop_read_polyhedron_matrix (file, &ph, output, input, locals,
554 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (ps, ph);
556 ppl_Pointset_Powerset_C_Polyhedron_add_disjunct (*ps, ph);
560 /* Read a scattering function from FILE and save it to PBB. Return whether
561 the scattering function was provided or not. */
564 graphite_read_scatt (FILE *file, poly_bb_p pbb)
566 bool scattering_provided = false;
567 int output, input, locals, params;
568 ppl_Polyhedron_t newp;
570 if (openscop_read_one_int (file) > 0)
572 /* Read number of disjunct components. */
573 openscop_read_one_int (file);
575 /* Read scattering function. */
576 openscop_read_polyhedron_matrix (file, &newp, &output, &input,
578 store_scattering (PBB_SCOP (pbb));
579 PBB_TRANSFORMED (pbb) = poly_scattering_new ();
580 PBB_TRANSFORMED_SCATTERING (pbb) = newp;
581 PBB_NB_LOCAL_VARIABLES (pbb) = locals;
583 /* New scattering dimension. */
584 PBB_NB_SCATTERING_TRANSFORM (pbb) = output;
586 scattering_provided = true;
589 return scattering_provided;
592 /* Read a scop file. Return true if the scop is transformed. */
595 graphite_read_scop_file (FILE *file, scop_p scop)
597 char *tmp, *language;
598 size_t i, j, nb_statements, nbr, nbw;
599 int input, output, locals, params;
600 ppl_Pointset_Powerset_C_Polyhedron_t ps;
602 bool transform_done = false;
604 /* Ensure that the file is in OpenScop format. */
605 tmp = openscop_read_N_string (file, 2);
607 if (strcmp (tmp, "SCoP 1"))
609 error ("The file is not in OpenScop format.\n");
615 /* Read the language. */
616 language = openscop_read_one_string (file);
618 if (strcmp (language, "Gimple"))
620 error ("The language is not recognized\n");
626 /* Read the context but do not use it. */
627 openscop_read_powerset_matrix (file, &ps, &input, &output, &locals, ¶ms);
629 if ((size_t) params != scop->nb_params)
631 error ("Parameters number in the scop file is different from the"
632 " internal scop parameter number.");
636 /* Read parameter names if provided. */
637 if (openscop_read_one_int (file))
638 openscop_read_N_string (file, scop->nb_params);
640 nb_statements = openscop_read_one_int (file);
642 if (nb_statements != VEC_length (poly_bb_p, SCOP_BBS (scop)))
644 error ("Number of statements in the OpenScop file does not match"
645 " the graphite internal statements number.");
649 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
651 /* Read iteration domain. */
652 openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
655 /* Read scattering. */
656 transform_done = graphite_read_scatt (file, pbb);
658 /* Scattering names. */
659 openscop_read_one_int (file);
661 /* Read access functions. */
662 if (openscop_read_one_int (file) > 0)
664 nbr = openscop_read_one_int (file);
666 /* Read access functions. */
667 for (j = 0; j < nbr; j++)
668 openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
671 nbw = openscop_read_one_int (file);
673 /* Write access functions. */
674 for (j = 0; j < nbw; j++)
675 openscop_read_powerset_matrix (file, &ps, &input, &output, &locals,
679 /* Statement body. */
680 openscop_read_one_int (file);
683 return transform_done;
686 /* Initialize and return a file that will be used to write a scop. SCOP_NUMBER
687 is a sequential number (identifier) used to differentiate scop files.
688 Examples of the generated file names: dump_base_name.0.graphite,
689 dump_base_name.1.graphite, dump_base_name.2.graphite, etc. */
692 init_graphite_out_file (int scop_number)
694 FILE *graphite_out_file;
695 int len = strlen (dump_base_name);
696 char *dumpname = XNEWVEC (char, len + 25);
697 char *s_scop_number = XNEWVEC (char, 15);
699 memcpy (dumpname, dump_base_name, len + 1);
700 strip_off_ending (dumpname, len);
701 sprintf (s_scop_number, ".%d", scop_number);
702 strcat (dumpname, s_scop_number);
703 strcat (dumpname, ".graphite");
704 graphite_out_file = fopen (dumpname, "w+b");
706 if (graphite_out_file == 0)
707 fatal_error ("can%'t open %s for writing: %m", dumpname);
711 return graphite_out_file;
714 /* Open and return a file used for scop reading. SCOP_NUMBER is a sequential
715 number (identifier) used to differentiate scop files. Examples of the
716 generated file names: dump_base_name.0.graphite, dump_base_name.1.graphite,
717 dump_base_name.2.graphite, etc. */
720 init_graphite_in_file (int scop_number)
722 FILE *graphite_in_file;
723 int len = strlen (dump_base_name);
724 char *dumpname = XNEWVEC (char, len + 25);
725 char *s_scop_number = XNEWVEC (char, 15);
727 memcpy (dumpname, dump_base_name, len + 1);
728 strip_off_ending (dumpname, len);
729 sprintf (s_scop_number, ".%d", scop_number);
730 strcat (dumpname, s_scop_number);
731 strcat (dumpname, ".graphite");
732 graphite_in_file = fopen (dumpname, "r+b");
734 if (graphite_in_file == 0)
735 fatal_error ("can%'t open %s for reading: %m", dumpname);
739 return graphite_in_file;
742 /* Apply graphite transformations to all the basic blocks of SCOP. */
745 apply_poly_transforms (scop_p scop)
747 bool transform_done = false;
749 static size_t file_scop_number = 0;
751 /* This feature is only enabled in the Graphite branch. */
754 graphite_file = init_graphite_in_file (file_scop_number);
755 transform_done |= graphite_read_scop_file (graphite_file, scop);
757 if (!graphite_legal_transform (scop))
758 fatal_error ("the graphite file read for scop %d does not contain a legal transform",
759 (int) file_scop_number);
764 /* Generate code even if we did not apply any real transformation.
765 This also allows to check the performance for the identity
766 transformation: GIMPLE -> GRAPHITE -> GIMPLE
767 Keep in mind that CLooG optimizes in control, so the loop structure
768 may change, even if we only use -fgraphite-identity. */
769 if (flag_graphite_identity)
770 transform_done = true;
772 if (flag_loop_parallelize_all)
773 transform_done = true;
776 transform_done |= scop_do_block (scop);
779 if (flag_loop_strip_mine)
780 transform_done |= scop_do_strip_mine (scop);
782 if (flag_loop_interchange)
783 transform_done |= scop_do_interchange (scop);
786 /* This feature is only enabled in the Graphite branch. */
789 graphite_file = init_graphite_out_file (file_scop_number);
790 print_scop (graphite_file, scop, 1);
794 return transform_done;
797 /* Returns true when it PDR1 is a duplicate of PDR2: same PBB, and
798 their ACCESSES, TYPE, and NB_SUBSCRIPTS are the same. */
801 can_collapse_pdrs (poly_dr_p pdr1, poly_dr_p pdr2)
804 ppl_Pointset_Powerset_C_Polyhedron_t af1, af2, diff;
806 if (PDR_PBB (pdr1) != PDR_PBB (pdr2)
807 || PDR_NB_SUBSCRIPTS (pdr1) != PDR_NB_SUBSCRIPTS (pdr2)
808 || PDR_TYPE (pdr1) != PDR_TYPE (pdr2))
811 af1 = PDR_ACCESSES (pdr1);
812 af2 = PDR_ACCESSES (pdr2);
813 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
815 ppl_Pointset_Powerset_C_Polyhedron_difference_assign (diff, af2);
817 res = ppl_Pointset_Powerset_C_Polyhedron_is_empty (diff);
818 ppl_delete_Pointset_Powerset_C_Polyhedron (diff);
822 /* Removes duplicated data references in PBB. */
825 pbb_remove_duplicate_pdrs (poly_bb_p pbb)
828 poly_dr_p pdr1, pdr2;
829 unsigned n = VEC_length (poly_dr_p, PBB_DRS (pbb));
830 VEC (poly_dr_p, heap) *collapsed = VEC_alloc (poly_dr_p, heap, n);
832 FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr1)
833 FOR_EACH_VEC_ELT (poly_dr_p, collapsed, j, pdr2)
834 if (!can_collapse_pdrs (pdr1, pdr2))
835 VEC_quick_push (poly_dr_p, collapsed, pdr1);
837 VEC_free (poly_dr_p, heap, collapsed);
838 PBB_PDR_DUPLICATES_REMOVED (pbb) = true;
841 /* Create a new polyhedral data reference and add it to PBB. It is
842 defined by its ACCESSES, its TYPE, and the number of subscripts
846 new_poly_dr (poly_bb_p pbb, int dr_base_object_set,
847 ppl_Pointset_Powerset_C_Polyhedron_t accesses,
848 enum poly_dr_type type, void *cdr, graphite_dim_t nb_subscripts)
851 poly_dr_p pdr = XNEW (struct poly_dr);
854 PDR_BASE_OBJECT_SET (pdr) = dr_base_object_set;
855 PDR_NB_REFS (pdr) = 1;
857 PDR_ACCESSES (pdr) = accesses;
858 PDR_TYPE (pdr) = type;
860 PDR_NB_SUBSCRIPTS (pdr) = nb_subscripts;
861 VEC_safe_push (poly_dr_p, heap, PBB_DRS (pbb), pdr);
864 /* Free polyhedral data reference PDR. */
867 free_poly_dr (poly_dr_p pdr)
869 ppl_delete_Pointset_Powerset_C_Polyhedron (PDR_ACCESSES (pdr));
873 /* Create a new polyhedral black box. */
876 new_poly_bb (scop_p scop, void *black_box, bool reduction)
878 poly_bb_p pbb = XNEW (struct poly_bb);
880 PBB_DOMAIN (pbb) = NULL;
881 PBB_SCOP (pbb) = scop;
882 pbb_set_black_box (pbb, black_box);
883 PBB_TRANSFORMED (pbb) = NULL;
884 PBB_SAVED (pbb) = NULL;
885 PBB_ORIGINAL (pbb) = NULL;
886 PBB_DRS (pbb) = VEC_alloc (poly_dr_p, heap, 3);
887 PBB_IS_REDUCTION (pbb) = reduction;
888 PBB_PDR_DUPLICATES_REMOVED (pbb) = false;
889 VEC_safe_push (poly_bb_p, heap, SCOP_BBS (scop), pbb);
892 /* Free polyhedral black box. */
895 free_poly_bb (poly_bb_p pbb)
900 ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb));
902 if (PBB_TRANSFORMED (pbb))
903 poly_scattering_free (PBB_TRANSFORMED (pbb));
906 poly_scattering_free (PBB_SAVED (pbb));
908 if (PBB_ORIGINAL (pbb))
909 poly_scattering_free (PBB_ORIGINAL (pbb));
912 FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr)
915 VEC_free (poly_dr_p, heap, PBB_DRS (pbb));
920 print_pdr_access_layout (FILE *file, poly_bb_p pbb, poly_dr_p pdr)
924 fprintf (file, "# eq");
926 fprintf (file, " alias");
928 for (i = 0; i < PDR_NB_SUBSCRIPTS (pdr); i++)
929 fprintf (file, " sub%d", (int) i);
931 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
932 fprintf (file, " i%d", (int) i);
934 for (i = 0; i < pbb_nb_params (pbb); i++)
935 fprintf (file, " p%d", (int) i);
937 fprintf (file, " cst\n");
940 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
944 print_pdr (FILE *file, poly_dr_p pdr, int verbosity)
950 fprintf (file, "# pdr_%d (", PDR_ID (pdr));
952 switch (PDR_TYPE (pdr))
955 fprintf (file, "read \n");
959 fprintf (file, "write \n");
963 fprintf (file, "may_write \n");
970 dump_data_reference (file, (data_reference_p) PDR_CDR (pdr));
975 fprintf (file, "# data accesses (\n");
976 print_pdr_access_layout (file, PDR_PBB (pdr), pdr);
979 alias_set_dim = pdr_alias_set_dim (pdr) + 1;
981 openscop_print_pdr_powerset (file,
983 PDR_NB_SUBSCRIPTS (pdr),
985 pbb_nb_params (PDR_PBB (pdr)));
988 fprintf (file, "#)\n");
991 fprintf (file, "#)\n");
994 /* Prints to STDERR the polyhedral data reference PDR, at some
998 debug_pdr (poly_dr_p pdr, int verbosity)
1000 print_pdr (stderr, pdr, verbosity);
1003 /* Creates a new SCOP containing REGION. */
1006 new_scop (void *region)
1008 scop_p scop = XNEW (struct scop);
1010 SCOP_CONTEXT (scop) = NULL;
1011 scop_set_region (scop, region);
1012 SCOP_BBS (scop) = VEC_alloc (poly_bb_p, heap, 3);
1013 SCOP_ORIGINAL_PDDRS (scop) = htab_create (10, hash_poly_ddr_p,
1014 eq_poly_ddr_p, free_poly_ddr);
1015 SCOP_ORIGINAL_SCHEDULE (scop) = NULL;
1016 SCOP_TRANSFORMED_SCHEDULE (scop) = NULL;
1017 SCOP_SAVED_SCHEDULE (scop) = NULL;
1018 POLY_SCOP_P (scop) = false;
1026 free_scop (scop_p scop)
1031 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
1034 VEC_free (poly_bb_p, heap, SCOP_BBS (scop));
1036 if (SCOP_CONTEXT (scop))
1037 ppl_delete_Pointset_Powerset_C_Polyhedron (SCOP_CONTEXT (scop));
1039 htab_delete (SCOP_ORIGINAL_PDDRS (scop));
1040 free_lst (SCOP_ORIGINAL_SCHEDULE (scop));
1041 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
1042 free_lst (SCOP_SAVED_SCHEDULE (scop));
1046 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
1050 openscop_print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity)
1053 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
1055 if (!PBB_DOMAIN (pbb))
1060 fprintf (file, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index);
1061 fprintf (file, "#eq");
1063 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
1064 fprintf (file, " i%d", (int) i);
1066 for (i = 0; i < pbb_nb_params (pbb); i++)
1067 fprintf (file, " p%d", (int) i);
1069 fprintf (file, " cst\n");
1072 if (PBB_DOMAIN (pbb))
1073 openscop_print_powerset_matrix (file, PBB_DOMAIN (pbb),
1074 pbb_dim_iter_domain (pbb),
1077 pbb_nb_params (pbb));
1079 fprintf (file, "0\n");
1082 fprintf (file, "#)\n");
1085 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
1088 print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity)
1091 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
1093 if (!PBB_DOMAIN (pbb))
1098 fprintf (file, "# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index);
1099 fprintf (file, "# eq");
1101 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
1102 fprintf (file, " i%d", (int) i);
1104 for (i = 0; i < pbb_nb_params (pbb); i++)
1105 fprintf (file, " p%d", (int) i);
1107 fprintf (file, " cst\n");
1110 if (PBB_DOMAIN (pbb))
1111 ppl_print_powerset_matrix (file, PBB_DOMAIN (pbb));
1113 fprintf (file, "0\n");
1116 fprintf (file, "#)\n");
1119 /* Dump the cases of a graphite basic block GBB on FILE. */
1122 dump_gbb_cases (FILE *file, gimple_bb_p gbb)
1126 VEC (gimple, heap) *cases;
1131 cases = GBB_CONDITION_CASES (gbb);
1132 if (VEC_empty (gimple, cases))
1135 fprintf (file, "# cases bb_%d (\n", GBB_BB (gbb)->index);
1137 FOR_EACH_VEC_ELT (gimple, cases, i, stmt)
1139 fprintf (file, "# ");
1140 print_gimple_stmt (file, stmt, 0, 0);
1143 fprintf (file, "#)\n");
1146 /* Dump conditions of a graphite basic block GBB on FILE. */
1149 dump_gbb_conditions (FILE *file, gimple_bb_p gbb)
1153 VEC (gimple, heap) *conditions;
1158 conditions = GBB_CONDITIONS (gbb);
1159 if (VEC_empty (gimple, conditions))
1162 fprintf (file, "# conditions bb_%d (\n", GBB_BB (gbb)->index);
1164 FOR_EACH_VEC_ELT (gimple, conditions, i, stmt)
1166 fprintf (file, "# ");
1167 print_gimple_stmt (file, stmt, 0, 0);
1170 fprintf (file, "#)\n");
1173 /* Print to FILE all the data references of PBB, at some VERBOSITY
1177 print_pdrs (FILE *file, poly_bb_p pbb, int verbosity)
1184 if (VEC_length (poly_dr_p, PBB_DRS (pbb)) == 0)
1187 fprintf (file, "# Access informations are not provided\n");\
1188 fprintf (file, "0\n");
1193 fprintf (file, "# Data references (\n");
1196 fprintf (file, "# Access informations are provided\n");
1197 fprintf (file, "1\n");
1199 FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr)
1200 if (PDR_TYPE (pdr) == PDR_READ)
1206 fprintf (file, "# Read data references (\n");
1209 fprintf (file, "# Read access informations\n");
1210 fprintf (file, "%d\n", nb_reads);
1212 FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr)
1213 if (PDR_TYPE (pdr) == PDR_READ)
1214 print_pdr (file, pdr, verbosity);
1217 fprintf (file, "#)\n");
1220 fprintf (file, "# Write data references (\n");
1223 fprintf (file, "# Write access informations\n");
1224 fprintf (file, "%d\n", nb_writes);
1226 FOR_EACH_VEC_ELT (poly_dr_p, PBB_DRS (pbb), i, pdr)
1227 if (PDR_TYPE (pdr) != PDR_READ)
1228 print_pdr (file, pdr, verbosity);
1231 fprintf (file, "#)\n");
1234 fprintf (file, "#)\n");
1237 /* Print to STDERR all the data references of PBB. */
1240 debug_pdrs (poly_bb_p pbb, int verbosity)
1242 print_pdrs (stderr, pbb, verbosity);
1245 /* Print to FILE the body of PBB, at some VERBOSITY level.
1246 If statement_body_provided is false statement body is not printed. */
1249 print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity,
1250 bool statement_body_provided)
1253 fprintf (file, "# Body (\n");
1255 if (!statement_body_provided)
1258 fprintf (file, "# Statement body is not provided\n");
1260 fprintf (file, "0\n");
1263 fprintf (file, "#)\n");
1268 fprintf (file, "# Statement body is provided\n");
1269 fprintf (file, "1\n");
1272 fprintf (file, "# Original iterator names\n# Iterator names are not provided yet.\n");
1275 fprintf (file, "# Statement body\n");
1277 fprintf (file, "{\n");
1278 dump_bb (pbb_bb (pbb), file, 0);
1279 fprintf (file, "}\n");
1282 fprintf (file, "#)\n");
1285 /* Print to FILE the domain and scattering function of PBB, at some
1289 print_pbb (FILE *file, poly_bb_p pbb, int verbosity)
1293 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
1294 dump_gbb_conditions (file, PBB_BLACK_BOX (pbb));
1295 dump_gbb_cases (file, PBB_BLACK_BOX (pbb));
1298 openscop_print_pbb_domain (file, pbb, verbosity);
1299 print_scattering_function (file, pbb, verbosity);
1300 print_pdrs (file, pbb, verbosity);
1301 print_pbb_body (file, pbb, verbosity, false);
1304 fprintf (file, "#)\n");
1307 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
1310 print_scop_params (FILE *file, scop_p scop, int verbosity)
1316 fprintf (file, "# parameters (\n");
1318 if (VEC_length (tree, SESE_PARAMS (SCOP_REGION (scop))))
1321 fprintf (file, "# Parameter names are provided\n");
1323 fprintf (file, "1\n");
1326 fprintf (file, "# Parameter names\n");
1331 fprintf (file, "# Parameter names are not provided\n");
1332 fprintf (file, "0\n");
1335 FOR_EACH_VEC_ELT (tree, SESE_PARAMS (SCOP_REGION (scop)), i, t)
1337 print_generic_expr (file, t, 0);
1338 fprintf (file, " ");
1341 fprintf (file, "\n");
1344 fprintf (file, "#)\n");
1347 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
1351 openscop_print_scop_context (FILE *file, scop_p scop, int verbosity)
1357 fprintf (file, "# Context (\n");
1358 fprintf (file, "#eq");
1360 for (i = 0; i < scop_nb_params (scop); i++)
1361 fprintf (file, " p%d", (int) i);
1363 fprintf (file, " cst\n");
1366 if (SCOP_CONTEXT (scop))
1367 openscop_print_powerset_matrix (file, SCOP_CONTEXT (scop), 0, 0, 0,
1368 scop_nb_params (scop));
1370 fprintf (file, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop) + 2,
1371 (int) scop_nb_params (scop));
1374 fprintf (file, "# )\n");
1377 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
1380 print_scop_context (FILE *file, scop_p scop, int verbosity)
1386 fprintf (file, "# Context (\n");
1387 fprintf (file, "#eq");
1389 for (i = 0; i < scop_nb_params (scop); i++)
1390 fprintf (file, " p%d", (int) i);
1392 fprintf (file, " cst\n");
1395 if (SCOP_CONTEXT (scop))
1396 ppl_print_powerset_matrix (file, SCOP_CONTEXT (scop));
1398 fprintf (file, "0 %d\n", (int) scop_nb_params (scop) + 2);
1401 fprintf (file, "# )\n");
1404 /* Print to FILE the SCOP, at some VERBOSITY level. */
1407 print_scop (FILE *file, scop_p scop, int verbosity)
1412 fprintf (file, "SCoP 1\n#(\n");
1413 fprintf (file, "# Language\nGimple\n");
1414 openscop_print_scop_context (file, scop, verbosity);
1415 print_scop_params (file, scop, verbosity);
1418 fprintf (file, "# Number of statements\n");
1420 fprintf (file, "%d\n",VEC_length (poly_bb_p, SCOP_BBS (scop)));
1422 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
1423 print_pbb (file, pbb, verbosity);
1427 fprintf (file, "# original_lst (\n");
1428 print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0);
1429 fprintf (file, "\n#)\n");
1431 fprintf (file, "# transformed_lst (\n");
1432 print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0);
1433 fprintf (file, "\n#)\n");
1436 fprintf (file, "#)\n");
1439 /* Print to FILE the input file that CLooG would expect as input, at
1440 some VERBOSITY level. */
1443 print_cloog (FILE *file, scop_p scop, int verbosity)
1448 fprintf (file, "# SCoP (generated by GCC/Graphite\n");
1450 fprintf (file, "# CLooG output language\n");
1451 fprintf (file, "c\n");
1453 print_scop_context (file, scop, verbosity);
1454 print_scop_params (file, scop, verbosity);
1457 fprintf (file, "# Number of statements\n");
1459 fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
1461 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
1464 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
1466 print_pbb_domain (file, pbb, verbosity);
1467 fprintf (file, "0 0 0");
1470 fprintf (file, "# For future CLooG options.\n");
1472 fprintf (file, "\n");
1475 fprintf (file, "#)\n");
1478 fprintf (file, "0");
1480 fprintf (file, "# Don't set the iterator names.\n");
1482 fprintf (file, "\n");
1485 fprintf (file, "# Number of scattering functions\n");
1487 fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
1488 unify_scattering_dimensions (scop);
1490 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
1492 if (!PBB_TRANSFORMED (pbb)
1493 || !(PBB_TRANSFORMED_SCATTERING (pbb)
1494 || PBB_ORIGINAL_SCATTERING (pbb)))
1498 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
1500 print_scattering_function_1 (file, pbb, verbosity);
1503 fprintf (file, "#)\n");
1506 fprintf (file, "0");
1508 fprintf (file, "# Don't set the scattering dimension names.\n");
1510 fprintf (file, "\n");
1512 fprintf (file, "#)\n");
1515 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
1518 debug_pbb_domain (poly_bb_p pbb, int verbosity)
1520 print_pbb_domain (stderr, pbb, verbosity);
1523 /* Print to FILE the domain and scattering function of PBB, at some
1527 debug_pbb (poly_bb_p pbb, int verbosity)
1529 print_pbb (stderr, pbb, verbosity);
1532 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
1535 debug_scop_context (scop_p scop, int verbosity)
1537 print_scop_context (stderr, scop, verbosity);
1540 /* Print to STDERR the SCOP, at some VERBOSITY level. */
1543 debug_scop (scop_p scop, int verbosity)
1545 print_scop (stderr, scop, verbosity);
1548 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
1552 debug_cloog (scop_p scop, int verbosity)
1554 print_cloog (stderr, scop, verbosity);
1557 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
1561 debug_scop_params (scop_p scop, int verbosity)
1563 print_scop_params (stderr, scop, verbosity);
1567 /* The dimension in the transformed scattering polyhedron of PBB
1568 containing the scattering iterator for the loop at depth LOOP_DEPTH. */
1571 psct_scattering_dim_for_loop_depth (poly_bb_p pbb, graphite_dim_t loop_depth)
1573 ppl_const_Constraint_System_t pcs;
1574 ppl_Constraint_System_const_iterator_t cit, cend;
1575 ppl_const_Constraint_t cstr;
1576 ppl_Polyhedron_t ph = PBB_TRANSFORMED_SCATTERING (pbb);
1577 ppl_dimension_type iter = psct_iterator_dim (pbb, loop_depth);
1578 ppl_Linear_Expression_t expr;
1579 ppl_Coefficient_t coef;
1584 ppl_new_Coefficient (&coef);
1585 ppl_Polyhedron_get_constraints (ph, &pcs);
1586 ppl_new_Constraint_System_const_iterator (&cit);
1587 ppl_new_Constraint_System_const_iterator (&cend);
1589 for (ppl_Constraint_System_begin (pcs, cit),
1590 ppl_Constraint_System_end (pcs, cend);
1591 !ppl_Constraint_System_const_iterator_equal_test (cit, cend);
1592 ppl_Constraint_System_const_iterator_increment (cit))
1594 ppl_Constraint_System_const_iterator_dereference (cit, &cstr);
1595 ppl_new_Linear_Expression_from_Constraint (&expr, cstr);
1596 ppl_Linear_Expression_coefficient (expr, iter, coef);
1597 ppl_Coefficient_to_mpz_t (coef, val);
1599 if (mpz_sgn (val) == 0)
1601 ppl_delete_Linear_Expression (expr);
1605 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
1607 ppl_dimension_type scatter = psct_scattering_dim (pbb, i);
1609 ppl_Linear_Expression_coefficient (expr, scatter, coef);
1610 ppl_Coefficient_to_mpz_t (coef, val);
1612 if (mpz_sgn (val) != 0)
1615 ppl_delete_Linear_Expression (expr);
1616 ppl_delete_Coefficient (coef);
1617 ppl_delete_Constraint_System_const_iterator (cit);
1618 ppl_delete_Constraint_System_const_iterator (cend);
1628 /* Returns the number of iterations RES of the loop around PBB at
1629 time(scattering) dimension TIME_DEPTH. */
1632 pbb_number_of_iterations_at_time (poly_bb_p pbb,
1633 graphite_dim_t time_depth,
1636 ppl_Pointset_Powerset_C_Polyhedron_t domain, sctr_lb, sctr_ub;
1637 ppl_dimension_type domain_dim, sctr_dim;
1638 ppl_Linear_Expression_t le;
1639 mpz_t lb, ub, diff, one;
1642 ppl_Polyhedron_space_dimension (PBB_TRANSFORMED_SCATTERING (pbb), &sctr_dim);
1644 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
1645 (&domain, PBB_DOMAIN (pbb));
1647 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (domain, &domain_dim);
1652 mpz_set_si (one, 1);
1654 /* Compute the upper bound on the original iteration domain and add
1655 that upper bound to the scattering. */
1656 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
1657 (&sctr_ub, PBB_TRANSFORMED_SCATTERING (pbb));
1658 for (i = 0; i < (int) domain_dim; i++)
1660 ppl_Linear_Expression_t eq;
1661 ppl_Constraint_t pc;
1662 ppl_Constraint_System_t cs;
1663 ppl_Polyhedron_t ph;
1664 ppl_Pointset_Powerset_C_Polyhedron_t pph;
1666 ppl_new_Linear_Expression_with_dimension (&le, domain_dim);
1667 ppl_set_coef (le, i, 1);
1668 ppl_min_for_le_pointset (domain, le, lb);
1669 ppl_max_for_le_pointset (domain, le, ub);
1670 mpz_sub (diff, ub, lb);
1671 mpz_add (diff, diff, one);
1673 ppl_new_Linear_Expression_with_dimension (&eq, sctr_dim);
1674 ppl_set_coef (eq, psct_iterator_dim (pbb, i), -1);
1675 ppl_set_inhomogeneous_gmp (eq, diff);
1677 ppl_new_Constraint (&pc, eq, PPL_CONSTRAINT_TYPE_EQUAL);
1678 ppl_new_Constraint_System_from_Constraint (&cs, pc);
1679 ppl_new_C_Polyhedron_from_Constraint_System (&ph, cs);
1680 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&pph, ph);
1681 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr_ub, pph);
1683 ppl_delete_Linear_Expression (le);
1684 ppl_delete_Linear_Expression (eq);
1685 ppl_delete_Polyhedron (ph);
1686 ppl_delete_Pointset_Powerset_C_Polyhedron (pph);
1687 ppl_delete_Constraint (pc);
1688 ppl_delete_Constraint_System (cs);
1691 /* Compute the lower bound on the original iteration domain. */
1692 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
1693 (&sctr_lb, PBB_TRANSFORMED_SCATTERING (pbb));
1694 for (i = 0; i < (int) domain_dim; i++)
1696 ppl_Linear_Expression_t eq;
1697 ppl_Constraint_t pc;
1698 ppl_Constraint_System_t cs;
1699 ppl_Polyhedron_t ph;
1700 ppl_Pointset_Powerset_C_Polyhedron_t pph;
1702 ppl_new_Linear_Expression_with_dimension (&le, domain_dim);
1703 ppl_set_coef (le, i, 1);
1704 ppl_min_for_le_pointset (domain, le, lb);
1706 ppl_new_Linear_Expression_with_dimension (&eq, sctr_dim);
1707 ppl_set_coef (eq, psct_iterator_dim (pbb, i), -1);
1708 ppl_set_inhomogeneous_gmp (eq, lb);
1710 ppl_new_Constraint (&pc, eq, PPL_CONSTRAINT_TYPE_EQUAL);
1711 ppl_new_Constraint_System_from_Constraint (&cs, pc);
1712 ppl_new_C_Polyhedron_from_Constraint_System (&ph, cs);
1713 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&pph, ph);
1714 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr_lb, pph);
1716 ppl_delete_Linear_Expression (le);
1717 ppl_delete_Linear_Expression (eq);
1718 ppl_delete_Polyhedron (ph);
1719 ppl_delete_Pointset_Powerset_C_Polyhedron (pph);
1720 ppl_delete_Constraint (pc);
1721 ppl_delete_Constraint_System (cs);
1724 /* Extract the number of iterations. */
1725 ppl_new_Linear_Expression_with_dimension (&le, sctr_dim);
1726 ppl_set_coef (le, time_depth, 1);
1727 ppl_min_for_le_pointset (sctr_lb, le, lb);
1728 ppl_max_for_le_pointset (sctr_ub, le, ub);
1729 mpz_sub (res, ub, lb);
1735 ppl_delete_Pointset_Powerset_C_Polyhedron (sctr_ub);
1736 ppl_delete_Pointset_Powerset_C_Polyhedron (sctr_lb);
1739 /* Translates LOOP to LST. */
1742 loop_to_lst (loop_p loop, VEC (poly_bb_p, heap) *bbs, int *i)
1745 VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
1747 for (; VEC_iterate (poly_bb_p, bbs, *i, pbb); (*i)++)
1750 basic_block bb = GBB_BB (PBB_BLACK_BOX (pbb));
1752 if (bb->loop_father == loop)
1753 stmt = new_lst_stmt (pbb);
1754 else if (flow_bb_inside_loop_p (loop, bb))
1756 loop_p next = loop->inner;
1758 while (next && !flow_bb_inside_loop_p (next, bb))
1761 stmt = loop_to_lst (next, bbs, i);
1766 return new_lst_loop (seq);
1769 VEC_safe_push (lst_p, heap, seq, stmt);
1772 return new_lst_loop (seq);
1775 /* Reads the original scattering of the SCOP and returns an LST
1779 scop_to_lst (scop_p scop)
1782 int i, n = VEC_length (poly_bb_p, SCOP_BBS (scop));
1783 VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
1784 sese region = SCOP_REGION (scop);
1786 for (i = 0; i < n; i++)
1788 poly_bb_p pbb = VEC_index (poly_bb_p, SCOP_BBS (scop), i);
1789 loop_p loop = outermost_loop_in_sese (region, GBB_BB (PBB_BLACK_BOX (pbb)));
1791 if (loop_in_sese_p (loop, region))
1792 res = loop_to_lst (loop, SCOP_BBS (scop), &i);
1794 res = new_lst_stmt (pbb);
1796 VEC_safe_push (lst_p, heap, seq, res);
1799 res = new_lst_loop (seq);
1800 SCOP_ORIGINAL_SCHEDULE (scop) = res;
1801 SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (res);
1804 /* Print to FILE on a new line COLUMN white spaces. */
1807 lst_indent_to (FILE *file, int column)
1812 fprintf (file, "\n#");
1814 for (i = 0; i < column; i++)
1815 fprintf (file, " ");
1818 /* Print LST to FILE with INDENT spaces of indentation. */
1821 print_lst (FILE *file, lst_p lst, int indent)
1826 lst_indent_to (file, indent);
1828 if (LST_LOOP_P (lst))
1833 if (LST_LOOP_FATHER (lst))
1834 fprintf (file, "%d (loop", lst_dewey_number (lst));
1836 fprintf (file, "#(root");
1838 FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
1839 print_lst (file, l, indent + 2);
1841 fprintf (file, ")");
1844 fprintf (file, "%d stmt_%d", lst_dewey_number (lst), pbb_index (LST_PBB (lst)));
1847 /* Print LST to STDERR. */
1850 debug_lst (lst_p lst)
1852 print_lst (stderr, lst, 0);
1855 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1858 dot_lst_1 (FILE *file, lst_p lst)
1863 if (LST_LOOP_P (lst))
1868 if (!LST_LOOP_FATHER (lst))
1869 fprintf (file, "L -> L_%d_%d\n",
1871 lst_dewey_number (lst));
1873 fprintf (file, "L_%d_%d -> L_%d_%d\n",
1874 lst_depth (LST_LOOP_FATHER (lst)),
1875 lst_dewey_number (LST_LOOP_FATHER (lst)),
1877 lst_dewey_number (lst));
1879 FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
1880 dot_lst_1 (file, l);
1884 fprintf (file, "L_%d_%d -> S_%d\n",
1885 lst_depth (LST_LOOP_FATHER (lst)),
1886 lst_dewey_number (LST_LOOP_FATHER (lst)),
1887 pbb_index (LST_PBB (lst)));
1891 /* Display the LST using dotty. */
1896 /* When debugging, enable the following code. This cannot be used
1897 in production compilers because it calls "system". */
1899 FILE *stream = fopen ("/tmp/lst.dot", "w");
1900 gcc_assert (stream);
1902 fputs ("digraph all {\n", stream);
1903 dot_lst_1 (stream, lst);
1904 fputs ("}\n\n", stream);
1907 system ("dotty /tmp/lst.dot &");
1909 fputs ("digraph all {\n", stderr);
1910 dot_lst_1 (stderr, lst);
1911 fputs ("}\n\n", stderr);