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;
41 // Provide out-of-line definition to prevent weak vtable.
46 class ExtendedIntegerType : public Type {
49 explicit ExtendedIntegerType(unsigned bits)
50 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
51 virtual ~ExtendedIntegerType();
52 static bool classof(const Type *T) {
53 return T->getKind() == TK_ExtendedIntegerType;
55 virtual unsigned getSizeInBits() const {
58 unsigned getBitWidth() const {
63 // Provide out-of-line definition to prevent weak vtable.
64 ExtendedIntegerType::~ExtendedIntegerType() {}
66 class ExtendedVectorType : public Type {
70 ExtendedVectorType(EVT elty, unsigned num)
71 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
72 virtual ~ExtendedVectorType();
73 static bool classof(const Type *T) {
74 return T->getKind() == TK_ExtendedVectorType;
76 virtual unsigned getSizeInBits() const {
77 return getNumElements() * getElementType().getSizeInBits();
79 EVT getElementType() const {
82 unsigned getNumElements() const {
87 // Provide out-of-line definition to prevent weak vtable.
88 ExtendedVectorType::~ExtendedVectorType() {}
90 static std::map<unsigned, const Type *>
91 ExtendedIntegerTypeMap;
92 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
93 ExtendedVectorTypeMap;
95 bool EVT::isExtendedFloatingPoint() const {
96 assert(isExtended() && "Type is not extended!");
97 // Extended floating-point types are not supported yet.
101 bool EVT::isExtendedInteger() const {
102 assert(isExtended() && "Type is not extended!");
103 return isa<ExtendedIntegerType>(LLVMTy);
106 bool EVT::isExtendedVector() const {
107 assert(isExtended() && "Type is not extended!");
108 return isa<ExtendedVectorType>(LLVMTy);
111 bool EVT::isExtended64BitVector() const {
112 assert(isExtended() && "Type is not extended!");
113 return isExtendedVector() && getSizeInBits() == 64;
116 bool EVT::isExtended128BitVector() const {
117 assert(isExtended() && "Type is not extended!");
118 return isExtendedVector() && getSizeInBits() == 128;
121 EVT EVT::getExtendedVectorElementType() const {
122 assert(isExtendedVector() && "Type is not an extended vector!");
123 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
126 unsigned EVT::getExtendedVectorNumElements() const {
127 assert(isExtendedVector() && "Type is not an extended vector!");
128 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
131 unsigned EVT::getExtendedSizeInBits() const {
132 assert(isExtended() && "Type is not extended!");
133 return LLVMTy->getSizeInBits();