Index: include/polly/Support/ISLTools.h =================================================================== --- include/polly/Support/ISLTools.h +++ include/polly/Support/ISLTools.h @@ -19,6 +19,60 @@ namespace polly { +/// A set of list accessors which make the subsequent iterator implementation +/// easier. +inline isl::basic_set list_get(isl::basic_set_list list, long idx) { + return list.get_basic_set(idx); +} +inline isl::set list_get(isl::set_list list, long idx) { + return list.get_set(idx); +} +inline isl::basic_map list_get(isl::basic_map_list list, long idx) { + return list.get_basic_map(idx); +} +inline isl::map list_get(isl::map_list list, long idx) { + return list.get_map(idx); +} + +/// A set of list size functions which make the subsequent iterator +/// implementation easier. +inline int list_size(isl::basic_set_list list) { return list.n_basic_set(); } +inline int list_size(isl::set_list list) { return list.n_set(); } +inline int list_size(isl::basic_map_list list) { return list.n_basic_map(); } +inline int list_size(isl::map_list list) { return list.n_map(); } + +/// An iterator for isl lists, which enables e.g. C++ foreach loops. +template struct list_iterator { +private: + list_type &list; + int position; + +public: + list_iterator(list_type &list, int position) + : list(list), position(position) {} + + element_type operator*() { return list_get(list, position); } + + void operator++() { position++; } + + bool operator!=(const list_iterator &that) { + return that.position != position; + } +}; + +template +auto begin(list_type &list) + -> list_iterator { + return list_iterator(list, 0); +} + +template +auto end(list_type &list) + -> list_iterator { + return list_iterator(list, + list_size(list)); +} + /// Return the range elements that are lexicographically smaller. /// /// @param Map { Space[] -> Scatter[] } Index: lib/Support/ISLTools.cpp =================================================================== --- lib/Support/ISLTools.cpp +++ lib/Support/ISLTools.cpp @@ -89,11 +89,12 @@ isl::union_map polly::beforeScatter(isl::union_map UMap, bool Strict) { isl::union_map Result = isl::union_map::empty(UMap.get_space()); - UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat { + + for (isl::map Map : UMap.get_map_list()) { isl::map After = beforeScatter(Map, Strict); Result = Result.add_map(After); - return isl::stat::ok; - }); + } + return Result; } @@ -106,11 +107,10 @@ isl::union_map polly::afterScatter(const isl::union_map &UMap, bool Strict) { isl::union_map Result = isl::union_map::empty(UMap.get_space()); - UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat { + for (isl::map Map : UMap.get_map_list()) { isl::map After = afterScatter(Map, Strict); Result = Result.add_map(After); - return isl::stat::ok; - }); + } return Result; } @@ -158,10 +158,8 @@ unsigned polly::getNumScatterDims(const isl::union_map &Schedule) { unsigned Dims = 0; - Schedule.foreach_map([&Dims](isl::map Map) -> isl::stat { + for (isl::map Map : Schedule.get_map_list()) Dims = std::max(Dims, Map.dim(isl::dim::out)); - return isl::stat::ok; - }); return Dims; } @@ -176,13 +174,12 @@ isl::union_map polly::makeIdentityMap(const isl::union_set &USet, bool RestrictDomain) { isl::union_map Result = isl::union_map::empty(USet.get_space()); - USet.foreach_set([=, &Result](isl::set Set) -> isl::stat { + for (isl::set Set : USet.get_set_list()) { isl::map IdentityMap = isl::map::identity(Set.get_space().map_from_set()); if (RestrictDomain) IdentityMap = IdentityMap.intersect_domain(Set); Result = Result.add_map(IdentityMap); - return isl::stat::ok; - }); + } return Result; } @@ -196,11 +193,10 @@ isl::union_map polly::reverseDomain(const isl::union_map &UMap) { isl::union_map Result = isl::union_map::empty(UMap.get_space()); - UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat { + for (isl::map Map : UMap.get_map_list()) { auto Reversed = reverseDomain(std::move(Map)); Result = Result.add_map(Reversed); - return isl::stat::ok; - }); + } return Result; } @@ -218,11 +214,10 @@ isl::union_set polly::shiftDim(isl::union_set USet, int Pos, int Amount) { isl::union_set Result = isl::union_set::empty(USet.get_space()); - USet.foreach_set([=, &Result](isl::set Set) -> isl::stat { + for (isl::set Set : USet.get_set_list()) { isl::set Shifted = shiftDim(Set, Pos, Amount); Result = Result.add_set(Shifted); - return isl::stat::ok; - }); + } return Result; } @@ -259,11 +254,10 @@ int Amount) { isl::union_map Result = isl::union_map::empty(UMap.get_space()); - UMap.foreach_map([=, &Result](isl::map Map) -> isl::stat { + for (isl::map Map : UMap.get_map_list()) { isl::map Shifted = shiftDim(Map, Dim, Pos, Amount); Result = Result.add_map(Shifted); - return isl::stat::ok; - }); + } return Result; } @@ -474,13 +468,10 @@ isl::union_map polly::distributeDomain(isl::union_map UMap) { isl::union_map Result = isl::union_map::empty(UMap.get_space()); - isl::stat Success = UMap.foreach_map([=, &Result](isl::map Map) { + for (isl::map Map : UMap.get_map_list()) { auto Distributed = distributeDomain(Map); Result = Result.add_map(Distributed); - return isl::stat::ok; - }); - if (Success != isl::stat::ok) - return {}; + } return Result; } @@ -710,13 +701,12 @@ // Get all the polyhedra. std::vector BSets; - USet.foreach_set([&BSets](isl::set Set) -> isl::stat { - Set.foreach_basic_set([&BSets](isl::basic_set BSet) -> isl::stat { + + for (isl::set Set : USet.get_set_list()) { + for (isl::basic_set BSet : Set.get_basic_set_list()) { BSets.push_back(BSet); - return isl::stat::ok; - }); - return isl::stat::ok; - }); + } + } if (BSets.empty()) { OS << "{\n}\n"; @@ -785,10 +775,8 @@ /// { [0]; [1] } static isl::set expand(const isl::set &Set) { isl::set Expanded = isl::set::empty(Set.get_space()); - Set.foreach_basic_set([&](isl::basic_set BSet) -> isl::stat { + for (isl::basic_set BSet : Set.get_basic_set_list()) recursiveExpand(BSet, 0, Expanded); - return isl::stat::ok; - }); return Expanded; } @@ -797,11 +785,10 @@ /// @see expand(const isl::set) static isl::union_set expand(const isl::union_set &USet) { isl::union_set Expanded = isl::union_set::empty(USet.get_space()); - USet.foreach_set([&](isl::set Set) -> isl::stat { + for (isl::set Set : USet.get_set_list()) { isl::set SetExpanded = expand(Set); Expanded = Expanded.add_set(SetExpanded); - return isl::stat::ok; - }); + } return Expanded; }