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