Silence -Wunused-variable in release builds.
[llvm/stm8.git] / utils / TableGen / TGValueTypes.cpp
blobaf0d9f44cf434aca1f4abdb56ca578f579dd82da
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 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 <map>
19 using namespace llvm;
21 namespace llvm {
23 class Type {
24 public:
25 virtual unsigned getSizeInBits() const = 0;
26 virtual ~Type() {}
31 class ExtendedIntegerType : public Type {
32 unsigned BitWidth;
33 public:
34 explicit ExtendedIntegerType(unsigned bits)
35 : BitWidth(bits) {}
36 unsigned getSizeInBits() const {
37 return getBitWidth();
39 unsigned getBitWidth() const {
40 return BitWidth;
44 class ExtendedVectorType : public Type {
45 EVT ElementType;
46 unsigned NumElements;
47 public:
48 ExtendedVectorType(EVT elty, unsigned num)
49 : ElementType(elty), NumElements(num) {}
50 unsigned getSizeInBits() const {
51 return getNumElements() * getElementType().getSizeInBits();
53 EVT getElementType() const {
54 return ElementType;
56 unsigned getNumElements() const {
57 return NumElements;
61 static std::map<unsigned, const Type *>
62 ExtendedIntegerTypeMap;
63 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
64 ExtendedVectorTypeMap;
66 bool EVT::isExtendedFloatingPoint() const {
67 assert(isExtended() && "Type is not extended!");
68 // Extended floating-point types are not supported yet.
69 return false;
72 bool EVT::isExtendedInteger() const {
73 assert(isExtended() && "Type is not extended!");
74 return dynamic_cast<const ExtendedIntegerType *>(LLVMTy) != 0;
77 bool EVT::isExtendedVector() const {
78 assert(isExtended() && "Type is not extended!");
79 return dynamic_cast<const ExtendedVectorType *>(LLVMTy) != 0;
82 bool EVT::isExtended64BitVector() const {
83 assert(isExtended() && "Type is not extended!");
84 return isExtendedVector() && getSizeInBits() == 64;
87 bool EVT::isExtended128BitVector() const {
88 assert(isExtended() && "Type is not extended!");
89 return isExtendedVector() && getSizeInBits() == 128;
92 EVT EVT::getExtendedVectorElementType() const {
93 assert(isExtendedVector() && "Type is not an extended vector!");
94 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
97 unsigned EVT::getExtendedVectorNumElements() const {
98 assert(isExtendedVector() && "Type is not an extended vector!");
99 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
102 unsigned EVT::getExtendedSizeInBits() const {
103 assert(isExtended() && "Type is not extended!");
104 return LLVMTy->getSizeInBits();