• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <map>
19 using namespace llvm;
20 
21 namespace llvm {
22 
23 class Type {
24 public:
25   virtual unsigned getSizeInBits() const = 0;
~Type()26   virtual ~Type() {}
27 };
28 
29 }
30 
31 class ExtendedIntegerType : public Type {
32   unsigned BitWidth;
33 public:
ExtendedIntegerType(unsigned bits)34   explicit ExtendedIntegerType(unsigned bits)
35     : BitWidth(bits) {}
getSizeInBits() const36   unsigned getSizeInBits() const {
37     return getBitWidth();
38   }
getBitWidth() const39   unsigned getBitWidth() const {
40     return BitWidth;
41   }
42 };
43 
44 class ExtendedVectorType : public Type {
45   EVT ElementType;
46   unsigned NumElements;
47 public:
ExtendedVectorType(EVT elty,unsigned num)48   ExtendedVectorType(EVT elty, unsigned num)
49     : ElementType(elty), NumElements(num) {}
getSizeInBits() const50   unsigned getSizeInBits() const {
51     return getNumElements() * getElementType().getSizeInBits();
52   }
getElementType() const53   EVT getElementType() const {
54     return ElementType;
55   }
getNumElements() const56   unsigned getNumElements() const {
57     return NumElements;
58   }
59 };
60 
61 static std::map<unsigned, const Type *>
62   ExtendedIntegerTypeMap;
63 static std::map<std::pair<uintptr_t, uintptr_t>, const Type *>
64   ExtendedVectorTypeMap;
65 
isExtendedFloatingPoint() const66 bool EVT::isExtendedFloatingPoint() const {
67   assert(isExtended() && "Type is not extended!");
68   // Extended floating-point types are not supported yet.
69   return false;
70 }
71 
isExtendedInteger() const72 bool EVT::isExtendedInteger() const {
73   assert(isExtended() && "Type is not extended!");
74   return dynamic_cast<const ExtendedIntegerType *>(LLVMTy) != 0;
75 }
76 
isExtendedVector() const77 bool EVT::isExtendedVector() const {
78   assert(isExtended() && "Type is not extended!");
79   return dynamic_cast<const ExtendedVectorType *>(LLVMTy) != 0;
80 }
81 
isExtended64BitVector() const82 bool EVT::isExtended64BitVector() const {
83   assert(isExtended() && "Type is not extended!");
84   return isExtendedVector() && getSizeInBits() == 64;
85 }
86 
isExtended128BitVector() const87 bool EVT::isExtended128BitVector() const {
88   assert(isExtended() && "Type is not extended!");
89   return isExtendedVector() && getSizeInBits() == 128;
90 }
91 
getExtendedVectorElementType() const92 EVT EVT::getExtendedVectorElementType() const {
93   assert(isExtendedVector() && "Type is not an extended vector!");
94   return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
95 }
96 
getExtendedVectorNumElements() const97 unsigned EVT::getExtendedVectorNumElements() const {
98   assert(isExtendedVector() && "Type is not an extended vector!");
99   return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
100 }
101 
getExtendedSizeInBits() const102 unsigned EVT::getExtendedSizeInBits() const {
103   assert(isExtended() && "Type is not extended!");
104   return LLVMTy->getSizeInBits();
105 }
106