Index: lib/Transform/DeadCodeElimination.cpp =================================================================== --- lib/Transform/DeadCodeElimination.cpp +++ lib/Transform/DeadCodeElimination.cpp @@ -42,6 +42,8 @@ #include "isl/union_map.h" #include "isl/union_set.h" +#include "isl-noexceptions.h" + using namespace llvm; using namespace polly; @@ -73,7 +75,7 @@ /// overwrite the same memory location and is consequently the only one that /// is visible after the execution of the SCoP. /// - isl_union_set *getLiveOut(Scop &S); + isl::union_set getLiveOut(Scop &S); bool eliminateDeadCode(Scop &S, int PreciseSteps); }; } // namespace @@ -90,21 +92,20 @@ // bounded write accesses can not overwrite all of the data-locations. As // this means may-writes are in the current situation always live, there is // no point in trying to remove them from the live-out set. -__isl_give isl_union_set *DeadCodeElim::getLiveOut(Scop &S) { - isl_union_map *Schedule = S.getSchedule(); - assert(Schedule && - "Schedules that contain extension nodes require special handling."); - isl_union_map *WriteIterations = isl_union_map_reverse(S.getMustWrites()); - isl_union_map *WriteTimes = - isl_union_map_apply_range(WriteIterations, isl_union_map_copy(Schedule)); - - isl_union_map *LastWriteTimes = isl_union_map_lexmax(WriteTimes); - isl_union_map *LastWriteIterations = isl_union_map_apply_range( - LastWriteTimes, isl_union_map_reverse(Schedule)); - - isl_union_set *Live = isl_union_map_range(LastWriteIterations); - Live = isl_union_set_union(Live, isl_union_map_domain(S.getMayWrites())); - return isl_union_set_coalesce(Live); +isl::union_set DeadCodeElim::getLiveOut(Scop &S) { + isl::union_map Schedule = isl::manage(S.getSchedule()); + isl::union_map MustWrites = isl::manage(S.getMustWrites()); + isl::union_map WriteIterations = MustWrites.reverse(); + isl::union_map WriteTimes = WriteIterations.apply_range(Schedule); + + isl::union_map LastWriteTimes = WriteTimes.lexmax(); + isl::union_map LastWriteIterations = + LastWriteTimes.apply_range(Schedule.reverse()); + + isl::union_set Live = LastWriteIterations.range(); + isl::union_map MayWrites = isl::manage(S.getMayWrites()); + Live = Live.unite(MayWrites.domain()); + return Live.coalesce(); } /// Performs polyhedral dead iteration elimination by: @@ -122,41 +123,37 @@ if (!D.hasValidDependences()) return false; - isl_union_set *Live = getLiveOut(S); - isl_union_map *Dep = - D.getDependences(Dependences::TYPE_RAW | Dependences::TYPE_RED); - Dep = isl_union_map_reverse(Dep); + isl::union_set Live = getLiveOut(S); + isl::union_map Dep = isl::manage( + D.getDependences(Dependences::TYPE_RAW | Dependences::TYPE_RED)); + Dep = Dep.reverse(); if (PreciseSteps == -1) - Live = isl_union_set_affine_hull(Live); + Live = Live.affine_hull(); - isl_union_set *OriginalDomain = S.getDomains(); + isl::union_set OriginalDomain = isl::manage(S.getDomains()); int Steps = 0; while (true) { - isl_union_set *Extra; Steps++; - Extra = - isl_union_set_apply(isl_union_set_copy(Live), isl_union_map_copy(Dep)); + isl::union_set Extra = Live.apply(Dep); - if (isl_union_set_is_subset(Extra, Live)) { - isl_union_set_free(Extra); + if (Extra.is_subset(Live)) break; - } - Live = isl_union_set_union(Live, Extra); + Live = Live.unite(Extra); if (Steps > PreciseSteps) { Steps = 0; - Live = isl_union_set_affine_hull(Live); + Live = Live.affine_hull(); } - Live = isl_union_set_intersect(Live, isl_union_set_copy(OriginalDomain)); + Live = Live.intersect(OriginalDomain); } - isl_union_map_free(Dep); - isl_union_set_free(OriginalDomain); - bool Changed = S.restrictDomains(isl_union_set_coalesce(Live)); + Live = Live.coalesce(); + + bool Changed = S.restrictDomains(Live.copy()); // FIXME: We can probably avoid the recomputation of all dependences by // updating them explicitly.