Skip to content

Commit b78a649

Browse files
authored
Merge pull request #34755 from gottesmm/pr-c948d27bcce9be4feb87ece1fc46b74931415542
[value-lifetime] Cleanup constructors.
2 parents 4f37a1f + 7718bd1 commit b78a649

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"
@@ -64,18 +65,37 @@ class ValueLifetimeAnalysis {
6465
/// ValueLifetimeAnalysis with misc iterators including transform
6566
/// iterators.
6667
template <typename RangeTy>
67-
ValueLifetimeAnalysis(decltype(defValue) def, const RangeTy &userRange)
68-
: defValue(def), userSet(userRange.begin(), userRange.end()) {
68+
ValueLifetimeAnalysis(SILArgument *def, const RangeTy &useRange)
69+
: defValue(def), userSet() {
70+
for (SILInstruction *use : useRange)
71+
userSet.insert(use);
6972
propagateLiveness();
7073
}
7174

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

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)