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 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
51 bool Type::isIntegerTy(unsigned Bitwidth) const {
52 return isIntegerTy() && cast<IntegerType>(this)->getBitWidth() == Bitwidth;
55 /// isIntOrIntVectorTy - Return true if this is an integer type or a vector of
58 bool Type::isIntOrIntVectorTy() const {
61 if (getTypeID() != Type::VectorTyID) return false;
63 return cast<VectorType>(this)->getElementType()->isIntegerTy();
66 /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP types.
68 bool Type::isFPOrFPVectorTy() const {
69 if (getTypeID() == Type::HalfTyID || getTypeID() == Type::FloatTyID ||
70 getTypeID() == Type::DoubleTyID ||
71 getTypeID() == Type::FP128TyID || getTypeID() == Type::X86_FP80TyID ||
72 getTypeID() == Type::PPC_FP128TyID)
74 if (getTypeID() != Type::VectorTyID) return false;
76 return cast<VectorType>(this)->getElementType()->isFloatingPointTy();
79 // canLosslesslyBitCastTo - Return true if this type can be converted to
80 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
82 bool Type::canLosslesslyBitCastTo(Type *Ty) const {
83 // Identity cast means no change so return true
87 // They are not convertible unless they are at least first class types
88 if (!this->isFirstClassType() || !Ty->isFirstClassType())
91 // Vector -> Vector conversions are always lossless if the two vector types
92 // have the same size, otherwise not. Also, 64-bit vector types can be
93 // converted to x86mmx.
94 if (const VectorType *thisPTy = dyn_cast<VectorType>(this)) {
95 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
96 return thisPTy->getBitWidth() == thatPTy->getBitWidth();
97 if (Ty->getTypeID() == Type::X86_MMXTyID &&
98 thisPTy->getBitWidth() == 64)
102 if (this->getTypeID() == Type::X86_MMXTyID)
103 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
104 if (thatPTy->getBitWidth() == 64)
107 // At this point we have only various mismatches of the first class types
108 // remaining and ptr->ptr. Just select the lossless conversions. Everything
109 // else is not lossless.
110 if (this->isPointerTy())
111 return Ty->isPointerTy();
112 return false; // Other types have no identity values
115 bool Type::isEmptyTy() const {
116 const ArrayType *ATy = dyn_cast<ArrayType>(this);
118 unsigned NumElements = ATy->getNumElements();
119 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
122 const StructType *STy = dyn_cast<StructType>(this);
124 unsigned NumElements = STy->getNumElements();
125 for (unsigned i = 0; i < NumElements; ++i)
126 if (!STy->getElementType(i)->isEmptyTy())
134 unsigned Type::getPrimitiveSizeInBits() const {
135 switch (getTypeID()) {
136 case Type::HalfTyID: return 16;
137 case Type::FloatTyID: return 32;
138 case Type::DoubleTyID: return 64;
139 case Type::X86_FP80TyID: return 80;
140 case Type::FP128TyID: return 128;
141 case Type::PPC_FP128TyID: return 128;
142 case Type::X86_MMXTyID: return 64;
143 case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
144 case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
149 /// getScalarSizeInBits - If this is a vector type, return the
150 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
151 /// getPrimitiveSizeInBits value for this type.
152 unsigned Type::getScalarSizeInBits() {
153 return getScalarType()->getPrimitiveSizeInBits();
156 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
157 /// is only valid on floating point types. If the FP type does not
158 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
159 int Type::getFPMantissaWidth() const {
160 if (const VectorType *VTy = dyn_cast<VectorType>(this))
161 return VTy->getElementType()->getFPMantissaWidth();
162 assert(isFloatingPointTy() && "Not a floating point type!");
163 if (getTypeID() == HalfTyID) return 11;
164 if (getTypeID() == FloatTyID) return 24;
165 if (getTypeID() == DoubleTyID) return 53;
166 if (getTypeID() == X86_FP80TyID) return 64;
167 if (getTypeID() == FP128TyID) return 113;
168 assert(getTypeID() == PPC_FP128TyID && "unknown fp type");
172 /// isSizedDerivedType - Derived types like structures and arrays are sized
173 /// iff all of the members of the type are sized as well. Since asking for
174 /// their size is relatively uncommon, move this operation out of line.
175 bool Type::isSizedDerivedType() const {
176 if (this->isIntegerTy())
179 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
180 return ATy->getElementType()->isSized();
182 if (const VectorType *VTy = dyn_cast<VectorType>(this))
183 return VTy->getElementType()->isSized();
185 if (!this->isStructTy())
188 // Opaque structs have no size.
189 if (cast<StructType>(this)->isOpaque())
192 // Okay, our struct is sized if all of the elements are.
193 for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
194 if (!(*I)->isSized())
200 //===----------------------------------------------------------------------===//
201 // Primitive 'Type' data
202 //===----------------------------------------------------------------------===//
204 Type *Type::getVoidTy(LLVMContext &C) { return &C.pImpl->VoidTy; }
205 Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; }
206 Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; }
207 Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; }
208 Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; }
209 Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; }
210 Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; }
211 Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; }
212 Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; }
213 Type *Type::getX86_MMXTy(LLVMContext &C) { return &C.pImpl->X86_MMXTy; }
215 IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; }
216 IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
217 IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; }
218 IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; }
219 IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; }
221 IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
222 return IntegerType::get(C, N);
225 PointerType *Type::getHalfPtrTy(LLVMContext &C, unsigned AS) {
226 return getHalfTy(C)->getPointerTo(AS);
229 PointerType *Type::getFloatPtrTy(LLVMContext &C, unsigned AS) {
230 return getFloatTy(C)->getPointerTo(AS);
233 PointerType *Type::getDoublePtrTy(LLVMContext &C, unsigned AS) {
234 return getDoubleTy(C)->getPointerTo(AS);
237 PointerType *Type::getX86_FP80PtrTy(LLVMContext &C, unsigned AS) {
238 return getX86_FP80Ty(C)->getPointerTo(AS);
241 PointerType *Type::getFP128PtrTy(LLVMContext &C, unsigned AS) {
242 return getFP128Ty(C)->getPointerTo(AS);
245 PointerType *Type::getPPC_FP128PtrTy(LLVMContext &C, unsigned AS) {
246 return getPPC_FP128Ty(C)->getPointerTo(AS);
249 PointerType *Type::getX86_MMXPtrTy(LLVMContext &C, unsigned AS) {
250 return getX86_MMXTy(C)->getPointerTo(AS);
253 PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
254 return getIntNTy(C, N)->getPointerTo(AS);
257 PointerType *Type::getInt1PtrTy(LLVMContext &C, unsigned AS) {
258 return getInt1Ty(C)->getPointerTo(AS);
261 PointerType *Type::getInt8PtrTy(LLVMContext &C, unsigned AS) {
262 return getInt8Ty(C)->getPointerTo(AS);
265 PointerType *Type::getInt16PtrTy(LLVMContext &C, unsigned AS) {
266 return getInt16Ty(C)->getPointerTo(AS);
269 PointerType *Type::getInt32PtrTy(LLVMContext &C, unsigned AS) {
270 return getInt32Ty(C)->getPointerTo(AS);
273 PointerType *Type::getInt64PtrTy(LLVMContext &C, unsigned AS) {
274 return getInt64Ty(C)->getPointerTo(AS);
278 //===----------------------------------------------------------------------===//
279 // IntegerType Implementation
280 //===----------------------------------------------------------------------===//
282 IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
283 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
284 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
286 // Check for the built-in integer types
288 case 1: return cast<IntegerType>(Type::getInt1Ty(C));
289 case 8: return cast<IntegerType>(Type::getInt8Ty(C));
290 case 16: return cast<IntegerType>(Type::getInt16Ty(C));
291 case 32: return cast<IntegerType>(Type::getInt32Ty(C));
292 case 64: return cast<IntegerType>(Type::getInt64Ty(C));
297 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
300 Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits);
305 bool IntegerType::isPowerOf2ByteWidth() const {
306 unsigned BitWidth = getBitWidth();
307 return (BitWidth > 7) && isPowerOf2_32(BitWidth);
310 APInt IntegerType::getMask() const {
311 return APInt::getAllOnesValue(getBitWidth());
314 //===----------------------------------------------------------------------===//
315 // FunctionType Implementation
316 //===----------------------------------------------------------------------===//
318 FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
320 : Type(Result->getContext(), FunctionTyID) {
321 Type **SubTys = reinterpret_cast<Type**>(this+1);
322 assert(isValidReturnType(Result) && "invalid return type for function");
323 setSubclassData(IsVarArgs);
325 SubTys[0] = const_cast<Type*>(Result);
327 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
328 assert(isValidArgumentType(Params[i]) &&
329 "Not a valid type for function argument!");
330 SubTys[i+1] = Params[i];
333 ContainedTys = SubTys;
334 NumContainedTys = Params.size() + 1; // + 1 for result type
337 // FunctionType::get - The factory function for the FunctionType class.
338 FunctionType *FunctionType::get(Type *ReturnType,
339 ArrayRef<Type*> Params, bool isVarArg) {
340 // TODO: This is brutally slow.
341 std::vector<Type*> Key;
342 Key.reserve(Params.size()+2);
343 Key.push_back(const_cast<Type*>(ReturnType));
344 for (unsigned i = 0, e = Params.size(); i != e; ++i)
345 Key.push_back(const_cast<Type*>(Params[i]));
349 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
350 FunctionType *&FT = pImpl->FunctionTypes[Key];
353 FT = (FunctionType*) pImpl->TypeAllocator.
354 Allocate(sizeof(FunctionType) + sizeof(Type*)*(Params.size()+1),
355 AlignOf<FunctionType>::Alignment);
356 new (FT) FunctionType(ReturnType, Params, isVarArg);
363 FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
364 return get(Result, ArrayRef<Type *>(), isVarArg);
368 /// isValidReturnType - Return true if the specified type is valid as a return
370 bool FunctionType::isValidReturnType(Type *RetTy) {
371 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
372 !RetTy->isMetadataTy();
375 /// isValidArgumentType - Return true if the specified type is valid as an
377 bool FunctionType::isValidArgumentType(Type *ArgTy) {
378 return ArgTy->isFirstClassType();
381 //===----------------------------------------------------------------------===//
382 // StructType Implementation
383 //===----------------------------------------------------------------------===//
385 // Primitive Constructors.
387 StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
389 // FIXME: std::vector is horribly inefficient for this probe.
390 std::vector<Type*> Key;
391 for (unsigned i = 0, e = ETypes.size(); i != e; ++i) {
392 assert(isValidElementType(ETypes[i]) &&
393 "Invalid type for structure element!");
394 Key.push_back(ETypes[i]);
399 StructType *&ST = Context.pImpl->AnonStructTypes[Key];
402 // Value not found. Create a new type!
403 ST = new (Context.pImpl->TypeAllocator) StructType(Context);
404 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
405 ST->setBody(ETypes, isPacked);
409 void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
410 assert(isOpaque() && "Struct body already set!");
412 setSubclassData(getSubclassData() | SCDB_HasBody);
414 setSubclassData(getSubclassData() | SCDB_Packed);
416 Type **Elts = getContext().pImpl->
417 TypeAllocator.Allocate<Type*>(Elements.size());
418 memcpy(Elts, Elements.data(), sizeof(Elements[0])*Elements.size());
421 NumContainedTys = Elements.size();
424 void StructType::setName(StringRef Name) {
425 if (Name == getName()) return;
427 // If this struct already had a name, remove its symbol table entry.
428 if (SymbolTableEntry) {
429 getContext().pImpl->NamedStructTypes.erase(getName());
430 SymbolTableEntry = 0;
433 // If this is just removing the name, we're done.
437 // Look up the entry for the name.
438 StringMapEntry<StructType*> *Entry =
439 &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name);
441 // While we have a name collision, try a random rename.
442 if (Entry->getValue()) {
443 SmallString<64> TempStr(Name);
444 TempStr.push_back('.');
445 raw_svector_ostream TmpStream(TempStr);
448 TempStr.resize(Name.size()+1);
450 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
452 Entry = &getContext().pImpl->
453 NamedStructTypes.GetOrCreateValue(TmpStream.str());
454 } while (Entry->getValue());
457 // Okay, we found an entry that isn't used. It's us!
458 Entry->setValue(this);
460 SymbolTableEntry = Entry;
463 //===----------------------------------------------------------------------===//
464 // StructType Helper functions.
466 StructType *StructType::create(LLVMContext &Context, StringRef Name) {
467 StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context);
473 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
474 return get(Context, llvm::ArrayRef<Type*>(), isPacked);
477 StructType *StructType::get(Type *type, ...) {
478 assert(type != 0 && "Cannot create a struct type with no elements with this");
479 LLVMContext &Ctx = type->getContext();
481 SmallVector<llvm::Type*, 8> StructFields;
484 StructFields.push_back(type);
485 type = va_arg(ap, llvm::Type*);
487 return llvm::StructType::get(Ctx, StructFields);
490 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements,
491 StringRef Name, bool isPacked) {
492 StructType *ST = create(Context, Name);
493 ST->setBody(Elements, isPacked);
497 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements) {
498 return create(Context, Elements, StringRef());
501 StructType *StructType::create(LLVMContext &Context) {
502 return create(Context, StringRef());
506 StructType *StructType::create(ArrayRef<Type*> Elements, StringRef Name,
508 assert(!Elements.empty() &&
509 "This method may not be invoked with an empty list");
510 return create(Elements[0]->getContext(), Elements, Name, isPacked);
513 StructType *StructType::create(ArrayRef<Type*> Elements) {
514 assert(!Elements.empty() &&
515 "This method may not be invoked with an empty list");
516 return create(Elements[0]->getContext(), Elements, StringRef());
519 StructType *StructType::create(StringRef Name, Type *type, ...) {
520 assert(type != 0 && "Cannot create a struct type with no elements with this");
521 LLVMContext &Ctx = type->getContext();
523 SmallVector<llvm::Type*, 8> StructFields;
526 StructFields.push_back(type);
527 type = va_arg(ap, llvm::Type*);
529 return llvm::StructType::create(Ctx, StructFields, Name);
533 StringRef StructType::getName() const {
534 assert(!isLiteral() && "Literal structs never have names");
535 if (SymbolTableEntry == 0) return StringRef();
537 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
540 void StructType::setBody(Type *type, ...) {
541 assert(type != 0 && "Cannot create a struct type with no elements with this");
543 SmallVector<llvm::Type*, 8> StructFields;
546 StructFields.push_back(type);
547 type = va_arg(ap, llvm::Type*);
549 setBody(StructFields);
552 bool StructType::isValidElementType(Type *ElemTy) {
553 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
554 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
557 /// isLayoutIdentical - Return true if this is layout identical to the
558 /// specified struct.
559 bool StructType::isLayoutIdentical(StructType *Other) const {
560 if (this == Other) return true;
562 if (isPacked() != Other->isPacked() ||
563 getNumElements() != Other->getNumElements())
566 return std::equal(element_begin(), element_end(), Other->element_begin());
570 /// getTypeByName - Return the type with the specified name, or null if there
571 /// is none by that name.
572 StructType *Module::getTypeByName(StringRef Name) const {
573 StringMap<StructType*>::iterator I =
574 getContext().pImpl->NamedStructTypes.find(Name);
575 if (I != getContext().pImpl->NamedStructTypes.end())
581 //===----------------------------------------------------------------------===//
582 // CompositeType Implementation
583 //===----------------------------------------------------------------------===//
585 Type *CompositeType::getTypeAtIndex(const Value *V) {
586 if (StructType *STy = dyn_cast<StructType>(this)) {
587 unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
588 assert(indexValid(Idx) && "Invalid structure index!");
589 return STy->getElementType(Idx);
592 return cast<SequentialType>(this)->getElementType();
594 Type *CompositeType::getTypeAtIndex(unsigned Idx) {
595 if (StructType *STy = dyn_cast<StructType>(this)) {
596 assert(indexValid(Idx) && "Invalid structure index!");
597 return STy->getElementType(Idx);
600 return cast<SequentialType>(this)->getElementType();
602 bool CompositeType::indexValid(const Value *V) const {
603 if (const StructType *STy = dyn_cast<StructType>(this)) {
604 // Structure indexes require 32-bit integer constants.
605 if (V->getType()->isIntegerTy(32))
606 if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
607 return CU->getZExtValue() < STy->getNumElements();
611 // Sequential types can be indexed by any integer.
612 return V->getType()->isIntegerTy();
615 bool CompositeType::indexValid(unsigned Idx) const {
616 if (const StructType *STy = dyn_cast<StructType>(this))
617 return Idx < STy->getNumElements();
618 // Sequential types can be indexed by any integer.
623 //===----------------------------------------------------------------------===//
624 // ArrayType Implementation
625 //===----------------------------------------------------------------------===//
627 ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
628 : SequentialType(ArrayTyID, ElType) {
633 ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) {
634 Type *ElementType = const_cast<Type*>(elementType);
635 assert(isValidElementType(ElementType) && "Invalid type for array element!");
637 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
639 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
642 Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements);
646 bool ArrayType::isValidElementType(Type *ElemTy) {
647 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
648 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
651 //===----------------------------------------------------------------------===//
652 // VectorType Implementation
653 //===----------------------------------------------------------------------===//
655 VectorType::VectorType(Type *ElType, unsigned NumEl)
656 : SequentialType(VectorTyID, ElType) {
660 VectorType *VectorType::get(Type *elementType, unsigned NumElements) {
661 Type *ElementType = const_cast<Type*>(elementType);
662 assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
663 assert(isValidElementType(ElementType) &&
664 "Elements of a VectorType must be a primitive type");
666 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
667 VectorType *&Entry = ElementType->getContext().pImpl
668 ->VectorTypes[std::make_pair(ElementType, NumElements)];
671 Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements);
675 bool VectorType::isValidElementType(Type *ElemTy) {
676 if (PointerType *PTy = dyn_cast<PointerType>(ElemTy))
677 ElemTy = PTy->getElementType();
678 return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy();
681 //===----------------------------------------------------------------------===//
682 // PointerType Implementation
683 //===----------------------------------------------------------------------===//
685 PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
686 assert(EltTy && "Can't get a pointer to <null> type!");
687 assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
689 LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
691 // Since AddressSpace #0 is the common case, we special case it.
692 PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
693 : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
696 Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace);
701 PointerType::PointerType(Type *E, unsigned AddrSpace)
702 : SequentialType(PointerTyID, E) {
704 const unsigned oldNCT = NumContainedTys;
706 setSubclassData(AddrSpace);
707 // Check for miscompile. PR11652.
708 assert(oldNCT == NumContainedTys && "bitfield written out of bounds?");
711 PointerType *Type::getPointerTo(unsigned addrs) {
712 return PointerType::get(this, addrs);
715 bool PointerType::isValidElementType(Type *ElemTy) {
716 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
717 !ElemTy->isMetadataTy();