Skip to content

Commit d2de176

Browse files
committed
[sil][value-lifetime] Add ValueLifetimeAnalysis::FrontierImpl = SmallVectorImpl<SILInstruction *>
Otherwise, one is always forced to use ValueLifetimeAnalysis::Frontier, a SmallVector<SILInstruction *, 4>. This may not be a size appropriate for every problem, so it makes sense to provide Frontier as a good rule of thumb, but use FrontierImpl on the actual API boundary to loosen the constraint if the user wishes to do so.
1 parent c2b3be4 commit d2de176

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

include/swift/SILOptimizer/Utils/ValueLifetime.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ class ValueLifetimeAnalysis {
5454
/// end the value's lifetime.
5555
using Frontier = SmallVector<SILInstruction *, 4>;
5656

57+
/// A type erased version of frontier so callers can customize the inline
58+
/// size.
59+
using FrontierImpl = SmallVectorImpl<SILInstruction *>;
60+
5761
/// Constructor for the value \p def with a specific range of users.
5862
///
5963
/// We templatize over the RangeTy so that we can initialize
@@ -106,7 +110,7 @@ class ValueLifetimeAnalysis {
106110
///
107111
/// If \p deBlocks is provided, all dead-end blocks are ignored. This
108112
/// prevents unreachable-blocks to be included in the frontier.
109-
bool computeFrontier(Frontier &frontier, Mode mode,
113+
bool computeFrontier(FrontierImpl &frontier, Mode mode,
110114
DeadEndBlocks *deBlocks = nullptr);
111115

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

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

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

lib/SILOptimizer/Utils/ValueLifetime.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ SILInstruction *ValueLifetimeAnalysis::findLastUserInBlock(SILBasicBlock *bb) {
9090
llvm_unreachable("Expected to find use of value in block!");
9191
}
9292

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

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

328328
void swift::endLifetimeAtFrontier(
329-
SILValue valueOrStackLoc, const ValueLifetimeAnalysis::Frontier &frontier,
329+
SILValue valueOrStackLoc,
330+
const ValueLifetimeAnalysis::FrontierImpl &frontier,
330331
SILBuilderContext &builderCtxt, InstModCallbacks callbacks) {
331332
for (SILInstruction *endPoint : frontier) {
332333
SILBuilderWithScope builder(endPoint, builderCtxt);

0 commit comments

Comments
 (0)