Coverage Report

Created: 2018-04-24 22:41

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_schedule_band.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2013-2014 Ecole Normale Superieure
3
 * Copyright 2014      INRIA Rocquencourt
4
 *
5
 * Use of this software is governed by the MIT license
6
 *
7
 * Written by Sven Verdoolaege,
8
 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
9
 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
10
 * B.P. 105 - 78153 Le Chesnay, France
11
 */
12
13
#include <string.h>
14
#include <isl/val.h>
15
#include <isl/space.h>
16
#include <isl/map.h>
17
#include <isl/schedule_node.h>
18
#include <isl_schedule_band.h>
19
#include <isl_schedule_private.h>
20
21
isl_ctx *isl_schedule_band_get_ctx(__isl_keep isl_schedule_band *band)
22
3.36k
{
23
3.36k
  return band ? isl_multi_union_pw_aff_get_ctx(band->mupa) : NULL;
24
3.36k
}
25
26
/* Return a new uninitialized isl_schedule_band.
27
 */
28
static __isl_give isl_schedule_band *isl_schedule_band_alloc(isl_ctx *ctx)
29
3.23k
{
30
3.23k
  isl_schedule_band *band;
31
3.23k
32
3.23k
  band = isl_calloc_type(ctx, isl_schedule_band);
33
3.23k
  if (!band)
34
0
    return NULL;
35
3.23k
36
3.23k
  band->ref = 1;
37
3.23k
38
3.23k
  return band;
39
3.23k
}
40
41
/* Return a new isl_schedule_band with partial schedule "mupa".
42
 * First replace "mupa" by its greatest integer part to ensure
43
 * that the schedule is always integral.
44
 * The band is not marked permutable, the dimensions are not
45
 * marked coincident and the AST build options are empty.
46
 * Since there are no build options, the node is not anchored.
47
 */
48
__isl_give isl_schedule_band *isl_schedule_band_from_multi_union_pw_aff(
49
  __isl_take isl_multi_union_pw_aff *mupa)
50
1.99k
{
51
1.99k
  isl_ctx *ctx;
52
1.99k
  isl_schedule_band *band;
53
1.99k
  isl_space *space;
54
1.99k
55
1.99k
  mupa = isl_multi_union_pw_aff_floor(mupa);
56
1.99k
  if (!mupa)
57
0
    return NULL;
58
1.99k
  ctx = isl_multi_union_pw_aff_get_ctx(mupa);
59
1.99k
  band = isl_schedule_band_alloc(ctx);
60
1.99k
  if (!band)
61
0
    goto error;
62
1.99k
63
1.99k
  band->n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set);
64
1.99k
  band->coincident = isl_calloc_array(ctx, int, band->n);
65
1.99k
  band->mupa = mupa;
66
1.99k
  space = isl_space_params_alloc(ctx, 0);
67
1.99k
  band->ast_build_options = isl_union_set_empty(space);
68
1.99k
  band->anchored = 0;
69
1.99k
70
1.99k
  if ((band->n && !band->coincident) || !band->ast_build_options)
71
0
    return isl_schedule_band_free(band);
72
1.99k
73
1.99k
  return band;
74
0
error:
75
0
  isl_multi_union_pw_aff_free(mupa);
76
0
  return NULL;
77
1.99k
}
78
79
/* Create a duplicate of the given isl_schedule_band.
80
 */
81
__isl_give isl_schedule_band *isl_schedule_band_dup(
82
  __isl_keep isl_schedule_band *band)
83
1.24k
{
84
1.24k
  int i;
85
1.24k
  isl_ctx *ctx;
86
1.24k
  isl_schedule_band *dup;
87
1.24k
88
1.24k
  if (!band)
89
0
    return NULL;
90
1.24k
91
1.24k
  ctx = isl_schedule_band_get_ctx(band);
92
1.24k
  dup = isl_schedule_band_alloc(ctx);
93
1.24k
  if (!dup)
94
0
    return NULL;
95
1.24k
96
1.24k
  dup->n = band->n;
97
1.24k
  dup->coincident = isl_alloc_array(ctx, int, band->n);
98
1.24k
  if (band->n && !dup->coincident)
99
0
    return isl_schedule_band_free(dup);
100
1.24k
101
3.17k
  
for (i = 0; 1.24k
i < band->n;
++i1.93k
)
102
1.93k
    dup->coincident[i] = band->coincident[i];
103
1.24k
  dup->permutable = band->permutable;
104
1.24k
105
1.24k
  dup->mupa = isl_multi_union_pw_aff_copy(band->mupa);
106
1.24k
  dup->ast_build_options = isl_union_set_copy(band->ast_build_options);
107
1.24k
  if (!dup->mupa || !dup->ast_build_options)
108
0
    return isl_schedule_band_free(dup);
109
1.24k
110
1.24k
  if (band->loop_type) {
111
18
    dup->loop_type = isl_alloc_array(ctx,
112
18
              enum isl_ast_loop_type, band->n);
113
18
    if (band->n && !dup->loop_type)
114
0
      return isl_schedule_band_free(dup);
115
62
    
for (i = 0; 18
i < band->n;
++i44
)
116
44
      dup->loop_type[i] = band->loop_type[i];
117
18
  }
118
1.24k
  if (band->isolate_loop_type) {
119
0
    dup->isolate_loop_type = isl_alloc_array(ctx,
120
0
              enum isl_ast_loop_type, band->n);
121
0
    if (band->n && !dup->isolate_loop_type)
122
0
      return isl_schedule_band_free(dup);
123
0
    for (i = 0; i < band->n; ++i)
124
0
      dup->isolate_loop_type[i] = band->isolate_loop_type[i];
125
0
  }
126
1.24k
127
1.24k
  return dup;
128
1.24k
}
129
130
/* Return an isl_schedule_band that is equal to "band" and that has only
131
 * a single reference.
132
 */
133
__isl_give isl_schedule_band *isl_schedule_band_cow(
134
  __isl_take isl_schedule_band *band)
135
1.31k
{
136
1.31k
  if (!band)
137
0
    return NULL;
138
1.31k
139
1.31k
  if (band->ref == 1)
140
70
    return band;
141
1.24k
  band->ref--;
142
1.24k
  return isl_schedule_band_dup(band);
143
1.24k
}
144
145
/* Return a new reference to "band".
146
 */
147
__isl_give isl_schedule_band *isl_schedule_band_copy(
148
  __isl_keep isl_schedule_band *band)
149
3.12k
{
150
3.12k
  if (!band)
151
0
    return NULL;
152
3.12k
153
3.12k
  band->ref++;
154
3.12k
  return band;
155
3.12k
}
156
157
/* Free a reference to "band" and return NULL.
158
 */
159
__isl_null isl_schedule_band *isl_schedule_band_free(
160
  __isl_take isl_schedule_band *band)
161
5.08k
{
162
5.08k
  if (!band)
163
0
    return NULL;
164
5.08k
165
5.08k
  if (--band->ref > 0)
166
1.88k
    return NULL;
167
3.20k
168
3.20k
  isl_multi_union_pw_aff_free(band->mupa);
169
3.20k
  isl_union_set_free(band->ast_build_options);
170
3.20k
  free(band->loop_type);
171
3.20k
  free(band->isolate_loop_type);
172
3.20k
  free(band->coincident);
173
3.20k
  free(band);
174
3.20k
175
3.20k
  return NULL;
176
3.20k
}
177
178
/* Are "band1" and "band2" obviously equal?
179
 */
180
isl_bool isl_schedule_band_plain_is_equal(__isl_keep isl_schedule_band *band1,
181
  __isl_keep isl_schedule_band *band2)
182
0
{
183
0
  int i;
184
0
  isl_bool equal;
185
0
186
0
  if (!band1 || !band2)
187
0
    return isl_bool_error;
188
0
  if (band1 == band2)
189
0
    return isl_bool_true;
190
0
191
0
  if (band1->n != band2->n)
192
0
    return isl_bool_false;
193
0
  for (i = 0; i < band1->n; ++i)
194
0
    if (band1->coincident[i] != band2->coincident[i])
195
0
      return isl_bool_false;
196
0
  if (band1->permutable != band2->permutable)
197
0
    return isl_bool_false;
198
0
199
0
  equal = isl_multi_union_pw_aff_plain_is_equal(band1->mupa, band2->mupa);
200
0
  if (equal < 0 || !equal)
201
0
    return equal;
202
0
203
0
  if (!band1->loop_type != !band2->loop_type)
204
0
    return isl_bool_false;
205
0
  if (band1->loop_type)
206
0
    for (i = 0; i < band1->n; ++i)
207
0
      if (band1->loop_type[i] != band2->loop_type[i])
208
0
        return isl_bool_false;
209
0
210
0
  if (!band1->isolate_loop_type != !band2->isolate_loop_type)
211
0
    return isl_bool_false;
212
0
  if (band1->isolate_loop_type)
213
0
    for (i = 0; i < band1->n; ++i)
214
0
      if (band1->isolate_loop_type[i] !=
215
0
            band2->isolate_loop_type[i])
216
0
        return isl_bool_false;
217
0
218
0
  return isl_union_set_is_equal(band1->ast_build_options,
219
0
          band2->ast_build_options);
220
0
}
221
222
/* Return the number of scheduling dimensions in the band.
223
 */
224
int isl_schedule_band_n_member(__isl_keep isl_schedule_band *band)
225
77.7k
{
226
77.7k
  return band ? band->n : 
00
;
227
77.7k
}
228
229
/* Is the given scheduling dimension coincident within the band and
230
 * with respect to the coincidence constraints?
231
 */
232
isl_bool isl_schedule_band_member_get_coincident(
233
  __isl_keep isl_schedule_band *band, int pos)
234
1.18k
{
235
1.18k
  if (!band)
236
0
    return isl_bool_error;
237
1.18k
238
1.18k
  if (pos < 0 || pos >= band->n)
239
1.18k
    
isl_die0
(isl_schedule_band_get_ctx(band), isl_error_invalid,
240
1.18k
      "invalid member position", return isl_bool_error);
241
1.18k
242
1.18k
  return band->coincident[pos];
243
1.18k
}
244
245
/* Mark the given scheduling dimension as being coincident or not
246
 * according to "coincident".
247
 */
248
__isl_give isl_schedule_band *isl_schedule_band_member_set_coincident(
249
  __isl_take isl_schedule_band *band, int pos, int coincident)
250
188
{
251
188
  if (!band)
252
0
    return NULL;
253
188
  if (isl_schedule_band_member_get_coincident(band, pos) == coincident)
254
0
    return band;
255
188
  band = isl_schedule_band_cow(band);
256
188
  if (!band)
257
0
    return NULL;
258
188
259
188
  if (pos < 0 || pos >= band->n)
260
188
    
isl_die0
(isl_schedule_band_get_ctx(band), isl_error_invalid,
261
188
      "invalid member position",
262
188
      return isl_schedule_band_free(band));
263
188
264
188
  band->coincident[pos] = coincident;
265
188
266
188
  return band;
267
188
}
268
269
/* Is the schedule band mark permutable?
270
 */
271
isl_bool isl_schedule_band_get_permutable(__isl_keep isl_schedule_band *band)
272
798
{
273
798
  if (!band)
274
0
    return isl_bool_error;
275
798
  return band->permutable;
276
798
}
277
278
/* Mark the schedule band permutable or not according to "permutable"?
279
 */
280
__isl_give isl_schedule_band *isl_schedule_band_set_permutable(
281
  __isl_take isl_schedule_band *band, int permutable)
282
142
{
283
142
  if (!band)
284
0
    return NULL;
285
142
  if (band->permutable == permutable)
286
0
    return band;
287
142
  band = isl_schedule_band_cow(band);
288
142
  if (!band)
289
0
    return NULL;
290
142
291
142
  band->permutable = permutable;
292
142
293
142
  return band;
294
142
}
295
296
/* Is the band node "node" anchored?  That is, does it reference
297
 * the outer band nodes?
298
 */
299
int isl_schedule_band_is_anchored(__isl_keep isl_schedule_band *band)
300
4.84k
{
301
4.84k
  return band ? band->anchored : 
-10
;
302
4.84k
}
303
304
/* Return the schedule space of the band.
305
 */
306
__isl_give isl_space *isl_schedule_band_get_space(
307
  __isl_keep isl_schedule_band *band)
308
2.66k
{
309
2.66k
  if (!band)
310
0
    return NULL;
311
2.66k
  return isl_multi_union_pw_aff_get_space(band->mupa);
312
2.66k
}
313
314
/* Intersect the domain of the band schedule of "band" with "domain".
315
 */
316
__isl_give isl_schedule_band *isl_schedule_band_intersect_domain(
317
  __isl_take isl_schedule_band *band, __isl_take isl_union_set *domain)
318
2
{
319
2
  band = isl_schedule_band_cow(band);
320
2
  if (!band || !domain)
321
0
    goto error;
322
2
323
2
  band->mupa = isl_multi_union_pw_aff_intersect_domain(band->mupa,
324
2
                domain);
325
2
  if (!band->mupa)
326
0
    return isl_schedule_band_free(band);
327
2
328
2
  return band;
329
0
error:
330
0
  isl_schedule_band_free(band);
331
0
  isl_union_set_free(domain);
332
0
  return NULL;
333
2
}
334
335
/* Return the schedule of the band in isolation.
336
 */
337
__isl_give isl_multi_union_pw_aff *isl_schedule_band_get_partial_schedule(
338
  __isl_keep isl_schedule_band *band)
339
12.1k
{
340
12.1k
  return band ? isl_multi_union_pw_aff_copy(band->mupa) : NULL;
341
12.1k
}
342
343
/* Replace the schedule of "band" by "schedule".
344
 */
345
__isl_give isl_schedule_band *isl_schedule_band_set_partial_schedule(
346
  __isl_take isl_schedule_band *band,
347
  __isl_take isl_multi_union_pw_aff *schedule)
348
2
{
349
2
  band = isl_schedule_band_cow(band);
350
2
  if (!band || !schedule)
351
0
    goto error;
352
2
353
2
  isl_multi_union_pw_aff_free(band->mupa);
354
2
  band->mupa = schedule;
355
2
356
2
  return band;
357
0
error:
358
0
  isl_schedule_band_free(band);
359
0
  isl_multi_union_pw_aff_free(schedule);
360
0
  return NULL;
361
2
}
362
363
/* Return the loop AST generation type for the band member of "band"
364
 * at position "pos".
365
 */
366
enum isl_ast_loop_type isl_schedule_band_member_get_ast_loop_type(
367
  __isl_keep isl_schedule_band *band, int pos)
368
795
{
369
795
  if (!band)
370
0
    return isl_ast_loop_error;
371
795
372
795
  if (pos < 0 || pos >= band->n)
373
795
    
isl_die0
(isl_schedule_band_get_ctx(band), isl_error_invalid,
374
795
      "invalid member position", return -1);
375
795
376
795
  if (!band->loop_type)
377
686
    return isl_ast_loop_default;
378
109
379
109
  return band->loop_type[pos];
380
109
}
381
382
/* Set the loop AST generation type for the band member of "band"
383
 * at position "pos" to "type".
384
 */
385
__isl_give isl_schedule_band *isl_schedule_band_member_set_ast_loop_type(
386
  __isl_take isl_schedule_band *band, int pos,
387
  enum isl_ast_loop_type type)
388
0
{
389
0
  if (!band)
390
0
    return NULL;
391
0
  if (isl_schedule_band_member_get_ast_loop_type(band, pos) == type)
392
0
    return band;
393
0
394
0
  if (pos < 0 || pos >= band->n)
395
0
    isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid,
396
0
      "invalid member position",
397
0
      return isl_schedule_band_free(band));
398
0
399
0
  band = isl_schedule_band_cow(band);
400
0
  if (!band)
401
0
    return isl_schedule_band_free(band);
402
0
403
0
  if (!band->loop_type) {
404
0
    isl_ctx *ctx;
405
0
406
0
    ctx = isl_schedule_band_get_ctx(band);
407
0
    band->loop_type = isl_calloc_array(ctx,
408
0
              enum isl_ast_loop_type, band->n);
409
0
    if (band->n && !band->loop_type)
410
0
      return isl_schedule_band_free(band);
411
0
  }
412
0
413
0
  band->loop_type[pos] = type;
414
0
415
0
  return band;
416
0
}
417
418
/* Return the loop AST generation type for the band member of "band"
419
 * at position "pos" for the part that has been isolated by the isolate option.
420
 */
421
enum isl_ast_loop_type isl_schedule_band_member_get_isolate_ast_loop_type(
422
  __isl_keep isl_schedule_band *band, int pos)
423
913
{
424
913
  if (!band)
425
0
    return isl_ast_loop_error;
426
913
427
913
  if (pos < 0 || pos >= band->n)
428
913
    
isl_die0
(isl_schedule_band_get_ctx(band), isl_error_invalid,
429
913
      "invalid member position", return -1);
430
913
431
913
  if (!band->isolate_loop_type)
432
46
    return isl_ast_loop_default;
433
867
434
867
  return band->isolate_loop_type[pos];
435
867
}
436
437
/* Set the loop AST generation type for the band member of "band"
438
 * at position "pos" to "type" for the part that has been isolated
439
 * by the isolate option.
440
 */
441
__isl_give isl_schedule_band *
442
isl_schedule_band_member_set_isolate_ast_loop_type(
443
  __isl_take isl_schedule_band *band, int pos,
444
  enum isl_ast_loop_type type)
445
0
{
446
0
  if (!band)
447
0
    return NULL;
448
0
  if (isl_schedule_band_member_get_isolate_ast_loop_type(band, pos) ==
449
0
                  type)
450
0
    return band;
451
0
452
0
  if (pos < 0 || pos >= band->n)
453
0
    isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid,
454
0
      "invalid member position",
455
0
      return isl_schedule_band_free(band));
456
0
457
0
  band = isl_schedule_band_cow(band);
458
0
  if (!band)
459
0
    return isl_schedule_band_free(band);
460
0
461
0
  if (!band->isolate_loop_type) {
462
0
    isl_ctx *ctx;
463
0
464
0
    ctx = isl_schedule_band_get_ctx(band);
465
0
    band->isolate_loop_type = isl_calloc_array(ctx,
466
0
              enum isl_ast_loop_type, band->n);
467
0
    if (band->n && !band->isolate_loop_type)
468
0
      return isl_schedule_band_free(band);
469
0
  }
470
0
471
0
  band->isolate_loop_type[pos] = type;
472
0
473
0
  return band;
474
0
}
475
476
static const char *option_str[] = {
477
  [isl_ast_loop_atomic] = "atomic",
478
  [isl_ast_loop_unroll] = "unroll",
479
  [isl_ast_loop_separate] = "separate"
480
};
481
482
/* Given a parameter space "space", extend it to a set space
483
 *
484
 *  { type[x] }
485
 *
486
 * or
487
 *
488
 *  { [isolate[] -> type[x]] }
489
 *
490
 * depending on whether "isolate" is set.
491
 * These can be used to encode loop AST generation options of the given type.
492
 */
493
static __isl_give isl_space *loop_type_space(__isl_take isl_space *space,
494
  enum isl_ast_loop_type type, int isolate)
495
714
{
496
714
  const char *name;
497
714
498
714
  name = option_str[type];
499
714
  space = isl_space_set_from_params(space);
500
714
  space = isl_space_add_dims(space, isl_dim_set, 1);
501
714
  space = isl_space_set_tuple_name(space, isl_dim_set, name);
502
714
  if (!isolate)
503
570
    return space;
504
144
  space = isl_space_from_range(space);
505
144
  space = isl_space_set_tuple_name(space, isl_dim_in, "isolate");
506
144
  space = isl_space_wrap(space);
507
144
508
144
  return space;
509
144
}
510
511
/* Add encodings of the "n" loop AST generation options "type" to "options".
512
 * If "isolate" is set, then these options refer to the isolated part.
513
 *
514
 * In particular, for each sequence of consecutive identical types "t",
515
 * different from the default, add an option
516
 *
517
 *  { t[x] : first <= x <= last }
518
 *
519
 * or
520
 *
521
 *  { [isolate[] -> t[x]] : first <= x <= last }
522
 */
523
static __isl_give isl_union_set *add_loop_types(
524
  __isl_take isl_union_set *options, int n, enum isl_ast_loop_type *type,
525
  int isolate)
526
0
{
527
0
  int i;
528
0
529
0
  if (!type)
530
0
    return options;
531
0
  if (!options)
532
0
    return NULL;
533
0
534
0
  for (i = 0; i < n; ++i) {
535
0
    int first;
536
0
    isl_space *space;
537
0
    isl_set *option;
538
0
539
0
    if (type[i] == isl_ast_loop_default)
540
0
      continue;
541
0
542
0
    first = i;
543
0
    while (i + 1 < n && type[i + 1] == type[i])
544
0
      ++i;
545
0
546
0
    space = isl_union_set_get_space(options);
547
0
    space = loop_type_space(space, type[i], isolate);
548
0
    option = isl_set_universe(space);
549
0
    option = isl_set_lower_bound_si(option, isl_dim_set, 0, first);
550
0
    option = isl_set_upper_bound_si(option, isl_dim_set, 0, i);
551
0
    options = isl_union_set_add_set(options, option);
552
0
  }
553
0
554
0
  return options;
555
0
}
556
557
/* Return the AST build options associated to "band".
558
 */
559
__isl_give isl_union_set *isl_schedule_band_get_ast_build_options(
560
  __isl_keep isl_schedule_band *band)
561
0
{
562
0
  isl_union_set *options;
563
0
564
0
  if (!band)
565
0
    return NULL;
566
0
567
0
  options = isl_union_set_copy(band->ast_build_options);
568
0
  options = add_loop_types(options, band->n, band->loop_type, 0);
569
0
  options = add_loop_types(options, band->n, band->isolate_loop_type, 1);
570
0
571
0
  return options;
572
0
}
573
574
/* Does "uset" contain any set that satisfies "is"?
575
 * "is" is assumed to set its integer argument to 1 if it is satisfied.
576
 */
577
static int has_any(__isl_keep isl_union_set *uset,
578
  isl_stat (*is)(__isl_take isl_set *set, void *user))
579
216
{
580
216
  int found = 0;
581
216
582
216
  if (isl_union_set_foreach_set(uset, is, &found) < 0 && 
!found108
)
583
0
    return -1;
584
216
585
216
  return found;
586
216
}
587
588
/* Does "set" live in a space of the form
589
 *
590
 *  isolate[[...] -> [...]]
591
 *
592
 * ?
593
 *
594
 * If so, set *found and abort the search.
595
 */
596
static isl_stat is_isolate(__isl_take isl_set *set, void *user)
597
69
{
598
69
  int *found = user;
599
69
600
69
  if (isl_set_has_tuple_name(set)) {
601
58
    const char *name;
602
58
    name = isl_set_get_tuple_name(set);
603
58
    if (isl_set_is_wrapping(set) && 
!strcmp(name, "isolate")40
)
604
40
      *found = 1;
605
58
  }
606
69
  isl_set_free(set);
607
69
608
69
  return *found ? 
isl_stat_error40
:
isl_stat_ok29
;
609
69
}
610
611
/* Does "options" include an option of the ofrm
612
 *
613
 *  isolate[[...] -> [...]]
614
 *
615
 * ?
616
 */
617
static int has_isolate_option(__isl_keep isl_union_set *options)
618
72
{
619
72
  return has_any(options, &is_isolate);
620
72
}
621
622
/* Does "set" encode a loop AST generation option?
623
 */
624
static isl_stat is_loop_type_option(__isl_take isl_set *set, void *user)
625
105
{
626
105
  int *found = user;
627
105
628
105
  if (isl_set_dim(set, isl_dim_set) == 1 &&
629
105
      
isl_set_has_tuple_name(set)67
) {
630
56
    const char *name;
631
56
    enum isl_ast_loop_type type;
632
56
    name = isl_set_get_tuple_name(set);
633
56
    for (type = isl_ast_loop_atomic;
634
108
        type <= isl_ast_loop_separate; 
++type52
) {
635
108
      if (strcmp(name, option_str[type]))
636
52
        continue;
637
56
      *found = 1;
638
56
      break;
639
56
    }
640
56
  }
641
105
  isl_set_free(set);
642
105
643
105
  return *found ? 
isl_stat_error56
:
isl_stat_ok49
;
644
105
}
645
646
/* Does "set" encode a loop AST generation option for the isolated part?
647
 * That is, is of the form
648
 *
649
 *  { [isolate[] -> t[x]] }
650
 *
651
 * with t equal to "atomic", "unroll" or "separate"?
652
 */
653
static isl_stat is_isolate_loop_type_option(__isl_take isl_set *set, void *user)
654
86
{
655
86
  int *found = user;
656
86
  const char *name;
657
86
  enum isl_ast_loop_type type;
658
86
  isl_map *map;
659
86
660
86
  if (!isl_set_is_wrapping(set)) {
661
45
    isl_set_free(set);
662
45
    return isl_stat_ok;
663
45
  }
664
41
  map = isl_set_unwrap(set);
665
41
  if (!isl_map_has_tuple_name(map, isl_dim_in) ||
666
41
      
!isl_map_has_tuple_name(map, isl_dim_out)12
) {
667
29
    isl_map_free(map);
668
29
    return isl_stat_ok;
669
29
  }
670
12
  name = isl_map_get_tuple_name(map, isl_dim_in);
671
12
  if (!strcmp(name, "isolate")) {
672
12
    name = isl_map_get_tuple_name(map, isl_dim_out);
673
12
    for (type = isl_ast_loop_atomic;
674
24
        type <= isl_ast_loop_separate; 
++type12
) {
675
24
      if (strcmp(name, option_str[type]))
676
12
        continue;
677
12
      *found = 1;
678
12
      break;
679
12
    }
680
12
  }
681
12
  isl_map_free(map);
682
12
683
12
  return *found ? isl_stat_error : 
isl_stat_ok0
;
684
12
}
685
686
/* Does "options" encode any loop AST generation options
687
 * for the isolated part?
688
 */
689
static int has_isolate_loop_type_options(__isl_keep isl_union_set *options)
690
72
{
691
72
  return has_any(options, &is_isolate_loop_type_option);
692
72
}
693
694
/* Does "options" encode any loop AST generation options?
695
 */
696
static int has_loop_type_options(__isl_keep isl_union_set *options)
697
72
{
698
72
  return has_any(options, &is_loop_type_option);
699
72
}
700
701
/* Extract the loop AST generation type for the band member
702
 * at position "pos" from "options".
703
 * If "isolate" is set, then extract the loop types for the isolated part.
704
 */
705
static enum isl_ast_loop_type extract_loop_type(
706
  __isl_keep isl_union_set *options, int pos, int isolate)
707
170
{
708
170
  isl_ctx *ctx;
709
170
  enum isl_ast_loop_type type, res = isl_ast_loop_default;
710
170
711
170
  ctx = isl_union_set_get_ctx(options);
712
170
  for (type = isl_ast_loop_atomic;
713
680
      type <= isl_ast_loop_separate; 
++type510
) {
714
510
    isl_space *space;
715
510
    isl_set *option;
716
510
    int empty;
717
510
718
510
    space = isl_union_set_get_space(options);
719
510
    space = loop_type_space(space, type, isolate);
720
510
    option = isl_union_set_extract_set(options, space);
721
510
    option = isl_set_fix_si(option, isl_dim_set, 0, pos);
722
510
    empty = isl_set_is_empty(option);
723
510
    isl_set_free(option);
724
510
725
510
    if (empty < 0)
726
0
      return isl_ast_loop_error;
727
510
    if (empty)
728
340
      continue;
729
170
    if (res != isl_ast_loop_default)
730
170
      
isl_die0
(ctx, isl_error_invalid,
731
170
        "conflicting loop type options",
732
170
        return isl_ast_loop_error);
733
170
    res = type;
734
170
  }
735
170
736
170
  return res;
737
170
}
738
739
/* Extract the loop AST generation types for the members of "band"
740
 * from "options" and store them in band->loop_type.
741
 * Return -1 on error.
742
 */
743
static int extract_loop_types(__isl_keep isl_schedule_band *band,
744
  __isl_keep isl_union_set *options)
745
56
{
746
56
  int i;
747
56
748
56
  if (!band->loop_type) {
749
43
    isl_ctx *ctx = isl_schedule_band_get_ctx(band);
750
43
    band->loop_type = isl_alloc_array(ctx,
751
43
              enum isl_ast_loop_type, band->n);
752
43
    if (band->n && !band->loop_type)
753
0
      return -1;
754
56
  }
755
190
  
for (i = 0; 56
i < band->n;
++i134
) {
756
134
    band->loop_type[i] = extract_loop_type(options, i, 0);
757
134
    if (band->loop_type[i] == isl_ast_loop_error)
758
0
      return -1;
759
134
  }
760
56
761
56
  return 0;
762
56
}
763
764
/* Extract the loop AST generation types for the members of "band"
765
 * from "options" for the isolated part and
766
 * store them in band->isolate_loop_type.
767
 * Return -1 on error.
768
 */
769
static int extract_isolate_loop_types(__isl_keep isl_schedule_band *band,
770
  __isl_keep isl_union_set *options)
771
12
{
772
12
  int i;
773
12
774
12
  if (!band->isolate_loop_type) {
775
12
    isl_ctx *ctx = isl_schedule_band_get_ctx(band);
776
12
    band->isolate_loop_type = isl_alloc_array(ctx,
777
12
              enum isl_ast_loop_type, band->n);
778
12
    if (band->n && !band->isolate_loop_type)
779
0
      return -1;
780
12
  }
781
48
  
for (i = 0; 12
i < band->n;
++i36
) {
782
36
    band->isolate_loop_type[i] = extract_loop_type(options, i, 1);
783
36
    if (band->isolate_loop_type[i] == isl_ast_loop_error)
784
0
      return -1;
785
36
  }
786
12
787
12
  return 0;
788
12
}
789
790
/* Construct universe sets of the spaces that encode loop AST generation
791
 * types (for the isolated part if "isolate" is set).  That is, construct
792
 *
793
 *  { atomic[x]; separate[x]; unroll[x] }
794
 *
795
 * or
796
 *
797
 *  { [isolate[] -> atomic[x]]; [isolate[] -> separate[x]];
798
 *    [isolate[] -> unroll[x]] }
799
 */
800
static __isl_give isl_union_set *loop_types(__isl_take isl_space *space,
801
  int isolate)
802
68
{
803
68
  enum isl_ast_loop_type type;
804
68
  isl_union_set *types;
805
68
806
68
  types = isl_union_set_empty(space);
807
68
  for (type = isl_ast_loop_atomic;
808
272
      type <= isl_ast_loop_separate; 
++type204
) {
809
204
    isl_set *set;
810
204
811
204
    space = isl_union_set_get_space(types);
812
204
    space = loop_type_space(space, type, isolate);
813
204
    set = isl_set_universe(space);
814
204
    types = isl_union_set_add_set(types, set);
815
204
  }
816
68
817
68
  return types;
818
68
}
819
820
/* Remove all elements from spaces that encode loop AST generation types
821
 * from "options".
822
 */
823
static __isl_give isl_union_set *clear_loop_types(
824
  __isl_take isl_union_set *options)
825
56
{
826
56
  isl_union_set *types;
827
56
828
56
  types = loop_types(isl_union_set_get_space(options), 0);
829
56
  options = isl_union_set_subtract(options, types);
830
56
831
56
  return options;
832
56
}
833
834
/* Remove all elements from spaces that encode loop AST generation types
835
 * for the isolated part from "options".
836
 */
837
static __isl_give isl_union_set *clear_isolate_loop_types(
838
  __isl_take isl_union_set *options)
839
12
{
840
12
  isl_union_set *types;
841
12
842
12
  types = loop_types(isl_union_set_get_space(options), 1);
843
12
  options = isl_union_set_subtract(options, types);
844
12
845
12
  return options;
846
12
}
847
848
/* Replace the AST build options associated to "band" by "options".
849
 * If there are any loop AST generation type options, then they
850
 * are extracted and stored in band->loop_type.  Otherwise,
851
 * band->loop_type is removed to indicate that the default applies
852
 * to all members.  Similarly for the loop AST generation type options
853
 * for the isolated part, which are stored in band->isolate_loop_type.
854
 * The remaining options are stored in band->ast_build_options.
855
 *
856
 * Set anchored if the options include an isolate option since the
857
 * domain of the wrapped map references the outer band node schedules.
858
 */
859
__isl_give isl_schedule_band *isl_schedule_band_set_ast_build_options(
860
  __isl_take isl_schedule_band *band, __isl_take isl_union_set *options)
861
72
{
862
72
  int has_isolate, has_loop_type, has_isolate_loop_type;
863
72
864
72
  band = isl_schedule_band_cow(band);
865
72
  if (!band || !options)
866
0
    goto error;
867
72
  has_isolate = has_isolate_option(options);
868
72
  if (has_isolate < 0)
869
0
    goto error;
870
72
  has_loop_type = has_loop_type_options(options);
871
72
  if (has_loop_type < 0)
872
0
    goto error;
873
72
  has_isolate_loop_type = has_isolate_loop_type_options(options);
874
72
  if (has_isolate_loop_type < 0)
875
0
    goto error;
876
72
877
72
  if (!has_loop_type) {
878
16
    free(band->loop_type);
879
16
    band->loop_type = NULL;
880
56
  } else {
881
56
    if (extract_loop_types(band, options) < 0)
882
0
      goto error;
883
56
    options = clear_loop_types(options);
884
56
    if (!options)
885
0
      goto error;
886
72
  }
887
72
888
72
  if (!has_isolate_loop_type) {
889
60
    free(band->isolate_loop_type);
890
60
    band->isolate_loop_type = NULL;
891
60
  } else {
892
12
    if (extract_isolate_loop_types(band, options) < 0)
893
0
      goto error;
894
12
    options = clear_isolate_loop_types(options);
895
12
    if (!options)
896
0
      goto error;
897
72
  }
898
72
899
72
  isl_union_set_free(band->ast_build_options);
900
72
  band->ast_build_options = options;
901
72
  band->anchored = has_isolate;
902
72
903
72
  return band;
904
0
error:
905
0
  isl_schedule_band_free(band);
906
0
  isl_union_set_free(options);
907
0
  return NULL;
908
72
}
909
910
/* Return the "isolate" option associated to "band", assuming
911
 * it at appears at schedule depth "depth".
912
 *
913
 * The isolate option is of the form
914
 *
915
 *  isolate[[flattened outer bands] -> band]
916
 */
917
__isl_give isl_set *isl_schedule_band_get_ast_isolate_option(
918
  __isl_keep isl_schedule_band *band, int depth)
919
2.36k
{
920
2.36k
  isl_space *space;
921
2.36k
  isl_set *isolate;
922
2.36k
923
2.36k
  if (!band)
924
0
    return NULL;
925
2.36k
926
2.36k
  space = isl_schedule_band_get_space(band);
927
2.36k
  space = isl_space_from_range(space);
928
2.36k
  space = isl_space_add_dims(space, isl_dim_in, depth);
929
2.36k
  space = isl_space_wrap(space);
930
2.36k
  space = isl_space_set_tuple_name(space, isl_dim_set, "isolate");
931
2.36k
932
2.36k
  isolate = isl_union_set_extract_set(band->ast_build_options, space);
933
2.36k
934
2.36k
  return isolate;
935
2.36k
}
936
937
/* Replace the option "drop" in the AST build options by "add".
938
 * That is, remove "drop" and add "add".
939
 */
940
__isl_give isl_schedule_band *isl_schedule_band_replace_ast_build_option(
941
  __isl_take isl_schedule_band *band, __isl_take isl_set *drop,
942
  __isl_take isl_set *add)
943
68
{
944
68
  isl_union_set *options;
945
68
946
68
  band = isl_schedule_band_cow(band);
947
68
  if (!band)
948
0
    goto error;
949
68
950
68
  options = band->ast_build_options;
951
68
  options = isl_union_set_subtract(options, isl_union_set_from_set(drop));
952
68
  options = isl_union_set_union(options, isl_union_set_from_set(add));
953
68
  band->ast_build_options = options;
954
68
955
68
  if (!band->ast_build_options)
956
0
    return isl_schedule_band_free(band);
957
68
958
68
  return band;
959
0
error:
960
0
  isl_schedule_band_free(band);
961
0
  isl_set_free(drop);
962
0
  isl_set_free(add);
963
0
  return NULL;
964
68
}
965
966
/* Multiply the partial schedule of "band" with the factors in "mv".
967
 * Replace the result by its greatest integer part to ensure
968
 * that the schedule is always integral.
969
 */
970
__isl_give isl_schedule_band *isl_schedule_band_scale(
971
  __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv)
972
0
{
973
0
  band = isl_schedule_band_cow(band);
974
0
  if (!band || !mv)
975
0
    goto error;
976
0
  band->mupa = isl_multi_union_pw_aff_scale_multi_val(band->mupa, mv);
977
0
  band->mupa = isl_multi_union_pw_aff_floor(band->mupa);
978
0
  if (!band->mupa)
979
0
    return isl_schedule_band_free(band);
980
0
  return band;
981
0
error:
982
0
  isl_schedule_band_free(band);
983
0
  isl_multi_val_free(mv);
984
0
  return NULL;
985
0
}
986
987
/* Divide the partial schedule of "band" by the factors in "mv".
988
 * Replace the result by its greatest integer part to ensure
989
 * that the schedule is always integral.
990
 */
991
__isl_give isl_schedule_band *isl_schedule_band_scale_down(
992
  __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv)
993
0
{
994
0
  band = isl_schedule_band_cow(band);
995
0
  if (!band || !mv)
996
0
    goto error;
997
0
  band->mupa = isl_multi_union_pw_aff_scale_down_multi_val(band->mupa,
998
0
                mv);
999
0
  band->mupa = isl_multi_union_pw_aff_floor(band->mupa);
1000
0
  if (!band->mupa)
1001
0
    return isl_schedule_band_free(band);
1002
0
  return band;
1003
0
error:
1004
0
  isl_schedule_band_free(band);
1005
0
  isl_multi_val_free(mv);
1006
0
  return NULL;
1007
0
}
1008
1009
/* Reduce the partial schedule of "band" modulo the factors in "mv".
1010
 */
1011
__isl_give isl_schedule_band *isl_schedule_band_mod(
1012
  __isl_take isl_schedule_band *band, __isl_take isl_multi_val *mv)
1013
0
{
1014
0
  band = isl_schedule_band_cow(band);
1015
0
  if (!band || !mv)
1016
0
    goto error;
1017
0
  band->mupa = isl_multi_union_pw_aff_mod_multi_val(band->mupa, mv);
1018
0
  if (!band->mupa)
1019
0
    return isl_schedule_band_free(band);
1020
0
  return band;
1021
0
error:
1022
0
  isl_schedule_band_free(band);
1023
0
  isl_multi_val_free(mv);
1024
0
  return NULL;
1025
0
}
1026
1027
/* Shift the partial schedule of "band" by "shift" after checking
1028
 * that the domain of the partial schedule would not be affected
1029
 * by this shift.
1030
 */
1031
__isl_give isl_schedule_band *isl_schedule_band_shift(
1032
  __isl_take isl_schedule_band *band,
1033
  __isl_take isl_multi_union_pw_aff *shift)
1034
0
{
1035
0
  isl_union_set *dom1, *dom2;
1036
0
  isl_bool subset;
1037
0
1038
0
  band = isl_schedule_band_cow(band);
1039
0
  if (!band || !shift)
1040
0
    goto error;
1041
0
  dom1 = isl_multi_union_pw_aff_domain(
1042
0
        isl_multi_union_pw_aff_copy(band->mupa));
1043
0
  dom2 = isl_multi_union_pw_aff_domain(
1044
0
        isl_multi_union_pw_aff_copy(shift));
1045
0
  subset = isl_union_set_is_subset(dom1, dom2);
1046
0
  isl_union_set_free(dom1);
1047
0
  isl_union_set_free(dom2);
1048
0
  if (subset < 0)
1049
0
    goto error;
1050
0
  if (!subset)
1051
0
    isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid,
1052
0
      "domain of shift needs to include domain of "
1053
0
      "partial schedule", goto error);
1054
0
  band->mupa = isl_multi_union_pw_aff_add(band->mupa, shift);
1055
0
  if (!band->mupa)
1056
0
    return isl_schedule_band_free(band);
1057
0
  return band;
1058
0
error:
1059
0
  isl_schedule_band_free(band);
1060
0
  isl_multi_union_pw_aff_free(shift);
1061
0
  return NULL;
1062
0
}
1063
1064
/* Given the schedule of a band, construct the corresponding
1065
 * schedule for the tile loops based on the given tile sizes
1066
 * and return the result.
1067
 *
1068
 * If the scale tile loops options is set, then the tile loops
1069
 * are scaled by the tile sizes.
1070
 *
1071
 * That is replace each schedule dimension "i" by either
1072
 * "floor(i/s)" or "s * floor(i/s)".
1073
 */
1074
static isl_multi_union_pw_aff *isl_multi_union_pw_aff_tile(
1075
  __isl_take isl_multi_union_pw_aff *sched,
1076
  __isl_take isl_multi_val *sizes)
1077
78
{
1078
78
  isl_ctx *ctx;
1079
78
  int i, n;
1080
78
  isl_val *v;
1081
78
  int scale;
1082
78
1083
78
  ctx = isl_multi_val_get_ctx(sizes);
1084
78
  scale = isl_options_get_tile_scale_tile_loops(ctx);
1085
78
1086
78
  n = isl_multi_union_pw_aff_dim(sched, isl_dim_set);
1087
250
  for (i = 0; i < n; 
++i172
) {
1088
172
    isl_union_pw_aff *upa;
1089
172
1090
172
    upa = isl_multi_union_pw_aff_get_union_pw_aff(sched, i);
1091
172
    v = isl_multi_val_get_val(sizes, i);
1092
172
1093
172
    upa = isl_union_pw_aff_scale_down_val(upa, isl_val_copy(v));
1094
172
    upa = isl_union_pw_aff_floor(upa);
1095
172
    if (scale)
1096
4
      upa = isl_union_pw_aff_scale_val(upa, isl_val_copy(v));
1097
172
    isl_val_free(v);
1098
172
1099
172
    sched = isl_multi_union_pw_aff_set_union_pw_aff(sched, i, upa);
1100
172
  }
1101
78
1102
78
  isl_multi_val_free(sizes);
1103
78
  return sched;
1104
78
}
1105
1106
/* Replace "band" by a band corresponding to the tile loops of a tiling
1107
 * with the given tile sizes.
1108
 */
1109
__isl_give isl_schedule_band *isl_schedule_band_tile(
1110
  __isl_take isl_schedule_band *band, __isl_take isl_multi_val *sizes)
1111
78
{
1112
78
  band = isl_schedule_band_cow(band);
1113
78
  if (!band || !sizes)
1114
0
    goto error;
1115
78
  band->mupa = isl_multi_union_pw_aff_tile(band->mupa, sizes);
1116
78
  if (!band->mupa)
1117
0
    return isl_schedule_band_free(band);
1118
78
  return band;
1119
0
error:
1120
0
  isl_schedule_band_free(band);
1121
0
  isl_multi_val_free(sizes);
1122
0
  return NULL;
1123
78
}
1124
1125
/* Replace "band" by a band corresponding to the point loops of a tiling
1126
 * with the given tile sizes.
1127
 * "tile" is the corresponding tile loop band.
1128
 *
1129
 * If the shift point loops option is set, then the point loops
1130
 * are shifted to start at zero.  That is, each schedule dimension "i"
1131
 * is replaced by "i - s * floor(i/s)".
1132
 * The expression "floor(i/s)" (or "s * floor(i/s)") is extracted from
1133
 * the tile band.
1134
 *
1135
 * Otherwise, the band is left untouched.
1136
 */
1137
__isl_give isl_schedule_band *isl_schedule_band_point(
1138
  __isl_take isl_schedule_band *band, __isl_keep isl_schedule_band *tile,
1139
  __isl_take isl_multi_val *sizes)
1140
78
{
1141
78
  isl_ctx *ctx;
1142
78
  isl_multi_union_pw_aff *scaled;
1143
78
1144
78
  if (!band || !sizes)
1145
0
    goto error;
1146
78
1147
78
  ctx = isl_schedule_band_get_ctx(band);
1148
78
  if (!isl_options_get_tile_shift_point_loops(ctx)) {
1149
2
    isl_multi_val_free(sizes);
1150
2
    return band;
1151
2
  }
1152
76
  band = isl_schedule_band_cow(band);
1153
76
  if (!band)
1154
0
    goto error;
1155
76
1156
76
  scaled = isl_schedule_band_get_partial_schedule(tile);
1157
76
  if (!isl_options_get_tile_scale_tile_loops(ctx))
1158
75
    scaled = isl_multi_union_pw_aff_scale_multi_val(scaled, sizes);
1159
1
  else
1160
1
    isl_multi_val_free(sizes);
1161
76
  band->mupa = isl_multi_union_pw_aff_sub(band->mupa, scaled);
1162
76
  if (!band->mupa)
1163
0
    return isl_schedule_band_free(band);
1164
76
  return band;
1165
0
error:
1166
0
  isl_schedule_band_free(band);
1167
0
  isl_multi_val_free(sizes);
1168
0
  return NULL;
1169
76
}
1170
1171
/* Drop the "n" dimensions starting at "pos" from "band".
1172
 *
1173
 * We apply the transformation even if "n" is zero to ensure consistent
1174
 * behavior with respect to changes in the schedule space.
1175
 *
1176
 * The caller is responsible for updating the isolate option.
1177
 */
1178
__isl_give isl_schedule_band *isl_schedule_band_drop(
1179
  __isl_take isl_schedule_band *band, int pos, int n)
1180
68
{
1181
68
  int i;
1182
68
1183
68
  if (pos < 0 || n < 0 || pos + n > band->n)
1184
68
    
isl_die0
(isl_schedule_band_get_ctx(band), isl_error_internal,
1185
68
      "range out of bounds",
1186
68
      return isl_schedule_band_free(band));
1187
68
1188
68
  band = isl_schedule_band_cow(band);
1189
68
  if (!band)
1190
0
    return NULL;
1191
68
1192
68
  band->mupa = isl_multi_union_pw_aff_drop_dims(band->mupa,
1193
68
              isl_dim_set, pos, n);
1194
68
  if (!band->mupa)
1195
0
    return isl_schedule_band_free(band);
1196
68
1197
108
  
for (i = pos + n; 68
i < band->n;
++i40
)
1198
40
    band->coincident[i - n] = band->coincident[i];
1199
68
  if (band->loop_type)
1200
3
    
for (i = pos + n; 2
i < band->n;
++i1
)
1201
1
      band->loop_type[i - n] = band->loop_type[i];
1202
68
  if (band->isolate_loop_type)
1203
0
    for (i = pos + n; i < band->n; ++i)
1204
0
      band->isolate_loop_type[i - n] =
1205
0
                band->isolate_loop_type[i];
1206
68
1207
68
  band->n -= n;
1208
68
1209
68
  return band;
1210
68
}
1211
1212
/* Reset the user pointer on all identifiers of parameters and tuples
1213
 * in "band".
1214
 */
1215
__isl_give isl_schedule_band *isl_schedule_band_reset_user(
1216
  __isl_take isl_schedule_band *band)
1217
0
{
1218
0
  band = isl_schedule_band_cow(band);
1219
0
  if (!band)
1220
0
    return NULL;
1221
0
1222
0
  band->mupa = isl_multi_union_pw_aff_reset_user(band->mupa);
1223
0
  band->ast_build_options =
1224
0
    isl_union_set_reset_user(band->ast_build_options);
1225
0
  if (!band->mupa || !band->ast_build_options)
1226
0
    return isl_schedule_band_free(band);
1227
0
1228
0
  return band;
1229
0
}
1230
1231
/* Align the parameters of "band" to those of "space".
1232
 */
1233
__isl_give isl_schedule_band *isl_schedule_band_align_params(
1234
  __isl_take isl_schedule_band *band, __isl_take isl_space *space)
1235
0
{
1236
0
  band = isl_schedule_band_cow(band);
1237
0
  if (!band || !space)
1238
0
    goto error;
1239
0
1240
0
  band->mupa = isl_multi_union_pw_aff_align_params(band->mupa,
1241
0
            isl_space_copy(space));
1242
0
  band->ast_build_options =
1243
0
    isl_union_set_align_params(band->ast_build_options, space);
1244
0
  if (!band->mupa || !band->ast_build_options)
1245
0
    return isl_schedule_band_free(band);
1246
0
1247
0
  return band;
1248
0
error:
1249
0
  isl_space_free(space);
1250
0
  isl_schedule_band_free(band);
1251
0
  return NULL;
1252
0
}
1253
1254
/* Compute the pullback of "band" by the function represented by "upma".
1255
 * In other words, plug in "upma" in the iteration domains of "band".
1256
 */
1257
__isl_give isl_schedule_band *isl_schedule_band_pullback_union_pw_multi_aff(
1258
  __isl_take isl_schedule_band *band,
1259
  __isl_take isl_union_pw_multi_aff *upma)
1260
322
{
1261
322
  band = isl_schedule_band_cow(band);
1262
322
  if (!band || !upma)
1263
0
    goto error;
1264
322
1265
322
  band->mupa =
1266
322
    isl_multi_union_pw_aff_pullback_union_pw_multi_aff(band->mupa,
1267
322
                  upma);
1268
322
  if (!band->mupa)
1269
0
    return isl_schedule_band_free(band);
1270
322
1271
322
  return band;
1272
0
error:
1273
0
  isl_union_pw_multi_aff_free(upma);
1274
0
  isl_schedule_band_free(band);
1275
0
  return NULL;
1276
322
}
1277
1278
/* Compute the gist of "band" with respect to "context".
1279
 * In particular, compute the gist of the associated partial schedule.
1280
 */
1281
__isl_give isl_schedule_band *isl_schedule_band_gist(
1282
  __isl_take isl_schedule_band *band, __isl_take isl_union_set *context)
1283
292
{
1284
292
  if (!band || !context)
1285
0
    goto error;
1286
292
  if (band->n == 0) {
1287
0
    isl_union_set_free(context);
1288
0
    return band;
1289
0
  }
1290
292
  band = isl_schedule_band_cow(band);
1291
292
  if (!band)
1292
0
    goto error;
1293
292
  band->mupa = isl_multi_union_pw_aff_gist(band->mupa, context);
1294
292
  if (!band->mupa)
1295
0
    return isl_schedule_band_free(band);
1296
292
  return band;
1297
0
error:
1298
0
  isl_union_set_free(context);
1299
0
  isl_schedule_band_free(band);
1300
0
  return NULL;
1301
292
}