LCOV - code coverage report
Current view: top level - lib/IR - ValueTypes.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 151 228 66.2 %
Date: 2017-09-14 15:23:50 Functions: 17 23 73.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===----------- ValueTypes.cpp - Implementation of EVT methods -----------===//
       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             : // This file implements methods in the CodeGen/ValueTypes.h header.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/CodeGen/ValueTypes.h"
      15             : #include "llvm/ADT/StringExtras.h"
      16             : #include "llvm/IR/DerivedTypes.h"
      17             : #include "llvm/IR/LLVMContext.h"
      18             : #include "llvm/IR/Type.h"
      19             : #include "llvm/Support/ErrorHandling.h"
      20             : using namespace llvm;
      21             : 
      22           0 : EVT EVT::changeExtendedTypeToInteger() const {
      23           0 :   LLVMContext &Context = LLVMTy->getContext();
      24           0 :   return getIntegerVT(Context, getSizeInBits());
      25             : }
      26             : 
      27          83 : EVT EVT::changeExtendedVectorElementTypeToInteger() const {
      28          83 :   LLVMContext &Context = LLVMTy->getContext();
      29          83 :   EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
      30          83 :   return getVectorVT(Context, IntTy, getVectorNumElements());
      31             : }
      32             : 
      33      346793 : EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
      34      346793 :   EVT VT;
      35      346793 :   VT.LLVMTy = IntegerType::get(Context, BitWidth);
      36             :   assert(VT.isExtended() && "Type is not extended!");
      37      346793 :   return VT;
      38             : }
      39             : 
      40      114827 : EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
      41             :                              unsigned NumElements) {
      42      114827 :   EVT ResultVT;
      43      114827 :   ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
      44             :   assert(ResultVT.isExtended() && "Type is not extended!");
      45      114827 :   return ResultVT;
      46             : }
      47             : 
      48        2522 : bool EVT::isExtendedFloatingPoint() const {
      49             :   assert(isExtended() && "Type is not extended!");
      50        5044 :   return LLVMTy->isFPOrFPVectorTy();
      51             : }
      52             : 
      53       26429 : bool EVT::isExtendedInteger() const {
      54             :   assert(isExtended() && "Type is not extended!");
      55       52858 :   return LLVMTy->isIntOrIntVectorTy();
      56             : }
      57             : 
      58        2852 : bool EVT::isExtendedScalarInteger() const {
      59             :   assert(isExtended() && "Type is not extended!");
      60        5704 :   return LLVMTy->isIntegerTy();
      61             : }
      62             : 
      63      510350 : bool EVT::isExtendedVector() const {
      64             :   assert(isExtended() && "Type is not extended!");
      65     1020700 :   return LLVMTy->isVectorTy();
      66             : }
      67             : 
      68           0 : bool EVT::isExtended16BitVector() const {
      69           0 :   return isExtendedVector() && getExtendedSizeInBits() == 16;
      70             : }
      71             : 
      72           0 : bool EVT::isExtended32BitVector() const {
      73           0 :   return isExtendedVector() && getExtendedSizeInBits() == 32;
      74             : }
      75             : 
      76           0 : bool EVT::isExtended64BitVector() const {
      77           0 :   return isExtendedVector() && getExtendedSizeInBits() == 64;
      78             : }
      79             : 
      80         128 : bool EVT::isExtended128BitVector() const {
      81         128 :   return isExtendedVector() && getExtendedSizeInBits() == 128;
      82             : }
      83             : 
      84        2537 : bool EVT::isExtended256BitVector() const {
      85        2537 :   return isExtendedVector() && getExtendedSizeInBits() == 256;
      86             : }
      87             : 
      88         101 : bool EVT::isExtended512BitVector() const {
      89         101 :   return isExtendedVector() && getExtendedSizeInBits() == 512;
      90             : }
      91             : 
      92           0 : bool EVT::isExtended1024BitVector() const {
      93           0 :   return isExtendedVector() && getExtendedSizeInBits() == 1024;
      94             : }
      95             : 
      96           0 : bool EVT::isExtended2048BitVector() const {
      97           0 :   return isExtendedVector() && getExtendedSizeInBits() == 2048;
      98             : }
      99             : 
     100       71185 : EVT EVT::getExtendedVectorElementType() const {
     101             :   assert(isExtended() && "Type is not extended!");
     102      142370 :   return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
     103             : }
     104             : 
     105      106945 : unsigned EVT::getExtendedVectorNumElements() const {
     106             :   assert(isExtended() && "Type is not extended!");
     107      213890 :   return cast<VectorType>(LLVMTy)->getNumElements();
     108             : }
     109             : 
     110      716546 : unsigned EVT::getExtendedSizeInBits() const {
     111             :   assert(isExtended() && "Type is not extended!");
     112     1413787 :   if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
     113      697241 :     return ITy->getBitWidth();
     114       38610 :   if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
     115       19305 :     return VTy->getBitWidth();
     116           0 :   llvm_unreachable("Unrecognized extended type!");
     117             : }
     118             : 
     119             : /// getEVTString - This function returns value type as a string, e.g. "i32".
     120      295675 : std::string EVT::getEVTString() const {
     121      295675 :   switch (V.SimpleTy) {
     122         322 :   default:
     123         322 :     if (isVector())
     124           0 :       return "v" + utostr(getVectorNumElements()) +
     125           0 :              getVectorElementType().getEVTString();
     126         322 :     if (isInteger())
     127         644 :       return "i" + utostr(getSizeInBits());
     128           0 :     llvm_unreachable("Invalid EVT!");
     129         570 :   case MVT::i1:      return "i1";
     130      263274 :   case MVT::i8:      return "i8";
     131       13557 :   case MVT::i16:     return "i16";
     132       80418 :   case MVT::i32:     return "i32";
     133      110320 :   case MVT::i64:     return "i64";
     134         170 :   case MVT::i128:    return "i128";
     135        9694 :   case MVT::f16:     return "f16";
     136       68706 :   case MVT::f32:     return "f32";
     137       27914 :   case MVT::f64:     return "f64";
     138         342 :   case MVT::f80:     return "f80";
     139         914 :   case MVT::f128:    return "f128";
     140         148 :   case MVT::ppcf128: return "ppcf128";
     141        1122 :   case MVT::isVoid:  return "isVoid";
     142           0 :   case MVT::Other:   return "ch";
     143           0 :   case MVT::Glue:    return "glue";
     144           0 :   case MVT::x86mmx:  return "x86mmx";
     145           0 :   case MVT::v1i1:    return "v1i1";
     146           0 :   case MVT::v2i1:    return "v2i1";
     147           0 :   case MVT::v4i1:    return "v4i1";
     148           0 :   case MVT::v8i1:    return "v8i1";
     149           0 :   case MVT::v16i1:   return "v16i1";
     150           0 :   case MVT::v32i1:   return "v32i1";
     151           0 :   case MVT::v64i1:   return "v64i1";
     152           0 :   case MVT::v512i1:  return "v512i1";
     153           0 :   case MVT::v1024i1: return "v1024i1";
     154           0 :   case MVT::v1i8:    return "v1i8";
     155           0 :   case MVT::v2i8:    return "v2i8";
     156           0 :   case MVT::v4i8:    return "v4i8";
     157           0 :   case MVT::v8i8:    return "v8i8";
     158           0 :   case MVT::v16i8:   return "v16i8";
     159           0 :   case MVT::v32i8:   return "v32i8";
     160           0 :   case MVT::v64i8:   return "v64i8";
     161           0 :   case MVT::v128i8:  return "v128i8";
     162           0 :   case MVT::v256i8:  return "v256i8";
     163           0 :   case MVT::v1i16:   return "v1i16";
     164           0 :   case MVT::v2i16:   return "v2i16";
     165           0 :   case MVT::v4i16:   return "v4i16";
     166           0 :   case MVT::v8i16:   return "v8i16";
     167           0 :   case MVT::v16i16:  return "v16i16";
     168           0 :   case MVT::v32i16:  return "v32i16";
     169           0 :   case MVT::v64i16:  return "v64i16";
     170           0 :   case MVT::v128i16: return "v128i16";
     171           0 :   case MVT::v1i32:   return "v1i32";
     172           0 :   case MVT::v2i32:   return "v2i32";
     173           0 :   case MVT::v4i32:   return "v4i32";
     174           0 :   case MVT::v8i32:   return "v8i32";
     175           0 :   case MVT::v16i32:  return "v16i32";
     176           0 :   case MVT::v32i32:  return "v32i32";
     177           0 :   case MVT::v64i32:  return "v64i32";
     178           0 :   case MVT::v1i64:   return "v1i64";
     179           0 :   case MVT::v2i64:   return "v2i64";
     180           0 :   case MVT::v4i64:   return "v4i64";
     181           0 :   case MVT::v8i64:   return "v8i64";
     182           0 :   case MVT::v16i64:  return "v16i64";
     183           0 :   case MVT::v32i64:  return "v32i64";
     184           0 :   case MVT::v1i128:  return "v1i128";
     185           0 :   case MVT::v1f32:   return "v1f32";
     186           0 :   case MVT::v2f32:   return "v2f32";
     187           0 :   case MVT::v2f16:   return "v2f16";
     188           0 :   case MVT::v4f16:   return "v4f16";
     189           0 :   case MVT::v8f16:   return "v8f16";
     190           0 :   case MVT::v4f32:   return "v4f32";
     191           0 :   case MVT::v8f32:   return "v8f32";
     192           0 :   case MVT::v16f32:  return "v16f32";
     193           0 :   case MVT::v1f64:   return "v1f64";
     194           0 :   case MVT::v2f64:   return "v2f64";
     195           0 :   case MVT::v4f64:   return "v4f64";
     196           0 :   case MVT::v8f64:   return "v8f64";
     197           0 :   case MVT::Metadata:return "Metadata";
     198           0 :   case MVT::Untyped: return "Untyped";
     199             :   }
     200             : }
     201             : 
     202             : /// getTypeForEVT - This method returns an LLVM type corresponding to the
     203             : /// specified EVT.  For integer types, this returns an unsigned type.  Note
     204             : /// that this will abort for types that cannot be represented.
     205     3700309 : Type *EVT::getTypeForEVT(LLVMContext &Context) const {
     206     3700309 :   switch (V.SimpleTy) {
     207       15191 :   default:
     208             :     assert(isExtended() && "Type is not extended!");
     209       15191 :     return LLVMTy;
     210         183 :   case MVT::isVoid:  return Type::getVoidTy(Context);
     211        6794 :   case MVT::i1:      return Type::getInt1Ty(Context);
     212      166038 :   case MVT::i8:      return Type::getInt8Ty(Context);
     213       48706 :   case MVT::i16:     return Type::getInt16Ty(Context);
     214     1907472 :   case MVT::i32:     return Type::getInt32Ty(Context);
     215      576787 :   case MVT::i64:     return Type::getInt64Ty(Context);
     216        6655 :   case MVT::i128:    return IntegerType::get(Context, 128);
     217       12603 :   case MVT::f16:     return Type::getHalfTy(Context);
     218       58350 :   case MVT::f32:     return Type::getFloatTy(Context);
     219       47847 :   case MVT::f64:     return Type::getDoubleTy(Context);
     220        2299 :   case MVT::f80:     return Type::getX86_FP80Ty(Context);
     221        5861 :   case MVT::f128:    return Type::getFP128Ty(Context);
     222         503 :   case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
     223        3401 :   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
     224          55 :   case MVT::v1i1:    return VectorType::get(Type::getInt1Ty(Context), 1);
     225         380 :   case MVT::v2i1:    return VectorType::get(Type::getInt1Ty(Context), 2);
     226        1654 :   case MVT::v4i1:    return VectorType::get(Type::getInt1Ty(Context), 4);
     227         721 :   case MVT::v8i1:    return VectorType::get(Type::getInt1Ty(Context), 8);
     228        3809 :   case MVT::v16i1:   return VectorType::get(Type::getInt1Ty(Context), 16);
     229        2105 :   case MVT::v32i1:   return VectorType::get(Type::getInt1Ty(Context), 32);
     230         540 :   case MVT::v64i1:   return VectorType::get(Type::getInt1Ty(Context), 64);
     231         155 :   case MVT::v512i1:  return VectorType::get(Type::getInt1Ty(Context), 512);
     232           4 :   case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024);
     233         199 :   case MVT::v1i8:    return VectorType::get(Type::getInt8Ty(Context), 1);
     234         983 :   case MVT::v2i8:    return VectorType::get(Type::getInt8Ty(Context), 2);
     235        2824 :   case MVT::v4i8:    return VectorType::get(Type::getInt8Ty(Context), 4);
     236        3079 :   case MVT::v8i8:    return VectorType::get(Type::getInt8Ty(Context), 8);
     237       90313 :   case MVT::v16i8:   return VectorType::get(Type::getInt8Ty(Context), 16);
     238        3943 :   case MVT::v32i8:   return VectorType::get(Type::getInt8Ty(Context), 32);
     239        1154 :   case MVT::v64i8:   return VectorType::get(Type::getInt8Ty(Context), 64);
     240          38 :   case MVT::v128i8:  return VectorType::get(Type::getInt8Ty(Context), 128);
     241           2 :   case MVT::v256i8:  return VectorType::get(Type::getInt8Ty(Context), 256);
     242         285 :   case MVT::v1i16:   return VectorType::get(Type::getInt16Ty(Context), 1);
     243        1908 :   case MVT::v2i16:   return VectorType::get(Type::getInt16Ty(Context), 2);
     244        4786 :   case MVT::v4i16:   return VectorType::get(Type::getInt16Ty(Context), 4);
     245       14660 :   case MVT::v8i16:   return VectorType::get(Type::getInt16Ty(Context), 8);
     246        4511 :   case MVT::v16i16:  return VectorType::get(Type::getInt16Ty(Context), 16);
     247        1621 :   case MVT::v32i16:  return VectorType::get(Type::getInt16Ty(Context), 32);
     248          64 :   case MVT::v64i16:  return VectorType::get(Type::getInt16Ty(Context), 64);
     249           0 :   case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128);
     250        1076 :   case MVT::v1i32:   return VectorType::get(Type::getInt32Ty(Context), 1);
     251       91118 :   case MVT::v2i32:   return VectorType::get(Type::getInt32Ty(Context), 2);
     252      176902 :   case MVT::v4i32:   return VectorType::get(Type::getInt32Ty(Context), 4);
     253       10360 :   case MVT::v8i32:   return VectorType::get(Type::getInt32Ty(Context), 8);
     254        6756 :   case MVT::v16i32:  return VectorType::get(Type::getInt32Ty(Context), 16);
     255         728 :   case MVT::v32i32:  return VectorType::get(Type::getInt32Ty(Context), 32);
     256          75 :   case MVT::v64i32:  return VectorType::get(Type::getInt32Ty(Context), 64);
     257        2095 :   case MVT::v1i64:   return VectorType::get(Type::getInt64Ty(Context), 1);
     258      314833 :   case MVT::v2i64:   return VectorType::get(Type::getInt64Ty(Context), 2);
     259       21546 :   case MVT::v4i64:   return VectorType::get(Type::getInt64Ty(Context), 4);
     260        7235 :   case MVT::v8i64:   return VectorType::get(Type::getInt64Ty(Context), 8);
     261         450 :   case MVT::v16i64:  return VectorType::get(Type::getInt64Ty(Context), 16);
     262         146 :   case MVT::v32i64:  return VectorType::get(Type::getInt64Ty(Context), 32);
     263         163 :   case MVT::v1i128:  return VectorType::get(Type::getInt128Ty(Context), 1);
     264        2619 :   case MVT::v2f16:   return VectorType::get(Type::getHalfTy(Context), 2);
     265         317 :   case MVT::v4f16:   return VectorType::get(Type::getHalfTy(Context), 4);
     266         272 :   case MVT::v8f16:   return VectorType::get(Type::getHalfTy(Context), 8);
     267         263 :   case MVT::v1f32:   return VectorType::get(Type::getFloatTy(Context), 1);
     268        2020 :   case MVT::v2f32:   return VectorType::get(Type::getFloatTy(Context), 2);
     269       18768 :   case MVT::v4f32:   return VectorType::get(Type::getFloatTy(Context), 4);
     270        7965 :   case MVT::v8f32:   return VectorType::get(Type::getFloatTy(Context), 8);
     271        3071 :   case MVT::v16f32:   return VectorType::get(Type::getFloatTy(Context), 16);
     272         358 :   case MVT::v1f64:   return VectorType::get(Type::getDoubleTy(Context), 1);
     273       22851 :   case MVT::v2f64:   return VectorType::get(Type::getDoubleTy(Context), 2);
     274        6970 :   case MVT::v4f64:   return VectorType::get(Type::getDoubleTy(Context), 4); 
     275        2869 :   case MVT::v8f64:   return VectorType::get(Type::getDoubleTy(Context), 8); 
     276           0 :   case MVT::Metadata: return Type::getMetadataTy(Context);
     277             :  }
     278             : }
     279             : 
     280             : /// Return the value type corresponding to the specified type.  This returns all
     281             : /// pointers as MVT::iPTR.  If HandleUnknown is true, unknown types are returned
     282             : /// as Other, otherwise they are invalid.
     283      555819 : MVT MVT::getVT(Type *Ty, bool HandleUnknown){
     284      555819 :   switch (Ty->getTypeID()) {
     285        1751 :   default:
     286        1751 :     if (HandleUnknown) return MVT(MVT::Other);
     287           0 :     llvm_unreachable("Unknown type!");
     288         605 :   case Type::VoidTyID:
     289         605 :     return MVT::isVoid;
     290       10396 :   case Type::IntegerTyID:
     291       20792 :     return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
     292       36188 :   case Type::HalfTyID:      return MVT(MVT::f16);
     293      328313 :   case Type::FloatTyID:     return MVT(MVT::f32);
     294      162467 :   case Type::DoubleTyID:    return MVT(MVT::f64);
     295        2152 :   case Type::X86_FP80TyID:  return MVT(MVT::f80);
     296        4376 :   case Type::X86_MMXTyID:   return MVT(MVT::x86mmx);
     297        7139 :   case Type::FP128TyID:     return MVT(MVT::f128);
     298         937 :   case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
     299           2 :   case Type::PointerTyID:   return MVT(MVT::iPTR);
     300        1493 :   case Type::VectorTyID: {
     301        1493 :     VectorType *VTy = cast<VectorType>(Ty);
     302             :     return getVectorVT(
     303        1493 :       getVT(VTy->getElementType(), false), VTy->getNumElements());
     304             :   }
     305             :   }
     306             : }
     307             : 
     308             : /// getEVT - Return the value type corresponding to the specified type.  This
     309             : /// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
     310             : /// are returned as Other, otherwise they are invalid.
     311     4994481 : EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
     312     4994481 :   switch (Ty->getTypeID()) {
     313      541672 :   default:
     314      541672 :     return MVT::getVT(Ty, HandleUnknown);
     315     4452459 :   case Type::IntegerTyID:
     316     8904918 :     return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
     317         350 :   case Type::VectorTyID: {
     318         350 :     VectorType *VTy = cast<VectorType>(Ty);
     319             :     return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
     320         350 :                        VTy->getNumElements());
     321             :   }
     322             :   }
     323             : }

Generated by: LCOV version 1.13