[cfe-commits] r47142 - in /cfe/trunk: Analysis/RValues.cpp Analysis/ValueState.cpp Analysis/ValueState.h include/clang/Analysis/PathSensitive/RValues.h

Ted Kremenek kremenek at apple.com
Thu Feb 14 15:25:54 PST 2008


Author: kremenek
Date: Thu Feb 14 17:25:54 2008
New Revision: 47142

URL: http://llvm.org/viewvc/llvm-project?rev=47142&view=rev
Log:
Added "symbol iterators" for RValues, allowing easy iteration over the symbols
referenced by an RValue, instead of having to query the type of the RValue.

Modified ValueState::RemoveDeadBindings to also prune dead symbols.

Modified:
    cfe/trunk/Analysis/RValues.cpp
    cfe/trunk/Analysis/ValueState.cpp
    cfe/trunk/Analysis/ValueState.h
    cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h

Modified: cfe/trunk/Analysis/RValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.cpp?rev=47142&r1=47141&r2=47142&view=diff

==============================================================================
--- cfe/trunk/Analysis/RValues.cpp (original)
+++ cfe/trunk/Analysis/RValues.cpp Thu Feb 14 17:25:54 2008
@@ -123,8 +123,32 @@
   return *C;
 }
 
+//===----------------------------------------------------------------------===//
+// Symbol Iteration.
+//===----------------------------------------------------------------------===//
+
+RValue::symbol_iterator RValue::symbol_begin() const {
+  if (isa<LValue>(this)) {
+    if (isa<lval::SymbolVal>(this))
+      return (symbol_iterator) (&Data);
+  }
+  else {
+    if (isa<nonlval::SymbolVal>(this))
+      return (symbol_iterator) (&Data);
+    else if (isa<nonlval::SymIntConstraintVal>(this)) {
+      const SymIntConstraint& C =
+        cast<nonlval::SymIntConstraintVal>(this)->getConstraint();
+      return (symbol_iterator) &C.getSymbol();
+    }
+  }
+  
+  return NULL;
+}
 
- 
+RValue::symbol_iterator RValue::symbol_end() const {
+  symbol_iterator X = symbol_begin();
+  return X ? X+1 : NULL;
+}
 
 //===----------------------------------------------------------------------===//
 // Transfer function dispatch for Non-LValues.

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

==============================================================================
--- cfe/trunk/Analysis/ValueState.cpp (original)
+++ cfe/trunk/Analysis/ValueState.cpp Thu Feb 14 17:25:54 2008
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "ValueState.h"
+#include "llvm/ADT/SmallSet.h"
 
 using namespace clang;
 
@@ -43,6 +44,8 @@
   // for optimum performance.
   
   llvm::SmallVector<ValueDecl*, 10> WList;
+  llvm::SmallPtrSet<ValueDecl*, 10> Marked;  
+  llvm::SmallSet<SymbolID, 20> MarkedSymbols;
   
   ValueStateImpl NewSt = *St;
   
@@ -55,10 +58,16 @@
     Expr* BlkExpr = I.getKey();
     
     if (Liveness.isLive(Loc, BlkExpr)) {
-      if (isa<lval::DeclVal>(I.getData())) {
-        lval::DeclVal LV = cast<lval::DeclVal>(I.getData());
+      RValue X = I.getData();
+      
+      if (isa<lval::DeclVal>(X)) {
+        lval::DeclVal LV = cast<lval::DeclVal>(X);
         WList.push_back(LV.getDecl());
       }
+      
+      for (RValue::symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end();
+                                   SI != SE; ++SI)
+        MarkedSymbols.insert(*SI);      
     }
     else
       NewSt.BlockExprBindings = Remove(NewSt, BlkExpr);
@@ -70,8 +79,7 @@
   for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I)
     if (Liveness.isLive(Loc, I.getKey()))
       WList.push_back(I.getKey());
-  
-  llvm::SmallPtrSet<ValueDecl*, 10> Marked;  
+
   
   while (!WList.empty()) {
     ValueDecl* V = WList.back();
@@ -83,7 +91,11 @@
     Marked.insert(V);
     
     if (V->getType()->isPointerType()) {
-      const LValue& LV = cast<LValue>(GetValue(St, lval::DeclVal(V)));
+      const LValue& LV = cast<LValue>(GetValue(St, lval::DeclVal(V)));      
+      
+      for (RValue::symbol_iterator SI=LV.symbol_begin(), SE=LV.symbol_end();
+           SI != SE; ++SI)
+        MarkedSymbols.insert(*SI); 
       
       if (!isa<lval::DeclVal>(LV))
         continue;
@@ -93,10 +105,20 @@
     }    
   }
   
+  // Remove dead variable bindings.
   for (ValueState::vb_iterator I = St.vb_begin(), E = St.vb_end(); I!=E ; ++I)
     if (!Marked.count(I.getKey()))
       NewSt.VarBindings = Remove(NewSt, I.getKey());
   
+  // Remove dead symbols.
+  for (ValueState::ce_iterator I = St.ce_begin(), E=St.ce_end(); I!=E; ++I)
+    if (!MarkedSymbols.count(I.getKey()))
+      NewSt.ConstantEq = CEFactory.Remove(NewSt.ConstantEq, I.getKey());
+  
+  for (ValueState::cne_iterator I = St.cne_begin(), E=St.cne_end(); I!=E; ++I)
+    if (!MarkedSymbols.count(I.getKey()))
+      NewSt.ConstantNotEq = CNEFactory.Remove(NewSt.ConstantNotEq, I.getKey());
+  
   return getPersistentState(NewSt);
 }
 

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

==============================================================================
--- cfe/trunk/Analysis/ValueState.h (original)
+++ cfe/trunk/Analysis/ValueState.h Thu Feb 14 17:25:54 2008
@@ -153,6 +153,14 @@
   beb_iterator beb_begin() const { return Data->BlockExprBindings.begin(); }
   beb_iterator beb_end() const { return Data->BlockExprBindings.end(); }
   
+  typedef ConstantNotEqTy::iterator cne_iterator;
+  cne_iterator cne_begin() const { return Data->ConstantNotEq.begin(); }
+  cne_iterator cne_end() const { return Data->ConstantNotEq.end(); }
+  
+  typedef ConstantEqTy::iterator ce_iterator;
+  ce_iterator ce_begin() const { return Data->ConstantEq.begin(); }
+  ce_iterator ce_end() const { return Data->ConstantEq.end(); }
+  
   // Profiling and equality testing.
   
   bool operator==(const ValueState& RHS) const {

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

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/RValues.h Thu Feb 14 17:25:54 2008
@@ -137,7 +137,7 @@
       Op(op), Val(V) {}
   
   BinaryOperator::Opcode getOpcode() const { return Op; }
-  SymbolID getSymbol() const { return Symbol; }
+  const SymbolID& getSymbol() const { return Symbol; }
   const llvm::APSInt& getInt() const { return Val; }
   
   static inline void Profile(llvm::FoldingSetNodeID& ID,
@@ -249,7 +249,7 @@
   enum { BaseBits = 2, 
          BaseMask = 0x3 };
   
-private:
+protected:
   void* Data;
   unsigned Kind;
   
@@ -261,10 +261,6 @@
   explicit RValue(BaseKind k)
     : Data(0), Kind(k) {}
   
-  void* getRawPtr() const {
-    return reinterpret_cast<void*>(Data);
-  }
-  
 public:
   ~RValue() {};
   
@@ -293,6 +289,10 @@
   void print(std::ostream& OS) const;
   void print() const;
   
+  typedef const SymbolID* symbol_iterator;
+  symbol_iterator symbol_begin() const;
+  symbol_iterator symbol_end() const;  
+  
   // Implement isa<T> support.
   static inline bool classof(const RValue*) { return true; }
 };
@@ -374,7 +374,7 @@
                 reinterpret_cast<void*>((uintptr_t) SymID)) {}
     
     SymbolID getSymbol() const {
-      return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
+      return (SymbolID) reinterpret_cast<uintptr_t>(Data);
     }
     
     static inline bool classof(const RValue* V) {
@@ -388,7 +388,7 @@
     : NonLValue(SymIntConstraintValKind, reinterpret_cast<const void*>(&C)) {}
 
     const SymIntConstraint& getConstraint() const {
-      return *reinterpret_cast<SymIntConstraint*>(getRawPtr());
+      return *reinterpret_cast<SymIntConstraint*>(Data);
     }
     
     static inline bool classof(const RValue* V) {
@@ -401,7 +401,7 @@
     ConcreteInt(const llvm::APSInt& V) : NonLValue(ConcreteIntKind, &V) {}
     
     const llvm::APSInt& getValue() const {
-      return *static_cast<llvm::APSInt*>(getRawPtr());
+      return *static_cast<llvm::APSInt*>(Data);
     }
     
     // Transfer functions for binary/unary operations on ConcreteInts.
@@ -442,7 +442,7 @@
     : LValue(SymbolValKind, reinterpret_cast<void*>((uintptr_t) SymID)) {}
     
     SymbolID getSymbol() const {
-      return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr());
+      return (SymbolID) reinterpret_cast<uintptr_t>(Data);
     }
     
     static inline bool classof(const RValue* V) {
@@ -459,7 +459,7 @@
     GotoLabel(LabelStmt* Label) : LValue(GotoLabelKind, Label) {}
     
     LabelStmt* getLabel() const {
-      return static_cast<LabelStmt*>(getRawPtr());
+      return static_cast<LabelStmt*>(Data);
     }
     
     static inline bool classof(const RValue* V) {
@@ -477,7 +477,7 @@
     DeclVal(const ValueDecl* vd) : LValue(DeclValKind,vd) {}
     
     ValueDecl* getDecl() const {
-      return static_cast<ValueDecl*>(getRawPtr());
+      return static_cast<ValueDecl*>(Data);
     }
     
     inline bool operator==(const DeclVal& R) const {
@@ -503,7 +503,7 @@
     ConcreteInt(const llvm::APSInt& V) : LValue(ConcreteIntKind, &V) {}
     
     const llvm::APSInt& getValue() const {
-      return *static_cast<llvm::APSInt*>(getRawPtr());
+      return *static_cast<llvm::APSInt*>(Data);
     }
     
 





More information about the cfe-commits mailing list