1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file defines the set of low-level target independent types which various
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// values in the code generator are.  This allows the target specific behavior
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// of instructions to be described to target independent passes.
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_CODEGEN_VALUETYPES_H
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_CODEGEN_VALUETYPES_H
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <cassert>
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <string>
2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "llvm/Support/DataTypes.h"
22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/MathExtras.h"
23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  class Type;
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  class LLVMContext;
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  struct EVT;
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// MVT - Machine Value Type.  Every type that is supported natively by some
3019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// processor targeted by LLVM occurs here.  This means that any legal value
3119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// type can be represented by a MVT.
3219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  class MVT {
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public:
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    enum SimpleValueType {
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // If you change this numbering, you must change the values in
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // ValueTypes.td as well!
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Other          =   0,   // This is a non-standard value
38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i1             =   1,   // This is a 1 bit integer value
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i8             =   2,   // This is an 8 bit integer value
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i16            =   3,   // This is a 16 bit integer value
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i32            =   4,   // This is a 32 bit integer value
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i64            =   5,   // This is a 64 bit integer value
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      i128           =   6,   // This is a 128 bit integer value
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      FIRST_INTEGER_VALUETYPE = i1,
46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      LAST_INTEGER_VALUETYPE  = i128,
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      f32            =   7,   // This is a 32 bit floating point value
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      f64            =   8,   // This is a 64 bit floating point value
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      f80            =   9,   // This is a 80 bit floating point value
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      f128           =  10,   // This is a 128 bit floating point value
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      ppcf128        =  11,   // This is a PPC 128-bit floating point value
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2i8           =  12,   //  2 x i8
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4i8           =  13,   //  4 x i8
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v8i8           =  14,   //  8 x i8
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v16i8          =  15,   // 16 x i8
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v32i8          =  16,   // 32 x i8
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2i16          =  17,   //  2 x i16
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4i16          =  18,   //  4 x i16
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v8i16          =  19,   //  8 x i16
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v16i16         =  20,   // 16 x i16
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2i32          =  21,   //  2 x i32
64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4i32          =  22,   //  4 x i32
65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v8i32          =  23,   //  8 x i32
66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v1i64          =  24,   //  1 x i64
67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2i64          =  25,   //  2 x i64
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4i64          =  26,   //  4 x i64
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v8i64          =  27,   //  8 x i64
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2f32          =  28,   //  2 x f32
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4f32          =  29,   //  4 x f32
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v8f32          =  30,   //  8 x f32
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v2f64          =  31,   //  2 x f64
75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      v4f64          =  32,   //  4 x f64
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      FIRST_VECTOR_VALUETYPE = v2i8,
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      LAST_VECTOR_VALUETYPE  = v4f64,
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      x86mmx         =  33,   // This is an X86 MMX value
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      Glue           =  34,   // This glues nodes together during pre-RA sched
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      isVoid         =  35,   // This has no value
8519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      untyped        =  36,   // This value takes a register, but has
8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                              // unspecified type.  The register class
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                              // will be determined by the opcode.
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      LAST_VALUETYPE =  37,   // This always remains at the end of the list.
91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // This is the current maximum for LAST_VALUETYPE.
9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      // MVT::MAX_ALLOWED_VALUETYPE is used for asserts and to size bit vectors
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // This value must be a multiple of 32.
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      MAX_ALLOWED_VALUETYPE = 64,
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // Metadata - This is MDNode or MDString.
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      Metadata       = 250,
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // iPTRAny - An int value the size of the pointer of the current
101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // target to any address space. This must only be used internal to
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // tblgen. Other than for overloading, we treat iPTRAny the same as iPTR.
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      iPTRAny        = 251,
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // vAny - A vector with any length and element size. This is used
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // for intrinsics that have overloadings based on vector types.
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // This is only for tblgen's consumption!
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      vAny           = 252,
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // fAny - Any floating-point or vector floating-point value. This is used
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // for intrinsics that have overloadings based on floating-point types.
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // This is only for tblgen's consumption!
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      fAny           = 253,
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // iAny - An integer or vector integer value of any bit width. This is
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // used for intrinsics that have overloadings based on integer bit widths.
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // This is only for tblgen's consumption!
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      iAny           = 254,
119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // iPTR - An int value the size of the pointer of the current
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // target.  This should only be used internal to tblgen!
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      iPTR           = 255,
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // LastSimpleValueType - The greatest valid SimpleValueType value.
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      LastSimpleValueType = 255,
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // INVALID_SIMPLE_VALUE_TYPE - Simple value types greater than or equal
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      // to this are considered extended value types.
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      INVALID_SIMPLE_VALUE_TYPE = LastSimpleValueType + 1
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    };
131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    SimpleValueType SimpleTy;
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
13619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool operator==(const MVT& S) const { return SimpleTy == S.SimpleTy; }
14019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    bool operator!=(const MVT& S) const { return SimpleTy != S.SimpleTy; }
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
14319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isFloatingPoint() const {
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return ((SimpleTy >= MVT::f32 && SimpleTy <= MVT::ppcf128) ||
14719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	      (SimpleTy >= MVT::v2f32 && SimpleTy <= MVT::v4f64));
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isInteger - Return true if this is an integer, or a vector integer type.
151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isInteger() const {
152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return ((SimpleTy >= MVT::FIRST_INTEGER_VALUETYPE &&
153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman               SimpleTy <= MVT::LAST_INTEGER_VALUETYPE) ||
15419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman	      (SimpleTy >= MVT::v2i8 && SimpleTy <= MVT::v8i64));
155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isVector - Return true if this is a vector value type.
158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isVector() const {
159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return (SimpleTy >= MVT::FIRST_VECTOR_VALUETYPE &&
160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman              SimpleTy <= MVT::LAST_VECTOR_VALUETYPE);
161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
16219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isPow2VectorType - Returns true if the given vector is a power of 2.
164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isPow2VectorType() const {
165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      unsigned NElts = getVectorNumElements();
166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return !(NElts & (NElts - 1));
167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
16919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// getPow2VectorType - Widens the length of the given vector MVT up to
170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// the nearest power of 2 and returns that type.
171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT getPow2VectorType() const {
17219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (isPow2VectorType())
173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return *this;
17419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      unsigned NElts = getVectorNumElements();
17619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      unsigned Pow2NElts = 1 << Log2_32_Ceil(NElts);
17719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return MVT::getVectorVT(getVectorElementType(), Pow2NElts);
178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getScalarType - If this is a vector type, return the element type,
181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// otherwise return this.
182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT getScalarType() const {
183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isVector() ? getVectorElementType() : *this;
184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
18519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT getVectorElementType() const {
187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (SimpleTy) {
188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i8 :
191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i8 :
192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i8 :
193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i8:
194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v32i8: return i8;
195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i16:
196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i16:
197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i16:
198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i16: return i16;
199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i32:
200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i32:
201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i32: return i32;
202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v1i64:
203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i64:
204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i64:
205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i64: return i64;
206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f32:
207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f32:
208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8f32: return f32;
209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f64:
210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f64: return f64;
211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
21319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getVectorNumElements() const {
215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (SimpleTy) {
216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return ~0U;
218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v32i8: return 32;
219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i8:
220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i16: return 16;
221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i8 :
222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i16:
223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i32:
224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i64:
225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8f32: return 8;
226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i8:
227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i16:
228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i32:
229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i64:
230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f32:
231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f64: return 4;
232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i8:
233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i16:
234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i32:
235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i64:
236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f32:
237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f64: return 2;
238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v1i64: return 1;
239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getSizeInBits() const {
243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (SimpleTy) {
244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case iPTR:
245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        assert(0 && "Value type size is target-dependent. Ask TLI.");
246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case iPTRAny:
247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case iAny:
248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case fAny:
249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        assert(0 && "Value type is overloaded.");
250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        assert(0 && "getSizeInBits called on extended MVT.");
252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i1  :  return 1;
253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i8  :  return 8;
254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i16 :
255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i8:  return 16;
256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case f32 :
257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i32 :
258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i8:
259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i16: return 32;
26019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case x86mmx:
261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case f64 :
262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i64 :
263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i8:
264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i16:
265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i32:
266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v1i64:
267894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f32: return 64;
268894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case f80 :  return 80;
269894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case f128:
270894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case ppcf128:
271894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case i128:
272894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i8:
273894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i16:
274894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i32:
275894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2i64:
276894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f32:
277894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v2f64: return 128;
278894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v32i8:
279894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v16i16:
280894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i32:
281894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4i64:
282894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8f32:
283894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v4f64: return 256;
284894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case v8i64: return 512;
285894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
286894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
28719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
28819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// getStoreSize - Return the number of bytes overwritten by a store
28919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// of the specified value type.
29019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned getStoreSize() const {
29119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return (getSizeInBits() + 7) / 8;
29219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
29319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
29419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// getStoreSizeInBits - Return the number of bits overwritten by a store
29519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// of the specified value type.
29619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    unsigned getStoreSizeInBits() const {
29719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getStoreSize() * 8;
29819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
29919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
300894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static MVT getFloatingPointVT(unsigned BitWidth) {
301894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (BitWidth) {
302894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
303894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        assert(false && "Bad bit width!");
304894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 32:
305894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::f32;
306894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 64:
307894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::f64;
308894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 80:
309894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::f80;
310894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 128:
311894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::f128;
312894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
313894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
31419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
315894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static MVT getIntegerVT(unsigned BitWidth) {
316894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (BitWidth) {
317894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
318894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
319894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 1:
320894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i1;
321894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 8:
322894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i8;
323894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 16:
324894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i16;
325894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 32:
326894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i32;
327894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 64:
328894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i64;
329894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case 128:
330894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return MVT::i128;
331894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
332894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
33319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
334894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static MVT getVectorVT(MVT VT, unsigned NumElements) {
335894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      switch (VT.SimpleTy) {
336894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      default:
337894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
338894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::i8:
339894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2i8;
340894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4i8;
341894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 8)  return MVT::v8i8;
342894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 16) return MVT::v16i8;
343894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 32) return MVT::v32i8;
344894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
345894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::i16:
346894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2i16;
347894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4i16;
348894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 8)  return MVT::v8i16;
349894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 16) return MVT::v16i16;
350894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
351894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::i32:
352894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2i32;
353894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4i32;
354894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 8)  return MVT::v8i32;
355894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
356894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::i64:
357894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 1)  return MVT::v1i64;
358894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2i64;
359894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4i64;
360894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 8)  return MVT::v8i64;
361894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
362894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::f32:
363894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2f32;
364894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4f32;
365894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 8)  return MVT::v8f32;
366894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
367894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      case MVT::f64:
368894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 2)  return MVT::v2f64;
369894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (NumElements == 4)  return MVT::v4f64;
370894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        break;
371894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
372894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return (MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE);
373894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
374894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
375894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
37619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
37719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// EVT - Extended Value Type.  Capable of holding value types which are not
37819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// native for any processor (such as the i12345 type), as well as the types
37919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  /// a MVT can represent.
38019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  struct EVT {
381894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  private:
382894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT V;
38319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Type *LLVMTy;
384894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
385894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  public:
386894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
387894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman            LLVMTy(0) {}
388894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(0) { }
389894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT(MVT S) : V(S), LLVMTy(0) {}
390894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
39119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    bool operator==(EVT VT) const {
39219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return !(*this != VT);
39319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
39419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    bool operator!=(EVT VT) const {
39519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (V.SimpleTy != VT.V.SimpleTy)
396894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return true;
39719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (V.SimpleTy == MVT::INVALID_SIMPLE_VALUE_TYPE)
39819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        return LLVMTy != VT.LLVMTy;
399894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return false;
400894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
401894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
402894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getFloatingPointVT - Returns the EVT that represents a floating point
403894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// type with the given number of bits.  There are two floating point types
404894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// with 128 bits - this returns f128 rather than ppcf128.
405894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getFloatingPointVT(unsigned BitWidth) {
406894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return MVT::getFloatingPointVT(BitWidth);
407894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
408894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
409894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getIntegerVT - Returns the EVT that represents an integer with the given
410894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// number of bits.
411894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth) {
412894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      MVT M = MVT::getIntegerVT(BitWidth);
41319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
414894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return M;
41519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getExtendedIntegerVT(Context, BitWidth);
416894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
417894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
418894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getVectorVT - Returns the EVT that represents a vector NumElements in
419894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// length, where each element is of type VT.
420894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements) {
421894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      MVT M = MVT::getVectorVT(VT.V, NumElements);
42219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (M.SimpleTy != MVT::INVALID_SIMPLE_VALUE_TYPE)
423894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return M;
42419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getExtendedVectorVT(Context, VT, NumElements);
425894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
426894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
427894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getIntVectorWithNumElements - Return any integer vector type that has
428894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// the specified number of elements.
429894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getIntVectorWithNumElements(LLVMContext &C, unsigned NumElts) {
43019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      switch (NumElts) {
43119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      default: return getVectorVT(C, MVT::i8, NumElts);
43219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case  1: return MVT::v1i64;
43319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case  2: return MVT::v2i32;
43419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case  4: return MVT::v4i16;
43519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case  8: return MVT::v8i8;
43619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      case 16: return MVT::v16i8;
43719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      }
43819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return MVT::INVALID_SIMPLE_VALUE_TYPE;
43919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    }
44019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
44119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// changeVectorElementTypeToInteger - Return a vector with the same number
44219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// of elements as this vector, but with the element type converted to an
44319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    /// integer type with the same bitwidth.
44419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    EVT changeVectorElementTypeToInteger() const {
44519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (!isSimple())
44619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        return changeExtendedVectorElementTypeToInteger();
44719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      MVT EltTy = getSimpleVT().getVectorElementType();
44819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      unsigned BitWidth = EltTy.getSizeInBits();
44919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      MVT IntTy = MVT::getIntegerVT(BitWidth);
45019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      MVT VecTy = MVT::getVectorVT(IntTy, getVectorNumElements());
45119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      assert(VecTy != MVT::INVALID_SIMPLE_VALUE_TYPE &&
45219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman             "Simple vector VT not representable by simple integer vector VT!");
45319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return VecTy;
454894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
455894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
456894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isSimple - Test if the given EVT is simple (as opposed to being
457894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// extended).
458894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isSimple() const {
459894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return V.SimpleTy <= MVT::LastSimpleValueType;
460894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
461894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
462894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isExtended - Test if the given EVT is extended (as opposed to
463894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// being simple).
464894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtended() const {
465894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return !isSimple();
466894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
467894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
468894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isFloatingPoint - Return true if this is a FP, or a vector FP type.
469894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isFloatingPoint() const {
470894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
471894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
472894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
473894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isInteger - Return true if this is an integer, or a vector integer type.
474894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isInteger() const {
475894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isSimple() ? V.isInteger() : isExtendedInteger();
476894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
477894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
478894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isVector - Return true if this is a vector value type.
479894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isVector() const {
480894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isSimple() ? V.isVector() : isExtendedVector();
481894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
482894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
483894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// is64BitVector - Return true if this is a 64-bit vector type.
484894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool is64BitVector() const {
48519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (!isSimple())
48619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        return isExtended64BitVector();
48719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
48819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return (V == MVT::v8i8  || V==MVT::v4i16 || V==MVT::v2i32 ||
48919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman              V == MVT::v1i64 || V==MVT::v2f32);
490894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
491894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
492894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// is128BitVector - Return true if this is a 128-bit vector type.
493894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool is128BitVector() const {
49419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (!isSimple())
49519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        return isExtended128BitVector();
49619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return (V==MVT::v16i8 || V==MVT::v8i16 || V==MVT::v4i32 ||
49719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman              V==MVT::v2i64 || V==MVT::v4f32 || V==MVT::v2f64);
498894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
499894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
500894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// is256BitVector - Return true if this is a 256-bit vector type.
501894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    inline bool is256BitVector() const {
50219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      if (!isSimple())
50319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        return isExtended256BitVector();
50419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return (V == MVT::v8f32  || V == MVT::v4f64 || V == MVT::v32i8 ||
50519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman              V == MVT::v16i16 || V == MVT::v8i32 || V == MVT::v4i64);
506894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
507894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
508894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// is512BitVector - Return true if this is a 512-bit vector type.
509894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    inline bool is512BitVector() const {
510894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isSimple() ? (V == MVT::v8i64) : isExtended512BitVector();
511894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
512894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
513894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isOverloaded - Return true if this is an overloaded type for TableGen.
514894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isOverloaded() const {
515894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return (V==MVT::iAny || V==MVT::fAny || V==MVT::vAny || V==MVT::iPTRAny);
516894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
517894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
518894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isByteSized - Return true if the bit size is a multiple of 8.
519894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isByteSized() const {
520894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return (getSizeInBits() & 7) == 0;
521894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
522894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
523894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isRound - Return true if the size is a power-of-two number of bytes.
524894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isRound() const {
525894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      unsigned BitSize = getSizeInBits();
526894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return BitSize >= 8 && !(BitSize & (BitSize - 1));
527894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
528894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
529894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// bitsEq - Return true if this has the same number of bits as VT.
530894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool bitsEq(EVT VT) const {
531894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (EVT::operator==(VT)) return true;
532894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getSizeInBits() == VT.getSizeInBits();
533894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
534894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
535894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// bitsGT - Return true if this has more bits than VT.
536894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool bitsGT(EVT VT) const {
537894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (EVT::operator==(VT)) return false;
538894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getSizeInBits() > VT.getSizeInBits();
539894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
540894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
541894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// bitsGE - Return true if this has no less bits than VT.
542894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool bitsGE(EVT VT) const {
543894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (EVT::operator==(VT)) return true;
544894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getSizeInBits() >= VT.getSizeInBits();
545894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
546894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
547894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// bitsLT - Return true if this has less bits than VT.
548894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool bitsLT(EVT VT) const {
549894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (EVT::operator==(VT)) return false;
550894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getSizeInBits() < VT.getSizeInBits();
551894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
552894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
553894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// bitsLE - Return true if this has no more bits than VT.
554894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool bitsLE(EVT VT) const {
555894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (EVT::operator==(VT)) return true;
556894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getSizeInBits() <= VT.getSizeInBits();
557894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
558894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
559894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
560894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getSimpleVT - Return the SimpleValueType held in the specified
561894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// simple EVT.
562894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    MVT getSimpleVT() const {
563894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(isSimple() && "Expected a SimpleValueType!");
564894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return V;
565894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
566894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
567894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getScalarType - If this is a vector type, return the element type,
568894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// otherwise return this.
569894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getScalarType() const {
570894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return isVector() ? getVectorElementType() : *this;
571894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
57219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
573894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getVectorElementType - Given a vector type, return the type of
574894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// each element.
575894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getVectorElementType() const {
576894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(isVector() && "Invalid vector type!");
577894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (isSimple())
578894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return V.getVectorElementType();
57919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getExtendedVectorElementType();
580894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
581894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
582894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getVectorNumElements - Given a vector type, return the number of
583894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// elements it contains.
584894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getVectorNumElements() const {
585894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(isVector() && "Invalid vector type!");
586894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (isSimple())
587894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return V.getVectorNumElements();
58819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getExtendedVectorNumElements();
589894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
590894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
591894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getSizeInBits - Return the size of the specified value type in bits.
592894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getSizeInBits() const {
593894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (isSimple())
594894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return V.getSizeInBits();
59519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getExtendedSizeInBits();
596894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
597894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
598894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getStoreSize - Return the number of bytes overwritten by a store
599894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// of the specified value type.
600894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getStoreSize() const {
601894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return (getSizeInBits() + 7) / 8;
602894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
603894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
604894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getStoreSizeInBits - Return the number of bits overwritten by a store
605894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// of the specified value type.
606894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getStoreSizeInBits() const {
607894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getStoreSize() * 8;
608894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
609894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
610894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getRoundIntegerType - Rounds the bit-width of the given integer EVT up
611894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// to the nearest power of two (and at least to eight), and returns the
612894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// integer EVT with that number of bits.
613894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getRoundIntegerType(LLVMContext &Context) const {
614894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(isInteger() && !isVector() && "Invalid integer type!");
615894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      unsigned BitWidth = getSizeInBits();
616894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (BitWidth <= 8)
617894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return EVT(MVT::i8);
61819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman      return getIntegerVT(Context, 1 << Log2_32_Ceil(BitWidth));
619894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
620894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
621894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getHalfSizedIntegerVT - Finds the smallest simple value type that is
622894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// greater than or equal to half the width of this EVT. If no simple
623894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// value type can be found, an extended integer value type of half the
624894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// size (rounded up) is returned.
625894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getHalfSizedIntegerVT(LLVMContext &Context) const {
626894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      assert(isInteger() && !isVector() && "Invalid integer type!");
627894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      unsigned EVTSize = getSizeInBits();
628894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      for (unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
62919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman          IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
630894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        EVT HalfVT = EVT((MVT::SimpleValueType)IntVT);
63119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman        if (HalfVT.getSizeInBits() * 2 >= EVTSize)
632894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          return HalfVT;
633894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
634894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return getIntegerVT(Context, (EVTSize + 1) / 2);
635894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
636894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
637894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// isPow2VectorType - Returns true if the given vector is a power of 2.
638894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isPow2VectorType() const {
639894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      unsigned NElts = getVectorNumElements();
640894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      return !(NElts & (NElts - 1));
641894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
642894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
643894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getPow2VectorType - Widens the length of the given vector EVT up to
644894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// the nearest power of 2 and returns that type.
645894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getPow2VectorType(LLVMContext &Context) const {
646894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (!isPow2VectorType()) {
647894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        unsigned NElts = getVectorNumElements();
648894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        unsigned Pow2NElts = 1 <<  Log2_32_Ceil(NElts);
649894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return EVT::getVectorVT(Context, getVectorElementType(), Pow2NElts);
650894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
651894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      else {
652894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return *this;
653894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
654894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
655894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
656894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getEVTString - This function returns value type as a string,
657894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// e.g. "i32".
658894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    std::string getEVTString() const;
659894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
660894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getTypeForEVT - This method returns an LLVM type corresponding to the
661894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// specified EVT.  For integer types, this returns an unsigned type.  Note
662894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// that this will abort for types that cannot be represented.
66319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    Type *getTypeForEVT(LLVMContext &Context) const;
664894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
665894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// getEVT - Return the value type corresponding to the specified type.
666894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// This returns all pointers as iPTR.  If HandleUnknown is true, unknown
667894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// types are returned as Other, otherwise they are invalid.
66819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    static EVT getEVT(Type *Ty, bool HandleUnknown = false);
669894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
670894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    intptr_t getRawBits() {
671894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      if (isSimple())
672894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return V.SimpleTy;
673894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      else
674894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        return (intptr_t)(LLVMTy);
675894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    }
676894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
677894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// compareRawBits - A meaningless but well-behaved order, useful for
678894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    /// constructing containers.
679894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    struct compareRawBits {
680894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      bool operator()(EVT L, EVT R) const {
681894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        if (L.V.SimpleTy == R.V.SimpleTy)
682894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          return L.LLVMTy < R.LLVMTy;
683894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman        else
684894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman          return L.V.SimpleTy < R.V.SimpleTy;
685894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman      }
686894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    };
687894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
688894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  private:
689894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // Methods for handling the Extended-type case in functions above.
690894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // These are all out-of-line to prevent users of this header file
691894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    // from having a dependency on Type.h.
69219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman    EVT changeExtendedVectorElementTypeToInteger() const;
693894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getExtendedIntegerVT(LLVMContext &C, unsigned BitWidth);
694894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    static EVT getExtendedVectorVT(LLVMContext &C, EVT VT,
695894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   unsigned NumElements);
696894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtendedFloatingPoint() const;
697894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtendedInteger() const;
698894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtendedVector() const;
699894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtended64BitVector() const;
700894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtended128BitVector() const;
701894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtended256BitVector() const;
702894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    bool isExtended512BitVector() const;
703894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    EVT getExtendedVectorElementType() const;
704894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getExtendedVectorNumElements() const;
705894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman    unsigned getExtendedSizeInBits() const;
706894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  };
707894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
708894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // End llvm namespace
709894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
710894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
711