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