@@ -974,6 +974,9 @@ static Operand *getProjectedDefOperand(SILValue value) {
974974 case ValueKind::OpenExistentialBoxValueInst:
975975 assert (value->getOwnershipKind () == OwnershipKind::Guaranteed);
976976 return &cast<SingleValueInstruction>(value)->getAllOperands ()[0 ];
977+ case ValueKind::TuplePackExtractInst:
978+ assert (value->getOwnershipKind () == OwnershipKind::Guaranteed);
979+ return &cast<SingleValueInstruction>(value)->getAllOperands ()[1 ];
977980 }
978981}
979982
@@ -1703,6 +1706,8 @@ class AddressMaterialization {
17031706
17041707 SILValue materializeTupleExtract (SILInstruction *extractInst,
17051708 SILValue elementValue, unsigned fieldIdx);
1709+ SILValue materializeTuplePackExtract (SILInstruction *extractInst,
1710+ SILValue elementValue, SILValue index);
17061711
17071712 SILValue materializeProjectionIntoUse (Operand *operand, bool intoPhiOperand);
17081713 SILValue materializeProjectionIntoUseImpl (Operand *operand,
@@ -1859,6 +1864,11 @@ SILValue AddressMaterialization::materializeDefProjection(SILValue origValue) {
18591864 return materializeTupleExtract (extractInst, origValue,
18601865 extractInst->getFieldIndex ());
18611866 }
1867+ case ValueKind::TuplePackExtractInst: {
1868+ auto *extractInst = cast<TuplePackExtractInst>(origValue);
1869+ return materializeTuplePackExtract (extractInst, origValue,
1870+ extractInst->getIndex ());
1871+ }
18621872 case ValueKind::SILPhiArgument: {
18631873 // Handle this in the caller. unchecked_take_enum_data_addr is
18641874 // destructive. It cannot be materialized on demand.
@@ -1888,6 +1898,14 @@ SILValue AddressMaterialization::materializeTupleExtract(
18881898 elementValue->getType ().getAddressType ());
18891899}
18901900
1901+ SILValue AddressMaterialization::materializeTuplePackExtract (
1902+ SILInstruction *extractInst, SILValue elementValue, SILValue fieldIdx) {
1903+ SILValue srcAddr = pass.getMaterializedAddress (extractInst->getOperand (1 ));
1904+ return projectionBuilder.createTuplePackElementAddr (
1905+ pass.genLoc (), fieldIdx, srcAddr,
1906+ elementValue->getType ().getAddressType ());
1907+ }
1908+
18911909SILValue
18921910AddressMaterialization::materializeProjectionIntoUse (Operand *operand,
18931911 bool intoPhiOperand) {
@@ -3528,6 +3546,9 @@ class UseRewriter : SILInstructionVisitor<UseRewriter> {
35283546 // Extract from an opaque tuple.
35293547 void visitTupleExtractInst (TupleExtractInst *extractInst);
35303548
3549+ // Extract from an opaque pack tuple.
3550+ void visitTuplePackExtractInst (TuplePackExtractInst *extractInst);
3551+
35313552 void
35323553 visitUncheckedBitwiseCastInst (UncheckedBitwiseCastInst *uncheckedCastInst) {
35333554 SILValue srcVal = uncheckedCastInst->getOperand ();
@@ -3819,6 +3840,10 @@ void UseRewriter::visitTupleExtractInst(TupleExtractInst *extractInst) {
38193840 emitExtract (extractInst);
38203841}
38213842
3843+ void UseRewriter::visitTuplePackExtractInst (TuplePackExtractInst *extractInst) {
3844+ emitExtract (extractInst);
3845+ }
3846+
38223847// Rewrite switch_enum to switch_enum_addr. All associated block arguments are
38233848// removed.
38243849void UseRewriter::visitSwitchEnumInst (SwitchEnumInst * switchEnum) {
0 commit comments