[llvm-commits] [llvm] r73628 - /llvm/trunk/lib/VMCore/Constants.cpp
Bill Wendling
isanbard at gmail.com
Wed Jun 17 13:30:40 PDT 2009
On Wed, Jun 17, 2009 at 1:10 PM, Owen Anderson<resistor at mac.com> wrote:
> --- llvm/trunk/lib/VMCore/Constants.cpp (original)
> +++ llvm/trunk/lib/VMCore/Constants.cpp Wed Jun 17 15:10:08 2009
> @@ -1225,37 +1229,85 @@
> /// necessary.
> ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
> MapKey Lookup(Ty, V);
> - typename MapTy::iterator I = Map.find(Lookup);
> - // Is it in the map?
> - if (I != Map.end())
> - return static_cast<ConstantClass *>(I->second);
> -
> - // If no preexisting value, create one now...
> - ConstantClass *Result =
> - ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
> -
> - assert(Result->getType() == Ty && "Type specified is not correct!");
> - I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
> -
> - if (HasLargeKey) // Remember the reverse mapping if needed.
> - InverseMap.insert(std::make_pair(Result, I));
> -
> - // If the type of the constant is abstract, make sure that an entry exists
> - // for it in the AbstractTypeMap.
> - if (Ty->isAbstract()) {
> - typename AbstractTypeMapTy::iterator TI = AbstractTypeMap.find(Ty);
> -
> - if (TI == AbstractTypeMap.end()) {
> - // Add ourselves to the ATU list of the type.
> - cast<DerivedType>(Ty)->addAbstractTypeUser(this);
> -
> - AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
> + if (llvm_is_multithreaded()) {
> + ConstantClass* Result = 0;
> +
> + ConstantsLock->reader_acquire();
> + typename MapTy::iterator I = Map.find(Lookup);
> + // Is it in the map?
> + if (I != Map.end())
> + Result = static_cast<ConstantClass *>(I->second);
> + ConstantsLock->reader_release();
> +
> + if (!Result) {
> + ConstantsLock->writer_acquire();
> + I = Map.find(Lookup);
> + // Is it in the map?
> + if (I != Map.end())
> + Result = static_cast<ConstantClass *>(I->second);
> + if (!Result) {
> + // If no preexisting value, create one now...
> + Result =
> + ConstantCreator<ConstantClass,TypeClass,ValType>::create(Ty, V);
> +
> + assert(Result->getType() == Ty && "Type specified is not correct!");
> + I = Map.insert(I, std::make_pair(MapKey(Ty, V), Result));
> +
> + if (HasLargeKey) // Remember the reverse mapping if needed.
> + InverseMap.insert(std::make_pair(Result, I));
> +
> + // If the type of the constant is abstract, make sure that an entry
> + // exists for it in the AbstractTypeMap.
> + if (Ty->isAbstract()) {
> + typename AbstractTypeMapTy::iterator TI =
> + AbstractTypeMap.find(Ty);
> +
> + if (TI == AbstractTypeMap.end()) {
> + // Add ourselves to the ATU list of the type.
> + cast<DerivedType>(Ty)->addAbstractTypeUser(this);
> +
> + AbstractTypeMap.insert(TI, std::make_pair(Ty, I));
> + }
> + }
> + }
> + ConstantsLock->writer_release();
> }
Owen,
Could you revisit and rework this so that so much code isn't copied in
the if-then-else statement?
-bw
More information about the llvm-commits
mailing list