Swift Optimizer: simplification for apply, try_apply, begin_apply and partial_apply

* move the apply of partial_apply transformation from simplify-apply to simplify-partial_apply
* delete dead partial_apply instructions
* devirtualize apply, try_apply and begin_apply
This commit is contained in:
Erik Eckstein
2023-05-09 15:35:04 +02:00
parent 6488da99fa
commit 82734b6ac2
21 changed files with 368 additions and 159 deletions

View File

@@ -202,7 +202,17 @@ struct BridgedPassContext {
block.getBlock()->eraseFromParent();
}
bool tryDeleteDeadClosure(BridgedInstruction closure) const;
bool tryOptimizeApplyOfPartialApply(BridgedInstruction closure) const;
bool tryDeleteDeadClosure(BridgedInstruction closure, bool needKeepArgsAlive) const;
struct DevirtResult {
OptionalBridgedInstruction newApply;
bool cfgChanged;
};
SWIFT_IMPORT_UNSAFE
DevirtResult tryDevirtualizeApply(BridgedInstruction apply, bool isMandatory) const;
SWIFT_IMPORT_UNSAFE
OptionalBridgedValue constantFoldBuiltin(BridgedInstruction builtin) const;

View File

@@ -69,7 +69,8 @@ SubstitutionMap getWitnessMethodSubstitutions(SILModule &Module, ApplySite AI,
/// Return the new apply and true if the CFG was also modified.
std::pair<ApplySite, bool>
tryDevirtualizeApply(ApplySite AI, ClassHierarchyAnalysis *CHA,
OptRemark::Emitter *ORE = nullptr);
OptRemark::Emitter *ORE = nullptr,
bool isMandatory = false);
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
bool canDevirtualizeClassMethod(FullApplySite AI, ClassDecl *CD,
OptRemark::Emitter *ORE = nullptr,
@@ -108,7 +109,9 @@ tryDevirtualizeClassMethod(FullApplySite AI, SILValue ClassInstance,
/// the original apply site.
///
/// Return the new apply and true if the CFG was also modified.
std::pair<ApplySite, bool> tryDevirtualizeWitnessMethod(ApplySite AI, OptRemark::Emitter *ORE);
std::pair<ApplySite, bool> tryDevirtualizeWitnessMethod(ApplySite AI,
OptRemark::Emitter *ORE,
bool isMandatory);
/// Delete a successfully-devirtualized apply site. This must always be
/// called after devirtualizing an apply; not only is it not semantically