-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Introduce stub
mode for -unavailable-decl-optimization
#65557
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
tshortli
merged 13 commits into
swiftlang:main
from
tshortli:unavailable-decl-optimization-stub
May 5, 2023
Merged
Introduce stub
mode for -unavailable-decl-optimization
#65557
tshortli
merged 13 commits into
swiftlang:main
from
tshortli:unavailable-decl-optimization-stub
May 5, 2023
Conversation
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
Part of rdar://107388493
When `-unavailable-decl-optimization=stub` is specified, insert a call to `_diagnoseUnavailableCodeReached()` at the beginning of the function to cause it to trap if executed at run time. Part of rdar://107388493
…tubs. User code should not be diagnosed as "unreachable" by the SIL optimizer when the no-return function that made the code unreachable is a compiler inserted call to `_diagnoseUnavailableCodeReached()`. Part of rdar://107388493
Part of rdar://107388493
Part of rdar://107388493
Part of rdar://107388493
Part of rdar://107388493
…thunk. Part of rdar://107388493.
The logic was defaulting to `arm64` when a binary only contained `amr64_32` and `arm64e` slices.
ab89db6
to
12a122a
Compare
@swift-ci please test |
nkcsgexi
reviewed
May 3, 2023
/// @_semantics("unavailable_code_reached") | ||
bool isCalleeUnavailableCodeReached() const { | ||
auto calleeFn = getCalleeFunction(); | ||
if (!calleeFn) return false; |
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: usually we split return
to a separate line for better debuggability.
@swift-ci please test Linux |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implement a new
-unavailable-decl-optimization
mode that replaces the bodies of unavailable functions with calls to a standard library function that invokesfatalError
. Unlike-unavailable-decl-optimization=complete
, this compilation mode is designed to improve the code size of unavailable code while also preserving ABI compatibility. This is important since there are existing compiled binaries that link the symbols for unavailable functions even though those symbols should be provably unreachable.This optimization is implemented in SILGen by inserting a call to a new standard library function
_diagnoseUnavailableCodeReached()
in the prologue of each unavailable function. The existing dead code elimination optimization pass then determines that the remainder of the function body is unreachable and removes all other code, leaving the body of the function as a single call to a no-return function.There are several follow up changes that can be made to maximize the effectiveness of this optimization:
_diagnoseUnavailableCodeReached()
and sometimes also includes abrk
instruction after the call. Some work to reduce the machine code for these stubs down to the minimal necessary instructions (probably just a single branch?) may be warranted.Resolves rdar://107388493