1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2013 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"
42 #include "tree-flow.h"
44 #include "gimple-pretty-print.h"
46 #include "tree-chrec.h"
47 #include "tree-data-ref.h"
48 #include "tree-scalar-evolution.h"
52 #include "graphite-poly.h"
54 #define OPENSCOP_MAX_STRING 256
57 /* Print to STDERR the GMP value VAL. */
60 debug_gmp_value (mpz_t val
)
62 gmp_fprintf (stderr
, "%Zd", val
);
65 /* Return the maximal loop depth in SCOP. */
68 scop_max_loop_depth (scop_p scop
)
74 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
76 int nb_loops
= pbb_dim_iter_domain (pbb
);
77 if (max_nb_loops
< nb_loops
)
78 max_nb_loops
= nb_loops
;
84 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
88 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
94 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
95 fprintf (file
, "#eq");
97 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
98 fprintf (file
, " s%d", (int) i
);
100 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
101 fprintf (file
, " lv%d", (int) i
);
103 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
104 fprintf (file
, " i%d", (int) i
);
106 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
107 fprintf (file
, " p%d", (int) i
);
109 fprintf (file
, " cst\n");
112 fprintf (file
, "isl\n");
113 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
116 fprintf (file
, "#)\n");
119 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
123 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
125 if (!PBB_TRANSFORMED (pbb
))
128 if (pbb
->schedule
|| pbb
->transformed
)
131 fprintf (file
, "# Scattering function is provided\n");
133 fprintf (file
, "1\n");
138 fprintf (file
, "# Scattering function is not provided\n");
140 fprintf (file
, "0\n");
144 print_scattering_function_1 (file
, pbb
, verbosity
);
147 fprintf (file
, "# Scattering names are not provided\n");
149 fprintf (file
, "0\n");
153 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
157 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
159 print_pbb_domain (file
, pbb
, verbosity
);
162 /* Prints to FILE the scattering functions of every PBB of SCOP. */
165 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
170 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
171 print_scattering_function (file
, pbb
, verbosity
);
174 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
178 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
183 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
184 print_iteration_domain (file
, pbb
, verbosity
);
187 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
191 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
193 print_scattering_function (stderr
, pbb
, verbosity
);
196 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
200 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
202 print_iteration_domain (stderr
, pbb
, verbosity
);
205 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
206 some VERBOSITY level. */
209 debug_scattering_functions (scop_p scop
, int verbosity
)
211 print_scattering_functions (stderr
, scop
, verbosity
);
214 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
215 some VERBOSITY level. */
218 debug_iteration_domains (scop_p scop
, int verbosity
)
220 print_iteration_domains (stderr
, scop
, verbosity
);
223 /* Apply graphite transformations to all the basic blocks of SCOP. */
226 apply_poly_transforms (scop_p scop
)
228 bool transform_done
= false;
230 /* Generate code even if we did not apply any real transformation.
231 This also allows to check the performance for the identity
232 transformation: GIMPLE -> GRAPHITE -> GIMPLE
233 Keep in mind that CLooG optimizes in control, so the loop structure
234 may change, even if we only use -fgraphite-identity. */
235 if (flag_graphite_identity
)
236 transform_done
= true;
238 if (flag_loop_parallelize_all
)
239 transform_done
= true;
242 transform_done
|= scop_do_block (scop
);
245 if (flag_loop_strip_mine
)
246 transform_done
|= scop_do_strip_mine (scop
, 0);
248 if (flag_loop_interchange
)
249 transform_done
|= scop_do_interchange (scop
);
252 /* This pass needs to be run at the final stage, as it does not
254 if (flag_loop_optimize_isl
)
255 transform_done
|= optimize_isl (scop
);
257 return transform_done
;
260 /* Create a new polyhedral data reference and add it to PBB. It is
261 defined by its ACCESSES, its TYPE, and the number of subscripts
265 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
266 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
267 isl_map
*acc
, isl_set
*extent
)
270 poly_dr_p pdr
= XNEW (struct poly_dr
);
273 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
274 PDR_NB_REFS (pdr
) = 1;
277 pdr
->extent
= extent
;
278 PDR_TYPE (pdr
) = type
;
280 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
281 PBB_DRS (pbb
).safe_push (pdr
);
284 /* Free polyhedral data reference PDR. */
287 free_poly_dr (poly_dr_p pdr
)
289 isl_map_free (pdr
->accesses
);
290 isl_set_free (pdr
->extent
);
294 /* Create a new polyhedral black box. */
297 new_poly_bb (scop_p scop
, void *black_box
)
299 poly_bb_p pbb
= XNEW (struct poly_bb
);
302 pbb
->schedule
= NULL
;
303 pbb
->transformed
= NULL
;
305 PBB_SCOP (pbb
) = scop
;
306 pbb_set_black_box (pbb
, black_box
);
307 PBB_TRANSFORMED (pbb
) = NULL
;
308 PBB_SAVED (pbb
) = NULL
;
309 PBB_ORIGINAL (pbb
) = NULL
;
310 PBB_DRS (pbb
).create (3);
311 PBB_IS_REDUCTION (pbb
) = false;
312 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
317 /* Free polyhedral black box. */
320 free_poly_bb (poly_bb_p pbb
)
325 isl_set_free (pbb
->domain
);
326 isl_map_free (pbb
->schedule
);
327 isl_map_free (pbb
->transformed
);
328 isl_map_free (pbb
->saved
);
330 if (PBB_DRS (pbb
).exists ())
331 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
334 PBB_DRS (pbb
).release ();
339 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
343 fprintf (file
, "# eq");
345 fprintf (file
, " alias");
347 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
348 fprintf (file
, " sub%d", (int) i
);
350 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
351 fprintf (file
, " i%d", (int) i
);
353 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
354 fprintf (file
, " p%d", (int) i
);
356 fprintf (file
, " cst\n");
359 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
363 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
367 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
369 switch (PDR_TYPE (pdr
))
372 fprintf (file
, "read \n");
376 fprintf (file
, "write \n");
380 fprintf (file
, "may_write \n");
387 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
392 fprintf (file
, "# data accesses (\n");
393 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
396 /* XXX isl dump accesses/subscripts */
399 fprintf (file
, "#)\n");
402 fprintf (file
, "#)\n");
405 /* Prints to STDERR the polyhedral data reference PDR, at some
409 debug_pdr (poly_dr_p pdr
, int verbosity
)
411 print_pdr (stderr
, pdr
, verbosity
);
414 /* Creates a new SCOP containing REGION. */
417 new_scop (void *region
)
419 scop_p scop
= XNEW (struct scop
);
421 scop
->context
= NULL
;
422 scop
->must_raw
= NULL
;
423 scop
->may_raw
= NULL
;
424 scop
->must_raw_no_source
= NULL
;
425 scop
->may_raw_no_source
= NULL
;
426 scop
->must_war
= NULL
;
427 scop
->may_war
= NULL
;
428 scop
->must_war_no_source
= NULL
;
429 scop
->may_war_no_source
= NULL
;
430 scop
->must_waw
= NULL
;
431 scop
->may_waw
= NULL
;
432 scop
->must_waw_no_source
= NULL
;
433 scop
->may_waw_no_source
= NULL
;
434 scop_set_region (scop
, region
);
435 SCOP_BBS (scop
).create (3);
436 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
437 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
438 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
439 POLY_SCOP_P (scop
) = false;
447 free_scop (scop_p scop
)
452 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
455 SCOP_BBS (scop
).release ();
457 isl_set_free (scop
->context
);
458 isl_union_map_free (scop
->must_raw
);
459 isl_union_map_free (scop
->may_raw
);
460 isl_union_map_free (scop
->must_raw_no_source
);
461 isl_union_map_free (scop
->may_raw_no_source
);
462 isl_union_map_free (scop
->must_war
);
463 isl_union_map_free (scop
->may_war
);
464 isl_union_map_free (scop
->must_war_no_source
);
465 isl_union_map_free (scop
->may_war_no_source
);
466 isl_union_map_free (scop
->must_waw
);
467 isl_union_map_free (scop
->may_waw
);
468 isl_union_map_free (scop
->must_waw_no_source
);
469 isl_union_map_free (scop
->may_waw_no_source
);
470 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
471 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
472 free_lst (SCOP_SAVED_SCHEDULE (scop
));
476 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
480 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
483 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
490 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
491 fprintf (file
, "#eq");
493 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
494 fprintf (file
, " i%d", (int) i
);
496 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
497 fprintf (file
, " p%d", (int) i
);
499 fprintf (file
, " cst\n");
502 fprintf (file
, "XXX isl\n");
505 fprintf (file
, "#)\n");
508 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
511 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
513 print_isl_set (file
, pbb
->domain
);
516 /* Dump the cases of a graphite basic block GBB on FILE. */
519 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
528 cases
= GBB_CONDITION_CASES (gbb
);
529 if (cases
.is_empty ())
532 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
534 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
536 fprintf (file
, "# ");
537 print_gimple_stmt (file
, stmt
, 0, 0);
540 fprintf (file
, "#)\n");
543 /* Dump conditions of a graphite basic block GBB on FILE. */
546 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
550 vec
<gimple
> conditions
;
555 conditions
= GBB_CONDITIONS (gbb
);
556 if (conditions
.is_empty ())
559 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
561 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
563 fprintf (file
, "# ");
564 print_gimple_stmt (file
, stmt
, 0, 0);
567 fprintf (file
, "#)\n");
570 /* Print to FILE all the data references of PBB, at some VERBOSITY
574 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
581 if (PBB_DRS (pbb
).length () == 0)
584 fprintf (file
, "# Access informations are not provided\n");\
585 fprintf (file
, "0\n");
590 fprintf (file
, "# Data references (\n");
593 fprintf (file
, "# Access informations are provided\n");
594 fprintf (file
, "1\n");
596 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
597 if (PDR_TYPE (pdr
) == PDR_READ
)
603 fprintf (file
, "# Read data references (\n");
606 fprintf (file
, "# Read access informations\n");
607 fprintf (file
, "%d\n", nb_reads
);
609 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
610 if (PDR_TYPE (pdr
) == PDR_READ
)
611 print_pdr (file
, pdr
, verbosity
);
614 fprintf (file
, "#)\n");
617 fprintf (file
, "# Write data references (\n");
620 fprintf (file
, "# Write access informations\n");
621 fprintf (file
, "%d\n", nb_writes
);
623 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
624 if (PDR_TYPE (pdr
) != PDR_READ
)
625 print_pdr (file
, pdr
, verbosity
);
628 fprintf (file
, "#)\n");
631 fprintf (file
, "#)\n");
634 /* Print to STDERR all the data references of PBB. */
637 debug_pdrs (poly_bb_p pbb
, int verbosity
)
639 print_pdrs (stderr
, pbb
, verbosity
);
642 /* Print to FILE the body of PBB, at some VERBOSITY level.
643 If statement_body_provided is false statement body is not printed. */
646 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
647 bool statement_body_provided
)
650 fprintf (file
, "# Body (\n");
652 if (!statement_body_provided
)
655 fprintf (file
, "# Statement body is not provided\n");
657 fprintf (file
, "0\n");
660 fprintf (file
, "#)\n");
665 fprintf (file
, "# Statement body is provided\n");
666 fprintf (file
, "1\n");
669 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
672 fprintf (file
, "# Statement body\n");
674 fprintf (file
, "{\n");
675 dump_bb (file
, pbb_bb (pbb
), 0, 0);
676 fprintf (file
, "}\n");
679 fprintf (file
, "#)\n");
682 /* Print to FILE the domain and scattering function of PBB, at some
686 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
690 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
691 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
692 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
695 openscop_print_pbb_domain (file
, pbb
, verbosity
);
696 print_scattering_function (file
, pbb
, verbosity
);
697 print_pdrs (file
, pbb
, verbosity
);
698 print_pbb_body (file
, pbb
, verbosity
, false);
701 fprintf (file
, "#)\n");
704 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
707 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
713 fprintf (file
, "# parameters (\n");
715 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
718 fprintf (file
, "# Parameter names are provided\n");
720 fprintf (file
, "1\n");
723 fprintf (file
, "# Parameter names\n");
728 fprintf (file
, "# Parameter names are not provided\n");
729 fprintf (file
, "0\n");
732 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
734 print_generic_expr (file
, t
, 0);
738 fprintf (file
, "\n");
741 fprintf (file
, "#)\n");
744 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
748 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
754 fprintf (file
, "# Context (\n");
755 fprintf (file
, "#eq");
757 for (i
= 0; i
< scop_nb_params (scop
); i
++)
758 fprintf (file
, " p%d", (int) i
);
760 fprintf (file
, " cst\n");
764 /* XXX isl print context */
765 fprintf (file
, "XXX isl\n");
767 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
768 (int) scop_nb_params (scop
));
771 fprintf (file
, "# )\n");
774 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
777 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
783 fprintf (file
, "# Context (\n");
784 fprintf (file
, "#eq");
786 for (i
= 0; i
< scop_nb_params (scop
); i
++)
787 fprintf (file
, " p%d", (int) i
);
789 fprintf (file
, " cst\n");
793 print_isl_set (file
, scop
->context
);
795 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
798 fprintf (file
, "# )\n");
801 /* Print to FILE the SCOP, at some VERBOSITY level. */
804 print_scop (FILE *file
, scop_p scop
, int verbosity
)
809 fprintf (file
, "SCoP 1\n#(\n");
810 fprintf (file
, "# Language\nGimple\n");
811 openscop_print_scop_context (file
, scop
, verbosity
);
812 print_scop_params (file
, scop
, verbosity
);
815 fprintf (file
, "# Number of statements\n");
817 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
819 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
820 print_pbb (file
, pbb
, verbosity
);
824 fprintf (file
, "# original_lst (\n");
825 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
826 fprintf (file
, "\n#)\n");
828 fprintf (file
, "# transformed_lst (\n");
829 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
830 fprintf (file
, "\n#)\n");
833 fprintf (file
, "#)\n");
836 /* Print to FILE the input file that CLooG would expect as input, at
837 some VERBOSITY level. */
840 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
845 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
847 fprintf (file
, "# CLooG output language\n");
848 fprintf (file
, "c\n");
850 print_scop_context (file
, scop
, verbosity
);
851 print_scop_params (file
, scop
, verbosity
);
854 fprintf (file
, "# Number of statements\n");
856 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
858 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
861 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
863 print_pbb_domain (file
, pbb
, verbosity
);
864 fprintf (file
, "0 0 0");
867 fprintf (file
, "# For future CLooG options.\n");
869 fprintf (file
, "\n");
872 fprintf (file
, "#)\n");
877 fprintf (file
, "# Don't set the iterator names.\n");
879 fprintf (file
, "\n");
882 fprintf (file
, "# Number of scattering functions\n");
884 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
886 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
888 if (!(pbb
->transformed
|| pbb
->schedule
))
892 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
894 print_scattering_function_1 (file
, pbb
, verbosity
);
897 fprintf (file
, "#)\n");
902 fprintf (file
, "# Don't set the scattering dimension names.\n");
904 fprintf (file
, "\n");
906 fprintf (file
, "#)\n");
909 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
912 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
914 print_pbb_domain (stderr
, pbb
, verbosity
);
917 /* Print to FILE the domain and scattering function of PBB, at some
921 debug_pbb (poly_bb_p pbb
, int verbosity
)
923 print_pbb (stderr
, pbb
, verbosity
);
926 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
929 debug_scop_context (scop_p scop
, int verbosity
)
931 print_scop_context (stderr
, scop
, verbosity
);
934 /* Print to STDERR the SCOP, at some VERBOSITY level. */
937 debug_scop (scop_p scop
, int verbosity
)
939 print_scop (stderr
, scop
, verbosity
);
942 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
946 debug_cloog (scop_p scop
, int verbosity
)
948 print_cloog (stderr
, scop
, verbosity
);
951 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
955 debug_scop_params (scop_p scop
, int verbosity
)
957 print_scop_params (stderr
, scop
, verbosity
);
960 extern isl_ctx
*the_isl_ctx
;
962 print_isl_set (FILE *f
, isl_set
*set
)
964 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
965 p
= isl_printer_print_set (p
, set
);
966 isl_printer_free (p
);
970 debug_isl_set (isl_set
*set
)
972 print_isl_set (stderr
, set
);
976 print_isl_map (FILE *f
, isl_map
*map
)
978 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
979 p
= isl_printer_print_map (p
, map
);
980 isl_printer_free (p
);
984 debug_isl_map (isl_map
*map
)
986 print_isl_map (stderr
, map
);
990 print_isl_aff (FILE *f
, isl_aff
*aff
)
992 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
993 p
= isl_printer_print_aff (p
, aff
);
994 isl_printer_free (p
);
998 debug_isl_aff (isl_aff
*aff
)
1000 print_isl_aff (stderr
, aff
);
1004 print_isl_constraint (FILE *f
, isl_constraint
*c
)
1006 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1007 p
= isl_printer_print_constraint (p
, c
);
1008 isl_printer_free (p
);
1012 debug_isl_constraint (isl_constraint
*c
)
1014 print_isl_constraint (stderr
, c
);
1017 /* Returns the number of iterations RES of the loop around PBB at
1018 time(scattering) dimension TIME_DEPTH. */
1021 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1022 graphite_dim_t time_depth
,
1025 isl_set
*transdomain
;
1028 isl_int isllb
, islub
;
1030 isl_int_init (isllb
);
1031 isl_int_init (islub
);
1033 /* Map the iteration domain through the current scatter, and work
1034 on the resulting set. */
1035 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
1036 isl_map_copy (pbb
->transformed
));
1038 /* Select the time_depth' dimension via an affine expression. */
1039 dc
= isl_set_get_space (transdomain
);
1040 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
1041 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
1043 /* And find the min/max for that function. */
1044 /* XXX isl check results? */
1045 isl_set_min (transdomain
, aff
, &isllb
);
1046 isl_set_max (transdomain
, aff
, &islub
);
1048 isl_int_sub (islub
, islub
, isllb
);
1049 isl_int_add_ui (islub
, islub
, 1);
1050 isl_int_get_gmp (islub
, res
);
1052 isl_int_clear (isllb
);
1053 isl_int_clear (islub
);
1055 isl_set_free (transdomain
);
1058 /* Translates LOOP to LST. */
1061 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
1067 for (; bbs
.iterate (*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 seq
.safe_push (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
= SCOP_BBS (scop
).length ();
1105 sese region
= SCOP_REGION (scop
);
1107 for (i
= 0; i
< n
; i
++)
1109 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1110 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1112 if (loop_in_sese_p (loop
, region
))
1113 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1115 res
= new_lst_stmt (pbb
);
1117 seq
.safe_push (res
);
1120 res
= new_lst_loop (seq
);
1121 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1122 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1125 /* Print to FILE on a new line COLUMN white spaces. */
1128 lst_indent_to (FILE *file
, int column
)
1133 fprintf (file
, "\n#");
1135 for (i
= 0; i
< column
; i
++)
1136 fprintf (file
, " ");
1139 /* Print LST to FILE with INDENT spaces of indentation. */
1142 print_lst (FILE *file
, lst_p lst
, int indent
)
1147 lst_indent_to (file
, indent
);
1149 if (LST_LOOP_P (lst
))
1154 if (LST_LOOP_FATHER (lst
))
1155 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1157 fprintf (file
, "#(root");
1159 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1160 print_lst (file
, l
, indent
+ 2);
1162 fprintf (file
, ")");
1165 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1168 /* Print LST to STDERR. */
1171 debug_lst (lst_p lst
)
1173 print_lst (stderr
, lst
, 0);
1176 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1179 dot_lst_1 (FILE *file
, lst_p lst
)
1184 if (LST_LOOP_P (lst
))
1189 if (!LST_LOOP_FATHER (lst
))
1190 fprintf (file
, "L -> L_%d_%d\n",
1192 lst_dewey_number (lst
));
1194 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1195 lst_depth (LST_LOOP_FATHER (lst
)),
1196 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1198 lst_dewey_number (lst
));
1200 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1201 dot_lst_1 (file
, l
);
1205 fprintf (file
, "L_%d_%d -> S_%d\n",
1206 lst_depth (LST_LOOP_FATHER (lst
)),
1207 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1208 pbb_index (LST_PBB (lst
)));
1212 /* Display the LST using dotty. */
1217 /* When debugging, enable the following code. This cannot be used
1218 in production compilers because it calls "system". */
1220 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1221 gcc_assert (stream
);
1223 fputs ("digraph all {\n", stream
);
1224 dot_lst_1 (stream
, lst
);
1225 fputs ("}\n\n", stream
);
1228 system ("dotty /tmp/lst.dot &");
1230 fputs ("digraph all {\n", stderr
);
1231 dot_lst_1 (stderr
, lst
);
1232 fputs ("}\n\n", stderr
);
1237 /* Computes a checksum for the code generated by CLooG for SCOP. */
1240 cloog_checksum (scop_p scop ATTRIBUTE_UNUSED
)
1242 /* When debugging, enable the following code. This cannot be used
1243 in production compilers because it calls "system". */
1245 FILE *stream
= fopen ("/tmp/scop.cloog", "w");
1246 gcc_assert (stream
);
1247 print_cloog (stream
, scop
, 0);
1250 fputs ("\n", stdout
);
1251 system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
1255 /* Reverse the loop around PBB at level DEPTH. */
1258 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1260 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1261 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1262 isl_space
*d1
= isl_space_range (d
);
1263 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1264 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1265 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1266 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1268 for (i
= 0; i
< n
; i
++)
1270 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1272 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1273 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1274 x
= isl_map_add_constraint (x
, c
);
1278 /* Reverse the loop at level DEPTH for all the PBBS. */
1281 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1285 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1286 isl_union_map
*res
= isl_union_map_empty (space
);
1288 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1289 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));