@@ -250,6 +250,25 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
250250 return asImpl ().remapASTType (ty);
251251 }
252252
253+ // / Remap a structural index into a pack so that it will point to the
254+ // / corresponding structural index in the remapped pack type.
255+ unsigned getOpStructuralPackIndex (CanPackType origPackType,
256+ unsigned origIndex) {
257+ assert (origIndex < origPackType->getNumElements ());
258+ unsigned newIndex = 0 ;
259+ for (unsigned i = 0 ; i != origIndex; ++i) {
260+ auto origComponentType = origPackType.getElementType (i);
261+ if (auto origExpansionType =
262+ dyn_cast<PackExpansionType>(origComponentType)) {
263+ auto newShapeClass = getOpASTType (origExpansionType.getCountType ());
264+ newIndex += cast<PackType>(newShapeClass)->getNumElements ();
265+ } else {
266+ newIndex++;
267+ }
268+ }
269+ return newIndex;
270+ }
271+
253272 void remapRootOpenedType (CanOpenedArchetypeType archetypeTy) {
254273 assert (archetypeTy->isRoot ());
255274
@@ -2392,6 +2411,54 @@ void SILCloner<ImplClass>::visitDeinitExistentialValueInst(
23922411 getOpLocation (Inst->getLoc ()), getOpValue (Inst->getOperand ())));
23932412}
23942413
2414+ template <typename ImplClass>
2415+ void SILCloner<ImplClass>::visitDynamicPackIndexInst(
2416+ DynamicPackIndexInst *Inst) {
2417+ getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2418+
2419+ auto newIndexValue = getOpValue (Inst->getOperand ());
2420+ auto loc = getOpLocation (Inst->getLoc ());
2421+ auto newPackType = cast<PackType>(getOpASTType (Inst->getIndexedPackType ()));
2422+
2423+ recordClonedInstruction (
2424+ Inst, getBuilder ().createDynamicPackIndex (loc, newIndexValue,
2425+ newPackType));
2426+ }
2427+
2428+ template <typename ImplClass>
2429+ void SILCloner<ImplClass>::visitPackPackIndexInst(PackPackIndexInst *Inst) {
2430+ getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2431+
2432+ auto newIndexValue = getOpValue (Inst->getOperand ());
2433+ auto loc = getOpLocation (Inst->getLoc ());
2434+ auto newPackType = cast<PackType>(getOpASTType (Inst->getIndexedPackType ()));
2435+
2436+ auto newComponentStartIndex =
2437+ getOpStructuralPackIndex (Inst->getIndexedPackType (),
2438+ Inst->getComponentStartIndex ());
2439+
2440+ recordClonedInstruction (
2441+ Inst, getBuilder ().createPackPackIndex (loc, newComponentStartIndex,
2442+ newIndexValue, newPackType));
2443+ }
2444+
2445+ template <typename ImplClass>
2446+ void SILCloner<ImplClass>::visitScalarPackIndexInst(
2447+ ScalarPackIndexInst *Inst) {
2448+ getBuilder ().setCurrentDebugScope (getOpScope (Inst->getDebugScope ()));
2449+
2450+ auto loc = getOpLocation (Inst->getLoc ());
2451+ auto newPackType = cast<PackType>(getOpASTType (Inst->getIndexedPackType ()));
2452+
2453+ auto newComponentIndex =
2454+ getOpStructuralPackIndex (Inst->getIndexedPackType (),
2455+ Inst->getComponentIndex ());
2456+
2457+ recordClonedInstruction (
2458+ Inst, getBuilder ().createScalarPackIndex (loc, newComponentIndex,
2459+ newPackType));
2460+ }
2461+
23952462template <typename ImplClass>
23962463void SILCloner<ImplClass>::visitOpenPackElementInst(
23972464 OpenPackElementInst *Inst) {
0 commit comments