[PATCH] D21520: [SelectionDAG] use <mutex> instead of LLVM home-grown primitive

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 10:41:02 PDT 2016


davide created this revision.
davide added reviewers: bogner, resistor.
davide added a subscriber: llvm-commits.

I hope to get rid of SmartMutex et similia in the short to medium term, now that C++ has a decent infrastructure for locking. 
Some comments (on the patch):
!) SmartMutex by default allows recursion but I'm not entirely sure we need that here? Anyway, to keep the semantic equivalent to the existing code I switched to std::recursive_mutex.

2) I'm not entirely sure if we want to guard the mutex code with #if defined(LLVM_ENABLE_THREADS) to make it a no-op in the single threaded case. I wasn't able to measure a substantial impact when benchmarking, but, that goes without saying, your mileage may vary and, of course, feedback welcome.

http://reviews.llvm.org/D21520

Files:
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -38,7 +38,6 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/Mutex.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetIntrinsicInfo.h"
@@ -49,6 +48,7 @@
 #include "llvm/Target/TargetSubtargetInfo.h"
 #include <algorithm>
 #include <cmath>
+#include <mutex>
 #include <utility>
 
 using namespace llvm;
@@ -6765,13 +6765,13 @@
 
 static ManagedStatic<std::set<EVT, EVT::compareRawBits> > EVTs;
 static ManagedStatic<EVTArray> SimpleVTArray;
-static ManagedStatic<sys::SmartMutex<true> > VTMutex;
+static ManagedStatic<std::recursive_mutex> VTMutex;
 
 /// getValueTypeList - Return a pointer to the specified value type.
 ///
 const EVT *SDNode::getValueTypeList(EVT VT) {
   if (VT.isExtended()) {
-    sys::SmartScopedLock<true> Lock(*VTMutex);
+    std::lock_guard<std::recursive_mutex> Lock(*VTMutex);
     return &(*EVTs->insert(VT).first);
   } else {
     assert(VT.getSimpleVT() < MVT::LAST_VALUETYPE &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21520.61265.patch
Type: text/x-patch
Size: 1283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160620/c6ed6782/attachment.bin>


More information about the llvm-commits mailing list