Skip to content

Commit d1bd039

Browse files
committed
[IRGen] Use BC TI for resilient conformers.
Resilient types conforming to BitwiseCopyable mostly shouldn't go through the VWT for value operations, they should just use memcpy.
1 parent 4151f3b commit d1bd039

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7198,6 +7198,14 @@ ResilientEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
71987198
EnumDecl *theEnum,
71997199
llvm::StructType *enumTy) {
72007200
auto abiAccessible = IsABIAccessible_t(TC.IGM.isTypeABIAccessible(Type));
7201+
auto *bitwiseCopyableProtocol =
7202+
IGM.getSwiftModule()->getASTContext().getProtocol(
7203+
KnownProtocolKind::BitwiseCopyable);
7204+
if (bitwiseCopyableProtocol &&
7205+
IGM.getSwiftModule()->lookupConformance(
7206+
theEnum->getDeclaredInterfaceType(), bitwiseCopyableProtocol)) {
7207+
return BitwiseCopyableTypeInfo::create(enumTy, abiAccessible);
7208+
}
72017209
auto copyable = !theEnum->canBeCopyable()
72027210
? IsNotCopyable : IsCopyable;
72037211
return registerEnumTypeInfo(

lib/IRGen/GenStruct.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,14 @@ const TypeInfo *TypeConverter::convertStructType(TypeBase *key, CanType type,
16901690
? IsNotCopyable : IsCopyable;
16911691
auto structAccessible =
16921692
IsABIAccessible_t(IGM.getSILModule().isTypeMetadataAccessible(type));
1693+
auto *bitwiseCopyableProtocol =
1694+
IGM.getSwiftModule()->getASTContext().getProtocol(
1695+
KnownProtocolKind::BitwiseCopyable);
1696+
if (bitwiseCopyableProtocol &&
1697+
IGM.getSwiftModule()->lookupConformance(D->getDeclaredInterfaceType(),
1698+
bitwiseCopyableProtocol)) {
1699+
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, structAccessible);
1700+
}
16931701
return &getResilientStructTypeInfo(copyable, structAccessible);
16941702
}
16951703

lib/IRGen/GenTuple.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,13 @@ namespace {
520520

521521
const TypeInfo *TypeConverter::convertTupleType(TupleType *tuple) {
522522
if (tuple->containsPackExpansionType()) {
523+
auto *bitwiseCopyableProtocol =
524+
IGM.getSwiftModule()->getASTContext().getProtocol(
525+
KnownProtocolKind::BitwiseCopyable);
526+
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->lookupConformance(
527+
tuple, bitwiseCopyableProtocol)) {
528+
return BitwiseCopyableTypeInfo::create(IGM.OpaqueTy, IsABIAccessible);
529+
}
523530
// FIXME: Figure out if its copyable at least
524531
return &getDynamicTupleTypeInfo(IsCopyable);
525532
}
@@ -696,4 +703,4 @@ llvm::Value *irgen::emitTupleTypeMetadataElementType(IRGenFunction &IGF,
696703

697704
return IGF.Builder.CreateLoad(slot, IGF.IGM.SizeTy,
698705
IGF.IGM.getPointerAlignment());
699-
}
706+
}

lib/IRGen/NonFixedTypeInfo.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,13 @@ class BitwiseCopyableTypeInfo
136136
: public WitnessSizedTypeInfo<BitwiseCopyableTypeInfo> {
137137
using Self = BitwiseCopyableTypeInfo;
138138
using Super = WitnessSizedTypeInfo<Self>;
139-
BitwiseCopyableTypeInfo(llvm::Type *type,
140-
IsABIAccessible_t abiAccessible)
139+
BitwiseCopyableTypeInfo(llvm::Type *type, IsABIAccessible_t abiAccessible)
141140
: Super(type, Alignment(1), IsNotTriviallyDestroyable,
142141
IsNotBitwiseTakable, IsCopyable, abiAccessible) {}
143142

144143
public:
145-
static const BitwiseCopyableTypeInfo *
146-
create(llvm::Type *type, IsABIAccessible_t abiAccessible) {
144+
static BitwiseCopyableTypeInfo *create(llvm::Type *type,
145+
IsABIAccessible_t abiAccessible) {
147146
return new Self(type, abiAccessible);
148147
}
149148

0 commit comments

Comments
 (0)