blob: def87c2c47b468ba653218f5668fb1e05f3f13b0 [file] [log] [blame]
Ted Kremenek8e49dd62008-02-12 18:08:17 +00001//==- GRBlockCounter.h - ADT for counting block visits -------------*- C++ -*-//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines GRBlockCounter, an abstract data type used to count
11// the number of times a given block has been visited along a path
12// analyzed by GREngine.
13//
14//===----------------------------------------------------------------------===//
15
16#include "clang/Analysis/PathSensitive/GRBlockCounter.h"
17#include "llvm/ADT/ImmutableMap.h"
18
19using namespace clang;
20
21typedef llvm::ImmutableMap<unsigned,unsigned> CountMap;
22
23static inline CountMap GetMap(void* D) {
24 return CountMap(static_cast<CountMap::TreeTy*>(D));
25}
26
27static inline CountMap::Factory& GetFactory(void* F) {
28 return *static_cast<CountMap::Factory*>(F);
29}
30
31unsigned GRBlockCounter::getNumVisited(unsigned BlockID) const {
32 CountMap M = GetMap(Data);
33 CountMap::TreeTy* T = M.SlimFind(BlockID);
34 return T ? T->getValue().second : 0;
35}
36
37GRBlockCounter::Factory::Factory(llvm::BumpPtrAllocator& Alloc) {
38 F = new CountMap::Factory(Alloc);
39}
40
41GRBlockCounter::Factory::~Factory() {
42 delete static_cast<CountMap*>(F);
43}
44
45GRBlockCounter
46GRBlockCounter::Factory::IncrementCount(GRBlockCounter BC, unsigned BlockID) {
47 return GRBlockCounter(GetFactory(F).Add(GetMap(BC.Data), BlockID,
48 BC.getNumVisited(BlockID)+1).getRoot());
49}
50
51GRBlockCounter
52GRBlockCounter::Factory::GetEmptyCounter() {
53 return GRBlockCounter(GetFactory(F).GetEmptyMap().getRoot());
54}