-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Frontend] Add experimental flag to skip non-inlinable function bodies #20420
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
Merged
harlanhaskins
merged 2 commits into
swiftlang:master
from
harlanhaskins:thats-the-uhh-bodies
Sep 26, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
lib/SILOptimizer/UtilityPasses/NonInlinableFunctionSkippingChecker.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
//===------------- NonInlinableFunctionSkippingChecker.cpp ----------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "swift/Basic/LLVM.h" | ||
#include "swift/SIL/SILFunction.h" | ||
#include "swift/SIL/SILInstruction.h" | ||
#include "swift/SIL/SILModule.h" | ||
#include "swift/SILOptimizer/PassManager/Transforms.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
|
||
using namespace swift; | ||
|
||
/// Determines whether we should have skipped SILGenning a function that | ||
/// appears in a SILModule. This only applies when | ||
/// \c -experimental-skip-non-inlinable-function-bodies is enabled. | ||
static bool shouldHaveSkippedFunction(const SILFunction &F) { | ||
assert(F.getModule().getOptions().SkipNonInlinableFunctionBodies && | ||
"this check only makes sense if we're skipping function bodies"); | ||
|
||
// First, we only care about functions that haven't been marked serialized. | ||
// If they've been marked serialized, they will end up in the final module | ||
// and we needed to SILGen them. | ||
if (F.isSerialized()) | ||
return false; | ||
|
||
// Next, we're looking for functions that shouldn't have a body, but do. If | ||
// the function doesn't have a body (i.e. it's an external declaration), we | ||
// skipped it successfully. | ||
if (F.isExternalDeclaration()) | ||
return false; | ||
|
||
// Thunks and specializations are automatically synthesized, so it's fine that | ||
// they end up in the module. | ||
if (F.isThunk() || F.isSpecialization()) | ||
return false; | ||
|
||
// FIXME: We can probably skip property initializers, too. | ||
auto func = F.getLocation().getAsASTNode<AbstractFunctionDecl>(); | ||
if (!func) | ||
return false; | ||
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. Yeah, this scares me. All sorts of synthesized things will slip through here too. |
||
|
||
// If a body is synthesized/implicit, it shouldn't be skipped. | ||
if (func->isImplicit()) | ||
return false; | ||
|
||
// Local function bodies in inlinable code are okay to show up in the module. | ||
if (func->getDeclContext()->isLocalContext()) | ||
return false; | ||
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. Worth checking that the enclosing context is in fact inlinable. |
||
|
||
// FIXME: Identify __ivar_destroyer, __allocating_init, and | ||
// __deallocating_deinit, which have no special marking, are always | ||
// emitted, and do have a source location with the original decl | ||
// attached. | ||
if (isa<DestructorDecl>(func) || isa<ConstructorDecl>(func)) | ||
return false; | ||
|
||
// If none of those conditions trip, then this is something that _should_ | ||
// be serialized in the module even when we're skipping non-inlinable | ||
// function bodies. | ||
return true; | ||
} | ||
|
||
namespace { | ||
|
||
/// This is a verification utility pass that's meant to be used with | ||
/// \c -experimental-skip-non-inlinable-function-bodies. It checks all the | ||
/// functions in a module and ensures that, if the function was written in | ||
/// source and not serialized, then it wasn't even SILGen'd. | ||
class NonInlinableFunctionSkippingChecker : public SILModuleTransform { | ||
void run() override { | ||
// Skip this if we're not skipping function bodies | ||
if (!getModule()->getOptions().SkipNonInlinableFunctionBodies) | ||
return; | ||
|
||
// Skip this verification for SwiftOnoneSupport | ||
if (getModule()->isOptimizedOnoneSupportModule()) | ||
return; | ||
|
||
for (auto &F : *getModule()) { | ||
if (!shouldHaveSkippedFunction(F)) | ||
continue; | ||
|
||
llvm::dbgs() << "Function serialized that should have been skipped!\n"; | ||
F.getLocation().dump(F.getModule().getSourceManager()); | ||
llvm::dbgs() << "\n"; | ||
F.dump(); | ||
abort(); | ||
} | ||
} | ||
|
||
}; | ||
|
||
} // end anonymous namespace | ||
|
||
SILTransform *swift::createNonInlinableFunctionSkippingChecker() { | ||
return new NonInlinableFunctionSkippingChecker(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: why is this in the middle of all the stats options?
(Also, why is it a Driver option again?)