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> 20 using namespace llvm; 21 22 namespace llvm { 23 24 class Type { 25 protected: 26 enum TypeKind { 27 TK_ExtendedIntegerType, 28 TK_ExtendedVectorType 29 }; 30 private: 31 TypeKind Kind; 32 public: 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 } 42 43 class ExtendedIntegerType : public Type { 44 unsigned BitWidth; 45 public: 46 explicit ExtendedIntegerType(unsigned bits) 47 : Type(TK_ExtendedIntegerType), BitWidth(bits) {} 48 static bool classof(const Type *T) { 49 return T->getKind() == TK_ExtendedIntegerType; 50 } 51 unsigned getSizeInBits() const { 52 return getBitWidth(); 53 } 54 unsigned getBitWidth() const { 55 return BitWidth; 56 } 57 }; 58 59 class ExtendedVectorType : public Type { 60 EVT ElementType; 61 unsigned NumElements; 62 public: 63 ExtendedVectorType(EVT elty, unsigned num) 64 : Type(TK_ExtendedVectorType), ElementType(elty), NumElements(num) {} 65 static bool classof(const Type *T) { 66 return T->getKind() == TK_ExtendedVectorType; 67 } 68 unsigned getSizeInBits() const { 69 return getNumElements() * getElementType().getSizeInBits(); 70 } 71 EVT getElementType() const { 72 return ElementType; 73 } 74 unsigned getNumElements() const { 75 return NumElements; 76 } 77 }; 78 79 static std::map<unsigned, const Type *> 80 ExtendedIntegerTypeMap; 81 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *> 82 ExtendedVectorTypeMap; 83 84 bool EVT::isExtendedFloatingPoint() const { 85 assert(isExtended() && "Type is not extended!"); 86 // Extended floating-point types are not supported yet. 87 return false; 88 } 89 90 bool EVT::isExtendedInteger() const { 91 assert(isExtended() && "Type is not extended!"); 92 return isa<ExtendedIntegerType>(LLVMTy); 93 } 94 95 bool EVT::isExtendedVector() const { 96 assert(isExtended() && "Type is not extended!"); 97 return isa<ExtendedVectorType>(LLVMTy); 98 } 99 100 bool EVT::isExtended64BitVector() const { 101 assert(isExtended() && "Type is not extended!"); 102 return isExtendedVector() && getSizeInBits() == 64; 103 } 104 105 bool EVT::isExtended128BitVector() const { 106 assert(isExtended() && "Type is not extended!"); 107 return isExtendedVector() && getSizeInBits() == 128; 108 } 109 110 EVT EVT::getExtendedVectorElementType() const { 111 assert(isExtendedVector() && "Type is not an extended vector!"); 112 return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType(); 113 } 114 115 unsigned EVT::getExtendedVectorNumElements() const { 116 assert(isExtendedVector() && "Type is not an extended vector!"); 117 return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements(); 118 } 119 120 unsigned EVT::getExtendedSizeInBits() const { 121 assert(isExtended() && "Type is not extended!"); 122 return LLVMTy->getSizeInBits(); 123 } 124