1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2014 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>
33 #ifdef HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE
34 #include <isl/deprecated/int.h>
35 #include <isl/deprecated/ilp_int.h>
40 #include "coretypes.h"
41 #include "diagnostic-core.h"
43 #include "basic-block.h"
44 #include "tree-ssa-alias.h"
45 #include "internal-fn.h"
46 #include "gimple-expr.h"
49 #include "gimple-iterator.h"
50 #include "tree-ssa-loop.h"
52 #include "gimple-pretty-print.h"
54 #include "tree-chrec.h"
55 #include "tree-data-ref.h"
56 #include "tree-scalar-evolution.h"
60 #include "graphite-poly.h"
62 #define OPENSCOP_MAX_STRING 256
65 /* Print to STDERR the GMP value VAL. */
68 debug_gmp_value (mpz_t val
)
70 gmp_fprintf (stderr
, "%Zd", val
);
73 /* Return the maximal loop depth in SCOP. */
76 scop_max_loop_depth (scop_p scop
)
82 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
84 int nb_loops
= pbb_dim_iter_domain (pbb
);
85 if (max_nb_loops
< nb_loops
)
86 max_nb_loops
= nb_loops
;
92 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
96 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
102 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
103 fprintf (file
, "#eq");
105 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
106 fprintf (file
, " s%d", (int) i
);
108 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
109 fprintf (file
, " lv%d", (int) i
);
111 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
112 fprintf (file
, " i%d", (int) i
);
114 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
115 fprintf (file
, " p%d", (int) i
);
117 fprintf (file
, " cst\n");
120 fprintf (file
, "isl\n");
121 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
124 fprintf (file
, "#)\n");
127 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
131 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
133 if (!PBB_TRANSFORMED (pbb
))
136 if (pbb
->schedule
|| pbb
->transformed
)
139 fprintf (file
, "# Scattering function is provided\n");
141 fprintf (file
, "1\n");
146 fprintf (file
, "# Scattering function is not provided\n");
148 fprintf (file
, "0\n");
152 print_scattering_function_1 (file
, pbb
, verbosity
);
155 fprintf (file
, "# Scattering names are not provided\n");
157 fprintf (file
, "0\n");
161 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
165 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
167 print_pbb_domain (file
, pbb
, verbosity
);
170 /* Prints to FILE the scattering functions of every PBB of SCOP. */
173 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
178 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
179 print_scattering_function (file
, pbb
, verbosity
);
182 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
186 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
191 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
192 print_iteration_domain (file
, pbb
, verbosity
);
195 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
199 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
201 print_scattering_function (stderr
, pbb
, verbosity
);
204 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
208 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
210 print_iteration_domain (stderr
, pbb
, verbosity
);
213 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
214 some VERBOSITY level. */
217 debug_scattering_functions (scop_p scop
, int verbosity
)
219 print_scattering_functions (stderr
, scop
, verbosity
);
222 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
223 some VERBOSITY level. */
226 debug_iteration_domains (scop_p scop
, int verbosity
)
228 print_iteration_domains (stderr
, scop
, verbosity
);
231 /* Apply graphite transformations to all the basic blocks of SCOP. */
234 apply_poly_transforms (scop_p scop
)
236 bool transform_done
= false;
238 /* Generate code even if we did not apply any real transformation.
239 This also allows to check the performance for the identity
240 transformation: GIMPLE -> GRAPHITE -> GIMPLE
241 Keep in mind that CLooG optimizes in control, so the loop structure
242 may change, even if we only use -fgraphite-identity. */
243 if (flag_graphite_identity
)
244 transform_done
= true;
246 if (flag_loop_parallelize_all
)
247 transform_done
= true;
250 transform_done
|= scop_do_block (scop
);
253 if (flag_loop_strip_mine
)
254 transform_done
|= scop_do_strip_mine (scop
, 0);
256 if (flag_loop_interchange
)
257 transform_done
|= scop_do_interchange (scop
);
260 /* This pass needs to be run at the final stage, as it does not
262 if (flag_loop_optimize_isl
)
263 transform_done
|= optimize_isl (scop
);
265 return transform_done
;
268 /* Create a new polyhedral data reference and add it to PBB. It is
269 defined by its ACCESSES, its TYPE, and the number of subscripts
273 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
274 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
275 isl_map
*acc
, isl_set
*extent
)
278 poly_dr_p pdr
= XNEW (struct poly_dr
);
281 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
282 PDR_NB_REFS (pdr
) = 1;
285 pdr
->extent
= extent
;
286 PDR_TYPE (pdr
) = type
;
288 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
289 PBB_DRS (pbb
).safe_push (pdr
);
292 /* Free polyhedral data reference PDR. */
295 free_poly_dr (poly_dr_p pdr
)
297 isl_map_free (pdr
->accesses
);
298 isl_set_free (pdr
->extent
);
302 /* Create a new polyhedral black box. */
305 new_poly_bb (scop_p scop
, void *black_box
)
307 poly_bb_p pbb
= XNEW (struct poly_bb
);
310 pbb
->schedule
= NULL
;
311 pbb
->transformed
= NULL
;
313 PBB_SCOP (pbb
) = scop
;
314 pbb_set_black_box (pbb
, black_box
);
315 PBB_TRANSFORMED (pbb
) = NULL
;
316 PBB_SAVED (pbb
) = NULL
;
317 PBB_ORIGINAL (pbb
) = NULL
;
318 PBB_DRS (pbb
).create (3);
319 PBB_IS_REDUCTION (pbb
) = false;
320 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
325 /* Free polyhedral black box. */
328 free_poly_bb (poly_bb_p pbb
)
333 isl_set_free (pbb
->domain
);
334 isl_map_free (pbb
->schedule
);
335 isl_map_free (pbb
->transformed
);
336 isl_map_free (pbb
->saved
);
338 if (PBB_DRS (pbb
).exists ())
339 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
342 PBB_DRS (pbb
).release ();
347 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
351 fprintf (file
, "# eq");
353 fprintf (file
, " alias");
355 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
356 fprintf (file
, " sub%d", (int) i
);
358 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
359 fprintf (file
, " i%d", (int) i
);
361 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
362 fprintf (file
, " p%d", (int) i
);
364 fprintf (file
, " cst\n");
367 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
371 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
375 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
377 switch (PDR_TYPE (pdr
))
380 fprintf (file
, "read \n");
384 fprintf (file
, "write \n");
388 fprintf (file
, "may_write \n");
395 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
400 fprintf (file
, "# data accesses (\n");
401 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
404 /* XXX isl dump accesses/subscripts */
407 fprintf (file
, "#)\n");
410 fprintf (file
, "#)\n");
413 /* Prints to STDERR the polyhedral data reference PDR, at some
417 debug_pdr (poly_dr_p pdr
, int verbosity
)
419 print_pdr (stderr
, pdr
, verbosity
);
422 /* Creates a new SCOP containing REGION. */
425 new_scop (void *region
)
427 scop_p scop
= XNEW (struct scop
);
429 scop
->context
= NULL
;
430 scop
->must_raw
= NULL
;
431 scop
->may_raw
= NULL
;
432 scop
->must_raw_no_source
= NULL
;
433 scop
->may_raw_no_source
= NULL
;
434 scop
->must_war
= NULL
;
435 scop
->may_war
= NULL
;
436 scop
->must_war_no_source
= NULL
;
437 scop
->may_war_no_source
= NULL
;
438 scop
->must_waw
= NULL
;
439 scop
->may_waw
= NULL
;
440 scop
->must_waw_no_source
= NULL
;
441 scop
->may_waw_no_source
= NULL
;
442 scop_set_region (scop
, region
);
443 SCOP_BBS (scop
).create (3);
444 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
445 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
446 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
447 POLY_SCOP_P (scop
) = false;
455 free_scop (scop_p scop
)
460 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
463 SCOP_BBS (scop
).release ();
465 isl_set_free (scop
->context
);
466 isl_union_map_free (scop
->must_raw
);
467 isl_union_map_free (scop
->may_raw
);
468 isl_union_map_free (scop
->must_raw_no_source
);
469 isl_union_map_free (scop
->may_raw_no_source
);
470 isl_union_map_free (scop
->must_war
);
471 isl_union_map_free (scop
->may_war
);
472 isl_union_map_free (scop
->must_war_no_source
);
473 isl_union_map_free (scop
->may_war_no_source
);
474 isl_union_map_free (scop
->must_waw
);
475 isl_union_map_free (scop
->may_waw
);
476 isl_union_map_free (scop
->must_waw_no_source
);
477 isl_union_map_free (scop
->may_waw_no_source
);
478 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
479 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
480 free_lst (SCOP_SAVED_SCHEDULE (scop
));
484 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
488 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
491 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
498 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
499 fprintf (file
, "#eq");
501 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
502 fprintf (file
, " i%d", (int) i
);
504 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
505 fprintf (file
, " p%d", (int) i
);
507 fprintf (file
, " cst\n");
510 fprintf (file
, "XXX isl\n");
513 fprintf (file
, "#)\n");
516 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
519 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
521 print_isl_set (file
, pbb
->domain
);
524 /* Dump the cases of a graphite basic block GBB on FILE. */
527 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
536 cases
= GBB_CONDITION_CASES (gbb
);
537 if (cases
.is_empty ())
540 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
542 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
544 fprintf (file
, "# ");
545 print_gimple_stmt (file
, stmt
, 0, 0);
548 fprintf (file
, "#)\n");
551 /* Dump conditions of a graphite basic block GBB on FILE. */
554 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
558 vec
<gimple
> conditions
;
563 conditions
= GBB_CONDITIONS (gbb
);
564 if (conditions
.is_empty ())
567 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
569 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
571 fprintf (file
, "# ");
572 print_gimple_stmt (file
, stmt
, 0, 0);
575 fprintf (file
, "#)\n");
578 /* Print to FILE all the data references of PBB, at some VERBOSITY
582 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
589 if (PBB_DRS (pbb
).length () == 0)
592 fprintf (file
, "# Access informations are not provided\n");\
593 fprintf (file
, "0\n");
598 fprintf (file
, "# Data references (\n");
601 fprintf (file
, "# Access informations are provided\n");
602 fprintf (file
, "1\n");
604 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
605 if (PDR_TYPE (pdr
) == PDR_READ
)
611 fprintf (file
, "# Read data references (\n");
614 fprintf (file
, "# Read access informations\n");
615 fprintf (file
, "%d\n", nb_reads
);
617 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
618 if (PDR_TYPE (pdr
) == PDR_READ
)
619 print_pdr (file
, pdr
, verbosity
);
622 fprintf (file
, "#)\n");
625 fprintf (file
, "# Write data references (\n");
628 fprintf (file
, "# Write access informations\n");
629 fprintf (file
, "%d\n", nb_writes
);
631 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
632 if (PDR_TYPE (pdr
) != PDR_READ
)
633 print_pdr (file
, pdr
, verbosity
);
636 fprintf (file
, "#)\n");
639 fprintf (file
, "#)\n");
642 /* Print to STDERR all the data references of PBB. */
645 debug_pdrs (poly_bb_p pbb
, int verbosity
)
647 print_pdrs (stderr
, pbb
, verbosity
);
650 /* Print to FILE the body of PBB, at some VERBOSITY level.
651 If statement_body_provided is false statement body is not printed. */
654 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
655 bool statement_body_provided
)
658 fprintf (file
, "# Body (\n");
660 if (!statement_body_provided
)
663 fprintf (file
, "# Statement body is not provided\n");
665 fprintf (file
, "0\n");
668 fprintf (file
, "#)\n");
673 fprintf (file
, "# Statement body is provided\n");
674 fprintf (file
, "1\n");
677 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
680 fprintf (file
, "# Statement body\n");
682 fprintf (file
, "{\n");
683 dump_bb (file
, pbb_bb (pbb
), 0, 0);
684 fprintf (file
, "}\n");
687 fprintf (file
, "#)\n");
690 /* Print to FILE the domain and scattering function of PBB, at some
694 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
698 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
699 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
700 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
703 openscop_print_pbb_domain (file
, pbb
, verbosity
);
704 print_scattering_function (file
, pbb
, verbosity
);
705 print_pdrs (file
, pbb
, verbosity
);
706 print_pbb_body (file
, pbb
, verbosity
, false);
709 fprintf (file
, "#)\n");
712 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
715 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
721 fprintf (file
, "# parameters (\n");
723 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
726 fprintf (file
, "# Parameter names are provided\n");
728 fprintf (file
, "1\n");
731 fprintf (file
, "# Parameter names\n");
736 fprintf (file
, "# Parameter names are not provided\n");
737 fprintf (file
, "0\n");
740 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
742 print_generic_expr (file
, t
, 0);
746 fprintf (file
, "\n");
749 fprintf (file
, "#)\n");
752 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
756 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
762 fprintf (file
, "# Context (\n");
763 fprintf (file
, "#eq");
765 for (i
= 0; i
< scop_nb_params (scop
); i
++)
766 fprintf (file
, " p%d", (int) i
);
768 fprintf (file
, " cst\n");
772 /* XXX isl print context */
773 fprintf (file
, "XXX isl\n");
775 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
776 (int) scop_nb_params (scop
));
779 fprintf (file
, "# )\n");
782 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
785 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
791 fprintf (file
, "# Context (\n");
792 fprintf (file
, "#eq");
794 for (i
= 0; i
< scop_nb_params (scop
); i
++)
795 fprintf (file
, " p%d", (int) i
);
797 fprintf (file
, " cst\n");
801 print_isl_set (file
, scop
->context
);
803 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
806 fprintf (file
, "# )\n");
809 /* Print to FILE the SCOP, at some VERBOSITY level. */
812 print_scop (FILE *file
, scop_p scop
, int verbosity
)
817 fprintf (file
, "SCoP 1\n#(\n");
818 fprintf (file
, "# Language\nGimple\n");
819 openscop_print_scop_context (file
, scop
, verbosity
);
820 print_scop_params (file
, scop
, verbosity
);
823 fprintf (file
, "# Number of statements\n");
825 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
827 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
828 print_pbb (file
, pbb
, verbosity
);
832 fprintf (file
, "# original_lst (\n");
833 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
834 fprintf (file
, "\n#)\n");
836 fprintf (file
, "# transformed_lst (\n");
837 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
838 fprintf (file
, "\n#)\n");
841 fprintf (file
, "#)\n");
844 /* Print to FILE the input file that CLooG would expect as input, at
845 some VERBOSITY level. */
848 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
853 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
855 fprintf (file
, "# CLooG output language\n");
856 fprintf (file
, "c\n");
858 print_scop_context (file
, scop
, verbosity
);
859 print_scop_params (file
, scop
, verbosity
);
862 fprintf (file
, "# Number of statements\n");
864 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
866 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
869 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
871 print_pbb_domain (file
, pbb
, verbosity
);
872 fprintf (file
, "0 0 0");
875 fprintf (file
, "# For future CLooG options.\n");
877 fprintf (file
, "\n");
880 fprintf (file
, "#)\n");
885 fprintf (file
, "# Don't set the iterator names.\n");
887 fprintf (file
, "\n");
890 fprintf (file
, "# Number of scattering functions\n");
892 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
894 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
896 if (!(pbb
->transformed
|| pbb
->schedule
))
900 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
902 print_scattering_function_1 (file
, pbb
, verbosity
);
905 fprintf (file
, "#)\n");
910 fprintf (file
, "# Don't set the scattering dimension names.\n");
912 fprintf (file
, "\n");
914 fprintf (file
, "#)\n");
917 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
920 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
922 print_pbb_domain (stderr
, pbb
, verbosity
);
925 /* Print to FILE the domain and scattering function of PBB, at some
929 debug_pbb (poly_bb_p pbb
, int verbosity
)
931 print_pbb (stderr
, pbb
, verbosity
);
934 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
937 debug_scop_context (scop_p scop
, int verbosity
)
939 print_scop_context (stderr
, scop
, verbosity
);
942 /* Print to STDERR the SCOP, at some VERBOSITY level. */
945 debug_scop (scop_p scop
, int verbosity
)
947 print_scop (stderr
, scop
, verbosity
);
950 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
954 debug_cloog (scop_p scop
, int verbosity
)
956 print_cloog (stderr
, scop
, verbosity
);
959 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
963 debug_scop_params (scop_p scop
, int verbosity
)
965 print_scop_params (stderr
, scop
, verbosity
);
968 extern isl_ctx
*the_isl_ctx
;
970 print_isl_set (FILE *f
, isl_set
*set
)
972 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
973 p
= isl_printer_print_set (p
, set
);
974 isl_printer_free (p
);
978 debug_isl_set (isl_set
*set
)
980 print_isl_set (stderr
, set
);
984 print_isl_map (FILE *f
, isl_map
*map
)
986 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
987 p
= isl_printer_print_map (p
, map
);
988 isl_printer_free (p
);
992 debug_isl_map (isl_map
*map
)
994 print_isl_map (stderr
, map
);
998 print_isl_aff (FILE *f
, isl_aff
*aff
)
1000 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1001 p
= isl_printer_print_aff (p
, aff
);
1002 isl_printer_free (p
);
1006 debug_isl_aff (isl_aff
*aff
)
1008 print_isl_aff (stderr
, aff
);
1012 print_isl_constraint (FILE *f
, isl_constraint
*c
)
1014 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1015 p
= isl_printer_print_constraint (p
, c
);
1016 isl_printer_free (p
);
1020 debug_isl_constraint (isl_constraint
*c
)
1022 print_isl_constraint (stderr
, c
);
1025 /* Returns the number of iterations RES of the loop around PBB at
1026 time(scattering) dimension TIME_DEPTH. */
1029 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1030 graphite_dim_t time_depth
,
1033 isl_set
*transdomain
;
1036 isl_int isllb
, islub
;
1038 isl_int_init (isllb
);
1039 isl_int_init (islub
);
1041 /* Map the iteration domain through the current scatter, and work
1042 on the resulting set. */
1043 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
1044 isl_map_copy (pbb
->transformed
));
1046 /* Select the time_depth' dimension via an affine expression. */
1047 dc
= isl_set_get_space (transdomain
);
1048 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
1049 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
1051 /* And find the min/max for that function. */
1052 /* XXX isl check results? */
1053 isl_set_min (transdomain
, aff
, &isllb
);
1054 isl_set_max (transdomain
, aff
, &islub
);
1056 isl_int_sub (islub
, islub
, isllb
);
1057 isl_int_add_ui (islub
, islub
, 1);
1058 isl_int_get_gmp (islub
, res
);
1060 isl_int_clear (isllb
);
1061 isl_int_clear (islub
);
1063 isl_set_free (transdomain
);
1066 /* Translates LOOP to LST. */
1069 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
1075 for (; bbs
.iterate (*i
, &pbb
); (*i
)++)
1078 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1080 if (bb
->loop_father
== loop
)
1081 stmt
= new_lst_stmt (pbb
);
1082 else if (flow_bb_inside_loop_p (loop
, bb
))
1084 loop_p next
= loop
->inner
;
1086 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1089 stmt
= loop_to_lst (next
, bbs
, i
);
1094 return new_lst_loop (seq
);
1097 seq
.safe_push (stmt
);
1100 return new_lst_loop (seq
);
1103 /* Reads the original scattering of the SCOP and returns an LST
1107 scop_to_lst (scop_p scop
)
1110 int i
, n
= SCOP_BBS (scop
).length ();
1113 sese region
= SCOP_REGION (scop
);
1115 for (i
= 0; i
< n
; i
++)
1117 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1118 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1120 if (loop_in_sese_p (loop
, region
))
1121 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1123 res
= new_lst_stmt (pbb
);
1125 seq
.safe_push (res
);
1128 res
= new_lst_loop (seq
);
1129 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1130 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1133 /* Print to FILE on a new line COLUMN white spaces. */
1136 lst_indent_to (FILE *file
, int column
)
1141 fprintf (file
, "\n#");
1143 for (i
= 0; i
< column
; i
++)
1144 fprintf (file
, " ");
1147 /* Print LST to FILE with INDENT spaces of indentation. */
1150 print_lst (FILE *file
, lst_p lst
, int indent
)
1155 lst_indent_to (file
, indent
);
1157 if (LST_LOOP_P (lst
))
1162 if (LST_LOOP_FATHER (lst
))
1163 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1165 fprintf (file
, "#(root");
1167 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1168 print_lst (file
, l
, indent
+ 2);
1170 fprintf (file
, ")");
1173 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1176 /* Print LST to STDERR. */
1179 debug_lst (lst_p lst
)
1181 print_lst (stderr
, lst
, 0);
1184 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1187 dot_lst_1 (FILE *file
, lst_p lst
)
1192 if (LST_LOOP_P (lst
))
1197 if (!LST_LOOP_FATHER (lst
))
1198 fprintf (file
, "L -> L_%d_%d\n",
1200 lst_dewey_number (lst
));
1202 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1203 lst_depth (LST_LOOP_FATHER (lst
)),
1204 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1206 lst_dewey_number (lst
));
1208 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1209 dot_lst_1 (file
, l
);
1213 fprintf (file
, "L_%d_%d -> S_%d\n",
1214 lst_depth (LST_LOOP_FATHER (lst
)),
1215 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1216 pbb_index (LST_PBB (lst
)));
1220 /* Display the LST using dotty. */
1225 /* When debugging, enable the following code. This cannot be used
1226 in production compilers because it calls "system". */
1228 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1229 gcc_assert (stream
);
1231 fputs ("digraph all {\n", stream
);
1232 dot_lst_1 (stream
, lst
);
1233 fputs ("}\n\n", stream
);
1236 system ("dotty /tmp/lst.dot &");
1238 fputs ("digraph all {\n", stderr
);
1239 dot_lst_1 (stderr
, lst
);
1240 fputs ("}\n\n", stderr
);
1245 /* Computes a checksum for the code generated by CLooG for SCOP. */
1248 cloog_checksum (scop_p scop ATTRIBUTE_UNUSED
)
1250 /* When debugging, enable the following code. This cannot be used
1251 in production compilers because it calls "system". */
1253 FILE *stream
= fopen ("/tmp/scop.cloog", "w");
1254 gcc_assert (stream
);
1255 print_cloog (stream
, scop
, 0);
1258 fputs ("\n", stdout
);
1259 system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
1263 /* Reverse the loop around PBB at level DEPTH. */
1266 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1268 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1269 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1270 isl_space
*d1
= isl_space_range (d
);
1271 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1272 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1273 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1274 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1276 for (i
= 0; i
< n
; i
++)
1278 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1280 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1281 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1282 x
= isl_map_add_constraint (x
, c
);
1286 /* Reverse the loop at level DEPTH for all the PBBS. */
1289 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1293 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1294 isl_union_map
*res
= isl_union_map_empty (space
);
1296 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1297 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));