-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SwiftCompilerSources: added OwnershipUtils for ForwardingInstruction. #68885
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 |
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.
Basically LGTM, nice work!
I have a few comments about the implementation details
SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipUtils.swift
Outdated
Show resolved
Hide resolved
// | ||
// This walker is used to query basic lifetime attributes on values, such as "escaping" or "lexical". It must be precise for correctness and is performance critical. | ||
// | ||
// TODO: Ideally, this would be defined alongside ForwardingInstruction, but basic data structures and utilities are not available in the SIL module. |
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.
Are the walkers really part of SIL? You can also view them as utility, based on ForwardingInstruction.
Anyway, if we want we can easily move the WalkUtils into SIL
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.
Any walker that is required for well-formed SIL is part of SIL. In this case, the behavior of the walker will change SIL semantics, so it's definitely part of SIL. If the walker, "stops early" and we fail to see that some value has a pointer-escape, then we lose information needed for correctness. We also cache some information about lifetimes as instruction flags, and that cache needs to be consistent with the walker.
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.
Note that I'm not too concerned about the final resting place for new lifetime utilities because I expect them to change a lot in the next few months.
} | ||
|
||
extension Value { | ||
public var forwardingInstruction: ForwardingInstruction? { |
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.
Though it's a bit lengthy, I think that definingForwardingInstruction
would make it a bit clearer.
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.
I don't care much about the name here, but I'm worried that people will think they can use definingForwardingInstruction
the same way they use definingInstruction
. But it doesn't work that way. For terminator results, you cannot use the forwarding instruction as an insertion point.
43e4785
to
60d4561
Compare
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 looks already great!
A have a few more comments
SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipUtils.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipUtils.swift
Outdated
Show resolved
Hide resolved
SwiftCompilerSources/Sources/Optimizer/Utilities/OwnershipUtils.swift
Outdated
Show resolved
Hide resolved
return tpei.tupleOperand | ||
case let sei as SelectEnumInst: | ||
return sei.enumOperand | ||
default: |
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 can be the default implementation
841f6c4
to
4a8b091
Compare
This could be combined with ValueUseDefWalker if the latter is refactored to classsify instructions by projections and aggegation (which always forward) vs. other arbitrary hard-coded instruction types. It would also need to limit the walk to real operands (which are always forwarded). Then this walker can call into the default walk for projections and track the projection path. The current implementation is however simpler and more efficient.
4a8b091
to
e27b308
Compare
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.
perfect! lgtm!
Adding unit tests is taking longer than expected. I'll put them in a follow-up PR. |
@swift-ci test |
Add SwiftCompilerSources bridging for operand ownership and forwarding instructions.
This needs to be in place to bootstrap lifetime diagnostics. We'll start adding unit tests as we explore different diagnostic test cases.