acb9985e499d3d207e66dfd1572feb9f4ba28bc7
[oota-llvm.git] / utils / TableGen / TGValueTypes.cpp
1 //===- ValueTypes.cpp - Tablegen extended ValueType implementation --------===//
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 // The EVT type is used by tablegen as well as in LLVM. In order to handle
11 // extended types, the EVT type uses support functions that call into
12 // LLVM's type system code. These aren't accessible in tablegen, so this
13 // file provides simple replacements.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "llvm/CodeGen/ValueTypes.h"
18 #include <map>
19 using namespace llvm;
20
21 #pragma clang diagnostic push
22 #pragma clang diagnostic ignored "-Wweak-vtables"
23
24 namespace llvm {
25
26 class Type {
27 public:
28   virtual unsigned getSizeInBits() const = 0;
29   virtual ~Type() {}
30 };
31
32 }
33
34 class ExtendedIntegerType : public Type {
35   unsigned BitWidth;
36 public:
37   explicit ExtendedIntegerType(unsigned bits)
38     : BitWidth(bits) {}
39   unsigned getSizeInBits() const {
40     return getBitWidth();
41   }
42   unsigned getBitWidth() const {
43     return BitWidth;
44   }
45 };
46
47 class ExtendedVectorType : public Type {
48   EVT ElementType;
49   unsigned NumElements;
50 public:
51   ExtendedVectorType(EVT elty, unsigned num)
52     : ElementType(elty), NumElements(num) {}
53   unsigned getSizeInBits() const {
54     return getNumElements() * getElementType().getSizeInBits();
55   }
56   EVT getElementType() const {
57     return ElementType;
58   }
59   unsigned getNumElements() const {
60     return NumElements;
61   }
62 };
63
64 #pragma clang diagnostic pop
65
66 static std::map<unsigned, const Type *>
67   ExtendedIntegerTypeMap;
68 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
69   ExtendedVectorTypeMap;
70
71 bool EVT::isExtendedFloatingPoint() const {
72   assert(isExtended() && "Type is not extended!");
73   // Extended floating-point types are not supported yet.
74   return false;
75 }
76
77 bool EVT::isExtendedInteger() const {
78   assert(isExtended() && "Type is not extended!");
79   return dynamic_cast<const ExtendedIntegerType *>(LLVMTy) != 0;
80 }
81
82 bool EVT::isExtendedVector() const {
83   assert(isExtended() && "Type is not extended!");
84   return dynamic_cast<const ExtendedVectorType *>(LLVMTy) != 0;
85 }
86
87 bool EVT::isExtended64BitVector() const {
88   assert(isExtended() && "Type is not extended!");
89   return isExtendedVector() && getSizeInBits() == 64;
90 }
91
92 bool EVT::isExtended128BitVector() const {
93   assert(isExtended() && "Type is not extended!");
94   return isExtendedVector() && getSizeInBits() == 128;
95 }
96
97 EVT EVT::getExtendedVectorElementType() const {
98   assert(isExtendedVector() && "Type is not an extended vector!");
99   return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
100 }
101
102 unsigned EVT::getExtendedVectorNumElements() const {
103   assert(isExtendedVector() && "Type is not an extended vector!");
104   return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
105 }
106
107 unsigned EVT::getExtendedSizeInBits() const {
108   assert(isExtended() && "Type is not extended!");
109   return LLVMTy->getSizeInBits();
110 }