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:
getKind() const33 TypeKind getKind() const {
34 return Kind;
35 }
Type(TypeKind K)36 Type(TypeKind K) : Kind(K) {}
37 virtual unsigned getSizeInBits() const = 0;
~Type()38 virtual ~Type() {}
39 };
40
41 }
42
43 class ExtendedIntegerType : public Type {
44 unsigned BitWidth;
45 public:
ExtendedIntegerType(unsigned bits)46 explicit ExtendedIntegerType(unsigned bits)
47 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
classof(const Type * T)48 static bool classof(const Type *T) {
49 return T->getKind() == TK_ExtendedIntegerType;
50 }
getSizeInBits() const51 unsigned getSizeInBits() const {
52 return getBitWidth();
53 }
getBitWidth() const54 unsigned getBitWidth() const {
55 return BitWidth;
56 }
57 };
58
59 class ExtendedVectorType : public Type {
60 EVT ElementType;
61 unsigned NumElements;
62 public:
ExtendedVectorType(EVT elty,unsigned num)63 ExtendedVectorType(EVT elty, unsigned num)
64 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
classof(const Type * T)65 static bool classof(const Type *T) {
66 return T->getKind() == TK_ExtendedVectorType;
67 }
getSizeInBits() const68 unsigned getSizeInBits() const {
69 return getNumElements() * getElementType().getSizeInBits();
70 }
getElementType() const71 EVT getElementType() const {
72 return ElementType;
73 }
getNumElements() const74 unsigned getNumElements() const {
75 return NumElements;
76 }
77 };
78
79 static std::map<unsigned, const Type *>
80 ExtendedIntegerTypeMap;
81 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
82 ExtendedVectorTypeMap;
83
isExtendedFloatingPoint() const84 bool EVT::isExtendedFloatingPoint() const {
85 assert(isExtended() && "Type is not extended!");
86 // Extended floating-point types are not supported yet.
87 return false;
88 }
89
isExtendedInteger() const90 bool EVT::isExtendedInteger() const {
91 assert(isExtended() && "Type is not extended!");
92 return isa<ExtendedIntegerType>(LLVMTy);
93 }
94
isExtendedVector() const95 bool EVT::isExtendedVector() const {
96 assert(isExtended() && "Type is not extended!");
97 return isa<ExtendedVectorType>(LLVMTy);
98 }
99
isExtended64BitVector() const100 bool EVT::isExtended64BitVector() const {
101 assert(isExtended() && "Type is not extended!");
102 return isExtendedVector() && getSizeInBits() == 64;
103 }
104
isExtended128BitVector() const105 bool EVT::isExtended128BitVector() const {
106 assert(isExtended() && "Type is not extended!");
107 return isExtendedVector() && getSizeInBits() == 128;
108 }
109
getExtendedVectorElementType() const110 EVT EVT::getExtendedVectorElementType() const {
111 assert(isExtendedVector() && "Type is not an extended vector!");
112 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
113 }
114
getExtendedVectorNumElements() const115 unsigned EVT::getExtendedVectorNumElements() const {
116 assert(isExtendedVector() && "Type is not an extended vector!");
117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
118 }
119
getExtendedSizeInBits() const120 unsigned EVT::getExtendedSizeInBits() const {
121 assert(isExtended() && "Type is not extended!");
122 return LLVMTy->getSizeInBits();
123 }
124