Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- subzero/src/IceTypeConverter.h - Convert Ice/LLVm Types --*- C++ -*-===// | |
|
Jim Stichnoth
2014/07/17 23:00:33
ICE/LLVM
jvoung (off chromium)
2014/07/17 23:57:55
LLVm -> LLVM
Karl
2014/07/18 20:27:42
Done.
Karl
2014/07/18 20:27:43
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 defines how to convert LLVM types to ICE types, and ICE types | |
| 11 // to LLVM types. | |
| 12 // | |
| 13 //===----------------------------------------------------------------------===// | |
| 14 | |
| 15 #ifndef SUBZERO_SRC_ICETYPECONVERTER_H | |
| 16 #define SUBZERO_SRC_ICETYPECONVERTER_H | |
| 17 | |
| 18 #include "IceDefs.h" | |
| 19 #include "IceTypes.h" | |
| 20 #include "llvm/IR/DerivedTypes.h" | |
| 21 | |
| 22 #include <map> | |
|
jvoung (off chromium)
2014/07/17 23:57:55
Currently, src/IceDefs.h is the one place where <m
Karl
2014/07/18 20:27:43
Talked with Jim. Agreed to let IceDefs.h do the in
Jim Stichnoth
2014/07/21 22:25:21
Karl and I discussed offline. I agree it's a good
| |
| 23 | |
| 24 namespace llvm { | |
| 25 class LLVMContext; | |
| 26 } // end of llvm namespace. | |
| 27 | |
| 28 namespace Ice { | |
| 29 | |
| 30 /// Converts LLVM types to ICE types, and ICE types to LLVM types. | |
| 31 class TypeConverter { | |
| 32 TypeConverter(const TypeConverter&) LLVM_DELETED_FUNCTION; | |
| 33 TypeConverter &operator=(const TypeConverter&) LLVM_DELETED_FUNCTION; | |
| 34 public: | |
| 35 /// Context is the context to use to build llvm types. | |
| 36 TypeConverter(llvm::LLVMContext &Context); | |
| 37 | |
| 38 /// Returns the LLVM type for the corresponding ICE type Ty. | |
| 39 llvm::Type *convertToLlvmType(Type Ty) const { | |
| 40 return LlvmTypes.at(Ty); | |
| 41 } | |
| 42 | |
| 43 /// Converts LLVM type LlvmTy to an ICE type. Returns | |
| 44 /// Ice::IceType_NUM if unable to convert. | |
| 45 Type convertToIceType(llvm::Type *LlvmTy) const { | |
| 46 std::map<llvm::Type *, Type>::const_iterator | |
| 47 Pos = Llvm2IceMap.find(LlvmTy); | |
| 48 if (Pos == Llvm2IceMap.end()) | |
| 49 return convertToIceTypeOther(LlvmTy); | |
| 50 return Pos->second; | |
| 51 } | |
| 52 | |
| 53 /// Returns ICE model of pointer type. | |
| 54 Type getIcePointerType() const { | |
| 55 return IceType_i32; | |
| 56 } | |
| 57 | |
| 58 /// Returns LLVM void type. | |
| 59 llvm::Type *getLlvmVoidType() const { | |
|
jvoung (off chromium)
2014/07/17 23:57:55
This doesn't appear to be used anywhere?
Karl
2014/07/18 20:27:42
Removed.
| |
| 60 return LlvmTypes.at(IceType_void); | |
| 61 } | |
| 62 | |
| 63 /// Returns LLVM integer type with number of bits. Returns NULL | |
| 64 /// if not a valid PNaCl integer type. | |
| 65 llvm::Type *getLlvmIntegerType(unsigned NumBits) const; | |
| 66 | |
| 67 /// Returns the LLVM vector type for Size and Ty arguments. Returns | |
| 68 /// NULL if not a valid PNaCl vector type. | |
| 69 llvm::Type *getLlvmVectorType(unsigned Size, Type Ty) const; | |
| 70 | |
| 71 private: | |
| 72 // The LLVM context to use to build LLVM types. | |
| 73 llvm::LLVMContext &Context; | |
| 74 // The list of allowable LLVM types. Indexed by ICE type. | |
| 75 std::vector<llvm::Type*> LlvmTypes; | |
| 76 // The inverse mapping of LlvmTypes. | |
| 77 std::map<llvm::Type *, Type> Llvm2IceMap; | |
| 78 | |
| 79 // Add LLVM/ICE pair to internal tables. | |
| 80 void AddLlvmType(Type Ty, llvm::Type *LlvmTy); | |
| 81 | |
| 82 // Converts types not in Llvm2IceMap. | |
| 83 Type convertToIceTypeOther(llvm::Type *LlvmTy) const; | |
| 84 }; | |
| 85 | |
| 86 } // end of Ice namespace. | |
| 87 | |
| 88 #endif // SUBZERO_SRC_ICETYPECONVERTER_H | |
| OLD | NEW |