]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/graphite-poly.c
pt.c (comp_template_args): Remove.
[thirdparty/gcc.git] / gcc / graphite-poly.c
CommitLineData
2abae5f1 1/* Graphite polyhedral representation.
5624e564 2 Copyright (C) 2009-2015 Free Software Foundation, Inc.
2abae5f1
SP
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GCC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
33ad93b9 21
4d776011
DE
22#define USES_ISL
23
2abae5f1 24#include "config.h"
33ad93b9 25
eae1a5d4 26#ifdef HAVE_isl
4d776011
DE
27
28#include "system.h"
29#include "coretypes.h"
30#include "backend.h"
31#include "tree.h"
32#include "gimple.h"
33#include "cfghooks.h"
4d776011
DE
34#include "diagnostic-core.h"
35#include "fold-const.h"
36#include "gimple-iterator.h"
37#include "tree-ssa-loop.h"
38#include "cfgloop.h"
39#include "tree-data-ref.h"
040b0c97
AK
40#include "pretty-print.h"
41#include "gimple-pretty-print.h"
42#include "tree-dump.h"
4bc190dc 43
32400032 44#include <isl/constraint.h>
33ad93b9
RG
45#include <isl/set.h>
46#include <isl/map.h>
47#include <isl/union_map.h>
48#include <isl/constraint.h>
49#include <isl/ilp.h>
50#include <isl/aff.h>
b47595f7 51#include <isl/val.h>
b47595f7 52#include <isl/val_gmp.h>
33ad93b9 53
cf98f0f4 54#include "graphite.h"
2abae5f1 55
721c8b1e
RB
56#define OPENSCOP_MAX_STRING 256
57
33ad93b9
RG
58
59/* Print to STDERR the GMP value VAL. */
60
61DEBUG_FUNCTION void
62debug_gmp_value (mpz_t val)
63{
8ac16127 64 gmp_fprintf (stderr, "%Zd", val);
33ad93b9
RG
65}
66
5c24066b 67/* Prints to FILE the iteration domain of PBB. */
2abae5f1
SP
68
69void
5c24066b 70print_iteration_domain (FILE *file, poly_bb_p pbb)
2abae5f1 71{
5c24066b 72 print_pbb_domain (file, pbb);
2abae5f1
SP
73}
74
5c24066b 75/* Prints to FILE the iteration domains of every PBB of SCOP. */
2abae5f1
SP
76
77void
5c24066b 78print_iteration_domains (FILE *file, scop_p scop)
2abae5f1
SP
79{
80 int i;
81 poly_bb_p pbb;
82
b0b5710c 83 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
5c24066b 84 print_iteration_domain (file, pbb);
2abae5f1
SP
85}
86
5c24066b 87/* Prints to STDERR the iteration domain of PBB. */
2abae5f1 88
24e47c76 89DEBUG_FUNCTION void
5c24066b 90debug_iteration_domain (poly_bb_p pbb)
2abae5f1 91{
5c24066b 92 print_iteration_domain (stderr, pbb);
2abae5f1
SP
93}
94
5c24066b 95/* Prints to STDERR the iteration domains of every PBB of SCOP. */
2abae5f1 96
24e47c76 97DEBUG_FUNCTION void
5c24066b 98debug_iteration_domains (scop_p scop)
2abae5f1 99{
5c24066b 100 print_iteration_domains (stderr, scop);
2abae5f1
SP
101}
102
103/* Apply graphite transformations to all the basic blocks of SCOP. */
104
105bool
106apply_poly_transforms (scop_p scop)
107{
108 bool transform_done = false;
721c8b1e 109
2abae5f1
SP
110 /* Generate code even if we did not apply any real transformation.
111 This also allows to check the performance for the identity
d6bb5ccf 112 transformation: GIMPLE -> GRAPHITE -> GIMPLE. */
2abae5f1
SP
113 if (flag_graphite_identity)
114 transform_done = true;
115
3cf0e270 116 if (flag_loop_parallelize_all)
2abae5f1
SP
117 transform_done = true;
118
84c36240 119 if (flag_loop_nest_optimize)
b60cc080
TG
120 transform_done |= optimize_isl (scop);
121
2abae5f1
SP
122 return transform_done;
123}
124
25d7cc15
SP
125/* Create a new polyhedral data reference and add it to PBB. It is
126 defined by its ACCESSES, its TYPE, and the number of subscripts
127 NB_SUBSCRIPTS. */
2abae5f1
SP
128
129void
65b016eb 130new_poly_dr (poly_bb_p pbb, gimple *stmt, enum poly_dr_type type,
24757752 131 isl_map *acc, isl_set *subscript_sizes)
2abae5f1 132{
afae0207 133 static int id = 0;
211694b6 134 poly_dr_p pdr = XNEW (struct poly_dr);
2abae5f1 135
65b016eb 136 pdr->stmt = stmt;
afae0207 137 PDR_ID (pdr) = id++;
7bd2a8a7 138 PDR_NB_REFS (pdr) = 1;
2abae5f1 139 PDR_PBB (pdr) = pbb;
33ad93b9 140 pdr->accesses = acc;
24757752 141 pdr->subscript_sizes = subscript_sizes;
2abae5f1 142 PDR_TYPE (pdr) = type;
9771b263 143 PBB_DRS (pbb).safe_push (pdr);
040b0c97
AK
144
145 if (dump_file)
146 {
147 fprintf (dump_file, "Converting dr: ");
148 print_pdr (dump_file, pdr);
149 fprintf (dump_file, "To polyhedral representation:\n");
150 fprintf (dump_file, " - access functions: ");
151 print_isl_map (dump_file, acc);
152 fprintf (dump_file, " - subscripts: ");
153 print_isl_set (dump_file, subscript_sizes);
154 }
2abae5f1
SP
155}
156
157/* Free polyhedral data reference PDR. */
158
159void
160free_poly_dr (poly_dr_p pdr)
161{
33ad93b9 162 isl_map_free (pdr->accesses);
24757752 163 isl_set_free (pdr->subscript_sizes);
2abae5f1
SP
164 XDELETE (pdr);
165}
166
167/* Create a new polyhedral black box. */
168
efa21390 169poly_bb_p
8e4dc590 170new_poly_bb (scop_p scop, gimple_poly_bb_p black_box)
2abae5f1
SP
171{
172 poly_bb_p pbb = XNEW (struct poly_bb);
173
33ad93b9
RG
174 pbb->domain = NULL;
175 pbb->schedule = NULL;
176 pbb->transformed = NULL;
177 pbb->saved = NULL;
2abae5f1
SP
178 PBB_SCOP (pbb) = scop;
179 pbb_set_black_box (pbb, black_box);
9771b263 180 PBB_DRS (pbb).create (3);
efa21390 181 PBB_IS_REDUCTION (pbb) = false;
65ef70d6 182 GBB_PBB ((gimple_poly_bb_p) black_box) = pbb;
efa21390
SP
183
184 return pbb;
2abae5f1
SP
185}
186
187/* Free polyhedral black box. */
188
189void
190free_poly_bb (poly_bb_p pbb)
191{
192 int i;
193 poly_dr_p pdr;
194
33ad93b9
RG
195 isl_set_free (pbb->domain);
196 isl_map_free (pbb->schedule);
197 isl_map_free (pbb->transformed);
198 isl_map_free (pbb->saved);
2abae5f1 199
9771b263
DN
200 if (PBB_DRS (pbb).exists ())
201 FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr)
2abae5f1
SP
202 free_poly_dr (pdr);
203
9771b263 204 PBB_DRS (pbb).release ();
2abae5f1
SP
205 XDELETE (pbb);
206}
207
5c24066b 208/* Prints to FILE the polyhedral data reference PDR. */
2abae5f1
SP
209
210void
5c24066b 211print_pdr (FILE *file, poly_dr_p pdr)
2abae5f1 212{
5c24066b 213 fprintf (file, "pdr_%d (", PDR_ID (pdr));
2abae5f1 214
5c24066b
AK
215 switch (PDR_TYPE (pdr))
216 {
217 case PDR_READ:
218 fprintf (file, "read \n");
219 break;
2abae5f1 220
5c24066b
AK
221 case PDR_WRITE:
222 fprintf (file, "write \n");
223 break;
2abae5f1 224
5c24066b
AK
225 case PDR_MAY_WRITE:
226 fprintf (file, "may_write \n");
227 break;
40bf935e 228
5c24066b
AK
229 default:
230 gcc_unreachable ();
2abae5f1
SP
231 }
232
65b016eb
AK
233 fprintf (file, "in gimple stmt: ");
234 print_gimple_stmt (file, pdr->stmt, 0, 0);
5c24066b
AK
235 fprintf (file, "data accesses: ");
236 print_isl_map (file, pdr->accesses);
237 fprintf (file, "subscript sizes: ");
238 print_isl_set (file, pdr->subscript_sizes);
239 fprintf (file, ")\n");
2abae5f1
SP
240}
241
5c24066b 242/* Prints to STDERR the polyhedral data reference PDR. */
2abae5f1 243
24e47c76 244DEBUG_FUNCTION void
5c24066b 245debug_pdr (poly_dr_p pdr)
2abae5f1 246{
5c24066b 247 print_pdr (stderr, pdr);
2abae5f1
SP
248}
249
87ccab5d
AK
250/* Store the GRAPHITE representation of BB. */
251
252gimple_poly_bb_p
65b016eb
AK
253new_gimple_poly_bb (basic_block bb, vec<data_reference_p> drs,
254 vec<scalar_use> reads, vec<tree> writes)
87ccab5d 255{
65b016eb 256 gimple_poly_bb_p gbb = XNEW (struct gimple_poly_bb);
87ccab5d
AK
257 GBB_BB (gbb) = bb;
258 GBB_DATA_REFS (gbb) = drs;
65b016eb
AK
259 gbb->read_scalar_refs = reads;
260 gbb->write_scalar_refs = writes;
87ccab5d
AK
261 GBB_CONDITIONS (gbb).create (0);
262 GBB_CONDITION_CASES (gbb).create (0);
263
264 return gbb;
265}
266
87ccab5d
AK
267/* Frees GBB. */
268
269void
270free_gimple_poly_bb (gimple_poly_bb_p gbb)
271{
87ccab5d 272 free_data_refs (GBB_DATA_REFS (gbb));
87ccab5d
AK
273 GBB_CONDITIONS (gbb).release ();
274 GBB_CONDITION_CASES (gbb).release ();
65b016eb
AK
275 gbb->read_scalar_refs.release ();
276 gbb->write_scalar_refs.release ();
87ccab5d
AK
277 XDELETE (gbb);
278}
279
280/* Deletes all gimple bbs in SCOP. */
281
282static void
283remove_gbbs_in_scop (scop_p scop)
284{
285 int i;
286 poly_bb_p pbb;
287
b0b5710c 288 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
87ccab5d
AK
289 free_gimple_poly_bb (PBB_BLACK_BOX (pbb));
290}
291
292/* Creates a new SCOP containing the region (ENTRY, EXIT). */
2abae5f1
SP
293
294scop_p
87ccab5d 295new_scop (edge entry, edge exit)
2abae5f1 296{
bafcb153 297 sese_info_p region = new_sese_info (entry, exit);
0f7a02a3
AK
298 scop_p s;
299 s = XNEW (struct scop);
300
301 s->param_context = NULL;
302 scop_set_region (s, region);
303 s->pbbs.create (3);
304 s->drs.create (3);
305 s->dependence = NULL;
306 return s;
2abae5f1
SP
307}
308
309/* Deletes SCOP. */
310
311void
312free_scop (scop_p scop)
313{
314 int i;
315 poly_bb_p pbb;
316
87ccab5d 317 remove_gbbs_in_scop (scop);
d37fc3aa 318 free_sese_info (scop->scop_info);
87ccab5d 319
b0b5710c 320 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
2abae5f1
SP
321 free_poly_bb (pbb);
322
b0b5710c 323 scop->pbbs.release ();
ec17e433 324 scop->drs.release ();
2abae5f1 325
8e4dc590 326 isl_set_free (scop->param_context);
0f7a02a3
AK
327 isl_union_map_free (scop->dependence);
328 scop->dependence = NULL;
2abae5f1
SP
329 XDELETE (scop);
330}
331
5c24066b 332/* Print to FILE the domain of PBB. */
2abae5f1
SP
333
334void
5c24066b 335print_pbb_domain (FILE *file, poly_bb_p pbb)
2abae5f1 336{
33ad93b9 337 print_isl_set (file, pbb->domain);
2abae5f1
SP
338}
339
340/* Dump the cases of a graphite basic block GBB on FILE. */
341
342static void
65ef70d6 343dump_gbb_cases (FILE *file, gimple_poly_bb_p gbb)
2abae5f1
SP
344{
345 int i;
355fe088
TS
346 gimple *stmt;
347 vec<gimple *> cases;
2abae5f1
SP
348
349 if (!gbb)
350 return;
351
352 cases = GBB_CONDITION_CASES (gbb);
9771b263 353 if (cases.is_empty ())
2abae5f1
SP
354 return;
355
5c24066b 356 fprintf (file, "cases bb_%d (\n", GBB_BB (gbb)->index);
2abae5f1 357
9771b263 358 FOR_EACH_VEC_ELT (cases, i, stmt)
5c24066b 359 print_gimple_stmt (file, stmt, 0, 0);
2abae5f1 360
5c24066b 361 fprintf (file, ")\n");
2abae5f1
SP
362}
363
364/* Dump conditions of a graphite basic block GBB on FILE. */
365
366static void
65ef70d6 367dump_gbb_conditions (FILE *file, gimple_poly_bb_p gbb)
2abae5f1
SP
368{
369 int i;
355fe088
TS
370 gimple *stmt;
371 vec<gimple *> conditions;
2abae5f1
SP
372
373 if (!gbb)
374 return;
375
376 conditions = GBB_CONDITIONS (gbb);
9771b263 377 if (conditions.is_empty ())
2abae5f1
SP
378 return;
379
5c24066b 380 fprintf (file, "conditions bb_%d (\n", GBB_BB (gbb)->index);
2abae5f1 381
9771b263 382 FOR_EACH_VEC_ELT (conditions, i, stmt)
5c24066b 383 print_gimple_stmt (file, stmt, 0, 0);
2abae5f1 384
5c24066b 385 fprintf (file, ")\n");
2abae5f1
SP
386}
387
5c24066b 388/* Print to FILE all the data references of PBB. */
2abae5f1
SP
389
390void
5c24066b 391print_pdrs (FILE *file, poly_bb_p pbb)
2abae5f1
SP
392{
393 int i;
394 poly_dr_p pdr;
03922af3
SP
395 int nb_reads = 0;
396 int nb_writes = 0;
2abae5f1 397
5c24066b
AK
398 if (PBB_DRS (pbb).is_empty ())
399 return;
40bf935e 400
5c24066b 401 fprintf (file, "Data references (\n");
03922af3 402
9771b263 403 FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr)
03922af3
SP
404 if (PDR_TYPE (pdr) == PDR_READ)
405 nb_reads++;
406 else
407 nb_writes++;
408
5c24066b 409 fprintf (file, "Read data references (\n");
40bf935e 410
9771b263 411 FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr)
03922af3 412 if (PDR_TYPE (pdr) == PDR_READ)
5c24066b 413 print_pdr (file, pdr);
03922af3 414
5c24066b
AK
415 fprintf (file, ")\n");
416 fprintf (file, "Write data references (\n");
9771b263 417 FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr)
03922af3 418 if (PDR_TYPE (pdr) != PDR_READ)
5c24066b
AK
419 print_pdr (file, pdr);
420 fprintf (file, ")\n");
421 fprintf (file, ")\n");
2abae5f1
SP
422}
423
424/* Print to STDERR all the data references of PBB. */
425
24e47c76 426DEBUG_FUNCTION void
5c24066b 427debug_pdrs (poly_bb_p pbb)
2abae5f1 428{
5c24066b 429 print_pdrs (stderr, pbb);
2abae5f1
SP
430}
431
5c24066b 432/* Print to FILE the body of PBB. */
03922af3
SP
433
434static void
5c24066b 435print_pbb_body (FILE *file, poly_bb_p pbb)
03922af3 436{
5c24066b 437 fprintf (file, "Body (\n");
512ab654 438 dump_bb (file, pbb_bb (pbb), 0, 0);
5c24066b 439 fprintf (file, ")\n");
03922af3
SP
440}
441
5c24066b 442/* Print to FILE the domain and scattering function of PBB. */
2abae5f1
SP
443
444void
5c24066b 445print_pbb (FILE *file, poly_bb_p pbb)
40bf935e 446{
5c24066b
AK
447 fprintf (file, "pbb_%d (\n", pbb_index (pbb));
448 dump_gbb_conditions (file, PBB_BLACK_BOX (pbb));
449 dump_gbb_cases (file, PBB_BLACK_BOX (pbb));
40bf935e 450
5c24066b
AK
451 print_pbb_domain (file, pbb);
452 print_pdrs (file, pbb);
453 print_pbb_body (file, pbb);
40bf935e 454
5c24066b 455 fprintf (file, ")\n");
2abae5f1
SP
456}
457
5c24066b 458/* Print to FILE the parameters of SCOP. */
2abae5f1
SP
459
460void
5c24066b 461print_scop_params (FILE *file, scop_p scop)
2abae5f1 462{
65b016eb 463 if (scop->scop_info->params.is_empty ())
5c24066b
AK
464 return;
465
2abae5f1
SP
466 int i;
467 tree t;
5c24066b 468 fprintf (file, "parameters (");
65b016eb 469 FOR_EACH_VEC_ELT (scop->scop_info->params, i, t)
2abae5f1 470 {
2abae5f1 471 print_generic_expr (file, t, 0);
5c24066b 472 fprintf (file, ", ");
2abae5f1 473 }
5c24066b 474 fprintf (file, ")\n");
2abae5f1
SP
475}
476
5c24066b 477/* Print to FILE the context of SCoP. */
40bf935e 478
2abae5f1 479void
5c24066b 480print_scop_context (FILE *file, scop_p scop)
2abae5f1 481{
5c24066b
AK
482 if (!scop->param_context)
483 return;
2abae5f1 484
5c24066b
AK
485 fprintf (file, "Context (\n");
486 print_isl_set (file, scop->param_context);
487 fprintf (file, ")\n");
2abae5f1
SP
488}
489
5c24066b 490/* Print to FILE the SCOP. */
2abae5f1 491
0ba82567 492void
5c24066b 493print_scop (FILE *file, scop_p scop)
2abae5f1 494{
0ba82567
SP
495 int i;
496 poly_bb_p pbb;
497
5c24066b
AK
498 fprintf (file, "SCoP (\n");
499 print_scop_context (file, scop);
500 print_scop_params (file, scop);
40bf935e 501
5c24066b 502 fprintf (file, "Number of statements: ");
b0b5710c 503 fprintf (file, "%d\n", scop->pbbs.length ());
2abae5f1 504
b0b5710c 505 FOR_EACH_VEC_ELT (scop->pbbs, i, pbb)
5c24066b 506 print_pbb (file, pbb);
e31a5bd4 507
5c24066b 508 fprintf (file, ")\n");
2abae5f1
SP
509}
510
5c24066b 511/* Print to STDERR the domain of PBB. */
2abae5f1 512
24e47c76 513DEBUG_FUNCTION void
5c24066b 514debug_pbb_domain (poly_bb_p pbb)
2abae5f1 515{
5c24066b 516 print_pbb_domain (stderr, pbb);
2abae5f1
SP
517}
518
5c24066b 519/* Print to FILE the domain and scattering function of PBB. */
2abae5f1 520
24e47c76 521DEBUG_FUNCTION void
5c24066b 522debug_pbb (poly_bb_p pbb)
2abae5f1 523{
5c24066b 524 print_pbb (stderr, pbb);
2abae5f1
SP
525}
526
5c24066b 527/* Print to STDERR the context of SCOP. */
2abae5f1 528
24e47c76 529DEBUG_FUNCTION void
5c24066b 530debug_scop_context (scop_p scop)
2abae5f1 531{
5c24066b 532 print_scop_context (stderr, scop);
2abae5f1
SP
533}
534
5c24066b 535/* Print to STDERR the SCOP. */
2abae5f1 536
24e47c76 537DEBUG_FUNCTION void
5c24066b 538debug_scop (scop_p scop)
2abae5f1 539{
5c24066b 540 print_scop (stderr, scop);
2abae5f1
SP
541}
542
5c24066b 543/* Print to STDERR the parameters of SCOP. */
2abae5f1 544
24e47c76 545DEBUG_FUNCTION void
5c24066b 546debug_scop_params (scop_p scop)
2abae5f1 547{
5c24066b 548 print_scop_params (stderr, scop);
2abae5f1
SP
549}
550
33ad93b9
RG
551extern isl_ctx *the_isl_ctx;
552void
553print_isl_set (FILE *f, isl_set *set)
2abae5f1 554{
33ad93b9
RG
555 isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
556 p = isl_printer_print_set (p, set);
d6bb5ccf 557 p = isl_printer_print_str (p, "\n");
33ad93b9
RG
558 isl_printer_free (p);
559}
2abae5f1 560
33ad93b9
RG
561DEBUG_FUNCTION void
562debug_isl_set (isl_set *set)
563{
564 print_isl_set (stderr, set);
565}
2abae5f1 566
33ad93b9
RG
567void
568print_isl_map (FILE *f, isl_map *map)
569{
570 isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
571 p = isl_printer_print_map (p, map);
d6bb5ccf 572 p = isl_printer_print_str (p, "\n");
33ad93b9
RG
573 isl_printer_free (p);
574}
2abae5f1 575
33ad93b9
RG
576DEBUG_FUNCTION void
577debug_isl_map (isl_map *map)
578{
579 print_isl_map (stderr, map);
580}
2abae5f1 581
ea17c0fe
AK
582void
583print_isl_union_map (FILE *f, isl_union_map *map)
584{
585 isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
586 p = isl_printer_print_union_map (p, map);
587 p = isl_printer_print_str (p, "\n");
588 isl_printer_free (p);
589}
590
591DEBUG_FUNCTION void
592debug_isl_union_map (isl_union_map *map)
593{
594 print_isl_union_map (stderr, map);
595}
596
597
33ad93b9
RG
598void
599print_isl_aff (FILE *f, isl_aff *aff)
600{
601 isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
602 p = isl_printer_print_aff (p, aff);
d6bb5ccf 603 p = isl_printer_print_str (p, "\n");
33ad93b9
RG
604 isl_printer_free (p);
605}
2abae5f1 606
33ad93b9
RG
607DEBUG_FUNCTION void
608debug_isl_aff (isl_aff *aff)
609{
610 print_isl_aff (stderr, aff);
611}
2abae5f1 612
33ad93b9
RG
613void
614print_isl_constraint (FILE *f, isl_constraint *c)
615{
616 isl_printer *p = isl_printer_to_file (the_isl_ctx, f);
617 p = isl_printer_print_constraint (p, c);
d6bb5ccf 618 p = isl_printer_print_str (p, "\n");
33ad93b9
RG
619 isl_printer_free (p);
620}
2abae5f1 621
33ad93b9
RG
622DEBUG_FUNCTION void
623debug_isl_constraint (isl_constraint *c)
624{
625 print_isl_constraint (stderr, c);
2abae5f1
SP
626}
627
26ccb556 628/* Returns the number of iterations RES of the loop around PBB at
baf4b881
KT
629 time(scattering) dimension TIME_DEPTH. */
630
631void
632pbb_number_of_iterations_at_time (poly_bb_p pbb,
633 graphite_dim_t time_depth,
26ccb556 634 mpz_t res)
baf4b881 635{
33ad93b9
RG
636 isl_set *transdomain;
637 isl_space *dc;
638 isl_aff *aff;
b47595f7 639 isl_val *isllb, *islub;
2b7c09a8 640
33ad93b9
RG
641 /* Map the iteration domain through the current scatter, and work
642 on the resulting set. */
643 transdomain = isl_set_apply (isl_set_copy (pbb->domain),
644 isl_map_copy (pbb->transformed));
2b7c09a8 645
33ad93b9
RG
646 /* Select the time_depth' dimension via an affine expression. */
647 dc = isl_set_get_space (transdomain);
648 aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc));
649 aff = isl_aff_set_coefficient_si (aff, isl_dim_in, time_depth, 1);
aad78a1a 650
33ad93b9
RG
651 /* And find the min/max for that function. */
652 /* XXX isl check results? */
b47595f7
MN
653 isllb = isl_set_min_val (transdomain, aff);
654 islub = isl_set_max_val (transdomain, aff);
2b7c09a8 655
b47595f7
MN
656 islub = isl_val_sub (islub, isllb);
657 islub = isl_val_add_ui (islub, 1);
658 isl_val_get_num_gmp (islub, res);
baf4b881 659
b47595f7 660 isl_val_free (islub);
33ad93b9
RG
661 isl_aff_free (aff);
662 isl_set_free (transdomain);
baf4b881
KT
663}
664
9c358739 665#endif /* HAVE_isl */
2abae5f1 666