Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
option only affects the tools that run on the host (the compiler), and has
no effect on the target libraries (the standard library and the runtime).")

option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
"When building ThinLTO using ld64 on Darwin, controls whether to opt out of
LLVM IR optimizations when linking targets that will get
little benefit from it (e.g. tools for bootstrapping or
debugging Swift)"
FALSE)

option(BOOTSTRAPPING_MODE [=[
How to build the swift compiler modules. Possible values are
OFF: build without swift modules
Expand Down
15 changes: 14 additions & 1 deletion cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ macro(add_swift_lib_subdirectory name)
endmacro()

function(add_swift_host_tool executable)
set(options HAS_SWIFT_MODULES)
set(options HAS_SWIFT_MODULES THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
set(single_parameter_options SWIFT_COMPONENT BOOTSTRAPPING)
set(multiple_parameter_options LLVM_LINK_COMPONENTS)

Expand Down Expand Up @@ -859,6 +859,19 @@ function(add_swift_host_tool executable)
endif()
endif()

if(ASHT_THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY)
string(CONCAT lto_codegen_only_link_options
"$<"
"$<AND:"
"$<BOOL:${LLVM_LINKER_IS_LD64}>,"
"$<BOOL:${SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS}>,"
"$<STREQUAL:${SWIFT_TOOLS_ENABLE_LTO},thin>"
">:"
"LINKER:-flto-codegen-only"
">")
target_link_options(${executable} PRIVATE "${lto_codegen_only_link_options}")
endif()

if(NOT ${ASHT_SWIFT_COMPONENT} STREQUAL "no_component")
add_dependencies(${ASHT_SWIFT_COMPONENT} ${executable})
swift_install_in_component(TARGETS ${executable}
Expand Down
2 changes: 2 additions & 0 deletions tools/driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
SWIFT_COMPONENT no_component
HAS_SWIFT_MODULES
BOOTSTRAPPING 0
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-frontend-bootstrapping0
PRIVATE
Expand All @@ -28,6 +29,7 @@ if(${BOOTSTRAPPING_MODE} MATCHES "BOOTSTRAPPING.*")
SWIFT_COMPONENT no_component
HAS_SWIFT_MODULES
BOOTSTRAPPING 1
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-frontend-bootstrapping1
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions tools/swift-ast-script/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_swift_host_tool(swift-ast-script
ASTScriptEvaluator.cpp
swift-ast-script.cpp
SWIFT_COMPONENT tools
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-ast-script
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions tools/swift-dependency-tool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_swift_host_tool(swift-dependency-tool
swift-dependency-tool.cpp
SWIFT_COMPONENT tools
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-dependency-tool
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions tools/swift-ide-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_swift_host_tool(swift-ide-test
ModuleAPIDiff.cpp
XMLValidator.cpp
SWIFT_COMPONENT tools
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-ide-test
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions tools/swift-remoteast-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_swift_host_tool(swift-remoteast-test
swift-remoteast-test.cpp
SWIFT_COMPONENT testsuite-tools
THINLTO_LD64_ADD_FLTO_CODEGEN_ONLY
)
target_link_libraries(swift-remoteast-test
PRIVATE
Expand Down
8 changes: 8 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,14 @@ def create_argument_parser():
help='the maximum number of parallel link jobs to use when '
'compiling swift tools.')

option('--swift-tools-ld64-lto-codegen-only-for-supporting-targets',
toggle_true,
default=False,
help='When building ThinLTO using ld64 on Darwin, controls whether '
'to opt out of LLVM IR optimizations when linking targets that '
'will get little benefit from it (e.g. tools for '
'bootstrapping or debugging Swift)')

option('--dsymutil-jobs', store_int,
default=defaults.DSYMUTIL_JOBS,
metavar='COUNT',
Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
'swift_freestanding_is_darwin': False,
'swift_stdlib_assertions': True,
'swift_stdlib_build_variant': 'Debug',
'swift_tools_ld64_lto_codegen_only_for_supporting_targets': False,
'swift_tools_max_parallel_lto_link_jobs':
defaults.SWIFT_MAX_PARALLEL_LTO_LINK_JOBS,
'swift_user_visible_version': defaults.SWIFT_USER_VISIBLE_VERSION,
Expand Down Expand Up @@ -714,6 +715,7 @@ class BuildScriptImplOption(_BaseOption):
IntOption('--jobs', dest='build_jobs'),
IntOption('--llvm-max-parallel-lto-link-jobs'),
IntOption('--swift-tools-max-parallel-lto-link-jobs'),
EnableOption('--swift-tools-ld64-lto-codegen-only-for-supporting-targets'),
IntOption('-j', dest='build_jobs'),
IntOption('--dsymutil-jobs', dest='dsymutil_jobs'),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):

self.cmake_options.extend(self._enable_stdlib_unicode_data)

self.cmake_options.extend(
self._swift_tools_ld64_lto_codegen_only_for_supporting_targets)

@classmethod
def is_build_script_impl_product(cls):
"""is_build_script_impl_product -> bool
Expand Down Expand Up @@ -184,6 +187,11 @@ def _build_swift_private_stdlib(self):
return [('SWIFT_STDLIB_BUILD_PRIVATE:BOOL',
self.args.build_swift_private_stdlib)]

@property
def _swift_tools_ld64_lto_codegen_only_for_supporting_targets(self):
return [('SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL',
self.args.swift_tools_ld64_lto_codegen_only_for_supporting_targets)]

@classmethod
def get_dependencies(cls):
return [cmark.CMark,
Expand Down
18 changes: 17 additions & 1 deletion utils/swift_build_support/tests/products/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def setUp(self):
build_swift_stdlib_static_print=False,
build_swift_stdlib_unicode_data=True,
swift_freestanding_is_darwin=False,
build_swift_private_stdlib=True)
build_swift_private_stdlib=True,
swift_tools_ld64_lto_codegen_only_for_supporting_targets=False)

# Setup shell
shell.dry_run = True
Expand Down Expand Up @@ -102,6 +103,7 @@ def test_by_default_no_cmake_options(self):
'-DSWIFT_FREESTANDING_IS_DARWIN:BOOL=FALSE',
'-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE',
'-DSWIFT_STDLIB_ENABLE_UNICODE_DATA=TRUE',
'-DSWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL=FALSE',
]
self.assertEqual(set(swift.cmake_options), set(expected))

Expand All @@ -124,6 +126,7 @@ def test_swift_runtime_tsan(self):
'-DSWIFT_FREESTANDING_IS_DARWIN:BOOL=FALSE',
'-DSWIFT_STDLIB_BUILD_PRIVATE:BOOL=TRUE',
'-DSWIFT_STDLIB_ENABLE_UNICODE_DATA=TRUE',
'-DSWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL=FALSE',
]
self.assertEqual(set(swift.cmake_options), set(flags_set))

Expand Down Expand Up @@ -388,3 +391,16 @@ def test_build_swift_private_stdlib_flags(self):
'FALSE'],
[x for x in swift.cmake_options
if 'SWIFT_STDLIB_BUILD_PRIVATE' in x])

def test_swift_tools_ld64_lto_codegen_only_for_supporting_targets(self):
self.args.swift_tools_ld64_lto_codegen_only_for_supporting_targets = True
swift = Swift(
args=self.args,
toolchain=self.toolchain,
source_dir='/path/to/src',
build_dir='/path/to/build')
self.assertEqual(
['-DSWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL='
'TRUE'],
[x for x in swift.cmake_options
if 'SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS' in x])