LCOV - code coverage report
Current view: top level - lib/CodeGen - ValueTypes.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 128 220 58.2 %
Date: 2018-10-20 13:21:21 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             : #include "llvm/CodeGen/ValueTypes.h"
      11             : #include "llvm/ADT/StringExtras.h"
      12             : #include "llvm/IR/DerivedTypes.h"
      13             : #include "llvm/IR/Type.h"
      14             : #include "llvm/Support/ErrorHandling.h"
      15             : using namespace llvm;
      16             : 
      17           0 : EVT EVT::changeExtendedTypeToInteger() const {
      18           0 :   LLVMContext &Context = LLVMTy->getContext();
      19           0 :   return getIntegerVT(Context, getSizeInBits());
      20             : }
      21             : 
      22         272 : EVT EVT::changeExtendedVectorElementTypeToInteger() const {
      23         272 :   LLVMContext &Context = LLVMTy->getContext();
      24         272 :   EVT IntTy = getIntegerVT(Context, getScalarSizeInBits());
      25         272 :   return getVectorVT(Context, IntTy, getVectorNumElements());
      26             : }
      27             : 
      28      464972 : EVT EVT::getExtendedIntegerVT(LLVMContext &Context, unsigned BitWidth) {
      29             :   EVT VT;
      30      464972 :   VT.LLVMTy = IntegerType::get(Context, BitWidth);
      31             :   assert(VT.isExtended() && "Type is not extended!");
      32      464972 :   return VT;
      33             : }
      34             : 
      35      163129 : EVT EVT::getExtendedVectorVT(LLVMContext &Context, EVT VT,
      36             :                              unsigned NumElements) {
      37             :   EVT ResultVT;
      38      163129 :   ResultVT.LLVMTy = VectorType::get(VT.getTypeForEVT(Context), NumElements);
      39             :   assert(ResultVT.isExtended() && "Type is not extended!");
      40      163129 :   return ResultVT;
      41             : }
      42             : 
      43        7073 : bool EVT::isExtendedFloatingPoint() const {
      44             :   assert(isExtended() && "Type is not extended!");
      45        7073 :   return LLVMTy->isFPOrFPVectorTy();
      46             : }
      47             : 
      48      112432 : bool EVT::isExtendedInteger() const {
      49             :   assert(isExtended() && "Type is not extended!");
      50      112432 :   return LLVMTy->isIntOrIntVectorTy();
      51             : }
      52             : 
      53        5293 : bool EVT::isExtendedScalarInteger() const {
      54             :   assert(isExtended() && "Type is not extended!");
      55       10586 :   return LLVMTy->isIntegerTy();
      56             : }
      57             : 
      58      821996 : bool EVT::isExtendedVector() const {
      59             :   assert(isExtended() && "Type is not extended!");
      60     1643992 :   return LLVMTy->isVectorTy();
      61             : }
      62             : 
      63           0 : bool EVT::isExtended16BitVector() const {
      64           0 :   return isExtendedVector() && getExtendedSizeInBits() == 16;
      65             : }
      66             : 
      67           0 : bool EVT::isExtended32BitVector() const {
      68           0 :   return isExtendedVector() && getExtendedSizeInBits() == 32;
      69             : }
      70             : 
      71           0 : bool EVT::isExtended64BitVector() const {
      72           0 :   return isExtendedVector() && getExtendedSizeInBits() == 64;
      73             : }
      74             : 
      75         276 : bool EVT::isExtended128BitVector() const {
      76         276 :   return isExtendedVector() && getExtendedSizeInBits() == 128;
      77             : }
      78             : 
      79        2701 : bool EVT::isExtended256BitVector() const {
      80        2701 :   return isExtendedVector() && getExtendedSizeInBits() == 256;
      81             : }
      82             : 
      83         176 : bool EVT::isExtended512BitVector() const {
      84         176 :   return isExtendedVector() && getExtendedSizeInBits() == 512;
      85             : }
      86             : 
      87           0 : bool EVT::isExtended1024BitVector() const {
      88           0 :   return isExtendedVector() && getExtendedSizeInBits() == 1024;
      89             : }
      90             : 
      91           0 : bool EVT::isExtended2048BitVector() const {
      92           0 :   return isExtendedVector() && getExtendedSizeInBits() == 2048;
      93             : }
      94             : 
      95      269477 : EVT EVT::getExtendedVectorElementType() const {
      96             :   assert(isExtended() && "Type is not extended!");
      97      269477 :   return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());
      98             : }
      99             : 
     100      440675 : unsigned EVT::getExtendedVectorNumElements() const {
     101             :   assert(isExtended() && "Type is not extended!");
     102      440675 :   return cast<VectorType>(LLVMTy)->getNumElements();
     103             : }
     104             : 
     105     1311821 : unsigned EVT::getExtendedSizeInBits() const {
     106             :   assert(isExtended() && "Type is not extended!");
     107     1311821 :   if (IntegerType *ITy = dyn_cast<IntegerType>(LLVMTy))
     108     1178958 :     return ITy->getBitWidth();
     109             :   if (VectorType *VTy = dyn_cast<VectorType>(LLVMTy))
     110      132863 :     return VTy->getBitWidth();
     111           0 :   llvm_unreachable("Unrecognized extended type!");
     112             : }
     113             : 
     114             : /// getEVTString - This function returns value type as a string, e.g. "i32".
     115          57 : std::string EVT::getEVTString() const {
     116          57 :   switch (V.SimpleTy) {
     117             :   default:
     118           0 :     if (isVector())
     119           0 :       return "v" + utostr(getVectorNumElements()) +
     120           0 :              getVectorElementType().getEVTString();
     121           0 :     if (isInteger())
     122           0 :       return "i" + utostr(getSizeInBits());
     123           0 :     llvm_unreachable("Invalid EVT!");
     124           0 :   case MVT::i1:      return "i1";
     125           0 :   case MVT::i8:      return "i8";
     126           0 :   case MVT::i16:     return "i16";
     127          34 :   case MVT::i32:     return "i32";
     128          19 :   case MVT::i64:     return "i64";
     129           0 :   case MVT::i128:    return "i128";
     130           0 :   case MVT::f16:     return "f16";
     131           4 :   case MVT::f32:     return "f32";
     132           0 :   case MVT::f64:     return "f64";
     133           0 :   case MVT::f80:     return "f80";
     134           0 :   case MVT::f128:    return "f128";
     135           0 :   case MVT::ppcf128: return "ppcf128";
     136           0 :   case MVT::isVoid:  return "isVoid";
     137           0 :   case MVT::Other:   return "ch";
     138           0 :   case MVT::Glue:    return "glue";
     139           0 :   case MVT::x86mmx:  return "x86mmx";
     140           0 :   case MVT::v1i1:    return "v1i1";
     141           0 :   case MVT::v2i1:    return "v2i1";
     142           0 :   case MVT::v4i1:    return "v4i1";
     143           0 :   case MVT::v8i1:    return "v8i1";
     144           0 :   case MVT::v16i1:   return "v16i1";
     145           0 :   case MVT::v32i1:   return "v32i1";
     146           0 :   case MVT::v64i1:   return "v64i1";
     147           0 :   case MVT::v128i1:  return "v128i1";
     148           0 :   case MVT::v512i1:  return "v512i1";
     149           0 :   case MVT::v1024i1: return "v1024i1";
     150           0 :   case MVT::v1i8:    return "v1i8";
     151           0 :   case MVT::v2i8:    return "v2i8";
     152           0 :   case MVT::v4i8:    return "v4i8";
     153           0 :   case MVT::v8i8:    return "v8i8";
     154           0 :   case MVT::v16i8:   return "v16i8";
     155           0 :   case MVT::v32i8:   return "v32i8";
     156           0 :   case MVT::v64i8:   return "v64i8";
     157           0 :   case MVT::v128i8:  return "v128i8";
     158           0 :   case MVT::v256i8:  return "v256i8";
     159           0 :   case MVT::v1i16:   return "v1i16";
     160           0 :   case MVT::v2i16:   return "v2i16";
     161           0 :   case MVT::v4i16:   return "v4i16";
     162           0 :   case MVT::v8i16:   return "v8i16";
     163           0 :   case MVT::v16i16:  return "v16i16";
     164           0 :   case MVT::v32i16:  return "v32i16";
     165           0 :   case MVT::v64i16:  return "v64i16";
     166           0 :   case MVT::v128i16: return "v128i16";
     167           0 :   case MVT::v1i32:   return "v1i32";
     168           0 :   case MVT::v2i32:   return "v2i32";
     169           0 :   case MVT::v4i32:   return "v4i32";
     170           0 :   case MVT::v8i32:   return "v8i32";
     171           0 :   case MVT::v16i32:  return "v16i32";
     172           0 :   case MVT::v32i32:  return "v32i32";
     173           0 :   case MVT::v64i32:  return "v64i32";
     174           0 :   case MVT::v1i64:   return "v1i64";
     175           0 :   case MVT::v2i64:   return "v2i64";
     176           0 :   case MVT::v4i64:   return "v4i64";
     177           0 :   case MVT::v8i64:   return "v8i64";
     178           0 :   case MVT::v16i64:  return "v16i64";
     179           0 :   case MVT::v32i64:  return "v32i64";
     180           0 :   case MVT::v1i128:  return "v1i128";
     181           0 :   case MVT::v1f32:   return "v1f32";
     182           0 :   case MVT::v2f32:   return "v2f32";
     183           0 :   case MVT::v2f16:   return "v2f16";
     184           0 :   case MVT::v4f16:   return "v4f16";
     185           0 :   case MVT::v8f16:   return "v8f16";
     186           0 :   case MVT::v4f32:   return "v4f32";
     187           0 :   case MVT::v8f32:   return "v8f32";
     188           0 :   case MVT::v16f32:  return "v16f32";
     189           0 :   case MVT::v1f64:   return "v1f64";
     190           0 :   case MVT::v2f64:   return "v2f64";
     191           0 :   case MVT::v4f64:   return "v4f64";
     192           0 :   case MVT::v8f64:   return "v8f64";
     193           0 :   case MVT::Metadata:return "Metadata";
     194           0 :   case MVT::Untyped: return "Untyped";
     195           0 :   case MVT::ExceptRef: return "ExceptRef";
     196             :   }
     197             : }
     198             : 
     199             : /// getTypeForEVT - This method returns an LLVM type corresponding to the
     200             : /// specified EVT.  For integer types, this returns an unsigned type.  Note
     201             : /// that this will abort for types that cannot be represented.
     202    14624425 : Type *EVT::getTypeForEVT(LLVMContext &Context) const {
     203    14624425 :   switch (V.SimpleTy) {
     204       18103 :   default:
     205             :     assert(isExtended() && "Type is not extended!");
     206       18103 :     return LLVMTy;
     207         249 :   case MVT::isVoid:  return Type::getVoidTy(Context);
     208       45779 :   case MVT::i1:      return Type::getInt1Ty(Context);
     209      346569 :   case MVT::i8:      return Type::getInt8Ty(Context);
     210       84608 :   case MVT::i16:     return Type::getInt16Ty(Context);
     211     2394199 :   case MVT::i32:     return Type::getInt32Ty(Context);
     212     9693937 :   case MVT::i64:     return Type::getInt64Ty(Context);
     213        9986 :   case MVT::i128:    return IntegerType::get(Context, 128);
     214       16241 :   case MVT::f16:     return Type::getHalfTy(Context);
     215       99717 :   case MVT::f32:     return Type::getFloatTy(Context);
     216       90950 :   case MVT::f64:     return Type::getDoubleTy(Context);
     217       62719 :   case MVT::f80:     return Type::getX86_FP80Ty(Context);
     218        8172 :   case MVT::f128:    return Type::getFP128Ty(Context);
     219         522 :   case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
     220        7293 :   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
     221         147 :   case MVT::v1i1:    return VectorType::get(Type::getInt1Ty(Context), 1);
     222         394 :   case MVT::v2i1:    return VectorType::get(Type::getInt1Ty(Context), 2);
     223        1364 :   case MVT::v4i1:    return VectorType::get(Type::getInt1Ty(Context), 4);
     224         839 :   case MVT::v8i1:    return VectorType::get(Type::getInt1Ty(Context), 8);
     225        2111 :   case MVT::v16i1:   return VectorType::get(Type::getInt1Ty(Context), 16);
     226         986 :   case MVT::v32i1:   return VectorType::get(Type::getInt1Ty(Context), 32);
     227         690 :   case MVT::v64i1:   return VectorType::get(Type::getInt1Ty(Context), 64);
     228           6 :   case MVT::v128i1:  return VectorType::get(Type::getInt1Ty(Context), 128);
     229         568 :   case MVT::v512i1:  return VectorType::get(Type::getInt1Ty(Context), 512);
     230           8 :   case MVT::v1024i1: return VectorType::get(Type::getInt1Ty(Context), 1024);
     231         269 :   case MVT::v1i8:    return VectorType::get(Type::getInt8Ty(Context), 1);
     232        1197 :   case MVT::v2i8:    return VectorType::get(Type::getInt8Ty(Context), 2);
     233        3254 :   case MVT::v4i8:    return VectorType::get(Type::getInt8Ty(Context), 4);
     234        3512 :   case MVT::v8i8:    return VectorType::get(Type::getInt8Ty(Context), 8);
     235      402383 :   case MVT::v16i8:   return VectorType::get(Type::getInt8Ty(Context), 16);
     236        7566 :   case MVT::v32i8:   return VectorType::get(Type::getInt8Ty(Context), 32);
     237        2366 :   case MVT::v64i8:   return VectorType::get(Type::getInt8Ty(Context), 64);
     238         979 :   case MVT::v128i8:  return VectorType::get(Type::getInt8Ty(Context), 128);
     239         672 :   case MVT::v256i8:  return VectorType::get(Type::getInt8Ty(Context), 256);
     240         339 :   case MVT::v1i16:   return VectorType::get(Type::getInt16Ty(Context), 1);
     241        2907 :   case MVT::v2i16:   return VectorType::get(Type::getInt16Ty(Context), 2);
     242        6112 :   case MVT::v4i16:   return VectorType::get(Type::getInt16Ty(Context), 4);
     243       19214 :   case MVT::v8i16:   return VectorType::get(Type::getInt16Ty(Context), 8);
     244        7359 :   case MVT::v16i16:  return VectorType::get(Type::getInt16Ty(Context), 16);
     245        2796 :   case MVT::v32i16:  return VectorType::get(Type::getInt16Ty(Context), 32);
     246         269 :   case MVT::v64i16:  return VectorType::get(Type::getInt16Ty(Context), 64);
     247           1 :   case MVT::v128i16: return VectorType::get(Type::getInt16Ty(Context), 128);
     248        1242 :   case MVT::v1i32:   return VectorType::get(Type::getInt32Ty(Context), 1);
     249       85600 :   case MVT::v2i32:   return VectorType::get(Type::getInt32Ty(Context), 2);
     250      517989 :   case MVT::v4i32:   return VectorType::get(Type::getInt32Ty(Context), 4);
     251       16664 :   case MVT::v8i32:   return VectorType::get(Type::getInt32Ty(Context), 8);
     252       10070 :   case MVT::v16i32:  return VectorType::get(Type::getInt32Ty(Context), 16);
     253        1796 :   case MVT::v32i32:  return VectorType::get(Type::getInt32Ty(Context), 32);
     254         103 :   case MVT::v64i32:  return VectorType::get(Type::getInt32Ty(Context), 64);
     255        2363 :   case MVT::v1i64:   return VectorType::get(Type::getInt64Ty(Context), 1);
     256      491160 :   case MVT::v2i64:   return VectorType::get(Type::getInt64Ty(Context), 2);
     257       32200 :   case MVT::v4i64:   return VectorType::get(Type::getInt64Ty(Context), 4);
     258       10676 :   case MVT::v8i64:   return VectorType::get(Type::getInt64Ty(Context), 8);
     259         570 :   case MVT::v16i64:  return VectorType::get(Type::getInt64Ty(Context), 16);
     260         172 :   case MVT::v32i64:  return VectorType::get(Type::getInt64Ty(Context), 32);
     261         163 :   case MVT::v1i128:  return VectorType::get(Type::getInt128Ty(Context), 1);
     262        3095 :   case MVT::v2f16:   return VectorType::get(Type::getHalfTy(Context), 2);
     263         820 :   case MVT::v4f16:   return VectorType::get(Type::getHalfTy(Context), 4);
     264         546 :   case MVT::v8f16:   return VectorType::get(Type::getHalfTy(Context), 8);
     265         314 :   case MVT::v1f32:   return VectorType::get(Type::getFloatTy(Context), 1);
     266        2606 :   case MVT::v2f32:   return VectorType::get(Type::getFloatTy(Context), 2);
     267       29574 :   case MVT::v4f32:   return VectorType::get(Type::getFloatTy(Context), 4);
     268       11715 :   case MVT::v8f32:   return VectorType::get(Type::getFloatTy(Context), 8);
     269        6003 :   case MVT::v16f32:   return VectorType::get(Type::getFloatTy(Context), 16);
     270         386 :   case MVT::v1f64:   return VectorType::get(Type::getDoubleTy(Context), 1);
     271       35485 :   case MVT::v2f64:   return VectorType::get(Type::getDoubleTy(Context), 2);
     272       10424 :   case MVT::v4f64:   return VectorType::get(Type::getDoubleTy(Context), 4);
     273        5337 :   case MVT::v8f64:   return VectorType::get(Type::getDoubleTy(Context), 8);
     274           0 :   case MVT::Metadata: return Type::getMetadataTy(Context);
     275             :  }
     276             : }
     277             : 
     278             : /// Return the value type corresponding to the specified type.  This returns all
     279             : /// pointers as MVT::iPTR.  If HandleUnknown is true, unknown types are returned
     280             : /// as Other, otherwise they are invalid.
     281     1113334 : MVT MVT::getVT(Type *Ty, bool HandleUnknown){
     282     1113334 :   switch (Ty->getTypeID()) {
     283       41518 :   default:
     284       41518 :     if (HandleUnknown) return MVT(MVT::Other);
     285           0 :     llvm_unreachable("Unknown type!");
     286             :   case Type::VoidTyID:
     287          25 :     return MVT::isVoid;
     288             :   case Type::IntegerTyID:
     289       29893 :     return getIntegerVT(cast<IntegerType>(Ty)->getBitWidth());
     290       50826 :   case Type::HalfTyID:      return MVT(MVT::f16);
     291      509667 :   case Type::FloatTyID:     return MVT(MVT::f32);
     292      416288 :   case Type::DoubleTyID:    return MVT(MVT::f64);
     293       33382 :   case Type::X86_FP80TyID:  return MVT(MVT::f80);
     294       12418 :   case Type::X86_MMXTyID:   return MVT(MVT::x86mmx);
     295        8621 :   case Type::FP128TyID:     return MVT(MVT::f128);
     296         873 :   case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
     297           0 :   case Type::PointerTyID:   return MVT(MVT::iPTR);
     298             :   case Type::VectorTyID: {
     299             :     VectorType *VTy = cast<VectorType>(Ty);
     300             :     return getVectorVT(
     301        9823 :       getVT(VTy->getElementType(), false), VTy->getNumElements());
     302             :   }
     303             :   }
     304             : }
     305             : 
     306             : /// getEVT - Return the value type corresponding to the specified type.  This
     307             : /// returns all pointers as MVT::iPTR.  If HandleUnknown is true, unknown types
     308             : /// are returned as Other, otherwise they are invalid.
     309    22398316 : EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
     310    22398316 :   switch (Ty->getTypeID()) {
     311     1063828 :   default:
     312     1063828 :     return MVT::getVT(Ty, HandleUnknown);
     313             :   case Type::IntegerTyID:
     314    21333593 :     return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
     315             :   case Type::VectorTyID: {
     316             :     VectorType *VTy = cast<VectorType>(Ty);
     317             :     return getVectorVT(Ty->getContext(), getEVT(VTy->getElementType(), false),
     318         895 :                        VTy->getNumElements());
     319             :   }
     320             :   }
     321             : }

Generated by: LCOV version 1.13