[MLIR] Add onnf-opt Support (#359)

* support onnf-opt, register standard dialect

* use onnf native assertions

* fix build

* nit
This commit is contained in:
Tian Jin 2019-11-04 10:58:48 -05:00 committed by Doru Bercea
parent 958a2fbffc
commit 02e1e8720f
5 changed files with 233 additions and 19 deletions

View File

@ -41,55 +41,84 @@ set(MLIR_INCLUDE_PATHS
${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH}) ${LLVM_SRC_INCLUDE_PATH};${LLVM_BIN_INCLUDE_PATH};${MLIR_SRC_INCLUDE_PATH};${MLIR_BIN_INCLUDE_PATH})
include_directories(${MLIR_INCLUDE_PATHS}) include_directories(${MLIR_INCLUDE_PATHS})
find_library(MLIRLIBANALYSIS find_library(MLIR_LIB_ANALYSIS
NAMES MLIRAnalysis NAMES MLIRAnalysis
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) 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 NAMES MLIRParser
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) 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 NAMES MLIRTransforms
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
find_library(MLIRLIBVECTOROPS find_library(MLIR_LIB_VECTOR_OPS
NAMES MLIRVectorOps NAMES MLIRVectorOps
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
find_library(MLIRLIBSUPPORT find_library(MLIR_LIB_SUPPORT
NAMES MLIRSupport NAMES MLIRSupport
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
find_library(MLIRLIBSTANDARDOPS find_library(MLIR_LIB_STANDARD_OPS
NAMES MLIRStandardOps NAMES MLIRStandardOps
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) 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 NAMES LLVMSupport
PATHS ${LLVM_PROJECT_LIB} PATHS ${LLVM_PROJECT_LIB}
NO_DEFAULT_PATH) NO_DEFAULT_PATH)
# libraries are set according to toy/Ch2 # Threading libraries required due to parallel pass execution.
find_package(Threads REQUIRED)
set(MLIRLIBS set(MLIRLIBS
${MLIRLIBANALYSIS} ${MLIR_LIB_ANALYSIS}
${MLIRLIBIR} ${MLIR_LIB_IR}
${MLIRLIBPARSER} ${MLIR_LIB_PARSER}
${MLIRLIBTRANSFORMS} ${MLIR_LIB_PASS}
${MLIRLIBANALYSIS} ${MLIR_LIB_TRANSFORMS}
${MLIRLIBVECTOROPS} ${MLIR_LIB_VECTOR_OPS}
${MLIRLIBIR} ${MLIR_LIB_STANDARD_OPS}
${MLIRLIBSUPPORT} ${MLIR_LIB_OPT_MAIN}
${MLIRLIBSTANDARDOPS} ${MLIR_LIB_SUPPORT}
${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}
${LLVM_LIB_SUPPORT}
Threads::Threads)
# Set up TableGen environment. # Set up TableGen environment.
include(${LLVM_BUILD}/lib/cmake/llvm/TableGen.cmake) include(${LLVM_BUILD}/lib/cmake/llvm/TableGen.cmake)
@ -112,3 +141,4 @@ set_property(TARGET mlir-tblgen
PROPERTY IMPORTED_LOCATION PROPERTY IMPORTED_LOCATION
${LLVM_BUILD}/bin/mlir-tblgen) ${LLVM_BUILD}/bin/mlir-tblgen)
set(MLIR_TABLEGEN_EXE mlir-tblgen) set(MLIR_TABLEGEN_EXE mlir-tblgen)

View File

@ -24,6 +24,13 @@ target_link_libraries(compiler
${Boost_LIBRARIES} ${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) set(LLVM_TARGET_DEFINITIONS ir/knl/knl.td)
onnf_tablegen(knl.hpp.inc -gen-op-decls) onnf_tablegen(knl.hpp.inc -gen-op-decls)
onnf_tablegen(knl.cpp.inc -gen-op-defs) onnf_tablegen(knl.cpp.inc -gen-op-defs)

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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));
}