Home | History | Annotate | Download | only in src
      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 /// \file
     11 /// \brief Defines how to convert LLVM types to ICE types, and ICE types to LLVM
     12 /// types.
     13 ///
     14 //===----------------------------------------------------------------------===//
     15 
     16 #ifndef SUBZERO_SRC_ICETYPECONVERTER_H
     17 #define SUBZERO_SRC_ICETYPECONVERTER_H
     18 
     19 #include "IceDefs.h"
     20 #include "IceTypes.h"
     21 
     22 #ifdef __clang__
     23 #pragma clang diagnostic push
     24 #pragma clang diagnostic ignored "-Wunused-parameter"
     25 #endif // __clang__
     26 
     27 #include "llvm/IR/DerivedTypes.h"
     28 
     29 #ifdef __clang__
     30 #pragma clang diagnostic pop
     31 #endif // __clang__
     32 
     33 namespace llvm {
     34 class LLVMContext;
     35 } // end of namespace llvm
     36 
     37 namespace Ice {
     38 
     39 /// Converts LLVM types to ICE types, and ICE types to LLVM types.
     40 class TypeConverter {
     41   TypeConverter() = delete;
     42   TypeConverter(const TypeConverter &) = delete;
     43   TypeConverter &operator=(const TypeConverter &) = delete;
     44 
     45 public:
     46   /// Context is the context to use to build llvm types.
     47   explicit TypeConverter(llvm::LLVMContext &Context);
     48 
     49   /// Converts LLVM type LLVMTy to an ICE type. Returns Ice::IceType_NUM if
     50   /// unable to convert.
     51   Type convertToIceType(llvm::Type *LLVMTy) const {
     52     auto Pos = LLVM2IceMap.find(LLVMTy);
     53     if (Pos == LLVM2IceMap.end())
     54       return convertToIceTypeOther(LLVMTy);
     55     return Pos->second;
     56   }
     57 
     58 private:
     59   /// The mapping from LLVM types to corresopnding Ice types.
     60   std::map<llvm::Type *, Type> LLVM2IceMap;
     61 
     62   /// Add LLVM/ICE pair to internal tables.
     63   void addLLVMType(Type Ty, llvm::Type *LLVMTy);
     64 
     65   /// Converts types not in LLVM2IceMap.
     66   Type convertToIceTypeOther(llvm::Type *LLVMTy) const;
     67 };
     68 
     69 } // end of namespace Ice
     70 
     71 #endif // SUBZERO_SRC_ICETYPECONVERTER_H
     72