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 /// \file
11 /// \brief Implements how to convert LLVM types to ICE types, and ICE types to
12 /// LLVM types.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "IceTypeConverter.h"
17 
18 #include "llvm/Support/raw_ostream.h"
19 
20 namespace Ice {
21 
TypeConverter(llvm::LLVMContext & Context)22 TypeConverter::TypeConverter(llvm::LLVMContext &Context) {
23   addLLVMType(IceType_void, llvm::Type::getVoidTy(Context));
24   llvm::Type *Type_i1 = llvm::IntegerType::get(Context, 1);
25   llvm::Type *Type_i8 = llvm::IntegerType::get(Context, 8);
26   llvm::Type *Type_i16 = llvm::IntegerType::get(Context, 16);
27   llvm::Type *Type_i32 = llvm::IntegerType::get(Context, 32);
28   llvm::Type *Type_f32 = llvm::Type::getFloatTy(Context);
29   addLLVMType(IceType_i1, Type_i1);
30   addLLVMType(IceType_i8, Type_i8);
31   addLLVMType(IceType_i16, Type_i16);
32   addLLVMType(IceType_i32, Type_i32);
33   addLLVMType(IceType_i64, llvm::IntegerType::get(Context, 64));
34   addLLVMType(IceType_f32, Type_f32);
35   addLLVMType(IceType_f64, llvm::Type::getDoubleTy(Context));
36   addLLVMType(IceType_v4i1, llvm::VectorType::get(Type_i1, 4));
37   addLLVMType(IceType_v8i1, llvm::VectorType::get(Type_i1, 8));
38   addLLVMType(IceType_v16i1, llvm::VectorType::get(Type_i1, 16));
39   addLLVMType(IceType_v16i8, llvm::VectorType::get(Type_i8, 16));
40   addLLVMType(IceType_v8i16, llvm::VectorType::get(Type_i16, 8));
41   addLLVMType(IceType_v4i32, llvm::VectorType::get(Type_i32, 4));
42   addLLVMType(IceType_v4f32, llvm::VectorType::get(Type_f32, 4));
43   assert(LLVM2IceMap.size() == static_cast<size_t>(IceType_NUM));
44 }
45 
addLLVMType(Type Ty,llvm::Type * LLVMTy)46 void TypeConverter::addLLVMType(Type Ty, llvm::Type *LLVMTy) {
47   LLVM2IceMap[LLVMTy] = Ty;
48 }
49 
convertToIceTypeOther(llvm::Type * LLVMTy) const50 Type TypeConverter::convertToIceTypeOther(llvm::Type *LLVMTy) const {
51   switch (LLVMTy->getTypeID()) {
52   case llvm::Type::PointerTyID:
53   case llvm::Type::FunctionTyID:
54     return getPointerType();
55   default:
56     return Ice::IceType_NUM;
57   }
58 }
59 
60 } // end of Ice namespace.
61