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 MVT type is used by tablegen as well as in LLVM. In order to handle
11 // extended types, the MVT 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/Streams.h"
27 virtual unsigned getSizeInBits() const = 0;
32 class ExtendedIntegerType : public Type {
35 explicit ExtendedIntegerType(unsigned bits)
37 unsigned getSizeInBits() const {
40 unsigned getBitWidth() const {
45 class ExtendedVectorType : public Type {
49 ExtendedVectorType(MVT elty, unsigned num)
50 : ElementType(elty), NumElements(num) {}
51 unsigned getSizeInBits() const {
52 return getNumElements() * getElementType().getSizeInBits();
54 MVT getElementType() const {
57 unsigned getNumElements() const {
62 static std::map<unsigned, const Type *>
63 ExtendedIntegerTypeMap;
64 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
65 ExtendedVectorTypeMap;
67 MVT MVT::getExtendedIntegerVT(unsigned BitWidth) {
68 const Type *&ET = ExtendedIntegerTypeMap[BitWidth];
69 if (!ET) ET = new ExtendedIntegerType(BitWidth);
75 MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
76 const Type *&ET = ExtendedVectorTypeMap[std::make_pair(VT.getRawBits(),
78 if (!ET) ET = new ExtendedVectorType(VT, NumElements);
84 bool MVT::isExtendedFloatingPoint() const {
85 assert(isExtended() && "Type is not extended!");
86 // Extended floating-point types are not supported yet.
90 bool MVT::isExtendedInteger() const {
91 assert(isExtended() && "Type is not extended!");
92 return dynamic_cast<const ExtendedIntegerType *>(LLVMTy) != 0;
95 bool MVT::isExtendedVector() const {
96 assert(isExtended() && "Type is not extended!");
97 return dynamic_cast<const ExtendedVectorType *>(LLVMTy) != 0;
100 bool MVT::isExtended64BitVector() const {
101 assert(isExtended() && "Type is not extended!");
102 return isExtendedVector() && getSizeInBits() == 64;
105 bool MVT::isExtended128BitVector() const {
106 assert(isExtended() && "Type is not extended!");
107 return isExtendedVector() && getSizeInBits() == 128;
110 MVT MVT::getExtendedVectorElementType() const {
111 assert(isExtendedVector() && "Type is not an extended vector!");
112 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
115 unsigned MVT::getExtendedVectorNumElements() const {
116 assert(isExtendedVector() && "Type is not an extended vector!");
117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
120 unsigned MVT::getExtendedSizeInBits() const {
121 assert(isExtended() && "Type is not extended!");
122 return LLVMTy->getSizeInBits();