llvm.org GIT mirror llvm / 3755615
switch UndefValue and ConstantPointerNull over to DenseMap's for uniquing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148693 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
4 changed file(s) with 44 addition(s) and 40 deletion(s). Raw diff Collapse all Expand all
11261126 //
11271127
11281128 ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
1129 return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0);
1129 OwningPtr &Entry =
1130 Ty->getContext().pImpl->CPNConstants[Ty];
1131 if (Entry == 0)
1132 Entry.reset(new ConstantPointerNull(Ty));
1133
1134 return Entry.get();
11301135 }
11311136
11321137 // destroyConstant - Remove the constant from the constant table...
11331138 //
11341139 void ConstantPointerNull::destroyConstant() {
1135 getType()->getContext().pImpl->NullPtrConstants.remove(this);
1140 // Drop ownership of the CPN object before removing the entry so that it
1141 // doesn't get double deleted.
1142 LLVMContextImpl::CPNMapTy &CPNConstants = getContext().pImpl->CPNConstants;
1143 LLVMContextImpl::CPNMapTy::iterator I = CPNConstants.find(getType());
1144 assert(I != CPNConstants.end() && "CPN object not in uniquing map");
1145 I->second.take();
1146
1147 // Actually remove the entry from the DenseMap now, which won't free the
1148 // constant.
1149 CPNConstants.erase(I);
1150
1151 // Free the constant and any dangling references to it.
11361152 destroyConstantImpl();
11371153 }
11381154
11411157 //
11421158
11431159 UndefValue *UndefValue::get(Type *Ty) {
1144 return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
1160 OwningPtr &Entry = Ty->getContext().pImpl->UVConstants[Ty];
1161 if (Entry == 0)
1162 Entry.reset(new UndefValue(Ty));
1163
1164 return Entry.get();
11451165 }
11461166
11471167 // destroyConstant - Remove the constant from the constant table.
11481168 //
11491169 void UndefValue::destroyConstant() {
1150 getType()->getContext().pImpl->UndefValueConstants.remove(this);
1170 // Drop ownership of the object before removing the entry so that it
1171 // doesn't get double deleted.
1172 LLVMContextImpl::UVMapTy &UVConstants = getContext().pImpl->UVConstants;
1173 LLVMContextImpl::UVMapTy::iterator I = UVConstants.find(getType());
1174 assert(I != UVConstants.end() && "UV object not in uniquing map");
1175 I->second.take();
1176
1177 // Actually remove the entry from the DenseMap now, which won't free the
1178 // constant.
1179 UVConstants.erase(I);
1180
1181 // Free the constant and any dangling references to it.
11511182 destroyConstantImpl();
11521183 }
11531184
513513 }
514514 };
515515
516 // ConstantPointerNull does not take extra "value" argument...
517 template
518 struct ConstantCreator {
519 static ConstantPointerNull *create(PointerType *Ty, const ValType &V){
520 return new ConstantPointerNull(Ty);
521 }
522 };
523
524 template<>
525 struct ConstantKeyData {
526 typedef char ValType;
527 static ValType getValType(ConstantPointerNull *C) {
528 return 0;
529 }
530 };
531
532 // UndefValue does not take extra "value" argument...
533 template
534 struct ConstantCreator {
535 static UndefValue *create(Type *Ty, const ValType &V) {
536 return new UndefValue(Ty);
537 }
538 };
539
540 template<>
541 struct ConstantKeyData {
542 typedef char ValType;
543 static ValType getValType(UndefValue *C) {
544 return 0;
545 }
546 };
547516
548517 template<>
549518 struct ConstantCreator {
5757 std::vector Modules(OwnedModules.begin(), OwnedModules.end());
5858 DeleteContainerPointers(Modules);
5959
60 // Free the constants. This is important to do here to ensure that they are
61 // freed before the LeakDetector is torn down.
6062 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
6163 DropReferences());
6264 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
7072 StructConstants.freeConstants();
7173 VectorConstants.freeConstants();
7274 CAZConstants.clear();
73 NullPtrConstants.freeConstants();
74 UndefValueConstants.freeConstants();
75 CPNConstants.clear();
76 UVConstants.clear();
7577 InlineAsms.freeConstants();
7678 DeleteContainerSeconds(IntConstants);
7779 DeleteContainerSeconds(FPConstants);
153153 VectorType, ConstantVector> VectorConstantsTy;
154154 VectorConstantsTy VectorConstants;
155155
156 ConstantUniqueMap
157 NullPtrConstants;
158 ConstantUniqueMap UndefValueConstants;
156 typedef DenseMap > CPNMapTy;
157 CPNMapTy CPNConstants;
158
159 typedef DenseMap > UVMapTy;
160 UVMapTy UVConstants;
159161
160162 DenseMap , BlockAddress*> BlockAddresses;
161163 ConstantUniqueMap