OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceTypeConverter.cpp - Convert ICE/LLVM Types ----------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 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 how to convert LLVM types to ICE types, and ICE types |
| 11 // to LLVM types. |
| 12 // |
| 13 //===----------------------------------------------------------------------===// |
| 14 |
| 15 #include "IceTypeConverter.h" |
| 16 #include "llvm/Support/raw_ostream.h" |
| 17 |
| 18 namespace Ice { |
| 19 |
| 20 TypeConverter::TypeConverter(llvm::LLVMContext &Context) : Context(Context) { |
| 21 AddLLVMType(IceType_void, llvm::Type::getVoidTy(Context)); |
| 22 AddLLVMType(IceType_i1, llvm::IntegerType::get(Context, 1)); |
| 23 AddLLVMType(IceType_i8, llvm::IntegerType::get(Context, 8)); |
| 24 AddLLVMType(IceType_i16, llvm::IntegerType::get(Context, 16)); |
| 25 AddLLVMType(IceType_i32, llvm::IntegerType::get(Context, 32)); |
| 26 AddLLVMType(IceType_i64, llvm::IntegerType::get(Context, 64)); |
| 27 AddLLVMType(IceType_f32, llvm::Type::getFloatTy(Context)); |
| 28 AddLLVMType(IceType_f64, llvm::Type::getDoubleTy(Context)); |
| 29 AddLLVMType(IceType_v4i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 4)); |
| 30 AddLLVMType(IceType_v8i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 8)); |
| 31 AddLLVMType(IceType_v16i1, llvm::VectorType::get(LLVMTypes[IceType_i1], 16)); |
| 32 AddLLVMType(IceType_v16i8, llvm::VectorType::get(LLVMTypes[IceType_i8], 16)); |
| 33 AddLLVMType(IceType_v8i16, llvm::VectorType::get(LLVMTypes[IceType_i16], 8)); |
| 34 AddLLVMType(IceType_v4i32, llvm::VectorType::get(LLVMTypes[IceType_i32], 4)); |
| 35 AddLLVMType(IceType_v4f32, llvm::VectorType::get(LLVMTypes[IceType_f32], 4)); |
| 36 assert(LLVMTypes.size() == static_cast<size_t>(IceType_NUM)); |
| 37 } |
| 38 |
| 39 void TypeConverter::AddLLVMType(Type Ty, llvm::Type *LLVMTy) { |
| 40 assert(static_cast<size_t>(Ty) == LLVMTypes.size()); |
| 41 LLVMTypes.push_back(LLVMTy); |
| 42 LLVM2IceMap[LLVMTy] = Ty; |
| 43 } |
| 44 |
| 45 Type TypeConverter::convertToIceTypeOther(llvm::Type *LLVMTy) const { |
| 46 switch (LLVMTy->getTypeID()) { |
| 47 case llvm::Type::PointerTyID: |
| 48 case llvm::Type::FunctionTyID: |
| 49 return getIcePointerType(); |
| 50 default: |
| 51 return Ice::IceType_NUM; |
| 52 } |
| 53 } |
| 54 |
| 55 llvm::Type *TypeConverter::getLLVMIntegerType(unsigned NumBits) const { |
| 56 switch (NumBits) { |
| 57 case 1: |
| 58 return LLVMTypes[IceType_i1]; |
| 59 case 8: |
| 60 return LLVMTypes[IceType_i8]; |
| 61 case 16: |
| 62 return LLVMTypes[IceType_i16]; |
| 63 case 32: |
| 64 return LLVMTypes[IceType_i32]; |
| 65 case 64: |
| 66 return LLVMTypes[IceType_i64]; |
| 67 default: |
| 68 return NULL; |
| 69 } |
| 70 } |
| 71 |
| 72 llvm::Type *TypeConverter::getLLVMVectorType(unsigned Size, Type Ty) const { |
| 73 switch (Ty) { |
| 74 case IceType_i1: |
| 75 switch (Size) { |
| 76 case 4: |
| 77 return convertToLLVMType(IceType_v4i1); |
| 78 case 8: |
| 79 return convertToLLVMType(IceType_v8i1); |
| 80 case 16: |
| 81 return convertToLLVMType(IceType_v16i1); |
| 82 default: |
| 83 break; |
| 84 } |
| 85 break; |
| 86 case IceType_i8: |
| 87 if (Size == 16) |
| 88 return convertToLLVMType(IceType_v16i8); |
| 89 break; |
| 90 case IceType_i16: |
| 91 if (Size == 8) |
| 92 return convertToLLVMType(IceType_v8i16); |
| 93 break; |
| 94 case IceType_i32: |
| 95 if (Size == 4) |
| 96 return convertToLLVMType(IceType_v4i32); |
| 97 break; |
| 98 case IceType_f32: |
| 99 if (Size == 4) |
| 100 return convertToLLVMType(IceType_v4f32); |
| 101 break; |
| 102 default: |
| 103 break; |
| 104 } |
| 105 return NULL; |
| 106 } |
| 107 |
| 108 } // end of Ice namespace. |
OLD | NEW |