Skip to content

Commit b0dd5f1

Browse files
authored
Merge pull request #41 from apple/master
[pull] swiftwasm from apple:master
2 parents f257acf + efa526e commit b0dd5f1

File tree

10 files changed

+87
-90
lines changed

10 files changed

+87
-90
lines changed

Diff for: cmake/modules/AddSwift.cmake

+37-60
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,6 @@ function(_add_swift_lipo_target)
708708
endif()
709709
endfunction()
710710

711-
function(swift_target_link_search_directories target directories)
712-
set(STLD_FLAGS "")
713-
foreach(directory ${directories})
714-
set(STLD_FLAGS "${STLD_FLAGS} \"${CMAKE_LIBRARY_PATH_FLAG}${directory}\"")
715-
endforeach()
716-
set_property(TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS ${STLD_FLAGS})
717-
endfunction()
718-
719711
# Add a single variant of a new Swift library.
720712
#
721713
# Usage:
@@ -892,22 +884,10 @@ function(_add_swift_library_single target name)
892884
if(SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
893885
if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "IOS" OR "${SWIFTLIB_SINGLE_SDK}" STREQUAL "TVOS" OR "${SWIFTLIB_SINGLE_SDK}" STREQUAL "WATCHOS")
894886
list(APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS "-fembed-bitcode")
895-
list(APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-bitcode_bundle" "-Xlinker" "-lto_library" "-Xlinker" "${LLVM_LIBRARY_DIR}/libLTO.dylib")
896-
# If we are asked to hide symbols, pass the obfuscation flag to libLTO.
897-
if (SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS)
898-
list(APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-bitcode_hide_symbols")
899-
endif()
900887
set(embed_bitcode_arg EMBED_BITCODE)
901888
endif()
902889
endif()
903890

904-
if(${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
905-
list(APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-compatibility_version" "-Xlinker" "1")
906-
if (SWIFT_COMPILER_VERSION)
907-
list(APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-current_version" "-Xlinker" "${SWIFT_COMPILER_VERSION}" )
908-
endif()
909-
endif()
910-
911891
if(XCODE)
912892
string(REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR})
913893
list(GET split_path -1 dir)
@@ -1281,23 +1261,6 @@ function(_add_swift_library_single target name)
12811261
"${swift_module_dependency_target}"
12821262
${LLVM_COMMON_DEPENDS})
12831263

1284-
# HACK: On some systems or build directory setups, CMake will not find static
1285-
# archives of Clang libraries in the Clang build directory, and it will pass
1286-
# them as '-lclangFoo'. Some other logic in CMake would reorder libraries
1287-
# specified with this syntax, which breaks linking.
1288-
set(prefixed_link_libraries)
1289-
foreach(dep ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
1290-
if("${dep}" MATCHES "^clang")
1291-
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS")
1292-
set(dep "${LLVM_LIBRARY_OUTPUT_INTDIR}/${dep}.lib")
1293-
else()
1294-
set(dep "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${dep}.a")
1295-
endif()
1296-
endif()
1297-
list(APPEND prefixed_link_libraries "${dep}")
1298-
endforeach()
1299-
set(SWIFTLIB_SINGLE_LINK_LIBRARIES "${prefixed_link_libraries}")
1300-
13011264
if("${libkind}" STREQUAL "SHARED")
13021265
target_link_libraries("${target}" PRIVATE ${SWIFTLIB_SINGLE_LINK_LIBRARIES})
13031266
elseif("${libkind}" STREQUAL "OBJECT")
@@ -1463,17 +1426,32 @@ function(_add_swift_library_single target name)
14631426
set(PLIST_INFO_BUILD_VERSION)
14641427
endif()
14651428

1466-
# Convert variables to space-separated strings.
1467-
_list_escape_for_shell("${c_compile_flags}" c_compile_flags)
1468-
_list_escape_for_shell("${link_flags}" link_flags)
1469-
14701429
# Set compilation and link flags.
1471-
set_property(TARGET "${target}" APPEND_STRING PROPERTY
1472-
COMPILE_FLAGS " ${c_compile_flags}")
1473-
set_property(TARGET "${target}" APPEND_STRING PROPERTY
1474-
LINK_FLAGS " ${link_flags}")
1475-
set_property(TARGET "${target}" APPEND PROPERTY LINK_LIBRARIES ${link_libraries})
1476-
swift_target_link_search_directories("${target}" "${library_search_directories}")
1430+
target_compile_options(${target} PRIVATE
1431+
${c_compile_flags})
1432+
target_link_options(${target} PRIVATE
1433+
${link_flags})
1434+
if(${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
1435+
target_link_options(${target} PRIVATE
1436+
"LINKER:-compatibility_version,1")
1437+
if(SWIFT_COMPILER_VERSION)
1438+
target_link_options(${target} PRIVATE
1439+
"LINKER:-current_version,${SWIFT_COMPILER_VERSION}")
1440+
endif()
1441+
# Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
1442+
if(SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
1443+
if(${SWIFTLIB_SINGLE_SDK} MATCHES "(I|TV|WATCH)OS")
1444+
target_link_options(${target} PRIVATE
1445+
"LINKER:-bitcode_bundle"
1446+
$<$<BOOL:SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS>:"LINKER:-bitcode_hide_symbols">
1447+
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
1448+
endif()
1449+
endif()
1450+
endif()
1451+
target_link_libraries(${target} PRIVATE
1452+
${link_libraries})
1453+
target_link_directories(${target} PRIVATE
1454+
${library_search_directories})
14771455

14781456
# Adjust the linked libraries for windows targets. On Windows, the link is
14791457
# performed against the import library, and the runtime uses the dll. Not
@@ -1523,8 +1501,8 @@ function(_add_swift_library_single target name)
15231501
endif()
15241502

15251503
if(target_static)
1526-
set_property(TARGET "${target_static}" APPEND_STRING PROPERTY
1527-
COMPILE_FLAGS " ${c_compile_flags}")
1504+
target_link_options(${target_static} PRIVATE
1505+
${c_compile_flags})
15281506
# FIXME: The fallback paths here are going to be dynamic libraries.
15291507

15301508
if(SWIFTLIB_INSTALL_WITH_SHARED)
@@ -1536,7 +1514,8 @@ function(_add_swift_library_single target name)
15361514
"${search_base_dir}/${SWIFTLIB_SINGLE_SUBDIR}"
15371515
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFTLIB_SINGLE_SUBDIR}"
15381516
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH}/../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_LIB_SUBDIR}")
1539-
swift_target_link_search_directories("${target_static}" "${library_search_directories}")
1517+
target_link_directories(${target_static} PRIVATE
1518+
${library_search_directories})
15401519
target_link_libraries("${target_static}" PRIVATE
15411520
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES})
15421521
endif()
@@ -2637,16 +2616,14 @@ function(_add_swift_executable_single name)
26372616
${SWIFTEXE_SINGLE_DEPENDS})
26382617
llvm_update_compile_flags("${name}")
26392618

2640-
# Convert variables to space-separated strings.
2641-
_list_escape_for_shell("${c_compile_flags}" c_compile_flags)
2642-
_list_escape_for_shell("${link_flags}" link_flags)
2643-
2644-
set_property(TARGET ${name} APPEND_STRING PROPERTY
2645-
COMPILE_FLAGS " ${c_compile_flags}")
2646-
swift_target_link_search_directories("${name}" "${library_search_directories}")
2647-
set_property(TARGET ${name} APPEND_STRING PROPERTY
2648-
LINK_FLAGS " ${link_flags}")
2649-
set_property(TARGET ${name} APPEND PROPERTY LINK_LIBRARIES ${link_libraries})
2619+
target_compile_options(${name} PRIVATE
2620+
${c_compile_flags})
2621+
target_link_directories(${name} PRIVATE
2622+
${library_search_directories})
2623+
target_link_options(${name} PRIVATE
2624+
${link_flags})
2625+
target_link_libraries(${name} PRIVATE
2626+
${link_libraries})
26502627
if (SWIFT_PARALLEL_LINK_JOBS)
26512628
set_property(TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool)
26522629
endif()

Diff for: cmake/modules/SwiftList.cmake

-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ function(_list_add_string_suffix input_list suffix result_var_name)
3838
set("${result_var_name}" "${result}" PARENT_SCOPE)
3939
endfunction()
4040

41-
function(_list_escape_for_shell input_list result_var_name)
42-
set(result "")
43-
foreach(element ${input_list})
44-
string(REPLACE " " "\\ " element "${element}")
45-
set(result "${result}${element} ")
46-
endforeach()
47-
set("${result_var_name}" "${result}" PARENT_SCOPE)
48-
endfunction()
49-
5041
function(list_replace input_list old new)
5142
set(replaced_list)
5243
foreach(item ${${input_list}})

Diff for: include/swift/SILOptimizer/PassManager/Passes.def

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ PASS(LICM, "licm",
200200
"Loop Invariant Code Motion")
201201
PASS(LateCodeMotion, "late-codemotion",
202202
"Late Code Motion with Release Hoisting")
203+
PASS(LateDeadFunctionElimination, "late-deadfuncelim",
204+
"Late Dead Function Elimination")
203205
PASS(LateInliner, "late-inline",
204206
"Late Function Inlining")
205207
PASS(LoopCanonicalizer, "loop-canonicalizer",

Diff for: lib/SILOptimizer/IPO/DeadFunctionElimination.cpp

+27-6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class FunctionLivenessComputation {
9090

9191
llvm::SmallPtrSet<void *, 32> AliveFunctionsAndTables;
9292

93+
bool keepExternalWitnessTablesAlive;
94+
9395
/// Checks is a function is alive, e.g. because it is visible externally.
9496
bool isAnchorFunction(SILFunction *F) {
9597

@@ -148,6 +150,11 @@ class FunctionLivenessComputation {
148150
/// Marks all contained functions and witness tables of a witness table as
149151
/// alive.
150152
void makeAlive(SILWitnessTable *WT) {
153+
if (isAvailableExternally(WT->getLinkage()) &&
154+
!keepExternalWitnessTablesAlive) {
155+
return;
156+
}
157+
151158
LLVM_DEBUG(llvm::dbgs() << " scan witness table " << WT->getName()
152159
<< '\n');
153160

@@ -393,8 +400,10 @@ class FunctionLivenessComputation {
393400
}
394401

395402
public:
396-
FunctionLivenessComputation(SILModule *module) :
397-
Module(module) {}
403+
FunctionLivenessComputation(SILModule *module,
404+
bool keepExternalWitnessTablesAlive) :
405+
Module(module),
406+
keepExternalWitnessTablesAlive(keepExternalWitnessTablesAlive) {}
398407

399408
/// The main entry point of the optimization.
400409
bool findAliveFunctions() {
@@ -635,8 +644,8 @@ class DeadFunctionElimination : FunctionLivenessComputation {
635644
}
636645

637646
public:
638-
DeadFunctionElimination(SILModule *module)
639-
: FunctionLivenessComputation(module) {}
647+
DeadFunctionElimination(SILModule *module, bool keepExternalWitnessTablesAlive)
648+
: FunctionLivenessComputation(module, keepExternalWitnessTablesAlive) {}
640649

641650
/// The main entry point of the optimization.
642651
void eliminateFunctions(SILModuleTransform *DFEPass) {
@@ -693,6 +702,13 @@ class DeadFunctionElimination : FunctionLivenessComputation {
693702
namespace {
694703

695704
class SILDeadFuncElimination : public SILModuleTransform {
705+
706+
private:
707+
bool isLateDFE;
708+
709+
public:
710+
SILDeadFuncElimination(bool isLateDFE) : isLateDFE(isLateDFE) { }
711+
696712
void run() override {
697713
LLVM_DEBUG(llvm::dbgs() << "Running DeadFuncElimination\n");
698714

@@ -703,15 +719,20 @@ class SILDeadFuncElimination : public SILModuleTransform {
703719
// can eliminate such functions.
704720
getModule()->invalidateSILLoaderCaches();
705721

706-
DeadFunctionElimination deadFunctionElimination(getModule());
722+
DeadFunctionElimination deadFunctionElimination(getModule(),
723+
/*keepExternalWitnessTablesAlive*/ !isLateDFE);
707724
deadFunctionElimination.eliminateFunctions(this);
708725
}
709726
};
710727

711728
} // end anonymous namespace
712729

713730
SILTransform *swift::createDeadFunctionElimination() {
714-
return new SILDeadFuncElimination();
731+
return new SILDeadFuncElimination(/*isLateDFE*/ false);
732+
}
733+
734+
SILTransform *swift::createLateDeadFunctionElimination() {
735+
return new SILDeadFuncElimination(/*isLateDFE*/ true);
715736
}
716737

717738
void swift::performSILDeadFunctionElimination(SILModule *M) {

Diff for: lib/SILOptimizer/PassManager/PassPipeline.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ static void addLateLoopOptPassPipeline(SILPassPipelinePlan &P) {
522522
P.startPipeline("LateLoopOpt");
523523

524524
// Delete dead code and drop the bodies of shared functions.
525-
P.addDeadFunctionElimination();
525+
// Also, remove externally available witness tables. They are not needed
526+
// anymore after the last devirtualizer run.
527+
P.addLateDeadFunctionElimination();
526528

527529
// Perform the final lowering transformations.
528530
P.addCodeSinking();

Diff for: lib/SymbolGraphGen/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_swift_host_library(swiftSymbolGraphGen STATIC
77
SymbolGraphGen.cpp
88
SymbolGraphASTWalker.cpp)
99

10-
target_link_libraries(swiftSymbolGraphGen
10+
target_link_libraries(swiftSymbolGraphGen PRIVATE
1111
swiftAST
1212
swiftFrontend
1313
swiftMarkup)

Diff for: test/SIL/Serialization/init_existential_inst_deserializes_witness_tables.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -sil-inline-threshold 0 %S/Inputs/init_existential_inst_deserializes_witness_tables_input.swift -o %t/Swift.swiftmodule -emit-module -parse-as-library -parse-stdlib -module-link-name swiftCore -module-name Swift -O
3-
// RUN: %target-swift-frontend -I %t -O %s -emit-sil -o - | %FileCheck %s
3+
// RUN: %target-swift-frontend -I %t -O %s -Xllvm -sil-disable-pass=late-deadfuncelim -emit-sil -o - | %FileCheck %s
44

55
// CHECK: sil_witness_table public_external X: P module Swift {
66

Diff for: test/SILOptimizer/devirt_opaque_witness.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/opaque_conformance.swiftmodule -primary-file %S/Inputs/opaque_conformance.swift
3-
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s -I %t | %FileCheck %s
3+
// RUN: %target-swift-frontend -O -emit-sil -primary-file %s -I %t -Xllvm -sil-disable-pass=late-deadfuncelim | %FileCheck %s
44

55
import opaque_conformance
66

Diff for: test/SILOptimizer/sil_witness_tables_external_witnesstable.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module %S/Inputs/sil_witness_tables_external_input.swift -o %t/Swift.swiftmodule -parse-stdlib -parse-as-library -module-name Swift -module-link-name swiftCore
3-
// RUN: %target-swift-frontend -O -I %t %s -emit-sil | %FileCheck %s
3+
// RUN: %target-swift-frontend -O -I %t %s -Xllvm -sil-disable-pass=late-deadfuncelim -emit-sil | %FileCheck %s
4+
// RUN: %target-swift-frontend -O -I %t %s -emit-sil | %FileCheck -check-prefix=CHECK-DFE %s
45

56
import Swift
67

78
// Make sure the specializer produces an external witness table.
89
//
910
// CHECK: sil_witness_table public_external X: P module Swift {
1011

12+
// Also check that late dead-function-elimination is removing externally
13+
// available witness tables.
14+
//
15+
// CHECK-DFE-NOT: sil_witness_table public_external
16+
1117
func doSomething<T : P>(_ t : T) -> Y {
1218
return t.doSomething()
1319
}

Diff for: tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

+8-10
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@ function(add_sourcekit_default_compiler_flags target)
7070
LINK_LIBRARIES_VAR_NAME link_libraries
7171
LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories)
7272

73-
# Convert variables to space-separated strings.
74-
_list_escape_for_shell("${c_compile_flags}" c_compile_flags)
75-
_list_escape_for_shell("${link_flags}" link_flags)
76-
7773
# Set compilation and link flags.
78-
set_property(TARGET "${target}" APPEND_STRING PROPERTY
79-
COMPILE_FLAGS " ${c_compile_flags} -fblocks")
80-
set_property(TARGET "${target}" APPEND_STRING PROPERTY
81-
LINK_FLAGS " ${link_flags}")
82-
set_property(TARGET "${target}" APPEND PROPERTY LINK_LIBRARIES ${link_libraries})
83-
swift_target_link_search_directories("${target}" "${library_search_directories}")
74+
target_compile_options(${target} PRIVATE
75+
-fblocks)
76+
target_link_options(${target} PRIVATE
77+
${link_flags})
78+
target_link_directories(${target} PRIVATE
79+
${library_search_directories})
80+
target_link_libraries(${target} PRIVATE
81+
${link_libraries})
8482
endfunction()
8583

8684
# Add a new SourceKit library.

0 commit comments

Comments
 (0)