OLD | NEW |
1 //===- subzero/src/IceTypeConverter.h - Convert ICE/LLVM Types --*- C++ -*-===// | 1 //===- subzero/src/IceTypeConverter.h - Convert ICE/LLVM Types --*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines how to convert LLVM types to ICE types, and ICE types | 10 // This file defines how to convert LLVM types to ICE types, and ICE types |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 /// Converts LLVM types to ICE types, and ICE types to LLVM types. | 29 /// Converts LLVM types to ICE types, and ICE types to LLVM types. |
30 class TypeConverter { | 30 class TypeConverter { |
31 TypeConverter(const TypeConverter &) = delete; | 31 TypeConverter(const TypeConverter &) = delete; |
32 TypeConverter &operator=(const TypeConverter &) = delete; | 32 TypeConverter &operator=(const TypeConverter &) = delete; |
33 | 33 |
34 public: | 34 public: |
35 /// Context is the context to use to build llvm types. | 35 /// Context is the context to use to build llvm types. |
36 TypeConverter(llvm::LLVMContext &Context); | 36 TypeConverter(llvm::LLVMContext &Context); |
37 | 37 |
38 /// Returns the LLVM type for the corresponding ICE type Ty. | |
39 llvm::Type *convertToLLVMType(Type Ty) const { | |
40 // Note: We use "at" here in case Ty wasn't registered. | |
41 return LLVMTypes.at(Ty); | |
42 } | |
43 | |
44 /// Converts LLVM type LLVMTy to an ICE type. Returns | 38 /// Converts LLVM type LLVMTy to an ICE type. Returns |
45 /// Ice::IceType_NUM if unable to convert. | 39 /// Ice::IceType_NUM if unable to convert. |
46 Type convertToIceType(llvm::Type *LLVMTy) const { | 40 Type convertToIceType(llvm::Type *LLVMTy) const { |
47 auto Pos = LLVM2IceMap.find(LLVMTy); | 41 auto Pos = LLVM2IceMap.find(LLVMTy); |
48 if (Pos == LLVM2IceMap.end()) | 42 if (Pos == LLVM2IceMap.end()) |
49 return convertToIceTypeOther(LLVMTy); | 43 return convertToIceTypeOther(LLVMTy); |
50 return Pos->second; | 44 return Pos->second; |
51 } | 45 } |
52 | 46 |
53 /// Returns ICE model of pointer type. | |
54 Type getIcePointerType() const { return IceType_i32; } | |
55 | |
56 private: | 47 private: |
57 // The list of allowable LLVM types. Indexed by ICE type. | 48 // The mapping from LLVM types to corresopnding Ice types. |
58 std::vector<llvm::Type *> LLVMTypes; | |
59 // The inverse mapping of LLVMTypes. | |
60 std::map<llvm::Type *, Type> LLVM2IceMap; | 49 std::map<llvm::Type *, Type> LLVM2IceMap; |
61 | 50 |
62 // Add LLVM/ICE pair to internal tables. | 51 // Add LLVM/ICE pair to internal tables. |
63 void addLLVMType(Type Ty, llvm::Type *LLVMTy); | 52 void addLLVMType(Type Ty, llvm::Type *LLVMTy); |
64 | 53 |
65 // Converts types not in LLVM2IceMap. | 54 // Converts types not in LLVM2IceMap. |
66 Type convertToIceTypeOther(llvm::Type *LLVMTy) const; | 55 Type convertToIceTypeOther(llvm::Type *LLVMTy) const; |
67 }; | 56 }; |
68 | 57 |
69 } // end of Ice namespace. | 58 } // end of Ice namespace. |
70 | 59 |
71 #endif // SUBZERO_SRC_ICETYPECONVERTER_H | 60 #endif // SUBZERO_SRC_ICETYPECONVERTER_H |
OLD | NEW |