1 //===- ValueTypes.cpp - Tablegen extended ValueType implementation --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/CodeGen/ValueTypes.h"
18 #include "llvm/Support/Casting.h"
27 TK_ExtendedIntegerType,
33 TypeKind getKind() const {
36 Type(TypeKind K) : Kind(K) {}
37 virtual unsigned getSizeInBits() const = 0;
45 class ExtendedIntegerType : public Type {
48 explicit ExtendedIntegerType(unsigned bits)
49 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
50 virtual ~ExtendedIntegerType();
51 static bool classof(const Type *T) {
52 return T->getKind() == TK_ExtendedIntegerType;
54 virtual unsigned getSizeInBits() const {
57 unsigned getBitWidth() const {
62 ExtendedIntegerType::~ExtendedIntegerType() {}
65 class ExtendedVectorType : public Type {
69 ExtendedVectorType(EVT elty, unsigned num)
70 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
71 virtual ~ExtendedVectorType();
72 static bool classof(const Type *T) {
73 return T->getKind() == TK_ExtendedVectorType;
75 virtual unsigned getSizeInBits() const {
76 return getNumElements() * getElementType().getSizeInBits();
78 EVT getElementType() const {
81 unsigned getNumElements() const {
86 ExtendedVectorType::~ExtendedVectorType() {}
89 static std::map<unsigned, const Type *>
90 ExtendedIntegerTypeMap;
91 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
92 ExtendedVectorTypeMap;
94 bool EVT::isExtendedFloatingPoint() const {
95 assert(isExtended() && "Type is not extended!");
96 // Extended floating-point types are not supported yet.
100 bool EVT::isExtendedInteger() const {
101 assert(isExtended() && "Type is not extended!");
102 return isa<ExtendedIntegerType>(LLVMTy);
105 bool EVT::isExtendedVector() const {
106 assert(isExtended() && "Type is not extended!");
107 return isa<ExtendedVectorType>(LLVMTy);
110 bool EVT::isExtended64BitVector() const {
111 assert(isExtended() && "Type is not extended!");
112 return isExtendedVector() && getSizeInBits() == 64;
115 bool EVT::isExtended128BitVector() const {
116 assert(isExtended() && "Type is not extended!");
117 return isExtendedVector() && getSizeInBits() == 128;
120 EVT EVT::getExtendedVectorElementType() const {
121 assert(isExtendedVector() && "Type is not an extended vector!");
122 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
125 unsigned EVT::getExtendedVectorNumElements() const {
126 assert(isExtendedVector() && "Type is not an extended vector!");
127 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
130 unsigned EVT::getExtendedSizeInBits() const {
131 assert(isExtended() && "Type is not extended!");
132 return LLVMTy->getSizeInBits();