2020-03-25 01:48:54 +08:00
|
|
|
//===--------------------------- main_utils.hpp ---------------------------===//
|
|
|
|
//
|
|
|
|
// Copyright 2019-2020 The IBM Research Authors.
|
|
|
|
//
|
|
|
|
// =============================================================================
|
|
|
|
//
|
|
|
|
// Functions for adding passes and processing input files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "llvm/Bitcode/BitcodeWriter.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/FileUtilities.h"
|
|
|
|
#include "llvm/Support/InitLLVM.h"
|
|
|
|
#include "llvm/Support/Regex.h"
|
|
|
|
#include "llvm/Support/SourceMgr.h"
|
|
|
|
|
|
|
|
#include "src/Builder/FrontendDialectTransformer.hpp"
|
|
|
|
#include "src/Dialect/Krnl/KrnlOps.hpp"
|
|
|
|
#include "src/Dialect/ONNX/ONNXOps.hpp"
|
|
|
|
#include "src/Pass/Passes.hpp"
|
|
|
|
|
2020-05-20 15:45:42 +08:00
|
|
|
#include "mlir/Conversion/SCFToStandard/SCFToStandard.h"
|
2020-03-25 01:48:54 +08:00
|
|
|
#include "mlir/ExecutionEngine/ExecutionEngine.h"
|
|
|
|
#include "mlir/ExecutionEngine/OptUtils.h"
|
|
|
|
#include "mlir/IR/MLIRContext.h"
|
|
|
|
#include "mlir/IR/Module.h"
|
2020-05-13 22:37:51 +08:00
|
|
|
#include "mlir/InitAllDialects.h"
|
2020-03-25 01:48:54 +08:00
|
|
|
#include "mlir/Parser.h"
|
|
|
|
#include "mlir/Pass/Pass.h"
|
|
|
|
#include "mlir/Pass/PassManager.h"
|
|
|
|
#include "mlir/Target/LLVMIR.h"
|
|
|
|
#include "mlir/Transforms/Passes.h"
|
|
|
|
|
|
|
|
enum EmissionTargetType {
|
2020-04-06 23:35:17 +08:00
|
|
|
EmitONNXBasic,
|
2020-03-25 01:48:54 +08:00
|
|
|
EmitONNXIR,
|
|
|
|
EmitMLIR,
|
|
|
|
EmitLLVMIR,
|
2020-05-19 10:15:48 +08:00
|
|
|
EmitLib,
|
2020-07-11 13:23:13 +08:00
|
|
|
EmitJNI,
|
2020-03-25 01:48:54 +08:00
|
|
|
};
|
|
|
|
|
2020-07-11 13:23:13 +08:00
|
|
|
void setExecPath(const char *argv0, void *fmain);
|
|
|
|
|
2020-03-25 01:48:54 +08:00
|
|
|
void LoadMLIR(std::string inputFilename, mlir::MLIRContext &context,
|
2020-05-13 22:37:51 +08:00
|
|
|
mlir::OwningModuleRef &module);
|
2020-03-25 01:48:54 +08:00
|
|
|
|
2020-05-19 10:15:48 +08:00
|
|
|
void compileModuleToSharedLibrary(
|
|
|
|
const mlir::OwningModuleRef &module, std::string outputBaseName);
|
2020-03-25 01:48:54 +08:00
|
|
|
|
2020-07-11 13:23:13 +08:00
|
|
|
void compileModuleToJniJar(
|
|
|
|
const mlir::OwningModuleRef &module, std::string outputBaseName);
|
|
|
|
|
2020-03-25 01:48:54 +08:00
|
|
|
void registerDialects();
|
|
|
|
|
|
|
|
void addONNXToMLIRPasses(mlir::PassManager &pm);
|
|
|
|
|
|
|
|
void addONNXToKrnlPasses(mlir::PassManager &pm);
|
|
|
|
|
|
|
|
void addKrnlToAffinePasses(mlir::PassManager &pm);
|
|
|
|
|
|
|
|
void addKrnlToLLVMPasses(mlir::PassManager &pm);
|
|
|
|
|
|
|
|
void processInputFile(std::string inputFilename,
|
2020-04-25 04:15:36 +08:00
|
|
|
EmissionTargetType emissionTarget, mlir::MLIRContext &context,
|
|
|
|
mlir::OwningModuleRef &module);
|
|
|
|
|
|
|
|
void outputCode(
|
2020-05-13 22:37:51 +08:00
|
|
|
mlir::OwningModuleRef &module, std::string filename, std::string extension);
|
2020-04-25 04:15:36 +08:00
|
|
|
|
|
|
|
void emitOutputFiles(std::string outputBaseName,
|
|
|
|
EmissionTargetType emissionTarget, mlir::MLIRContext &context,
|
2020-05-20 15:45:42 +08:00
|
|
|
mlir::OwningModuleRef &module);
|
2020-06-08 10:18:55 +08:00
|
|
|
|
|
|
|
int compileModule(mlir::OwningModuleRef &module, mlir::MLIRContext &context,
|
|
|
|
std::string outputBaseName, EmissionTargetType targetType);
|