//===- ModuleTranslation.h - MLIR to LLVM conversion ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the translation between an MLIR LLVM dialect module and // the corresponding LLVMIR module. It only handles core LLVM IR operations. // //===----------------------------------------------------------------------===// #ifndef MLIR_TARGET_LLVMIR_MODULETRANSLATION_H #define MLIR_TARGET_LLVMIR_MODULETRANSLATION_H #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h" #include "mlir/IR/Operation.h" #include "mlir/IR/SymbolTable.h" #include "mlir/IR/Value.h" #include "mlir/Target/LLVMIR/Export.h" #include "mlir/Target/LLVMIR/LLVMTranslationInterface.h" #include "mlir/Target/LLVMIR/TypeToLLVM.h" #include "llvm/ADT/SetVector.h" #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" namespace llvm { class BasicBlock; class IRBuilderBase; class Function; class Value; } // namespace llvm namespace mlir { class Attribute; class Block; class Location; namespace LLVM { namespace detail { class DebugTranslation; class LoopAnnotationTranslation; } // namespace detail class AliasScopeAttr; class AliasScopeDomainAttr; class DINodeAttr; class LLVMFuncOp; class ComdatSelectorOp; /// Implementation class for module translation. Holds a reference to the module /// being translated, and the mappings between the original and the translated /// functions, basic blocks and values. It is practically easier to hold these /// mappings in one class since the conversion of control flow operations /// needs to look up block and function mappings. class ModuleTranslation { … }; namespace detail { /// For all blocks in the region that were converted to LLVM IR using the given /// ModuleTranslation, connect the PHI nodes of the corresponding LLVM IR blocks /// to the results of preceding blocks. void connectPHINodes(Region ®ion, const ModuleTranslation &state); /// Create an LLVM IR constant of `llvmType` from the MLIR attribute `attr`. /// This currently supports integer, floating point, splat and dense element /// attributes and combinations thereof. Also, an array attribute with two /// elements is supported to represent a complex constant. In case of error, /// report it to `loc` and return nullptr. llvm::Constant *getLLVMConstant(llvm::Type *llvmType, Attribute attr, Location loc, const ModuleTranslation &moduleTranslation); /// Creates a call to an LLVM IR intrinsic function with the given arguments. llvm::CallInst *createIntrinsicCall(llvm::IRBuilderBase &builder, llvm::Intrinsic::ID intrinsic, ArrayRef<llvm::Value *> args = { … }; /// Creates a call to a LLVM IR intrinsic defined by LLVM_IntrOpBase. This /// resolves the overloads, and maps mixed MLIR value and attribute arguments to /// LLVM values. llvm::CallInst *createIntrinsicCall( llvm::IRBuilderBase &builder, ModuleTranslation &moduleTranslation, Operation *intrOp, llvm::Intrinsic::ID intrinsic, unsigned numResults, ArrayRef<unsigned> overloadedResults, ArrayRef<unsigned> overloadedOperands, ArrayRef<unsigned> immArgPositions, ArrayRef<StringLiteral> immArgAttrNames); } // namespace detail } // namespace LLVM } // namespace mlir namespace llvm { isa_impl<T, ::mlir::LLVM::ModuleTranslation::StackFrame>; } // namespace llvm #endif // MLIR_TARGET_LLVMIR_MODULETRANSLATION_H