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"
47 #include "graphite-cloog-util.h"
52 #include "graphite-ppl.h"
54 #include "graphite-poly.h"
55 #include "graphite-dependences.h"
57 /* Return the maximal loop depth in SCOP. */
60 scop_max_loop_depth (scop_p scop
)
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
;
76 /* Extend the scattering matrix of PBB to MAX_SCATTERING scattering
80 extend_scattering (poly_bb_p pbb
, int max_scattering
)
82 ppl_dimension_type nb_old_dims
, nb_new_dims
;
84 ppl_Coefficient_t coef
;
87 nb_added_dims
= max_scattering
- pbb_nb_scattering_transform (pbb
);
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
);
121 /* All scattering matrices in SCOP will have the same number of scattering
125 unify_scattering_dimensions (scop_p scop
)
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. */
145 openscop_print_pdr_polyhedron (FILE *file
, ppl_const_Polyhedron_t ph
,
146 int nb_subscripts
, int alias_set_dimension
,
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);
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. */
182 openscop_print_pdr_powerset (FILE *file
,
183 ppl_Pointset_Powerset_C_Polyhedron_t ps
,
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
,
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. */
216 openscop_print_powerset_matrix (FILE *file
,
217 ppl_Pointset_Powerset_C_Polyhedron_t ps
,
218 int output
, int input
, int locals
,
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
,
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
250 openscop_print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
253 ppl_const_Polyhedron_t ph
;
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
));
290 fprintf (file
, "#)\n");
293 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
297 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
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
));
329 fprintf (file
, "#)\n");
332 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
336 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
338 if (!PBB_TRANSFORMED (pbb
))
341 if (PBB_TRANSFORMED_SCATTERING (pbb
)
342 || PBB_ORIGINAL_SCATTERING (pbb
))
345 fprintf (file
, "# Scattering function is provided\n");
347 fprintf (file
, "1\n");
352 fprintf (file
, "# Scattering function is not provided\n");
354 fprintf (file
, "0\n");
358 openscop_print_scattering_function_1 (file
, pbb
, verbosity
);
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
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. */
379 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
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
392 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
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
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
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. */
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. */
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
441 graphite_read_transforms (scop_p scop
)
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
;
457 /* Apply graphite transformations to all the basic blocks of SCOP. */
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;
482 transform_done
|= scop_do_block (scop
);
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. */
502 can_collapse_pdrs (poly_dr_p pdr1
, poly_dr_p pdr2
)
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
))
512 af1
= PDR_ACCESSES (pdr1
);
513 af2
= PDR_ACCESSES (pdr2
);
514 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
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
);
523 /* Removes duplicated data references in PBB. */
526 pbb_remove_duplicate_pdrs (poly_bb_p pbb
)
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
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
)
552 poly_dr_p pdr
= XNEW (struct poly_dr
);
555 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
556 PDR_NB_REFS (pdr
) = 1;
558 PDR_ACCESSES (pdr
) = accesses
;
559 PDR_TYPE (pdr
) = type
;
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. */
568 free_poly_dr (poly_dr_p pdr
)
570 ppl_delete_Pointset_Powerset_C_Polyhedron (PDR_ACCESSES (pdr
));
574 /* Create a new polyhedral black box. */
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. */
596 free_poly_bb (poly_bb_p pbb
)
601 ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb
));
603 if (PBB_TRANSFORMED (pbb
))
604 poly_scattering_free (PBB_TRANSFORMED (pbb
));
607 poly_scattering_free (PBB_SAVED (pbb
));
609 if (PBB_ORIGINAL (pbb
))
610 poly_scattering_free (PBB_ORIGINAL (pbb
));
613 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
616 VEC_free (poly_dr_p
, heap
, PBB_DRS (pbb
));
621 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
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
645 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
651 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
653 switch (PDR_TYPE (pdr
))
656 fprintf (file
, "read \n");
660 fprintf (file
, "write \n");
664 fprintf (file
, "may_write \n");
671 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
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
,
684 PDR_NB_SUBSCRIPTS (pdr
),
686 pbb_nb_params (PDR_PBB (pdr
)));
689 fprintf (file
, "#)\n");
692 fprintf (file
, "#)\n");
695 /* Prints to STDERR the polyhedral data reference PDR, at some
699 debug_pdr (poly_dr_p pdr
, int verbosity
)
701 print_pdr (stderr
, pdr
, verbosity
);
704 /* Creates a new SCOP containing REGION. */
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;
727 free_scop (scop_p scop
)
732 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
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
));
747 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
751 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
754 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
756 if (!PBB_DOMAIN (pbb
))
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
));
780 fprintf (file
, "0\n");
783 fprintf (file
, "#)\n");
786 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
789 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
792 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
794 if (!PBB_DOMAIN (pbb
))
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
));
814 fprintf (file
, "0\n");
817 fprintf (file
, "#)\n");
820 /* Dump the cases of a graphite basic block GBB on FILE. */
823 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
827 VEC (gimple
, heap
) *cases
;
832 cases
= GBB_CONDITION_CASES (gbb
);
833 if (VEC_empty (gimple
, cases
))
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. */
850 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
854 VEC (gimple
, heap
) *conditions
;
859 conditions
= GBB_CONDITIONS (gbb
);
860 if (VEC_empty (gimple
, conditions
))
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
878 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
885 if (VEC_length (poly_dr_p
, PBB_DRS (pbb
)) == 0)
888 fprintf (file
, "# Access informations are not provided\n");\
889 fprintf (file
, "0\n");
894 fprintf (file
, "# Data references (\n");
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
)
907 fprintf (file
, "# Read data references (\n");
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
);
918 fprintf (file
, "#)\n");
921 fprintf (file
, "# Write data references (\n");
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
);
932 fprintf (file
, "#)\n");
935 fprintf (file
, "#)\n");
938 /* Print to STDERR all the data references of PBB. */
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. */
950 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
951 bool statement_body_provided
)
954 fprintf (file
, "# Body (\n");
956 if (!statement_body_provided
)
959 fprintf (file
, "# Statement body is not provided\n");
961 fprintf (file
, "0\n");
966 fprintf (file
, "# Statement body is provided\n");
967 fprintf (file
, "1\n");
970 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
973 fprintf (file
, "# Statement body\n");
975 fprintf (file
, "{\n");
976 dump_bb (pbb_bb (pbb
), file
, 0);
977 fprintf (file
, "}\n");
980 fprintf (file
, "#)\n");
983 /* Print to FILE the domain and scattering function of PBB, at some
987 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
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);
1002 fprintf (file
, "#)\n");
1005 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
1008 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
1014 fprintf (file
, "# parameters (\n");
1016 if (VEC_length (tree
, SESE_PARAMS (SCOP_REGION (scop
))))
1019 fprintf (file
, "# Parameter names are provided\n");
1021 fprintf (file
, "1\n");
1024 fprintf (file
, "# Parameter names\n");
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");
1042 fprintf (file
, "#)\n");
1045 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
1049 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
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
));
1068 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
1069 (int) scop_nb_params (scop
));
1072 fprintf (file
, "# )\n");
1075 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
1078 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
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
));
1096 fprintf (file
, "0 %d\n", (int) scop_nb_params (scop
) + 2);
1099 fprintf (file
, "# )\n");
1102 /* Print to FILE the SCOP header: context, parameters, and statements
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
);
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. */
1122 print_scop (FILE *file
, scop_p scop
, int verbosity
)
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
);
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. */
1150 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
1155 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
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
);
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
++)
1171 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
1173 print_pbb_domain (file
, pbb
, verbosity
);
1174 fprintf (file
, "0 0 0");
1177 fprintf (file
, "# For future CLooG options.\n");
1179 fprintf (file
, "\n");
1182 fprintf (file
, "#)\n");
1185 fprintf (file
, "0");
1187 fprintf (file
, "# Don't set the iterator names.\n");
1189 fprintf (file
, "\n");
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
)))
1205 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
1207 print_scattering_function_1 (file
, pbb
, verbosity
);
1210 fprintf (file
, "#)\n");
1213 fprintf (file
, "0");
1215 fprintf (file
, "# Don't set the scattering dimension names.\n");
1217 fprintf (file
, "\n");
1219 fprintf (file
, "#)\n");
1222 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
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
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. */
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. */
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
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
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. */
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
;
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
);
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)
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
);
1335 /* Returns the number of iterations NITER of the loop around PBB at
1336 depth LOOP_DEPTH. */
1339 pbb_number_of_iterations (poly_bb_p pbb
,
1340 graphite_dim_t loop_depth
,
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. */
1358 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1359 graphite_dim_t time_depth
,
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}
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. */
1406 loop_to_lst (loop_p loop
, VEC (poly_bb_p
, heap
) *bbs
, int *i
)
1409 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
1411 for (; VEC_iterate (poly_bb_p
, bbs
, *i
, pbb
); (*i
)++)
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
))
1425 stmt
= loop_to_lst (next
, bbs
, 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
1443 scop_to_lst (scop_p scop
)
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
);
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. */
1471 lst_indent_to (FILE *file
, int column
)
1476 fprintf (file
, "\n#");
1478 for (i
= 0; i
< column
; i
++)
1479 fprintf (file
, " ");
1482 /* Print LST to FILE with INDENT spaces of indentation. */
1485 print_lst (FILE *file
, lst_p lst
, int indent
)
1490 lst_indent_to (file
, indent
);
1492 if (LST_LOOP_P (lst
))
1497 if (LST_LOOP_FATHER (lst
))
1498 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
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
, ")");
1508 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1511 /* Print LST to STDERR. */
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. */
1522 dot_lst_1 (FILE *file
, lst_p lst
)
1527 if (LST_LOOP_P (lst
))
1532 if (!LST_LOOP_FATHER (lst
))
1533 fprintf (file
, "L -> L_%d_%d\n",
1535 lst_dewey_number (lst
));
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
)),
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
);
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. */
1560 /* When debugging, enable the following code. This cannot be used
1561 in production compilers because it calls "system". */
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
);
1571 system ("dotty /tmp/lst.dot &");
1573 fputs ("digraph all {\n", stderr
);
1574 dot_lst_1 (stderr
, lst
);
1575 fputs ("}\n\n", stderr
);