blob: 81dde9216dd80e146adc993b6355e369bca410e2 [file] [log] [blame]
Karl Schimpfd6064a12014-08-27 15:34:58 -07001//===- 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 Scull9612d322015-07-06 14:53:25 -07009///
10/// \file
11/// This file defines how to convert LLVM types to ICE types, and ICE types
12/// to LLVM types.
13///
Karl Schimpfd6064a12014-08-27 15:34:58 -070014//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICETYPECONVERTER_H
17#define SUBZERO_SRC_ICETYPECONVERTER_H
18
19#include "IceDefs.h"
20#include "IceTypes.h"
John Porto67f8de92015-06-25 10:14:17 -070021#include "llvm/IR/DerivedTypes.h"
Karl Schimpfd6064a12014-08-27 15:34:58 -070022
23namespace llvm {
24class LLVMContext;
John Porto67f8de92015-06-25 10:14:17 -070025} // end of namespace llvm
Karl Schimpfd6064a12014-08-27 15:34:58 -070026
27namespace Ice {
28
29/// Converts LLVM types to ICE types, and ICE types to LLVM types.
30class TypeConverter {
Jim Stichnothc6ead202015-02-24 09:30:30 -080031 TypeConverter() = delete;
Jim Stichnoth0795ba02014-10-01 14:23:01 -070032 TypeConverter(const TypeConverter &) = delete;
33 TypeConverter &operator=(const TypeConverter &) = delete;
Karl Schimpfd6064a12014-08-27 15:34:58 -070034
35public:
36 /// Context is the context to use to build llvm types.
Jim Stichnothc6ead202015-02-24 09:30:30 -080037 explicit TypeConverter(llvm::LLVMContext &Context);
Karl Schimpfd6064a12014-08-27 15:34:58 -070038
Karl Schimpfd6064a12014-08-27 15:34:58 -070039 /// 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 Stichnothf44f3712014-10-01 14:05:51 -070042 auto Pos = LLVM2IceMap.find(LLVMTy);
Karl Schimpfd6064a12014-08-27 15:34:58 -070043 if (Pos == LLVM2IceMap.end())
44 return convertToIceTypeOther(LLVMTy);
45 return Pos->second;
46 }
47
Karl Schimpfd6064a12014-08-27 15:34:58 -070048private:
Andrew Scull9612d322015-07-06 14:53:25 -070049 /// The mapping from LLVM types to corresopnding Ice types.
Karl Schimpfd6064a12014-08-27 15:34:58 -070050 std::map<llvm::Type *, Type> LLVM2IceMap;
51
Andrew Scull9612d322015-07-06 14:53:25 -070052 /// Add LLVM/ICE pair to internal tables.
Karl Schimpfe3f64d02014-10-07 10:38:22 -070053 void addLLVMType(Type Ty, llvm::Type *LLVMTy);
Karl Schimpfd6064a12014-08-27 15:34:58 -070054
Andrew Scull9612d322015-07-06 14:53:25 -070055 /// Converts types not in LLVM2IceMap.
Karl Schimpfd6064a12014-08-27 15:34:58 -070056 Type convertToIceTypeOther(llvm::Type *LLVMTy) const;
57};
58
John Porto67f8de92015-06-25 10:14:17 -070059} // end of namespace Ice
Karl Schimpfd6064a12014-08-27 15:34:58 -070060
61#endif // SUBZERO_SRC_ICETYPECONVERTER_H