Fix columns order in openscop.
[official-gcc/graphite-test-results.git] / gcc / graphite-poly.c
blob0ff332bd17634c9928c7dd5785e26575b5271be5
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)
11 any later version.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "ggc.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "output.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"
34 #include "toplev.h"
35 #include "tree-dump.h"
36 #include "timevar.h"
37 #include "cfgloop.h"
38 #include "tree-chrec.h"
39 #include "tree-data-ref.h"
40 #include "tree-scalar-evolution.h"
41 #include "tree-pass.h"
42 #include "domwalk.h"
43 #include "value-prof.h"
44 #include "pointer-set.h"
45 #include "gimple.h"
46 #include "params.h"
47 #include "graphite-cloog-util.h"
49 #ifdef HAVE_cloog
50 #include "ppl_c.h"
51 #include "sese.h"
52 #include "graphite-ppl.h"
53 #include "graphite.h"
54 #include "graphite-poly.h"
55 #include "graphite-dependences.h"
57 /* Return the maximal loop depth in SCOP. */
59 int
60 scop_max_loop_depth (scop_p scop)
62 int i;
63 poly_bb_p pbb;
64 int max_nb_loops = 0;
66 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
68 int nb_loops = pbb_dim_iter_domain (pbb);
69 if (max_nb_loops < nb_loops)
70 max_nb_loops = nb_loops;
73 return max_nb_loops;
76 /* Extend the scattering matrix of PBB to MAX_SCATTERING scattering
77 dimensions. */
79 static void
80 extend_scattering (poly_bb_p pbb, int max_scattering)
82 ppl_dimension_type nb_old_dims, nb_new_dims;
83 int nb_added_dims, i;
84 ppl_Coefficient_t coef;
85 mpz_t one;
87 nb_added_dims = max_scattering - pbb_nb_scattering_transform (pbb);
88 mpz_init (one);
89 mpz_set_si (one, 1);
90 ppl_new_Coefficient (&coef);
91 ppl_assign_Coefficient_from_mpz_t (coef, one);
93 gcc_assert (nb_added_dims >= 0);
95 nb_old_dims = pbb_nb_scattering_transform (pbb) + pbb_dim_iter_domain (pbb)
96 + scop_nb_params (PBB_SCOP (pbb));
97 nb_new_dims = nb_old_dims + nb_added_dims;
99 ppl_insert_dimensions (PBB_TRANSFORMED_SCATTERING (pbb),
100 pbb_nb_scattering_transform (pbb), nb_added_dims);
101 PBB_NB_SCATTERING_TRANSFORM (pbb) += nb_added_dims;
103 /* Add identity matrix for the added dimensions. */
104 for (i = max_scattering - nb_added_dims; i < max_scattering; i++)
106 ppl_Constraint_t cstr;
107 ppl_Linear_Expression_t expr;
109 ppl_new_Linear_Expression_with_dimension (&expr, nb_new_dims);
110 ppl_Linear_Expression_add_to_coefficient (expr, i, coef);
111 ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_EQUAL);
112 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb), cstr);
113 ppl_delete_Constraint (cstr);
114 ppl_delete_Linear_Expression (expr);
117 ppl_delete_Coefficient (coef);
118 mpz_clear (one);
121 /* All scattering matrices in SCOP will have the same number of scattering
122 dimensions. */
125 unify_scattering_dimensions (scop_p scop)
127 int i;
128 poly_bb_p pbb;
129 graphite_dim_t max_scattering = 0;
131 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
132 max_scattering = MAX (pbb_nb_scattering_transform (pbb), max_scattering);
134 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
135 extend_scattering (pbb, max_scattering);
137 return max_scattering;
140 /* Print to FILE the pdr PH in OpenScop format. NB_SUBSCRIPTS is the number
141 of subscripts in PH, ALIAS_SET_DIM is the dimension of the alias set and
142 NB_PARAMS is the number of parameters in PH. */
144 static void
145 openscop_print_pdr_polyhedron (FILE *file, ppl_const_Polyhedron_t ph,
146 int nb_subscripts, int alias_set_dimension,
147 int nb_params)
149 int input, locals, output;
150 ppl_dimension_type alias_set_dim = (ppl_dimension_type) alias_set_dimension;
151 ppl_dimension_type sub_dim_last = alias_set_dim + nb_subscripts;
152 ppl_dimension_type *map, i, ph_space_dim = sub_dim_last + 1;
153 ppl_Polyhedron_t pph;
155 ppl_new_C_Polyhedron_from_C_Polyhedron (&pph, ph);
157 map = (ppl_dimension_type *) XNEWVEC (ppl_dimension_type, ph_space_dim);
159 for (i = 0; i < alias_set_dim - 1; i++)
160 map[i] = nb_subscripts + 1 + i;
162 for (i = alias_set_dim - 1; i < sub_dim_last; i++)
163 map[i] = i - alias_set_dim + 1;
165 ppl_Polyhedron_map_space_dimensions (pph, map, ph_space_dim - 1);
167 locals = 0;
168 input = alias_set_dim - nb_params - 1;
170 /* According to OpenScop specification, the alias set column is a part of
171 the output columns. */
172 output = nb_subscripts + 1;
174 openscop_print_polyhedron_matrix (file, pph, output, input, locals, nb_params);
177 /* Print to FILE the powerset PDR. NB_SUBSCRIPTS is the number of subscripts
178 in PDR, ALIAS_SET_DIM is the dimension of the alias set in PDR and
179 NB_PARAMS is the number of parameters in PDR. */
181 static void
182 openscop_print_pdr_powerset (FILE *file,
183 ppl_Pointset_Powerset_C_Polyhedron_t ps,
184 int nb_subscripts,
185 int alias_set_dim,
186 int nb_params)
188 size_t nb_disjuncts;
189 ppl_Pointset_Powerset_C_Polyhedron_iterator_t it, end;
191 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&it);
192 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&end);
194 ppl_Pointset_Powerset_C_Polyhedron_size (ps, &nb_disjuncts);
195 fprintf (file, "%d\n", (int) nb_disjuncts);
197 for (ppl_Pointset_Powerset_C_Polyhedron_iterator_begin (ps, it),
198 ppl_Pointset_Powerset_C_Polyhedron_iterator_end (ps, end);
199 !ppl_Pointset_Powerset_C_Polyhedron_iterator_equal_test (it, end);
200 ppl_Pointset_Powerset_C_Polyhedron_iterator_increment (it))
202 ppl_const_Polyhedron_t ph;
204 ppl_Pointset_Powerset_C_Polyhedron_iterator_dereference (it, &ph);
205 openscop_print_pdr_polyhedron (file, ph, nb_subscripts, alias_set_dim,
206 nb_params);
209 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (it);
210 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (end);
213 /* Print to FILE the powerset PS in its OpenScop matrix form. */
215 static void
216 openscop_print_powerset_matrix (FILE *file,
217 ppl_Pointset_Powerset_C_Polyhedron_t ps,
218 int output, int input, int locals,
219 int params)
221 size_t nb_disjuncts;
222 ppl_Pointset_Powerset_C_Polyhedron_iterator_t it, end;
224 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&it);
225 ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&end);
227 ppl_Pointset_Powerset_C_Polyhedron_size (ps, &nb_disjuncts);
228 fprintf (file, "%d\n", (int) nb_disjuncts);
230 for (ppl_Pointset_Powerset_C_Polyhedron_iterator_begin (ps, it),
231 ppl_Pointset_Powerset_C_Polyhedron_iterator_end (ps, end);
232 !ppl_Pointset_Powerset_C_Polyhedron_iterator_equal_test (it, end);
233 ppl_Pointset_Powerset_C_Polyhedron_iterator_increment (it))
235 ppl_const_Polyhedron_t ph;
237 ppl_Pointset_Powerset_C_Polyhedron_iterator_dereference (it, &ph);
238 openscop_print_polyhedron_matrix (file, ph, output, input, locals,
239 params);
242 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (it);
243 ppl_delete_Pointset_Powerset_C_Polyhedron_iterator (end);
246 /* Prints to FILE the scattering function of PBB in OpenScop format, at some
247 VERBOSITY level. */
249 static void
250 openscop_print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity)
252 graphite_dim_t i;
253 ppl_const_Polyhedron_t ph;
255 if (verbosity > 0)
257 fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb));
258 fprintf (file, "# eq");
260 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
261 fprintf (file, " s%d", (int) i);
263 for (i = 0; i < pbb_nb_local_vars (pbb); i++)
264 fprintf (file, " lv%d", (int) i);
266 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
267 fprintf (file, " i%d", (int) i);
269 for (i = 0; i < pbb_nb_params (pbb); i++)
270 fprintf (file, " p%d", (int) i);
272 fprintf (file, " cst\n");
275 /* Number of disjunct components. Remove this when
276 PBB_TRANSFORMED_SCATTERING will be a pointset_powerset. */
277 fprintf (file, "1\n");
279 ph = PBB_TRANSFORMED_SCATTERING (pbb)
280 ? PBB_TRANSFORMED_SCATTERING (pbb)
281 : PBB_ORIGINAL_SCATTERING (pbb);
283 openscop_print_polyhedron_matrix (file, ph,
284 pbb_nb_scattering_transform (pbb),
285 pbb_dim_iter_domain (pbb),
286 pbb_nb_local_vars (pbb),
287 pbb_nb_params (pbb));
289 if (verbosity > 0)
290 fprintf (file, "#)\n");
293 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
294 level. */
296 static void
297 print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity)
299 graphite_dim_t i;
301 if (verbosity > 0)
303 fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb));
304 fprintf (file, "# eq");
306 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
307 fprintf (file, " s%d", (int) i);
309 for (i = 0; i < pbb_nb_local_vars (pbb); i++)
310 fprintf (file, " lv%d", (int) i);
312 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
313 fprintf (file, " i%d", (int) i);
315 for (i = 0; i < pbb_nb_params (pbb); i++)
316 fprintf (file, " p%d", (int) i);
318 fprintf (file, " cst\n");
321 /* Number of disjunct components. Remove this when
322 PBB_TRANSFORMED_SCATTERING will be a pointset_powerset. */
323 fprintf (file, "1\n");
324 ppl_print_polyhedron_matrix (file, PBB_TRANSFORMED_SCATTERING (pbb)
325 ? PBB_TRANSFORMED_SCATTERING (pbb)
326 : PBB_ORIGINAL_SCATTERING (pbb));
328 if (verbosity > 0)
329 fprintf (file, "#)\n");
332 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
333 level. */
335 void
336 print_scattering_function (FILE *file, poly_bb_p pbb, int verbosity)
338 if (!PBB_TRANSFORMED (pbb))
339 return;
341 if (PBB_TRANSFORMED_SCATTERING (pbb)
342 || PBB_ORIGINAL_SCATTERING (pbb))
344 if (verbosity > 0)
345 fprintf (file, "# Scattering function is provided\n");
347 fprintf (file, "1\n");
349 else
351 if (verbosity > 0)
352 fprintf (file, "# Scattering function is not provided\n");
354 fprintf (file, "0\n");
355 return;
358 openscop_print_scattering_function_1 (file, pbb, verbosity);
360 if (verbosity > 0)
361 fprintf (file, "# Scattering names are not provided\n");
363 fprintf (file, "0\n");
367 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
368 level. */
370 void
371 print_iteration_domain (FILE *file, poly_bb_p pbb, int verbosity)
373 print_pbb_domain (file, pbb, verbosity);
376 /* Prints to FILE the scattering functions of every PBB of SCOP. */
378 void
379 print_scattering_functions (FILE *file, scop_p scop, int verbosity)
381 int i;
382 poly_bb_p pbb;
384 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
385 print_scattering_function (file, pbb, verbosity);
388 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
389 VERBOSITY level. */
391 void
392 print_iteration_domains (FILE *file, scop_p scop, int verbosity)
394 int i;
395 poly_bb_p pbb;
397 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
398 print_iteration_domain (file, pbb, verbosity);
401 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
402 level. */
404 DEBUG_FUNCTION void
405 debug_scattering_function (poly_bb_p pbb, int verbosity)
407 print_scattering_function (stderr, pbb, verbosity);
410 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
411 level. */
413 DEBUG_FUNCTION void
414 debug_iteration_domain (poly_bb_p pbb, int verbosity)
416 print_iteration_domain (stderr, pbb, verbosity);
419 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
420 some VERBOSITY level. */
422 DEBUG_FUNCTION void
423 debug_scattering_functions (scop_p scop, int verbosity)
425 print_scattering_functions (stderr, scop, verbosity);
428 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
429 some VERBOSITY level. */
431 DEBUG_FUNCTION void
432 debug_iteration_domains (scop_p scop, int verbosity)
434 print_iteration_domains (stderr, scop, verbosity);
437 /* Read transforms from file_name.graphite and set the transforms on
438 SCOP. */
440 static bool
441 graphite_read_transforms (scop_p scop)
443 int i;
444 poly_bb_p pbb;
446 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
448 ppl_Polyhedron_t newp;
449 ppl_read_polyhedron_matrix (&newp, graphite_in_file);
450 PBB_TRANSFORMED (pbb) = poly_scattering_new ();
451 PBB_TRANSFORMED_SCATTERING (pbb) = newp;
454 return true;
457 /* Apply graphite transformations to all the basic blocks of SCOP. */
459 bool
460 apply_poly_transforms (scop_p scop)
462 bool transform_done = false;
464 if (flag_graphite_read)
466 transform_done |= graphite_read_transforms (scop);
467 gcc_assert (graphite_legal_transform (scop));
470 /* Generate code even if we did not apply any real transformation.
471 This also allows to check the performance for the identity
472 transformation: GIMPLE -> GRAPHITE -> GIMPLE
473 Keep in mind that CLooG optimizes in control, so the loop structure
474 may change, even if we only use -fgraphite-identity. */
475 if (flag_graphite_identity)
476 transform_done = true;
478 if (flag_loop_parallelize_all)
479 transform_done = true;
481 if (flag_loop_block)
482 transform_done |= scop_do_block (scop);
483 else
485 if (flag_loop_strip_mine)
486 transform_done |= scop_do_strip_mine (scop);
488 if (flag_loop_interchange)
489 transform_done |= scop_do_interchange (scop);
492 if (flag_graphite_write)
493 print_scop (graphite_out_file, scop, 1);
495 return transform_done;
498 /* Returns true when it PDR1 is a duplicate of PDR2: same PBB, and
499 their ACCESSES, TYPE, and NB_SUBSCRIPTS are the same. */
501 static inline bool
502 can_collapse_pdrs (poly_dr_p pdr1, poly_dr_p pdr2)
504 bool res;
505 ppl_Pointset_Powerset_C_Polyhedron_t af1, af2, diff;
507 if (PDR_PBB (pdr1) != PDR_PBB (pdr2)
508 || PDR_NB_SUBSCRIPTS (pdr1) != PDR_NB_SUBSCRIPTS (pdr2)
509 || PDR_TYPE (pdr1) != PDR_TYPE (pdr2))
510 return false;
512 af1 = PDR_ACCESSES (pdr1);
513 af2 = PDR_ACCESSES (pdr2);
514 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
515 (&diff, af1);
516 ppl_Pointset_Powerset_C_Polyhedron_difference_assign (diff, af2);
518 res = ppl_Pointset_Powerset_C_Polyhedron_is_empty (diff);
519 ppl_delete_Pointset_Powerset_C_Polyhedron (diff);
520 return res;
523 /* Removes duplicated data references in PBB. */
525 void
526 pbb_remove_duplicate_pdrs (poly_bb_p pbb)
528 int i, j;
529 poly_dr_p pdr1, pdr2;
530 unsigned n = VEC_length (poly_dr_p, PBB_DRS (pbb));
531 VEC (poly_dr_p, heap) *collapsed = VEC_alloc (poly_dr_p, heap, n);
533 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr1); i++)
534 for (j = 0; VEC_iterate (poly_dr_p, collapsed, j, pdr2); j++)
535 if (!can_collapse_pdrs (pdr1, pdr2))
536 VEC_quick_push (poly_dr_p, collapsed, pdr1);
538 VEC_free (poly_dr_p, heap, collapsed);
539 PBB_PDR_DUPLICATES_REMOVED (pbb) = true;
542 /* Create a new polyhedral data reference and add it to PBB. It is
543 defined by its ACCESSES, its TYPE, and the number of subscripts
544 NB_SUBSCRIPTS. */
546 void
547 new_poly_dr (poly_bb_p pbb, int dr_base_object_set,
548 ppl_Pointset_Powerset_C_Polyhedron_t accesses,
549 enum poly_dr_type type, void *cdr, graphite_dim_t nb_subscripts)
551 static int id = 0;
552 poly_dr_p pdr = XNEW (struct poly_dr);
554 PDR_ID (pdr) = id++;
555 PDR_BASE_OBJECT_SET (pdr) = dr_base_object_set;
556 PDR_NB_REFS (pdr) = 1;
557 PDR_PBB (pdr) = pbb;
558 PDR_ACCESSES (pdr) = accesses;
559 PDR_TYPE (pdr) = type;
560 PDR_CDR (pdr) = cdr;
561 PDR_NB_SUBSCRIPTS (pdr) = nb_subscripts;
562 VEC_safe_push (poly_dr_p, heap, PBB_DRS (pbb), pdr);
565 /* Free polyhedral data reference PDR. */
567 void
568 free_poly_dr (poly_dr_p pdr)
570 ppl_delete_Pointset_Powerset_C_Polyhedron (PDR_ACCESSES (pdr));
571 XDELETE (pdr);
574 /* Create a new polyhedral black box. */
576 void
577 new_poly_bb (scop_p scop, void *black_box, bool reduction)
579 poly_bb_p pbb = XNEW (struct poly_bb);
581 PBB_DOMAIN (pbb) = NULL;
582 PBB_SCOP (pbb) = scop;
583 pbb_set_black_box (pbb, black_box);
584 PBB_TRANSFORMED (pbb) = NULL;
585 PBB_SAVED (pbb) = NULL;
586 PBB_ORIGINAL (pbb) = NULL;
587 PBB_DRS (pbb) = VEC_alloc (poly_dr_p, heap, 3);
588 PBB_IS_REDUCTION (pbb) = reduction;
589 PBB_PDR_DUPLICATES_REMOVED (pbb) = false;
590 VEC_safe_push (poly_bb_p, heap, SCOP_BBS (scop), pbb);
593 /* Free polyhedral black box. */
595 void
596 free_poly_bb (poly_bb_p pbb)
598 int i;
599 poly_dr_p pdr;
601 ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb));
603 if (PBB_TRANSFORMED (pbb))
604 poly_scattering_free (PBB_TRANSFORMED (pbb));
606 if (PBB_SAVED (pbb))
607 poly_scattering_free (PBB_SAVED (pbb));
609 if (PBB_ORIGINAL (pbb))
610 poly_scattering_free (PBB_ORIGINAL (pbb));
612 if (PBB_DRS (pbb))
613 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
614 free_poly_dr (pdr);
616 VEC_free (poly_dr_p, heap, PBB_DRS (pbb));
617 XDELETE (pbb);
620 static void
621 print_pdr_access_layout (FILE *file, poly_bb_p pbb, poly_dr_p pdr)
623 graphite_dim_t i;
625 fprintf (file, "# eq");
627 fprintf (file, " alias");
629 for (i = 0; i < PDR_NB_SUBSCRIPTS (pdr); i++)
630 fprintf (file, " sub%d", (int) i);
632 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
633 fprintf (file, " i%d", (int) i);
635 for (i = 0; i < pbb_nb_params (pbb); i++)
636 fprintf (file, " p%d", (int) i);
638 fprintf (file, " cst\n");
641 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
642 level. */
644 void
645 print_pdr (FILE *file, poly_dr_p pdr, int verbosity)
647 int alias_set_dim;
649 if (verbosity > 1)
651 fprintf (file, "# pdr_%d (", PDR_ID (pdr));
653 switch (PDR_TYPE (pdr))
655 case PDR_READ:
656 fprintf (file, "read \n");
657 break;
659 case PDR_WRITE:
660 fprintf (file, "write \n");
661 break;
663 case PDR_MAY_WRITE:
664 fprintf (file, "may_write \n");
665 break;
667 default:
668 gcc_unreachable ();
671 dump_data_reference (file, (data_reference_p) PDR_CDR (pdr));
674 if (verbosity > 0)
676 fprintf (file, "# data accesses (\n");
677 print_pdr_access_layout (file, PDR_PBB (pdr), pdr);
680 alias_set_dim = pdr_alias_set_dim (pdr) + 1;
682 openscop_print_pdr_powerset (file,
683 PDR_ACCESSES (pdr),
684 PDR_NB_SUBSCRIPTS (pdr),
685 alias_set_dim,
686 pbb_nb_params (PDR_PBB (pdr)));
688 if (verbosity > 0)
689 fprintf (file, "#)\n");
691 if (verbosity > 1)
692 fprintf (file, "#)\n");
695 /* Prints to STDERR the polyhedral data reference PDR, at some
696 VERBOSITY level. */
698 DEBUG_FUNCTION void
699 debug_pdr (poly_dr_p pdr, int verbosity)
701 print_pdr (stderr, pdr, verbosity);
704 /* Creates a new SCOP containing REGION. */
706 scop_p
707 new_scop (void *region)
709 scop_p scop = XNEW (struct scop);
711 SCOP_CONTEXT (scop) = NULL;
712 scop_set_region (scop, region);
713 SCOP_BBS (scop) = VEC_alloc (poly_bb_p, heap, 3);
714 SCOP_ORIGINAL_PDDRS (scop) = htab_create (10, hash_poly_ddr_p,
715 eq_poly_ddr_p, free_poly_ddr);
716 SCOP_ORIGINAL_SCHEDULE (scop) = NULL;
717 SCOP_TRANSFORMED_SCHEDULE (scop) = NULL;
718 SCOP_SAVED_SCHEDULE (scop) = NULL;
719 POLY_SCOP_P (scop) = false;
721 return scop;
724 /* Deletes SCOP. */
726 void
727 free_scop (scop_p scop)
729 int i;
730 poly_bb_p pbb;
732 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
733 free_poly_bb (pbb);
735 VEC_free (poly_bb_p, heap, SCOP_BBS (scop));
737 if (SCOP_CONTEXT (scop))
738 ppl_delete_Pointset_Powerset_C_Polyhedron (SCOP_CONTEXT (scop));
740 htab_delete (SCOP_ORIGINAL_PDDRS (scop));
741 free_lst (SCOP_ORIGINAL_SCHEDULE (scop));
742 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop));
743 free_lst (SCOP_SAVED_SCHEDULE (scop));
744 XDELETE (scop);
747 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
748 level. */
750 static void
751 openscop_print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity)
753 graphite_dim_t i;
754 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
756 if (!PBB_DOMAIN (pbb))
757 return;
759 if (verbosity > 0)
761 fprintf (file, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index);
762 fprintf (file, "# eq");
764 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
765 fprintf (file, " i%d", (int) i);
767 for (i = 0; i < pbb_nb_params (pbb); i++)
768 fprintf (file, " p%d", (int) i);
770 fprintf (file, " cst\n");
773 if (PBB_DOMAIN (pbb))
774 openscop_print_powerset_matrix (file, PBB_DOMAIN (pbb),
775 pbb_dim_iter_domain (pbb),
778 pbb_nb_params (pbb));
779 else
780 fprintf (file, "0\n");
782 if (verbosity > 0)
783 fprintf (file, "#)\n");
786 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
788 void
789 print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity)
791 graphite_dim_t i;
792 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
794 if (!PBB_DOMAIN (pbb))
795 return;
797 if (verbosity > 0)
799 fprintf (file, "# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index);
800 fprintf (file, "# eq");
802 for (i = 0; i < pbb_dim_iter_domain (pbb); i++)
803 fprintf (file, " i%d", (int) i);
805 for (i = 0; i < pbb_nb_params (pbb); i++)
806 fprintf (file, " p%d", (int) i);
808 fprintf (file, " cst\n");
811 if (PBB_DOMAIN (pbb))
812 ppl_print_powerset_matrix (file, PBB_DOMAIN (pbb));
813 else
814 fprintf (file, "0\n");
816 if (verbosity > 0)
817 fprintf (file, "#)\n");
820 /* Dump the cases of a graphite basic block GBB on FILE. */
822 static void
823 dump_gbb_cases (FILE *file, gimple_bb_p gbb)
825 int i;
826 gimple stmt;
827 VEC (gimple, heap) *cases;
829 if (!gbb)
830 return;
832 cases = GBB_CONDITION_CASES (gbb);
833 if (VEC_empty (gimple, cases))
834 return;
836 fprintf (file, "# cases bb_%d (\n", GBB_BB (gbb)->index);
838 for (i = 0; VEC_iterate (gimple, cases, i, stmt); i++)
840 fprintf (file, "# ");
841 print_gimple_stmt (file, stmt, 0, 0);
844 fprintf (file, "#)\n");
847 /* Dump conditions of a graphite basic block GBB on FILE. */
849 static void
850 dump_gbb_conditions (FILE *file, gimple_bb_p gbb)
852 int i;
853 gimple stmt;
854 VEC (gimple, heap) *conditions;
856 if (!gbb)
857 return;
859 conditions = GBB_CONDITIONS (gbb);
860 if (VEC_empty (gimple, conditions))
861 return;
863 fprintf (file, "# conditions bb_%d (\n", GBB_BB (gbb)->index);
865 for (i = 0; VEC_iterate (gimple, conditions, i, stmt); i++)
867 fprintf (file, "# ");
868 print_gimple_stmt (file, stmt, 0, 0);
871 fprintf (file, "#)\n");
874 /* Print to FILE all the data references of PBB, at some VERBOSITY
875 level. */
877 void
878 print_pdrs (FILE *file, poly_bb_p pbb, int verbosity)
880 int i;
881 poly_dr_p pdr;
882 int nb_reads = 0;
883 int nb_writes = 0;
885 if (VEC_length (poly_dr_p, PBB_DRS (pbb)) == 0)
887 if (verbosity > 0)
888 fprintf (file, "# Access informations are not provided\n");\
889 fprintf (file, "0\n");
890 return;
893 if (verbosity > 1)
894 fprintf (file, "# Data references (\n");
896 if (verbosity > 0)
897 fprintf (file, "# Access informations are provided\n");
898 fprintf (file, "1\n");
900 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
901 if (PDR_TYPE (pdr) == PDR_READ)
902 nb_reads++;
903 else
904 nb_writes++;
906 if (verbosity > 1)
907 fprintf (file, "# Read data references (\n");
909 if (verbosity > 0)
910 fprintf (file, "# Read access informations\n");
911 fprintf (file, "%d\n", nb_reads);
913 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
914 if (PDR_TYPE (pdr) == PDR_READ)
915 print_pdr (file, pdr, verbosity);
917 if (verbosity > 1)
918 fprintf (file, "#)\n");
920 if (verbosity > 1)
921 fprintf (file, "# Write data references (\n");
923 if (verbosity > 0)
924 fprintf (file, "# Write access informations\n");
925 fprintf (file, "%d\n", nb_writes);
927 for (i = 0; VEC_iterate (poly_dr_p, PBB_DRS (pbb), i, pdr); i++)
928 if (PDR_TYPE (pdr) != PDR_READ)
929 print_pdr (file, pdr, verbosity);
931 if (verbosity > 1)
932 fprintf (file, "#)\n");
934 if (verbosity > 1)
935 fprintf (file, "#)\n");
938 /* Print to STDERR all the data references of PBB. */
940 DEBUG_FUNCTION void
941 debug_pdrs (poly_bb_p pbb, int verbosity)
943 print_pdrs (stderr, pbb, verbosity);
946 /* Print to FILE the body of PBB, at some VERBOSITY level.
947 If statement_body_provided is false statement body is not printed. */
949 static void
950 print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity,
951 bool statement_body_provided)
953 if (verbosity > 1)
954 fprintf (file, "# Body (\n");
956 if (!statement_body_provided)
958 if (verbosity > 0)
959 fprintf (file, "# Statement body is not provided\n");
961 fprintf (file, "0\n");
962 return;
965 if (verbosity > 0)
966 fprintf (file, "# Statement body is provided\n");
967 fprintf (file, "1\n");
969 if (verbosity > 0)
970 fprintf (file, "# Original iterator names\n# Iterator names are not provided yet.\n");
972 if (verbosity > 0)
973 fprintf (file, "# Statement body\n");
975 fprintf (file, "{\n");
976 dump_bb (pbb_bb (pbb), file, 0);
977 fprintf (file, "}\n");
979 if (verbosity > 1)
980 fprintf (file, "#)\n");
983 /* Print to FILE the domain and scattering function of PBB, at some
984 VERBOSITY level. */
986 void
987 print_pbb (FILE *file, poly_bb_p pbb, int verbosity)
989 if (verbosity > 1)
991 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
992 dump_gbb_conditions (file, PBB_BLACK_BOX (pbb));
993 dump_gbb_cases (file, PBB_BLACK_BOX (pbb));
996 openscop_print_pbb_domain (file, pbb, verbosity);
997 print_scattering_function (file, pbb, verbosity);
998 print_pdrs (file, pbb, verbosity);
999 print_pbb_body (file, pbb, verbosity, false);
1001 if (verbosity > 1)
1002 fprintf (file, "#)\n");
1005 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
1007 void
1008 print_scop_params (FILE *file, scop_p scop, int verbosity)
1010 int i;
1011 tree t;
1013 if (verbosity > 1)
1014 fprintf (file, "# parameters (\n");
1016 if (VEC_length (tree, SESE_PARAMS (SCOP_REGION (scop))))
1018 if (verbosity > 0)
1019 fprintf (file, "# Parameter names are provided\n");
1021 fprintf (file, "1\n");
1023 if (verbosity > 0)
1024 fprintf (file, "# Parameter names\n");
1026 else
1028 if (verbosity > 0)
1029 fprintf (file, "# Parameter names are not provided\n");
1030 fprintf (file, "0\n");
1033 for (i = 0; VEC_iterate (tree, SESE_PARAMS (SCOP_REGION (scop)), i, t); i++)
1035 print_generic_expr (file, t, 0);
1036 fprintf (file, " ");
1039 fprintf (file, "\n");
1041 if (verbosity > 1)
1042 fprintf (file, "#)\n");
1045 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
1046 level. */
1048 static void
1049 openscop_print_scop_context (FILE *file, scop_p scop, int verbosity)
1051 graphite_dim_t i;
1053 if (verbosity > 0)
1055 fprintf (file, "# Context (\n");
1056 fprintf (file, "# eq");
1058 for (i = 0; i < scop_nb_params (scop); i++)
1059 fprintf (file, " p%d", (int) i);
1061 fprintf (file, " cst\n");
1064 if (SCOP_CONTEXT (scop))
1065 openscop_print_powerset_matrix (file, SCOP_CONTEXT (scop), 0, 0, 0,
1066 scop_nb_params (scop));
1067 else
1068 fprintf (file, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop) + 2,
1069 (int) scop_nb_params (scop));
1071 if (verbosity > 0)
1072 fprintf (file, "# )\n");
1075 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
1077 void
1078 print_scop_context (FILE *file, scop_p scop, int verbosity)
1080 graphite_dim_t i;
1082 if (verbosity > 0)
1084 fprintf (file, "# Context (\n");
1085 fprintf (file, "# eq");
1087 for (i = 0; i < scop_nb_params (scop); i++)
1088 fprintf (file, " p%d", (int) i);
1090 fprintf (file, " cst\n");
1093 if (SCOP_CONTEXT (scop))
1094 ppl_print_powerset_matrix (file, SCOP_CONTEXT (scop));
1095 else
1096 fprintf (file, "0 %d\n", (int) scop_nb_params (scop) + 2);
1098 if (verbosity > 0)
1099 fprintf (file, "# )\n");
1102 /* Print to FILE the SCOP header: context, parameters, and statements
1103 number. */
1105 static void
1106 print_scop_header (FILE *file, scop_p scop, int verbosity)
1108 fprintf (file, "SCoP 1\n#(\n");
1109 fprintf (file, "# Language\nGimple\n");
1110 openscop_print_scop_context (file, scop, verbosity);
1111 print_scop_params (file, scop, verbosity);
1113 if (verbosity > 0)
1114 fprintf (file, "# Number of statements\n");
1116 fprintf (file, "%d\n",VEC_length (poly_bb_p, SCOP_BBS (scop)));
1119 /* Print to FILE the SCOP, at some VERBOSITY level. */
1121 void
1122 print_scop (FILE *file, scop_p scop, int verbosity)
1124 int i;
1125 poly_bb_p pbb;
1127 print_scop_header (file, scop, verbosity);
1129 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
1130 print_pbb (file, pbb, verbosity);
1132 if (verbosity > 1)
1134 fprintf (file, "# original_lst (\n");
1135 print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0);
1136 fprintf (file, "\n#)\n");
1138 fprintf (file, "# transformed_lst (\n");
1139 print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0);
1140 fprintf (file, "\n#)\n");
1143 fprintf (file, "#)\n");
1146 /* Print to FILE the input file that CLooG would expect as input, at
1147 some VERBOSITY level. */
1149 void
1150 print_cloog (FILE *file, scop_p scop, int verbosity)
1152 int i;
1153 poly_bb_p pbb;
1155 fprintf (file, "# SCoP (generated by GCC/Graphite\n");
1156 if (verbosity > 0)
1157 fprintf (file, "# CLooG output language\n");
1158 fprintf (file, "c\n");
1160 print_scop_context (file, scop, verbosity);
1161 print_scop_params (file, scop, verbosity);
1163 if (verbosity > 0)
1164 fprintf (file, "# Number of statements\n");
1166 fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
1168 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
1170 if (verbosity > 1)
1171 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
1173 print_pbb_domain (file, pbb, verbosity);
1174 fprintf (file, "0 0 0");
1176 if (verbosity > 0)
1177 fprintf (file, "# For future CLooG options.\n");
1178 else
1179 fprintf (file, "\n");
1181 if (verbosity > 1)
1182 fprintf (file, "#)\n");
1185 fprintf (file, "0");
1186 if (verbosity > 0)
1187 fprintf (file, "# Don't set the iterator names.\n");
1188 else
1189 fprintf (file, "\n");
1191 if (verbosity > 0)
1192 fprintf (file, "# Number of scattering functions\n");
1194 fprintf (file, "%d\n", VEC_length (poly_bb_p, SCOP_BBS (scop)));
1195 unify_scattering_dimensions (scop);
1197 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
1199 if (!PBB_TRANSFORMED (pbb)
1200 || !(PBB_TRANSFORMED_SCATTERING (pbb)
1201 || PBB_ORIGINAL_SCATTERING (pbb)))
1202 continue;
1204 if (verbosity > 1)
1205 fprintf (file, "# pbb_%d (\n", pbb_index (pbb));
1207 print_scattering_function_1 (file, pbb, verbosity);
1209 if (verbosity > 1)
1210 fprintf (file, "#)\n");
1213 fprintf (file, "0");
1214 if (verbosity > 0)
1215 fprintf (file, "# Don't set the scattering dimension names.\n");
1216 else
1217 fprintf (file, "\n");
1219 fprintf (file, "#)\n");
1222 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
1224 DEBUG_FUNCTION void
1225 debug_pbb_domain (poly_bb_p pbb, int verbosity)
1227 print_pbb_domain (stderr, pbb, verbosity);
1230 /* Print to FILE the domain and scattering function of PBB, at some
1231 VERBOSITY level. */
1233 DEBUG_FUNCTION void
1234 debug_pbb (poly_bb_p pbb, int verbosity)
1236 print_pbb (stderr, pbb, verbosity);
1239 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
1241 DEBUG_FUNCTION void
1242 debug_scop_context (scop_p scop, int verbosity)
1244 print_scop_context (stderr, scop, verbosity);
1247 /* Print to STDERR the SCOP, at some VERBOSITY level. */
1249 DEBUG_FUNCTION void
1250 debug_scop (scop_p scop, int verbosity)
1252 print_scop (stderr, scop, verbosity);
1255 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
1256 level. */
1258 DEBUG_FUNCTION void
1259 debug_cloog (scop_p scop, int verbosity)
1261 print_cloog (stderr, scop, verbosity);
1264 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
1265 level. */
1267 DEBUG_FUNCTION void
1268 debug_scop_params (scop_p scop, int verbosity)
1270 print_scop_params (stderr, scop, verbosity);
1274 /* The dimension in the transformed scattering polyhedron of PBB
1275 containing the scattering iterator for the loop at depth LOOP_DEPTH. */
1277 ppl_dimension_type
1278 psct_scattering_dim_for_loop_depth (poly_bb_p pbb, graphite_dim_t loop_depth)
1280 ppl_const_Constraint_System_t pcs;
1281 ppl_Constraint_System_const_iterator_t cit, cend;
1282 ppl_const_Constraint_t cstr;
1283 ppl_Polyhedron_t ph = PBB_TRANSFORMED_SCATTERING (pbb);
1284 ppl_dimension_type iter = psct_iterator_dim (pbb, loop_depth);
1285 ppl_Linear_Expression_t expr;
1286 ppl_Coefficient_t coef;
1287 mpz_t val;
1288 graphite_dim_t i;
1290 mpz_init (val);
1291 ppl_new_Coefficient (&coef);
1292 ppl_Polyhedron_get_constraints (ph, &pcs);
1293 ppl_new_Constraint_System_const_iterator (&cit);
1294 ppl_new_Constraint_System_const_iterator (&cend);
1296 for (ppl_Constraint_System_begin (pcs, cit),
1297 ppl_Constraint_System_end (pcs, cend);
1298 !ppl_Constraint_System_const_iterator_equal_test (cit, cend);
1299 ppl_Constraint_System_const_iterator_increment (cit))
1301 ppl_Constraint_System_const_iterator_dereference (cit, &cstr);
1302 ppl_new_Linear_Expression_from_Constraint (&expr, cstr);
1303 ppl_Linear_Expression_coefficient (expr, iter, coef);
1304 ppl_Coefficient_to_mpz_t (coef, val);
1306 if (mpz_sgn (val) == 0)
1308 ppl_delete_Linear_Expression (expr);
1309 continue;
1312 for (i = 0; i < pbb_nb_scattering_transform (pbb); i++)
1314 ppl_dimension_type scatter = psct_scattering_dim (pbb, i);
1316 ppl_Linear_Expression_coefficient (expr, scatter, coef);
1317 ppl_Coefficient_to_mpz_t (coef, val);
1319 if (mpz_sgn (val) != 0)
1321 mpz_clear (val);
1322 ppl_delete_Linear_Expression (expr);
1323 ppl_delete_Coefficient (coef);
1324 ppl_delete_Constraint_System_const_iterator (cit);
1325 ppl_delete_Constraint_System_const_iterator (cend);
1327 return scatter;
1332 gcc_unreachable ();
1335 /* Returns the number of iterations NITER of the loop around PBB at
1336 depth LOOP_DEPTH. */
1338 void
1339 pbb_number_of_iterations (poly_bb_p pbb,
1340 graphite_dim_t loop_depth,
1341 mpz_t niter)
1343 ppl_Linear_Expression_t le;
1344 ppl_dimension_type dim;
1346 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (PBB_DOMAIN (pbb), &dim);
1347 ppl_new_Linear_Expression_with_dimension (&le, dim);
1348 ppl_set_coef (le, pbb_iterator_dim (pbb, loop_depth), 1);
1349 mpz_set_si (niter, -1);
1350 ppl_max_for_le_pointset (PBB_DOMAIN (pbb), le, niter);
1351 ppl_delete_Linear_Expression (le);
1354 /* Returns the number of iterations NITER of the loop around PBB at
1355 time(scattering) dimension TIME_DEPTH. */
1357 void
1358 pbb_number_of_iterations_at_time (poly_bb_p pbb,
1359 graphite_dim_t time_depth,
1360 mpz_t niter)
1362 ppl_Pointset_Powerset_C_Polyhedron_t ext_domain, sctr;
1363 ppl_Linear_Expression_t le;
1364 ppl_dimension_type dim;
1366 /* Takes together domain and scattering polyhedrons, and composes
1367 them into the bigger polyhedron that has the following format:
1369 t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}
1371 where
1372 | t0..t_{n-1} are time dimensions (scattering dimensions)
1373 | l0..l_{nclc-1} are local variables in scattering function
1374 | i0..i_{niter-1} are original iteration variables
1375 | g0..g_{nparam-1} are global parameters. */
1377 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr,
1378 PBB_TRANSFORMED_SCATTERING (pbb));
1380 /* Extend the iteration domain with the scattering dimensions:
1381 0..0 | 0..0 | i0..i_{niter-1} | g0..g_{nparm-1}. */
1382 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
1383 (&ext_domain, PBB_DOMAIN (pbb));
1384 ppl_insert_dimensions_pointset (ext_domain, 0,
1385 pbb_nb_scattering_transform (pbb)
1386 + pbb_nb_local_vars (pbb));
1388 /* Add to sctr the extended domain. */
1389 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr, ext_domain);
1391 /* Extract the number of iterations. */
1392 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (sctr, &dim);
1393 ppl_new_Linear_Expression_with_dimension (&le, dim);
1394 ppl_set_coef (le, time_depth, 1);
1395 mpz_set_si (niter, -1);
1396 ppl_max_for_le_pointset (sctr, le, niter);
1398 ppl_delete_Linear_Expression (le);
1399 ppl_delete_Pointset_Powerset_C_Polyhedron (sctr);
1400 ppl_delete_Pointset_Powerset_C_Polyhedron (ext_domain);
1403 /* Translates LOOP to LST. */
1405 static lst_p
1406 loop_to_lst (loop_p loop, VEC (poly_bb_p, heap) *bbs, int *i)
1408 poly_bb_p pbb;
1409 VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
1411 for (; VEC_iterate (poly_bb_p, bbs, *i, pbb); (*i)++)
1413 lst_p stmt;
1414 basic_block bb = GBB_BB (PBB_BLACK_BOX (pbb));
1416 if (bb->loop_father == loop)
1417 stmt = new_lst_stmt (pbb);
1418 else if (flow_bb_inside_loop_p (loop, bb))
1420 loop_p next = loop->inner;
1422 while (next && !flow_bb_inside_loop_p (next, bb))
1423 next = next->next;
1425 stmt = loop_to_lst (next, bbs, i);
1427 else
1429 (*i)--;
1430 return new_lst_loop (seq);
1433 VEC_safe_push (lst_p, heap, seq, stmt);
1436 return new_lst_loop (seq);
1439 /* Reads the original scattering of the SCOP and returns an LST
1440 representing it. */
1442 void
1443 scop_to_lst (scop_p scop)
1445 lst_p res;
1446 int i, n = VEC_length (poly_bb_p, SCOP_BBS (scop));
1447 VEC (lst_p, heap) *seq = VEC_alloc (lst_p, heap, 5);
1448 sese region = SCOP_REGION (scop);
1450 for (i = 0; i < n; i++)
1452 poly_bb_p pbb = VEC_index (poly_bb_p, SCOP_BBS (scop), i);
1453 loop_p loop = outermost_loop_in_sese (region, GBB_BB (PBB_BLACK_BOX (pbb)));
1455 if (loop_in_sese_p (loop, region))
1456 res = loop_to_lst (loop, SCOP_BBS (scop), &i);
1457 else
1458 res = new_lst_stmt (pbb);
1460 VEC_safe_push (lst_p, heap, seq, res);
1463 res = new_lst_loop (seq);
1464 SCOP_ORIGINAL_SCHEDULE (scop) = res;
1465 SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (res);
1468 /* Print to FILE on a new line COLUMN white spaces. */
1470 static void
1471 lst_indent_to (FILE *file, int column)
1473 int i;
1475 if (column > 0)
1476 fprintf (file, "\n#");
1478 for (i = 0; i < column; i++)
1479 fprintf (file, " ");
1482 /* Print LST to FILE with INDENT spaces of indentation. */
1484 void
1485 print_lst (FILE *file, lst_p lst, int indent)
1487 if (!lst)
1488 return;
1490 lst_indent_to (file, indent);
1492 if (LST_LOOP_P (lst))
1494 int i;
1495 lst_p l;
1497 if (LST_LOOP_FATHER (lst))
1498 fprintf (file, "%d (loop", lst_dewey_number (lst));
1499 else
1500 fprintf (file, "#(root");
1502 for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
1503 print_lst (file, l, indent + 2);
1505 fprintf (file, ")");
1507 else
1508 fprintf (file, "%d stmt_%d", lst_dewey_number (lst), pbb_index (LST_PBB (lst)));
1511 /* Print LST to STDERR. */
1513 DEBUG_FUNCTION void
1514 debug_lst (lst_p lst)
1516 print_lst (stderr, lst, 0);
1519 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1521 static void
1522 dot_lst_1 (FILE *file, lst_p lst)
1524 if (!lst)
1525 return;
1527 if (LST_LOOP_P (lst))
1529 int i;
1530 lst_p l;
1532 if (!LST_LOOP_FATHER (lst))
1533 fprintf (file, "L -> L_%d_%d\n",
1534 lst_depth (lst),
1535 lst_dewey_number (lst));
1536 else
1537 fprintf (file, "L_%d_%d -> L_%d_%d\n",
1538 lst_depth (LST_LOOP_FATHER (lst)),
1539 lst_dewey_number (LST_LOOP_FATHER (lst)),
1540 lst_depth (lst),
1541 lst_dewey_number (lst));
1543 for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
1544 dot_lst_1 (file, l);
1547 else
1548 fprintf (file, "L_%d_%d -> S_%d\n",
1549 lst_depth (LST_LOOP_FATHER (lst)),
1550 lst_dewey_number (LST_LOOP_FATHER (lst)),
1551 pbb_index (LST_PBB (lst)));
1555 /* Display the LST using dotty. */
1557 void
1558 dot_lst (lst_p lst)
1560 /* When debugging, enable the following code. This cannot be used
1561 in production compilers because it calls "system". */
1562 #if 1
1563 FILE *stream = fopen ("/tmp/lst.dot", "w");
1564 gcc_assert (stream);
1566 fputs ("digraph all {\n", stream);
1567 dot_lst_1 (stream, lst);
1568 fputs ("}\n\n", stream);
1569 fclose (stream);
1571 system ("dotty /tmp/lst.dot &");
1572 #else
1573 fputs ("digraph all {\n", stderr);
1574 dot_lst_1 (stderr, lst);
1575 fputs ("}\n\n", stderr);
1577 #endif
1580 #endif