@@ -55,6 +55,8 @@ class UsePrespecialized: public SILModuleTransform {
55
55
bool replaceByPrespecialized (SILFunction &F);
56
56
};
57
57
58
+ } // end anonymous namespace
59
+
58
60
// Analyze the function and replace each apply of
59
61
// a generic function by an apply of the corresponding
60
62
// pre-specialized function, if such a pre-specialization exists.
@@ -143,12 +145,17 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
143
145
<< " : " << NewF->getName () << " \n " );
144
146
145
147
auto NewAI = replaceWithSpecializedFunction (AI, NewF, ReInfo);
146
- if (auto oldApply = dyn_cast<ApplyInst>(AI)) {
147
- oldApply->replaceAllUsesWith (cast<ApplyInst>(NewAI));
148
- } else if (auto oldPApply = dyn_cast<PartialApplyInst>(AI)) {
149
- oldPApply->replaceAllUsesWith (cast<PartialApplyInst>(NewAI));
150
- } else {
151
- assert (isa<TryApplyInst>(NewAI) || isa<BeginApplyInst>(NewAI));
148
+ switch (AI.getKind ()) {
149
+ case ApplySiteKind::ApplyInst:
150
+ cast<ApplyInst>(AI)->replaceAllUsesWith (cast<ApplyInst>(NewAI));
151
+ break ;
152
+ case ApplySiteKind::PartialApplyInst:
153
+ cast<PartialApplyInst>(AI)->replaceAllUsesWith (
154
+ cast<PartialApplyInst>(NewAI));
155
+ break ;
156
+ case ApplySiteKind::TryApplyInst:
157
+ case ApplySiteKind::BeginApplyInst:
158
+ break ;
152
159
}
153
160
recursivelyDeleteTriviallyDeadInstructions (AI.getInstruction (), true );
154
161
Changed = true ;
@@ -157,8 +164,6 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
157
164
return Changed;
158
165
}
159
166
160
- } // end anonymous namespace
161
-
162
167
163
168
SILTransform *swift::createUsePrespecialized () {
164
169
return new UsePrespecialized ();
0 commit comments