@@ -256,7 +256,7 @@ class BridgedProperty : public OutlinePattern {
256
256
std::string getOutlinedFunctionName () override ;
257
257
258
258
private:
259
- bool matchMethodCall (SILBasicBlock::iterator);
259
+ bool matchMethodCall (SILBasicBlock::iterator, LoadInst * );
260
260
CanSILFunctionType getOutlinedFunctionType (SILModule &M);
261
261
void clearState ();
262
262
};
@@ -546,7 +546,8 @@ static bool matchSwitch(SwitchInfo &SI, SILInstruction *Inst,
546
546
return true ;
547
547
}
548
548
549
- bool BridgedProperty::matchMethodCall (SILBasicBlock::iterator It) {
549
+ bool BridgedProperty::matchMethodCall (SILBasicBlock::iterator It,
550
+ LoadInst *Load) {
550
551
// Matches:
551
552
// %33 = objc_method %31 : $UITextField, #UITextField.text!getter.foreign : (UITextField) -> () -> String?, $@convention(objc_method) (UITextField) -> @autoreleased Optional<NSString>
552
553
// %34 = apply %33(%31) : $@convention(objc_method) (UITextField) -> @autoreleased Optional<NSString>
@@ -590,6 +591,44 @@ bool BridgedProperty::matchMethodCall(SILBasicBlock::iterator It) {
590
591
PropApply->getArgument (0 ) != Instance || !PropApply->hasOneUse ())
591
592
return false ;
592
593
594
+ if (Load) {
595
+ // In OSSA, there will be a destroy_value matching the earlier load [copy].
596
+ // In non-ossa, there will be a release matching the earlier retain. The
597
+ // only user of the retained value is the unowned objective-c method
598
+ // consumer.
599
+ unsigned NumUses = 0 ;
600
+ Release = nullptr ;
601
+ bool hasOwnership = Load->getFunction ()->hasOwnership ();
602
+ for (auto *Use : Load->getUses ()) {
603
+ ++NumUses;
604
+ SILInstruction *R;
605
+ if (hasOwnership) {
606
+ R = dyn_cast<DestroyValueInst>(Use->getUser ());
607
+ } else {
608
+ R = dyn_cast<StrongReleaseInst>(Use->getUser ());
609
+ }
610
+ if (R) {
611
+ if (!Release) {
612
+ Release = R;
613
+ } else {
614
+ Release = nullptr ;
615
+ break ;
616
+ }
617
+ }
618
+ }
619
+ if (!Release)
620
+ return false ;
621
+ if (hasOwnership) {
622
+ if (NumUses != 3 )
623
+ return false ;
624
+ } else {
625
+ if (NumUses != 4 )
626
+ return false ;
627
+ }
628
+ ADVANCE_ITERATOR_OR_RETURN_FALSE (It);
629
+ assert (Release == &*It);
630
+ }
631
+
593
632
// switch_enum %34 : $Optional<NSString>, case #Optional.some!enumelt: bb8, case #Optional.none!enumelt: bb9
594
633
ADVANCE_ITERATOR_OR_RETURN_FALSE (It);
595
634
return matchSwitch (switchInfo, &*It, PropApply);
@@ -653,44 +692,9 @@ bool BridgedProperty::matchInstSequence(SILBasicBlock::iterator It) {
653
692
}
654
693
}
655
694
656
- if (!matchMethodCall (It))
695
+ if (!matchMethodCall (It, Load ))
657
696
return false ;
658
697
659
- if (Load) {
660
- // In OSSA, there will be a destroy_value matching the earlier load [copy].
661
- // In non-ossa, there will be a release matching the earlier retain. The
662
- // only user of the retained value is the unowned objective-c method
663
- // consumer.
664
- unsigned NumUses = 0 ;
665
- Release = nullptr ;
666
- bool hasOwnership = Load->getFunction ()->hasOwnership ();
667
- for (auto *Use : Load->getUses ()) {
668
- ++NumUses;
669
- SILInstruction *R;
670
- if (hasOwnership) {
671
- R = dyn_cast<DestroyValueInst>(Use->getUser ());
672
- } else {
673
- R = dyn_cast<StrongReleaseInst>(Use->getUser ());
674
- }
675
- if (R) {
676
- if (!Release) {
677
- Release = R;
678
- } else {
679
- Release = nullptr ;
680
- break ;
681
- }
682
- }
683
- }
684
- if (!Release)
685
- return false ;
686
- if (hasOwnership) {
687
- if (NumUses != 3 )
688
- return false ;
689
- } else {
690
- if (NumUses != 4 )
691
- return false ;
692
- }
693
- }
694
698
return true ;
695
699
}
696
700
0 commit comments