Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- subzero/src/IceTypeConverter.h - Convert ICE/LLVM Types --*- C++ -*-===// | |
| 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 namespace llvm { | |
| 23 class LLVMContext; | |
| 24 } // end of llvm namespace. | |
| 25 | |
| 26 namespace Ice { | |
| 27 | |
| 28 /// Converts LLVM types to ICE types, and ICE types to LLVM types. | |
| 29 class TypeConverter { | |
| 30 TypeConverter(const TypeConverter&) LLVM_DELETED_FUNCTION; | |
| 31 TypeConverter &operator=(const TypeConverter&) LLVM_DELETED_FUNCTION; | |
| 32 public: | |
| 33 /// Context is the context to use to build llvm types. | |
| 34 TypeConverter(llvm::LLVMContext &Context); | |
| 35 | |
| 36 /// Returns the LLVM type for the corresponding ICE type Ty. | |
| 37 llvm::Type *convertToLLVMType(Type Ty) const { | |
| 38 // Note: We use "at" here to verify Ty is valid. | |
|
Jim Stichnoth
2014/08/01 18:05:33
How about:
We use "at" here in case Ty wasn't re
Karl
2014/08/25 17:46:53
Done.
| |
| 39 return LLVMTypes.at(Ty); | |
| 40 } | |
| 41 | |
| 42 /// Converts LLVM type LLVMTy to an ICE type. Returns | |
| 43 /// Ice::IceType_NUM if unable to convert. | |
| 44 Type convertToIceType(llvm::Type *LLVMTy) const { | |
| 45 std::map<llvm::Type *, Type>::const_iterator | |
| 46 Pos = LLVM2IceMap.find(LLVMTy); | |
| 47 if (Pos == LLVM2IceMap.end()) | |
| 48 return convertToIceTypeOther(LLVMTy); | |
| 49 return Pos->second; | |
| 50 } | |
| 51 | |
| 52 /// Returns ICE model of pointer type. | |
| 53 Type getIcePointerType() const { | |
| 54 return IceType_i32; | |
| 55 } | |
| 56 | |
| 57 /// Returns LLVM integer type with number of bits. Returns NULL | |
|
Jim Stichnoth
2014/08/01 18:05:33
with *specified* number
Karl
2014/08/25 17:46:53
Done.
| |
| 58 /// if not a valid PNaCl integer type. | |
| 59 llvm::Type *getLLVMIntegerType(unsigned NumBits) const; | |
| 60 | |
| 61 /// Returns the LLVM vector type for Size and Ty arguments. Returns | |
| 62 /// NULL if not a valid PNaCl vector type. | |
| 63 llvm::Type *getLLVMVectorType(unsigned Size, Type Ty) const; | |
| 64 | |
| 65 private: | |
| 66 // The LLVM context to use to build LLVM types. | |
| 67 llvm::LLVMContext &Context; | |
| 68 // The list of allowable LLVM types. Indexed by ICE type. | |
| 69 std::vector<llvm::Type*> LLVMTypes; | |
| 70 // The inverse mapping of LLVMTypes. | |
| 71 std::map<llvm::Type *, Type> LLVM2IceMap; | |
| 72 | |
| 73 // Add LLVM/ICE pair to internal tables. | |
| 74 void AddLLVMType(Type Ty, llvm::Type *LLVMTy); | |
| 75 | |
| 76 // Converts types not in LLVM2IceMap. | |
| 77 Type convertToIceTypeOther(llvm::Type *LLVMTy) const; | |
| 78 }; | |
| 79 | |
| 80 } // end of Ice namespace. | |
| 81 | |
| 82 #endif // SUBZERO_SRC_ICETYPECONVERTER_H | |
| OLD | NEW |