[cfe-commits] r46888 - in /cfe/trunk/Analysis: GRConstants.cpp ValueState.cpp ValueState.h

Ted Kremenek kremenek at apple.com
Fri Feb 8 11:17:19 PST 2008


Author: kremenek
Date: Fri Feb  8 13:17:19 2008
New Revision: 46888

URL: http://llvm.org/viewvc/llvm-project?rev=46888&view=rev
Log:
Moved implementation of "RemoveDeadBindings" from the main
GRConstants logic to ValueStateManager.

Modified:
    cfe/trunk/Analysis/GRConstants.cpp
    cfe/trunk/Analysis/ValueState.cpp
    cfe/trunk/Analysis/ValueState.h

Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46888&r1=46887&r2=46888&view=diff

==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Fri Feb  8 13:17:19 2008
@@ -192,11 +192,13 @@
   ///  nodes by processing the 'effects' of a branch condition.
   void ProcessBranch(Expr* Condition, Stmt* Term, BranchNodeBuilder& builder);
 
-  /// RemoveDeadBindings - Return a new state that is the same as 'M' except
+  /// RemoveDeadBindings - Return a new state that is the same as 'St' except
   ///  that all subexpression mappings are removed and that any
   ///  block-level expressions that are not live at 'S' also have their
   ///  mappings removed.
-  StateTy RemoveDeadBindings(Stmt* S, StateTy M);
+  inline StateTy RemoveDeadBindings(Stmt* S, StateTy St) {
+    return StateMgr.RemoveDeadBindings(St, S, Liveness);
+  }
 
   StateTy SetValue(StateTy St, Stmt* S, const RValue& V);
 
@@ -509,76 +511,6 @@
   Builder = NULL;
 }
 
-GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) {
-  
-  // This code essentially performs a "mark-and-sweep" of the VariableBindings.
-  // The roots are any Block-level exprs and Decls that our liveness algorithm
-  // tells us are live.  We then see what Decls they may reference, and keep
-  // those around.  This code more than likely can be made faster, and the
-  // frequency of which this method is called should be experimented with
-  // for optimum performance.
-
-  llvm::SmallVector<ValueDecl*, 10> WList;
-
-  for (StateTy::vb_iterator I = M.begin(), E = M.end(); I!=E ; ++I) {
-
-    // Remove old bindings for subexpressions.
-    if (I.getKey().isSubExpr()) {
-      M = StateMgr.Remove(M, I.getKey());
-      continue;
-    }
-    
-    if (I.getKey().isBlkExpr()) {
-      if (Liveness.isLive(Loc, cast<Stmt>(I.getKey()))) {
-        if (isa<lval::DeclVal>(I.getData())) {
-          lval::DeclVal LV = cast<lval::DeclVal>(I.getData());
-          WList.push_back(LV.getDecl());
-        }
-      }
-      else
-        M = StateMgr.Remove(M, I.getKey());
-    
-      continue;
-    }
-    
-    assert (I.getKey().isDecl());
-
-    if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
-      if (Liveness.isLive(Loc, V))
-        WList.push_back(V);
-  }
-
-  llvm::SmallPtrSet<ValueDecl*, 10> Marked;
-  
-  while (!WList.empty()) {
-    ValueDecl* V = WList.back();
-    WList.pop_back();
-    
-    if (Marked.count(V))
-      continue;
-    
-    Marked.insert(V);
-    
-    if (V->getType()->isPointerType()) {
-      const LValue& LV = cast<LValue>(GetValue(M, lval::DeclVal(V)));
-
-      if (!isa<lval::DeclVal>(LV))
-        continue;
-      
-      const lval::DeclVal& LVD = cast<lval::DeclVal>(LV);
-      WList.push_back(LVD.getDecl());
-    }    
-  }
-
-  for (StateTy::vb_iterator I = M.begin(), E = M.end(); I!=E ; ++I)
-    if (I.getKey().isDecl())
-      if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
-        if (!Marked.count(V))
-          M = StateMgr.Remove(M, V);
-
-  return M;
-}
-
 GRConstants::NodeTy*
 GRConstants::Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St) {
  

Modified: cfe/trunk/Analysis/ValueState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ValueState.cpp?rev=46888&r1=46887&r2=46888&view=diff

==============================================================================
--- cfe/trunk/Analysis/ValueState.cpp (original)
+++ cfe/trunk/Analysis/ValueState.cpp Fri Feb  8 13:17:19 2008
@@ -31,6 +31,77 @@
   return T ? T->getValue().second : NULL;  
 }
 
+ValueState
+ValueStateManager::RemoveDeadBindings(ValueState St, Stmt* Loc,
+                                      const LiveVariables& Liveness) {  
+  
+  // This code essentially performs a "mark-and-sweep" of the VariableBindings.
+  // The roots are any Block-level exprs and Decls that our liveness algorithm
+  // tells us are live.  We then see what Decls they may reference, and keep
+  // those around.  This code more than likely can be made faster, and the
+  // frequency of which this method is called should be experimented with
+  // for optimum performance.
+  
+  llvm::SmallVector<ValueDecl*, 10> WList;
+  
+  for (StateTy::vb_iterator I = St.begin(), E = St.end(); I!=E ; ++I) {
+    
+    // Remove old bindings for subexpressions.
+    if (I.getKey().isSubExpr()) {
+      St = Remove(St, I.getKey());
+      continue;
+    }
+    
+    if (I.getKey().isBlkExpr()) {
+      if (Liveness.isLive(Loc, cast<Stmt>(I.getKey()))) {
+        if (isa<lval::DeclVal>(I.getData())) {
+          lval::DeclVal LV = cast<lval::DeclVal>(I.getData());
+          WList.push_back(LV.getDecl());
+        }
+      }
+      else
+        St = Remove(St, I.getKey());
+      
+      continue;
+    }
+    
+    assert (I.getKey().isDecl());
+    
+    if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
+      if (Liveness.isLive(Loc, V))
+        WList.push_back(V);
+  }
+  
+  llvm::SmallPtrSet<ValueDecl*, 10> Marked;
+  
+  while (!WList.empty()) {
+    ValueDecl* V = WList.back();
+    WList.pop_back();
+    
+    if (Marked.count(V))
+      continue;
+    
+    Marked.insert(V);
+    
+    if (V->getType()->isPointerType()) {
+      const LValue& LV = cast<LValue>(GetValue(St, lval::DeclVal(V)));
+      
+      if (!isa<lval::DeclVal>(LV))
+        continue;
+      
+      const lval::DeclVal& LVD = cast<lval::DeclVal>(LV);
+      WList.push_back(LVD.getDecl());
+    }    
+  }
+  
+  for (StateTy::vb_iterator I = St.begin(), E = St.end(); I!=E ; ++I)
+    if (I.getKey().isDecl())
+      if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
+        if (!Marked.count(V))
+          St = Remove(St, V);
+  
+  return St;
+}
 
 
 RValue ValueStateManager::GetValue(const StateTy& St, const LValue& LV,

Modified: cfe/trunk/Analysis/ValueState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ValueState.h?rev=46888&r1=46887&r2=46888&view=diff

==============================================================================
--- cfe/trunk/Analysis/ValueState.h (original)
+++ cfe/trunk/Analysis/ValueState.h Fri Feb  8 13:17:19 2008
@@ -241,13 +241,18 @@
   ValueManager& getValueManager() { return ValMgr; }
   SymbolManager& getSymbolManager() { return SymMgr; }
   
+  StateTy RemoveDeadBindings(StateTy St, Stmt* Loc, 
+                             const LiveVariables& Liveness);
+  
   StateTy SetValue(StateTy St, Stmt* S, bool isBlkExpr, const RValue& V);
   StateTy SetValue(StateTy St, const LValue& LV, const RValue& V);
 
   RValue GetValue(const StateTy& St, Stmt* S, bool* hasVal = NULL);
-  RValue GetValue(const StateTy& St, const LValue& LV, QualType* T = NULL);
-    
+  RValue GetValue(const StateTy& St, const LValue& LV, QualType* T = NULL);    
   LValue GetLValue(const StateTy& St, Stmt* S);
+  
+  
+  
 
   StateTy Add(StateTy St, VarBindKey K, const RValue& V);
   StateTy Remove(StateTy St, VarBindKey K);





More information about the cfe-commits mailing list