Index: include/polly/ScheduleOptimizer.h =================================================================== --- include/polly/ScheduleOptimizer.h +++ include/polly/ScheduleOptimizer.h @@ -71,8 +71,6 @@ extern bool DisablePollyTiling; -} // namespace polly - class ScheduleTreeOptimizer { public: /// Apply schedule tree transformations. @@ -354,4 +352,5 @@ /// relation. isl::set getPartialTilePrefixes(isl::set ScheduleRange, int VectorWidth); +} // namespace polly #endif // POLLY_SCHEDULEOPTIMIZER_H Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -40,10 +40,7 @@ #include "llvm/IR/ValueHandle.h" #include "llvm/Pass.h" #include "llvm/Support/Casting.h" -#include "isl/aff.h" -#include "isl/ctx.h" #include "isl/isl-noexceptions.h" -#include "isl/set.h" #include #include #include @@ -1174,7 +1171,7 @@ /// /// It is the union of the execution domains of the memory accesses in the /// InvariantAccesses list. - isl_set *ExecutionContext; + isl::set ExecutionContext; /// The type of the invariant access /// @@ -1326,7 +1323,7 @@ public: /// Get an isl_ctx pointer. - isl_ctx *getIslCtx() const; + isl::ctx getIslCtx() const; /// Get the iteration domain of this ScopStmt. /// @@ -1680,7 +1677,7 @@ class Scop { public: /// Type to represent a pair of minimal/maximal access to an array. - using MinMaxAccessTy = std::pair; + using MinMaxAccessTy = std::pair; /// Vector of minimal/maximal accesses to different arrays. using MinMaxVectorTy = SmallVector; @@ -1696,6 +1693,15 @@ private: friend class ScopBuilder; + /// Isl context. + /// + /// We need a shared_ptr with reference counter to delete the context when all + /// isl objects are deleted. We will distribute the shared_ptr to all objects + /// that use the context to create isl objects, and increase the reference + /// counter. By doing this, we guarantee that the context is deleted when we + /// delete the last object that creates isl objects with the context. + std::shared_ptr IslCtx; + ScalarEvolution *SE; DominatorTree *DT; @@ -1751,15 +1757,6 @@ /// OptimizationRemarkEmitter object for displaying diagnostic remarks OptimizationRemarkEmitter &ORE; - /// Isl context. - /// - /// We need a shared_ptr with reference counter to delete the context when all - /// isl objects are deleted. We will distribute the shared_ptr to all objects - /// that use the context to create isl objects, and increase the reference - /// counter. By doing this, we guarantee that the context is deleted when we - /// delete the last object that creates isl objects with the context. - std::shared_ptr IslCtx; - /// A map from basic blocks to vector of SCoP statements. Currently this /// vector comprises only of a single statement. DenseMap> StmtMap; @@ -1771,7 +1768,7 @@ DenseMap DomainMap; /// Constraints on parameters. - isl_set *Context = nullptr; + isl::set Context = nullptr; /// The affinator used to translate SCEVs to isl expressions. SCEVAffinator Affinator; @@ -1806,7 +1803,7 @@ /// lot simpler, but which is only valid under certain assumptions. The /// assumed context records the assumptions taken during the construction of /// this scop and that need to be code generated as a run-time test. - isl_set *AssumedContext = nullptr; + isl::set AssumedContext; /// The restrictions under which this SCoP was built. /// @@ -1814,7 +1811,7 @@ /// constraints over the parameters. However, while we need the constraints /// in the assumed context to be "true" the constraints in the invalid context /// need to be "false". Otherwise they behave the same. - isl_set *InvalidContext = nullptr; + isl::set InvalidContext; /// Helper struct to remember assumptions. struct Assumption { @@ -1825,7 +1822,7 @@ AssumptionSign Sign; /// The valid/invalid context if this is an assumption/restriction. - isl_set *Set; + isl::set Set; /// The location that caused this assumption. DebugLoc Loc; @@ -1880,7 +1877,7 @@ /// set of statement instances that will be scheduled in a subtree. There /// are also several other nodes. A full description of the different nodes /// in a schedule tree is given in the isl manual. - isl_schedule *Schedule = nullptr; + isl::schedule Schedule = nullptr; /// The set of minimal/maximal accesses for each alias group. /// @@ -2305,14 +2302,13 @@ Loop *L; // The (possibly incomplete) schedule for this loop. - isl_schedule *Schedule; + isl::schedule Schedule; // The number of basic blocks in the current loop, for which a schedule has // already been constructed. unsigned NumBlocksProcessed; - LoopStackElement(Loop *L, __isl_give isl_schedule *S, - unsigned NumBlocksProcessed) + LoopStackElement(Loop *L, isl::schedule S, unsigned NumBlocksProcessed) : L(L), Schedule(S), NumBlocksProcessed(NumBlocksProcessed) {} }; @@ -2599,7 +2595,7 @@ /// (needed/assumptions) or negative (invalid/restrictions). /// /// @returns True if the assumption @p Set is not trivial. - bool isEffectiveAssumption(__isl_keep isl_set *Set, AssumptionSign Sign); + bool isEffectiveAssumption(isl::set Set, AssumptionSign Sign); /// Track and report an assumption. /// @@ -2615,8 +2611,8 @@ /// calculate hotness when emitting remark. /// /// @returns True if the assumption is not trivial. - bool trackAssumption(AssumptionKind Kind, __isl_keep isl_set *Set, - DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB); + bool trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, + AssumptionSign Sign, BasicBlock *BB); /// Add assumptions to assumed context. /// @@ -2636,7 +2632,7 @@ /// (needed/assumptions) or negative (invalid/restrictions). /// @param BB The block in which this assumption was taken. Used to /// calculate hotness when emitting remark. - void addAssumption(AssumptionKind Kind, __isl_take isl_set *Set, DebugLoc Loc, + void addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB); /// Record an assumption for later addition to the assumed context. @@ -2654,9 +2650,8 @@ /// set, the domain of that block will be used to simplify the /// actual assumption in @p Set once it is added. This is useful /// if the assumption was created prior to the domain. - void recordAssumption(AssumptionKind Kind, __isl_take isl_set *Set, - DebugLoc Loc, AssumptionSign Sign, - BasicBlock *BB = nullptr); + void recordAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, + AssumptionSign Sign, BasicBlock *BB = nullptr); /// Add all recorded assumptions to the assumed context. void addRecordedAssumptions(); @@ -2679,9 +2674,7 @@ isl::set getInvalidContext() const; /// Return true if and only if the InvalidContext is trivial (=empty). - bool hasTrivialInvalidContext() const { - return isl_set_is_empty(InvalidContext); - } + bool hasTrivialInvalidContext() const { return InvalidContext.is_empty(); } /// A vector of memory accesses that belong to an alias group. using AliasGroupTy = SmallVector; @@ -2867,7 +2860,7 @@ ScopArrayInfoMap.erase(It); } - void setContext(__isl_take isl_set *NewContext); + void setContext(isl::set NewContext); /// Align the parameters in the statement to the scop context void realignParams(); @@ -2901,7 +2894,7 @@ /// Get the isl context of this static control part. /// /// @return The isl context of this static control part. - isl_ctx *getIslCtx() const; + isl::ctx getIslCtx() const; /// Directly return the shared_ptr of the context. const std::shared_ptr &getSharedIslCtx() const { return IslCtx; } @@ -2918,8 +2911,8 @@ /// the translation of @p E was deemed to complex the SCoP is invalidated and /// a dummy value of appropriate dimension is returned. This allows to bail /// for complex cases without "error handling code" needed on the users side. - __isl_give PWACtx getPwAff(const SCEV *E, BasicBlock *BB = nullptr, - bool NonNegative = false); + PWACtx getPwAff(const SCEV *E, BasicBlock *BB = nullptr, + bool NonNegative = false); /// Compute the isl representation for the SCEV @p E /// @@ -2972,12 +2965,12 @@ /// Update the current schedule /// /// NewSchedule The new schedule (given as a flat union-map). - void setSchedule(__isl_take isl_union_map *NewSchedule); + void setSchedule(isl::union_map NewSchedule); /// Update the current schedule /// /// NewSchedule The new schedule (given as schedule tree). - void setScheduleTree(__isl_take isl_schedule *NewSchedule); + void setScheduleTree(isl::schedule NewSchedule); /// Intersects the domains of all statements in the SCoP. /// @@ -2999,7 +2992,7 @@ /// Check whether @p Schedule contains extension nodes. /// /// @return true if @p Schedule contains extension nodes. - static bool containsExtensionNode(__isl_keep isl_schedule *Schedule); + static bool containsExtensionNode(isl::schedule Schedule); /// Simplify the SCoP representation. /// Index: include/polly/Support/GICHelper.h =================================================================== --- include/polly/Support/GICHelper.h +++ include/polly/Support/GICHelper.h @@ -177,6 +177,42 @@ std::string stringFromIslObj(__isl_keep isl_aff *aff); std::string stringFromIslObj(__isl_keep isl_pw_aff *pwaff); std::string stringFromIslObj(__isl_keep isl_space *space); +static inline std::string stringFromIslObj(isl::map map) { + return stringFromIslObj(map.keep()); +} +static inline std::string stringFromIslObj(isl::union_map umap) { + return stringFromIslObj(umap.keep()); +} +static inline std::string stringFromIslObj(isl::set set) { + return stringFromIslObj(set.keep()); +} +static inline std::string stringFromIslObj(isl::union_set uset) { + return stringFromIslObj(uset.keep()); +} +static inline std::string stringFromIslObj(isl::schedule schedule) { + return stringFromIslObj(schedule.keep()); +} +static inline std::string stringFromIslObj(isl::multi_aff maff) { + return stringFromIslObj(maff.keep()); +} +static inline std::string stringFromIslObj(isl::pw_multi_aff pma) { + return stringFromIslObj(pma.keep()); +} +static inline std::string stringFromIslObj(isl::multi_pw_aff mpa) { + return stringFromIslObj(mpa.keep()); +} +static inline std::string stringFromIslObj(isl::union_pw_multi_aff upma) { + return stringFromIslObj(upma.keep()); +} +static inline std::string stringFromIslObj(isl::aff aff) { + return stringFromIslObj(aff.keep()); +} +static inline std::string stringFromIslObj(isl::pw_aff pwaff) { + return stringFromIslObj(pwaff.keep()); +} +static inline std::string stringFromIslObj(isl::space space) { + return stringFromIslObj(space.keep()); +} //@} inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, Index: include/polly/Support/ISLOStream.h =================================================================== --- include/polly/Support/ISLOStream.h +++ include/polly/Support/ISLOStream.h @@ -35,6 +35,7 @@ ADD_OSTREAM_PRINTER(isl::multi_union_pw_aff) ADD_OSTREAM_PRINTER(isl::point) ADD_OSTREAM_PRINTER(isl::pw_aff) +ADD_OSTREAM_PRINTER(isl::pw_multi_aff) ADD_OSTREAM_PRINTER(isl::schedule) ADD_OSTREAM_PRINTER(isl::schedule_node) ADD_OSTREAM_PRINTER(isl::space) Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -249,15 +249,13 @@ // Create a sequence of two schedules. Either argument may be null and is // interpreted as the empty schedule. Can also return null if both schedules are // empty. -static __isl_give isl_schedule * -combineInSequence(__isl_take isl_schedule *Prev, - __isl_take isl_schedule *Succ) { +static isl::schedule combineInSequence(isl::schedule Prev, isl::schedule Succ) { if (!Prev) return Succ; if (!Succ) return Prev; - return isl_schedule_sequence(Prev, Succ); + return Prev.sequence(Succ); } static isl::set addRangeBoundsToSet(isl::set S, const ConstantRange &Range, @@ -709,7 +707,7 @@ } std::string MemoryAccess::getOriginalAccessRelationStr() const { - return stringFromIslObj(AccessRelation.get()); + return stringFromIslObj(AccessRelation); } isl::space MemoryAccess::getOriginalAccessRelationSpace() const { @@ -721,7 +719,7 @@ } std::string MemoryAccess::getNewAccessRelationStr() const { - return stringFromIslObj(NewAccessRelation.get()); + return stringFromIslObj(NewAccessRelation); } std::string MemoryAccess::getAccessRelationStr() const { @@ -793,7 +791,7 @@ : DebugLoc(); if (!PollyPreciseInbounds) Outside = Outside.gist_params(Statement->getDomain().params()); - Statement->getParent()->recordAssumption(INBOUNDS, Outside.release(), Loc, + Statement->getParent()->recordAssumption(INBOUNDS, Outside, Loc, AS_ASSUMPTION); } @@ -1766,7 +1764,7 @@ return NestLoops[Dimension]; } -isl_ctx *ScopStmt::getIslCtx() const { return Parent.getIslCtx(); } +isl::ctx ScopStmt::getIslCtx() const { return Parent.getIslCtx(); } isl::set ScopStmt::getDomain() const { return Domain; } @@ -1894,10 +1892,8 @@ //===----------------------------------------------------------------------===// /// Scop class implement -void Scop::setContext(__isl_take isl_set *NewContext) { - NewContext = isl_set_align_params(NewContext, isl_set_get_space(Context)); - isl_set_free(Context); - Context = NewContext; +void Scop::setContext(isl::set NewContext) { + Context = NewContext.align_params(Context.get_space()); } namespace { @@ -2105,7 +2101,7 @@ SmallVector ConditionSets; auto *TI = InScop ? CI->getParent()->getTerminator() : nullptr; BasicBlock *BB = InScop ? CI->getParent() : getRegion().getEntry(); - auto *Dom = InScop ? DomainMap[BB].copy() : isl_set_copy(Context); + auto *Dom = InScop ? DomainMap[BB].copy() : Context.copy(); assert(Dom && "Cannot propagate a nullptr."); bool Valid = buildConditionSets(*this, BB, Val, TI, L, Dom, InvalidDomainMap, ConditionSets); @@ -2139,7 +2135,7 @@ } ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "UserAssumption", CI) << "Use user assumption: " << stringFromIslObj(AssumptionCtx)); - Context = isl_set_intersect(Context, AssumptionCtx); + Context = Context.intersect(isl::manage(AssumptionCtx)); } } @@ -2148,7 +2144,7 @@ return; isl_set *UserContext = - isl_set_read_from_str(getIslCtx(), UserContextStr.c_str()); + isl_set_read_from_str(getIslCtx().get(), UserContextStr.c_str()); isl_space *Space = getParamSpace().release(); if (isl_space_dim(Space, isl_dim_param) != isl_set_dim(UserContext, isl_dim_param)) { @@ -2164,10 +2160,11 @@ } for (unsigned i = 0; i < isl_space_dim(Space, isl_dim_param); i++) { - auto *NameContext = isl_set_get_dim_name(Context, isl_dim_param, i); - auto *NameUserContext = isl_set_get_dim_name(UserContext, isl_dim_param, i); + std::string NameContext = Context.get_dim_name(isl::dim::param, i); + std::string NameUserContext = + isl_set_get_dim_name(UserContext, isl_dim_param, i); - if (strcmp(NameContext, NameUserContext) != 0) { + if (NameContext != NameUserContext) { auto SpaceStr = isl_space_to_str(Space); errs() << "Error: the name of dimension " << i << " provided in -polly-context " @@ -2187,7 +2184,7 @@ isl_space_get_dim_id(Space, isl_dim_param, i)); } - Context = isl_set_intersect(Context, UserContext); + Context = Context.intersect(isl::manage(UserContext)); isl_space_free(Space); } @@ -2212,19 +2209,17 @@ } void Scop::buildContext() { - isl_space *Space = isl_space_params_alloc(getIslCtx(), 0); - Context = isl_set_universe(isl_space_copy(Space)); - InvalidContext = isl_set_empty(isl_space_copy(Space)); - AssumedContext = isl_set_universe(Space); + auto Space = isl::space::params_alloc(getIslCtx(), 0); + Context = isl::set::universe(Space); + InvalidContext = isl::set::empty(Space); + AssumedContext = isl::set::universe(Space); } void Scop::addParameterBounds() { unsigned PDim = 0; for (auto *Parameter : Parameters) { ConstantRange SRange = SE->getSignedRange(Parameter); - Context = - addRangeBoundsToSet(give(Context), SRange, PDim++, isl::dim::param) - .release(); + Context = addRangeBoundsToSet(Context, SRange, PDim++, isl::dim::param); } } @@ -2252,14 +2247,14 @@ } // The FORTRAN array size parameters are known to be non-negative. -static isl_set *boundFortranArrayParams(__isl_give isl_set *Context, +static isl::set boundFortranArrayParams(isl::set Context, Scop::array_range Arrays) { std::vector OutermostSizeIds; OutermostSizeIds = getFortranArrayIds(Arrays); for (isl::id Id : OutermostSizeIds) { - int dim = isl_set_find_dim_by_id(Context, isl_dim_param, Id.get()); - Context = isl_set_lower_bound_si(Context, isl_dim_param, dim, 0); + int dim = Context.find_dim_by_id(isl::dim::param, Id); + Context = Context.lower_bound_si(isl::dim::param, dim, 0); } return Context; @@ -2273,7 +2268,7 @@ isl::space Space = getFullParamSpace(); // Align the parameters of all data structures to the model. - Context = isl_set_align_params(Context, Space.copy()); + Context = Context.align_params(Space); // Bound the size of the fortran array dimensions. Context = boundFortranArrayParams(Context, arrays()); @@ -2284,12 +2279,11 @@ for (ScopStmt &Stmt : *this) Stmt.realignParams(); // Simplify the schedule according to the context too. - Schedule = isl_schedule_gist_domain_params(Schedule, getContext().release()); + Schedule = Schedule.gist_domain_params(getContext()); } -static __isl_give isl_set * -simplifyAssumptionContext(__isl_take isl_set *AssumptionContext, - const Scop &S) { +static isl::set simplifyAssumptionContext(isl::set AssumptionContext, + const Scop &S) { // If we have modeled all blocks in the SCoP that have side effects we can // simplify the context with the constraints that are needed for anything to // be executed at all. However, if we have error blocks in the SCoP we already @@ -2297,13 +2291,11 @@ // domains, thus we cannot use the remaining domain to simplify the // assumptions. if (!S.hasErrorBlock()) { - isl_set *DomainParameters = isl_union_set_params(S.getDomains().release()); - AssumptionContext = - isl_set_gist_params(AssumptionContext, DomainParameters); + auto DomainParameters = S.getDomains().params(); + AssumptionContext = AssumptionContext.gist_params(DomainParameters); } - AssumptionContext = - isl_set_gist_params(AssumptionContext, S.getContext().release()); + AssumptionContext = AssumptionContext.gist_params(S.getContext()); return AssumptionContext; } @@ -2337,8 +2329,7 @@ // otherwise we would access out of bound data. Now, knowing that code is // only executed for the case m >= 0, it is sufficient to assume p >= 0. AssumedContext = simplifyAssumptionContext(AssumedContext, *this); - InvalidContext = - isl_set_align_params(InvalidContext, getParamSpace().release()); + InvalidContext = InvalidContext.align_params(getParamSpace()); } /// Add the minimal/maximal access in @p Set to @p User. @@ -2403,7 +2394,7 @@ LastDimAff = LastDimAff.add(OneAff); MaxPMA = MaxPMA.set_pw_aff(Pos, LastDimAff); - MinMaxAccesses.push_back(std::make_pair(MinPMA.copy(), MaxPMA.copy())); + MinMaxAccesses.push_back(std::make_pair(MinPMA, MaxPMA)); return isl::stat::ok; } @@ -2564,7 +2555,7 @@ auto *EntryBB = R->getEntry(); auto *L = IsOnlyNonAffineRegion ? nullptr : LI.getLoopFor(EntryBB); int LD = getRelativeLoopDepth(L); - auto *S = isl_set_universe(isl_space_set_alloc(getIslCtx(), 0, LD + 1)); + auto *S = isl_set_universe(isl_space_set_alloc(getIslCtx().get(), 0, LD + 1)); while (LD-- >= 0) { S = addDomainDimId(S, LD + 1, L); @@ -2680,8 +2671,8 @@ } else { InvalidDomain = Domain; isl::set DomPar = Domain.params(); - recordAssumption(ERRORBLOCK, DomPar.release(), - BB->getTerminator()->getDebugLoc(), AS_RESTRICTION); + recordAssumption(ERRORBLOCK, DomPar, BB->getTerminator()->getDebugLoc(), + AS_RESTRICTION); Domain = nullptr; } @@ -3104,7 +3095,7 @@ return true; } - isl_set *UnboundedCtx = isl_set_params(Parts.first); + isl::set UnboundedCtx = isl::manage(Parts.first).params(); recordAssumption(INFINITELOOP, UnboundedCtx, HeaderBB->getTerminator()->getDebugLoc(), AS_RESTRICTION); return true; @@ -3251,12 +3242,12 @@ return false; { - IslMaxOperationsGuard MaxOpGuard(getIslCtx(), OptComputeOut); + IslMaxOperationsGuard MaxOpGuard(getIslCtx().get(), OptComputeOut); bool Valid = buildAliasGroup(AG, HasWriteAccess); if (!Valid) return false; } - if (isl_ctx_last_error(getIslCtx()) == isl_error_quota) { + if (isl_ctx_last_error(getIslCtx().get()) == isl_error_quota) { invalidate(COMPLEXITY, DebugLoc()); return false; } @@ -3380,40 +3371,28 @@ Scop::Scop(Region &R, ScalarEvolution &ScalarEvolution, LoopInfo &LI, DominatorTree &DT, ScopDetection::DetectionContext &DC, OptimizationRemarkEmitter &ORE) - : SE(&ScalarEvolution), DT(&DT), R(R), name(R.getNameStr()), - HasSingleExitEdge(R.getExitingBlock()), DC(DC), ORE(ORE), - IslCtx(isl_ctx_alloc(), isl_ctx_free), Affinator(this, LI), + : IslCtx(isl_ctx_alloc(), isl_ctx_free), SE(&ScalarEvolution), DT(&DT), + R(R), name(R.getNameStr()), HasSingleExitEdge(R.getExitingBlock()), + DC(DC), ORE(ORE), Affinator(this, LI), ID(getNextID((*R.getEntry()->getParent()).getName().str())) { if (IslOnErrorAbort) - isl_options_set_on_error(getIslCtx(), ISL_ON_ERROR_ABORT); + isl_options_set_on_error(getIslCtx().get(), ISL_ON_ERROR_ABORT); buildContext(); } Scop::~Scop() { - isl_set_free(Context); - isl_set_free(AssumedContext); - isl_set_free(InvalidContext); - isl_schedule_free(Schedule); + Context = nullptr; + AssumedContext = nullptr; + InvalidContext = nullptr; + Schedule = nullptr; ParameterIds.clear(); - for (auto &AS : RecordedAssumptions) - isl_set_free(AS.Set); - // Free the alias groups - for (MinMaxVectorPairTy &MinMaxAccessPair : MinMaxAliasGroups) { - for (MinMaxAccessTy &MMA : MinMaxAccessPair.first) { - isl_pw_multi_aff_free(MMA.first); - isl_pw_multi_aff_free(MMA.second); - } - for (MinMaxAccessTy &MMA : MinMaxAccessPair.second) { - isl_pw_multi_aff_free(MMA.first); - isl_pw_multi_aff_free(MMA.second); - } - } + RecordedAssumptions.clear(); + MinMaxAliasGroups.clear(); - for (const auto &IAClass : InvariantEquivClasses) - isl_set_free(IAClass.ExecutionContext); + InvariantEquivClasses.clear(); // Explicitly release all Scop objects and the underlying isl objects before // we release the isl context. @@ -3841,12 +3820,12 @@ Consolidated = true; // Unify the execution context of the class and this statement. - isl::set IAClassDomainCtx = isl::manage(IAClass.ExecutionContext); + isl::set IAClassDomainCtx = IAClass.ExecutionContext; if (IAClassDomainCtx) IAClassDomainCtx = IAClassDomainCtx.unite(MACtx).coalesce(); else IAClassDomainCtx = MACtx; - IAClass.ExecutionContext = IAClassDomainCtx.release(); + IAClass.ExecutionContext = IAClassDomainCtx; break; } @@ -3855,8 +3834,8 @@ // If we did not consolidate MA, thus did not find an equivalence class // for it, we create a new one. - InvariantEquivClasses.emplace_back(InvariantEquivClassTy{ - PointerSCEV, MemoryAccessList{MA}, MACtx.release(), Ty}); + InvariantEquivClasses.emplace_back( + InvariantEquivClassTy{PointerSCEV, MemoryAccessList{MA}, MACtx, Ty}); } } @@ -3953,8 +3932,8 @@ if (TooComplex || !isRequiredInvariantLoad(LI)) return nullptr; - addAssumption(INVARIANTLOAD, WrittenCtx.copy(), LI->getDebugLoc(), - AS_RESTRICTION, LI->getParent()); + addAssumption(INVARIANTLOAD, WrittenCtx, LI->getDebugLoc(), AS_RESTRICTION, + LI->getParent()); return WrittenCtx; } @@ -4148,7 +4127,7 @@ return std::make_pair(EntryName, ExitName); } -isl::set Scop::getContext() const { return isl::manage(isl_set_copy(Context)); } +isl::set Scop::getContext() const { return Context; } isl::space Scop::getParamSpace() const { return getContext().get_space(); } isl::space Scop::getFullParamSpace() const { @@ -4172,7 +4151,7 @@ isl::set Scop::getAssumedContext() const { assert(AssumedContext && "Assumed context not yet built"); - return isl::manage(isl_set_copy(AssumedContext)); + return AssumedContext; } bool Scop::isProfitable(bool ScalarsAreUnprofitable) const { @@ -4204,23 +4183,20 @@ } bool Scop::hasFeasibleRuntimeContext() const { - auto *PositiveContext = getAssumedContext().release(); - auto *NegativeContext = getInvalidContext().release(); - PositiveContext = - addNonEmptyDomainConstraints(isl::manage(PositiveContext)).release(); - bool IsFeasible = !(isl_set_is_empty(PositiveContext) || - isl_set_is_subset(PositiveContext, NegativeContext)); - isl_set_free(PositiveContext); - if (!IsFeasible) { - isl_set_free(NegativeContext); + auto PositiveContext = getAssumedContext(); + auto NegativeContext = getInvalidContext(); + PositiveContext = addNonEmptyDomainConstraints(PositiveContext); + if (!PositiveContext) + return false; + + bool IsFeasible = !(PositiveContext.is_empty() || + PositiveContext.is_subset(NegativeContext)); + if (!IsFeasible) return false; - } - auto *DomainContext = isl_union_set_params(getDomains().release()); - IsFeasible = !isl_set_is_subset(DomainContext, NegativeContext); - IsFeasible &= !isl_set_is_subset(Context, NegativeContext); - isl_set_free(NegativeContext); - isl_set_free(DomainContext); + auto DomainContext = getDomains().params(); + IsFeasible = !DomainContext.is_subset(NegativeContext); + IsFeasible &= !Context.is_subset(NegativeContext); return IsFeasible; } @@ -4251,37 +4227,36 @@ llvm_unreachable("Unknown AssumptionKind!"); } -bool Scop::isEffectiveAssumption(__isl_keep isl_set *Set, AssumptionSign Sign) { +bool Scop::isEffectiveAssumption(isl::set Set, AssumptionSign Sign) { if (Sign == AS_ASSUMPTION) { - if (isl_set_is_subset(Context, Set)) + if (Context.is_subset(Set)) return false; - if (isl_set_is_subset(AssumedContext, Set)) + if (AssumedContext.is_subset(Set)) return false; } else { - if (isl_set_is_disjoint(Set, Context)) + if (Set.is_disjoint(Context)) return false; - if (isl_set_is_subset(Set, InvalidContext)) + if (Set.is_subset(InvalidContext)) return false; } return true; } -bool Scop::trackAssumption(AssumptionKind Kind, __isl_keep isl_set *Set, - DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB) { +bool Scop::trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, + AssumptionSign Sign, BasicBlock *BB) { if (PollyRemarksMinimal && !isEffectiveAssumption(Set, Sign)) return false; // Do never emit trivial assumptions as they only clutter the output. if (!PollyRemarksMinimal) { - isl_set *Univ = nullptr; + isl::set Univ; if (Sign == AS_ASSUMPTION) - Univ = isl_set_universe(isl_set_get_space(Set)); + Univ = isl::set::universe(Set.get_space()); - bool IsTrivial = (Sign == AS_RESTRICTION && isl_set_is_empty(Set)) || - (Sign == AS_ASSUMPTION && isl_set_is_equal(Univ, Set)); - isl_set_free(Univ); + bool IsTrivial = (Sign == AS_RESTRICTION && Set.is_empty()) || + (Sign == AS_ASSUMPTION && Univ.is_equal(Set)); if (IsTrivial) return false; @@ -4332,35 +4307,30 @@ return true; } -void Scop::addAssumption(AssumptionKind Kind, __isl_take isl_set *Set, - DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB) { +void Scop::addAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, + AssumptionSign Sign, BasicBlock *BB) { // Simplify the assumptions/restrictions first. - Set = isl_set_gist_params(Set, getContext().release()); + Set = Set.gist_params(getContext()); - if (!trackAssumption(Kind, Set, Loc, Sign, BB)) { - isl_set_free(Set); + if (!trackAssumption(Kind, Set, Loc, Sign, BB)) return; - } - if (Sign == AS_ASSUMPTION) { - AssumedContext = isl_set_intersect(AssumedContext, Set); - AssumedContext = isl_set_coalesce(AssumedContext); - } else { - InvalidContext = isl_set_union(InvalidContext, Set); - InvalidContext = isl_set_coalesce(InvalidContext); - } + if (Sign == AS_ASSUMPTION) + AssumedContext = AssumedContext.intersect(Set).coalesce(); + else + InvalidContext = InvalidContext.unite(Set).coalesce(); } -void Scop::recordAssumption(AssumptionKind Kind, __isl_take isl_set *Set, - DebugLoc Loc, AssumptionSign Sign, BasicBlock *BB) { - assert((isl_set_is_params(Set) || BB) && +void Scop::recordAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc, + AssumptionSign Sign, BasicBlock *BB) { + assert((Set.is_params() || BB) && "Assumptions without a basic block must be parameter sets"); RecordedAssumptions.push_back({Kind, Sign, Set, Loc, BB}); } void Scop::addRecordedAssumptions() { while (!RecordedAssumptions.empty()) { - const Assumption &AS = RecordedAssumptions.pop_back_val(); + Assumption AS = RecordedAssumptions.pop_back_val(); if (!AS.BB) { addAssumption(AS.Kind, AS.Set, AS.Loc, AS.Sign, nullptr /* BasicBlock */); @@ -4369,10 +4339,8 @@ // If the domain was deleted the assumptions are void. isl_set *Dom = getDomainConditions(AS.BB).release(); - if (!Dom) { - isl_set_free(AS.Set); + if (!Dom) continue; - } // If a basic block was given use its domain to simplify the assumption. // In case of restrictions we know they only have to hold on the domain, @@ -4383,25 +4351,22 @@ // // To avoid the complement we will register A - B as a restriction not an // assumption. - isl_set *S = AS.Set; + isl_set *S = AS.Set.copy(); if (AS.Sign == AS_RESTRICTION) S = isl_set_params(isl_set_intersect(S, Dom)); else /* (AS.Sign == AS_ASSUMPTION) */ S = isl_set_params(isl_set_subtract(Dom, S)); - addAssumption(AS.Kind, S, AS.Loc, AS_RESTRICTION, AS.BB); + addAssumption(AS.Kind, isl::manage(S), AS.Loc, AS_RESTRICTION, AS.BB); } } void Scop::invalidate(AssumptionKind Kind, DebugLoc Loc, BasicBlock *BB) { DEBUG(dbgs() << "Invalidate SCoP because of reason " << Kind << "\n"); - addAssumption(Kind, isl_set_empty(getParamSpace().release()), Loc, - AS_ASSUMPTION, BB); + addAssumption(Kind, isl::set::empty(getParamSpace()), Loc, AS_ASSUMPTION, BB); } -isl::set Scop::getInvalidContext() const { - return isl::manage(isl_set_copy(InvalidContext)); -} +isl::set Scop::getInvalidContext() const { return InvalidContext; } void Scop::printContext(raw_ostream &OS) const { OS << "Context:\n"; @@ -4510,7 +4475,7 @@ LLVM_DUMP_METHOD void Scop::dump() const { print(dbgs(), true); } #endif -isl_ctx *Scop::getIslCtx() const { return IslCtx.get(); } +isl::ctx Scop::getIslCtx() const { return IslCtx.get(); } __isl_give PWACtx Scop::getPwAff(const SCEV *E, BasicBlock *BB, bool NonNegative) { @@ -4537,7 +4502,7 @@ } isl::union_set Scop::getDomains() const { - isl_space *EmptySpace = isl_space_params_alloc(getIslCtx(), 0); + isl_space *EmptySpace = isl_space_params_alloc(getIslCtx().get(), 0); isl_union_set *Domain = isl_union_set_empty(EmptySpace); for (const ScopStmt &Stmt : *this) @@ -4606,37 +4571,30 @@ return isl_bool_true; } -bool Scop::containsExtensionNode(__isl_keep isl_schedule *Schedule) { - return isl_schedule_foreach_schedule_node_top_down(Schedule, isNotExtNode, - nullptr) == isl_stat_error; +bool Scop::containsExtensionNode(isl::schedule Schedule) { + return isl_schedule_foreach_schedule_node_top_down( + Schedule.keep(), isNotExtNode, nullptr) == isl_stat_error; } isl::union_map Scop::getSchedule() const { - auto *Tree = getScheduleTree().release(); - if (containsExtensionNode(Tree)) { - isl_schedule_free(Tree); + auto Tree = getScheduleTree(); + if (containsExtensionNode(Tree)) return nullptr; - } - auto *S = isl_schedule_get_map(Tree); - isl_schedule_free(Tree); - return isl::manage(S); + + return Tree.get_map(); } isl::schedule Scop::getScheduleTree() const { - return isl::manage(isl_schedule_intersect_domain(isl_schedule_copy(Schedule), - getDomains().release())); + return Schedule.intersect_domain(getDomains()); } -void Scop::setSchedule(__isl_take isl_union_map *NewSchedule) { - auto *S = isl_schedule_from_domain(getDomains().release()); - S = isl_schedule_insert_partial_schedule( - S, isl_multi_union_pw_aff_from_union_map(NewSchedule)); - isl_schedule_free(Schedule); - Schedule = S; +void Scop::setSchedule(isl::union_map NewSchedule) { + auto S = isl::schedule::from_domain(getDomains()); + Schedule = S.insert_partial_schedule( + isl::multi_union_pw_aff::from_union_map(NewSchedule)); } -void Scop::setScheduleTree(__isl_take isl_schedule *NewSchedule) { - isl_schedule_free(Schedule); +void Scop::setScheduleTree(isl::schedule NewSchedule) { Schedule = NewSchedule; } @@ -4840,13 +4798,13 @@ } } - auto &LoopData = LoopStack.back(); - LoopData.NumBlocksProcessed += getNumBlocksInRegionNode(RN); + auto LoopData = LoopStack.rbegin(); + LoopData->NumBlocksProcessed += getNumBlocksInRegionNode(RN); for (auto *Stmt : getStmtListFor(RN)) { - auto *UDomain = isl_union_set_from_set(Stmt->getDomain().release()); - auto *StmtSchedule = isl_schedule_from_domain(UDomain); - LoopData.Schedule = combineInSequence(LoopData.Schedule, StmtSchedule); + isl::union_set UDomain{Stmt->getDomain()}; + auto StmtSchedule = isl::schedule::from_domain(UDomain); + LoopData->Schedule = combineInSequence(LoopData->Schedule, StmtSchedule); } // Check if we just processed the last node in this loop. If we did, finalize @@ -4858,25 +4816,25 @@ // // Then continue to check surrounding loops, which might also have been // completed by this node. - while (LoopData.L && - LoopData.NumBlocksProcessed == getNumBlocksInLoop(LoopData.L)) { - auto *Schedule = LoopData.Schedule; - auto NumBlocksProcessed = LoopData.NumBlocksProcessed; - - LoopStack.pop_back(); - auto &NextLoopData = LoopStack.back(); - + auto Dimension = LoopStack.size(); + while (LoopData->L && + LoopData->NumBlocksProcessed == getNumBlocksInLoop(LoopData->L)) { + isl::schedule Schedule = LoopData->Schedule; + auto NumBlocksProcessed = LoopData->NumBlocksProcessed; + + assert(std::next(LoopData) != LoopStack.rend()); + ++LoopData; + --Dimension; if (Schedule) { - isl::union_set Domain = give(isl_schedule_get_domain(Schedule)); - isl::multi_union_pw_aff MUPA = mapToDimension(Domain, LoopStack.size()); - Schedule = isl_schedule_insert_partial_schedule(Schedule, MUPA.release()); - NextLoopData.Schedule = - combineInSequence(NextLoopData.Schedule, Schedule); + isl::union_set Domain = Schedule.get_domain(); + isl::multi_union_pw_aff MUPA = mapToDimension(Domain, Dimension); + Schedule = Schedule.insert_partial_schedule(MUPA); + LoopData->Schedule = combineInSequence(LoopData->Schedule, Schedule); } - NextLoopData.NumBlocksProcessed += NumBlocksProcessed; - LoopData = NextLoopData; + LoopData->NumBlocksProcessed += NumBlocksProcessed; } + LoopStack.erase(LoopStack.begin() + Dimension, LoopStack.end()); } ArrayRef Scop::getStmtListFor(BasicBlock *BB) const { Index: lib/CodeGen/IslAst.cpp =================================================================== --- lib/CodeGen/IslAst.cpp +++ lib/CodeGen/IslAst.cpp @@ -351,10 +351,10 @@ const Scop::MinMaxAccessTy *It0, const Scop::MinMaxAccessTy *It1) { - isl::pw_multi_aff AFirst = isl::manage(isl_pw_multi_aff_copy(It0->first)); - isl::pw_multi_aff ASecond = isl::manage(isl_pw_multi_aff_copy(It0->second)); - isl::pw_multi_aff BFirst = isl::manage(isl_pw_multi_aff_copy(It1->first)); - isl::pw_multi_aff BSecond = isl::manage(isl_pw_multi_aff_copy(It1->second)); + isl::pw_multi_aff AFirst = It0->first; + isl::pw_multi_aff ASecond = It0->second; + isl::pw_multi_aff BFirst = It1->first; + isl::pw_multi_aff BSecond = It1->second; isl::id Left = AFirst.get_tuple_id(isl::dim::set); isl::id Right = BFirst.get_tuple_id(isl::dim::set); @@ -529,10 +529,9 @@ // We can not perform the dependence analysis and, consequently, // the parallel code generation in case the schedule tree contains // extension nodes. - auto *ScheduleTree = S.getScheduleTree().release(); + auto ScheduleTree = S.getScheduleTree(); PerformParallelTest = PerformParallelTest && !S.containsExtensionNode(ScheduleTree); - isl_schedule_free(ScheduleTree); // Skip AST and code generation if there was no benefit achieved. if (!benefitsFromPolly(S, PerformParallelTest)) @@ -543,9 +542,9 @@ BeneficialAffineLoops += ScopStats.NumAffineLoops; BeneficialBoxedLoops += ScopStats.NumBoxedLoops; - isl_ctx *Ctx = S.getIslCtx(); - isl_options_set_ast_build_atomic_upper_bound(Ctx, true); - isl_options_set_ast_build_detect_min_max(Ctx, true); + auto Ctx = S.getIslCtx(); + isl_options_set_ast_build_atomic_upper_bound(Ctx.get(), true); + isl_options_set_ast_build_detect_min_max(Ctx.get(), true); isl_ast_build *Build; AstBuildUserInfo BuildInfo; @@ -676,8 +675,9 @@ IslAstInfo IslAstAnalysis::run(Scop &S, ScopAnalysisManager &SAM, ScopStandardAnalysisResults &SAR) { - return {S, SAM.getResult(S, SAR).getDependences( - Dependences::AL_Statement)}; + return {S, + SAM.getResult(S, SAR).getDependences( + Dependences::AL_Statement)}; } static __isl_give isl_printer *cbPrintUser(__isl_take isl_printer *P, @@ -749,14 +749,14 @@ isl_ast_expr *RunCondition = Ast.getRunCondition(); char *RtCStr, *AstStr; - Options = isl_ast_print_options_alloc(S.getIslCtx()); + Options = isl_ast_print_options_alloc(S.getIslCtx().get()); if (PrintAccesses) Options = isl_ast_print_options_set_print_user(Options, cbPrintUser, nullptr); Options = isl_ast_print_options_set_print_for(Options, cbPrintFor, nullptr); - isl_printer *P = isl_printer_to_str(S.getIslCtx()); + isl_printer *P = isl_printer_to_str(S.getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); P = isl_printer_print_ast_expr(P, RunCondition); RtCStr = isl_printer_get_str(P); Index: lib/CodeGen/IslNodeBuilder.cpp =================================================================== --- lib/CodeGen/IslNodeBuilder.cpp +++ lib/CodeGen/IslNodeBuilder.cpp @@ -849,7 +849,7 @@ IslNodeBuilder::createNewAccesses(ScopStmt *Stmt, __isl_keep isl_ast_node *Node) { isl_id_to_ast_expr *NewAccesses = - isl_id_to_ast_expr_alloc(Stmt->getParent()->getIslCtx(), 0); + isl_id_to_ast_expr_alloc(Stmt->getParent()->getIslCtx().get(), 0); auto *Build = IslAstInfo::getBuild(Node); assert(Build && "Could not obtain isl_ast_build from user node"); @@ -1071,8 +1071,9 @@ // there is a statement or the domain is not empty Inst is not dead. auto MemInst = MemAccInst::dyn_cast(Inst); auto Address = MemInst ? MemInst.getPointerOperand() : nullptr; - if (Address && SE.getUnknown(UndefValue::get(Address->getType())) == - SE.getPointerBase(SE.getSCEV(Address))) { + if (Address && + SE.getUnknown(UndefValue::get(Address->getType())) == + SE.getPointerBase(SE.getSCEV(Address))) { } else if (S.getStmtFor(Inst)) { IsDead = false; } else { @@ -1353,7 +1354,7 @@ return false; // The execution context of the IAClass. - isl_set *&ExecutionCtx = IAClass.ExecutionContext; + isl::set &ExecutionCtx = IAClass.ExecutionContext; // If the base pointer of this class is dependent on another one we have to // make sure it was preloaded already. @@ -1364,8 +1365,8 @@ // After we preloaded the BaseIAClass we adjusted the BaseExecutionCtx and // we need to refine the ExecutionCtx. - isl_set *BaseExecutionCtx = isl_set_copy(BaseIAClass->ExecutionContext); - ExecutionCtx = isl_set_intersect(ExecutionCtx, BaseExecutionCtx); + auto BaseExecutionCtx = BaseIAClass->ExecutionContext; + ExecutionCtx = ExecutionCtx.intersect(BaseExecutionCtx); } // If the size of a dimension is dependent on another class, make sure it is @@ -1381,8 +1382,8 @@ // After we preloaded the BaseIAClass we adjusted the BaseExecutionCtx // and we need to refine the ExecutionCtx. - isl_set *BaseExecutionCtx = isl_set_copy(BaseIAClass->ExecutionContext); - ExecutionCtx = isl_set_intersect(ExecutionCtx, BaseExecutionCtx); + auto BaseExecutionCtx = BaseIAClass->ExecutionContext; + ExecutionCtx = ExecutionCtx.intersect(BaseExecutionCtx); } } } @@ -1390,7 +1391,7 @@ Instruction *AccInst = MA->getAccessInstruction(); Type *AccInstTy = AccInst->getType(); - Value *PreloadVal = preloadInvariantLoad(*MA, isl_set_copy(ExecutionCtx)); + Value *PreloadVal = preloadInvariantLoad(*MA, ExecutionCtx.copy()); if (!PreloadVal) return false; Index: lib/CodeGen/PPCGCodeGeneration.cpp =================================================================== --- lib/CodeGen/PPCGCodeGeneration.cpp +++ lib/CodeGen/PPCGCodeGeneration.cpp @@ -2261,7 +2261,7 @@ } SAI = S.getOrCreateScopArrayInfo(Allocation, EleTy, Sizes, MemoryKind::Array); - Id = isl_id_alloc(S.getIslCtx(), Var.name, nullptr); + Id = isl_id_alloc(S.getIslCtx().get(), Var.name, nullptr); IDToValue[Id] = Allocation; LocalArrays.push_back(Allocation); KernelIds.push_back(Id); @@ -2684,9 +2684,9 @@ /// @returns Retun a map from collected ids to 'zero' ast expressions. __isl_give isl_id_to_ast_expr *getNames() { auto *Names = isl_id_to_ast_expr_alloc( - S->getIslCtx(), + S->getIslCtx().get(), S->getNumParams() + std::distance(S->array_begin(), S->array_end())); - auto *Zero = isl_ast_expr_from_val(isl_val_zero(S->getIslCtx())); + auto *Zero = isl_ast_expr_from_val(isl_val_zero(S->getIslCtx().get())); for (const SCEV *P : S->parameters()) { isl_id *Id = S->getIdForParam(P).release(); @@ -2773,7 +2773,8 @@ gpu_stmt_access *Accesses = nullptr; for (MemoryAccess *Acc : Stmt) { - auto Access = isl_alloc_type(S->getIslCtx(), struct gpu_stmt_access); + auto Access = + isl_alloc_type(S->getIslCtx().get(), struct gpu_stmt_access); Access->read = Acc->isRead(); Access->write = Acc->isWrite(); Access->access = Acc->getAccessRelation().release(); @@ -2806,7 +2807,7 @@ /// /// @returns A linked-list of statements. gpu_stmt *getStatements() { - gpu_stmt *Stmts = isl_calloc_array(S->getIslCtx(), struct gpu_stmt, + gpu_stmt *Stmts = isl_calloc_array(S->getIslCtx().get(), struct gpu_stmt, std::distance(S->begin(), S->end())); int i = 0; @@ -2978,7 +2979,7 @@ assert(AlignSpace && "alignPwAffs did not initialise AlignSpace"); isl_pw_aff_list *BoundsList = - createPwAffList(S->getIslCtx(), std::move(AlignedBounds)); + createPwAffList(S->getIslCtx().get(), std::move(AlignedBounds)); isl_space *BoundsSpace = isl_set_get_space(PPCGArray.extent); BoundsSpace = isl_space_align_params(BoundsSpace, AlignSpace); @@ -3059,9 +3060,9 @@ if (!PPCGScop) return nullptr; - auto PPCGProg = isl_calloc_type(S->getIslCtx(), struct gpu_prog); + auto PPCGProg = isl_calloc_type(S->getIslCtx().get(), struct gpu_prog); - PPCGProg->ctx = S->getIslCtx(); + PPCGProg->ctx = S->getIslCtx().get(); PPCGProg->scop = PPCGScop; PPCGProg->context = isl_set_copy(PPCGScop->context); PPCGProg->read = isl_union_map_copy(PPCGScop->reads); @@ -3090,7 +3091,7 @@ PPCGProg->n_array = ValidSAIs.size(); // std::distance(S->array_begin(), S->array_end()); - PPCGProg->array = isl_calloc_array(S->getIslCtx(), struct gpu_array_info, + PPCGProg->array = isl_calloc_array(S->getIslCtx().get(), struct gpu_array_info, PPCGProg->n_array); createArrays(PPCGProg, ValidSAIs); @@ -3155,9 +3156,9 @@ /// /// @param Kernel The kernel to print void printKernel(ppcg_kernel *Kernel) { - auto *P = isl_printer_to_str(S->getIslCtx()); + auto *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); - auto *Options = isl_ast_print_options_alloc(S->getIslCtx()); + auto *Options = isl_ast_print_options_alloc(S->getIslCtx().get()); P = isl_ast_node_print(Kernel->tree, P, Options); char *String = isl_printer_get_str(P); printf("%s\n", String); @@ -3170,13 +3171,13 @@ /// @param Tree An AST describing GPU code /// @param PPCGProg The PPCG program from which @Tree has been constructed. void printGPUTree(isl_ast_node *Tree, gpu_prog *PPCGProg) { - auto *P = isl_printer_to_str(S->getIslCtx()); + auto *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_output_format(P, ISL_FORMAT_C); PrintGPUUserData Data; Data.PPCGProg = PPCGProg; - auto *Options = isl_ast_print_options_alloc(S->getIslCtx()); + auto *Options = isl_ast_print_options_alloc(S->getIslCtx().get()); Options = isl_ast_print_options_set_print_user(Options, printHostUser, &Data); P = isl_ast_node_print(Tree, P, Options); @@ -3205,9 +3206,9 @@ // strategy directly from this pass. gpu_gen *generateGPU(ppcg_scop *PPCGScop, gpu_prog *PPCGProg) { - auto PPCGGen = isl_calloc_type(S->getIslCtx(), struct gpu_gen); + auto PPCGGen = isl_calloc_type(S->getIslCtx().get(), struct gpu_gen); - PPCGGen->ctx = S->getIslCtx(); + PPCGGen->ctx = S->getIslCtx().get(); PPCGGen->options = PPCGScop->options; PPCGGen->print = nullptr; PPCGGen->print_user = nullptr; @@ -3243,7 +3244,7 @@ } if (DumpSchedule) { - isl_printer *P = isl_printer_to_str(S->getIslCtx()); + isl_printer *P = isl_printer_to_str(S->getIslCtx().get()); P = isl_printer_set_yaml_style(P, ISL_YAML_STYLE_BLOCK); P = isl_printer_print_str(P, "Schedule\n"); P = isl_printer_print_str(P, "========\n"); @@ -3355,7 +3356,7 @@ } } - isl_val *InstVal = isl_val_int_from_si(S->getIslCtx(), InstCount); + isl_val *InstVal = isl_val_int_from_si(S->getIslCtx().get(), InstCount); auto *InstExpr = isl_ast_expr_from_val(InstVal); return isl_ast_expr_mul(InstExpr, Iterations); } @@ -3371,7 +3372,7 @@ getNumberOfIterations(Scop &S, __isl_keep isl_ast_build *Build) { isl_ast_expr *Instructions; - isl_val *Zero = isl_val_int_from_si(S.getIslCtx(), 0); + isl_val *Zero = isl_val_int_from_si(S.getIslCtx().get(), 0); Instructions = isl_ast_expr_from_val(Zero); for (ScopStmt &Stmt : S) { @@ -3391,7 +3392,7 @@ __isl_give isl_ast_expr * createSufficientComputeCheck(Scop &S, __isl_keep isl_ast_build *Build) { auto Iterations = getNumberOfIterations(S, Build); - auto *MinComputeVal = isl_val_int_from_si(S.getIslCtx(), MinCompute); + auto *MinComputeVal = isl_val_int_from_si(S.getIslCtx().get(), MinCompute); auto *MinComputeExpr = isl_ast_expr_from_val(MinComputeVal); return isl_ast_expr_ge(Iterations, MinComputeExpr); } @@ -3477,7 +3478,7 @@ auto SplitBlock = StartBlock->getSinglePredecessor(); Builder.SetInsertPoint(SplitBlock->getTerminator()); - isl_ast_build *Build = isl_ast_build_alloc(S->getIslCtx()); + isl_ast_build *Build = isl_ast_build_alloc(S->getIslCtx().get()); isl_ast_expr *Condition = IslAst::buildRunCondition(*S, Build); isl_ast_expr *SufficientCompute = createSufficientComputeCheck(*S, Build); Condition = isl_ast_expr_and(Condition, SufficientCompute); Index: lib/Exchange/JSONExporter.cpp =================================================================== --- lib/Exchange/JSONExporter.cpp +++ lib/Exchange/JSONExporter.cpp @@ -210,53 +210,45 @@ /// /// @returns True if the import succeeded, otherwise False. static bool importContext(Scop &S, Json::Value &JScop) { - isl_set *OldContext = S.getContext().release(); + isl::set OldContext = S.getContext(); // Check if key 'context' is present. if (!JScop.isMember("context")) { errs() << "JScop file has no key named 'context'.\n"; - isl_set_free(OldContext); return false; } - isl_set *NewContext = - isl_set_read_from_str(S.getIslCtx(), JScop["context"].asCString()); + isl::set NewContext = + isl::set{S.getIslCtx().get(), JScop["context"].asString()}; // Check whether the context was parsed successfully. if (!NewContext) { errs() << "The context was not parsed successfully by ISL.\n"; - isl_set_free(NewContext); - isl_set_free(OldContext); return false; } // Check if the isl_set is a parameter set. - if (!isl_set_is_params(NewContext)) { + if (!NewContext.is_params()) { errs() << "The isl_set is not a parameter set.\n"; - isl_set_free(NewContext); - isl_set_free(OldContext); return false; } - unsigned OldContextDim = isl_set_dim(OldContext, isl_dim_param); - unsigned NewContextDim = isl_set_dim(NewContext, isl_dim_param); + unsigned OldContextDim = OldContext.dim(isl::dim::param); + unsigned NewContextDim = NewContext.dim(isl::dim::param); // Check if the imported context has the right number of parameters. if (OldContextDim != NewContextDim) { errs() << "Imported context has the wrong number of parameters : " << "Found " << NewContextDim << " Expected " << OldContextDim << "\n"; - isl_set_free(NewContext); - isl_set_free(OldContext); return false; } for (unsigned i = 0; i < OldContextDim; i++) { - isl_id *Id = isl_set_get_dim_id(OldContext, isl_dim_param, i); - NewContext = isl_set_set_dim_id(NewContext, isl_dim_param, i, Id); + isl::id Id = OldContext.get_dim_id(isl::dim::param, i); + NewContext = NewContext.set_dim_id(isl::dim::param, i, Id); } - isl_set_free(OldContext); S.setContext(NewContext); return true; } @@ -301,7 +293,8 @@ Json::Value Schedule = statements[Index]["schedule"]; assert(!Schedule.asString().empty() && "Schedules that contain extension nodes require special handling."); - isl_map *Map = isl_map_read_from_str(S.getIslCtx(), Schedule.asCString()); + isl_map *Map = + isl_map_read_from_str(S.getIslCtx().get(), Schedule.asCString()); // Check whether the schedule was parsed successfully if (!Map) { @@ -337,13 +330,12 @@ return false; } - auto ScheduleMap = isl_union_map_empty(S.getParamSpace().release()); + auto ScheduleMap = isl::union_map::empty(S.getParamSpace()); for (ScopStmt &Stmt : S) { if (NewSchedule.find(&Stmt) != NewSchedule.end()) - ScheduleMap = isl_union_map_add_map(ScheduleMap, NewSchedule[&Stmt]); + ScheduleMap = ScheduleMap.add_map(isl::manage(NewSchedule[&Stmt])); else - ScheduleMap = - isl_union_map_add_map(ScheduleMap, Stmt.getSchedule().release()); + ScheduleMap = ScheduleMap.add_map(Stmt.getSchedule()); } S.setSchedule(ScheduleMap); @@ -409,7 +401,7 @@ } Json::Value Accesses = JsonMemoryAccess["relation"]; isl_map *NewAccessMap = - isl_map_read_from_str(S.getIslCtx(), Accesses.asCString()); + isl_map_read_from_str(S.getIslCtx().get(), Accesses.asCString()); // Check whether the access was parsed successfully if (!NewAccessMap) { Index: lib/Support/GICHelper.cpp =================================================================== --- lib/Support/GICHelper.cpp +++ lib/Support/GICHelper.cpp @@ -24,6 +24,7 @@ #include using namespace llvm; +using namespace polly; __isl_give isl_val *polly::isl_valFromAPInt(isl_ctx *Ctx, const APInt Int, bool IsSigned) { Index: lib/Support/SCEVAffinator.cpp =================================================================== --- lib/Support/SCEVAffinator.cpp +++ lib/Support/SCEVAffinator.cpp @@ -96,7 +96,7 @@ } SCEVAffinator::SCEVAffinator(Scop *S, LoopInfo &LI) - : S(S), Ctx(S->getIslCtx()), SE(*S->getSE()), LI(LI), + : S(S), Ctx(S->getIslCtx().get()), SE(*S->getSE()), LI(LI), TD(S->getFunction().getParent()->getDataLayout()) {} SCEVAffinator::~SCEVAffinator() { @@ -122,7 +122,7 @@ PWAC.second = isl_set_union(PWAC.second, isl_set_copy(NegDom)); auto *Restriction = BB ? NegDom : isl_set_params(NegDom); auto DL = BB ? BB->getTerminator()->getDebugLoc() : DebugLoc(); - S->recordAssumption(UNSIGNED, Restriction, DL, AS_RESTRICTION, BB); + S->recordAssumption(UNSIGNED, isl::manage(Restriction), DL, AS_RESTRICTION, BB); } __isl_give PWACtx SCEVAffinator::getPWACtxFromPWA(__isl_take isl_pw_aff *PWA) { @@ -168,7 +168,7 @@ if (isl_set_is_empty(NotEqualSet)) isl_set_free(NotEqualSet); else - S->recordAssumption(WRAPPING, NotEqualSet, Loc, AS_RESTRICTION, BB); + S->recordAssumption(WRAPPING, isl::manage(NotEqualSet), Loc, AS_RESTRICTION, BB); return PWAC; } @@ -317,7 +317,7 @@ OutOfBoundsDom = isl_set_params(OutOfBoundsDom); } - S->recordAssumption(UNSIGNED, OutOfBoundsDom, DebugLoc(), AS_RESTRICTION, BB); + S->recordAssumption(UNSIGNED, isl::manage(OutOfBoundsDom), DebugLoc(), AS_RESTRICTION, BB); return OpPWAC; } Index: lib/Transform/FlattenSchedule.cpp =================================================================== --- lib/Transform/FlattenSchedule.cpp +++ lib/Transform/FlattenSchedule.cpp @@ -77,7 +77,7 @@ DEBUG(dbgs() << "Gisted, flattened new schedule:\n"); DEBUG(printSchedule(dbgs(), NewSchedule, 2)); - S.setSchedule(NewSchedule.take()); + S.setSchedule(NewSchedule); return false; } Index: lib/Transform/ForwardOpTree.cpp =================================================================== --- lib/Transform/ForwardOpTree.cpp +++ lib/Transform/ForwardOpTree.cpp @@ -962,7 +962,7 @@ LoopInfo &LI = getAnalysis().getLoopInfo(); { - IslMaxOperationsGuard MaxOpGuard(S.getIslCtx(), MaxOps, false); + IslMaxOperationsGuard MaxOpGuard(S.getIslCtx().get(), MaxOps, false); Impl = llvm::make_unique(&S, &LI, MaxOpGuard); if (AnalyzeKnown) { Index: lib/Transform/ScheduleOptimizer.cpp =================================================================== --- lib/Transform/ScheduleOptimizer.cpp +++ lib/Transform/ScheduleOptimizer.cpp @@ -372,7 +372,7 @@ return Set.add_constraint(ExtConstr); } -isl::set getPartialTilePrefixes(isl::set ScheduleRange, int VectorWidth) { +isl::set polly::getPartialTilePrefixes(isl::set ScheduleRange, int VectorWidth) { unsigned Dims = ScheduleRange.dim(isl::dim::set); isl::set LoopPrefixes = ScheduleRange.drop_constraints_involving_dims(isl::dim::set, Dims - 1, 1); @@ -1374,7 +1374,7 @@ // optimizations, by comparing (yet to be defined) performance metrics // before/after the scheduling optimizer // (e.g., #stride-one accesses) - if (S.containsExtensionNode(NewSchedule.get())) + if (S.containsExtensionNode(NewSchedule)) return true; auto NewScheduleMap = NewSchedule.get_map(); auto OldSchedule = S.getSchedule(); @@ -1582,7 +1582,7 @@ IslOuterCoincidence = 0; } - isl_ctx *Ctx = S.getIslCtx(); + isl_ctx *Ctx = S.getIslCtx().get(); isl_options_set_schedule_outer_coincidence(Ctx, IslOuterCoincidence); isl_options_set_schedule_serialize_sccs(Ctx, IslSerializeSCCs); @@ -1634,7 +1634,7 @@ NumAffineLoopsOptimized += ScopStats.NumAffineLoops; NumBoxedLoopsOptimized += ScopStats.NumBoxedLoops; - S.setScheduleTree(NewSchedule.release()); + S.setScheduleTree(NewSchedule); S.markAsOptimized(); if (OptimizedScops) Index: lib/Transform/Simplify.cpp =================================================================== --- lib/Transform/Simplify.cpp +++ lib/Transform/Simplify.cpp @@ -234,11 +234,11 @@ assert(V); isl::set &Result = ValueSets[V]; if (Result.is_null()) { - isl_ctx *Ctx = S->getIslCtx(); + isl::ctx Ctx = S->getIslCtx(); std::string Name = getIslCompatibleName("Val", V, ValueSets.size() - 1, std::string(), UseInstructionNames); - isl::id Id = give(isl_id_alloc(Ctx, Name.c_str(), V)); + isl::id Id = isl::id::alloc(Ctx, Name, V); Result = isl::set::universe( isl::space(Ctx, 0, 0).set_tuple_id(isl::dim::set, Id)); } @@ -404,7 +404,7 @@ assert(V); isl::set &Result = ValueSets[V]; if (Result.is_null()) { - isl_ctx *Ctx = S->getIslCtx(); + isl_ctx *Ctx = S->getIslCtx().get(); std::string Name = getIslCompatibleName("Val", V, ValueSets.size() - 1, std::string(), UseInstructionNames); Index: unittests/ScheduleOptimizer/ScheduleOptimizerTest.cpp =================================================================== --- unittests/ScheduleOptimizer/ScheduleOptimizerTest.cpp +++ unittests/ScheduleOptimizer/ScheduleOptimizerTest.cpp @@ -12,6 +12,7 @@ #include "isl/stream.h" #include "isl/val.h" +using namespace polly; using namespace isl; namespace {