Skip to content

Commit 346de9b

Browse files
author
serge-sans-paille
committed
Fix several issues with compiler extensions
- Update documentation now that the move to monorepo has been made - Do not tie compiler extension testing to LLVM_BUILD_EXAMPLES - No need to specify LLVM libraries for plugins - Add NO_MODULE option to match Polly specific requirements (i.e. building the module *and* linking it statically) - Issue a warning when building the compiler extension with LLVM_BYE_LINK_INTO_TOOLS=ON, as it modifies the behavior of clang, which only makes sense for testing purpose. Still mark llvm/test/Feature/load_extension.ll as XFAIL because of a ManagedStatic dependency that's going to be fixed in a seperate commit. Differential Revision: https://reviews.llvm.org/D72327
1 parent abfa27e commit 346de9b

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -847,32 +847,40 @@ macro(add_llvm_executable name)
847847
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
848848
endmacro(add_llvm_executable name)
849849

850-
# add_llvm_pass_plugin(name)
850+
# add_llvm_pass_plugin(name [NO_MODULE] ...)
851851
# Add ${name} as an llvm plugin.
852852
# If option LLVM_${name_upper}_LINK_INTO_TOOLS is set to ON, the plugin is registered statically.
853853
# Otherwise a pluggable shared library is registered.
854+
#
855+
# If NO_MODULE is specified, when option LLVM_${name_upper}_LINK_INTO_TOOLS is set to OFF,
856+
# only an object library is built, and no module is built. This is specific to the Polly use case.
854857
function(add_llvm_pass_plugin name)
858+
cmake_parse_arguments(ARG
859+
"NO_MODULE" "" ""
860+
${ARGN})
855861

856862
string(TOUPPER ${name} name_upper)
857863

858864
option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" OFF)
859865

860-
# process_llvm_pass_plugins takes care of the actual linking, just create an
861-
# object library as of now
862-
add_llvm_library(${name} OBJECT ${ARGN})
863-
864-
if(LLVM_${name_upper}_LINK_INTO_TOOLS)
865-
target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS)
866-
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS)
867-
if (TARGET intrinsics_gen)
868-
add_dependencies(obj.${name} intrinsics_gen)
869-
endif()
870-
endif()
871-
872-
message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
873866
if(LLVM_${name_upper}_LINK_INTO_TOOLS)
867+
list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS BUILDTREE_ONLY)
868+
# process_llvm_pass_plugins takes care of the actual linking, just create an
869+
# object library as of now
870+
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
871+
target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS)
872+
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS)
873+
if (TARGET intrinsics_gen)
874+
add_dependencies(obj.${name} intrinsics_gen)
875+
endif()
876+
message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
874877
set_property(GLOBAL APPEND PROPERTY LLVM_COMPILE_EXTENSIONS ${name})
878+
elseif(NOT ARG_NO_MODULE)
879+
add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
880+
else()
881+
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
875882
endif()
883+
876884
endfunction(add_llvm_pass_plugin)
877885

878886
# Generate X Macro file for extension handling. It provides a

llvm/examples/Bye/CMakeLists.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
add_llvm_pass_plugin(Bye
2-
Bye.cpp
3-
DEPENDS
4-
intrinsics_gen
5-
BUILDTREE_ONLY
6-
)
7-
8-
if (LLVM_LINK_LLVM_DYLIB)
9-
target_link_libraries(Bye PUBLIC LLVM)
10-
else()
11-
target_link_libraries(Bye
12-
PUBLIC
13-
LLVMSupport
14-
LLVMCore
15-
LLVMipo
16-
LLVMPasses
17-
)
1+
if(LLVM_BYE_LINK_INTO_TOOLS)
2+
message(WARNING "Setting LLVM_BYE_LINK_INTO_TOOLS=ON only makes sense for testing purpose")
183
endif()
194

20-
if( LLVM_BUILD_EXAMPLES )
21-
install(TARGETS ${name} RUNTIME DESTINATION examples)
22-
endif()
5+
add_llvm_pass_plugin(Bye
6+
Bye.cpp
7+
DEPENDS
8+
intrinsics_gen
9+
BUILDTREE_ONLY
10+
)
11+
12+
install(TARGETS ${name} RUNTIME DESTINATION examples)
2313
set_target_properties(${name} PROPERTIES FOLDER "Examples")

llvm/test/lit.cfg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ def get_asan_rtlib():
200200
if config.build_examples:
201201
config.available_features.add('examples')
202202

203-
if config.linked_bye_extension and config.build_examples:
203+
if config.linked_bye_extension:
204204
config.substitutions.append(('%llvmcheckext', 'CHECK-EXT'))
205205
config.substitutions.append(('%loadbye', ''))
206206
else:
207207
config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT'))
208208
config.substitutions.append(('%loadbye',
209-
'-load={}/libBye{}'.format(config.llvm_shlib_dir,
209+
'-load={}/Bye{}'.format(config.llvm_shlib_dir,
210210
config.llvm_shlib_ext)))
211211

212212
# Static libraries are not built if BUILD_SHARED_LIBS is ON.

polly/lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ endif ()
2424
# Use an object-library to add the same files to multiple libs without requiring
2525
# the sources them to be recompiled for each of them.
2626
add_llvm_pass_plugin(Polly
27+
NO_MODULE
2728
Analysis/DependenceInfo.cpp
2829
Analysis/PolyhedralInfo.cpp
2930
Analysis/ScopDetection.cpp

0 commit comments

Comments
 (0)