Home | History | Annotate | Download | only in TableGen
      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;
     26   virtual ~Type() {}
     27 };
     28 
     29 }
     30 
     31 class ExtendedIntegerType : public Type {
     32   unsigned BitWidth;
     33 public:
     34   explicit ExtendedIntegerType(unsigned bits)
     35     : BitWidth(bits) {}
     36   unsigned getSizeInBits() const {
     37     return getBitWidth();
     38   }
     39   unsigned getBitWidth() const {
     40     return BitWidth;
     41   }
     42 };
     43 
     44 class ExtendedVectorType : public Type {
     45   EVT ElementType;
     46   unsigned NumElements;
     47 public:
     48   ExtendedVectorType(EVT elty, unsigned num)
     49     : ElementType(elty), NumElements(num) {}
     50   unsigned getSizeInBits() const {
     51     return getNumElements() * getElementType().getSizeInBits();
     52   }
     53   EVT getElementType() const {
     54     return ElementType;
     55   }
     56   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 
     66 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 
     72 bool EVT::isExtendedInteger() const {
     73   assert(isExtended() && "Type is not extended!");
     74   return dynamic_cast<const ExtendedIntegerType *>(LLVMTy) != 0;
     75 }
     76 
     77 bool EVT::isExtendedVector() const {
     78   assert(isExtended() && "Type is not extended!");
     79   return dynamic_cast<const ExtendedVectorType *>(LLVMTy) != 0;
     80 }
     81 
     82 bool EVT::isExtended64BitVector() const {
     83   assert(isExtended() && "Type is not extended!");
     84   return isExtendedVector() && getSizeInBits() == 64;
     85 }
     86 
     87 bool EVT::isExtended128BitVector() const {
     88   assert(isExtended() && "Type is not extended!");
     89   return isExtendedVector() && getSizeInBits() == 128;
     90 }
     91 
     92 EVT EVT::getExtendedVectorElementType() const {
     93   assert(isExtendedVector() && "Type is not an extended vector!");
     94   return static_cast<const ExtendedVectorType *>(LLVMTy)->getElementType();
     95 }
     96 
     97 unsigned EVT::getExtendedVectorNumElements() const {
     98   assert(isExtendedVector() && "Type is not an extended vector!");
     99   return static_cast<const ExtendedVectorType *>(LLVMTy)->getNumElements();
    100 }
    101 
    102 unsigned EVT::getExtendedSizeInBits() const {
    103   assert(isExtended() && "Type is not extended!");
    104   return LLVMTy->getSizeInBits();
    105 }
    106