1 //===- llvm/DerivedTypes.h - Classes for handling data types ----*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file contains the declarations of classes that represent "derived
10 // types". These are things like "arrays of x" or "structure of x, y, z" or
11 // "function returning x taking (y,z) as parameters", etc...
13 // The implementations of these classes live in the Type.cpp file.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_IR_DERIVEDTYPES_H
18 #define LLVM_IR_DERIVEDTYPES_H
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/IR/Type.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/TypeSize.h"
36 /// Class to represent integer types. Note that this class is also used to
37 /// represent the built-in integer types: Int1Ty, Int8Ty, Int16Ty, Int32Ty and
39 /// Integer representation type
40 class IntegerType : public Type {
41 friend class LLVMContextImpl;
44 explicit IntegerType(LLVMContext &C, unsigned NumBits) : Type(C, IntegerTyID){
45 setSubclassData(NumBits);
49 /// This enum is just used to hold constants we need for IntegerType.
51 MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified
52 MAX_INT_BITS = (1<<24)-1 ///< Maximum number of bits that can be specified
53 ///< Note that bit width is stored in the Type classes SubclassData field
54 ///< which has 24 bits. This yields a maximum bit width of 16,777,215
58 /// This static method is the primary way of constructing an IntegerType.
59 /// If an IntegerType with the same NumBits value was previously instantiated,
60 /// that instance will be returned. Otherwise a new one will be created. Only
61 /// one instance with a given NumBits value is ever created.
62 /// Get or create an IntegerType instance.
63 static IntegerType *get(LLVMContext &C, unsigned NumBits);
65 /// Returns type twice as wide the input type.
66 IntegerType *getExtendedType() const {
67 return Type::getIntNTy(getContext(), 2 * getScalarSizeInBits());
70 /// Get the number of bits in this IntegerType
71 unsigned getBitWidth() const { return getSubclassData(); }
73 /// Return a bitmask with ones set for all of the bits that can be set by an
74 /// unsigned version of this type. This is 0xFF for i8, 0xFFFF for i16, etc.
75 uint64_t getBitMask() const {
76 return ~uint64_t(0UL) >> (64-getBitWidth());
79 /// Return a uint64_t with just the most significant bit set (the sign bit, if
80 /// the value is treated as a signed number).
81 uint64_t getSignBit() const {
82 return 1ULL << (getBitWidth()-1);
85 /// For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
86 /// @returns a bit mask with ones set for all the bits of this type.
87 /// Get a bit mask for this type.
88 APInt getMask() const;
90 /// This method determines if the width of this IntegerType is a power-of-2
91 /// in terms of 8 bit bytes.
92 /// @returns true if this is a power-of-2 byte width.
93 /// Is this a power-of-2 byte-width IntegerType ?
94 bool isPowerOf2ByteWidth() const;
96 /// Methods for support type inquiry through isa, cast, and dyn_cast.
97 static bool classof(const Type *T) {
98 return T->getTypeID() == IntegerTyID;
102 unsigned Type::getIntegerBitWidth() const {
103 return cast<IntegerType>(this)->getBitWidth();
106 /// Class to represent function types
108 class FunctionType : public Type {
109 FunctionType(Type *Result, ArrayRef<Type*> Params, bool IsVarArgs);
112 FunctionType(const FunctionType &) = delete;
113 FunctionType &operator=(const FunctionType &) = delete;
115 /// This static method is the primary way of constructing a FunctionType.
116 static FunctionType *get(Type *Result,
117 ArrayRef<Type*> Params, bool isVarArg);
119 /// Create a FunctionType taking no parameters.
120 static FunctionType *get(Type *Result, bool isVarArg);
122 /// Return true if the specified type is valid as a return type.
123 static bool isValidReturnType(Type *RetTy);
125 /// Return true if the specified type is valid as an argument type.
126 static bool isValidArgumentType(Type *ArgTy);
128 bool isVarArg() const { return getSubclassData()!=0; }
129 Type *getReturnType() const { return ContainedTys[0]; }
131 using param_iterator = Type::subtype_iterator;
133 param_iterator param_begin() const { return ContainedTys + 1; }
134 param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
135 ArrayRef<Type *> params() const {
136 return makeArrayRef(param_begin(), param_end());
139 /// Parameter type accessors.
140 Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
142 /// Return the number of fixed parameters this function type requires.
143 /// This does not consider varargs.
144 unsigned getNumParams() const { return NumContainedTys - 1; }
146 /// Methods for support type inquiry through isa, cast, and dyn_cast.
147 static bool classof(const Type *T) {
148 return T->getTypeID() == FunctionTyID;
151 static_assert(alignof(FunctionType) >= alignof(Type *),
152 "Alignment sufficient for objects appended to FunctionType");
154 bool Type::isFunctionVarArg() const {
155 return cast<FunctionType>(this)->isVarArg();
158 Type *Type::getFunctionParamType(unsigned i) const {
159 return cast<FunctionType>(this)->getParamType(i);
162 unsigned Type::getFunctionNumParams() const {
163 return cast<FunctionType>(this)->getNumParams();
166 /// A handy container for a FunctionType+Callee-pointer pair, which can be
167 /// passed around as a single entity. This assists in replacing the use of
168 /// PointerType::getElementType() to access the function's type, since that's
169 /// slated for removal as part of the [opaque pointer types] project.
170 class FunctionCallee {
172 // Allow implicit conversion from types which have a getFunctionType member
173 // (e.g. Function and InlineAsm).
174 template <typename T, typename U = decltype(&T::getFunctionType)>
175 FunctionCallee(T *Fn)
176 : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
178 FunctionCallee(FunctionType *FnTy, Value *Callee)
179 : FnTy(FnTy), Callee(Callee) {
180 assert((FnTy == nullptr) == (Callee == nullptr));
183 FunctionCallee(std::nullptr_t) {}
185 FunctionCallee() = default;
187 FunctionType *getFunctionType() { return FnTy; }
189 Value *getCallee() { return Callee; }
191 explicit operator bool() { return Callee; }
194 FunctionType *FnTy = nullptr;
195 Value *Callee = nullptr;
198 /// Class to represent struct types. There are two different kinds of struct
199 /// types: Literal structs and Identified structs.
201 /// Literal struct types (e.g. { i32, i32 }) are uniqued structurally, and must
202 /// always have a body when created. You can get one of these by using one of
203 /// the StructType::get() forms.
205 /// Identified structs (e.g. %foo or %42) may optionally have a name and are not
206 /// uniqued. The names for identified structs are managed at the LLVMContext
207 /// level, so there can only be a single identified struct with a given name in
208 /// a particular LLVMContext. Identified structs may also optionally be opaque
209 /// (have no body specified). You get one of these by using one of the
210 /// StructType::create() forms.
212 /// Independent of what kind of struct you have, the body of a struct type are
213 /// laid out in memory consecutively with the elements directly one after the
214 /// other (if the struct is packed) or (if not packed) with padding between the
215 /// elements as defined by DataLayout (which is required to match what the code
216 /// generator for a target expects).
218 class StructType : public Type {
219 StructType(LLVMContext &C) : Type(C, StructTyID) {}
222 /// This is the contents of the SubClassData field.
229 /// For a named struct that actually has a name, this is a pointer to the
230 /// symbol table entry (maintained by LLVMContext) for the struct.
231 /// This is null if the type is an literal struct or if it is a identified
232 /// type that has an empty name.
233 void *SymbolTableEntry = nullptr;
236 StructType(const StructType &) = delete;
237 StructType &operator=(const StructType &) = delete;
239 /// This creates an identified struct.
240 static StructType *create(LLVMContext &Context, StringRef Name);
241 static StructType *create(LLVMContext &Context);
243 static StructType *create(ArrayRef<Type *> Elements, StringRef Name,
244 bool isPacked = false);
245 static StructType *create(ArrayRef<Type *> Elements);
246 static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements,
247 StringRef Name, bool isPacked = false);
248 static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements);
249 template <class... Tys>
250 static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *>
251 create(StringRef Name, Type *elt1, Tys *... elts) {
252 assert(elt1 && "Cannot create a struct type with no elements with this");
253 SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
254 return create(StructFields, Name);
257 /// This static method is the primary way to create a literal StructType.
258 static StructType *get(LLVMContext &Context, ArrayRef<Type*> Elements,
259 bool isPacked = false);
261 /// Create an empty structure type.
262 static StructType *get(LLVMContext &Context, bool isPacked = false);
264 /// This static method is a convenience method for creating structure types by
265 /// specifying the elements as arguments. Note that this method always returns
266 /// a non-packed struct, and requires at least one element type.
267 template <class... Tys>
268 static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *>
269 get(Type *elt1, Tys *... elts) {
270 assert(elt1 && "Cannot create a struct type with no elements with this");
271 LLVMContext &Ctx = elt1->getContext();
272 SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
273 return llvm::StructType::get(Ctx, StructFields);
276 bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
278 /// Return true if this type is uniqued by structural equivalence, false if it
279 /// is a struct definition.
280 bool isLiteral() const { return (getSubclassData() & SCDB_IsLiteral) != 0; }
282 /// Return true if this is a type with an identity that has no body specified
283 /// yet. These prints as 'opaque' in .ll files.
284 bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
286 /// isSized - Return true if this is a sized type.
287 bool isSized(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
289 /// Return true if this is a named struct that has a non-empty name.
290 bool hasName() const { return SymbolTableEntry != nullptr; }
292 /// Return the name for this struct type if it has an identity.
293 /// This may return an empty string for an unnamed struct type. Do not call
294 /// this on an literal type.
295 StringRef getName() const;
297 /// Change the name of this type to the specified name, or to a name with a
298 /// suffix if there is a collision. Do not call this on an literal type.
299 void setName(StringRef Name);
301 /// Specify a body for an opaque identified type.
302 void setBody(ArrayRef<Type*> Elements, bool isPacked = false);
304 template <typename... Tys>
305 std::enable_if_t<are_base_of<Type, Tys...>::value, void>
306 setBody(Type *elt1, Tys *... elts) {
307 assert(elt1 && "Cannot create a struct type with no elements with this");
308 SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
309 setBody(StructFields);
312 /// Return true if the specified type is valid as a element type.
313 static bool isValidElementType(Type *ElemTy);
315 // Iterator access to the elements.
316 using element_iterator = Type::subtype_iterator;
318 element_iterator element_begin() const { return ContainedTys; }
319 element_iterator element_end() const { return &ContainedTys[NumContainedTys];}
320 ArrayRef<Type *> const elements() const {
321 return makeArrayRef(element_begin(), element_end());
324 /// Return true if this is layout identical to the specified struct.
325 bool isLayoutIdentical(StructType *Other) const;
327 /// Random access to the elements
328 unsigned getNumElements() const { return NumContainedTys; }
329 Type *getElementType(unsigned N) const {
330 assert(N < NumContainedTys && "Element number out of range!");
331 return ContainedTys[N];
333 /// Given an index value into the type, return the type of the element.
334 Type *getTypeAtIndex(const Value *V) const;
335 Type *getTypeAtIndex(unsigned N) const { return getElementType(N); }
336 bool indexValid(const Value *V) const;
337 bool indexValid(unsigned Idx) const { return Idx < getNumElements(); }
339 /// Methods for support type inquiry through isa, cast, and dyn_cast.
340 static bool classof(const Type *T) {
341 return T->getTypeID() == StructTyID;
345 StringRef Type::getStructName() const {
346 return cast<StructType>(this)->getName();
349 unsigned Type::getStructNumElements() const {
350 return cast<StructType>(this)->getNumElements();
353 Type *Type::getStructElementType(unsigned N) const {
354 return cast<StructType>(this)->getElementType(N);
357 /// Class to represent array types.
358 class ArrayType : public Type {
359 /// The element type of the array.
361 /// Number of elements in the array.
362 uint64_t NumElements;
364 ArrayType(Type *ElType, uint64_t NumEl);
367 ArrayType(const ArrayType &) = delete;
368 ArrayType &operator=(const ArrayType &) = delete;
370 uint64_t getNumElements() const { return NumElements; }
371 Type *getElementType() const { return ContainedType; }
373 /// This static method is the primary way to construct an ArrayType
374 static ArrayType *get(Type *ElementType, uint64_t NumElements);
376 /// Return true if the specified type is valid as a element type.
377 static bool isValidElementType(Type *ElemTy);
379 /// Methods for support type inquiry through isa, cast, and dyn_cast.
380 static bool classof(const Type *T) {
381 return T->getTypeID() == ArrayTyID;
385 uint64_t Type::getArrayNumElements() const {
386 return cast<ArrayType>(this)->getNumElements();
389 /// Base class of all SIMD vector types
390 class VectorType : public Type {
391 /// A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
392 /// minimum number of elements of type Ty contained within the vector, and
393 /// 'vscale x' indicates that the total element count is an integer multiple
394 /// of 'n', where the multiple is either guaranteed to be one, or is
395 /// statically unknown at compile time.
397 /// If the multiple is known to be 1, then the extra term is discarded in
400 /// <4 x i32> - a vector containing 4 i32s
401 /// <vscale x 4 x i32> - a vector containing an unknown integer multiple
404 /// The element type of the vector.
408 /// The element quantity of this vector. The meaning of this value depends
409 /// on the type of vector:
410 /// - For FixedVectorType = <ElementQuantity x ty>, there are
411 /// exactly ElementQuantity elements in this vector.
412 /// - For ScalableVectorType = <vscale x ElementQuantity x ty>,
413 /// there are vscale * ElementQuantity elements in this vector, where
414 /// vscale is a runtime-constant integer greater than 0.
415 const unsigned ElementQuantity;
417 VectorType(Type *ElType, unsigned EQ, Type::TypeID TID);
420 VectorType(const VectorType &) = delete;
421 VectorType &operator=(const VectorType &) = delete;
423 /// Get the number of elements in this vector. It does not make sense to call
424 /// this function on a scalable vector, and this will be moved into
425 /// FixedVectorType in a future commit
426 unsigned getNumElements() const {
427 ElementCount EC = getElementCount();
428 #ifdef STRICT_FIXED_SIZE_VECTORS
429 assert(!EC.Scalable &&
430 "Request for fixed number of elements from scalable vector");
435 << "The code that requested the fixed number of elements has made "
436 "the assumption that this vector is not scalable. This assumption "
437 "was not correct, and this may lead to broken code\n";
442 Type *getElementType() const { return ContainedType; }
444 /// This static method is the primary way to construct an VectorType.
445 static VectorType *get(Type *ElementType, ElementCount EC);
447 /// Base class getter that specifically constructs a FixedVectorType. This
448 /// function is deprecated, and will be removed after LLVM 11 ships. Since
449 /// this always returns a FixedVectorType via a base VectorType pointer,
450 /// FixedVectorType::get(Type *, unsigned) is strictly better since no cast is
451 /// required to call getNumElements() on the result.
452 LLVM_ATTRIBUTE_DEPRECATED(
453 inline static VectorType *get(Type *ElementType, unsigned NumElements),
454 "The base class version of get with the scalable argument defaulted to "
455 "false is deprecated. Either call VectorType::get(Type *, unsigned, "
456 "bool) and pass false, or call FixedVectorType::get(Type *, unsigned).");
458 static VectorType *get(Type *ElementType, unsigned NumElements,
460 return VectorType::get(ElementType, {NumElements, Scalable});
463 static VectorType *get(Type *ElementType, const VectorType *Other) {
464 return VectorType::get(ElementType, Other->getElementCount());
467 /// This static method gets a VectorType with the same number of elements as
468 /// the input type, and the element type is an integer type of the same width
469 /// as the input element type.
470 static VectorType *getInteger(VectorType *VTy) {
471 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
472 assert(EltBits && "Element size must be of a non-zero size");
473 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
474 return VectorType::get(EltTy, VTy->getElementCount());
477 /// This static method is like getInteger except that the element types are
478 /// twice as wide as the elements in the input type.
479 static VectorType *getExtendedElementVectorType(VectorType *VTy) {
480 assert(VTy->isIntOrIntVectorTy() && "VTy expected to be a vector of ints.");
481 auto *EltTy = cast<IntegerType>(VTy->getElementType());
482 return VectorType::get(EltTy->getExtendedType(), VTy->getElementCount());
485 // This static method gets a VectorType with the same number of elements as
486 // the input type, and the element type is an integer or float type which
487 // is half as wide as the elements in the input type.
488 static VectorType *getTruncatedElementVectorType(VectorType *VTy) {
490 if (VTy->getElementType()->isFloatingPointTy()) {
491 switch(VTy->getElementType()->getTypeID()) {
493 EltTy = Type::getFloatTy(VTy->getContext());
496 EltTy = Type::getHalfTy(VTy->getContext());
499 llvm_unreachable("Cannot create narrower fp vector element type");
502 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
503 assert((EltBits & 1) == 0 &&
504 "Cannot truncate vector element with odd bit-width");
505 EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
507 return VectorType::get(EltTy, VTy->getElementCount());
510 // This static method returns a VectorType with a smaller number of elements
511 // of a larger type than the input element type. For example, a <16 x i8>
512 // subdivided twice would return <4 x i32>
513 static VectorType *getSubdividedVectorType(VectorType *VTy, int NumSubdivs) {
514 for (int i = 0; i < NumSubdivs; ++i) {
515 VTy = VectorType::getDoubleElementsVectorType(VTy);
516 VTy = VectorType::getTruncatedElementVectorType(VTy);
521 /// This static method returns a VectorType with half as many elements as the
522 /// input type and the same element type.
523 static VectorType *getHalfElementsVectorType(VectorType *VTy) {
524 auto EltCnt = VTy->getElementCount();
525 assert ((EltCnt.Min & 1) == 0 &&
526 "Cannot halve vector with odd number of elements.");
527 return VectorType::get(VTy->getElementType(), EltCnt/2);
530 /// This static method returns a VectorType with twice as many elements as the
531 /// input type and the same element type.
532 static VectorType *getDoubleElementsVectorType(VectorType *VTy) {
533 auto EltCnt = VTy->getElementCount();
534 assert((EltCnt.Min * 2ull) <= UINT_MAX && "Too many elements in vector");
535 return VectorType::get(VTy->getElementType(), EltCnt * 2);
538 /// Return true if the specified type is valid as a element type.
539 static bool isValidElementType(Type *ElemTy);
541 /// Return an ElementCount instance to represent the (possibly scalable)
542 /// number of elements in the vector.
543 inline ElementCount getElementCount() const;
545 /// Methods for support type inquiry through isa, cast, and dyn_cast.
546 static bool classof(const Type *T) {
547 return T->getTypeID() == FixedVectorTyID ||
548 T->getTypeID() == ScalableVectorTyID;
552 inline VectorType *VectorType::get(Type *ElementType, unsigned NumElements) {
553 return VectorType::get(ElementType, NumElements, false);
556 /// Class to represent fixed width SIMD vectors
557 class FixedVectorType : public VectorType {
559 FixedVectorType(Type *ElTy, unsigned NumElts)
560 : VectorType(ElTy, NumElts, FixedVectorTyID) {}
563 static FixedVectorType *get(Type *ElementType, unsigned NumElts);
565 static FixedVectorType *get(Type *ElementType, const FixedVectorType *FVTy) {
566 return get(ElementType, FVTy->getNumElements());
569 static FixedVectorType *getInteger(FixedVectorType *VTy) {
570 return cast<FixedVectorType>(VectorType::getInteger(VTy));
573 static FixedVectorType *getExtendedElementVectorType(FixedVectorType *VTy) {
574 return cast<FixedVectorType>(VectorType::getExtendedElementVectorType(VTy));
577 static FixedVectorType *getTruncatedElementVectorType(FixedVectorType *VTy) {
578 return cast<FixedVectorType>(
579 VectorType::getTruncatedElementVectorType(VTy));
582 static FixedVectorType *getSubdividedVectorType(FixedVectorType *VTy,
584 return cast<FixedVectorType>(
585 VectorType::getSubdividedVectorType(VTy, NumSubdivs));
588 static FixedVectorType *getHalfElementsVectorType(FixedVectorType *VTy) {
589 return cast<FixedVectorType>(VectorType::getHalfElementsVectorType(VTy));
592 static FixedVectorType *getDoubleElementsVectorType(FixedVectorType *VTy) {
593 return cast<FixedVectorType>(VectorType::getDoubleElementsVectorType(VTy));
596 static bool classof(const Type *T) {
597 return T->getTypeID() == FixedVectorTyID;
601 /// Class to represent scalable SIMD vectors
602 class ScalableVectorType : public VectorType {
604 ScalableVectorType(Type *ElTy, unsigned MinNumElts)
605 : VectorType(ElTy, MinNumElts, ScalableVectorTyID) {}
608 static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts);
610 static ScalableVectorType *get(Type *ElementType,
611 const ScalableVectorType *SVTy) {
612 return get(ElementType, SVTy->getMinNumElements());
615 static ScalableVectorType *getInteger(ScalableVectorType *VTy) {
616 return cast<ScalableVectorType>(VectorType::getInteger(VTy));
619 static ScalableVectorType *
620 getExtendedElementVectorType(ScalableVectorType *VTy) {
621 return cast<ScalableVectorType>(
622 VectorType::getExtendedElementVectorType(VTy));
625 static ScalableVectorType *
626 getTruncatedElementVectorType(ScalableVectorType *VTy) {
627 return cast<ScalableVectorType>(
628 VectorType::getTruncatedElementVectorType(VTy));
631 static ScalableVectorType *getSubdividedVectorType(ScalableVectorType *VTy,
633 return cast<ScalableVectorType>(
634 VectorType::getSubdividedVectorType(VTy, NumSubdivs));
637 static ScalableVectorType *
638 getHalfElementsVectorType(ScalableVectorType *VTy) {
639 return cast<ScalableVectorType>(VectorType::getHalfElementsVectorType(VTy));
642 static ScalableVectorType *
643 getDoubleElementsVectorType(ScalableVectorType *VTy) {
644 return cast<ScalableVectorType>(
645 VectorType::getDoubleElementsVectorType(VTy));
648 /// Get the minimum number of elements in this vector. The actual number of
649 /// elements in the vector is an integer multiple of this value.
650 uint64_t getMinNumElements() const { return ElementQuantity; }
652 static bool classof(const Type *T) {
653 return T->getTypeID() == ScalableVectorTyID;
657 inline ElementCount VectorType::getElementCount() const {
658 return ElementCount(ElementQuantity, isa<ScalableVectorType>(this));
661 /// Class to represent pointers.
662 class PointerType : public Type {
663 explicit PointerType(Type *ElType, unsigned AddrSpace);
668 PointerType(const PointerType &) = delete;
669 PointerType &operator=(const PointerType &) = delete;
671 /// This constructs a pointer to an object of the specified type in a numbered
673 static PointerType *get(Type *ElementType, unsigned AddressSpace);
675 /// This constructs a pointer to an object of the specified type in the
676 /// generic address space (address space zero).
677 static PointerType *getUnqual(Type *ElementType) {
678 return PointerType::get(ElementType, 0);
681 Type *getElementType() const { return PointeeTy; }
683 /// Return true if the specified type is valid as a element type.
684 static bool isValidElementType(Type *ElemTy);
686 /// Return true if we can load or store from a pointer to this type.
687 static bool isLoadableOrStorableType(Type *ElemTy);
689 /// Return the address space of the Pointer type.
690 inline unsigned getAddressSpace() const { return getSubclassData(); }
692 /// Implement support type inquiry through isa, cast, and dyn_cast.
693 static bool classof(const Type *T) {
694 return T->getTypeID() == PointerTyID;
698 Type *Type::getExtendedType() const {
700 isIntOrIntVectorTy() &&
701 "Original type expected to be a vector of integers or a scalar integer.");
702 if (auto *VTy = dyn_cast<VectorType>(this))
703 return VectorType::getExtendedElementVectorType(
704 const_cast<VectorType *>(VTy));
705 return cast<IntegerType>(this)->getExtendedType();
708 Type *Type::getWithNewBitWidth(unsigned NewBitWidth) const {
710 isIntOrIntVectorTy() &&
711 "Original type expected to be a vector of integers or a scalar integer.");
712 Type *NewType = getIntNTy(getContext(), NewBitWidth);
713 if (auto *VTy = dyn_cast<VectorType>(this))
714 NewType = VectorType::get(NewType, VTy->getElementCount());
718 unsigned Type::getPointerAddressSpace() const {
719 return cast<PointerType>(getScalarType())->getAddressSpace();
722 } // end namespace llvm
724 #endif // LLVM_IR_DERIVEDTYPES_H