[llvm-commits] [llvm] r114130 - in /llvm/trunk: include/llvm/PassRegistry.h lib/VMCore/PassRegistry.cpp

Chris Lattner clattner at apple.com
Thu Sep 16 16:40:47 PDT 2010


On Sep 16, 2010, at 4:32 PM, Owen Anderson wrote:

> Author: resistor
> Date: Thu Sep 16 18:32:35 2010
> New Revision: 114130
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=114130&view=rev
> Log:
> Do not expose the locking for the PassRegistry in the header.  Be careful to
> synchronize any method that might lazily initialize the pImpl.


$ make CXX.Flags=-Wglobal-constructors
llvm[0]: Compiling PassRegistry.cpp for Debug+Asserts build
PassRegistry.cpp:37:23: warning: declaration requires a global constructor [-Wglobal-constructors]
sys::SmartMutex<true> Lock;
                      ^
PassRegistry.cpp:37:23: warning: declaration requires a global destructor [-Wglobal-constructors]
2 warnings generated.

Why not ManagedStatic?

-Chris

> 
> Modified:
>    llvm/trunk/include/llvm/PassRegistry.h
>    llvm/trunk/lib/VMCore/PassRegistry.cpp
> 
> Modified: llvm/trunk/include/llvm/PassRegistry.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassRegistry.h?rev=114130&r1=114129&r2=114130&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/PassRegistry.h (original)
> +++ llvm/trunk/include/llvm/PassRegistry.h Thu Sep 16 18:32:35 2010
> @@ -18,7 +18,6 @@
> #define LLVM_PASSREGISTRY_H
> 
> #include "llvm/ADT/StringRef.h"
> -#include "llvm/System/Mutex.h"
> 
> namespace llvm {
> 
> @@ -33,7 +32,6 @@
> /// each thread.
> class PassRegistry {
>   mutable void *pImpl;
> -  mutable sys::SmartMutex<true> Lock;
>   void *getImpl() const;
> 
> public:
> 
> Modified: llvm/trunk/lib/VMCore/PassRegistry.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassRegistry.cpp?rev=114130&r1=114129&r2=114130&view=diff
> ==============================================================================
> --- llvm/trunk/lib/VMCore/PassRegistry.cpp (original)
> +++ llvm/trunk/lib/VMCore/PassRegistry.cpp Thu Sep 16 18:32:35 2010
> @@ -16,6 +16,7 @@
> #include "llvm/PassSupport.h"
> #include "llvm/Support/Compiler.h"
> #include "llvm/Support/ManagedStatic.h"
> +#include "llvm/System/Mutex.h"
> #include "llvm/ADT/DenseMap.h"
> #include "llvm/ADT/SmallPtrSet.h"
> #include "llvm/ADT/StringMap.h"
> @@ -33,6 +34,8 @@
>   return &*PassRegistryObj;
> }
> 
> +sys::SmartMutex<true> Lock;
> +
> //===----------------------------------------------------------------------===//
> // PassRegistryImpl
> //
> @@ -65,18 +68,21 @@
> //
> 
> PassRegistry::~PassRegistry() {
> +  sys::SmartScopedLock<true> Guard(Lock);
>   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(pImpl);
>   if (Impl) delete Impl;
>   pImpl = 0;
> }
> 
> const PassInfo *PassRegistry::getPassInfo(const void *TI) const {
> +  sys::SmartScopedLock<true> Guard(Lock);
>   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
>   PassRegistryImpl::MapType::const_iterator I = Impl->PassInfoMap.find(TI);
>   return I != Impl->PassInfoMap.end() ? I->second : 0;
> }
> 
> const PassInfo *PassRegistry::getPassInfo(StringRef Arg) const {
> +  sys::SmartScopedLock<true> Guard(Lock);
>   PassRegistryImpl *Impl = static_cast<PassRegistryImpl*>(getImpl());
>   PassRegistryImpl::StringMapType::const_iterator
>     I = Impl->PassInfoStringMap.find(Arg);
> @@ -127,7 +133,6 @@
>                                          const void *PassID,
>                                          PassInfo& Registeree,
>                                          bool isDefault) {
> -  sys::SmartScopedLock<true> Guard(Lock);
>   PassInfo *InterfaceInfo =  const_cast<PassInfo*>(getPassInfo(InterfaceID));
>   if (InterfaceInfo == 0) {
>     // First reference to Interface, register it now.
> @@ -142,6 +147,8 @@
>     assert(ImplementationInfo &&
>            "Must register pass before adding to AnalysisGroup!");
> 
> +    sys::SmartScopedLock<true> Guard(Lock);
> +    
>     // Make sure we keep track of the fact that the implementation implements
>     // the interface.
>     ImplementationInfo->addInterfaceImplemented(InterfaceInfo);
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list