Skip to content

Commit 765d23b

Browse files
committed
[NFC] IRGen: Clarify metadata collection helper.
Gather the circumstances under which the collector should be used and what it should collect separately and then collect only in one place if collection should happen.
1 parent 1253dba commit 765d23b

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

lib/IRGen/Outlining.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,29 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
151151
}
152152

153153
bool TypeInfo::withWitnessableMetadataCollector(
154-
IRGenFunction &IGF, SILType T, LayoutIsNeeded_t needsLayout,
154+
IRGenFunction &IGF, SILType T, LayoutIsNeeded_t mayNeedLayout,
155155
DeinitIsNeeded_t needsDeinit,
156156
llvm::function_ref<void(OutliningMetadataCollector &)> invocation) const {
157+
bool needsCollector = false;
158+
LayoutIsNeeded_t needsLayout = LayoutIsNotNeeded;
157159
if (!T.hasLocalArchetype() &&
158160
!IGF.outliningCanCallValueWitnesses()) {
159-
OutliningMetadataCollector collector(IGF, needsLayout, needsDeinit);
161+
needsCollector = true;
160162
if (T.hasArchetype()) {
161-
collectMetadataForOutlining(collector, T);
163+
needsLayout = LayoutIsNeeded;
162164
}
163-
invocation(collector);
164-
return true;
165+
} else if (!T.hasArchetype()) {
166+
needsCollector = true;
167+
// The implementation will call vwt in this case.
168+
needsLayout = LayoutIsNotNeeded;
165169
}
166170

167-
if (!T.hasArchetype()) {
168-
// The implementation will call vwt in this case.
171+
if (needsCollector) {
169172
OutliningMetadataCollector collector(IGF, needsLayout, needsDeinit);
173+
if (needsDeinit || needsLayout) {
174+
// Only collect if anything would be collected.
175+
collectMetadataForOutlining(collector, T);
176+
}
170177
invocation(collector);
171178
return true;
172179
}
@@ -198,10 +205,8 @@ void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
198205
}
199206

200207
void OutliningMetadataCollector::emitCallToOutlinedCopy(
201-
Address dest, Address src,
202-
SILType T, const TypeInfo &ti,
203-
IsInitialization_t isInit, IsTake_t isTake) const {
204-
assert(needsLayout);
208+
Address dest, Address src, SILType T, const TypeInfo &ti,
209+
IsInitialization_t isInit, IsTake_t isTake) const {
205210
assert(!needsDeinit);
206211
llvm::SmallVector<llvm::Value *, 4> args;
207212
args.push_back(IGF.Builder.CreateElementBitCast(src, ti.getStorageType())
@@ -387,8 +392,7 @@ void TypeInfo::callOutlinedDestroy(IRGenFunction &IGF,
387392
}
388393

389394
void OutliningMetadataCollector::emitCallToOutlinedDestroy(
390-
Address addr, SILType T, const TypeInfo &ti) const {
391-
assert(needsLayout);
395+
Address addr, SILType T, const TypeInfo &ti) const {
392396
assert(needsDeinit);
393397
llvm::SmallVector<llvm::Value *, 4> args;
394398
args.push_back(IGF.Builder.CreateElementBitCast(addr, ti.getStorageType())

0 commit comments

Comments
 (0)