Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: src/IceTypeConverter.cpp

Issue 395193005: Start processing function blocks in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix issues in patch set 13. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceTypeConverter.h ('k') | src/IceTypes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceTypeConverter.cpp
diff --git a/src/IceTypeConverter.cpp b/src/IceTypeConverter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bfe19769cb06e5e4b86a0f5934f05ee6a9851bcc
--- /dev/null
+++ b/src/IceTypeConverter.cpp
@@ -0,0 +1,108 @@
+//===- subzero/src/IceTypeConverter.cpp - Convert ICE/LLVM Types ----------===//
+//
+// 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
+// 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));
+ 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() == static_cast<size_t>(IceType_NUM));
+}
+
+void TypeConverter::AddLLVMType(Type Ty, llvm::Type *LLVMTy) {
+ assert(static_cast<size_t>(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[IceType_i1];
+ case 8:
+ return LLVMTypes[IceType_i8];
+ case 16:
+ return LLVMTypes[IceType_i16];
+ case 32:
+ return LLVMTypes[IceType_i32];
+ case 64:
+ return LLVMTypes[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.
« no previous file with comments | « src/IceTypeConverter.h ('k') | src/IceTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698