@@ -333,16 +333,21 @@ void DestroyHoisting::getUsedLocationsOfOperands(Bits &bits, SILInstruction *I)
333333 }
334334}
335335
336- // Set all bits of locations which instruction \p I is using. It's including
337- // parent and sub-locations (see comment in getUsedLocationsOfAddr).
336+ // NOTE: All instructions handled in
337+ // MemoryLocations::analyzeLocationUsesRecursively should also be handled
338+ // explicitly here.
339+ // Set all bits of locations which instruction \p I is using.
340+ // It's including parent and sub-locations (see comment in
341+ // getUsedLocationsOfAddr).
338342void DestroyHoisting::getUsedLocationsOfInst (Bits &bits, SILInstruction *I) {
339343 switch (I->getKind ()) {
340- case SILInstructionKind::EndBorrowInst:
341- if ( auto *LBI = dyn_cast<LoadBorrowInst>(
342- cast<EndBorrowInst>(I)-> getOperand () )) {
344+ case SILInstructionKind::EndBorrowInst: {
345+ auto op = cast<EndBorrowInst>(I)-> getOperand ();
346+ if ( auto *LBI = dyn_cast<LoadBorrowInst>(op )) {
343347 getUsedLocationsOfAddr (bits, LBI->getOperand ());
344348 }
345349 break ;
350+ }
346351 case SILInstructionKind::EndApplyInst:
347352 // Operands passed to begin_apply are alive throughout an end_apply ...
348353 getUsedLocationsOfOperands (bits, cast<EndApplyInst>(I)->getBeginApply ());
@@ -351,6 +356,19 @@ void DestroyHoisting::getUsedLocationsOfInst(Bits &bits, SILInstruction *I) {
351356 // ... or abort_apply.
352357 getUsedLocationsOfOperands (bits, cast<AbortApplyInst>(I)->getBeginApply ());
353358 break ;
359+ case SILInstructionKind::EndAccessInst:
360+ getUsedLocationsOfOperands (bits,
361+ cast<EndAccessInst>(I)->getBeginAccess ());
362+ break ;
363+ // These instructions do not access the memory location for read/write
364+ case SILInstructionKind::StructElementAddrInst:
365+ case SILInstructionKind::TupleElementAddrInst:
366+ case SILInstructionKind::WitnessMethodInst:
367+ case SILInstructionKind::OpenExistentialAddrInst:
368+ break ;
369+ case SILInstructionKind::InitExistentialAddrInst:
370+ case SILInstructionKind::InitEnumDataAddrInst:
371+ case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
354372 case SILInstructionKind::SelectEnumAddrInst:
355373 case SILInstructionKind::ExistentialMetatypeInst:
356374 case SILInstructionKind::ValueMetatypeInst:
@@ -368,6 +386,7 @@ void DestroyHoisting::getUsedLocationsOfInst(Bits &bits, SILInstruction *I) {
368386 case SILInstructionKind::ApplyInst:
369387 case SILInstructionKind::TryApplyInst:
370388 case SILInstructionKind::YieldInst:
389+ case SILInstructionKind::SwitchEnumAddrInst:
371390 getUsedLocationsOfOperands (bits, I);
372391 break ;
373392 case SILInstructionKind::DebugValueAddrInst:
@@ -765,18 +784,11 @@ class DestroyHoistingPass : public SILFunctionTransform {
765784 LLVM_DEBUG (llvm::dbgs () << " *** DestroyHoisting on function: "
766785 << F->getName () << " ***\n " );
767786
768- bool EdgeChanged = splitAllCriticalEdges (*F, nullptr , nullptr );
769-
770787 DominanceAnalysis *DA = PM->getAnalysis <DominanceAnalysis>();
771788
772789 DestroyHoisting CM (F, DA);
773790 bool InstChanged = CM.hoistDestroys ();
774791
775- if (EdgeChanged) {
776- // We split critical edges.
777- invalidateAnalysis (SILAnalysis::InvalidationKind::FunctionBody);
778- return ;
779- }
780792 if (InstChanged) {
781793 // We moved instructions.
782794 invalidateAnalysis (SILAnalysis::InvalidationKind::Instructions);
0 commit comments