1 //===- TypeToLLVM.h - Translate types from MLIR to LLVM --*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file declares the type translation function going from MLIR LLVM dialect 10 // to LLVM IR and back. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef MLIR_TARGET_LLVMIR_TYPETOLLVM_H 15 #define MLIR_TARGET_LLVMIR_TYPETOLLVM_H 16 17 #include <memory> 18 19 namespace llvm { 20 class DataLayout; 21 class LLVMContext; 22 class Type; 23 } // namespace llvm 24 25 namespace mlir { 26 27 class Type; 28 class MLIRContext; 29 30 namespace LLVM { 31 32 namespace detail { 33 class TypeToLLVMIRTranslatorImpl; 34 } // namespace detail 35 36 /// Utility class to translate MLIR LLVM dialect types to LLVM IR. Stores the 37 /// translation state, in particular any identified structure types that can be 38 /// reused in further translation. 39 class TypeToLLVMIRTranslator { 40 public: 41 TypeToLLVMIRTranslator(llvm::LLVMContext &context); 42 ~TypeToLLVMIRTranslator(); 43 44 /// Returns the preferred alignment for the type given the data layout. Note 45 /// that this will perform type conversion and store its results for future 46 /// uses. 47 // TODO: this should be removed when MLIR has proper data layout. 48 unsigned getPreferredAlignment(Type type, const llvm::DataLayout &layout); 49 50 /// Translates the given MLIR LLVM dialect type to LLVM IR. 51 llvm::Type *translateType(Type type); 52 53 private: 54 /// Private implementation. 55 std::unique_ptr<detail::TypeToLLVMIRTranslatorImpl> impl; 56 }; 57 58 } // namespace LLVM 59 } // namespace mlir 60 61 #endif // MLIR_TARGET_LLVMIR_TYPETOLLVM_H 62