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