1 //== FunctionSummary.h - Stores summaries of functions. ------------*- C++ -*-//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a summary of a function gathered/used by static analyzes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_GR_FUNCTIONSUMMARY_H
15 #define LLVM_CLANG_GR_FUNCTIONSUMMARY_H
18 #include "clang/AST/Decl.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/DenseSet.h"
21 #include "llvm/ADT/BitVector.h"
25 typedef std::deque<Decl*> SetOfDecls;
26 typedef llvm::DenseSet<const Decl*> SetOfConstDecls;
28 class FunctionSummariesTy {
29 struct FunctionSummary {
30 /// True if this function has reached a max block count while inlined from
31 /// at least one call site.
32 bool MayReachMaxBlockCount;
34 /// Total number of blocks in the function.
35 unsigned TotalBasicBlocks;
37 /// Marks the IDs of the basic blocks visited during the analyzes.
38 llvm::BitVector VisitedBasicBlocks;
41 MayReachMaxBlockCount(false),
43 VisitedBasicBlocks(0) {}
46 typedef llvm::DenseMap<const Decl*, FunctionSummary*> MapTy;
50 ~FunctionSummariesTy();
52 MapTy::iterator findOrInsertSummary(const Decl *D) {
53 MapTy::iterator I = Map.find(D);
56 FunctionSummary *DS = new FunctionSummary();
57 I = Map.insert(std::pair<const Decl*, FunctionSummary*>(D, DS)).first;
58 assert(I != Map.end());
62 void markReachedMaxBlockCount(const Decl* D) {
63 MapTy::iterator I = findOrInsertSummary(D);
64 I->second->MayReachMaxBlockCount = true;
67 bool hasReachedMaxBlockCount(const Decl* D) {
68 MapTy::const_iterator I = Map.find(D);
70 return I->second->MayReachMaxBlockCount;
74 void markVisitedBasicBlock(unsigned ID, const Decl* D, unsigned TotalIDs) {
75 MapTy::iterator I = findOrInsertSummary(D);
76 llvm::BitVector &Blocks = I->second->VisitedBasicBlocks;
77 assert(ID < TotalIDs);
78 if (TotalIDs > Blocks.size()) {
79 Blocks.resize(TotalIDs);
80 I->second->TotalBasicBlocks = TotalIDs;
85 unsigned getNumVisitedBasicBlocks(const Decl* D) {
86 MapTy::const_iterator I = Map.find(D);
88 return I->second->VisitedBasicBlocks.count();
92 /// Get the percentage of the reachable blocks.
93 unsigned getPercentBlocksReachable(const Decl *D) {
94 MapTy::const_iterator I = Map.find(D);
96 return ((I->second->VisitedBasicBlocks.count() * 100) /
97 I->second->TotalBasicBlocks);
101 unsigned getTotalNumBasicBlocks();
102 unsigned getTotalNumVisitedBasicBlocks();
106 }} // end clang ento namespaces