Files
swift-mirror/include/swift/SILAnalysis/LoopAnalysis.h
Michael Gottesman 24c138f29c Move SILLoopInfo into swiftSIL from swiftSILAnalysis so that we match the separation in between analysis and IR entities.
This follows the model of dominance info and allows me to create reachability
methods on SILBasicBlock without creating dependencies from swiftSIL to
swiftSILAnalysis.

Swift SVN r21866
2014-09-11 03:03:06 +00:00

95 lines
2.6 KiB
C++

//===-------------- LoopAnalysis.h - SIL Loop Analysis -*- C++ -*----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SILANALYSIS_LOOPINFOANALYSIS_H
#define SWIFT_SILANALYSIS_LOOPINFOANALYSIS_H
#include "swift/SIL/CFG.h"
#include "swift/SIL/LoopInfo.h"
#include "swift/SIL/SILBasicBlock.h"
#include "swift/SILAnalysis/Analysis.h"
#include "llvm/ADT/DenseMap.h"
namespace swift {
class DominanceInfo;
class SILLoop;
class SILPassManager;
}
namespace swift {
/// Computes natural loop information for SIL basic blocks.
class SILLoopAnalysis : public SILAnalysis {
using LoopInfoMap = llvm::DenseMap<SILFunction *, SILLoopInfo *>;
LoopInfoMap LoopInfos;
SILPassManager *PM;
public:
SILLoopAnalysis(SILModule *, SILPassManager *PM)
: SILAnalysis(AnalysisKind::LoopInfo), PM(PM) {}
virtual ~SILLoopAnalysis() {
for (auto LI : LoopInfos)
delete LI.second;
}
static bool classof(const SILAnalysis *S) {
return S->getKind() == AnalysisKind::LoopInfo;
}
virtual void invalidate(InvalidationKind K) {
if (K >= InvalidationKind::CFG) {
for (auto LI : LoopInfos)
delete LI.second;
// Clear the maps.
LoopInfos.clear();
}
}
virtual void invalidate(SILFunction* F, InvalidationKind K) {
if (K >= InvalidationKind::CFG) {
if (LoopInfos.count(F)) {
delete LoopInfos[F];
LoopInfos.erase(F);
}
}
}
// Computes loop information for the function using dominance information or
// returns a cached result if available.
SILLoopInfo *getLoopInfo(SILFunction *F);
/// Update the loop information with the passed analysis info.
/// Takes ownership of the analysis info.
void updateAnalysis(SILFunction *F, std::unique_ptr<SILLoopInfo> Info) {
if (LoopInfos.count(F)) {
assert(LoopInfos[F] != Info.get());
delete LoopInfos[F];
}
LoopInfos[F] = Info.release();
}
/// Release ownership of the dominance information for the function. The
/// returned unique_ptr takes ownership of the object.
std::unique_ptr<SILLoopInfo> preserveAnalysis(SILFunction *F) {
assert(LoopInfos.count(F));
std::unique_ptr<SILLoopInfo> Info(LoopInfos[F]);
LoopInfos.erase(F);
return Info;
}
};
} // end namespace swift
#endif