[llvm-commits] [llvm] r73639 - /llvm/trunk/lib/VMCore/PassManager.cpp

Chris Lattner clattner at apple.com
Wed Jun 17 17:40:35 PDT 2009


On Jun 17, 2009, at 2:28 PM, Owen Anderson wrote:

> Author: resistor
> Date: Wed Jun 17 16:28:54 2009
> New Revision: 73639
>
> URL: http://llvm.org/viewvc/llvm-project?rev=73639&view=rev
> Log:
> Guard mutation of the timing info global.

Owen, why does all this code need to explicitly check to see if  
multithreading is on?  It seems like you should change sys::Mutex to  
take a template argument that indicates whether it does this or not by  
default.  Forcing all the clients to do this is bad.

-Chris

>
>
> Modified:
>    llvm/trunk/lib/VMCore/PassManager.cpp
>
> Modified: llvm/trunk/lib/VMCore/PassManager.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/PassManager.cpp?rev=73639&r1=73638&r2=73639&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/VMCore/PassManager.cpp (original)
> +++ llvm/trunk/lib/VMCore/PassManager.cpp Wed Jun 17 16:28:54 2009
> @@ -20,6 +20,8 @@
> #include "llvm/Support/Streams.h"
> #include "llvm/Support/ManagedStatic.h"
> #include "llvm/Support/raw_ostream.h"
> +#include "llvm/Support/Threading.h"
> +#include "llvm/System/Mutex.h"
> #include "llvm/Analysis/Dominators.h"
> #include "llvm-c/Core.h"
> #include <algorithm>
> @@ -355,6 +357,9 @@
> /// amount of time each pass takes to execute.  This only happens when
> /// -time-passes is enabled on the command line.
> ///
> +
> +static ManagedStatic<sys::Mutex> TimingInfoMutex;
> +
> class VISIBILITY_HIDDEN TimingInfo {
>   std::map<Pass*, Timer> TimingData;
>   TimerGroup TG;
> @@ -379,18 +384,22 @@
>     if (dynamic_cast<PMDataManager *>(P))
>       return;
>
> +    if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
>     std::map<Pass*, Timer>::iterator I = TimingData.find(P);
>     if (I == TimingData.end())
>       I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(),  
> TG))).first;
>     I->second.startTimer();
> +    if (llvm_is_multithreaded()) TimingInfoMutex->release();
>   }
>   void passEnded(Pass *P) {
>     if (dynamic_cast<PMDataManager *>(P))
>       return;
>
> +    if (llvm_is_multithreaded()) TimingInfoMutex->acquire();
>     std::map<Pass*, Timer>::iterator I = TimingData.find(P);
>     assert(I != TimingData.end() && "passStarted/passEnded not  
> nested right!");
>     I->second.stopTimer();
> +    if (llvm_is_multithreaded()) TimingInfoMutex->release();
>   }
> };
>
>
>
> _______________________________________________
> 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