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 (ID != 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 (ID == Type::HalfTyID || ID == Type::FloatTyID || ID == Type::DoubleTyID ||
78 ID == Type::FP128TyID || ID == Type::X86_FP80TyID ||
79 ID == Type::PPC_FP128TyID)
81 if (ID != Type::VectorTyID) return false;
83 return cast<VectorType>(this)->getElementType()->isFloatingPointTy();
86 // canLosslesslyBitCastTo - Return true if this type can be converted to
87 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
89 bool Type::canLosslesslyBitCastTo(Type *Ty) const {
90 // Identity cast means no change so return true
94 // They are not convertible unless they are at least first class types
95 if (!this->isFirstClassType() || !Ty->isFirstClassType())
98 // Vector -> Vector conversions are always lossless if the two vector types
99 // have the same size, otherwise not. Also, 64-bit vector types can be
100 // converted to x86mmx.
101 if (const VectorType *thisPTy = dyn_cast<VectorType>(this)) {
102 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
103 return thisPTy->getBitWidth() == thatPTy->getBitWidth();
104 if (Ty->getTypeID() == Type::X86_MMXTyID &&
105 thisPTy->getBitWidth() == 64)
109 if (this->getTypeID() == Type::X86_MMXTyID)
110 if (const VectorType *thatPTy = dyn_cast<VectorType>(Ty))
111 if (thatPTy->getBitWidth() == 64)
114 // At this point we have only various mismatches of the first class types
115 // remaining and ptr->ptr. Just select the lossless conversions. Everything
116 // else is not lossless.
117 if (this->isPointerTy())
118 return Ty->isPointerTy();
119 return false; // Other types have no identity values
122 bool Type::isEmptyTy() const {
123 const ArrayType *ATy = dyn_cast<ArrayType>(this);
125 unsigned NumElements = ATy->getNumElements();
126 return NumElements == 0 || ATy->getElementType()->isEmptyTy();
129 const StructType *STy = dyn_cast<StructType>(this);
131 unsigned NumElements = STy->getNumElements();
132 for (unsigned i = 0; i < NumElements; ++i)
133 if (!STy->getElementType(i)->isEmptyTy())
141 unsigned Type::getPrimitiveSizeInBits() const {
142 switch (getTypeID()) {
143 case Type::HalfTyID: return 16;
144 case Type::FloatTyID: return 32;
145 case Type::DoubleTyID: return 64;
146 case Type::X86_FP80TyID: return 80;
147 case Type::FP128TyID: return 128;
148 case Type::PPC_FP128TyID: return 128;
149 case Type::X86_MMXTyID: return 64;
150 case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
151 case Type::VectorTyID: return cast<VectorType>(this)->getBitWidth();
156 /// getScalarSizeInBits - If this is a vector type, return the
157 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
158 /// getPrimitiveSizeInBits value for this type.
159 unsigned Type::getScalarSizeInBits() {
160 return getScalarType()->getPrimitiveSizeInBits();
163 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
164 /// is only valid on floating point types. If the FP type does not
165 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
166 int Type::getFPMantissaWidth() const {
167 if (const VectorType *VTy = dyn_cast<VectorType>(this))
168 return VTy->getElementType()->getFPMantissaWidth();
169 assert(isFloatingPointTy() && "Not a floating point type!");
170 if (ID == HalfTyID) return 11;
171 if (ID == FloatTyID) return 24;
172 if (ID == DoubleTyID) return 53;
173 if (ID == X86_FP80TyID) return 64;
174 if (ID == FP128TyID) return 113;
175 assert(ID == PPC_FP128TyID && "unknown fp type");
179 /// isSizedDerivedType - Derived types like structures and arrays are sized
180 /// iff all of the members of the type are sized as well. Since asking for
181 /// their size is relatively uncommon, move this operation out of line.
182 bool Type::isSizedDerivedType() const {
183 if (this->isIntegerTy())
186 if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
187 return ATy->getElementType()->isSized();
189 if (const VectorType *VTy = dyn_cast<VectorType>(this))
190 return VTy->getElementType()->isSized();
192 if (!this->isStructTy())
195 // Opaque structs have no size.
196 if (cast<StructType>(this)->isOpaque())
199 // Okay, our struct is sized if all of the elements are.
200 for (subtype_iterator I = subtype_begin(), E = subtype_end(); I != E; ++I)
201 if (!(*I)->isSized())
207 //===----------------------------------------------------------------------===//
208 // Primitive 'Type' data
209 //===----------------------------------------------------------------------===//
211 Type *Type::getVoidTy(LLVMContext &C) { return &C.pImpl->VoidTy; }
212 Type *Type::getLabelTy(LLVMContext &C) { return &C.pImpl->LabelTy; }
213 Type *Type::getHalfTy(LLVMContext &C) { return &C.pImpl->HalfTy; }
214 Type *Type::getFloatTy(LLVMContext &C) { return &C.pImpl->FloatTy; }
215 Type *Type::getDoubleTy(LLVMContext &C) { return &C.pImpl->DoubleTy; }
216 Type *Type::getMetadataTy(LLVMContext &C) { return &C.pImpl->MetadataTy; }
217 Type *Type::getX86_FP80Ty(LLVMContext &C) { return &C.pImpl->X86_FP80Ty; }
218 Type *Type::getFP128Ty(LLVMContext &C) { return &C.pImpl->FP128Ty; }
219 Type *Type::getPPC_FP128Ty(LLVMContext &C) { return &C.pImpl->PPC_FP128Ty; }
220 Type *Type::getX86_MMXTy(LLVMContext &C) { return &C.pImpl->X86_MMXTy; }
222 IntegerType *Type::getInt1Ty(LLVMContext &C) { return &C.pImpl->Int1Ty; }
223 IntegerType *Type::getInt8Ty(LLVMContext &C) { return &C.pImpl->Int8Ty; }
224 IntegerType *Type::getInt16Ty(LLVMContext &C) { return &C.pImpl->Int16Ty; }
225 IntegerType *Type::getInt32Ty(LLVMContext &C) { return &C.pImpl->Int32Ty; }
226 IntegerType *Type::getInt64Ty(LLVMContext &C) { return &C.pImpl->Int64Ty; }
228 IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {
229 return IntegerType::get(C, N);
232 PointerType *Type::getHalfPtrTy(LLVMContext &C, unsigned AS) {
233 return getHalfTy(C)->getPointerTo(AS);
236 PointerType *Type::getFloatPtrTy(LLVMContext &C, unsigned AS) {
237 return getFloatTy(C)->getPointerTo(AS);
240 PointerType *Type::getDoublePtrTy(LLVMContext &C, unsigned AS) {
241 return getDoubleTy(C)->getPointerTo(AS);
244 PointerType *Type::getX86_FP80PtrTy(LLVMContext &C, unsigned AS) {
245 return getX86_FP80Ty(C)->getPointerTo(AS);
248 PointerType *Type::getFP128PtrTy(LLVMContext &C, unsigned AS) {
249 return getFP128Ty(C)->getPointerTo(AS);
252 PointerType *Type::getPPC_FP128PtrTy(LLVMContext &C, unsigned AS) {
253 return getPPC_FP128Ty(C)->getPointerTo(AS);
256 PointerType *Type::getX86_MMXPtrTy(LLVMContext &C, unsigned AS) {
257 return getX86_MMXTy(C)->getPointerTo(AS);
260 PointerType *Type::getIntNPtrTy(LLVMContext &C, unsigned N, unsigned AS) {
261 return getIntNTy(C, N)->getPointerTo(AS);
264 PointerType *Type::getInt1PtrTy(LLVMContext &C, unsigned AS) {
265 return getInt1Ty(C)->getPointerTo(AS);
268 PointerType *Type::getInt8PtrTy(LLVMContext &C, unsigned AS) {
269 return getInt8Ty(C)->getPointerTo(AS);
272 PointerType *Type::getInt16PtrTy(LLVMContext &C, unsigned AS) {
273 return getInt16Ty(C)->getPointerTo(AS);
276 PointerType *Type::getInt32PtrTy(LLVMContext &C, unsigned AS) {
277 return getInt32Ty(C)->getPointerTo(AS);
280 PointerType *Type::getInt64PtrTy(LLVMContext &C, unsigned AS) {
281 return getInt64Ty(C)->getPointerTo(AS);
285 //===----------------------------------------------------------------------===//
286 // IntegerType Implementation
287 //===----------------------------------------------------------------------===//
289 IntegerType *IntegerType::get(LLVMContext &C, unsigned NumBits) {
290 assert(NumBits >= MIN_INT_BITS && "bitwidth too small");
291 assert(NumBits <= MAX_INT_BITS && "bitwidth too large");
293 // Check for the built-in integer types
295 case 1: return cast<IntegerType>(Type::getInt1Ty(C));
296 case 8: return cast<IntegerType>(Type::getInt8Ty(C));
297 case 16: return cast<IntegerType>(Type::getInt16Ty(C));
298 case 32: return cast<IntegerType>(Type::getInt32Ty(C));
299 case 64: return cast<IntegerType>(Type::getInt64Ty(C));
304 IntegerType *&Entry = C.pImpl->IntegerTypes[NumBits];
307 Entry = new (C.pImpl->TypeAllocator) IntegerType(C, NumBits);
312 bool IntegerType::isPowerOf2ByteWidth() const {
313 unsigned BitWidth = getBitWidth();
314 return (BitWidth > 7) && isPowerOf2_32(BitWidth);
317 APInt IntegerType::getMask() const {
318 return APInt::getAllOnesValue(getBitWidth());
321 //===----------------------------------------------------------------------===//
322 // FunctionType Implementation
323 //===----------------------------------------------------------------------===//
325 FunctionType::FunctionType(Type *Result, ArrayRef<Type*> Params,
327 : Type(Result->getContext(), FunctionTyID) {
328 Type **SubTys = reinterpret_cast<Type**>(this+1);
329 assert(isValidReturnType(Result) && "invalid return type for function");
330 setSubclassData(IsVarArgs);
332 SubTys[0] = const_cast<Type*>(Result);
334 for (unsigned i = 0, e = Params.size(); i != e; ++i) {
335 assert(isValidArgumentType(Params[i]) &&
336 "Not a valid type for function argument!");
337 SubTys[i+1] = Params[i];
340 ContainedTys = SubTys;
341 NumContainedTys = Params.size() + 1; // + 1 for result type
344 // FunctionType::get - The factory function for the FunctionType class.
345 FunctionType *FunctionType::get(Type *ReturnType,
346 ArrayRef<Type*> Params, bool isVarArg) {
347 // TODO: This is brutally slow.
348 std::vector<Type*> Key;
349 Key.reserve(Params.size()+2);
350 Key.push_back(const_cast<Type*>(ReturnType));
351 for (unsigned i = 0, e = Params.size(); i != e; ++i)
352 Key.push_back(const_cast<Type*>(Params[i]));
356 LLVMContextImpl *pImpl = ReturnType->getContext().pImpl;
357 FunctionType *&FT = pImpl->FunctionTypes[Key];
360 FT = (FunctionType*) pImpl->TypeAllocator.
361 Allocate(sizeof(FunctionType) + sizeof(Type*)*(Params.size()+1),
362 AlignOf<FunctionType>::Alignment);
363 new (FT) FunctionType(ReturnType, Params, isVarArg);
370 FunctionType *FunctionType::get(Type *Result, bool isVarArg) {
371 return get(Result, ArrayRef<Type *>(), isVarArg);
375 /// isValidReturnType - Return true if the specified type is valid as a return
377 bool FunctionType::isValidReturnType(Type *RetTy) {
378 return !RetTy->isFunctionTy() && !RetTy->isLabelTy() &&
379 !RetTy->isMetadataTy();
382 /// isValidArgumentType - Return true if the specified type is valid as an
384 bool FunctionType::isValidArgumentType(Type *ArgTy) {
385 return ArgTy->isFirstClassType();
388 //===----------------------------------------------------------------------===//
389 // StructType Implementation
390 //===----------------------------------------------------------------------===//
392 // Primitive Constructors.
394 StructType *StructType::get(LLVMContext &Context, ArrayRef<Type*> ETypes,
396 // FIXME: std::vector is horribly inefficient for this probe.
397 std::vector<Type*> Key;
398 for (unsigned i = 0, e = ETypes.size(); i != e; ++i) {
399 assert(isValidElementType(ETypes[i]) &&
400 "Invalid type for structure element!");
401 Key.push_back(ETypes[i]);
406 StructType *&ST = Context.pImpl->AnonStructTypes[Key];
409 // Value not found. Create a new type!
410 ST = new (Context.pImpl->TypeAllocator) StructType(Context);
411 ST->setSubclassData(SCDB_IsLiteral); // Literal struct.
412 ST->setBody(ETypes, isPacked);
416 void StructType::setBody(ArrayRef<Type*> Elements, bool isPacked) {
417 assert(isOpaque() && "Struct body already set!");
419 setSubclassData(getSubclassData() | SCDB_HasBody);
421 setSubclassData(getSubclassData() | SCDB_Packed);
423 Type **Elts = getContext().pImpl->
424 TypeAllocator.Allocate<Type*>(Elements.size());
425 memcpy(Elts, Elements.data(), sizeof(Elements[0])*Elements.size());
428 NumContainedTys = Elements.size();
431 void StructType::setName(StringRef Name) {
432 if (Name == getName()) return;
434 // If this struct already had a name, remove its symbol table entry.
435 if (SymbolTableEntry) {
436 getContext().pImpl->NamedStructTypes.erase(getName());
437 SymbolTableEntry = 0;
440 // If this is just removing the name, we're done.
444 // Look up the entry for the name.
445 StringMapEntry<StructType*> *Entry =
446 &getContext().pImpl->NamedStructTypes.GetOrCreateValue(Name);
448 // While we have a name collision, try a random rename.
449 if (Entry->getValue()) {
450 SmallString<64> TempStr(Name);
451 TempStr.push_back('.');
452 raw_svector_ostream TmpStream(TempStr);
455 TempStr.resize(Name.size()+1);
457 TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
459 Entry = &getContext().pImpl->
460 NamedStructTypes.GetOrCreateValue(TmpStream.str());
461 } while (Entry->getValue());
464 // Okay, we found an entry that isn't used. It's us!
465 Entry->setValue(this);
467 SymbolTableEntry = Entry;
470 //===----------------------------------------------------------------------===//
471 // StructType Helper functions.
473 StructType *StructType::create(LLVMContext &Context, StringRef Name) {
474 StructType *ST = new (Context.pImpl->TypeAllocator) StructType(Context);
480 StructType *StructType::get(LLVMContext &Context, bool isPacked) {
481 return get(Context, llvm::ArrayRef<Type*>(), isPacked);
484 StructType *StructType::get(Type *type, ...) {
485 assert(type != 0 && "Cannot create a struct type with no elements with this");
486 LLVMContext &Ctx = type->getContext();
488 SmallVector<llvm::Type*, 8> StructFields;
491 StructFields.push_back(type);
492 type = va_arg(ap, llvm::Type*);
494 return llvm::StructType::get(Ctx, StructFields);
497 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements,
498 StringRef Name, bool isPacked) {
499 StructType *ST = create(Context, Name);
500 ST->setBody(Elements, isPacked);
504 StructType *StructType::create(LLVMContext &Context, ArrayRef<Type*> Elements) {
505 return create(Context, Elements, StringRef());
508 StructType *StructType::create(LLVMContext &Context) {
509 return create(Context, StringRef());
513 StructType *StructType::create(ArrayRef<Type*> Elements, StringRef Name,
515 assert(!Elements.empty() &&
516 "This method may not be invoked with an empty list");
517 return create(Elements[0]->getContext(), Elements, Name, isPacked);
520 StructType *StructType::create(ArrayRef<Type*> Elements) {
521 assert(!Elements.empty() &&
522 "This method may not be invoked with an empty list");
523 return create(Elements[0]->getContext(), Elements, StringRef());
526 StructType *StructType::create(StringRef Name, Type *type, ...) {
527 assert(type != 0 && "Cannot create a struct type with no elements with this");
528 LLVMContext &Ctx = type->getContext();
530 SmallVector<llvm::Type*, 8> StructFields;
533 StructFields.push_back(type);
534 type = va_arg(ap, llvm::Type*);
536 return llvm::StructType::create(Ctx, StructFields, Name);
540 StringRef StructType::getName() const {
541 assert(!isLiteral() && "Literal structs never have names");
542 if (SymbolTableEntry == 0) return StringRef();
544 return ((StringMapEntry<StructType*> *)SymbolTableEntry)->getKey();
547 void StructType::setBody(Type *type, ...) {
548 assert(type != 0 && "Cannot create a struct type with no elements with this");
550 SmallVector<llvm::Type*, 8> StructFields;
553 StructFields.push_back(type);
554 type = va_arg(ap, llvm::Type*);
556 setBody(StructFields);
559 bool StructType::isValidElementType(Type *ElemTy) {
560 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
561 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
564 /// isLayoutIdentical - Return true if this is layout identical to the
565 /// specified struct.
566 bool StructType::isLayoutIdentical(StructType *Other) const {
567 if (this == Other) return true;
569 if (isPacked() != Other->isPacked() ||
570 getNumElements() != Other->getNumElements())
573 return std::equal(element_begin(), element_end(), Other->element_begin());
577 /// getTypeByName - Return the type with the specified name, or null if there
578 /// is none by that name.
579 StructType *Module::getTypeByName(StringRef Name) const {
580 StringMap<StructType*>::iterator I =
581 getContext().pImpl->NamedStructTypes.find(Name);
582 if (I != getContext().pImpl->NamedStructTypes.end())
588 //===----------------------------------------------------------------------===//
589 // CompositeType Implementation
590 //===----------------------------------------------------------------------===//
592 Type *CompositeType::getTypeAtIndex(const Value *V) {
593 if (StructType *STy = dyn_cast<StructType>(this)) {
594 unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
595 assert(indexValid(Idx) && "Invalid structure index!");
596 return STy->getElementType(Idx);
599 return cast<SequentialType>(this)->getElementType();
601 Type *CompositeType::getTypeAtIndex(unsigned Idx) {
602 if (StructType *STy = dyn_cast<StructType>(this)) {
603 assert(indexValid(Idx) && "Invalid structure index!");
604 return STy->getElementType(Idx);
607 return cast<SequentialType>(this)->getElementType();
609 bool CompositeType::indexValid(const Value *V) const {
610 if (const StructType *STy = dyn_cast<StructType>(this)) {
611 // Structure indexes require 32-bit integer constants.
612 if (V->getType()->isIntegerTy(32))
613 if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
614 return CU->getZExtValue() < STy->getNumElements();
618 // Sequential types can be indexed by any integer.
619 return V->getType()->isIntegerTy();
622 bool CompositeType::indexValid(unsigned Idx) const {
623 if (const StructType *STy = dyn_cast<StructType>(this))
624 return Idx < STy->getNumElements();
625 // Sequential types can be indexed by any integer.
630 //===----------------------------------------------------------------------===//
631 // ArrayType Implementation
632 //===----------------------------------------------------------------------===//
634 ArrayType::ArrayType(Type *ElType, uint64_t NumEl)
635 : SequentialType(ArrayTyID, ElType) {
640 ArrayType *ArrayType::get(Type *elementType, uint64_t NumElements) {
641 Type *ElementType = const_cast<Type*>(elementType);
642 assert(isValidElementType(ElementType) && "Invalid type for array element!");
644 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
646 pImpl->ArrayTypes[std::make_pair(ElementType, NumElements)];
649 Entry = new (pImpl->TypeAllocator) ArrayType(ElementType, NumElements);
653 bool ArrayType::isValidElementType(Type *ElemTy) {
654 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
655 !ElemTy->isMetadataTy() && !ElemTy->isFunctionTy();
658 //===----------------------------------------------------------------------===//
659 // VectorType Implementation
660 //===----------------------------------------------------------------------===//
662 VectorType::VectorType(Type *ElType, unsigned NumEl)
663 : SequentialType(VectorTyID, ElType) {
667 VectorType *VectorType::get(Type *elementType, unsigned NumElements) {
668 Type *ElementType = const_cast<Type*>(elementType);
669 assert(NumElements > 0 && "#Elements of a VectorType must be greater than 0");
670 assert(isValidElementType(ElementType) &&
671 "Elements of a VectorType must be a primitive type");
673 LLVMContextImpl *pImpl = ElementType->getContext().pImpl;
674 VectorType *&Entry = ElementType->getContext().pImpl
675 ->VectorTypes[std::make_pair(ElementType, NumElements)];
678 Entry = new (pImpl->TypeAllocator) VectorType(ElementType, NumElements);
682 bool VectorType::isValidElementType(Type *ElemTy) {
683 if (PointerType *PTy = dyn_cast<PointerType>(ElemTy))
684 ElemTy = PTy->getElementType();
685 return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy();
688 //===----------------------------------------------------------------------===//
689 // PointerType Implementation
690 //===----------------------------------------------------------------------===//
692 PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) {
693 assert(EltTy && "Can't get a pointer to <null> type!");
694 assert(isValidElementType(EltTy) && "Invalid type for pointer element!");
696 LLVMContextImpl *CImpl = EltTy->getContext().pImpl;
698 // Since AddressSpace #0 is the common case, we special case it.
699 PointerType *&Entry = AddressSpace == 0 ? CImpl->PointerTypes[EltTy]
700 : CImpl->ASPointerTypes[std::make_pair(EltTy, AddressSpace)];
703 Entry = new (CImpl->TypeAllocator) PointerType(EltTy, AddressSpace);
708 PointerType::PointerType(Type *E, unsigned AddrSpace)
709 : SequentialType(PointerTyID, E) {
710 setSubclassData(AddrSpace);
713 PointerType *Type::getPointerTo(unsigned addrs) {
714 return PointerType::get(this, addrs);
717 bool PointerType::isValidElementType(Type *ElemTy) {
718 return !ElemTy->isVoidTy() && !ElemTy->isLabelTy() &&
719 !ElemTy->isMetadataTy();