1cde4d5a6SJacques Pienaar //===- ConvertToLLVMIR.cpp - MLIR to LLVM IR conversion -------------------===//
2ac6bfa67SAlex Zinenko //
3ac6bfa67SAlex Zinenko // Copyright 2019 The MLIR Authors.
4ac6bfa67SAlex Zinenko //
5ac6bfa67SAlex Zinenko // Licensed under the Apache License, Version 2.0 (the "License");
6ac6bfa67SAlex Zinenko // you may not use this file except in compliance with the License.
7ac6bfa67SAlex Zinenko // You may obtain a copy of the License at
8ac6bfa67SAlex Zinenko //
9ac6bfa67SAlex Zinenko //   http://www.apache.org/licenses/LICENSE-2.0
10ac6bfa67SAlex Zinenko //
11ac6bfa67SAlex Zinenko // Unless required by applicable law or agreed to in writing, software
12ac6bfa67SAlex Zinenko // distributed under the License is distributed on an "AS IS" BASIS,
13ac6bfa67SAlex Zinenko // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14ac6bfa67SAlex Zinenko // See the License for the specific language governing permissions and
15ac6bfa67SAlex Zinenko // limitations under the License.
16ac6bfa67SAlex Zinenko // =============================================================================
17ac6bfa67SAlex Zinenko //
1850700b81SAlex Zinenko // This file implements a translation between the MLIR LLVM dialect and LLVM IR.
19ac6bfa67SAlex Zinenko //
20ac6bfa67SAlex Zinenko //===----------------------------------------------------------------------===//
21ac6bfa67SAlex Zinenko 
2233285de9SAlex Zinenko #include "mlir/Target/LLVMIR.h"
235d7231d8SStephan Herhut 
245d7231d8SStephan Herhut #include "mlir/Target/LLVMIR/ModuleTranslation.h"
25ac6bfa67SAlex Zinenko #include "mlir/Translation.h"
2650700b81SAlex Zinenko 
275d7231d8SStephan Herhut #include "llvm/ADT/StringRef.h"
28ac6bfa67SAlex Zinenko #include "llvm/IR/Module.h"
29ac5a50e1SLei Zhang #include "llvm/Support/ToolOutputFile.h"
30ac6bfa67SAlex Zinenko 
31ac6bfa67SAlex Zinenko using namespace mlir;
32ac6bfa67SAlex Zinenko 
33fec20e59SRiver Riddle std::unique_ptr<llvm::Module> mlir::translateModuleToLLVMIR(ModuleOp m) {
345d7231d8SStephan Herhut   return LLVM::ModuleTranslation::translateModule<>(m);
3550700b81SAlex Zinenko }
3650700b81SAlex Zinenko 
3750700b81SAlex Zinenko static TranslateFromMLIRRegistration registration(
38*b00a522bSLei Zhang     "mlir-to-llvmir", [](ModuleOp module, llvm::raw_ostream &output) {
39206e55ccSRiver Riddle       auto llvmModule = LLVM::ModuleTranslation::translateModule<>(module);
40ac6bfa67SAlex Zinenko       if (!llvmModule)
416f7f2bceSAlex Zinenko         return failure();
42ac6bfa67SAlex Zinenko 
43*b00a522bSLei Zhang       llvmModule->print(output, nullptr);
446f7f2bceSAlex Zinenko       return success();
45ac6bfa67SAlex Zinenko     });
46