Skip to content

Commit 4151f3b

Browse files
committed
[NFC] IRGen: Promote BC TypeInfo to header.
In preparation to use it for resilient conformers.
1 parent 2ded8ba commit 4151f3b

File tree

2 files changed

+73
-72
lines changed

2 files changed

+73
-72
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -172,77 +172,6 @@ class FixedSizeArchetypeTypeInfo
172172
return new FixedSizeArchetypeTypeInfo(type, size, align, spareBits);
173173
}
174174
};
175-
176-
class BitwiseCopyableArchetypeTypeInfo
177-
: public WitnessSizedTypeInfo<BitwiseCopyableArchetypeTypeInfo> {
178-
using Self = BitwiseCopyableArchetypeTypeInfo;
179-
using Super = WitnessSizedTypeInfo<Self>;
180-
BitwiseCopyableArchetypeTypeInfo(llvm::Type *type,
181-
IsABIAccessible_t abiAccessible)
182-
: Super(type, Alignment(1), IsNotTriviallyDestroyable,
183-
IsNotBitwiseTakable, IsCopyable, abiAccessible) {}
184-
185-
public:
186-
static const BitwiseCopyableArchetypeTypeInfo *
187-
create(llvm::Type *type, IsABIAccessible_t abiAccessible) {
188-
return new Self(type, abiAccessible);
189-
}
190-
191-
void bitwiseCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
192-
SILType T, bool isOutlined) const {
193-
IGF.Builder.CreateMemCpy(destAddr, srcAddr, getSize(IGF, T));
194-
}
195-
196-
void initializeWithTake(IRGenFunction &IGF, Address destAddr, Address srcAddr,
197-
SILType T, bool isOutlined) const override {
198-
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
199-
}
200-
201-
void initializeWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
202-
SILType T, bool isOutlined) const override {
203-
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
204-
}
205-
206-
void assignWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
207-
SILType T, bool isOutlined) const override {
208-
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
209-
}
210-
211-
void assignWithTake(IRGenFunction &IGF, Address destAddr, Address srcAddr,
212-
SILType T, bool isOutlined) const override {
213-
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
214-
}
215-
216-
void destroy(IRGenFunction &IGF, Address address, SILType T,
217-
bool isOutlined) const override {
218-
// BitwiseCopyable types are trivial, so destroy is a no-op.
219-
}
220-
221-
llvm::Value *getEnumTagSinglePayload(IRGenFunction &IGF,
222-
llvm::Value *numEmptyCases,
223-
Address enumAddr, SILType T,
224-
bool isOutlined) const override {
225-
return emitGetEnumTagSinglePayloadCall(IGF, T, numEmptyCases, enumAddr);
226-
}
227-
228-
void storeEnumTagSinglePayload(IRGenFunction &IGF, llvm::Value *whichCase,
229-
llvm::Value *numEmptyCases, Address enumAddr,
230-
SILType T, bool isOutlined) const override {
231-
emitStoreEnumTagSinglePayloadCall(IGF, T, whichCase, numEmptyCases,
232-
enumAddr);
233-
}
234-
235-
void collectMetadataForOutlining(OutliningMetadataCollector &collector,
236-
SILType T) const override {
237-
// We'll need formal type metadata for this archetype.
238-
collector.collectTypeMetadataForLayout(T);
239-
}
240-
241-
TypeLayoutEntry *buildTypeLayoutEntry(IRGenModule &IGM, SILType T,
242-
bool useStructLayouts) const override {
243-
return IGM.typeLayoutCache.getOrCreateArchetypeEntry(T.getObjectType());
244-
}
245-
};
246175
} // end anonymous namespace
247176

248177
/// Emit a single protocol witness table reference.
@@ -440,7 +369,7 @@ const TypeInfo *TypeConverter::convertArchetypeType(ArchetypeType *archetype) {
440369
// The protocol won't be present in swiftinterfaces from older SDKs.
441370
if (bitwiseCopyableProtocol && IGM.getSwiftModule()->lookupConformance(
442371
archetype, bitwiseCopyableProtocol)) {
443-
return BitwiseCopyableArchetypeTypeInfo::create(storageType, abiAccessible);
372+
return BitwiseCopyableTypeInfo::create(storageType, abiAccessible);
444373
}
445374

446375
return OpaqueArchetypeTypeInfo::create(storageType, abiAccessible);

lib/IRGen/NonFixedTypeInfo.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "Address.h"
2727
#include "GenOpaque.h"
2828
#include "IndirectTypeInfo.h"
29+
#include "Outlining.h"
2930

3031
namespace swift {
3132
namespace irgen {
@@ -130,6 +131,77 @@ class WitnessSizedTypeInfo : public IndirectTypeInfo<Impl, TypeInfo> {
130131
return nullptr;
131132
}
132133
};
134+
135+
class BitwiseCopyableTypeInfo
136+
: public WitnessSizedTypeInfo<BitwiseCopyableTypeInfo> {
137+
using Self = BitwiseCopyableTypeInfo;
138+
using Super = WitnessSizedTypeInfo<Self>;
139+
BitwiseCopyableTypeInfo(llvm::Type *type,
140+
IsABIAccessible_t abiAccessible)
141+
: Super(type, Alignment(1), IsNotTriviallyDestroyable,
142+
IsNotBitwiseTakable, IsCopyable, abiAccessible) {}
143+
144+
public:
145+
static const BitwiseCopyableTypeInfo *
146+
create(llvm::Type *type, IsABIAccessible_t abiAccessible) {
147+
return new Self(type, abiAccessible);
148+
}
149+
150+
void bitwiseCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
151+
SILType T, bool isOutlined) const {
152+
IGF.Builder.CreateMemCpy(destAddr, srcAddr, getSize(IGF, T));
153+
}
154+
155+
void initializeWithTake(IRGenFunction &IGF, Address destAddr, Address srcAddr,
156+
SILType T, bool isOutlined) const override {
157+
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
158+
}
159+
160+
void initializeWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
161+
SILType T, bool isOutlined) const override {
162+
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
163+
}
164+
165+
void assignWithCopy(IRGenFunction &IGF, Address destAddr, Address srcAddr,
166+
SILType T, bool isOutlined) const override {
167+
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
168+
}
169+
170+
void assignWithTake(IRGenFunction &IGF, Address destAddr, Address srcAddr,
171+
SILType T, bool isOutlined) const override {
172+
bitwiseCopy(IGF, destAddr, srcAddr, T, isOutlined);
173+
}
174+
175+
void destroy(IRGenFunction &IGF, Address address, SILType T,
176+
bool isOutlined) const override {
177+
// BitwiseCopyable types are trivial, so destroy is a no-op.
178+
}
179+
180+
llvm::Value *getEnumTagSinglePayload(IRGenFunction &IGF,
181+
llvm::Value *numEmptyCases,
182+
Address enumAddr, SILType T,
183+
bool isOutlined) const override {
184+
return emitGetEnumTagSinglePayloadCall(IGF, T, numEmptyCases, enumAddr);
185+
}
186+
187+
void storeEnumTagSinglePayload(IRGenFunction &IGF, llvm::Value *whichCase,
188+
llvm::Value *numEmptyCases, Address enumAddr,
189+
SILType T, bool isOutlined) const override {
190+
emitStoreEnumTagSinglePayloadCall(IGF, T, whichCase, numEmptyCases,
191+
enumAddr);
192+
}
193+
194+
void collectMetadataForOutlining(OutliningMetadataCollector &collector,
195+
SILType T) const override {
196+
// We'll need formal type metadata for this archetype.
197+
collector.collectTypeMetadataForLayout(T);
198+
}
199+
200+
TypeLayoutEntry *buildTypeLayoutEntry(IRGenModule &IGM, SILType T,
201+
bool useStructLayouts) const override {
202+
return IGM.typeLayoutCache.getOrCreateArchetypeEntry(T.getObjectType());
203+
}
204+
};
133205
}
134206
}
135207

0 commit comments

Comments
 (0)