Skip to content

Commit cccaf01

Browse files
Merge pull request #71770 from nate-chandler/rdar123203791
[NFC] IRGen: Extracted TI::withMetadataCollector.
2 parents 94b06b4 + 48e1428 commit cccaf01

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

lib/IRGen/Outlining.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,35 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
135135
env->getGenericSignature().getCanonicalSignature()};
136136
}
137137

138-
void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
139-
SILType T, IsInitialization_t isInit,
140-
IsTake_t isTake) const {
138+
bool TypeInfo::withMetadataCollector(
139+
IRGenFunction &IGF, SILType T,
140+
llvm::function_ref<void(OutliningMetadataCollector &)> invocation) const {
141141
if (!T.hasLocalArchetype() &&
142142
!IGF.outliningCanCallValueWitnesses()) {
143143
OutliningMetadataCollector collector(IGF);
144144
if (T.hasArchetype()) {
145145
collectMetadataForOutlining(collector, T);
146146
}
147-
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
148-
return;
147+
invocation(collector);
148+
return true;
149149
}
150150

151151
if (!T.hasArchetype()) {
152-
// Call the outlined copy function (the implementation will call vwt in this
153-
// case).
152+
// The implementation will call vwt in this case.
154153
OutliningMetadataCollector collector(IGF);
155-
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
154+
invocation(collector);
155+
return true;
156+
}
157+
158+
return false;
159+
}
160+
161+
void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
162+
SILType T, IsInitialization_t isInit,
163+
IsTake_t isTake) const {
164+
if (withMetadataCollector(IGF, T, [&](auto collector) {
165+
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
166+
})) {
156167
return;
157168
}
158169

@@ -345,21 +356,9 @@ void TypeInfo::callOutlinedDestroy(IRGenFunction &IGF,
345356
if (IGF.IGM.getTypeLowering(T).isTrivial())
346357
return;
347358

348-
if (!T.hasLocalArchetype() &&
349-
!IGF.outliningCanCallValueWitnesses()) {
350-
OutliningMetadataCollector collector(IGF);
351-
if (T.hasArchetype()) {
352-
collectMetadataForOutlining(collector, T);
353-
}
354-
collector.emitCallToOutlinedDestroy(addr, T, *this);
355-
return;
356-
}
357-
358-
if (!T.hasArchetype()) {
359-
// Call the outlined copy function (the implementation will call vwt in this
360-
// case).
361-
OutliningMetadataCollector collector(IGF);
362-
collector.emitCallToOutlinedDestroy(addr, T, *this);
359+
if (withMetadataCollector(IGF, T, [&](auto collector) {
360+
collector.emitCallToOutlinedDestroy(addr, T, *this);
361+
})) {
363362
return;
364363
}
365364

lib/IRGen/TypeInfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@ class TypeInfo {
569569
virtual void verify(IRGenTypeVerifierFunction &IGF,
570570
llvm::Value *typeMetadata,
571571
SILType T) const;
572+
/// Perform \p invocation with the appropriate metadata collector if there is
573+
/// one.
574+
///
575+
/// Returns whether there was an appropriate metadata collector (and whether
576+
/// \p invocation was called.
577+
bool withMetadataCollector(
578+
IRGenFunction &IGF, SILType T,
579+
llvm::function_ref<void(OutliningMetadataCollector &)> invocation) const;
572580

573581
void callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
574582
SILType T, IsInitialization_t isInit,

0 commit comments

Comments
 (0)