Coverage Report

Created: 2017-04-28 04:32

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