-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e400b66
Cleanup replaceAllUsesAndErase, return an iterator, allow erase handl…
atrick 9aa2523
Add a CanonicalizeInstruction utility.
atrick 301ff8c
Add a SILGenCleanup pass.
atrick f395f86
Canonicalize loads in SILGenCleanup.
atrick e70b7c7
SILGenCleanup tests.
atrick 4a11549
Fix IRGen/enum.sil RUN line.
atrick a27b96e
Fixup access_markers.sil test case.
atrick ca9ae0d
Canonicalize nontrivial loads.
atrick c3c1dc7
Add a CanonicalizeInstruction test case for nontrivial loads.
atrick c3b7c19
Extend an exclusivity diagnostic test for nontrivial let's.
atrick ece096d
Fix eraseFromParentWithdebugInsts to call a callback.
atrick 9447d73
Add a BeginBorrowInst::getEndBorrows helper.
atrick f151a96
Add a comment on replaceUsesOfExtract per review feedback.
atrick 52237aa
Avoid else-return in splitAggregateLoad.
atrick 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
87 changes: 87 additions & 0 deletions
87
include/swift/SILOptimizer/Utils/CanonicalizeInstruction.h
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,87 @@ | ||
//===-- CanonicalizeInstruction.h - canonical SIL peepholes -----*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2019 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
/// | ||
/// SSA-peephole transformations that yield a more canonical SIL representation. | ||
/// | ||
/// Unlike simplifyInstruction, these transformations may effect any | ||
/// instruction, not only single-values, and may arbitrarily generate new SIL | ||
/// instructions. | ||
/// | ||
/// Unlike SILCombine, these peepholes must work on 'raw' SIL form and should be | ||
/// limited to those necessary to aid in diagnostics and other mandatory | ||
/// pipelin/e passes. Optimization may only be done to the extent that it | ||
/// neither interferes with diagnostics nor increases compile time. | ||
/// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H | ||
#define SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H | ||
|
||
#include "swift/SIL/SILBasicBlock.h" | ||
#include "swift/SIL/SILInstruction.h" | ||
#include "llvm/Support/Debug.h" | ||
|
||
namespace swift { | ||
|
||
/// Abstract base class. Implements all canonicalization transforms. Extended by | ||
/// passes to be notified of each SIL modification. | ||
struct CanonicalizeInstruction { | ||
// May be overriden by passes. | ||
static constexpr const char *defaultDebugType = "sil-canonicalize"; | ||
const char *debugType = defaultDebugType; | ||
|
||
CanonicalizeInstruction(const char *passDebugType) { | ||
gottesmm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#ifndef NDEBUG | ||
if (llvm::DebugFlag && !llvm::isCurrentDebugType(debugType)) | ||
debugType = passDebugType; | ||
#endif | ||
} | ||
|
||
virtual ~CanonicalizeInstruction(); | ||
|
||
/// Rewrite this instruction, based on its operands and uses, into a more | ||
/// canonical representation. | ||
/// | ||
/// Return an iterator to the next instruction or to the end of the block. | ||
/// The returned iterator will follow any newly added or to-be-deleted | ||
/// instructions, regardless of whether the pass immediately deletes the | ||
/// instructions or simply records them for later deletion. | ||
/// | ||
/// To (re)visit new instructions, override notifyNewInstruction(). | ||
/// | ||
/// To determine if any transformation at all occurred, override | ||
/// notifyNewInstruction(), killInstruction(), and notifyNewUsers(). | ||
/// | ||
/// Warning: If the \p inst argument is killed and the client immediately | ||
/// erases \p inst, then it may be an invalid pointer upon return. | ||
SILBasicBlock::iterator canonicalize(SILInstruction *inst); | ||
|
||
/// Record a newly generated instruction. | ||
virtual void notifyNewInstruction(SILInstruction *inst) = 0; | ||
|
||
/// Kill an instruction that no longer has uses, or whose side effect is now | ||
/// represented by a different instruction. The client can defer erasing the | ||
/// instruction but must eventually erase all killed instructions to restore | ||
/// valid SIL. | ||
/// | ||
/// This callback should not mutate any other instructions. It may only delete | ||
/// the given argument. It will be called separately for each end-of-scope and | ||
/// debug use before being called on the instruction they use. | ||
virtual void killInstruction(SILInstruction *inst) = 0; | ||
|
||
/// Record a SIL value that has acquired new users. | ||
virtual void notifyHasNewUsers(SILValue value) = 0; | ||
}; | ||
|
||
} // end namespace swift | ||
|
||
#endif // SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEINSTRUCTION_H |
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
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.
Uh oh!
There was an error while loading. Please reload this page.