Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/swift/SIL/PrunedLiveness.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ struct PrunedLivenessBoundary {
///
/// bool isDef(SILInstruction *inst) const
///
/// bool isDef(SILArgument *arg) const
///
/// bool isDefBlock(SILBasicBlock *block) const
///
template <typename LivenessWithDefs>
Expand All @@ -611,6 +613,15 @@ class PrunedLiveRange : public PrunedLiveness {
ValueSet &visited,
SILValue value);

bool isInstructionLive(SILInstruction *instruction, bool liveOut) const;
bool isAvailableOut(SILBasicBlock *block, DeadEndBlocks &deadEndBlocks) const;
bool isInstructionAvailable(SILInstruction *user,
DeadEndBlocks &deadEndBlocks) const;
/// Whether \p user is within the boundary extended from live regions into
/// dead-end regions up to the availability boundary.
bool isWithinExtendedBoundary(SILInstruction *user,
DeadEndBlocks *deadEndBlocks) const;

public:
/// Add \p inst to liveness which uses the def as indicated by \p usage.
void updateForUse(SILInstruction *inst, LifetimeEnding usage);
Expand Down Expand Up @@ -735,6 +746,8 @@ class SSAPrunedLiveness : public PrunedLiveRange<SSAPrunedLiveness> {

bool isDef(SILInstruction *inst) const { return inst == defInst; }

bool isDef(SILArgument *arg) const { return def == arg; }

bool isDefBlock(SILBasicBlock *block) const {
return def->getParentBlock() == block;
}
Expand Down
6 changes: 0 additions & 6 deletions include/swift/SILOptimizer/Utils/CanonicalizeBorrowScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ bool shrinkBorrowScope(
MoveValueInst *foldDestroysOfCopiedLexicalBorrow(BeginBorrowInst *bbi,
DominanceInfo &dominanceTree,
InstructionDeleter &deleter);

bool hoistDestroysOfOwnedLexicalValue(SILValue const value,
SILFunction &function,
InstructionDeleter &deleter,
BasicCalleeAnalysis *calleeAnalysis);

} // namespace swift

#endif // SWIFT_SILOPTIMIZER_UTILS_CANONICALIZEBORROWSCOPES_H
40 changes: 24 additions & 16 deletions include/swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
#include "swift/Basic/SmallPtrSetVector.h"
#include "swift/SIL/PrunedLiveness.h"
#include "swift/SIL/SILInstruction.h"
#include "swift/SILOptimizer/Analysis/DeadEndBlocksAnalysis.h"
#include "swift/SILOptimizer/Analysis/DominanceAnalysis.h"
#include "swift/SILOptimizer/Analysis/NonLocalAccessBlockAnalysis.h"
#include "swift/SILOptimizer/Utils/InstructionDeleter.h"
Expand Down Expand Up @@ -247,6 +248,8 @@ class CanonicalizeOSSALifetime final {
// extendLivenessThroughOverlappingAccess is invoked.
NonLocalAccessBlocks *accessBlocks = nullptr;

DeadEndBlocksAnalysis *deadEndBlocksAnalysis;

DominanceInfo *domTree = nullptr;

BasicCalleeAnalysis *calleeAnalysis;
Expand Down Expand Up @@ -326,27 +329,22 @@ class CanonicalizeOSSALifetime final {
}
};

CanonicalizeOSSALifetime(PruneDebugInsts_t pruneDebugMode,
MaximizeLifetime_t maximizeLifetime,
SILFunction *function,
NonLocalAccessBlockAnalysis *accessBlockAnalysis,
DominanceInfo *domTree,
BasicCalleeAnalysis *calleeAnalysis,
InstructionDeleter &deleter)
CanonicalizeOSSALifetime(
PruneDebugInsts_t pruneDebugMode, MaximizeLifetime_t maximizeLifetime,
SILFunction *function, NonLocalAccessBlockAnalysis *accessBlockAnalysis,
DeadEndBlocksAnalysis *deadEndBlocksAnalysis, DominanceInfo *domTree,
BasicCalleeAnalysis *calleeAnalysis, InstructionDeleter &deleter)
: pruneDebugMode(pruneDebugMode), maximizeLifetime(maximizeLifetime),
accessBlockAnalysis(accessBlockAnalysis), domTree(domTree),
accessBlockAnalysis(accessBlockAnalysis),
deadEndBlocksAnalysis(deadEndBlocksAnalysis), domTree(domTree),
calleeAnalysis(calleeAnalysis), deleter(deleter) {}

SILValue getCurrentDef() const { return currentDef; }

void initializeLiveness(SILValue def,
ArrayRef<SILInstruction *> lexicalLifetimeEnds) {
assert(consumingBlocks.empty() && debugValues.empty());
// Clear the cached analysis pointer just in case the client invalidates the
// analysis, freeing its memory.
accessBlocks = nullptr;
consumes.clear();
destroys.clear();
clear();

currentDef = def;
currentLexicalLifetimeEnds = lexicalLifetimeEnds;
Expand All @@ -358,9 +356,18 @@ class CanonicalizeOSSALifetime final {
}

void clear() {
// Clear the access blocks analysis pointer in case the client invalidates
// the analysis. If the client did, the analysis will be recomputed in
// extendLivenessThroughOverlappingAccess; if it didn't, the analysis
// pointer will just be set back to its old value when the analysis' cache
// is consulted in extendLivenessThroughOverlappingAccess.
accessBlocks = nullptr;

consumingBlocks.clear();
debugValues.clear();
discoveredBlocks.clear();
consumes.clear();
destroys.clear();
}

/// Top-Level API: rewrites copies and destroys within \p def's extended
Expand Down Expand Up @@ -472,7 +479,7 @@ class CanonicalizeOSSALifetime final {
void findExtendedBoundary(PrunedLivenessBoundary const &originalBoundary,
PrunedLivenessBoundary &boundary);

void findDestroysOutsideBoundary(SmallVectorImpl<SILInstruction *> &destroys);
void extendLivenessToDeadEnds();
void extendLivenessToDeinitBarriers();

void extendUnconsumedLiveness(PrunedLivenessBoundary const &boundary);
Expand All @@ -481,9 +488,10 @@ class CanonicalizeOSSALifetime final {
llvm::function_ref<void(SILInstruction *, PrunedLiveness::LifetimeEnding)>
visitor);

void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary);
void insertDestroysOnBoundary(PrunedLivenessBoundary const &boundary,
SmallVectorImpl<DestroyValueInst *> &destroys);

void rewriteCopies();
void rewriteCopies(SmallVectorImpl<DestroyValueInst *> const &destroys);
};

} // end namespace swift
Expand Down
Loading