-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] Remove unspecialized functions before running IRGen #68781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b049319
8b1aca9
c8b0273
7c5962b
540d7bb
325bc94
4fa9e53
d784822
ff1d177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,13 @@ class DeadFunctionAndGlobalElimination { | |
|
||
/// Checks is a function is alive, e.g. because it is visible externally. | ||
bool isAnchorFunction(SILFunction *F) { | ||
// In embedded Swift, (even public) generic functions *after serialization* | ||
// cannot be used externally and are not anchors. | ||
bool embedded = Module->getOptions().EmbeddedSwift; | ||
bool generic = F->isGeneric(); | ||
bool isSerialized = Module->isSerialized(); | ||
if (embedded && generic && isSerialized) | ||
return false; | ||
|
||
// Functions that may be used externally cannot be removed. | ||
if (F->isPossiblyUsedExternally()) | ||
|
@@ -148,6 +155,7 @@ class DeadFunctionAndGlobalElimination { | |
|
||
/// Marks a function as alive. | ||
void makeAlive(SILFunction *F) { | ||
LLVM_DEBUG(llvm::dbgs() << " makeAlive " << F->getName() << '\n'); | ||
AliveFunctionsAndTables.insert(F); | ||
assert(F && "function does not exist"); | ||
Worklist.insert(F); | ||
|
@@ -431,7 +439,11 @@ class DeadFunctionAndGlobalElimination { | |
F.forEachSpecializeAttrTargetFunction( | ||
[this](SILFunction *targetFun) { ensureAlive(targetFun); }); | ||
|
||
if (!F.shouldOptimize()) { | ||
bool retainBecauseFunctionIsNoOpt = !F.shouldOptimize(); | ||
if (Module->getOptions().EmbeddedSwift) | ||
retainBecauseFunctionIsNoOpt = false; | ||
|
||
if (retainBecauseFunctionIsNoOpt) { | ||
LLVM_DEBUG(llvm::dbgs() << " anchor a no optimization function: " | ||
<< F.getName() << "\n"); | ||
ensureAlive(&F); | ||
|
@@ -526,6 +538,8 @@ class DeadFunctionAndGlobalElimination { | |
|
||
// Check vtable methods. | ||
for (auto &vTable : Module->getVTables()) { | ||
LLVM_DEBUG(llvm::dbgs() << " processing vtable " | ||
<< vTable->getClass()->getName() << '\n'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have to be very careful with class methods. I'm not sure if DFE will now remove generic (non-final) vtable methods - which are not allowed in embedded swift. If we don't diagnose this earlier, calling such a method will result in a runtime error instead of a compiler error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, and this PR is not changing anything around classes and DFE on them (it doesn't happen). I just added this log to get some more visibility into what is considered to be anchors when debugging. |
||
for (const SILVTable::Entry &entry : vTable->getEntries()) { | ||
if (entry.getMethod().kind == SILDeclRef::Kind::Deallocator || | ||
entry.getMethod().kind == SILDeclRef::Kind::IVarDestroyer) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// RUN: %target-swift-frontend -g -emit-ir %s -enable-experimental-feature Embedded | ||
// RUN: %target-swift-frontend -g -O -emit-ir %s -enable-experimental-feature Embedded | ||
// RUN: %target-swift-frontend -g -Osize -emit-ir %s -enable-experimental-feature Embedded | ||
// RUN: %target-swift-frontend -emit-ir %s -enable-experimental-feature Embedded | ||
// RUN: %target-swift-frontend -O -emit-ir %s -enable-experimental-feature Embedded | ||
// RUN: %target-swift-frontend -Osize -emit-ir %s -enable-experimental-feature Embedded | ||
|
||
// REQUIRES: swift_in_compiler | ||
// REQUIRES: VENDOR=apple | ||
// REQUIRES: OS=macosx | ||
|
||
public func foo<T>(_ array: inout [T]) { | ||
array.withUnsafeMutableBytes { | ||
$0[0] = 0 | ||
} | ||
} | ||
|
||
func foo2<T>(_ array: inout [T]) { | ||
array.withUnsafeMutableBytes { | ||
$0[0] = 0 | ||
} | ||
} | ||
|
||
public func test() { | ||
var a: [UInt8] = [1, 2, 3] | ||
foo(&a) | ||
foo2(&a) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.