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>
36 #include "coretypes.h"
37 #include "diagnostic-core.h"
39 #include "basic-block.h"
40 #include "tree-ssa-alias.h"
41 #include "internal-fn.h"
42 #include "gimple-expr.h"
45 #include "gimple-iterator.h"
46 #include "tree-ssa-loop.h"
48 #include "gimple-pretty-print.h"
50 #include "tree-chrec.h"
51 #include "tree-data-ref.h"
52 #include "tree-scalar-evolution.h"
56 #include "graphite-poly.h"
58 #define OPENSCOP_MAX_STRING 256
61 /* Print to STDERR the GMP value VAL. */
64 debug_gmp_value (mpz_t val
)
66 gmp_fprintf (stderr
, "%Zd", val
);
69 /* Return the maximal loop depth in SCOP. */
72 scop_max_loop_depth (scop_p scop
)
78 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
80 int nb_loops
= pbb_dim_iter_domain (pbb
);
81 if (max_nb_loops
< nb_loops
)
82 max_nb_loops
= nb_loops
;
88 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
92 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
98 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
99 fprintf (file
, "#eq");
101 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
102 fprintf (file
, " s%d", (int) i
);
104 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
105 fprintf (file
, " lv%d", (int) i
);
107 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
108 fprintf (file
, " i%d", (int) i
);
110 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
111 fprintf (file
, " p%d", (int) i
);
113 fprintf (file
, " cst\n");
116 fprintf (file
, "isl\n");
117 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
120 fprintf (file
, "#)\n");
123 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
127 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
129 if (!PBB_TRANSFORMED (pbb
))
132 if (pbb
->schedule
|| pbb
->transformed
)
135 fprintf (file
, "# Scattering function is provided\n");
137 fprintf (file
, "1\n");
142 fprintf (file
, "# Scattering function is not provided\n");
144 fprintf (file
, "0\n");
148 print_scattering_function_1 (file
, pbb
, verbosity
);
151 fprintf (file
, "# Scattering names are not provided\n");
153 fprintf (file
, "0\n");
157 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
161 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
163 print_pbb_domain (file
, pbb
, verbosity
);
166 /* Prints to FILE the scattering functions of every PBB of SCOP. */
169 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
174 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
175 print_scattering_function (file
, pbb
, verbosity
);
178 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
182 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
187 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
188 print_iteration_domain (file
, pbb
, verbosity
);
191 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
195 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
197 print_scattering_function (stderr
, pbb
, verbosity
);
200 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
204 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
206 print_iteration_domain (stderr
, pbb
, verbosity
);
209 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
210 some VERBOSITY level. */
213 debug_scattering_functions (scop_p scop
, int verbosity
)
215 print_scattering_functions (stderr
, scop
, verbosity
);
218 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
219 some VERBOSITY level. */
222 debug_iteration_domains (scop_p scop
, int verbosity
)
224 print_iteration_domains (stderr
, scop
, verbosity
);
227 /* Apply graphite transformations to all the basic blocks of SCOP. */
230 apply_poly_transforms (scop_p scop
)
232 bool transform_done
= false;
234 /* Generate code even if we did not apply any real transformation.
235 This also allows to check the performance for the identity
236 transformation: GIMPLE -> GRAPHITE -> GIMPLE
237 Keep in mind that CLooG optimizes in control, so the loop structure
238 may change, even if we only use -fgraphite-identity. */
239 if (flag_graphite_identity
)
240 transform_done
= true;
242 if (flag_loop_parallelize_all
)
243 transform_done
= true;
246 transform_done
|= scop_do_block (scop
);
249 if (flag_loop_strip_mine
)
250 transform_done
|= scop_do_strip_mine (scop
, 0);
252 if (flag_loop_interchange
)
253 transform_done
|= scop_do_interchange (scop
);
256 /* This pass needs to be run at the final stage, as it does not
258 if (flag_loop_optimize_isl
)
259 transform_done
|= optimize_isl (scop
);
261 return transform_done
;
264 /* Create a new polyhedral data reference and add it to PBB. It is
265 defined by its ACCESSES, its TYPE, and the number of subscripts
269 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
270 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
271 isl_map
*acc
, isl_set
*extent
)
274 poly_dr_p pdr
= XNEW (struct poly_dr
);
277 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
278 PDR_NB_REFS (pdr
) = 1;
281 pdr
->extent
= extent
;
282 PDR_TYPE (pdr
) = type
;
284 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
285 PBB_DRS (pbb
).safe_push (pdr
);
288 /* Free polyhedral data reference PDR. */
291 free_poly_dr (poly_dr_p pdr
)
293 isl_map_free (pdr
->accesses
);
294 isl_set_free (pdr
->extent
);
298 /* Create a new polyhedral black box. */
301 new_poly_bb (scop_p scop
, void *black_box
)
303 poly_bb_p pbb
= XNEW (struct poly_bb
);
306 pbb
->schedule
= NULL
;
307 pbb
->transformed
= NULL
;
309 PBB_SCOP (pbb
) = scop
;
310 pbb_set_black_box (pbb
, black_box
);
311 PBB_TRANSFORMED (pbb
) = NULL
;
312 PBB_SAVED (pbb
) = NULL
;
313 PBB_ORIGINAL (pbb
) = NULL
;
314 PBB_DRS (pbb
).create (3);
315 PBB_IS_REDUCTION (pbb
) = false;
316 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
321 /* Free polyhedral black box. */
324 free_poly_bb (poly_bb_p pbb
)
329 isl_set_free (pbb
->domain
);
330 isl_map_free (pbb
->schedule
);
331 isl_map_free (pbb
->transformed
);
332 isl_map_free (pbb
->saved
);
334 if (PBB_DRS (pbb
).exists ())
335 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
338 PBB_DRS (pbb
).release ();
343 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
347 fprintf (file
, "# eq");
349 fprintf (file
, " alias");
351 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
352 fprintf (file
, " sub%d", (int) i
);
354 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
355 fprintf (file
, " i%d", (int) i
);
357 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
358 fprintf (file
, " p%d", (int) i
);
360 fprintf (file
, " cst\n");
363 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
367 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
371 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
373 switch (PDR_TYPE (pdr
))
376 fprintf (file
, "read \n");
380 fprintf (file
, "write \n");
384 fprintf (file
, "may_write \n");
391 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
396 fprintf (file
, "# data accesses (\n");
397 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
400 /* XXX isl dump accesses/subscripts */
403 fprintf (file
, "#)\n");
406 fprintf (file
, "#)\n");
409 /* Prints to STDERR the polyhedral data reference PDR, at some
413 debug_pdr (poly_dr_p pdr
, int verbosity
)
415 print_pdr (stderr
, pdr
, verbosity
);
418 /* Creates a new SCOP containing REGION. */
421 new_scop (void *region
)
423 scop_p scop
= XNEW (struct scop
);
425 scop
->context
= NULL
;
426 scop
->must_raw
= NULL
;
427 scop
->may_raw
= NULL
;
428 scop
->must_raw_no_source
= NULL
;
429 scop
->may_raw_no_source
= NULL
;
430 scop
->must_war
= NULL
;
431 scop
->may_war
= NULL
;
432 scop
->must_war_no_source
= NULL
;
433 scop
->may_war_no_source
= NULL
;
434 scop
->must_waw
= NULL
;
435 scop
->may_waw
= NULL
;
436 scop
->must_waw_no_source
= NULL
;
437 scop
->may_waw_no_source
= NULL
;
438 scop_set_region (scop
, region
);
439 SCOP_BBS (scop
).create (3);
440 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
441 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
442 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
443 POLY_SCOP_P (scop
) = false;
451 free_scop (scop_p scop
)
456 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
459 SCOP_BBS (scop
).release ();
461 isl_set_free (scop
->context
);
462 isl_union_map_free (scop
->must_raw
);
463 isl_union_map_free (scop
->may_raw
);
464 isl_union_map_free (scop
->must_raw_no_source
);
465 isl_union_map_free (scop
->may_raw_no_source
);
466 isl_union_map_free (scop
->must_war
);
467 isl_union_map_free (scop
->may_war
);
468 isl_union_map_free (scop
->must_war_no_source
);
469 isl_union_map_free (scop
->may_war_no_source
);
470 isl_union_map_free (scop
->must_waw
);
471 isl_union_map_free (scop
->may_waw
);
472 isl_union_map_free (scop
->must_waw_no_source
);
473 isl_union_map_free (scop
->may_waw_no_source
);
474 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
475 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
476 free_lst (SCOP_SAVED_SCHEDULE (scop
));
480 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
484 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
487 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
494 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
495 fprintf (file
, "#eq");
497 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
498 fprintf (file
, " i%d", (int) i
);
500 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
501 fprintf (file
, " p%d", (int) i
);
503 fprintf (file
, " cst\n");
506 fprintf (file
, "XXX isl\n");
509 fprintf (file
, "#)\n");
512 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
515 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
517 print_isl_set (file
, pbb
->domain
);
520 /* Dump the cases of a graphite basic block GBB on FILE. */
523 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
532 cases
= GBB_CONDITION_CASES (gbb
);
533 if (cases
.is_empty ())
536 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
538 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
540 fprintf (file
, "# ");
541 print_gimple_stmt (file
, stmt
, 0, 0);
544 fprintf (file
, "#)\n");
547 /* Dump conditions of a graphite basic block GBB on FILE. */
550 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
554 vec
<gimple
> conditions
;
559 conditions
= GBB_CONDITIONS (gbb
);
560 if (conditions
.is_empty ())
563 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
565 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
567 fprintf (file
, "# ");
568 print_gimple_stmt (file
, stmt
, 0, 0);
571 fprintf (file
, "#)\n");
574 /* Print to FILE all the data references of PBB, at some VERBOSITY
578 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
585 if (PBB_DRS (pbb
).length () == 0)
588 fprintf (file
, "# Access informations are not provided\n");\
589 fprintf (file
, "0\n");
594 fprintf (file
, "# Data references (\n");
597 fprintf (file
, "# Access informations are provided\n");
598 fprintf (file
, "1\n");
600 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
601 if (PDR_TYPE (pdr
) == PDR_READ
)
607 fprintf (file
, "# Read data references (\n");
610 fprintf (file
, "# Read access informations\n");
611 fprintf (file
, "%d\n", nb_reads
);
613 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
614 if (PDR_TYPE (pdr
) == PDR_READ
)
615 print_pdr (file
, pdr
, verbosity
);
618 fprintf (file
, "#)\n");
621 fprintf (file
, "# Write data references (\n");
624 fprintf (file
, "# Write access informations\n");
625 fprintf (file
, "%d\n", nb_writes
);
627 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
628 if (PDR_TYPE (pdr
) != PDR_READ
)
629 print_pdr (file
, pdr
, verbosity
);
632 fprintf (file
, "#)\n");
635 fprintf (file
, "#)\n");
638 /* Print to STDERR all the data references of PBB. */
641 debug_pdrs (poly_bb_p pbb
, int verbosity
)
643 print_pdrs (stderr
, pbb
, verbosity
);
646 /* Print to FILE the body of PBB, at some VERBOSITY level.
647 If statement_body_provided is false statement body is not printed. */
650 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
651 bool statement_body_provided
)
654 fprintf (file
, "# Body (\n");
656 if (!statement_body_provided
)
659 fprintf (file
, "# Statement body is not provided\n");
661 fprintf (file
, "0\n");
664 fprintf (file
, "#)\n");
669 fprintf (file
, "# Statement body is provided\n");
670 fprintf (file
, "1\n");
673 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
676 fprintf (file
, "# Statement body\n");
678 fprintf (file
, "{\n");
679 dump_bb (file
, pbb_bb (pbb
), 0, 0);
680 fprintf (file
, "}\n");
683 fprintf (file
, "#)\n");
686 /* Print to FILE the domain and scattering function of PBB, at some
690 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
694 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
695 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
696 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
699 openscop_print_pbb_domain (file
, pbb
, verbosity
);
700 print_scattering_function (file
, pbb
, verbosity
);
701 print_pdrs (file
, pbb
, verbosity
);
702 print_pbb_body (file
, pbb
, verbosity
, false);
705 fprintf (file
, "#)\n");
708 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
711 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
717 fprintf (file
, "# parameters (\n");
719 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
722 fprintf (file
, "# Parameter names are provided\n");
724 fprintf (file
, "1\n");
727 fprintf (file
, "# Parameter names\n");
732 fprintf (file
, "# Parameter names are not provided\n");
733 fprintf (file
, "0\n");
736 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
738 print_generic_expr (file
, t
, 0);
742 fprintf (file
, "\n");
745 fprintf (file
, "#)\n");
748 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
752 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
758 fprintf (file
, "# Context (\n");
759 fprintf (file
, "#eq");
761 for (i
= 0; i
< scop_nb_params (scop
); i
++)
762 fprintf (file
, " p%d", (int) i
);
764 fprintf (file
, " cst\n");
768 /* XXX isl print context */
769 fprintf (file
, "XXX isl\n");
771 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
772 (int) scop_nb_params (scop
));
775 fprintf (file
, "# )\n");
778 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
781 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
787 fprintf (file
, "# Context (\n");
788 fprintf (file
, "#eq");
790 for (i
= 0; i
< scop_nb_params (scop
); i
++)
791 fprintf (file
, " p%d", (int) i
);
793 fprintf (file
, " cst\n");
797 print_isl_set (file
, scop
->context
);
799 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
802 fprintf (file
, "# )\n");
805 /* Print to FILE the SCOP, at some VERBOSITY level. */
808 print_scop (FILE *file
, scop_p scop
, int verbosity
)
813 fprintf (file
, "SCoP 1\n#(\n");
814 fprintf (file
, "# Language\nGimple\n");
815 openscop_print_scop_context (file
, scop
, verbosity
);
816 print_scop_params (file
, scop
, verbosity
);
819 fprintf (file
, "# Number of statements\n");
821 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
823 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
824 print_pbb (file
, pbb
, verbosity
);
828 fprintf (file
, "# original_lst (\n");
829 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
830 fprintf (file
, "\n#)\n");
832 fprintf (file
, "# transformed_lst (\n");
833 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
834 fprintf (file
, "\n#)\n");
837 fprintf (file
, "#)\n");
840 /* Print to FILE the input file that CLooG would expect as input, at
841 some VERBOSITY level. */
844 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
849 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
851 fprintf (file
, "# CLooG output language\n");
852 fprintf (file
, "c\n");
854 print_scop_context (file
, scop
, verbosity
);
855 print_scop_params (file
, scop
, verbosity
);
858 fprintf (file
, "# Number of statements\n");
860 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
862 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
865 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
867 print_pbb_domain (file
, pbb
, verbosity
);
868 fprintf (file
, "0 0 0");
871 fprintf (file
, "# For future CLooG options.\n");
873 fprintf (file
, "\n");
876 fprintf (file
, "#)\n");
881 fprintf (file
, "# Don't set the iterator names.\n");
883 fprintf (file
, "\n");
886 fprintf (file
, "# Number of scattering functions\n");
888 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
890 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
892 if (!(pbb
->transformed
|| pbb
->schedule
))
896 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
898 print_scattering_function_1 (file
, pbb
, verbosity
);
901 fprintf (file
, "#)\n");
906 fprintf (file
, "# Don't set the scattering dimension names.\n");
908 fprintf (file
, "\n");
910 fprintf (file
, "#)\n");
913 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
916 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
918 print_pbb_domain (stderr
, pbb
, verbosity
);
921 /* Print to FILE the domain and scattering function of PBB, at some
925 debug_pbb (poly_bb_p pbb
, int verbosity
)
927 print_pbb (stderr
, pbb
, verbosity
);
930 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
933 debug_scop_context (scop_p scop
, int verbosity
)
935 print_scop_context (stderr
, scop
, verbosity
);
938 /* Print to STDERR the SCOP, at some VERBOSITY level. */
941 debug_scop (scop_p scop
, int verbosity
)
943 print_scop (stderr
, scop
, verbosity
);
946 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
950 debug_cloog (scop_p scop
, int verbosity
)
952 print_cloog (stderr
, scop
, verbosity
);
955 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
959 debug_scop_params (scop_p scop
, int verbosity
)
961 print_scop_params (stderr
, scop
, verbosity
);
964 extern isl_ctx
*the_isl_ctx
;
966 print_isl_set (FILE *f
, isl_set
*set
)
968 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
969 p
= isl_printer_print_set (p
, set
);
970 isl_printer_free (p
);
974 debug_isl_set (isl_set
*set
)
976 print_isl_set (stderr
, set
);
980 print_isl_map (FILE *f
, isl_map
*map
)
982 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
983 p
= isl_printer_print_map (p
, map
);
984 isl_printer_free (p
);
988 debug_isl_map (isl_map
*map
)
990 print_isl_map (stderr
, map
);
994 print_isl_aff (FILE *f
, isl_aff
*aff
)
996 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
997 p
= isl_printer_print_aff (p
, aff
);
998 isl_printer_free (p
);
1002 debug_isl_aff (isl_aff
*aff
)
1004 print_isl_aff (stderr
, aff
);
1008 print_isl_constraint (FILE *f
, isl_constraint
*c
)
1010 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1011 p
= isl_printer_print_constraint (p
, c
);
1012 isl_printer_free (p
);
1016 debug_isl_constraint (isl_constraint
*c
)
1018 print_isl_constraint (stderr
, c
);
1021 /* Returns the number of iterations RES of the loop around PBB at
1022 time(scattering) dimension TIME_DEPTH. */
1025 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1026 graphite_dim_t time_depth
,
1029 isl_set
*transdomain
;
1032 isl_int isllb
, islub
;
1034 isl_int_init (isllb
);
1035 isl_int_init (islub
);
1037 /* Map the iteration domain through the current scatter, and work
1038 on the resulting set. */
1039 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
1040 isl_map_copy (pbb
->transformed
));
1042 /* Select the time_depth' dimension via an affine expression. */
1043 dc
= isl_set_get_space (transdomain
);
1044 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
1045 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
1047 /* And find the min/max for that function. */
1048 /* XXX isl check results? */
1049 isl_set_min (transdomain
, aff
, &isllb
);
1050 isl_set_max (transdomain
, aff
, &islub
);
1052 isl_int_sub (islub
, islub
, isllb
);
1053 isl_int_add_ui (islub
, islub
, 1);
1054 isl_int_get_gmp (islub
, res
);
1056 isl_int_clear (isllb
);
1057 isl_int_clear (islub
);
1059 isl_set_free (transdomain
);
1062 /* Translates LOOP to LST. */
1065 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
1071 for (; bbs
.iterate (*i
, &pbb
); (*i
)++)
1074 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1076 if (bb
->loop_father
== loop
)
1077 stmt
= new_lst_stmt (pbb
);
1078 else if (flow_bb_inside_loop_p (loop
, bb
))
1080 loop_p next
= loop
->inner
;
1082 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1085 stmt
= loop_to_lst (next
, bbs
, i
);
1090 return new_lst_loop (seq
);
1093 seq
.safe_push (stmt
);
1096 return new_lst_loop (seq
);
1099 /* Reads the original scattering of the SCOP and returns an LST
1103 scop_to_lst (scop_p scop
)
1106 int i
, n
= SCOP_BBS (scop
).length ();
1109 sese region
= SCOP_REGION (scop
);
1111 for (i
= 0; i
< n
; i
++)
1113 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1114 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1116 if (loop_in_sese_p (loop
, region
))
1117 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1119 res
= new_lst_stmt (pbb
);
1121 seq
.safe_push (res
);
1124 res
= new_lst_loop (seq
);
1125 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1126 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1129 /* Print to FILE on a new line COLUMN white spaces. */
1132 lst_indent_to (FILE *file
, int column
)
1137 fprintf (file
, "\n#");
1139 for (i
= 0; i
< column
; i
++)
1140 fprintf (file
, " ");
1143 /* Print LST to FILE with INDENT spaces of indentation. */
1146 print_lst (FILE *file
, lst_p lst
, int indent
)
1151 lst_indent_to (file
, indent
);
1153 if (LST_LOOP_P (lst
))
1158 if (LST_LOOP_FATHER (lst
))
1159 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1161 fprintf (file
, "#(root");
1163 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1164 print_lst (file
, l
, indent
+ 2);
1166 fprintf (file
, ")");
1169 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1172 /* Print LST to STDERR. */
1175 debug_lst (lst_p lst
)
1177 print_lst (stderr
, lst
, 0);
1180 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1183 dot_lst_1 (FILE *file
, lst_p lst
)
1188 if (LST_LOOP_P (lst
))
1193 if (!LST_LOOP_FATHER (lst
))
1194 fprintf (file
, "L -> L_%d_%d\n",
1196 lst_dewey_number (lst
));
1198 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1199 lst_depth (LST_LOOP_FATHER (lst
)),
1200 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1202 lst_dewey_number (lst
));
1204 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1205 dot_lst_1 (file
, l
);
1209 fprintf (file
, "L_%d_%d -> S_%d\n",
1210 lst_depth (LST_LOOP_FATHER (lst
)),
1211 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1212 pbb_index (LST_PBB (lst
)));
1216 /* Display the LST using dotty. */
1221 /* When debugging, enable the following code. This cannot be used
1222 in production compilers because it calls "system". */
1224 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1225 gcc_assert (stream
);
1227 fputs ("digraph all {\n", stream
);
1228 dot_lst_1 (stream
, lst
);
1229 fputs ("}\n\n", stream
);
1232 system ("dotty /tmp/lst.dot &");
1234 fputs ("digraph all {\n", stderr
);
1235 dot_lst_1 (stderr
, lst
);
1236 fputs ("}\n\n", stderr
);
1241 /* Computes a checksum for the code generated by CLooG for SCOP. */
1244 cloog_checksum (scop_p scop ATTRIBUTE_UNUSED
)
1246 /* When debugging, enable the following code. This cannot be used
1247 in production compilers because it calls "system". */
1249 FILE *stream
= fopen ("/tmp/scop.cloog", "w");
1250 gcc_assert (stream
);
1251 print_cloog (stream
, scop
, 0);
1254 fputs ("\n", stdout
);
1255 system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
1259 /* Reverse the loop around PBB at level DEPTH. */
1262 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1264 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1265 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1266 isl_space
*d1
= isl_space_range (d
);
1267 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1268 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1269 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1270 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1272 for (i
= 0; i
< n
; i
++)
1274 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1276 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1277 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1278 x
= isl_map_add_constraint (x
, c
);
1282 /* Reverse the loop at level DEPTH for all the PBBS. */
1285 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1289 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1290 isl_union_map
*res
= isl_union_map_empty (space
);
1292 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1293 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));