-
Notifications
You must be signed in to change notification settings - Fork 10.5k
optimize keypath instructions #24929
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
Conversation
@swift-ci test |
@@ -1393,6 +1582,12 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) { | |||
return nullptr; | |||
} | |||
|
|||
SILInstruction *SILCombiner::visitBeginApplyInst(BeginApplyInst *BAI) { | |||
if (tryOptimizeInoutKeypath(BAI)) |
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.
Should we try this more generally on all address values, not only begin_apply
s?
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.
This is the call of the keypath runtime function itself. It can only be an apply or begin_apply.
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.
Thanks, sorry, I got it confused with "begin_access".
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.
Awesome!
Build failed |
@swift-ci test linux |
Just out of curiosity, it would not yet be able to optimize something more complex like this segment in DriverUtils, correct? …
func deltaEquation(_ stat: KeyPath<rusage, Int>) -> String {
let b = baseline[keyPath: stat], c = current[keyPath: stat]
return "\(c) - \(b) = \(c - b)"
}
logVerbose(
"""
MAX_RSS \(deltaEquation(\rusage.ru_maxrss)) (\(pages()) pages)
ICS \(deltaEquation(\rusage.ru_nivcsw))
VCS \(deltaEquation(\rusage.ru_nvcsw))
""")
… |
If |
If the keypath argument of a keypath access function is a keypath literal instruction, generate the projection inline and remove the access function. For example, replaces (simplified SIL): %kp = keypath ... stored_property #Foo.bar apply %keypath_runtime_function(%root_object, %kp, %addr) with: %addr = struct_element_addr %root_object, #Foo.bar load/store %addr Currently this only handles stored property patterns. rdar://problem/36244734
56e6bbc
to
da38e3a
Compare
@swift-ci smoke test and merge |
1 similar comment
@swift-ci smoke test and merge |
If the keypath argument of a keypath access function is a keypath literal instruction, generate the projection inline and remove the access function.
For example, replaces (simplified SIL):
%kp = keypath ... stored_property #Foo.bar
apply %keypath_runtime_function(%root_object, %kp, %addr)
with:
%addr = struct_element_addr %root_object, #Foo.bar
load/store %addr
Currently this only handles stored property patterns.
rdar://problem/36244734