~ubuntu-branches/ubuntu/quantal/llvm-3.1/quantal

« back to all changes in this revision

Viewing changes to include/llvm/CodeGen/ValueTypes.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-03-29 19:09:51 UTC
  • Revision ID: package-import@ubuntu.com-20120329190951-aq83ivog4cg8bxun
Tags: upstream-3.1~svn153643
ImportĀ upstreamĀ versionĀ 3.1~svn153643

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- CodeGen/ValueTypes.h - Low-Level Target independ. 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 low-level target independent types which various
 
11
// values in the code generator are.  This allows the target specific behavior
 
12
// of instructions to be described to target independent passes.
 
13
//
 
14
//===----------------------------------------------------------------------===//
 
15
 
 
16
#ifndef LLVM_CODEGEN_VALUETYPES_H
 
17
#define LLVM_CODEGEN_VALUETYPES_H
 
18
 
 
19
#include "llvm/Support/DataTypes.h"
 
20
#include "llvm/Support/ErrorHandling.h"
 
21
#include "llvm/Support/MathExtras.h"
 
22
#include <cassert>
 
23
#include <string>
 
24
 
 
25
namespace llvm {
 
26
  class Type;
 
27
  class LLVMContext;
 
28
  struct EVT;
 
29
 
 
30
  /// MVT - Machine Value Type.  Every type that is supported natively by some
 
31
  /// processor targeted by LLVM occurs here.  This means that any legal value
 
32
  /// type can be represented by a MVT.
 
33
  class MVT {
 
34
  public:
 
35
    enum SimpleValueType {
 
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
      v2i8           =  13,   //  2 x i8
 
60
      v4i8           =  14,   //  4 x i8
 
61
      v8i8           =  15,   //  8 x i8
 
62
      v16i8          =  16,   // 16 x i8
 
63
      v32i8          =  17,   // 32 x i8
 
64
      v2i16          =  18,   //  2 x i16
 
65
      v4i16          =  19,   //  4 x i16
 
66
      v8i16          =  20,   //  8 x i16
 
67
      v16i16         =  21,   // 16 x i16
 
68
      v2i32          =  22,   //  2 x i32
 
69
      v4i32          =  23,   //  4 x i32
 
70
      v8i32          =  24,   //  8 x i32
 
71
      v1i64          =  25,   //  1 x i64
 
72
      v2i64          =  26,   //  2 x i64
 
73
      v4i64          =  27,   //  4 x i64
 
74
      v8i64          =  28,   //  8 x i64
 
75
 
 
76
      v2f16          =  29,   //  2 x f16
 
77
      v2f32          =  30,   //  2 x f32
 
78
      v4f32          =  31,   //  4 x f32
 
79
      v8f32          =  32,   //  8 x f32
 
80
      v2f64          =  33,   //  2 x f64
 
81
      v4f64          =  34,   //  4 x f64
 
82
 
 
83
      FIRST_VECTOR_VALUETYPE = v2i8,
 
84
      LAST_VECTOR_VALUETYPE  = v4f64,
 
85
      FIRST_FP_VECTOR_VALUETYPE = v2f16,
 
86
      LAST_FP_VECTOR_VALUETYPE = v4f64,
 
87
 
 
88
      x86mmx         =  35,   // This is an X86 MMX value
 
89
 
 
90
      Glue           =  36,   // This glues nodes together during pre-RA sched
 
91
 
 
92
      isVoid         =  37,   // This has no value
 
93
 
 
94
      Untyped        =  38,   // This value takes a register, but has
 
95
                              // unspecified type.  The register class
 
96
                              // will be determined by the opcode.
 
97
 
 
98
      LAST_VALUETYPE =  39,   // This always remains at the end of the list.
 
99
 
 
100
      // This is the current maximum for LAST_VALUETYPE.
 
101
      // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
 
102
      // This value must be a multiple of 32.
 
103
      MAX_ALLOWED_VALUETYPE = 64,
 
104
 
 
105
      // Metadata - This is MDNode or MDString.
 
106
      Metadata       = 250,
 
107
 
 
108
      // iPTRAny - An int value the size of the pointer of the current
 
109
      // target to any address space. This must only be used internal to
 
110
      // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
 
111
      iPTRAny        = 251,
 
112
 
 
113
      // vAny - A vector with any length and element size. This is used
 
114
      // for intrinsics that have overloadings based on vector types.
 
115
      // This is only for tblgen's consumption!
 
116
      vAny           = 252,
 
117
 
 
118
      // fAny - Any floating-point or vector floating-point value. This is used
 
119
      // for intrinsics that have overloadings based on floating-point types.
 
120
      // This is only for tblgen's consumption!
 
121
      fAny           = 253,
 
122
 
 
123
      // iAny - An integer or vector integer value of any bit width. This is
 
124
      // used for intrinsics that have overloadings based on integer bit widths.
 
125
      // This is only for tblgen's consumption!
 
126
      iAny           = 254,
 
127
 
 
128
      // iPTR - An int value the size of the pointer of the current
 
129
      // target.  This should only be used internal to tblgen!
 
130
      iPTR           = 255,
 
131
 
 
132
      // LastSimpleValueType - The greatest valid SimpleValueType value.
 
133
      LastSimpleValueType = 255,
 
134
 
 
135
      // INVALID_SIMPLE_VALUE_TYPE - Simple value types greater than or equal
 
136
      // to this are considered extended value types.
 
137
      INVALID_SIMPLE_VALUE_TYPE = LastSimpleValueType + 1
 
138
    };
 
139
 
 
140
    SimpleValueType SimpleTy;
 
141
 
 
142
    MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
 
143
    MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
 
144
 
 
145
    bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
 
146
    bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
 
147
    bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
 
148
    bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
 
149
    bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
 
150
    bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
 
151
 
 
152
    /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
 
153
    bool isFloatingPoint() const {
 
154
      return ((SimpleTy >= MVT::FIRST_FP_VALUETYPE &&
 
155
               SimpleTy <= MVT::LAST_FP_VALUETYPE) ||
 
156
              (SimpleTy >= MVT::FIRST_FP_VECTOR_VALUETYPE &&
 
157
         SimpleTy <= MVT::LAST_FP_VECTOR_VALUETYPE));
 
158
    }
 
159
 
 
160
    /// isInteger - Return true if this is an integer, or a vector integer type.
 
161
    bool isInteger() const {
 
162
      return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
 
163
               SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
 
164
              (SimpleTy >= MVT::v2i8 && SimpleTy <= MVT::v8i64));
 
165
    }
 
166
 
 
167
    /// isVector - Return true if this is a vector value type.
 
168
    bool isVector() const {
 
169
      return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
 
170
              SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
 
171
    }
 
172
 
 
173
    /// isPow2VectorType - Returns true if the given vector is a power of 2.
 
174
    bool isPow2VectorType() const {
 
175
      unsigned NElts = getVectorNumElements();
 
176
      return !(NElts & (NElts - 1));
 
177
    }
 
178
 
 
179
    /// getPow2VectorType - Widens the length of the given vector MVT up to
 
180
    /// the nearest power of 2 and returns that type.
 
181
    MVT getPow2VectorType() const {
 
182
      if (isPow2VectorType())
 
183
        return *this;
 
184
 
 
185
      unsigned NElts = getVectorNumElements();
 
186
      unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
 
187
      return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
 
188
    }
 
189
 
 
190
    /// getScalarType - If this is a vector type, return the element type,
 
191
    /// otherwise return this.
 
192
    MVT getScalarType() const {
 
193
      return isVector() ? getVectorElementType() : *this;
 
194
    }
 
195
 
 
196
    MVT getVectorElementType() const {
 
197
      switch (SimpleTy) {
 
198
      default:
 
199
        return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
 
200
      case v2i8 :
 
201
      case v4i8 :
 
202
      case v8i8 :
 
203
      case v16i8:
 
204
      case v32i8: return i8;
 
205
      case v2i16:
 
206
      case v4i16:
 
207
      case v8i16:
 
208
      case v16i16: return i16;
 
209
      case v2i32:
 
210
      case v4i32:
 
211
      case v8i32: return i32;
 
212
      case v1i64:
 
213
      case v2i64:
 
214
      case v4i64:
 
215
      case v8i64: return i64;
 
216
      case v2f16: return f16;
 
217
      case v2f32:
 
218
      case v4f32:
 
219
      case v8f32: return f32;
 
220
      case v2f64:
 
221
      case v4f64: return f64;
 
222
      }
 
223
    }
 
224
 
 
225
    unsigned getVectorNumElements() const {
 
226
      switch (SimpleTy) {
 
227
      default:
 
228
        return ~0U;
 
229
      case v32i8: return 32;
 
230
      case v16i8:
 
231
      case v16i16: return 16;
 
232
      case v8i8 :
 
233
      case v8i16:
 
234
      case v8i32:
 
235
      case v8i64:
 
236
      case v8f32: return 8;
 
237
      case v4i8:
 
238
      case v4i16:
 
239
      case v4i32:
 
240
      case v4i64:
 
241
      case v4f32:
 
242
      case v4f64: return 4;
 
243
      case v2i8:
 
244
      case v2i16:
 
245
      case v2i32:
 
246
      case v2i64:
 
247
      case v2f16:
 
248
      case v2f32:
 
249
      case v2f64: return 2;
 
250
      case v1i64: return 1;
 
251
      }
 
252
    }
 
253
 
 
254
    unsigned getSizeInBits() const {
 
255
      switch (SimpleTy) {
 
256
      case iPTR:
 
257
        llvm_unreachable("Value type size is target-dependent. Ask TLI.");
 
258
      case iPTRAny:
 
259
      case iAny:
 
260
      case fAny:
 
261
        llvm_unreachable("Value type is overloaded.");
 
262
      default:
 
263
        llvm_unreachable("getSizeInBits called on extended MVT.");
 
264
      case i1  :  return 1;
 
265
      case i8  :  return 8;
 
266
      case i16 :
 
267
      case f16:
 
268
      case v2i8:  return 16;
 
269
      case f32 :
 
270
      case i32 :
 
271
      case v4i8:
 
272
      case v2i16:
 
273
      case v2f16: return 32;
 
274
      case x86mmx:
 
275
      case f64 :
 
276
      case i64 :
 
277
      case v8i8:
 
278
      case v4i16:
 
279
      case v2i32:
 
280
      case v1i64:
 
281
      case v2f32: return 64;
 
282
      case f80 :  return 80;
 
283
      case f128:
 
284
      case ppcf128:
 
285
      case i128:
 
286
      case v16i8:
 
287
      case v8i16:
 
288
      case v4i32:
 
289
      case v2i64:
 
290
      case v4f32:
 
291
      case v2f64: return 128;
 
292
      case v32i8:
 
293
      case v16i16:
 
294
      case v8i32:
 
295
      case v4i64:
 
296
      case v8f32:
 
297
      case v4f64: return 256;
 
298
      case v8i64: return 512;
 
299
      }
 
300
    }
 
301
 
 
302
    /// getStoreSize - Return the number of bytes overwritten by a store
 
303
    /// of the specified value type.
 
304
    unsigned getStoreSize() const {
 
305
      return (getSizeInBits() + 7) / 8;
 
306
    }
 
307
 
 
308
    /// getStoreSizeInBits - Return the number of bits overwritten by a store
 
309
    /// of the specified value type.
 
310
    unsigned getStoreSizeInBits() const {
 
311
      return getStoreSize() * 8;
 
312
    }
 
313
 
 
314
    static MVT getFloatingPointVT(unsigned BitWidth) {
 
315
      switch (BitWidth) {
 
316
      default:
 
317
        llvm_unreachable("Bad bit width!");
 
318
      case 16:
 
319
        return MVT::f16;
 
320
      case 32:
 
321
        return MVT::f32;
 
322
      case 64:
 
323
        return MVT::f64;
 
324
      case 80:
 
325
        return MVT::f80;
 
326
      case 128:
 
327
        return MVT::f128;
 
328
      }
 
329
    }
 
330
 
 
331
    static MVT getIntegerVT(unsigned BitWidth) {
 
332
      switch (BitWidth) {
 
333
      default:
 
334
        return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
 
335
      case 1:
 
336
        return MVT::i1;
 
337
      case 8:
 
338
        return MVT::i8;
 
339
      case 16:
 
340
        return MVT::i16;
 
341
      case 32:
 
342
        return MVT::i32;
 
343
      case 64:
 
344
        return MVT::i64;
 
345
      case 128:
 
346
        return MVT::i128;
 
347
      }
 
348
    }
 
349
 
 
350
    static MVT getVectorVT(MVT VT, unsigned NumElements) {
 
351
      switch (VT.SimpleTy) {
 
352
      default:
 
353
        break;
 
354
      case MVT::i8:
 
355
        if (NumElements == 2)  return MVT::v2i8;
 
356
        if (NumElements == 4)  return MVT::v4i8;
 
357
        if (NumElements == 8)  return MVT::v8i8;
 
358
        if (NumElements == 16) return MVT::v16i8;
 
359
        if (NumElements == 32) return MVT::v32i8;
 
360
        break;
 
361
      case MVT::i16:
 
362
        if (NumElements == 2)  return MVT::v2i16;
 
363
        if (NumElements == 4)  return MVT::v4i16;
 
364
        if (NumElements == 8)  return MVT::v8i16;
 
365
        if (NumElements == 16) return MVT::v16i16;
 
366
        break;
 
367
      case MVT::i32:
 
368
        if (NumElements == 2)  return MVT::v2i32;
 
369
        if (NumElements == 4)  return MVT::v4i32;
 
370
        if (NumElements == 8)  return MVT::v8i32;
 
371
        break;
 
372
      case MVT::i64:
 
373
        if (NumElements == 1)  return MVT::v1i64;
 
374
        if (NumElements == 2)  return MVT::v2i64;
 
375
        if (NumElements == 4)  return MVT::v4i64;
 
376
        if (NumElements == 8)  return MVT::v8i64;
 
377
        break;
 
378
      case MVT::f16:
 
379
        if (NumElements == 2)  return MVT::v2f16;
 
380
        break;
 
381
      case MVT::f32:
 
382
        if (NumElements == 2)  return MVT::v2f32;
 
383
        if (NumElements == 4)  return MVT::v4f32;
 
384
        if (NumElements == 8)  return MVT::v8f32;
 
385
        break;
 
386
      case MVT::f64:
 
387
        if (NumElements == 2)  return MVT::v2f64;
 
388
        if (NumElements == 4)  return MVT::v4f64;
 
389
        break;
 
390
      }
 
391
      return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
 
392
    }
 
393
  };
 
394
 
 
395
 
 
396
  /// EVT - Extended Value Type.  Capable of holding value types which are not
 
397
  /// native for any processor (such as the i12345 type), as well as the types
 
398
  /// a MVT can represent.
 
399
  struct EVT {
 
400
  private:
 
401
    MVT V;
 
402
    Type *LLVMTy;
 
403
 
 
404
  public:
 
405
    EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
 
406
            LLVMTy(0) {}
 
407
    EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
 
408
    EVT(MVT S) : V(S), LLVMTy(0) {}
 
409
 
 
410
    bool operator==(EVT VT) const {
 
411
      return !(*this != VT);
 
412
    }
 
413
    bool operator!=(EVT VT) const {
 
414
      if (V.SimpleTy != VT.V.SimpleTy)
 
415
        return true;
 
416
      if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
 
417
        return LLVMTy != VT.LLVMTy;
 
418
      return false;
 
419
    }
 
420
 
 
421
    /// getFloatingPointVT - Returns the EVT that represents a floating point
 
422
    /// type with the given number of bits.  There are two floating point types
 
423
    /// with 128 bits - this returns f128 rather than ppcf128.
 
424
    static EVT getFloatingPointVT(unsigned BitWidth) {
 
425
      return MVT::getFloatingPointVT(BitWidth);
 
426
    }
 
427
 
 
428
    /// getIntegerVT - Returns the EVT that represents an integer with the given
 
429
    /// number of bits.
 
430
    static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
 
431
      MVT M = MVT::getIntegerVT(BitWidth);
 
432
      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
 
433
        return M;
 
434
      return getExtendedIntegerVT(Context, BitWidth);
 
435
    }
 
436
 
 
437
    /// getVectorVT - Returns the EVT that represents a vector NumElements in
 
438
    /// length, where each element is of type VT.
 
439
    static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
 
440
      MVT M = MVT::getVectorVT(VT.V, NumElements);
 
441
      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
 
442
        return M;
 
443
      return getExtendedVectorVT(Context, VT, NumElements);
 
444
    }
 
445
 
 
446
    /// changeVectorElementTypeToInteger - Return a vector with the same number
 
447
    /// of elements as this vector, but with the element type converted to an
 
448
    /// integer type with the same bitwidth.
 
449
    EVT changeVectorElementTypeToInteger() const {
 
450
      if (!isSimple())
 
451
        return changeExtendedVectorElementTypeToInteger();
 
452
      MVT EltTy = getSimpleVT().getVectorElementType();
 
453
      unsigned BitWidth = EltTy.getSizeInBits();
 
454
      MVT IntTy = MVT::getIntegerVT(BitWidth);
 
455
      MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
 
456
      assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
 
457
             "Simple vector VT not representable by simple integer vector VT!");
 
458
      return VecTy;
 
459
    }
 
460
 
 
461
    /// isSimple - Test if the given EVT is simple (as opposed to being
 
462
    /// extended).
 
463
    bool isSimple() const {
 
464
      return V.SimpleTy <= MVT::LastSimpleValueType;
 
465
    }
 
466
 
 
467
    /// isExtended - Test if the given EVT is extended (as opposed to
 
468
    /// being simple).
 
469
    bool isExtended() const {
 
470
      return !isSimple();
 
471
    }
 
472
 
 
473
    /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
 
474
    bool isFloatingPoint() const {
 
475
      return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
 
476
    }
 
477
 
 
478
    /// isInteger - Return true if this is an integer, or a vector integer type.
 
479
    bool isInteger() const {
 
480
      return isSimple() ? V.isInteger() : isExtendedInteger();
 
481
    }
 
482
 
 
483
    /// isVector - Return true if this is a vector value type.
 
484
    bool isVector() const {
 
485
      return isSimple() ? V.isVector() : isExtendedVector();
 
486
    }
 
487
 
 
488
    /// is64BitVector - Return true if this is a 64-bit vector type.
 
489
    bool is64BitVector() const {
 
490
      if (!isSimple())
 
491
        return isExtended64BitVector();
 
492
 
 
493
      return (V == MVT::v8i8  || V==MVT::v4i16 || V==MVT::v2i32 ||
 
494
              V == MVT::v1i64 || V==MVT::v2f32);
 
495
    }
 
496
 
 
497
    /// is128BitVector - Return true if this is a 128-bit vector type.
 
498
    bool is128BitVector() const {
 
499
      if (!isSimple())
 
500
        return isExtended128BitVector();
 
501
      return (V==MVT::v16i8 || V==MVT::v8i16 || V==MVT::v4i32 ||
 
502
              V==MVT::v2i64 || V==MVT::v4f32 || V==MVT::v2f64);
 
503
    }
 
504
 
 
505
    /// is256BitVector - Return true if this is a 256-bit vector type.
 
506
    inline bool is256BitVector() const {
 
507
      if (!isSimple())
 
508
        return isExtended256BitVector();
 
509
      return (V == MVT::v8f32  || V == MVT::v4f64 || V == MVT::v32i8 ||
 
510
              V == MVT::v16i16 || V == MVT::v8i32 || V == MVT::v4i64);
 
511
    }
 
512
 
 
513
    /// is512BitVector - Return true if this is a 512-bit vector type.
 
514
    inline bool is512BitVector() const {
 
515
      return isSimple() ? (V == MVT::v8i64) : isExtended512BitVector();
 
516
    }
 
517
 
 
518
    /// isOverloaded - Return true if this is an overloaded type for TableGen.
 
519
    bool isOverloaded() const {
 
520
      return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
 
521
    }
 
522
 
 
523
    /// isByteSized - Return true if the bit size is a multiple of 8.
 
524
    bool isByteSized() const {
 
525
      return (getSizeInBits() & 7) == 0;
 
526
    }
 
527
 
 
528
    /// isRound - Return true if the size is a power-of-two number of bytes.
 
529
    bool isRound() const {
 
530
      unsigned BitSize = getSizeInBits();
 
531
      return BitSize >= 8 && !(BitSize & (BitSize - 1));
 
532
    }
 
533
 
 
534
    /// bitsEq - Return true if this has the same number of bits as VT.
 
535
    bool bitsEq(EVT VT) const {
 
536
      if (EVT::operator==(VT)) return true;
 
537
      return getSizeInBits() == VT.getSizeInBits();
 
538
    }
 
539
 
 
540
    /// bitsGT - Return true if this has more bits than VT.
 
541
    bool bitsGT(EVT VT) const {
 
542
      if (EVT::operator==(VT)) return false;
 
543
      return getSizeInBits() > VT.getSizeInBits();
 
544
    }
 
545
 
 
546
    /// bitsGE - Return true if this has no less bits than VT.
 
547
    bool bitsGE(EVT VT) const {
 
548
      if (EVT::operator==(VT)) return true;
 
549
      return getSizeInBits() >= VT.getSizeInBits();
 
550
    }
 
551
 
 
552
    /// bitsLT - Return true if this has less bits than VT.
 
553
    bool bitsLT(EVT VT) const {
 
554
      if (EVT::operator==(VT)) return false;
 
555
      return getSizeInBits() < VT.getSizeInBits();
 
556
    }
 
557
 
 
558
    /// bitsLE - Return true if this has no more bits than VT.
 
559
    bool bitsLE(EVT VT) const {
 
560
      if (EVT::operator==(VT)) return true;
 
561
      return getSizeInBits() <= VT.getSizeInBits();
 
562
    }
 
563
 
 
564
 
 
565
    /// getSimpleVT - Return the SimpleValueType held in the specified
 
566
    /// simple EVT.
 
567
    MVT getSimpleVT() const {
 
568
      assert(isSimple() && "Expected a SimpleValueType!");
 
569
      return V;
 
570
    }
 
571
 
 
572
    /// getScalarType - If this is a vector type, return the element type,
 
573
    /// otherwise return this.
 
574
    EVT getScalarType() const {
 
575
      return isVector() ? getVectorElementType() : *this;
 
576
    }
 
577
 
 
578
    /// getVectorElementType - Given a vector type, return the type of
 
579
    /// each element.
 
580
    EVT getVectorElementType() const {
 
581
      assert(isVector() && "Invalid vector type!");
 
582
      if (isSimple())
 
583
        return V.getVectorElementType();
 
584
      return getExtendedVectorElementType();
 
585
    }
 
586
 
 
587
    /// getVectorNumElements - Given a vector type, return the number of
 
588
    /// elements it contains.
 
589
    unsigned getVectorNumElements() const {
 
590
      assert(isVector() && "Invalid vector type!");
 
591
      if (isSimple())
 
592
        return V.getVectorNumElements();
 
593
      return getExtendedVectorNumElements();
 
594
    }
 
595
 
 
596
    /// getSizeInBits - Return the size of the specified value type in bits.
 
597
    unsigned getSizeInBits() const {
 
598
      if (isSimple())
 
599
        return V.getSizeInBits();
 
600
      return getExtendedSizeInBits();
 
601
    }
 
602
 
 
603
    /// getStoreSize - Return the number of bytes overwritten by a store
 
604
    /// of the specified value type.
 
605
    unsigned getStoreSize() const {
 
606
      return (getSizeInBits() + 7) / 8;
 
607
    }
 
608
 
 
609
    /// getStoreSizeInBits - Return the number of bits overwritten by a store
 
610
    /// of the specified value type.
 
611
    unsigned getStoreSizeInBits() const {
 
612
      return getStoreSize() * 8;
 
613
    }
 
614
 
 
615
    /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
 
616
    /// to the nearest power of two (and at least to eight), and returns the
 
617
    /// integer EVT with that number of bits.
 
618
    EVT getRoundIntegerType(LLVMContext &Context) const {
 
619
      assert(isInteger() && !isVector() && "Invalid integer type!");
 
620
      unsigned BitWidth = getSizeInBits();
 
621
      if (BitWidth <= 8)
 
622
        return EVT(MVT::i8);
 
623
      return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
 
624
    }
 
625
 
 
626
    /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
 
627
    /// greater than or equal to half the width of this EVT. If no simple
 
628
    /// value type can be found, an extended integer value type of half the
 
629
    /// size (rounded up) is returned.
 
630
    EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
 
631
      assert(isInteger() && !isVector() && "Invalid integer type!");
 
632
      unsigned EVTSize = getSizeInBits();
 
633
      for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
 
634
          IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
 
635
        EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
 
636
        if (HalfVT.getSizeInBits() * 2 >= EVTSize)
 
637
          return HalfVT;
 
638
      }
 
639
      return getIntegerVT(Context, (EVTSize + 1) / 2);
 
640
    }
 
641
 
 
642
    /// isPow2VectorType - Returns true if the given vector is a power of 2.
 
643
    bool isPow2VectorType() const {
 
644
      unsigned NElts = getVectorNumElements();
 
645
      return !(NElts & (NElts - 1));
 
646
    }
 
647
 
 
648
    /// getPow2VectorType - Widens the length of the given vector EVT up to
 
649
    /// the nearest power of 2 and returns that type.
 
650
    EVT getPow2VectorType(LLVMContext &Context) const {
 
651
      if (!isPow2VectorType()) {
 
652
        unsigned NElts = getVectorNumElements();
 
653
        unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
 
654
        return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
 
655
      }
 
656
      else {
 
657
        return *this;
 
658
      }
 
659
    }
 
660
 
 
661
    /// getEVTString - This function returns value type as a string,
 
662
    /// e.g. "i32".
 
663
    std::string getEVTString() const;
 
664
 
 
665
    /// getTypeForEVT - This method returns an LLVM type corresponding to the
 
666
    /// specified EVT.  For integer types, this returns an unsigned type.  Note
 
667
    /// that this will abort for types that cannot be represented.
 
668
    Type *getTypeForEVT(LLVMContext &Context) const;
 
669
 
 
670
    /// getEVT - Return the value type corresponding to the specified type.
 
671
    /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
 
672
    /// types are returned as Other, otherwise they are invalid.
 
673
    static EVT getEVT(Type *Ty, bool HandleUnknown = false);
 
674
 
 
675
    intptr_t getRawBits() {
 
676
      if (isSimple())
 
677
        return V.SimpleTy;
 
678
      else
 
679
        return (intptr_t)(LLVMTy);
 
680
    }
 
681
 
 
682
    /// compareRawBits - A meaningless but well-behaved order, useful for
 
683
    /// constructing containers.
 
684
    struct compareRawBits {
 
685
      bool operator()(EVT L, EVT R) const {
 
686
        if (L.V.SimpleTy == R.V.SimpleTy)
 
687
          return L.LLVMTy < R.LLVMTy;
 
688
        else
 
689
          return L.V.SimpleTy < R.V.SimpleTy;
 
690
      }
 
691
    };
 
692
 
 
693
  private:
 
694
    // Methods for handling the Extended-type case in functions above.
 
695
    // These are all out-of-line to prevent users of this header file
 
696
    // from having a dependency on Type.h.
 
697
    EVT changeExtendedVectorElementTypeToInteger() const;
 
698
    static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
 
699
    static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
 
700
                                   unsigned NumElements);
 
701
    bool isExtendedFloatingPoint() const;
 
702
    bool isExtendedInteger() const;
 
703
    bool isExtendedVector() const;
 
704
    bool isExtended64BitVector() const;
 
705
    bool isExtended128BitVector() const;
 
706
    bool isExtended256BitVector() const;
 
707
    bool isExtended512BitVector() const;
 
708
    EVT getExtendedVectorElementType() const;
 
709
    unsigned getExtendedVectorNumElements() const;
 
710
    unsigned getExtendedSizeInBits() const;
 
711
  };
 
712
 
 
713
} // End llvm namespace
 
714
 
 
715
#endif