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>
32 #if defined(__cplusplus)
35 #include <isl/val_gmp.h>
36 #if defined(__cplusplus)
40 #include <cloog/cloog.h>
41 #include <cloog/isl/domain.h>
46 #include "coretypes.h"
47 #include "diagnostic-core.h"
49 #include "basic-block.h"
50 #include "tree-ssa-alias.h"
51 #include "internal-fn.h"
52 #include "gimple-expr.h"
55 #include "gimple-iterator.h"
56 #include "tree-ssa-loop.h"
58 #include "gimple-pretty-print.h"
60 #include "tree-chrec.h"
61 #include "tree-data-ref.h"
62 #include "tree-scalar-evolution.h"
66 #include "graphite-poly.h"
68 #define OPENSCOP_MAX_STRING 256
71 /* Print to STDERR the GMP value VAL. */
74 debug_gmp_value (mpz_t val
)
76 gmp_fprintf (stderr
, "%Zd", val
);
79 /* Return the maximal loop depth in SCOP. */
82 scop_max_loop_depth (scop_p scop
)
88 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
90 int nb_loops
= pbb_dim_iter_domain (pbb
);
91 if (max_nb_loops
< nb_loops
)
92 max_nb_loops
= nb_loops
;
98 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
102 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
108 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
109 fprintf (file
, "#eq");
111 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
112 fprintf (file
, " s%d", (int) i
);
114 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
115 fprintf (file
, " lv%d", (int) i
);
117 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
118 fprintf (file
, " i%d", (int) i
);
120 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
121 fprintf (file
, " p%d", (int) i
);
123 fprintf (file
, " cst\n");
126 fprintf (file
, "isl\n");
127 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
130 fprintf (file
, "#)\n");
133 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
137 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
139 if (!PBB_TRANSFORMED (pbb
))
142 if (pbb
->schedule
|| pbb
->transformed
)
145 fprintf (file
, "# Scattering function is provided\n");
147 fprintf (file
, "1\n");
152 fprintf (file
, "# Scattering function is not provided\n");
154 fprintf (file
, "0\n");
158 print_scattering_function_1 (file
, pbb
, verbosity
);
161 fprintf (file
, "# Scattering names are not provided\n");
163 fprintf (file
, "0\n");
167 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
171 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
173 print_pbb_domain (file
, pbb
, verbosity
);
176 /* Prints to FILE the scattering functions of every PBB of SCOP. */
179 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
184 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
185 print_scattering_function (file
, pbb
, verbosity
);
188 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
192 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
197 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
198 print_iteration_domain (file
, pbb
, verbosity
);
201 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
205 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
207 print_scattering_function (stderr
, pbb
, verbosity
);
210 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
214 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
216 print_iteration_domain (stderr
, pbb
, verbosity
);
219 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
220 some VERBOSITY level. */
223 debug_scattering_functions (scop_p scop
, int verbosity
)
225 print_scattering_functions (stderr
, scop
, verbosity
);
228 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
229 some VERBOSITY level. */
232 debug_iteration_domains (scop_p scop
, int verbosity
)
234 print_iteration_domains (stderr
, scop
, verbosity
);
237 /* Apply graphite transformations to all the basic blocks of SCOP. */
240 apply_poly_transforms (scop_p scop
)
242 bool transform_done
= false;
244 /* Generate code even if we did not apply any real transformation.
245 This also allows to check the performance for the identity
246 transformation: GIMPLE -> GRAPHITE -> GIMPLE
247 Keep in mind that CLooG optimizes in control, so the loop structure
248 may change, even if we only use -fgraphite-identity. */
249 if (flag_graphite_identity
)
250 transform_done
= true;
252 if (flag_loop_parallelize_all
)
253 transform_done
= true;
256 transform_done
|= scop_do_block (scop
);
259 if (flag_loop_strip_mine
)
260 transform_done
|= scop_do_strip_mine (scop
, 0);
262 if (flag_loop_interchange
)
263 transform_done
|= scop_do_interchange (scop
);
266 /* This pass needs to be run at the final stage, as it does not
268 if (flag_loop_optimize_isl
)
269 transform_done
|= optimize_isl (scop
);
271 return transform_done
;
274 /* Create a new polyhedral data reference and add it to PBB. It is
275 defined by its ACCESSES, its TYPE, and the number of subscripts
279 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
280 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
281 isl_map
*acc
, isl_set
*extent
)
284 poly_dr_p pdr
= XNEW (struct poly_dr
);
287 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
288 PDR_NB_REFS (pdr
) = 1;
291 pdr
->extent
= extent
;
292 PDR_TYPE (pdr
) = type
;
294 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
295 PBB_DRS (pbb
).safe_push (pdr
);
298 /* Free polyhedral data reference PDR. */
301 free_poly_dr (poly_dr_p pdr
)
303 isl_map_free (pdr
->accesses
);
304 isl_set_free (pdr
->extent
);
308 /* Create a new polyhedral black box. */
311 new_poly_bb (scop_p scop
, void *black_box
)
313 poly_bb_p pbb
= XNEW (struct poly_bb
);
316 pbb
->schedule
= NULL
;
317 pbb
->transformed
= NULL
;
319 PBB_SCOP (pbb
) = scop
;
320 pbb_set_black_box (pbb
, black_box
);
321 PBB_TRANSFORMED (pbb
) = NULL
;
322 PBB_SAVED (pbb
) = NULL
;
323 PBB_ORIGINAL (pbb
) = NULL
;
324 PBB_DRS (pbb
).create (3);
325 PBB_IS_REDUCTION (pbb
) = false;
326 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
331 /* Free polyhedral black box. */
334 free_poly_bb (poly_bb_p pbb
)
339 isl_set_free (pbb
->domain
);
340 isl_map_free (pbb
->schedule
);
341 isl_map_free (pbb
->transformed
);
342 isl_map_free (pbb
->saved
);
344 if (PBB_DRS (pbb
).exists ())
345 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
348 PBB_DRS (pbb
).release ();
353 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
357 fprintf (file
, "# eq");
359 fprintf (file
, " alias");
361 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
362 fprintf (file
, " sub%d", (int) i
);
364 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
365 fprintf (file
, " i%d", (int) i
);
367 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
368 fprintf (file
, " p%d", (int) i
);
370 fprintf (file
, " cst\n");
373 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
377 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
381 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
383 switch (PDR_TYPE (pdr
))
386 fprintf (file
, "read \n");
390 fprintf (file
, "write \n");
394 fprintf (file
, "may_write \n");
401 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
406 fprintf (file
, "# data accesses (\n");
407 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
410 /* XXX isl dump accesses/subscripts */
413 fprintf (file
, "#)\n");
416 fprintf (file
, "#)\n");
419 /* Prints to STDERR the polyhedral data reference PDR, at some
423 debug_pdr (poly_dr_p pdr
, int verbosity
)
425 print_pdr (stderr
, pdr
, verbosity
);
428 /* Creates a new SCOP containing REGION. */
431 new_scop (void *region
)
433 scop_p scop
= XNEW (struct scop
);
435 scop
->context
= NULL
;
436 scop
->must_raw
= NULL
;
437 scop
->may_raw
= NULL
;
438 scop
->must_raw_no_source
= NULL
;
439 scop
->may_raw_no_source
= NULL
;
440 scop
->must_war
= NULL
;
441 scop
->may_war
= NULL
;
442 scop
->must_war_no_source
= NULL
;
443 scop
->may_war_no_source
= NULL
;
444 scop
->must_waw
= NULL
;
445 scop
->may_waw
= NULL
;
446 scop
->must_waw_no_source
= NULL
;
447 scop
->may_waw_no_source
= NULL
;
448 scop_set_region (scop
, region
);
449 SCOP_BBS (scop
).create (3);
450 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
451 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
452 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
453 POLY_SCOP_P (scop
) = false;
461 free_scop (scop_p scop
)
466 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
469 SCOP_BBS (scop
).release ();
471 isl_set_free (scop
->context
);
472 isl_union_map_free (scop
->must_raw
);
473 isl_union_map_free (scop
->may_raw
);
474 isl_union_map_free (scop
->must_raw_no_source
);
475 isl_union_map_free (scop
->may_raw_no_source
);
476 isl_union_map_free (scop
->must_war
);
477 isl_union_map_free (scop
->may_war
);
478 isl_union_map_free (scop
->must_war_no_source
);
479 isl_union_map_free (scop
->may_war_no_source
);
480 isl_union_map_free (scop
->must_waw
);
481 isl_union_map_free (scop
->may_waw
);
482 isl_union_map_free (scop
->must_waw_no_source
);
483 isl_union_map_free (scop
->may_waw_no_source
);
484 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
485 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
486 free_lst (SCOP_SAVED_SCHEDULE (scop
));
490 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
494 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
497 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
504 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
505 fprintf (file
, "#eq");
507 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
508 fprintf (file
, " i%d", (int) i
);
510 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
511 fprintf (file
, " p%d", (int) i
);
513 fprintf (file
, " cst\n");
516 fprintf (file
, "XXX isl\n");
519 fprintf (file
, "#)\n");
522 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
525 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
527 print_isl_set (file
, pbb
->domain
);
530 /* Dump the cases of a graphite basic block GBB on FILE. */
533 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
542 cases
= GBB_CONDITION_CASES (gbb
);
543 if (cases
.is_empty ())
546 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
548 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
550 fprintf (file
, "# ");
551 print_gimple_stmt (file
, stmt
, 0, 0);
554 fprintf (file
, "#)\n");
557 /* Dump conditions of a graphite basic block GBB on FILE. */
560 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
564 vec
<gimple
> conditions
;
569 conditions
= GBB_CONDITIONS (gbb
);
570 if (conditions
.is_empty ())
573 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
575 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
577 fprintf (file
, "# ");
578 print_gimple_stmt (file
, stmt
, 0, 0);
581 fprintf (file
, "#)\n");
584 /* Print to FILE all the data references of PBB, at some VERBOSITY
588 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
595 if (PBB_DRS (pbb
).length () == 0)
598 fprintf (file
, "# Access informations are not provided\n");\
599 fprintf (file
, "0\n");
604 fprintf (file
, "# Data references (\n");
607 fprintf (file
, "# Access informations are provided\n");
608 fprintf (file
, "1\n");
610 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
611 if (PDR_TYPE (pdr
) == PDR_READ
)
617 fprintf (file
, "# Read data references (\n");
620 fprintf (file
, "# Read access informations\n");
621 fprintf (file
, "%d\n", nb_reads
);
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
, "# Write data references (\n");
634 fprintf (file
, "# Write access informations\n");
635 fprintf (file
, "%d\n", nb_writes
);
637 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
638 if (PDR_TYPE (pdr
) != PDR_READ
)
639 print_pdr (file
, pdr
, verbosity
);
642 fprintf (file
, "#)\n");
645 fprintf (file
, "#)\n");
648 /* Print to STDERR all the data references of PBB. */
651 debug_pdrs (poly_bb_p pbb
, int verbosity
)
653 print_pdrs (stderr
, pbb
, verbosity
);
656 /* Print to FILE the body of PBB, at some VERBOSITY level.
657 If statement_body_provided is false statement body is not printed. */
660 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
661 bool statement_body_provided
)
664 fprintf (file
, "# Body (\n");
666 if (!statement_body_provided
)
669 fprintf (file
, "# Statement body is not provided\n");
671 fprintf (file
, "0\n");
674 fprintf (file
, "#)\n");
679 fprintf (file
, "# Statement body is provided\n");
680 fprintf (file
, "1\n");
683 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
686 fprintf (file
, "# Statement body\n");
688 fprintf (file
, "{\n");
689 dump_bb (file
, pbb_bb (pbb
), 0, 0);
690 fprintf (file
, "}\n");
693 fprintf (file
, "#)\n");
696 /* Print to FILE the domain and scattering function of PBB, at some
700 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
704 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
705 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
706 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
709 openscop_print_pbb_domain (file
, pbb
, verbosity
);
710 print_scattering_function (file
, pbb
, verbosity
);
711 print_pdrs (file
, pbb
, verbosity
);
712 print_pbb_body (file
, pbb
, verbosity
, false);
715 fprintf (file
, "#)\n");
718 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
721 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
727 fprintf (file
, "# parameters (\n");
729 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
732 fprintf (file
, "# Parameter names are provided\n");
734 fprintf (file
, "1\n");
737 fprintf (file
, "# Parameter names\n");
742 fprintf (file
, "# Parameter names are not provided\n");
743 fprintf (file
, "0\n");
746 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
748 print_generic_expr (file
, t
, 0);
752 fprintf (file
, "\n");
755 fprintf (file
, "#)\n");
758 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
762 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
768 fprintf (file
, "# Context (\n");
769 fprintf (file
, "#eq");
771 for (i
= 0; i
< scop_nb_params (scop
); i
++)
772 fprintf (file
, " p%d", (int) i
);
774 fprintf (file
, " cst\n");
778 /* XXX isl print context */
779 fprintf (file
, "XXX isl\n");
781 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
782 (int) scop_nb_params (scop
));
785 fprintf (file
, "# )\n");
788 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
791 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
797 fprintf (file
, "# Context (\n");
798 fprintf (file
, "#eq");
800 for (i
= 0; i
< scop_nb_params (scop
); i
++)
801 fprintf (file
, " p%d", (int) i
);
803 fprintf (file
, " cst\n");
807 print_isl_set (file
, scop
->context
);
809 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
812 fprintf (file
, "# )\n");
815 /* Print to FILE the SCOP, at some VERBOSITY level. */
818 print_scop (FILE *file
, scop_p scop
, int verbosity
)
823 fprintf (file
, "SCoP 1\n#(\n");
824 fprintf (file
, "# Language\nGimple\n");
825 openscop_print_scop_context (file
, scop
, verbosity
);
826 print_scop_params (file
, scop
, verbosity
);
829 fprintf (file
, "# Number of statements\n");
831 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
833 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
834 print_pbb (file
, pbb
, verbosity
);
838 fprintf (file
, "# original_lst (\n");
839 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
840 fprintf (file
, "\n#)\n");
842 fprintf (file
, "# transformed_lst (\n");
843 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
844 fprintf (file
, "\n#)\n");
847 fprintf (file
, "#)\n");
850 /* Print to FILE the input file that CLooG would expect as input, at
851 some VERBOSITY level. */
854 print_cloog (FILE *file
, scop_p scop
, int verbosity
)
859 fprintf (file
, "# SCoP (generated by GCC/Graphite\n");
861 fprintf (file
, "# CLooG output language\n");
862 fprintf (file
, "c\n");
864 print_scop_context (file
, scop
, verbosity
);
865 print_scop_params (file
, scop
, verbosity
);
868 fprintf (file
, "# Number of statements\n");
870 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
872 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
875 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
877 print_pbb_domain (file
, pbb
, verbosity
);
878 fprintf (file
, "0 0 0");
881 fprintf (file
, "# For future CLooG options.\n");
883 fprintf (file
, "\n");
886 fprintf (file
, "#)\n");
891 fprintf (file
, "# Don't set the iterator names.\n");
893 fprintf (file
, "\n");
896 fprintf (file
, "# Number of scattering functions\n");
898 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
900 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
902 if (!(pbb
->transformed
|| pbb
->schedule
))
906 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
908 print_scattering_function_1 (file
, pbb
, verbosity
);
911 fprintf (file
, "#)\n");
916 fprintf (file
, "# Don't set the scattering dimension names.\n");
918 fprintf (file
, "\n");
920 fprintf (file
, "#)\n");
923 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
926 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
928 print_pbb_domain (stderr
, pbb
, verbosity
);
931 /* Print to FILE the domain and scattering function of PBB, at some
935 debug_pbb (poly_bb_p pbb
, int verbosity
)
937 print_pbb (stderr
, pbb
, verbosity
);
940 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
943 debug_scop_context (scop_p scop
, int verbosity
)
945 print_scop_context (stderr
, scop
, verbosity
);
948 /* Print to STDERR the SCOP, at some VERBOSITY level. */
951 debug_scop (scop_p scop
, int verbosity
)
953 print_scop (stderr
, scop
, verbosity
);
956 /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY
960 debug_cloog (scop_p scop
, int verbosity
)
962 print_cloog (stderr
, scop
, verbosity
);
965 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
969 debug_scop_params (scop_p scop
, int verbosity
)
971 print_scop_params (stderr
, scop
, verbosity
);
974 extern isl_ctx
*the_isl_ctx
;
976 print_isl_set (FILE *f
, isl_set
*set
)
978 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
979 p
= isl_printer_print_set (p
, set
);
980 isl_printer_free (p
);
984 debug_isl_set (isl_set
*set
)
986 print_isl_set (stderr
, set
);
990 print_isl_map (FILE *f
, isl_map
*map
)
992 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
993 p
= isl_printer_print_map (p
, map
);
994 isl_printer_free (p
);
998 debug_isl_map (isl_map
*map
)
1000 print_isl_map (stderr
, map
);
1004 print_isl_aff (FILE *f
, isl_aff
*aff
)
1006 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1007 p
= isl_printer_print_aff (p
, aff
);
1008 isl_printer_free (p
);
1012 debug_isl_aff (isl_aff
*aff
)
1014 print_isl_aff (stderr
, aff
);
1018 print_isl_constraint (FILE *f
, isl_constraint
*c
)
1020 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
1021 p
= isl_printer_print_constraint (p
, c
);
1022 isl_printer_free (p
);
1026 debug_isl_constraint (isl_constraint
*c
)
1028 print_isl_constraint (stderr
, c
);
1031 /* Returns the number of iterations RES of the loop around PBB at
1032 time(scattering) dimension TIME_DEPTH. */
1035 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
1036 graphite_dim_t time_depth
,
1039 isl_set
*transdomain
;
1042 isl_val
*isllb
, *islub
;
1044 /* Map the iteration domain through the current scatter, and work
1045 on the resulting set. */
1046 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
1047 isl_map_copy (pbb
->transformed
));
1049 /* Select the time_depth' dimension via an affine expression. */
1050 dc
= isl_set_get_space (transdomain
);
1051 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
1052 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
1054 /* And find the min/max for that function. */
1055 /* XXX isl check results? */
1056 isllb
= isl_set_min_val (transdomain
, aff
);
1057 islub
= isl_set_max_val (transdomain
, aff
);
1059 islub
= isl_val_sub (islub
, isllb
);
1060 islub
= isl_val_add_ui (islub
, 1);
1061 isl_val_get_num_gmp (islub
, res
);
1063 isl_val_free (islub
);
1065 isl_set_free (transdomain
);
1068 /* Translates LOOP to LST. */
1071 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
1077 for (; bbs
.iterate (*i
, &pbb
); (*i
)++)
1080 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1082 if (bb
->loop_father
== loop
)
1083 stmt
= new_lst_stmt (pbb
);
1084 else if (flow_bb_inside_loop_p (loop
, bb
))
1086 loop_p next
= loop
->inner
;
1088 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1091 stmt
= loop_to_lst (next
, bbs
, i
);
1096 return new_lst_loop (seq
);
1099 seq
.safe_push (stmt
);
1102 return new_lst_loop (seq
);
1105 /* Reads the original scattering of the SCOP and returns an LST
1109 scop_to_lst (scop_p scop
)
1112 int i
, n
= SCOP_BBS (scop
).length ();
1115 sese region
= SCOP_REGION (scop
);
1117 for (i
= 0; i
< n
; i
++)
1119 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1120 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1122 if (loop_in_sese_p (loop
, region
))
1123 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1125 res
= new_lst_stmt (pbb
);
1127 seq
.safe_push (res
);
1130 res
= new_lst_loop (seq
);
1131 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1132 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1135 /* Print to FILE on a new line COLUMN white spaces. */
1138 lst_indent_to (FILE *file
, int column
)
1143 fprintf (file
, "\n#");
1145 for (i
= 0; i
< column
; i
++)
1146 fprintf (file
, " ");
1149 /* Print LST to FILE with INDENT spaces of indentation. */
1152 print_lst (FILE *file
, lst_p lst
, int indent
)
1157 lst_indent_to (file
, indent
);
1159 if (LST_LOOP_P (lst
))
1164 if (LST_LOOP_FATHER (lst
))
1165 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1167 fprintf (file
, "#(root");
1169 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1170 print_lst (file
, l
, indent
+ 2);
1172 fprintf (file
, ")");
1175 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1178 /* Print LST to STDERR. */
1181 debug_lst (lst_p lst
)
1183 print_lst (stderr
, lst
, 0);
1186 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1189 dot_lst_1 (FILE *file
, lst_p lst
)
1194 if (LST_LOOP_P (lst
))
1199 if (!LST_LOOP_FATHER (lst
))
1200 fprintf (file
, "L -> L_%d_%d\n",
1202 lst_dewey_number (lst
));
1204 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1205 lst_depth (LST_LOOP_FATHER (lst
)),
1206 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1208 lst_dewey_number (lst
));
1210 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1211 dot_lst_1 (file
, l
);
1215 fprintf (file
, "L_%d_%d -> S_%d\n",
1216 lst_depth (LST_LOOP_FATHER (lst
)),
1217 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1218 pbb_index (LST_PBB (lst
)));
1222 /* Display the LST using dotty. */
1227 /* When debugging, enable the following code. This cannot be used
1228 in production compilers because it calls "system". */
1230 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1231 gcc_assert (stream
);
1233 fputs ("digraph all {\n", stream
);
1234 dot_lst_1 (stream
, lst
);
1235 fputs ("}\n\n", stream
);
1238 system ("dotty /tmp/lst.dot &");
1240 fputs ("digraph all {\n", stderr
);
1241 dot_lst_1 (stderr
, lst
);
1242 fputs ("}\n\n", stderr
);
1247 /* Computes a checksum for the code generated by CLooG for SCOP. */
1250 cloog_checksum (scop_p scop ATTRIBUTE_UNUSED
)
1252 /* When debugging, enable the following code. This cannot be used
1253 in production compilers because it calls "system". */
1255 FILE *stream
= fopen ("/tmp/scop.cloog", "w");
1256 gcc_assert (stream
);
1257 print_cloog (stream
, scop
, 0);
1260 fputs ("\n", stdout
);
1261 system ("cloog -compilable 1 /tmp/scop.cloog > /tmp/scop.c ; gcc -O0 -g /tmp/scop.c -lm -o /tmp/scop; /tmp/scop | md5sum ");
1265 /* Reverse the loop around PBB at level DEPTH. */
1268 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1270 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1271 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1272 isl_space
*d1
= isl_space_range (d
);
1273 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1274 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1275 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1276 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1278 for (i
= 0; i
< n
; i
++)
1280 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1282 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1283 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1284 x
= isl_map_add_constraint (x
, c
);
1288 /* Reverse the loop at level DEPTH for all the PBBS. */
1291 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1295 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1296 isl_union_map
*res
= isl_union_map_empty (space
);
1298 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1299 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));