@@ -31,71 +31,12 @@ namespace polyhedral {
31
31
using detail::ScheduleTree;
32
32
33
33
namespace {
34
- std::pair<isl::val, isl::aff> outputRange (
35
- isl::basic_set wrappedAccess,
36
- isl::constraint cstr) {
37
- auto emptyRange =
38
- std::make_pair (isl::val::nan (wrappedAccess.get_ctx ()), isl::aff ());
39
- int pos = cstr.dim (isl::dim_type::set) - 1 ;
40
- if (!cstr.is_lower_bound (isl::dim_type::set, pos)) {
41
- return emptyRange;
42
- }
43
- if (cstr.involves_dims (isl::dim_type::div, 0 , cstr.dim (isl::dim_type::div))) {
44
- return emptyRange;
45
- }
46
-
47
- auto lowerBound = cstr.get_bound (isl::dim_type::set, pos).ceil ();
48
- auto aff = lowerBound.neg ().add_coefficient_si (isl::dim_type::in, pos, 1 );
49
- lowerBound = lowerBound.drop_dims (isl::dim_type::in, pos, 1 );
50
-
51
- auto range = wrappedAccess.max_val (aff);
52
- if (range.is_int ()) {
53
- return std::make_pair (range + 1 , lowerBound);
54
- }
55
- return emptyRange;
56
- }
57
-
58
- std::pair<isl::val, isl::aff> outputRangeSingle (isl::map access) {
59
- CHECK_EQ (access.dim (isl::dim_type::out), 1u )
60
- << " expected 1-dim output, call outputRanges instead" ;
61
- access = access.detect_equalities ();
62
- auto wrappedAccess = access.wrap ().flatten ().compute_divs ().simple_hull ();
34
+ ScopedFootprint outputRanges (isl::map access) {
35
+ ScopedFootprint footprint;
63
36
64
37
// TODO: also compute strides
65
38
66
- isl::val minRange;
67
- isl::aff lowerBoundWithMinRange;
68
- for (auto cstr : wrappedAccess.get_constraint_list ()) {
69
- auto range = outputRange (wrappedAccess, cstr);
70
- if (range.first .is_nan ()) {
71
- continue ;
72
- }
73
- if (minRange.is_null () || range.first < minRange) {
74
- minRange = range.first ;
75
- lowerBoundWithMinRange = range.second ;
76
- }
77
- }
78
- if (minRange.is_null ()) {
79
- return std::make_pair (
80
- isl::val::nan (access.get_ctx ()), lowerBoundWithMinRange);
81
- }
82
-
83
- return std::make_pair (minRange, lowerBoundWithMinRange);
84
- }
85
-
86
- ScopedFootprint outputRanges (isl::map access) {
87
- int nSubscripts = access.dim (isl::dim_type::out);
88
- ScopedFootprint footprint;
89
- for (int i = 0 ; i < nSubscripts; ++i) {
90
- auto singleDim =
91
- access.project_out (isl::dim_type::out, 0 , i)
92
- .project_out (isl::dim_type::out, 1 , nSubscripts - i - 1 );
93
- auto range = outputRangeSingle (singleDim);
94
- if (range.first .is_nan ()) {
95
- return {};
96
- }
97
- footprint.emplace_back (range.second , range.first );
98
- }
39
+ footprint.box = access.get_range_simple_fixed_box_hull ();
99
40
return footprint;
100
41
}
101
42
@@ -126,7 +67,7 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
126
67
group->references .push_back (std::move (ref));
127
68
group->approximation = outputRanges (scopedAccess);
128
69
129
- if (group->approximation .size () != scopedAccess. dim (isl::dim_type::out )) {
70
+ if (! group->approximation .box . is_valid ( )) {
130
71
std::stringstream ss;
131
72
ss << " could not compute rectangular overapproximation of: "
132
73
<< scopedAccess;
@@ -137,32 +78,25 @@ std::unique_ptr<TensorReferenceGroup> TensorReferenceGroup::makeSingleton(
137
78
}
138
79
139
80
isl::set ScopedFootprint::footprint (isl::set domain) const {
140
- auto space = add_range (domain .get_space (), size () );
81
+ auto space = box .get_space ();
141
82
auto accessed = isl::map::universe (space).intersect_domain (domain);
142
83
auto lspace = isl::local_space (accessed.get_space ().range ());
143
84
144
- for (size_t i = 0 ; i < size (); ++i) {
145
- auto dim = at (i);
85
+ for (size_t i = 0 ; i < dim (); ++i) {
86
+ auto dimLowerBound = lowerBound (i);
146
87
auto rhs = isl::aff (lspace, isl::dim_type::set, i);
147
- isl::map partial = (isl::aff_map (dim. lowerBound ) <= rhs) &
148
- (isl::aff_map (dim. lowerBound + dim. size ) > rhs);
88
+ isl::map partial = (isl::aff_map (dimLowerBound ) <= rhs) &
89
+ (isl::aff_map (dimLowerBound + size (i) ) > rhs);
149
90
accessed = accessed & partial;
150
91
}
151
92
return accessed.range ();
152
93
}
153
94
154
95
isl::multi_aff ScopedFootprint::lowerBounds () const {
155
- if (size () == 0 ) {
96
+ if (dim () == 0 ) {
156
97
throw promotion::PromotionNYI (" promotion for scalars" );
157
98
}
158
- auto space = add_range (at (0 ).lowerBound .get_space ().domain (), size ());
159
- auto ma = isl::multi_aff::zero (space);
160
-
161
- int i = 0 ;
162
- for (const auto & a : *this ) {
163
- ma = ma.set_aff (i++, a.lowerBound );
164
- }
165
- return ma;
99
+ return box.get_offset ();
166
100
}
167
101
168
102
bool TensorReferenceGroup::isReadOnly () const {
@@ -193,9 +127,9 @@ isl::set TensorReferenceGroup::promotedFootprint() const {
193
127
194
128
std::vector<size_t > TensorReferenceGroup::approximationSizes () const {
195
129
std::vector<size_t > result;
196
- result.reserve (approximation.size ());
197
- for (const auto & dim : approximation) {
198
- result.push_back (dim. size .get_num_si ());
130
+ result.reserve (approximation.dim ());
131
+ for (const auto & size : approximation. box . get_size (). get_val_list () ) {
132
+ result.push_back (size.get_num_si ());
199
133
}
200
134
return result;
201
135
}
@@ -382,9 +316,7 @@ isl::multi_aff TensorReferenceGroup::promotion() const {
382
316
// lower bounds space is S -> P; which we transform into [S -> O] -> P
383
317
auto lowerBounds = approximation.lowerBounds ().pullback (
384
318
isl::multi_aff::domain_map (accessSpace));
385
- auto promotion = isl::multi_aff::range_map (accessSpace)
386
- .reset_tuple_id (isl::dim_type::out) -
387
- lowerBounds;
319
+ auto promotion = isl::multi_aff::range_map (accessSpace) - lowerBounds;
388
320
return promotion;
389
321
}
390
322
0 commit comments