Proper name 16 bit libcalls
[llvm/msp430.git] / utils / TableGen / TGValueTypes.cpp
blob8979e13f72baf95a78471fe8ca6e774e43f763a0
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 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"
19 #include <map>
20 #include <vector>
21 using namespace llvm;
23 namespace llvm {
25 class Type {
26 public:
27 virtual unsigned getSizeInBits() const = 0;
28 virtual ~Type() {}
33 class ExtendedIntegerType : public Type {
34 unsigned BitWidth;
35 public:
36 explicit ExtendedIntegerType(unsigned bits)
37 : BitWidth(bits) {}
38 unsigned getSizeInBits() const {
39 return getBitWidth();
41 unsigned getBitWidth() const {
42 return BitWidth;
46 class ExtendedVectorType : public Type {
47 MVT ElementType;
48 unsigned NumElements;
49 public:
50 ExtendedVectorType(MVT elty, unsigned num)
51 : ElementType(elty), NumElements(num) {}
52 unsigned getSizeInBits() const {
53 return getNumElements() * getElementType().getSizeInBits();
55 MVT getElementType() const {
56 return ElementType;
58 unsigned getNumElements() const {
59 return NumElements;
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);
71 MVT VT;
72 VT.LLVMTy = ET;
73 assert(VT.isExtended() && "Type is not extended!");
74 return VT;
77 MVT MVT::getExtendedVectorVT(MVT VT, unsigned NumElements) {
78 const Type *&ET = ExtendedVectorTypeMap[std::make_pair(VT.getRawBits(),
79 NumElements)];
80 if (!ET) ET = new ExtendedVectorType(VT, NumElements);
81 MVT ResultVT;
82 ResultVT.LLVMTy = ET;
83 assert(ResultVT.isExtended() && "Type is not extended!");
84 return ResultVT;
87 bool MVT::isExtendedFloatingPoint() const {
88 assert(isExtended() && "Type is not extended!");
89 // Extended floating-point types are not supported yet.
90 return false;
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();