Skip to content

Commit b9f7acb

Browse files
authored
Merge pull request #70309 from kubamracek/embedded-dfe
[embedded] Run DeadFunctionAndGlobalElimination after MandatoryPerformanceOptimizations
2 parents 14e3bc0 + df638b0 commit b9f7acb

File tree

7 files changed

+62
-9
lines changed

7 files changed

+62
-9
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
255255
P.addOnoneSimplification();
256256
P.addAllocVectorLowering();
257257
P.addInitializeStaticGlobals();
258+
259+
// MandatoryPerformanceOptimizations might create specializations that are not
260+
// used, and by being unused they are might have unspecialized applies.
261+
// Eliminate them via the DeadFunctionAndGlobalElimination in embedded Swift
262+
// to avoid getting metadata/existential use errors in them. We don't want to
263+
// run this pass in regular Swift: Even unused functions are expected to be
264+
// available in debug (-Onone) builds for debugging and development purposes.
265+
if (P.getOptions().EmbeddedSwift) {
266+
P.addDeadFunctionAndGlobalElimination();
267+
}
268+
258269
P.addPerformanceDiagnostics();
259270
}
260271

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
using namespace swift;
1919

20+
static llvm::cl::opt<bool> LinkEmbeddedRuntime("link-embedded-runtime",
21+
llvm::cl::init(true));
22+
2023
//===----------------------------------------------------------------------===//
2124
// Top Level Driver
2225
//===----------------------------------------------------------------------===//
@@ -39,7 +42,7 @@ class SILLinker : public SILModuleTransform {
3942

4043
// In embedded Swift, the stdlib contains all the runtime functions needed
4144
// (swift_retain, etc.). Link them in so they can be referenced in IRGen.
42-
if (M.getOptions().EmbeddedSwift) {
45+
if (M.getOptions().EmbeddedSwift && LinkEmbeddedRuntime) {
4346
linkEmbeddedRuntimeFromStdlib();
4447
}
4548
}

stdlib/public/Platform/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
7777
INSTALL_IN_COMPONENT sdk-overlay
7878
MACCATALYST_BUILD_FLAVOR "zippered")
7979

80-
# TODO(mracek): Disable building Darwin module as embedded pending investigations into a build failure
81-
if(FALSE)
80+
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB)
8281
set(SWIFT_ENABLE_REFLECTION OFF)
8382

8483
add_custom_target(embedded-darwin ALL)

test/embedded/darwin-bridging-header.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// REQUIRES: VENDOR=apple
1212
// REQUIRES: OS=macosx
1313

14-
// Temporarily disabled:
15-
// REQUIRES: rdar119283700
16-
1714
// BEGIN BridgingHeader.h
1815

1916
#include <unistd.h>

test/embedded/darwin.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
// REQUIRES: VENDOR=apple
1010
// REQUIRES: OS=macosx
1111

12-
// Temporarily disabled:
13-
// REQUIRES: rdar119283700
14-
1512
import Darwin
1613

1714
@main

test/embedded/duration.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-emit-ir %s -enable-experimental-feature Embedded -wmo
2+
// RUN: %target-swift-emit-ir -O %s -enable-experimental-feature Embedded -wmo
3+
// RUN: %target-swift-emit-ir -Osize %s -enable-experimental-feature Embedded -wmo
4+
5+
// REQUIRES: swift_in_compiler
6+
// REQUIRES: OS=macosx || OS=linux-gnu
7+
8+
@available(SwiftStdlib 5.7, *)
9+
extension Duration {
10+
@available(SwiftStdlib 5.7, *)
11+
public init() {
12+
self = .seconds(10) + .nanoseconds(20)
13+
}
14+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %target-swift-frontend -parse-stdlib -emit-ir %s -enable-experimental-feature Embedded -Xllvm -link-embedded-runtime=0
2+
3+
// REQUIRES: swift_in_compiler
4+
// REQUIRES: VENDOR=apple
5+
// REQUIRES: OS=macosx
6+
7+
public struct UInt23 {
8+
}
9+
10+
public protocol MyBinaryInteger {
11+
}
12+
13+
extension UInt23: MyBinaryInteger {
14+
}
15+
16+
protocol MyProto {
17+
static var my_static_var: UInt23 { get }
18+
static func foo()
19+
}
20+
21+
struct MyStruct: MyProto {
22+
static let my_static_var = UInt23()
23+
}
24+
25+
extension MyProto {
26+
public static func foo() {
27+
bar(Self.my_static_var)
28+
}
29+
}
30+
31+
public func bar<T: MyBinaryInteger>(_ value: @autoclosure () -> T) {
32+
}

0 commit comments

Comments
 (0)