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