[llvm-commits] [llvm] r80040 - /llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Chris Lattner
clattner at apple.com
Tue Aug 25 21:24:35 PDT 2009
On Aug 25, 2009, at 3:27 PM, Owen Anderson wrote:
> Author: resistor
> Date: Tue Aug 25 17:27:22 2009
> New Revision: 80040
>
> URL: http://llvm.org/viewvc/llvm-project?rev=80040&view=rev
> Log:
> Get rid of this horrible "benign race" by exploiting ManagedStatic
> to initialize
> the array on its first access.
Thanks Owen, very nice!
-Chris
>
> Modified:
> llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp?rev=80040&r1=80039&r2=80040&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Tue Aug 25
> 17:27:22 2009
> @@ -5014,8 +5014,20 @@
> 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 @@
> 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];
> }
> }
>
>
>
> _______________________________________________
> 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