LLVM  10.0.0svn
ValueTypes.cpp
Go to the documentation of this file.
1 //===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
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 
10 #include "llvm/ADT/StringExtras.h"
11 #include "llvm/IR/DerivedTypes.h"
12 #include "llvm/IR/Type.h"
14 using namespace llvm;
15 
16 EVT EVT::changeExtendedTypeToInteger() const {
17  LLVMContext &Context = LLVMTy->getContext();
18  return getIntegerVT(Context, getSizeInBits());
19 }
20 
21 EVT EVT::changeExtendedVectorElementTypeToInteger() const {
22  LLVMContext &Context = LLVMTy->getContext();
23  EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
24  return getVectorVT(Context, IntTy, getVectorNumElements());
25 }
26 
27 EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
28  EVT VT;
29  VT.LLVMTy = IntegerType::get(Context, BitWidth);
30  assert(VT.isExtended() && "Type is not extended!");
31  return VT;
32 }
33 
34 EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
35  unsigned NumElements) {
36  EVT ResultVT;
37  ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
38  assert(ResultVT.isExtended() && "Type is not extended!");
39  return ResultVT;
40 }
41 
42 bool EVT::isExtendedFloatingPoint() const {
43  assert(isExtended() && "Type is not extended!");
44  return LLVMTy->isFPOrFPVectorTy();
45 }
46 
47 bool EVT::isExtendedInteger() const {
48  assert(isExtended() && "Type is not extended!");
49  return LLVMTy->isIntOrIntVectorTy();
50 }
51 
52 bool EVT::isExtendedScalarInteger() const {
53  assert(isExtended() && "Type is not extended!");
54  return LLVMTy->isIntegerTy();
55 }
56 
57 bool EVT::isExtendedVector() const {
58  assert(isExtended() && "Type is not extended!");
59  return LLVMTy->isVectorTy();
60 }
61 
62 bool EVT::isExtended16BitVector() const {
63  return isExtendedVector() && getExtendedSizeInBits() == 16;
64 }
65 
66 bool EVT::isExtended32BitVector() const {
67  return isExtendedVector() && getExtendedSizeInBits() == 32;
68 }
69 
70 bool EVT::isExtended64BitVector() const {
71  return isExtendedVector() && getExtendedSizeInBits() == 64;
72 }
73 
74 bool EVT::isExtended128BitVector() const {
75  return isExtendedVector() && getExtendedSizeInBits() == 128;
76 }
77 
78 bool EVT::isExtended256BitVector() const {
79  return isExtendedVector() && getExtendedSizeInBits() == 256;
80 }
81 
82 bool EVT::isExtended512BitVector() const {
83  return isExtendedVector() && getExtendedSizeInBits() == 512;
84 }
85 
86 bool EVT::isExtended1024BitVector() const {
87  return isExtendedVector() && getExtendedSizeInBits() == 1024;
88 }
89 
90 bool EVT::isExtended2048BitVector() const {
91  return isExtendedVector() && getExtendedSizeInBits() == 2048;
92 }
93 
94 EVT EVT::getExtendedVectorElementType() const {
95  assert(isExtended() && "Type is not extended!");
96  return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
97 }
98 
99 unsigned EVT::getExtendedVectorNumElements() const {
100  assert(isExtended() && "Type is not extended!");
101  return cast<VectorType>(LLVMTy)->getNumElements();
102 }
103 
104 unsigned EVT::getExtendedSizeInBits() const {
105  assert(isExtended() && "Type is not extended!");
106  if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
107  return ITy->getBitWidth();
108  if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
109  return VTy->getBitWidth();
110  llvm_unreachable("Unrecognized extended type!");
111 }
112 
113 /// getEVTString - This function returns value type as a string, e.g. "i32".
114 std::string EVT::getEVTString() const {
115  switch (V.SimpleTy) {
116  default:
117  if (isVector())
118  return (isScalableVector() ? "nxv" : "v") + utostr(getVectorNumElements())
120  if (isInteger())
121  return "i" + utostr(getSizeInBits());
122  llvm_unreachable("Invalid EVT!");
123  case MVT::i1: return "i1";
124  case MVT::i8: return "i8";
125  case MVT::i16: return "i16";
126  case MVT::i32: return "i32";
127  case MVT::i64: return "i64";
128  case MVT::i128: return "i128";
129  case MVT::f16: return "f16";
130  case MVT::f32: return "f32";
131  case MVT::f64: return "f64";
132  case MVT::f80: return "f80";
133  case MVT::f128: return "f128";
134  case MVT::ppcf128: return "ppcf128";
135  case MVT::isVoid: return "isVoid";
136  case MVT::Other: return "ch";
137  case MVT::Glue: return "glue";
138  case MVT::x86mmx: return "x86mmx";
139  case MVT::v1i1: return "v1i1";
140  case MVT::v2i1: return "v2i1";
141  case MVT::v4i1: return "v4i1";
142  case MVT::v8i1: return "v8i1";
143  case MVT::v16i1: return "v16i1";
144  case MVT::v32i1: return "v32i1";
145  case MVT::v64i1: return "v64i1";
146  case MVT::v128i1: return "v128i1";
147  case MVT::v512i1: return "v512i1";
148  case MVT::v1024i1: return "v1024i1";
149  case MVT::v1i8: return "v1i8";
150  case MVT::v2i8: return "v2i8";
151  case MVT::v4i8: return "v4i8";
152  case MVT::v8i8: return "v8i8";
153  case MVT::v16i8: return "v16i8";
154  case MVT::v32i8: return "v32i8";
155  case MVT::v64i8: return "v64i8";
156  case MVT::v128i8: return "v128i8";
157  case MVT::v256i8: return "v256i8";
158  case MVT::v1i16: return "v1i16";
159  case MVT::v2i16: return "v2i16";
160  case MVT::v3i16: return "v3i16";
161  case MVT::v4i16: return "v4i16";
162  case MVT::v8i16: return "v8i16";
163  case MVT::v16i16: return "v16i16";
164  case MVT::v32i16: return "v32i16";
165  case MVT::v64i16: return "v64i16";
166  case MVT::v128i16: return "v128i16";
167  case MVT::v1i32: return "v1i32";
168  case MVT::v2i32: return "v2i32";
169  case MVT::v3i32: return "v3i32";
170  case MVT::v4i32: return "v4i32";
171  case MVT::v5i32: return "v5i32";
172  case MVT::v8i32: return "v8i32";
173  case MVT::v16i32: return "v16i32";
174  case MVT::v32i32: return "v32i32";
175  case MVT::v64i32: return "v64i32";
176  case MVT::v128i32: return "v128i32";
177  case MVT::v256i32: return "v256i32";
178  case MVT::v512i32: return "v512i32";
179  case MVT::v1024i32:return "v1024i32";
180  case MVT::v2048i32:return "v2048i32";
181  case MVT::v1i64: return "v1i64";
182  case MVT::v2i64: return "v2i64";
183  case MVT::v4i64: return "v4i64";
184  case MVT::v8i64: return "v8i64";
185  case MVT::v16i64: return "v16i64";
186  case MVT::v32i64: return "v32i64";
187  case MVT::v1i128: return "v1i128";
188  case MVT::v1f32: return "v1f32";
189  case MVT::v2f32: return "v2f32";
190  case MVT::v2f16: return "v2f16";
191  case MVT::v3f16: return "v3f16";
192  case MVT::v4f16: return "v4f16";
193  case MVT::v8f16: return "v8f16";
194  case MVT::v3f32: return "v3f32";
195  case MVT::v4f32: return "v4f32";
196  case MVT::v5f32: return "v5f32";
197  case MVT::v8f32: return "v8f32";
198  case MVT::v16f32: return "v16f32";
199  case MVT::v32f32: return "v32f32";
200  case MVT::v64f32: return "v64f32";
201  case MVT::v128f32: return "v128f32";
202  case MVT::v256f32: return "v256f32";
203  case MVT::v512f32: return "v512f32";
204  case MVT::v1024f32:return "v1024f32";
205  case MVT::v2048f32:return "v2048f32";
206  case MVT::v1f64: return "v1f64";
207  case MVT::v2f64: return "v2f64";
208  case MVT::v4f64: return "v4f64";
209  case MVT::v8f64: return "v8f64";
210  case MVT::nxv1i1: return "nxv1i1";
211  case MVT::nxv2i1: return "nxv2i1";
212  case MVT::nxv4i1: return "nxv4i1";
213  case MVT::nxv8i1: return "nxv8i1";
214  case MVT::nxv16i1: return "nxv16i1";
215  case MVT::nxv32i1: return "nxv32i1";
216  case MVT::nxv1i8: return "nxv1i8";
217  case MVT::nxv2i8: return "nxv2i8";
218  case MVT::nxv4i8: return "nxv4i8";
219  case MVT::nxv8i8: return "nxv8i8";
220  case MVT::nxv16i8: return "nxv16i8";
221  case MVT::nxv32i8: return "nxv32i8";
222  case MVT::nxv1i16: return "nxv1i16";
223  case MVT::nxv2i16: return "nxv2i16";
224  case MVT::nxv4i16: return "nxv4i16";
225  case MVT::nxv8i16: return "nxv8i16";
226  case MVT::nxv16i16:return "nxv16i16";
227  case MVT::nxv32i16:return "nxv32i16";
228  case MVT::nxv1i32: return "nxv1i32";
229  case MVT::nxv2i32: return "nxv2i32";
230  case MVT::nxv4i32: return "nxv4i32";
231  case MVT::nxv8i32: return "nxv8i32";
232  case MVT::nxv16i32:return "nxv16i32";
233  case MVT::nxv32i32:return "nxv32i32";
234  case MVT::nxv1i64: return "nxv1i64";
235  case MVT::nxv2i64: return "nxv2i64";
236  case MVT::nxv4i64: return "nxv4i64";
237  case MVT::nxv8i64: return "nxv8i64";
238  case MVT::nxv16i64:return "nxv16i64";
239  case MVT::nxv32i64:return "nxv32i64";
240  case MVT::nxv2f16: return "nxv2f16";
241  case MVT::nxv4f16: return "nxv4f16";
242  case MVT::nxv8f16: return "nxv8f16";
243  case MVT::nxv1f32: return "nxv1f32";
244  case MVT::nxv2f32: return "nxv2f32";
245  case MVT::nxv4f32: return "nxv4f32";
246  case MVT::nxv8f32: return "nxv8f32";
247  case MVT::nxv16f32:return "nxv16f32";
248  case MVT::nxv1f64: return "nxv1f64";
249  case MVT::nxv2f64: return "nxv2f64";
250  case MVT::nxv4f64: return "nxv4f64";
251  case MVT::nxv8f64: return "nxv8f64";
252  case MVT::Metadata:return "Metadata";
253  case MVT::Untyped: return "Untyped";
254  case MVT::exnref : return "exnref";
255  }
256 }
257 
258 /// getTypeForEVT - This method returns an LLVM type corresponding to the
259 /// specified EVT. For integer types, this returns an unsigned type. Note
260 /// that this will abort for types that cannot be represented.
262  switch (V.SimpleTy) {
263  default:
264  assert(isExtended() && "Type is not extended!");
265  return LLVMTy;
266  case MVT::isVoid: return Type::getVoidTy(Context);
267  case MVT::i1: return Type::getInt1Ty(Context);
268  case MVT::i8: return Type::getInt8Ty(Context);
269  case MVT::i16: return Type::getInt16Ty(Context);
270  case MVT::i32: return Type::getInt32Ty(Context);
271  case MVT::i64: return Type::getInt64Ty(Context);
272  case MVT::i128: return IntegerType::get(Context, 128);
273  case MVT::f16: return Type::getHalfTy(Context);
274  case MVT::f32: return Type::getFloatTy(Context);
275  case MVT::f64: return Type::getDoubleTy(Context);
276  case MVT::f80: return Type::getX86_FP80Ty(Context);
277  case MVT::f128: return Type::getFP128Ty(Context);
278  case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
279  case MVT::x86mmx: return Type::getX86_MMXTy(Context);
280  case MVT::v1i1: return VectorType::get(Type::getInt1Ty(Context), 1);
281  case MVT::v2i1: return VectorType::get(Type::getInt1Ty(Context), 2);
282  case MVT::v4i1: return VectorType::get(Type::getInt1Ty(Context), 4);
283  case MVT::v8i1: return VectorType::get(Type::getInt1Ty(Context), 8);
284  case MVT::v16i1: return VectorType::get(Type::getInt1Ty(Context), 16);
285  case MVT::v32i1: return VectorType::get(Type::getInt1Ty(Context), 32);
286  case MVT::v64i1: return VectorType::get(Type::getInt1Ty(Context), 64);
287  case MVT::v128i1: return VectorType::get(Type::getInt1Ty(Context), 128);
288  case MVT::v512i1: return VectorType::get(Type::getInt1Ty(Context), 512);
289  case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024);
290  case MVT::v1i8: return VectorType::get(Type::getInt8Ty(Context), 1);
291  case MVT::v2i8: return VectorType::get(Type::getInt8Ty(Context), 2);
292  case MVT::v4i8: return VectorType::get(Type::getInt8Ty(Context), 4);
293  case MVT::v8i8: return VectorType::get(Type::getInt8Ty(Context), 8);
294  case MVT::v16i8: return VectorType::get(Type::getInt8Ty(Context), 16);
295  case MVT::v32i8: return VectorType::get(Type::getInt8Ty(Context), 32);
296  case MVT::v64i8: return VectorType::get(Type::getInt8Ty(Context), 64);
297  case MVT::v128i8: return VectorType::get(Type::getInt8Ty(Context), 128);
298  case MVT::v256i8: return VectorType::get(Type::getInt8Ty(Context), 256);
299  case MVT::v1i16: return VectorType::get(Type::getInt16Ty(Context), 1);
300  case MVT::v2i16: return VectorType::get(Type::getInt16Ty(Context), 2);
301  case MVT::v3i16: return VectorType::get(Type::getInt16Ty(Context), 3);
302  case MVT::v4i16: return VectorType::get(Type::getInt16Ty(Context), 4);
303  case MVT::v8i16: return VectorType::get(Type::getInt16Ty(Context), 8);
304  case MVT::v16i16: return VectorType::get(Type::getInt16Ty(Context), 16);
305  case MVT::v32i16: return VectorType::get(Type::getInt16Ty(Context), 32);
306  case MVT::v64i16: return VectorType::get(Type::getInt16Ty(Context), 64);
307  case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128);
308  case MVT::v1i32: return VectorType::get(Type::getInt32Ty(Context), 1);
309  case MVT::v2i32: return VectorType::get(Type::getInt32Ty(Context), 2);
310  case MVT::v3i32: return VectorType::get(Type::getInt32Ty(Context), 3);
311  case MVT::v4i32: return VectorType::get(Type::getInt32Ty(Context), 4);
312  case MVT::v5i32: return VectorType::get(Type::getInt32Ty(Context), 5);
313  case MVT::v8i32: return VectorType::get(Type::getInt32Ty(Context), 8);
314  case MVT::v16i32: return VectorType::get(Type::getInt32Ty(Context), 16);
315  case MVT::v32i32: return VectorType::get(Type::getInt32Ty(Context), 32);
316  case MVT::v64i32: return VectorType::get(Type::getInt32Ty(Context), 64);
317  case MVT::v128i32: return VectorType::get(Type::getInt32Ty(Context), 128);
318  case MVT::v256i32: return VectorType::get(Type::getInt32Ty(Context), 256);
319  case MVT::v512i32: return VectorType::get(Type::getInt32Ty(Context), 512);
320  case MVT::v1024i32:return VectorType::get(Type::getInt32Ty(Context), 1024);
321  case MVT::v2048i32:return VectorType::get(Type::getInt32Ty(Context), 2048);
322  case MVT::v1i64: return VectorType::get(Type::getInt64Ty(Context), 1);
323  case MVT::v2i64: return VectorType::get(Type::getInt64Ty(Context), 2);
324  case MVT::v4i64: return VectorType::get(Type::getInt64Ty(Context), 4);
325  case MVT::v8i64: return VectorType::get(Type::getInt64Ty(Context), 8);
326  case MVT::v16i64: return VectorType::get(Type::getInt64Ty(Context), 16);
327  case MVT::v32i64: return VectorType::get(Type::getInt64Ty(Context), 32);
328  case MVT::v1i128: return VectorType::get(Type::getInt128Ty(Context), 1);
329  case MVT::v2f16: return VectorType::get(Type::getHalfTy(Context), 2);
330  case MVT::v3f16: return VectorType::get(Type::getHalfTy(Context), 3);
331  case MVT::v4f16: return VectorType::get(Type::getHalfTy(Context), 4);
332  case MVT::v8f16: return VectorType::get(Type::getHalfTy(Context), 8);
333  case MVT::v16f16: return VectorType::get(Type::getHalfTy(Context), 16);
334  case MVT::v32f16: return VectorType::get(Type::getHalfTy(Context), 32);
335  case MVT::v1f32: return VectorType::get(Type::getFloatTy(Context), 1);
336  case MVT::v2f32: return VectorType::get(Type::getFloatTy(Context), 2);
337  case MVT::v3f32: return VectorType::get(Type::getFloatTy(Context), 3);
338  case MVT::v4f32: return VectorType::get(Type::getFloatTy(Context), 4);
339  case MVT::v5f32: return VectorType::get(Type::getFloatTy(Context), 5);
340  case MVT::v8f32: return VectorType::get(Type::getFloatTy(Context), 8);
341  case MVT::v16f32: return VectorType::get(Type::getFloatTy(Context), 16);
342  case MVT::v32f32: return VectorType::get(Type::getFloatTy(Context), 32);
343  case MVT::v64f32: return VectorType::get(Type::getFloatTy(Context), 64);
344  case MVT::v128f32: return VectorType::get(Type::getFloatTy(Context), 128);
345  case MVT::v256f32: return VectorType::get(Type::getFloatTy(Context), 256);
346  case MVT::v512f32: return VectorType::get(Type::getFloatTy(Context), 512);
347  case MVT::v1024f32:return VectorType::get(Type::getFloatTy(Context), 1024);
348  case MVT::v2048f32:return VectorType::get(Type::getFloatTy(Context), 2048);
349  case MVT::v1f64: return VectorType::get(Type::getDoubleTy(Context), 1);
350  case MVT::v2f64: return VectorType::get(Type::getDoubleTy(Context), 2);
351  case MVT::v4f64: return VectorType::get(Type::getDoubleTy(Context), 4);
352  case MVT::v8f64: return VectorType::get(Type::getDoubleTy(Context), 8);
353  case MVT::nxv1i1:
354  return VectorType::get(Type::getInt1Ty(Context), 1, /*Scalable=*/ true);
355  case MVT::nxv2i1:
356  return VectorType::get(Type::getInt1Ty(Context), 2, /*Scalable=*/ true);
357  case MVT::nxv4i1:
358  return VectorType::get(Type::getInt1Ty(Context), 4, /*Scalable=*/ true);
359  case MVT::nxv8i1:
360  return VectorType::get(Type::getInt1Ty(Context), 8, /*Scalable=*/ true);
361  case MVT::nxv16i1:
362  return VectorType::get(Type::getInt1Ty(Context), 16, /*Scalable=*/ true);
363  case MVT::nxv32i1:
364  return VectorType::get(Type::getInt1Ty(Context), 32, /*Scalable=*/ true);
365  case MVT::nxv1i8:
366  return VectorType::get(Type::getInt8Ty(Context), 1, /*Scalable=*/ true);
367  case MVT::nxv2i8:
368  return VectorType::get(Type::getInt8Ty(Context), 2, /*Scalable=*/ true);
369  case MVT::nxv4i8:
370  return VectorType::get(Type::getInt8Ty(Context), 4, /*Scalable=*/ true);
371  case MVT::nxv8i8:
372  return VectorType::get(Type::getInt8Ty(Context), 8, /*Scalable=*/ true);
373  case MVT::nxv16i8:
374  return VectorType::get(Type::getInt8Ty(Context), 16, /*Scalable=*/ true);
375  case MVT::nxv32i8:
376  return VectorType::get(Type::getInt8Ty(Context), 32, /*Scalable=*/ true);
377  case MVT::nxv1i16:
378  return VectorType::get(Type::getInt16Ty(Context), 1, /*Scalable=*/ true);
379  case MVT::nxv2i16:
380  return VectorType::get(Type::getInt16Ty(Context), 2, /*Scalable=*/ true);
381  case MVT::nxv4i16:
382  return VectorType::get(Type::getInt16Ty(Context), 4, /*Scalable=*/ true);
383  case MVT::nxv8i16:
384  return VectorType::get(Type::getInt16Ty(Context), 8, /*Scalable=*/ true);
385  case MVT::nxv16i16:
386  return VectorType::get(Type::getInt16Ty(Context), 16, /*Scalable=*/ true);
387  case MVT::nxv32i16:
388  return VectorType::get(Type::getInt16Ty(Context), 32, /*Scalable=*/ true);
389  case MVT::nxv1i32:
390  return VectorType::get(Type::getInt32Ty(Context), 1, /*Scalable=*/ true);
391  case MVT::nxv2i32:
392  return VectorType::get(Type::getInt32Ty(Context), 2, /*Scalable=*/ true);
393  case MVT::nxv4i32:
394  return VectorType::get(Type::getInt32Ty(Context), 4, /*Scalable=*/ true);
395  case MVT::nxv8i32:
396  return VectorType::get(Type::getInt32Ty(Context), 8, /*Scalable=*/ true);
397  case MVT::nxv16i32:
398  return VectorType::get(Type::getInt32Ty(Context), 16,/*Scalable=*/ true);
399  case MVT::nxv32i32:
400  return VectorType::get(Type::getInt32Ty(Context), 32,/*Scalable=*/ true);
401  case MVT::nxv1i64:
402  return VectorType::get(Type::getInt64Ty(Context), 1, /*Scalable=*/ true);
403  case MVT::nxv2i64:
404  return VectorType::get(Type::getInt64Ty(Context), 2, /*Scalable=*/ true);
405  case MVT::nxv4i64:
406  return VectorType::get(Type::getInt64Ty(Context), 4, /*Scalable=*/ true);
407  case MVT::nxv8i64:
408  return VectorType::get(Type::getInt64Ty(Context), 8, /*Scalable=*/ true);
409  case MVT::nxv16i64:
410  return VectorType::get(Type::getInt64Ty(Context), 16, /*Scalable=*/ true);
411  case MVT::nxv32i64:
412  return VectorType::get(Type::getInt64Ty(Context), 32, /*Scalable=*/ true);
413  case MVT::nxv2f16:
414  return VectorType::get(Type::getHalfTy(Context), 2, /*Scalable=*/ true);
415  case MVT::nxv4f16:
416  return VectorType::get(Type::getHalfTy(Context), 4, /*Scalable=*/ true);
417  case MVT::nxv8f16:
418  return VectorType::get(Type::getHalfTy(Context), 8, /*Scalable=*/ true);
419  case MVT::nxv1f32:
420  return VectorType::get(Type::getFloatTy(Context), 1, /*Scalable=*/ true);
421  case MVT::nxv2f32:
422  return VectorType::get(Type::getFloatTy(Context), 2, /*Scalable=*/ true);
423  case MVT::nxv4f32:
424  return VectorType::get(Type::getFloatTy(Context), 4, /*Scalable=*/ true);
425  case MVT::nxv8f32:
426  return VectorType::get(Type::getFloatTy(Context), 8, /*Scalable=*/ true);
427  case MVT::nxv16f32:
428  return VectorType::get(Type::getFloatTy(Context), 16, /*Scalable=*/ true);
429  case MVT::nxv1f64:
430  return VectorType::get(Type::getDoubleTy(Context), 1, /*Scalable=*/ true);
431  case MVT::nxv2f64:
432  return VectorType::get(Type::getDoubleTy(Context), 2, /*Scalable=*/ true);
433  case MVT::nxv4f64:
434  return VectorType::get(Type::getDoubleTy(Context), 4, /*Scalable=*/ true);
435  case MVT::nxv8f64:
436  return VectorType::get(Type::getDoubleTy(Context), 8, /*Scalable=*/ true);
437  case MVT::Metadata: return Type::getMetadataTy(Context);
438  }
439 }
440 
441 /// Return the value type corresponding to the specified type. This returns all
442 /// pointers as MVT::iPTR. If HandleUnknown is true, unknown types are returned
443 /// as Other, otherwise they are invalid.
444 MVT MVT::getVT(Type *Ty, bool HandleUnknown){
445  switch (Ty->getTypeID()) {
446  default:
447  if (HandleUnknown) return MVT(MVT::Other);
448  llvm_unreachable("Unknown type!");
449  case Type::VoidTyID:
450  return MVT::isVoid;
451  case Type::IntegerTyID:
452  return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
453  case Type::HalfTyID: return MVT(MVT::f16);
454  case Type::FloatTyID: return MVT(MVT::f32);
455  case Type::DoubleTyID: return MVT(MVT::f64);
456  case Type::X86_FP80TyID: return MVT(MVT::f80);
457  case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
458  case Type::FP128TyID: return MVT(MVT::f128);
459  case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
460  case Type::PointerTyID: return MVT(MVT::iPTR);
461  case Type::VectorTyID: {
462  VectorType *VTy = cast<VectorType>(Ty);
463  return getVectorVT(
464  getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
465  VTy->getElementCount());
466  }
467  }
468 }
469 
470 /// getEVT - Return the value type corresponding to the specified type. This
471 /// returns all pointers as MVT::iPTR. If HandleUnknown is true, unknown types
472 /// are returned as Other, otherwise they are invalid.
473 EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
474  switch (Ty->getTypeID()) {
475  default:
476  return MVT::getVT(Ty, HandleUnknown);
477  case Type::IntegerTyID:
478  return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
479  case Type::VectorTyID: {
480  VectorType *VTy = cast<VectorType>(Ty);
481  return getVectorVT(Ty->getContext(),
482  getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),
483  VTy->getElementCount());
484  }
485  }
486 }
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static Type * getDoubleTy(LLVMContext &C)
Definition: Type.cpp:164
static IntegerType * getInt1Ty(LLVMContext &C)
Definition: Type.cpp:172
LLVMContext & Context
This class represents lattice values for constants.
Definition: AllocatorList.h:23
2: 32-bit floating point type
Definition: Type.h:58
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
Definition: DerivedTypes.h:511
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
Definition: ValueTypes.h:156
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:140
4: 80-bit floating point type (X87)
Definition: Type.h:60
1: 16-bit floating point type
Definition: Type.h:57
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:176
static Type * getMetadataTy(LLVMContext &C)
Definition: Type.cpp:165
bool isVectorTy() const
True if this is an instance of VectorType.
Definition: Type.h:229
15: Pointers
Definition: Type.h:74
static IntegerType * getInt16Ty(LLVMContext &C)
Definition: Type.cpp:174
static Type * getX86_MMXTy(LLVMContext &C)
Definition: Type.cpp:170
static Type * getX86_FP80Ty(LLVMContext &C)
Definition: Type.cpp:167
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:129
static Type * getFloatTy(LLVMContext &C)
Definition: Type.cpp:163
TypeID getTypeID() const
Return the type id for the type.
Definition: Type.h:137
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
Definition: ValueTypes.cpp:261
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition: Type.h:196
SimpleValueType SimpleTy
static Type * getPPC_FP128Ty(LLVMContext &C)
Definition: Type.cpp:169
unsigned getScalarSizeInBits() const
Definition: ValueTypes.h:297
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:291
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Definition: Type.h:202
11: Arbitrary bit width integers
Definition: Type.h:70
0: type with no size
Definition: Type.h:56
static IntegerType * getInt128Ty(LLVMContext &C)
Definition: Type.cpp:177
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:64
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:272
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:160
6: 128-bit floating point type (two 64-bits, PowerPC)
Definition: Type.h:62
std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
Definition: ValueTypes.cpp:114
Class to represent integer types.
Definition: DerivedTypes.h:40
static MVT getVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:444
Extended Value Type.
Definition: ValueTypes.h:33
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Type * getFP128Ty(LLVMContext &C)
Definition: Type.cpp:168
static Type * getHalfTy(LLVMContext &C)
Definition: Type.cpp:162
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition: Type.cpp:239
16: SIMD &#39;packed&#39; format, or other vector type
Definition: Type.h:75
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:264
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
Class to represent vector types.
Definition: DerivedTypes.h:427
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT...
Definition: ValueTypes.h:72
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:150
static IntegerType * getInt32Ty(LLVMContext &C)
Definition: Type.cpp:175
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Definition: Type.cpp:609
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:473
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Definition: Type.h:184
3: 64-bit floating point type
Definition: Type.h:59
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Type * getElementType() const
Definition: DerivedTypes.h:394
9: MMX vectors (64 bits, X86 specific)
Definition: Type.h:65
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:63
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:173
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
Definition: ValueTypes.h:130
5: 128-bit floating point type (112-bit mantissa)
Definition: Type.h:61