[cfe-commits] r45928 - in /cfe/trunk: Analysis/ExplodedGraph.cpp include/clang/Analysis/PathSensitive/ExplodedGraph.h

Ted Kremenek kremenek at apple.com
Sat Jan 12 20:56:14 PST 2008


Author: kremenek
Date: Sat Jan 12 22:56:13 2008
New Revision: 45928

URL: http://llvm.org/viewvc/llvm-project?rev=45928&view=rev
Log:
Created ExplodedGraph.cpp and moved most method implementations of
ExplodedNodeImpl::NodeGroup from being defined inline to being defined
"out-of-line" in ExplodedGraph.cpp. This removes a dependence on including
<vector> in ExplodedGraph.h, and will hopefully result in smaller generated code
with negligible performance impact.

Added:
    cfe/trunk/Analysis/ExplodedGraph.cpp
Modified:
    cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h

Added: cfe/trunk/Analysis/ExplodedGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ExplodedGraph.cpp?rev=45928&view=auto

==============================================================================
--- cfe/trunk/Analysis/ExplodedGraph.cpp (added)
+++ cfe/trunk/Analysis/ExplodedGraph.cpp Sat Jan 12 22:56:13 2008
@@ -0,0 +1,70 @@
+//=-- ExplodedGraph.cpp - Local, Path-Sens. "Exploded Graph" -*- 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 the template classes ExplodedNode and ExplodedGraph,
+//  which represent a path-sensitive, intra-procedural "exploded graph."
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Analysis/PathSensitive/ExplodedGraph.h"
+#include <vector>
+
+using namespace clang;
+
+
+static inline std::vector<ExplodedNodeImpl*>& getVector(void* P) {
+  return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P);
+}
+
+void ExplodedNodeImpl::NodeGroup::addNode(ExplodedNodeImpl* N) {
+  if (getKind() == Size1) {
+    if (ExplodedNodeImpl* NOld = getNode()) {
+      std::vector<ExplodedNodeImpl*>* V = new std::vector<ExplodedNodeImpl*>();
+      V->push_back(NOld);
+      V->push_back(N);
+      P = reinterpret_cast<uintptr_t>(V) & SizeOther;
+    }
+    else
+      P = reinterpret_cast<uintptr_t>(N);
+  }
+  else
+    getVector(getPtr()).push_back(N);
+}
+
+bool ExplodedNodeImpl::NodeGroup::empty() const {
+  if (getKind() == Size1)
+    return getNode() ? false : true;
+  else
+    return getVector(getPtr()).empty();
+}
+
+unsigned ExplodedNodeImpl::NodeGroup::size() const {
+  if (getKind() == Size1)
+    return getNode() ? 1 : 0;
+  else
+    return getVector(getPtr()).size();
+}
+
+ExplodedNodeImpl** ExplodedNodeImpl::NodeGroup::begin() const {
+  if (getKind() == Size1)
+    return (ExplodedNodeImpl**) &P;
+  else
+    return const_cast<ExplodedNodeImpl**>(&*(getVector(getPtr()).begin()));
+}
+
+ExplodedNodeImpl** ExplodedNodeImpl::NodeGroup::end() const {
+  if (getKind() == Size1)
+    return ((ExplodedNodeImpl**) &P)+1;
+  else
+    return const_cast<ExplodedNodeImpl**>(&*(getVector(getPtr()).rbegin())+1);
+}
+
+ExplodedNodeImpl::NodeGroup::~NodeGroup() {
+  if (getKind() == SizeOther) delete &getVector(getPtr());
+}

Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h?rev=45928&r1=45927&r2=45928&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ExplodedGraph.h Sat Jan 12 22:56:13 2008
@@ -39,68 +39,23 @@
     uintptr_t P;
     
     unsigned getKind() const { return P & Flags; }
-    
-    std::vector<ExplodedNodeImpl*>& getVector() {
-      assert (getKind() == SizeOther);
-      return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags);
-    }  
-    const std::vector<ExplodedNodeImpl*>& getVector() const {
-      assert (getKind() == SizeOther);
-      return *reinterpret_cast<std::vector<ExplodedNodeImpl*>*>(P & ~Flags);
-    }
-    
-    ExplodedNodeImpl* getNode() const {
-      assert (getKind() == Size1);
-      return reinterpret_cast<ExplodedNodeImpl*>(P);
-    }
+    void* getPtr() const { return reinterpret_cast<void*>(P & ~Flags); }
+    ExplodedNodeImpl* getNode() const;
     
   public:
     NodeGroup() : P(0) {}
     
-    ~NodeGroup() { if (getKind() == SizeOther) delete &getVector(); }
+    ~NodeGroup();
     
-    inline ExplodedNodeImpl** begin() const {
-      if (getKind() == Size1)
-        return (ExplodedNodeImpl**) &P;
-      else
-        return const_cast<ExplodedNodeImpl**>(&*(getVector().begin()));
-    }
-    
-    inline ExplodedNodeImpl** end() const {
-      if (getKind() == Size1)
-        return ((ExplodedNodeImpl**) &P)+1;
-      else
-        return const_cast<ExplodedNodeImpl**>(&*(getVector().rbegin())+1);
-    }
-    
-    inline unsigned size() const {
-      if (getKind() == Size1)
-        return getNode() ? 1 : 0;
-      else
-        return getVector().size();
-    }
-    
-    inline bool empty() const {
-      if (getKind() == Size1)
-        return getNode() ? false : true;
-      else
-        return getVector().empty();
-    }
-    
-    inline void addNode(ExplodedNodeImpl* N) {
-      if (getKind() == Size1) {
-        if (ExplodedNodeImpl* NOld = getNode()) {
-          std::vector<ExplodedNodeImpl*>* V = new std::vector<ExplodedNodeImpl*>();
-          V->push_back(NOld);
-          V->push_back(N);
-          P = reinterpret_cast<uintptr_t>(V) & SizeOther;
-        }
-        else
-          P = reinterpret_cast<uintptr_t>(N);
-      }
-      else
-        getVector().push_back(N);
-    }
+    inline ExplodedNodeImpl** begin() const;
+    
+    inline ExplodedNodeImpl** end() const;
+    
+    inline unsigned size() const;
+    
+    inline bool empty() const;
+    
+    void addNode(ExplodedNodeImpl* N);
   };
   
   





More information about the cfe-commits mailing list