1 //===-- Type.cpp - Implement the Type class -------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Type class for the VMCore library.
12 //===----------------------------------------------------------------------===//
14 #include "LLVMContextImpl.h"
15 #include "llvm/Module.h"
18 #include "llvm/ADT/SmallString.h"
21 //===----------------------------------------------------------------------===//
22 // Type Class Implementation
23 //===----------------------------------------------------------------------===//
25 Type *Type::getPrimitiveType(LLVMContext &C, TypeID IDNumber) {
27 case VoidTyID : return getVoidTy(C);
28 case HalfTyID : return getHalfTy(C);
29 case FloatTyID : return getFloatTy(C);
30 case DoubleTyID : return getDoubleTy(C);
31 case X86_FP80TyID : return getX86_FP80Ty(C);
32 case FP128TyID : return getFP128Ty(C);
33 case PPC_FP128TyID : return getPPC_FP128Ty(C);
34 case LabelTyID : return getLabelTy(C);
35 case MetadataTyID : return getMetadataTy(C);
36 case X86_MMXTyID : return getX86_MMXTy(C);
42 /// getScalarType - If this is a vector type, return the element type,
43 /// otherwise return this.
44 Type *Type::getScalarType() {
45 if (VectorType *VTy = dyn_cast<VectorType>(this))
46 return VTy->getElementType();
50 /// getNumElements - If this is a vector type, return the number of elements,
51 /// otherwise return zero.
52 unsigned Type::getNumElements() {
53 if (VectorType *VTy = dyn_cast<VectorType>(this))
54 return VTy->getNumElements();
58 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
59 bool Type::isIntegerTy(unsigned Bitwidth) const {
60 return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
63 /// isIntOrIntVectorTy - Return true if this is an integer type or a vector of
66 bool Type::isIntOrIntVectorTy() const {
69 if (getTypeID() != Type::VectorTyID) return false;
71 return cast<VectorType>(this)->getElementType()->isIntegerTy();
74 /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP types.
76 bool Type::isFPOrFPVectorTy() const {
77 if (getTypeID() == Type::HalfTyID || getTypeID() == Type::FloatTyID ||
78 getTypeID() == Type::DoubleTyID ||
79 getTypeID() == Type::FP128TyID || getTypeID() == Type::X86_FP80TyID ||
80 getTypeID() == Type::PPC_FP128TyID)
82 if (getTypeID() != Type::VectorTyID) return false;
84 return cast<VectorType>(this)->getElementType()->isFloatingPointTy();
87 // canLosslesslyBitCastTo - Return true if this type can be converted to
88 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
90 bool Type::canLosslesslyBitCastTo(Type *Ty) const {
91 // Identity cast means no change so return true
95 // They are not convertible unless they are at least first class types
96 if (!this->isFirstClassType() || !Ty->isFirstClassType())
99 // Vector -> Vector conversions are always lossless if the two vector types
100 // have the same size, otherwise not. Also, 64-bit vector types can be
101 // converted to x86mmx.
102 if (const VectorType *thisPTy = dyn_cast<VectorType>(this)) {
103 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
104 return thisPTy->getBitWidth() == thatPTy->getBitWidth();
105 if (Ty->getTypeID() == Type::X86_MMXTyID &&
106 thisPTy->getBitWidth() == 64)
110 if (this->getTypeID() == Type::X86_MMXTyID)
111 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
112 if (thatPTy->getBitWidth() == 64)
115 // At this point we have only various mismatches of the first class types
116 // remaining and ptr->ptr. Just select the lossless conversions. Everything
117 // else is not lossless.
118 if (this->isPointerTy())
119 return Ty->isPointerTy();
120 return false; // Other types have no identity values
123 bool Type::isEmptyTy() const {
124 const ArrayType *ATy = dyn_cast<ArrayType>(this);
126 unsigned NumElements = ATy->getNumElements();
127 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
130 const StructType *STy = dyn_cast<StructType>(this);
132 unsigned NumElements = STy->getNumElements();
133 for (unsigned i = 0; i < NumElements; ++i)
134 if (!STy->getElementType(i)->isEmptyTy())
142 unsigned Type::getPrimitiveSizeInBits() const {
143 switch (getTypeID()) {
144 case Type::HalfTyID: return 16;
145 case Type::FloatTyID: return 32;
146 case Type::DoubleTyID: return 64;
147 case Type::X86_FP80TyID: return 80;
148 case Type::FP128TyID: return 128;
149 case Type::PPC_FP128TyID: return 128;
150 case Type::X86_MMXTyID: return 64;
151 case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
152 case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
157 /// getScalarSizeInBits - If this is a vector type, return the
158 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
159 /// getPrimitiveSizeInBits value for this type.
160 unsigned Type::getScalarSizeInBits() {
161 return getScalarType()->getPrimitiveSizeInBits();
164 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
165 /// is only valid on floating point types. If the FP type does not
166 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
167 int Type::getFPMantissaWidth() const {
168 if (const VectorType *VTy = dyn_cast<VectorType>(this))
169 return VTy->getElementType()->getFPMantissaWidth();
170 assert(isFloatingPointTy() && "Not a floating point type!");
171 if (getTypeID() == HalfTyID) return 11;
172 if (getTypeID() == FloatTyID) return 24;
173 if (getTypeID() == DoubleTyID) return 53;
174 if (getTypeID() == X86_FP80TyID) return 64;
175 if (getTypeID() == FP128TyID) return 113;
176 assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
180 /// isSizedDerivedType - Derived types like structures and arrays are sized
181 /// iff all of the members of the type are sized as well. Since asking for
182 /// their size is relatively uncommon, move this operation out of line.
183 bool Type::isSizedDerivedType() const {
184 if (this->isIntegerTy())
187 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
188 return ATy->getElementType()->isSized();
190 if (const VectorType *VTy = dyn_cast<VectorType>(this))
191 return VTy->getElementType()->isSized();
193 if (!this->isStructTy())
196 // Opaque structs have no size.
197 if (cast<StructType>(this)->isOpaque())
200 // Okay, our struct is sized if all of the elements are.
201 for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
202 if (!(*I)->isSized())
208 //===----------------------------------------------------------------------===//
209 // Primitive 'Type' data
210 //===----------------------------------------------------------------------===//
212 Type *Type::getVoidTy(LLVMContext &C) { return &C.pImpl->VoidTy; }
213 Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; }
214 Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; }
215 Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; }
216 Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; }
217 Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; }
218 Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; }
219 Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; }
220 Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; }
221 Type *Type::getX86_MMXTy(LLVMContext &C) { return &C.pImpl->X86_MMXTy; }
223 IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; }
224 IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
225 IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; }
226 IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; }
227 IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; }
229 IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
230 return IntegerType::get(C, N);
233 PointerType *Type::getHalfPtrTy(LLVMContext &C, unsigned AS) {
234 return getHalfTy(C)->getPointerTo(AS);
237 PointerType *Type::getFloatPtrTy(LLVMContext &C, unsigned AS) {
238 return getFloatTy(C)->getPointerTo(AS);
241 PointerType *Type::getDoublePtrTy(LLVMContext &C, unsigned AS) {
242 return getDoubleTy(C)->getPointerTo(AS);
245 PointerType *Type::getX86_FP80PtrTy(LLVMContext &C, unsigned AS) {
246 return getX86_FP80Ty(C)->getPointerTo(AS);
249 PointerType *Type::getFP128PtrTy(LLVMContext &C, unsigned AS) {
250 return getFP128Ty(C)->getPointerTo(AS);
253 PointerType *Type::getPPC_FP128PtrTy(LLVMContext &C, unsigned AS) {
254 return getPPC_FP128Ty(C)->getPointerTo(AS);
257 PointerType *Type::getX86_MMXPtrTy(LLVMContext &C, unsigned AS) {
258 return getX86_MMXTy(C)->getPointerTo(AS);
261 PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
262 return getIntNTy(C, N)->getPointerTo(AS);
265 PointerType *Type::getInt1PtrTy(LLVMContext &C, unsigned AS) {
266 return getInt1Ty(C)->getPointerTo(AS);
269 PointerType *Type::getInt8PtrTy(LLVMContext &C, unsigned AS) {
270 return getInt8Ty(C)->getPointerTo(AS);
273 PointerType *Type::getInt16PtrTy(LLVMContext &C, unsigned AS) {
274 return getInt16Ty(C)->getPointerTo(AS);
277 PointerType *Type::getInt32PtrTy(LLVMContext &C, unsigned AS) {
278 return getInt32Ty(C)->getPointerTo(AS);
281 PointerType *Type::getInt64PtrTy(LLVMContext &C, unsigned AS) {
282 return getInt64Ty(C)->getPointerTo(AS);
286 //===----------------------------------------------------------------------===//
287 // IntegerType Implementation
288 //===----------------------------------------------------------------------===//
290 IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
291 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
292 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
294 // Check for the built-in integer types
296 case 1: return cast<IntegerType>(Type::getInt1Ty(C));
297 case 8: return cast<IntegerType>(Type::getInt8Ty(C));
298 case 16: return cast<IntegerType>(Type::getInt16Ty(C));
299 case 32: return cast<IntegerType>(Type::getInt32Ty(C));
300 case 64: return cast<IntegerType>(Type::getInt64Ty(C));
305 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
308 Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits);
313 bool IntegerType::isPowerOf2ByteWidth() const {
314 unsigned BitWidth = getBitWidth();
315 return (BitWidth > 7) && isPowerOf2_32(BitWidth);
318 APInt IntegerType::getMask() const {
319 return APInt::getAllOnesValue(getBitWidth());
322 //===----------------------------------------------------------------------===//
323 // FunctionType Implementation
324 //===----------------------------------------------------------------------===//
326 FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
328 : Type(Result->getContext(), FunctionTyID) {
329 Type **SubTys = reinterpret_cast<Type**>(this+1);
330 assert(isValidReturnType(Result) && "invalid return type for function");
331 setSubclassData(IsVarArgs);
333 SubTys[0] = const_cast<Type*>(Result);
335 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
336 assert(isValidArgumentType(Params[i]) &&
337 "Not a valid type for function argument!");
338 SubTys[i+1] = Params[i];
341 ContainedTys = SubTys;
342 NumContainedTys = Params.size() + 1; // + 1 for result type
345 // FunctionType::get - The factory function for the FunctionType class.
346 FunctionType *FunctionType::get(Type *ReturnType,
347 ArrayRef<Type*> Params, bool isVarArg) {
348 // TODO: This is brutally slow.
349 std::vector<Type*> Key;
350 Key.reserve(Params.size()+2);
351 Key.push_back(const_cast<Type*>(ReturnType));
352 for (unsigned i = 0, e = Params.size(); i != e; ++i)
353 Key.push_back(const_cast<Type*>(Params[i]));
357 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
358 FunctionType *&FT = pImpl->FunctionTypes[Key];
361 FT = (FunctionType*) pImpl->TypeAllocator.
362 Allocate(sizeof(FunctionType) + sizeof(Type*)*(Params.size()+1),
363 AlignOf<FunctionType>::Alignment);
364 new (FT) FunctionType(ReturnType, Params, isVarArg);
371 FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
372 return get(Result, ArrayRef<Type *>(), isVarArg);
376 /// isValidReturnType - Return true if the specified type is valid as a return
378 bool FunctionType::isValidReturnType(Type *RetTy) {
379 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
380 !RetTy->isMetadataTy();
383 /// isValidArgumentType - Return true if the specified type is valid as an
385 bool FunctionType::isValidArgumentType(Type *ArgTy) {
386 return ArgTy->isFirstClassType();
389 //===----------------------------------------------------------------------===//
390 // StructType Implementation
391 //===----------------------------------------------------------------------===//
393 // Primitive Constructors.
395 StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
397 // FIXME: std::vector is horribly inefficient for this probe.
398 std::vector<Type*> Key;
399 for (unsigned i = 0, e = ETypes.size(); i != e; ++i) {
400 assert(isValidElementType(ETypes[i]) &&
401 "Invalid type for structure element!");
402 Key.push_back(ETypes[i]);
407 StructType *&ST = Context.pImpl->AnonStructTypes[Key];
410 // Value not found. Create a new type!
411 ST = new (Context.pImpl->TypeAllocator) StructType(Context);
412 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
413 ST->setBody(ETypes, isPacked);
417 void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
418 assert(isOpaque() && "Struct body already set!");
420 setSubclassData(getSubclassData() | SCDB_HasBody);
422 setSubclassData(getSubclassData() | SCDB_Packed);
424 Type **Elts = getContext().pImpl->
425 TypeAllocator.Allocate<Type*>(Elements.size());
426 memcpy(Elts, Elements.data(), sizeof(Elements[0])*Elements.size());
429 NumContainedTys = Elements.size();
432 void StructType::setName(StringRef Name) {
433 if (Name == getName()) return;
435 // If this struct already had a name, remove its symbol table entry.
436 if (SymbolTableEntry) {
437 getContext().pImpl->NamedStructTypes.erase(getName());
438 SymbolTableEntry = 0;
441 // If this is just removing the name, we're done.
445 // Look up the entry for the name.
446 StringMapEntry<StructType*> *Entry =
447 &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name);
449 // While we have a name collision, try a random rename.
450 if (Entry->getValue()) {
451 SmallString<64> TempStr(Name);
452 TempStr.push_back('.');
453 raw_svector_ostream TmpStream(TempStr);
456 TempStr.resize(Name.size()+1);
458 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
460 Entry = &getContext().pImpl->
461 NamedStructTypes.GetOrCreateValue(TmpStream.str());
462 } while (Entry->getValue());
465 // Okay, we found an entry that isn't used. It's us!
466 Entry->setValue(this);
468 SymbolTableEntry = Entry;
471 //===----------------------------------------------------------------------===//
472 // StructType Helper functions.
474 StructType *StructType::create(LLVMContext &Context, StringRef Name) {
475 StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context);
481 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
482 return get(Context, llvm::ArrayRef<Type*>(), isPacked);
485 StructType *StructType::get(Type *type, ...) {
486 assert(type != 0 && "Cannot create a struct type with no elements with this");
487 LLVMContext &Ctx = type->getContext();
489 SmallVector<llvm::Type*, 8> StructFields;
492 StructFields.push_back(type);
493 type = va_arg(ap, llvm::Type*);
495 return llvm::StructType::get(Ctx, StructFields);
498 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements,
499 StringRef Name, bool isPacked) {
500 StructType *ST = create(Context, Name);
501 ST->setBody(Elements, isPacked);
505 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements) {
506 return create(Context, Elements, StringRef());
509 StructType *StructType::create(LLVMContext &Context) {
510 return create(Context, StringRef());
514 StructType *StructType::create(ArrayRef<Type*> Elements, StringRef Name,
516 assert(!Elements.empty() &&
517 "This method may not be invoked with an empty list");
518 return create(Elements[0]->getContext(), Elements, Name, isPacked);
521 StructType *StructType::create(ArrayRef<Type*> Elements) {
522 assert(!Elements.empty() &&
523 "This method may not be invoked with an empty list");
524 return create(Elements[0]->getContext(), Elements, StringRef());
527 StructType *StructType::create(StringRef Name, Type *type, ...) {
528 assert(type != 0 && "Cannot create a struct type with no elements with this");
529 LLVMContext &Ctx = type->getContext();
531 SmallVector<llvm::Type*, 8> StructFields;
534 StructFields.push_back(type);
535 type = va_arg(ap, llvm::Type*);
537 return llvm::StructType::create(Ctx, StructFields, Name);
541 StringRef StructType::getName() const {
542 assert(!isLiteral() && "Literal structs never have names");
543 if (SymbolTableEntry == 0) return StringRef();
545 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
548 void StructType::setBody(Type *type, ...) {
549 assert(type != 0 && "Cannot create a struct type with no elements with this");
551 SmallVector<llvm::Type*, 8> StructFields;
554 StructFields.push_back(type);
555 type = va_arg(ap, llvm::Type*);
557 setBody(StructFields);
560 bool StructType::isValidElementType(Type *ElemTy) {
561 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
562 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
565 /// isLayoutIdentical - Return true if this is layout identical to the
566 /// specified struct.
567 bool StructType::isLayoutIdentical(StructType *Other) const {
568 if (this == Other) return true;
570 if (isPacked() != Other->isPacked() ||
571 getNumElements() != Other->getNumElements())
574 return std::equal(element_begin(), element_end(), Other->element_begin());
578 /// getTypeByName - Return the type with the specified name, or null if there
579 /// is none by that name.
580 StructType *Module::getTypeByName(StringRef Name) const {
581 StringMap<StructType*>::iterator I =
582 getContext().pImpl->NamedStructTypes.find(Name);
583 if (I != getContext().pImpl->NamedStructTypes.end())
589 //===----------------------------------------------------------------------===//
590 // CompositeType Implementation
591 //===----------------------------------------------------------------------===//
593 Type *CompositeType::getTypeAtIndex(const Value *V) {
594 if (StructType *STy = dyn_cast<StructType>(this)) {
595 unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
596 assert(indexValid(Idx) && "Invalid structure index!");
597 return STy->getElementType(Idx);
600 return cast<SequentialType>(this)->getElementType();
602 Type *CompositeType::getTypeAtIndex(unsigned Idx) {
603 if (StructType *STy = dyn_cast<StructType>(this)) {
604 assert(indexValid(Idx) && "Invalid structure index!");
605 return STy->getElementType(Idx);
608 return cast<SequentialType>(this)->getElementType();
610 bool CompositeType::indexValid(const Value *V) const {
611 if (const StructType *STy = dyn_cast<StructType>(this)) {
612 // Structure indexes require 32-bit integer constants.
613 if (V->getType()->isIntegerTy(32))
614 if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
615 return CU->getZExtValue() < STy->getNumElements();
619 // Sequential types can be indexed by any integer.
620 return V->getType()->isIntegerTy();
623 bool CompositeType::indexValid(unsigned Idx) const {
624 if (const StructType *STy = dyn_cast<StructType>(this))
625 return Idx < STy->getNumElements();
626 // Sequential types can be indexed by any integer.
631 //===----------------------------------------------------------------------===//
632 // ArrayType Implementation
633 //===----------------------------------------------------------------------===//
635 ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
636 : SequentialType(ArrayTyID, ElType) {
641 ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) {
642 Type *ElementType = const_cast<Type*>(elementType);
643 assert(isValidElementType(ElementType) && "Invalid type for array element!");
645 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
647 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
650 Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements);
654 bool ArrayType::isValidElementType(Type *ElemTy) {
655 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
656 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
659 //===----------------------------------------------------------------------===//
660 // VectorType Implementation
661 //===----------------------------------------------------------------------===//
663 VectorType::VectorType(Type *ElType, unsigned NumEl)
664 : SequentialType(VectorTyID, ElType) {
668 VectorType *VectorType::get(Type *elementType, unsigned NumElements) {
669 Type *ElementType = const_cast<Type*>(elementType);
670 assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
671 assert(isValidElementType(ElementType) &&
672 "Elements of a VectorType must be a primitive type");
674 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
675 VectorType *&Entry = ElementType->getContext().pImpl
676 ->VectorTypes[std::make_pair(ElementType, NumElements)];
679 Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements);
683 bool VectorType::isValidElementType(Type *ElemTy) {
684 if (PointerType *PTy = dyn_cast<PointerType>(ElemTy))
685 ElemTy = PTy->getElementType();
686 return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy();
689 //===----------------------------------------------------------------------===//
690 // PointerType Implementation
691 //===----------------------------------------------------------------------===//
693 PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
694 assert(EltTy && "Can't get a pointer to <null> type!");
695 assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
697 LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
699 // Since AddressSpace #0 is the common case, we special case it.
700 PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
701 : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
704 Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace);
709 PointerType::PointerType(Type *E, unsigned AddrSpace)
710 : SequentialType(PointerTyID, E) {
712 const unsigned oldNCT = NumContainedTys;
714 setSubclassData(AddrSpace);
715 // Check for miscompile. PR11652.
716 assert(oldNCT == NumContainedTys && "bitfield written out of bounds?");
719 PointerType *Type::getPointerTo(unsigned addrs) {
720 return PointerType::get(this, addrs);
723 bool PointerType::isValidElementType(Type *ElemTy) {
724 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
725 !ElemTy->isMetadataTy();