Index: llvm/lib/IR/Constants.cpp =================================================================== --- llvm/lib/IR/Constants.cpp +++ llvm/lib/IR/Constants.cpp @@ -545,14 +545,14 @@ ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt &V) { // get an existing value or the insertion position LLVMContextImpl *pImpl = Context.pImpl; - ConstantInt *&Slot = pImpl->IntConstants[V]; + std::unique_ptr &Slot = pImpl->IntConstants[V]; if (!Slot) { // Get the corresponding integer type for the bit width of the value. IntegerType *ITy = IntegerType::get(Context, V.getBitWidth()); - Slot = new ConstantInt(ITy, V); + Slot.reset(new ConstantInt(ITy, V)); } assert(Slot->getType() == IntegerType::get(Context, V.getBitWidth())); - return Slot; + return Slot.get(); } Constant *ConstantInt::get(Type *Ty, uint64_t V, bool isSigned) { @@ -685,7 +685,7 @@ ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) { LLVMContextImpl* pImpl = Context.pImpl; - ConstantFP *&Slot = pImpl->FPConstants[V]; + std::unique_ptr &Slot = pImpl->FPConstants[V]; if (!Slot) { Type *Ty; @@ -704,10 +704,10 @@ "Unknown FP format"); Ty = Type::getPPC_FP128Ty(Context); } - Slot = new ConstantFP(Ty, V); + Slot.reset(new ConstantFP(Ty, V)); } - return Slot; + return Slot.get(); } Constant *ConstantFP::getInfinity(Type *Ty, bool Negative) { @@ -1259,12 +1259,13 @@ ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) { assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) && "Cannot create an aggregate zero of non-aggregate type!"); - - ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty]; - if (!Entry) - Entry = new ConstantAggregateZero(Ty); - return Entry; + std::unique_ptr &Entry = + Ty->getContext().pImpl->CAZConstants[Ty]; + if (!Entry) + Entry.reset(new ConstantAggregateZero(Ty)); + + return Entry.get(); } /// Remove the constant from the constant table. @@ -1325,11 +1326,12 @@ // ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) { - ConstantPointerNull *&Entry = Ty->getContext().pImpl->CPNConstants[Ty]; + std::unique_ptr &Entry = + Ty->getContext().pImpl->CPNConstants[Ty]; if (!Entry) - Entry = new ConstantPointerNull(Ty); + Entry.reset(new ConstantPointerNull(Ty)); - return Entry; + return Entry.get(); } /// Remove the constant from the constant table. @@ -1338,11 +1340,11 @@ } UndefValue *UndefValue::get(Type *Ty) { - UndefValue *&Entry = Ty->getContext().pImpl->UVConstants[Ty]; + std::unique_ptr &Entry = Ty->getContext().pImpl->UVConstants[Ty]; if (!Entry) - Entry = new UndefValue(Ty); + Entry.reset(new UndefValue(Ty)); - return Entry; + return Entry.get(); } /// Remove the constant from the constant table. Index: llvm/lib/IR/LLVMContextImpl.h =================================================================== --- llvm/lib/IR/LLVMContextImpl.h +++ llvm/lib/IR/LLVMContextImpl.h @@ -1049,10 +1049,12 @@ LLVMContext::YieldCallbackTy YieldCallback; void *YieldOpaqueHandle; - typedef DenseMap IntMapTy; + typedef DenseMap, DenseMapAPIntKeyInfo> + IntMapTy; IntMapTy IntConstants; - typedef DenseMap FPMapTy; + typedef DenseMap, DenseMapAPFloatKeyInfo> + FPMapTy; FPMapTy FPConstants; FoldingSet AttrsSet; @@ -1078,7 +1080,7 @@ // them on context teardown. std::vector DistinctMDNodes; - DenseMap CAZConstants; + DenseMap> CAZConstants; typedef ConstantUniqueMap ArrayConstantsTy; ArrayConstantsTy ArrayConstants; @@ -1088,11 +1090,11 @@ typedef ConstantUniqueMap VectorConstantsTy; VectorConstantsTy VectorConstants; - - DenseMap CPNConstants; - DenseMap UVConstants; - + DenseMap> CPNConstants; + + DenseMap> UVConstants; + StringMap CDSConstants; DenseMap, BlockAddress *> Index: llvm/lib/IR/LLVMContextImpl.cpp =================================================================== --- llvm/lib/IR/LLVMContextImpl.cpp +++ llvm/lib/IR/LLVMContextImpl.cpp @@ -94,12 +94,13 @@ ArrayConstants.freeConstants(); StructConstants.freeConstants(); VectorConstants.freeConstants(); - DeleteContainerSeconds(CAZConstants); - DeleteContainerSeconds(CPNConstants); - DeleteContainerSeconds(UVConstants); InlineAsms.freeConstants(); - DeleteContainerSeconds(IntConstants); - DeleteContainerSeconds(FPConstants); + + CAZConstants.clear(); + CPNConstants.clear(); + UVConstants.clear(); + IntConstants.clear(); + FPConstants.clear(); for (auto &CDSConstant : CDSConstants) delete CDSConstant.second;