eliminate some pointless virtual methods.
[oota-llvm.git] / lib / VMCore / Type.cpp
1 //===-- Type.cpp - Implement the Type class -------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the Type class for the VMCore library.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "LLVMContextImpl.h"
15 #include "llvm/ADT/SCCIterator.h"
16 #include <algorithm>
17 #include <cstdarg>
18 using namespace llvm;
19
20 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
21 // created and later destroyed, all in an effort to make sure that there is only
22 // a single canonical version of a type.
23 //
24 // #define DEBUG_MERGE_TYPES 1
25
26 AbstractTypeUser::~AbstractTypeUser() {}
27
28 void AbstractTypeUser::setType(Value *V, const Type *NewTy) {
29   V->VTy = NewTy;
30 }
31
32 //===----------------------------------------------------------------------===//
33 //                         Type Class Implementation
34 //===----------------------------------------------------------------------===//
35
36 /// Because of the way Type subclasses are allocated, this function is necessary
37 /// to use the correct kind of "delete" operator to deallocate the Type object.
38 /// Some type objects (FunctionTy, StructTy) allocate additional space
39 /// after the space for their derived type to hold the contained types array of
40 /// PATypeHandles. Using this allocation scheme means all the PATypeHandles are
41 /// allocated with the type object, decreasing allocations and eliminating the
42 /// need for a std::vector to be used in the Type class itself. 
43 /// @brief Type destruction function
44 void Type::destroy() const {
45   // Nothing calls getForwardedType from here on.
46   if (ForwardType && ForwardType->isAbstract()) {
47     ForwardType->dropRef();
48     ForwardType = NULL;
49   }
50
51   // Structures and Functions allocate their contained types past the end of
52   // the type object itself. These need to be destroyed differently than the
53   // other types.
54   if (this->isFunctionTy() || this->isStructTy()) {
55     // First, make sure we destruct any PATypeHandles allocated by these
56     // subclasses.  They must be manually destructed. 
57     for (unsigned i = 0; i < NumContainedTys; ++i)
58       ContainedTys[i].PATypeHandle::~PATypeHandle();
59
60     // Now call the destructor for the subclass directly because we're going
61     // to delete this as an array of char.
62     if (this->isFunctionTy())
63       static_cast<const FunctionType*>(this)->FunctionType::~FunctionType();
64     else {
65       assert(isStructTy());
66       static_cast<const StructType*>(this)->StructType::~StructType();
67     }
68
69     // Finally, remove the memory as an array deallocation of the chars it was
70     // constructed from.
71     operator delete(const_cast<Type *>(this));
72
73     return;
74   }
75   
76   if (const OpaqueType *opaque_this = dyn_cast<OpaqueType>(this)) {
77     LLVMContextImpl *pImpl = this->getContext().pImpl;
78     pImpl->OpaqueTypes.erase(opaque_this);
79   }
80
81   // For all the other type subclasses, there is either no contained types or 
82   // just one (all Sequentials). For Sequentials, the PATypeHandle is not
83   // allocated past the type object, its included directly in the SequentialType
84   // class. This means we can safely just do "normal" delete of this object and
85   // all the destructors that need to run will be run.
86   delete this; 
87 }
88
89 const Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) {
90   switch (IDNumber) {
91   case VoidTyID      : return getVoidTy(C);
92   case FloatTyID     : return getFloatTy(C);
93   case DoubleTyID    : return getDoubleTy(C);
94   case X86_FP80TyID  : return getX86_FP80Ty(C);
95   case FP128TyID     : return getFP128Ty(C);
96   case PPC_FP128TyID : return getPPC_FP128Ty(C);
97   case LabelTyID     : return getLabelTy(C);
98   case MetadataTyID  : return getMetadataTy(C);
99   case X86_MMXTyID   : return getX86_MMXTy(C);
100   default:
101     return 0;
102   }
103 }
104
105 /// getScalarType - If this is a vector type, return the element type,
106 /// otherwise return this.
107 const Type *Type::getScalarType() const {
108   if (const VectorType *VTy = dyn_cast<VectorType>(this))
109     return VTy->getElementType();
110   return this;
111 }
112
113 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
114 bool Type::isIntegerTy(unsigned Bitwidth) const {
115   return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
116 }
117
118 /// isIntOrIntVectorTy - Return true if this is an integer type or a vector of
119 /// integer types.
120 ///
121 bool Type::isIntOrIntVectorTy() const {
122   if (isIntegerTy())
123     return true;
124   if (ID != Type::VectorTyID) return false;
125   
126   return cast<VectorType>(this)->getElementType()->isIntegerTy();
127 }
128
129 /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP types.
130 ///
131 bool Type::isFPOrFPVectorTy() const {
132   if (ID == Type::FloatTyID || ID == Type::DoubleTyID || 
133       ID == Type::FP128TyID || ID == Type::X86_FP80TyID || 
134       ID == Type::PPC_FP128TyID)
135     return true;
136   if (ID != Type::VectorTyID) return false;
137   
138   return cast<VectorType>(this)->getElementType()->isFloatingPointTy();
139 }
140
141 // canLosslesslyBitCastTo - Return true if this type can be converted to
142 // 'Ty' without any reinterpretation of bits.  For example, i8* to i32*.
143 //
144 bool Type::canLosslesslyBitCastTo(const Type *Ty) const {
145   // Identity cast means no change so return true
146   if (this == Ty) 
147     return true;
148   
149   // They are not convertible unless they are at least first class types
150   if (!this->isFirstClassType() || !Ty->isFirstClassType())
151     return false;
152
153   // Vector -> Vector conversions are always lossless if the two vector types
154   // have the same size, otherwise not.  Also, 64-bit vector types can be
155   // converted to x86mmx.
156   if (const VectorType *thisPTy = dyn_cast<VectorType>(this)) {
157     if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
158       return thisPTy->getBitWidth() == thatPTy->getBitWidth();
159     if (Ty->getTypeID() == Type::X86_MMXTyID &&
160         thisPTy->getBitWidth() == 64)
161       return true;
162   }
163
164   if (this->getTypeID() == Type::X86_MMXTyID)
165     if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
166       if (thatPTy->getBitWidth() == 64)
167         return true;
168
169   // At this point we have only various mismatches of the first class types
170   // remaining and ptr->ptr. Just select the lossless conversions. Everything
171   // else is not lossless.
172   if (this->isPointerTy())
173     return Ty->isPointerTy();
174   return false;  // Other types have no identity values
175 }
176
177 bool Type::isEmptyTy() const {
178   const ArrayType *ATy = dyn_cast<ArrayType>(this);
179   if (ATy) {
180     unsigned NumElements = ATy->getNumElements();
181     return NumElements == 0 || ATy->getElementType()->isEmptyTy();
182   }
183
184   const StructType *STy = dyn_cast<StructType>(this);
185   if (STy) {
186     unsigned NumElements = STy->getNumElements();
187     for (unsigned i = 0; i < NumElements; ++i)
188       if (!STy->getElementType(i)->isEmptyTy())
189         return false;
190     return true;
191   }
192
193   return false;
194 }
195
196 unsigned Type::getPrimitiveSizeInBits() const {
197   switch (getTypeID()) {
198   case Type::FloatTyID: return 32;
199   case Type::DoubleTyID: return 64;
200   case Type::X86_FP80TyID: return 80;
201   case Type::FP128TyID: return 128;
202   case Type::PPC_FP128TyID: return 128;
203   case Type::X86_MMXTyID: return 64;
204   case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
205   case Type::VectorTyID:  return cast<VectorType>(this)->getBitWidth();
206   default: return 0;
207   }
208 }
209
210 /// getScalarSizeInBits - If this is a vector type, return the
211 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
212 /// getPrimitiveSizeInBits value for this type.
213 unsigned Type::getScalarSizeInBits() const {
214   return getScalarType()->getPrimitiveSizeInBits();
215 }
216
217 /// getFPMantissaWidth - Return the width of the mantissa of this type.  This
218 /// is only valid on floating point types.  If the FP type does not
219 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
220 int Type::getFPMantissaWidth() const {
221   if (const VectorType *VTy = dyn_cast<VectorType>(this))
222     return VTy->getElementType()->getFPMantissaWidth();
223   assert(isFloatingPointTy() && "Not a floating point type!");
224   if (ID == FloatTyID) return 24;
225   if (ID == DoubleTyID) return 53;
226   if (ID == X86_FP80TyID) return 64;
227   if (ID == FP128TyID) return 113;
228   assert(ID == PPC_FP128TyID && "unknown fp type");
229   return -1;
230 }
231
232 /// isSizedDerivedType - Derived types like structures and arrays are sized
233 /// iff all of the members of the type are sized as well.  Since asking for
234 /// their size is relatively uncommon, move this operation out of line.
235 bool Type::isSizedDerivedType() const {
236   if (this->isIntegerTy())
237     return true;
238
239   if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
240     return ATy->getElementType()->isSized();
241
242   if (const VectorType *VTy = dyn_cast<VectorType>(this))
243     return VTy->getElementType()->isSized();
244
245   if (!this->isStructTy()) 
246     return false;
247
248   // Okay, our struct is sized if all of the elements are...
249   for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
250     if (!(*I)->isSized()) 
251       return false;
252
253   return true;
254 }
255
256 /// getForwardedTypeInternal - This method is used to implement the union-find
257 /// algorithm for when a type is being forwarded to another type.
258 const Type *Type::getForwardedTypeInternal() const {
259   assert(ForwardType && "This type is not being forwarded to another type!");
260
261   // Check to see if the forwarded type has been forwarded on.  If so, collapse
262   // the forwarding links.
263   const Type *RealForwardedType = ForwardType->getForwardedType();
264   if (!RealForwardedType)
265     return ForwardType;  // No it's not forwarded again
266
267   // Yes, it is forwarded again.  First thing, add the reference to the new
268   // forward type.
269   if (RealForwardedType->isAbstract())
270     RealForwardedType->addRef();
271
272   // Now drop the old reference.  This could cause ForwardType to get deleted.
273   // ForwardType must be abstract because only abstract types can have their own
274   // ForwardTypes.
275   ForwardType->dropRef();
276
277   // Return the updated type.
278   ForwardType = RealForwardedType;
279   return ForwardType;
280 }
281
282 void Type::refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
283   llvm_unreachable("Attempting to refine a derived type!");
284 }
285 void Type::typeBecameConcrete(const DerivedType *AbsTy) {
286   llvm_unreachable("DerivedType is already a concrete type!");
287 }
288
289 const Type *CompositeType::getTypeAtIndex(const Value *V) const {
290   if (const StructType *STy = dyn_cast<StructType>(this)) {
291     unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
292     assert(indexValid(Idx) && "Invalid structure index!");
293     return STy->getElementType(Idx);
294   }
295     
296   return cast<SequentialType>(this)->getElementType();
297 }
298 const Type *CompositeType::getTypeAtIndex(unsigned Idx) const {
299   if (const StructType *STy = dyn_cast<StructType>(this)) {
300     assert(indexValid(Idx) && "Invalid structure index!");
301     return STy->getElementType(Idx);
302   }
303   
304   return cast<SequentialType>(this)->getElementType();
305 }
306 bool CompositeType::indexValid(const Value *V) const {
307   if (const StructType *STy = dyn_cast<StructType>(this)) {
308     // Structure indexes require 32-bit integer constants.
309     if (V->getType()->isIntegerTy(32))
310       if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
311         return CU->getZExtValue() < STy->getNumElements();
312     return false;
313   }
314   
315   // Sequential types can be indexed by any integer.
316   return V->getType()->isIntegerTy();
317 }
318
319 bool CompositeType::indexValid(unsigned Idx) const {
320   if (const StructType *STy = dyn_cast<StructType>(this))
321     return Idx < STy->getNumElements();
322   // Sequential types can be indexed by any integer.
323   return true;
324 }
325
326
327 //===----------------------------------------------------------------------===//
328 //                          Primitive 'Type' data
329 //===----------------------------------------------------------------------===//
330
331 const Type *Type::getVoidTy(LLVMContext &C) {
332   return &C.pImpl->VoidTy;
333 }
334
335 const Type *Type::getLabelTy(LLVMContext &C) {
336   return &C.pImpl->LabelTy;
337 }
338
339 const Type *Type::getFloatTy(LLVMContext &C) {
340   return &C.pImpl->FloatTy;
341 }
342
343 const Type *Type::getDoubleTy(LLVMContext &C) {
344   return &C.pImpl->DoubleTy;
345 }
346
347 const Type *Type::getMetadataTy(LLVMContext &C) {
348   return &C.pImpl->MetadataTy;
349 }
350
351 const Type *Type::getX86_FP80Ty(LLVMContext &C) {
352   return &C.pImpl->X86_FP80Ty;
353 }
354
355 const Type *Type::getFP128Ty(LLVMContext &C) {
356   return &C.pImpl->FP128Ty;
357 }
358
359 const Type *Type::getPPC_FP128Ty(LLVMContext &C) {
360   return &C.pImpl->PPC_FP128Ty;
361 }
362
363 const Type *Type::getX86_MMXTy(LLVMContext &C) {
364   return &C.pImpl->X86_MMXTy;
365 }
366
367 const IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
368   return IntegerType::get(C, N);
369 }
370
371 const IntegerType *Type::getInt1Ty(LLVMContext &C) {
372   return &C.pImpl->Int1Ty;
373 }
374
375 const IntegerType *Type::getInt8Ty(LLVMContext &C) {
376   return &C.pImpl->Int8Ty;
377 }
378
379 const IntegerType *Type::getInt16Ty(LLVMContext &C) {
380   return &C.pImpl->Int16Ty;
381 }
382
383 const IntegerType *Type::getInt32Ty(LLVMContext &C) {
384   return &C.pImpl->Int32Ty;
385 }
386
387 const IntegerType *Type::getInt64Ty(LLVMContext &C) {
388   return &C.pImpl->Int64Ty;
389 }
390
391 const PointerType *Type::getFloatPtrTy(LLVMContext &C, unsigned AS) {
392   return getFloatTy(C)->getPointerTo(AS);
393 }
394
395 const PointerType *Type::getDoublePtrTy(LLVMContext &C, unsigned AS) {
396   return getDoubleTy(C)->getPointerTo(AS);
397 }
398
399 const PointerType *Type::getX86_FP80PtrTy(LLVMContext &C, unsigned AS) {
400   return getX86_FP80Ty(C)->getPointerTo(AS);
401 }
402
403 const PointerType *Type::getFP128PtrTy(LLVMContext &C, unsigned AS) {
404   return getFP128Ty(C)->getPointerTo(AS);
405 }
406
407 const PointerType *Type::getPPC_FP128PtrTy(LLVMContext &C, unsigned AS) {
408   return getPPC_FP128Ty(C)->getPointerTo(AS);
409 }
410
411 const PointerType *Type::getX86_MMXPtrTy(LLVMContext &C, unsigned AS) {
412   return getX86_MMXTy(C)->getPointerTo(AS);
413 }
414
415 const PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
416   return getIntNTy(C, N)->getPointerTo(AS);
417 }
418
419 const PointerType *Type::getInt1PtrTy(LLVMContext &C, unsigned AS) {
420   return getInt1Ty(C)->getPointerTo(AS);
421 }
422
423 const PointerType *Type::getInt8PtrTy(LLVMContext &C, unsigned AS) {
424   return getInt8Ty(C)->getPointerTo(AS);
425 }
426
427 const PointerType *Type::getInt16PtrTy(LLVMContext &C, unsigned AS) {
428   return getInt16Ty(C)->getPointerTo(AS);
429 }
430
431 const PointerType *Type::getInt32PtrTy(LLVMContext &C, unsigned AS) {
432   return getInt32Ty(C)->getPointerTo(AS);
433 }
434
435 const PointerType *Type::getInt64PtrTy(LLVMContext &C, unsigned AS) {
436   return getInt64Ty(C)->getPointerTo(AS);
437 }
438
439 //===----------------------------------------------------------------------===//
440 //                          Derived Type Constructors
441 //===----------------------------------------------------------------------===//
442
443 /// isValidReturnType - Return true if the specified type is valid as a return
444 /// type.
445 bool FunctionType::isValidReturnType(const Type *RetTy) {
446   return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
447          !RetTy->isMetadataTy();
448 }
449
450 /// isValidArgumentType - Return true if the specified type is valid as an
451 /// argument type.
452 bool FunctionType::isValidArgumentType(const Type *ArgTy) {
453   return ArgTy->isFirstClassType() || ArgTy->isOpaqueTy();
454 }
455
456 FunctionType::FunctionType(const Type *Result,
457                            ArrayRef<const Type*> Params,
458                            bool IsVarArgs)
459   : DerivedType(Result->getContext(), FunctionTyID) {
460   ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
461   NumContainedTys = Params.size() + 1; // + 1 for result type
462   assert(isValidReturnType(Result) && "invalid return type for function");
463   setSubclassData(IsVarArgs);
464
465   bool isAbstract = Result->isAbstract();
466   new (&ContainedTys[0]) PATypeHandle(Result, this);
467
468   for (unsigned i = 0; i != Params.size(); ++i) {
469     assert(isValidArgumentType(Params[i]) &&
470            "Not a valid type for function argument!");
471     new (&ContainedTys[i+1]) PATypeHandle(Params[i], this);
472     isAbstract |= Params[i]->isAbstract();
473   }
474
475   // Calculate whether or not this type is abstract
476   setAbstract(isAbstract);
477 }
478
479 StructType::StructType(LLVMContext &C, 
480                        ArrayRef<const Type*> Types, bool isPacked)
481   : CompositeType(C, StructTyID) {
482   ContainedTys = reinterpret_cast<PATypeHandle*>(this + 1);
483   NumContainedTys = Types.size();
484   setSubclassData(isPacked);
485   bool isAbstract = false;
486   for (unsigned i = 0; i < Types.size(); ++i) {
487     assert(Types[i] && "<null> type for structure field!");
488     assert(isValidElementType(Types[i]) &&
489            "Invalid type for structure element!");
490     new (&ContainedTys[i]) PATypeHandle(Types[i], this);
491     isAbstract |= Types[i]->isAbstract();
492   }
493
494   // Calculate whether or not this type is abstract
495   setAbstract(isAbstract);
496 }
497
498 ArrayType::ArrayType(const Type *ElType, uint64_t NumEl)
499   : SequentialType(ArrayTyID, ElType) {
500   NumElements = NumEl;
501
502   // Calculate whether or not this type is abstract
503   setAbstract(ElType->isAbstract());
504 }
505
506 VectorType::VectorType(const Type *ElType, unsigned NumEl)
507   : SequentialType(VectorTyID, ElType) {
508   NumElements = NumEl;
509   setAbstract(ElType->isAbstract());
510   assert(NumEl > 0 && "NumEl of a VectorType must be greater than 0");
511   assert(isValidElementType(ElType) &&
512          "Elements of a VectorType must be a primitive type");
513
514 }
515
516
517 PointerType::PointerType(const Type *E, unsigned AddrSpace)
518   : SequentialType(PointerTyID, E) {
519   setSubclassData(AddrSpace);
520   // Calculate whether or not this type is abstract
521   setAbstract(E->isAbstract());
522 }
523
524 OpaqueType::OpaqueType(LLVMContext &C) : DerivedType(C, OpaqueTyID) {
525   setAbstract(true);
526 #ifdef DEBUG_MERGE_TYPES
527   DEBUG(dbgs() << "Derived new type: " << *this << "\n");
528 #endif
529 }
530
531 void PATypeHolder::destroy() {
532   Ty = 0;
533 }
534
535 // dropAllTypeUses - When this (abstract) type is resolved to be equal to
536 // another (more concrete) type, we must eliminate all references to other
537 // types, to avoid some circular reference problems.
538 void DerivedType::dropAllTypeUses() {
539   if (NumContainedTys != 0) {
540     // The type must stay abstract.  To do this, we insert a pointer to a type
541     // that will never get resolved, thus will always be abstract.
542     ContainedTys[0] = getContext().pImpl->AlwaysOpaqueTy;
543
544     // Change the rest of the types to be Int32Ty's.  It doesn't matter what we
545     // pick so long as it doesn't point back to this type.  We choose something
546     // concrete to avoid overhead for adding to AbstractTypeUser lists and
547     // stuff.
548     const Type *ConcreteTy = Type::getInt32Ty(getContext());
549     for (unsigned i = 1, e = NumContainedTys; i != e; ++i)
550       ContainedTys[i] = ConcreteTy;
551   }
552 }
553
554
555 namespace {
556
557 /// TypePromotionGraph and graph traits - this is designed to allow us to do
558 /// efficient SCC processing of type graphs.  This is the exact same as
559 /// GraphTraits<Type*>, except that we pretend that concrete types have no
560 /// children to avoid processing them.
561 struct TypePromotionGraph {
562   Type *Ty;
563   TypePromotionGraph(Type *T) : Ty(T) {}
564 };
565
566 }
567
568 namespace llvm {
569   template <> struct GraphTraits<TypePromotionGraph> {
570     typedef Type NodeType;
571     typedef Type::subtype_iterator ChildIteratorType;
572
573     static inline NodeType *getEntryNode(TypePromotionGraph G) { return G.Ty; }
574     static inline ChildIteratorType child_begin(NodeType *N) {
575       if (N->isAbstract())
576         return N->subtype_begin();
577       // No need to process children of concrete types.
578       return N->subtype_end();
579     }
580     static inline ChildIteratorType child_end(NodeType *N) {
581       return N->subtype_end();
582     }
583   };
584 }
585
586
587 // PromoteAbstractToConcrete - This is a recursive function that walks a type
588 // graph calculating whether or not a type is abstract.
589 //
590 void Type::PromoteAbstractToConcrete() {
591   if (!isAbstract()) return;
592
593   scc_iterator<TypePromotionGraph> SI = scc_begin(TypePromotionGraph(this));
594   scc_iterator<TypePromotionGraph> SE = scc_end  (TypePromotionGraph(this));
595
596   for (; SI != SE; ++SI) {
597     std::vector<Type*> &SCC = *SI;
598
599     // Concrete types are leaves in the tree.  Since an SCC will either be all
600     // abstract or all concrete, we only need to check one type.
601     if (!SCC[0]->isAbstract()) continue;
602     
603     if (SCC[0]->isOpaqueTy())
604       return;     // Not going to be concrete, sorry.
605
606     // If all of the children of all of the types in this SCC are concrete,
607     // then this SCC is now concrete as well.  If not, neither this SCC, nor
608     // any parent SCCs will be concrete, so we might as well just exit.
609     for (unsigned i = 0, e = SCC.size(); i != e; ++i)
610       for (Type::subtype_iterator CI = SCC[i]->subtype_begin(),
611              E = SCC[i]->subtype_end(); CI != E; ++CI)
612         if ((*CI)->isAbstract())
613           // If the child type is in our SCC, it doesn't make the entire SCC
614           // abstract unless there is a non-SCC abstract type.
615           if (std::find(SCC.begin(), SCC.end(), *CI) == SCC.end())
616             return;               // Not going to be concrete, sorry.
617
618     // Okay, we just discovered this whole SCC is now concrete, mark it as
619     // such!
620     for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
621       assert(SCC[i]->isAbstract() && "Why are we processing concrete types?");
622
623       SCC[i]->setAbstract(false);
624     }
625
626     for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
627       assert(!SCC[i]->isAbstract() && "Concrete type became abstract?");
628       // The type just became concrete, notify all users!
629       cast<DerivedType>(SCC[i])->notifyUsesThatTypeBecameConcrete();
630     }
631   }
632 }
633
634
635 //===----------------------------------------------------------------------===//
636 //                      Type Structural Equality Testing
637 //===----------------------------------------------------------------------===//
638
639 // TypesEqual - Two types are considered structurally equal if they have the
640 // same "shape": Every level and element of the types have identical primitive
641 // ID's, and the graphs have the same edges/nodes in them.  Nodes do not have to
642 // be pointer equals to be equivalent though.  This uses an optimistic algorithm
643 // that assumes that two graphs are the same until proven otherwise.
644 //
645 static bool TypesEqual(const Type *Ty, const Type *Ty2,
646                        std::map<const Type *, const Type *> &EqTypes) {
647   if (Ty == Ty2) return true;
648   if (Ty->getTypeID() != Ty2->getTypeID()) return false;
649   if (Ty->isOpaqueTy())
650     return false;  // Two unequal opaque types are never equal
651
652   std::map<const Type*, const Type*>::iterator It = EqTypes.find(Ty);
653   if (It != EqTypes.end())
654     return It->second == Ty2;    // Looping back on a type, check for equality
655
656   // Otherwise, add the mapping to the table to make sure we don't get
657   // recursion on the types...
658   EqTypes.insert(It, std::make_pair(Ty, Ty2));
659
660   // Two really annoying special cases that breaks an otherwise nice simple
661   // algorithm is the fact that arraytypes have sizes that differentiates types,
662   // and that function types can be varargs or not.  Consider this now.
663   //
664   if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) {
665     const IntegerType *ITy2 = cast<IntegerType>(Ty2);
666     return ITy->getBitWidth() == ITy2->getBitWidth();
667   }
668   
669   if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
670     const PointerType *PTy2 = cast<PointerType>(Ty2);
671     return PTy->getAddressSpace() == PTy2->getAddressSpace() &&
672            TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
673   }
674   
675   if (const StructType *STy = dyn_cast<StructType>(Ty)) {
676     const StructType *STy2 = cast<StructType>(Ty2);
677     if (STy->getNumElements() != STy2->getNumElements()) return false;
678     if (STy->isPacked() != STy2->isPacked()) return false;
679     for (unsigned i = 0, e = STy2->getNumElements(); i != e; ++i)
680       if (!TypesEqual(STy->getElementType(i), STy2->getElementType(i), EqTypes))
681         return false;
682     return true;
683   }
684   
685   if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
686     const ArrayType *ATy2 = cast<ArrayType>(Ty2);
687     return ATy->getNumElements() == ATy2->getNumElements() &&
688            TypesEqual(ATy->getElementType(), ATy2->getElementType(), EqTypes);
689   }
690   
691   if (const VectorType *PTy = dyn_cast<VectorType>(Ty)) {
692     const VectorType *PTy2 = cast<VectorType>(Ty2);
693     return PTy->getNumElements() == PTy2->getNumElements() &&
694            TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
695   }
696   
697   if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
698     const FunctionType *FTy2 = cast<FunctionType>(Ty2);
699     if (FTy->isVarArg() != FTy2->isVarArg() ||
700         FTy->getNumParams() != FTy2->getNumParams() ||
701         !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
702       return false;
703     for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
704       if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
705         return false;
706     }
707     return true;
708   }
709   
710   llvm_unreachable("Unknown derived type!");
711   return false;
712 }
713
714 namespace llvm { // in namespace llvm so findable by ADL
715 static bool TypesEqual(const Type *Ty, const Type *Ty2) {
716   std::map<const Type *, const Type *> EqTypes;
717   return ::TypesEqual(Ty, Ty2, EqTypes);
718 }
719 }
720
721 // AbstractTypeHasCycleThrough - Return true there is a path from CurTy to
722 // TargetTy in the type graph.  We know that Ty is an abstract type, so if we
723 // ever reach a non-abstract type, we know that we don't need to search the
724 // subgraph.
725 static bool AbstractTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
726                                 SmallPtrSet<const Type*, 128> &VisitedTypes) {
727   if (TargetTy == CurTy) return true;
728   if (!CurTy->isAbstract()) return false;
729
730   if (!VisitedTypes.insert(CurTy))
731     return false;  // Already been here.
732
733   for (Type::subtype_iterator I = CurTy->subtype_begin(),
734        E = CurTy->subtype_end(); I != E; ++I)
735     if (AbstractTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
736       return true;
737   return false;
738 }
739
740 static bool ConcreteTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
741                                 SmallPtrSet<const Type*, 128> &VisitedTypes) {
742   if (TargetTy == CurTy) return true;
743
744   if (!VisitedTypes.insert(CurTy))
745     return false;  // Already been here.
746
747   for (Type::subtype_iterator I = CurTy->subtype_begin(),
748        E = CurTy->subtype_end(); I != E; ++I)
749     if (ConcreteTypeHasCycleThrough(TargetTy, *I, VisitedTypes))
750       return true;
751   return false;
752 }
753
754 /// TypeHasCycleThroughItself - Return true if the specified type has
755 /// a cycle back to itself.
756
757 namespace llvm { // in namespace llvm so it's findable by ADL
758 static bool TypeHasCycleThroughItself(const Type *Ty) {
759   SmallPtrSet<const Type*, 128> VisitedTypes;
760
761   if (Ty->isAbstract()) {  // Optimized case for abstract types.
762     for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
763          I != E; ++I)
764       if (AbstractTypeHasCycleThrough(Ty, *I, VisitedTypes))
765         return true;
766   } else {
767     for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
768          I != E; ++I)
769       if (ConcreteTypeHasCycleThrough(Ty, *I, VisitedTypes))
770         return true;
771   }
772   return false;
773 }
774 }
775
776 //===----------------------------------------------------------------------===//
777 // Function Type Factory and Value Class...
778 //
779 const IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
780   assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
781   assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
782
783   // Check for the built-in integer types
784   switch (NumBits) {
785   case  1: return cast<IntegerType>(Type::getInt1Ty(C));
786   case  8: return cast<IntegerType>(Type::getInt8Ty(C));
787   case 16: return cast<IntegerType>(Type::getInt16Ty(C));
788   case 32: return cast<IntegerType>(Type::getInt32Ty(C));
789   case 64: return cast<IntegerType>(Type::getInt64Ty(C));
790   default: 
791     break;
792   }
793
794   LLVMContextImpl *pImpl = C.pImpl;
795   
796   IntegerValType IVT(NumBits);
797   IntegerType *ITy = 0;
798   
799   // First, see if the type is already in the table, for which
800   // a reader lock suffices.
801   ITy = pImpl->IntegerTypes.get(IVT);
802     
803   if (!ITy) {
804     // Value not found.  Derive a new type!
805     ITy = new IntegerType(C, NumBits);
806     pImpl->IntegerTypes.add(IVT, ITy);
807   }
808 #ifdef DEBUG_MERGE_TYPES
809   DEBUG(dbgs() << "Derived new type: " << *ITy << "\n");
810 #endif
811   return ITy;
812 }
813
814 bool IntegerType::isPowerOf2ByteWidth() const {
815   unsigned BitWidth = getBitWidth();
816   return (BitWidth > 7) && isPowerOf2_32(BitWidth);
817 }
818
819 APInt IntegerType::getMask() const {
820   return APInt::getAllOnesValue(getBitWidth());
821 }
822
823 FunctionValType FunctionValType::get(const FunctionType *FT) {
824   // Build up a FunctionValType
825   std::vector<const Type *> ParamTypes;
826   ParamTypes.reserve(FT->getNumParams());
827   for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
828     ParamTypes.push_back(FT->getParamType(i));
829   return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
830 }
831
832 FunctionType *FunctionType::get(const Type *Result, bool isVarArg) {
833   return get(Result, ArrayRef<const Type *>(), isVarArg);
834 }
835
836 // FunctionType::get - The factory function for the FunctionType class...
837 FunctionType *FunctionType::get(const Type *ReturnType,
838                                 ArrayRef<const Type*> Params,
839                                 bool isVarArg) {
840   FunctionValType VT(ReturnType, Params, isVarArg);
841   FunctionType *FT = 0;
842   
843   LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
844   
845   FT = pImpl->FunctionTypes.get(VT);
846   
847   if (!FT) {
848     FT = (FunctionType*) operator new(sizeof(FunctionType) +
849                                     sizeof(PATypeHandle)*(Params.size()+1));
850     new (FT) FunctionType(ReturnType, Params, isVarArg);
851     pImpl->FunctionTypes.add(VT, FT);
852   }
853
854 #ifdef DEBUG_MERGE_TYPES
855   DEBUG(dbgs() << "Derived new type: " << FT << "\n");
856 #endif
857   return FT;
858 }
859
860 ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
861   assert(ElementType && "Can't get array of <null> types!");
862   assert(isValidElementType(ElementType) && "Invalid type for array element!");
863
864   ArrayValType AVT(ElementType, NumElements);
865   ArrayType *AT = 0;
866
867   LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
868   
869   AT = pImpl->ArrayTypes.get(AVT);
870       
871   if (!AT) {
872     // Value not found.  Derive a new type!
873     pImpl->ArrayTypes.add(AVT, AT = new ArrayType(ElementType, NumElements));
874   }
875 #ifdef DEBUG_MERGE_TYPES
876   DEBUG(dbgs() << "Derived new type: " << *AT << "\n");
877 #endif
878   return AT;
879 }
880
881 bool ArrayType::isValidElementType(const Type *ElemTy) {
882   return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
883          !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
884 }
885
886 VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
887   assert(ElementType && "Can't get vector of <null> types!");
888
889   VectorValType PVT(ElementType, NumElements);
890   VectorType *PT = 0;
891   
892   LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
893   
894   PT = pImpl->VectorTypes.get(PVT);
895     
896   if (!PT) {
897     pImpl->VectorTypes.add(PVT, PT = new VectorType(ElementType, NumElements));
898   }
899 #ifdef DEBUG_MERGE_TYPES
900   DEBUG(dbgs() << "Derived new type: " << *PT << "\n");
901 #endif
902   return PT;
903 }
904
905 bool VectorType::isValidElementType(const Type *ElemTy) {
906   return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
907          ElemTy->isOpaqueTy();
908 }
909
910 //===----------------------------------------------------------------------===//
911 // Struct Type Factory.
912 //
913
914 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
915   return get(Context, llvm::ArrayRef<const Type*>(), isPacked);
916 }
917
918
919 StructType *StructType::get(LLVMContext &Context,
920                             ArrayRef<const Type*> ETypes, 
921                             bool isPacked) {
922   StructValType STV(ETypes, isPacked);
923   StructType *ST = 0;
924   
925   LLVMContextImpl *pImpl = Context.pImpl;
926   
927   ST = pImpl->StructTypes.get(STV);
928     
929   if (!ST) {
930     // Value not found.  Derive a new type!
931     ST = (StructType*) operator new(sizeof(StructType) +
932                                     sizeof(PATypeHandle) * ETypes.size());
933     new (ST) StructType(Context, ETypes, isPacked);
934     pImpl->StructTypes.add(STV, ST);
935   }
936 #ifdef DEBUG_MERGE_TYPES
937   DEBUG(dbgs() << "Derived new type: " << *ST << "\n");
938 #endif
939   return ST;
940 }
941
942 StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
943   va_list ap;
944   std::vector<const llvm::Type*> StructFields;
945   va_start(ap, type);
946   while (type) {
947     StructFields.push_back(type);
948     type = va_arg(ap, llvm::Type*);
949   }
950   return llvm::StructType::get(Context, StructFields);
951 }
952
953 bool StructType::isValidElementType(const Type *ElemTy) {
954   return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
955          !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
956 }
957
958
959 //===----------------------------------------------------------------------===//
960 // Pointer Type Factory...
961 //
962
963 PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
964   assert(ValueType && "Can't get a pointer to <null> type!");
965   assert(ValueType->getTypeID() != VoidTyID &&
966          "Pointer to void is not valid, use i8* instead!");
967   assert(isValidElementType(ValueType) && "Invalid type for pointer element!");
968   PointerValType PVT(ValueType, AddressSpace);
969
970   PointerType *PT = 0;
971   
972   LLVMContextImpl *pImpl = ValueType->getContext().pImpl;
973   
974   PT = pImpl->PointerTypes.get(PVT);
975   
976   if (!PT) {
977     // Value not found.  Derive a new type!
978     pImpl->PointerTypes.add(PVT, PT = new PointerType(ValueType, AddressSpace));
979   }
980 #ifdef DEBUG_MERGE_TYPES
981   DEBUG(dbgs() << "Derived new type: " << *PT << "\n");
982 #endif
983   return PT;
984 }
985
986 const PointerType *Type::getPointerTo(unsigned addrs) const {
987   return PointerType::get(this, addrs);
988 }
989
990 bool PointerType::isValidElementType(const Type *ElemTy) {
991   return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
992          !ElemTy->isMetadataTy();
993 }
994
995
996 //===----------------------------------------------------------------------===//
997 // Opaque Type Factory...
998 //
999
1000 OpaqueType *OpaqueType::get(LLVMContext &C) {
1001   OpaqueType *OT = new OpaqueType(C);       // All opaque types are distinct.
1002   LLVMContextImpl *pImpl = C.pImpl;
1003   pImpl->OpaqueTypes.insert(OT);
1004   return OT;
1005 }
1006
1007
1008
1009 //===----------------------------------------------------------------------===//
1010 //                     Derived Type Refinement Functions
1011 //===----------------------------------------------------------------------===//
1012
1013 // addAbstractTypeUser - Notify an abstract type that there is a new user of
1014 // it.  This function is called primarily by the PATypeHandle class.
1015 void Type::addAbstractTypeUser(AbstractTypeUser *U) const {
1016   assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
1017   AbstractTypeUsers.push_back(U);
1018 }
1019
1020
1021 // removeAbstractTypeUser - Notify an abstract type that a user of the class
1022 // no longer has a handle to the type.  This function is called primarily by
1023 // the PATypeHandle class.  When there are no users of the abstract type, it
1024 // is annihilated, because there is no way to get a reference to it ever again.
1025 //
1026 void Type::removeAbstractTypeUser(AbstractTypeUser *U) const {
1027   
1028   // Search from back to front because we will notify users from back to
1029   // front.  Also, it is likely that there will be a stack like behavior to
1030   // users that register and unregister users.
1031   //
1032   unsigned i;
1033   for (i = AbstractTypeUsers.size(); AbstractTypeUsers[i-1] != U; --i)
1034     assert(i != 0 && "AbstractTypeUser not in user list!");
1035
1036   --i;  // Convert to be in range 0 <= i < size()
1037   assert(i < AbstractTypeUsers.size() && "Index out of range!");  // Wraparound?
1038
1039   AbstractTypeUsers.erase(AbstractTypeUsers.begin()+i);
1040
1041 #ifdef DEBUG_MERGE_TYPES
1042   DEBUG(dbgs() << "  remAbstractTypeUser[" << (void*)this << ", "
1043                << *this << "][" << i << "] User = " << U << "\n");
1044 #endif
1045
1046   if (AbstractTypeUsers.empty() && getRefCount() == 0 && isAbstract()) {
1047 #ifdef DEBUG_MERGE_TYPES
1048     DEBUG(dbgs() << "DELETEing unused abstract type: <" << *this
1049                  << ">[" << (void*)this << "]" << "\n");
1050 #endif
1051   
1052     this->destroy();
1053   }
1054 }
1055
1056 // refineAbstractTypeTo - This function is used when it is discovered
1057 // that the 'this' abstract type is actually equivalent to the NewType
1058 // specified. This causes all users of 'this' to switch to reference the more 
1059 // concrete type NewType and for 'this' to be deleted.  Only used for internal
1060 // callers.
1061 //
1062 void DerivedType::refineAbstractTypeTo(const Type *NewType) {
1063   assert(isAbstract() && "refineAbstractTypeTo: Current type is not abstract!");
1064   assert(this != NewType && "Can't refine to myself!");
1065   assert(ForwardType == 0 && "This type has already been refined!");
1066
1067 #ifdef DEBUG_MERGE_TYPES
1068   DEBUG(dbgs() << "REFINING abstract type [" << (void*)this << " "
1069                << *this << "] to [" << (void*)NewType << " "
1070                << *NewType << "]!\n");
1071 #endif
1072
1073   // Make sure to put the type to be refined to into a holder so that if IT gets
1074   // refined, that we will not continue using a dead reference...
1075   //
1076   PATypeHolder NewTy(NewType);
1077   // Any PATypeHolders referring to this type will now automatically forward to
1078   // the type we are resolved to.
1079   ForwardType = NewType;
1080   if (ForwardType->isAbstract())
1081     ForwardType->addRef();
1082
1083   // Add a self use of the current type so that we don't delete ourself until
1084   // after the function exits.
1085   //
1086   PATypeHolder CurrentTy(this);
1087
1088   // To make the situation simpler, we ask the subclass to remove this type from
1089   // the type map, and to replace any type uses with uses of non-abstract types.
1090   // This dramatically limits the amount of recursive type trouble we can find
1091   // ourselves in.
1092   dropAllTypeUses();
1093
1094   // Iterate over all of the uses of this type, invoking callback.  Each user
1095   // should remove itself from our use list automatically.  We have to check to
1096   // make sure that NewTy doesn't _become_ 'this'.  If it does, resolving types
1097   // will not cause users to drop off of the use list.  If we resolve to ourself
1098   // we succeed!
1099   //
1100   while (!AbstractTypeUsers.empty() && NewTy != this) {
1101     AbstractTypeUser *User = AbstractTypeUsers.back();
1102
1103     unsigned OldSize = AbstractTypeUsers.size(); (void)OldSize;
1104 #ifdef DEBUG_MERGE_TYPES
1105     DEBUG(dbgs() << " REFINING user " << OldSize-1 << "[" << (void*)User
1106                  << "] of abstract type [" << (void*)this << " "
1107                  << *this << "] to [" << (void*)NewTy.get() << " "
1108                  << *NewTy << "]!\n");
1109 #endif
1110     User->refineAbstractType(this, NewTy);
1111
1112     assert(AbstractTypeUsers.size() != OldSize &&
1113            "AbsTyUser did not remove self from user list!");
1114   }
1115
1116   // If we were successful removing all users from the type, 'this' will be
1117   // deleted when the last PATypeHolder is destroyed or updated from this type.
1118   // This may occur on exit of this function, as the CurrentTy object is
1119   // destroyed.
1120 }
1121
1122 // notifyUsesThatTypeBecameConcrete - Notify AbstractTypeUsers of this type that
1123 // the current type has transitioned from being abstract to being concrete.
1124 //
1125 void DerivedType::notifyUsesThatTypeBecameConcrete() {
1126 #ifdef DEBUG_MERGE_TYPES
1127   DEBUG(dbgs() << "typeIsREFINED type: " << (void*)this << " " << *this <<"\n");
1128 #endif
1129
1130   unsigned OldSize = AbstractTypeUsers.size(); (void)OldSize;
1131   while (!AbstractTypeUsers.empty()) {
1132     AbstractTypeUser *ATU = AbstractTypeUsers.back();
1133     ATU->typeBecameConcrete(this);
1134
1135     assert(AbstractTypeUsers.size() < OldSize-- &&
1136            "AbstractTypeUser did not remove itself from the use list!");
1137   }
1138 }
1139
1140 // refineAbstractType - Called when a contained type is found to be more
1141 // concrete - this could potentially change us from an abstract type to a
1142 // concrete type.
1143 //
1144 void FunctionType::refineAbstractType(const DerivedType *OldType,
1145                                       const Type *NewType) {
1146   LLVMContextImpl *pImpl = OldType->getContext().pImpl;
1147   pImpl->FunctionTypes.RefineAbstractType(this, OldType, NewType);
1148 }
1149
1150 void FunctionType::typeBecameConcrete(const DerivedType *AbsTy) {
1151   LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
1152   pImpl->FunctionTypes.TypeBecameConcrete(this, AbsTy);
1153 }
1154
1155
1156 // refineAbstractType - Called when a contained type is found to be more
1157 // concrete - this could potentially change us from an abstract type to a
1158 // concrete type.
1159 //
1160 void ArrayType::refineAbstractType(const DerivedType *OldType,
1161                                    const Type *NewType) {
1162   LLVMContextImpl *pImpl = OldType->getContext().pImpl;
1163   pImpl->ArrayTypes.RefineAbstractType(this, OldType, NewType);
1164 }
1165
1166 void ArrayType::typeBecameConcrete(const DerivedType *AbsTy) {
1167   LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
1168   pImpl->ArrayTypes.TypeBecameConcrete(this, AbsTy);
1169 }
1170
1171 // refineAbstractType - Called when a contained type is found to be more
1172 // concrete - this could potentially change us from an abstract type to a
1173 // concrete type.
1174 //
1175 void VectorType::refineAbstractType(const DerivedType *OldType,
1176                                    const Type *NewType) {
1177   LLVMContextImpl *pImpl = OldType->getContext().pImpl;
1178   pImpl->VectorTypes.RefineAbstractType(this, OldType, NewType);
1179 }
1180
1181 void VectorType::typeBecameConcrete(const DerivedType *AbsTy) {
1182   LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
1183   pImpl->VectorTypes.TypeBecameConcrete(this, AbsTy);
1184 }
1185
1186 // refineAbstractType - Called when a contained type is found to be more
1187 // concrete - this could potentially change us from an abstract type to a
1188 // concrete type.
1189 //
1190 void StructType::refineAbstractType(const DerivedType *OldType,
1191                                     const Type *NewType) {
1192   LLVMContextImpl *pImpl = OldType->getContext().pImpl;
1193   pImpl->StructTypes.RefineAbstractType(this, OldType, NewType);
1194 }
1195
1196 void StructType::typeBecameConcrete(const DerivedType *AbsTy) {
1197   LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
1198   pImpl->StructTypes.TypeBecameConcrete(this, AbsTy);
1199 }
1200
1201 // refineAbstractType - Called when a contained type is found to be more
1202 // concrete - this could potentially change us from an abstract type to a
1203 // concrete type.
1204 //
1205 void PointerType::refineAbstractType(const DerivedType *OldType,
1206                                      const Type *NewType) {
1207   LLVMContextImpl *pImpl = OldType->getContext().pImpl;
1208   pImpl->PointerTypes.RefineAbstractType(this, OldType, NewType);
1209 }
1210
1211 void PointerType::typeBecameConcrete(const DerivedType *AbsTy) {
1212   LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
1213   pImpl->PointerTypes.TypeBecameConcrete(this, AbsTy);
1214 }
1215
1216 namespace llvm {
1217 raw_ostream &operator<<(raw_ostream &OS, const Type &T) {
1218   T.print(OS);
1219   return OS;
1220 }
1221 }