[weak vtables] Remove a bunch of weak vtables
[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 "llvm/Support/Casting.h"
19 #include <map>
20 using namespace llvm;
21
22 namespace llvm {
23
24 class Type {
25 protected:
26   enum TypeKind {
27     TK_ExtendedIntegerType,
28     TK_ExtendedVectorType
29   };
30 private:
31   TypeKind Kind;
32 public:
33   TypeKind getKind() const {
34     return Kind;
35   }
36   Type(TypeKind K) : Kind(K) {}
37   virtual unsigned getSizeInBits() const = 0;
38   virtual ~Type();
39 };
40
41 // Provide out-of-line definition to prevent weak vtable.
42 Type::~Type() {}
43
44 }
45
46 class ExtendedIntegerType : public Type {
47   unsigned BitWidth;
48 public:
49   explicit ExtendedIntegerType(unsigned bits)
50     : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
51   virtual ~ExtendedIntegerType();
52   static bool classof(const Type *T) {
53     return T->getKind() == TK_ExtendedIntegerType;
54   }
55   virtual unsigned getSizeInBits() const {
56     return getBitWidth();
57   }
58   unsigned getBitWidth() const {
59     return BitWidth;
60   }
61 };
62
63 // Provide out-of-line definition to prevent weak vtable.
64 ExtendedIntegerType::~ExtendedIntegerType() {}
65
66 class ExtendedVectorType : public Type {
67   EVT ElementType;
68   unsigned NumElements;
69 public:
70   ExtendedVectorType(EVT elty, unsigned num)
71     : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
72   virtual ~ExtendedVectorType();
73   static bool classof(const Type *T) {
74     return T->getKind() == TK_ExtendedVectorType;
75   }
76   virtual unsigned getSizeInBits() const {
77     return getNumElements() * getElementType().getSizeInBits();
78   }
79   EVT getElementType() const {
80     return ElementType;
81   }
82   unsigned getNumElements() const {
83     return NumElements;
84   }
85 };
86
87 // Provide out-of-line definition to prevent weak vtable.
88 ExtendedVectorType::~ExtendedVectorType() {}
89
90 static std::map<unsigned, const Type *>
91   ExtendedIntegerTypeMap;
92 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
93   ExtendedVectorTypeMap;
94
95 bool EVT::isExtendedFloatingPoint() const {
96   assert(isExtended() && "Type is not extended!");
97   // Extended floating-point types are not supported yet.
98   return false;
99 }
100
101 bool EVT::isExtendedInteger() const {
102   assert(isExtended() && "Type is not extended!");
103   return isa<ExtendedIntegerType>(LLVMTy);
104 }
105
106 bool EVT::isExtendedVector() const {
107   assert(isExtended() && "Type is not extended!");
108   return isa<ExtendedVectorType>(LLVMTy);
109 }
110
111 bool EVT::isExtended64BitVector() const {
112   assert(isExtended() && "Type is not extended!");
113   return isExtendedVector() && getSizeInBits() == 64;
114 }
115
116 bool EVT::isExtended128BitVector() const {
117   assert(isExtended() && "Type is not extended!");
118   return isExtendedVector() && getSizeInBits() == 128;
119 }
120
121 EVT EVT::getExtendedVectorElementType() const {
122   assert(isExtendedVector() && "Type is not an extended vector!");
123   return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
124 }
125
126 unsigned EVT::getExtendedVectorNumElements() const {
127   assert(isExtendedVector() && "Type is not an extended vector!");
128   return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
129 }
130
131 unsigned EVT::getExtendedSizeInBits() const {
132   assert(isExtended() && "Type is not extended!");
133   return LLVMTy->getSizeInBits();
134 }