Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- subzero/src/IceTypeTranslator.cpp - Convert Ice/LLVm Types ---------===// | |
|
Jim Stichnoth
2014/07/17 23:00:33
ICE/LLVM
jvoung (off chromium)
2014/07/17 23:57:55
TypeTranslator -> TypeConverter
Karl
2014/07/18 20:27:42
Done.
Karl
2014/07/18 20:27:42
Done.
| |
| 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 | |
|
Jim Stichnoth
2014/07/17 23:00:33
2 spaces between implements and how :)
jvoung (off chromium)
2014/07/17 23:57:55
implements how ->
implements how
Karl
2014/07/18 20:27:42
Done.
Karl
2014/07/18 20:27:42
Done.
| |
| 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)); | |
|
Jim Stichnoth
2014/07/17 23:00:33
It would be great if this could be encoded in IceT
Karl
2014/07/18 20:27:42
Neither can I.
| |
| 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() == IceType_NUM); | |
| 37 } | |
| 38 | |
| 39 void TypeConverter::AddLlvmType(Type Ty, llvm::Type *LlvmTy) { | |
| 40 assert(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.at(IceType_i1); | |
|
Jim Stichnoth
2014/07/17 23:00:33
Any reason not to use LlvmTypes[] instead of LlvmT
Karl
2014/07/18 20:27:42
Fixing to use "[]", since during the constructor w
| |
| 59 case 8: | |
| 60 return LlvmTypes.at(IceType_i8); | |
| 61 case 16: | |
| 62 return LlvmTypes.at(IceType_i16); | |
| 63 case 32: | |
| 64 return LlvmTypes.at(IceType_i32); | |
| 65 case 64: | |
| 66 return LlvmTypes.at(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 |