Skip to content

Commit 58954ab

Browse files
committed
[IRGen] Added getPackElementSize.
1 parent 6dca3e9 commit 58954ab

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
@@ -865,15 +865,20 @@ void irgen::cleanupTypeMetadataPack(IRGenFunction &IGF,
865865
}
866866
}
867867

868-
Address irgen::emitStorageAddressOfPackElement(IRGenFunction &IGF,
869-
Address pack,
868+
Address irgen::emitStorageAddressOfPackElement(IRGenFunction &IGF, Address pack,
870869
llvm::Value *index,
871-
SILType elementType) {
870+
SILType elementType,
871+
CanSILPackType packType) {
872872
// When we have an indirect pack, the elements are pointers, so we can
873873
// simply index into that flat array.
874874
assert(elementType.isAddress() && "direct packs not currently supported");
875-
auto elementSize = IGF.IGM.getPointerSize();
875+
auto elementSize = getPackElementSize(IGF.IGM, packType);
876876
auto elementAddress = IGF.Builder.CreateArrayGEP(pack, index, elementSize);
877877
return IGF.Builder.CreateElementBitCast(elementAddress,
878878
IGF.IGM.getStoragePointerType(elementType));
879879
}
880+
881+
Size irgen::getPackElementSize(IRGenModule &IGM, CanSILPackType ty) {
882+
assert(ty->isElementAddress() && "not implemented for direct packs");
883+
return IGM.getPointerSize();
884+
}

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
#include "llvm/ADT/SmallVector.h"
@@ -32,6 +33,7 @@ namespace swift {
3233
namespace irgen {
3334
class Address;
3435
class IRGenFunction;
36+
class IRGenModule;
3537
class DynamicMetadataRequest;
3638
class MetadataResponse;
3739
class StackAddress;
@@ -83,9 +85,11 @@ llvm::Value *emitIndexOfStructuralPackComponent(IRGenFunction &IGF,
8385
///
8486
/// For indirect packs, note that this is the address of the pack
8587
/// array element, not the address stored in the pack array element.
86-
Address emitStorageAddressOfPackElement(IRGenFunction &IGF,
87-
Address pack, llvm::Value *index,
88-
SILType elementType);
88+
Address emitStorageAddressOfPackElement(IRGenFunction &IGF, Address pack,
89+
llvm::Value *index, SILType elementType,
90+
CanSILPackType packType);
91+
92+
Size getPackElementSize(IRGenModule &, CanSILPackType ty);
8993

9094
} // end namespace irgen
9195
} // end namespace swift

lib/IRGen/IRGenSIL.cpp

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

6900-
auto elementStorageAddr =
6901-
emitStorageAddressOfPackElement(*this, pack, index, elementType);
6900+
auto elementStorageAddr = emitStorageAddressOfPackElement(
6901+
*this, pack, index, elementType, i->getPackType());
69026902

69036903
assert(elementType.isAddress() &&
69046904
i->getPackType()->isElementAddress() &&
@@ -6913,8 +6913,8 @@ void IRGenSILFunction::visitPackElementSetInst(PackElementSetInst *i) {
69136913
llvm::Value *index = getLoweredSingletonExplosion(i->getIndex());
69146914

69156915
auto elementType = i->getElementType();
6916-
auto elementStorageAddress =
6917-
emitStorageAddressOfPackElement(*this, pack, index, elementType);
6916+
auto elementStorageAddress = emitStorageAddressOfPackElement(
6917+
*this, pack, index, elementType, i->getPackType());
69186918

69196919
assert(elementType.isAddress() &&
69206920
i->getPackType()->isElementAddress() &&

0 commit comments

Comments
 (0)