1 //===-- Type.cpp - Implement the Type class -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Type class for the VMCore library.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/AbstractTypeUser.h"
15 #include "llvm/DerivedTypes.h"
16 #include "llvm/SymbolTable.h"
17 #include "llvm/Constants.h"
18 #include "llvm/ADT/DepthFirstIterator.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/ADT/SCCIterator.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/Support/MathExtras.h"
27 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
28 // created and later destroyed, all in an effort to make sure that there is only
29 // a single canonical version of a type.
31 //#define DEBUG_MERGE_TYPES 1
33 AbstractTypeUser::~AbstractTypeUser() {}
35 //===----------------------------------------------------------------------===//
36 // Type Class Implementation
37 //===----------------------------------------------------------------------===//
39 // Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions
40 // for types as they are needed. Because resolution of types must invalidate
41 // all of the abstract type descriptions, we keep them in a seperate map to make
43 static std::map<const Type*, std::string> ConcreteTypeDescriptions;
44 static std::map<const Type*, std::string> AbstractTypeDescriptions;
46 Type::Type(const char *Name, TypeID id)
47 : ID(id), Abstract(false), RefCount(0), ForwardType(0) {
48 assert(Name && Name[0] && "Should use other ctor if no name!");
49 ConcreteTypeDescriptions[this] = Name;
53 const Type *Type::getPrimitiveType(TypeID IDNumber) {
55 case VoidTyID : return VoidTy;
56 case BoolTyID : return BoolTy;
57 case UByteTyID : return UByteTy;
58 case SByteTyID : return SByteTy;
59 case UShortTyID: return UShortTy;
60 case ShortTyID : return ShortTy;
61 case UIntTyID : return UIntTy;
62 case IntTyID : return IntTy;
63 case ULongTyID : return ULongTy;
64 case LongTyID : return LongTy;
65 case FloatTyID : return FloatTy;
66 case DoubleTyID: return DoubleTy;
67 case LabelTyID : return LabelTy;
73 // isLosslesslyConvertibleTo - Return true if this type can be converted to
74 // 'Ty' without any reinterpretation of bits. For example, uint to int.
76 bool Type::isLosslesslyConvertibleTo(const Type *Ty) const {
77 if (this == Ty) return true;
78 if ((!isPrimitiveType() && !isa<PointerType>(this)) ||
79 (!isa<PointerType>(Ty) && !Ty->isPrimitiveType())) return false;
81 if (getTypeID() == Ty->getTypeID())
82 return true; // Handles identity cast, and cast of differing pointer types
84 // Now we know that they are two differing primitive or pointer types
85 switch (getTypeID()) {
86 case Type::UByteTyID: return Ty == Type::SByteTy;
87 case Type::SByteTyID: return Ty == Type::UByteTy;
88 case Type::UShortTyID: return Ty == Type::ShortTy;
89 case Type::ShortTyID: return Ty == Type::UShortTy;
90 case Type::UIntTyID: return Ty == Type::IntTy;
91 case Type::IntTyID: return Ty == Type::UIntTy;
92 case Type::ULongTyID: return Ty == Type::LongTy;
93 case Type::LongTyID: return Ty == Type::ULongTy;
94 case Type::PointerTyID: return isa<PointerType>(Ty);
96 return false; // Other types have no identity values
100 /// getUnsignedVersion - If this is an integer type, return the unsigned
101 /// variant of this type. For example int -> uint.
102 const Type *Type::getUnsignedVersion() const {
103 switch (getTypeID()) {
105 assert(isInteger()&&"Type::getUnsignedVersion is only valid for integers!");
106 case Type::UByteTyID:
107 case Type::SByteTyID: return Type::UByteTy;
108 case Type::UShortTyID:
109 case Type::ShortTyID: return Type::UShortTy;
111 case Type::IntTyID: return Type::UIntTy;
112 case Type::ULongTyID:
113 case Type::LongTyID: return Type::ULongTy;
117 /// getSignedVersion - If this is an integer type, return the signed variant
118 /// of this type. For example uint -> int.
119 const Type *Type::getSignedVersion() const {
120 switch (getTypeID()) {
122 assert(isInteger() && "Type::getSignedVersion is only valid for integers!");
123 case Type::UByteTyID:
124 case Type::SByteTyID: return Type::SByteTy;
125 case Type::UShortTyID:
126 case Type::ShortTyID: return Type::ShortTy;
128 case Type::IntTyID: return Type::IntTy;
129 case Type::ULongTyID:
130 case Type::LongTyID: return Type::LongTy;
135 // getPrimitiveSize - Return the basic size of this type if it is a primitive
136 // type. These are fixed by LLVM and are not target dependent. This will
137 // return zero if the type does not have a size or is not a primitive type.
139 unsigned Type::getPrimitiveSize() const {
140 switch (getTypeID()) {
142 case Type::SByteTyID:
143 case Type::UByteTyID: return 1;
144 case Type::UShortTyID:
145 case Type::ShortTyID: return 2;
146 case Type::FloatTyID:
148 case Type::UIntTyID: return 4;
150 case Type::ULongTyID:
151 case Type::DoubleTyID: return 8;
156 unsigned Type::getPrimitiveSizeInBits() const {
157 switch (getTypeID()) {
158 case Type::BoolTyID: return 1;
159 case Type::SByteTyID:
160 case Type::UByteTyID: return 8;
161 case Type::UShortTyID:
162 case Type::ShortTyID: return 16;
163 case Type::FloatTyID:
165 case Type::UIntTyID: return 32;
167 case Type::ULongTyID:
168 case Type::DoubleTyID: return 64;
173 /// isSizedDerivedType - Derived types like structures and arrays are sized
174 /// iff all of the members of the type are sized as well. Since asking for
175 /// their size is relatively uncommon, move this operation out of line.
176 bool Type::isSizedDerivedType() const {
177 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
178 return ATy->getElementType()->isSized();
180 if (const PackedType *PTy = dyn_cast<PackedType>(this))
181 return PTy->getElementType()->isSized();
183 if (!isa<StructType>(this)) return false;
185 // Okay, our struct is sized if all of the elements are...
186 for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
187 if (!(*I)->isSized()) return false;
192 /// getForwardedTypeInternal - This method is used to implement the union-find
193 /// algorithm for when a type is being forwarded to another type.
194 const Type *Type::getForwardedTypeInternal() const {
195 assert(ForwardType && "This type is not being forwarded to another type!");
197 // Check to see if the forwarded type has been forwarded on. If so, collapse
198 // the forwarding links.
199 const Type *RealForwardedType = ForwardType->getForwardedType();
200 if (!RealForwardedType)
201 return ForwardType; // No it's not forwarded again
203 // Yes, it is forwarded again. First thing, add the reference to the new
205 if (RealForwardedType->isAbstract())
206 cast<DerivedType>(RealForwardedType)->addRef();
208 // Now drop the old reference. This could cause ForwardType to get deleted.
209 cast<DerivedType>(ForwardType)->dropRef();
211 // Return the updated type.
212 ForwardType = RealForwardedType;
216 void Type::refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
219 void Type::typeBecameConcrete(const DerivedType *AbsTy) {
224 // getTypeDescription - This is a recursive function that walks a type hierarchy
225 // calculating the description for a type.
227 static std::string getTypeDescription(const Type *Ty,
228 std::vector<const Type *> &TypeStack) {
229 if (isa<OpaqueType>(Ty)) { // Base case for the recursion
230 std::map<const Type*, std::string>::iterator I =
231 AbstractTypeDescriptions.lower_bound(Ty);
232 if (I != AbstractTypeDescriptions.end() && I->first == Ty)
234 std::string Desc = "opaque";
235 AbstractTypeDescriptions.insert(std::make_pair(Ty, Desc));
239 if (!Ty->isAbstract()) { // Base case for the recursion
240 std::map<const Type*, std::string>::iterator I =
241 ConcreteTypeDescriptions.find(Ty);
242 if (I != ConcreteTypeDescriptions.end()) return I->second;
245 // Check to see if the Type is already on the stack...
246 unsigned Slot = 0, CurSize = TypeStack.size();
247 while (Slot < CurSize && TypeStack[Slot] != Ty) ++Slot; // Scan for type
249 // This is another base case for the recursion. In this case, we know
250 // that we have looped back to a type that we have previously visited.
251 // Generate the appropriate upreference to handle this.
254 return "\\" + utostr(CurSize-Slot); // Here's the upreference
256 // Recursive case: derived types...
258 TypeStack.push_back(Ty); // Add us to the stack..
260 switch (Ty->getTypeID()) {
261 case Type::FunctionTyID: {
262 const FunctionType *FTy = cast<FunctionType>(Ty);
263 Result = getTypeDescription(FTy->getReturnType(), TypeStack) + " (";
264 for (FunctionType::param_iterator I = FTy->param_begin(),
265 E = FTy->param_end(); I != E; ++I) {
266 if (I != FTy->param_begin())
268 Result += getTypeDescription(*I, TypeStack);
270 if (FTy->isVarArg()) {
271 if (FTy->getNumParams()) Result += ", ";
277 case Type::StructTyID: {
278 const StructType *STy = cast<StructType>(Ty);
280 for (StructType::element_iterator I = STy->element_begin(),
281 E = STy->element_end(); I != E; ++I) {
282 if (I != STy->element_begin())
284 Result += getTypeDescription(*I, TypeStack);
289 case Type::PointerTyID: {
290 const PointerType *PTy = cast<PointerType>(Ty);
291 Result = getTypeDescription(PTy->getElementType(), TypeStack) + " *";
294 case Type::ArrayTyID: {
295 const ArrayType *ATy = cast<ArrayType>(Ty);
296 unsigned NumElements = ATy->getNumElements();
298 Result += utostr(NumElements) + " x ";
299 Result += getTypeDescription(ATy->getElementType(), TypeStack) + "]";
302 case Type::PackedTyID: {
303 const PackedType *PTy = cast<PackedType>(Ty);
304 unsigned NumElements = PTy->getNumElements();
306 Result += utostr(NumElements) + " x ";
307 Result += getTypeDescription(PTy->getElementType(), TypeStack) + ">";
312 assert(0 && "Unhandled type in getTypeDescription!");
315 TypeStack.pop_back(); // Remove self from stack...
322 static const std::string &getOrCreateDesc(std::map<const Type*,std::string>&Map,
324 std::map<const Type*, std::string>::iterator I = Map.find(Ty);
325 if (I != Map.end()) return I->second;
327 std::vector<const Type *> TypeStack;
328 std::string Result = getTypeDescription(Ty, TypeStack);
329 return Map[Ty] = Result;
333 const std::string &Type::getDescription() const {
335 return getOrCreateDesc(AbstractTypeDescriptions, this);
337 return getOrCreateDesc(ConcreteTypeDescriptions, this);
341 bool StructType::indexValid(const Value *V) const {
342 // Structure indexes require unsigned integer constants.
343 if (V->getType() == Type::UIntTy)
344 if (const ConstantUInt *CU = dyn_cast<ConstantUInt>(V))
345 return CU->getValue() < ContainedTys.size();
349 // getTypeAtIndex - Given an index value into the type, return the type of the
350 // element. For a structure type, this must be a constant value...
352 const Type *StructType::getTypeAtIndex(const Value *V) const {
353 assert(indexValid(V) && "Invalid structure index!");
354 unsigned Idx = (unsigned)cast<ConstantUInt>(V)->getValue();
355 return ContainedTys[Idx];
359 //===----------------------------------------------------------------------===//
360 // Static 'Type' data
361 //===----------------------------------------------------------------------===//
364 struct PrimType : public Type {
365 PrimType(const char *S, TypeID ID) : Type(S, ID) {}
369 static PrimType TheVoidTy ("void" , Type::VoidTyID);
370 static PrimType TheBoolTy ("bool" , Type::BoolTyID);
371 static PrimType TheSByteTy ("sbyte" , Type::SByteTyID);
372 static PrimType TheUByteTy ("ubyte" , Type::UByteTyID);
373 static PrimType TheShortTy ("short" , Type::ShortTyID);
374 static PrimType TheUShortTy("ushort", Type::UShortTyID);
375 static PrimType TheIntTy ("int" , Type::IntTyID);
376 static PrimType TheUIntTy ("uint" , Type::UIntTyID);
377 static PrimType TheLongTy ("long" , Type::LongTyID);
378 static PrimType TheULongTy ("ulong" , Type::ULongTyID);
379 static PrimType TheFloatTy ("float" , Type::FloatTyID);
380 static PrimType TheDoubleTy("double", Type::DoubleTyID);
381 static PrimType TheLabelTy ("label" , Type::LabelTyID);
383 Type *Type::VoidTy = &TheVoidTy;
384 Type *Type::BoolTy = &TheBoolTy;
385 Type *Type::SByteTy = &TheSByteTy;
386 Type *Type::UByteTy = &TheUByteTy;
387 Type *Type::ShortTy = &TheShortTy;
388 Type *Type::UShortTy = &TheUShortTy;
389 Type *Type::IntTy = &TheIntTy;
390 Type *Type::UIntTy = &TheUIntTy;
391 Type *Type::LongTy = &TheLongTy;
392 Type *Type::ULongTy = &TheULongTy;
393 Type *Type::FloatTy = &TheFloatTy;
394 Type *Type::DoubleTy = &TheDoubleTy;
395 Type *Type::LabelTy = &TheLabelTy;
398 //===----------------------------------------------------------------------===//
399 // Derived Type Constructors
400 //===----------------------------------------------------------------------===//
402 FunctionType::FunctionType(const Type *Result,
403 const std::vector<const Type*> &Params,
404 bool IsVarArgs) : DerivedType(FunctionTyID),
405 isVarArgs(IsVarArgs) {
406 assert((Result->isFirstClassType() || Result == Type::VoidTy ||
407 isa<OpaqueType>(Result)) &&
408 "LLVM functions cannot return aggregates");
409 bool isAbstract = Result->isAbstract();
410 ContainedTys.reserve(Params.size()+1);
411 ContainedTys.push_back(PATypeHandle(Result, this));
413 for (unsigned i = 0; i != Params.size(); ++i) {
414 assert((Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])) &&
415 "Function arguments must be value types!");
417 ContainedTys.push_back(PATypeHandle(Params[i], this));
418 isAbstract |= Params[i]->isAbstract();
421 // Calculate whether or not this type is abstract
422 setAbstract(isAbstract);
425 StructType::StructType(const std::vector<const Type*> &Types)
426 : CompositeType(StructTyID) {
427 ContainedTys.reserve(Types.size());
428 bool isAbstract = false;
429 for (unsigned i = 0; i < Types.size(); ++i) {
430 assert(Types[i] != Type::VoidTy && "Void type for structure field!!");
431 ContainedTys.push_back(PATypeHandle(Types[i], this));
432 isAbstract |= Types[i]->isAbstract();
435 // Calculate whether or not this type is abstract
436 setAbstract(isAbstract);
439 ArrayType::ArrayType(const Type *ElType, uint64_t NumEl)
440 : SequentialType(ArrayTyID, ElType) {
443 // Calculate whether or not this type is abstract
444 setAbstract(ElType->isAbstract());
447 PackedType::PackedType(const Type *ElType, unsigned NumEl)
448 : SequentialType(PackedTyID, ElType) {
451 assert(NumEl > 0 && "NumEl of a PackedType must be greater than 0");
452 assert((ElType->isIntegral() || ElType->isFloatingPoint()) &&
453 "Elements of a PackedType must be a primitive type");
457 PointerType::PointerType(const Type *E) : SequentialType(PointerTyID, E) {
458 // Calculate whether or not this type is abstract
459 setAbstract(E->isAbstract());
462 OpaqueType::OpaqueType() : DerivedType(OpaqueTyID) {
464 #ifdef DEBUG_MERGE_TYPES
465 std::cerr << "Derived new type: " << *this << "\n";
469 // dropAllTypeUses - When this (abstract) type is resolved to be equal to
470 // another (more concrete) type, we must eliminate all references to other
471 // types, to avoid some circular reference problems.
472 void DerivedType::dropAllTypeUses() {
473 if (!ContainedTys.empty()) {
474 // The type must stay abstract. To do this, we insert a pointer to a type
475 // that will never get resolved, thus will always be abstract.
476 static Type *AlwaysOpaqueTy = OpaqueType::get();
477 static PATypeHolder Holder(AlwaysOpaqueTy);
478 ContainedTys[0] = AlwaysOpaqueTy;
480 // Change the rest of the types to be intty's. It doesn't matter what we
481 // pick so long as it doesn't point back to this type. We choose something
482 // concrete to avoid overhead for adding to AbstracTypeUser lists and stuff.
483 for (unsigned i = 1, e = ContainedTys.size(); i != e; ++i)
484 ContainedTys[i] = Type::IntTy;
490 /// TypePromotionGraph and graph traits - this is designed to allow us to do
491 /// efficient SCC processing of type graphs. This is the exact same as
492 /// GraphTraits<Type*>, except that we pretend that concrete types have no
493 /// children to avoid processing them.
494 struct TypePromotionGraph {
496 TypePromotionGraph(Type *T) : Ty(T) {}
500 template <> struct GraphTraits<TypePromotionGraph> {
501 typedef Type NodeType;
502 typedef Type::subtype_iterator ChildIteratorType;
504 static inline NodeType *getEntryNode(TypePromotionGraph G) { return G.Ty; }
505 static inline ChildIteratorType child_begin(NodeType *N) {
507 return N->subtype_begin();
508 else // No need to process children of concrete types.
509 return N->subtype_end();
511 static inline ChildIteratorType child_end(NodeType *N) {
512 return N->subtype_end();
518 // PromoteAbstractToConcrete - This is a recursive function that walks a type
519 // graph calculating whether or not a type is abstract.
521 void Type::PromoteAbstractToConcrete() {
522 if (!isAbstract()) return;
524 scc_iterator<TypePromotionGraph> SI = scc_begin(TypePromotionGraph(this));
525 scc_iterator<TypePromotionGraph> SE = scc_end (TypePromotionGraph(this));
527 for (; SI != SE; ++SI) {
528 std::vector<Type*> &SCC = *SI;
530 // Concrete types are leaves in the tree. Since an SCC will either be all
531 // abstract or all concrete, we only need to check one type.
532 if (SCC[0]->isAbstract()) {
533 if (isa<OpaqueType>(SCC[0]))
534 return; // Not going to be concrete, sorry.
536 // If all of the children of all of the types in this SCC are concrete,
537 // then this SCC is now concrete as well. If not, neither this SCC, nor
538 // any parent SCCs will be concrete, so we might as well just exit.
539 for (unsigned i = 0, e = SCC.size(); i != e; ++i)
540 for (Type::subtype_iterator CI = SCC[i]->subtype_begin(),
541 E = SCC[i]->subtype_end(); CI != E; ++CI)
542 if ((*CI)->isAbstract())
543 // If the child type is in our SCC, it doesn't make the entire SCC
544 // abstract unless there is a non-SCC abstract type.
545 if (std::find(SCC.begin(), SCC.end(), *CI) == SCC.end())
546 return; // Not going to be concrete, sorry.
548 // Okay, we just discovered this whole SCC is now concrete, mark it as
550 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
551 assert(SCC[i]->isAbstract() && "Why are we processing concrete types?");
553 SCC[i]->setAbstract(false);
556 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
557 assert(!SCC[i]->isAbstract() && "Concrete type became abstract?");
558 // The type just became concrete, notify all users!
559 cast<DerivedType>(SCC[i])->notifyUsesThatTypeBecameConcrete();
566 //===----------------------------------------------------------------------===//
567 // Type Structural Equality Testing
568 //===----------------------------------------------------------------------===//
570 // TypesEqual - Two types are considered structurally equal if they have the
571 // same "shape": Every level and element of the types have identical primitive
572 // ID's, and the graphs have the same edges/nodes in them. Nodes do not have to
573 // be pointer equals to be equivalent though. This uses an optimistic algorithm
574 // that assumes that two graphs are the same until proven otherwise.
576 static bool TypesEqual(const Type *Ty, const Type *Ty2,
577 std::map<const Type *, const Type *> &EqTypes) {
578 if (Ty == Ty2) return true;
579 if (Ty->getTypeID() != Ty2->getTypeID()) return false;
580 if (isa<OpaqueType>(Ty))
581 return false; // Two unequal opaque types are never equal
583 std::map<const Type*, const Type*>::iterator It = EqTypes.lower_bound(Ty);
584 if (It != EqTypes.end() && It->first == Ty)
585 return It->second == Ty2; // Looping back on a type, check for equality
587 // Otherwise, add the mapping to the table to make sure we don't get
588 // recursion on the types...
589 EqTypes.insert(It, std::make_pair(Ty, Ty2));
591 // Two really annoying special cases that breaks an otherwise nice simple
592 // algorithm is the fact that arraytypes have sizes that differentiates types,
593 // and that function types can be varargs or not. Consider this now.
595 if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
596 return TypesEqual(PTy->getElementType(),
597 cast<PointerType>(Ty2)->getElementType(), EqTypes);
598 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
599 const StructType *STy2 = cast<StructType>(Ty2);
600 if (STy->getNumElements() != STy2->getNumElements()) return false;
601 for (unsigned i = 0, e = STy2->getNumElements(); i != e; ++i)
602 if (!TypesEqual(STy->getElementType(i), STy2->getElementType(i), EqTypes))
605 } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
606 const ArrayType *ATy2 = cast<ArrayType>(Ty2);
607 return ATy->getNumElements() == ATy2->getNumElements() &&
608 TypesEqual(ATy->getElementType(), ATy2->getElementType(), EqTypes);
609 } else if (const PackedType *PTy = dyn_cast<PackedType>(Ty)) {
610 const PackedType *PTy2 = cast<PackedType>(Ty2);
611 return PTy->getNumElements() == PTy2->getNumElements() &&
612 TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
613 } else if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
614 const FunctionType *FTy2 = cast<FunctionType>(Ty2);
615 if (FTy->isVarArg() != FTy2->isVarArg() ||
616 FTy->getNumParams() != FTy2->getNumParams() ||
617 !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
619 for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i)
620 if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
624 assert(0 && "Unknown derived type!");
629 static bool TypesEqual(const Type *Ty, const Type *Ty2) {
630 std::map<const Type *, const Type *> EqTypes;
631 return TypesEqual(Ty, Ty2, EqTypes);
634 // AbstractTypeHasCycleThrough - Return true there is a path from CurTy to
635 // TargetTy in the type graph. We know that Ty is an abstract type, so if we
636 // ever reach a non-abstract type, we know that we don't need to search the
638 static bool AbstractTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
639 std::set<const Type*> &VisitedTypes) {
640 if (TargetTy == CurTy) return true;
641 if (!CurTy->isAbstract()) return false;
643 if (!VisitedTypes.insert(CurTy).second)
644 return false; // Already been here.
646 for (Type::subtype_iterator I = CurTy->subtype_begin(),
647 E = CurTy->subtype_end(); I != E; ++I)
648 if (AbstractTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
653 static bool ConcreteTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
654 std::set<const Type*> &VisitedTypes) {
655 if (TargetTy == CurTy) return true;
657 if (!VisitedTypes.insert(CurTy).second)
658 return false; // Already been here.
660 for (Type::subtype_iterator I = CurTy->subtype_begin(),
661 E = CurTy->subtype_end(); I != E; ++I)
662 if (ConcreteTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
667 /// TypeHasCycleThroughItself - Return true if the specified type has a cycle
669 static bool TypeHasCycleThroughItself(const Type *Ty) {
670 std::set<const Type*> VisitedTypes;
672 if (Ty->isAbstract()) { // Optimized case for abstract types.
673 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
675 if (AbstractTypeHasCycleThrough(Ty, *I, VisitedTypes))
678 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
680 if (ConcreteTypeHasCycleThrough(Ty, *I, VisitedTypes))
686 /// getSubElementHash - Generate a hash value for all of the SubType's of this
687 /// type. The hash value is guaranteed to be zero if any of the subtypes are
688 /// an opaque type. Otherwise we try to mix them in as well as possible, but do
689 /// not look at the subtype's subtype's.
690 static unsigned getSubElementHash(const Type *Ty) {
691 unsigned HashVal = 0;
692 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
695 const Type *SubTy = I->get();
696 HashVal += SubTy->getTypeID();
697 switch (SubTy->getTypeID()) {
699 case Type::OpaqueTyID: return 0; // Opaque -> hash = 0 no matter what.
700 case Type::FunctionTyID:
701 HashVal ^= cast<FunctionType>(SubTy)->getNumParams()*2 +
702 cast<FunctionType>(SubTy)->isVarArg();
704 case Type::ArrayTyID:
705 HashVal ^= cast<ArrayType>(SubTy)->getNumElements();
707 case Type::PackedTyID:
708 HashVal ^= cast<PackedType>(SubTy)->getNumElements();
710 case Type::StructTyID:
711 HashVal ^= cast<StructType>(SubTy)->getNumElements();
715 return HashVal ? HashVal : 1; // Do not return zero unless opaque subty.
718 //===----------------------------------------------------------------------===//
719 // Derived Type Factory Functions
720 //===----------------------------------------------------------------------===//
725 /// TypesByHash - Keep track of types by their structure hash value. Note
726 /// that we only keep track of types that have cycles through themselves in
729 std::multimap<unsigned, PATypeHolder> TypesByHash;
732 void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
733 std::multimap<unsigned, PATypeHolder>::iterator I =
734 TypesByHash.lower_bound(Hash);
735 for (; I != TypesByHash.end() && I->first == Hash; ++I) {
736 if (I->second == Ty) {
737 TypesByHash.erase(I);
742 // This must be do to an opaque type that was resolved. Switch down to hash
744 assert(Hash && "Didn't find type entry!");
745 RemoveFromTypesByHash(0, Ty);
748 /// TypeBecameConcrete - When Ty gets a notification that TheType just became
749 /// concrete, drop uses and make Ty non-abstract if we should.
750 void TypeBecameConcrete(DerivedType *Ty, const DerivedType *TheType) {
751 // If the element just became concrete, remove 'ty' from the abstract
752 // type user list for the type. Do this for as many times as Ty uses
754 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
756 if (I->get() == TheType)
757 TheType->removeAbstractTypeUser(Ty);
759 // If the type is currently thought to be abstract, rescan all of our
760 // subtypes to see if the type has just become concrete! Note that this
761 // may send out notifications to AbstractTypeUsers that types become
763 if (Ty->isAbstract())
764 Ty->PromoteAbstractToConcrete();
770 // TypeMap - Make sure that only one instance of a particular type may be
771 // created on any given run of the compiler... note that this involves updating
772 // our map if an abstract type gets refined somehow.
775 template<class ValType, class TypeClass>
776 class TypeMap : public TypeMapBase {
777 std::map<ValType, PATypeHolder> Map;
779 typedef typename std::map<ValType, PATypeHolder>::iterator iterator;
780 ~TypeMap() { print("ON EXIT"); }
782 inline TypeClass *get(const ValType &V) {
783 iterator I = Map.find(V);
784 return I != Map.end() ? cast<TypeClass>((Type*)I->second.get()) : 0;
787 inline void add(const ValType &V, TypeClass *Ty) {
788 Map.insert(std::make_pair(V, Ty));
790 // If this type has a cycle, remember it.
791 TypesByHash.insert(std::make_pair(ValType::hashTypeStructure(Ty), Ty));
795 void clear(std::vector<Type *> &DerivedTypes) {
796 for (typename std::map<ValType, PATypeHolder>::iterator I = Map.begin(),
797 E = Map.end(); I != E; ++I)
798 DerivedTypes.push_back(I->second.get());
803 /// RefineAbstractType - This method is called after we have merged a type
804 /// with another one. We must now either merge the type away with
805 /// some other type or reinstall it in the map with it's new configuration.
806 void RefineAbstractType(TypeClass *Ty, const DerivedType *OldType,
807 const Type *NewType) {
808 #ifdef DEBUG_MERGE_TYPES
809 std::cerr << "RefineAbstractType(" << (void*)OldType << "[" << *OldType
810 << "], " << (void*)NewType << " [" << *NewType << "])\n";
813 // Otherwise, we are changing one subelement type into another. Clearly the
814 // OldType must have been abstract, making us abstract.
815 assert(Ty->isAbstract() && "Refining a non-abstract type!");
816 assert(OldType != NewType);
818 // Make a temporary type holder for the type so that it doesn't disappear on
819 // us when we erase the entry from the map.
820 PATypeHolder TyHolder = Ty;
822 // The old record is now out-of-date, because one of the children has been
823 // updated. Remove the obsolete entry from the map.
824 unsigned NumErased = Map.erase(ValType::get(Ty));
825 assert(NumErased && "Element not found!");
827 // Remember the structural hash for the type before we start hacking on it,
828 // in case we need it later.
829 unsigned OldTypeHash = ValType::hashTypeStructure(Ty);
831 // Find the type element we are refining... and change it now!
832 for (unsigned i = 0, e = Ty->ContainedTys.size(); i != e; ++i)
833 if (Ty->ContainedTys[i] == OldType)
834 Ty->ContainedTys[i] = NewType;
835 unsigned NewTypeHash = ValType::hashTypeStructure(Ty);
837 // If there are no cycles going through this node, we can do a simple,
838 // efficient lookup in the map, instead of an inefficient nasty linear
840 if (!TypeHasCycleThroughItself(Ty)) {
841 typename std::map<ValType, PATypeHolder>::iterator I;
844 tie(I, Inserted) = Map.insert(std::make_pair(ValType::get(Ty), Ty));
846 // Refined to a different type altogether?
847 RemoveFromTypesByHash(OldTypeHash, Ty);
849 // We already have this type in the table. Get rid of the newly refined
851 TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
852 Ty->refineAbstractTypeTo(NewTy);
856 // Now we check to see if there is an existing entry in the table which is
857 // structurally identical to the newly refined type. If so, this type
858 // gets refined to the pre-existing type.
860 std::multimap<unsigned, PATypeHolder>::iterator I, E, Entry;
861 tie(I, E) = TypesByHash.equal_range(NewTypeHash);
863 for (; I != E; ++I) {
864 if (I->second == Ty) {
865 // Remember the position of the old type if we see it in our scan.
868 if (TypesEqual(Ty, I->second)) {
869 TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
871 // Remove the old entry form TypesByHash. If the hash values differ
872 // now, remove it from the old place. Otherwise, continue scanning
873 // withing this hashcode to reduce work.
874 if (NewTypeHash != OldTypeHash) {
875 RemoveFromTypesByHash(OldTypeHash, Ty);
878 // Find the location of Ty in the TypesByHash structure if we
879 // haven't seen it already.
880 while (I->second != Ty) {
882 assert(I != E && "Structure doesn't contain type??");
886 TypesByHash.erase(Entry);
888 Ty->refineAbstractTypeTo(NewTy);
894 // If there is no existing type of the same structure, we reinsert an
895 // updated record into the map.
896 Map.insert(std::make_pair(ValType::get(Ty), Ty));
899 // If the hash codes differ, update TypesByHash
900 if (NewTypeHash != OldTypeHash) {
901 RemoveFromTypesByHash(OldTypeHash, Ty);
902 TypesByHash.insert(std::make_pair(NewTypeHash, Ty));
905 // If the type is currently thought to be abstract, rescan all of our
906 // subtypes to see if the type has just become concrete! Note that this
907 // may send out notifications to AbstractTypeUsers that types become
909 if (Ty->isAbstract())
910 Ty->PromoteAbstractToConcrete();
913 void print(const char *Arg) const {
914 #ifdef DEBUG_MERGE_TYPES
915 std::cerr << "TypeMap<>::" << Arg << " table contents:\n";
917 for (typename std::map<ValType, PATypeHolder>::const_iterator I
918 = Map.begin(), E = Map.end(); I != E; ++I)
919 std::cerr << " " << (++i) << ". " << (void*)I->second.get() << " "
920 << *I->second.get() << "\n";
924 void dump() const { print("dump output"); }
929 //===----------------------------------------------------------------------===//
930 // Function Type Factory and Value Class...
933 // FunctionValType - Define a class to hold the key that goes into the TypeMap
936 class FunctionValType {
938 std::vector<const Type*> ArgTypes;
941 FunctionValType(const Type *ret, const std::vector<const Type*> &args,
942 bool IVA) : RetTy(ret), isVarArg(IVA) {
943 for (unsigned i = 0; i < args.size(); ++i)
944 ArgTypes.push_back(args[i]);
947 static FunctionValType get(const FunctionType *FT);
949 static unsigned hashTypeStructure(const FunctionType *FT) {
950 return FT->getNumParams()*2+FT->isVarArg();
953 // Subclass should override this... to update self as usual
954 void doRefinement(const DerivedType *OldType, const Type *NewType) {
955 if (RetTy == OldType) RetTy = NewType;
956 for (unsigned i = 0, e = ArgTypes.size(); i != e; ++i)
957 if (ArgTypes[i] == OldType) ArgTypes[i] = NewType;
960 inline bool operator<(const FunctionValType &MTV) const {
961 if (RetTy < MTV.RetTy) return true;
962 if (RetTy > MTV.RetTy) return false;
964 if (ArgTypes < MTV.ArgTypes) return true;
965 return ArgTypes == MTV.ArgTypes && isVarArg < MTV.isVarArg;
970 // Define the actual map itself now...
971 static TypeMap<FunctionValType, FunctionType> FunctionTypes;
973 FunctionValType FunctionValType::get(const FunctionType *FT) {
974 // Build up a FunctionValType
975 std::vector<const Type *> ParamTypes;
976 ParamTypes.reserve(FT->getNumParams());
977 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
978 ParamTypes.push_back(FT->getParamType(i));
979 return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
983 // FunctionType::get - The factory function for the FunctionType class...
984 FunctionType *FunctionType::get(const Type *ReturnType,
985 const std::vector<const Type*> &Params,
987 FunctionValType VT(ReturnType, Params, isVarArg);
988 FunctionType *MT = FunctionTypes.get(VT);
991 FunctionTypes.add(VT, MT = new FunctionType(ReturnType, Params, isVarArg));
993 #ifdef DEBUG_MERGE_TYPES
994 std::cerr << "Derived new type: " << MT << "\n";
999 //===----------------------------------------------------------------------===//
1000 // Array Type Factory...
1003 class ArrayValType {
1007 ArrayValType(const Type *val, uint64_t sz) : ValTy(val), Size(sz) {}
1009 static ArrayValType get(const ArrayType *AT) {
1010 return ArrayValType(AT->getElementType(), AT->getNumElements());
1013 static unsigned hashTypeStructure(const ArrayType *AT) {
1014 return (unsigned)AT->getNumElements();
1017 // Subclass should override this... to update self as usual
1018 void doRefinement(const DerivedType *OldType, const Type *NewType) {
1019 assert(ValTy == OldType);
1023 inline bool operator<(const ArrayValType &MTV) const {
1024 if (Size < MTV.Size) return true;
1025 return Size == MTV.Size && ValTy < MTV.ValTy;
1029 static TypeMap<ArrayValType, ArrayType> ArrayTypes;
1032 ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
1033 assert(ElementType && "Can't get array of null types!");
1035 ArrayValType AVT(ElementType, NumElements);
1036 ArrayType *AT = ArrayTypes.get(AVT);
1037 if (AT) return AT; // Found a match, return it!
1039 // Value not found. Derive a new type!
1040 ArrayTypes.add(AVT, AT = new ArrayType(ElementType, NumElements));
1042 #ifdef DEBUG_MERGE_TYPES
1043 std::cerr << "Derived new type: " << *AT << "\n";
1049 //===----------------------------------------------------------------------===//
1050 // Packed Type Factory...
1053 class PackedValType {
1057 PackedValType(const Type *val, int sz) : ValTy(val), Size(sz) {}
1059 static PackedValType get(const PackedType *PT) {
1060 return PackedValType(PT->getElementType(), PT->getNumElements());
1063 static unsigned hashTypeStructure(const PackedType *PT) {
1064 return PT->getNumElements();
1067 // Subclass should override this... to update self as usual
1068 void doRefinement(const DerivedType *OldType, const Type *NewType) {
1069 assert(ValTy == OldType);
1073 inline bool operator<(const PackedValType &MTV) const {
1074 if (Size < MTV.Size) return true;
1075 return Size == MTV.Size && ValTy < MTV.ValTy;
1079 static TypeMap<PackedValType, PackedType> PackedTypes;
1082 PackedType *PackedType::get(const Type *ElementType, unsigned NumElements) {
1083 assert(ElementType && "Can't get packed of null types!");
1084 assert(isPowerOf2_32(NumElements) && "Vector length should be a power of 2!");
1086 PackedValType PVT(ElementType, NumElements);
1087 PackedType *PT = PackedTypes.get(PVT);
1088 if (PT) return PT; // Found a match, return it!
1090 // Value not found. Derive a new type!
1091 PackedTypes.add(PVT, PT = new PackedType(ElementType, NumElements));
1093 #ifdef DEBUG_MERGE_TYPES
1094 std::cerr << "Derived new type: " << *PT << "\n";
1099 //===----------------------------------------------------------------------===//
1100 // Struct Type Factory...
1104 // StructValType - Define a class to hold the key that goes into the TypeMap
1106 class StructValType {
1107 std::vector<const Type*> ElTypes;
1109 StructValType(const std::vector<const Type*> &args) : ElTypes(args) {}
1111 static StructValType get(const StructType *ST) {
1112 std::vector<const Type *> ElTypes;
1113 ElTypes.reserve(ST->getNumElements());
1114 for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i)
1115 ElTypes.push_back(ST->getElementType(i));
1117 return StructValType(ElTypes);
1120 static unsigned hashTypeStructure(const StructType *ST) {
1121 return ST->getNumElements();
1124 // Subclass should override this... to update self as usual
1125 void doRefinement(const DerivedType *OldType, const Type *NewType) {
1126 for (unsigned i = 0; i < ElTypes.size(); ++i)
1127 if (ElTypes[i] == OldType) ElTypes[i] = NewType;
1130 inline bool operator<(const StructValType &STV) const {
1131 return ElTypes < STV.ElTypes;
1136 static TypeMap<StructValType, StructType> StructTypes;
1138 StructType *StructType::get(const std::vector<const Type*> &ETypes) {
1139 StructValType STV(ETypes);
1140 StructType *ST = StructTypes.get(STV);
1143 // Value not found. Derive a new type!
1144 StructTypes.add(STV, ST = new StructType(ETypes));
1146 #ifdef DEBUG_MERGE_TYPES
1147 std::cerr << "Derived new type: " << *ST << "\n";
1154 //===----------------------------------------------------------------------===//
1155 // Pointer Type Factory...
1158 // PointerValType - Define a class to hold the key that goes into the TypeMap
1161 class PointerValType {
1164 PointerValType(const Type *val) : ValTy(val) {}
1166 static PointerValType get(const PointerType *PT) {
1167 return PointerValType(PT->getElementType());
1170 static unsigned hashTypeStructure(const PointerType *PT) {
1171 return getSubElementHash(PT);
1174 // Subclass should override this... to update self as usual
1175 void doRefinement(const DerivedType *OldType, const Type *NewType) {
1176 assert(ValTy == OldType);
1180 bool operator<(const PointerValType &MTV) const {
1181 return ValTy < MTV.ValTy;
1186 static TypeMap<PointerValType, PointerType> PointerTypes;
1188 PointerType *PointerType::get(const Type *ValueType) {
1189 assert(ValueType && "Can't get a pointer to <null> type!");
1190 // FIXME: The sparc backend makes void pointers, which is horribly broken.
1191 // "Fix" it, then reenable this assertion.
1192 //assert(ValueType != Type::VoidTy &&
1193 // "Pointer to void is not valid, use sbyte* instead!");
1194 PointerValType PVT(ValueType);
1196 PointerType *PT = PointerTypes.get(PVT);
1199 // Value not found. Derive a new type!
1200 PointerTypes.add(PVT, PT = new PointerType(ValueType));
1202 #ifdef DEBUG_MERGE_TYPES
1203 std::cerr << "Derived new type: " << *PT << "\n";
1208 //===----------------------------------------------------------------------===//
1209 // Derived Type Refinement Functions
1210 //===----------------------------------------------------------------------===//
1212 // removeAbstractTypeUser - Notify an abstract type that a user of the class
1213 // no longer has a handle to the type. This function is called primarily by
1214 // the PATypeHandle class. When there are no users of the abstract type, it
1215 // is annihilated, because there is no way to get a reference to it ever again.
1217 void Type::removeAbstractTypeUser(AbstractTypeUser *U) const {
1218 // Search from back to front because we will notify users from back to
1219 // front. Also, it is likely that there will be a stack like behavior to
1220 // users that register and unregister users.
1223 for (i = AbstractTypeUsers.size(); AbstractTypeUsers[i-1] != U; --i)
1224 assert(i != 0 && "AbstractTypeUser not in user list!");
1226 --i; // Convert to be in range 0 <= i < size()
1227 assert(i < AbstractTypeUsers.size() && "Index out of range!"); // Wraparound?
1229 AbstractTypeUsers.erase(AbstractTypeUsers.begin()+i);
1231 #ifdef DEBUG_MERGE_TYPES
1232 std::cerr << " remAbstractTypeUser[" << (void*)this << ", "
1233 << *this << "][" << i << "] User = " << U << "\n";
1236 if (AbstractTypeUsers.empty() && getRefCount() == 0 && isAbstract()) {
1237 #ifdef DEBUG_MERGE_TYPES
1238 std::cerr << "DELETEing unused abstract type: <" << *this
1239 << ">[" << (void*)this << "]" << "\n";
1241 delete this; // No users of this abstract type!
1246 // refineAbstractTypeTo - This function is used to when it is discovered that
1247 // the 'this' abstract type is actually equivalent to the NewType specified.
1248 // This causes all users of 'this' to switch to reference the more concrete type
1249 // NewType and for 'this' to be deleted.
1251 void DerivedType::refineAbstractTypeTo(const Type *NewType) {
1252 assert(isAbstract() && "refineAbstractTypeTo: Current type is not abstract!");
1253 assert(this != NewType && "Can't refine to myself!");
1254 assert(ForwardType == 0 && "This type has already been refined!");
1256 // The descriptions may be out of date. Conservatively clear them all!
1257 AbstractTypeDescriptions.clear();
1259 #ifdef DEBUG_MERGE_TYPES
1260 std::cerr << "REFINING abstract type [" << (void*)this << " "
1261 << *this << "] to [" << (void*)NewType << " "
1262 << *NewType << "]!\n";
1265 // Make sure to put the type to be refined to into a holder so that if IT gets
1266 // refined, that we will not continue using a dead reference...
1268 PATypeHolder NewTy(NewType);
1270 // Any PATypeHolders referring to this type will now automatically forward to
1271 // the type we are resolved to.
1272 ForwardType = NewType;
1273 if (NewType->isAbstract())
1274 cast<DerivedType>(NewType)->addRef();
1276 // Add a self use of the current type so that we don't delete ourself until
1277 // after the function exits.
1279 PATypeHolder CurrentTy(this);
1281 // To make the situation simpler, we ask the subclass to remove this type from
1282 // the type map, and to replace any type uses with uses of non-abstract types.
1283 // This dramatically limits the amount of recursive type trouble we can find
1287 // Iterate over all of the uses of this type, invoking callback. Each user
1288 // should remove itself from our use list automatically. We have to check to
1289 // make sure that NewTy doesn't _become_ 'this'. If it does, resolving types
1290 // will not cause users to drop off of the use list. If we resolve to ourself
1293 while (!AbstractTypeUsers.empty() && NewTy != this) {
1294 AbstractTypeUser *User = AbstractTypeUsers.back();
1296 unsigned OldSize = AbstractTypeUsers.size();
1297 #ifdef DEBUG_MERGE_TYPES
1298 std::cerr << " REFINING user " << OldSize-1 << "[" << (void*)User
1299 << "] of abstract type [" << (void*)this << " "
1300 << *this << "] to [" << (void*)NewTy.get() << " "
1301 << *NewTy << "]!\n";
1303 User->refineAbstractType(this, NewTy);
1305 assert(AbstractTypeUsers.size() != OldSize &&
1306 "AbsTyUser did not remove self from user list!");
1309 // If we were successful removing all users from the type, 'this' will be
1310 // deleted when the last PATypeHolder is destroyed or updated from this type.
1311 // This may occur on exit of this function, as the CurrentTy object is
1315 // notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type that
1316 // the current type has transitioned from being abstract to being concrete.
1318 void DerivedType::notifyUsesThatTypeBecameConcrete() {
1319 #ifdef DEBUG_MERGE_TYPES
1320 std::cerr << "typeIsREFINED type: " << (void*)this << " " << *this << "\n";
1323 unsigned OldSize = AbstractTypeUsers.size();
1324 while (!AbstractTypeUsers.empty()) {
1325 AbstractTypeUser *ATU = AbstractTypeUsers.back();
1326 ATU->typeBecameConcrete(this);
1328 assert(AbstractTypeUsers.size() < OldSize-- &&
1329 "AbstractTypeUser did not remove itself from the use list!");
1333 // refineAbstractType - Called when a contained type is found to be more
1334 // concrete - this could potentially change us from an abstract type to a
1337 void FunctionType::refineAbstractType(const DerivedType *OldType,
1338 const Type *NewType) {
1339 FunctionTypes.RefineAbstractType(this, OldType, NewType);
1342 void FunctionType::typeBecameConcrete(const DerivedType *AbsTy) {
1343 FunctionTypes.TypeBecameConcrete(this, AbsTy);
1347 // refineAbstractType - Called when a contained type is found to be more
1348 // concrete - this could potentially change us from an abstract type to a
1351 void ArrayType::refineAbstractType(const DerivedType *OldType,
1352 const Type *NewType) {
1353 ArrayTypes.RefineAbstractType(this, OldType, NewType);
1356 void ArrayType::typeBecameConcrete(const DerivedType *AbsTy) {
1357 ArrayTypes.TypeBecameConcrete(this, AbsTy);
1360 // refineAbstractType - Called when a contained type is found to be more
1361 // concrete - this could potentially change us from an abstract type to a
1364 void PackedType::refineAbstractType(const DerivedType *OldType,
1365 const Type *NewType) {
1366 PackedTypes.RefineAbstractType(this, OldType, NewType);
1369 void PackedType::typeBecameConcrete(const DerivedType *AbsTy) {
1370 PackedTypes.TypeBecameConcrete(this, AbsTy);
1373 // refineAbstractType - Called when a contained type is found to be more
1374 // concrete - this could potentially change us from an abstract type to a
1377 void StructType::refineAbstractType(const DerivedType *OldType,
1378 const Type *NewType) {
1379 StructTypes.RefineAbstractType(this, OldType, NewType);
1382 void StructType::typeBecameConcrete(const DerivedType *AbsTy) {
1383 StructTypes.TypeBecameConcrete(this, AbsTy);
1386 // refineAbstractType - Called when a contained type is found to be more
1387 // concrete - this could potentially change us from an abstract type to a
1390 void PointerType::refineAbstractType(const DerivedType *OldType,
1391 const Type *NewType) {
1392 PointerTypes.RefineAbstractType(this, OldType, NewType);
1395 void PointerType::typeBecameConcrete(const DerivedType *AbsTy) {
1396 PointerTypes.TypeBecameConcrete(this, AbsTy);
1399 bool SequentialType::indexValid(const Value *V) const {
1400 const Type *Ty = V->getType();
1401 switch (Ty->getTypeID()) {
1403 case Type::UIntTyID:
1404 case Type::LongTyID:
1405 case Type::ULongTyID:
1413 std::ostream &operator<<(std::ostream &OS, const Type *T) {
1415 OS << "<null> value!\n";
1421 std::ostream &operator<<(std::ostream &OS, const Type &T) {
1427 /// clearAllTypeMaps - This method frees all internal memory used by the
1428 /// type subsystem, which can be used in environments where this memory is
1429 /// otherwise reported as a leak.
1430 void Type::clearAllTypeMaps() {
1431 std::vector<Type *> DerivedTypes;
1433 FunctionTypes.clear(DerivedTypes);
1434 PointerTypes.clear(DerivedTypes);
1435 StructTypes.clear(DerivedTypes);
1436 ArrayTypes.clear(DerivedTypes);
1437 PackedTypes.clear(DerivedTypes);
1439 for(std::vector<Type *>::iterator I = DerivedTypes.begin(),
1440 E = DerivedTypes.end(); I != E; ++I)
1441 (*I)->ContainedTys.clear();
1442 for(std::vector<Type *>::iterator I = DerivedTypes.begin(),
1443 E = DerivedTypes.end(); I != E; ++I)
1445 DerivedTypes.clear();