[llvm] r231385 - Revert r231276 (including r231277): Add a lock() function in PassRegistry to speed up multi-thread synchronization.

Erik Eckstein eeckstein at apple.com
Thu Mar 5 09:53:00 PST 2015


Author: eeckstein
Date: Thu Mar  5 11:53:00 2015
New Revision: 231385

URL: http://llvm.org/viewvc/llvm-project?rev=231385&view=rev
Log:
Revert r231276 (including r231277): Add a lock() function in PassRegistry to speed up multi-thread synchronization.


Modified:
    llvm/trunk/include/llvm/PassRegistry.h
    llvm/trunk/lib/IR/PassRegistry.cpp

Modified: llvm/trunk/include/llvm/PassRegistry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=231385&r1=231384&r2=231385&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassRegistry.h (original)
+++ llvm/trunk/include/llvm/PassRegistry.h Thu Mar  5 11:53:00 2015
@@ -25,7 +25,6 @@
 #include "llvm/PassInfo.h"
 #include "llvm/Support/CBindingWrapping.h"
 #include "llvm/Support/RWMutex.h"
-#include <atomic>
 #include <vector>
 
 namespace llvm {
@@ -42,9 +41,6 @@ struct PassRegistrationListener;
 class PassRegistry {
   mutable sys::SmartRWMutex<true> Lock;
 
-  /// Only if false, synchronization must use the Lock mutex.
-  std::atomic<bool> locked;
-
   /// PassInfoMap - Keep track of the PassInfo object for each registered pass.
   typedef DenseMap<const void *, const PassInfo *> MapType;
   MapType PassInfoMap;
@@ -56,7 +52,7 @@ class PassRegistry {
   std::vector<PassRegistrationListener *> Listeners;
 
 public:
-  PassRegistry() : locked(false) {}
+  PassRegistry() {}
   ~PassRegistry();
 
   /// getPassRegistry - Access the global registry object, which is
@@ -64,10 +60,6 @@ public:
   /// llvm_shutdown.
   static PassRegistry *getPassRegistry();
 
-  /// Enables fast thread synchronization in getPassInfo().
-  /// After calling lock() no more passes may be registered.
-  void lock() { locked = true; }
-
   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'
   /// type identifier (&MyPass::ID).
   const PassInfo *getPassInfo(const void *TI) const;

Modified: llvm/trunk/lib/IR/PassRegistry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassRegistry.cpp?rev=231385&r1=231384&r2=231385&view=diff
==============================================================================
--- llvm/trunk/lib/IR/PassRegistry.cpp (original)
+++ llvm/trunk/lib/IR/PassRegistry.cpp Thu Mar  5 11:53:00 2015
@@ -13,7 +13,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/PassRegistry.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/IR/Function.h"
 #include "llvm/PassSupport.h"
 #include "llvm/Support/Compiler.h"
@@ -40,23 +39,13 @@ PassRegistry *PassRegistry::getPassRegis
 PassRegistry::~PassRegistry() {}
 
 const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
-  // We don't need thread synchronization after the PassRegistry is locked
-  // (that means: is read-only).
-  Optional<sys::SmartScopedReader<true>> Guard;
-  if (!locked)
-    Guard.emplace(Lock);
-
+  sys::SmartScopedReader<true> Guard(Lock);
   MapType::const_iterator I = PassInfoMap.find(TI);
   return I != PassInfoMap.end() ? I->second : nullptr;
 }
 
 const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
-  // We don't need thread synchronization after the PassRegistry is locked
-  // (that means: is read-only).
-  Optional<sys::SmartScopedReader<true>> Guard;
-  if (!locked)
-    Guard.emplace(Lock);
-
+  sys::SmartScopedReader<true> Guard(Lock);
   StringMapType::const_iterator I = PassInfoStringMap.find(Arg);
   return I != PassInfoStringMap.end() ? I->second : nullptr;
 }
@@ -66,9 +55,6 @@ const PassInfo *PassRegistry::getPassInf
 //
 
 void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {
-
-  assert(!locked && "Trying to register a pass in a locked PassRegistry");
-
   sys::SmartScopedWriter<true> Guard(Lock);
   bool Inserted =
       PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;
@@ -82,8 +68,6 @@ void PassRegistry::registerPass(const Pa
 
   if (ShouldFree)
     ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));
-
-  assert(!locked && "PassRegistry locked during registering a pass");
 }
 
 void PassRegistry::enumerateWith(PassRegistrationListener *L) {





More information about the llvm-commits mailing list