150
|
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
|
236
|
13 #include "mlir/Dialect/DLTI/DLTI.h"
|
|
14 #include "mlir/Dialect/Func/IR/FuncOps.h"
|
221
|
15 #include "mlir/IR/BuiltinOps.h"
|
252
|
16 #include "mlir/Target/LLVM/NVVM/Target.h"
|
|
17 #include "mlir/Target/LLVM/ROCDL/Target.h"
|
221
|
18 #include "mlir/Target/LLVMIR/Dialect/All.h"
|
|
19 #include "mlir/Target/LLVMIR/Export.h"
|
236
|
20 #include "mlir/Tools/mlir-translate/Translation.h"
|
221
|
21 #include "llvm/IR/LLVMContext.h"
|
150
|
22 #include "llvm/IR/Module.h"
|
|
23
|
|
24 using namespace mlir;
|
|
25
|
173
|
26 namespace mlir {
|
|
27 void registerToLLVMIRTranslation() {
|
|
28 TranslateFromMLIRRegistration registration(
|
252
|
29 "mlir-to-llvmir", "Translate MLIR to LLVMIR",
|
236
|
30 [](Operation *op, raw_ostream &output) {
|
221
|
31 llvm::LLVMContext llvmContext;
|
236
|
32 auto llvmModule = translateModuleToLLVMIR(op, llvmContext);
|
173
|
33 if (!llvmModule)
|
|
34 return failure();
|
150
|
35
|
173
|
36 llvmModule->print(output, nullptr);
|
|
37 return success();
|
221
|
38 },
|
|
39 [](DialectRegistry ®istry) {
|
236
|
40 registry.insert<DLTIDialect, func::FuncDialect>();
|
252
|
41 registerNVVMTarget(registry);
|
|
42 registerROCDLTarget(registry);
|
221
|
43 registerAllToLLVMIRTranslations(registry);
|
173
|
44 });
|
|
45 }
|
|
46 } // namespace mlir
|