Skip to content

Commit 7718bd1

Browse files
committed
[value-lifetime] Cleanup constructors.
1 parent c2b3be4 commit 7718bd1

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

include/swift/SILOptimizer/Utils/ValueLifetime.h

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_SILOPTIMIZER_UTILS_CFG_H
1818
#define SWIFT_SILOPTIMIZER_UTILS_CFG_H
1919

20+
#include "swift/Basic/STLExtras.h"
2021
#include "swift/SIL/SILBuilder.h"
2122
#include "swift/SIL/SILInstruction.h"
2223
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
@@ -60,18 +61,37 @@ class ValueLifetimeAnalysis {
6061
/// ValueLifetimeAnalysis with misc iterators including transform
6162
/// iterators.
6263
template <typename RangeTy>
63-
ValueLifetimeAnalysis(decltype(defValue) def, const RangeTy &userRange)
64-
: defValue(def), userSet(userRange.begin(), userRange.end()) {
64+
ValueLifetimeAnalysis(SILArgument *def, const RangeTy &useRange)
65+
: defValue(def), userSet() {
66+
for (SILInstruction *use : useRange)
67+
userSet.insert(use);
6568
propagateLiveness();
6669
}
6770

68-
/// Constructor for the value \p def considering all the value's uses.
69-
ValueLifetimeAnalysis(SILInstruction *def) : defValue(def) {
70-
for (auto result : def->getResults()) {
71-
for (Operand *op : result->getUses()) {
72-
userSet.insert(op->getUser());
73-
}
74-
}
71+
ValueLifetimeAnalysis(
72+
SILArgument *def,
73+
llvm::iterator_range<ValueBaseUseIterator> useRange)
74+
: defValue(def), userSet() {
75+
for (Operand *use : useRange)
76+
userSet.insert(use->getUser());
77+
propagateLiveness();
78+
}
79+
80+
template <typename RangeTy>
81+
ValueLifetimeAnalysis(
82+
SILInstruction *def, const RangeTy &useRange)
83+
: defValue(def), userSet() {
84+
for (SILInstruction *use : useRange)
85+
userSet.insert(use);
86+
propagateLiveness();
87+
}
88+
89+
ValueLifetimeAnalysis(
90+
SILInstruction *def,
91+
llvm::iterator_range<ValueBaseUseIterator> useRange)
92+
: defValue(def), userSet() {
93+
for (Operand *use : useRange)
94+
userSet.insert(use->getUser());
7595
propagateLiveness();
7696
}
7797

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,8 @@ specializeApplySite(SILOptFunctionBuilder &FuncBuilder, ApplySite Apply,
937937
// release it explicitly when the partial_apply is released.
938938
if (Apply.getKind() == ApplySiteKind::PartialApplyInst) {
939939
if (PAFrontier.empty()) {
940-
ValueLifetimeAnalysis VLA(cast<PartialApplyInst>(Apply));
940+
auto *PAI = cast<PartialApplyInst>(Apply);
941+
ValueLifetimeAnalysis VLA(PAI, PAI->getUses());
941942
pass.CFGChanged |= !VLA.computeFrontier(
942943
PAFrontier, ValueLifetimeAnalysis::AllowToModifyCFG);
943944
assert(!PAFrontier.empty() &&

0 commit comments

Comments
 (0)