[PATCH] D17241: [Refactor] Use ManagedStatic to manage the global isl_ctx.

Hongbin Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 13 01:06:49 PST 2016


etherzhhb created this revision.
etherzhhb added a reviewer: grosser.
etherzhhb added a subscriber: Polly.
etherzhhb set the repository for this revision to rL LLVM.

This patch makes the ScopInfo carry less context, and makes it easier for the new PassManager change.

Repository:
  rL LLVM

http://reviews.llvm.org/D17241

Files:
  include/polly/ScopInfo.h
  lib/Analysis/ScopInfo.cpp

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>() {
+  isl_ctx *ctx = isl_ctx_alloc();
+  isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
+  return ctx;
+}
+
+template <> struct object_deleter<isl_ctx> {
+  static void call(void *Ptr) { isl_ctx_free((isl_ctx *)Ptr); }
+};
+}
+
+static ManagedStatic<isl_ctx> 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<LoopInfoWrapperPass>();
Index: include/polly/ScopInfo.h
===================================================================
--- include/polly/ScopInfo.h
+++ include/polly/ScopInfo.h
@@ -2010,7 +2010,6 @@
 
   // The Scop
   std::unique_ptr<Scop> scop;
-  isl_ctx *ctx;
 
   // Clear the context.
   void clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17241.47904.patch
Type: text/x-patch
Size: 2349 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160213/829862d1/attachment.bin>


More information about the llvm-commits mailing list