Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 9 | /// |
| 10 | /// \file |
| 11 | /// This file defines how to convert LLVM types to ICE types, and ICE types |
| 12 | /// to LLVM types. |
| 13 | /// |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETYPECONVERTER_H |
| 17 | #define SUBZERO_SRC_ICETYPECONVERTER_H |
| 18 | |
| 19 | #include "IceDefs.h" |
| 20 | #include "IceTypes.h" |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 21 | #include "llvm/IR/DerivedTypes.h" |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | class LLVMContext; |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 25 | } // end of namespace llvm |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 26 | |
| 27 | namespace Ice { |
| 28 | |
| 29 | /// Converts LLVM types to ICE types, and ICE types to LLVM types. |
| 30 | class TypeConverter { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 31 | TypeConverter() = delete; |
Jim Stichnoth | 0795ba0 | 2014-10-01 14:23:01 -0700 | [diff] [blame] | 32 | TypeConverter(const TypeConverter &) = delete; |
| 33 | TypeConverter &operator=(const TypeConverter &) = delete; |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 34 | |
| 35 | public: |
| 36 | /// Context is the context to use to build llvm types. |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 37 | explicit TypeConverter(llvm::LLVMContext &Context); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 38 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 39 | /// Converts LLVM type LLVMTy to an ICE type. Returns |
| 40 | /// Ice::IceType_NUM if unable to convert. |
| 41 | Type convertToIceType(llvm::Type *LLVMTy) const { |
Jim Stichnoth | f44f371 | 2014-10-01 14:05:51 -0700 | [diff] [blame] | 42 | auto Pos = LLVM2IceMap.find(LLVMTy); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 43 | if (Pos == LLVM2IceMap.end()) |
| 44 | return convertToIceTypeOther(LLVMTy); |
| 45 | return Pos->second; |
| 46 | } |
| 47 | |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 48 | private: |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 49 | /// The mapping from LLVM types to corresopnding Ice types. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 50 | std::map<llvm::Type *, Type> LLVM2IceMap; |
| 51 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 52 | /// Add LLVM/ICE pair to internal tables. |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 53 | void addLLVMType(Type Ty, llvm::Type *LLVMTy); |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 54 | |
Andrew Scull | 9612d32 | 2015-07-06 14:53:25 -0700 | [diff] [blame] | 55 | /// Converts types not in LLVM2IceMap. |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 56 | Type convertToIceTypeOther(llvm::Type *LLVMTy) const; |
| 57 | }; |
| 58 | |
John Porto | 67f8de9 | 2015-06-25 10:14:17 -0700 | [diff] [blame] | 59 | } // end of namespace Ice |
Karl Schimpf | d6064a1 | 2014-08-27 15:34:58 -0700 | [diff] [blame] | 60 | |
| 61 | #endif // SUBZERO_SRC_ICETYPECONVERTER_H |