-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add a SILGenCleanup pass and CanonicalizeInstruction utility. #24153
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
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.
Quick drive by. I want to do another pass through on this before I give the LGTM. Also can you split this up so that:
- Adding the new code/utilities is one commit.
- We have separate commits for each pass that are being updated.
@@ -113,6 +135,39 @@ void SILCombineWorklist::add(SILInstruction *I) { | |||
Worklist.push_back(I); | |||
} | |||
|
|||
// Define a CanonicalizeInstruction subclass for use in SILCombine. | |||
class SILCombineCanonicalize : CanonicalizeInstruction { |
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.
Can you make this final/add override to all of the overridden entry points.
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.
Yes, fixed.
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 will rebase this soon after splitting it into 4 commits.
SILBasicBlock::iterator canonicalize(SILInstruction *inst); | ||
|
||
/// Record a newly generated instruction. | ||
virtual void genInstruction(SILInstruction *inst) = 0; |
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.
Much better, fixed.
@@ -113,6 +135,39 @@ void SILCombineWorklist::add(SILInstruction *I) { | |||
Worklist.push_back(I); | |||
} | |||
|
|||
// Define a CanonicalizeInstruction subclass for use in SILCombine. | |||
class SILCombineCanonicalize : CanonicalizeInstruction { |
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.
Yes, fixed.
@gottesmm this PR now has the full set of commits that I want to get into 5.1 to fix exclusivity diagnostics. I'll make a separate PR for store canonicalization for master only. |
@swift-ci test |
@swift-ci test source compatibility |
@swift-ci benchmark |
Build failed |
Build failed before running benchmark. |
Build failed |
@swift-ci test |
@swift-ci benchmark |
Build failed |
Build failed |
Build failed before running benchmark. |
Forced pushed a minor test case fix for i386. |
@swift-ci test. |
@swift-ci benchmark. |
Build failed |
Build failed |
@swift-ci benchmark |
Build failed before running benchmark. |
@swift-ci benchmark |
@gottesmm I don't think there are any more build/test issues to fix here, but I'll wait to restart CI until you've finished your review. |
Performance: -O
Performance: -Osize
How to read the dataThe tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.If you see any unexpected regressions, you should consider fixing the Noise: Sometimes the performance results (not code size!) contain false Hardware Overview
|
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.
Some more suggestions. I went line by line. I need to read the load [copy] a bit more in depth. While you are looking at these I will look in more depth there.
…ers. This will make the forthcoming CanonicalizeInstruction interface more clear. This is generally the better approach to utilities that mutate the instruction stream. It avoids the temptation to assume that only a single instruction will be deleted or that only instructions before the current iterator will be deleted. This often happens to work but eventually fails in the presense of debug and end-of-scope instructions. A function returning an iterator has a more clear contract than one accepting some iterator reference of unknown providence. Unfortunately, it doesn't work at the lowest level of utilities, such as recursivelyDeleteTriviallyDeadInstructions, where we want to handle instruction batches.
CanonicalizeInstruction will be a superset of simplifyInstruction (once all the transforms are fixed for ownership SIL). Additionally, it will also include simple SSA-based canonicalization that requires new instruction creation. It may not perform any optimization that interferes with diagnostics or increases compile time. Canonicalization replaces simplifyInstruction in SILCombine so we can easily factor some existing SILCombine transforms into canonicalization.
The SILGenCleanup pass runs before diagnostics to perform any canonicalization required by diagnostics.
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.
Some small additional asks. But beyond that... LGTM! This is a great PR! Great work Andy!
Reimplement load instruction canonicalization as part of the CanonicalizeInstruction utility.
Add -disable-diagnostic-passes because we want to test IRGen on precisely the SIL input sequence.
Canonical access markers should always guard some memory operation. It's valid to delete dead access markers even before exclusivity diagnostics. Deleting dead memory operations before diagnostics would *not* be ok.
This adds support to the load->struct_extract canonicalization for nontrivial element types which look like: load [copy] borrow struct_extract ...uses... end_borrow destroy
The recursivelyDeleteTriviallyDeadInstructions utility takes a callBack to be called for every deleted instruction. However, it wasn't passing this callBack to eraseFromParentWithdebugInsts. The callback was used to update an iterator in some cases, so not calling it resulted in iterator invalidation. Doing this also cleans up the both APIs: recursivelyDeleteTriviallyDeadInstructions and eraseFromParentWithdebugInsts.
@swift-ci test. |
@swift-ci test source compatibility |
Build failed |
Build failed |
[5.1] Merge pull request #24153 from atrick/fix-let-exclusivity
Canonicalize instruction will be a superset of
simplifyInstruction (once all the transforms are fixed for ownership
SIL). Additionally, it will also include simple SSA-based
canonicalization that requires new instruction creation. It may not
perform any optimization that interferes with diagnostics or increases
compile time.
The SILGenCleanup pass runs before diagnostics to perform any
canonicalization required by diagnostics.
Canonicalization replaces simplifyInstruction in SILCombine so we can
easily factor some existing SILCombine transforms into canonicalization.