summaryrefslogtreecommitdiffstats
path: root/clang/lib/EntoSA/BlockCounter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-12-23 07:22:02 +0000
committerTed Kremenek <kremenek@apple.com>2010-12-23 07:22:02 +0000
commitef33f0996c6a625767690395f3cfb41afb84db5a (patch)
treee7d0e6ec23cdcb950b06d65a125b150aba35c7f0 /clang/lib/EntoSA/BlockCounter.cpp
parent98857c986078c6e6a10910628dbabf75ae735b76 (diff)
downloadbcm5719-llvm-ef33f0996c6a625767690395f3cfb41afb84db5a.tar.gz
bcm5719-llvm-ef33f0996c6a625767690395f3cfb41afb84db5a.zip
Rename headers: 'clang/GR' 'clang/EntoSA' and
update Makefile. llvm-svn: 122493
Diffstat (limited to 'clang/lib/EntoSA/BlockCounter.cpp')
-rw-r--r--clang/lib/EntoSA/BlockCounter.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/clang/lib/EntoSA/BlockCounter.cpp b/clang/lib/EntoSA/BlockCounter.cpp
new file mode 100644
index 00000000000..b4e6eeee3f4
--- /dev/null
+++ b/clang/lib/EntoSA/BlockCounter.cpp
@@ -0,0 +1,86 @@
+//==- BlockCounter.h - ADT for counting block visits -------------*- C++ -*-//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines BlockCounter, an abstract data type used to count
+// the number of times a given block has been visited along a path
+// analyzed by CoreEngine.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/EntoSA/PathSensitive/BlockCounter.h"
+#include "llvm/ADT/ImmutableMap.h"
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+
+class CountKey {
+ const StackFrameContext *CallSite;
+ unsigned BlockID;
+
+public:
+ CountKey(const StackFrameContext *CS, unsigned ID)
+ : CallSite(CS), BlockID(ID) {}
+
+ bool operator==(const CountKey &RHS) const {
+ return (CallSite == RHS.CallSite) && (BlockID == RHS.BlockID);
+ }
+
+ bool operator<(const CountKey &RHS) const {
+ return (CallSite == RHS.CallSite) ? (BlockID < RHS.BlockID)
+ : (CallSite < RHS.CallSite);
+ }
+
+ void Profile(llvm::FoldingSetNodeID &ID) const {
+ ID.AddPointer(CallSite);
+ ID.AddInteger(BlockID);
+ }
+};
+
+}
+
+typedef llvm::ImmutableMap<CountKey, unsigned> CountMap;
+
+static inline CountMap GetMap(void* D) {
+ return CountMap(static_cast<CountMap::TreeTy*>(D));
+}
+
+static inline CountMap::Factory& GetFactory(void* F) {
+ return *static_cast<CountMap::Factory*>(F);
+}
+
+unsigned BlockCounter::getNumVisited(const StackFrameContext *CallSite,
+ unsigned BlockID) const {
+ CountMap M = GetMap(Data);
+ CountMap::data_type* T = M.lookup(CountKey(CallSite, BlockID));
+ return T ? *T : 0;
+}
+
+BlockCounter::Factory::Factory(llvm::BumpPtrAllocator& Alloc) {
+ F = new CountMap::Factory(Alloc);
+}
+
+BlockCounter::Factory::~Factory() {
+ delete static_cast<CountMap::Factory*>(F);
+}
+
+BlockCounter
+BlockCounter::Factory::IncrementCount(BlockCounter BC,
+ const StackFrameContext *CallSite,
+ unsigned BlockID) {
+ return BlockCounter(GetFactory(F).add(GetMap(BC.Data),
+ CountKey(CallSite, BlockID),
+ BC.getNumVisited(CallSite, BlockID)+1).getRoot());
+}
+
+BlockCounter
+BlockCounter::Factory::GetEmptyCounter() {
+ return BlockCounter(GetFactory(F).getEmptyMap().getRoot());
+}
OpenPOWER on IntegriCloud