1 //===-- Type.cpp - Implement the Type class -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Type class for the VMCore library.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/DerivedTypes.h"
15 #include "llvm/Constants.h"
16 #include "llvm/Assembly/Writer.h"
17 #include "llvm/ADT/DepthFirstIterator.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/SCCIterator.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/Debug.h"
23 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/MathExtras.h"
25 #include "llvm/Support/raw_ostream.h"
30 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
31 // created and later destroyed, all in an effort to make sure that there is only
32 // a single canonical version of a type.
34 // #define DEBUG_MERGE_TYPES 1
36 AbstractTypeUser::~AbstractTypeUser() {}
39 //===----------------------------------------------------------------------===//
40 // Type Class Implementation
41 //===----------------------------------------------------------------------===//
43 // Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions
44 // for types as they are needed. Because resolution of types must invalidate
45 // all of the abstract type descriptions, we keep them in a seperate map to make
47 static ManagedStatic<TypePrinting> ConcreteTypeDescriptions;
48 static ManagedStatic<TypePrinting> AbstractTypeDescriptions;
50 /// Because of the way Type subclasses are allocated, this function is necessary
51 /// to use the correct kind of "delete" operator to deallocate the Type object.
52 /// Some type objects (FunctionTy, StructTy) allocate additional space after
53 /// the space for their derived type to hold the contained types array of
54 /// PATypeHandles. Using this allocation scheme means all the PATypeHandles are
55 /// allocated with the type object, decreasing allocations and eliminating the
56 /// need for a std::vector to be used in the Type class itself.
57 /// @brief Type destruction function
58 void Type::destroy() const {
60 // Structures and Functions allocate their contained types past the end of
61 // the type object itself. These need to be destroyed differently than the
63 if (isa<FunctionType>(this) || isa<StructType>(this)) {
64 // First, make sure we destruct any PATypeHandles allocated by these
65 // subclasses. They must be manually destructed.
66 for (unsigned i = 0; i < NumContainedTys; ++i)
67 ContainedTys[i].PATypeHandle::~PATypeHandle();
69 // Now call the destructor for the subclass directly because we're going
70 // to delete this as an array of char.
71 if (isa<FunctionType>(this))
72 static_cast<const FunctionType*>(this)->FunctionType::~FunctionType();
74 static_cast<const StructType*>(this)->StructType::~StructType();
76 // Finally, remove the memory as an array deallocation of the chars it was
78 operator delete(const_cast<Type *>(this));
83 // For all the other type subclasses, there is either no contained types or
84 // just one (all Sequentials). For Sequentials, the PATypeHandle is not
85 // allocated past the type object, its included directly in the SequentialType
86 // class. This means we can safely just do "normal" delete of this object and
87 // all the destructors that need to run will be run.
91 const Type *Type::getPrimitiveType(TypeID IDNumber) {
93 case VoidTyID : return VoidTy;
94 case FloatTyID : return FloatTy;
95 case DoubleTyID : return DoubleTy;
96 case X86_FP80TyID : return X86_FP80Ty;
97 case FP128TyID : return FP128Ty;
98 case PPC_FP128TyID : return PPC_FP128Ty;
99 case LabelTyID : return LabelTy;
105 const Type *Type::getVAArgsPromotedType() const {
106 if (ID == IntegerTyID && getSubclassData() < 32)
107 return Type::Int32Ty;
108 else if (ID == FloatTyID)
109 return Type::DoubleTy;
114 /// isIntOrIntVector - Return true if this is an integer type or a vector of
117 bool Type::isIntOrIntVector() const {
120 if (ID != Type::VectorTyID) return false;
122 return cast<VectorType>(this)->getElementType()->isInteger();
125 /// isFPOrFPVector - Return true if this is a FP type or a vector of FP types.
127 bool Type::isFPOrFPVector() const {
128 if (ID == Type::FloatTyID || ID == Type::DoubleTyID ||
129 ID == Type::FP128TyID || ID == Type::X86_FP80TyID ||
130 ID == Type::PPC_FP128TyID)
132 if (ID != Type::VectorTyID) return false;
134 return cast<VectorType>(this)->getElementType()->isFloatingPoint();
137 // canLosslesllyBitCastTo - Return true if this type can be converted to
138 // 'Ty' without any reinterpretation of bits. For example, uint to int.
140 bool Type::canLosslesslyBitCastTo(const Type *Ty) const {
141 // Identity cast means no change so return true
145 // They are not convertible unless they are at least first class types
146 if (!this->isFirstClassType() || !Ty->isFirstClassType())
149 // Vector -> Vector conversions are always lossless if the two vector types
150 // have the same size, otherwise not.
151 if (const VectorType *thisPTy = dyn_cast<VectorType>(this))
152 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
153 return thisPTy->getBitWidth() == thatPTy->getBitWidth();
155 // At this point we have only various mismatches of the first class types
156 // remaining and ptr->ptr. Just select the lossless conversions. Everything
157 // else is not lossless.
158 if (isa<PointerType>(this))
159 return isa<PointerType>(Ty);
160 return false; // Other types have no identity values
163 unsigned Type::getPrimitiveSizeInBits() const {
164 switch (getTypeID()) {
165 case Type::FloatTyID: return 32;
166 case Type::DoubleTyID: return 64;
167 case Type::X86_FP80TyID: return 80;
168 case Type::FP128TyID: return 128;
169 case Type::PPC_FP128TyID: return 128;
170 case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
171 case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
176 /// isSizedDerivedType - Derived types like structures and arrays are sized
177 /// iff all of the members of the type are sized as well. Since asking for
178 /// their size is relatively uncommon, move this operation out of line.
179 bool Type::isSizedDerivedType() const {
180 if (isa<IntegerType>(this))
183 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
184 return ATy->getElementType()->isSized();
186 if (const VectorType *PTy = dyn_cast<VectorType>(this))
187 return PTy->getElementType()->isSized();
189 if (!isa<StructType>(this))
192 // Okay, our struct is sized if all of the elements are...
193 for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
194 if (!(*I)->isSized())
200 /// getForwardedTypeInternal - This method is used to implement the union-find
201 /// algorithm for when a type is being forwarded to another type.
202 const Type *Type::getForwardedTypeInternal() const {
203 assert(ForwardType && "This type is not being forwarded to another type!");
205 // Check to see if the forwarded type has been forwarded on. If so, collapse
206 // the forwarding links.
207 const Type *RealForwardedType = ForwardType->getForwardedType();
208 if (!RealForwardedType)
209 return ForwardType; // No it's not forwarded again
211 // Yes, it is forwarded again. First thing, add the reference to the new
213 if (RealForwardedType->isAbstract())
214 cast<DerivedType>(RealForwardedType)->addRef();
216 // Now drop the old reference. This could cause ForwardType to get deleted.
217 cast<DerivedType>(ForwardType)->dropRef();
219 // Return the updated type.
220 ForwardType = RealForwardedType;
224 void Type::refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
227 void Type::typeBecameConcrete(const DerivedType *AbsTy) {
232 std::string Type::getDescription() const {
234 isAbstract() ? *AbstractTypeDescriptions : *ConcreteTypeDescriptions;
237 raw_string_ostream DescOS(DescStr);
238 Map.print(this, DescOS);
243 bool StructType::indexValid(const Value *V) const {
244 // Structure indexes require 32-bit integer constants.
245 if (V->getType() == Type::Int32Ty)
246 if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
247 return indexValid(CU->getZExtValue());
251 bool StructType::indexValid(unsigned V) const {
252 return V < NumContainedTys;
255 // getTypeAtIndex - Given an index value into the type, return the type of the
256 // element. For a structure type, this must be a constant value...
258 const Type *StructType::getTypeAtIndex(const Value *V) const {
259 unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
260 return getTypeAtIndex(Idx);
263 const Type *StructType::getTypeAtIndex(unsigned Idx) const {
264 assert(indexValid(Idx) && "Invalid structure index!");
265 return ContainedTys[Idx];
268 //===----------------------------------------------------------------------===//
269 // Primitive 'Type' data
270 //===----------------------------------------------------------------------===//
272 const Type *Type::VoidTy = new Type(Type::VoidTyID);
273 const Type *Type::FloatTy = new Type(Type::FloatTyID);
274 const Type *Type::DoubleTy = new Type(Type::DoubleTyID);
275 const Type *Type::X86_FP80Ty = new Type(Type::X86_FP80TyID);
276 const Type *Type::FP128Ty = new Type(Type::FP128TyID);
277 const Type *Type::PPC_FP128Ty = new Type(Type::PPC_FP128TyID);
278 const Type *Type::LabelTy = new Type(Type::LabelTyID);
281 struct BuiltinIntegerType : public IntegerType {
282 explicit BuiltinIntegerType(unsigned W) : IntegerType(W) {}
285 const IntegerType *Type::Int1Ty = new BuiltinIntegerType(1);
286 const IntegerType *Type::Int8Ty = new BuiltinIntegerType(8);
287 const IntegerType *Type::Int16Ty = new BuiltinIntegerType(16);
288 const IntegerType *Type::Int32Ty = new BuiltinIntegerType(32);
289 const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
291 const Type *Type::EmptyStructTy = StructType::get(NULL, NULL);
294 //===----------------------------------------------------------------------===//
295 // Derived Type Constructors
296 //===----------------------------------------------------------------------===//
298 /// isValidReturnType - Return true if the specified type is valid as a return
300 bool FunctionType::isValidReturnType(const Type *RetTy) {
301 if (RetTy->isFirstClassType())
303 if (RetTy == Type::VoidTy || isa<OpaqueType>(RetTy))
306 // If this is a multiple return case, verify that each return is a first class
307 // value and that there is at least one value.
308 const StructType *SRetTy = dyn_cast<StructType>(RetTy);
309 if (SRetTy == 0 || SRetTy->getNumElements() == 0)
312 for (unsigned i = 0, e = SRetTy->getNumElements(); i != e; ++i)
313 if (!SRetTy->getElementType(i)->isFirstClassType())
318 FunctionType::FunctionType(const Type *Result,
319 const std::vector<const Type*> &Params,
321 : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) {
322 ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
323 NumContainedTys = Params.size() + 1; // + 1 for result type
324 assert(isValidReturnType(Result) && "invalid return type for function");
327 bool isAbstract = Result->isAbstract();
328 new (&ContainedTys[0]) PATypeHandle(Result, this);
330 for (unsigned i = 0; i != Params.size(); ++i) {
331 assert((Params[i]->isFirstClassType() || isa<OpaqueType>(Params[i])) &&
332 "Function arguments must be value types!");
333 new (&ContainedTys[i+1]) PATypeHandle(Params[i],this);
334 isAbstract |= Params[i]->isAbstract();
337 // Calculate whether or not this type is abstract
338 setAbstract(isAbstract);
341 StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
342 : CompositeType(StructTyID) {
343 ContainedTys = reinterpret_cast<PATypeHandle*>(this + 1);
344 NumContainedTys = Types.size();
345 setSubclassData(isPacked);
346 bool isAbstract = false;
347 for (unsigned i = 0; i < Types.size(); ++i) {
348 assert(Types[i] != Type::VoidTy && "Void type for structure field!!");
349 new (&ContainedTys[i]) PATypeHandle(Types[i], this);
350 isAbstract |= Types[i]->isAbstract();
353 // Calculate whether or not this type is abstract
354 setAbstract(isAbstract);
357 ArrayType::ArrayType(const Type *ElType, uint64_t NumEl)
358 : SequentialType(ArrayTyID, ElType) {
361 // Calculate whether or not this type is abstract
362 setAbstract(ElType->isAbstract());
365 VectorType::VectorType(const Type *ElType, unsigned NumEl)
366 : SequentialType(VectorTyID, ElType) {
368 setAbstract(ElType->isAbstract());
369 assert(NumEl > 0 && "NumEl of a VectorType must be greater than 0");
370 assert((ElType->isInteger() || ElType->isFloatingPoint() ||
371 isa<OpaqueType>(ElType)) &&
372 "Elements of a VectorType must be a primitive type");
377 PointerType::PointerType(const Type *E, unsigned AddrSpace)
378 : SequentialType(PointerTyID, E) {
379 AddressSpace = AddrSpace;
380 // Calculate whether or not this type is abstract
381 setAbstract(E->isAbstract());
384 OpaqueType::OpaqueType() : DerivedType(OpaqueTyID) {
386 #ifdef DEBUG_MERGE_TYPES
387 DOUT << "Derived new type: " << *this << "\n";
391 // dropAllTypeUses - When this (abstract) type is resolved to be equal to
392 // another (more concrete) type, we must eliminate all references to other
393 // types, to avoid some circular reference problems.
394 void DerivedType::dropAllTypeUses() {
395 if (NumContainedTys != 0) {
396 // The type must stay abstract. To do this, we insert a pointer to a type
397 // that will never get resolved, thus will always be abstract.
398 static Type *AlwaysOpaqueTy = OpaqueType::get();
399 static PATypeHolder Holder(AlwaysOpaqueTy);
400 ContainedTys[0] = AlwaysOpaqueTy;
402 // Change the rest of the types to be Int32Ty's. It doesn't matter what we
403 // pick so long as it doesn't point back to this type. We choose something
404 // concrete to avoid overhead for adding to AbstracTypeUser lists and stuff.
405 for (unsigned i = 1, e = NumContainedTys; i != e; ++i)
406 ContainedTys[i] = Type::Int32Ty;
413 /// TypePromotionGraph and graph traits - this is designed to allow us to do
414 /// efficient SCC processing of type graphs. This is the exact same as
415 /// GraphTraits<Type*>, except that we pretend that concrete types have no
416 /// children to avoid processing them.
417 struct TypePromotionGraph {
419 TypePromotionGraph(Type *T) : Ty(T) {}
425 template <> struct GraphTraits<TypePromotionGraph> {
426 typedef Type NodeType;
427 typedef Type::subtype_iterator ChildIteratorType;
429 static inline NodeType *getEntryNode(TypePromotionGraph G) { return G.Ty; }
430 static inline ChildIteratorType child_begin(NodeType *N) {
432 return N->subtype_begin();
433 else // No need to process children of concrete types.
434 return N->subtype_end();
436 static inline ChildIteratorType child_end(NodeType *N) {
437 return N->subtype_end();
443 // PromoteAbstractToConcrete - This is a recursive function that walks a type
444 // graph calculating whether or not a type is abstract.
446 void Type::PromoteAbstractToConcrete() {
447 if (!isAbstract()) return;
449 scc_iterator<TypePromotionGraph> SI = scc_begin(TypePromotionGraph(this));
450 scc_iterator<TypePromotionGraph> SE = scc_end (TypePromotionGraph(this));
452 for (; SI != SE; ++SI) {
453 std::vector<Type*> &SCC = *SI;
455 // Concrete types are leaves in the tree. Since an SCC will either be all
456 // abstract or all concrete, we only need to check one type.
457 if (SCC[0]->isAbstract()) {
458 if (isa<OpaqueType>(SCC[0]))
459 return; // Not going to be concrete, sorry.
461 // If all of the children of all of the types in this SCC are concrete,
462 // then this SCC is now concrete as well. If not, neither this SCC, nor
463 // any parent SCCs will be concrete, so we might as well just exit.
464 for (unsigned i = 0, e = SCC.size(); i != e; ++i)
465 for (Type::subtype_iterator CI = SCC[i]->subtype_begin(),
466 E = SCC[i]->subtype_end(); CI != E; ++CI)
467 if ((*CI)->isAbstract())
468 // If the child type is in our SCC, it doesn't make the entire SCC
469 // abstract unless there is a non-SCC abstract type.
470 if (std::find(SCC.begin(), SCC.end(), *CI) == SCC.end())
471 return; // Not going to be concrete, sorry.
473 // Okay, we just discovered this whole SCC is now concrete, mark it as
475 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
476 assert(SCC[i]->isAbstract() && "Why are we processing concrete types?");
478 SCC[i]->setAbstract(false);
481 for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
482 assert(!SCC[i]->isAbstract() && "Concrete type became abstract?");
483 // The type just became concrete, notify all users!
484 cast<DerivedType>(SCC[i])->notifyUsesThatTypeBecameConcrete();
491 //===----------------------------------------------------------------------===//
492 // Type Structural Equality Testing
493 //===----------------------------------------------------------------------===//
495 // TypesEqual - Two types are considered structurally equal if they have the
496 // same "shape": Every level and element of the types have identical primitive
497 // ID's, and the graphs have the same edges/nodes in them. Nodes do not have to
498 // be pointer equals to be equivalent though. This uses an optimistic algorithm
499 // that assumes that two graphs are the same until proven otherwise.
501 static bool TypesEqual(const Type *Ty, const Type *Ty2,
502 std::map<const Type *, const Type *> &EqTypes) {
503 if (Ty == Ty2) return true;
504 if (Ty->getTypeID() != Ty2->getTypeID()) return false;
505 if (isa<OpaqueType>(Ty))
506 return false; // Two unequal opaque types are never equal
508 std::map<const Type*, const Type*>::iterator It = EqTypes.find(Ty);
509 if (It != EqTypes.end())
510 return It->second == Ty2; // Looping back on a type, check for equality
512 // Otherwise, add the mapping to the table to make sure we don't get
513 // recursion on the types...
514 EqTypes.insert(It, std::make_pair(Ty, Ty2));
516 // Two really annoying special cases that breaks an otherwise nice simple
517 // algorithm is the fact that arraytypes have sizes that differentiates types,
518 // and that function types can be varargs or not. Consider this now.
520 if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
521 const IntegerType *ITy2 = cast<IntegerType>(Ty2);
522 return ITy->getBitWidth() == ITy2->getBitWidth();
523 } else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
524 const PointerType *PTy2 = cast<PointerType>(Ty2);
525 return PTy->getAddressSpace() == PTy2->getAddressSpace() &&
526 TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
527 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
528 const StructType *STy2 = cast<StructType>(Ty2);
529 if (STy->getNumElements() != STy2->getNumElements()) return false;
530 if (STy->isPacked() != STy2->isPacked()) return false;
531 for (unsigned i = 0, e = STy2->getNumElements(); i != e; ++i)
532 if (!TypesEqual(STy->getElementType(i), STy2->getElementType(i), EqTypes))
535 } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
536 const ArrayType *ATy2 = cast<ArrayType>(Ty2);
537 return ATy->getNumElements() == ATy2->getNumElements() &&
538 TypesEqual(ATy->getElementType(), ATy2->getElementType(), EqTypes);
539 } else if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) {
540 const VectorType *PTy2 = cast<VectorType>(Ty2);
541 return PTy->getNumElements() == PTy2->getNumElements() &&
542 TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
543 } else if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
544 const FunctionType *FTy2 = cast<FunctionType>(Ty2);
545 if (FTy->isVarArg() != FTy2->isVarArg() ||
546 FTy->getNumParams() != FTy2->getNumParams() ||
547 !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
549 for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
550 if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
555 assert(0 && "Unknown derived type!");
560 static bool TypesEqual(const Type *Ty, const Type *Ty2) {
561 std::map<const Type *, const Type *> EqTypes;
562 return TypesEqual(Ty, Ty2, EqTypes);
565 // AbstractTypeHasCycleThrough - Return true there is a path from CurTy to
566 // TargetTy in the type graph. We know that Ty is an abstract type, so if we
567 // ever reach a non-abstract type, we know that we don't need to search the
569 static bool AbstractTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
570 SmallPtrSet<const Type*, 128> &VisitedTypes) {
571 if (TargetTy == CurTy) return true;
572 if (!CurTy->isAbstract()) return false;
574 if (!VisitedTypes.insert(CurTy))
575 return false; // Already been here.
577 for (Type::subtype_iterator I = CurTy->subtype_begin(),
578 E = CurTy->subtype_end(); I != E; ++I)
579 if (AbstractTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
584 static bool ConcreteTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
585 SmallPtrSet<const Type*, 128> &VisitedTypes) {
586 if (TargetTy == CurTy) return true;
588 if (!VisitedTypes.insert(CurTy))
589 return false; // Already been here.
591 for (Type::subtype_iterator I = CurTy->subtype_begin(),
592 E = CurTy->subtype_end(); I != E; ++I)
593 if (ConcreteTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
598 /// TypeHasCycleThroughItself - Return true if the specified type has a cycle
600 static bool TypeHasCycleThroughItself(const Type *Ty) {
601 SmallPtrSet<const Type*, 128> VisitedTypes;
603 if (Ty->isAbstract()) { // Optimized case for abstract types.
604 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
606 if (AbstractTypeHasCycleThrough(Ty, *I, VisitedTypes))
609 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
611 if (ConcreteTypeHasCycleThrough(Ty, *I, VisitedTypes))
617 /// getSubElementHash - Generate a hash value for all of the SubType's of this
618 /// type. The hash value is guaranteed to be zero if any of the subtypes are
619 /// an opaque type. Otherwise we try to mix them in as well as possible, but do
620 /// not look at the subtype's subtype's.
621 static unsigned getSubElementHash(const Type *Ty) {
622 unsigned HashVal = 0;
623 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
626 const Type *SubTy = I->get();
627 HashVal += SubTy->getTypeID();
628 switch (SubTy->getTypeID()) {
630 case Type::OpaqueTyID: return 0; // Opaque -> hash = 0 no matter what.
631 case Type::IntegerTyID:
632 HashVal ^= (cast<IntegerType>(SubTy)->getBitWidth() << 3);
634 case Type::FunctionTyID:
635 HashVal ^= cast<FunctionType>(SubTy)->getNumParams()*2 +
636 cast<FunctionType>(SubTy)->isVarArg();
638 case Type::ArrayTyID:
639 HashVal ^= cast<ArrayType>(SubTy)->getNumElements();
641 case Type::VectorTyID:
642 HashVal ^= cast<VectorType>(SubTy)->getNumElements();
644 case Type::StructTyID:
645 HashVal ^= cast<StructType>(SubTy)->getNumElements();
647 case Type::PointerTyID:
648 HashVal ^= cast<PointerType>(SubTy)->getAddressSpace();
652 return HashVal ? HashVal : 1; // Do not return zero unless opaque subty.
655 //===----------------------------------------------------------------------===//
656 // Derived Type Factory Functions
657 //===----------------------------------------------------------------------===//
662 /// TypesByHash - Keep track of types by their structure hash value. Note
663 /// that we only keep track of types that have cycles through themselves in
666 std::multimap<unsigned, PATypeHolder> TypesByHash;
671 for (std::multimap<unsigned, PATypeHolder>::iterator I
672 = TypesByHash.begin(), E = TypesByHash.end(); I != E;) {
673 Type *Ty = I->second.get();
674 if (!Ty->isAbstract() && (isa<PointerType>(Ty) || isa<FunctionType>(Ty) ||
675 isa<VectorType>(Ty))) {
676 TypesByHash.erase(I++);
677 // PATypeHolder won't destroy it, so we must
685 void RemoveFromTypesByHash(unsigned Hash, const Type *Ty) {
686 std::multimap<unsigned, PATypeHolder>::iterator I =
687 TypesByHash.lower_bound(Hash);
688 for (; I != TypesByHash.end() && I->first == Hash; ++I) {
689 if (I->second == Ty) {
690 TypesByHash.erase(I);
695 // This must be do to an opaque type that was resolved. Switch down to hash
697 assert(Hash && "Didn't find type entry!");
698 RemoveFromTypesByHash(0, Ty);
701 /// TypeBecameConcrete - When Ty gets a notification that TheType just became
702 /// concrete, drop uses and make Ty non-abstract if we should.
703 void TypeBecameConcrete(DerivedType *Ty, const DerivedType *TheType) {
704 // If the element just became concrete, remove 'ty' from the abstract
705 // type user list for the type. Do this for as many times as Ty uses
707 for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
709 if (I->get() == TheType)
710 TheType->removeAbstractTypeUser(Ty);
712 // If the type is currently thought to be abstract, rescan all of our
713 // subtypes to see if the type has just become concrete! Note that this
714 // may send out notifications to AbstractTypeUsers that types become
716 if (Ty->isAbstract())
717 Ty->PromoteAbstractToConcrete();
723 // TypeMap - Make sure that only one instance of a particular type may be
724 // created on any given run of the compiler... note that this involves updating
725 // our map if an abstract type gets refined somehow.
728 template<class ValType, class TypeClass>
729 class TypeMap : public TypeMapBase {
730 std::map<ValType, PATypeHolder> Map;
732 typedef typename std::map<ValType, PATypeHolder>::iterator iterator;
733 ~TypeMap() { print("ON EXIT"); }
735 inline TypeClass *get(const ValType &V) {
736 iterator I = Map.find(V);
737 return I != Map.end() ? cast<TypeClass>((Type*)I->second.get()) : 0;
740 inline void add(const ValType &V, TypeClass *Ty) {
741 Map.insert(std::make_pair(V, Ty));
743 // If this type has a cycle, remember it.
744 TypesByHash.insert(std::make_pair(ValType::hashTypeStructure(Ty), Ty));
748 /// RefineAbstractType - This method is called after we have merged a type
749 /// with another one. We must now either merge the type away with
750 /// some other type or reinstall it in the map with it's new configuration.
751 void RefineAbstractType(TypeClass *Ty, const DerivedType *OldType,
752 const Type *NewType) {
753 #ifdef DEBUG_MERGE_TYPES
754 DOUT << "RefineAbstractType(" << (void*)OldType << "[" << *OldType
755 << "], " << (void*)NewType << " [" << *NewType << "])\n";
758 // Otherwise, we are changing one subelement type into another. Clearly the
759 // OldType must have been abstract, making us abstract.
760 assert(Ty->isAbstract() && "Refining a non-abstract type!");
761 assert(OldType != NewType);
763 // Make a temporary type holder for the type so that it doesn't disappear on
764 // us when we erase the entry from the map.
765 PATypeHolder TyHolder = Ty;
767 // The old record is now out-of-date, because one of the children has been
768 // updated. Remove the obsolete entry from the map.
769 unsigned NumErased = Map.erase(ValType::get(Ty));
770 assert(NumErased && "Element not found!"); NumErased = NumErased;
772 // Remember the structural hash for the type before we start hacking on it,
773 // in case we need it later.
774 unsigned OldTypeHash = ValType::hashTypeStructure(Ty);
776 // Find the type element we are refining... and change it now!
777 for (unsigned i = 0, e = Ty->getNumContainedTypes(); i != e; ++i)
778 if (Ty->ContainedTys[i] == OldType)
779 Ty->ContainedTys[i] = NewType;
780 unsigned NewTypeHash = ValType::hashTypeStructure(Ty);
782 // If there are no cycles going through this node, we can do a simple,
783 // efficient lookup in the map, instead of an inefficient nasty linear
785 if (!TypeHasCycleThroughItself(Ty)) {
786 typename std::map<ValType, PATypeHolder>::iterator I;
789 tie(I, Inserted) = Map.insert(std::make_pair(ValType::get(Ty), Ty));
791 // Refined to a different type altogether?
792 RemoveFromTypesByHash(OldTypeHash, Ty);
794 // We already have this type in the table. Get rid of the newly refined
796 TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
797 Ty->refineAbstractTypeTo(NewTy);
801 // Now we check to see if there is an existing entry in the table which is
802 // structurally identical to the newly refined type. If so, this type
803 // gets refined to the pre-existing type.
805 std::multimap<unsigned, PATypeHolder>::iterator I, E, Entry;
806 tie(I, E) = TypesByHash.equal_range(NewTypeHash);
808 for (; I != E; ++I) {
809 if (I->second == Ty) {
810 // Remember the position of the old type if we see it in our scan.
813 if (TypesEqual(Ty, I->second)) {
814 TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
816 // Remove the old entry form TypesByHash. If the hash values differ
817 // now, remove it from the old place. Otherwise, continue scanning
818 // withing this hashcode to reduce work.
819 if (NewTypeHash != OldTypeHash) {
820 RemoveFromTypesByHash(OldTypeHash, Ty);
823 // Find the location of Ty in the TypesByHash structure if we
824 // haven't seen it already.
825 while (I->second != Ty) {
827 assert(I != E && "Structure doesn't contain type??");
831 TypesByHash.erase(Entry);
833 Ty->refineAbstractTypeTo(NewTy);
839 // If there is no existing type of the same structure, we reinsert an
840 // updated record into the map.
841 Map.insert(std::make_pair(ValType::get(Ty), Ty));
844 // If the hash codes differ, update TypesByHash
845 if (NewTypeHash != OldTypeHash) {
846 RemoveFromTypesByHash(OldTypeHash, Ty);
847 TypesByHash.insert(std::make_pair(NewTypeHash, Ty));
850 // If the type is currently thought to be abstract, rescan all of our
851 // subtypes to see if the type has just become concrete! Note that this
852 // may send out notifications to AbstractTypeUsers that types become
854 if (Ty->isAbstract())
855 Ty->PromoteAbstractToConcrete();
858 void print(const char *Arg) const {
859 #ifdef DEBUG_MERGE_TYPES
860 DOUT << "TypeMap<>::" << Arg << " table contents:\n";
862 for (typename std::map<ValType, PATypeHolder>::const_iterator I
863 = Map.begin(), E = Map.end(); I != E; ++I)
864 DOUT << " " << (++i) << ". " << (void*)I->second.get() << " "
865 << *I->second.get() << "\n";
869 void dump() const { print("dump output"); }
874 //===----------------------------------------------------------------------===//
875 // Function Type Factory and Value Class...
878 //===----------------------------------------------------------------------===//
879 // Integer Type Factory...
882 class IntegerValType {
885 IntegerValType(uint16_t numbits) : bits(numbits) {}
887 static IntegerValType get(const IntegerType *Ty) {
888 return IntegerValType(Ty->getBitWidth());
891 static unsigned hashTypeStructure(const IntegerType *Ty) {
892 return (unsigned)Ty->getBitWidth();
895 inline bool operator<(const IntegerValType &IVT) const {
896 return bits < IVT.bits;
901 static ManagedStatic<TypeMap<IntegerValType, IntegerType> > IntegerTypes;
903 const IntegerType *IntegerType::get(unsigned NumBits) {
904 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
905 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
907 // Check for the built-in integer types
909 case 1: return cast<IntegerType>(Type::Int1Ty);
910 case 8: return cast<IntegerType>(Type::Int8Ty);
911 case 16: return cast<IntegerType>(Type::Int16Ty);
912 case 32: return cast<IntegerType>(Type::Int32Ty);
913 case 64: return cast<IntegerType>(Type::Int64Ty);
918 IntegerValType IVT(NumBits);
919 IntegerType *ITy = IntegerTypes->get(IVT);
920 if (ITy) return ITy; // Found a match, return it!
922 // Value not found. Derive a new type!
923 ITy = new IntegerType(NumBits);
924 IntegerTypes->add(IVT, ITy);
926 #ifdef DEBUG_MERGE_TYPES
927 DOUT << "Derived new type: " << *ITy << "\n";
932 bool IntegerType::isPowerOf2ByteWidth() const {
933 unsigned BitWidth = getBitWidth();
934 return (BitWidth > 7) && isPowerOf2_32(BitWidth);
937 APInt IntegerType::getMask() const {
938 return APInt::getAllOnesValue(getBitWidth());
941 // FunctionValType - Define a class to hold the key that goes into the TypeMap
944 class FunctionValType {
946 std::vector<const Type*> ArgTypes;
949 FunctionValType(const Type *ret, const std::vector<const Type*> &args,
950 bool isVA) : RetTy(ret), ArgTypes(args), isVarArg(isVA) {}
952 static FunctionValType get(const FunctionType *FT);
954 static unsigned hashTypeStructure(const FunctionType *FT) {
955 unsigned Result = FT->getNumParams()*2 + FT->isVarArg();
959 inline bool operator<(const FunctionValType &MTV) const {
960 if (RetTy < MTV.RetTy) return true;
961 if (RetTy > MTV.RetTy) return false;
962 if (isVarArg < MTV.isVarArg) return true;
963 if (isVarArg > MTV.isVarArg) return false;
964 if (ArgTypes < MTV.ArgTypes) return true;
965 if (ArgTypes > MTV.ArgTypes) return false;
971 // Define the actual map itself now...
972 static ManagedStatic<TypeMap<FunctionValType, FunctionType> > FunctionTypes;
974 FunctionValType FunctionValType::get(const FunctionType *FT) {
975 // Build up a FunctionValType
976 std::vector<const Type *> ParamTypes;
977 ParamTypes.reserve(FT->getNumParams());
978 for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
979 ParamTypes.push_back(FT->getParamType(i));
980 return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
984 // FunctionType::get - The factory function for the FunctionType class...
985 FunctionType *FunctionType::get(const Type *ReturnType,
986 const std::vector<const Type*> &Params,
988 FunctionValType VT(ReturnType, Params, isVarArg);
989 FunctionType *FT = FunctionTypes->get(VT);
993 FT = (FunctionType*) operator new(sizeof(FunctionType) +
994 sizeof(PATypeHandle)*(Params.size()+1));
995 new (FT) FunctionType(ReturnType, Params, isVarArg);
996 FunctionTypes->add(VT, FT);
998 #ifdef DEBUG_MERGE_TYPES
999 DOUT << "Derived new type: " << FT << "\n";
1004 //===----------------------------------------------------------------------===//
1005 // Array Type Factory...
1008 class ArrayValType {
1012 ArrayValType(const Type *val, uint64_t sz) : ValTy(val), Size(sz) {}
1014 static ArrayValType get(const ArrayType *AT) {
1015 return ArrayValType(AT->getElementType(), AT->getNumElements());
1018 static unsigned hashTypeStructure(const ArrayType *AT) {
1019 return (unsigned)AT->getNumElements();
1022 inline bool operator<(const ArrayValType &MTV) const {
1023 if (Size < MTV.Size) return true;
1024 return Size == MTV.Size && ValTy < MTV.ValTy;
1028 static ManagedStatic<TypeMap<ArrayValType, ArrayType> > ArrayTypes;
1031 ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
1032 assert(ElementType && "Can't get array of null types!");
1034 ArrayValType AVT(ElementType, NumElements);
1035 ArrayType *AT = ArrayTypes->get(AVT);
1036 if (AT) return AT; // Found a match, return it!
1038 // Value not found. Derive a new type!
1039 ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
1041 #ifdef DEBUG_MERGE_TYPES
1042 DOUT << "Derived new type: " << *AT << "\n";
1048 //===----------------------------------------------------------------------===//
1049 // Vector Type Factory...
1052 class VectorValType {
1056 VectorValType(const Type *val, int sz) : ValTy(val), Size(sz) {}
1058 static VectorValType get(const VectorType *PT) {
1059 return VectorValType(PT->getElementType(), PT->getNumElements());
1062 static unsigned hashTypeStructure(const VectorType *PT) {
1063 return PT->getNumElements();
1066 inline bool operator<(const VectorValType &MTV) const {
1067 if (Size < MTV.Size) return true;
1068 return Size == MTV.Size && ValTy < MTV.ValTy;
1072 static ManagedStatic<TypeMap<VectorValType, VectorType> > VectorTypes;
1075 VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
1076 assert(ElementType && "Can't get vector of null types!");
1078 VectorValType PVT(ElementType, NumElements);
1079 VectorType *PT = VectorTypes->get(PVT);
1080 if (PT) return PT; // Found a match, return it!
1082 // Value not found. Derive a new type!
1083 VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
1085 #ifdef DEBUG_MERGE_TYPES
1086 DOUT << "Derived new type: " << *PT << "\n";
1091 //===----------------------------------------------------------------------===//
1092 // Struct Type Factory...
1096 // StructValType - Define a class to hold the key that goes into the TypeMap
1098 class StructValType {
1099 std::vector<const Type*> ElTypes;
1102 StructValType(const std::vector<const Type*> &args, bool isPacked)
1103 : ElTypes(args), packed(isPacked) {}
1105 static StructValType get(const StructType *ST) {
1106 std::vector<const Type *> ElTypes;
1107 ElTypes.reserve(ST->getNumElements());
1108 for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i)
1109 ElTypes.push_back(ST->getElementType(i));
1111 return StructValType(ElTypes, ST->isPacked());
1114 static unsigned hashTypeStructure(const StructType *ST) {
1115 return ST->getNumElements();
1118 inline bool operator<(const StructValType &STV) const {
1119 if (ElTypes < STV.ElTypes) return true;
1120 else if (ElTypes > STV.ElTypes) return false;
1121 else return (int)packed < (int)STV.packed;
1126 static ManagedStatic<TypeMap<StructValType, StructType> > StructTypes;
1128 StructType *StructType::get(const std::vector<const Type*> &ETypes,
1130 StructValType STV(ETypes, isPacked);
1131 StructType *ST = StructTypes->get(STV);
1134 // Value not found. Derive a new type!
1135 ST = (StructType*) operator new(sizeof(StructType) +
1136 sizeof(PATypeHandle) * ETypes.size());
1137 new (ST) StructType(ETypes, isPacked);
1138 StructTypes->add(STV, ST);
1140 #ifdef DEBUG_MERGE_TYPES
1141 DOUT << "Derived new type: " << *ST << "\n";
1146 StructType *StructType::get(const Type *type, ...) {
1148 std::vector<const llvm::Type*> StructFields;
1151 StructFields.push_back(type);
1152 type = va_arg(ap, llvm::Type*);
1154 return llvm::StructType::get(StructFields);
1159 //===----------------------------------------------------------------------===//
1160 // Pointer Type Factory...
1163 // PointerValType - Define a class to hold the key that goes into the TypeMap
1166 class PointerValType {
1168 unsigned AddressSpace;
1170 PointerValType(const Type *val, unsigned as) : ValTy(val), AddressSpace(as) {}
1172 static PointerValType get(const PointerType *PT) {
1173 return PointerValType(PT->getElementType(), PT->getAddressSpace());
1176 static unsigned hashTypeStructure(const PointerType *PT) {
1177 return getSubElementHash(PT);
1180 bool operator<(const PointerValType &MTV) const {
1181 if (AddressSpace < MTV.AddressSpace) return true;
1182 return AddressSpace == MTV.AddressSpace && ValTy < MTV.ValTy;
1187 static ManagedStatic<TypeMap<PointerValType, PointerType> > PointerTypes;
1189 PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
1190 assert(ValueType && "Can't get a pointer to <null> type!");
1191 assert(ValueType != Type::VoidTy &&
1192 "Pointer to void is not valid, use sbyte* instead!");
1193 assert(ValueType != Type::LabelTy && "Pointer to label is not valid!");
1194 PointerValType PVT(ValueType, AddressSpace);
1196 PointerType *PT = PointerTypes->get(PVT);
1199 // Value not found. Derive a new type!
1200 PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
1202 #ifdef DEBUG_MERGE_TYPES
1203 DOUT << "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 DOUT << " remAbstractTypeUser[" << (void*)this << ", "
1233 << *this << "][" << i << "] User = " << U << "\n";
1236 if (AbstractTypeUsers.empty() && getRefCount() == 0 && isAbstract()) {
1237 #ifdef DEBUG_MERGE_TYPES
1238 DOUT << "DELETEing unused abstract type: <" << *this
1239 << ">[" << (void*)this << "]" << "\n";
1245 // refineAbstractTypeTo - This function is used when it is discovered that
1246 // the 'this' abstract type is actually equivalent to the NewType specified.
1247 // This causes all users of 'this' to switch to reference the more concrete type
1248 // NewType and for 'this' to be deleted.
1250 void DerivedType::refineAbstractTypeTo(const Type *NewType) {
1251 assert(isAbstract() && "refineAbstractTypeTo: Current type is not abstract!");
1252 assert(this != NewType && "Can't refine to myself!");
1253 assert(ForwardType == 0 && "This type has already been refined!");
1255 // The descriptions may be out of date. Conservatively clear them all!
1256 if (AbstractTypeDescriptions.isConstructed())
1257 AbstractTypeDescriptions->clear();
1259 #ifdef DEBUG_MERGE_TYPES
1260 DOUT << "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(); OldSize=OldSize;
1297 #ifdef DEBUG_MERGE_TYPES
1298 DOUT << " 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 DOUT << "typeIsREFINED type: " << (void*)this << " " << *this << "\n";
1323 unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize;
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 VectorType::refineAbstractType(const DerivedType *OldType,
1365 const Type *NewType) {
1366 VectorTypes->RefineAbstractType(this, OldType, NewType);
1369 void VectorType::typeBecameConcrete(const DerivedType *AbsTy) {
1370 VectorTypes->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 if (const IntegerType *IT = dyn_cast<IntegerType>(V->getType()))
1401 return IT->getBitWidth() == 32 || IT->getBitWidth() == 64;
1406 std::ostream &operator<<(std::ostream &OS, const Type *T) {
1408 OS << "<null> value!\n";
1414 std::ostream &operator<<(std::ostream &OS, const Type &T) {