2019-05-14 15:03:48 -07:00
|
|
|
//===- ConvertToLLVMIR.cpp - MLIR to LLVM IR conversion -------------------===//
|
2018-11-21 06:37:49 -08:00
|
|
|
//
|
2020-01-26 03:58:30 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-23 09:35:36 -08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-11-21 06:37:49 -08:00
|
|
|
//
|
2019-12-23 09:35:36 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2018-11-21 06:37:49 -08:00
|
|
|
//
|
2019-02-13 15:30:24 -08:00
|
|
|
// This file implements a translation between the MLIR LLVM dialect and LLVM IR.
|
2018-11-21 06:37:49 -08:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2019-04-05 08:15:41 -07:00
|
|
|
#include "mlir/Target/LLVMIR.h"
|
2019-04-30 06:08:21 -07:00
|
|
|
|
|
|
|
|
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
|
2018-11-21 06:37:49 -08:00
|
|
|
#include "mlir/Translation.h"
|
2019-02-13 15:30:24 -08:00
|
|
|
|
2019-04-30 06:08:21 -07:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-11-21 06:37:49 -08:00
|
|
|
#include "llvm/IR/Module.h"
|
2019-01-11 07:22:57 -08:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2018-11-21 06:37:49 -08:00
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
2020-08-06 18:15:47 +02:00
|
|
|
std::unique_ptr<llvm::Module>
|
|
|
|
|
mlir::translateModuleToLLVMIR(ModuleOp m, llvm::LLVMContext &llvmContext,
|
|
|
|
|
StringRef name) {
|
|
|
|
|
return LLVM::ModuleTranslation::translateModule<>(m, llvmContext, name);
|
2019-02-13 15:30:24 -08:00
|
|
|
}
|
|
|
|
|
|
2020-04-05 14:42:16 -06:00
|
|
|
namespace mlir {
|
|
|
|
|
void registerToLLVMIRTranslation() {
|
|
|
|
|
TranslateFromMLIRRegistration registration(
|
2020-08-23 00:57:47 +00:00
|
|
|
"mlir-to-llvmir",
|
|
|
|
|
[](ModuleOp module, raw_ostream &output) {
|
2020-08-06 18:15:47 +02:00
|
|
|
llvm::LLVMContext llvmContext;
|
|
|
|
|
auto llvmModule = LLVM::ModuleTranslation::translateModule<>(
|
|
|
|
|
module, llvmContext, "LLVMDialectModule");
|
2020-04-05 14:42:16 -06:00
|
|
|
if (!llvmModule)
|
|
|
|
|
return failure();
|
2018-11-21 06:37:49 -08:00
|
|
|
|
2020-04-05 14:42:16 -06:00
|
|
|
llvmModule->print(output, nullptr);
|
|
|
|
|
return success();
|
2020-08-23 00:57:47 +00:00
|
|
|
},
|
|
|
|
|
[](DialectRegistry ®istry) { registry.insert<LLVM::LLVMDialect>(); });
|
2020-04-05 14:42:16 -06:00
|
|
|
}
|
|
|
|
|
} // namespace mlir
|