From 19196f23e1c4f9f4e1609630ef8e77f64669e714 Mon Sep 17 00:00:00 2001 From: Stella Laurenzo Date: Thu, 11 Jun 2020 17:47:14 -0700 Subject: [PATCH] Make a real library for InitAll and extend it to conditionally initialize dependencies. * Conditioned on the top level CMake option to enable IREE. * There is still some warning flags and such that need triage, but it does build/work. --- CMakeLists.txt | 5 +- include/npcomp/InitAll.h | 40 +-------------- lib/CMakeLists.txt | 34 ++++++++++++ lib/InitAll.cpp | 77 ++++++++++++++++++++++++++++ python_native/CMakeLists.txt | 10 +--- tools/npcomp-opt/CMakeLists.txt | 10 +--- tools/npcomp-run-mlir/CMakeLists.txt | 2 +- 7 files changed, 121 insertions(+), 57 deletions(-) create mode 100644 lib/InitAll.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 40ed6c081..567095475 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ add_definitions(${LLVM_DEFINITIONS}) # IREE configuration #------------------------------------------------------------------------------- -if(${NPCOMP_ENABLE_IREE}) +if(NPCOMP_ENABLE_IREE) add_compile_definitions(NPCOMP_ENABLE_IREE) if(NPCOMP_IREE_SRCDIR) message(STATUS "Depending on IREE source: ${NPCOMP_IREE_SRCDIR}") @@ -63,6 +63,9 @@ if(${NPCOMP_ENABLE_IREE}) else() find_package(IREE REQUIRED CONFIG) endif() + + message(STATUS "IREE INCLUDE DIRS: ${IREE_PUBLIC_INCLUDE_DIRS}") + include_directories("${IREE_PUBLIC_INCLUDE_DIRS}") endif() #------------------------------------------------------------------------------- diff --git a/include/npcomp/InitAll.h b/include/npcomp/InitAll.h index ce9238b50..00a4fbd39 100644 --- a/include/npcomp/InitAll.h +++ b/include/npcomp/InitAll.h @@ -9,48 +9,12 @@ #ifndef NPCOMP_INITALL_H #define NPCOMP_INITALL_H -#include "npcomp/Dialect/Basicpy/IR/BasicpyDialect.h" -#include "npcomp/Dialect/Basicpy/Transforms/Passes.h" -#include "npcomp/Dialect/NpcompRt/IR/NpcompRtDialect.h" -#include "npcomp/Dialect/Numpy/IR/NumpyDialect.h" -#include "npcomp/Dialect/TCF/IR/TCFDialect.h" -#include "npcomp/Dialect/TCP/IR/TCPDialect.h" - -#include "npcomp/Conversion/TCFToTCP/TCFToTCP.h" -#include "npcomp/Conversion/TCPToLinalg/TCPToLinalg.h" -#include "npcomp/E2E/E2E.h" - - namespace mlir { namespace NPCOMP { -inline void registerAllDialects() { - registerDialect(); - registerDialect(); - registerDialect(); - registerDialect(); - registerDialect(); -} +void registerAllDialects(); +void registerAllPasses(); -inline void registerAllPasses() { - using mlir::Pass; // The .inc files reference this unqualified. -#define GEN_PASS_REGISTRATION -#include "npcomp/E2E/Passes.h.inc" - // TODO: The following pipeline registration uses pass manager options, - // which causes vague linkage issues when co-mingled with code that - // uses RTTI. - mlir::PassPipelineRegistration( - "e2e-lowering-pipeline", "E2E lowering pipeline.", - mlir::NPCOMP::createE2ELoweringPipeline); - mlir::PassPipelineRegistration<>( - "lower-to-hybrid-tensor-memref-pipeline", - "Pipeline lowering to hybrid tensor/memref.", - mlir::NPCOMP::createLowerToHybridTensorMemRefPipeline); -#define GEN_PASS_REGISTRATION -#include "npcomp/Conversion/Passes.h.inc" -#define GEN_PASS_REGISTRATION -#include "npcomp/Dialect/Basicpy/Transforms/Passes.h.inc" -} } // namespace NPCOMP } // namespace mlir diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 064d7d470..c87b7745c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,3 +1,37 @@ add_subdirectory(Conversion) add_subdirectory(Dialect) add_subdirectory(E2E) + +################################################################################ +# Setup the initialization target. +# This includes conditional dependencies based on whether features are enabled. +################################################################################ + +set(ALL_DEPENDS) +if(NPCOMP_ENABLE_IREE) + list(APPEND ALL_DEPENDS + iree_tools_init_compiler_modules + iree_tools_init_iree_passes_and_dialects + iree_tools_init_mlir_passes_and_dialects + iree_tools_init_targets + iree_tools_init_xla_dialects + ) +endif() + +add_mlir_library(NPCOMPInitAll + InitAll.cpp + + LINK_LIBS + + PRIVATE + # Local depends + NPCOMPE2E + NPCOMPTCP + NPCOMPTCF + NPCOMPNpcompRt + NPCOMPBasicpyDialect + NPCOMPBasicpyPasses + NPCOMPNumpyDialect + + ${ALL_DEPENDS} +) diff --git a/lib/InitAll.cpp b/lib/InitAll.cpp new file mode 100644 index 000000000..0a5f3a8ab --- /dev/null +++ b/lib/InitAll.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// This file is licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "npcomp/InitAll.h" + +#include "npcomp/Dialect/Basicpy/IR/BasicpyDialect.h" +#include "npcomp/Dialect/Basicpy/Transforms/Passes.h" +#include "npcomp/Dialect/NpcompRt/IR/NpcompRtDialect.h" +#include "npcomp/Dialect/Numpy/IR/NumpyDialect.h" +#include "npcomp/Dialect/TCF/IR/TCFDialect.h" +#include "npcomp/Dialect/TCP/IR/TCPDialect.h" + +#include "npcomp/Conversion/TCFToTCP/TCFToTCP.h" +#include "npcomp/Conversion/TCPToLinalg/TCPToLinalg.h" +#include "npcomp/E2E/E2E.h" + +#ifdef NPCOMP_ENABLE_IREE +#include "iree/tools/init_compiler_modules.h" +#include "iree/tools/init_iree_dialects.h" +#include "iree/tools/init_iree_passes.h" +#include "iree/tools/init_mlir_dialects.h" +#include "iree/tools/init_mlir_passes.h" +#include "iree/tools/init_targets.h" +#include "iree/tools/init_xla_dialects.h" +#endif // NPCOMP_ENABLE_IREE + +static void registerDependencyDialects() { +#ifdef NPCOMP_ENABLE_IREE + // TODO: We should probably be registering the MLIR dialects regardless + // of building with IREE, but we have to do it with IREE, and the + // dependencies are coming from there and wouldn't be great to duplicate. + // See iree/tools:init_mlir_passes_and_dialects + mlir::registerMlirDialects(); + mlir::registerXLADialects(); + mlir::iree_compiler::registerIreeDialects(); + mlir::iree_compiler::registerIreeCompilerModuleDialects(); +#endif // NPCOMP_ENABLE_IREE +} + +static void registerDependencyPasses() { + +} + +void mlir::NPCOMP::registerAllDialects() { + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDialect(); + registerDependencyDialects(); +} + +void mlir::NPCOMP::registerAllPasses() { + using mlir::Pass; // The .inc files reference this unqualified. +#define GEN_PASS_REGISTRATION +#include "npcomp/E2E/Passes.h.inc" + // TODO: The following pipeline registration uses pass manager options, + // which causes vague linkage issues when co-mingled with code that + // uses RTTI. + mlir::PassPipelineRegistration( + "e2e-lowering-pipeline", "E2E lowering pipeline.", + mlir::NPCOMP::createE2ELoweringPipeline); + mlir::PassPipelineRegistration<>( + "lower-to-hybrid-tensor-memref-pipeline", + "Pipeline lowering to hybrid tensor/memref.", + mlir::NPCOMP::createLowerToHybridTensorMemRefPipeline); +#define GEN_PASS_REGISTRATION +#include "npcomp/Conversion/Passes.h.inc" +#define GEN_PASS_REGISTRATION +#include "npcomp/Dialect/Basicpy/Transforms/Passes.h.inc" + registerDependencyPasses(); +} diff --git a/python_native/CMakeLists.txt b/python_native/CMakeLists.txt index b3d08bae7..aaf11f99d 100644 --- a/python_native/CMakeLists.txt +++ b/python_native/CMakeLists.txt @@ -71,15 +71,7 @@ target_link_libraries(${extension_target} ${conversion_libs} pybind11::module - # Local depends - # Note: These need to also match tools/npcomp-opt/CMakeLists.txt - NPCOMPE2E - NPCOMPTCP - NPCOMPTCF - NPCOMPNpcompRt - NPCOMPBasicpyDialect - NPCOMPBasicpyPasses - NPCOMPNumpyDialect + NPCOMPInitAll # Core dialects MLIRSCF diff --git a/tools/npcomp-opt/CMakeLists.txt b/tools/npcomp-opt/CMakeLists.txt index 76dac165b..c094e0b5d 100644 --- a/tools/npcomp-opt/CMakeLists.txt +++ b/tools/npcomp-opt/CMakeLists.txt @@ -4,14 +4,8 @@ set(LIBS ${dialect_libs} ${conversion_libs} MLIROptLib - # Note: the following must also match python_native/CMakeLists.txt - NPCOMPE2E - NPCOMPTCP - NPCOMPTCF - NPCOMPNpcompRt - NPCOMPNumpyDialect - NPCOMPBasicpyDialect - ) + NPCOMPInitAll +) add_llvm_executable(npcomp-opt npcomp-opt.cpp) llvm_update_compile_flags(npcomp-opt) diff --git a/tools/npcomp-run-mlir/CMakeLists.txt b/tools/npcomp-run-mlir/CMakeLists.txt index 01c79aacb..347f7ebce 100644 --- a/tools/npcomp-run-mlir/CMakeLists.txt +++ b/tools/npcomp-run-mlir/CMakeLists.txt @@ -22,5 +22,5 @@ target_link_libraries(npcomp-run-mlir PRIVATE MLIRParser MLIRTargetLLVMIR MLIRSupport - NPCOMPE2E + NPCOMPInitAll )