Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/DerivedTypes.h
Line
Count
Source (jump to first uncovered line)
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"
24
#include "llvm/Support/Casting.h"
25
#include "llvm/Support/Compiler.h"
26
#include "llvm/Support/ScalableSize.h"
27
#include <cassert>
28
#include <cstdint>
29
30
namespace llvm {
31
32
class Value;
33
class APInt;
34
class 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
40
class IntegerType : public Type {
41
  friend class LLVMContextImpl;
42
43
protected:
44
710k
  explicit IntegerType(LLVMContext &C, unsigned NumBits) : Type(C, IntegerTyID){
45
710k
    setSubclassData(NumBits);
46
710k
  }
47
48
public:
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<<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
55
      ///< bits.
56
  };
57
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);
64
65
  /// Get the number of bits in this IntegerType
66
2.17G
  unsigned getBitWidth() const { return getSubclassData(); }
67
68
  /// Return a bitmask with ones set for all of the bits that can be set by an
69
  /// unsigned version of this type. This is 0xFF for i8, 0xFFFF for i16, etc.
70
213
  uint64_t getBitMask() const {
71
213
    return ~uint64_t(0UL) >> (64-getBitWidth());
72
213
  }
73
74
  /// Return a uint64_t with just the most significant bit set (the sign bit, if
75
  /// the value is treated as a signed number).
76
0
  uint64_t getSignBit() const {
77
0
    return 1ULL << (getBitWidth()-1);
78
0
  }
79
80
  /// For example, this is 0xFF for an 8 bit integer, 0xFFFF for i16, etc.
81
  /// @returns a bit mask with ones set for all the bits of this type.
82
  /// Get a bit mask for this type.
83
  APInt getMask() const;
84
85
  /// This method determines if the width of this IntegerType is a power-of-2
86
  /// in terms of 8 bit bytes.
87
  /// @returns true if this is a power-of-2 byte width.
88
  /// Is this a power-of-2 byte-width IntegerType ?
89
  bool isPowerOf2ByteWidth() const;
90
91
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
92
57.8M
  static bool classof(const Type *T) {
93
57.8M
    return T->getTypeID() == IntegerTyID;
94
57.8M
  }
95
};
96
97
1.37G
unsigned Type::getIntegerBitWidth() const {
98
1.37G
  return cast<IntegerType>(this)->getBitWidth();
99
1.37G
}
100
101
/// Class to represent function types
102
///
103
class FunctionType : public Type {
104
  FunctionType(Type *Result, ArrayRef<Type*> Params, bool IsVarArgs);
105
106
public:
107
  FunctionType(const FunctionType &) = delete;
108
  FunctionType &operator=(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
45.0M
  bool isVarArg() const { return getSubclassData()!=0; }
124
44.5M
  Type *getReturnType() const { return ContainedTys[0]; }
125
126
  using param_iterator = Type::subtype_iterator;
127
128
15.2M
  param_iterator param_begin() const { return ContainedTys + 1; }
129
15.0M
  param_iterator param_end() const { return &ContainedTys[NumContainedTys]; }
130
13.8M
  ArrayRef<Type *> params() const {
131
13.8M
    return makeArrayRef(param_begin(), param_end());
132
13.8M
  }
133
134
  /// Parameter type accessors.
135
32.9M
  Type *getParamType(unsigned i) const { return ContainedTys[i+1]; }
136
137
  /// Return the number of fixed parameters this function type requires.
138
  /// This does not consider varargs.
139
26.6M
  unsigned getNumParams() const { return NumContainedTys - 1; }
140
141
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
142
6.28M
  static bool classof(const Type *T) {
143
6.28M
    return T->getTypeID() == FunctionTyID;
144
6.28M
  }
145
};
146
static_assert(alignof(FunctionType) >= alignof(Type *),
147
              "Alignment sufficient for objects appended to FunctionType");
148
149
0
bool Type::isFunctionVarArg() const {
150
0
  return cast<FunctionType>(this)->isVarArg();
151
0
}
152
153
38
Type *Type::getFunctionParamType(unsigned i) const {
154
38
  return cast<FunctionType>(this)->getParamType(i);
155
38
}
156
157
0
unsigned Type::getFunctionNumParams() const {
158
0
  return cast<FunctionType>(this)->getNumParams();
159
0
}
160
161
/// A handy container for a FunctionType+Callee-pointer pair, which can be
162
/// passed around as a single entity. This assists in replacing the use of
163
/// PointerType::getElementType() to access the function's type, since that's
164
/// slated for removal as part of the [opaque pointer types] project.
165
class FunctionCallee {
166
public:
167
  // Allow implicit conversion from types which have a getFunctionType member
168
  // (e.g. Function and InlineAsm).
169
  template <typename T, typename U = decltype(&T::getFunctionType)>
170
  FunctionCallee(T *Fn)
171
25.3k
      : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
llvm::FunctionCallee::FunctionCallee<llvm::Function, llvm::FunctionType* (llvm::Function::*)() const>(llvm::Function*)
Line
Count
Source
171
25.3k
      : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
llvm::FunctionCallee::FunctionCallee<llvm::InlineAsm, llvm::FunctionType* (llvm::InlineAsm::*)() const>(llvm::InlineAsm*)
Line
Count
Source
171
59
      : FnTy(Fn ? Fn->getFunctionType() : nullptr), Callee(Fn) {}
172
173
  FunctionCallee(FunctionType *FnTy, Value *Callee)
174
4.11M
      : FnTy(FnTy), Callee(Callee) {
175
4.11M
    assert((FnTy == nullptr) == (Callee == nullptr));
176
4.11M
  }
177
178
180k
  FunctionCallee(std::nullptr_t) {}
179
180
298k
  FunctionCallee() = default;
181
182
112k
  FunctionType *getFunctionType() { return FnTy; }
183
184
4.15M
  Value *getCallee() { return Callee; }
185
186
23.2k
  explicit operator bool() { return Callee; }
187
188
private:
189
  FunctionType *FnTy = nullptr;
190
  Value *Callee = nullptr;
191
};
192
193
/// Common super class of ArrayType, StructType and VectorType.
194
class CompositeType : public Type {
195
protected:
196
800k
  explicit CompositeType(LLVMContext &C, TypeID tid) : Type(C, tid) {}
197
198
public:
199
  /// Given an index value into the type, return the type of the element.
200
  Type *getTypeAtIndex(const Value *V) const;
201
  Type *getTypeAtIndex(unsigned Idx) const;
202
  bool indexValid(const Value *V) const;
203
  bool indexValid(unsigned Idx) const;
204
205
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
206
112M
  static bool classof(const Type *T) {
207
112M
    return T->getTypeID() == ArrayTyID ||
208
112M
           
T->getTypeID() == StructTyID78.1M
||
209
112M
           
T->getTypeID() == VectorTyID7.68M
;
210
112M
  }
211
};
212
213
/// Class to represent struct types. There are two different kinds of struct
214
/// types: Literal structs and Identified structs.
215
///
216
/// Literal struct types (e.g. { i32, i32 }) are uniqued structurally, and must
217
/// always have a body when created.  You can get one of these by using one of
218
/// the StructType::get() forms.
219
///
220
/// Identified structs (e.g. %foo or %42) may optionally have a name and are not
221
/// uniqued.  The names for identified structs are managed at the LLVMContext
222
/// level, so there can only be a single identified struct with a given name in
223
/// a particular LLVMContext.  Identified structs may also optionally be opaque
224
/// (have no body specified).  You get one of these by using one of the
225
/// StructType::create() forms.
226
///
227
/// Independent of what kind of struct you have, the body of a struct type are
228
/// laid out in memory consecutively with the elements directly one after the
229
/// other (if the struct is packed) or (if not packed) with padding between the
230
/// elements as defined by DataLayout (which is required to match what the code
231
/// generator for a target expects).
232
///
233
class StructType : public CompositeType {
234
281k
  StructType(LLVMContext &C) : CompositeType(C, StructTyID) {}
235
236
  enum {
237
    /// This is the contents of the SubClassData field.
238
    SCDB_HasBody = 1,
239
    SCDB_Packed = 2,
240
    SCDB_IsLiteral = 4,
241
    SCDB_IsSized = 8
242
  };
243
244
  /// For a named struct that actually has a name, this is a pointer to the
245
  /// symbol table entry (maintained by LLVMContext) for the struct.
246
  /// This is null if the type is an literal struct or if it is a identified
247
  /// type that has an empty name.
248
  void *SymbolTableEntry = nullptr;
249
250
public:
251
  StructType(const StructType &) = delete;
252
  StructType &operator=(const StructType &) = delete;
253
254
  /// This creates an identified struct.
255
  static StructType *create(LLVMContext &Context, StringRef Name);
256
  static StructType *create(LLVMContext &Context);
257
258
  static StructType *create(ArrayRef<Type *> Elements, StringRef Name,
259
                            bool isPacked = false);
260
  static StructType *create(ArrayRef<Type *> Elements);
261
  static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements,
262
                            StringRef Name, bool isPacked = false);
263
  static StructType *create(LLVMContext &Context, ArrayRef<Type *> Elements);
264
  template <class... Tys>
265
  static typename std::enable_if<are_base_of<Type, Tys...>::value,
266
                                 StructType *>::type
267
9.14k
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
9.14k
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
9.14k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
9.14k
    return create(StructFields, Name);
271
9.14k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::create<llvm::Type>(llvm::StringRef, llvm::Type*, llvm::Type*)
Line
Count
Source
267
493
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
493
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
493
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
493
    return create(StructFields, Name);
271
493
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::create<llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::Type>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*, llvm::PointerType*, llvm::Type*)
Line
Count
Source
267
166
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
166
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
166
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
166
    return create(StructFields, Name);
271
166
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::IntegerType, llvm::ArrayType>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::ArrayType*)
Line
Count
Source
267
1.98k
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
1.98k
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
1.98k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
1.98k
    return create(StructFields, Name);
271
1.98k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*)
Line
Count
Source
267
1.54k
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
1.54k
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
1.54k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
1.54k
    return create(StructFields, Name);
271
1.54k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::ArrayType>(llvm::StringRef, llvm::Type*, llvm::ArrayType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::IntegerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
1.54k
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
1.54k
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
1.54k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
1.54k
    return create(StructFields, Name);
271
1.54k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::ArrayType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::ArrayType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::IntegerType, llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
165
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
165
    return create(StructFields, Name);
271
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
606
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
606
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
606
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
606
    return create(StructFields, Name);
271
606
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
267
606
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
606
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
606
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
606
    return create(StructFields, Name);
271
606
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::StringRef, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
267
606
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
606
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
606
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
606
    return create(StructFields, Name);
271
606
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::create<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType>(llvm::StringRef, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
267
606
  create(StringRef Name, Type *elt1, Tys *... elts) {
268
606
    assert(elt1 && "Cannot create a struct type with no elements with this");
269
606
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
270
606
    return create(StructFields, Name);
271
606
  }
272
273
  /// This static method is the primary way to create a literal StructType.
274
  static StructType *get(LLVMContext &Context, ArrayRef<Type*> Elements,
275
                         bool isPacked = false);
276
277
  /// Create an empty structure type.
278
  static StructType *get(LLVMContext &Context, bool isPacked = false);
279
280
  /// This static method is a convenience method for creating structure types by
281
  /// specifying the elements as arguments. Note that this method always returns
282
  /// a non-packed struct, and requires at least one element type.
283
  template <class... Tys>
284
  static typename std::enable_if<are_base_of<Type, Tys...>::value,
285
                                 StructType *>::type
286
71.1k
  get(Type *elt1, Tys *... elts) {
287
71.1k
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
71.1k
    LLVMContext &Ctx = elt1->getContext();
289
71.1k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
71.1k
    return llvm::StructType::get(Ctx, StructFields);
291
71.1k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::get<llvm::Type>(llvm::Type*, llvm::Type*)
Line
Count
Source
286
33.9k
  get(Type *elt1, Tys *... elts) {
287
33.9k
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
33.9k
    LLVMContext &Ctx = elt1->getContext();
289
33.9k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
33.9k
    return llvm::StructType::get(Ctx, StructFields);
291
33.9k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::get<llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type>(llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
286
1.72k
  get(Type *elt1, Tys *... elts) {
287
1.72k
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
1.72k
    LLVMContext &Ctx = elt1->getContext();
289
1.72k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
1.72k
    return llvm::StructType::get(Ctx, StructFields);
291
1.72k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::IntegerType>(llvm::Type*, llvm::PointerType*, llvm::IntegerType*)
Line
Count
Source
286
27
  get(Type *elt1, Tys *... elts) {
287
27
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
27
    LLVMContext &Ctx = elt1->getContext();
289
27
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
27
    return llvm::StructType::get(Ctx, StructFields);
291
27
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::Type, llvm::PointerType>(llvm::Type*, llvm::Type*, llvm::PointerType*)
Line
Count
Source
286
2.18k
  get(Type *elt1, Tys *... elts) {
287
2.18k
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
2.18k
    LLVMContext &Ctx = elt1->getContext();
289
2.18k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
2.18k
    return llvm::StructType::get(Ctx, StructFields);
291
2.18k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::IntegerType>(llvm::Type*, llvm::IntegerType*)
Line
Count
Source
286
31.9k
  get(Type *elt1, Tys *... elts) {
287
31.9k
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
31.9k
    LLVMContext &Ctx = elt1->getContext();
289
31.9k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
31.9k
    return llvm::StructType::get(Ctx, StructFields);
291
31.9k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::get<llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type, llvm::Type>(llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*, llvm::Type*)
Line
Count
Source
286
71
  get(Type *elt1, Tys *... elts) {
287
71
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
71
    LLVMContext &Ctx = elt1->getContext();
289
71
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
71
    return llvm::StructType::get(Ctx, StructFields);
291
71
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::ArrayType, llvm::ArrayType, llvm::ArrayType, llvm::IntegerType, llvm::ArrayType, llvm::Type, llvm::Type>::value, llvm::StructType*>::type llvm::StructType::get<llvm::ArrayType, llvm::ArrayType, llvm::ArrayType, llvm::IntegerType, llvm::ArrayType, llvm::Type, llvm::Type>(llvm::Type*, llvm::ArrayType*, llvm::ArrayType*, llvm::ArrayType*, llvm::IntegerType*, llvm::ArrayType*, llvm::Type*, llvm::Type*)
Line
Count
Source
286
68
  get(Type *elt1, Tys *... elts) {
287
68
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
68
    LLVMContext &Ctx = elt1->getContext();
289
68
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
68
    return llvm::StructType::get(Ctx, StructFields);
291
68
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType>(llvm::Type*, llvm::PointerType*)
Line
Count
Source
286
185
  get(Type *elt1, Tys *... elts) {
287
185
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
185
    LLVMContext &Ctx = elt1->getContext();
289
185
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
185
    return llvm::StructType::get(Ctx, StructFields);
291
185
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::ArrayType>(llvm::Type*, llvm::ArrayType*)
Line
Count
Source
286
19
  get(Type *elt1, Tys *... elts) {
287
19
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
19
    LLVMContext &Ctx = elt1->getContext();
289
19
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
19
    return llvm::StructType::get(Ctx, StructFields);
291
19
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::PointerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
286
559
  get(Type *elt1, Tys *... elts) {
287
559
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
559
    LLVMContext &Ctx = elt1->getContext();
289
559
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
559
    return llvm::StructType::get(Ctx, StructFields);
291
559
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::Type, llvm::Type, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::Type, llvm::Type, llvm::ArrayType>(llvm::Type*, llvm::Type*, llvm::Type*, llvm::ArrayType*)
Line
Count
Source
286
113
  get(Type *elt1, Tys *... elts) {
287
113
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
113
    LLVMContext &Ctx = elt1->getContext();
289
113
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
113
    return llvm::StructType::get(Ctx, StructFields);
291
113
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::IntegerType, llvm::ArrayType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::IntegerType, llvm::IntegerType, llvm::ArrayType>(llvm::Type*, llvm::IntegerType*, llvm::IntegerType*, llvm::ArrayType*)
Line
Count
Source
286
126
  get(Type *elt1, Tys *... elts) {
287
126
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
126
    LLVMContext &Ctx = elt1->getContext();
289
126
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
126
    return llvm::StructType::get(Ctx, StructFields);
291
126
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::IntegerType, llvm::PointerType, llvm::PointerType>(llvm::Type*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
286
11
  get(Type *elt1, Tys *... elts) {
287
11
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
11
    LLVMContext &Ctx = elt1->getContext();
289
11
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
11
    return llvm::StructType::get(Ctx, StructFields);
291
11
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::IntegerType, llvm::IntegerType>(llvm::Type*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
286
11
  get(Type *elt1, Tys *... elts) {
287
11
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
11
    LLVMContext &Ctx = elt1->getContext();
289
11
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
11
    return llvm::StructType::get(Ctx, StructFields);
291
11
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::StructType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::StructType, llvm::PointerType>(llvm::Type*, llvm::StructType*, llvm::PointerType*)
Line
Count
Source
286
11
  get(Type *elt1, Tys *... elts) {
287
11
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
11
    LLVMContext &Ctx = elt1->getContext();
289
11
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
11
    return llvm::StructType::get(Ctx, StructFields);
291
11
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
286
83
  get(Type *elt1, Tys *... elts) {
287
83
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
83
    LLVMContext &Ctx = elt1->getContext();
289
83
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
83
    return llvm::StructType::get(Ctx, StructFields);
291
83
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::PointerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::PointerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::PointerType*)
Line
Count
Source
286
33
  get(Type *elt1, Tys *... elts) {
287
33
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
33
    LLVMContext &Ctx = elt1->getContext();
289
33
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
33
    return llvm::StructType::get(Ctx, StructFields);
291
33
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::IntegerType, llvm::Type, llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::Type, llvm::Type, llvm::IntegerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::IntegerType, llvm::Type, llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::Type, llvm::Type, llvm::IntegerType, llvm::IntegerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::Type*, llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::Type*, llvm::Type*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
286
38
  get(Type *elt1, Tys *... elts) {
287
38
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
38
    LLVMContext &Ctx = elt1->getContext();
289
38
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
38
    return llvm::StructType::get(Ctx, StructFields);
291
38
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType>::value, llvm::StructType*>::type llvm::StructType::get<llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*)
Line
Count
Source
286
3
  get(Type *elt1, Tys *... elts) {
287
3
    assert(elt1 && "Cannot create a struct type with no elements with this");
288
3
    LLVMContext &Ctx = elt1->getContext();
289
3
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
290
3
    return llvm::StructType::get(Ctx, StructFields);
291
3
  }
292
293
96.6M
  bool isPacked() const { return (getSubclassData() & SCDB_Packed) != 0; }
294
295
  /// Return true if this type is uniqued by structural equivalence, false if it
296
  /// is a struct definition.
297
848k
  bool isLiteral() const { return (getSubclassData() & SCDB_IsLiteral) != 0; }
298
299
  /// Return true if this is a type with an identity that has no body specified
300
  /// yet. These prints as 'opaque' in .ll files.
301
1.34M
  bool isOpaque() const { return (getSubclassData() & SCDB_HasBody) == 0; }
302
303
  /// isSized - Return true if this is a sized type.
304
  bool isSized(SmallPtrSetImpl<Type *> *Visited = nullptr) const;
305
306
  /// Return true if this is a named struct that has a non-empty name.
307
509
  bool hasName() const { return SymbolTableEntry != nullptr; }
308
309
  /// Return the name for this struct type if it has an identity.
310
  /// This may return an empty string for an unnamed struct type.  Do not call
311
  /// this on an literal type.
312
  StringRef getName() const;
313
314
  /// Change the name of this type to the specified name, or to a name with a
315
  /// suffix if there is a collision. Do not call this on an literal type.
316
  void setName(StringRef Name);
317
318
  /// Specify a body for an opaque identified type.
319
  void setBody(ArrayRef<Type*> Elements, bool isPacked = false);
320
321
  template <typename... Tys>
322
  typename std::enable_if<are_base_of<Type, Tys...>::value, void>::type
323
1.70k
  setBody(Type *elt1, Tys *... elts) {
324
1.70k
    assert(elt1 && "Cannot create a struct type with no elements with this");
325
1.70k
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
326
1.70k
    setBody(StructFields);
327
1.70k
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::IntegerType, llvm::ArrayType>::value, void>::type llvm::StructType::setBody<llvm::IntegerType, llvm::ArrayType>(llvm::Type*, llvm::IntegerType*, llvm::ArrayType*)
Line
Count
Source
323
165
  setBody(Type *elt1, Tys *... elts) {
324
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
325
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
326
165
    setBody(StructFields);
327
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, void>::type llvm::StructType::setBody<llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
323
771
  setBody(Type *elt1, Tys *... elts) {
324
771
    assert(elt1 && "Cannot create a struct type with no elements with this");
325
771
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
326
771
    setBody(StructFields);
327
771
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>::value, void>::type llvm::StructType::setBody<llvm::PointerType, llvm::PointerType, llvm::IntegerType, llvm::IntegerType, llvm::IntegerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType, llvm::PointerType>(llvm::Type*, llvm::PointerType*, llvm::PointerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::IntegerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*, llvm::PointerType*)
Line
Count
Source
323
165
  setBody(Type *elt1, Tys *... elts) {
324
165
    assert(elt1 && "Cannot create a struct type with no elements with this");
325
165
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
326
165
    setBody(StructFields);
327
165
  }
std::__1::enable_if<are_base_of<llvm::Type, llvm::ArrayType>::value, void>::type llvm::StructType::setBody<llvm::ArrayType>(llvm::Type*, llvm::ArrayType*)
Line
Count
Source
323
606
  setBody(Type *elt1, Tys *... elts) {
324
606
    assert(elt1 && "Cannot create a struct type with no elements with this");
325
606
    SmallVector<llvm::Type *, 8> StructFields({elt1, elts...});
326
606
    setBody(StructFields);
327
606
  }
328
329
  /// Return true if the specified type is valid as a element type.
330
  static bool isValidElementType(Type *ElemTy);
331
332
  // Iterator access to the elements.
333
  using element_iterator = Type::subtype_iterator;
334
335
777k
  element_iterator element_begin() const { return ContainedTys; }
336
741k
  element_iterator element_end() const { return &ContainedTys[NumContainedTys];}
337
283k
  ArrayRef<Type *> const elements() const {
338
283k
    return makeArrayRef(element_begin(), element_end());
339
283k
  }
340
341
  /// Return true if this is layout identical to the specified struct.
342
  bool isLayoutIdentical(StructType *Other) const;
343
344
  /// Random access to the elements
345
66.3M
  unsigned getNumElements() const { return NumContainedTys; }
346
256M
  Type *getElementType(unsigned N) const {
347
256M
    assert(N < NumContainedTys && "Element number out of range!");
348
256M
    return ContainedTys[N];
349
256M
  }
350
351
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
352
894M
  static bool classof(const Type *T) {
353
894M
    return T->getTypeID() == StructTyID;
354
894M
  }
355
};
356
357
0
StringRef Type::getStructName() const {
358
0
  return cast<StructType>(this)->getName();
359
0
}
360
361
18.0k
unsigned Type::getStructNumElements() const {
362
18.0k
  return cast<StructType>(this)->getNumElements();
363
18.0k
}
364
365
17.7k
Type *Type::getStructElementType(unsigned N) const {
366
17.7k
  return cast<StructType>(this)->getElementType(N);
367
17.7k
}
368
369
/// This is the superclass of the array and vector type classes. Both of these
370
/// represent "arrays" in memory. The array type represents a specifically sized
371
/// array, and the vector type represents a specifically sized array that allows
372
/// for use of SIMD instructions. SequentialType holds the common features of
373
/// both, which stem from the fact that both lay their components out in memory
374
/// identically.
375
class SequentialType : public CompositeType {
376
  Type *ContainedType;               ///< Storage for the single contained type.
377
  uint64_t NumElements;
378
379
protected:
380
  SequentialType(TypeID TID, Type *ElType, uint64_t NumElements)
381
    : CompositeType(ElType->getContext(), TID), ContainedType(ElType),
382
518k
      NumElements(NumElements) {
383
518k
    ContainedTys = &ContainedType;
384
518k
    NumContainedTys = 1;
385
518k
  }
386
387
public:
388
  SequentialType(const SequentialType &) = delete;
389
  SequentialType &operator=(const SequentialType &) = delete;
390
391
  /// For scalable vectors, this will return the minimum number of elements
392
  /// in the vector.
393
242M
  uint64_t getNumElements() const { return NumElements; }
394
583M
  Type *getElementType() const { return ContainedType; }
395
396
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
397
452M
  static bool classof(const Type *T) {
398
452M
    return T->getTypeID() == ArrayTyID || 
T->getTypeID() == VectorTyID357M
;
399
452M
  }
400
};
401
402
/// Class to represent array types.
403
class ArrayType : public SequentialType {
404
  ArrayType(Type *ElType, uint64_t NumEl);
405
406
public:
407
  ArrayType(const ArrayType &) = delete;
408
  ArrayType &operator=(const ArrayType &) = delete;
409
410
  /// This static method is the primary way to construct an ArrayType
411
  static ArrayType *get(Type *ElementType, uint64_t NumElements);
412
413
  /// Return true if the specified type is valid as a element type.
414
  static bool isValidElementType(Type *ElemTy);
415
416
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
417
364M
  static bool classof(const Type *T) {
418
364M
    return T->getTypeID() == ArrayTyID;
419
364M
  }
420
};
421
422
563k
uint64_t Type::getArrayNumElements() const {
423
563k
  return cast<ArrayType>(this)->getNumElements();
424
563k
}
425
426
/// Class to represent vector types.
427
class VectorType : public SequentialType {
428
  /// A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
429
  /// minimum number of elements of type Ty contained within the vector, and
430
  /// 'vscale x' indicates that the total element count is an integer multiple
431
  /// of 'n', where the multiple is either guaranteed to be one, or is
432
  /// statically unknown at compile time.
433
  ///
434
  /// If the multiple is known to be 1, then the extra term is discarded in
435
  /// textual IR:
436
  ///
437
  /// <4 x i32>          - a vector containing 4 i32s
438
  /// <vscale x 4 x i32> - a vector containing an unknown integer multiple
439
  ///                      of 4 i32s
440
441
  VectorType(Type *ElType, unsigned NumEl, bool Scalable = false);
442
  VectorType(Type *ElType, ElementCount EC);
443
444
  // If true, the total number of elements is an unknown multiple of the
445
  // minimum 'NumElements' from SequentialType. Otherwise the total number
446
  // of elements is exactly equal to 'NumElements'.
447
  bool Scalable;
448
449
public:
450
  VectorType(const VectorType &) = delete;
451
  VectorType &operator=(const VectorType &) = delete;
452
453
  /// This static method is the primary way to construct an VectorType.
454
  static VectorType *get(Type *ElementType, ElementCount EC);
455
  static VectorType *get(Type *ElementType, unsigned NumElements,
456
9.09M
                         bool Scalable = false) {
457
9.09M
    return VectorType::get(ElementType, {NumElements, Scalable});
458
9.09M
  }
459
460
  /// This static method gets a VectorType with the same number of elements as
461
  /// the input type, and the element type is an integer type of the same width
462
  /// as the input element type.
463
1.01k
  static VectorType *getInteger(VectorType *VTy) {
464
1.01k
    unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
465
1.01k
    assert(EltBits && "Element size must be of a non-zero size");
466
1.01k
    Type *EltTy = IntegerType::get(VTy->getContext(), EltBits);
467
1.01k
    return VectorType::get(EltTy, VTy->getElementCount());
468
1.01k
  }
469
470
  /// This static method is like getInteger except that the element types are
471
  /// twice as wide as the elements in the input type.
472
2.63k
  static VectorType *getExtendedElementVectorType(VectorType *VTy) {
473
2.63k
    unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
474
2.63k
    Type *EltTy = IntegerType::get(VTy->getContext(), EltBits * 2);
475
2.63k
    return VectorType::get(EltTy, VTy->getElementCount());
476
2.63k
  }
477
478
  /// This static method is like getInteger except that the element types are
479
  /// half as wide as the elements in the input type.
480
5.57k
  static VectorType *getTruncatedElementVectorType(VectorType *VTy) {
481
5.57k
    unsigned EltBits = VTy->getElementType()->getPrimitiveSizeInBits();
482
5.57k
    assert((EltBits & 1) == 0 &&
483
5.57k
           "Cannot truncate vector element with odd bit-width");
484
5.57k
    Type *EltTy = IntegerType::get(VTy->getContext(), EltBits / 2);
485
5.57k
    return VectorType::get(EltTy, VTy->getElementCount());
486
5.57k
  }
487
488
  /// This static method returns a VectorType with half as many elements as the
489
  /// input type and the same element type.
490
2
  static VectorType *getHalfElementsVectorType(VectorType *VTy) {
491
2
    auto EltCnt = VTy->getElementCount();
492
2
    assert ((EltCnt.Min & 1) == 0 &&
493
2
            "Cannot halve vector with odd number of elements.");
494
2
    return VectorType::get(VTy->getElementType(), EltCnt/2);
495
2
  }
496
497
  /// This static method returns a VectorType with twice as many elements as the
498
  /// input type and the same element type.
499
  static VectorType *getDoubleElementsVectorType(VectorType *VTy) {
500
    auto EltCnt = VTy->getElementCount();
501
    assert((VTy->getNumElements() * 2ull) <= UINT_MAX &&
502
           "Too many elements in vector");
503
    return VectorType::get(VTy->getElementType(), EltCnt*2);
504
  }
505
506
  /// Return true if the specified type is valid as a element type.
507
  static bool isValidElementType(Type *ElemTy);
508
509
  /// Return an ElementCount instance to represent the (possibly scalable)
510
  /// number of elements in the vector.
511
9.23k
  ElementCount getElementCount() const {
512
9.23k
    uint64_t MinimumEltCnt = getNumElements();
513
9.23k
    assert(MinimumEltCnt <= UINT_MAX && "Too many elements in vector");
514
9.23k
    return { (unsigned)MinimumEltCnt, Scalable };
515
9.23k
  }
516
517
  /// Returns whether or not this is a scalable vector (meaning the total
518
  /// element count is a multiple of the minimum).
519
1.17M
  bool isScalable() const {
520
1.17M
    return Scalable;
521
1.17M
  }
522
523
  /// Return the minimum number of bits in the Vector type.
524
  /// Returns zero when the vector is a vector of pointers.
525
1.15M
  unsigned getBitWidth() const {
526
1.15M
    return getNumElements() * getElementType()->getPrimitiveSizeInBits();
527
1.15M
  }
528
529
  /// Methods for support type inquiry through isa, cast, and dyn_cast.
530
824M
  static bool classof(const Type *T) {
531
824M
    return T->getTypeID() == VectorTyID;
532
824M
  }
533
};
534
535
42.7M
unsigned Type::getVectorNumElements() const {
536
42.7M
  return cast<VectorType>(this)->getNumElements();
537
42.7M
}
538
539
2
bool Type::getVectorIsScalable() const {
540
2
  return cast<VectorType>(this)->isScalable();
541
2
}
542
543
/// Class to represent pointers.
544
class PointerType : public Type {
545
  explicit PointerType(Type *ElType, unsigned AddrSpace);
546
547
  Type *PointeeTy;
548
549
public:
550
  PointerType(const PointerType &) = delete;
551
  PointerType &operator=(const PointerType &) = delete;
552
553
  /// This constructs a pointer to an object of the specified type in a numbered
554
  /// address space.
555
  static PointerType *get(Type *ElementType, unsigned AddressSpace);
556
557
  /// This constructs a pointer to an object of the specified type in the
558
  /// generic address space (address space zero).
559
910k
  static PointerType *getUnqual(Type *ElementType) {
560
910k
    return PointerType::get(ElementType, 0);
561
910k
  }
562
563
82.6M
  Type *getElementType() const { return PointeeTy; }
564
565
  /// Return true if the specified type is valid as a element type.
566
  static bool isValidElementType(Type *ElemTy);
567
568
  /// Return true if we can load or store from a pointer to this type.
569
  static bool isLoadableOrStorableType(Type *ElemTy);
570
571
  /// Return the address space of the Pointer type.
572
872M
  inline unsigned getAddressSpace() const { return getSubclassData(); }
573
574
  /// Implement support type inquiry through isa, cast, and dyn_cast.
575
0
  static bool classof(const Type *T) {
576
0
    return T->getTypeID() == PointerTyID;
577
0
  }
578
};
579
580
284M
unsigned Type::getPointerAddressSpace() const {
581
284M
  return cast<PointerType>(getScalarType())->getAddressSpace();
582
284M
}
583
584
} // end namespace llvm
585
586
#endif // LLVM_IR_DERIVEDTYPES_H