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.
47 class ExtendedIntegerType : public Type {
50 explicit ExtendedIntegerType(unsigned bits)
51 : Type(TK_ExtendedIntegerType), BitWidth(bits) {}
52 static bool classof(const Type *T) {
53 return T->getKind() == TK_ExtendedIntegerType;
55 virtual unsigned getSizeInBits() const {
58 unsigned getBitWidth() const {
63 class ExtendedVectorType : public Type {
67 ExtendedVectorType(EVT elty, unsigned num)
68 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {}
69 static bool classof(const Type *T) {
70 return T->getKind() == TK_ExtendedVectorType;
72 virtual unsigned getSizeInBits() const {
73 return getNumElements() * getElementType().getSizeInBits();
75 EVT getElementType() const {
78 unsigned getNumElements() const {
82 } // end anonymous namespace
84 static std::map<unsigned, const Type *>
85 ExtendedIntegerTypeMap;
86 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
87 ExtendedVectorTypeMap;
89 bool EVT::isExtendedFloatingPoint() const {
90 assert(isExtended() && "Type is not extended!");
91 // Extended floating-point types are not supported yet.
95 bool EVT::isExtendedInteger() const {
96 assert(isExtended() && "Type is not extended!");
97 return isa<ExtendedIntegerType>(LLVMTy);
100 bool EVT::isExtendedVector() const {
101 assert(isExtended() && "Type is not extended!");
102 return isa<ExtendedVectorType>(LLVMTy);
105 bool EVT::isExtended64BitVector() const {
106 assert(isExtended() && "Type is not extended!");
107 return isExtendedVector() && getSizeInBits() == 64;
110 bool EVT::isExtended128BitVector() const {
111 assert(isExtended() && "Type is not extended!");
112 return isExtendedVector() && getSizeInBits() == 128;
115 EVT EVT::getExtendedVectorElementType() const {
116 assert(isExtendedVector() && "Type is not an extended vector!");
117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
120 unsigned EVT::getExtendedVectorNumElements() const {
121 assert(isExtendedVector() && "Type is not an extended vector!");
122 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
125 unsigned EVT::getExtendedSizeInBits() const {
126 assert(isExtended() && "Type is not extended!");
127 return LLVMTy->getSizeInBits();