Skip to content

Commit a4b8255

Browse files
authored
Merge pull request #31517 from gottesmm/pr-21ee1341c442c91af419f44d230f9528f6dd9dba
[silgen] Instead of creating a single CleanupCloner for an RValue, use a helper routine that stores into an outarray a cloner for each ManagedValue in the RValue.
2 parents 2370197 + 05667e4 commit a4b8255

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

lib/SILGen/Cleanup.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,19 @@ CleanupCloner::CleanupCloner(SILGenFunction &SGF, const ManagedValue &mv)
349349
CleanupCloner::CleanupCloner(SILGenBuilder &builder, const ManagedValue &mv)
350350
: CleanupCloner(builder.getSILGenFunction(), mv) {}
351351

352-
CleanupCloner::CleanupCloner(SILGenFunction &SGF, const RValue &rv)
353-
: SGF(SGF), hasCleanup(rv.isPlusOne(SGF)), isLValue(false) {}
352+
void CleanupCloner::getClonersForRValue(
353+
SILGenBuilder &builder, const RValue &rvalue,
354+
SmallVectorImpl<CleanupCloner> &resultingCloners) {
355+
return getClonersForRValue(builder.getSILGenFunction(), rvalue,
356+
resultingCloners);
357+
}
354358

355-
CleanupCloner::CleanupCloner(SILGenBuilder &builder, const RValue &rv)
356-
: CleanupCloner(builder.getSILGenFunction(), rv) {}
359+
void CleanupCloner::getClonersForRValue(
360+
SILGenFunction &SGF, const RValue &rvalue,
361+
SmallVectorImpl<CleanupCloner> &resultingCloners) {
362+
transform(rvalue.values, std::back_inserter(resultingCloners),
363+
[&](ManagedValue mv) { return CleanupCloner(SGF, mv); });
364+
}
357365

358366
ManagedValue CleanupCloner::clone(SILValue value) const {
359367
if (isLValue) {

lib/SILGen/Cleanup.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,16 @@ class CleanupCloner {
282282
public:
283283
CleanupCloner(SILGenFunction &SGF, const ManagedValue &mv);
284284
CleanupCloner(SILGenBuilder &builder, const ManagedValue &mv);
285-
CleanupCloner(SILGenFunction &SGF, const RValue &rv);
286-
CleanupCloner(SILGenBuilder &builder, const RValue &rv);
287285

288286
ManagedValue clone(SILValue value) const;
287+
288+
static void
289+
getClonersForRValue(SILGenFunction &SGF, const RValue &rvalue,
290+
SmallVectorImpl<CleanupCloner> &resultingCloners);
291+
292+
static void
293+
getClonersForRValue(SILGenBuilder &builder, const RValue &rvalue,
294+
SmallVectorImpl<CleanupCloner> &resultingCloners);
289295
};
290296

291297
} // end namespace Lowering

lib/SILGen/RValue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Initialization;
3535
class Scope;
3636
class SILGenFunction;
3737
class TypeLowering;
38+
class CleanupCloner;
3839

3940
/// An "exploded" SIL rvalue, in which tuple values are recursively
4041
/// destructured.
@@ -71,6 +72,7 @@ class TypeLowering;
7172
class RValue {
7273
friend class swift::Lowering::Scope;
7374
friend class swift::Lowering::ArgumentSource;
75+
friend class swift::Lowering::CleanupCloner;
7476

7577
std::vector<ManagedValue> values;
7678
CanType type;

lib/SILGen/Scope.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ RValue Scope::popPreservingValue(RValue &&rv) {
8686
// recreate the RValue in the outer scope.
8787
CanType type = rv.type;
8888
unsigned numEltsRemaining = rv.elementsToBeAdded;
89-
CleanupCloner cloner(SGF, rv);
90-
llvm::SmallVector<SILValue, 4> values;
89+
SmallVector<CleanupCloner, 4> cloners;
90+
CleanupCloner::getClonersForRValue(SGF, rv, cloners);
91+
92+
SmallVector<SILValue, 4> values;
9193
std::move(rv).forwardAll(SGF, values);
9294

9395
// Lifetime any address only values that we may have.
94-
llvm::SmallVector<SILValue, 4> lifetimeExtendingBoxes;
96+
SmallVector<SILValue, 4> lifetimeExtendingBoxes;
9597
lifetimeExtendAddressOnlyRValueSubValues(SGF, loc, values,
9698
lifetimeExtendingBoxes);
9799

@@ -111,9 +113,9 @@ RValue Scope::popPreservingValue(RValue &&rv) {
111113
// Reconstruct the managed values from the underlying sil values in the outer
112114
// scope. Since the RValue wants a std::vector value, we use that instead.
113115
std::vector<ManagedValue> managedValues;
114-
std::transform(
115-
values.begin(), values.end(), std::back_inserter(managedValues),
116-
[&cloner](SILValue v) -> ManagedValue { return cloner.clone(v); });
116+
for (unsigned i : indices(values)) {
117+
managedValues.push_back(cloners[i].clone(values[i]));
118+
}
117119

118120
// And then assemble the managed values into a rvalue.
119121
return RValue(SGF, std::move(managedValues), type, numEltsRemaining);

0 commit comments

Comments
 (0)