Coverage Report

Created: 2017-11-21 16:49

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/lib/External/isl/isl_schedule_constraints.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2012      Ecole Normale Superieure
3
 * Copyright 2015-2016 Sven Verdoolaege
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
 */
10
11
#include <isl_schedule_constraints.h>
12
#include <isl/schedule.h>
13
#include <isl/set.h>
14
#include <isl/map.h>
15
#include <isl/union_set.h>
16
#include <isl/union_map.h>
17
#include <isl/stream.h>
18
19
/* The constraints that need to be satisfied by a schedule on "domain".
20
 *
21
 * "context" specifies extra constraints on the parameters.
22
 *
23
 * "validity" constraints map domain elements i to domain elements
24
 * that should be scheduled after i.  (Hard constraint)
25
 * "proximity" constraints map domain elements i to domains elements
26
 * that should be scheduled as early as possible after i (or before i).
27
 * (Soft constraint)
28
 *
29
 * "condition" and "conditional_validity" constraints map possibly "tagged"
30
 * domain elements i -> s to "tagged" domain elements j -> t.
31
 * The elements of the "conditional_validity" constraints, but without the
32
 * tags (i.e., the elements i -> j) are treated as validity constraints,
33
 * except that during the construction of a tilable band,
34
 * the elements of the "conditional_validity" constraints may be violated
35
 * provided that all adjacent elements of the "condition" constraints
36
 * are local within the band.
37
 * A dependence is local within a band if domain and range are mapped
38
 * to the same schedule point by the band.
39
 */
40
struct isl_schedule_constraints {
41
  isl_union_set *domain;
42
  isl_set *context;
43
44
  isl_union_map *constraint[isl_edge_last + 1];
45
};
46
47
__isl_give isl_schedule_constraints *isl_schedule_constraints_copy(
48
  __isl_keep isl_schedule_constraints *sc)
49
48
{
50
48
  isl_ctx *ctx;
51
48
  isl_schedule_constraints *sc_copy;
52
48
  enum isl_edge_type i;
53
48
54
48
  ctx = isl_union_set_get_ctx(sc->domain);
55
48
  sc_copy = isl_calloc_type(ctx, struct isl_schedule_constraints);
56
48
  if (!sc_copy)
57
0
    return NULL;
58
48
59
48
  sc_copy->domain = isl_union_set_copy(sc->domain);
60
48
  sc_copy->context = isl_set_copy(sc->context);
61
48
  if (!sc_copy->domain || !sc_copy->context)
62
0
    return isl_schedule_constraints_free(sc_copy);
63
48
64
288
  
for (i = isl_edge_first; 48
i <= isl_edge_last;
++i240
) {
65
240
    sc_copy->constraint[i] = isl_union_map_copy(sc->constraint[i]);
66
240
    if (!sc_copy->constraint[i])
67
0
      return isl_schedule_constraints_free(sc_copy);
68
240
  }
69
48
70
48
  return sc_copy;
71
48
}
72
73
/* Construct an empty (invalid) isl_schedule_constraints object.
74
 * The caller is responsible for setting the domain and initializing
75
 * all the other fields, e.g., by calling isl_schedule_constraints_init.
76
 */
77
static __isl_give isl_schedule_constraints *isl_schedule_constraints_alloc(
78
  isl_ctx *ctx)
79
12
{
80
12
  return isl_calloc_type(ctx, struct isl_schedule_constraints);
81
12
}
82
83
/* Initialize all the fields of "sc", except domain, which is assumed
84
 * to have been set by the caller.
85
 */
86
static __isl_give isl_schedule_constraints *isl_schedule_constraints_init(
87
  __isl_take isl_schedule_constraints *sc)
88
12
{
89
12
  isl_space *space;
90
12
  isl_union_map *empty;
91
12
  enum isl_edge_type i;
92
12
93
12
  if (!sc)
94
0
    return NULL;
95
12
  if (!sc->domain)
96
0
    return isl_schedule_constraints_free(sc);
97
12
  space = isl_union_set_get_space(sc->domain);
98
12
  if (!sc->context)
99
12
    sc->context = isl_set_universe(isl_space_copy(space));
100
12
  empty = isl_union_map_empty(space);
101
72
  for (i = isl_edge_first; i <= isl_edge_last; 
++i60
) {
102
60
    if (sc->constraint[i])
103
0
      continue;
104
60
    sc->constraint[i] = isl_union_map_copy(empty);
105
60
    if (!sc->constraint[i])
106
0
      sc->domain = isl_union_set_free(sc->domain);
107
60
  }
108
12
  isl_union_map_free(empty);
109
12
110
12
  if (!sc->domain || !sc->context)
111
0
    return isl_schedule_constraints_free(sc);
112
12
113
12
  return sc;
114
12
}
115
116
/* Construct an isl_schedule_constraints object for computing a schedule
117
 * on "domain".  The initial object does not impose any constraints.
118
 */
119
__isl_give isl_schedule_constraints *isl_schedule_constraints_on_domain(
120
  __isl_take isl_union_set *domain)
121
12
{
122
12
  isl_ctx *ctx;
123
12
  isl_schedule_constraints *sc;
124
12
125
12
  if (!domain)
126
0
    return NULL;
127
12
128
12
  ctx = isl_union_set_get_ctx(domain);
129
12
  sc = isl_schedule_constraints_alloc(ctx);
130
12
  if (!sc)
131
0
    goto error;
132
12
133
12
  sc->domain = domain;
134
12
  return isl_schedule_constraints_init(sc);
135
0
error:
136
0
  isl_union_set_free(domain);
137
0
  return NULL;
138
12
}
139
140
/* Replace the domain of "sc" by "domain".
141
 */
142
static __isl_give isl_schedule_constraints *isl_schedule_constraints_set_domain(
143
  __isl_take isl_schedule_constraints *sc,
144
  __isl_take isl_union_set *domain)
145
0
{
146
0
  if (!sc || !domain)
147
0
    goto error;
148
0
149
0
  isl_union_set_free(sc->domain);
150
0
  sc->domain = domain;
151
0
152
0
  return sc;
153
0
error:
154
0
  isl_schedule_constraints_free(sc);
155
0
  isl_union_set_free(domain);
156
0
  return NULL;
157
0
}
158
159
/* Replace the context of "sc" by "context".
160
 */
161
__isl_give isl_schedule_constraints *isl_schedule_constraints_set_context(
162
  __isl_take isl_schedule_constraints *sc, __isl_take isl_set *context)
163
0
{
164
0
  if (!sc || !context)
165
0
    goto error;
166
0
167
0
  isl_set_free(sc->context);
168
0
  sc->context = context;
169
0
170
0
  return sc;
171
0
error:
172
0
  isl_schedule_constraints_free(sc);
173
0
  isl_set_free(context);
174
0
  return NULL;
175
0
}
176
177
/* Replace the constraints of type "type" in "sc" by "c".
178
 */
179
static __isl_give isl_schedule_constraints *isl_schedule_constraints_set(
180
  __isl_take isl_schedule_constraints *sc, enum isl_edge_type type,
181
  __isl_take isl_union_map *c)
182
36
{
183
36
  if (!sc || !c)
184
0
    goto error;
185
36
186
36
  isl_union_map_free(sc->constraint[type]);
187
36
  sc->constraint[type] = c;
188
36
189
36
  return sc;
190
0
error:
191
0
  isl_schedule_constraints_free(sc);
192
0
  isl_union_map_free(c);
193
0
  return NULL;
194
36
}
195
196
/* Replace the validity constraints of "sc" by "validity".
197
 */
198
__isl_give isl_schedule_constraints *isl_schedule_constraints_set_validity(
199
  __isl_take isl_schedule_constraints *sc,
200
  __isl_take isl_union_map *validity)
201
12
{
202
12
  return isl_schedule_constraints_set(sc, isl_edge_validity, validity);
203
12
}
204
205
/* Replace the coincidence constraints of "sc" by "coincidence".
206
 */
207
__isl_give isl_schedule_constraints *isl_schedule_constraints_set_coincidence(
208
  __isl_take isl_schedule_constraints *sc,
209
  __isl_take isl_union_map *coincidence)
210
12
{
211
12
  return isl_schedule_constraints_set(sc, isl_edge_coincidence,
212
12
            coincidence);
213
12
}
214
215
/* Replace the proximity constraints of "sc" by "proximity".
216
 */
217
__isl_give isl_schedule_constraints *isl_schedule_constraints_set_proximity(
218
  __isl_take isl_schedule_constraints *sc,
219
  __isl_take isl_union_map *proximity)
220
12
{
221
12
  return isl_schedule_constraints_set(sc, isl_edge_proximity, proximity);
222
12
}
223
224
/* Replace the conditional validity constraints of "sc" by "condition"
225
 * and "validity".
226
 */
227
__isl_give isl_schedule_constraints *
228
isl_schedule_constraints_set_conditional_validity(
229
  __isl_take isl_schedule_constraints *sc,
230
  __isl_take isl_union_map *condition,
231
  __isl_take isl_union_map *validity)
232
0
{
233
0
  sc = isl_schedule_constraints_set(sc, isl_edge_condition, condition);
234
0
  sc = isl_schedule_constraints_set(sc, isl_edge_conditional_validity,
235
0
            validity);
236
0
  return sc;
237
0
}
238
239
__isl_null isl_schedule_constraints *isl_schedule_constraints_free(
240
  __isl_take isl_schedule_constraints *sc)
241
60
{
242
60
  enum isl_edge_type i;
243
60
244
60
  if (!sc)
245
0
    return NULL;
246
60
247
60
  isl_union_set_free(sc->domain);
248
60
  isl_set_free(sc->context);
249
360
  for (i = isl_edge_first; i <= isl_edge_last; 
++i300
)
250
300
    isl_union_map_free(sc->constraint[i]);
251
60
252
60
  free(sc);
253
60
254
60
  return NULL;
255
60
}
256
257
isl_ctx *isl_schedule_constraints_get_ctx(
258
  __isl_keep isl_schedule_constraints *sc)
259
24
{
260
24
  return sc ? isl_union_set_get_ctx(sc->domain) : NULL;
261
24
}
262
263
/* Return the domain of "sc".
264
 */
265
__isl_give isl_union_set *isl_schedule_constraints_get_domain(
266
  __isl_keep isl_schedule_constraints *sc)
267
48
{
268
48
  if (!sc)
269
0
    return NULL;
270
48
271
48
  return isl_union_set_copy(sc->domain);
272
48
}
273
274
/* Return the context of "sc".
275
 */
276
__isl_give isl_set *isl_schedule_constraints_get_context(
277
  __isl_keep isl_schedule_constraints *sc)
278
12
{
279
12
  if (!sc)
280
0
    return NULL;
281
12
282
12
  return isl_set_copy(sc->context);
283
12
}
284
285
/* Return the constraints of type "type" in "sc".
286
 */
287
__isl_give isl_union_map *isl_schedule_constraints_get(
288
  __isl_keep isl_schedule_constraints *sc, enum isl_edge_type type)
289
120
{
290
120
  if (!sc)
291
0
    return NULL;
292
120
293
120
  return isl_union_map_copy(sc->constraint[type]);
294
120
}
295
296
/* Return the validity constraints of "sc".
297
 */
298
__isl_give isl_union_map *isl_schedule_constraints_get_validity(
299
  __isl_keep isl_schedule_constraints *sc)
300
0
{
301
0
  return isl_schedule_constraints_get(sc, isl_edge_validity);
302
0
}
303
304
/* Return the coincidence constraints of "sc".
305
 */
306
__isl_give isl_union_map *isl_schedule_constraints_get_coincidence(
307
  __isl_keep isl_schedule_constraints *sc)
308
0
{
309
0
  return isl_schedule_constraints_get(sc, isl_edge_coincidence);
310
0
}
311
312
/* Return the proximity constraints of "sc".
313
 */
314
__isl_give isl_union_map *isl_schedule_constraints_get_proximity(
315
  __isl_keep isl_schedule_constraints *sc)
316
0
{
317
0
  return isl_schedule_constraints_get(sc, isl_edge_proximity);
318
0
}
319
320
/* Return the conditional validity constraints of "sc".
321
 */
322
__isl_give isl_union_map *isl_schedule_constraints_get_conditional_validity(
323
  __isl_keep isl_schedule_constraints *sc)
324
0
{
325
0
  return isl_schedule_constraints_get(sc, isl_edge_conditional_validity);
326
0
}
327
328
/* Return the conditions for the conditional validity constraints of "sc".
329
 */
330
__isl_give isl_union_map *
331
isl_schedule_constraints_get_conditional_validity_condition(
332
  __isl_keep isl_schedule_constraints *sc)
333
0
{
334
0
  return isl_schedule_constraints_get(sc, isl_edge_condition);
335
0
}
336
337
/* Add "c" to the constraints of type "type" in "sc".
338
 */
339
__isl_give isl_schedule_constraints *isl_schedule_constraints_add(
340
  __isl_take isl_schedule_constraints *sc, enum isl_edge_type type,
341
  __isl_take isl_union_map *c)
342
0
{
343
0
  if (!sc || !c)
344
0
    goto error;
345
0
346
0
  c = isl_union_map_union(sc->constraint[type], c);
347
0
  sc->constraint[type] = c;
348
0
  if (!c)
349
0
    return isl_schedule_constraints_free(sc);
350
0
351
0
  return sc;
352
0
error:
353
0
  isl_schedule_constraints_free(sc);
354
0
  isl_union_map_free(c);
355
0
  return NULL;
356
0
}
357
358
/* Can a schedule constraint of type "type" be tagged?
359
 */
360
static int may_be_tagged(enum isl_edge_type type)
361
0
{
362
0
  if (type == isl_edge_condition || type == isl_edge_conditional_validity)
363
0
    return 1;
364
0
  return 0;
365
0
}
366
367
/* Apply "umap" to the domains of the wrapped relations
368
 * inside the domain and range of "c".
369
 *
370
 * That is, for each map of the form
371
 *
372
 *  [D -> S] -> [E -> T]
373
 *
374
 * in "c", apply "umap" to D and E.
375
 *
376
 * D is exposed by currying the relation to
377
 *
378
 *  D -> [S -> [E -> T]]
379
 *
380
 * E is exposed by doing the same to the inverse of "c".
381
 */
382
static __isl_give isl_union_map *apply_factor_domain(
383
  __isl_take isl_union_map *c, __isl_keep isl_union_map *umap)
384
0
{
385
0
  c = isl_union_map_curry(c);
386
0
  c = isl_union_map_apply_domain(c, isl_union_map_copy(umap));
387
0
  c = isl_union_map_uncurry(c);
388
0
389
0
  c = isl_union_map_reverse(c);
390
0
  c = isl_union_map_curry(c);
391
0
  c = isl_union_map_apply_domain(c, isl_union_map_copy(umap));
392
0
  c = isl_union_map_uncurry(c);
393
0
  c = isl_union_map_reverse(c);
394
0
395
0
  return c;
396
0
}
397
398
/* Apply "umap" to domain and range of "c".
399
 * If "tag" is set, then "c" may contain tags and then "umap"
400
 * needs to be applied to the domains of the wrapped relations
401
 * inside the domain and range of "c".
402
 */
403
static __isl_give isl_union_map *apply(__isl_take isl_union_map *c,
404
  __isl_keep isl_union_map *umap, int tag)
405
0
{
406
0
  isl_union_map *t;
407
0
408
0
  if (tag)
409
0
    t = isl_union_map_copy(c);
410
0
  c = isl_union_map_apply_domain(c, isl_union_map_copy(umap));
411
0
  c = isl_union_map_apply_range(c, isl_union_map_copy(umap));
412
0
  if (!tag)
413
0
    return c;
414
0
  t = apply_factor_domain(t, umap);
415
0
  c = isl_union_map_union(c, t);
416
0
  return c;
417
0
}
418
419
/* Apply "umap" to the domain of the schedule constraints "sc".
420
 *
421
 * The two sides of the various schedule constraints are adjusted
422
 * accordingly.
423
 */
424
__isl_give isl_schedule_constraints *isl_schedule_constraints_apply(
425
  __isl_take isl_schedule_constraints *sc,
426
  __isl_take isl_union_map *umap)
427
0
{
428
0
  enum isl_edge_type i;
429
0
430
0
  if (!sc || !umap)
431
0
    goto error;
432
0
433
0
  for (i = isl_edge_first; i <= isl_edge_last; ++i) {
434
0
    int tag = may_be_tagged(i);
435
0
436
0
    sc->constraint[i] = apply(sc->constraint[i], umap, tag);
437
0
    if (!sc->constraint[i])
438
0
      goto error;
439
0
  }
440
0
  sc->domain = isl_union_set_apply(sc->domain, umap);
441
0
  if (!sc->domain)
442
0
    return isl_schedule_constraints_free(sc);
443
0
444
0
  return sc;
445
0
error:
446
0
  isl_schedule_constraints_free(sc);
447
0
  isl_union_map_free(umap);
448
0
  return NULL;
449
0
}
450
451
/* An enumeration of the various keys that may appear in a YAML mapping
452
 * of an isl_schedule_constraints object.
453
 * The keys for the edge types are assumed to have the same values
454
 * as the edge types in isl_edge_type.
455
 */
456
enum isl_sc_key {
457
  isl_sc_key_error = -1,
458
  isl_sc_key_validity = isl_edge_validity,
459
  isl_sc_key_coincidence = isl_edge_coincidence,
460
  isl_sc_key_condition = isl_edge_condition,
461
  isl_sc_key_conditional_validity = isl_edge_conditional_validity,
462
  isl_sc_key_proximity = isl_edge_proximity,
463
  isl_sc_key_domain,
464
  isl_sc_key_context,
465
  isl_sc_key_end
466
};
467
468
/* Textual representations of the YAML keys for an isl_schedule_constraints
469
 * object.
470
 */
471
static char *key_str[] = {
472
  [isl_sc_key_validity] = "validity",
473
  [isl_sc_key_coincidence] = "coincidence",
474
  [isl_sc_key_condition] = "condition",
475
  [isl_sc_key_conditional_validity] = "conditional_validity",
476
  [isl_sc_key_proximity] = "proximity",
477
  [isl_sc_key_domain] = "domain",
478
  [isl_sc_key_context] = "context",
479
};
480
481
/* Print a key, value pair for the edge of type "type" in "sc" to "p".
482
 */
483
static __isl_give isl_printer *print_constraint(__isl_take isl_printer *p,
484
  __isl_keep isl_schedule_constraints *sc, enum isl_edge_type type)
485
0
{
486
0
  p = isl_printer_print_str(p, key_str[type]);
487
0
  p = isl_printer_yaml_next(p);
488
0
  p = isl_printer_print_union_map(p, sc->constraint[type]);
489
0
  p = isl_printer_yaml_next(p);
490
0
491
0
  return p;
492
0
}
493
494
/* Print "sc" to "p"
495
 *
496
 * In particular, print the isl_schedule_constraints object as a YAML document.
497
 */
498
__isl_give isl_printer *isl_printer_print_schedule_constraints(
499
  __isl_take isl_printer *p, __isl_keep isl_schedule_constraints *sc)
500
0
{
501
0
  if (!sc)
502
0
    return isl_printer_free(p);
503
0
504
0
  p = isl_printer_yaml_start_mapping(p);
505
0
  p = isl_printer_print_str(p, key_str[isl_sc_key_domain]);
506
0
  p = isl_printer_yaml_next(p);
507
0
  p = isl_printer_print_union_set(p, sc->domain);
508
0
  p = isl_printer_yaml_next(p);
509
0
  p = isl_printer_print_str(p, key_str[isl_sc_key_context]);
510
0
  p = isl_printer_yaml_next(p);
511
0
  p = isl_printer_print_set(p, sc->context);
512
0
  p = isl_printer_yaml_next(p);
513
0
  p = print_constraint(p, sc, isl_edge_validity);
514
0
  p = print_constraint(p, sc, isl_edge_proximity);
515
0
  p = print_constraint(p, sc, isl_edge_coincidence);
516
0
  p = print_constraint(p, sc, isl_edge_condition);
517
0
  p = print_constraint(p, sc, isl_edge_conditional_validity);
518
0
  p = isl_printer_yaml_end_mapping(p);
519
0
520
0
  return p;
521
0
}
522
523
#undef BASE
524
#define BASE schedule_constraints
525
#include <print_templ_yaml.c>
526
527
#undef KEY
528
0
#define KEY enum isl_sc_key
529
#undef KEY_ERROR
530
0
#define KEY_ERROR isl_sc_key_error
531
#undef KEY_END
532
0
#define KEY_END isl_sc_key_end
533
#include "extract_key.c"
534
535
#undef BASE
536
#define BASE set
537
#include "read_in_string_templ.c"
538
539
#undef BASE
540
#define BASE union_set
541
#include "read_in_string_templ.c"
542
543
#undef BASE
544
#define BASE union_map
545
#include "read_in_string_templ.c"
546
547
/* Read an isl_schedule_constraints object from "s".
548
 *
549
 * Start off with an empty (invalid) isl_schedule_constraints object and
550
 * then fill up the fields based on the input.
551
 * The input needs to contain at least a description of the domain.
552
 * The other fields are set to defaults by isl_schedule_constraints_init
553
 * if they are not specified in the input.
554
 */
555
__isl_give isl_schedule_constraints *isl_stream_read_schedule_constraints(
556
  isl_stream *s)
557
0
{
558
0
  isl_ctx *ctx;
559
0
  isl_schedule_constraints *sc;
560
0
  int more;
561
0
  int domain_set = 0;
562
0
563
0
  if (isl_stream_yaml_read_start_mapping(s))
564
0
    return NULL;
565
0
566
0
  ctx = isl_stream_get_ctx(s);
567
0
  sc = isl_schedule_constraints_alloc(ctx);
568
0
  while ((more = isl_stream_yaml_next(s)) > 0) {
569
0
    enum isl_sc_key key;
570
0
    isl_set *context;
571
0
    isl_union_set *domain;
572
0
    isl_union_map *constraints;
573
0
574
0
    key = get_key(s);
575
0
    if (isl_stream_yaml_next(s) < 0)
576
0
      return isl_schedule_constraints_free(sc);
577
0
    switch (key) {
578
0
    case isl_sc_key_end:
579
0
    case isl_sc_key_error:
580
0
      return isl_schedule_constraints_free(sc);
581
0
    case isl_sc_key_domain:
582
0
      domain_set = 1;
583
0
      domain = read_union_set(s);
584
0
      sc = isl_schedule_constraints_set_domain(sc, domain);
585
0
      if (!sc)
586
0
        return NULL;
587
0
      break;
588
0
    case isl_sc_key_context:
589
0
      context = read_set(s);
590
0
      sc = isl_schedule_constraints_set_context(sc, context);
591
0
      if (!sc)
592
0
        return NULL;
593
0
      break;
594
0
    default:
595
0
      constraints = read_union_map(s);
596
0
      sc = isl_schedule_constraints_set(sc, key, constraints);
597
0
      if (!sc)
598
0
        return NULL;
599
0
      break;
600
0
    }
601
0
  }
602
0
  if (more < 0)
603
0
    return isl_schedule_constraints_free(sc);
604
0
605
0
  if (isl_stream_yaml_read_end_mapping(s) < 0) {
606
0
    isl_stream_error(s, NULL, "unexpected extra elements");
607
0
    return isl_schedule_constraints_free(sc);
608
0
  }
609
0
610
0
  if (!domain_set) {
611
0
    isl_stream_error(s, NULL, "no domain specified");
612
0
    return isl_schedule_constraints_free(sc);
613
0
  }
614
0
615
0
  return isl_schedule_constraints_init(sc);
616
0
}
617
618
/* Read an isl_schedule_constraints object from the file "input".
619
 */
620
__isl_give isl_schedule_constraints *isl_schedule_constraints_read_from_file(
621
  isl_ctx *ctx, FILE *input)
622
0
{
623
0
  struct isl_stream *s;
624
0
  isl_schedule_constraints *sc;
625
0
626
0
  s = isl_stream_new_file(ctx, input);
627
0
  if (!s)
628
0
    return NULL;
629
0
  sc = isl_stream_read_schedule_constraints(s);
630
0
  isl_stream_free(s);
631
0
632
0
  return sc;
633
0
}
634
635
/* Read an isl_schedule_constraints object from the string "str".
636
 */
637
__isl_give isl_schedule_constraints *isl_schedule_constraints_read_from_str(
638
  isl_ctx *ctx, const char *str)
639
0
{
640
0
  struct isl_stream *s;
641
0
  isl_schedule_constraints *sc;
642
0
643
0
  s = isl_stream_new_str(ctx, str);
644
0
  if (!s)
645
0
    return NULL;
646
0
  sc = isl_stream_read_schedule_constraints(s);
647
0
  isl_stream_free(s);
648
0
649
0
  return sc;
650
0
}
651
652
/* Align the parameters of the fields of "sc".
653
 */
654
__isl_give isl_schedule_constraints *
655
isl_schedule_constraints_align_params(__isl_take isl_schedule_constraints *sc)
656
12
{
657
12
  isl_space *space;
658
12
  enum isl_edge_type i;
659
12
660
12
  if (!sc)
661
0
    return NULL;
662
12
663
12
  space = isl_union_set_get_space(sc->domain);
664
12
  space = isl_space_align_params(space, isl_set_get_space(sc->context));
665
72
  for (i = isl_edge_first; i <= isl_edge_last; 
++i60
)
666
60
    space = isl_space_align_params(space,
667
60
            isl_union_map_get_space(sc->constraint[i]));
668
12
669
72
  for (i = isl_edge_first; i <= isl_edge_last; 
++i60
) {
670
60
    sc->constraint[i] = isl_union_map_align_params(
671
60
            sc->constraint[i], isl_space_copy(space));
672
60
    if (!sc->constraint[i])
673
0
      space = isl_space_free(space);
674
60
  }
675
12
  sc->context = isl_set_align_params(sc->context, isl_space_copy(space));
676
12
  sc->domain = isl_union_set_align_params(sc->domain, space);
677
12
  if (!sc->context || !sc->domain)
678
0
    return isl_schedule_constraints_free(sc);
679
12
680
12
  return sc;
681
12
}
682
683
/* Add the number of basic maps in "map" to *n.
684
 */
685
static isl_stat add_n_basic_map(__isl_take isl_map *map, void *user)
686
45
{
687
45
  int *n = user;
688
45
689
45
  *n += isl_map_n_basic_map(map);
690
45
  isl_map_free(map);
691
45
692
45
  return isl_stat_ok;
693
45
}
694
695
/* Return the total number of isl_basic_maps in the constraints of "sc".
696
 * Return -1 on error.
697
 */
698
int isl_schedule_constraints_n_basic_map(
699
  __isl_keep isl_schedule_constraints *sc)
700
12
{
701
12
  enum isl_edge_type i;
702
12
  int n = 0;
703
12
704
12
  if (!sc)
705
0
    return -1;
706
72
  
for (i = isl_edge_first; 12
i <= isl_edge_last;
++i60
)
707
60
    if (isl_union_map_foreach_map(sc->constraint[i],
708
60
            &add_n_basic_map, &n) < 0)
709
0
      return -1;
710
12
711
12
  return n;
712
12
}
713
714
/* Return the total number of isl_maps in the constraints of "sc".
715
 */
716
int isl_schedule_constraints_n_map(__isl_keep isl_schedule_constraints *sc)
717
12
{
718
12
  enum isl_edge_type i;
719
12
  int n = 0;
720
12
721
72
  for (i = isl_edge_first; i <= isl_edge_last; 
++i60
)
722
60
    n += isl_union_map_n_map(sc->constraint[i]);
723
12
724
12
  return n;
725
12
}