Skip to content

Commit a3f2406

Browse files
committed
[IRGen] Added getPackElementSize.
1 parent e06e4a2 commit a3f2406

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,15 +587,20 @@ void irgen::cleanupTypeMetadataPack(IRGenFunction &IGF,
587587
}
588588
}
589589

590-
Address irgen::emitStorageAddressOfPackElement(IRGenFunction &IGF,
591-
Address pack,
590+
Address irgen::emitStorageAddressOfPackElement(IRGenFunction &IGF, Address pack,
592591
llvm::Value *index,
593-
SILType elementType) {
592+
SILType elementType,
593+
CanSILPackType packType) {
594594
// When we have an indirect pack, the elements are pointers, so we can
595595
// simply index into that flat array.
596596
assert(elementType.isAddress() && "direct packs not currently supported");
597-
auto elementSize = IGF.IGM.getPointerSize();
597+
auto elementSize = getPackElementSize(IGF.IGM, packType);
598598
auto elementAddress = IGF.Builder.CreateArrayGEP(pack, index, elementSize);
599599
return IGF.Builder.CreateElementBitCast(elementAddress,
600600
IGF.IGM.getStoragePointerType(elementType));
601601
}
602+
603+
Size irgen::getPackElementSize(IRGenModule &IGM, CanSILPackType ty) {
604+
assert(ty->isElementAddress() && "not implemented for direct packs");
605+
return IGM.getPointerSize();
606+
}

lib/IRGen/GenPack.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_IRGEN_GENPACK_H
1818
#define SWIFT_IRGEN_GENPACK_H
1919

20+
#include "IRGen.h"
2021
#include "swift/AST/Types.h"
2122
#include "llvm/ADT/STLExtras.h"
2223

@@ -31,6 +32,7 @@ namespace swift {
3132
namespace irgen {
3233
class Address;
3334
class IRGenFunction;
35+
class IRGenModule;
3436
class DynamicMetadataRequest;
3537
class MetadataResponse;
3638
class StackAddress;
@@ -71,9 +73,11 @@ llvm::Value *emitIndexOfStructuralPackComponent(IRGenFunction &IGF,
7173
///
7274
/// For indirect packs, note that this is the address of the pack
7375
/// array element, not the address stored in the pack array element.
74-
Address emitStorageAddressOfPackElement(IRGenFunction &IGF,
75-
Address pack, llvm::Value *index,
76-
SILType elementType);
76+
Address emitStorageAddressOfPackElement(IRGenFunction &IGF, Address pack,
77+
llvm::Value *index, SILType elementType,
78+
CanSILPackType packType);
79+
80+
Size getPackElementSize(IRGenModule &, CanSILPackType ty);
7781

7882
} // end namespace irgen
7983
} // end namespace swift

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6894,8 +6894,8 @@ void IRGenSILFunction::visitPackElementGetInst(PackElementGetInst *i) {
68946894
auto elementType = i->getElementType();
68956895
auto &elementTI = getTypeInfo(elementType);
68966896

6897-
auto elementStorageAddr =
6898-
emitStorageAddressOfPackElement(*this, pack, index, elementType);
6897+
auto elementStorageAddr = emitStorageAddressOfPackElement(
6898+
*this, pack, index, elementType, i->getPackType());
68996899

69006900
assert(elementType.isAddress() &&
69016901
i->getPackType()->isElementAddress() &&
@@ -6910,8 +6910,8 @@ void IRGenSILFunction::visitPackElementSetInst(PackElementSetInst *i) {
69106910
llvm::Value *index = getLoweredSingletonExplosion(i->getIndex());
69116911

69126912
auto elementType = i->getElementType();
6913-
auto elementStorageAddress =
6914-
emitStorageAddressOfPackElement(*this, pack, index, elementType);
6913+
auto elementStorageAddress = emitStorageAddressOfPackElement(
6914+
*this, pack, index, elementType, i->getPackType());
69156915

69166916
assert(elementType.isAddress() &&
69176917
i->getPackType()->isElementAddress() &&

0 commit comments

Comments
 (0)