@@ -393,6 +393,43 @@ bool swift::isLetAddress(SILValue address) {
393393 return isLetForBase (base);
394394}
395395
396+ // ===----------------------------------------------------------------------===//
397+ // MARK: Deinitialization barriers.
398+ // ===----------------------------------------------------------------------===//
399+
400+ static bool isBarrierApply (FullApplySite) {
401+ // TODO: check side effect analysis
402+ return true ;
403+ }
404+
405+ static bool mayAccessPointer (SILInstruction *instruction) {
406+ if (!instruction->mayReadOrWriteMemory ())
407+ return false ;
408+ bool fail = false ;
409+ visitAccessedAddress (instruction, [&fail](Operand *operand) {
410+ auto accessStorage = AccessStorage::compute (operand->get ());
411+ if (accessStorage.getKind () != AccessRepresentation::Kind::Unidentified)
412+ fail = true ;
413+ });
414+ return fail;
415+ }
416+
417+ static bool mayLoadWeakOrUnowned (SILInstruction *instruction) {
418+ // TODO: It is possible to do better here by looking at the address that is
419+ // being loaded.
420+ return isa<LoadWeakInst>(instruction) || isa<LoadUnownedInst>(instruction);
421+ }
422+
423+ bool swift::isDeinitBarrier (SILInstruction *instruction) {
424+ if (instruction->maySynchronize ()) {
425+ if (auto apply = FullApplySite::isa (instruction)) {
426+ return isBarrierApply (apply);
427+ }
428+ return true ;
429+ }
430+ return mayLoadWeakOrUnowned (instruction) || mayAccessPointer (instruction);
431+ }
432+
396433// ===----------------------------------------------------------------------===//
397434// MARK: AccessRepresentation
398435// ===----------------------------------------------------------------------===//
0 commit comments