1 /* Graphite polyhedral representation.
2 Copyright (C) 2009, 2010, 2011 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/>. */
27 #include <isl/union_map.h>
28 #include <isl/constraint.h>
31 #include <cloog/cloog.h>
32 #include <cloog/isl/domain.h>
36 #include "coretypes.h"
37 #include "diagnostic-core.h"
38 #include "tree-flow.h"
40 #include "gimple-pretty-print.h"
42 #include "tree-chrec.h"
43 #include "tree-data-ref.h"
44 #include "tree-scalar-evolution.h"
48 #include "graphite-poly.h"
50 #define OPENSCOP_MAX_STRING 256
53 /* Print to STDERR the GMP value VAL. */
56 debug_gmp_value (mpz_t val
)
58 char *str
= mpz_get_str (0, 10, val
);
59 void (*gmp_free
) (void *, size_t);
61 fprintf (stderr
, "%s", str
);
62 mp_get_memory_functions (NULL
, NULL
, &gmp_free
);
63 (*gmp_free
) (str
, strlen (str
) + 1);
66 /* Return the maximal loop depth in SCOP. */
69 scop_max_loop_depth (scop_p scop
)
75 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
77 int nb_loops
= pbb_dim_iter_domain (pbb
);
78 if (max_nb_loops
< nb_loops
)
79 max_nb_loops
= nb_loops
;
85 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
89 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
95 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
96 fprintf (file
, "#eq");
98 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
99 fprintf (file
, " s%d", (int) i
);
101 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
102 fprintf (file
, " lv%d", (int) i
);
104 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
105 fprintf (file
, " i%d", (int) i
);
107 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
108 fprintf (file
, " p%d", (int) i
);
110 fprintf (file
, " cst\n");
113 fprintf (file
, "isl\n");
114 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
117 fprintf (file
, "#)\n");
120 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
124 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
126 if (!PBB_TRANSFORMED (pbb
))
129 if (pbb
->schedule
|| pbb
->transformed
)
132 fprintf (file
, "# Scattering function is provided\n");
134 fprintf (file
, "1\n");
139 fprintf (file
, "# Scattering function is not provided\n");
141 fprintf (file
, "0\n");
145 print_scattering_function_1 (file
, pbb
, verbosity
);
148 fprintf (file
, "# Scattering names are not provided\n");
150 fprintf (file
, "0\n");
154 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
158 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
160 print_pbb_domain (file
, pbb
, verbosity
);
163 /* Prints to FILE the scattering functions of every PBB of SCOP. */
166 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
171 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
172 print_scattering_function (file
, pbb
, verbosity
);
175 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
179 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
184 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
185 print_iteration_domain (file
, pbb
, verbosity
);
188 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
192 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
194 print_scattering_function (stderr
, pbb
, verbosity
);
197 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
201 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
203 print_iteration_domain (stderr
, pbb
, verbosity
);
206 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
207 some VERBOSITY level. */
210 debug_scattering_functions (scop_p scop
, int verbosity
)
212 print_scattering_functions (stderr
, scop
, verbosity
);
215 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
216 some VERBOSITY level. */
219 debug_iteration_domains (scop_p scop
, int verbosity
)
221 print_iteration_domains (stderr
, scop
, verbosity
);
224 /* Apply graphite transformations to all the basic blocks of SCOP. */
227 apply_poly_transforms (scop_p scop
)
229 bool transform_done
= false;
231 /* Generate code even if we did not apply any real transformation.
232 This also allows to check the performance for the identity
233 transformation: GIMPLE -> GRAPHITE -> GIMPLE
234 Keep in mind that CLooG optimizes in control, so the loop structure
235 may change, even if we only use -fgraphite-identity. */
236 if (flag_graphite_identity
)
237 transform_done
= true;
239 if (flag_loop_parallelize_all
)
240 transform_done
= true;
243 transform_done
|= scop_do_block (scop
);
246 if (flag_loop_strip_mine
)
247 transform_done
|= scop_do_strip_mine (scop
, 0);
249 if (flag_loop_interchange
)
250 transform_done
|= scop_do_interchange (scop
);
253 /* This pass needs to be run at the final stage, as it does not
255 if (flag_loop_optimize_isl
)
256 transform_done
|= optimize_isl (scop
);
258 return transform_done
;
261 /* Create a new polyhedral data reference and add it to PBB. It is
262 defined by its ACCESSES, its TYPE, and the number of subscripts
266 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
267 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
268 isl_map
*acc
, isl_set
*extent
)
271 poly_dr_p pdr
= XNEW (struct poly_dr
);
274 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
275 PDR_NB_REFS (pdr
) = 1;
278 pdr
->extent
= extent
;
279 PDR_TYPE (pdr
) = type
;
281 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
282 VEC_safe_push (poly_dr_p
, heap
, PBB_DRS (pbb
), pdr
);
285 /* Free polyhedral data reference PDR. */
288 free_poly_dr (poly_dr_p pdr
)
290 isl_map_free (pdr
->accesses
);
291 isl_set_free (pdr
->extent
);
295 /* Create a new polyhedral black box. */
298 new_poly_bb (scop_p scop
, void *black_box
)
300 poly_bb_p pbb
= XNEW (struct poly_bb
);
303 pbb
->schedule
= NULL
;
304 pbb
->transformed
= NULL
;
306 PBB_SCOP (pbb
) = scop
;
307 pbb_set_black_box (pbb
, black_box
);
308 PBB_TRANSFORMED (pbb
) = NULL
;
309 PBB_SAVED (pbb
) = NULL
;
310 PBB_ORIGINAL (pbb
) = NULL
;
311 PBB_DRS (pbb
) = VEC_alloc (poly_dr_p
, heap
, 3);
312 PBB_IS_REDUCTION (pbb
) = false;
313 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
318 /* Free polyhedral black box. */
321 free_poly_bb (poly_bb_p pbb
)
326 isl_set_free (pbb
->domain
);
327 isl_map_free (pbb
->schedule
);
328 isl_map_free (pbb
->transformed
);
329 isl_map_free (pbb
->saved
);
332 FOR_EACH_VEC_ELT (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
)
335 VEC_free (poly_dr_p
, heap
, PBB_DRS (pbb
));
340 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
344 fprintf (file
, "# eq");
346 fprintf (file
, " alias");
348 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
349 fprintf (file
, " sub%d", (int) i
);
351 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
352 fprintf (file
, " i%d", (int) i
);
354 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
355 fprintf (file
, " p%d", (int) i
);
357 fprintf (file
, " cst\n");
360 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
364 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
368 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
370 switch (PDR_TYPE (pdr
))
373 fprintf (file
, "read \n");
377 fprintf (file
, "write \n");
381 fprintf (file
, "may_write \n");
388 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
393 fprintf (file
, "# data accesses (\n");
394 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
397 /* XXX isl dump accesses/subscripts */
400 fprintf (file
, "#)\n");
403 fprintf (file
, "#)\n");
406 /* Prints to STDERR the polyhedral data reference PDR, at some
410 debug_pdr (poly_dr_p pdr
, int verbosity
)
412 print_pdr (stderr
, pdr
, verbosity
);
415 /* Creates a new SCOP containing REGION. */
418 new_scop (void *region
)
420 scop_p scop
= XNEW (struct scop
);
422 scop
->context
= NULL
;
423 scop
->must_raw
= NULL
;
424 scop
->may_raw
= NULL
;
425 scop
->must_raw_no_source
= NULL
;
426 scop
->may_raw_no_source
= NULL
;
427 scop
->must_war
= NULL
;
428 scop
->may_war
= NULL
;
429 scop
->must_war_no_source
= NULL
;
430 scop
->may_war_no_source
= NULL
;
431 scop
->must_waw
= NULL
;
432 scop
->may_waw
= NULL
;
433 scop
->must_waw_no_source
= NULL
;
434 scop
->may_waw_no_source
= NULL
;
435 scop_set_region (scop
, region
);
436 SCOP_BBS (scop
) = VEC_alloc (poly_bb_p
, heap
, 3);
437 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
438 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
439 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
440 POLY_SCOP_P (scop
) = false;
448 free_scop (scop_p scop
)
453 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
456 VEC_free (poly_bb_p
, heap
, SCOP_BBS (scop
));
458 isl_set_free (scop
->context
);
459 isl_union_map_free (scop
->must_raw
);
460 isl_union_map_free (scop
->may_raw
);
461 isl_union_map_free (scop
->must_raw_no_source
);
462 isl_union_map_free (scop
->may_raw_no_source
);
463 isl_union_map_free (scop
->must_war
);
464 isl_union_map_free (scop
->may_war
);
465 isl_union_map_free (scop
->must_war_no_source
);
466 isl_union_map_free (scop
->may_war_no_source
);
467 isl_union_map_free (scop
->must_waw
);
468 isl_union_map_free (scop
->may_waw
);
469 isl_union_map_free (scop
->must_waw_no_source
);
470 isl_union_map_free (scop
->may_waw_no_source
);
471 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
472 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
473 free_lst (SCOP_SAVED_SCHEDULE (scop
));
477 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
481 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
484 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
491 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
492 fprintf (file
, "#eq");
494 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
495 fprintf (file
, " i%d", (int) i
);
497 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
498 fprintf (file
, " p%d", (int) i
);
500 fprintf (file
, " cst\n");
503 fprintf (file
, "XXX isl\n");
506 fprintf (file
, "#)\n");
509 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
512 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
514 print_isl_set (file
, pbb
->domain
);
517 /* Dump the cases of a graphite basic block GBB on FILE. */
520 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
524 VEC (gimple
, heap
) *cases
;
529 cases
= GBB_CONDITION_CASES (gbb
);
530 if (VEC_empty (gimple
, cases
))
533 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
535 FOR_EACH_VEC_ELT (gimple
, cases
, i
, stmt
)
537 fprintf (file
, "# ");
538 print_gimple_stmt (file
, stmt
, 0, 0);
541 fprintf (file
, "#)\n");
544 /* Dump conditions of a graphite basic block GBB on FILE. */
547 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
551 VEC (gimple
, heap
) *conditions
;
556 conditions
= GBB_CONDITIONS (gbb
);
557 if (VEC_empty (gimple
, conditions
))
560 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
562 FOR_EACH_VEC_ELT (gimple
, conditions
, i
, stmt
)
564 fprintf (file
, "# ");
565 print_gimple_stmt (file
, stmt
, 0, 0);
568 fprintf (file
, "#)\n");
571 /* Print to FILE all the data references of PBB, at some VERBOSITY
575 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
582 if (VEC_length (poly_dr_p
, PBB_DRS (pbb
)) == 0)
585 fprintf (file
, "# Access informations are not provided\n");\
586 fprintf (file
, "0\n");
591 fprintf (file
, "# Data references (\n");
594 fprintf (file
, "# Access informations are provided\n");
595 fprintf (file
, "1\n");
597 FOR_EACH_VEC_ELT (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
)
598 if (PDR_TYPE (pdr
) == PDR_READ
)
604 fprintf (file
, "# Read data references (\n");
607 fprintf (file
, "# Read access informations\n");
608 fprintf (file
, "%d\n", nb_reads
);
610 FOR_EACH_VEC_ELT (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
)
611 if (PDR_TYPE (pdr
) == PDR_READ
)
612 print_pdr (file
, pdr
, verbosity
);
615 fprintf (file
, "#)\n");
618 fprintf (file
, "# Write data references (\n");
621 fprintf (file
, "# Write access informations\n");
622 fprintf (file
, "%d\n", nb_writes
);
624 FOR_EACH_VEC_ELT (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
)
625 if (PDR_TYPE (pdr
) != PDR_READ
)
626 print_pdr (file
, pdr
, verbosity
);
629 fprintf (file
, "#)\n");
632 fprintf (file
, "#)\n");
635 /* Print to STDERR all the data references of PBB. */
638 debug_pdrs (poly_bb_p pbb
, int verbosity
)
640 print_pdrs (stderr
, pbb
, verbosity
);
643 /* Print to FILE the body of PBB, at some VERBOSITY level.
644 If statement_body_provided is false statement body is not printed. */
647 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
648 bool statement_body_provided
)
651 fprintf (file
, "# Body (\n");
653 if (!statement_body_provided
)
656 fprintf (file
, "# Statement body is not provided\n");
658 fprintf (file
, "0\n");
661 fprintf (file
, "#)\n");
666 fprintf (file
, "# Statement body is provided\n");
667 fprintf (file
, "1\n");
670 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
673 fprintf (file
, "# Statement body\n");
675 fprintf (file
, "{\n");
676 dump_bb (file
, pbb_bb (pbb
), 0, 0);
677 fprintf (file
, "}\n");
680 fprintf (file
, "#)\n");
683 /* Print to FILE the domain and scattering function of PBB, at some
687 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
691 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
692 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
693 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
696 openscop_print_pbb_domain (file
, pbb
, verbosity
);
697 print_scattering_function (file
, pbb
, verbosity
);
698 print_pdrs (file
, pbb
, verbosity
);
699 print_pbb_body (file
, pbb
, verbosity
, false);
702 fprintf (file
, "#)\n");
705 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
708 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
714 fprintf (file
, "# parameters (\n");
716 if (VEC_length (tree
, SESE_PARAMS (SCOP_REGION (scop
))))
719 fprintf (file
, "# Parameter names are provided\n");
721 fprintf (file
, "1\n");
724 fprintf (file
, "# Parameter names\n");
729 fprintf (file
, "# Parameter names are not provided\n");
730 fprintf (file
, "0\n");
733 FOR_EACH_VEC_ELT (tree
, SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
735 print_generic_expr (file
, t
, 0);
739 fprintf (file
, "\n");
742 fprintf (file
, "#)\n");
745 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
749 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
755 fprintf (file
, "# Context (\n");
756 fprintf (file
, "#eq");
758 for (i
= 0; i
< scop_nb_params (scop
); i
++)
759 fprintf (file
, " p%d", (int) i
);
761 fprintf (file
, " cst\n");
765 /* XXX isl print context */
766 fprintf (file
, "XXX isl\n");
768 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
769 (int) scop_nb_params (scop
));
772 fprintf (file
, "# )\n");
775 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
778 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
784 fprintf (file
, "# Context (\n");
785 fprintf (file
, "#eq");
787 for (i
= 0; i
< scop_nb_params (scop
); i
++)
788 fprintf (file
, " p%d", (int) i
);
790 fprintf (file
, " cst\n");
794 print_isl_set (file
, scop
->context
);
796 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
799 fprintf (file
, "# )\n");
802 /* Print to FILE the SCOP, at some VERBOSITY level. */
805 print_scop (FILE *file
, scop_p scop
, int verbosity
)
810 fprintf (file
, "SCoP 1\n#(\n");
811 fprintf (file
, "# Language\nGimple\n");
812 openscop_print_scop_context (file
, scop
, verbosity
);
813 print_scop_params (file
, scop
, verbosity
);
816 fprintf (file
, "# Number of statements\n");
818 fprintf (file
, "%d\n",VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
820 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
821 print_pbb (file
, pbb
, verbosity
);
825 fprintf (file
, "# original_lst (\n");
826 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
827 fprintf (file
, "\n#)\n");
829 fprintf (file
, "# transformed_lst (\n");
830 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
831 fprintf (file
, "\n#)\n");
834 fprintf (file
, "#)\n");
837 /* Print to FILE the input file that CLooG would expect as input, at
838 some VERBOSITY level. */
841 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
846 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
848 fprintf (file
, "# CLooG output language\n");
849 fprintf (file
, "c\n");
851 print_scop_context (file
, scop
, verbosity
);
852 print_scop_params (file
, scop
, verbosity
);
855 fprintf (file
, "# Number of statements\n");
857 fprintf (file
, "%d\n", VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
859 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
862 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
864 print_pbb_domain (file
, pbb
, verbosity
);
865 fprintf (file
, "0 0 0");
868 fprintf (file
, "# For future CLooG options.\n");
870 fprintf (file
, "\n");
873 fprintf (file
, "#)\n");
878 fprintf (file
, "# Don't set the iterator names.\n");
880 fprintf (file
, "\n");
883 fprintf (file
, "# Number of scattering functions\n");
885 fprintf (file
, "%d\n", VEC_length (poly_bb_p
, SCOP_BBS (scop
)));
887 FOR_EACH_VEC_ELT (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
)
889 if (!(pbb
->transformed
|| pbb
->schedule
))
893 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
895 print_scattering_function_1 (file
, pbb
, verbosity
);
898 fprintf (file
, "#)\n");
903 fprintf (file
, "# Don't set the scattering dimension names.\n");
905 fprintf (file
, "\n");
907 fprintf (file
, "#)\n");
910 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
913 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
915 print_pbb_domain (stderr
, pbb
, verbosity
);
918 /* Print to FILE the domain and scattering function of PBB, at some
922 debug_pbb (poly_bb_p pbb
, int verbosity
)
924 print_pbb (stderr
, pbb
, verbosity
);
927 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
930 debug_scop_context (scop_p scop
, int verbosity
)
932 print_scop_context (stderr
, scop
, verbosity
);
935 /* Print to STDERR the SCOP, at some VERBOSITY level. */
938 debug_scop (scop_p scop
, int verbosity
)
940 print_scop (stderr
, scop
, verbosity
);
943 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
947 debug_cloog (scop_p scop
, int verbosity
)
949 print_cloog (stderr
, scop
, verbosity
);
952 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
956 debug_scop_params (scop_p scop
, int verbosity
)
958 print_scop_params (stderr
, scop
, verbosity
);
961 extern isl_ctx
*the_isl_ctx
;
963 print_isl_set (FILE *f
, isl_set
*set
)
965 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
966 p
= isl_printer_print_set (p
, set
);
967 isl_printer_free (p
);
971 debug_isl_set (isl_set
*set
)
973 print_isl_set (stderr
, set
);
977 print_isl_map (FILE *f
, isl_map
*map
)
979 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
980 p
= isl_printer_print_map (p
, map
);
981 isl_printer_free (p
);
985 debug_isl_map (isl_map
*map
)
987 print_isl_map (stderr
, map
);
991 print_isl_aff (FILE *f
, isl_aff
*aff
)
993 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
994 p
= isl_printer_print_aff (p
, aff
);
995 isl_printer_free (p
);
999 debug_isl_aff (isl_aff
*aff
)
1001 print_isl_aff (stderr
, aff
);
1005 print_isl_constraint (FILE *f
, isl_constraint
*c
)
1007 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1008 p
= isl_printer_print_constraint (p
, c
);
1009 isl_printer_free (p
);
1013 debug_isl_constraint (isl_constraint
*c
)
1015 print_isl_constraint (stderr
, c
);
1018 /* Returns the number of iterations RES of the loop around PBB at
1019 time(scattering) dimension TIME_DEPTH. */
1022 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1023 graphite_dim_t time_depth
,
1026 isl_set
*transdomain
;
1029 isl_int isllb
, islub
;
1031 isl_int_init (isllb
);
1032 isl_int_init (islub
);
1034 /* Map the iteration domain through the current scatter, and work
1035 on the resulting set. */
1036 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
1037 isl_map_copy (pbb
->transformed
));
1039 /* Select the time_depth' dimension via an affine expression. */
1040 dc
= isl_set_get_space (transdomain
);
1041 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
1042 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
1044 /* And find the min/max for that function. */
1045 /* XXX isl check results? */
1046 isl_set_min (transdomain
, aff
, &isllb
);
1047 isl_set_max (transdomain
, aff
, &islub
);
1049 isl_int_sub (islub
, islub
, isllb
);
1050 isl_int_add_ui (islub
, islub
, 1);
1051 isl_int_get_gmp (islub
, res
);
1053 isl_int_clear (isllb
);
1054 isl_int_clear (islub
);
1056 isl_set_free (transdomain
);
1059 /* Translates LOOP to LST. */
1062 loop_to_lst (loop_p loop
, VEC (poly_bb_p
, heap
) *bbs
, int *i
)
1065 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
1067 for (; VEC_iterate (poly_bb_p
, bbs
, *i
, pbb
); (*i
)++)
1070 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1072 if (bb
->loop_father
== loop
)
1073 stmt
= new_lst_stmt (pbb
);
1074 else if (flow_bb_inside_loop_p (loop
, bb
))
1076 loop_p next
= loop
->inner
;
1078 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1081 stmt
= loop_to_lst (next
, bbs
, i
);
1086 return new_lst_loop (seq
);
1089 VEC_safe_push (lst_p
, heap
, seq
, stmt
);
1092 return new_lst_loop (seq
);
1095 /* Reads the original scattering of the SCOP and returns an LST
1099 scop_to_lst (scop_p scop
)
1102 int i
, n
= VEC_length (poly_bb_p
, SCOP_BBS (scop
));
1103 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
1104 sese region
= SCOP_REGION (scop
);
1106 for (i
= 0; i
< n
; i
++)
1108 poly_bb_p pbb
= VEC_index (poly_bb_p
, SCOP_BBS (scop
), i
);
1109 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1111 if (loop_in_sese_p (loop
, region
))
1112 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1114 res
= new_lst_stmt (pbb
);
1116 VEC_safe_push (lst_p
, heap
, seq
, res
);
1119 res
= new_lst_loop (seq
);
1120 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1121 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1124 /* Print to FILE on a new line COLUMN white spaces. */
1127 lst_indent_to (FILE *file
, int column
)
1132 fprintf (file
, "\n#");
1134 for (i
= 0; i
< column
; i
++)
1135 fprintf (file
, " ");
1138 /* Print LST to FILE with INDENT spaces of indentation. */
1141 print_lst (FILE *file
, lst_p lst
, int indent
)
1146 lst_indent_to (file
, indent
);
1148 if (LST_LOOP_P (lst
))
1153 if (LST_LOOP_FATHER (lst
))
1154 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1156 fprintf (file
, "#(root");
1158 FOR_EACH_VEC_ELT (lst_p
, LST_SEQ (lst
), i
, l
)
1159 print_lst (file
, l
, indent
+ 2);
1161 fprintf (file
, ")");
1164 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1167 /* Print LST to STDERR. */
1170 debug_lst (lst_p lst
)
1172 print_lst (stderr
, lst
, 0);
1175 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1178 dot_lst_1 (FILE *file
, lst_p lst
)
1183 if (LST_LOOP_P (lst
))
1188 if (!LST_LOOP_FATHER (lst
))
1189 fprintf (file
, "L -> L_%d_%d\n",
1191 lst_dewey_number (lst
));
1193 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1194 lst_depth (LST_LOOP_FATHER (lst
)),
1195 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1197 lst_dewey_number (lst
));
1199 FOR_EACH_VEC_ELT (lst_p
, LST_SEQ (lst
), i
, l
)
1200 dot_lst_1 (file
, l
);
1204 fprintf (file
, "L_%d_%d -> S_%d\n",
1205 lst_depth (LST_LOOP_FATHER (lst
)),
1206 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1207 pbb_index (LST_PBB (lst
)));
1211 /* Display the LST using dotty. */
1216 /* When debugging, enable the following code. This cannot be used
1217 in production compilers because it calls "system". */
1219 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1220 gcc_assert (stream
);
1222 fputs ("digraph all {\n", stream
);
1223 dot_lst_1 (stream
, lst
);
1224 fputs ("}\n\n", stream
);
1227 system ("dotty /tmp/lst.dot &");
1229 fputs ("digraph all {\n", stderr
);
1230 dot_lst_1 (stderr
, lst
);
1231 fputs ("}\n\n", stderr
);
1236 /* Computes a checksum for the code generated by CLooG for SCOP. */
1239 cloog_checksum (scop_p scop ATTRIBUTE_UNUSED
)
1241 /* When debugging, enable the following code. This cannot be used
1242 in production compilers because it calls "system". */
1244 FILE *stream
= fopen ("/tmp/scop.cloog", "w");
1245 gcc_assert (stream
);
1246 print_cloog (stream
, scop
, 0);
1249 fputs ("\n", stdout
);
1250 system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
1254 /* Reverse the loop around PBB at level DEPTH. */
1257 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1259 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1260 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1261 isl_space
*d1
= isl_space_range (d
);
1262 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1263 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1264 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1265 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1267 for (i
= 0; i
< n
; i
++)
1269 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1271 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1272 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1273 x
= isl_map_add_constraint (x
, c
);
1277 /* Reverse the loop at level DEPTH for all the PBBS. */
1280 reverse_loop_for_pbbs (scop_p scop
, VEC (poly_bb_p
, heap
) *pbbs
, int depth
)
1284 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1285 isl_union_map
*res
= isl_union_map_empty (space
);
1287 for (i
= 0; VEC_iterate (poly_bb_p
, pbbs
, i
, pbb
); i
++)
1288 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));