<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks for fixing this!<div class="">(I didn't see this on macos)</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 04 Mar 2015, at 20:16, Reid Kleckner <<a href="mailto:rnk@google.com" class="">rnk@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I had to add a missing <atomic> include in r231277 for MSVC.</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Mar 4, 2015 at 10:57 AM, Erik Eckstein <span dir="ltr" class=""><<a href="mailto:eeckstein@apple.com" target="_blank" class="">eeckstein@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: eeckstein<br class="">
Date: Wed Mar  4 12:57:11 2015<br class="">
New Revision: 231276<br class="">
<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=231276&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=231276&view=rev</a><br class="">
Log:<br class="">
Add a lock() function in PassRegistry to speed up multi-thread synchronization.<br class="">
<br class="">
When calling lock() after all passes are registered, the PassRegistry doesn't need a mutex anymore to look up passes.<br class="">
This speeds up multithreaded llvm execution by ~5% (tested with 4 threads).<br class="">
In an asserts build of llvm this has an even bigger impact.<br class="">
<br class="">
Note that it's not required to use the lock function.<br class="">
<br class="">
<br class="">
Modified:<br class="">
    llvm/trunk/include/llvm/PassRegistry.h<br class="">
    llvm/trunk/lib/IR/PassRegistry.cpp<br class="">
<br class="">
Modified: llvm/trunk/include/llvm/PassRegistry.h<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=231276&r1=231275&r2=231276&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=231276&r1=231275&r2=231276&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/include/llvm/PassRegistry.h (original)<br class="">
+++ llvm/trunk/include/llvm/PassRegistry.h Wed Mar  4 12:57:11 2015<br class="">
@@ -41,6 +41,9 @@ struct PassRegistrationListener;<br class="">
 class PassRegistry {<br class="">
   mutable sys::SmartRWMutex<true> Lock;<br class="">
<br class="">
+  /// Only if false, synchronization must use the Lock mutex.<br class="">
+  std::atomic<bool> locked;<br class="">
+<br class="">
   /// PassInfoMap - Keep track of the PassInfo object for each registered pass.<br class="">
   typedef DenseMap<const void *, const PassInfo *> MapType;<br class="">
   MapType PassInfoMap;<br class="">
@@ -52,7 +55,7 @@ class PassRegistry {<br class="">
   std::vector<PassRegistrationListener *> Listeners;<br class="">
<br class="">
 public:<br class="">
-  PassRegistry() {}<br class="">
+  PassRegistry() : locked(false) {}<br class="">
   ~PassRegistry();<br class="">
<br class="">
   /// getPassRegistry - Access the global registry object, which is<br class="">
@@ -60,6 +63,10 @@ public:<br class="">
   /// llvm_shutdown.<br class="">
   static PassRegistry *getPassRegistry();<br class="">
<br class="">
+  /// Enables fast thread synchronization in getPassInfo().<br class="">
+  /// After calling lock() no more passes may be registered.<br class="">
+  void lock() { locked = true; }<br class="">
+<br class="">
   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the pass'<br class="">
   /// type identifier (&MyPass::ID).<br class="">
   const PassInfo *getPassInfo(const void *TI) const;<br class="">
<br class="">
Modified: llvm/trunk/lib/IR/PassRegistry.cpp<br class="">
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassRegistry.cpp?rev=231276&r1=231275&r2=231276&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/PassRegistry.cpp?rev=231276&r1=231275&r2=231276&view=diff</a><br class="">
==============================================================================<br class="">
--- llvm/trunk/lib/IR/PassRegistry.cpp (original)<br class="">
+++ llvm/trunk/lib/IR/PassRegistry.cpp Wed Mar  4 12:57:11 2015<br class="">
@@ -13,6 +13,7 @@<br class="">
 //===----------------------------------------------------------------------===//<br class="">
<br class="">
 #include "llvm/PassRegistry.h"<br class="">
+#include "llvm/ADT/Optional.h"<br class="">
 #include "llvm/IR/Function.h"<br class="">
 #include "llvm/PassSupport.h"<br class="">
 #include "llvm/Support/Compiler.h"<br class="">
@@ -39,13 +40,23 @@ PassRegistry *PassRegistry::getPassRegis<br class="">
 PassRegistry::~PassRegistry() {}<br class="">
<br class="">
 const PassInfo *PassRegistry::getPassInfo(const void *TI) const {<br class="">
-  sys::SmartScopedReader<true> Guard(Lock);<br class="">
+  // We don't need thread synchronization after the PassRegistry is locked<br class="">
+  // (that means: is read-only).<br class="">
+  Optional<sys::SmartScopedReader<true>> Guard;<br class="">
+  if (!locked)<br class="">
+    Guard.emplace(Lock);<br class="">
+<br class="">
   MapType::const_iterator I = PassInfoMap.find(TI);<br class="">
   return I != PassInfoMap.end() ? I->second : nullptr;<br class="">
 }<br class="">
<br class="">
 const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {<br class="">
-  sys::SmartScopedReader<true> Guard(Lock);<br class="">
+  // We don't need thread synchronization after the PassRegistry is locked<br class="">
+  // (that means: is read-only).<br class="">
+  Optional<sys::SmartScopedReader<true>> Guard;<br class="">
+  if (!locked)<br class="">
+    Guard.emplace(Lock);<br class="">
+<br class="">
   StringMapType::const_iterator I = PassInfoStringMap.find(Arg);<br class="">
   return I != PassInfoStringMap.end() ? I->second : nullptr;<br class="">
 }<br class="">
@@ -55,6 +66,9 @@ const PassInfo *PassRegistry::getPassInf<br class="">
 //<br class="">
<br class="">
 void PassRegistry::registerPass(const PassInfo &PI, bool ShouldFree) {<br class="">
+<br class="">
+  assert(!locked && "Trying to register a pass in a locked PassRegistry");<br class="">
+<br class="">
   sys::SmartScopedWriter<true> Guard(Lock);<br class="">
   bool Inserted =<br class="">
       PassInfoMap.insert(std::make_pair(PI.getTypeInfo(), &PI)).second;<br class="">
@@ -68,6 +82,8 @@ void PassRegistry::registerPass(const Pa<br class="">
<br class="">
   if (ShouldFree)<br class="">
     ToFree.push_back(std::unique_ptr<const PassInfo>(&PI));<br class="">
+<br class="">
+  assert(!locked && "PassRegistry locked during registering a pass");<br class="">
 }<br class="">
<br class="">
 void PassRegistry::enumerateWith(PassRegistrationListener *L) {<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>