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
17 #include "clang/AST/Decl.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallPtrSet.h"
20 #include "llvm/ADT/BitVector.h"
24 typedef llvm::SmallPtrSet<Decl*, 24> SetOfDecls;
25 typedef llvm::SmallPtrSet<const Decl*, 24> SetOfConstDecls;
27 class FunctionSummariesTy {
28 struct FunctionSummary {
29 /// True if this function has reached a max block count while inlined from
30 /// at least one call site.
31 bool MayReachMaxBlockCount;
33 /// Total number of blocks in the function.
34 unsigned TotalBasicBlocks;
36 /// Marks the IDs of the basic blocks visited during the analyzes.
37 llvm::BitVector VisitedBasicBlocks;
40 MayReachMaxBlockCount(false),
42 VisitedBasicBlocks(0) {}
45 typedef llvm::DenseMap<const Decl*, FunctionSummary*> MapTy;
49 ~FunctionSummariesTy();
51 MapTy::iterator findOrInsertSummary(const Decl *D) {
52 MapTy::iterator I = Map.find(D);
55 FunctionSummary *DS = new FunctionSummary();
56 I = Map.insert(std::pair<const Decl*, FunctionSummary*>(D, DS)).first;
57 assert(I != Map.end());
61 void markReachedMaxBlockCount(const Decl* D) {
62 MapTy::iterator I = findOrInsertSummary(D);
63 I->second->MayReachMaxBlockCount = true;
66 bool hasReachedMaxBlockCount(const Decl* D) {
67 MapTy::const_iterator I = Map.find(D);
69 return I->second->MayReachMaxBlockCount;
73 void markVisitedBasicBlock(unsigned ID, const Decl* D, unsigned TotalIDs) {
74 MapTy::iterator I = findOrInsertSummary(D);
75 llvm::BitVector &Blocks = I->second->VisitedBasicBlocks;
76 assert(ID < TotalIDs);
77 if (TotalIDs > Blocks.size()) {
78 Blocks.resize(TotalIDs);
79 I->second->TotalBasicBlocks = TotalIDs;
84 unsigned getNumVisitedBasicBlocks(const Decl* D) {
85 MapTy::const_iterator I = Map.find(D);
87 return I->second->VisitedBasicBlocks.count();
91 /// Get the percentage of the reachable blocks.
92 unsigned getPercentBlocksReachable(const Decl *D) {
93 MapTy::const_iterator I = Map.find(D);
95 return ((I->second->VisitedBasicBlocks.count() * 100) /
96 I->second->TotalBasicBlocks);
100 unsigned getTotalNumBasicBlocks();
101 unsigned getTotalNumVisitedBasicBlocks();
105 }} // end clang ento namespaces