mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[NFC] SideEffectAnalysis refactoring and cleanup.
Make this a generic analysis so that it can be used to analyze any kind of function effect. FunctionSideEffect becomes a trivial specialization of the analysis. The immediate need for this is to introduce an new AccessedStorageAnalysis, although I foresee it as a generally very useful utility. This way, new kinds of function effects can be computed without adding any complexity or compile time to FunctionSideEffects. We have the flexibility of computing different kinds of function effects at different points in the pipeline. In the case of AccessedStorageAnalysis, it will compute both FunctionSideEffects and FunctionAccessedStorage in the same pass by implementing a simple wrapper on top of FunctionEffects. This cleanup reflects my feeling that nested classes make the code extremely unreadable unless they are very small and either private or only used directly via its parent class. It's easier to see how these classes compose with a flat type system. In addition to enabling new kinds of function effects analyses, I think this makes the implementation of side effect analysis easier to understand by separating concerns.
This commit is contained in:
@@ -874,8 +874,8 @@ bool CSE::canHandle(SILInstruction *Inst) {
|
||||
|
||||
// We can CSE function calls which do not read or write memory and don't
|
||||
// have any other side effects.
|
||||
SideEffectAnalysis::FunctionEffects Effects;
|
||||
SEA->getEffects(Effects, AI);
|
||||
FunctionSideEffects Effects;
|
||||
SEA->getCalleeEffects(Effects, AI);
|
||||
|
||||
// Note that the function also may not contain any retains. And there are
|
||||
// functions which are read-none and have a retain, e.g. functions which
|
||||
|
||||
Reference in New Issue
Block a user