Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -3313,97 +3313,74 @@ Scop::~Scop() = default; void Scop::foldSizeConstantsToRight() { - isl_union_set *Accessed = isl_union_map_range(getAccesses().release()); + isl::union_set Accessed = getAccesses().range(); for (auto Array : arrays()) { if (Array->getNumberOfDimensions() <= 1) continue; - isl_space *Space = Array->getSpace().release(); + isl::space Space = Array->getSpace(); + Space = Space.align_params(Accessed.get_space()); - Space = isl_space_align_params(Space, isl_union_set_get_space(Accessed)); - - if (!isl_union_set_contains(Accessed, Space)) { - isl_space_free(Space); + if (!Accessed.contains(Space)) continue; - } - isl_set *Elements = isl_union_set_extract_set(Accessed, Space); - - isl_map *Transform = - isl_map_universe(isl_space_map_from_set(Array->getSpace().release())); + isl::set Elements = Accessed.extract_set(Space); + isl::map Transform = isl::map::universe(Array->getSpace().map_from_set()); std::vector Int; - - int Dims = isl_set_dim(Elements, isl_dim_set); + int Dims = Elements.dim(isl::dim::set); for (int i = 0; i < Dims; i++) { - isl_set *DimOnly = - isl_set_project_out(isl_set_copy(Elements), isl_dim_set, 0, i); - DimOnly = isl_set_project_out(DimOnly, isl_dim_set, 1, Dims - i - 1); - DimOnly = isl_set_lower_bound_si(DimOnly, isl_dim_set, 0, 0); + isl::set DimOnly = isl::set(Elements).project_out(isl::dim::set, 0, i); + DimOnly = DimOnly.project_out(isl::dim::set, 1, Dims - i - 1); + DimOnly = DimOnly.lower_bound_si(isl::dim::set, 0, 0); - isl_basic_set *DimHull = isl_set_affine_hull(DimOnly); + isl::basic_set DimHull = DimOnly.affine_hull(); if (i == Dims - 1) { Int.push_back(1); - Transform = isl_map_equate(Transform, isl_dim_in, i, isl_dim_out, i); - isl_basic_set_free(DimHull); + Transform = Transform.equate(isl::dim::in, i, isl::dim::out, i); continue; } - if (isl_basic_set_dim(DimHull, isl_dim_div) == 1) { - isl_aff *Diff = isl_basic_set_get_div(DimHull, 0); - isl_val *Val = isl_aff_get_denominator_val(Diff); - isl_aff_free(Diff); + if (DimHull.dim(isl::dim::div) == 1) { + isl::aff Diff = DimHull.get_div(0); + isl::val Val = Diff.get_denominator_val(); int ValInt = 1; - - if (isl_val_is_int(Val)) { + if (Val.is_int()) { auto ValAPInt = APIntFromVal(Val); if (ValAPInt.isSignedIntN(32)) ValInt = ValAPInt.getSExtValue(); } else { - isl_val_free(Val); } Int.push_back(ValInt); - - isl_constraint *C = isl_constraint_alloc_equality( - isl_local_space_from_space(isl_map_get_space(Transform))); - C = isl_constraint_set_coefficient_si(C, isl_dim_out, i, ValInt); - C = isl_constraint_set_coefficient_si(C, isl_dim_in, i, -1); - Transform = isl_map_add_constraint(Transform, C); - isl_basic_set_free(DimHull); + isl::constraint C = isl::constraint::alloc_equality( + isl::local_space(Transform.get_space())); + C = C.set_coefficient_si(isl::dim::out, i, ValInt); + C = C.set_coefficient_si(isl::dim::in, i, -1); + Transform = Transform.add_constraint(C); continue; } - isl_basic_set *ZeroSet = isl_basic_set_copy(DimHull); - ZeroSet = isl_basic_set_fix_si(ZeroSet, isl_dim_set, 0, 0); + isl::basic_set ZeroSet = isl::basic_set(DimHull); + ZeroSet = ZeroSet.fix_si(isl::dim::set, 0, 0); int ValInt = 1; - if (isl_basic_set_is_equal(ZeroSet, DimHull)) { + if (ZeroSet.is_equal(DimHull)) { ValInt = 0; } Int.push_back(ValInt); - Transform = isl_map_equate(Transform, isl_dim_in, i, isl_dim_out, i); - isl_basic_set_free(DimHull); - isl_basic_set_free(ZeroSet); + Transform = Transform.equate(isl::dim::in, i, isl::dim::out, i); } - isl_set *MappedElements = isl_map_domain(isl_map_copy(Transform)); - - if (!isl_set_is_subset(Elements, MappedElements)) { - isl_set_free(Elements); - isl_set_free(MappedElements); - isl_map_free(Transform); + isl::set MappedElements = isl::map(Transform).domain(); + if (!Elements.is_subset(MappedElements)) continue; - } - - isl_set_free(MappedElements); bool CanFold = true; - if (Int[0] <= 1) CanFold = false; @@ -3412,18 +3389,13 @@ if (Int[0] != Int[i] && Int[i]) CanFold = false; - if (!CanFold) { - isl_set_free(Elements); - isl_map_free(Transform); + if (!CanFold) continue; - } for (auto &Access : AccessFunctions) if (Access->getScopArrayInfo() == Array) - Access->setAccessRelation(Access->getAccessRelation().apply_range( - isl::manage_copy(Transform))); - - isl_map_free(Transform); + Access->setAccessRelation( + Access->getAccessRelation().apply_range(Transform)); std::vector Sizes; for (unsigned i = 0; i < NumDims; i++) { @@ -3435,10 +3407,7 @@ } Array->updateSizes(Sizes, false /* CheckConsistency */); - - isl_set_free(Elements); } - isl_union_set_free(Accessed); } void Scop::markFortranArrays() {