Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -2010,7 +2010,6 @@ // The Scop std::unique_ptr scop; - isl_ctx *ctx; // Clear the context. void clear(); Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -38,6 +38,7 @@ #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/IR/DiagnosticInfo.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/ManagedStatic.h" #include "isl/aff.h" #include "isl/constraint.h" #include "isl/local_space.h" @@ -112,6 +113,21 @@ cl::Hidden, cl::ZeroOrMore, cl::init(false), cl::cat(PollyCategory)); //===----------------------------------------------------------------------===// +// Manage the global Scop context with ManagedStatic. And define the necessary +// creator and deleter below. +namespace llvm { +template <> void *object_creator() { + isl_ctx *ctx = isl_ctx_alloc(); + isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT); + return ctx; +} + +template <> struct object_deleter { + static void call(void *Ptr) { isl_ctx_free((isl_ctx *)Ptr); } +}; +} + +static ManagedStatic Ctx; // 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 @@ -4126,7 +4142,7 @@ void ScopInfo::buildScop(Region &R, AssumptionCache &AC) { unsigned MaxLoopDepth = getMaxLoopDepthInRegion(R, *LI, *SD); - scop.reset(new Scop(R, *SE, ctx, MaxLoopDepth)); + scop.reset(new Scop(R, *SE, &*Ctx, MaxLoopDepth)); buildStmts(R, R); buildAccessFunctions(R, R, SD->getInsnToMemAccMap()); @@ -4157,15 +4173,9 @@ void ScopInfo::clear() { scop.reset(); } //===----------------------------------------------------------------------===// -ScopInfo::ScopInfo() : RegionPass(ID) { - ctx = isl_ctx_alloc(); - isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT); -} +ScopInfo::ScopInfo() : RegionPass(ID) {} -ScopInfo::~ScopInfo() { - clear(); - isl_ctx_free(ctx); -} +ScopInfo::~ScopInfo() { clear(); } void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired();