[MLIR] Add onnf-opt Support (#359)
* support onnf-opt, register standard dialect * use onnf native assertions * fix build * nit
This commit is contained in:
parent
958a2fbffc
commit
02e1e8720f
68
MLIR.cmake
68
MLIR.cmake
|
@ -41,55 +41,84 @@ set(MLIR_INCLUDE_PATHS
|
|||
${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH})
|
||||
include_directories(${MLIR_INCLUDE_PATHS})
|
||||
|
||||
find_library(MLIRLIBANALYSIS
|
||||
find_library(MLIR_LIB_ANALYSIS
|
||||
NAMES MLIRAnalysis
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBIR NAMES MLIRIR PATHS ${LLVM_PROJECT_LIB} NO_DEFAULT_PATH)
|
||||
find_library(MLIR_LIB_IR NAMES MLIRIR PATHS ${LLVM_PROJECT_LIB} NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBPARSER
|
||||
find_library(MLIR_LIB_PARSER
|
||||
NAMES MLIRParser
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBTRANSFORMS
|
||||
find_library(MLIR_LIB_PASS
|
||||
NAMES MLIRPass
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIR_LIB_TRANSFORMS
|
||||
NAMES MLIRTransforms
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBVECTOROPS
|
||||
find_library(MLIR_LIB_VECTOR_OPS
|
||||
NAMES MLIRVectorOps
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBSUPPORT
|
||||
find_library(MLIR_LIB_SUPPORT
|
||||
NAMES MLIRSupport
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIRLIBSTANDARDOPS
|
||||
find_library(MLIR_LIB_STANDARD_OPS
|
||||
NAMES MLIRStandardOps
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(LLVMLIBSUPPORT
|
||||
find_library(MLIR_LIB_OPT_MAIN
|
||||
NAMES MLIROptMain
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(MLIR_LLVM_IR
|
||||
NAMES MLIRLLVMIR
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
find_library(LLVM_LIB_SUPPORT
|
||||
NAMES LLVMSupport
|
||||
PATHS ${LLVM_PROJECT_LIB}
|
||||
NO_DEFAULT_PATH)
|
||||
|
||||
# libraries are set according to toy/Ch2
|
||||
# Threading libraries required due to parallel pass execution.
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
set(MLIRLIBS
|
||||
${MLIRLIBANALYSIS}
|
||||
${MLIRLIBIR}
|
||||
${MLIRLIBPARSER}
|
||||
${MLIRLIBTRANSFORMS}
|
||||
${MLIRLIBANALYSIS}
|
||||
${MLIRLIBVECTOROPS}
|
||||
${MLIRLIBIR}
|
||||
${MLIRLIBSUPPORT}
|
||||
${MLIRLIBSTANDARDOPS}
|
||||
${LLVMLIBSUPPORT})
|
||||
${MLIR_LIB_ANALYSIS}
|
||||
${MLIR_LIB_IR}
|
||||
${MLIR_LIB_PARSER}
|
||||
${MLIR_LIB_PASS}
|
||||
${MLIR_LIB_TRANSFORMS}
|
||||
${MLIR_LIB_VECTOR_OPS}
|
||||
${MLIR_LIB_STANDARD_OPS}
|
||||
${MLIR_LIB_OPT_MAIN}
|
||||
${MLIR_LIB_SUPPORT}
|
||||
|
||||
${MLIR_LIB_ANALYSIS}
|
||||
${MLIR_LIB_IR}
|
||||
${MLIR_LIB_PARSER}
|
||||
${MLIR_LIB_PASS}
|
||||
${MLIR_LIB_TRANSFORMS}
|
||||
${MLIR_LIB_VECTOR_OPS}
|
||||
${MLIR_LIB_STANDARD_OPS}
|
||||
${MLIR_LIB_OPT_MAIN}
|
||||
${MLIR_LIB_SUPPORT}
|
||||
|
||||
${LLVM_LIB_SUPPORT}
|
||||
Threads::Threads)
|
||||
|
||||
# Set up TableGen environment.
|
||||
include(${LLVM_BUILD}/lib/cmake/llvm/TableGen.cmake)
|
||||
|
@ -112,3 +141,4 @@ set_property(TARGET mlir-tblgen
|
|||
PROPERTY IMPORTED_LOCATION
|
||||
${LLVM_BUILD}/bin/mlir-tblgen)
|
||||
set(MLIR_TABLEGEN_EXE mlir-tblgen)
|
||||
|
||||
|
|
|
@ -24,6 +24,13 @@ target_link_libraries(compiler
|
|||
${Boost_LIBRARIES}
|
||||
)
|
||||
|
||||
add_executable(onnf-opt
|
||||
tool/onnf_opt/onnf_opt.cpp)
|
||||
|
||||
target_link_libraries(onnf-opt ${Boost_LIBRARIES} ${MLIRLIBS} curses compiler)
|
||||
target_include_directories(onnf-opt PRIVATE ../..)
|
||||
target_include_directories(onnf-opt PRIVATE ${CMAKE_BINARY_DIR})
|
||||
|
||||
set(LLVM_TARGET_DEFINITIONS ir/knl/knl.td)
|
||||
onnf_tablegen(knl.hpp.inc -gen-op-decls)
|
||||
onnf_tablegen(knl.cpp.inc -gen-op-defs)
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#include <llvm/Support/CommandLine.h>
|
||||
#include <llvm/Support/InitLLVM.h>
|
||||
#include <llvm/Support/MemoryBuffer.h>
|
||||
#include <llvm/Support/ToolOutputFile.h>
|
||||
#include <mlir/Pass/Pass.h>
|
||||
#include <mlir/Pass/PassManager.h>
|
||||
#include <mlir/Support/FileUtilities.h>
|
||||
#include <mlir/Support/MlirOptMain.h>
|
||||
#include <mlir/Dialect/StandardOps/Ops.h>
|
||||
|
||||
#include "src/compiler/helper.hpp"
|
||||
|
||||
using namespace dlc;
|
||||
|
||||
static llvm::cl::opt<std::string> input_filename(
|
||||
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<std::string> output_filename("o",
|
||||
llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"),
|
||||
llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<bool> split_input_file("split-input-file",
|
||||
llvm::cl::desc("Split the input file into pieces and process each "
|
||||
"chunk independently"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_diagnostics("verify-diagnostics",
|
||||
llvm::cl::desc("Check that emitted diagnostics match "
|
||||
"expected-* lines on the corresponding line"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_passes("verify-each",
|
||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||
llvm::cl::init(true));
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
// Register any pass manager command line options.
|
||||
mlir::registerPassManagerCLOptions();
|
||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||
llvm::cl::ParseCommandLineOptions(
|
||||
argc, argv, "dlc MLIR modular optimizer driver\n");
|
||||
|
||||
// Set up the input file.
|
||||
std::string error_message;
|
||||
auto file = mlir::openInputFile(input_filename, &error_message);
|
||||
DLC_REQUIRE_MSG(file, error_message)
|
||||
|
||||
auto output = mlir::openOutputFile(output_filename, &error_message);
|
||||
DLC_REQUIRE_MSG(output, error_message)
|
||||
|
||||
mlir::registerDialect<mlir::StandardOpsDialect>();
|
||||
|
||||
return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline,
|
||||
split_input_file, verify_diagnostics, verify_passes));
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
//===---------------------- onnf-opt.cpp - MLIR Operations -----------------===//
|
||||
//
|
||||
// Copyright 2019 The IBM Research Authors.
|
||||
//
|
||||
// =============================================================================
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
#include <llvm/Support/InitLLVM.h>
|
||||
#include <llvm/Support/MemoryBuffer.h>
|
||||
#include <llvm/Support/ToolOutputFile.h>
|
||||
#include <mlir/Pass/Pass.h>
|
||||
#include <mlir/Pass/PassManager.h>
|
||||
#include <mlir/Support/FileUtilities.h>
|
||||
#include <mlir/Support/MlirOptMain.h>
|
||||
#include <mlir/Dialect/StandardOps/Ops.h>
|
||||
|
||||
using namespace onnf;
|
||||
|
||||
static llvm::cl::opt<std::string> input_filename(
|
||||
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<std::string> output_filename("o",
|
||||
llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"),
|
||||
llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<bool> split_input_file("split-input-file",
|
||||
llvm::cl::desc("Split the input file into pieces and process each "
|
||||
"chunk independently"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_diagnostics("verify-diagnostics",
|
||||
llvm::cl::desc("Check that emitted diagnostics match "
|
||||
"expected-* lines on the corresponding line"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_passes("verify-each",
|
||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||
llvm::cl::init(true));
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
// Register any pass manager command line options.
|
||||
mlir::registerPassManagerCLOptions();
|
||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||
llvm::cl::ParseCommandLineOptions(
|
||||
argc, argv, "onnf MLIR modular optimizer driver\n");
|
||||
|
||||
// Set up the input file.
|
||||
std::string error_message;
|
||||
auto file = mlir::openInputFile(input_filename, &error_message);
|
||||
|
||||
auto output = mlir::openOutputFile(output_filename, &error_message);
|
||||
|
||||
mlir::registerDialect<mlir::StandardOpsDialect>();
|
||||
|
||||
return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline,
|
||||
split_input_file, verify_diagnostics, verify_passes));
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
//===--------------------- onnf_opt.cpp - MLIR Operations -----------------===//
|
||||
//
|
||||
// Copyright 2019 The IBM Research Authors.
|
||||
//
|
||||
// =============================================================================
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
#include <llvm/Support/InitLLVM.h>
|
||||
#include <llvm/Support/MemoryBuffer.h>
|
||||
#include <llvm/Support/ToolOutputFile.h>
|
||||
#include <mlir/Pass/Pass.h>
|
||||
#include <mlir/Pass/PassManager.h>
|
||||
#include <mlir/Support/FileUtilities.h>
|
||||
#include <mlir/Support/MlirOptMain.h>
|
||||
#include <mlir/Dialect/StandardOps/Ops.h>
|
||||
|
||||
static llvm::cl::opt<std::string> input_filename(
|
||||
llvm::cl::Positional, llvm::cl::desc("<input file>"), llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<std::string> output_filename("o",
|
||||
llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"),
|
||||
llvm::cl::init("-"));
|
||||
|
||||
static llvm::cl::opt<bool> split_input_file("split-input-file",
|
||||
llvm::cl::desc("Split the input file into pieces and process each "
|
||||
"chunk independently"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_diagnostics("verify-diagnostics",
|
||||
llvm::cl::desc("Check that emitted diagnostics match "
|
||||
"expected-* lines on the corresponding line"),
|
||||
llvm::cl::init(false));
|
||||
|
||||
static llvm::cl::opt<bool> verify_passes("verify-each",
|
||||
llvm::cl::desc("Run the verifier after each transformation pass"),
|
||||
llvm::cl::init(true));
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
llvm::InitLLVM y(argc, argv);
|
||||
|
||||
// Register any pass manager command line options.
|
||||
mlir::registerPassManagerCLOptions();
|
||||
mlir::PassPipelineCLParser passPipeline("", "Compiler passes to run");
|
||||
llvm::cl::ParseCommandLineOptions(
|
||||
argc, argv, "onnf MLIR modular optimizer driver\n");
|
||||
|
||||
// Set up the input file.
|
||||
std::string error_message;
|
||||
auto file = mlir::openInputFile(input_filename, &error_message);
|
||||
|
||||
auto output = mlir::openOutputFile(output_filename, &error_message);
|
||||
|
||||
mlir::registerDialect<mlir::StandardOpsDialect>();
|
||||
|
||||
return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline,
|
||||
split_input_file, verify_diagnostics, verify_passes));
|
||||
}
|
Loading…
Reference in New Issue