Replace some DenseMap keys with simpler structures that don't need another DenseMapInfo specialization.

llvm-svn: 188580
This commit is contained in:
Benjamin Kramer 2013-08-16 21:57:06 +00:00
parent 04a452b712
commit 91c9867049
3 changed files with 18 additions and 105 deletions

View File

@ -19,7 +19,6 @@
#include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>
@ -581,35 +580,12 @@ private:
};
std::vector<StmtCheckerInfo> StmtCheckers;
struct CachedStmtCheckersKey {
unsigned StmtKind;
bool IsPreVisit;
CachedStmtCheckersKey() : StmtKind(0), IsPreVisit(false) { }
CachedStmtCheckersKey(unsigned stmtKind, bool isPreVisit)
: StmtKind(stmtKind), IsPreVisit(isPreVisit) { }
static CachedStmtCheckersKey getSentinel() {
return CachedStmtCheckersKey(~0U, false);
}
unsigned getHashValue() const {
llvm::FoldingSetNodeID ID;
ID.AddInteger(StmtKind);
ID.AddBoolean(IsPreVisit);
return ID.ComputeHash();
}
bool operator==(const CachedStmtCheckersKey &RHS) const {
return StmtKind == RHS.StmtKind && IsPreVisit == RHS.IsPreVisit;
}
};
friend struct llvm::DenseMapInfo<CachedStmtCheckersKey>;
typedef SmallVector<CheckStmtFunc, 4> CachedStmtCheckers;
typedef llvm::DenseMap<CachedStmtCheckersKey, CachedStmtCheckers>
CachedStmtCheckersMapTy;
typedef llvm::DenseMap<unsigned, CachedStmtCheckers> CachedStmtCheckersMapTy;
CachedStmtCheckersMapTy CachedStmtCheckersMap;
CachedStmtCheckers *getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit);
const CachedStmtCheckers &getCachedStmtCheckersFor(const Stmt *S,
bool isPreVisit);
std::vector<CheckObjCMessageFunc> PreObjCMessageCheckers;
std::vector<CheckObjCMessageFunc> PostObjCMessageCheckers;
@ -659,30 +635,4 @@ private:
} // end clang namespace
namespace llvm {
/// Define DenseMapInfo so that CachedStmtCheckersKey can be used as key
/// in DenseMap and DenseSets.
template <>
struct DenseMapInfo<clang::ento::CheckerManager::CachedStmtCheckersKey> {
static inline clang::ento::CheckerManager::CachedStmtCheckersKey
getEmptyKey() {
return clang::ento::CheckerManager::CachedStmtCheckersKey();
}
static inline clang::ento::CheckerManager::CachedStmtCheckersKey
getTombstoneKey() {
return clang::ento::CheckerManager::CachedStmtCheckersKey::getSentinel();
}
static unsigned
getHashValue(clang::ento::CheckerManager::CachedStmtCheckersKey S) {
return S.getHashValue();
}
static bool isEqual(clang::ento::CheckerManager::CachedStmtCheckersKey LHS,
clang::ento::CheckerManager::CachedStmtCheckersKey RHS) {
return LHS == RHS;
}
};
} // end namespace llvm
#endif

View File

@ -169,7 +169,7 @@ void CheckerManager::runCheckersForStmt(bool isPreVisit,
const Stmt *S,
ExprEngine &Eng,
bool WasInlined) {
CheckStmtContext C(isPreVisit, *getCachedStmtCheckersFor(S, isPreVisit),
CheckStmtContext C(isPreVisit, getCachedStmtCheckersFor(S, isPreVisit),
S, Eng, WasInlined);
expandGraphWithCheckers(C, Dst, Src);
}
@ -688,27 +688,23 @@ void CheckerManager::_registerForEndOfTranslationUnit(
// Implementation details.
//===----------------------------------------------------------------------===//
CheckerManager::CachedStmtCheckers *
const CheckerManager::CachedStmtCheckers &
CheckerManager::getCachedStmtCheckersFor(const Stmt *S, bool isPreVisit) {
assert(S);
CachedStmtCheckersKey key(S->getStmtClass(), isPreVisit);
CachedStmtCheckers *checkers = 0;
CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(key);
if (CCI != CachedStmtCheckersMap.end()) {
checkers = &(CCI->second);
} else {
// Find the checkers that should run for this Stmt and cache them.
checkers = &CachedStmtCheckersMap[key];
for (unsigned i = 0, e = StmtCheckers.size(); i != e; ++i) {
StmtCheckerInfo &info = StmtCheckers[i];
if (info.IsPreVisit == isPreVisit && info.IsForStmtFn(S))
checkers->push_back(info.CheckFn);
}
}
unsigned Key = (S->getStmtClass() << 1) | unsigned(isPreVisit);
CachedStmtCheckersMapTy::iterator CCI = CachedStmtCheckersMap.find(Key);
if (CCI != CachedStmtCheckersMap.end())
return CCI->second;
assert(checkers);
return checkers;
// Find the checkers that should run for this Stmt and cache them.
CachedStmtCheckers &Checkers = CachedStmtCheckersMap[Key];
for (unsigned i = 0, e = StmtCheckers.size(); i != e; ++i) {
StmtCheckerInfo &Info = StmtCheckers[i];
if (Info.IsPreVisit == isPreVisit && Info.IsForStmtFn(S))
Checkers.push_back(Info.CheckFn);
}
return Checkers;
}
CheckerManager::~CheckerManager() {

View File

@ -270,14 +270,6 @@ public:
}
};
struct RefFileOccurence {
const FileEntry *File;
const Decl *Dcl;
RefFileOccurence(const FileEntry *File, const Decl *Dcl)
: File(File), Dcl(Dcl) { }
};
class IndexingContext {
ASTContext *Ctx;
CXClientData ClientData;
@ -294,6 +286,7 @@ class IndexingContext {
ContainerMapTy ContainerMap;
EntityMapTy EntityMap;
typedef std::pair<const FileEntry *, const Decl *> RefFileOccurence;
llvm::DenseSet<RefFileOccurence> RefFileOccurences;
std::deque<DeclGroupRef> TUDeclsInObjCContainer;
@ -524,29 +517,3 @@ inline T *ScratchAlloc::allocate() {
}
}} // end clang::cxindex
namespace llvm {
/// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
/// DenseSets.
template <>
struct DenseMapInfo<clang::cxindex::RefFileOccurence> {
static inline clang::cxindex::RefFileOccurence getEmptyKey() {
return clang::cxindex::RefFileOccurence(0, 0);
}
static inline clang::cxindex::RefFileOccurence getTombstoneKey() {
return clang::cxindex::RefFileOccurence((const clang::FileEntry *)~0,
(const clang::Decl *)~0);
}
static unsigned getHashValue(clang::cxindex::RefFileOccurence S) {
typedef std::pair<const clang::FileEntry *, const clang::Decl *> PairTy;
return DenseMapInfo<PairTy>::getHashValue(PairTy(S.File, S.Dcl));
}
static bool isEqual(clang::cxindex::RefFileOccurence LHS,
clang::cxindex::RefFileOccurence RHS) {
return LHS.File == RHS.File && LHS.Dcl == RHS.Dcl;
}
};
}