MLIR  19.0.0git
ConvertToLLVMIR.cpp
Go to the documentation of this file.
1 //===- ConvertToLLVMIR.cpp - MLIR to LLVM IR conversion -------------------===//
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 implements a translation between the MLIR LLVM dialect and LLVM IR.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "mlir/Dialect/DLTI/DLTI.h"
15 #include "mlir/IR/BuiltinOps.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Module.h"
21 
22 using namespace mlir;
23 
24 namespace mlir {
26  TranslateFromMLIRRegistration registration(
27  "mlir-to-llvmir", "Translate MLIR to LLVMIR",
28  [](Operation *op, raw_ostream &output) {
29  llvm::LLVMContext llvmContext;
30  auto llvmModule = translateModuleToLLVMIR(op, llvmContext);
31  if (!llvmModule)
32  return failure();
33 
34  llvmModule->print(output, nullptr);
35  return success();
36  },
37  [](DialectRegistry &registry) {
38  registry.insert<DLTIDialect, func::FuncDialect>();
40  });
41 }
42 } // namespace mlir
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Include the generated interface declarations.
void registerToLLVMIRTranslation()
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
static void registerAllToLLVMIRTranslations(DialectRegistry &registry)
Registers all dialects that can be translated to LLVM IR and the corresponding translation interfaces...
Definition: All.h:39
std::unique_ptr< llvm::Module > translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext, llvm::StringRef name="LLVMDialectModule")
Translate operation that satisfies LLVM dialect module requirements into an LLVM IR module living in ...