r178514 - [analyzer] Use inline storage in the FunctionSummary DenseMap.

Jordan Rose jordan_rose at apple.com
Mon Apr 1 17:26:26 PDT 2013


Author: jrose
Date: Mon Apr  1 19:26:26 2013
New Revision: 178514

URL: http://llvm.org/viewvc/llvm-project?rev=178514&view=rev
Log:
[analyzer] Use inline storage in the FunctionSummary DenseMap.

The summaries lasted for the lifetime of the map anyway; no reason to
include an extra allocation.

Also, use SmallBitVector instead of BitVector to track the visited basic
blocks -- most functions will have less than 64 basic blocks -- and
use bitfields for the other fields to reduce the size of the structure.

No functionality change.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h
    cfe/trunk/lib/StaticAnalyzer/Core/FunctionSummary.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h?rev=178514&r1=178513&r2=178514&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/FunctionSummary.h Mon Apr  1 19:26:26 2013
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines a summary of a function gathered/used by static analyzes.
+// This file defines a summary of a function gathered/used by static analysis.
 //
 //===----------------------------------------------------------------------===//
 
@@ -15,7 +15,7 @@
 #define LLVM_CLANG_GR_FUNCTIONSUMMARY_H
 
 #include "clang/AST/Decl.h"
-#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include <deque>
@@ -27,90 +27,88 @@ typedef llvm::DenseSet<const Decl*> SetO
 
 class FunctionSummariesTy {
   struct FunctionSummary {
-    /// True if this function has reached a max block count while inlined from
-    /// at least one call site.
-    bool MayReachMaxBlockCount;
+    /// Marks the IDs of the basic blocks visited during the analyzes.
+    llvm::SmallBitVector VisitedBasicBlocks;
 
     /// Total number of blocks in the function.
-    unsigned TotalBasicBlocks;
+    unsigned TotalBasicBlocks : 31;
 
-    /// Marks the IDs of the basic blocks visited during the analyzes.
-    llvm::BitVector VisitedBasicBlocks;
+    /// True if this function has reached a max block count while inlined from
+    /// at least one call site.
+    unsigned MayReachMaxBlockCount : 1;
 
     /// The number of times the function has been inlined.
-    unsigned TimesInlined;
+    unsigned TimesInlined : 32;
 
     FunctionSummary() :
-      MayReachMaxBlockCount(false),
       TotalBasicBlocks(0),
-      VisitedBasicBlocks(0),
+      MayReachMaxBlockCount(0),
       TimesInlined(0) {}
   };
 
-  typedef llvm::DenseMap<const Decl*, FunctionSummary*> MapTy;
+  typedef llvm::DenseMap<const Decl *, FunctionSummary> MapTy;
   MapTy Map;
 
 public:
-  ~FunctionSummariesTy();
-
   MapTy::iterator findOrInsertSummary(const Decl *D) {
     MapTy::iterator I = Map.find(D);
     if (I != Map.end())
       return I;
-    FunctionSummary *DS = new FunctionSummary();
-    I = Map.insert(std::pair<const Decl*, FunctionSummary*>(D, DS)).first;
+
+    typedef std::pair<const Decl *, FunctionSummary> KVPair;
+    I = Map.insert(KVPair(D, FunctionSummary())).first;
     assert(I != Map.end());
     return I;
   }
 
   void markReachedMaxBlockCount(const Decl* D) {
     MapTy::iterator I = findOrInsertSummary(D);
-    I->second->MayReachMaxBlockCount = true;
+    I->second.MayReachMaxBlockCount = 1;
   }
 
   bool hasReachedMaxBlockCount(const Decl* D) {
   MapTy::const_iterator I = Map.find(D);
     if (I != Map.end())
-      return I->second->MayReachMaxBlockCount;
+      return I->second.MayReachMaxBlockCount;
     return false;
   }
 
   void markVisitedBasicBlock(unsigned ID, const Decl* D, unsigned TotalIDs) {
     MapTy::iterator I = findOrInsertSummary(D);
-    llvm::BitVector &Blocks = I->second->VisitedBasicBlocks;
+    llvm::SmallBitVector &Blocks = I->second.VisitedBasicBlocks;
     assert(ID < TotalIDs);
     if (TotalIDs > Blocks.size()) {
       Blocks.resize(TotalIDs);
-      I->second->TotalBasicBlocks = TotalIDs;
+      I->second.TotalBasicBlocks = TotalIDs;
     }
-    Blocks[ID] = true;
+    Blocks.set(ID);
   }
 
   unsigned getNumVisitedBasicBlocks(const Decl* D) {
     MapTy::const_iterator I = Map.find(D);
     if (I != Map.end())
-      return I->second->VisitedBasicBlocks.count();
+      return I->second.VisitedBasicBlocks.count();
     return 0;
   }
 
   unsigned getNumTimesInlined(const Decl* D) {
     MapTy::const_iterator I = Map.find(D);
     if (I != Map.end())
-      return I->second->TimesInlined;
+      return I->second.TimesInlined;
     return 0;
   }
 
   void bumpNumTimesInlined(const Decl* D) {
     MapTy::iterator I = findOrInsertSummary(D);
-    I->second->TimesInlined++;
+    I->second.TimesInlined++;
   }
 
   /// Get the percentage of the reachable blocks.
   unsigned getPercentBlocksReachable(const Decl *D) {
     MapTy::const_iterator I = Map.find(D);
       if (I != Map.end())
-        return ((I->second->VisitedBasicBlocks.count() * 100) /
-                 I->second->TotalBasicBlocks);
+        return ((I->second.VisitedBasicBlocks.count() * 100) /
+                 I->second.TotalBasicBlocks);
     return 0;
   }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/FunctionSummary.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/FunctionSummary.cpp?rev=178514&r1=178513&r2=178514&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/FunctionSummary.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/FunctionSummary.cpp Mon Apr  1 19:26:26 2013
@@ -1,4 +1,4 @@
-//== FunctionSummary.h - Stores summaries of functions. ------------*- C++ -*-//
+//== FunctionSummary.cpp - Stores summaries of functions. ----------*- C++ -*-//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file defines a summary of a function gathered/used by static analyzes.
+// This file defines a summary of a function gathered/used by static analysis.
 //
 //===----------------------------------------------------------------------===//
 
@@ -15,16 +15,10 @@
 using namespace clang;
 using namespace ento;
 
-FunctionSummariesTy::~FunctionSummariesTy() {
-  for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I) {
-    delete(I->second);
-  }
-}
-
 unsigned FunctionSummariesTy::getTotalNumBasicBlocks() {
   unsigned Total = 0;
   for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I) {
-    Total += I->second->TotalBasicBlocks;
+    Total += I->second.TotalBasicBlocks;
   }
   return Total;
 }
@@ -32,7 +26,7 @@ unsigned FunctionSummariesTy::getTotalNu
 unsigned FunctionSummariesTy::getTotalNumVisitedBasicBlocks() {
   unsigned Total = 0;
   for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I) {
-    Total += I->second->VisitedBasicBlocks.count();
+    Total += I->second.VisitedBasicBlocks.count();
   }
   return Total;
 }





More information about the cfe-commits mailing list