[PATCH] D17241: [Refactor] Move isl_ctx into Scop.

Hongbin Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 13 07:40:03 PST 2016


etherzhhb retitled this revision from "[Refactor] Use ManagedStatic to manage the global isl_ctx." to "[Refactor] Move isl_ctx into Scop.".
etherzhhb updated this revision to Diff 47909.
etherzhhb added a comment.

I have no opinion whether we should share isl_ctx across SCoPs or should make it becomes SCoP local, because I have no idea what context does it carry and  how it is used.

I think  make it becomes SCoP local is a good idea since the SCoPs are independent.

However, this patch does *NOT* work, and I get the following stack dump:

#6 0x00007ffff6a01528 abort /build/glibc-3Vu5mt/glibc-2.19/stdlib/abort.c:91:0
#7 0x00007ffff6581856 isl_handle_error /home/ether/work/llvm/tools/polly/lib/External/isl/isl_ctx.c:93:0
#8 0x00007ffff6581d35 isl_ctx_free /home/ether/work/llvm/tools/polly/lib/External/isl/isl_ctx.c:243:0
#9 0x00007ffff648a95c polly::Scop::~Scop() /home/ether/work/llvm/tools/polly/lib/Analysis/ScopInfo.cpp:2777:0
#10 0x00007ffff64a650a std::default_delete<polly::Scop>::operator()(polly::Scop*) const /usr/include/c++/4.9/bits/unique_ptr.h:76:0
#11 0x00007ffff649e6db std::unique_ptr<polly::Scop, std::default_delete<polly::Scop> >::reset(polly::Scop*) /usr/include/c++/4.9/bits/unique_ptr.h:345:0
#12 0x00007ffff6490b85 polly::ScopInfo::clear() /home/ether/work/llvm/tools/polly/lib/Analysis/ScopInfo.cpp:4157:0
#13 0x00007ffff64951de polly::ScopInfo::releaseMemory() /home/ether/work/llvm/tools/polly/include/polly/ScopInfo.h:2223:0
#14 0x000000000169a1dc llvm::PMDataManager::freePass(llvm::Pass*, llvm::StringRef, llvm::PassDebuggingString) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:976:0
#15 0x000000000169a0ee llvm::PMDataManager::removeDeadPasses(llvm::Pass*, llvm::StringRef, llvm::PassDebuggingString) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:964:0
#16 0x000000000119d602 llvm::RGPassManager::runOnFunction(llvm::Function&) /home/ether/work/llvm/lib/Analysis/RegionPass.cpp:130:0
#17 0x000000000169c75e llvm::FPPassManager::runOnFunction(llvm::Function&) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:1550:0
#18 0x000000000169c8f1 llvm::FPPassManager::runOnModule(llvm::Module&) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:1571:0
#19 0x000000000169cc7d (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:1627:0
#20 0x000000000169d373 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:1730:0
#21 0x000000000169d5b3 llvm::legacy::PassManager::run(llvm::Module&) /home/ether/work/llvm/lib/IR/LegacyPassManager.cpp:1762:0
#22 0x0000000000de12b5 main /home/ether/work/llvm/tools/opt/opt.cpp:631:0

I free the IslCtx by "isl_ctx_free(IslCtx)" at the end of the destructor and get the above error. I don't know why this happens, any hit?


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);
@@ -4156,15 +4172,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.47909.patch
Type: text/x-patch
Size: 2323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160213/5ffa18a8/attachment.bin>


More information about the llvm-commits mailing list