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;
43 class ExtendedIntegerType : public Type {
46 explicit ExtendedIntegerType(unsigned bits)
47 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
48 static bool classof(const Type *T) {
49 return T->getKind() == TK_ExtendedIntegerType;
51 unsigned getSizeInBits() const {
54 unsigned getBitWidth() const {
59 class ExtendedVectorType : public Type {
63 ExtendedVectorType(EVT elty, unsigned num)
64 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
65 static bool classof(const Type *T) {
66 return T->getKind() == TK_ExtendedVectorType;
68 unsigned getSizeInBits() const {
69 return getNumElements() * getElementType().getSizeInBits();
71 EVT getElementType() const {
74 unsigned getNumElements() const {
79 static std::map<unsigned, const Type *>
80 ExtendedIntegerTypeMap;
81 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
82 ExtendedVectorTypeMap;
84 bool EVT::isExtendedFloatingPoint() const {
85 assert(isExtended() && "Type is not extended!");
86 // Extended floating-point types are not supported yet.
90 bool EVT::isExtendedInteger() const {
91 assert(isExtended() && "Type is not extended!");
92 return isa<ExtendedIntegerType>(LLVMTy);
95 bool EVT::isExtendedVector() const {
96 assert(isExtended() && "Type is not extended!");
97 return isa<ExtendedVectorType>(LLVMTy);
100 bool EVT::isExtended64BitVector() const {
101 assert(isExtended() && "Type is not extended!");
102 return isExtendedVector() && getSizeInBits() == 64;
105 bool EVT::isExtended128BitVector() const {
106 assert(isExtended() && "Type is not extended!");
107 return isExtendedVector() && getSizeInBits() == 128;
110 EVT EVT::getExtendedVectorElementType() const {
111 assert(isExtendedVector() && "Type is not an extended vector!");
112 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
115 unsigned EVT::getExtendedVectorNumElements() const {
116 assert(isExtendedVector() && "Type is not an extended vector!");
117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
120 unsigned EVT::getExtendedSizeInBits() const {
121 assert(isExtended() && "Type is not extended!");
122 return LLVMTy->getSizeInBits();