Chromium Code Reviews| Index: src/IceTypeConverter.cpp |
| diff --git a/src/IceTypeConverter.cpp b/src/IceTypeConverter.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..623947eace11efa19a104e85c241143251bad50f |
| --- /dev/null |
| +++ b/src/IceTypeConverter.cpp |
| @@ -0,0 +1,108 @@ |
| +//===- 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.
|
| +// |
| +// The Subzero Code Generator |
| +// |
| +// This file is distributed under the University of Illinois Open Source |
| +// License. See LICENSE.TXT for details. |
| +// |
| +//===----------------------------------------------------------------------===// |
| +// |
| +// 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.
|
| +// to LLVM types. |
| +// |
| +//===----------------------------------------------------------------------===// |
| + |
| +#include "IceTypeConverter.h" |
| +#include "llvm/Support/raw_ostream.h" |
| + |
| +namespace Ice { |
| + |
| +TypeConverter::TypeConverter(llvm::LLVMContext &Context) : Context(Context) { |
| + 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.
|
| + AddLlvmType(IceType_i1, llvm::IntegerType::get(Context, 1)); |
| + AddLlvmType(IceType_i8, llvm::IntegerType::get(Context, 8)); |
| + AddLlvmType(IceType_i16, llvm::IntegerType::get(Context, 16)); |
| + AddLlvmType(IceType_i32, llvm::IntegerType::get(Context, 32)); |
| + AddLlvmType(IceType_i64, llvm::IntegerType::get(Context, 64)); |
| + AddLlvmType(IceType_f32, llvm::Type::getFloatTy(Context)); |
| + AddLlvmType(IceType_f64, llvm::Type::getDoubleTy(Context)); |
| + AddLlvmType(IceType_v4i1, llvm::VectorType::get(LlvmTypes[IceType_i1], 4)); |
| + AddLlvmType(IceType_v8i1, llvm::VectorType::get(LlvmTypes[IceType_i1], 8)); |
| + AddLlvmType(IceType_v16i1, llvm::VectorType::get(LlvmTypes[IceType_i1], 16)); |
| + AddLlvmType(IceType_v16i8, llvm::VectorType::get(LlvmTypes[IceType_i8], 16)); |
| + AddLlvmType(IceType_v8i16, llvm::VectorType::get(LlvmTypes[IceType_i16], 8)); |
| + AddLlvmType(IceType_v4i32, llvm::VectorType::get(LlvmTypes[IceType_i32], 4)); |
| + AddLlvmType(IceType_v4f32, llvm::VectorType::get(LlvmTypes[IceType_f32], 4)); |
| + assert(LlvmTypes.size() == IceType_NUM); |
| +} |
| + |
| +void TypeConverter::AddLlvmType(Type Ty, llvm::Type *LlvmTy) { |
| + assert(Ty == LlvmTypes.size()); |
| + LlvmTypes.push_back(LlvmTy); |
| + Llvm2IceMap[LlvmTy] = Ty; |
| +} |
| + |
| +Type TypeConverter::convertToIceTypeOther(llvm::Type *LlvmTy) const { |
| + switch (LlvmTy->getTypeID()) { |
| + case llvm::Type::PointerTyID: |
| + case llvm::Type::FunctionTyID: |
| + return getIcePointerType(); |
| + default: |
| + return Ice::IceType_NUM; |
| + } |
| +} |
| + |
| +llvm::Type *TypeConverter::getLlvmIntegerType(unsigned NumBits) const { |
| + switch (NumBits) { |
| + case 1: |
| + 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
|
| + case 8: |
| + return LlvmTypes.at(IceType_i8); |
| + case 16: |
| + return LlvmTypes.at(IceType_i16); |
| + case 32: |
| + return LlvmTypes.at(IceType_i32); |
| + case 64: |
| + return LlvmTypes.at(IceType_i64); |
| + default: |
| + return NULL; |
| + } |
| +} |
| + |
| +llvm::Type *TypeConverter::getLlvmVectorType(unsigned Size, Type Ty) const { |
| + switch (Ty) { |
| + case IceType_i1: |
| + switch (Size) { |
| + case 4: |
| + return convertToLlvmType(IceType_v4i1); |
| + case 8: |
| + return convertToLlvmType(IceType_v8i1); |
| + case 16: |
| + return convertToLlvmType(IceType_v16i1); |
| + default: |
| + break; |
| + } |
| + break; |
| + case IceType_i8: |
| + if (Size == 16) |
| + return convertToLlvmType(IceType_v16i8); |
| + break; |
| + case IceType_i16: |
| + if (Size == 8) |
| + return convertToLlvmType(IceType_v8i16); |
| + break; |
| + case IceType_i32: |
| + if (Size == 4) |
| + return convertToLlvmType(IceType_v4i32); |
| + break; |
| + case IceType_f32: |
| + if (Size == 4) |
| + return convertToLlvmType(IceType_v4f32); |
| + break; |
| + default: |
| + break; |
| + } |
| + return NULL; |
| +} |
| + |
| +} // end of Ice namespace. |