llvm.org GIT mirror llvm / 95889fa
revert r148691 and 148693 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148698 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
4 changed file(s) with 61 addition(s) and 67 deletion(s). Raw diff Collapse all Expand all
992992 //===----------------------------------------------------------------------===//
993993 // Factory Function Implementation
994994
995 ConstantAggregateZero *ConstantAggregateZero::get(Type *Ty) {
995 ConstantAggregateZero* ConstantAggregateZero::get(Type* Ty) {
996996 assert((Ty->isStructTy() || Ty->isArrayTy() || Ty->isVectorTy()) &&
997997 "Cannot create an aggregate zero of non-aggregate type!");
998998
999 OwningPtr &Entry =
1000 Ty->getContext().pImpl->CAZConstants[Ty];
1001 if (Entry == 0)
1002 Entry.reset(new ConstantAggregateZero(Ty));
1003
1004 return Entry.get();
999 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1000 return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
10051001 }
10061002
10071003 /// destroyConstant - Remove the constant from the constant table...
10081004 ///
10091005 void ConstantAggregateZero::destroyConstant() {
1010 // Drop ownership of the CAZ object before removing the entry so that it
1011 // doesn't get double deleted.
1012 LLVMContextImpl::CAZMapTy &CAZConstants = getContext().pImpl->CAZConstants;
1013 LLVMContextImpl::CAZMapTy::iterator I = CAZConstants.find(getType());
1014 assert(I != CAZConstants.end() && "CAZ object not in uniquing map");
1015 I->second.take();
1016
1017 // Actually remove the entry from the DenseMap now, which won't free the
1018 // constant.
1019 CAZConstants.erase(I);
1020
1021 // Free the constant and any dangling references to it.
1006 getType()->getContext().pImpl->AggZeroConstants.remove(this);
10221007 destroyConstantImpl();
10231008 }
10241009
11261111 //
11271112
11281113 ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
1129 OwningPtr &Entry =
1130 Ty->getContext().pImpl->CPNConstants[Ty];
1131 if (Entry == 0)
1132 Entry.reset(new ConstantPointerNull(Ty));
1133
1134 return Entry.get();
1114 return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0);
11351115 }
11361116
11371117 // destroyConstant - Remove the constant from the constant table...
11381118 //
11391119 void ConstantPointerNull::destroyConstant() {
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.
1120 getType()->getContext().pImpl->NullPtrConstants.remove(this);
11521121 destroyConstantImpl();
11531122 }
11541123
11571126 //
11581127
11591128 UndefValue *UndefValue::get(Type *Ty) {
1160 OwningPtr &Entry = Ty->getContext().pImpl->UVConstants[Ty];
1161 if (Entry == 0)
1162 Entry.reset(new UndefValue(Ty));
1163
1164 return Entry.get();
1129 return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
11651130 }
11661131
11671132 // destroyConstant - Remove the constant from the constant table.
11681133 //
11691134 void UndefValue::destroyConstant() {
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.
1135 getType()->getContext().pImpl->UndefValueConstants.remove(this);
11821136 destroyConstantImpl();
11831137 }
11841138
476476 }
477477 };
478478
479 // ConstantAggregateZero does not take extra "value" argument...
480 template
481 struct ConstantCreator {
482 static ConstantAggregateZero *create(Type *Ty, const ValType &V){
483 return new ConstantAggregateZero(Ty);
484 }
485 };
479486
480487 template<>
481488 struct ConstantKeyData {
490497 };
491498
492499 template<>
500 struct ConstantKeyData {
501 typedef char ValType;
502 static ValType getValType(ConstantAggregateZero *C) {
503 return 0;
504 }
505 };
506
507 template<>
493508 struct ConstantKeyData {
494509 typedef std::vector ValType;
495510 static ValType getValType(ConstantArray *CA) {
513528 }
514529 };
515530
531 // ConstantPointerNull does not take extra "value" argument...
532 template
533 struct ConstantCreator {
534 static ConstantPointerNull *create(PointerType *Ty, const ValType &V){
535 return new ConstantPointerNull(Ty);
536 }
537 };
538
539 template<>
540 struct ConstantKeyData {
541 typedef char ValType;
542 static ValType getValType(ConstantPointerNull *C) {
543 return 0;
544 }
545 };
546
547 // UndefValue does not take extra "value" argument...
548 template
549 struct ConstantCreator {
550 static UndefValue *create(Type *Ty, const ValType &V) {
551 return new UndefValue(Ty);
552 }
553 };
554
555 template<>
556 struct ConstantKeyData {
557 typedef char ValType;
558 static ValType getValType(UndefValue *C) {
559 return 0;
560 }
561 };
516562
517563 template<>
518564 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.
6260 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
6361 DropReferences());
6462 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
7169 ArrayConstants.freeConstants();
7270 StructConstants.freeConstants();
7371 VectorConstants.freeConstants();
74 CAZConstants.clear();
75 CPNConstants.clear();
76 UVConstants.clear();
72 AggZeroConstants.freeConstants();
73 NullPtrConstants.freeConstants();
74 UndefValueConstants.freeConstants();
7775 InlineAsms.freeConstants();
7876 DeleteContainerSeconds(IntConstants);
7977 DeleteContainerSeconds(FPConstants);
2626 #include "llvm/ADT/ArrayRef.h"
2727 #include "llvm/ADT/DenseMap.h"
2828 #include "llvm/ADT/FoldingSet.h"
29 #include "llvm/ADT/OwningPtr.h"
3029 #include "llvm/ADT/SmallPtrSet.h"
3130 #include "llvm/ADT/StringMap.h"
3231 #include
138137 // on Context destruction.
139138 SmallPtrSet NonUniquedMDNodes;
140139
141 typedef DenseMap > CAZMapTy;
142 CAZMapTy CAZConstants;
140 ConstantUniqueMap AggZeroConstants;
143141
144142 typedef ConstantUniqueMap, ArrayRef,
145143 ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy;
153151 VectorType, ConstantVector> VectorConstantsTy;
154152 VectorConstantsTy VectorConstants;
155153
156 typedef DenseMap > CPNMapTy;
157 CPNMapTy CPNConstants;
158
159 typedef DenseMap > UVMapTy;
160 UVMapTy UVConstants;
154 ConstantUniqueMap
155 NullPtrConstants;
156 ConstantUniqueMap UndefValueConstants;
161157
162158 DenseMap , BlockAddress*> BlockAddresses;
163159 ConstantUniqueMap