Coverage Report

Created: 2017-06-28 17:40

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/Support/ISLTools.cpp
Line
Count
Source (jump to first uncovered line)
1
//===------ ISLTools.cpp ----------------------------------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// Tools, utilities, helpers and extensions useful in conjunction with the
11
// Integer Set Library (isl).
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "polly/Support/ISLTools.h"
16
17
using namespace polly;
18
19
namespace {
20
/// Create a map that shifts one dimension by an offset.
21
///
22
/// Example:
23
/// makeShiftDimAff({ [i0, i1] -> [o0, o1] }, 1, -2)
24
///   = { [i0, i1] -> [i0, i1 - 1] }
25
///
26
/// @param Space  The map space of the result. Must have equal number of in- and
27
///               out-dimensions.
28
/// @param Pos    Position to shift.
29
/// @param Amount Value added to the shifted dimension.
30
///
31
/// @return An isl_multi_aff for the map with this shifted dimension.
32
734
isl::multi_aff makeShiftDimAff(isl::space Space, int Pos, int Amount) {
33
734
  auto Identity = give(isl_multi_aff_identity(Space.take()));
34
734
  if (Amount == 0)
35
0
    return Identity;
36
734
  auto ShiftAff = give(isl_multi_aff_get_aff(Identity.keep(), Pos));
37
734
  ShiftAff = give(isl_aff_set_constant_si(ShiftAff.take(), Amount));
38
734
  return give(isl_multi_aff_set_aff(Identity.take(), Pos, ShiftAff.take()));
39
734
}
40
41
/// Construct a map that swaps two nested tuples.
42
///
43
/// @param FromSpace1 { Space1[] }
44
/// @param FromSpace2 { Space2[] }
45
///
46
/// @return { [Space1[] -> Space2[]] -> [Space2[] -> Space1[]] }
47
isl::basic_map makeTupleSwapBasicMap(isl::space FromSpace1,
48
16
                                     isl::space FromSpace2) {
49
16
  assert(isl_space_is_set(FromSpace1.keep()) != isl_bool_false);
50
16
  assert(isl_space_is_set(FromSpace2.keep()) != isl_bool_false);
51
16
52
16
  auto Dims1 = isl_space_dim(FromSpace1.keep(), isl_dim_set);
53
16
  auto Dims2 = isl_space_dim(FromSpace2.keep(), isl_dim_set);
54
16
  auto FromSpace = give(isl_space_wrap(isl_space_map_from_domain_and_range(
55
16
      FromSpace1.copy(), FromSpace2.copy())));
56
16
  auto ToSpace = give(isl_space_wrap(isl_space_map_from_domain_and_range(
57
16
      FromSpace2.take(), FromSpace1.take())));
58
16
  auto MapSpace = give(
59
16
      isl_space_map_from_domain_and_range(FromSpace.take(), ToSpace.take()));
60
16
61
16
  auto Result = give(isl_basic_map_universe(MapSpace.take()));
62
19
  for (auto i = Dims1 - Dims1; 
i < Dims119
;
i += 13
)
{3
63
3
    Result = give(isl_basic_map_equate(Result.take(), isl_dim_in, i,
64
3
                                       isl_dim_out, Dims2 + i));
65
3
  }
66
33
  for (auto i = Dims2 - Dims2; 
i < Dims233
;
i += 117
)
{17
67
17
    Result = give(isl_basic_map_equate(Result.take(), isl_dim_in, Dims1 + i,
68
17
                                       isl_dim_out, i));
69
17
  }
70
16
71
16
  return Result;
72
16
}
73
74
/// Like makeTupleSwapBasicMap(isl::space,isl::space), but returns
75
/// an isl_map.
76
16
isl::map makeTupleSwapMap(isl::space FromSpace1, isl::space FromSpace2) {
77
16
  auto BMapResult =
78
16
      makeTupleSwapBasicMap(std::move(FromSpace1), std::move(FromSpace2));
79
16
  return give(isl_map_from_basic_map(BMapResult.take()));
80
16
}
81
} // anonymous namespace
82
83
162
isl::map polly::beforeScatter(isl::map Map, bool Strict) {
84
162
  auto RangeSpace = give(isl_space_range(isl_map_get_space(Map.keep())));
85
38
  auto ScatterRel = give(Strict ? isl_map_lex_gt(RangeSpace.take())
86
124
                                : isl_map_lex_ge(RangeSpace.take()));
87
162
  return give(isl_map_apply_range(Map.take(), ScatterRel.take()));
88
162
}
89
90
104
isl::union_map polly::beforeScatter(isl::union_map UMap, bool Strict) {
91
104
  auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
92
87
  UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat {
93
87
    auto After = beforeScatter(Map, Strict);
94
87
    Result = give(isl_union_map_add_map(Result.take(), After.take()));
95
87
    return isl::stat::ok;
96
87
  });
97
104
  return Result;
98
104
}
99
100
109
isl::map polly::afterScatter(isl::map Map, bool Strict) {
101
109
  auto RangeSpace = give(isl_space_range(isl_map_get_space(Map.keep())));
102
80
  auto ScatterRel = give(Strict ? isl_map_lex_lt(RangeSpace.take())
103
29
                                : isl_map_lex_le(RangeSpace.take()));
104
109
  return give(isl_map_apply_range(Map.take(), ScatterRel.take()));
105
109
}
106
107
104
isl::union_map polly::afterScatter(const isl::union_map &UMap, bool Strict) {
108
104
  auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
109
53
  UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat {
110
53
    auto After = afterScatter(Map, Strict);
111
53
    Result = give(isl_union_map_add_map(Result.take(), After.take()));
112
53
    return isl::stat::ok;
113
53
  });
114
104
  return Result;
115
104
}
116
117
isl::map polly::betweenScatter(isl::map From, isl::map To, bool InclFrom,
118
54
                               bool InclTo) {
119
54
  auto AfterFrom = afterScatter(From, !InclFrom);
120
54
  auto BeforeTo = beforeScatter(To, !InclTo);
121
54
122
54
  return give(isl_map_intersect(AfterFrom.take(), BeforeTo.take()));
123
54
}
124
125
isl::union_map polly::betweenScatter(isl::union_map From, isl::union_map To,
126
48
                                     bool InclFrom, bool InclTo) {
127
48
  auto AfterFrom = afterScatter(From, !InclFrom);
128
48
  auto BeforeTo = beforeScatter(To, !InclTo);
129
48
130
48
  return give(isl_union_map_intersect(AfterFrom.take(), BeforeTo.take()));
131
48
}
132
133
161
isl::map polly::singleton(isl::union_map UMap, isl::space ExpectedSpace) {
134
161
  if (!UMap)
135
2
    return nullptr;
136
161
137
159
  
if (159
isl_union_map_n_map(UMap.keep()) == 0159
)
138
1
    return give(isl_map_empty(ExpectedSpace.take()));
139
159
140
158
  auto Result = give(isl_map_from_union_map(UMap.take()));
141
158
  assert(!Result || isl_space_has_equal_tuples(
142
158
                        give(isl_map_get_space(Result.keep())).keep(),
143
158
                        ExpectedSpace.keep()) == isl_bool_true);
144
158
  return Result;
145
159
}
146
147
23
isl::set polly::singleton(isl::union_set USet, isl::space ExpectedSpace) {
148
23
  if (!USet)
149
0
    return nullptr;
150
23
151
23
  
if (23
isl_union_set_n_set(USet.keep()) == 023
)
152
1
    return give(isl_set_empty(ExpectedSpace.copy()));
153
23
154
22
  auto Result = give(isl_set_from_union_set(USet.take()));
155
22
  assert(!Result || isl_space_has_equal_tuples(
156
22
                        give(isl_set_get_space(Result.keep())).keep(),
157
22
                        ExpectedSpace.keep()) == isl_bool_true);
158
22
  return Result;
159
23
}
160
161
257
unsigned polly::getNumScatterDims(const isl::union_map &Schedule) {
162
257
  unsigned Dims = 0;
163
1.08k
  Schedule.foreach_map([&Dims](isl::map Map) -> isl::stat {
164
1.08k
    Dims = std::max(Dims, isl_map_dim(Map.keep(), isl_dim_out));
165
1.08k
    return isl::stat::ok;
166
1.08k
  });
167
257
  return Dims;
168
257
}
169
170
249
isl::space polly::getScatterSpace(const isl::union_map &Schedule) {
171
249
  if (!Schedule)
172
0
    return nullptr;
173
249
  auto Dims = getNumScatterDims(Schedule);
174
249
  auto ScatterSpace =
175
249
      give(isl_space_set_from_params(isl_union_map_get_space(Schedule.keep())));
176
249
  return give(isl_space_add_dims(ScatterSpace.take(), isl_dim_set, Dims));
177
249
}
178
179
isl::union_map polly::makeIdentityMap(const isl::union_set &USet,
180
39
                                      bool RestrictDomain) {
181
39
  auto Result = give(isl_union_map_empty(isl_union_set_get_space(USet.keep())));
182
40
  USet.foreach_set([=, &Result](isl::set Set) -> isl::stat {
183
40
    auto IdentityMap = give(isl_map_identity(
184
40
        isl_space_map_from_set(isl_set_get_space(Set.keep()))));
185
40
    if (RestrictDomain)
186
37
      IdentityMap =
187
37
          give(isl_map_intersect_domain(IdentityMap.take(), Set.take()));
188
40
    Result = give(isl_union_map_add_map(Result.take(), IdentityMap.take()));
189
40
    return isl::stat::ok;
190
40
  });
191
39
  return Result;
192
39
}
193
194
16
isl::map polly::reverseDomain(isl::map Map) {
195
16
  auto DomSpace =
196
16
      give(isl_space_unwrap(isl_space_domain(isl_map_get_space(Map.keep()))));
197
16
  auto Space1 = give(isl_space_domain(DomSpace.copy()));
198
16
  auto Space2 = give(isl_space_range(DomSpace.take()));
199
16
  auto Swap = makeTupleSwapMap(std::move(Space1), std::move(Space2));
200
16
  return give(isl_map_apply_domain(Map.take(), Swap.take()));
201
16
}
202
203
45
isl::union_map polly::reverseDomain(const isl::union_map &UMap) {
204
45
  auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
205
15
  UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat {
206
15
    auto Reversed = reverseDomain(std::move(Map));
207
15
    Result = give(isl_union_map_add_map(Result.take(), Reversed.take()));
208
15
    return isl::stat::ok;
209
15
  });
210
45
  return Result;
211
45
}
212
213
484
isl::set polly::shiftDim(isl::set Set, int Pos, int Amount) {
214
484
  int NumDims = isl_set_dim(Set.keep(), isl_dim_set);
215
484
  if (Pos < 0)
216
481
    Pos = NumDims + Pos;
217
484
  assert(Pos < NumDims && "Dimension index must be in range");
218
484
  auto Space = give(isl_set_get_space(Set.keep()));
219
484
  Space = give(isl_space_map_from_domain_and_range(Space.copy(), Space.copy()));
220
484
  auto Translator = makeShiftDimAff(std::move(Space), Pos, Amount);
221
484
  auto TranslatorMap = give(isl_map_from_multi_aff(Translator.take()));
222
484
  return give(isl_set_apply(Set.take(), TranslatorMap.take()));
223
484
}
224
225
470
isl::union_set polly::shiftDim(isl::union_set USet, int Pos, int Amount) {
226
470
  auto Result = give(isl_union_set_empty(isl_union_set_get_space(USet.keep())));
227
483
  USet.foreach_set([=, &Result](isl::set Set) -> isl::stat {
228
483
    auto Shifted = shiftDim(Set, Pos, Amount);
229
483
    Result = give(isl_union_set_add_set(Result.take(), Shifted.take()));
230
483
    return isl::stat::ok;
231
483
  });
232
470
  return Result;
233
470
}
234
235
250
isl::map polly::shiftDim(isl::map Map, isl::dim Dim, int Pos, int Amount) {
236
250
  int NumDims = Map.dim(Dim);
237
250
  if (Pos < 0)
238
246
    Pos = NumDims + Pos;
239
250
  assert(Pos < NumDims && "Dimension index must be in range");
240
250
  auto Space = give(isl_map_get_space(Map.keep()));
241
250
  switch (Dim) {
242
245
  case isl::dim::in:
243
245
    Space = std::move(Space).domain();
244
245
    break;
245
5
  case isl::dim::out:
246
5
    Space = give(isl_space_range(Space.take()));
247
5
    break;
248
0
  default:
249
0
    llvm_unreachable("Unsupported value for 'dim'");
250
250
  }
251
250
  Space = give(isl_space_map_from_domain_and_range(Space.copy(), Space.copy()));
252
250
  auto Translator = makeShiftDimAff(std::move(Space), Pos, Amount);
253
250
  auto TranslatorMap = give(isl_map_from_multi_aff(Translator.take()));
254
250
  switch (Dim) {
255
245
  case isl::dim::in:
256
245
    return Map.apply_domain(TranslatorMap);
257
5
  case isl::dim::out:
258
5
    return Map.apply_range(TranslatorMap);
259
0
  default:
260
0
    llvm_unreachable("Unsupported value for 'dim'");
261
250
  }
262
250
}
263
264
isl::union_map polly::shiftDim(isl::union_map UMap, isl::dim Dim, int Pos,
265
458
                               int Amount) {
266
458
  auto Result = isl::union_map::empty(UMap.get_space());
267
458
268
248
  UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat {
269
248
    auto Shifted = shiftDim(Map, Dim, Pos, Amount);
270
248
    Result = std::move(Result).add_map(Shifted);
271
248
    return isl::stat::ok;
272
248
  });
273
458
  return Result;
274
458
}
275
276
32
void polly::simplify(isl::set &Set) {
277
32
  Set = give(isl_set_compute_divs(Set.take()));
278
32
  Set = give(isl_set_detect_equalities(Set.take()));
279
32
  Set = give(isl_set_coalesce(Set.take()));
280
32
}
281
282
45
void polly::simplify(isl::union_set &USet) {
283
45
  USet = give(isl_union_set_compute_divs(USet.take()));
284
45
  USet = give(isl_union_set_detect_equalities(USet.take()));
285
45
  USet = give(isl_union_set_coalesce(USet.take()));
286
45
}
287
288
271
void polly::simplify(isl::map &Map) {
289
271
  Map = give(isl_map_compute_divs(Map.take()));
290
271
  Map = give(isl_map_detect_equalities(Map.take()));
291
271
  Map = give(isl_map_coalesce(Map.take()));
292
271
}
293
294
179
void polly::simplify(isl::union_map &UMap) {
295
179
  UMap = give(isl_union_map_compute_divs(UMap.take()));
296
179
  UMap = give(isl_union_map_detect_equalities(UMap.take()));
297
179
  UMap = give(isl_union_map_coalesce(UMap.take()));
298
179
}
299
300
isl::union_map polly::computeReachingWrite(isl::union_map Schedule,
301
                                           isl::union_map Writes, bool Reverse,
302
150
                                           bool InclPrevDef, bool InclNextDef) {
303
150
304
150
  // { Scatter[] }
305
150
  auto ScatterSpace = getScatterSpace(Schedule);
306
150
307
150
  // { ScatterRead[] -> ScatterWrite[] }
308
150
  isl::map Relation;
309
150
  if (Reverse)
310
77
    
Relation = give(InclPrevDef ? 77
isl_map_lex_lt(ScatterSpace.take())13
311
64
                                : isl_map_lex_le(ScatterSpace.take()));
312
150
  else
313
73
    
Relation = give(InclNextDef ? 73
isl_map_lex_gt(ScatterSpace.take())67
314
6
                                : isl_map_lex_ge(ScatterSpace.take()));
315
150
316
150
  // { ScatterWrite[] -> [ScatterRead[] -> ScatterWrite[]] }
317
150
  auto RelationMap = give(isl_map_reverse(isl_map_range_map(Relation.take())));
318
150
319
150
  // { Element[] -> ScatterWrite[] }
320
150
  auto WriteAction =
321
150
      give(isl_union_map_apply_domain(Schedule.copy(), Writes.take()));
322
150
323
150
  // { ScatterWrite[] -> Element[] }
324
150
  auto WriteActionRev = give(isl_union_map_reverse(WriteAction.copy()));
325
150
326
150
  // { Element[] -> [ScatterUse[] -> ScatterWrite[]] }
327
150
  auto DefSchedRelation = give(isl_union_map_apply_domain(
328
150
      isl_union_map_from_map(RelationMap.take()), WriteActionRev.take()));
329
150
330
150
  // For each element, at every point in time, map to the times of previous
331
150
  // definitions. { [Element[] -> ScatterRead[]] -> ScatterWrite[] }
332
150
  auto ReachableWrites = give(isl_union_map_uncurry(DefSchedRelation.take()));
333
150
  if (Reverse)
334
77
    ReachableWrites = give(isl_union_map_lexmin(ReachableWrites.copy()));
335
150
  else
336
73
    ReachableWrites = give(isl_union_map_lexmax(ReachableWrites.copy()));
337
150
338
150
  // { [Element[] -> ScatterWrite[]] -> ScatterWrite[] }
339
150
  auto SelfUse = give(isl_union_map_range_map(WriteAction.take()));
340
150
341
150
  if (
InclPrevDef && 150
InclNextDef17
)
{3
342
3
    // Add the Def itself to the solution.
343
3
    ReachableWrites =
344
3
        give(isl_union_map_union(ReachableWrites.take(), SelfUse.take()));
345
3
    ReachableWrites = give(isl_union_map_coalesce(ReachableWrites.take()));
346
147
  } else 
if (147
!InclPrevDef && 147
!InclNextDef133
)
{5
347
5
    // Remove Def itself from the solution.
348
5
    ReachableWrites =
349
5
        give(isl_union_map_subtract(ReachableWrites.take(), SelfUse.take()));
350
5
  }
351
150
352
150
  // { [Element[] -> ScatterRead[]] -> Domain[] }
353
150
  auto ReachableWriteDomain = give(isl_union_map_apply_range(
354
150
      ReachableWrites.take(), isl_union_map_reverse(Schedule.take())));
355
150
356
150
  return ReachableWriteDomain;
357
150
}
358
359
isl::union_map
360
polly::computeArrayUnused(isl::union_map Schedule, isl::union_map Writes,
361
                          isl::union_map Reads, bool ReadEltInSameInst,
362
44
                          bool IncludeLastRead, bool IncludeWrite) {
363
44
  // { Element[] -> Scatter[] }
364
44
  auto ReadActions =
365
44
      give(isl_union_map_apply_domain(Schedule.copy(), Reads.take()));
366
44
  auto WriteActions =
367
44
      give(isl_union_map_apply_domain(Schedule.copy(), Writes.copy()));
368
44
369
44
  // { [Element[] -> Scatter[] }
370
44
  auto AfterReads = afterScatter(ReadActions, ReadEltInSameInst);
371
44
  auto WritesBeforeAnyReads =
372
44
      give(isl_union_map_subtract(WriteActions.take(), AfterReads.take()));
373
44
  auto BeforeWritesBeforeAnyReads =
374
44
      beforeScatter(WritesBeforeAnyReads, !IncludeWrite);
375
44
376
44
  // { [Element[] -> DomainWrite[]] -> Scatter[] }
377
44
  auto EltDomWrites = give(isl_union_map_apply_range(
378
44
      isl_union_map_range_map(isl_union_map_reverse(Writes.copy())),
379
44
      Schedule.copy()));
380
44
381
44
  // { [Element[] -> Scatter[]] -> DomainWrite[] }
382
44
  auto ReachingOverwrite = computeReachingWrite(
383
44
      Schedule, Writes, true, ReadEltInSameInst, !ReadEltInSameInst);
384
44
385
44
  // { [Element[] -> Scatter[]] -> DomainWrite[] }
386
44
  auto ReadsOverwritten = give(isl_union_map_intersect_domain(
387
44
      ReachingOverwrite.take(), isl_union_map_wrap(ReadActions.take())));
388
44
389
44
  // { [Element[] -> DomainWrite[]] -> Scatter[] }
390
44
  auto ReadsOverwrittenRotated = give(isl_union_map_reverse(
391
44
      isl_union_map_curry(reverseDomain(ReadsOverwritten).take())));
392
44
  auto LastOverwrittenRead =
393
44
      give(isl_union_map_lexmax(ReadsOverwrittenRotated.take()));
394
44
395
44
  // { [Element[] -> DomainWrite[]] -> Scatter[] }
396
44
  auto BetweenLastReadOverwrite = betweenScatter(
397
44
      LastOverwrittenRead, EltDomWrites, IncludeLastRead, IncludeWrite);
398
44
399
44
  return give(isl_union_map_union(
400
44
      BeforeWritesBeforeAnyReads.take(),
401
44
      isl_union_map_domain_factor_domain(BetweenLastReadOverwrite.take())));
402
44
}
403
404
isl::union_set polly::convertZoneToTimepoints(isl::union_set Zone,
405
470
                                              bool InclStart, bool InclEnd) {
406
470
  if (
!InclStart && 470
InclEnd10
)
407
5
    return Zone;
408
470
409
465
  auto ShiftedZone = shiftDim(Zone, -1, -1);
410
465
  if (
InclStart && 465
!InclEnd460
)
411
455
    return ShiftedZone;
412
10
  else 
if (10
!InclStart && 10
!InclEnd5
)
413
5
    return give(isl_union_set_intersect(Zone.take(), ShiftedZone.take()));
414
465
415
5
  assert(InclStart && InclEnd);
416
5
  return give(isl_union_set_union(Zone.take(), ShiftedZone.take()));
417
465
}
418
419
isl::union_map polly::convertZoneToTimepoints(isl::union_map Zone, isl::dim Dim,
420
458
                                              bool InclStart, bool InclEnd) {
421
458
  if (
!InclStart && 458
InclEnd4
)
422
2
    return Zone;
423
458
424
456
  auto ShiftedZone = shiftDim(Zone, Dim, -1, -1);
425
456
  if (
InclStart && 456
!InclEnd454
)
426
452
    return ShiftedZone;
427
4
  else 
if (4
!InclStart && 4
!InclEnd2
)
428
2
    return give(isl_union_map_intersect(Zone.take(), ShiftedZone.take()));
429
456
430
2
  assert(InclStart && InclEnd);
431
2
  return give(isl_union_map_union(Zone.take(), ShiftedZone.take()));
432
456
}
433
434
33
isl::map polly::distributeDomain(isl::map Map) {
435
33
  // Note that we cannot take Map apart into { Domain[] -> Range1[] } and {
436
33
  // Domain[] -> Range2[] } and combine again. We would loose any relation
437
33
  // between Range1[] and Range2[] that is not also a constraint to Domain[].
438
33
439
33
  auto Space = give(isl_map_get_space(Map.keep()));
440
33
  auto DomainSpace = give(isl_space_domain(Space.copy()));
441
33
  assert(DomainSpace);
442
33
  auto DomainDims = isl_space_dim(DomainSpace.keep(), isl_dim_set);
443
33
  auto RangeSpace = give(isl_space_unwrap(isl_space_range(Space.copy())));
444
33
  auto Range1Space = give(isl_space_domain(RangeSpace.copy()));
445
33
  assert(Range1Space);
446
33
  auto Range1Dims = isl_space_dim(Range1Space.keep(), isl_dim_set);
447
33
  auto Range2Space = give(isl_space_range(RangeSpace.copy()));
448
33
  assert(Range2Space);
449
33
  auto Range2Dims = isl_space_dim(Range2Space.keep(), isl_dim_set);
450
33
451
33
  auto OutputSpace = give(isl_space_map_from_domain_and_range(
452
33
      isl_space_wrap(isl_space_map_from_domain_and_range(DomainSpace.copy(),
453
33
                                                         Range1Space.copy())),
454
33
      isl_space_wrap(isl_space_map_from_domain_and_range(DomainSpace.copy(),
455
33
                                                         Range2Space.copy()))));
456
33
457
33
  auto Translator =
458
33
      give(isl_basic_map_universe(isl_space_map_from_domain_and_range(
459
33
          isl_space_wrap(Space.copy()), isl_space_wrap(OutputSpace.copy()))));
460
33
461
68
  for (unsigned i = 0; 
i < DomainDims68
;
i += 135
)
{35
462
35
    Translator = give(
463
35
        isl_basic_map_equate(Translator.take(), isl_dim_in, i, isl_dim_out, i));
464
35
    Translator =
465
35
        give(isl_basic_map_equate(Translator.take(), isl_dim_in, i, isl_dim_out,
466
35
                                  DomainDims + Range1Dims + i));
467
35
  }
468
106
  for (unsigned i = 0; 
i < Range1Dims106
;
i += 173
)
{73
469
73
    Translator =
470
73
        give(isl_basic_map_equate(Translator.take(), isl_dim_in, DomainDims + i,
471
73
                                  isl_dim_out, DomainDims + i));
472
73
  }
473
72
  for (unsigned i = 0; 
i < Range2Dims72
;
i += 139
)
{39
474
39
    Translator = give(isl_basic_map_equate(
475
39
        Translator.take(), isl_dim_in, DomainDims + Range1Dims + i, isl_dim_out,
476
39
        DomainDims + Range1Dims + DomainDims + i));
477
39
  }
478
33
479
33
  return give(isl_set_unwrap(isl_set_apply(
480
33
      isl_map_wrap(Map.copy()), isl_map_from_basic_map(Translator.copy()))));
481
33
}
482
483
28
isl::union_map polly::distributeDomain(isl::union_map UMap) {
484
28
  auto Result = give(isl_union_map_empty(isl_union_map_get_space(UMap.keep())));
485
31
  UMap.foreach_map([=, &Result](isl::map Map) {
486
31
    auto Distributed = distributeDomain(Map);
487
31
    Result = give(isl_union_map_add_map(Result.take(), Distributed.copy()));
488
31
    return isl::stat::ok;
489
31
  });
490
28
  return Result;
491
28
}
492
493
33
isl::union_map polly::liftDomains(isl::union_map UMap, isl::union_set Factor) {
494
33
495
33
  // { Factor[] -> Factor[] }
496
33
  auto Factors = makeIdentityMap(std::move(Factor), true);
497
33
498
33
  return std::move(Factors).product(std::move(UMap));
499
33
}
500
501
isl::union_map polly::applyDomainRange(isl::union_map UMap,
502
30
                                       isl::union_map Func) {
503
30
  // This implementation creates unnecessary cross products of the
504
30
  // DomainDomain[] and Func. An alternative implementation could reverse
505
30
  // domain+uncurry,apply Func to what now is the domain, then undo the
506
30
  // preparing transformation. Another alternative implementation could create a
507
30
  // translator map for each piece.
508
30
509
30
  // { DomainDomain[] }
510
30
  auto DomainDomain = UMap.domain().unwrap().domain();
511
30
512
30
  // { [DomainDomain[] -> DomainRange[]] -> [DomainDomain[] -> NewDomainRange[]]
513
30
  // }
514
30
  auto LifetedFunc = liftDomains(std::move(Func), DomainDomain);
515
30
516
30
  return std::move(UMap).apply_domain(std::move(LifetedFunc));
517
30
}