Skip to content

Commit 71dbf14

Browse files
authored
[clang][bytecode][NFC] Remove Descriptor::MoveFn (#152317)
We don't use this anymore.
1 parent bd9117c commit 71dbf14

File tree

2 files changed

+6
-93
lines changed

2 files changed

+6
-93
lines changed

clang/lib/AST/ByteCode/Descriptor.cpp

Lines changed: 6 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,6 @@ static void dtorArrayDesc(Block *B, std::byte *Ptr, const Descriptor *D) {
153153
}
154154
}
155155

156-
static void moveArrayDesc(Block *B, std::byte *Src, std::byte *Dst,
157-
const Descriptor *D) {
158-
const unsigned NumElems = D->getNumElems();
159-
const unsigned ElemSize =
160-
D->ElemDesc->getAllocSize() + sizeof(InlineDescriptor);
161-
162-
unsigned ElemOffset = 0;
163-
for (unsigned I = 0; I < NumElems; ++I, ElemOffset += ElemSize) {
164-
auto *SrcPtr = Src + ElemOffset;
165-
auto *DstPtr = Dst + ElemOffset;
166-
167-
auto *SrcDesc = reinterpret_cast<InlineDescriptor *>(SrcPtr);
168-
auto *SrcElemLoc = reinterpret_cast<std::byte *>(SrcDesc + 1);
169-
auto *DstDesc = reinterpret_cast<InlineDescriptor *>(DstPtr);
170-
auto *DstElemLoc = reinterpret_cast<std::byte *>(DstDesc + 1);
171-
172-
*DstDesc = *SrcDesc;
173-
if (auto Fn = D->ElemDesc->MoveFn)
174-
Fn(B, SrcElemLoc, DstElemLoc, D->ElemDesc);
175-
}
176-
}
177-
178156
static void initField(Block *B, std::byte *Ptr, bool IsConst, bool IsMutable,
179157
bool IsVolatile, bool IsActive, bool IsUnionField,
180158
bool InUnion, const Descriptor *D, unsigned FieldOffset) {
@@ -268,45 +246,6 @@ static void dtorRecord(Block *B, std::byte *Ptr, const Descriptor *D) {
268246
destroyBase(B, Ptr, F.Desc, F.Offset);
269247
}
270248

271-
static void moveRecord(Block *B, std::byte *Src, std::byte *Dst,
272-
const Descriptor *D) {
273-
assert(D);
274-
assert(D->ElemRecord);
275-
276-
// FIXME: Code duplication.
277-
for (const auto &F : D->ElemRecord->fields()) {
278-
auto FieldOffset = F.Offset;
279-
const auto *SrcDesc =
280-
reinterpret_cast<const InlineDescriptor *>(Src + FieldOffset) - 1;
281-
auto *DestDesc =
282-
reinterpret_cast<InlineDescriptor *>(Dst + FieldOffset) - 1;
283-
std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
284-
285-
if (auto Fn = F.Desc->MoveFn)
286-
Fn(B, Src + FieldOffset, Dst + FieldOffset, F.Desc);
287-
}
288-
289-
for (const auto &Base : D->ElemRecord->bases()) {
290-
auto BaseOffset = Base.Offset;
291-
const auto *SrcDesc =
292-
reinterpret_cast<const InlineDescriptor *>(Src + BaseOffset) - 1;
293-
auto *DestDesc = reinterpret_cast<InlineDescriptor *>(Dst + BaseOffset) - 1;
294-
std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
295-
296-
if (auto Fn = Base.Desc->MoveFn)
297-
Fn(B, Src + BaseOffset, Dst + BaseOffset, Base.Desc);
298-
}
299-
300-
for (const auto &VBase : D->ElemRecord->virtual_bases()) {
301-
auto VBaseOffset = VBase.Offset;
302-
const auto *SrcDesc =
303-
reinterpret_cast<const InlineDescriptor *>(Src + VBaseOffset) - 1;
304-
auto *DestDesc =
305-
reinterpret_cast<InlineDescriptor *>(Dst + VBaseOffset) - 1;
306-
std::memcpy(DestDesc, SrcDesc, sizeof(InlineDescriptor));
307-
}
308-
}
309-
310249
static BlockCtorFn getCtorPrim(PrimType Type) {
311250
// Floating types are special. They are primitives, but need their
312251
// constructor called.
@@ -337,18 +276,6 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
337276
COMPOSITE_TYPE_SWITCH(Type, return dtorTy<T>, return nullptr);
338277
}
339278

340-
static BlockMoveFn getMovePrim(PrimType Type) {
341-
if (Type == PT_Float)
342-
return moveTy<PrimConv<PT_Float>::T>;
343-
if (Type == PT_IntAP)
344-
return moveTy<PrimConv<PT_IntAP>::T>;
345-
if (Type == PT_IntAPS)
346-
return moveTy<PrimConv<PT_IntAPS>::T>;
347-
if (Type == PT_MemberPtr)
348-
return moveTy<PrimConv<PT_MemberPtr>::T>;
349-
COMPOSITE_TYPE_SWITCH(Type, return moveTy<T>, return nullptr);
350-
}
351-
352279
static BlockCtorFn getCtorArrayPrim(PrimType Type) {
353280
TYPE_SWITCH(Type, return ctorArrayTy<T>);
354281
llvm_unreachable("unknown Expr");
@@ -359,11 +286,6 @@ static BlockDtorFn getDtorArrayPrim(PrimType Type) {
359286
llvm_unreachable("unknown Expr");
360287
}
361288

362-
static BlockMoveFn getMoveArrayPrim(PrimType Type) {
363-
TYPE_SWITCH(Type, return moveArrayTy<T>);
364-
llvm_unreachable("unknown Expr");
365-
}
366-
367289
/// Primitives.
368290
Descriptor::Descriptor(const DeclTy &D, const Type *SourceTy, PrimType Type,
369291
MetadataSize MD, bool IsConst, bool IsTemporary,
@@ -372,7 +294,7 @@ Descriptor::Descriptor(const DeclTy &D, const Type *SourceTy, PrimType Type,
372294
MDSize(MD.value_or(0)), AllocSize(align(Size + MDSize)), PrimT(Type),
373295
IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
374296
IsVolatile(IsVolatile), CtorFn(getCtorPrim(Type)),
375-
DtorFn(getDtorPrim(Type)), MoveFn(getMovePrim(Type)) {
297+
DtorFn(getDtorPrim(Type)) {
376298
assert(AllocSize >= Size);
377299
assert(Source && "Missing source");
378300
}
@@ -386,7 +308,7 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
386308
AllocSize(align(MDSize) + align(Size) + sizeof(InitMapPtr)), PrimT(Type),
387309
IsConst(IsConst), IsMutable(IsMutable), IsTemporary(IsTemporary),
388310
IsArray(true), CtorFn(getCtorArrayPrim(Type)),
389-
DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
311+
DtorFn(getDtorArrayPrim(Type)) {
390312
assert(Source && "Missing source");
391313
assert(NumElems <= (MaxArrayElemBytes / ElemSize));
392314
}
@@ -399,7 +321,7 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, MetadataSize MD,
399321
AllocSize(MDSize + sizeof(InitMapPtr) + alignof(void *)), PrimT(Type),
400322
IsConst(IsConst), IsMutable(false), IsTemporary(IsTemporary),
401323
IsArray(true), CtorFn(getCtorArrayPrim(Type)),
402-
DtorFn(getDtorArrayPrim(Type)), MoveFn(getMoveArrayPrim(Type)) {
324+
DtorFn(getDtorArrayPrim(Type)) {
403325
assert(Source && "Missing source");
404326
}
405327

@@ -414,7 +336,7 @@ Descriptor::Descriptor(const DeclTy &D, const Type *SourceTy,
414336
AllocSize(std::max<size_t>(alignof(void *), Size) + MDSize),
415337
ElemDesc(Elem), IsConst(IsConst), IsMutable(IsMutable),
416338
IsTemporary(IsTemporary), IsArray(true), CtorFn(ctorArrayDesc),
417-
DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
339+
DtorFn(dtorArrayDesc) {
418340
assert(Source && "Missing source");
419341
}
420342

@@ -425,7 +347,7 @@ Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize MD,
425347
Size(UnknownSizeMark), MDSize(MD.value_or(0)),
426348
AllocSize(MDSize + alignof(void *)), ElemDesc(Elem), IsConst(true),
427349
IsMutable(false), IsTemporary(IsTemporary), IsArray(true),
428-
CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc), MoveFn(moveArrayDesc) {
350+
CtorFn(ctorArrayDesc), DtorFn(dtorArrayDesc) {
429351
assert(Source && "Missing source");
430352
}
431353

@@ -437,7 +359,7 @@ Descriptor::Descriptor(const DeclTy &D, const Record *R, MetadataSize MD,
437359
Size(ElemSize), MDSize(MD.value_or(0)), AllocSize(Size + MDSize),
438360
ElemRecord(R), IsConst(IsConst), IsMutable(IsMutable),
439361
IsTemporary(IsTemporary), IsVolatile(IsVolatile), CtorFn(ctorRecord),
440-
DtorFn(dtorRecord), MoveFn(moveRecord) {
362+
DtorFn(dtorRecord) {
441363
assert(Source && "Missing source");
442364
}
443365

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ using BlockCtorFn = void (*)(Block *Storage, std::byte *FieldPtr, bool IsConst,
4141
using BlockDtorFn = void (*)(Block *Storage, std::byte *FieldPtr,
4242
const Descriptor *FieldDesc);
4343

44-
/// Invoked when a block with pointers referencing it goes out of scope. Such
45-
/// blocks are persisted: the move function copies all inline descriptors and
46-
/// non-trivial fields, as existing pointers might need to reference those
47-
/// descriptors. Data is not copied since it cannot be legally read.
48-
using BlockMoveFn = void (*)(Block *Storage, std::byte *SrcFieldPtr,
49-
std::byte *DstFieldPtr,
50-
const Descriptor *FieldDesc);
51-
5244
enum class GlobalInitState {
5345
Initialized,
5446
NoInitializer,
@@ -181,7 +173,6 @@ struct Descriptor final {
181173
/// Storage management methods.
182174
const BlockCtorFn CtorFn = nullptr;
183175
const BlockDtorFn DtorFn = nullptr;
184-
const BlockMoveFn MoveFn = nullptr;
185176

186177
/// Allocates a descriptor for a primitive.
187178
Descriptor(const DeclTy &D, const Type *SourceTy, PrimType Type,

0 commit comments

Comments
 (0)