diff --git a/MLIR.cmake b/MLIR.cmake index 4fbe8a0..1ad10de 100644 --- a/MLIR.cmake +++ b/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) + diff --git a/src/compiler/CMakeLists.txt b/src/compiler/CMakeLists.txt index 26a2c30..b7e0aae 100644 --- a/src/compiler/CMakeLists.txt +++ b/src/compiler/CMakeLists.txt @@ -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) diff --git a/src/compiler/tool/dlc_opt/dlc_opt.cpp b/src/compiler/tool/dlc_opt/dlc_opt.cpp new file mode 100644 index 0000000..c2c976a --- /dev/null +++ b/src/compiler/tool/dlc_opt/dlc_opt.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/compiler/helper.hpp" + +using namespace dlc; + +static llvm::cl::opt input_filename( + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-")); + +static llvm::cl::opt output_filename("o", + llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"), + llvm::cl::init("-")); + +static llvm::cl::opt 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 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 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(); + + return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline, + split_input_file, verify_diagnostics, verify_passes)); +} diff --git a/src/compiler/tool/dlc_opt/onnf_opt.cpp b/src/compiler/tool/dlc_opt/onnf_opt.cpp new file mode 100644 index 0000000..fc46803 --- /dev/null +++ b/src/compiler/tool/dlc_opt/onnf_opt.cpp @@ -0,0 +1,61 @@ +//===---------------------- onnf-opt.cpp - MLIR Operations -----------------===// +// +// Copyright 2019 The IBM Research Authors. +// +// ============================================================================= +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace onnf; + +static llvm::cl::opt input_filename( + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-")); + +static llvm::cl::opt output_filename("o", + llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"), + llvm::cl::init("-")); + +static llvm::cl::opt 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 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 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(); + + return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline, + split_input_file, verify_diagnostics, verify_passes)); +} diff --git a/src/compiler/tool/onnf_opt/onnf_opt.cpp b/src/compiler/tool/onnf_opt/onnf_opt.cpp new file mode 100644 index 0000000..b91d410 --- /dev/null +++ b/src/compiler/tool/onnf_opt/onnf_opt.cpp @@ -0,0 +1,59 @@ +//===--------------------- onnf_opt.cpp - MLIR Operations -----------------===// +// +// Copyright 2019 The IBM Research Authors. +// +// ============================================================================= +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static llvm::cl::opt input_filename( + llvm::cl::Positional, llvm::cl::desc(""), llvm::cl::init("-")); + +static llvm::cl::opt output_filename("o", + llvm::cl::desc("Output filename"), llvm::cl::value_desc("filename"), + llvm::cl::init("-")); + +static llvm::cl::opt 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 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 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(); + + return failed(mlir::MlirOptMain(output->os(), std::move(file), passPipeline, + split_input_file, verify_diagnostics, verify_passes)); +}