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-flow.h"
33 #include "tree-dump.h"
36 #include "tree-chrec.h"
37 #include "tree-data-ref.h"
38 #include "tree-scalar-evolution.h"
39 #include "tree-pass.h"
41 #include "value-prof.h"
42 #include "pointer-set.h"
47 #include "cloog/cloog.h"
50 #include "graphite-ppl.h"
52 #include "graphite-poly.h"
53 #include "graphite-dependences.h"
55 /* Return the maximal loop depth in SCOP. */
58 scop_max_loop_depth (scop_p scop
)
64 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
66 int nb_loops
= pbb_dim_iter_domain (pbb
);
67 if (max_nb_loops
< nb_loops
)
68 max_nb_loops
= nb_loops
;
74 /* Extend the scattering matrix of PBB to MAX_SCATTERING scattering
78 extend_scattering (poly_bb_p pbb
, int max_scattering
)
80 ppl_dimension_type nb_old_dims
, nb_new_dims
;
82 ppl_Coefficient_t coef
;
85 nb_added_dims
= max_scattering
- pbb_nb_scattering_transform (pbb
);
88 ppl_new_Coefficient (&coef
);
89 ppl_assign_Coefficient_from_mpz_t (coef
, one
);
91 gcc_assert (nb_added_dims
>= 0);
93 nb_old_dims
= pbb_nb_scattering_transform (pbb
) + pbb_dim_iter_domain (pbb
)
94 + scop_nb_params (PBB_SCOP (pbb
));
95 nb_new_dims
= nb_old_dims
+ nb_added_dims
;
97 ppl_insert_dimensions (PBB_TRANSFORMED_SCATTERING (pbb
),
98 pbb_nb_scattering_transform (pbb
), nb_added_dims
);
99 PBB_NB_SCATTERING_TRANSFORM (pbb
) += nb_added_dims
;
101 /* Add identity matrix for the added dimensions. */
102 for (i
= max_scattering
- nb_added_dims
; i
< max_scattering
; i
++)
104 ppl_Constraint_t cstr
;
105 ppl_Linear_Expression_t expr
;
107 ppl_new_Linear_Expression_with_dimension (&expr
, nb_new_dims
);
108 ppl_Linear_Expression_add_to_coefficient (expr
, i
, coef
);
109 ppl_new_Constraint (&cstr
, expr
, PPL_CONSTRAINT_TYPE_EQUAL
);
110 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb
), cstr
);
111 ppl_delete_Constraint (cstr
);
112 ppl_delete_Linear_Expression (expr
);
115 ppl_delete_Coefficient (coef
);
119 /* All scattering matrices in SCOP will have the same number of scattering
123 unify_scattering_dimensions (scop_p scop
)
127 graphite_dim_t max_scattering
= 0;
129 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
130 max_scattering
= MAX (pbb_nb_scattering_transform (pbb
), max_scattering
);
132 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
133 extend_scattering (pbb
, max_scattering
);
135 return max_scattering
;
138 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
142 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
148 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
149 fprintf (file
, "# eq");
151 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
152 fprintf (file
, " s%d", (int) i
);
154 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
155 fprintf (file
, " lv%d", (int) i
);
157 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
158 fprintf (file
, " i%d", (int) i
);
160 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
161 fprintf (file
, " p%d", (int) i
);
163 fprintf (file
, " cst\n");
166 /* Number of disjunct components. Remove this when
167 PBB_TRANSFORMED_SCATTERING will be a pointset_powerset. */
168 fprintf (file
, "1\n");
169 ppl_print_polyhedron_matrix (file
, PBB_TRANSFORMED_SCATTERING (pbb
)
170 ? PBB_TRANSFORMED_SCATTERING (pbb
)
171 : PBB_ORIGINAL_SCATTERING (pbb
));
174 fprintf (file
, "#)\n");
177 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
181 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
183 if (!PBB_TRANSFORMED (pbb
))
186 if (PBB_TRANSFORMED_SCATTERING (pbb
)
187 || PBB_ORIGINAL_SCATTERING (pbb
))
190 fprintf (file
, "# Scattering function is provided\n");
192 fprintf (file
, "1\n");
197 fprintf (file
, "# Scattering function is not provided\n");
199 fprintf (file
, "0\n");
203 print_scattering_function_1 (file
, pbb
, verbosity
);
206 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
210 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
212 print_pbb_domain (file
, pbb
, verbosity
);
215 /* Prints to FILE the scattering functions of every PBB of SCOP. */
218 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
223 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
224 print_scattering_function (file
, pbb
, verbosity
);
227 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
231 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
236 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
237 print_iteration_domain (file
, pbb
, verbosity
);
240 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
244 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
246 print_scattering_function (stderr
, pbb
, verbosity
);
249 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
253 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
255 print_iteration_domain (stderr
, pbb
, verbosity
);
258 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
259 some VERBOSITY level. */
262 debug_scattering_functions (scop_p scop
, int verbosity
)
264 print_scattering_functions (stderr
, scop
, verbosity
);
267 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
268 some VERBOSITY level. */
271 debug_iteration_domains (scop_p scop
, int verbosity
)
273 print_iteration_domains (stderr
, scop
, verbosity
);
277 /* Apply graphite transformations to all the basic blocks of SCOP. */
280 apply_poly_transforms (scop_p scop
)
282 bool transform_done
= false;
284 /* Generate code even if we did not apply any real transformation.
285 This also allows to check the performance for the identity
286 transformation: GIMPLE -> GRAPHITE -> GIMPLE
287 Keep in mind that CLooG optimizes in control, so the loop structure
288 may change, even if we only use -fgraphite-identity. */
289 if (flag_graphite_identity
)
290 transform_done
= true;
292 if (flag_loop_parallelize_all
)
293 transform_done
= true;
296 transform_done
|= scop_do_block (scop
);
299 if (flag_loop_strip_mine
)
300 transform_done
|= scop_do_strip_mine (scop
);
302 if (flag_loop_interchange
)
303 transform_done
|= scop_do_interchange (scop
);
306 return transform_done
;
309 /* Returns true when it PDR1 is a duplicate of PDR2: same PBB, and
310 their ACCESSES, TYPE, and NB_SUBSCRIPTS are the same. */
313 can_collapse_pdrs (poly_dr_p pdr1
, poly_dr_p pdr2
)
316 ppl_Pointset_Powerset_C_Polyhedron_t af1
, af2
, diff
;
318 if (PDR_PBB (pdr1
) != PDR_PBB (pdr2
)
319 || PDR_NB_SUBSCRIPTS (pdr1
) != PDR_NB_SUBSCRIPTS (pdr2
)
320 || PDR_TYPE (pdr1
) != PDR_TYPE (pdr2
))
323 af1
= PDR_ACCESSES (pdr1
);
324 af2
= PDR_ACCESSES (pdr2
);
325 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
327 ppl_Pointset_Powerset_C_Polyhedron_difference_assign (diff
, af2
);
329 res
= ppl_Pointset_Powerset_C_Polyhedron_is_empty (diff
);
330 ppl_delete_Pointset_Powerset_C_Polyhedron (diff
);
334 /* Removes duplicated data references in PBB. */
337 pbb_remove_duplicate_pdrs (poly_bb_p pbb
)
340 poly_dr_p pdr1
, pdr2
;
341 unsigned n
= VEC_length (poly_dr_p
, PBB_DRS (pbb
));
342 VEC (poly_dr_p
, heap
) *collapsed
= VEC_alloc (poly_dr_p
, heap
, n
);
344 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr1
); i
++)
345 for (j
= 0; VEC_iterate (poly_dr_p
, collapsed
, j
, pdr2
); j
++)
346 if (!can_collapse_pdrs (pdr1
, pdr2
))
347 VEC_quick_push (poly_dr_p
, collapsed
, pdr1
);
349 VEC_free (poly_dr_p
, heap
, collapsed
);
350 PBB_PDR_DUPLICATES_REMOVED (pbb
) = true;
353 /* Create a new polyhedral data reference and add it to PBB. It is
354 defined by its ACCESSES, its TYPE, and the number of subscripts
358 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
359 ppl_Pointset_Powerset_C_Polyhedron_t accesses
,
360 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
)
363 poly_dr_p pdr
= XNEW (struct poly_dr
);
366 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
367 PDR_NB_REFS (pdr
) = 1;
369 PDR_ACCESSES (pdr
) = accesses
;
370 PDR_TYPE (pdr
) = type
;
372 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
373 VEC_safe_push (poly_dr_p
, heap
, PBB_DRS (pbb
), pdr
);
376 /* Free polyhedral data reference PDR. */
379 free_poly_dr (poly_dr_p pdr
)
381 ppl_delete_Pointset_Powerset_C_Polyhedron (PDR_ACCESSES (pdr
));
385 /* Create a new polyhedral black box. */
388 new_poly_bb (scop_p scop
, void *black_box
, bool reduction
)
390 poly_bb_p pbb
= XNEW (struct poly_bb
);
392 PBB_DOMAIN (pbb
) = NULL
;
393 PBB_SCOP (pbb
) = scop
;
394 pbb_set_black_box (pbb
, black_box
);
395 PBB_TRANSFORMED (pbb
) = NULL
;
396 PBB_SAVED (pbb
) = NULL
;
397 PBB_ORIGINAL (pbb
) = NULL
;
398 PBB_DRS (pbb
) = VEC_alloc (poly_dr_p
, heap
, 3);
399 PBB_IS_REDUCTION (pbb
) = reduction
;
400 PBB_PDR_DUPLICATES_REMOVED (pbb
) = false;
401 VEC_safe_push (poly_bb_p
, heap
, SCOP_BBS (scop
), pbb
);
404 /* Free polyhedral black box. */
407 free_poly_bb (poly_bb_p pbb
)
412 ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb
));
414 if (PBB_TRANSFORMED (pbb
))
415 poly_scattering_free (PBB_TRANSFORMED (pbb
));
418 poly_scattering_free (PBB_SAVED (pbb
));
420 if (PBB_ORIGINAL (pbb
))
421 poly_scattering_free (PBB_ORIGINAL (pbb
));
424 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
427 VEC_free (poly_dr_p
, heap
, PBB_DRS (pbb
));
432 print_pdr_access_layout (FILE *file
, poly_dr_p pdr
)
436 fprintf (file
, "# eq");
438 for (i
= 0; i
< pdr_dim_iter_domain (pdr
); i
++)
439 fprintf (file
, " i%d", (int) i
);
441 for (i
= 0; i
< pdr_nb_params (pdr
); i
++)
442 fprintf (file
, " p%d", (int) i
);
444 fprintf (file
, " alias");
446 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
447 fprintf (file
, " sub%d", (int) i
);
449 fprintf (file
, " cst\n");
452 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
456 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
460 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
462 switch (PDR_TYPE (pdr
))
465 fprintf (file
, "read \n");
469 fprintf (file
, "write \n");
473 fprintf (file
, "may_write \n");
480 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
485 fprintf (file
, "# data accesses (\n");
486 print_pdr_access_layout (file
, pdr
);
489 ppl_print_powerset_matrix (file
, PDR_ACCESSES (pdr
));
492 fprintf (file
, "#)\n");
495 fprintf (file
, "#)\n");
498 /* Prints to STDERR the polyhedral data reference PDR, at some
502 debug_pdr (poly_dr_p pdr
, int verbosity
)
504 print_pdr (stderr
, pdr
, verbosity
);
507 /* Creates a new SCOP containing REGION. */
510 new_scop (void *region
)
512 scop_p scop
= XNEW (struct scop
);
514 SCOP_CONTEXT (scop
) = NULL
;
515 scop_set_region (scop
, region
);
516 SCOP_BBS (scop
) = VEC_alloc (poly_bb_p
, heap
, 3);
517 SCOP_ORIGINAL_PDDRS (scop
) = htab_create (10, hash_poly_ddr_p
,
518 eq_poly_ddr_p
, free_poly_ddr
);
519 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
520 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
521 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
522 POLY_SCOP_P (scop
) = false;
530 free_scop (scop_p scop
)
535 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
538 VEC_free (poly_bb_p
, heap
, SCOP_BBS (scop
));
540 if (SCOP_CONTEXT (scop
))
541 ppl_delete_Pointset_Powerset_C_Polyhedron (SCOP_CONTEXT (scop
));
543 htab_delete (SCOP_ORIGINAL_PDDRS (scop
));
544 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
545 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
546 free_lst (SCOP_SAVED_SCHEDULE (scop
));
550 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
553 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
556 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
558 if (!PBB_DOMAIN (pbb
))
563 fprintf (file
, "# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
564 fprintf (file
, "# eq");
566 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
567 fprintf (file
, " i%d", (int) i
);
569 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
570 fprintf (file
, " p%d", (int) i
);
572 fprintf (file
, " cst\n");
575 if (PBB_DOMAIN (pbb
))
576 ppl_print_powerset_matrix (file
, PBB_DOMAIN (pbb
));
578 fprintf (file
, "0\n");
581 fprintf (file
, "#)\n");
584 /* Dump the cases of a graphite basic block GBB on FILE. */
587 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
591 VEC (gimple
, heap
) *cases
;
596 cases
= GBB_CONDITION_CASES (gbb
);
597 if (VEC_empty (gimple
, cases
))
600 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
602 for (i
= 0; VEC_iterate (gimple
, cases
, i
, stmt
); i
++)
604 fprintf (file
, "# ");
605 print_gimple_stmt (file
, stmt
, 0, 0);
608 fprintf (file
, "#)\n");
611 /* Dump conditions of a graphite basic block GBB on FILE. */
614 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
618 VEC (gimple
, heap
) *conditions
;
623 conditions
= GBB_CONDITIONS (gbb
);
624 if (VEC_empty (gimple
, conditions
))
627 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
629 for (i
= 0; VEC_iterate (gimple
, conditions
, i
, stmt
); i
++)
631 fprintf (file
, "# ");
632 print_gimple_stmt (file
, stmt
, 0, 0);
635 fprintf (file
, "#)\n");
638 /* Print to FILE all the data references of PBB, at some VERBOSITY
642 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
649 if (VEC_length (poly_dr_p
, PBB_DRS (pbb
)) == 0)
652 fprintf (file
, "# Access informations are not provided\n");\
653 fprintf (file
, "0\n");
658 fprintf (file
, "# Data references (\n");
661 fprintf (file
, "# Access informations are provided\n");
662 fprintf (file
, "1\n");
664 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
665 if (PDR_TYPE (pdr
) == PDR_READ
)
671 fprintf (file
, "# Read data references (\n");
674 fprintf (file
, "# Read access informations\n");
675 fprintf (file
, "%d\n", nb_reads
);
677 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
678 if (PDR_TYPE (pdr
) == PDR_READ
)
679 print_pdr (file
, pdr
, verbosity
);
682 fprintf (file
, "#)\n");
685 fprintf (file
, "# Write data references (\n");
688 fprintf (file
, "# Write access informations\n");
689 fprintf (file
, "%d\n", nb_writes
);
691 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
692 if (PDR_TYPE (pdr
) != PDR_READ
)
693 print_pdr (file
, pdr
, verbosity
);
696 fprintf (file
, "#)\n");
699 fprintf (file
, "#)\n");
702 /* Print to STDERR all the data references of PBB. */
705 debug_pdrs (poly_bb_p pbb
, int verbosity
)
707 print_pdrs (stderr
, pbb
, verbosity
);
710 /* Print to FILE the body of PBB, at some VERBOSITY level. */
713 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
)
716 fprintf (file
, "# Body (\n");
719 fprintf (file
, "# Statement body is provided\n");
720 fprintf (file
, "1\n");
723 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
726 fprintf (file
, "# Statement body\n");
728 fprintf (file
, "{\n");
729 dump_bb (pbb_bb (pbb
), file
, 0);
730 fprintf (file
, "}\n");
733 fprintf (file
, "#)\n");
736 /* Print to FILE the domain and scattering function of PBB, at some
740 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
744 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
745 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
746 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
749 print_pbb_domain (file
, pbb
, verbosity
);
750 print_scattering_function (file
, pbb
, verbosity
);
751 print_pdrs (file
, pbb
, verbosity
);
752 print_pbb_body (file
, pbb
, verbosity
);
755 fprintf (file
, "#)\n");
758 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
761 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
767 fprintf (file
, "# parameters (\n");
769 if (VEC_length (tree
, SESE_PARAMS (SCOP_REGION (scop
))))
772 fprintf (file
, "# Parameter names are provided\n");
774 fprintf (file
, "1\n");
777 fprintf (file
, "# Parameter names\n");
782 fprintf (file
, "# Parameter names are not provided\n");
783 fprintf (file
, "0\n");
786 for (i
= 0; VEC_iterate (tree
, SESE_PARAMS (SCOP_REGION (scop
)), i
, t
); i
++)
788 print_generic_expr (file
, t
, 0);
792 fprintf (file
, "\n");
795 fprintf (file
, "#)\n");
798 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
801 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
807 fprintf (file
, "# Context (\n");
808 fprintf (file
, "# eq");
810 for (i
= 0; i
< scop_nb_params (scop
); i
++)
811 fprintf (file
, " p%d", (int) i
);
813 fprintf (file
, " cst\n");
816 if (SCOP_CONTEXT (scop
))
817 ppl_print_powerset_matrix (file
, SCOP_CONTEXT (scop
));
819 fprintf (file
, "0 %d\n", (int) scop_nb_params (scop
) + 2);
822 fprintf (file
, "# )\n");
825 /* Print to FILE the SCOP, at some VERBOSITY level. */
828 print_scop (FILE *file
, scop_p scop
, int verbosity
)
833 fprintf (file
, "SCoP #(\n");
834 fprintf (file
, "# Language\nGimple\n");
835 print_scop_context (file
, scop
, verbosity
);
836 print_scop_params (file
, scop
, verbosity
);
839 fprintf (file
, "# Number of statements\n");
841 fprintf (file
, "%d\n",VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
843 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
844 print_pbb (file
, pbb
, verbosity
);
848 fprintf (file
, "# original_lst (\n");
849 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
850 fprintf (file
, "\n#)\n");
852 fprintf (file
, "# transformed_lst (\n");
853 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
854 fprintf (file
, "\n#)\n");
857 fprintf (file
, "#)\n");
860 /* Print to FILE the input file that CLooG would expect as input, at
861 some VERBOSITY level. */
864 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
869 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
871 fprintf (file
, "# CLooG output language\n");
872 fprintf (file
, "c\n");
874 print_scop_context (file
, scop
, verbosity
);
875 print_scop_params (file
, scop
, verbosity
);
878 fprintf (file
, "# Number of statements\n");
880 fprintf (file
, "%d\n", VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
882 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
885 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
887 print_pbb_domain (file
, pbb
, verbosity
);
888 fprintf (file
, "0 0 0");
891 fprintf (file
, "# For future CLooG options.\n");
893 fprintf (file
, "\n");
896 fprintf (file
, "#)\n");
901 fprintf (file
, "# Don't set the iterator names.\n");
903 fprintf (file
, "\n");
906 fprintf (file
, "# Number of scattering functions\n");
908 fprintf (file
, "%d\n", VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
909 unify_scattering_dimensions (scop
);
911 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
913 if (!PBB_TRANSFORMED (pbb
)
914 || !(PBB_TRANSFORMED_SCATTERING (pbb
)
915 || PBB_ORIGINAL_SCATTERING (pbb
)))
919 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
921 print_scattering_function_1 (file
, pbb
, verbosity
);
924 fprintf (file
, "#)\n");
929 fprintf (file
, "# Don't set the scattering dimension names.\n");
931 fprintf (file
, "\n");
933 fprintf (file
, "#)\n");
936 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
939 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
941 print_pbb_domain (stderr
, pbb
, verbosity
);
944 /* Print to FILE the domain and scattering function of PBB, at some
948 debug_pbb (poly_bb_p pbb
, int verbosity
)
950 print_pbb (stderr
, pbb
, verbosity
);
953 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
956 debug_scop_context (scop_p scop
, int verbosity
)
958 print_scop_context (stderr
, scop
, verbosity
);
961 /* Print to STDERR the SCOP, at some VERBOSITY level. */
964 debug_scop (scop_p scop
, int verbosity
)
966 print_scop (stderr
, scop
, verbosity
);
969 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
973 debug_cloog (scop_p scop
, int verbosity
)
975 print_cloog (stderr
, scop
, verbosity
);
978 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
982 debug_scop_params (scop_p scop
, int verbosity
)
984 print_scop_params (stderr
, scop
, verbosity
);
988 /* The dimension in the transformed scattering polyhedron of PBB
989 containing the scattering iterator for the loop at depth LOOP_DEPTH. */
992 psct_scattering_dim_for_loop_depth (poly_bb_p pbb
, graphite_dim_t loop_depth
)
994 ppl_const_Constraint_System_t pcs
;
995 ppl_Constraint_System_const_iterator_t cit
, cend
;
996 ppl_const_Constraint_t cstr
;
997 ppl_Polyhedron_t ph
= PBB_TRANSFORMED_SCATTERING (pbb
);
998 ppl_dimension_type iter
= psct_iterator_dim (pbb
, loop_depth
);
999 ppl_Linear_Expression_t expr
;
1000 ppl_Coefficient_t coef
;
1005 ppl_new_Coefficient (&coef
);
1006 ppl_Polyhedron_get_constraints (ph
, &pcs
);
1007 ppl_new_Constraint_System_const_iterator (&cit
);
1008 ppl_new_Constraint_System_const_iterator (&cend
);
1010 for (ppl_Constraint_System_begin (pcs
, cit
),
1011 ppl_Constraint_System_end (pcs
, cend
);
1012 !ppl_Constraint_System_const_iterator_equal_test (cit
, cend
);
1013 ppl_Constraint_System_const_iterator_increment (cit
))
1015 ppl_Constraint_System_const_iterator_dereference (cit
, &cstr
);
1016 ppl_new_Linear_Expression_from_Constraint (&expr
, cstr
);
1017 ppl_Linear_Expression_coefficient (expr
, iter
, coef
);
1018 ppl_Coefficient_to_mpz_t (coef
, val
);
1022 ppl_delete_Linear_Expression (expr
);
1026 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
1028 ppl_dimension_type scatter
= psct_scattering_dim (pbb
, i
);
1030 ppl_Linear_Expression_coefficient (expr
, scatter
, coef
);
1031 ppl_Coefficient_to_mpz_t (coef
, val
);
1033 if (value_notzero_p (val
))
1036 ppl_delete_Linear_Expression (expr
);
1037 ppl_delete_Coefficient (coef
);
1038 ppl_delete_Constraint_System_const_iterator (cit
);
1039 ppl_delete_Constraint_System_const_iterator (cend
);
1049 /* Returns the number of iterations NITER of the loop around PBB at
1050 depth LOOP_DEPTH. */
1053 pbb_number_of_iterations (poly_bb_p pbb
,
1054 graphite_dim_t loop_depth
,
1057 ppl_Linear_Expression_t le
;
1058 ppl_dimension_type dim
;
1060 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (PBB_DOMAIN (pbb
), &dim
);
1061 ppl_new_Linear_Expression_with_dimension (&le
, dim
);
1062 ppl_set_coef (le
, pbb_iterator_dim (pbb
, loop_depth
), 1);
1063 mpz_set_si (niter
, -1);
1064 ppl_max_for_le_pointset (PBB_DOMAIN (pbb
), le
, niter
);
1065 ppl_delete_Linear_Expression (le
);
1068 /* Returns the number of iterations NITER of the loop around PBB at
1069 time(scattering) dimension TIME_DEPTH. */
1072 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1073 graphite_dim_t time_depth
,
1076 ppl_Pointset_Powerset_C_Polyhedron_t ext_domain
, sctr
;
1077 ppl_Linear_Expression_t le
;
1078 ppl_dimension_type dim
;
1080 /* Takes together domain and scattering polyhedrons, and composes
1081 them into the bigger polyhedron that has the following format:
1083 t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}
1086 | t0..t_{n-1} are time dimensions (scattering dimensions)
1087 | l0..l_{nclc-1} are local variables in scattering function
1088 | i0..i_{niter-1} are original iteration variables
1089 | g0..g_{nparam-1} are global parameters. */
1091 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr
,
1092 PBB_TRANSFORMED_SCATTERING (pbb
));
1094 /* Extend the iteration domain with the scattering dimensions:
1095 0..0 | 0..0 | i0..i_{niter-1} | g0..g_{nparm-1}. */
1096 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
1097 (&ext_domain
, PBB_DOMAIN (pbb
));
1098 ppl_insert_dimensions_pointset (ext_domain
, 0,
1099 pbb_nb_scattering_transform (pbb
)
1100 + pbb_nb_local_vars (pbb
));
1102 /* Add to sctr the extended domain. */
1103 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr
, ext_domain
);
1105 /* Extract the number of iterations. */
1106 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (sctr
, &dim
);
1107 ppl_new_Linear_Expression_with_dimension (&le
, dim
);
1108 ppl_set_coef (le
, time_depth
, 1);
1109 mpz_set_si (niter
, -1);
1110 ppl_max_for_le_pointset (sctr
, le
, niter
);
1112 ppl_delete_Linear_Expression (le
);
1113 ppl_delete_Pointset_Powerset_C_Polyhedron (sctr
);
1114 ppl_delete_Pointset_Powerset_C_Polyhedron (ext_domain
);
1117 /* Translates LOOP to LST. */
1120 loop_to_lst (loop_p loop
, VEC (poly_bb_p
, heap
) *bbs
, int *i
)
1123 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
1125 for (; VEC_iterate (poly_bb_p
, bbs
, *i
, pbb
); (*i
)++)
1128 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1130 if (bb
->loop_father
== loop
)
1131 stmt
= new_lst_stmt (pbb
);
1132 else if (flow_bb_inside_loop_p (loop
, bb
))
1134 loop_p next
= loop
->inner
;
1136 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1139 stmt
= loop_to_lst (next
, bbs
, i
);
1144 return new_lst_loop (seq
);
1147 VEC_safe_push (lst_p
, heap
, seq
, stmt
);
1150 return new_lst_loop (seq
);
1153 /* Reads the original scattering of the SCOP and returns an LST
1157 scop_to_lst (scop_p scop
)
1160 int i
, n
= VEC_length (poly_bb_p
, SCOP_BBS (scop
));
1161 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
1162 sese region
= SCOP_REGION (scop
);
1164 for (i
= 0; i
< n
; i
++)
1166 poly_bb_p pbb
= VEC_index (poly_bb_p
, SCOP_BBS (scop
), i
);
1167 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1169 if (loop_in_sese_p (loop
, region
))
1170 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1172 res
= new_lst_stmt (pbb
);
1174 VEC_safe_push (lst_p
, heap
, seq
, res
);
1177 res
= new_lst_loop (seq
);
1178 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1179 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1182 /* Print to FILE on a new line COLUMN white spaces. */
1185 lst_indent_to (FILE *file
, int column
)
1190 fprintf (file
, "\n#");
1192 for (i
= 0; i
< column
; i
++)
1193 fprintf (file
, " ");
1196 /* Print LST to FILE with INDENT spaces of indentation. */
1199 print_lst (FILE *file
, lst_p lst
, int indent
)
1204 lst_indent_to (file
, indent
);
1206 if (LST_LOOP_P (lst
))
1211 if (LST_LOOP_FATHER (lst
))
1212 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1214 fprintf (file
, "#(root");
1216 for (i
= 0; VEC_iterate (lst_p
, LST_SEQ (lst
), i
, l
); i
++)
1217 print_lst (file
, l
, indent
+ 2);
1219 fprintf (file
, ")");
1222 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1225 /* Print LST to STDERR. */
1228 debug_lst (lst_p lst
)
1230 print_lst (stderr
, lst
, 0);
1233 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1236 dot_lst_1 (FILE *file
, lst_p lst
)
1241 if (LST_LOOP_P (lst
))
1246 if (!LST_LOOP_FATHER (lst
))
1247 fprintf (file
, "L -> L_%d_%d\n",
1249 lst_dewey_number (lst
));
1251 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1252 lst_depth (LST_LOOP_FATHER (lst
)),
1253 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1255 lst_dewey_number (lst
));
1257 for (i
= 0; VEC_iterate (lst_p
, LST_SEQ (lst
), i
, l
); i
++)
1258 dot_lst_1 (file
, l
);
1262 fprintf (file
, "L_%d_%d -> S_%d\n",
1263 lst_depth (LST_LOOP_FATHER (lst
)),
1264 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1265 pbb_index (LST_PBB (lst
)));
1269 /* Display the LST using dotty. */
1274 /* When debugging, enable the following code. This cannot be used
1275 in production compilers because it calls "system". */
1278 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1279 gcc_assert (stream
);
1281 fputs ("digraph all {\n", stream
);
1282 dot_lst_1 (stream
, lst
);
1283 fputs ("}\n\n", stream
);
1286 x
= system ("dotty /tmp/lst.dot");
1288 fputs ("digraph all {\n", stderr
);
1289 dot_lst_1 (stderr
, lst
);
1290 fputs ("}\n\n", stderr
);