mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the call graph, so we've decided to change the way passes invalidate analysis. In the new scheme, the lattice is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches. Now, passes report which traits they preserve, which is the opposite of the previous implementation where passes needed to report what they invalidate. Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some of the code in a following commit. Swift SVN r26449
This commit is contained in:
@@ -127,9 +127,11 @@ public:
|
||||
return getMemoryBehavior(Inst, V) == MemoryBehavior::MayHaveSideEffects;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) { AliasCache.clear(); }
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) { AliasCache.clear(); }
|
||||
|
||||
virtual void invalidate(SILFunction *, InvalidationKind K) { invalidate(K); }
|
||||
virtual void invalidate(SILFunction *, SILAnalysis::PreserveKind K) {
|
||||
invalidate(K);
|
||||
}
|
||||
};
|
||||
|
||||
llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
|
||||
@@ -27,15 +27,21 @@ namespace swift {
|
||||
/// The base class for all SIL-level analysis.
|
||||
class SILAnalysis {
|
||||
public:
|
||||
/// The invalidation Lattice.
|
||||
/// This is a hierarchy of invalidation messages that are sent to analysis
|
||||
/// objects. Every invalidation kind invalidates the levels before it. For
|
||||
/// example, CFG invalidates Instructions and CFG.
|
||||
enum class InvalidationKind {
|
||||
Instructions, // Invalidate instruction-related analysis.
|
||||
CFG, // The control flow changes.
|
||||
CallGraph, // The call graph changed.
|
||||
All, // Invalidate everything.
|
||||
/// This is a list of values that allow passes to communicate to analysis
|
||||
/// which traits of the code were preserved. Based on this information
|
||||
/// the analysis can decide if it needs to be invalidated. This information
|
||||
/// may refer to a specific function or to a list of functions depending
|
||||
/// on the context in which it is used.
|
||||
enum PreserveKind : unsigned {
|
||||
Nothing = 0x0, // The pass does not preserve any analysis trait.
|
||||
Calls = 0x1, // The pass did not modify any calls.
|
||||
Branches = 0x2, // The pass did not modify any branches.
|
||||
|
||||
// This is a list of combined traits that is defined to make the use of
|
||||
/// the invalidation API more convenient.
|
||||
ProgramFlow = Calls | Branches, // The pass changed some instructions but
|
||||
// did not change the overall flow
|
||||
// of the code.
|
||||
};
|
||||
|
||||
/// A list of the known analysis.
|
||||
@@ -82,10 +88,10 @@ namespace swift {
|
||||
bool isLocked() { return invalidationLock; }
|
||||
|
||||
/// Invalidate all information in this analysis.
|
||||
virtual void invalidate(InvalidationKind K) {}
|
||||
virtual void invalidate(PreserveKind K) {}
|
||||
|
||||
/// Invalidate all of the information for a specific function.
|
||||
virtual void invalidate(SILFunction *F, InvalidationKind K) {}
|
||||
virtual void invalidate(SILFunction *F, PreserveKind K) {}
|
||||
|
||||
/// Verify the state of this analysis.
|
||||
virtual void verify() const {}
|
||||
@@ -109,12 +115,12 @@ namespace swift {
|
||||
return S->getKind() == AnalysisKind::CompleteFuncs;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
virtual void invalidate(PreserveKind K) {
|
||||
IsModulePending = true;
|
||||
HasChanged = true;
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction* F, InvalidationKind) {
|
||||
virtual void invalidate(SILFunction* F, PreserveKind) {
|
||||
PendingFuncs.insert(F);
|
||||
HasChanged = true;
|
||||
}
|
||||
|
||||
@@ -356,15 +356,15 @@ public:
|
||||
return *CG;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
if (K >= InvalidationKind::CallGraph) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Calls)) {
|
||||
BottomUpFunctionOrder.clear();
|
||||
delete CG;
|
||||
CG = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction*, InvalidationKind K) { invalidate(K); }
|
||||
virtual void invalidate(SILFunction*, SILAnalysis::PreserveKind K) { invalidate(K); }
|
||||
|
||||
virtual void verify() const;
|
||||
};
|
||||
|
||||
@@ -42,12 +42,8 @@ public:
|
||||
return S->getKind() == AnalysisKind::ClassHierarchyAnalysis;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
if (K >= InvalidationKind::All) {
|
||||
DirectSubclassesCache.clear();
|
||||
IndirectSubclassesCache.clear();
|
||||
init();
|
||||
}
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
// Nothing can invalidate the ClassHierarchyAnalysis!
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +76,7 @@ public:
|
||||
IndirectSubclassesCache[C].size() > 0;
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction *F, InvalidationKind K) {
|
||||
virtual void invalidate(SILFunction *F, SILAnalysis::PreserveKind K) {
|
||||
invalidate(K);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,11 +60,9 @@ class SILInstruction;
|
||||
return S->getKind() == AnalysisKind::Dominance;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
assert(!isLocked() && "invalidating a locked analysis?!");
|
||||
// FIXME: Invalidating the call graph should not invalidate the domtrees
|
||||
// of all functions.
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
// Delete Dominance Info.
|
||||
for (auto D : DomInfo)
|
||||
delete D.second;
|
||||
@@ -79,8 +77,8 @@ class SILInstruction;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction* F, InvalidationKind K) {
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
virtual void invalidate(SILFunction* F, SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
auto &it= DomInfo.FindAndConstruct(F);
|
||||
if (it.second) {
|
||||
delete it.second;
|
||||
|
||||
@@ -94,22 +94,18 @@ public:
|
||||
return *IVInfos[F];
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
if (K >= InvalidationKind::Instructions) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
for (auto IVI : IVInfos)
|
||||
delete IVI.second;
|
||||
|
||||
IVInfos.clear();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction *F, InvalidationKind K) {
|
||||
if (K >= InvalidationKind::Instructions) {
|
||||
virtual void invalidate(SILFunction *F, SILAnalysis::PreserveKind K) {
|
||||
if (IVInfos.count(F)) {
|
||||
delete IVInfos[F];
|
||||
IVInfos.erase(F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
return S->getKind() == AnalysisKind::LoopInfo;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
for (auto LI : LoopInfos)
|
||||
delete LI.second;
|
||||
|
||||
@@ -56,8 +56,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction* F, InvalidationKind K) {
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
virtual void invalidate(SILFunction* F, SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
if (LoopInfos.count(F)) {
|
||||
delete LoopInfos[F];
|
||||
LoopInfos.erase(F);
|
||||
|
||||
@@ -98,16 +98,14 @@ public:
|
||||
return S->getKind() == AnalysisKind::PostOrder;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
// FIXME: Invalidating the call graph should not invalidate the domtrees
|
||||
// of all functions.
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
FunctionToPOTMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void invalidate(SILFunction* F, InvalidationKind K) {
|
||||
if (K >= InvalidationKind::CFG) {
|
||||
virtual void invalidate(SILFunction* F, SILAnalysis::PreserveKind K) {
|
||||
if (!(K & PreserveKind::Branches)) {
|
||||
// Invalidate just this one function. We will lazily recompute it.
|
||||
FunctionToPOTMap[F].IsInvalidated = true;
|
||||
}
|
||||
|
||||
@@ -52,14 +52,12 @@ public:
|
||||
return S->getKind() == AnalysisKind::RCIdentity;
|
||||
}
|
||||
|
||||
virtual void invalidate(InvalidationKind K) {
|
||||
if (K >= InvalidationKind::Instructions) {
|
||||
virtual void invalidate(SILAnalysis::PreserveKind K) {
|
||||
Cache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add function specific cache to save compile time.
|
||||
virtual void invalidate(SILFunction* F, InvalidationKind K) {
|
||||
virtual void invalidate(SILFunction* F, SILAnalysis::PreserveKind K) {
|
||||
invalidate(K);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user