llvm.org GIT mirror llvm / 9df0fb4
convert CAZ, UndefValue, and CPN to use DenseMap's again, this time without using OwningPtr. OwningPtr would barf when the densemap had to reallocate, which doesn't appear to happen on the regression test suite, but obviously happens in real life :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148700 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
4 changed file(s) with 30 addition(s) and 61 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 LLVMContextImpl *pImpl = Ty->getContext().pImpl;
1000 return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
999 ConstantAggregateZero *&Entry = Ty->getContext().pImpl->CAZConstants[Ty];
1000 if (Entry == 0)
1001 Entry = new ConstantAggregateZero(Ty);
1002
1003 return Entry;
10011004 }
10021005
10031006 /// destroyConstant - Remove the constant from the constant table...
10041007 ///
10051008 void ConstantAggregateZero::destroyConstant() {
1006 getType()->getContext().pImpl->AggZeroConstants.remove(this);
1009 getContext().pImpl->CAZConstants.erase(getType());
10071010 destroyConstantImpl();
10081011 }
10091012
11111114 //
11121115
11131116 ConstantPointerNull *ConstantPointerNull::get(PointerType *Ty) {
1114 return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0);
1117 ConstantPointerNull *&Entry = Ty->getContext().pImpl->CPNConstants[Ty];
1118 if (Entry == 0)
1119 Entry = new ConstantPointerNull(Ty);
1120
1121 return Entry;
11151122 }
11161123
11171124 // destroyConstant - Remove the constant from the constant table...
11181125 //
11191126 void ConstantPointerNull::destroyConstant() {
1120 getType()->getContext().pImpl->NullPtrConstants.remove(this);
1127 getContext().pImpl->CPNConstants.erase(getType());
1128 // Free the constant and any dangling references to it.
11211129 destroyConstantImpl();
11221130 }
11231131
11261134 //
11271135
11281136 UndefValue *UndefValue::get(Type *Ty) {
1129 return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0);
1137 UndefValue *&Entry = Ty->getContext().pImpl->UVConstants[Ty];
1138 if (Entry == 0)
1139 Entry = new UndefValue(Ty);
1140
1141 return Entry;
11301142 }
11311143
11321144 // destroyConstant - Remove the constant from the constant table.
11331145 //
11341146 void UndefValue::destroyConstant() {
1135 getType()->getContext().pImpl->UndefValueConstants.remove(this);
1147 // Free the constant and any dangling references to it.
1148 getContext().pImpl->UVConstants.erase(getType());
11361149 destroyConstantImpl();
11371150 }
11381151
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 };
486479
487480 template<>
488481 struct ConstantKeyData {
497490 };
498491
499492 template<>
500 struct ConstantKeyData {
501 typedef char ValType;
502 static ValType getValType(ConstantAggregateZero *C) {
503 return 0;
504 }
505 };
506
507 template<>
508493 struct ConstantKeyData {
509494 typedef std::vector ValType;
510495 static ValType getValType(ConstantArray *CA) {
528513 }
529514 };
530515
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 };
562516
563517 template<>
564518 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(),
6971 ArrayConstants.freeConstants();
7072 StructConstants.freeConstants();
7173 VectorConstants.freeConstants();
72 AggZeroConstants.freeConstants();
73 NullPtrConstants.freeConstants();
74 UndefValueConstants.freeConstants();
74 DeleteContainerSeconds(CAZConstants);
75 DeleteContainerSeconds(CPNConstants);
76 DeleteContainerSeconds(UVConstants);
7577 InlineAsms.freeConstants();
7678 DeleteContainerSeconds(IntConstants);
7779 DeleteContainerSeconds(FPConstants);
137137 // on Context destruction.
138138 SmallPtrSet NonUniquedMDNodes;
139139
140 ConstantUniqueMap AggZeroConstants;
140 DenseMap CAZConstants;
141141
142142 typedef ConstantUniqueMap, ArrayRef,
143143 ArrayType, ConstantArray, true /*largekey*/> ArrayConstantsTy;
151151 VectorType, ConstantVector> VectorConstantsTy;
152152 VectorConstantsTy VectorConstants;
153153
154 ConstantUniqueMap
155 NullPtrConstants;
156 ConstantUniqueMap UndefValueConstants;
154 DenseMap CPNConstants;
155
156 DenseMap UVConstants;
157157
158158 DenseMap , BlockAddress*> BlockAddresses;
159159 ConstantUniqueMap