@@ -1603,6 +1603,8 @@ class LoadableByAddress : public SILModuleTransform {
1603
1603
SmallVectorImpl<SILInstruction *> &Delete);
1604
1604
bool recreateApply (SILInstruction &I,
1605
1605
SmallVectorImpl<SILInstruction *> &Delete);
1606
+ bool recreateTupleInstr (SILInstruction &I,
1607
+ SmallVectorImpl<SILInstruction *> &Delete);
1606
1608
bool recreateConvInstr (SILInstruction &I,
1607
1609
SmallVectorImpl<SILInstruction *> &Delete);
1608
1610
bool recreateBuiltinInstr (SILInstruction &I,
@@ -2613,6 +2615,34 @@ bool LoadableByAddress::fixStoreToBlockStorageInstr(
2613
2615
return true ;
2614
2616
}
2615
2617
2618
+ bool LoadableByAddress::recreateTupleInstr (
2619
+ SILInstruction &I, SmallVectorImpl<SILInstruction *> &Delete) {
2620
+ auto *tupleInstr = dyn_cast<TupleInst>(&I);
2621
+ if (!tupleInstr)
2622
+ return false ;
2623
+
2624
+ // Check if we need to recreate the tuple:
2625
+ auto *F = tupleInstr->getFunction ();
2626
+ auto *currIRMod = getIRGenModule ()->IRGen .getGenModule (F);
2627
+ GenericEnvironment *genEnv = F->getGenericEnvironment ();
2628
+ auto resultTy = tupleInstr->getType ();
2629
+ auto newResultTy = MapperCache.getNewSILType (genEnv, resultTy, *currIRMod);
2630
+ if (resultTy == newResultTy)
2631
+ return true ;
2632
+
2633
+ // The tuple type have changed based on its members.
2634
+ // For example if one or more of them are ‘large’ loadable types
2635
+ SILBuilderWithScope tupleBuilder (tupleInstr);
2636
+ SmallVector<SILValue, 8 > elems;
2637
+ for (auto elem : tupleInstr->getElements ()) {
2638
+ elems.push_back (elem);
2639
+ }
2640
+ auto *newTuple = tupleBuilder.createTuple (tupleInstr->getLoc (), elems);
2641
+ tupleInstr->replaceAllUsesWith (newTuple);
2642
+ Delete.push_back (tupleInstr);
2643
+ return true ;
2644
+ }
2645
+
2616
2646
bool LoadableByAddress::recreateConvInstr (SILInstruction &I,
2617
2647
SmallVectorImpl<SILInstruction *> &Delete) {
2618
2648
auto *convInstr = dyn_cast<SingleValueInstruction>(&I);
@@ -2851,7 +2881,9 @@ void LoadableByAddress::run() {
2851
2881
SmallVector<SILInstruction *, 32 > Delete;
2852
2882
for (SILBasicBlock &BB : CurrF) {
2853
2883
for (SILInstruction &I : BB) {
2854
- if (recreateConvInstr (I, Delete))
2884
+ if (recreateTupleInstr (I, Delete))
2885
+ continue ;
2886
+ else if (recreateConvInstr (I, Delete))
2855
2887
continue ;
2856
2888
else if (recreateBuiltinInstr (I, Delete))
2857
2889
continue ;
0 commit comments