Skip to content

[gardening] Change an if-else over ApplySite to a covered switch over… #22519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lib/SILOptimizer/IPO/UsePrespecialized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class UsePrespecialized: public SILModuleTransform {
bool replaceByPrespecialized(SILFunction &F);
};

} // end anonymous namespace

// Analyze the function and replace each apply of
// a generic function by an apply of the corresponding
// pre-specialized function, if such a pre-specialization exists.
Expand Down Expand Up @@ -143,12 +145,17 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
<< " : " << NewF->getName() << "\n");

auto NewAI = replaceWithSpecializedFunction(AI, NewF, ReInfo);
if (auto oldApply = dyn_cast<ApplyInst>(AI)) {
oldApply->replaceAllUsesWith(cast<ApplyInst>(NewAI));
} else if (auto oldPApply = dyn_cast<PartialApplyInst>(AI)) {
oldPApply->replaceAllUsesWith(cast<PartialApplyInst>(NewAI));
} else {
assert(isa<TryApplyInst>(NewAI) || isa<BeginApplyInst>(NewAI));
switch (AI.getKind()) {
case ApplySiteKind::ApplyInst:
cast<ApplyInst>(AI)->replaceAllUsesWith(cast<ApplyInst>(NewAI));
break;
case ApplySiteKind::PartialApplyInst:
cast<PartialApplyInst>(AI)->replaceAllUsesWith(
cast<PartialApplyInst>(NewAI));
break;
case ApplySiteKind::TryApplyInst:
case ApplySiteKind::BeginApplyInst:
break;
}
recursivelyDeleteTriviallyDeadInstructions(AI.getInstruction(), true);
Changed = true;
Expand All @@ -157,8 +164,6 @@ bool UsePrespecialized::replaceByPrespecialized(SILFunction &F) {
return Changed;
}

} // end anonymous namespace


SILTransform *swift::createUsePrespecialized() {
return new UsePrespecialized();
Expand Down