Skip to content

Commit 7dc3914

Browse files
authored
Merge pull request #72227 from eeckstein/reenable-embedded-dead-func-elimination
re-instate: embedded: allow dead function elimination for de-serialized functions
2 parents 2c6cc4a + 4017501 commit 7dc3914

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

lib/SIL/IR/Linker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ void SILLinkerVisitor::process() {
448448
Fn->setSerialized(IsSerialized_t::IsNotSerialized);
449449
}
450450

451-
// TODO: This should probably be done as a separate SIL pass ("internalize")
452-
if (Fn->getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
451+
if (Fn->getModule().getASTContext().LangOpts.hasFeature(Feature::Embedded) &&
452+
Fn->getModule().getASTContext().LangOpts.DebuggerSupport) {
453+
// LLDB requires that functions with bodies are not external.
453454
Fn->setLinkage(stripExternalFromLinkage(Fn->getLinkage()));
454455
}
455456

lib/SIL/IR/SILFunction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ bool SILFunction::shouldBePreservedForDebugger() const {
940940
if (getEffectiveOptimizationMode() != OptimizationMode::NoOptimization)
941941
return false;
942942

943+
if (isAvailableExternally())
944+
return false;
945+
943946
if (hasSemanticsAttr("no.preserve.debugger"))
944947
return false;
945948

lib/SILOptimizer/Mandatory/IRGenPrepare.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ class IRGenPrepare : public SILFunctionTransform {
8787
void run() override {
8888
SILFunction *F = getFunction();
8989

90+
if (getOptions().EmbeddedSwift) {
91+
// In embedded swift all the code is generated in the top-level module.
92+
// Even de-serialized functions must be code-gen'd.
93+
SILLinkage linkage = F->getLinkage();
94+
if (isAvailableExternally(linkage)) {
95+
F->setLinkage(stripExternalFromLinkage(linkage));
96+
}
97+
}
98+
9099
bool shouldInvalidate = cleanFunction(*F);
91100

92101
if (shouldInvalidate)

lib/SILOptimizer/UtilityPasses/Link.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class SILLinker : public SILModuleTransform {
8686

8787
if (M.linkFunction(Fn, LinkMode))
8888
invalidateAnalysis(Fn, SILAnalysis::InvalidationKind::Everything);
89+
90+
// Make sure that dead-function-elimination doesn't remove runtime functions.
91+
// TODO: lazily emit runtime functions in IRGen so that we don't have to
92+
// rely on dead-stripping in the linker to remove unused runtime
93+
// functions.
94+
if (Fn->isDefinition())
95+
Fn->setLinkage(SILLinkage::Public);
8996
}
9097
};
9198
} // end anonymous namespace

test/embedded/floatingpoint.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-run-simple-swift(-enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
2+
// RUN: %target-run-simple-swift(-O -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
3+
// RUN: %target-run-simple-swift(-O -lto=llvm-full %lto_flags -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck %s
4+
5+
// REQUIRES: swift_in_compiler
6+
// REQUIRES: executable_test
7+
// REQUIRES: optimized_stdlib
8+
// REQUIRES: OS=macosx || OS=linux-gnu
9+
10+
// Check that initializing a Double with an integer literal doesn't result in unresolved symbols
11+
@inline(never)
12+
func testLiteral() -> Double {
13+
return Double(1)
14+
}
15+
16+
@main
17+
struct Main {
18+
static func main() {
19+
print(testLiteral() == 1.0)
20+
// CHECK: true
21+
}
22+
}

test/embedded/stdlib-basic.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ public func checks(n: Int) {
4343

4444
// CHECK: define {{.*}}i32 @main(i32 %0, ptr %1)
4545
// CHECK: define {{.*}}i1 @"$s4main4boolSbyF"()
46-
// CHECK: define {{.*}}i1 @"$sSb22_builtinBooleanLiteralSbBi1__tcfC"(i1 %0)
4746
// CHECK: define {{.*}}{{i32|i64}} @"$s4main3intSiyF"()
48-
// CHECK: define {{.*}}{{i32|i64}} @"$sSi22_builtinIntegerLiteralSiBI_tcfC"(ptr %0, {{i32|i64}} %1)
4947
// CHECK: define {{.*}}ptr @"$s4main3ptr1p1nS2V_SitF"(ptr %0, {{i32|i64}} %1)
50-
// CHECK: define {{.*}}ptr @"$sSV8advanced2bySVSi_tF"({{i32|i64}} %0, ptr %1)
5148
// CHECK: define {{.*}}{ {{i32|i64}}, i8 } @"$s4main8optionalSiSgyF"()
5249
// CHECK: define {{.*}}{ {{i32|i64}}, {{i32|i64}}, i8 } @"$s4main12staticstrings12StaticStringVyF"()
53-
// CHECK: define {{.*}}{ {{i32|i64}}, {{i32|i64}}, i8 } @"$ss12StaticStringV08_builtinB7Literal17utf8CodeUnitCount7isASCIIABBp_BwBi1_tcfC"(ptr %0, {{i32|i64}} %1, i1 %2)
5450
// CHECK: define {{.*}}void @"$s4main6checks1nySi_tF"({{i32|i64}} %0)

0 commit comments

Comments
 (0)