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;
33 class ExtendedIntegerType
: public Type
{
36 explicit ExtendedIntegerType(unsigned bits
)
38 unsigned getSizeInBits() const {
41 unsigned getBitWidth() const {
46 class ExtendedVectorType
: public Type
{
50 ExtendedVectorType(MVT elty
, unsigned num
)
51 : ElementType(elty
), NumElements(num
) {}
52 unsigned getSizeInBits() const {
53 return getNumElements() * getElementType().getSizeInBits();
55 MVT
getElementType() const {
58 unsigned getNumElements() const {
63 static std::map
<unsigned, const Type
*>
64 ExtendedIntegerTypeMap
;
65 static std::map
<std::pair
<uintptr_t, uintptr_t>, const Type
*>
66 ExtendedVectorTypeMap
;
68 MVT
MVT::getExtendedIntegerVT(unsigned BitWidth
) {
69 const Type
*&ET
= ExtendedIntegerTypeMap
[BitWidth
];
70 if (!ET
) ET
= new ExtendedIntegerType(BitWidth
);
73 assert(VT
.isExtended() && "Type is not extended!");
77 MVT
MVT::getExtendedVectorVT(MVT VT
, unsigned NumElements
) {
78 const Type
*&ET
= ExtendedVectorTypeMap
[std::make_pair(VT
.getRawBits(),
80 if (!ET
) ET
= new ExtendedVectorType(VT
, NumElements
);
83 assert(ResultVT
.isExtended() && "Type is not extended!");
87 bool MVT::isExtendedFloatingPoint() const {
88 assert(isExtended() && "Type is not extended!");
89 // Extended floating-point types are not supported yet.
93 bool MVT::isExtendedInteger() const {
94 assert(isExtended() && "Type is not extended!");
95 return dynamic_cast<const ExtendedIntegerType
*>(LLVMTy
) != 0;
98 bool MVT::isExtendedVector() const {
99 assert(isExtended() && "Type is not extended!");
100 return dynamic_cast<const ExtendedVectorType
*>(LLVMTy
) != 0;
103 bool MVT::isExtended64BitVector() const {
104 assert(isExtended() && "Type is not extended!");
105 return isExtendedVector() && getSizeInBits() == 64;
108 bool MVT::isExtended128BitVector() const {
109 assert(isExtended() && "Type is not extended!");
110 return isExtendedVector() && getSizeInBits() == 128;
113 MVT
MVT::getExtendedVectorElementType() const {
114 assert(isExtendedVector() && "Type is not an extended vector!");
115 return static_cast<const ExtendedVectorType
*>(LLVMTy
)->getElementType();
118 unsigned MVT::getExtendedVectorNumElements() const {
119 assert(isExtendedVector() && "Type is not an extended vector!");
120 return static_cast<const ExtendedVectorType
*>(LLVMTy
)->getNumElements();
123 unsigned MVT::getExtendedSizeInBits() const {
124 assert(isExtended() && "Type is not extended!");
125 return LLVMTy
->getSizeInBits();