Skip to content

[sil][value-lifetime] Add ValueLifetimeAnalysis::FrontierImpl = SmallVectorImpl<SILInstruction *> #34753

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
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
10 changes: 7 additions & 3 deletions include/swift/SILOptimizer/Utils/ValueLifetime.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class ValueLifetimeAnalysis {
/// end the value's lifetime.
using Frontier = SmallVector<SILInstruction *, 4>;

/// A type erased version of frontier so callers can customize the inline
/// size.
using FrontierImpl = SmallVectorImpl<SILInstruction *>;

/// Constructor for the value \p def with a specific range of users.
///
/// We templatize over the RangeTy so that we can initialize
Expand Down Expand Up @@ -106,7 +110,7 @@ class ValueLifetimeAnalysis {
///
/// If \p deBlocks is provided, all dead-end blocks are ignored. This
/// prevents unreachable-blocks to be included in the frontier.
bool computeFrontier(Frontier &frontier, Mode mode,
bool computeFrontier(FrontierImpl &frontier, Mode mode,
DeadEndBlocks *deBlocks = nullptr);

ArrayRef<std::pair<TermInst *, unsigned>> getCriticalEdges() {
Expand All @@ -125,7 +129,7 @@ class ValueLifetimeAnalysis {
}

/// Checks if there is a dealloc_ref inside the value's live range.
bool containsDeallocRef(const Frontier &frontier);
bool containsDeallocRef(const FrontierImpl &frontier);

/// For debug dumping.
void dump() const;
Expand Down Expand Up @@ -159,7 +163,7 @@ class ValueLifetimeAnalysis {
/// Otherwise \p valueOrStackLoc must be a value type and in this case, inserts
/// destroy_value at each instruction of the \p frontier.
void endLifetimeAtFrontier(SILValue valueOrStackLoc,
const ValueLifetimeAnalysis::Frontier &frontier,
const ValueLifetimeAnalysis::FrontierImpl &frontier,
SILBuilderContext &builderCtxt,
InstModCallbacks callbacks);

Expand Down
7 changes: 4 additions & 3 deletions lib/SILOptimizer/Utils/ValueLifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ SILInstruction *ValueLifetimeAnalysis::findLastUserInBlock(SILBasicBlock *bb) {
llvm_unreachable("Expected to find use of value in block!");
}

bool ValueLifetimeAnalysis::computeFrontier(Frontier &frontier, Mode mode,
bool ValueLifetimeAnalysis::computeFrontier(FrontierImpl &frontier, Mode mode,
DeadEndBlocks *deBlocks) {
assert(!isAliveAtBeginOfBlock(getFunction()->getEntryBlock()) &&
"Can't compute frontier for def which does not dominate all uses");
Expand Down Expand Up @@ -287,7 +287,7 @@ blockContainsDeallocRef(SILBasicBlock *bb,
return false;
}

bool ValueLifetimeAnalysis::containsDeallocRef(const Frontier &frontier) {
bool ValueLifetimeAnalysis::containsDeallocRef(const FrontierImpl &frontier) {
SmallPtrSet<SILBasicBlock *, 8> frontierBlocks;
// Search in live blocks where the value is not alive until the end of the
// block, i.e. the live range is terminated by a frontier instruction.
Expand Down Expand Up @@ -326,7 +326,8 @@ void ValueLifetimeAnalysis::dump() const {
}

void swift::endLifetimeAtFrontier(
SILValue valueOrStackLoc, const ValueLifetimeAnalysis::Frontier &frontier,
SILValue valueOrStackLoc,
const ValueLifetimeAnalysis::FrontierImpl &frontier,
SILBuilderContext &builderCtxt, InstModCallbacks callbacks) {
for (SILInstruction *endPoint : frontier) {
SILBuilderWithScope builder(endPoint, builderCtxt);
Expand Down