1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2017 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/>. */
29 #include "coretypes.h"
34 #include "diagnostic-core.h"
35 #include "fold-const.h"
36 #include "gimple-iterator.h"
37 #include "tree-ssa-loop.h"
39 #include "tree-data-ref.h"
40 #include "pretty-print.h"
41 #include "gimple-pretty-print.h"
45 /* Print to STDERR the GMP value VAL. */
48 debug_gmp_value (mpz_t val
)
50 gmp_fprintf (stderr
, "%Zd", val
);
53 /* Prints to FILE the iteration domain of PBB. */
56 print_iteration_domain (FILE *file
, poly_bb_p pbb
)
58 print_pbb_domain (file
, pbb
);
61 /* Prints to FILE the iteration domains of every PBB of SCOP. */
64 print_iteration_domains (FILE *file
, scop_p scop
)
69 FOR_EACH_VEC_ELT (scop
->pbbs
, i
, pbb
)
70 print_iteration_domain (file
, pbb
);
73 /* Prints to STDERR the iteration domain of PBB. */
76 debug_iteration_domain (poly_bb_p pbb
)
78 print_iteration_domain (stderr
, pbb
);
81 /* Prints to STDERR the iteration domains of every PBB of SCOP. */
84 debug_iteration_domains (scop_p scop
)
86 print_iteration_domains (stderr
, scop
);
89 /* Create a new polyhedral data reference and add it to PBB. It is
90 defined by its ACCESSES, its TYPE, and the number of subscripts
94 new_poly_dr (poly_bb_p pbb
, gimple
*stmt
, enum poly_dr_type type
,
95 isl_map
*acc
, isl_set
*subscript_sizes
)
98 poly_dr_p pdr
= XNEW (struct poly_dr
);
102 PDR_NB_REFS (pdr
) = 1;
105 pdr
->subscript_sizes
= subscript_sizes
;
106 PDR_TYPE (pdr
) = type
;
107 PBB_DRS (pbb
).safe_push (pdr
);
111 fprintf (dump_file
, "Converting dr: ");
112 print_pdr (dump_file
, pdr
);
113 fprintf (dump_file
, "To polyhedral representation:\n");
114 fprintf (dump_file
, " - access functions: ");
115 print_isl_map (dump_file
, acc
);
116 fprintf (dump_file
, " - subscripts: ");
117 print_isl_set (dump_file
, subscript_sizes
);
121 /* Free polyhedral data reference PDR. */
124 free_poly_dr (poly_dr_p pdr
)
126 isl_map_free (pdr
->accesses
);
127 isl_set_free (pdr
->subscript_sizes
);
131 /* Create a new polyhedral black box. */
134 new_poly_bb (scop_p scop
, gimple_poly_bb_p black_box
)
136 poly_bb_p pbb
= XNEW (struct poly_bb
);
139 pbb
->iterators
= NULL
;
140 PBB_SCOP (pbb
) = scop
;
141 pbb_set_black_box (pbb
, black_box
);
142 PBB_DRS (pbb
).create (3);
143 GBB_PBB ((gimple_poly_bb_p
) black_box
) = pbb
;
148 /* Free polyhedral black box. */
151 free_poly_bb (poly_bb_p pbb
)
156 isl_set_free (pbb
->domain
);
158 isl_set_free (pbb
->iterators
);
159 pbb
->iterators
= NULL
;
161 if (PBB_DRS (pbb
).exists ())
162 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
165 PBB_DRS (pbb
).release ();
169 /* Prints to FILE the polyhedral data reference PDR. */
172 print_pdr (FILE *file
, poly_dr_p pdr
)
174 fprintf (file
, "pdr_%d (", PDR_ID (pdr
));
176 switch (PDR_TYPE (pdr
))
179 fprintf (file
, "read \n");
183 fprintf (file
, "write \n");
187 fprintf (file
, "may_write \n");
194 fprintf (file
, "in gimple stmt: ");
195 print_gimple_stmt (file
, pdr
->stmt
, 0);
196 fprintf (file
, "data accesses: ");
197 print_isl_map (file
, pdr
->accesses
);
198 fprintf (file
, "subscript sizes: ");
199 print_isl_set (file
, pdr
->subscript_sizes
);
200 fprintf (file
, ")\n");
203 /* Prints to STDERR the polyhedral data reference PDR. */
206 debug_pdr (poly_dr_p pdr
)
208 print_pdr (stderr
, pdr
);
211 /* Store the GRAPHITE representation of BB. */
214 new_gimple_poly_bb (basic_block bb
, vec
<data_reference_p
> drs
,
215 vec
<scalar_use
> reads
, vec
<tree
> writes
)
217 gimple_poly_bb_p gbb
= XNEW (struct gimple_poly_bb
);
219 GBB_DATA_REFS (gbb
) = drs
;
220 gbb
->read_scalar_refs
= reads
;
221 gbb
->write_scalar_refs
= writes
;
222 GBB_CONDITIONS (gbb
).create (0);
223 GBB_CONDITION_CASES (gbb
).create (0);
231 free_gimple_poly_bb (gimple_poly_bb_p gbb
)
233 free_data_refs (GBB_DATA_REFS (gbb
));
234 GBB_CONDITIONS (gbb
).release ();
235 GBB_CONDITION_CASES (gbb
).release ();
236 gbb
->read_scalar_refs
.release ();
237 gbb
->write_scalar_refs
.release ();
241 /* Deletes all gimple bbs in SCOP. */
244 remove_gbbs_in_scop (scop_p scop
)
249 FOR_EACH_VEC_ELT (scop
->pbbs
, i
, pbb
)
250 free_gimple_poly_bb (PBB_BLACK_BOX (pbb
));
253 /* Creates a new SCOP containing the region (ENTRY, EXIT). */
256 new_scop (edge entry
, edge exit
)
258 sese_info_p region
= new_sese_info (entry
, exit
);
259 scop_p s
= XNEW (struct scop
);
261 s
->original_schedule
= NULL
;
262 s
->transformed_schedule
= NULL
;
263 s
->param_context
= NULL
;
264 scop_set_region (s
, region
);
267 s
->dependence
= NULL
;
274 free_scop (scop_p scop
)
279 remove_gbbs_in_scop (scop
);
280 free_sese_info (scop
->scop_info
);
282 FOR_EACH_VEC_ELT (scop
->pbbs
, i
, pbb
)
285 scop
->pbbs
.release ();
286 scop
->drs
.release ();
288 isl_set_free (scop
->param_context
);
289 scop
->param_context
= NULL
;
290 isl_union_map_free (scop
->dependence
);
291 scop
->dependence
= NULL
;
292 isl_schedule_free (scop
->original_schedule
);
293 scop
->original_schedule
= NULL
;
294 isl_schedule_free (scop
->transformed_schedule
);
295 scop
->transformed_schedule
= NULL
;
299 /* Print to FILE the domain of PBB. */
302 print_pbb_domain (FILE *file
, poly_bb_p pbb
)
304 print_isl_set (file
, pbb
->domain
);
307 /* Dump the cases of a graphite basic block GBB on FILE. */
310 dump_gbb_cases (FILE *file
, gimple_poly_bb_p gbb
)
319 cases
= GBB_CONDITION_CASES (gbb
);
320 if (cases
.is_empty ())
323 fprintf (file
, "cases bb_%d (\n", GBB_BB (gbb
)->index
);
325 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
326 print_gimple_stmt (file
, stmt
, 0);
328 fprintf (file
, ")\n");
331 /* Dump conditions of a graphite basic block GBB on FILE. */
334 dump_gbb_conditions (FILE *file
, gimple_poly_bb_p gbb
)
338 vec
<gimple
*> conditions
;
343 conditions
= GBB_CONDITIONS (gbb
);
344 if (conditions
.is_empty ())
347 fprintf (file
, "conditions bb_%d (\n", GBB_BB (gbb
)->index
);
349 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
350 print_gimple_stmt (file
, stmt
, 0);
352 fprintf (file
, ")\n");
355 /* Print to FILE all the data references of PBB. */
358 print_pdrs (FILE *file
, poly_bb_p pbb
)
365 if (PBB_DRS (pbb
).is_empty ())
368 fprintf (file
, "Data references (\n");
370 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
371 if (PDR_TYPE (pdr
) == PDR_READ
)
376 fprintf (file
, "Read data references (\n");
378 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
379 if (PDR_TYPE (pdr
) == PDR_READ
)
380 print_pdr (file
, pdr
);
382 fprintf (file
, ")\n");
383 fprintf (file
, "Write data references (\n");
384 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
385 if (PDR_TYPE (pdr
) != PDR_READ
)
386 print_pdr (file
, pdr
);
387 fprintf (file
, ")\n");
388 fprintf (file
, ")\n");
391 /* Print to STDERR all the data references of PBB. */
394 debug_pdrs (poly_bb_p pbb
)
396 print_pdrs (stderr
, pbb
);
399 /* Print to FILE the body of PBB. */
402 print_pbb_body (FILE *file
, poly_bb_p pbb
)
404 fprintf (file
, "Body (\n");
405 dump_bb (file
, pbb_bb (pbb
), 0, 0);
406 fprintf (file
, ")\n");
409 /* Print to FILE the domain and scattering function of PBB. */
412 print_pbb (FILE *file
, poly_bb_p pbb
)
414 fprintf (file
, "pbb_%d (\n", pbb_index (pbb
));
415 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
416 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
418 print_pbb_domain (file
, pbb
);
419 print_pdrs (file
, pbb
);
420 print_pbb_body (file
, pbb
);
422 fprintf (file
, ")\n");
425 /* Print to FILE the parameters of SCOP. */
428 print_scop_params (FILE *file
, scop_p scop
)
430 if (scop
->scop_info
->params
.is_empty ())
435 fprintf (file
, "parameters (");
436 FOR_EACH_VEC_ELT (scop
->scop_info
->params
, i
, t
)
438 print_generic_expr (file
, t
);
439 fprintf (file
, ", ");
441 fprintf (file
, ")\n");
444 /* Print to FILE the context of SCoP. */
447 print_scop_context (FILE *file
, scop_p scop
)
449 if (!scop
->param_context
)
452 fprintf (file
, "Context (\n");
453 print_isl_set (file
, scop
->param_context
);
454 fprintf (file
, ")\n");
457 /* Print to FILE the SCOP. */
460 print_scop (FILE *file
, scop_p scop
)
465 fprintf (file
, "SCoP (\n");
466 print_scop_context (file
, scop
);
467 print_scop_params (file
, scop
);
469 fprintf (file
, "Number of statements: ");
470 fprintf (file
, "%d\n", scop
->pbbs
.length ());
472 FOR_EACH_VEC_ELT (scop
->pbbs
, i
, pbb
)
473 print_pbb (file
, pbb
);
475 fprintf (file
, ")\n");
478 /* Print to STDERR the domain of PBB. */
481 debug_pbb_domain (poly_bb_p pbb
)
483 print_pbb_domain (stderr
, pbb
);
486 /* Print to FILE the domain and scattering function of PBB. */
489 debug_pbb (poly_bb_p pbb
)
491 print_pbb (stderr
, pbb
);
494 /* Print to STDERR the context of SCOP. */
497 debug_scop_context (scop_p scop
)
499 print_scop_context (stderr
, scop
);
502 /* Print to STDERR the SCOP. */
505 debug_scop (scop_p scop
)
507 print_scop (stderr
, scop
);
510 /* Print to STDERR the parameters of SCOP. */
513 debug_scop_params (scop_p scop
)
515 print_scop_params (stderr
, scop
);
518 extern isl_ctx
*the_isl_ctx
;
520 print_isl_set (FILE *f
, __isl_keep isl_set
*set
)
522 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
523 p
= isl_printer_set_yaml_style (p
, ISL_YAML_STYLE_BLOCK
);
524 p
= isl_printer_print_set (p
, set
);
525 p
= isl_printer_print_str (p
, "\n");
526 isl_printer_free (p
);
530 debug_isl_set (__isl_keep isl_set
*set
)
532 print_isl_set (stderr
, set
);
536 print_isl_map (FILE *f
, __isl_keep isl_map
*map
)
538 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
539 p
= isl_printer_set_yaml_style (p
, ISL_YAML_STYLE_BLOCK
);
540 p
= isl_printer_print_map (p
, map
);
541 p
= isl_printer_print_str (p
, "\n");
542 isl_printer_free (p
);
546 debug_isl_map (__isl_keep isl_map
*map
)
548 print_isl_map (stderr
, map
);
552 print_isl_union_map (FILE *f
, __isl_keep isl_union_map
*map
)
554 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
555 p
= isl_printer_set_yaml_style (p
, ISL_YAML_STYLE_BLOCK
);
556 p
= isl_printer_print_union_map (p
, map
);
557 p
= isl_printer_print_str (p
, "\n");
558 isl_printer_free (p
);
562 debug_isl_union_map (__isl_keep isl_union_map
*map
)
564 print_isl_union_map (stderr
, map
);
568 print_isl_aff (FILE *f
, __isl_keep isl_aff
*aff
)
570 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
571 p
= isl_printer_print_aff (p
, aff
);
572 p
= isl_printer_print_str (p
, "\n");
573 isl_printer_free (p
);
577 debug_isl_aff (__isl_keep isl_aff
*aff
)
579 print_isl_aff (stderr
, aff
);
583 print_isl_constraint (FILE *f
, __isl_keep isl_constraint
*c
)
585 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
586 p
= isl_printer_print_constraint (p
, c
);
587 p
= isl_printer_print_str (p
, "\n");
588 isl_printer_free (p
);
592 debug_isl_constraint (__isl_keep isl_constraint
*c
)
594 print_isl_constraint (stderr
, c
);
598 print_isl_schedule (FILE *f
, __isl_keep isl_schedule
*s
)
600 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
601 p
= isl_printer_set_yaml_style (p
, ISL_YAML_STYLE_BLOCK
);
602 p
= isl_printer_print_schedule (p
, s
);
603 p
= isl_printer_print_str (p
, "\n");
604 isl_printer_free (p
);
608 debug_isl_schedule (__isl_keep isl_schedule
*s
)
610 print_isl_schedule (stderr
, s
);
614 print_isl_ast (FILE *file
, __isl_keep isl_ast_node
*n
)
616 isl_printer
*prn
= isl_printer_to_file (the_isl_ctx
, file
);
617 prn
= isl_printer_set_output_format (prn
, ISL_FORMAT_C
);
618 prn
= isl_printer_print_ast_node (prn
, n
);
619 prn
= isl_printer_print_str (prn
, "\n");
620 isl_printer_free (prn
);
624 debug_isl_ast (isl_ast_node
*n
)
626 print_isl_ast (stderr
, n
);
630 debug_scop_pbb (scop_p scop
, int i
)
632 debug_pbb (scop
->pbbs
[i
]);
635 #endif /* HAVE_isl */