LLVM 20.0.0git
DerivedTypes.h
Go to the documentation of this file.
1//===- llvm/DerivedTypes.h - Classes for handling data types ----*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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...
12//
13// The implementations of these classes live in the Type.cpp file.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_IR_DERIVEDTYPES_H
18#define LLVM_IR_DERIVEDTYPES_H
19
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/IR/Type.h"
27#include <cassert>
28#include <cstdint>
29
30namespace llvm {
31
32class Value;
33class APInt;
34class LLVMContext;
35
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
38/// Int64Ty.
39/// Integer representation type
40class IntegerType : public Type {
41 friend class LLVMContextImpl;
42
43protected:
44 explicit IntegerType(LLVMContext &C, unsigned NumBits) : Type(C, IntegerTyID){
45 setSubclassData(NumBits);
46 }
47
48public:
49 /// This enum is just used to hold constants we need for IntegerType.
50 enum {
51 MIN_INT_BITS = 1, ///< Minimum number of bits that can be specified
52 MAX_INT_BITS = (1<<23) ///< 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. SelectionDAG type legalization can require a
55 ///< power of 2 IntegerType, so limit to the largest representable power
56 ///< of 2, 8388608.
57 };
58
59 /// This static method is the primary way of constructing an IntegerType.
60 /// If an IntegerType with the same NumBits value was previously instantiated,
61 /// that instance will be returned. Otherwise a new one will be created. Only
62 /// one instance with a given NumBits value is ever created.
63 /// Get or create an IntegerType instance.
64 static IntegerType *get(LLVMContext &C, unsigned NumBits);
65
66 /// Returns type twice as wide the input type.
69 }
70
71 /// Get the number of bits in this IntegerType
72 unsigned getBitWidth() const { return getSubclassData(); }
73
74 /// Return a bitmask with ones set for all of the bits that can be set by an
75 /// unsigned version of this type. This is 0xFF for i8, 0xFFFF for i16, etc.
77 return ~uint64_t(0UL) >> (64-getBitWidth());
78 }
79
80 /// Return a uint64_t with just the most significant bit set (the sign bit, if
81 /// the value is treated as a signed number).
83 return 1ULL << (getBitWidth()-1);
84 }
85
86 /// For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
87 /// @returns a bit mask with ones set for all the bits of this type.
88 /// Get a bit mask for this type.
89 APInt getMask() const;
90
91 /// Methods for support type inquiry through isa, cast, and dyn_cast.
92 static bool classof(const Type *T) {
93 return T->getTypeID() == IntegerTyID;
94 }
95};
96
97unsigned Type::getIntegerBitWidth() const {
98 return cast<IntegerType>(this)->getBitWidth();
99}
100
101/// Class to represent function types
102///
103class FunctionType : public Type {
104 FunctionType(Type *Result, ArrayRef<Type*> Params, bool IsVarArgs);
105
106public:
107 FunctionType(const FunctionType &) = delete;
109
110 /// This static method is the primary way of constructing a FunctionType.
111 static FunctionType *get(Type *Result,
112 ArrayRef<Type*> Params, bool isVarArg);
113
114 /// Create a FunctionType taking no parameters.
115 static FunctionType *get(Type *Result, bool isVarArg);
116
117 /// Return true if the specified type is valid as a return type.
118 static bool isValidReturnType(Type *RetTy);
119
120 /// Return true if the specified type is valid as an argument type.
121 static bool isValidArgumentType(Type *ArgTy);
122
123 bool isVarArg() const { return getSubclassData()!=0; }
124 Type *getReturnType() const { return ContainedTys[0]; }
125
127
131 return ArrayRef(param_begin(), param_end());
132 }
133
134 /// Parameter type accessors.
135 Type *getParamType(unsigned i) const {
136 assert(i < getNumParams() && "getParamType() out of range!");
137 return ContainedTys[i + 1];
138 }
139
140 /// Return the number of fixed parameters this function type requires.
141 /// This does not consider varargs.
142 unsigned getNumParams() const { return NumContainedTys - 1; }
143
144 /// Methods for support type inquiry through isa, cast, and dyn_cast.
145 static bool classof(const Type *T) {
146 return T->getTypeID() == FunctionTyID;
147 }
148};
149static_assert(alignof(FunctionType) >= alignof(Type *),
150 "Alignment sufficient for objects appended to FunctionType");
151
152bool Type::isFunctionVarArg() const {
153 return cast<FunctionType>(this)->isVarArg();
154}
155
156Type *Type::getFunctionParamType(unsigned i) const {
157 return cast<FunctionType>(this)->getParamType(i);
158}
159
160unsigned Type::getFunctionNumParams() const {
161 return cast<FunctionType>(this)->getNumParams();
162}
163
164/// A handy container for a FunctionType+Callee-pointer pair, which can be
165/// passed around as a single entity. This assists in replacing the use of
166/// PointerType::getElementType() to access the function's type, since that's
167/// slated for removal as part of the [opaque pointer types] project.
169public:
170 // Allow implicit conversion from types which have a getFunctionType member
171 // (e.g. Function and InlineAsm).
172 template <typename T, typename U = decltype(&T::getFunctionType)>
174 : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
175
177 : FnTy(FnTy), Callee(Callee) {
178 assert((FnTy == nullptr) == (Callee == nullptr));
179 }
180
181 FunctionCallee(std::nullptr_t) {}
182
183 FunctionCallee() = default;
184
185 FunctionType *getFunctionType() { return FnTy; }
186
187 Value *getCallee() { return Callee; }
188
189 explicit operator bool() { return Callee; }
190
191private:
192 FunctionType *FnTy = nullptr;
193 Value *Callee = nullptr;
194};
195
196/// Class to represent struct types. There are two different kinds of struct
197/// types: Literal structs and Identified structs.
198///
199/// Literal struct types (e.g. { i32, i32 }) are uniqued structurally, and must
200/// always have a body when created. You can get one of these by using one of
201/// the StructType::get() forms.
202///
203/// Identified structs (e.g. %foo or %42) may optionally have a name and are not
204/// uniqued. The names for identified structs are managed at the LLVMContext
205/// level, so there can only be a single identified struct with a given name in
206/// a particular LLVMContext. Identified structs may also optionally be opaque
207/// (have no body specified). You get one of these by using one of the
208/// StructType::create() forms.
209///
210/// Independent of what kind of struct you have, the body of a struct type are
211/// laid out in memory consecutively with the elements directly one after the
212/// other (if the struct is packed) or (if not packed) with padding between the
213/// elements as defined by DataLayout (which is required to match what the code
214/// generator for a target expects).
215///
216class StructType : public Type {
218
219 enum {
220 /// This is the contents of the SubClassData field.
221 SCDB_HasBody = 1,
222 SCDB_Packed = 2,
223 SCDB_IsLiteral = 4,
224 SCDB_IsSized = 8,
225 SCDB_ContainsScalableVector = 16,
226 SCDB_NotContainsScalableVector = 32
227 };
228
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;
234
235public:
236 StructType(const StructType &) = delete;
237 StructType &operator=(const StructType &) = delete;
238
239 /// This creates an identified struct.
240 static StructType *create(LLVMContext &Context, StringRef Name);
241 static StructType *create(LLVMContext &Context);
242
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 return create(ArrayRef<Type *>({elt1, elts...}), Name);
254 }
255
256 /// This static method is the primary way to create a literal StructType.
257 static StructType *get(LLVMContext &Context, ArrayRef<Type*> Elements,
258 bool isPacked = false);
259
260 /// Create an empty structure type.
261 static StructType *get(LLVMContext &Context, bool isPacked = false);
262
263 /// This static method is a convenience method for creating structure types by
264 /// specifying the elements as arguments. Note that this method always returns
265 /// a non-packed struct, and requires at least one element type.
266 template <class... Tys>
267 static std::enable_if_t<are_base_of<Type, Tys...>::value, StructType *>
268 get(Type *elt1, Tys *... elts) {
269 assert(elt1 && "Cannot create a struct type with no elements with this");
270 LLVMContext &Ctx = elt1->getContext();
271 return StructType::get(Ctx, ArrayRef<Type *>({elt1, elts...}));
272 }
273
274 /// Return the type with the specified name, or null if there is none by that
275 /// name.
277
278 bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
279
280 /// Return true if this type is uniqued by structural equivalence, false if it
281 /// is a struct definition.
282 bool isLiteral() const { return (getSubclassData() & SCDB_IsLiteral) != 0; }
283
284 /// Return true if this is a type with an identity that has no body specified
285 /// yet. These prints as 'opaque' in .ll files.
286 bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
287
288 /// isSized - Return true if this is a sized type.
289 bool isSized(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
290
291 /// Returns true if this struct contains a scalable vector.
292 bool
293 containsScalableVectorType(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
294
295 /// Returns true if this struct contains homogeneous scalable vector types.
296 /// Note that the definition of homogeneous scalable vector type is not
297 /// recursive here. That means the following structure will return false
298 /// when calling this function.
299 /// {{<vscale x 2 x i32>, <vscale x 4 x i64>},
300 /// {<vscale x 2 x i32>, <vscale x 4 x i64>}}
302
303 /// Return true if this is a named struct that has a non-empty name.
304 bool hasName() const { return SymbolTableEntry != nullptr; }
305
306 /// Return the name for this struct type if it has an identity.
307 /// This may return an empty string for an unnamed struct type. Do not call
308 /// this on an literal type.
309 StringRef getName() const;
310
311 /// Change the name of this type to the specified name, or to a name with a
312 /// suffix if there is a collision. Do not call this on an literal type.
313 void setName(StringRef Name);
314
315 /// Specify a body for an opaque identified type.
316 void setBody(ArrayRef<Type*> Elements, bool isPacked = false);
317
318 template <typename... Tys>
319 std::enable_if_t<are_base_of<Type, Tys...>::value, void>
320 setBody(Type *elt1, Tys *... elts) {
321 assert(elt1 && "Cannot create a struct type with no elements with this");
322 setBody(ArrayRef<Type *>({elt1, elts...}));
323 }
324
325 /// Return true if the specified type is valid as a element type.
326 static bool isValidElementType(Type *ElemTy);
327
328 // Iterator access to the elements.
330
335 }
336
337 /// Return true if this is layout identical to the specified struct.
339
340 /// Random access to the elements
341 unsigned getNumElements() const { return NumContainedTys; }
342 Type *getElementType(unsigned N) const {
343 assert(N < NumContainedTys && "Element number out of range!");
344 return ContainedTys[N];
345 }
346 /// Given an index value into the type, return the type of the element.
347 Type *getTypeAtIndex(const Value *V) const;
348 Type *getTypeAtIndex(unsigned N) const { return getElementType(N); }
349 bool indexValid(const Value *V) const;
350 bool indexValid(unsigned Idx) const { return Idx < getNumElements(); }
351
352 /// Methods for support type inquiry through isa, cast, and dyn_cast.
353 static bool classof(const Type *T) {
354 return T->getTypeID() == StructTyID;
355 }
356};
357
358StringRef Type::getStructName() const {
359 return cast<StructType>(this)->getName();
360}
361
362unsigned Type::getStructNumElements() const {
363 return cast<StructType>(this)->getNumElements();
364}
365
366Type *Type::getStructElementType(unsigned N) const {
367 return cast<StructType>(this)->getElementType(N);
368}
369
370/// Class to represent array types.
371class ArrayType : public Type {
372 /// The element type of the array.
373 Type *ContainedType;
374 /// Number of elements in the array.
375 uint64_t NumElements;
376
377 ArrayType(Type *ElType, uint64_t NumEl);
378
379public:
380 ArrayType(const ArrayType &) = delete;
381 ArrayType &operator=(const ArrayType &) = delete;
382
383 uint64_t getNumElements() const { return NumElements; }
384 Type *getElementType() const { return ContainedType; }
385
386 /// This static method is the primary way to construct an ArrayType
387 static ArrayType *get(Type *ElementType, uint64_t NumElements);
388
389 /// Return true if the specified type is valid as a element type.
390 static bool isValidElementType(Type *ElemTy);
391
392 /// Methods for support type inquiry through isa, cast, and dyn_cast.
393 static bool classof(const Type *T) {
394 return T->getTypeID() == ArrayTyID;
395 }
396};
397
399 return cast<ArrayType>(this)->getNumElements();
400}
401
402/// Base class of all SIMD vector types
403class VectorType : public Type {
404 /// A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
405 /// minimum number of elements of type Ty contained within the vector, and
406 /// 'vscale x' indicates that the total element count is an integer multiple
407 /// of 'n', where the multiple is either guaranteed to be one, or is
408 /// statically unknown at compile time.
409 ///
410 /// If the multiple is known to be 1, then the extra term is discarded in
411 /// textual IR:
412 ///
413 /// <4 x i32> - a vector containing 4 i32s
414 /// <vscale x 4 x i32> - a vector containing an unknown integer multiple
415 /// of 4 i32s
416
417 /// The element type of the vector.
418 Type *ContainedType;
419
420protected:
421 /// The element quantity of this vector. The meaning of this value depends
422 /// on the type of vector:
423 /// - For FixedVectorType = <ElementQuantity x ty>, there are
424 /// exactly ElementQuantity elements in this vector.
425 /// - For ScalableVectorType = <vscale x ElementQuantity x ty>,
426 /// there are vscale * ElementQuantity elements in this vector, where
427 /// vscale is a runtime-constant integer greater than 0.
428 const unsigned ElementQuantity;
429
430 VectorType(Type *ElType, unsigned EQ, Type::TypeID TID);
431
432public:
433 VectorType(const VectorType &) = delete;
434 VectorType &operator=(const VectorType &) = delete;
435
436 Type *getElementType() const { return ContainedType; }
437
438 /// This static method is the primary way to construct an VectorType.
439 static VectorType *get(Type *ElementType, ElementCount EC);
440
441 static VectorType *get(Type *ElementType, unsigned NumElements,
442 bool Scalable) {
443 return VectorType::get(ElementType,
444 ElementCount::get(NumElements, Scalable));
445 }
446
447 static VectorType *get(Type *ElementType, const VectorType *Other) {
448 return VectorType::get(ElementType, Other->getElementCount());
449 }
450
451 /// This static method gets a VectorType with the same number of elements as
452 /// the input type, and the element type is an integer type of the same width
453 /// as the input element type.
455 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
456 assert(EltBits && "Element size must be of a non-zero size");
457 Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
458 return VectorType::get(EltTy, VTy->getElementCount());
459 }
460
461 /// This static method is like getInteger except that the element types are
462 /// twice as wide as the elements in the input type.
464 assert(VTy->isIntOrIntVectorTy() && "VTy expected to be a vector of ints.");
465 auto *EltTy = cast<IntegerType>(VTy->getElementType());
466 return VectorType::get(EltTy->getExtendedType(), VTy->getElementCount());
467 }
468
469 // This static method gets a VectorType with the same number of elements as
470 // the input type, and the element type is an integer or float type which
471 // is half as wide as the elements in the input type.
473 Type *EltTy;
474 if (VTy->getElementType()->isFloatingPointTy()) {
475 switch(VTy->getElementType()->getTypeID()) {
476 case DoubleTyID:
477 EltTy = Type::getFloatTy(VTy->getContext());
478 break;
479 case FloatTyID:
480 EltTy = Type::getHalfTy(VTy->getContext());
481 break;
482 default:
483 llvm_unreachable("Cannot create narrower fp vector element type");
484 }
485 } else {
486 unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
487 assert((EltBits & 1) == 0 &&
488 "Cannot truncate vector element with odd bit-width");
489 EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
490 }
491 return VectorType::get(EltTy, VTy->getElementCount());
492 }
493
494 // This static method returns a VectorType with a smaller number of elements
495 // of a larger type than the input element type. For example, a <16 x i8>
496 // subdivided twice would return <4 x i32>
497 static VectorType *getSubdividedVectorType(VectorType *VTy, int NumSubdivs) {
498 for (int i = 0; i < NumSubdivs; ++i) {
501 }
502 return VTy;
503 }
504
505 /// This static method returns a VectorType with half as many elements as the
506 /// input type and the same element type.
508 auto EltCnt = VTy->getElementCount();
509 assert(EltCnt.isKnownEven() &&
510 "Cannot halve vector with odd number of elements.");
511 return VectorType::get(VTy->getElementType(),
512 EltCnt.divideCoefficientBy(2));
513 }
514
515 /// This static method returns a VectorType with twice as many elements as the
516 /// input type and the same element type.
518 auto EltCnt = VTy->getElementCount();
519 assert((EltCnt.getKnownMinValue() * 2ull) <= UINT_MAX &&
520 "Too many elements in vector");
521 return VectorType::get(VTy->getElementType(), EltCnt * 2);
522 }
523
524 /// Return true if the specified type is valid as a element type.
525 static bool isValidElementType(Type *ElemTy);
526
527 /// Return an ElementCount instance to represent the (possibly scalable)
528 /// number of elements in the vector.
529 inline ElementCount getElementCount() const;
530
531 /// Methods for support type inquiry through isa, cast, and dyn_cast.
532 static bool classof(const Type *T) {
533 return T->getTypeID() == FixedVectorTyID ||
534 T->getTypeID() == ScalableVectorTyID;
535 }
536};
537
538/// Class to represent fixed width SIMD vectors
540protected:
541 FixedVectorType(Type *ElTy, unsigned NumElts)
542 : VectorType(ElTy, NumElts, FixedVectorTyID) {}
543
544public:
545 static FixedVectorType *get(Type *ElementType, unsigned NumElts);
546
547 static FixedVectorType *get(Type *ElementType, const FixedVectorType *FVTy) {
548 return get(ElementType, FVTy->getNumElements());
549 }
550
552 return cast<FixedVectorType>(VectorType::getInteger(VTy));
553 }
554
556 return cast<FixedVectorType>(VectorType::getExtendedElementVectorType(VTy));
557 }
558
560 return cast<FixedVectorType>(
562 }
563
565 int NumSubdivs) {
566 return cast<FixedVectorType>(
567 VectorType::getSubdividedVectorType(VTy, NumSubdivs));
568 }
569
571 return cast<FixedVectorType>(VectorType::getHalfElementsVectorType(VTy));
572 }
573
575 return cast<FixedVectorType>(VectorType::getDoubleElementsVectorType(VTy));
576 }
577
578 static bool classof(const Type *T) {
579 return T->getTypeID() == FixedVectorTyID;
580 }
581
582 unsigned getNumElements() const { return ElementQuantity; }
583};
584
585/// Class to represent scalable SIMD vectors
587protected:
588 ScalableVectorType(Type *ElTy, unsigned MinNumElts)
589 : VectorType(ElTy, MinNumElts, ScalableVectorTyID) {}
590
591public:
592 static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts);
593
594 static ScalableVectorType *get(Type *ElementType,
595 const ScalableVectorType *SVTy) {
596 return get(ElementType, SVTy->getMinNumElements());
597 }
598
600 return cast<ScalableVectorType>(VectorType::getInteger(VTy));
601 }
602
603 static ScalableVectorType *
605 return cast<ScalableVectorType>(
607 }
608
609 static ScalableVectorType *
611 return cast<ScalableVectorType>(
613 }
614
616 int NumSubdivs) {
617 return cast<ScalableVectorType>(
618 VectorType::getSubdividedVectorType(VTy, NumSubdivs));
619 }
620
621 static ScalableVectorType *
623 return cast<ScalableVectorType>(VectorType::getHalfElementsVectorType(VTy));
624 }
625
626 static ScalableVectorType *
628 return cast<ScalableVectorType>(
630 }
631
632 /// Get the minimum number of elements in this vector. The actual number of
633 /// elements in the vector is an integer multiple of this value.
634 unsigned getMinNumElements() const { return ElementQuantity; }
635
636 static bool classof(const Type *T) {
637 return T->getTypeID() == ScalableVectorTyID;
638 }
639};
640
642 return ElementCount::get(ElementQuantity, isa<ScalableVectorType>(this));
643}
644
645/// Class to represent pointers.
646class PointerType : public Type {
647 explicit PointerType(LLVMContext &C, unsigned AddrSpace);
648
649public:
650 PointerType(const PointerType &) = delete;
652
653 /// This constructs a pointer to an object of the specified type in a numbered
654 /// address space.
655 static PointerType *get(Type *ElementType, unsigned AddressSpace);
656 /// This constructs an opaque pointer to an object in a numbered address
657 /// space.
658 static PointerType *get(LLVMContext &C, unsigned AddressSpace);
659
660 /// This constructs a pointer to an object of the specified type in the
661 /// default address space (address space zero).
662 static PointerType *getUnqual(Type *ElementType) {
663 return PointerType::get(ElementType, 0);
664 }
665
666 /// This constructs an opaque pointer to an object in the
667 /// default address space (address space zero).
669 return PointerType::get(C, 0);
670 }
671
672 /// Return true if the specified type is valid as a element type.
673 static bool isValidElementType(Type *ElemTy);
674
675 /// Return true if we can load or store from a pointer to this type.
676 static bool isLoadableOrStorableType(Type *ElemTy);
677
678 /// Return the address space of the Pointer type.
679 inline unsigned getAddressSpace() const { return getSubclassData(); }
680
681 /// Implement support type inquiry through isa, cast, and dyn_cast.
682 static bool classof(const Type *T) {
683 return T->getTypeID() == PointerTyID;
684 }
685};
686
687Type *Type::getExtendedType() const {
688 assert(
690 "Original type expected to be a vector of integers or a scalar integer.");
691 if (auto *VTy = dyn_cast<VectorType>(this))
693 const_cast<VectorType *>(VTy));
694 return cast<IntegerType>(this)->getExtendedType();
695}
696
697Type *Type::getWithNewType(Type *EltTy) const {
698 if (auto *VTy = dyn_cast<VectorType>(this))
699 return VectorType::get(EltTy, VTy->getElementCount());
700 return EltTy;
701}
702
703Type *Type::getWithNewBitWidth(unsigned NewBitWidth) const {
704 assert(
706 "Original type expected to be a vector of integers or a scalar integer.");
707 return getWithNewType(getIntNTy(getContext(), NewBitWidth));
708}
709
710unsigned Type::getPointerAddressSpace() const {
711 return cast<PointerType>(getScalarType())->getAddressSpace();
712}
713
714/// Class to represent target extensions types, which are generally
715/// unintrospectable from target-independent optimizations.
716///
717/// Target extension types have a string name, and optionally have type and/or
718/// integer parameters. The exact meaning of any parameters is dependent on the
719/// target.
720class TargetExtType : public Type {
722 ArrayRef<unsigned> Ints);
723
724 // These strings are ultimately owned by the context.
725 StringRef Name;
726 unsigned *IntParams;
727
728public:
729 TargetExtType(const TargetExtType &) = delete;
731
732 /// Return a target extension type having the specified name and optional
733 /// type and integer parameters.
734 static TargetExtType *get(LLVMContext &Context, StringRef Name,
735 ArrayRef<Type *> Types = std::nullopt,
736 ArrayRef<unsigned> Ints = std::nullopt);
737
738 /// Return the name for this target extension type. Two distinct target
739 /// extension types may have the same name if their type or integer parameters
740 /// differ.
741 StringRef getName() const { return Name; }
742
743 /// Return the type parameters for this particular target extension type. If
744 /// there are no parameters, an empty array is returned.
747 }
748
753 }
754
755 Type *getTypeParameter(unsigned i) const { return getContainedType(i); }
756 unsigned getNumTypeParameters() const { return getNumContainedTypes(); }
757
758 /// Return the integer parameters for this particular target extension type.
759 /// If there are no parameters, an empty array is returned.
761 return ArrayRef(IntParams, getNumIntParameters());
762 }
763
764 unsigned getIntParameter(unsigned i) const { return IntParams[i]; }
765 unsigned getNumIntParameters() const { return getSubclassData(); }
766
767 enum Property {
768 /// zeroinitializer is valid for this target extension type.
769 HasZeroInit = 1U << 0,
770 /// This type may be used as the value type of a global variable.
771 CanBeGlobal = 1U << 1,
772 };
773
774 /// Returns true if the target extension type contains the given property.
775 bool hasProperty(Property Prop) const;
776
777 /// Returns an underlying layout type for the target extension type. This
778 /// type can be used to query size and alignment information, if it is
779 /// appropriate (although note that the layout type may also be void). It is
780 /// not legal to bitcast between this type and the layout type, however.
781 Type *getLayoutType() const;
782
783 /// Methods for support type inquiry through isa, cast, and dyn_cast.
784 static bool classof(const Type *T) { return T->getTypeID() == TargetExtTyID; }
785};
786
787StringRef Type::getTargetExtName() const {
788 return cast<TargetExtType>(this)->getName();
789}
790
791} // end namespace llvm
792
793#endif // LLVM_IR_DERIVEDTYPES_H
return RetTy
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live value
std::string Name
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
Class for arbitrary precision integers.
Definition: APInt.h:78
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Class to represent array types.
Definition: DerivedTypes.h:371
uint64_t getNumElements() const
Definition: DerivedTypes.h:383
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:647
ArrayType & operator=(const ArrayType &)=delete
ArrayType(const ArrayType &)=delete
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:393
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Definition: Type.cpp:635
Type * getElementType() const
Definition: DerivedTypes.h:384
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition: TypeSize.h:317
Class to represent fixed width SIMD vectors.
Definition: DerivedTypes.h:539
unsigned getNumElements() const
Definition: DerivedTypes.h:582
static FixedVectorType * getDoubleElementsVectorType(FixedVectorType *VTy)
Definition: DerivedTypes.h:574
static FixedVectorType * getInteger(FixedVectorType *VTy)
Definition: DerivedTypes.h:551
static FixedVectorType * getSubdividedVectorType(FixedVectorType *VTy, int NumSubdivs)
Definition: DerivedTypes.h:564
static FixedVectorType * getExtendedElementVectorType(FixedVectorType *VTy)
Definition: DerivedTypes.h:555
FixedVectorType(Type *ElTy, unsigned NumElts)
Definition: DerivedTypes.h:541
static FixedVectorType * get(Type *ElementType, const FixedVectorType *FVTy)
Definition: DerivedTypes.h:547
static FixedVectorType * getTruncatedElementVectorType(FixedVectorType *VTy)
Definition: DerivedTypes.h:559
static bool classof(const Type *T)
Definition: DerivedTypes.h:578
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Definition: Type.cpp:680
static FixedVectorType * getHalfElementsVectorType(FixedVectorType *VTy)
Definition: DerivedTypes.h:570
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Definition: DerivedTypes.h:168
FunctionCallee(std::nullptr_t)
Definition: DerivedTypes.h:181
FunctionType * getFunctionType()
Definition: DerivedTypes.h:185
FunctionCallee()=default
FunctionCallee(FunctionType *FnTy, Value *Callee)
Definition: DerivedTypes.h:176
Class to represent function types.
Definition: DerivedTypes.h:103
param_iterator param_begin() const
Definition: DerivedTypes.h:128
static bool isValidArgumentType(Type *ArgTy)
Return true if the specified type is valid as an argument type.
Definition: Type.cpp:351
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Definition: DerivedTypes.h:142
Type::subtype_iterator param_iterator
Definition: DerivedTypes.h:126
Type * getParamType(unsigned i) const
Parameter type accessors.
Definition: DerivedTypes.h:135
static bool isValidReturnType(Type *RetTy)
Return true if the specified type is valid as a return type.
Definition: Type.cpp:346
FunctionType(const FunctionType &)=delete
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
FunctionType & operator=(const FunctionType &)=delete
bool isVarArg() const
Definition: DerivedTypes.h:123
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:145
Type * getReturnType() const
Definition: DerivedTypes.h:124
param_iterator param_end() const
Definition: DerivedTypes.h:129
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Class to represent integer types.
Definition: DerivedTypes.h:40
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:266
@ MIN_INT_BITS
Minimum number of bits that can be specified.
Definition: DerivedTypes.h:51
@ MAX_INT_BITS
Maximum number of bits that can be specified.
Definition: DerivedTypes.h:52
uint64_t getSignBit() const
Return a uint64_t with just the most significant bit set (the sign bit, if the value is treated as a ...
Definition: DerivedTypes.h:82
APInt getMask() const
For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
Definition: Type.cpp:290
IntegerType * getExtendedType() const
Returns type twice as wide the input type.
Definition: DerivedTypes.h:67
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Definition: DerivedTypes.h:72
uint64_t getBitMask() const
Return a bitmask with ones set for all of the bits that can be set by an unsigned version of this typ...
Definition: DerivedTypes.h:76
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:92
IntegerType(LLVMContext &C, unsigned NumBits)
Definition: DerivedTypes.h:44
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Class to represent pointers.
Definition: DerivedTypes.h:646
static bool isLoadableOrStorableType(Type *ElemTy)
Return true if we can load or store from a pointer to this type.
Definition: Type.cpp:758
PointerType(const PointerType &)=delete
static PointerType * getUnqual(LLVMContext &C)
This constructs an opaque pointer to an object in the default address space (address space zero).
Definition: DerivedTypes.h:668
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static bool classof(const Type *T)
Implement support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:682
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:752
PointerType & operator=(const PointerType &)=delete
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:662
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:679
Class to represent scalable SIMD vectors.
Definition: DerivedTypes.h:586
static ScalableVectorType * get(Type *ElementType, const ScalableVectorType *SVTy)
Definition: DerivedTypes.h:594
static ScalableVectorType * getInteger(ScalableVectorType *VTy)
Definition: DerivedTypes.h:599
static ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
Definition: Type.cpp:701
static bool classof(const Type *T)
Definition: DerivedTypes.h:636
static ScalableVectorType * getExtendedElementVectorType(ScalableVectorType *VTy)
Definition: DerivedTypes.h:604
static ScalableVectorType * getHalfElementsVectorType(ScalableVectorType *VTy)
Definition: DerivedTypes.h:622
static ScalableVectorType * getSubdividedVectorType(ScalableVectorType *VTy, int NumSubdivs)
Definition: DerivedTypes.h:615
static ScalableVectorType * getDoubleElementsVectorType(ScalableVectorType *VTy)
Definition: DerivedTypes.h:627
unsigned getMinNumElements() const
Get the minimum number of elements in this vector.
Definition: DerivedTypes.h:634
ScalableVectorType(Type *ElTy, unsigned MinNumElts)
Definition: DerivedTypes.h:588
static ScalableVectorType * getTruncatedElementVectorType(ScalableVectorType *VTy)
Definition: DerivedTypes.h:610
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Definition: SmallPtrSet.h:346
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Class to represent struct types.
Definition: DerivedTypes.h:216
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:353
static std::enable_if_t< are_base_of< Type, Tys... >::value, StructType * > create(StringRef Name, Type *elt1, Tys *... elts)
Definition: DerivedTypes.h:251
bool indexValid(const Value *V) const
Definition: Type.cpp:606
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition: Type.cpp:361
element_iterator element_end() const
Definition: DerivedTypes.h:332
StructType(const StructType &)=delete
ArrayRef< Type * > elements() const
Definition: DerivedTypes.h:333
void setBody(ArrayRef< Type * > Elements, bool isPacked=false)
Specify a body for an opaque identified type.
Definition: Type.cpp:433
bool containsHomogeneousScalableVectorTypes() const
Returns true if this struct contains homogeneous scalable vector types.
Definition: Type.cpp:423
element_iterator element_begin() const
Definition: DerivedTypes.h:331
static StructType * getTypeByName(LLVMContext &C, StringRef Name)
Return the type with the specified name, or null if there is none by that name.
Definition: Type.cpp:620
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:501
bool isPacked() const
Definition: DerivedTypes.h:278
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:585
unsigned getNumElements() const
Random access to the elements.
Definition: DerivedTypes.h:341
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
isSized - Return true if this is a sized type.
Definition: Type.cpp:540
bool containsScalableVectorType(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Returns true if this struct contains a scalable vector.
Definition: Type.cpp:388
Type * getTypeAtIndex(unsigned N) const
Definition: DerivedTypes.h:348
StructType & operator=(const StructType &)=delete
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
Definition: Type.cpp:450
bool isLayoutIdentical(StructType *Other) const
Return true if this is layout identical to the specified struct.
Definition: Type.cpp:591
Type * getTypeAtIndex(const Value *V) const
Given an index value into the type, return the type of the element.
Definition: Type.cpp:600
bool hasName() const
Return true if this is a named struct that has a non-empty name.
Definition: DerivedTypes.h:304
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
Definition: DerivedTypes.h:282
bool indexValid(unsigned Idx) const
Definition: DerivedTypes.h:350
bool isOpaque() const
Return true if this is a type with an identity that has no body specified yet.
Definition: DerivedTypes.h:286
Type * getElementType(unsigned N) const
Definition: DerivedTypes.h:342
Type::subtype_iterator element_iterator
Definition: DerivedTypes.h:329
static std::enable_if_t< are_base_of< Type, Tys... >::value, StructType * > get(Type *elt1, Tys *... elts)
This static method is a convenience method for creating structure types by specifying the elements as...
Definition: DerivedTypes.h:268
std::enable_if_t< are_base_of< Type, Tys... >::value, void > setBody(Type *elt1, Tys *... elts)
Definition: DerivedTypes.h:320
StringRef getName() const
Return the name for this struct type if it has an identity.
Definition: Type.cpp:578
Symbol info for RuntimeDyld.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
Definition: DerivedTypes.h:720
ArrayRef< Type * > type_params() const
Return the type parameters for this particular target extension type.
Definition: DerivedTypes.h:745
unsigned getNumIntParameters() const
Definition: DerivedTypes.h:765
static TargetExtType * get(LLVMContext &Context, StringRef Name, ArrayRef< Type * > Types=std::nullopt, ArrayRef< unsigned > Ints=std::nullopt)
Return a target extension type having the specified name and optional type and integer parameters.
Definition: Type.cpp:784
type_param_iterator type_param_end() const
Definition: DerivedTypes.h:751
Type::subtype_iterator type_param_iterator
Definition: DerivedTypes.h:749
Type * getTypeParameter(unsigned i) const
Definition: DerivedTypes.h:755
unsigned getNumTypeParameters() const
Definition: DerivedTypes.h:756
ArrayRef< unsigned > int_params() const
Return the integer parameters for this particular target extension type.
Definition: DerivedTypes.h:760
type_param_iterator type_param_begin() const
Definition: DerivedTypes.h:750
unsigned getIntParameter(unsigned i) const
Definition: DerivedTypes.h:764
TargetExtType(const TargetExtType &)=delete
bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
Definition: Type.cpp:843
TargetExtType & operator=(const TargetExtType &)=delete
@ HasZeroInit
zeroinitializer is valid for this target extension type.
Definition: DerivedTypes.h:769
@ CanBeGlobal
This type may be used as the value type of a global variable.
Definition: DerivedTypes.h:771
StringRef getName() const
Return the name for this target extension type.
Definition: DerivedTypes.h:741
Type * getLayoutType() const
Returns an underlying layout type for the target extension type.
Definition: Type.cpp:839
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:784
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
static Type * getHalfTy(LLVMContext &C)
unsigned getIntegerBitWidth() const
Type * getStructElementType(unsigned N) const
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:230
StringRef getStructName() const
Type *const * subtype_iterator
Definition: Type.h:352
unsigned getStructNumElements() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
uint64_t getArrayNumElements() const
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
@ FunctionTyID
Functions.
Definition: Type.h:71
@ ArrayTyID
Arrays.
Definition: Type.h:74
@ TargetExtTyID
Target extension type.
Definition: Type.h:78
@ ScalableVectorTyID
Scalable SIMD vector type.
Definition: Type.h:76
@ FloatTyID
32-bit floating point type
Definition: Type.h:58
@ StructTyID
Structures.
Definition: Type.h:73
@ IntegerTyID
Arbitrary bit width integers.
Definition: Type.h:70
@ FixedVectorTyID
Fixed width SIMD vector type.
Definition: Type.h:75
@ DoubleTyID
64-bit floating point type
Definition: Type.h:59
@ PointerTyID
Pointers.
Definition: Type.h:72
unsigned getNumContainedTypes() const
Return the number of types in the derived type.
Definition: Type.h:378
unsigned NumContainedTys
Keeps track of how many Type*'s there are in the ContainedTys list.
Definition: Type.h:106
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
StringRef getTargetExtName() const
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Type * getWithNewBitWidth(unsigned NewBitWidth) const
Given an integer or vector type, change the lane bitwidth to NewBitwidth, whilst keeping the old numb...
Type * getWithNewType(Type *EltTy) const
Given vector type, change the element type, whilst keeping the old number of elements.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
Type *const * ContainedTys
A pointer to the array of Types contained by this Type.
Definition: Type.h:113
unsigned getSubclassData() const
Definition: Type.h:97
bool isFunctionVarArg() const
void setSubclassData(unsigned val)
Definition: Type.h:99
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
Definition: Type.h:184
Type * getExtendedType() const
Given scalar/vector integer type, returns a type with elements twice as wide as in the original type.
static Type * getFloatTy(LLVMContext &C)
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:136
Type * getFunctionParamType(unsigned i) const
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Type * getContainedType(unsigned i) const
This method is used to implement the type iterator (defined at the end of the file).
Definition: Type.h:372
unsigned getFunctionNumParams() const
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:343
LLVM Value Representation.
Definition: Value.h:74
Base class of all SIMD vector types.
Definition: DerivedTypes.h:403
static bool isValidElementType(Type *ElemTy)
Return true if the specified type is valid as a element type.
Definition: Type.cpp:671
static VectorType * getHalfElementsVectorType(VectorType *VTy)
This static method returns a VectorType with half as many elements as the input type and the same ele...
Definition: DerivedTypes.h:507
static VectorType * getExtendedElementVectorType(VectorType *VTy)
This static method is like getInteger except that the element types are twice as wide as the elements...
Definition: DerivedTypes.h:463
static bool classof(const Type *T)
Methods for support type inquiry through isa, cast, and dyn_cast.
Definition: DerivedTypes.h:532
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:641
static VectorType * getSubdividedVectorType(VectorType *VTy, int NumSubdivs)
Definition: DerivedTypes.h:497
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
Definition: DerivedTypes.h:454
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:664
const unsigned ElementQuantity
The element quantity of this vector.
Definition: DerivedTypes.h:428
static VectorType * get(Type *ElementType, const VectorType *Other)
Definition: DerivedTypes.h:447
static VectorType * getTruncatedElementVectorType(VectorType *VTy)
Definition: DerivedTypes.h:472
VectorType & operator=(const VectorType &)=delete
static VectorType * getDoubleElementsVectorType(VectorType *VTy)
This static method returns a VectorType with twice as many elements as the input type and the same el...
Definition: DerivedTypes.h:517
static VectorType * get(Type *ElementType, unsigned NumElements, bool Scalable)
Definition: DerivedTypes.h:441
VectorType(const VectorType &)=delete
Type * getElementType() const
Definition: DerivedTypes.h:436
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
Definition: MsgPackReader.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
std::conjunction< std::is_base_of< T, Ts >... > are_base_of
traits class for checking whether type T is a base class for all the given types in the variadic list...
Definition: STLExtras.h:134
AddressSpace
Definition: NVPTXBaseInfo.h:21
@ Other
Any other memory.
#define N
#define EQ(a, b)
Definition: regexec.c:112