]>
Commit | Line | Data |
---|---|---|
c6bb733d | 1 | /* Graphite polyhedral representation. |
711789cc | 2 | Copyright (C) 2009-2013 Free Software Foundation, Inc. |
c6bb733d | 3 | Contributed by Sebastian Pop <sebastian.pop@amd.com> and |
4 | Tobias Grosser <grosser@fim.uni-passau.de>. | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
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) | |
11 | any later version. | |
12 | ||
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. | |
17 | ||
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/>. */ | |
87e20041 | 21 | |
c6bb733d | 22 | #include "config.h" |
87e20041 | 23 | |
24 | #ifdef HAVE_cloog | |
25 | #include <isl/set.h> | |
26 | #include <isl/map.h> | |
27 | #include <isl/union_map.h> | |
28 | #include <isl/constraint.h> | |
29 | #include <isl/ilp.h> | |
30 | #include <isl/aff.h> | |
31 | #include <cloog/cloog.h> | |
32 | #include <cloog/isl/domain.h> | |
33 | #endif | |
34 | ||
c6bb733d | 35 | #include "system.h" |
36 | #include "coretypes.h" | |
52f91c04 | 37 | #include "diagnostic-core.h" |
41a8aa41 | 38 | #include "tree.h" |
bc61cadb | 39 | #include "basic-block.h" |
40 | #include "tree-ssa-alias.h" | |
41 | #include "internal-fn.h" | |
42 | #include "gimple-expr.h" | |
43 | #include "is-a.h" | |
073c1fd5 | 44 | #include "gimple.h" |
dcf1a1ec | 45 | #include "gimple-iterator.h" |
073c1fd5 | 46 | #include "tree-ssa-loop.h" |
b9ed1410 | 47 | #include "dumpfile.h" |
1e5b7b1f | 48 | #include "gimple-pretty-print.h" |
c6bb733d | 49 | #include "cfgloop.h" |
50 | #include "tree-chrec.h" | |
51 | #include "tree-data-ref.h" | |
52 | #include "tree-scalar-evolution.h" | |
1e5b7b1f | 53 | #include "sese.h" |
c6bb733d | 54 | |
55 | #ifdef HAVE_cloog | |
c6bb733d | 56 | #include "graphite-poly.h" |
c6bb733d | 57 | |
63b03ccf | 58 | #define OPENSCOP_MAX_STRING 256 |
59 | ||
87e20041 | 60 | |
61 | /* Print to STDERR the GMP value VAL. */ | |
62 | ||
63 | DEBUG_FUNCTION void | |
64 | debug_gmp_value (mpz_t val) | |
65 | { | |
de2e6b8a | 66 | gmp_fprintf (stderr, "%Zd", val); |
87e20041 | 67 | } |
68 | ||
c6bb733d | 69 | /* Return the maximal loop depth in SCOP. */ |
70 | ||
71 | int | |
72 | scop_max_loop_depth (scop_p scop) | |
73 | { | |
74 | int i; | |
75 | poly_bb_p pbb; | |
76 | int max_nb_loops = 0; | |
77 | ||
f1f41a6c | 78 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
c6bb733d | 79 | { |
80 | int nb_loops = pbb_dim_iter_domain (pbb); | |
81 | if (max_nb_loops < nb_loops) | |
82 | max_nb_loops = nb_loops; | |
83 | } | |
84 | ||
85 | return max_nb_loops; | |
86 | } | |
87 | ||
ff4c7a5a | 88 | /* Prints to FILE the scattering function of PBB, at some VERBOSITY |
89 | level. */ | |
c6bb733d | 90 | |
1f8d6d4d | 91 | static void |
ff4c7a5a | 92 | print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity) |
c6bb733d | 93 | { |
94 | graphite_dim_t i; | |
95 | ||
ff4c7a5a | 96 | if (verbosity > 0) |
97 | { | |
98 | fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb)); | |
086610eb | 99 | fprintf (file, "#eq"); |
c6bb733d | 100 | |
ff4c7a5a | 101 | for (i = 0; i < pbb_nb_scattering_transform (pbb); i++) |
102 | fprintf (file, " s%d", (int) i); | |
c6bb733d | 103 | |
ff4c7a5a | 104 | for (i = 0; i < pbb_nb_local_vars (pbb); i++) |
105 | fprintf (file, " lv%d", (int) i); | |
c6bb733d | 106 | |
ff4c7a5a | 107 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) |
108 | fprintf (file, " i%d", (int) i); | |
c6bb733d | 109 | |
ff4c7a5a | 110 | for (i = 0; i < pbb_nb_params (pbb); i++) |
111 | fprintf (file, " p%d", (int) i); | |
c6bb733d | 112 | |
ff4c7a5a | 113 | fprintf (file, " cst\n"); |
114 | } | |
c6bb733d | 115 | |
87e20041 | 116 | fprintf (file, "isl\n"); |
117 | print_isl_map (file, pbb->transformed ? pbb->transformed : pbb->schedule); | |
c6bb733d | 118 | |
ff4c7a5a | 119 | if (verbosity > 0) |
120 | fprintf (file, "#)\n"); | |
c6bb733d | 121 | } |
122 | ||
ff4c7a5a | 123 | /* Prints to FILE the scattering function of PBB, at some VERBOSITY |
124 | level. */ | |
1f8d6d4d | 125 | |
126 | void | |
ff4c7a5a | 127 | print_scattering_function (FILE *file, poly_bb_p pbb, int verbosity) |
1f8d6d4d | 128 | { |
129 | if (!PBB_TRANSFORMED (pbb)) | |
130 | return; | |
131 | ||
87e20041 | 132 | if (pbb->schedule || pbb->transformed) |
ff4c7a5a | 133 | { |
134 | if (verbosity > 0) | |
135 | fprintf (file, "# Scattering function is provided\n"); | |
136 | ||
137 | fprintf (file, "1\n"); | |
138 | } | |
1f8d6d4d | 139 | else |
140 | { | |
ff4c7a5a | 141 | if (verbosity > 0) |
142 | fprintf (file, "# Scattering function is not provided\n"); | |
143 | ||
144 | fprintf (file, "0\n"); | |
1f8d6d4d | 145 | return; |
146 | } | |
147 | ||
87e20041 | 148 | print_scattering_function_1 (file, pbb, verbosity); |
8c4b14b0 | 149 | |
150 | if (verbosity > 0) | |
151 | fprintf (file, "# Scattering names are not provided\n"); | |
152 | ||
153 | fprintf (file, "0\n"); | |
154 | ||
1f8d6d4d | 155 | } |
156 | ||
ff4c7a5a | 157 | /* Prints to FILE the iteration domain of PBB, at some VERBOSITY |
158 | level. */ | |
c6bb733d | 159 | |
160 | void | |
ff4c7a5a | 161 | print_iteration_domain (FILE *file, poly_bb_p pbb, int verbosity) |
c6bb733d | 162 | { |
ff4c7a5a | 163 | print_pbb_domain (file, pbb, verbosity); |
c6bb733d | 164 | } |
165 | ||
166 | /* Prints to FILE the scattering functions of every PBB of SCOP. */ | |
167 | ||
168 | void | |
ff4c7a5a | 169 | print_scattering_functions (FILE *file, scop_p scop, int verbosity) |
c6bb733d | 170 | { |
171 | int i; | |
172 | poly_bb_p pbb; | |
173 | ||
f1f41a6c | 174 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
ff4c7a5a | 175 | print_scattering_function (file, pbb, verbosity); |
c6bb733d | 176 | } |
177 | ||
ff4c7a5a | 178 | /* Prints to FILE the iteration domains of every PBB of SCOP, at some |
179 | VERBOSITY level. */ | |
c6bb733d | 180 | |
181 | void | |
ff4c7a5a | 182 | print_iteration_domains (FILE *file, scop_p scop, int verbosity) |
c6bb733d | 183 | { |
184 | int i; | |
185 | poly_bb_p pbb; | |
186 | ||
f1f41a6c | 187 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
ff4c7a5a | 188 | print_iteration_domain (file, pbb, verbosity); |
c6bb733d | 189 | } |
190 | ||
ff4c7a5a | 191 | /* Prints to STDERR the scattering function of PBB, at some VERBOSITY |
192 | level. */ | |
c6bb733d | 193 | |
4b987fac | 194 | DEBUG_FUNCTION void |
ff4c7a5a | 195 | debug_scattering_function (poly_bb_p pbb, int verbosity) |
c6bb733d | 196 | { |
ff4c7a5a | 197 | print_scattering_function (stderr, pbb, verbosity); |
c6bb733d | 198 | } |
199 | ||
ff4c7a5a | 200 | /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY |
201 | level. */ | |
c6bb733d | 202 | |
4b987fac | 203 | DEBUG_FUNCTION void |
ff4c7a5a | 204 | debug_iteration_domain (poly_bb_p pbb, int verbosity) |
c6bb733d | 205 | { |
ff4c7a5a | 206 | print_iteration_domain (stderr, pbb, verbosity); |
c6bb733d | 207 | } |
208 | ||
ff4c7a5a | 209 | /* Prints to STDERR the scattering functions of every PBB of SCOP, at |
210 | some VERBOSITY level. */ | |
c6bb733d | 211 | |
4b987fac | 212 | DEBUG_FUNCTION void |
ff4c7a5a | 213 | debug_scattering_functions (scop_p scop, int verbosity) |
c6bb733d | 214 | { |
ff4c7a5a | 215 | print_scattering_functions (stderr, scop, verbosity); |
c6bb733d | 216 | } |
217 | ||
ff4c7a5a | 218 | /* Prints to STDERR the iteration domains of every PBB of SCOP, at |
219 | some VERBOSITY level. */ | |
c6bb733d | 220 | |
4b987fac | 221 | DEBUG_FUNCTION void |
ff4c7a5a | 222 | debug_iteration_domains (scop_p scop, int verbosity) |
c6bb733d | 223 | { |
ff4c7a5a | 224 | print_iteration_domains (stderr, scop, verbosity); |
c6bb733d | 225 | } |
226 | ||
227 | /* Apply graphite transformations to all the basic blocks of SCOP. */ | |
228 | ||
229 | bool | |
230 | apply_poly_transforms (scop_p scop) | |
231 | { | |
232 | bool transform_done = false; | |
63b03ccf | 233 | |
c6bb733d | 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; | |
241 | ||
16848556 | 242 | if (flag_loop_parallelize_all) |
c6bb733d | 243 | transform_done = true; |
244 | ||
245 | if (flag_loop_block) | |
64d8f27a | 246 | transform_done |= scop_do_block (scop); |
dbe2e816 | 247 | else |
248 | { | |
249 | if (flag_loop_strip_mine) | |
68f6634f | 250 | transform_done |= scop_do_strip_mine (scop, 0); |
c6bb733d | 251 | |
dbe2e816 | 252 | if (flag_loop_interchange) |
253 | transform_done |= scop_do_interchange (scop); | |
254 | } | |
c6bb733d | 255 | |
89049f25 | 256 | /* This pass needs to be run at the final stage, as it does not |
257 | update the lst. */ | |
258 | if (flag_loop_optimize_isl) | |
259 | transform_done |= optimize_isl (scop); | |
260 | ||
c6bb733d | 261 | return transform_done; |
262 | } | |
263 | ||
85f74b79 | 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 | |
266 | NB_SUBSCRIPTS. */ | |
c6bb733d | 267 | |
268 | void | |
ae11f03b | 269 | new_poly_dr (poly_bb_p pbb, int dr_base_object_set, |
87e20041 | 270 | enum poly_dr_type type, void *cdr, graphite_dim_t nb_subscripts, |
271 | isl_map *acc, isl_set *extent) | |
c6bb733d | 272 | { |
96b6d5d7 | 273 | static int id = 0; |
9e3531b5 | 274 | poly_dr_p pdr = XNEW (struct poly_dr); |
c6bb733d | 275 | |
96b6d5d7 | 276 | PDR_ID (pdr) = id++; |
ae11f03b | 277 | PDR_BASE_OBJECT_SET (pdr) = dr_base_object_set; |
11b2102e | 278 | PDR_NB_REFS (pdr) = 1; |
c6bb733d | 279 | PDR_PBB (pdr) = pbb; |
87e20041 | 280 | pdr->accesses = acc; |
281 | pdr->extent = extent; | |
c6bb733d | 282 | PDR_TYPE (pdr) = type; |
283 | PDR_CDR (pdr) = cdr; | |
85f74b79 | 284 | PDR_NB_SUBSCRIPTS (pdr) = nb_subscripts; |
f1f41a6c | 285 | PBB_DRS (pbb).safe_push (pdr); |
c6bb733d | 286 | } |
287 | ||
288 | /* Free polyhedral data reference PDR. */ | |
289 | ||
290 | void | |
291 | free_poly_dr (poly_dr_p pdr) | |
292 | { | |
87e20041 | 293 | isl_map_free (pdr->accesses); |
294 | isl_set_free (pdr->extent); | |
c6bb733d | 295 | XDELETE (pdr); |
296 | } | |
297 | ||
298 | /* Create a new polyhedral black box. */ | |
299 | ||
8c6b3774 | 300 | poly_bb_p |
301 | new_poly_bb (scop_p scop, void *black_box) | |
c6bb733d | 302 | { |
303 | poly_bb_p pbb = XNEW (struct poly_bb); | |
304 | ||
87e20041 | 305 | pbb->domain = NULL; |
306 | pbb->schedule = NULL; | |
307 | pbb->transformed = NULL; | |
308 | pbb->saved = NULL; | |
c6bb733d | 309 | PBB_SCOP (pbb) = scop; |
310 | pbb_set_black_box (pbb, black_box); | |
a741358d | 311 | PBB_TRANSFORMED (pbb) = NULL; |
312 | PBB_SAVED (pbb) = NULL; | |
313 | PBB_ORIGINAL (pbb) = NULL; | |
f1f41a6c | 314 | PBB_DRS (pbb).create (3); |
8c6b3774 | 315 | PBB_IS_REDUCTION (pbb) = false; |
8c6b3774 | 316 | GBB_PBB ((gimple_bb_p) black_box) = pbb; |
317 | ||
318 | return pbb; | |
c6bb733d | 319 | } |
320 | ||
321 | /* Free polyhedral black box. */ | |
322 | ||
323 | void | |
324 | free_poly_bb (poly_bb_p pbb) | |
325 | { | |
326 | int i; | |
327 | poly_dr_p pdr; | |
328 | ||
87e20041 | 329 | isl_set_free (pbb->domain); |
330 | isl_map_free (pbb->schedule); | |
331 | isl_map_free (pbb->transformed); | |
332 | isl_map_free (pbb->saved); | |
c6bb733d | 333 | |
f1f41a6c | 334 | if (PBB_DRS (pbb).exists ()) |
335 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) | |
c6bb733d | 336 | free_poly_dr (pdr); |
337 | ||
f1f41a6c | 338 | PBB_DRS (pbb).release (); |
c6bb733d | 339 | XDELETE (pbb); |
340 | } | |
341 | ||
342 | static void | |
8c4b14b0 | 343 | print_pdr_access_layout (FILE *file, poly_bb_p pbb, poly_dr_p pdr) |
c6bb733d | 344 | { |
345 | graphite_dim_t i; | |
346 | ||
347 | fprintf (file, "# eq"); | |
348 | ||
8c4b14b0 | 349 | fprintf (file, " alias"); |
c6bb733d | 350 | |
85f74b79 | 351 | for (i = 0; i < PDR_NB_SUBSCRIPTS (pdr); i++) |
c6bb733d | 352 | fprintf (file, " sub%d", (int) i); |
353 | ||
8c4b14b0 | 354 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) |
355 | fprintf (file, " i%d", (int) i); | |
356 | ||
357 | for (i = 0; i < pbb_nb_params (pbb); i++) | |
358 | fprintf (file, " p%d", (int) i); | |
359 | ||
c6bb733d | 360 | fprintf (file, " cst\n"); |
361 | } | |
362 | ||
ff4c7a5a | 363 | /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY |
364 | level. */ | |
c6bb733d | 365 | |
366 | void | |
ff4c7a5a | 367 | print_pdr (FILE *file, poly_dr_p pdr, int verbosity) |
c6bb733d | 368 | { |
ff4c7a5a | 369 | if (verbosity > 1) |
c6bb733d | 370 | { |
ff4c7a5a | 371 | fprintf (file, "# pdr_%d (", PDR_ID (pdr)); |
372 | ||
373 | switch (PDR_TYPE (pdr)) | |
374 | { | |
375 | case PDR_READ: | |
376 | fprintf (file, "read \n"); | |
377 | break; | |
c6bb733d | 378 | |
ff4c7a5a | 379 | case PDR_WRITE: |
380 | fprintf (file, "write \n"); | |
381 | break; | |
c6bb733d | 382 | |
ff4c7a5a | 383 | case PDR_MAY_WRITE: |
384 | fprintf (file, "may_write \n"); | |
385 | break; | |
c6bb733d | 386 | |
ff4c7a5a | 387 | default: |
388 | gcc_unreachable (); | |
389 | } | |
390 | ||
391 | dump_data_reference (file, (data_reference_p) PDR_CDR (pdr)); | |
c6bb733d | 392 | } |
393 | ||
ff4c7a5a | 394 | if (verbosity > 0) |
395 | { | |
396 | fprintf (file, "# data accesses (\n"); | |
8c4b14b0 | 397 | print_pdr_access_layout (file, PDR_PBB (pdr), pdr); |
ff4c7a5a | 398 | } |
c6bb733d | 399 | |
87e20041 | 400 | /* XXX isl dump accesses/subscripts */ |
c6bb733d | 401 | |
ff4c7a5a | 402 | if (verbosity > 0) |
403 | fprintf (file, "#)\n"); | |
404 | ||
405 | if (verbosity > 1) | |
406 | fprintf (file, "#)\n"); | |
c6bb733d | 407 | } |
408 | ||
ff4c7a5a | 409 | /* Prints to STDERR the polyhedral data reference PDR, at some |
410 | VERBOSITY level. */ | |
c6bb733d | 411 | |
4b987fac | 412 | DEBUG_FUNCTION void |
ff4c7a5a | 413 | debug_pdr (poly_dr_p pdr, int verbosity) |
c6bb733d | 414 | { |
ff4c7a5a | 415 | print_pdr (stderr, pdr, verbosity); |
c6bb733d | 416 | } |
417 | ||
418 | /* Creates a new SCOP containing REGION. */ | |
419 | ||
420 | scop_p | |
421 | new_scop (void *region) | |
422 | { | |
423 | scop_p scop = XNEW (struct scop); | |
424 | ||
87e20041 | 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; | |
c6bb733d | 438 | scop_set_region (scop, region); |
f1f41a6c | 439 | SCOP_BBS (scop).create (3); |
7e7ffe19 | 440 | SCOP_ORIGINAL_SCHEDULE (scop) = NULL; |
441 | SCOP_TRANSFORMED_SCHEDULE (scop) = NULL; | |
442 | SCOP_SAVED_SCHEDULE (scop) = NULL; | |
94bdcd77 | 443 | POLY_SCOP_P (scop) = false; |
444 | ||
c6bb733d | 445 | return scop; |
446 | } | |
447 | ||
448 | /* Deletes SCOP. */ | |
449 | ||
450 | void | |
451 | free_scop (scop_p scop) | |
452 | { | |
453 | int i; | |
454 | poly_bb_p pbb; | |
455 | ||
f1f41a6c | 456 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
c6bb733d | 457 | free_poly_bb (pbb); |
458 | ||
f1f41a6c | 459 | SCOP_BBS (scop).release (); |
c6bb733d | 460 | |
87e20041 | 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); | |
7e7ffe19 | 474 | free_lst (SCOP_ORIGINAL_SCHEDULE (scop)); |
475 | free_lst (SCOP_TRANSFORMED_SCHEDULE (scop)); | |
476 | free_lst (SCOP_SAVED_SCHEDULE (scop)); | |
c6bb733d | 477 | XDELETE (scop); |
478 | } | |
479 | ||
8c4b14b0 | 480 | /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY |
481 | level. */ | |
482 | ||
483 | static void | |
484 | openscop_print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity) | |
485 | { | |
486 | graphite_dim_t i; | |
487 | gimple_bb_p gbb = PBB_BLACK_BOX (pbb); | |
488 | ||
87e20041 | 489 | if (!pbb->domain) |
8c4b14b0 | 490 | return; |
491 | ||
492 | if (verbosity > 0) | |
493 | { | |
494 | fprintf (file, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index); | |
086610eb | 495 | fprintf (file, "#eq"); |
8c4b14b0 | 496 | |
497 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) | |
498 | fprintf (file, " i%d", (int) i); | |
499 | ||
500 | for (i = 0; i < pbb_nb_params (pbb); i++) | |
501 | fprintf (file, " p%d", (int) i); | |
502 | ||
503 | fprintf (file, " cst\n"); | |
504 | } | |
505 | ||
87e20041 | 506 | fprintf (file, "XXX isl\n"); |
8c4b14b0 | 507 | |
508 | if (verbosity > 0) | |
509 | fprintf (file, "#)\n"); | |
510 | } | |
511 | ||
ff4c7a5a | 512 | /* Print to FILE the domain of PBB, at some VERBOSITY level. */ |
c6bb733d | 513 | |
514 | void | |
87e20041 | 515 | print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity ATTRIBUTE_UNUSED) |
c6bb733d | 516 | { |
87e20041 | 517 | print_isl_set (file, pbb->domain); |
c6bb733d | 518 | } |
519 | ||
520 | /* Dump the cases of a graphite basic block GBB on FILE. */ | |
521 | ||
522 | static void | |
523 | dump_gbb_cases (FILE *file, gimple_bb_p gbb) | |
524 | { | |
525 | int i; | |
526 | gimple stmt; | |
f1f41a6c | 527 | vec<gimple> cases; |
c6bb733d | 528 | |
529 | if (!gbb) | |
530 | return; | |
531 | ||
532 | cases = GBB_CONDITION_CASES (gbb); | |
f1f41a6c | 533 | if (cases.is_empty ()) |
c6bb733d | 534 | return; |
535 | ||
5dc5fe13 | 536 | fprintf (file, "# cases bb_%d (\n", GBB_BB (gbb)->index); |
c6bb733d | 537 | |
f1f41a6c | 538 | FOR_EACH_VEC_ELT (cases, i, stmt) |
5dc5fe13 | 539 | { |
540 | fprintf (file, "# "); | |
541 | print_gimple_stmt (file, stmt, 0, 0); | |
542 | } | |
c6bb733d | 543 | |
5dc5fe13 | 544 | fprintf (file, "#)\n"); |
c6bb733d | 545 | } |
546 | ||
547 | /* Dump conditions of a graphite basic block GBB on FILE. */ | |
548 | ||
549 | static void | |
550 | dump_gbb_conditions (FILE *file, gimple_bb_p gbb) | |
551 | { | |
552 | int i; | |
553 | gimple stmt; | |
f1f41a6c | 554 | vec<gimple> conditions; |
c6bb733d | 555 | |
556 | if (!gbb) | |
557 | return; | |
558 | ||
559 | conditions = GBB_CONDITIONS (gbb); | |
f1f41a6c | 560 | if (conditions.is_empty ()) |
c6bb733d | 561 | return; |
562 | ||
5dc5fe13 | 563 | fprintf (file, "# conditions bb_%d (\n", GBB_BB (gbb)->index); |
c6bb733d | 564 | |
f1f41a6c | 565 | FOR_EACH_VEC_ELT (conditions, i, stmt) |
5dc5fe13 | 566 | { |
567 | fprintf (file, "# "); | |
568 | print_gimple_stmt (file, stmt, 0, 0); | |
569 | } | |
c6bb733d | 570 | |
5dc5fe13 | 571 | fprintf (file, "#)\n"); |
c6bb733d | 572 | } |
573 | ||
ff4c7a5a | 574 | /* Print to FILE all the data references of PBB, at some VERBOSITY |
575 | level. */ | |
c6bb733d | 576 | |
577 | void | |
ff4c7a5a | 578 | print_pdrs (FILE *file, poly_bb_p pbb, int verbosity) |
c6bb733d | 579 | { |
580 | int i; | |
581 | poly_dr_p pdr; | |
5dc5fe13 | 582 | int nb_reads = 0; |
583 | int nb_writes = 0; | |
c6bb733d | 584 | |
f1f41a6c | 585 | if (PBB_DRS (pbb).length () == 0) |
5dc5fe13 | 586 | { |
ff4c7a5a | 587 | if (verbosity > 0) |
588 | fprintf (file, "# Access informations are not provided\n");\ | |
589 | fprintf (file, "0\n"); | |
5dc5fe13 | 590 | return; |
591 | } | |
592 | ||
ff4c7a5a | 593 | if (verbosity > 1) |
594 | fprintf (file, "# Data references (\n"); | |
595 | ||
596 | if (verbosity > 0) | |
597 | fprintf (file, "# Access informations are provided\n"); | |
598 | fprintf (file, "1\n"); | |
5dc5fe13 | 599 | |
f1f41a6c | 600 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 601 | if (PDR_TYPE (pdr) == PDR_READ) |
602 | nb_reads++; | |
603 | else | |
604 | nb_writes++; | |
605 | ||
ff4c7a5a | 606 | if (verbosity > 1) |
607 | fprintf (file, "# Read data references (\n"); | |
608 | ||
609 | if (verbosity > 0) | |
610 | fprintf (file, "# Read access informations\n"); | |
611 | fprintf (file, "%d\n", nb_reads); | |
612 | ||
f1f41a6c | 613 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 614 | if (PDR_TYPE (pdr) == PDR_READ) |
ff4c7a5a | 615 | print_pdr (file, pdr, verbosity); |
616 | ||
617 | if (verbosity > 1) | |
618 | fprintf (file, "#)\n"); | |
619 | ||
620 | if (verbosity > 1) | |
621 | fprintf (file, "# Write data references (\n"); | |
622 | ||
623 | if (verbosity > 0) | |
624 | fprintf (file, "# Write access informations\n"); | |
625 | fprintf (file, "%d\n", nb_writes); | |
5dc5fe13 | 626 | |
f1f41a6c | 627 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 628 | if (PDR_TYPE (pdr) != PDR_READ) |
ff4c7a5a | 629 | print_pdr (file, pdr, verbosity); |
630 | ||
631 | if (verbosity > 1) | |
632 | fprintf (file, "#)\n"); | |
633 | ||
634 | if (verbosity > 1) | |
635 | fprintf (file, "#)\n"); | |
c6bb733d | 636 | } |
637 | ||
638 | /* Print to STDERR all the data references of PBB. */ | |
639 | ||
4b987fac | 640 | DEBUG_FUNCTION void |
ff4c7a5a | 641 | debug_pdrs (poly_bb_p pbb, int verbosity) |
c6bb733d | 642 | { |
ff4c7a5a | 643 | print_pdrs (stderr, pbb, verbosity); |
c6bb733d | 644 | } |
645 | ||
8c4b14b0 | 646 | /* Print to FILE the body of PBB, at some VERBOSITY level. |
647 | If statement_body_provided is false statement body is not printed. */ | |
5dc5fe13 | 648 | |
649 | static void | |
8c4b14b0 | 650 | print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity, |
651 | bool statement_body_provided) | |
5dc5fe13 | 652 | { |
ff4c7a5a | 653 | if (verbosity > 1) |
654 | fprintf (file, "# Body (\n"); | |
655 | ||
8c4b14b0 | 656 | if (!statement_body_provided) |
d2cd543b | 657 | { |
658 | if (verbosity > 0) | |
659 | fprintf (file, "# Statement body is not provided\n"); | |
660 | ||
661 | fprintf (file, "0\n"); | |
8c4b14b0 | 662 | |
d2cd543b | 663 | if (verbosity > 1) |
664 | fprintf (file, "#)\n"); | |
665 | return; | |
666 | } | |
8c4b14b0 | 667 | |
ff4c7a5a | 668 | if (verbosity > 0) |
669 | fprintf (file, "# Statement body is provided\n"); | |
670 | fprintf (file, "1\n"); | |
671 | ||
672 | if (verbosity > 0) | |
673 | fprintf (file, "# Original iterator names\n# Iterator names are not provided yet.\n"); | |
674 | ||
675 | if (verbosity > 0) | |
676 | fprintf (file, "# Statement body\n"); | |
677 | ||
5dc5fe13 | 678 | fprintf (file, "{\n"); |
35e5655c | 679 | dump_bb (file, pbb_bb (pbb), 0, 0); |
5dc5fe13 | 680 | fprintf (file, "}\n"); |
ff4c7a5a | 681 | |
682 | if (verbosity > 1) | |
683 | fprintf (file, "#)\n"); | |
5dc5fe13 | 684 | } |
685 | ||
ff4c7a5a | 686 | /* Print to FILE the domain and scattering function of PBB, at some |
687 | VERBOSITY level. */ | |
c6bb733d | 688 | |
689 | void | |
ff4c7a5a | 690 | print_pbb (FILE *file, poly_bb_p pbb, int verbosity) |
691 | { | |
692 | if (verbosity > 1) | |
693 | { | |
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)); | |
697 | } | |
698 | ||
8c4b14b0 | 699 | openscop_print_pbb_domain (file, pbb, verbosity); |
ff4c7a5a | 700 | print_scattering_function (file, pbb, verbosity); |
701 | print_pdrs (file, pbb, verbosity); | |
8c4b14b0 | 702 | print_pbb_body (file, pbb, verbosity, false); |
ff4c7a5a | 703 | |
704 | if (verbosity > 1) | |
705 | fprintf (file, "#)\n"); | |
c6bb733d | 706 | } |
707 | ||
ff4c7a5a | 708 | /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */ |
c6bb733d | 709 | |
710 | void | |
ff4c7a5a | 711 | print_scop_params (FILE *file, scop_p scop, int verbosity) |
c6bb733d | 712 | { |
713 | int i; | |
714 | tree t; | |
715 | ||
ff4c7a5a | 716 | if (verbosity > 1) |
717 | fprintf (file, "# parameters (\n"); | |
5dc5fe13 | 718 | |
f1f41a6c | 719 | if (SESE_PARAMS (SCOP_REGION (scop)).length ()) |
ff4c7a5a | 720 | { |
721 | if (verbosity > 0) | |
722 | fprintf (file, "# Parameter names are provided\n"); | |
723 | ||
724 | fprintf (file, "1\n"); | |
725 | ||
726 | if (verbosity > 0) | |
727 | fprintf (file, "# Parameter names\n"); | |
728 | } | |
5dc5fe13 | 729 | else |
ff4c7a5a | 730 | { |
731 | if (verbosity > 0) | |
732 | fprintf (file, "# Parameter names are not provided\n"); | |
733 | fprintf (file, "0\n"); | |
734 | } | |
5dc5fe13 | 735 | |
f1f41a6c | 736 | FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop)), i, t) |
c6bb733d | 737 | { |
c6bb733d | 738 | print_generic_expr (file, t, 0); |
1f8d6d4d | 739 | fprintf (file, " "); |
c6bb733d | 740 | } |
ff4c7a5a | 741 | |
742 | fprintf (file, "\n"); | |
743 | ||
744 | if (verbosity > 1) | |
745 | fprintf (file, "#)\n"); | |
c6bb733d | 746 | } |
747 | ||
8c4b14b0 | 748 | /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY |
749 | level. */ | |
750 | ||
751 | static void | |
752 | openscop_print_scop_context (FILE *file, scop_p scop, int verbosity) | |
753 | { | |
754 | graphite_dim_t i; | |
755 | ||
756 | if (verbosity > 0) | |
757 | { | |
758 | fprintf (file, "# Context (\n"); | |
086610eb | 759 | fprintf (file, "#eq"); |
8c4b14b0 | 760 | |
761 | for (i = 0; i < scop_nb_params (scop); i++) | |
762 | fprintf (file, " p%d", (int) i); | |
763 | ||
764 | fprintf (file, " cst\n"); | |
765 | } | |
766 | ||
87e20041 | 767 | if (scop->context) |
768 | /* XXX isl print context */ | |
769 | fprintf (file, "XXX isl\n"); | |
8c4b14b0 | 770 | else |
771 | fprintf (file, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop) + 2, | |
772 | (int) scop_nb_params (scop)); | |
773 | ||
774 | if (verbosity > 0) | |
775 | fprintf (file, "# )\n"); | |
776 | } | |
777 | ||
ff4c7a5a | 778 | /* Print to FILE the context of SCoP, at some VERBOSITY level. */ |
779 | ||
c6bb733d | 780 | void |
ff4c7a5a | 781 | print_scop_context (FILE *file, scop_p scop, int verbosity) |
c6bb733d | 782 | { |
783 | graphite_dim_t i; | |
784 | ||
ff4c7a5a | 785 | if (verbosity > 0) |
786 | { | |
787 | fprintf (file, "# Context (\n"); | |
086610eb | 788 | fprintf (file, "#eq"); |
c6bb733d | 789 | |
ff4c7a5a | 790 | for (i = 0; i < scop_nb_params (scop); i++) |
791 | fprintf (file, " p%d", (int) i); | |
c6bb733d | 792 | |
ff4c7a5a | 793 | fprintf (file, " cst\n"); |
794 | } | |
c6bb733d | 795 | |
87e20041 | 796 | if (scop->context) |
797 | print_isl_set (file, scop->context); | |
5dc5fe13 | 798 | else |
87e20041 | 799 | fprintf (file, "no isl context %d\n", (int) scop_nb_params (scop) + 2); |
c6bb733d | 800 | |
ff4c7a5a | 801 | if (verbosity > 0) |
802 | fprintf (file, "# )\n"); | |
c6bb733d | 803 | } |
804 | ||
d2cd543b | 805 | /* Print to FILE the SCOP, at some VERBOSITY level. */ |
c6bb733d | 806 | |
d2cd543b | 807 | void |
808 | print_scop (FILE *file, scop_p scop, int verbosity) | |
c6bb733d | 809 | { |
d2cd543b | 810 | int i; |
811 | poly_bb_p pbb; | |
812 | ||
8c4b14b0 | 813 | fprintf (file, "SCoP 1\n#(\n"); |
5dc5fe13 | 814 | fprintf (file, "# Language\nGimple\n"); |
8c4b14b0 | 815 | openscop_print_scop_context (file, scop, verbosity); |
ff4c7a5a | 816 | print_scop_params (file, scop, verbosity); |
817 | ||
818 | if (verbosity > 0) | |
819 | fprintf (file, "# Number of statements\n"); | |
820 | ||
f1f41a6c | 821 | fprintf (file, "%d\n", SCOP_BBS (scop).length ()); |
c6bb733d | 822 | |
f1f41a6c | 823 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
ff4c7a5a | 824 | print_pbb (file, pbb, verbosity); |
95b2e0d3 | 825 | |
ff4c7a5a | 826 | if (verbosity > 1) |
827 | { | |
828 | fprintf (file, "# original_lst (\n"); | |
829 | print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0); | |
830 | fprintf (file, "\n#)\n"); | |
f77385d3 | 831 | |
ff4c7a5a | 832 | fprintf (file, "# transformed_lst (\n"); |
833 | print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0); | |
834 | fprintf (file, "\n#)\n"); | |
835 | } | |
9b6c835c | 836 | |
5dc5fe13 | 837 | fprintf (file, "#)\n"); |
c6bb733d | 838 | } |
839 | ||
ff4c7a5a | 840 | /* Print to FILE the input file that CLooG would expect as input, at |
841 | some VERBOSITY level. */ | |
1f8d6d4d | 842 | |
843 | void | |
ff4c7a5a | 844 | print_cloog (FILE *file, scop_p scop, int verbosity) |
1f8d6d4d | 845 | { |
846 | int i; | |
847 | poly_bb_p pbb; | |
848 | ||
849 | fprintf (file, "# SCoP (generated by GCC/Graphite\n"); | |
ff4c7a5a | 850 | if (verbosity > 0) |
851 | fprintf (file, "# CLooG output language\n"); | |
852 | fprintf (file, "c\n"); | |
853 | ||
854 | print_scop_context (file, scop, verbosity); | |
855 | print_scop_params (file, scop, verbosity); | |
856 | ||
857 | if (verbosity > 0) | |
858 | fprintf (file, "# Number of statements\n"); | |
859 | ||
f1f41a6c | 860 | fprintf (file, "%d\n", SCOP_BBS (scop).length ()); |
1f8d6d4d | 861 | |
f1f41a6c | 862 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
1f8d6d4d | 863 | { |
ff4c7a5a | 864 | if (verbosity > 1) |
865 | fprintf (file, "# pbb_%d (\n", pbb_index (pbb)); | |
866 | ||
867 | print_pbb_domain (file, pbb, verbosity); | |
868 | fprintf (file, "0 0 0"); | |
869 | ||
870 | if (verbosity > 0) | |
871 | fprintf (file, "# For future CLooG options.\n"); | |
872 | else | |
873 | fprintf (file, "\n"); | |
874 | ||
875 | if (verbosity > 1) | |
876 | fprintf (file, "#)\n"); | |
1f8d6d4d | 877 | } |
878 | ||
ff4c7a5a | 879 | fprintf (file, "0"); |
880 | if (verbosity > 0) | |
881 | fprintf (file, "# Don't set the iterator names.\n"); | |
882 | else | |
883 | fprintf (file, "\n"); | |
884 | ||
885 | if (verbosity > 0) | |
886 | fprintf (file, "# Number of scattering functions\n"); | |
1f8d6d4d | 887 | |
f1f41a6c | 888 | fprintf (file, "%d\n", SCOP_BBS (scop).length ()); |
1f8d6d4d | 889 | |
f1f41a6c | 890 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
1f8d6d4d | 891 | { |
87e20041 | 892 | if (!(pbb->transformed || pbb->schedule)) |
1f8d6d4d | 893 | continue; |
894 | ||
ff4c7a5a | 895 | if (verbosity > 1) |
896 | fprintf (file, "# pbb_%d (\n", pbb_index (pbb)); | |
897 | ||
898 | print_scattering_function_1 (file, pbb, verbosity); | |
899 | ||
900 | if (verbosity > 1) | |
901 | fprintf (file, "#)\n"); | |
1f8d6d4d | 902 | } |
903 | ||
ff4c7a5a | 904 | fprintf (file, "0"); |
905 | if (verbosity > 0) | |
906 | fprintf (file, "# Don't set the scattering dimension names.\n"); | |
907 | else | |
908 | fprintf (file, "\n"); | |
909 | ||
1f8d6d4d | 910 | fprintf (file, "#)\n"); |
911 | } | |
912 | ||
ff4c7a5a | 913 | /* Print to STDERR the domain of PBB, at some VERBOSITY level. */ |
c6bb733d | 914 | |
4b987fac | 915 | DEBUG_FUNCTION void |
ff4c7a5a | 916 | debug_pbb_domain (poly_bb_p pbb, int verbosity) |
c6bb733d | 917 | { |
ff4c7a5a | 918 | print_pbb_domain (stderr, pbb, verbosity); |
c6bb733d | 919 | } |
920 | ||
ff4c7a5a | 921 | /* Print to FILE the domain and scattering function of PBB, at some |
922 | VERBOSITY level. */ | |
c6bb733d | 923 | |
4b987fac | 924 | DEBUG_FUNCTION void |
ff4c7a5a | 925 | debug_pbb (poly_bb_p pbb, int verbosity) |
c6bb733d | 926 | { |
ff4c7a5a | 927 | print_pbb (stderr, pbb, verbosity); |
c6bb733d | 928 | } |
929 | ||
ff4c7a5a | 930 | /* Print to STDERR the context of SCOP, at some VERBOSITY level. */ |
c6bb733d | 931 | |
4b987fac | 932 | DEBUG_FUNCTION void |
ff4c7a5a | 933 | debug_scop_context (scop_p scop, int verbosity) |
c6bb733d | 934 | { |
ff4c7a5a | 935 | print_scop_context (stderr, scop, verbosity); |
c6bb733d | 936 | } |
937 | ||
ff4c7a5a | 938 | /* Print to STDERR the SCOP, at some VERBOSITY level. */ |
c6bb733d | 939 | |
4b987fac | 940 | DEBUG_FUNCTION void |
ff4c7a5a | 941 | debug_scop (scop_p scop, int verbosity) |
c6bb733d | 942 | { |
ff4c7a5a | 943 | print_scop (stderr, scop, verbosity); |
c6bb733d | 944 | } |
945 | ||
ff4c7a5a | 946 | /* Print to STDERR the SCOP under CLooG format, at some VERBOSITY |
947 | level. */ | |
1f8d6d4d | 948 | |
4b987fac | 949 | DEBUG_FUNCTION void |
ff4c7a5a | 950 | debug_cloog (scop_p scop, int verbosity) |
1f8d6d4d | 951 | { |
ff4c7a5a | 952 | print_cloog (stderr, scop, verbosity); |
1f8d6d4d | 953 | } |
954 | ||
ff4c7a5a | 955 | /* Print to STDERR the parameters of SCOP, at some VERBOSITY |
956 | level. */ | |
c6bb733d | 957 | |
4b987fac | 958 | DEBUG_FUNCTION void |
ff4c7a5a | 959 | debug_scop_params (scop_p scop, int verbosity) |
c6bb733d | 960 | { |
ff4c7a5a | 961 | print_scop_params (stderr, scop, verbosity); |
c6bb733d | 962 | } |
963 | ||
87e20041 | 964 | extern isl_ctx *the_isl_ctx; |
965 | void | |
966 | print_isl_set (FILE *f, isl_set *set) | |
c6bb733d | 967 | { |
87e20041 | 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); | |
971 | } | |
c6bb733d | 972 | |
87e20041 | 973 | DEBUG_FUNCTION void |
974 | debug_isl_set (isl_set *set) | |
975 | { | |
976 | print_isl_set (stderr, set); | |
977 | } | |
c6bb733d | 978 | |
87e20041 | 979 | void |
980 | print_isl_map (FILE *f, isl_map *map) | |
981 | { | |
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); | |
985 | } | |
c6bb733d | 986 | |
87e20041 | 987 | DEBUG_FUNCTION void |
988 | debug_isl_map (isl_map *map) | |
989 | { | |
990 | print_isl_map (stderr, map); | |
991 | } | |
c6bb733d | 992 | |
87e20041 | 993 | void |
994 | print_isl_aff (FILE *f, isl_aff *aff) | |
995 | { | |
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); | |
999 | } | |
c6bb733d | 1000 | |
87e20041 | 1001 | DEBUG_FUNCTION void |
1002 | debug_isl_aff (isl_aff *aff) | |
1003 | { | |
1004 | print_isl_aff (stderr, aff); | |
1005 | } | |
c6bb733d | 1006 | |
87e20041 | 1007 | void |
1008 | print_isl_constraint (FILE *f, isl_constraint *c) | |
1009 | { | |
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); | |
1013 | } | |
c6bb733d | 1014 | |
87e20041 | 1015 | DEBUG_FUNCTION void |
1016 | debug_isl_constraint (isl_constraint *c) | |
1017 | { | |
1018 | print_isl_constraint (stderr, c); | |
c6bb733d | 1019 | } |
1020 | ||
bd432164 | 1021 | /* Returns the number of iterations RES of the loop around PBB at |
ee0d08ad | 1022 | time(scattering) dimension TIME_DEPTH. */ |
1023 | ||
1024 | void | |
1025 | pbb_number_of_iterations_at_time (poly_bb_p pbb, | |
1026 | graphite_dim_t time_depth, | |
bd432164 | 1027 | mpz_t res) |
ee0d08ad | 1028 | { |
87e20041 | 1029 | isl_set *transdomain; |
1030 | isl_space *dc; | |
1031 | isl_aff *aff; | |
1032 | isl_int isllb, islub; | |
ee0d08ad | 1033 | |
87e20041 | 1034 | isl_int_init (isllb); |
1035 | isl_int_init (islub); | |
d9e94834 | 1036 | |
87e20041 | 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)); | |
d9e94834 | 1041 | |
87e20041 | 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); | |
dd37d9f7 | 1046 | |
87e20041 | 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); | |
d9e94834 | 1051 | |
87e20041 | 1052 | isl_int_sub (islub, islub, isllb); |
1053 | isl_int_add_ui (islub, islub, 1); | |
1054 | isl_int_get_gmp (islub, res); | |
ee0d08ad | 1055 | |
87e20041 | 1056 | isl_int_clear (isllb); |
1057 | isl_int_clear (islub); | |
1058 | isl_aff_free (aff); | |
1059 | isl_set_free (transdomain); | |
ee0d08ad | 1060 | } |
1061 | ||
f77385d3 | 1062 | /* Translates LOOP to LST. */ |
1063 | ||
1064 | static lst_p | |
f1f41a6c | 1065 | loop_to_lst (loop_p loop, vec<poly_bb_p> bbs, int *i) |
f77385d3 | 1066 | { |
1067 | poly_bb_p pbb; | |
f1f41a6c | 1068 | vec<lst_p> seq; |
1069 | seq.create (5); | |
f77385d3 | 1070 | |
f1f41a6c | 1071 | for (; bbs.iterate (*i, &pbb); (*i)++) |
f77385d3 | 1072 | { |
1073 | lst_p stmt; | |
1074 | basic_block bb = GBB_BB (PBB_BLACK_BOX (pbb)); | |
1075 | ||
1076 | if (bb->loop_father == loop) | |
1077 | stmt = new_lst_stmt (pbb); | |
71b90bc3 | 1078 | else if (flow_bb_inside_loop_p (loop, bb)) |
f77385d3 | 1079 | { |
71b90bc3 | 1080 | loop_p next = loop->inner; |
f77385d3 | 1081 | |
71b90bc3 | 1082 | while (next && !flow_bb_inside_loop_p (next, bb)) |
1083 | next = next->next; | |
f77385d3 | 1084 | |
71b90bc3 | 1085 | stmt = loop_to_lst (next, bbs, i); |
1086 | } | |
1087 | else | |
1088 | { | |
1089 | (*i)--; | |
1090 | return new_lst_loop (seq); | |
f77385d3 | 1091 | } |
1092 | ||
f1f41a6c | 1093 | seq.safe_push (stmt); |
f77385d3 | 1094 | } |
1095 | ||
1096 | return new_lst_loop (seq); | |
1097 | } | |
1098 | ||
1099 | /* Reads the original scattering of the SCOP and returns an LST | |
1100 | representing it. */ | |
1101 | ||
1102 | void | |
1103 | scop_to_lst (scop_p scop) | |
1104 | { | |
43217ce9 | 1105 | lst_p res; |
f1f41a6c | 1106 | int i, n = SCOP_BBS (scop).length (); |
1107 | vec<lst_p> seq; | |
1108 | seq.create (5); | |
43217ce9 | 1109 | sese region = SCOP_REGION (scop); |
1110 | ||
1111 | for (i = 0; i < n; i++) | |
1112 | { | |
f1f41a6c | 1113 | poly_bb_p pbb = SCOP_BBS (scop)[i]; |
43217ce9 | 1114 | loop_p loop = outermost_loop_in_sese (region, GBB_BB (PBB_BLACK_BOX (pbb))); |
1115 | ||
1116 | if (loop_in_sese_p (loop, region)) | |
1117 | res = loop_to_lst (loop, SCOP_BBS (scop), &i); | |
1118 | else | |
1119 | res = new_lst_stmt (pbb); | |
1120 | ||
f1f41a6c | 1121 | seq.safe_push (res); |
43217ce9 | 1122 | } |
f77385d3 | 1123 | |
43217ce9 | 1124 | res = new_lst_loop (seq); |
1125 | SCOP_ORIGINAL_SCHEDULE (scop) = res; | |
1126 | SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (res); | |
f77385d3 | 1127 | } |
1128 | ||
5dc5fe13 | 1129 | /* Print to FILE on a new line COLUMN white spaces. */ |
1130 | ||
1131 | static void | |
1132 | lst_indent_to (FILE *file, int column) | |
1133 | { | |
1134 | int i; | |
1135 | ||
1136 | if (column > 0) | |
1137 | fprintf (file, "\n#"); | |
1138 | ||
1139 | for (i = 0; i < column; i++) | |
1140 | fprintf (file, " "); | |
1141 | } | |
1142 | ||
f77385d3 | 1143 | /* Print LST to FILE with INDENT spaces of indentation. */ |
1144 | ||
1145 | void | |
1146 | print_lst (FILE *file, lst_p lst, int indent) | |
1147 | { | |
1148 | if (!lst) | |
1149 | return; | |
1150 | ||
5dc5fe13 | 1151 | lst_indent_to (file, indent); |
f77385d3 | 1152 | |
1153 | if (LST_LOOP_P (lst)) | |
1154 | { | |
1155 | int i; | |
1156 | lst_p l; | |
1157 | ||
43217ce9 | 1158 | if (LST_LOOP_FATHER (lst)) |
1159 | fprintf (file, "%d (loop", lst_dewey_number (lst)); | |
1160 | else | |
5dc5fe13 | 1161 | fprintf (file, "#(root"); |
f77385d3 | 1162 | |
f1f41a6c | 1163 | FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l) |
f77385d3 | 1164 | print_lst (file, l, indent + 2); |
1165 | ||
1166 | fprintf (file, ")"); | |
1167 | } | |
1168 | else | |
1169 | fprintf (file, "%d stmt_%d", lst_dewey_number (lst), pbb_index (LST_PBB (lst))); | |
1170 | } | |
1171 | ||
1172 | /* Print LST to STDERR. */ | |
1173 | ||
4b987fac | 1174 | DEBUG_FUNCTION void |
f77385d3 | 1175 | debug_lst (lst_p lst) |
1176 | { | |
1177 | print_lst (stderr, lst, 0); | |
1178 | } | |
1179 | ||
4938b827 | 1180 | /* Pretty print to FILE the loop statement tree LST in DOT format. */ |
1181 | ||
1182 | static void | |
1183 | dot_lst_1 (FILE *file, lst_p lst) | |
1184 | { | |
1185 | if (!lst) | |
1186 | return; | |
1187 | ||
1188 | if (LST_LOOP_P (lst)) | |
1189 | { | |
1190 | int i; | |
1191 | lst_p l; | |
1192 | ||
1193 | if (!LST_LOOP_FATHER (lst)) | |
1194 | fprintf (file, "L -> L_%d_%d\n", | |
1195 | lst_depth (lst), | |
1196 | lst_dewey_number (lst)); | |
1197 | else | |
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)), | |
1201 | lst_depth (lst), | |
1202 | lst_dewey_number (lst)); | |
1203 | ||
f1f41a6c | 1204 | FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l) |
4938b827 | 1205 | dot_lst_1 (file, l); |
1206 | } | |
1207 | ||
1208 | else | |
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))); | |
1213 | ||
1214 | } | |
1215 | ||
1216 | /* Display the LST using dotty. */ | |
1217 | ||
6b5822fe | 1218 | DEBUG_FUNCTION void |
4938b827 | 1219 | dot_lst (lst_p lst) |
1220 | { | |
1221 | /* When debugging, enable the following code. This cannot be used | |
1222 | in production compilers because it calls "system". */ | |
1223 | #if 0 | |
4938b827 | 1224 | FILE *stream = fopen ("/tmp/lst.dot", "w"); |
1225 | gcc_assert (stream); | |
1226 | ||
1227 | fputs ("digraph all {\n", stream); | |
1228 | dot_lst_1 (stream, lst); | |
1229 | fputs ("}\n\n", stream); | |
1230 | fclose (stream); | |
1231 | ||
97b0e4df | 1232 | system ("dotty /tmp/lst.dot &"); |
4938b827 | 1233 | #else |
1234 | fputs ("digraph all {\n", stderr); | |
1235 | dot_lst_1 (stderr, lst); | |
1236 | fputs ("}\n\n", stderr); | |
1237 | ||
1238 | #endif | |
1239 | } | |
1240 | ||
079f4f8c | 1241 | /* Computes a checksum for the code generated by CLooG for SCOP. */ |
1242 | ||
1243 | DEBUG_FUNCTION void | |
1244 | cloog_checksum (scop_p scop ATTRIBUTE_UNUSED) | |
1245 | { | |
1246 | /* When debugging, enable the following code. This cannot be used | |
1247 | in production compilers because it calls "system". */ | |
1248 | #if 0 | |
1249 | FILE *stream = fopen ("/tmp/scop.cloog", "w"); | |
1250 | gcc_assert (stream); | |
1251 | print_cloog (stream, scop, 0); | |
1252 | fclose (stream); | |
1253 | ||
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 "); | |
1256 | #endif | |
1257 | } | |
1258 | ||
87e20041 | 1259 | /* Reverse the loop around PBB at level DEPTH. */ |
1260 | ||
1261 | isl_map * | |
1262 | reverse_loop_at_level (poly_bb_p pbb, int depth) | |
1263 | { | |
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)); | |
1271 | ||
1272 | for (i = 0; i < n; i++) | |
1273 | if (i != depth_dim) | |
1274 | x = isl_map_equate (x, isl_dim_in, i, isl_dim_out, i); | |
1275 | ||
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); | |
1279 | return x; | |
1280 | } | |
1281 | ||
1282 | /* Reverse the loop at level DEPTH for all the PBBS. */ | |
1283 | ||
1284 | isl_union_map * | |
f1f41a6c | 1285 | reverse_loop_for_pbbs (scop_p scop, vec<poly_bb_p> pbbs, int depth) |
87e20041 | 1286 | { |
1287 | poly_bb_p pbb; | |
1288 | int i; | |
1289 | isl_space *space = isl_space_from_domain (isl_set_get_space (scop->context)); | |
1290 | isl_union_map *res = isl_union_map_empty (space); | |
1291 | ||
f1f41a6c | 1292 | for (i = 0; pbbs.iterate (i, &pbb); i++) |
87e20041 | 1293 | res = isl_union_map_add_map (res, reverse_loop_at_level (pbb, depth)); |
1294 | ||
1295 | return res; | |
1296 | } | |
1297 | ||
1298 | ||
c6bb733d | 1299 | #endif |
1300 |