Coverage Report

Created: 2017-03-28 09:59

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