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 FloatTyID
: return getFloatTy(C
);
29 case DoubleTyID
: return getDoubleTy(C
);
30 case X86_FP80TyID
: return getX86_FP80Ty(C
);
31 case FP128TyID
: return getFP128Ty(C
);
32 case PPC_FP128TyID
: return getPPC_FP128Ty(C
);
33 case LabelTyID
: return getLabelTy(C
);
34 case MetadataTyID
: return getMetadataTy(C
);
35 case X86_MMXTyID
: return getX86_MMXTy(C
);
41 /// getScalarType - If this is a vector type, return the element type,
42 /// otherwise return this.
43 const Type
*Type::getScalarType() const {
44 if (const VectorType
*VTy
= dyn_cast
<VectorType
>(this))
45 return VTy
->getElementType();
49 /// isIntegerTy - Return true if this is an IntegerType of the specified width.
50 bool Type::isIntegerTy(unsigned Bitwidth
) const {
51 return isIntegerTy() && cast
<IntegerType
>(this)->getBitWidth() == Bitwidth
;
54 /// isIntOrIntVectorTy - Return true if this is an integer type or a vector of
57 bool Type::isIntOrIntVectorTy() const {
60 if (ID
!= Type::VectorTyID
) return false;
62 return cast
<VectorType
>(this)->getElementType()->isIntegerTy();
65 /// isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP types.
67 bool Type::isFPOrFPVectorTy() const {
68 if (ID
== Type::FloatTyID
|| ID
== Type::DoubleTyID
||
69 ID
== Type::FP128TyID
|| ID
== Type::X86_FP80TyID
||
70 ID
== Type::PPC_FP128TyID
)
72 if (ID
!= Type::VectorTyID
) return false;
74 return cast
<VectorType
>(this)->getElementType()->isFloatingPointTy();
77 // canLosslesslyBitCastTo - Return true if this type can be converted to
78 // 'Ty' without any reinterpretation of bits. For example, i8* to i32*.
80 bool Type::canLosslesslyBitCastTo(const Type
*Ty
) const {
81 // Identity cast means no change so return true
85 // They are not convertible unless they are at least first class types
86 if (!this->isFirstClassType() || !Ty
->isFirstClassType())
89 // Vector -> Vector conversions are always lossless if the two vector types
90 // have the same size, otherwise not. Also, 64-bit vector types can be
91 // converted to x86mmx.
92 if (const VectorType
*thisPTy
= dyn_cast
<VectorType
>(this)) {
93 if (const VectorType
*thatPTy
= dyn_cast
<VectorType
>(Ty
))
94 return thisPTy
->getBitWidth() == thatPTy
->getBitWidth();
95 if (Ty
->getTypeID() == Type::X86_MMXTyID
&&
96 thisPTy
->getBitWidth() == 64)
100 if (this->getTypeID() == Type::X86_MMXTyID
)
101 if (const VectorType
*thatPTy
= dyn_cast
<VectorType
>(Ty
))
102 if (thatPTy
->getBitWidth() == 64)
105 // At this point we have only various mismatches of the first class types
106 // remaining and ptr->ptr. Just select the lossless conversions. Everything
107 // else is not lossless.
108 if (this->isPointerTy())
109 return Ty
->isPointerTy();
110 return false; // Other types have no identity values
113 bool Type::isEmptyTy() const {
114 const ArrayType
*ATy
= dyn_cast
<ArrayType
>(this);
116 unsigned NumElements
= ATy
->getNumElements();
117 return NumElements
== 0 || ATy
->getElementType()->isEmptyTy();
120 const StructType
*STy
= dyn_cast
<StructType
>(this);
122 unsigned NumElements
= STy
->getNumElements();
123 for (unsigned i
= 0; i
< NumElements
; ++i
)
124 if (!STy
->getElementType(i
)->isEmptyTy())
132 unsigned Type::getPrimitiveSizeInBits() const {
133 switch (getTypeID()) {
134 case Type::FloatTyID
: return 32;
135 case Type::DoubleTyID
: return 64;
136 case Type::X86_FP80TyID
: return 80;
137 case Type::FP128TyID
: return 128;
138 case Type::PPC_FP128TyID
: return 128;
139 case Type::X86_MMXTyID
: return 64;
140 case Type::IntegerTyID
: return cast
<IntegerType
>(this)->getBitWidth();
141 case Type::VectorTyID
: return cast
<VectorType
>(this)->getBitWidth();
146 /// getScalarSizeInBits - If this is a vector type, return the
147 /// getPrimitiveSizeInBits value for the element type. Otherwise return the
148 /// getPrimitiveSizeInBits value for this type.
149 unsigned Type::getScalarSizeInBits() const {
150 return getScalarType()->getPrimitiveSizeInBits();
153 /// getFPMantissaWidth - Return the width of the mantissa of this type. This
154 /// is only valid on floating point types. If the FP type does not
155 /// have a stable mantissa (e.g. ppc long double), this method returns -1.
156 int Type::getFPMantissaWidth() const {
157 if (const VectorType
*VTy
= dyn_cast
<VectorType
>(this))
158 return VTy
->getElementType()->getFPMantissaWidth();
159 assert(isFloatingPointTy() && "Not a floating point type!");
160 if (ID
== FloatTyID
) return 24;
161 if (ID
== DoubleTyID
) return 53;
162 if (ID
== X86_FP80TyID
) return 64;
163 if (ID
== FP128TyID
) return 113;
164 assert(ID
== PPC_FP128TyID
&& "unknown fp type");
168 /// isSizedDerivedType - Derived types like structures and arrays are sized
169 /// iff all of the members of the type are sized as well. Since asking for
170 /// their size is relatively uncommon, move this operation out of line.
171 bool Type::isSizedDerivedType() const {
172 if (this->isIntegerTy())
175 if (const ArrayType
*ATy
= dyn_cast
<ArrayType
>(this))
176 return ATy
->getElementType()->isSized();
178 if (const VectorType
*VTy
= dyn_cast
<VectorType
>(this))
179 return VTy
->getElementType()->isSized();
181 if (!this->isStructTy())
184 // Opaque structs have no size.
185 if (cast
<StructType
>(this)->isOpaque())
188 // Okay, our struct is sized if all of the elements are.
189 for (subtype_iterator I
= subtype_begin(), E
= subtype_end(); I
!= E
; ++I
)
190 if (!(*I
)->isSized())
196 //===----------------------------------------------------------------------===//
197 // Primitive 'Type' data
198 //===----------------------------------------------------------------------===//
200 Type
*Type::getVoidTy(LLVMContext
&C
) { return &C
.pImpl
->VoidTy
; }
201 Type
*Type::getLabelTy(LLVMContext
&C
) { return &C
.pImpl
->LabelTy
; }
202 Type
*Type::getFloatTy(LLVMContext
&C
) { return &C
.pImpl
->FloatTy
; }
203 Type
*Type::getDoubleTy(LLVMContext
&C
) { return &C
.pImpl
->DoubleTy
; }
204 Type
*Type::getMetadataTy(LLVMContext
&C
) { return &C
.pImpl
->MetadataTy
; }
205 Type
*Type::getX86_FP80Ty(LLVMContext
&C
) { return &C
.pImpl
->X86_FP80Ty
; }
206 Type
*Type::getFP128Ty(LLVMContext
&C
) { return &C
.pImpl
->FP128Ty
; }
207 Type
*Type::getPPC_FP128Ty(LLVMContext
&C
) { return &C
.pImpl
->PPC_FP128Ty
; }
208 Type
*Type::getX86_MMXTy(LLVMContext
&C
) { return &C
.pImpl
->X86_MMXTy
; }
210 IntegerType
*Type::getInt1Ty(LLVMContext
&C
) { return &C
.pImpl
->Int1Ty
; }
211 IntegerType
*Type::getInt8Ty(LLVMContext
&C
) { return &C
.pImpl
->Int8Ty
; }
212 IntegerType
*Type::getInt16Ty(LLVMContext
&C
) { return &C
.pImpl
->Int16Ty
; }
213 IntegerType
*Type::getInt32Ty(LLVMContext
&C
) { return &C
.pImpl
->Int32Ty
; }
214 IntegerType
*Type::getInt64Ty(LLVMContext
&C
) { return &C
.pImpl
->Int64Ty
; }
216 IntegerType
*Type::getIntNTy(LLVMContext
&C
, unsigned N
) {
217 return IntegerType::get(C
, N
);
220 PointerType
*Type::getFloatPtrTy(LLVMContext
&C
, unsigned AS
) {
221 return getFloatTy(C
)->getPointerTo(AS
);
224 PointerType
*Type::getDoublePtrTy(LLVMContext
&C
, unsigned AS
) {
225 return getDoubleTy(C
)->getPointerTo(AS
);
228 PointerType
*Type::getX86_FP80PtrTy(LLVMContext
&C
, unsigned AS
) {
229 return getX86_FP80Ty(C
)->getPointerTo(AS
);
232 PointerType
*Type::getFP128PtrTy(LLVMContext
&C
, unsigned AS
) {
233 return getFP128Ty(C
)->getPointerTo(AS
);
236 PointerType
*Type::getPPC_FP128PtrTy(LLVMContext
&C
, unsigned AS
) {
237 return getPPC_FP128Ty(C
)->getPointerTo(AS
);
240 PointerType
*Type::getX86_MMXPtrTy(LLVMContext
&C
, unsigned AS
) {
241 return getX86_MMXTy(C
)->getPointerTo(AS
);
244 PointerType
*Type::getIntNPtrTy(LLVMContext
&C
, unsigned N
, unsigned AS
) {
245 return getIntNTy(C
, N
)->getPointerTo(AS
);
248 PointerType
*Type::getInt1PtrTy(LLVMContext
&C
, unsigned AS
) {
249 return getInt1Ty(C
)->getPointerTo(AS
);
252 PointerType
*Type::getInt8PtrTy(LLVMContext
&C
, unsigned AS
) {
253 return getInt8Ty(C
)->getPointerTo(AS
);
256 PointerType
*Type::getInt16PtrTy(LLVMContext
&C
, unsigned AS
) {
257 return getInt16Ty(C
)->getPointerTo(AS
);
260 PointerType
*Type::getInt32PtrTy(LLVMContext
&C
, unsigned AS
) {
261 return getInt32Ty(C
)->getPointerTo(AS
);
264 PointerType
*Type::getInt64PtrTy(LLVMContext
&C
, unsigned AS
) {
265 return getInt64Ty(C
)->getPointerTo(AS
);
269 //===----------------------------------------------------------------------===//
270 // IntegerType Implementation
271 //===----------------------------------------------------------------------===//
273 IntegerType
*IntegerType::get(LLVMContext
&C
, unsigned NumBits
) {
274 assert(NumBits
>= MIN_INT_BITS
&& "bitwidth too small");
275 assert(NumBits
<= MAX_INT_BITS
&& "bitwidth too large");
277 // Check for the built-in integer types
279 case 1: return cast
<IntegerType
>(Type::getInt1Ty(C
));
280 case 8: return cast
<IntegerType
>(Type::getInt8Ty(C
));
281 case 16: return cast
<IntegerType
>(Type::getInt16Ty(C
));
282 case 32: return cast
<IntegerType
>(Type::getInt32Ty(C
));
283 case 64: return cast
<IntegerType
>(Type::getInt64Ty(C
));
288 IntegerType
*&Entry
= C
.pImpl
->IntegerTypes
[NumBits
];
291 Entry
= new IntegerType(C
, NumBits
);
296 bool IntegerType::isPowerOf2ByteWidth() const {
297 unsigned BitWidth
= getBitWidth();
298 return (BitWidth
> 7) && isPowerOf2_32(BitWidth
);
301 APInt
IntegerType::getMask() const {
302 return APInt::getAllOnesValue(getBitWidth());
305 //===----------------------------------------------------------------------===//
306 // FunctionType Implementation
307 //===----------------------------------------------------------------------===//
309 FunctionType::FunctionType(const Type
*Result
, ArrayRef
<Type
*> Params
,
311 : DerivedType(Result
->getContext(), FunctionTyID
) {
312 Type
**SubTys
= reinterpret_cast<Type
**>(this+1);
313 assert(isValidReturnType(Result
) && "invalid return type for function");
314 setSubclassData(IsVarArgs
);
316 SubTys
[0] = const_cast<Type
*>(Result
);
318 for (unsigned i
= 0, e
= Params
.size(); i
!= e
; ++i
) {
319 assert(isValidArgumentType(Params
[i
]) &&
320 "Not a valid type for function argument!");
321 SubTys
[i
+1] = Params
[i
];
324 ContainedTys
= SubTys
;
325 NumContainedTys
= Params
.size() + 1; // + 1 for result type
328 // FIXME: Remove this version.
329 FunctionType
*FunctionType::get(const Type
*ReturnType
,
330 ArrayRef
<const Type
*> Params
, bool isVarArg
) {
331 return get(ReturnType
, ArrayRef
<Type
*>(const_cast<Type
**>(Params
.data()),
332 Params
.size()), isVarArg
);
335 // FunctionType::get - The factory function for the FunctionType class.
336 FunctionType
*FunctionType::get(const Type
*ReturnType
,
337 ArrayRef
<Type
*> Params
, bool isVarArg
) {
338 // TODO: This is brutally slow.
339 std::vector
<Type
*> Key
;
340 Key
.reserve(Params
.size()+2);
341 Key
.push_back(const_cast<Type
*>(ReturnType
));
342 for (unsigned i
= 0, e
= Params
.size(); i
!= e
; ++i
)
343 Key
.push_back(const_cast<Type
*>(Params
[i
]));
347 FunctionType
*&FT
= ReturnType
->getContext().pImpl
->FunctionTypes
[Key
];
350 FT
= (FunctionType
*) operator new(sizeof(FunctionType
) +
351 sizeof(Type
*)*(Params
.size()+1));
352 new (FT
) FunctionType(ReturnType
, Params
, isVarArg
);
359 FunctionType
*FunctionType::get(const Type
*Result
, bool isVarArg
) {
360 return get(Result
, ArrayRef
<const Type
*>(), isVarArg
);
364 /// isValidReturnType - Return true if the specified type is valid as a return
366 bool FunctionType::isValidReturnType(const Type
*RetTy
) {
367 return !RetTy
->isFunctionTy() && !RetTy
->isLabelTy() &&
368 !RetTy
->isMetadataTy();
371 /// isValidArgumentType - Return true if the specified type is valid as an
373 bool FunctionType::isValidArgumentType(const Type
*ArgTy
) {
374 return ArgTy
->isFirstClassType();
377 //===----------------------------------------------------------------------===//
378 // StructType Implementation
379 //===----------------------------------------------------------------------===//
381 // Primitive Constructors.
383 StructType
*StructType::get(LLVMContext
&Context
, ArrayRef
<Type
*> ETypes
,
385 // FIXME: std::vector is horribly inefficient for this probe.
386 std::vector
<Type
*> Key
;
387 for (unsigned i
= 0, e
= ETypes
.size(); i
!= e
; ++i
) {
388 assert(isValidElementType(ETypes
[i
]) &&
389 "Invalid type for structure element!");
390 Key
.push_back(ETypes
[i
]);
395 StructType
*&ST
= Context
.pImpl
->AnonStructTypes
[Key
];
399 // Value not found. Create a new type!
400 ST
= new StructType(Context
);
401 ST
->setSubclassData(SCDB_IsAnonymous
); // Anonymous struct.
402 ST
->setBody(ETypes
, isPacked
);
406 void StructType::setBody(ArrayRef
<Type
*> Elements
, bool isPacked
) {
407 assert(isOpaque() && "Struct body already set!");
409 setSubclassData(getSubclassData() | SCDB_HasBody
);
411 setSubclassData(getSubclassData() | SCDB_Packed
);
413 Type
**Elts
= new Type
*[Elements
.size()];
414 memcpy(Elts
, Elements
.data(), sizeof(Elements
[0])*Elements
.size());
417 NumContainedTys
= Elements
.size();
420 StructType
*StructType::createNamed(LLVMContext
&Context
, StringRef Name
) {
421 StructType
*ST
= new StructType(Context
);
426 void StructType::setName(StringRef Name
) {
427 if (Name
== getName()) return;
429 // If this struct already had a name, remove its symbol table entry.
430 if (SymbolTableEntry
) {
431 getContext().pImpl
->NamedStructTypes
.erase(getName());
432 SymbolTableEntry
= 0;
435 // If this is just removing the name, we're done.
439 // Look up the entry for the name.
440 StringMapEntry
<StructType
*> *Entry
=
441 &getContext().pImpl
->NamedStructTypes
.GetOrCreateValue(Name
);
443 // While we have a name collision, try a random rename.
444 if (Entry
->getValue()) {
445 SmallString
<64> TempStr(Name
);
446 TempStr
.push_back('.');
447 raw_svector_ostream
TmpStream(TempStr
);
450 TempStr
.resize(Name
.size()+1);
452 TmpStream
<< getContext().pImpl
->NamedStructTypesUniqueID
++;
454 Entry
= &getContext().pImpl
->
455 NamedStructTypes
.GetOrCreateValue(TmpStream
.str());
456 } while (Entry
->getValue());
459 // Okay, we found an entry that isn't used. It's us!
460 Entry
->setValue(this);
462 SymbolTableEntry
= Entry
;
465 //===----------------------------------------------------------------------===//
466 // StructType Helper functions.
468 // FIXME: Remove this version.
469 StructType
*StructType::get(LLVMContext
&Context
, ArrayRef
<const Type
*>Elements
,
471 return get(Context
, ArrayRef
<Type
*>(const_cast<Type
**>(Elements
.data()),
472 Elements
.size()), isPacked
);
475 StructType
*StructType::get(LLVMContext
&Context
, bool isPacked
) {
476 return get(Context
, llvm::ArrayRef
<const Type
*>(), isPacked
);
479 StructType
*StructType::get(const Type
*type
, ...) {
480 assert(type
!= 0 && "Cannot create a struct type with no elements with this");
481 LLVMContext
&Ctx
= type
->getContext();
483 SmallVector
<const llvm::Type
*, 8> StructFields
;
486 StructFields
.push_back(type
);
487 type
= va_arg(ap
, llvm::Type
*);
489 return llvm::StructType::get(Ctx
, StructFields
);
492 StructType
*StructType::createNamed(LLVMContext
&Context
, StringRef Name
,
493 ArrayRef
<Type
*> Elements
, bool isPacked
) {
494 StructType
*ST
= createNamed(Context
, Name
);
495 ST
->setBody(Elements
, isPacked
);
499 StructType
*StructType::createNamed(StringRef Name
, ArrayRef
<Type
*> Elements
,
501 assert(!Elements
.empty() &&
502 "This method may not be invoked with an empty list");
503 return createNamed(Elements
[0]->getContext(), Name
, Elements
, isPacked
);
506 StructType
*StructType::createNamed(StringRef Name
, Type
*type
, ...) {
507 assert(type
!= 0 && "Cannot create a struct type with no elements with this");
508 LLVMContext
&Ctx
= type
->getContext();
510 SmallVector
<llvm::Type
*, 8> StructFields
;
513 StructFields
.push_back(type
);
514 type
= va_arg(ap
, llvm::Type
*);
516 return llvm::StructType::createNamed(Ctx
, Name
, StructFields
);
519 StringRef
StructType::getName() const {
520 assert(!isAnonymous() && "Anonymous structs never have names");
521 if (SymbolTableEntry
== 0) return StringRef();
523 return ((StringMapEntry
<StructType
*> *)SymbolTableEntry
)->getKey();
526 void StructType::setBody(Type
*type
, ...) {
527 assert(type
!= 0 && "Cannot create a struct type with no elements with this");
529 SmallVector
<llvm::Type
*, 8> StructFields
;
532 StructFields
.push_back(type
);
533 type
= va_arg(ap
, llvm::Type
*);
535 setBody(StructFields
);
538 bool StructType::isValidElementType(const Type
*ElemTy
) {
539 return !ElemTy
->isVoidTy() && !ElemTy
->isLabelTy() &&
540 !ElemTy
->isMetadataTy() && !ElemTy
->isFunctionTy();
543 /// isLayoutIdentical - Return true if this is layout identical to the
544 /// specified struct.
545 bool StructType::isLayoutIdentical(const StructType
*Other
) const {
546 if (this == Other
) return true;
548 if (isPacked() != Other
->isPacked() ||
549 getNumElements() != Other
->getNumElements())
552 return std::equal(element_begin(), element_end(), Other
->element_begin());
556 /// getTypeByName - Return the type with the specified name, or null if there
557 /// is none by that name.
558 StructType
*Module::getTypeByName(StringRef Name
) const {
559 StringMap
<StructType
*>::iterator I
=
560 getContext().pImpl
->NamedStructTypes
.find(Name
);
561 if (I
!= getContext().pImpl
->NamedStructTypes
.end())
567 //===----------------------------------------------------------------------===//
568 // CompositeType Implementation
569 //===----------------------------------------------------------------------===//
571 Type
*CompositeType::getTypeAtIndex(const Value
*V
) const {
572 if (const StructType
*STy
= dyn_cast
<StructType
>(this)) {
573 unsigned Idx
= (unsigned)cast
<ConstantInt
>(V
)->getZExtValue();
574 assert(indexValid(Idx
) && "Invalid structure index!");
575 return STy
->getElementType(Idx
);
578 return cast
<SequentialType
>(this)->getElementType();
580 Type
*CompositeType::getTypeAtIndex(unsigned Idx
) const {
581 if (const StructType
*STy
= dyn_cast
<StructType
>(this)) {
582 assert(indexValid(Idx
) && "Invalid structure index!");
583 return STy
->getElementType(Idx
);
586 return cast
<SequentialType
>(this)->getElementType();
588 bool CompositeType::indexValid(const Value
*V
) const {
589 if (const StructType
*STy
= dyn_cast
<StructType
>(this)) {
590 // Structure indexes require 32-bit integer constants.
591 if (V
->getType()->isIntegerTy(32))
592 if (const ConstantInt
*CU
= dyn_cast
<ConstantInt
>(V
))
593 return CU
->getZExtValue() < STy
->getNumElements();
597 // Sequential types can be indexed by any integer.
598 return V
->getType()->isIntegerTy();
601 bool CompositeType::indexValid(unsigned Idx
) const {
602 if (const StructType
*STy
= dyn_cast
<StructType
>(this))
603 return Idx
< STy
->getNumElements();
604 // Sequential types can be indexed by any integer.
609 //===----------------------------------------------------------------------===//
610 // ArrayType Implementation
611 //===----------------------------------------------------------------------===//
613 ArrayType::ArrayType(Type
*ElType
, uint64_t NumEl
)
614 : SequentialType(ArrayTyID
, ElType
) {
619 ArrayType
*ArrayType::get(const Type
*elementType
, uint64_t NumElements
) {
620 Type
*ElementType
= const_cast<Type
*>(elementType
);
621 assert(isValidElementType(ElementType
) && "Invalid type for array element!");
623 ArrayType
*&Entry
= ElementType
->getContext().pImpl
624 ->ArrayTypes
[std::make_pair(ElementType
, NumElements
)];
627 Entry
= new ArrayType(ElementType
, NumElements
);
631 bool ArrayType::isValidElementType(const Type
*ElemTy
) {
632 return !ElemTy
->isVoidTy() && !ElemTy
->isLabelTy() &&
633 !ElemTy
->isMetadataTy() && !ElemTy
->isFunctionTy();
636 //===----------------------------------------------------------------------===//
637 // VectorType Implementation
638 //===----------------------------------------------------------------------===//
640 VectorType::VectorType(Type
*ElType
, unsigned NumEl
)
641 : SequentialType(VectorTyID
, ElType
) {
645 VectorType
*VectorType::get(const Type
*elementType
, unsigned NumElements
) {
646 Type
*ElementType
= const_cast<Type
*>(elementType
);
647 assert(NumElements
> 0 && "#Elements of a VectorType must be greater than 0");
648 assert(isValidElementType(ElementType
) &&
649 "Elements of a VectorType must be a primitive type");
651 VectorType
*&Entry
= ElementType
->getContext().pImpl
652 ->VectorTypes
[std::make_pair(ElementType
, NumElements
)];
655 Entry
= new VectorType(ElementType
, NumElements
);
659 bool VectorType::isValidElementType(const Type
*ElemTy
) {
660 return ElemTy
->isIntegerTy() || ElemTy
->isFloatingPointTy();
663 //===----------------------------------------------------------------------===//
664 // PointerType Implementation
665 //===----------------------------------------------------------------------===//
667 PointerType
*PointerType::get(const Type
*eltTy
, unsigned AddressSpace
) {
668 Type
*EltTy
= const_cast<Type
*>(eltTy
);
669 assert(EltTy
&& "Can't get a pointer to <null> type!");
670 assert(isValidElementType(EltTy
) && "Invalid type for pointer element!");
672 LLVMContextImpl
*CImpl
= EltTy
->getContext().pImpl
;
674 // Since AddressSpace #0 is the common case, we special case it.
675 PointerType
*&Entry
= AddressSpace
== 0 ? CImpl
->PointerTypes
[EltTy
]
676 : CImpl
->ASPointerTypes
[std::make_pair(EltTy
, AddressSpace
)];
679 Entry
= new PointerType(EltTy
, AddressSpace
);
684 PointerType::PointerType(Type
*E
, unsigned AddrSpace
)
685 : SequentialType(PointerTyID
, E
) {
686 setSubclassData(AddrSpace
);
689 PointerType
*Type::getPointerTo(unsigned addrs
) const {
690 return PointerType::get(this, addrs
);
693 bool PointerType::isValidElementType(const Type
*ElemTy
) {
694 return !ElemTy
->isVoidTy() && !ElemTy
->isLabelTy() &&
695 !ElemTy
->isMetadataTy();