@@ -55,6 +55,7 @@ bool Devirtualizer::devirtualizeAppliesInFunction(SILFunction &F,
55
55
llvm::SmallVector<SILInstruction *, 8 > DeadApplies;
56
56
llvm::SmallVector<ApplySite, 8 > NewApplies;
57
57
58
+ SmallVector<FullApplySite, 16 > Applies;
58
59
for (auto &BB : F) {
59
60
for (auto It = BB.begin (), End = BB.end (); It != End;) {
60
61
auto &I = *It++;
@@ -64,20 +65,22 @@ bool Devirtualizer::devirtualizeAppliesInFunction(SILFunction &F,
64
65
auto Apply = FullApplySite::isa (&I);
65
66
if (!Apply)
66
67
continue ;
68
+ Applies.push_back (Apply);
69
+ }
70
+ }
71
+ for (auto Apply : Applies) {
72
+ auto NewInstPair = tryDevirtualizeApply (Apply, CHA);
73
+ if (!NewInstPair.second )
74
+ continue ;
67
75
68
- auto NewInstPair = tryDevirtualizeApply (Apply, CHA);
69
- if (!NewInstPair.second )
70
- continue ;
71
-
72
- Changed = true ;
76
+ Changed = true ;
73
77
74
- auto *AI = Apply.getInstruction ();
75
- if (!isa<TryApplyInst>(AI))
76
- AI->replaceAllUsesWith (NewInstPair.first );
78
+ auto *AI = Apply.getInstruction ();
79
+ if (!isa<TryApplyInst>(AI))
80
+ AI->replaceAllUsesWith (NewInstPair.first );
77
81
78
- DeadApplies.push_back (AI);
79
- NewApplies.push_back (NewInstPair.second );
80
- }
82
+ DeadApplies.push_back (AI);
83
+ NewApplies.push_back (NewInstPair.second );
81
84
}
82
85
83
86
// Remove all the now-dead applies.
0 commit comments