Skip to content

[NFC] IRGen: Extracted TI::withMetadataCollector. #71770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions lib/IRGen/Outlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,35 @@ irgen::getTypeAndGenericSignatureForManglingOutlineFunction(SILType type) {
env->getGenericSignature().getCanonicalSignature()};
}

void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, IsInitialization_t isInit,
IsTake_t isTake) const {
bool TypeInfo::withMetadataCollector(
IRGenFunction &IGF, SILType T,
llvm::function_ref<void(OutliningMetadataCollector &)> invocation) const {
if (!T.hasLocalArchetype() &&
!IGF.outliningCanCallValueWitnesses()) {
OutliningMetadataCollector collector(IGF);
if (T.hasArchetype()) {
collectMetadataForOutlining(collector, T);
}
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
return;
invocation(collector);
return true;
}

if (!T.hasArchetype()) {
// Call the outlined copy function (the implementation will call vwt in this
// case).
// The implementation will call vwt in this case.
OutliningMetadataCollector collector(IGF);
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
invocation(collector);
return true;
}

return false;
}

void TypeInfo::callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, IsInitialization_t isInit,
IsTake_t isTake) const {
if (withMetadataCollector(IGF, T, [&](auto collector) {
collector.emitCallToOutlinedCopy(dest, src, T, *this, isInit, isTake);
})) {
return;
}

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

if (!T.hasLocalArchetype() &&
!IGF.outliningCanCallValueWitnesses()) {
OutliningMetadataCollector collector(IGF);
if (T.hasArchetype()) {
collectMetadataForOutlining(collector, T);
}
collector.emitCallToOutlinedDestroy(addr, T, *this);
return;
}

if (!T.hasArchetype()) {
// Call the outlined copy function (the implementation will call vwt in this
// case).
OutliningMetadataCollector collector(IGF);
collector.emitCallToOutlinedDestroy(addr, T, *this);
if (withMetadataCollector(IGF, T, [&](auto collector) {
collector.emitCallToOutlinedDestroy(addr, T, *this);
})) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/IRGen/TypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ class TypeInfo {
virtual void verify(IRGenTypeVerifierFunction &IGF,
llvm::Value *typeMetadata,
SILType T) const;
/// Perform \p invocation with the appropriate metadata collector if there is
/// one.
///
/// Returns whether there was an appropriate metadata collector (and whether
/// \p invocation was called.
bool withMetadataCollector(
IRGenFunction &IGF, SILType T,
llvm::function_ref<void(OutliningMetadataCollector &)> invocation) const;

void callOutlinedCopy(IRGenFunction &IGF, Address dest, Address src,
SILType T, IsInitialization_t isInit,
Expand Down