@@ -2657,6 +2657,8 @@ bool SimplifyCFG::simplifyBlocks() {
2657
2657
for (auto &BB : Fn)
2658
2658
addToWorklist (&BB);
2659
2659
2660
+ bool hasOwnership = Fn.hasOwnership ();
2661
+
2660
2662
// Iteratively simplify while there is still work to do.
2661
2663
while (SILBasicBlock *BB = popWorklist ()) {
2662
2664
// If the block is dead, remove it.
@@ -2674,6 +2676,11 @@ bool SimplifyCFG::simplifyBlocks() {
2674
2676
Changed = true ;
2675
2677
continue ;
2676
2678
}
2679
+
2680
+ // We do not jump thread at all now.
2681
+ if (hasOwnership)
2682
+ continue ;
2683
+
2677
2684
// If this unconditional branch has BBArgs, check to see if duplicating
2678
2685
// the destination would allow it to be simplified. This is a simple form
2679
2686
// of jump threading.
@@ -2686,10 +2693,14 @@ bool SimplifyCFG::simplifyBlocks() {
2686
2693
Changed |= simplifyCondBrBlock (cast<CondBranchInst>(TI));
2687
2694
break ;
2688
2695
case TermKind::SwitchValueInst:
2696
+ if (hasOwnership)
2697
+ continue ;
2689
2698
// FIXME: Optimize for known switch values.
2690
2699
Changed |= simplifySwitchValueBlock (cast<SwitchValueInst>(TI));
2691
2700
break ;
2692
2701
case TermKind::SwitchEnumInst: {
2702
+ if (hasOwnership)
2703
+ continue ;
2693
2704
auto *SEI = cast<SwitchEnumInst>(TI);
2694
2705
if (simplifySwitchEnumBlock (SEI)) {
2695
2706
Changed = true ;
@@ -2705,31 +2716,49 @@ bool SimplifyCFG::simplifyBlocks() {
2705
2716
Changed |= simplifyUnreachableBlock (cast<UnreachableInst>(TI));
2706
2717
break ;
2707
2718
case TermKind::CheckedCastBranchInst:
2719
+ if (hasOwnership)
2720
+ continue ;
2708
2721
Changed |= simplifyCheckedCastBranchBlock (cast<CheckedCastBranchInst>(TI));
2709
2722
break ;
2710
2723
case TermKind::CheckedCastValueBranchInst:
2724
+ if (hasOwnership)
2725
+ continue ;
2711
2726
Changed |= simplifyCheckedCastValueBranchBlock (
2712
2727
cast<CheckedCastValueBranchInst>(TI));
2713
2728
break ;
2714
2729
case TermKind::CheckedCastAddrBranchInst:
2730
+ if (hasOwnership)
2731
+ continue ;
2715
2732
Changed |= simplifyCheckedCastAddrBranchBlock (cast<CheckedCastAddrBranchInst>(TI));
2716
2733
break ;
2717
2734
case TermKind::TryApplyInst:
2735
+ if (hasOwnership)
2736
+ continue ;
2718
2737
Changed |= simplifyTryApplyBlock (cast<TryApplyInst>(TI));
2719
2738
break ;
2720
2739
case TermKind::SwitchEnumAddrInst:
2740
+ if (hasOwnership)
2741
+ continue ;
2721
2742
Changed |= simplifyTermWithIdenticalDestBlocks (BB);
2722
2743
break ;
2723
2744
case TermKind::ThrowInst:
2724
2745
case TermKind::DynamicMethodBranchInst:
2725
2746
case TermKind::ReturnInst:
2726
2747
case TermKind::UnwindInst:
2727
2748
case TermKind::YieldInst:
2749
+ if (hasOwnership)
2750
+ continue ;
2728
2751
break ;
2729
2752
case TermKind::AwaitAsyncContinuationInst:
2753
+ if (hasOwnership)
2754
+ continue ;
2730
2755
// TODO(async): Simplify AwaitAsyncContinuationInst
2731
2756
break ;
2732
2757
}
2758
+
2759
+ if (hasOwnership)
2760
+ continue ;
2761
+
2733
2762
// If the block has a cond_fail, try to move it to the predecessors.
2734
2763
Changed |= tryMoveCondFailToPreds (BB);
2735
2764
@@ -3170,9 +3199,16 @@ bool SimplifyCFG::run() {
3170
3199
// First remove any block not reachable from the entry.
3171
3200
bool Changed = removeUnreachableBlocks (Fn);
3172
3201
3173
- // If we have ownership bail. We jus4t want to remove unreachable blocks.
3174
- if (Fn.hasOwnership ())
3202
+ // If we have ownership bail. We just want to remove unreachable blocks and
3203
+ // simplify.
3204
+ if (Fn.hasOwnership ()) {
3205
+ DT = nullptr ;
3206
+ if (simplifyBlocks ()) {
3207
+ removeUnreachableBlocks (Fn);
3208
+ Changed = true ;
3209
+ }
3175
3210
return Changed;
3211
+ }
3176
3212
3177
3213
// Find the set of loop headers. We don't want to jump-thread through headers.
3178
3214
findLoopHeaders ();
@@ -3900,6 +3936,7 @@ bool SimplifyCFG::simplifyProgramTerminationBlock(SILBasicBlock *BB) {
3900
3936
#include " swift/AST/ReferenceStorage.def"
3901
3937
case SILInstructionKind::StrongReleaseInst:
3902
3938
case SILInstructionKind::ReleaseValueInst:
3939
+ case SILInstructionKind::DestroyValueInst:
3903
3940
case SILInstructionKind::DestroyAddrInst:
3904
3941
break ;
3905
3942
default :
@@ -3942,8 +3979,6 @@ class JumpThreadSimplifyCFGPass : public SILFunctionTransform {
3942
3979
public:
3943
3980
void run () override {
3944
3981
// FIXME: Handle ownership.
3945
- if (getFunction ()->hasOwnership ())
3946
- return ;
3947
3982
if (SimplifyCFG (*getFunction (), *this , getOptions ().VerifyAll ,
3948
3983
/* EnableJumpThread=*/ true )
3949
3984
.run ())
0 commit comments