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<ConstantInt> &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) {
ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
LLVMContextImpl* pImpl = Context.pImpl;
- ConstantFP *&Slot = pImpl->FPConstants[V];
+ std::unique_ptr<ConstantFP> &Slot = pImpl->FPConstants[V];
if (!Slot) {
Type *Ty;
"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) {
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];
+
+ std::unique_ptr<ConstantAggregateZero> &Entry =
+ Ty->getContext().pImpl->CAZConstants[Ty];
if (!Entry)
- Entry = new ConstantAggregateZero(Ty);
+ Entry.reset(new ConstantAggregateZero(Ty));
- return Entry;
+ return Entry.get();
}
/// Remove the constant from the constant table.
//
ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
- ConstantPointerNull *&Entry = Ty->getContext().pImpl->CPNConstants[Ty];
+ std::unique_ptr<ConstantPointerNull> &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.
}
UndefValue *UndefValue::get(Type *Ty) {
- UndefValue *&Entry = Ty->getContext().pImpl->UVConstants[Ty];
+ std::unique_ptr<UndefValue> &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.
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;
LLVMContext::YieldCallbackTy YieldCallback;
void *YieldOpaqueHandle;
- typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
+ typedef DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>
+ IntMapTy;
IntMapTy IntConstants;
- typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
+ typedef DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>
+ FPMapTy;
FPMapTy FPConstants;
FoldingSet<AttributeImpl> AttrsSet;
// them on context teardown.
std::vector<MDNode *> DistinctMDNodes;
- DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
+ DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
ArrayConstantsTy ArrayConstants;
typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
VectorConstantsTy VectorConstants;
-
- DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
- DenseMap<Type*, UndefValue*> UVConstants;
-
+ DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
+
+ DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
+
StringMap<ConstantDataSequential*> CDSConstants;
DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>