]> git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/CodeGen/MachineValueType.h
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / include / llvm / CodeGen / MachineValueType.h
1 //===- CodeGen/MachineValueType.h - Machine-Level types ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the set of machine-level target independent types which
11 // legal values in the code generator use.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_MACHINEVALUETYPE_H
16 #define LLVM_CODEGEN_MACHINEVALUETYPE_H
17
18 #include "llvm/ADT/iterator_range.h"
19 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/MathExtras.h"
21
22 namespace llvm {
23
24 class Type;
25
26 /// MVT - Machine Value Type. Every type that is supported natively by some
27 /// processor targeted by LLVM occurs here. This means that any legal value
28 /// type can be represented by an MVT.
29 class MVT {
30 public:
31 enum SimpleValueType {
32 // INVALID_SIMPLE_VALUE_TYPE - Simple value types less than zero are
33 // considered extended value types.
34 INVALID_SIMPLE_VALUE_TYPE = -1,
35
36 // If you change this numbering, you must change the values in
37 // ValueTypes.td as well!
38 Other = 0, // This is a non-standard value
39 i1 = 1, // This is a 1 bit integer value
40 i8 = 2, // This is an 8 bit integer value
41 i16 = 3, // This is a 16 bit integer value
42 i32 = 4, // This is a 32 bit integer value
43 i64 = 5, // This is a 64 bit integer value
44 i128 = 6, // This is a 128 bit integer value
45
46 FIRST_INTEGER_VALUETYPE = i1,
47 LAST_INTEGER_VALUETYPE = i128,
48
49 f16 = 7, // This is a 16 bit floating point value
50 f32 = 8, // This is a 32 bit floating point value
51 f64 = 9, // This is a 64 bit floating point value
52 f80 = 10, // This is a 80 bit floating point value
53 f128 = 11, // This is a 128 bit floating point value
54 ppcf128 = 12, // This is a PPC 128-bit floating point value
55
56 FIRST_FP_VALUETYPE = f16,
57 LAST_FP_VALUETYPE = ppcf128,
58
59 v2i1 = 13, // 2 x i1
60 v4i1 = 14, // 4 x i1
61 v8i1 = 15, // 8 x i1
62 v16i1 = 16, // 16 x i1
63 v32i1 = 17, // 32 x i1
64 v64i1 = 18, // 64 x i1
65
66 v1i8 = 19, // 1 x i8
67 v2i8 = 20, // 2 x i8
68 v4i8 = 21, // 4 x i8
69 v8i8 = 22, // 8 x i8
70 v16i8 = 23, // 16 x i8
71 v32i8 = 24, // 32 x i8
72 v64i8 = 25, // 64 x i8
73 v1i16 = 26, // 1 x i16
74 v2i16 = 27, // 2 x i16
75 v4i16 = 28, // 4 x i16
76 v8i16 = 29, // 8 x i16
77 v16i16 = 30, // 16 x i16
78 v32i16 = 31, // 32 x i16
79 v1i32 = 32, // 1 x i32
80 v2i32 = 33, // 2 x i32
81 v4i32 = 34, // 4 x i32
82 v8i32 = 35, // 8 x i32
83 v16i32 = 36, // 16 x i32
84 v1i64 = 37, // 1 x i64
85 v2i64 = 38, // 2 x i64
86 v4i64 = 39, // 4 x i64
87 v8i64 = 40, // 8 x i64
88 v16i64 = 41, // 16 x i64
89
90 FIRST_INTEGER_VECTOR_VALUETYPE = v2i1,
91 LAST_INTEGER_VECTOR_VALUETYPE = v16i64,
92
93 v2f16 = 42, // 2 x f16
94 v4f16 = 43, // 4 x f16
95 v8f16 = 44, // 8 x f16
96 v1f32 = 45, // 1 x f32
97 v2f32 = 46, // 2 x f32
98 v4f32 = 47, // 4 x f32
99 v8f32 = 48, // 8 x f32
100 v16f32 = 49, // 16 x f32
101 v1f64 = 50, // 1 x f64
102 v2f64 = 51, // 2 x f64
103 v4f64 = 52, // 4 x f64
104 v8f64 = 53, // 8 x f64
105
106 FIRST_FP_VECTOR_VALUETYPE = v2f16,
107 LAST_FP_VECTOR_VALUETYPE = v8f64,
108
109 FIRST_VECTOR_VALUETYPE = v2i1,
110 LAST_VECTOR_VALUETYPE = v8f64,
111
112 x86mmx = 54, // This is an X86 MMX value
113
114 Glue = 55, // This glues nodes together during pre-RA sched
115
116 isVoid = 56, // This has no value
117
118 Untyped = 57, // This value takes a register, but has
119 // unspecified type. The register class
120 // will be determined by the opcode.
121
122 FIRST_VALUETYPE = 0, // This is always the beginning of the list.
123 LAST_VALUETYPE = 58, // This always remains at the end of the list.
124
125 // This is the current maximum for LAST_VALUETYPE.
126 // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
127 // This value must be a multiple of 32.
128 MAX_ALLOWED_VALUETYPE = 64,
129
130 // Metadata - This is MDNode or MDString.
131 Metadata = 250,
132
133 // iPTRAny - An int value the size of the pointer of the current
134 // target to any address space. This must only be used internal to
135 // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
136 iPTRAny = 251,
137
138 // vAny - A vector with any length and element size. This is used
139 // for intrinsics that have overloadings based on vector types.
140 // This is only for tblgen's consumption!
141 vAny = 252,
142
143 // fAny - Any floating-point or vector floating-point value. This is used
144 // for intrinsics that have overloadings based on floating-point types.
145 // This is only for tblgen's consumption!
146 fAny = 253,
147
148 // iAny - An integer or vector integer value of any bit width. This is
149 // used for intrinsics that have overloadings based on integer bit widths.
150 // This is only for tblgen's consumption!
151 iAny = 254,
152
153 // iPTR - An int value the size of the pointer of the current
154 // target. This should only be used internal to tblgen!
155 iPTR = 255
156 };
157
158 SimpleValueType SimpleTy;
159
160 MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
161 MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
162
163 bool operator>(const MVT& S) const { return SimpleTy > S.SimpleTy; }
164 bool operator<(const MVT& S) const { return SimpleTy < S.SimpleTy; }
165 bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
166 bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
167 bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
168 bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
169
170 /// isValid - Return true if this is a valid simple valuetype.
171 bool isValid() const {
172 return (SimpleTy >= MVT::FIRST_VALUETYPE &&
173 SimpleTy < MVT::LAST_VALUETYPE);
174 }
175
176 /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
177 bool isFloatingPoint() const {
178 return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
179 SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
180 (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
181 SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
182 }
183
184 /// isInteger - Return true if this is an integer, or a vector integer type.
185 bool isInteger() const {
186 return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
187 SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
188 (SimpleTy >= MVT::FIRST_INTEGER_VECTOR_VALUETYPE &&
189 SimpleTy <= MVT::LAST_INTEGER_VECTOR_VALUETYPE));
190 }
191
192 /// isVector - Return true if this is a vector value type.
193 bool isVector() const {
194 return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
195 SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
196 }
197
198 /// is16BitVector - Return true if this is a 16-bit vector type.
199 bool is16BitVector() const {
200 return (SimpleTy == MVT::v2i8 || SimpleTy == MVT::v1i16 ||
201 SimpleTy == MVT::v16i1);
202 }
203
204 /// is32BitVector - Return true if this is a 32-bit vector type.
205 bool is32BitVector() const {
206 return (SimpleTy == MVT::v4i8 || SimpleTy == MVT::v2i16 ||
207 SimpleTy == MVT::v1i32 || SimpleTy == MVT::v2f16 ||
208 SimpleTy == MVT::v1f32);
209 }
210
211 /// is64BitVector - Return true if this is a 64-bit vector type.
212 bool is64BitVector() const {
213 return (SimpleTy == MVT::v8i8 || SimpleTy == MVT::v4i16 ||
214 SimpleTy == MVT::v2i32 || SimpleTy == MVT::v1i64 ||
215 SimpleTy == MVT::v4f16 || SimpleTy == MVT::v2f32 ||
216 SimpleTy == MVT::v1f64);
217 }
218
219 /// is128BitVector - Return true if this is a 128-bit vector type.
220 bool is128BitVector() const {
221 return (SimpleTy == MVT::v16i8 || SimpleTy == MVT::v8i16 ||
222 SimpleTy == MVT::v4i32 || SimpleTy == MVT::v2i64 ||
223 SimpleTy == MVT::v8f16 || SimpleTy == MVT::v4f32 ||
224 SimpleTy == MVT::v2f64);
225 }
226
227 /// is256BitVector - Return true if this is a 256-bit vector type.
228 bool is256BitVector() const {
229 return (SimpleTy == MVT::v8f32 || SimpleTy == MVT::v4f64 ||
230 SimpleTy == MVT::v32i8 || SimpleTy == MVT::v16i16 ||
231 SimpleTy == MVT::v8i32 || SimpleTy == MVT::v4i64);
232 }
233
234 /// is512BitVector - Return true if this is a 512-bit vector type.
235 bool is512BitVector() const {
236 return (SimpleTy == MVT::v8f64 || SimpleTy == MVT::v16f32 ||
237 SimpleTy == MVT::v64i8 || SimpleTy == MVT::v32i16 ||
238 SimpleTy == MVT::v8i64 || SimpleTy == MVT::v16i32);
239 }
240
241 /// is1024BitVector - Return true if this is a 1024-bit vector type.
242 bool is1024BitVector() const {
243 return (SimpleTy == MVT::v16i64);
244 }
245
246 /// isOverloaded - Return true if this is an overloaded type for TableGen.
247 bool isOverloaded() const {
248 return (SimpleTy==MVT::iAny || SimpleTy==MVT::fAny ||
249 SimpleTy==MVT::vAny || SimpleTy==MVT::iPTRAny);
250 }
251
252 /// isPow2VectorType - Returns true if the given vector is a power of 2.
253 bool isPow2VectorType() const {
254 unsigned NElts = getVectorNumElements();
255 return !(NElts & (NElts - 1));
256 }
257
258 /// getPow2VectorType - Widens the length of the given vector MVT up to
259 /// the nearest power of 2 and returns that type.
260 MVT getPow2VectorType() const {
261 if (isPow2VectorType())
262 return *this;
263
264 unsigned NElts = getVectorNumElements();
265 unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
266 return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
267 }
268
269 /// getScalarType - If this is a vector type, return the element type,
270 /// otherwise return this.
271 MVT getScalarType() const {
272 return isVector() ? getVectorElementType() : *this;
273 }
274
275 MVT getVectorElementType() const {
276 switch (SimpleTy) {
277 default:
278 llvm_unreachable("Not a vector MVT!");
279 case v2i1 :
280 case v4i1 :
281 case v8i1 :
282 case v16i1 :
283 case v32i1 :
284 case v64i1: return i1;
285 case v1i8 :
286 case v2i8 :
287 case v4i8 :
288 case v8i8 :
289 case v16i8:
290 case v32i8:
291 case v64i8: return i8;
292 case v1i16:
293 case v2i16:
294 case v4i16:
295 case v8i16:
296 case v16i16:
297 case v32i16: return i16;
298 case v1i32:
299 case v2i32:
300 case v4i32:
301 case v8i32:
302 case v16i32: return i32;
303 case v1i64:
304 case v2i64:
305 case v4i64:
306 case v8i64:
307 case v16i64: return i64;
308 case v2f16:
309 case v4f16:
310 case v8f16: return f16;
311 case v1f32:
312 case v2f32:
313 case v4f32:
314 case v8f32:
315 case v16f32: return f32;
316 case v1f64:
317 case v2f64:
318 case v4f64:
319 case v8f64: return f64;
320 }
321 }
322
323 unsigned getVectorNumElements() const {
324 switch (SimpleTy) {
325 default:
326 llvm_unreachable("Not a vector MVT!");
327 case v32i1:
328 case v32i8:
329 case v32i16: return 32;
330 case v64i1:
331 case v64i8: return 64;
332 case v16i1:
333 case v16i8:
334 case v16i16:
335 case v16i32:
336 case v16i64:
337 case v16f32: return 16;
338 case v8i1 :
339 case v8i8 :
340 case v8i16:
341 case v8i32:
342 case v8i64:
343 case v8f16:
344 case v8f32:
345 case v8f64: return 8;
346 case v4i1:
347 case v4i8:
348 case v4i16:
349 case v4i32:
350 case v4i64:
351 case v4f16:
352 case v4f32:
353 case v4f64: return 4;
354 case v2i1:
355 case v2i8:
356 case v2i16:
357 case v2i32:
358 case v2i64:
359 case v2f16:
360 case v2f32:
361 case v2f64: return 2;
362 case v1i8:
363 case v1i16:
364 case v1i32:
365 case v1i64:
366 case v1f32:
367 case v1f64: return 1;
368 }
369 }
370
371 unsigned getSizeInBits() const {
372 switch (SimpleTy) {
373 default:
374 llvm_unreachable("getSizeInBits called on extended MVT.");
375 case Other:
376 llvm_unreachable("Value type is non-standard value, Other.");
377 case iPTR:
378 llvm_unreachable("Value type size is target-dependent. Ask TLI.");
379 case iPTRAny:
380 case iAny:
381 case fAny:
382 case vAny:
383 llvm_unreachable("Value type is overloaded.");
384 case Metadata:
385 llvm_unreachable("Value type is metadata.");
386 case i1 : return 1;
387 case v2i1: return 2;
388 case v4i1: return 4;
389 case i8 :
390 case v1i8:
391 case v8i1: return 8;
392 case i16 :
393 case f16:
394 case v16i1:
395 case v2i8:
396 case v1i16: return 16;
397 case f32 :
398 case i32 :
399 case v32i1:
400 case v4i8:
401 case v2i16:
402 case v2f16:
403 case v1f32:
404 case v1i32: return 32;
405 case x86mmx:
406 case f64 :
407 case i64 :
408 case v64i1:
409 case v8i8:
410 case v4i16:
411 case v2i32:
412 case v1i64:
413 case v4f16:
414 case v2f32:
415 case v1f64: return 64;
416 case f80 : return 80;
417 case f128:
418 case ppcf128:
419 case i128:
420 case v16i8:
421 case v8i16:
422 case v4i32:
423 case v2i64:
424 case v8f16:
425 case v4f32:
426 case v2f64: return 128;
427 case v32i8:
428 case v16i16:
429 case v8i32:
430 case v4i64:
431 case v8f32:
432 case v4f64: return 256;
433 case v64i8:
434 case v32i16:
435 case v16i32:
436 case v8i64:
437 case v16f32:
438 case v8f64: return 512;
439 case v16i64:return 1024;
440 }
441 }
442
443 unsigned getScalarSizeInBits() const {
444 return getScalarType().getSizeInBits();
445 }
446
447 /// getStoreSize - Return the number of bytes overwritten by a store
448 /// of the specified value type.
449 unsigned getStoreSize() const {
450 return (getSizeInBits() + 7) / 8;
451 }
452
453 /// getStoreSizeInBits - Return the number of bits overwritten by a store
454 /// of the specified value type.
455 unsigned getStoreSizeInBits() const {
456 return getStoreSize() * 8;
457 }
458
459 /// Return true if this has more bits than VT.
460 bool bitsGT(MVT VT) const {
461 return getSizeInBits() > VT.getSizeInBits();
462 }
463
464 /// Return true if this has no less bits than VT.
465 bool bitsGE(MVT VT) const {
466 return getSizeInBits() >= VT.getSizeInBits();
467 }
468
469 /// Return true if this has less bits than VT.
470 bool bitsLT(MVT VT) const {
471 return getSizeInBits() < VT.getSizeInBits();
472 }
473
474 /// Return true if this has no more bits than VT.
475 bool bitsLE(MVT VT) const {
476 return getSizeInBits() <= VT.getSizeInBits();
477 }
478
479
480 static MVT getFloatingPointVT(unsigned BitWidth) {
481 switch (BitWidth) {
482 default:
483 llvm_unreachable("Bad bit width!");
484 case 16:
485 return MVT::f16;
486 case 32:
487 return MVT::f32;
488 case 64:
489 return MVT::f64;
490 case 80:
491 return MVT::f80;
492 case 128:
493 return MVT::f128;
494 }
495 }
496
497 static MVT getIntegerVT(unsigned BitWidth) {
498 switch (BitWidth) {
499 default:
500 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
501 case 1:
502 return MVT::i1;
503 case 8:
504 return MVT::i8;
505 case 16:
506 return MVT::i16;
507 case 32:
508 return MVT::i32;
509 case 64:
510 return MVT::i64;
511 case 128:
512 return MVT::i128;
513 }
514 }
515
516 static MVT getVectorVT(MVT VT, unsigned NumElements) {
517 switch (VT.SimpleTy) {
518 default:
519 break;
520 case MVT::i1:
521 if (NumElements == 2) return MVT::v2i1;
522 if (NumElements == 4) return MVT::v4i1;
523 if (NumElements == 8) return MVT::v8i1;
524 if (NumElements == 16) return MVT::v16i1;
525 if (NumElements == 32) return MVT::v32i1;
526 if (NumElements == 64) return MVT::v64i1;
527 break;
528 case MVT::i8:
529 if (NumElements == 1) return MVT::v1i8;
530 if (NumElements == 2) return MVT::v2i8;
531 if (NumElements == 4) return MVT::v4i8;
532 if (NumElements == 8) return MVT::v8i8;
533 if (NumElements == 16) return MVT::v16i8;
534 if (NumElements == 32) return MVT::v32i8;
535 if (NumElements == 64) return MVT::v64i8;
536 break;
537 case MVT::i16:
538 if (NumElements == 1) return MVT::v1i16;
539 if (NumElements == 2) return MVT::v2i16;
540 if (NumElements == 4) return MVT::v4i16;
541 if (NumElements == 8) return MVT::v8i16;
542 if (NumElements == 16) return MVT::v16i16;
543 if (NumElements == 32) return MVT::v32i16;
544 break;
545 case MVT::i32:
546 if (NumElements == 1) return MVT::v1i32;
547 if (NumElements == 2) return MVT::v2i32;
548 if (NumElements == 4) return MVT::v4i32;
549 if (NumElements == 8) return MVT::v8i32;
550 if (NumElements == 16) return MVT::v16i32;
551 break;
552 case MVT::i64:
553 if (NumElements == 1) return MVT::v1i64;
554 if (NumElements == 2) return MVT::v2i64;
555 if (NumElements == 4) return MVT::v4i64;
556 if (NumElements == 8) return MVT::v8i64;
557 if (NumElements == 16) return MVT::v16i64;
558 break;
559 case MVT::f16:
560 if (NumElements == 2) return MVT::v2f16;
561 if (NumElements == 4) return MVT::v4f16;
562 if (NumElements == 8) return MVT::v8f16;
563 break;
564 case MVT::f32:
565 if (NumElements == 1) return MVT::v1f32;
566 if (NumElements == 2) return MVT::v2f32;
567 if (NumElements == 4) return MVT::v4f32;
568 if (NumElements == 8) return MVT::v8f32;
569 if (NumElements == 16) return MVT::v16f32;
570 break;
571 case MVT::f64:
572 if (NumElements == 1) return MVT::v1f64;
573 if (NumElements == 2) return MVT::v2f64;
574 if (NumElements == 4) return MVT::v4f64;
575 if (NumElements == 8) return MVT::v8f64;
576 break;
577 }
578 return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
579 }
580
581 /// Return the value type corresponding to the specified type. This returns
582 /// all pointers as iPTR. If HandleUnknown is true, unknown types are
583 /// returned as Other, otherwise they are invalid.
584 static MVT getVT(Type *Ty, bool HandleUnknown = false);
585
586 private:
587 /// A simple iterator over the MVT::SimpleValueType enum.
588 struct mvt_iterator {
589 SimpleValueType VT;
590 mvt_iterator(SimpleValueType VT) : VT(VT) {}
591 MVT operator*() const { return VT; }
592 bool operator!=(const mvt_iterator &LHS) const { return VT != LHS.VT; }
593 mvt_iterator& operator++() {
594 VT = (MVT::SimpleValueType)((int)VT + 1);
595 assert((int)VT <= MVT::MAX_ALLOWED_VALUETYPE &&
596 "MVT iterator overflowed.");
597 return *this;
598 }
599 };
600 /// A range of the MVT::SimpleValueType enum.
601 typedef iterator_range<mvt_iterator> mvt_range;
602
603 public:
604 /// SimpleValueType Iteration
605 /// @{
606 static mvt_range all_valuetypes() {
607 return mvt_range(MVT::FIRST_VALUETYPE, MVT::LAST_VALUETYPE);
608 }
609 static mvt_range integer_valuetypes() {
610 return mvt_range(MVT::FIRST_INTEGER_VALUETYPE,
611 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VALUETYPE + 1));
612 }
613 static mvt_range fp_valuetypes() {
614 return mvt_range(MVT::FIRST_FP_VALUETYPE,
615 (MVT::SimpleValueType)(MVT::LAST_FP_VALUETYPE + 1));
616 }
617 static mvt_range vector_valuetypes() {
618 return mvt_range(MVT::FIRST_VECTOR_VALUETYPE,
619 (MVT::SimpleValueType)(MVT::LAST_VECTOR_VALUETYPE + 1));
620 }
621 static mvt_range integer_vector_valuetypes() {
622 return mvt_range(
623 MVT::FIRST_INTEGER_VECTOR_VALUETYPE,
624 (MVT::SimpleValueType)(MVT::LAST_INTEGER_VECTOR_VALUETYPE + 1));
625 }
626 static mvt_range fp_vector_valuetypes() {
627 return mvt_range(
628 MVT::FIRST_FP_VECTOR_VALUETYPE,
629 (MVT::SimpleValueType)(MVT::LAST_FP_VECTOR_VALUETYPE + 1));
630 }
631 /// @}
632 };
633
634 } // End llvm namespace
635
636 #endif