forked from OSchip/llvm-project
parent
c94cf8faf6
commit
962c272f95
|
@ -993,33 +993,18 @@ bool ConstantFP::isValueValidForType(Type *Ty, const APFloat& Val) {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Factory Function Implementation
|
// Factory Function Implementation
|
||||||
|
|
||||||
ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
|
ConstantAggregateZero* ConstantAggregateZero::get(Type* Ty) {
|
||||||
assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
|
assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
|
||||||
"Cannot create an aggregate zero of non-aggregate type!");
|
"Cannot create an aggregate zero of non-aggregate type!");
|
||||||
|
|
||||||
OwningPtr<ConstantAggregateZero> &Entry =
|
LLVMContextImpl *pImpl = Ty->getContext().pImpl;
|
||||||
Ty->getContext().pImpl->CAZConstants[Ty];
|
return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
|
||||||
if (Entry == 0)
|
|
||||||
Entry.reset(new ConstantAggregateZero(Ty));
|
|
||||||
|
|
||||||
return Entry.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// destroyConstant - Remove the constant from the constant table...
|
/// destroyConstant - Remove the constant from the constant table...
|
||||||
///
|
///
|
||||||
void ConstantAggregateZero::destroyConstant() {
|
void ConstantAggregateZero::destroyConstant() {
|
||||||
// Drop ownership of the CAZ object before removing the entry so that it
|
getType()->getContext().pImpl->AggZeroConstants.remove(this);
|
||||||
// doesn't get double deleted.
|
|
||||||
LLVMContextImpl::CAZMapTy &CAZConstants = getContext().pImpl->CAZConstants;
|
|
||||||
LLVMContextImpl::CAZMapTy::iterator I = CAZConstants.find(getType());
|
|
||||||
assert(I != CAZConstants.end() && "CAZ object not in uniquing map");
|
|
||||||
I->second.take();
|
|
||||||
|
|
||||||
// Actually remove the entry from the DenseMap now, which won't free the
|
|
||||||
// constant.
|
|
||||||
CAZConstants.erase(I);
|
|
||||||
|
|
||||||
// Free the constant and any dangling references to it.
|
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,29 +1112,13 @@ Constant *ConstantVector::getSplatValue() const {
|
||||||
//
|
//
|
||||||
|
|
||||||
ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
|
ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
|
||||||
OwningPtr<ConstantPointerNull> &Entry =
|
return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0);
|
||||||
Ty->getContext().pImpl->CPNConstants[Ty];
|
|
||||||
if (Entry == 0)
|
|
||||||
Entry.reset(new ConstantPointerNull(Ty));
|
|
||||||
|
|
||||||
return Entry.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantPointerNull::destroyConstant() {
|
void ConstantPointerNull::destroyConstant() {
|
||||||
// Drop ownership of the CPN object before removing the entry so that it
|
getType()->getContext().pImpl->NullPtrConstants.remove(this);
|
||||||
// doesn't get double deleted.
|
|
||||||
LLVMContextImpl::CPNMapTy &CPNConstants = getContext().pImpl->CPNConstants;
|
|
||||||
LLVMContextImpl::CPNMapTy::iterator I = CPNConstants.find(getType());
|
|
||||||
assert(I != CPNConstants.end() && "CPN object not in uniquing map");
|
|
||||||
I->second.take();
|
|
||||||
|
|
||||||
// Actually remove the entry from the DenseMap now, which won't free the
|
|
||||||
// constant.
|
|
||||||
CPNConstants.erase(I);
|
|
||||||
|
|
||||||
// Free the constant and any dangling references to it.
|
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1158,28 +1127,13 @@ void ConstantPointerNull::destroyConstant() {
|
||||||
//
|
//
|
||||||
|
|
||||||
UndefValue *UndefValue::get(Type *Ty) {
|
UndefValue *UndefValue::get(Type *Ty) {
|
||||||
OwningPtr<UndefValue> &Entry = Ty->getContext().pImpl->UVConstants[Ty];
|
return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
|
||||||
if (Entry == 0)
|
|
||||||
Entry.reset(new UndefValue(Ty));
|
|
||||||
|
|
||||||
return Entry.get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroyConstant - Remove the constant from the constant table.
|
// destroyConstant - Remove the constant from the constant table.
|
||||||
//
|
//
|
||||||
void UndefValue::destroyConstant() {
|
void UndefValue::destroyConstant() {
|
||||||
// Drop ownership of the object before removing the entry so that it
|
getType()->getContext().pImpl->UndefValueConstants.remove(this);
|
||||||
// doesn't get double deleted.
|
|
||||||
LLVMContextImpl::UVMapTy &UVConstants = getContext().pImpl->UVConstants;
|
|
||||||
LLVMContextImpl::UVMapTy::iterator I = UVConstants.find(getType());
|
|
||||||
assert(I != UVConstants.end() && "UV object not in uniquing map");
|
|
||||||
I->second.take();
|
|
||||||
|
|
||||||
// Actually remove the entry from the DenseMap now, which won't free the
|
|
||||||
// constant.
|
|
||||||
UVConstants.erase(I);
|
|
||||||
|
|
||||||
// Free the constant and any dangling references to it.
|
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -477,6 +477,13 @@ struct ConstantKeyData<ConstantExpr> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ConstantAggregateZero does not take extra "value" argument...
|
||||||
|
template<class ValType>
|
||||||
|
struct ConstantCreator<ConstantAggregateZero, Type, ValType> {
|
||||||
|
static ConstantAggregateZero *create(Type *Ty, const ValType &V){
|
||||||
|
return new ConstantAggregateZero(Ty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConstantKeyData<ConstantVector> {
|
struct ConstantKeyData<ConstantVector> {
|
||||||
|
@ -490,6 +497,14 @@ struct ConstantKeyData<ConstantVector> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct ConstantKeyData<ConstantAggregateZero> {
|
||||||
|
typedef char ValType;
|
||||||
|
static ValType getValType(ConstantAggregateZero *C) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConstantKeyData<ConstantArray> {
|
struct ConstantKeyData<ConstantArray> {
|
||||||
typedef std::vector<Constant*> ValType;
|
typedef std::vector<Constant*> ValType;
|
||||||
|
@ -514,6 +529,37 @@ struct ConstantKeyData<ConstantStruct> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ConstantPointerNull does not take extra "value" argument...
|
||||||
|
template<class ValType>
|
||||||
|
struct ConstantCreator<ConstantPointerNull, PointerType, ValType> {
|
||||||
|
static ConstantPointerNull *create(PointerType *Ty, const ValType &V){
|
||||||
|
return new ConstantPointerNull(Ty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct ConstantKeyData<ConstantPointerNull> {
|
||||||
|
typedef char ValType;
|
||||||
|
static ValType getValType(ConstantPointerNull *C) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// UndefValue does not take extra "value" argument...
|
||||||
|
template<class ValType>
|
||||||
|
struct ConstantCreator<UndefValue, Type, ValType> {
|
||||||
|
static UndefValue *create(Type *Ty, const ValType &V) {
|
||||||
|
return new UndefValue(Ty);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct ConstantKeyData<UndefValue> {
|
||||||
|
typedef char ValType;
|
||||||
|
static ValType getValType(UndefValue *C) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType> {
|
struct ConstantCreator<InlineAsm, PointerType, InlineAsmKeyType> {
|
||||||
|
|
|
@ -58,8 +58,6 @@ LLVMContextImpl::~LLVMContextImpl() {
|
||||||
std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
|
std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
|
||||||
DeleteContainerPointers(Modules);
|
DeleteContainerPointers(Modules);
|
||||||
|
|
||||||
// Free the constants. This is important to do here to ensure that they are
|
|
||||||
// freed before the LeakDetector is torn down.
|
|
||||||
std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
|
std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
|
||||||
DropReferences());
|
DropReferences());
|
||||||
std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
|
std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
|
||||||
|
@ -72,9 +70,9 @@ LLVMContextImpl::~LLVMContextImpl() {
|
||||||
ArrayConstants.freeConstants();
|
ArrayConstants.freeConstants();
|
||||||
StructConstants.freeConstants();
|
StructConstants.freeConstants();
|
||||||
VectorConstants.freeConstants();
|
VectorConstants.freeConstants();
|
||||||
CAZConstants.clear();
|
AggZeroConstants.freeConstants();
|
||||||
CPNConstants.clear();
|
NullPtrConstants.freeConstants();
|
||||||
UVConstants.clear();
|
UndefValueConstants.freeConstants();
|
||||||
InlineAsms.freeConstants();
|
InlineAsms.freeConstants();
|
||||||
DeleteContainerSeconds(IntConstants);
|
DeleteContainerSeconds(IntConstants);
|
||||||
DeleteContainerSeconds(FPConstants);
|
DeleteContainerSeconds(FPConstants);
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/FoldingSet.h"
|
#include "llvm/ADT/FoldingSet.h"
|
||||||
#include "llvm/ADT/OwningPtr.h"
|
|
||||||
#include "llvm/ADT/SmallPtrSet.h"
|
#include "llvm/ADT/SmallPtrSet.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -139,8 +138,7 @@ public:
|
||||||
// on Context destruction.
|
// on Context destruction.
|
||||||
SmallPtrSet<MDNode*, 1> NonUniquedMDNodes;
|
SmallPtrSet<MDNode*, 1> NonUniquedMDNodes;
|
||||||
|
|
||||||
typedef DenseMap<Type*, OwningPtr<ConstantAggregateZero> > CAZMapTy;
|
ConstantUniqueMap<char, char, Type, ConstantAggregateZero> AggZeroConstants;
|
||||||
CAZMapTy CAZConstants;
|
|
||||||
|
|
||||||
typedef ConstantUniqueMap<std::vector<Constant*>, ArrayRef<Constant*>,
|
typedef ConstantUniqueMap<std::vector<Constant*>, ArrayRef<Constant*>,
|
||||||
ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy;
|
ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy;
|
||||||
|
@ -154,11 +152,9 @@ public:
|
||||||
VectorType, ConstantVector> VectorConstantsTy;
|
VectorType, ConstantVector> VectorConstantsTy;
|
||||||
VectorConstantsTy VectorConstants;
|
VectorConstantsTy VectorConstants;
|
||||||
|
|
||||||
typedef DenseMap<PointerType*, OwningPtr<ConstantPointerNull> > CPNMapTy;
|
ConstantUniqueMap<char, char, PointerType, ConstantPointerNull>
|
||||||
CPNMapTy CPNConstants;
|
NullPtrConstants;
|
||||||
|
ConstantUniqueMap<char, char, Type, UndefValue> UndefValueConstants;
|
||||||
typedef DenseMap<Type*, OwningPtr<UndefValue> > UVMapTy;
|
|
||||||
UVMapTy UVConstants;
|
|
||||||
|
|
||||||
DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses;
|
DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses;
|
||||||
ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr>
|
ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr>
|
||||||
|
|
Loading…
Reference in New Issue