Coverage Report

Created: 2018-09-25 00:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/polly/include/polly/Support/ISLTools.h
Line
Count
Source
1
//===------ ISLTools.h ------------------------------------------*- 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
#ifndef POLLY_ISLTOOLS_H
16
#define POLLY_ISLTOOLS_H
17
18
#include "polly/Support/GICHelper.h"
19
#include "llvm/ADT/iterator_range.h"
20
21
namespace isl {
22
inline namespace noexceptions {
23
24
template <typename ListT>
25
using list_element_type = decltype(std::declval<ListT>().get_at(0));
26
27
template <typename ListT>
28
struct isl_iterator
29
    : public llvm::iterator_facade_base<isl_iterator<ListT>,
30
                                        std::forward_iterator_tag,
31
                                        list_element_type<ListT>> {
32
33
  using ElementT = list_element_type<ListT>;
34
35
  explicit isl_iterator(const ListT &List)
36
9.27k
      : List(&List), Position(List.size()) {}
isl::noexceptions::isl_iterator<isl::noexceptions::set_list>::isl_iterator(isl::noexceptions::set_list const&)
Line
Count
Source
36
2.84k
      : List(&List), Position(List.size()) {}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list>::isl_iterator(isl::noexceptions::basic_set_list const&)
Line
Count
Source
36
2.08k
      : List(&List), Position(List.size()) {}
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list>::isl_iterator(isl::noexceptions::ast_node_list const&)
Line
Count
Source
36
2
      : List(&List), Position(List.size()) {}
isl::noexceptions::isl_iterator<isl::noexceptions::map_list>::isl_iterator(isl::noexceptions::map_list const&)
Line
Count
Source
36
4.12k
      : List(&List), Position(List.size()) {}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list>::isl_iterator(isl::noexceptions::basic_map_list const&)
Line
Count
Source
36
216
      : List(&List), Position(List.size()) {}
37
  isl_iterator(const ListT &List, int Position)
38
9.27k
      : List(&List), Position(Position) {}
isl::noexceptions::isl_iterator<isl::noexceptions::set_list>::isl_iterator(isl::noexceptions::set_list const&, int)
Line
Count
Source
38
2.84k
      : List(&List), Position(Position) {}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list>::isl_iterator(isl::noexceptions::basic_set_list const&, int)
Line
Count
Source
38
2.08k
      : List(&List), Position(Position) {}
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list>::isl_iterator(isl::noexceptions::ast_node_list const&, int)
Line
Count
Source
38
2
      : List(&List), Position(Position) {}
isl::noexceptions::isl_iterator<isl::noexceptions::map_list>::isl_iterator(isl::noexceptions::map_list const&, int)
Line
Count
Source
38
4.12k
      : List(&List), Position(Position) {}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list>::isl_iterator(isl::noexceptions::basic_map_list const&, int)
Line
Count
Source
38
216
      : List(&List), Position(Position) {}
39
  isl_iterator &operator=(const isl_iterator &R) = default;
40
41
23.4k
  bool operator==(const isl_iterator &O) const {
42
23.4k
    return List == O.List && Position == O.Position;
43
23.4k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::set_list>::operator==(isl::noexceptions::isl_iterator<isl::noexceptions::set_list> const&) const
Line
Count
Source
41
6.78k
  bool operator==(const isl_iterator &O) const {
42
6.78k
    return List == O.List && Position == O.Position;
43
6.78k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list>::operator==(isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list> const&) const
Line
Count
Source
41
4.83k
  bool operator==(const isl_iterator &O) const {
42
4.83k
    return List == O.List && Position == O.Position;
43
4.83k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list>::operator==(isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list> const&) const
Line
Count
Source
41
4
  bool operator==(const isl_iterator &O) const {
42
4
    return List == O.List && Position == O.Position;
43
4
  }
isl::noexceptions::isl_iterator<isl::noexceptions::map_list>::operator==(isl::noexceptions::isl_iterator<isl::noexceptions::map_list> const&) const
Line
Count
Source
41
11.5k
  bool operator==(const isl_iterator &O) const {
42
11.5k
    return List == O.List && Position == O.Position;
43
11.5k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list>::operator==(isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list> const&) const
Line
Count
Source
41
304
  bool operator==(const isl_iterator &O) const {
42
304
    return List == O.List && Position == O.Position;
43
304
  }
44
45
14.2k
  isl_iterator &operator++() {
46
14.2k
    ++Position;
47
14.2k
    return *this;
48
14.2k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::set_list>::operator++()
Line
Count
Source
45
3.94k
  isl_iterator &operator++() {
46
3.94k
    ++Position;
47
3.94k
    return *this;
48
3.94k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list>::operator++()
Line
Count
Source
45
2.75k
  isl_iterator &operator++() {
46
2.75k
    ++Position;
47
2.75k
    return *this;
48
2.75k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list>::operator++()
Line
Count
Source
45
2
  isl_iterator &operator++() {
46
2
    ++Position;
47
2
    return *this;
48
2
  }
isl::noexceptions::isl_iterator<isl::noexceptions::map_list>::operator++()
Line
Count
Source
45
7.42k
  isl_iterator &operator++() {
46
7.42k
    ++Position;
47
7.42k
    return *this;
48
7.42k
  }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list>::operator++()
Line
Count
Source
45
88
  isl_iterator &operator++() {
46
88
    ++Position;
47
88
    return *this;
48
88
  }
49
50
  isl_iterator operator++(int) {
51
    isl_iterator Copy{*this};
52
    ++Position;
53
    return Copy;
54
  }
55
56
14.4k
  ElementT operator*() const { return List->get_at(this->Position); }
isl::noexceptions::isl_iterator<isl::noexceptions::set_list>::operator*() const
Line
Count
Source
56
3.95k
  ElementT operator*() const { return List->get_at(this->Position); }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list>::operator*() const
Line
Count
Source
56
2.75k
  ElementT operator*() const { return List->get_at(this->Position); }
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list>::operator*() const
Line
Count
Source
56
3
  ElementT operator*() const { return List->get_at(this->Position); }
isl::noexceptions::isl_iterator<isl::noexceptions::map_list>::operator*() const
Line
Count
Source
56
7.54k
  ElementT operator*() const { return List->get_at(this->Position); }
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list>::operator*() const
Line
Count
Source
56
234
  ElementT operator*() const { return List->get_at(this->Position); }
57
58
protected:
59
  const ListT *List;
60
  int Position = 0;
61
};
62
63
9.27k
template <typename T> isl_iterator<T> begin(const T &t) {
64
9.27k
  return isl_iterator<T>(t, 0);
65
9.27k
}
isl::noexceptions::isl_iterator<isl::noexceptions::set_list> isl::noexceptions::begin<isl::noexceptions::set_list>(isl::noexceptions::set_list const&)
Line
Count
Source
63
2.84k
template <typename T> isl_iterator<T> begin(const T &t) {
64
2.84k
  return isl_iterator<T>(t, 0);
65
2.84k
}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list> isl::noexceptions::begin<isl::noexceptions::basic_set_list>(isl::noexceptions::basic_set_list const&)
Line
Count
Source
63
2.08k
template <typename T> isl_iterator<T> begin(const T &t) {
64
2.08k
  return isl_iterator<T>(t, 0);
65
2.08k
}
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list> isl::noexceptions::begin<isl::noexceptions::ast_node_list>(isl::noexceptions::ast_node_list const&)
Line
Count
Source
63
2
template <typename T> isl_iterator<T> begin(const T &t) {
64
2
  return isl_iterator<T>(t, 0);
65
2
}
isl::noexceptions::isl_iterator<isl::noexceptions::map_list> isl::noexceptions::begin<isl::noexceptions::map_list>(isl::noexceptions::map_list const&)
Line
Count
Source
63
4.12k
template <typename T> isl_iterator<T> begin(const T &t) {
64
4.12k
  return isl_iterator<T>(t, 0);
65
4.12k
}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list> isl::noexceptions::begin<isl::noexceptions::basic_map_list>(isl::noexceptions::basic_map_list const&)
Line
Count
Source
63
216
template <typename T> isl_iterator<T> begin(const T &t) {
64
216
  return isl_iterator<T>(t, 0);
65
216
}
66
9.27k
template <typename T> isl_iterator<T> end(const T &t) {
67
9.27k
  return isl_iterator<T>(t);
68
9.27k
}
isl::noexceptions::isl_iterator<isl::noexceptions::set_list> isl::noexceptions::end<isl::noexceptions::set_list>(isl::noexceptions::set_list const&)
Line
Count
Source
66
2.84k
template <typename T> isl_iterator<T> end(const T &t) {
67
2.84k
  return isl_iterator<T>(t);
68
2.84k
}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_set_list> isl::noexceptions::end<isl::noexceptions::basic_set_list>(isl::noexceptions::basic_set_list const&)
Line
Count
Source
66
2.08k
template <typename T> isl_iterator<T> end(const T &t) {
67
2.08k
  return isl_iterator<T>(t);
68
2.08k
}
isl::noexceptions::isl_iterator<isl::noexceptions::ast_node_list> isl::noexceptions::end<isl::noexceptions::ast_node_list>(isl::noexceptions::ast_node_list const&)
Line
Count
Source
66
2
template <typename T> isl_iterator<T> end(const T &t) {
67
2
  return isl_iterator<T>(t);
68
2
}
isl::noexceptions::isl_iterator<isl::noexceptions::map_list> isl::noexceptions::end<isl::noexceptions::map_list>(isl::noexceptions::map_list const&)
Line
Count
Source
66
4.12k
template <typename T> isl_iterator<T> end(const T &t) {
67
4.12k
  return isl_iterator<T>(t);
68
4.12k
}
isl::noexceptions::isl_iterator<isl::noexceptions::basic_map_list> isl::noexceptions::end<isl::noexceptions::basic_map_list>(isl::noexceptions::basic_map_list const&)
Line
Count
Source
66
216
template <typename T> isl_iterator<T> end(const T &t) {
67
216
  return isl_iterator<T>(t);
68
216
}
69
70
} // namespace noexceptions
71
} // namespace isl
72
73
namespace polly {
74
75
/// Return the range elements that are lexicographically smaller.
76
///
77
/// @param Map    { Space[] -> Scatter[] }
78
/// @param Strict True for strictly lexicographically smaller elements (exclude
79
///               same timepoints from the result).
80
///
81
/// @return { Space[] -> Scatter[] }
82
///         A map to all timepoints that happen before the timepoints the input
83
///         mapped to.
84
isl::map beforeScatter(isl::map Map, bool Strict);
85
86
/// Piecewise beforeScatter(isl::map,bool).
87
isl::union_map beforeScatter(isl::union_map UMap, bool Strict);
88
89
/// Return the range elements that are lexicographically larger.
90
///
91
/// @param Map    { Space[] -> Scatter[] }
92
/// @param Strict True for strictly lexicographically larger elements (exclude
93
///               same timepoints from the result).
94
///
95
/// @return { Space[] -> Scatter[] }
96
///         A map to all timepoints that happen after the timepoints the input
97
///         map originally mapped to.
98
isl::map afterScatter(isl::map Map, bool Strict);
99
100
/// Piecewise afterScatter(isl::map,bool).
101
isl::union_map afterScatter(const isl::union_map &UMap, bool Strict);
102
103
/// Construct a range of timepoints between two timepoints.
104
///
105
/// Example:
106
/// From := { A[] -> [0]; B[] -> [0] }
107
/// To   := {             B[] -> [10]; C[] -> [20] }
108
///
109
/// Result:
110
/// { B[] -> [i] : 0 < i < 10 }
111
///
112
/// Note that A[] and C[] are not in the result because they do not have a start
113
/// or end timepoint. If a start (or end) timepoint is not unique, the first
114
/// (respectively last) is chosen.
115
///
116
/// @param From     { Space[] -> Scatter[] }
117
///                 Map to start timepoints.
118
/// @param To       { Space[] -> Scatter[] }
119
///                 Map to end timepoints.
120
/// @param InclFrom Whether to include the start timepoints in the result. In
121
///                 the example, this would add { B[] -> [0] }
122
/// @param InclTo   Whether to include the end timepoints in the result. In this
123
///                 example, this would add { B[] -> [10] }
124
///
125
/// @return { Space[] -> Scatter[] }
126
///         A map for each domain element of timepoints between two extreme
127
///         points, or nullptr if @p From or @p To is nullptr, or the isl max
128
///         operations is exceeded.
129
isl::map betweenScatter(isl::map From, isl::map To, bool InclFrom, bool InclTo);
130
131
/// Piecewise betweenScatter(isl::map,isl::map,bool,bool).
132
isl::union_map betweenScatter(isl::union_map From, isl::union_map To,
133
                              bool InclFrom, bool InclTo);
134
135
/// If by construction a union map is known to contain only a single map, return
136
/// it.
137
///
138
/// This function combines isl_map_from_union_map() and
139
/// isl_union_map_extract_map(). isl_map_from_union_map() fails if the map is
140
/// empty because it does not know which space it would be in.
141
/// isl_union_map_extract_map() on the other hand does not check whether there
142
/// is (at most) one isl_map in the union, i.e. how it has been constructed is
143
/// probably wrong.
144
isl::map singleton(isl::union_map UMap, isl::space ExpectedSpace);
145
146
/// If by construction an isl_union_set is known to contain only a single
147
/// isl_set, return it.
148
///
149
/// This function combines isl_set_from_union_set() and
150
/// isl_union_set_extract_set(). isl_map_from_union_set() fails if the set is
151
/// empty because it does not know which space it would be in.
152
/// isl_union_set_extract_set() on the other hand does not check whether there
153
/// is (at most) one isl_set in the union, i.e. how it has been constructed is
154
/// probably wrong.
155
isl::set singleton(isl::union_set USet, isl::space ExpectedSpace);
156
157
/// Determine how many dimensions the scatter space of @p Schedule has.
158
///
159
/// The schedule must not be empty and have equal number of dimensions of any
160
/// subspace it contains.
161
///
162
/// The implementation currently returns the maximum number of dimensions it
163
/// encounters, if different, and 0 if none is encountered. However, most other
164
/// code will most likely fail if one of these happen.
165
unsigned getNumScatterDims(const isl::union_map &Schedule);
166
167
/// Return the scatter space of a @p Schedule.
168
///
169
/// This is basically the range space of the schedule map, but harder to
170
/// determine because it is an isl_union_map.
171
isl::space getScatterSpace(const isl::union_map &Schedule);
172
173
/// Construct an identity map for the given domain values.
174
///
175
/// There is no type resembling isl_union_space, hence we have to pass an
176
/// isl_union_set as the map's domain and range space.
177
///
178
/// @param USet           { Space[] }
179
///                       The returned map's domain and range.
180
/// @param RestrictDomain If true, the returned map only maps elements contained
181
///                       in @p USet and no other. If false, it returns an
182
///                       overapproximation with the identity maps of any space
183
///                       in @p USet, not just the elements in it.
184
///
185
/// @return { Space[] -> Space[] }
186
///         A map that maps each value of @p USet to itself.
187
isl::union_map makeIdentityMap(const isl::union_set &USet, bool RestrictDomain);
188
189
/// Reverse the nested map tuple in @p Map's domain.
190
///
191
/// @param Map { [Space1[] -> Space2[]] -> Space3[] }
192
///
193
/// @return { [Space2[] -> Space1[]] -> Space3[] }
194
isl::map reverseDomain(isl::map Map);
195
196
/// Piecewise reverseDomain(isl::map).
197
isl::union_map reverseDomain(const isl::union_map &UMap);
198
199
/// Add a constant to one dimension of a set.
200
///
201
/// @param Map    The set to shift a dimension in.
202
/// @param Pos    The dimension to shift. If negative, the dimensions are
203
///               counted from the end instead from the beginning. E.g. -1 is
204
///               the last dimension in the tuple.
205
/// @param Amount The offset to add to the specified dimension.
206
///
207
/// @return The modified set.
208
isl::set shiftDim(isl::set Set, int Pos, int Amount);
209
210
/// Piecewise shiftDim(isl::set,int,int).
211
isl::union_set shiftDim(isl::union_set USet, int Pos, int Amount);
212
213
/// Add a constant to one dimension of a map.
214
///
215
/// @param Map    The map to shift a dimension in.
216
/// @param Type   A tuple of @p Map which contains the dimension to shift.
217
/// @param Pos    The dimension to shift. If negative, the dimensions are
218
/// counted from the end instead from the beginning. Eg. -1 is the last
219
/// dimension in the tuple.
220
/// @param Amount The offset to add to the specified dimension.
221
///
222
/// @return The modified map.
223
isl::map shiftDim(isl::map Map, isl::dim Dim, int Pos, int Amount);
224
225
/// Add a constant to one dimension of a each map in a union map.
226
///
227
/// @param UMap   The maps to shift a dimension in.
228
/// @param Type   The tuple which contains the dimension to shift.
229
/// @param Pos    The dimension to shift. If negative, the dimensions are
230
///               counted from the ends of each map of union instead from their
231
///               beginning. E.g. -1 is the last dimension of any map.
232
/// @param Amount The offset to add to the specified dimension.
233
///
234
/// @return The union of all modified maps.
235
isl::union_map shiftDim(isl::union_map UMap, isl::dim Dim, int Pos, int Amount);
236
237
/// Simplify a set inplace.
238
void simplify(isl::set &Set);
239
240
/// Simplify a union set inplace.
241
void simplify(isl::union_set &USet);
242
243
/// Simplify a map inplace.
244
void simplify(isl::map &Map);
245
246
/// Simplify a union map inplace.
247
void simplify(isl::union_map &UMap);
248
249
/// Compute the reaching definition statement or the next overwrite for each
250
/// definition of an array element.
251
///
252
/// The reaching definition of an array element at a specific timepoint is the
253
/// statement instance that has written the current element's content.
254
/// Alternatively, this function determines for each timepoint and element which
255
/// write is going to overwrite an element at a future timepoint. This can be
256
/// seen as "reaching definition in reverse" where definitions are found in the
257
/// past.
258
///
259
/// For example:
260
///
261
/// Schedule := { Write[] -> [0]; Overwrite[] -> [10] }
262
/// Defs := { Write[] -> A[5]; Overwrite[] -> A[5] }
263
///
264
/// If index 5 of array A is written at timepoint 0 and 10, the resulting
265
/// reaching definitions are:
266
///
267
/// { [A[5] -> [i]] -> Write[] : 0 < i < 10;
268
///   [A[5] -> [i]] -> Overwrite[] : 10 < i }
269
///
270
/// Between timepoint 0 (Write[]) and timepoint 10 (Overwrite[]), the
271
/// content of A[5] is written by statement instance Write[] and after
272
/// timepoint 10 by Overwrite[]. Values not defined in the map have no known
273
/// definition. This includes the statement instance timepoints themselves,
274
/// because reads at those timepoints could either read the old or the new
275
/// value, defined only by the statement itself. But this can be changed by @p
276
/// InclPrevDef and @p InclNextDef. InclPrevDef=false and InclNextDef=true
277
/// returns a zone. Unless @p InclPrevDef and @p InclNextDef are both true,
278
/// there is only one unique definition per element and timepoint.
279
///
280
/// @param Schedule    { DomainWrite[] -> Scatter[] }
281
///                    Schedule of (at least) all array writes. Instances not in
282
///                    @p Writes are ignored.
283
/// @param Writes      { DomainWrite[] -> Element[] }
284
///                    Elements written to by the statement instances.
285
/// @param Reverse     If true, look for definitions in the future. That is,
286
///                    find the write that is overwrites the current value.
287
/// @param InclPrevDef Include the definition's timepoint to the set of
288
///                    well-defined elements (any load at that timepoint happen
289
///                    at the writes). In the example, enabling this option adds
290
///                    {[A[5] -> [0]] -> Write[]; [A[5] -> [10]] -> Overwrite[]}
291
///                    to the result.
292
/// @param InclNextDef Whether to assume that at the timepoint where an element
293
///                    is overwritten, it still contains the old value (any load
294
///                    at that timepoint would happen before the overwrite). In
295
///                    this example, enabling this adds
296
///                    { [A[] -> [10]] -> Write[] } to the result.
297
///
298
/// @return { [Element[] -> Scatter[]] -> DomainWrite[] }
299
///         The reaching definitions or future overwrite as described above, or
300
///         nullptr if either @p Schedule or @p Writes is nullptr, or the isl
301
///         max operations count has exceeded.
302
isl::union_map computeReachingWrite(isl::union_map Schedule,
303
                                    isl::union_map Writes, bool Reverse,
304
                                    bool InclPrevDef, bool InclNextDef);
305
306
/// Compute the timepoints where the contents of an array element are not used.
307
///
308
/// An element is unused at a timepoint when the element is overwritten in
309
/// the future, but it is not read in between. Another way to express this: the
310
/// time from when the element is written, to the most recent read before it, or
311
/// infinitely into the past if there is no read before. Such unused elements
312
/// can be overwritten by any value without changing the scop's semantics. An
313
/// example:
314
///
315
/// Schedule := { Read[] -> [0]; Write[] -> [10]; Def[] -> [20] }
316
/// Writes := { Write[] -> A[5]; Def[] -> A[6] }
317
/// Reads := { Read[] -> A[5] }
318
///
319
/// The result is:
320
///
321
/// { A[5] -> [i] : 0 < i < 10;
322
///   A[6] -> [i] : i < 20 }
323
///
324
/// That is, A[5] is unused between timepoint 0 (the read) and timepoint 10 (the
325
/// write). A[6] is unused before timepoint 20, but might be used after the
326
/// scop's execution (A[5] and any other A[i] as well). Use InclLastRead=false
327
/// and InclWrite=true to interpret the result as zone.
328
///
329
/// @param Schedule          { Domain[] -> Scatter[] }
330
///                          The schedule of (at least) all statement instances
331
///                          occurring in @p Writes or @p Reads. All other
332
///                          instances are ignored.
333
/// @param Writes            { DomainWrite[] -> Element[] }
334
///                          Elements written to by the statement instances.
335
/// @param Reads             { DomainRead[] -> Element[] }
336
///                          Elements read from by the statement instances.
337
/// @param ReadEltInSameInst Whether a load reads the value from a write
338
///                          that is scheduled at the same timepoint (Writes
339
///                          happen before reads). Otherwise, loads use the
340
///                          value of an element that it had before the
341
///                          timepoint (Reads before writes). For example:
342
///                          { Read[] -> [0]; Write[] -> [0] }
343
///                          With ReadEltInSameInst=false it is assumed that the
344
///                          read happens before the write, such that the
345
///                          element is never unused, or just at timepoint 0,
346
///                          depending on InclLastRead/InclWrite.
347
///                          With ReadEltInSameInst=false it assumes that the
348
///                          value just written is used. Anything before
349
///                          timepoint 0 is considered unused.
350
/// @param InclLastRead      Whether a timepoint where an element is last read
351
///                          counts as unused (the read happens at the beginning
352
///                          of its timepoint, and nothing (else) can use it
353
///                          during the timepoint). In the example, this option
354
///                          adds { A[5] -> [0] } to the result.
355
/// @param InclWrite         Whether the timepoint where an element is written
356
///                          itself counts as unused (the write happens at the
357
///                          end of its timepoint; no (other) operations uses
358
///                          the element during the timepoint). In this example,
359
///                          this adds
360
///                          { A[5] -> [10]; A[6] -> [20] } to the result.
361
///
362
/// @return { Element[] -> Scatter[] }
363
///         The unused timepoints as defined above, or nullptr if either @p
364
///         Schedule, @p Writes are @p Reads is nullptr, or the ISL max
365
///         operations count is exceeded.
366
isl::union_map computeArrayUnused(isl::union_map Schedule,
367
                                  isl::union_map Writes, isl::union_map Reads,
368
                                  bool ReadEltInSameInst, bool InclLastRead,
369
                                  bool InclWrite);
370
371
/// Convert a zone (range between timepoints) to timepoints.
372
///
373
/// A zone represents the time between (integer) timepoints, but not the
374
/// timepoints themselves. This function can be used to determine whether a
375
/// timepoint lies within a zone.
376
///
377
/// For instance, the range (1,3), representing the time between 1 and 3, is
378
/// represented by the zone
379
///
380
/// { [i] : 1 < i <= 3 }
381
///
382
/// The set of timepoints that lie completely within this range is
383
///
384
/// { [i] : 1 < i < 3 }
385
///
386
/// A typical use-case is the range in which a value written by a store is
387
/// available until it is overwritten by another value. If the write is at
388
/// timepoint 1 and its value is overwritten by another value at timepoint 3,
389
/// the value is available between those timepoints: timepoint 2 in this
390
/// example.
391
///
392
///
393
/// When InclStart is true, the range is interpreted left-inclusive, i.e. adds
394
/// the timepoint 1 to the result:
395
///
396
/// { [i] : 1 <= i < 3 }
397
///
398
/// In the use-case mentioned above that means that the value written at
399
/// timepoint 1 is already available in timepoint 1 (write takes place before
400
/// any read of it even if executed at the same timepoint)
401
///
402
/// When InclEnd is true, the range is interpreted right-inclusive, i.e. adds
403
/// the timepoint 3 to the result:
404
///
405
/// { [i] : 1 < i <= 3 }
406
///
407
/// In the use-case mentioned above that means that although the value is
408
/// overwritten in timepoint 3, the old value is still available at timepoint 3
409
/// (write takes place after any read even if executed at the same timepoint)
410
///
411
/// @param Zone      { Zone[] }
412
/// @param InclStart Include timepoints adjacent to the beginning of a zone.
413
/// @param InclEnd   Include timepoints adjacent to the ending of a zone.
414
///
415
/// @return { Scatter[] }
416
isl::union_set convertZoneToTimepoints(isl::union_set Zone, bool InclStart,
417
                                       bool InclEnd);
418
419
/// Like convertZoneToTimepoints(isl::union_set,InclStart,InclEnd), but convert
420
/// either the domain or the range of a map.
421
isl::union_map convertZoneToTimepoints(isl::union_map Zone, isl::dim Dim,
422
                                       bool InclStart, bool InclEnd);
423
424
/// Overload of convertZoneToTimepoints(isl::map,InclStart,InclEnd) to process
425
/// only a single map.
426
isl::map convertZoneToTimepoints(isl::map Zone, isl::dim Dim, bool InclStart,
427
                                 bool InclEnd);
428
429
/// Distribute the domain to the tuples of a wrapped range map.
430
///
431
/// @param Map { Domain[] -> [Range1[] -> Range2[]] }
432
///
433
/// @return { [Domain[] -> Range1[]] -> [Domain[] -> Range2[]] }
434
isl::map distributeDomain(isl::map Map);
435
436
/// Apply distributeDomain(isl::map) to each map in the union.
437
isl::union_map distributeDomain(isl::union_map UMap);
438
439
/// Prepend a space to the tuples of a map.
440
///
441
/// @param UMap   { Domain[] -> Range[] }
442
/// @param Factor { Factor[] }
443
///
444
/// @return { [Factor[] -> Domain[]] -> [Factor[] -> Range[]] }
445
isl::union_map liftDomains(isl::union_map UMap, isl::union_set Factor);
446
447
/// Apply a map to the 'middle' of another relation.
448
///
449
/// @param UMap { [DomainDomain[] -> DomainRange[]] -> Range[] }
450
/// @param Func { DomainRange[] -> NewDomainRange[] }
451
///
452
/// @return { [DomainDomain[] -> NewDomainRange[]] -> Range[] }
453
isl::union_map applyDomainRange(isl::union_map UMap, isl::union_map Func);
454
455
/// Intersect the range of @p Map with @p Range.
456
///
457
/// Since @p Map is an isl::map, the result will be a single space, even though
458
/// @p Range is an isl::union_set. This is the only difference to
459
/// isl::map::intersect_range and isl::union_map::interset_range.
460
///
461
/// @param Map   { Domain[] -> Range[] }
462
/// @param Range { Range[] }
463
///
464
/// @return { Domain[] -> Range[] }
465
isl::map intersectRange(isl::map Map, isl::union_set Range);
466
467
/// If @p PwAff maps to a constant, return said constant. If @p Max/@p Min, it
468
/// can also be a piecewise constant and it would return the minimum/maximum
469
/// value. Otherwise, return NaN.
470
isl::val getConstant(isl::pw_aff PwAff, bool Max, bool Min);
471
472
/// Dump a description of the argument to llvm::errs().
473
///
474
/// In contrast to isl's dump function, there are a few differences:
475
/// - Each polyhedron (pieces) is written on its own line.
476
/// - Spaces are sorted by structure. E.g. maps with same domain space are
477
///   grouped. Isl sorts them according to the space's hash function.
478
/// - Pieces of the same space are sorted using their lower bound.
479
/// - A more compact to_str representation is used instead of Isl's dump
480
///   functions that try to show the internal representation.
481
///
482
/// The goal is to get a better understandable representation that is also
483
/// useful to compare two sets. As all dump() functions, its intended use is to
484
/// be called in a debugger only.
485
///
486
/// isl_map_dump example:
487
/// [p_0, p_1, p_2] -> { Stmt0[i0] -> [o0, o1] : (o0 = i0 and o1 = 0 and i0 > 0
488
/// and i0 <= 5 - p_2) or (i0 = 0 and o0 = 0 and o1 = 0); Stmt3[i0] -> [o0, o1]
489
/// : (o0 = i0 and o1 = 3 and i0 > 0 and i0 <= 5 - p_2) or (i0 = 0 and o0 = 0
490
/// and o1 = 3); Stmt2[i0] -> [o0, o1] : (o0 = i0 and o1 = 1 and i0 >= 3 + p_0 -
491
/// p_1 and i0 > 0 and i0 <= 5 - p_2) or (o0 = i0 and o1 = 1 and i0 > 0 and i0
492
/// <= 5 - p_2 and i0 < p_0 - p_1) or (i0 = 0 and o0 = 0 and o1 = 1 and p_1 >= 3
493
/// + p_0) or (i0 = 0 and o0 = 0 and o1 = 1 and p_1 < p_0) or (p_0 = 0 and i0 =
494
/// 2 - p_1 and o0 = 2 - p_1 and o1 = 1 and p_2 <= 3 + p_1 and p_1 <= 1) or (p_1
495
/// = 1 + p_0 and i0 = 0 and o0 = 0 and o1 = 1) or (p_0 = 0 and p_1 = 2 and i0 =
496
/// 0 and o0 = 0 and o1 = 1) or (p_0 = -1 and p_1 = -1 and i0 = 0 and o0 = 0 and
497
/// o1 = 1); Stmt1[i0] -> [o0, o1] : (p_0 = -1 and i0 = 1 - p_1 and o0 = 1 - p_1
498
/// and o1 = 2 and p_2 <= 4 + p_1 and p_1 <= 0) or (p_0 = 0 and i0 = -p_1 and o0
499
/// = -p_1 and o1 = 2 and p_2 <= 5 + p_1 and p_1 < 0) or (p_0 = -1 and p_1 = 1
500
/// and i0 = 0 and o0 = 0 and o1 = 2) or (p_0 = 0 and p_1 = 0 and i0 = 0 and o0
501
/// = 0 and o1 = 2) }
502
///
503
/// dumpPw example (same set):
504
/// [p_0, p_1, p_2] -> {
505
///   Stmt0[0] -> [0, 0];
506
///   Stmt0[i0] -> [i0, 0] : 0 < i0 <= 5 - p_2;
507
///   Stmt1[0] -> [0, 2] : p_1 = 1 and p_0 = -1;
508
///   Stmt1[0] -> [0, 2] : p_1 = 0 and p_0 = 0;
509
///   Stmt1[1 - p_1] -> [1 - p_1, 2] : p_0 = -1 and p_1 <= 0 and p_2 <= 4 + p_1;
510
///   Stmt1[-p_1] -> [-p_1, 2] : p_0 = 0 and p_1 < 0 and p_2 <= 5 + p_1;
511
///   Stmt2[0] -> [0, 1] : p_1 >= 3 + p_0;
512
///   Stmt2[0] -> [0, 1] : p_1 < p_0;
513
///   Stmt2[0] -> [0, 1] : p_1 = 1 + p_0;
514
///   Stmt2[0] -> [0, 1] : p_1 = 2 and p_0 = 0;
515
///   Stmt2[0] -> [0, 1] : p_1 = -1 and p_0 = -1;
516
///   Stmt2[i0] -> [i0, 1] : i0 >= 3 + p_0 - p_1 and 0 < i0 <= 5 - p_2;
517
///   Stmt2[i0] -> [i0, 1] : 0 < i0 <= 5 - p_2 and i0 < p_0 - p_1;
518
///   Stmt2[2 - p_1] -> [2 - p_1, 1] : p_0 = 0 and p_1 <= 1 and p_2 <= 3 + p_1;
519
///   Stmt3[0] -> [0, 3];
520
///   Stmt3[i0] -> [i0, 3] : 0 < i0 <= 5 - p_2
521
/// }
522
/// @{
523
void dumpPw(const isl::set &Set);
524
void dumpPw(const isl::map &Map);
525
void dumpPw(const isl::union_set &USet);
526
void dumpPw(const isl::union_map &UMap);
527
void dumpPw(__isl_keep isl_set *Set);
528
void dumpPw(__isl_keep isl_map *Map);
529
void dumpPw(__isl_keep isl_union_set *USet);
530
void dumpPw(__isl_keep isl_union_map *UMap);
531
/// @}
532
533
/// Dump all points of the argument to llvm::errs().
534
///
535
/// Before being printed by dumpPw(), the argument's pieces are expanded to
536
/// contain only single points. If a dimension is unbounded, it keeps its
537
/// representation.
538
///
539
/// This is useful for debugging reduced cases where parameters are set to
540
/// constants to keep the example simple. Such sets can still contain
541
/// existential dimensions which makes the polyhedral hard to compare.
542
///
543
/// Example:
544
///   { [MemRef_A[i0] -> [i1]] : (exists (e0 = floor((1 + i1)/3): i0 = 1 and 3e0
545
///   <= i1 and 3e0 >= -1 + i1 and i1 >= 15 and i1 <= 25)) or (exists (e0 =
546
///   floor((i1)/3): i0 = 0 and 3e0 < i1 and 3e0 >= -2 + i1 and i1 > 0 and i1 <=
547
///   11)) }
548
///
549
/// dumpExpanded:
550
/// {
551
///   [MemRef_A[0] ->[1]];
552
///   [MemRef_A[0] ->[2]];
553
///   [MemRef_A[0] ->[4]];
554
///   [MemRef_A[0] ->[5]];
555
///   [MemRef_A[0] ->[7]];
556
///   [MemRef_A[0] ->[8]];
557
///   [MemRef_A[0] ->[10]];
558
///   [MemRef_A[0] ->[11]];
559
///   [MemRef_A[1] ->[15]];
560
///   [MemRef_A[1] ->[16]];
561
///   [MemRef_A[1] ->[18]];
562
///   [MemRef_A[1] ->[19]];
563
///   [MemRef_A[1] ->[21]];
564
///   [MemRef_A[1] ->[22]];
565
///   [MemRef_A[1] ->[24]];
566
///   [MemRef_A[1] ->[25]]
567
/// }
568
/// @{
569
void dumpExpanded(const isl::set &Set);
570
void dumpExpanded(const isl::map &Map);
571
void dumpExpanded(const isl::union_set &USet);
572
void dumpExpanded(const isl::union_map &UMap);
573
void dumpExpanded(__isl_keep isl_set *Set);
574
void dumpExpanded(__isl_keep isl_map *Map);
575
void dumpExpanded(__isl_keep isl_union_set *USet);
576
void dumpExpanded(__isl_keep isl_union_map *UMap);
577
/// @}
578
} // namespace polly
579
580
#endif /* POLLY_ISLTOOLS_H */