summaryrefslogtreecommitdiff
path: root/lib/CodeGen/SelectionDAG
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-08-25 22:27:22 +0000
committerOwen Anderson <resistor@mac.com>2009-08-25 22:27:22 +0000
commitd8110fb7264993f30133c532cd074313bead0afa (patch)
treea3746e283d0eea162864ae9054061d5d8f1bfee5 /lib/CodeGen/SelectionDAG
parent75b0edae7275436c1255c10eb98e5b0dffc978f6 (diff)
downloadllvm-d8110fb7264993f30133c532cd074313bead0afa.tar.gz
llvm-d8110fb7264993f30133c532cd074313bead0afa.tar.bz2
llvm-d8110fb7264993f30133c532cd074313bead0afa.tar.xz
Get rid of this horrible "benign race" by exploiting ManagedStatic to initialize
the array on its first access. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80040 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/SelectionDAG')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAG.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index cbc4dc886c..11f12c9475 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5014,8 +5014,20 @@ void SDNode::Profile(FoldingSetNodeID &ID) const {
AddNodeIDNode(ID, this);
}
+namespace {
+ struct EVTArray {
+ std::vector<EVT> VTs;
+
+ EVTArray() {
+ VTs.reserve(MVT::LAST_VALUETYPE);
+ for (unsigned i = 0; i < MVT::LAST_VALUETYPE; ++i)
+ VTs.push_back(MVT((MVT::SimpleValueType)i));
+ }
+ };
+}
+
static ManagedStatic<std::set<EVT, EVT::compareRawBits> > EVTs;
-static EVT VTs[MVT::LAST_VALUETYPE];
+static ManagedStatic<EVTArray> SimpleVTArray;
static ManagedStatic<sys::SmartMutex<true> > VTMutex;
/// getValueTypeList - Return a pointer to the specified value type.
@@ -5025,12 +5037,7 @@ const EVT *SDNode::getValueTypeList(EVT VT) {
sys::SmartScopedLock<true> Lock(*VTMutex);
return &(*EVTs->insert(VT).first);
} else {
- // All writes to this location will have the same value, so it's ok
- // to race on it. We only need to ensure that at least one write has
- // succeeded before we return the pointer into the array.
- VTs[VT.getSimpleVT().SimpleTy] = VT;
- sys::MemoryFence();
- return VTs + VT.getSimpleVT().SimpleTy;
+ return &SimpleVTArray->VTs[VT.getSimpleVT().SimpleTy];
}
}