TGValueTypes.cpp revision 263508
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. 14// 15//===----------------------------------------------------------------------===// 16 17#include "llvm/CodeGen/ValueTypes.h" 18#include "llvm/Support/Casting.h" 19#include <map> 20using namespace llvm; 21 22namespace llvm { 23 24class Type { 25protected: 26 enum TypeKind { 27 TK_ExtendedIntegerType, 28 TK_ExtendedVectorType 29 }; 30private: 31 TypeKind Kind; 32public: 33 TypeKind getKind() const { 34 return Kind; 35 } 36 Type(TypeKind K) : Kind(K) {} 37 virtual unsigned getSizeInBits() const = 0; 38 virtual ~Type(); 39}; 40 41// Provide out-of-line definition to prevent weak vtable. 42Type::~Type() {} 43 44} 45 46namespace { 47class ExtendedIntegerType : public Type { 48 unsigned BitWidth; 49public: 50 explicit ExtendedIntegerType(unsigned bits) 51 : Type(TK_ExtendedIntegerType), BitWidth(bits) {} 52 static bool classof(const Type *T) { 53 return T->getKind() == TK_ExtendedIntegerType; 54 } 55 virtual unsigned getSizeInBits() const { 56 return getBitWidth(); 57 } 58 unsigned getBitWidth() const { 59 return BitWidth; 60 } 61}; 62 63class ExtendedVectorType : public Type { 64 EVT ElementType; 65 unsigned NumElements; 66public: 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; 71 } 72 virtual unsigned getSizeInBits() const { 73 return getNumElements() * getElementType().getSizeInBits(); 74 } 75 EVT getElementType() const { 76 return ElementType; 77 } 78 unsigned getNumElements() const { 79 return NumElements; 80 } 81}; 82} // end anonymous namespace 83 84static std::map<unsigned, const Type *> 85 ExtendedIntegerTypeMap; 86static std::map<std::pair<uintptr_t, uintptr_t>, const Type *> 87 ExtendedVectorTypeMap; 88 89bool EVT::isExtendedFloatingPoint() const { 90 assert(isExtended() && "Type is not extended!"); 91 // Extended floating-point types are not supported yet. 92 return false; 93} 94 95bool EVT::isExtendedInteger() const { 96 assert(isExtended() && "Type is not extended!"); 97 return isa<ExtendedIntegerType>(LLVMTy); 98} 99 100bool EVT::isExtendedVector() const { 101 assert(isExtended() && "Type is not extended!"); 102 return isa<ExtendedVectorType>(LLVMTy); 103} 104 105bool EVT::isExtended64BitVector() const { 106 assert(isExtended() && "Type is not extended!"); 107 return isExtendedVector() && getSizeInBits() == 64; 108} 109 110bool EVT::isExtended128BitVector() const { 111 assert(isExtended() && "Type is not extended!"); 112 return isExtendedVector() && getSizeInBits() == 128; 113} 114 115EVT EVT::getExtendedVectorElementType() const { 116 assert(isExtendedVector() && "Type is not an extended vector!"); 117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType(); 118} 119 120unsigned EVT::getExtendedVectorNumElements() const { 121 assert(isExtendedVector() && "Type is not an extended vector!"); 122 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements(); 123} 124 125unsigned EVT::getExtendedSizeInBits() const { 126 assert(isExtended() && "Type is not extended!"); 127 return LLVMTy->getSizeInBits(); 128} 129