diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b6195d9a..cab9da054 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") option(GC_LEGACY_ENABLE ON) option(GC_TEST_ENABLE "Build the tests" ON) +option(GC_DEV_LINK_LLVM_DYLIB "Link dynamic libraries of LLVM and MLIR. For developers only. Do not use it in packing the library." OFF) if(GC_LEGACY_ENABLE) add_subdirectory(legacy/core) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 32cbdf052..675def341 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -94,3 +94,16 @@ function(gc_add_path list_name paths) CACHE INTERNAL "${list_name} paths" ) endfunction() + + +macro(gc_set_mlir_link_components VAR) + if(GC_DEV_LINK_LLVM_DYLIB) + set(${VAR} + MLIR + ) + else() + set(${VAR} + ${ARGN} + ) + endif() +endmacro() diff --git a/lib/gc/CMakeLists.txt b/lib/gc/CMakeLists.txt index f5ed3a6e5..fd78d6cab 100644 --- a/lib/gc/CMakeLists.txt +++ b/lib/gc/CMakeLists.txt @@ -2,5 +2,7 @@ if(GC_MLIR_CXX_FLAGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") endif() +include(functions) + add_subdirectory(Dialect) add_subdirectory(Transforms) \ No newline at end of file diff --git a/lib/gc/Dialect/Linalgx/CMakeLists.txt b/lib/gc/Dialect/Linalgx/CMakeLists.txt index 65957f316..d0daa2bcf 100644 --- a/lib/gc/Dialect/Linalgx/CMakeLists.txt +++ b/lib/gc/Dialect/Linalgx/CMakeLists.txt @@ -1,3 +1,5 @@ +gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) + add_mlir_dialect_library(MLIRLinalgx LinalgxDialect.cpp LinalgxOps.cpp @@ -9,5 +11,6 @@ add_mlir_dialect_library(MLIRLinalgx MLIRLinalgxOpsIncGen LINK_LIBS PUBLIC - MLIRIR -) \ No newline at end of file + ${MLIR_LINK_COMPONENTS} +) +set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIRLinalgx) \ No newline at end of file diff --git a/lib/gc/Dialect/Microkernel/CMakeLists.txt b/lib/gc/Dialect/Microkernel/CMakeLists.txt index e6d911a3b..a3eaa8d3d 100644 --- a/lib/gc/Dialect/Microkernel/CMakeLists.txt +++ b/lib/gc/Dialect/Microkernel/CMakeLists.txt @@ -1,3 +1,5 @@ +gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) + add_mlir_dialect_library(MLIRMicrokernel MicrokernelDialect.cpp MicrokernelOps.cpp @@ -9,5 +11,6 @@ add_mlir_dialect_library(MLIRMicrokernel MLIRMicrokernelOpsIncGen LINK_LIBS PUBLIC - MLIRIR -) \ No newline at end of file + ${MLIR_LINK_COMPONENTS} +) +set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIRMicrokernel) \ No newline at end of file diff --git a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt index 2dc50f1b7..a030820ee 100644 --- a/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt +++ b/lib/gc/Dialect/OneDNNGraph/CMakeLists.txt @@ -1,3 +1,4 @@ +gc_set_mlir_link_components(MLIR_LINK_COMPONENTS MLIRIR) add_mlir_dialect_library(MLIROneDNNGraph OneDNNGraphDialect.cpp OneDNNGraphOps.cpp @@ -9,5 +10,6 @@ add_mlir_dialect_library(MLIROneDNNGraph MLIROneDNNGraphOpsIncGen LINK_LIBS PUBLIC - MLIRIR -) \ No newline at end of file + ${MLIR_LINK_COMPONENTS} +) +set_property(GLOBAL APPEND PROPERTY GC_DIALECT_LIBS MLIROneDNNGraph) \ No newline at end of file diff --git a/lib/gc/Transforms/CMakeLists.txt b/lib/gc/Transforms/CMakeLists.txt index 1bcdf115c..e7e97ea26 100644 --- a/lib/gc/Transforms/CMakeLists.txt +++ b/lib/gc/Transforms/CMakeLists.txt @@ -1,3 +1,9 @@ +gc_set_mlir_link_components(MLIR_LINK_COMPONENTS + MLIRIR + MLIRSupport + MLIRBufferizationToMemRef + MLIRBufferizationPipelines) + add_mlir_library(GCPasses OneDNNGraphToLinalg.cpp TileNamed.cpp @@ -10,9 +16,7 @@ add_mlir_library(GCPasses LINK_LIBS PUBLIC ${mlir_dialect_libs} + ${MLIR_LINK_COMPONENTS} MLIROneDNNGraph - MLIRIR - MLIRSupport - MLIRBufferizationToMemRef - MLIRBufferizationPipelines ) +set_property(GLOBAL APPEND PROPERTY GC_PASS_LIBS GCPasses) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f6298c270..a1af4a91a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,3 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) -get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) - add_subdirectory(dnnl) add_subdirectory(gc-cpu-runner) add_subdirectory(gc-opt) diff --git a/src/gc-cpu-runner/CMakeLists.txt b/src/gc-cpu-runner/CMakeLists.txt index eb45c93b0..f3f768612 100644 --- a/src/gc-cpu-runner/CMakeLists.txt +++ b/src/gc-cpu-runner/CMakeLists.txt @@ -1,23 +1,34 @@ -# the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream -set(LLVM_LINK_COMPONENTS - Core - Support - nativecodegen - native -) -set(MLIR_LINK_COMPONENTS - MLIRAnalysis - MLIRBuiltinToLLVMIRTranslation - MLIRExecutionEngine - MLIRIR - MLIRJitRunner - MLIRLLVMDialect - MLIRLLVMToLLVMIRTranslation - MLIRToLLVMIRTranslationRegistration - MLIRParser - MLIRTargetLLVMIRExport - MLIRSupport -) +if(GC_DEV_LINK_LLVM_DYLIB) + set(LLVM_LINK_COMPONENTS + LLVM + ) + set(MLIR_LINK_COMPONENTS + MLIR + MLIRExecutionEngineShared + MLIRJitRunner + ) +else() + # the dependency list copied from mlir/tools/mlir-cpu-runner/CMakeLists.txt of upstream + set(LLVM_LINK_COMPONENTS + Core + Support + nativecodegen + native + ) + set(MLIR_LINK_COMPONENTS + MLIRAnalysis + MLIRBuiltinToLLVMIRTranslation + MLIRExecutionEngine + MLIRIR + MLIRJitRunner + MLIRLLVMDialect + MLIRLLVMToLLVMIRTranslation + MLIRToLLVMIRTranslationRegistration + MLIRParser + MLIRTargetLLVMIRExport + MLIRSupport + ) +endif() if(GC_MLIR_CXX_FLAGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") @@ -26,8 +37,10 @@ endif() #LLVM_LINK_COMPONENTS is processed by LLVM cmake in add_llvm_executable set(gc_cpu_runner_libs ${MLIR_LINK_COMPONENTS}) -add_llvm_executable(gc-cpu-runner gc-cpu-runner.cpp) +add_mlir_tool(gc-cpu-runner + gc-cpu-runner.cpp +) +llvm_update_compile_flags(gc-cpu-runner) target_link_libraries(gc-cpu-runner PRIVATE ${gc_cpu_runner_libs}) -llvm_update_compile_flags(gc-cpu-runner) mlir_check_all_link_libraries(gc-cpu-runner) diff --git a/src/gc-opt/CMakeLists.txt b/src/gc-opt/CMakeLists.txt index ff33375de..2a0ba0d7a 100644 --- a/src/gc-opt/CMakeLists.txt +++ b/src/gc-opt/CMakeLists.txt @@ -1,8 +1,23 @@ +if(GC_DEV_LINK_LLVM_DYLIB) + set(MLIR_LINK_COMPONENTS + MLIR + ) + get_property(dialect_libs GLOBAL PROPERTY GC_DIALECT_LIBS) + get_property(conversion_libs GLOBAL PROPERTY GC_PASS_LIBS) +else() + set(MLIR_LINK_COMPONENTS + MLIROptLib + ) + get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) + get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS) +endif() + set(gc_opt_libs ${dialect_libs} ${conversion_libs} - MLIROptLib + ${MLIR_LINK_COMPONENTS} GCPasses) + if(GC_MLIR_CXX_FLAGS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_MLIR_CXX_FLAGS}") endif()