diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -852,27 +852,33 @@ # If option LLVM_${name_upper}_LINK_INTO_TOOLS is set to ON, the plugin is registered statically. # Otherwise a pluggable shared library is registered. function(add_llvm_pass_plugin name) + cmake_parse_arguments(ARG + "NO_MODULE" "" "" + ${ARGN}) string(TOUPPER ${name} name_upper) option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" OFF) - # process_llvm_pass_plugins takes care of the actual linking, just create an - # object library as of now - add_llvm_library(${name} OBJECT ${ARGN}) - - if(LLVM_${name_upper}_LINK_INTO_TOOLS) - target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS) - set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS) - if (TARGET intrinsics_gen) - add_dependencies(obj.${name} intrinsics_gen) - endif() - endif() - - message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})") if(LLVM_${name_upper}_LINK_INTO_TOOLS) + # In a static build, BUILDTREE_ONLY is irrelevant + list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS BUILDTREE_ONLY) + # process_llvm_pass_plugins takes care of the actual linking, just create an + # object library as of now + add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS}) + target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS) + set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS) + if (TARGET intrinsics_gen) + add_dependencies(obj.${name} intrinsics_gen) + endif() + message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})") set_property(GLOBAL APPEND PROPERTY LLVM_COMPILE_EXTENSIONS ${name}) + elseif(NOT ARG_NO_MODULE) + add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS}) + else() + add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS}) endif() + endfunction(add_llvm_pass_plugin) # Generate X Macro file for extension handling. It provides a @@ -893,15 +899,12 @@ string(CONCAT llvm_extension_project ${llvm_extension_upper_first} ${llvm_extension_lower_tail}) if(LLVM_${llvm_extension_upper}_LINK_INTO_TOOLS) - file(APPEND "${CMAKE_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n") - - get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS) - foreach(llvm_plugin_target ${llvm_plugin_targets}) - set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) - set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) - endforeach() - else() - add_llvm_library(${llvm_extension_lower} MODULE obj.${llvm_extension_lower}) + file(APPEND "${CMAKE_BINARY_DIR}/include/llvm/Support/Extension.def.tmp" "HANDLE_EXTENSION(${llvm_extension_project})\n") + get_property(llvm_plugin_targets GLOBAL PROPERTY LLVM_PLUGIN_TARGETS) + foreach(llvm_plugin_target ${llvm_plugin_targets}) + set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY LINK_LIBRARIES ${llvm_extension}) + set_property(TARGET ${llvm_plugin_target} APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${llvm_extension}) + endforeach() endif() endforeach() diff --git a/llvm/docs/WritingAnLLVMPass.rst b/llvm/docs/WritingAnLLVMPass.rst --- a/llvm/docs/WritingAnLLVMPass.rst +++ b/llvm/docs/WritingAnLLVMPass.rst @@ -1180,8 +1180,8 @@ As an alternative to using ``PLUGIN_TOOL``, LLVM provides a mechanism to automatically register pass plugins within ``clang``, ``opt`` and ``bugpoint``. -One first needs to create an independent project and add it to either ``tools/`` -or, using the MonoRepo layout, at the root of the repo alongside other projects. +One first needs to create an independent project and add it at the root of the +repo alongside other projects. This project must contain the following minimal ``CMakeLists.txt``: .. code-block:: cmake diff --git a/llvm/examples/Bye/CMakeLists.txt b/llvm/examples/Bye/CMakeLists.txt --- a/llvm/examples/Bye/CMakeLists.txt +++ b/llvm/examples/Bye/CMakeLists.txt @@ -1,23 +1,25 @@ -add_llvm_pass_plugin(Bye +if(LLVM_BUILD_EXAMPLES) + add_llvm_pass_plugin(Bye Bye.cpp DEPENDS intrinsics_gen BUILDTREE_ONLY - ) + ) -if (LLVM_LINK_LLVM_DYLIB) - target_link_libraries(Bye PUBLIC LLVM) -else() - target_link_libraries(Bye - PUBLIC - LLVMSupport - LLVMCore - LLVMipo - LLVMPasses - ) -endif() + if(LLVM_BYE_LINK_INTO_TOOLS) + if (LLVM_LINK_LLVM_DYLIB) + target_link_libraries(Bye PUBLIC LLVM) + else() + target_link_libraries(Bye + PUBLIC + LLVMSupport + LLVMCore + LLVMipo + LLVMPasses + ) + endif() + endif() -if( LLVM_BUILD_EXAMPLES ) install(TARGETS ${name} RUNTIME DESTINATION examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") endif() -set_target_properties(${name} PROPERTIES FOLDER "Examples") diff --git a/llvm/test/Feature/load_extension.ll b/llvm/test/Feature/load_extension.ll --- a/llvm/test/Feature/load_extension.ll +++ b/llvm/test/Feature/load_extension.ll @@ -1,6 +1,3 @@ -; This fails at least on macOS. -; XFAIL: darwin - ; RUN: opt %s %loadbye -goodbye -wave-goodbye -disable-output 2>&1 | FileCheck %s ; REQUIRES: plugins, examples ; CHECK: Bye diff --git a/llvm/test/lit.cfg.py b/llvm/test/lit.cfg.py --- a/llvm/test/lit.cfg.py +++ b/llvm/test/lit.cfg.py @@ -206,7 +206,7 @@ else: config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT')) config.substitutions.append(('%loadbye', - '-load={}/libBye{}'.format(config.llvm_shlib_dir, + '-load={}/Bye{}'.format(config.llvm_shlib_dir, config.llvm_shlib_ext))) # Static libraries are not built if BUILD_SHARED_LIBS is ON. diff --git a/polly/lib/CMakeLists.txt b/polly/lib/CMakeLists.txt --- a/polly/lib/CMakeLists.txt +++ b/polly/lib/CMakeLists.txt @@ -24,6 +24,7 @@ # Use an object-library to add the same files to multiple libs without requiring # the sources them to be recompiled for each of them. add_llvm_pass_plugin(Polly + NO_MODULE Analysis/DependenceInfo.cpp Analysis/PolyhedralInfo.cpp Analysis/ScopDetection.cpp