Remove unneeded variable usage analysis.
authorkmillikin@chromium.org <kmillikin@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 8 Mar 2010 13:01:24 +0000 (13:01 +0000)
committerkmillikin@chromium.org <kmillikin@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 8 Mar 2010 13:01:24 +0000 (13:01 +0000)
A variable usage analysis pass was run on toplevel and lazily-compiled
code but never used.  Remove this pass and the data structures it
builds.

The representation of variable usage for Variables has been changed
from a struct containing a (weighted) count of reads and writes to a
simple flag.  VariableProxies are always used, as before.  The unused
"object uses" is removed.

Review URL: http://codereview.chromium.org/669270

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4052 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

16 files changed:
src/SConscript
src/ast.cc
src/ast.h
src/compiler.cc
src/flag-definitions.h
src/parser.cc
src/scopeinfo.cc
src/scopes.cc
src/usage-analyzer.cc [deleted file]
src/usage-analyzer.h [deleted file]
src/variables.cc
src/variables.h
tools/gyp/v8.gyp
tools/visual_studio/v8_base.vcproj
tools/visual_studio/v8_base_arm.vcproj
tools/visual_studio/v8_base_x64.vcproj

index da252904d8349dfb859f8e4060815482440b4f25..d61da3e07898af6bf8d3a3ea44df2ed9e3de52f8 100755 (executable)
@@ -97,7 +97,6 @@ SOURCES = {
     token.cc
     top.cc
     unicode.cc
-    usage-analyzer.cc
     utils.cc
     v8-counters.cc
     v8.cc
index 7cb5578317f627d363bd51822525cc11af313f8a..062a5c67adca40a699100d64b6a2a8d96892dc50 100644 (file)
@@ -67,8 +67,6 @@ VariableProxy::VariableProxy(Handle<String> name,
     inside_with_(inside_with) {
   // names must be canonicalized for fast equality checks
   ASSERT(name->IsSymbol());
-  // at least one access, otherwise no need for a VariableProxy
-  var_uses_.RecordRead(1);
 }
 
 
@@ -87,8 +85,7 @@ void VariableProxy::BindTo(Variable* var) {
   // eval() etc.  Const-ness and variable declarations are a complete mess
   // in JS. Sigh...
   var_ = var;
-  var->var_uses()->RecordUses(&var_uses_);
-  var->obj_uses()->RecordUses(&obj_uses_);
+  var->set_is_used(true);
 }
 
 
index 2f2a0bb9328746a3327dd0b067655847ab991b67..52241c6b85234f000adf41d850976cfa59104755 100644 (file)
--- a/src/ast.h
+++ b/src/ast.h
@@ -1006,8 +1006,6 @@ class VariableProxy: public Expression {
 
   Handle<String> name() const  { return name_; }
   Variable* var() const  { return var_; }
-  UseCount* var_uses()  { return &var_uses_; }
-  UseCount* obj_uses()  { return &obj_uses_; }
   bool is_this() const  { return is_this_; }
   bool inside_with() const  { return inside_with_; }
 
@@ -1020,10 +1018,6 @@ class VariableProxy: public Expression {
   bool is_this_;
   bool inside_with_;
 
-  // VariableProxy usage info.
-  UseCount var_uses_;  // uses of the variable value
-  UseCount obj_uses_;  // uses of the object the variable points to
-
   VariableProxy(Handle<String> name, bool is_this, bool inside_with);
   explicit VariableProxy(bool is_this);
 
index 50e16a06e2c6cfc9b760faf21bd55264d094bde9..ebb62f11c2df42a4aabeac97632df72463091b50 100755 (executable)
 #include "debug.h"
 #include "fast-codegen.h"
 #include "full-codegen.h"
+#include "liveedit.h"
 #include "oprofile-agent.h"
 #include "rewriter.h"
 #include "scopes.h"
-#include "usage-analyzer.h"
-#include "liveedit.h"
 
 namespace v8 {
 namespace internal {
@@ -49,7 +48,7 @@ static Handle<Code> MakeCode(Handle<Context> context, CompilationInfo* info) {
   FunctionLiteral* function = info->function();
   ASSERT(function != NULL);
   // Rewrite the AST by introducing .result assignments where needed.
-  if (!Rewriter::Process(function) || !AnalyzeVariableUsage(function)) {
+  if (!Rewriter::Process(function)) {
     // Signal a stack overflow by returning a null handle.  The stack
     // overflow exception will be thrown by the caller.
     return Handle<Code>::null();
index 5f5e98166940e95d8cb0dcb16147f56c646d3133..4b02cdfa11f5906d4b9a4aafdc0f433969ac9117 100644 (file)
@@ -232,9 +232,6 @@ DEFINE_bool(trace_exception, false,
 DEFINE_bool(preallocate_message_memory, false,
             "preallocate some memory to build stack traces.")
 
-// usage-analyzer.cc
-DEFINE_bool(usage_computation, true, "compute variable usage counts")
-
 // v8.cc
 DEFINE_bool(preemption, false,
             "activate a 100ms timer that switches between V8 threads")
index 0ea77858c3c7a6da92bd9ea6b62949662f50d4a2..7906a7a1cf55b7f3ae2463dbd3ba3beed712ba79 100644 (file)
@@ -3256,7 +3256,6 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
         result = VariableProxySentinel::this_proxy();
       } else {
         VariableProxy* recv = top_scope_->receiver();
-        recv->var_uses()->RecordRead(1);
         result = recv;
       }
       break;
index de1841b027eb558041ea5852c9f570da7e12d8db..8b7e2ad972f39bca81777f2a86729bc8d31dc27a 100644 (file)
@@ -82,7 +82,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope)
   List<Variable*, Allocator> heap_locals(locals.length());
   for (int i = 0; i < locals.length(); i++) {
     Variable* var = locals[i];
-    if (var->var_uses()->is_used()) {
+    if (var->is_used()) {
       Slot* slot = var->slot();
       if (slot != NULL) {
         switch (slot->type()) {
@@ -130,7 +130,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope)
   if (scope->is_function_scope()) {
     Variable* var = scope->function();
     if (var != NULL &&
-        var->var_uses()->is_used() &&
+        var->is_used() &&
         var->slot()->type() == Slot::CONTEXT) {
       function_name_ = var->name();
       // Note that we must not find the function name in the context slot
index 701e5e3eddbdf3995515f0465076d9e93822496b..b55e5d5d7bd38744ad07ffcc9d679d9f96b5e481 100644 (file)
@@ -309,7 +309,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
   // which is the current user of this function).
   for (int i = 0; i < temps_.length(); i++) {
     Variable* var = temps_[i];
-    if (var->var_uses()->is_used()) {
+    if (var->is_used()) {
       locals->Add(var);
     }
   }
@@ -317,7 +317,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
        p != NULL;
        p = variables_.Next(p)) {
     Variable* var = reinterpret_cast<Variable*>(p->value);
-    if (var->var_uses()->is_used()) {
+    if (var->is_used()) {
       locals->Add(var);
     }
   }
@@ -418,17 +418,16 @@ static void PrintName(Handle<String> name) {
 
 
 static void PrintVar(PrettyPrinter* printer, int indent, Variable* var) {
-  if (var->var_uses()->is_used() || var->rewrite() != NULL) {
+  if (var->is_used() || var->rewrite() != NULL) {
     Indent(indent, Variable::Mode2String(var->mode()));
     PrintF(" ");
     PrintName(var->name());
     PrintF(";  // ");
-    if (var->rewrite() != NULL) PrintF("%s, ", printer->Print(var->rewrite()));
-    if (var->is_accessed_from_inner_scope()) PrintF("inner scope access, ");
-    PrintF("var ");
-    var->var_uses()->Print();
-    PrintF(", obj ");
-    var->obj_uses()->Print();
+    if (var->rewrite() != NULL) {
+      PrintF("%s, ", printer->Print(var->rewrite()));
+      if (var->is_accessed_from_inner_scope()) PrintF(", ");
+    }
+    if (var->is_accessed_from_inner_scope()) PrintF("inner scope access");
     PrintF("\n");
   }
 }
@@ -738,10 +737,10 @@ bool Scope::MustAllocate(Variable* var) {
       (var->is_accessed_from_inner_scope_ ||
        scope_calls_eval_ || inner_scope_calls_eval_ ||
        scope_contains_with_)) {
-    var->var_uses()->RecordAccess(1);
+    var->set_is_used(true);
   }
   // Global variables do not need to be allocated.
-  return !var->is_global() && var->var_uses()->is_used();
+  return !var->is_global() && var->is_used();
 }
 
 
@@ -847,7 +846,7 @@ void Scope::AllocateParameterLocals() {
                        new Literal(Handle<Object>(Smi::FromInt(i))),
                        RelocInfo::kNoPosition,
                        Property::SYNTHETIC);
-        arguments_shadow->var_uses()->RecordUses(var->var_uses());
+        if (var->is_used()) arguments_shadow->set_is_used(true);
       }
     }
 
diff --git a/src/usage-analyzer.cc b/src/usage-analyzer.cc
deleted file mode 100644 (file)
index 74cf982..0000000
+++ /dev/null
@@ -1,426 +0,0 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-//       notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-//       copyright notice, this list of conditions and the following
-//       disclaimer in the documentation and/or other materials provided
-//       with the distribution.
-//     * Neither the name of Google Inc. nor the names of its
-//       contributors may be used to endorse or promote products derived
-//       from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "v8.h"
-
-#include "ast.h"
-#include "scopes.h"
-#include "usage-analyzer.h"
-
-namespace v8 {
-namespace internal {
-
-// Weight boundaries
-static const int MinWeight = 1;
-static const int MaxWeight = 1000000;
-static const int InitialWeight = 100;
-
-
-class UsageComputer: public AstVisitor {
- public:
-  static bool Traverse(AstNode* node);
-
-  // AST node visit functions.
-#define DECLARE_VISIT(type) void Visit##type(type* node);
-  AST_NODE_LIST(DECLARE_VISIT)
-#undef DECLARE_VISIT
-
-  void VisitVariable(Variable* var);
-
- private:
-  int weight_;
-  bool is_write_;
-
-  UsageComputer(int weight, bool is_write);
-  virtual ~UsageComputer();
-
-  // Helper functions
-  void RecordUses(UseCount* uses);
-  void Read(Expression* x);
-  void Write(Expression* x);
-  void ReadList(ZoneList<Expression*>* list);
-  void ReadList(ZoneList<ObjectLiteral::Property*>* list);
-
-  friend class WeightScaler;
-};
-
-
-class WeightScaler BASE_EMBEDDED {
- public:
-  WeightScaler(UsageComputer* uc, float scale);
-  ~WeightScaler();
-
- private:
-  UsageComputer* uc_;
-  int old_weight_;
-};
-
-
-// ----------------------------------------------------------------------------
-// Implementation of UsageComputer
-
-bool UsageComputer::Traverse(AstNode* node) {
-  UsageComputer uc(InitialWeight, false);
-  uc.Visit(node);
-  return !uc.HasStackOverflow();
-}
-
-
-void UsageComputer::VisitBlock(Block* node) {
-  VisitStatements(node->statements());
-}
-
-
-void UsageComputer::VisitDeclaration(Declaration* node) {
-  Write(node->proxy());
-  if (node->fun() != NULL)
-    VisitFunctionLiteral(node->fun());
-}
-
-
-void UsageComputer::VisitExpressionStatement(ExpressionStatement* node) {
-  Visit(node->expression());
-}
-
-
-void UsageComputer::VisitEmptyStatement(EmptyStatement* node) {
-  // nothing to do
-}
-
-
-void UsageComputer::VisitIfStatement(IfStatement* node) {
-  Read(node->condition());
-  { WeightScaler ws(this, 0.5);  // executed 50% of the time
-    Visit(node->then_statement());
-    Visit(node->else_statement());
-  }
-}
-
-
-void UsageComputer::VisitContinueStatement(ContinueStatement* node) {
-  // nothing to do
-}
-
-
-void UsageComputer::VisitBreakStatement(BreakStatement* node) {
-  // nothing to do
-}
-
-
-void UsageComputer::VisitReturnStatement(ReturnStatement* node) {
-  Read(node->expression());
-}
-
-
-void UsageComputer::VisitWithEnterStatement(WithEnterStatement* node) {
-  Read(node->expression());
-}
-
-
-void UsageComputer::VisitWithExitStatement(WithExitStatement* node) {
-  // nothing to do
-}
-
-
-void UsageComputer::VisitSwitchStatement(SwitchStatement* node) {
-  Read(node->tag());
-  ZoneList<CaseClause*>* cases = node->cases();
-  for (int i = cases->length(); i-- > 0;) {
-    WeightScaler ws(this, static_cast<float>(1.0 / cases->length()));
-    CaseClause* clause = cases->at(i);
-    if (!clause->is_default())
-      Read(clause->label());
-    VisitStatements(clause->statements());
-  }
-}
-
-
-void UsageComputer::VisitDoWhileStatement(DoWhileStatement* node) {
-  WeightScaler ws(this, 10.0);
-  Read(node->cond());
-  Visit(node->body());
-}
-
-
-void UsageComputer::VisitWhileStatement(WhileStatement* node) {
-  WeightScaler ws(this, 10.0);
-  Read(node->cond());
-  Visit(node->body());
-}
-
-
-void UsageComputer::VisitForStatement(ForStatement* node) {
-  if (node->init() != NULL) Visit(node->init());
-  { WeightScaler ws(this, 10.0);  // executed in each iteration
-    if (node->cond() != NULL) Read(node->cond());
-    if (node->next() != NULL) Visit(node->next());
-    Visit(node->body());
-  }
-}
-
-
-void UsageComputer::VisitForInStatement(ForInStatement* node) {
-  WeightScaler ws(this, 10.0);
-  Write(node->each());
-  Read(node->enumerable());
-  Visit(node->body());
-}
-
-
-void UsageComputer::VisitTryCatchStatement(TryCatchStatement* node) {
-  Visit(node->try_block());
-  { WeightScaler ws(this, 0.25);
-    Write(node->catch_var());
-    Visit(node->catch_block());
-  }
-}
-
-
-void UsageComputer::VisitTryFinallyStatement(TryFinallyStatement* node) {
-  Visit(node->try_block());
-  Visit(node->finally_block());
-}
-
-
-void UsageComputer::VisitDebuggerStatement(DebuggerStatement* node) {
-}
-
-
-void UsageComputer::VisitFunctionLiteral(FunctionLiteral* node) {
-  ZoneList<Declaration*>* decls = node->scope()->declarations();
-  for (int i = 0; i < decls->length(); i++) VisitDeclaration(decls->at(i));
-  VisitStatements(node->body());
-}
-
-
-void UsageComputer::VisitFunctionBoilerplateLiteral(
-    FunctionBoilerplateLiteral* node) {
-  // Do nothing.
-}
-
-
-void UsageComputer::VisitConditional(Conditional* node) {
-  Read(node->condition());
-  { WeightScaler ws(this, 0.5);
-    Read(node->then_expression());
-    Read(node->else_expression());
-  }
-}
-
-
-void UsageComputer::VisitSlot(Slot* node) {
-  UNREACHABLE();
-}
-
-
-void UsageComputer::VisitVariable(Variable* node) {
-  RecordUses(node->var_uses());
-}
-
-
-void UsageComputer::VisitVariableProxy(VariableProxy* node) {
-  // The proxy may refer to a variable in which case it was bound via
-  // VariableProxy::BindTo.
-  RecordUses(node->var_uses());
-}
-
-
-void UsageComputer::VisitLiteral(Literal* node) {
-  // nothing to do
-}
-
-void UsageComputer::VisitRegExpLiteral(RegExpLiteral* node) {
-  // nothing to do
-}
-
-
-void UsageComputer::VisitObjectLiteral(ObjectLiteral* node) {
-  ReadList(node->properties());
-}
-
-
-void UsageComputer::VisitArrayLiteral(ArrayLiteral* node) {
-  ReadList(node->values());
-}
-
-
-void UsageComputer::VisitCatchExtensionObject(CatchExtensionObject* node) {
-  Read(node->value());
-}
-
-
-void UsageComputer::VisitAssignment(Assignment* node) {
-  if (node->op() != Token::ASSIGN)
-    Read(node->target());
-  Write(node->target());
-  Read(node->value());
-}
-
-
-void UsageComputer::VisitThrow(Throw* node) {
-  Read(node->exception());
-}
-
-
-void UsageComputer::VisitProperty(Property* node) {
-  // In any case (read or write) we read both the
-  // node's object and the key.
-  Read(node->obj());
-  Read(node->key());
-  // If the node's object is a variable proxy,
-  // we have a 'simple' object property access. We count
-  // the access via the variable or proxy's object uses.
-  VariableProxy* proxy = node->obj()->AsVariableProxy();
-  if (proxy != NULL) {
-    RecordUses(proxy->obj_uses());
-  }
-}
-
-
-void UsageComputer::VisitCall(Call* node) {
-  Read(node->expression());
-  ReadList(node->arguments());
-}
-
-
-void UsageComputer::VisitCallNew(CallNew* node) {
-  Read(node->expression());
-  ReadList(node->arguments());
-}
-
-
-void UsageComputer::VisitCallRuntime(CallRuntime* node) {
-  ReadList(node->arguments());
-}
-
-
-void UsageComputer::VisitUnaryOperation(UnaryOperation* node) {
-  Read(node->expression());
-}
-
-
-void UsageComputer::VisitCountOperation(CountOperation* node) {
-  Read(node->expression());
-  Write(node->expression());
-}
-
-
-void UsageComputer::VisitBinaryOperation(BinaryOperation* node) {
-  Read(node->left());
-  Read(node->right());
-}
-
-
-void UsageComputer::VisitCompareOperation(CompareOperation* node) {
-  Read(node->left());
-  Read(node->right());
-}
-
-
-void UsageComputer::VisitThisFunction(ThisFunction* node) {
-}
-
-
-UsageComputer::UsageComputer(int weight, bool is_write) {
-  weight_ = weight;
-  is_write_ = is_write;
-}
-
-
-UsageComputer::~UsageComputer() {
-  // nothing to do
-}
-
-
-void UsageComputer::RecordUses(UseCount* uses) {
-  if (is_write_)
-    uses->RecordWrite(weight_);
-  else
-    uses->RecordRead(weight_);
-}
-
-
-void UsageComputer::Read(Expression* x) {
-  if (is_write_) {
-    UsageComputer uc(weight_, false);
-    uc.Visit(x);
-  } else {
-    Visit(x);
-  }
-}
-
-
-void UsageComputer::Write(Expression* x) {
-  if (!is_write_) {
-    UsageComputer uc(weight_, true);
-    uc.Visit(x);
-  } else {
-    Visit(x);
-  }
-}
-
-
-void UsageComputer::ReadList(ZoneList<Expression*>* list) {
-  for (int i = list->length(); i-- > 0; )
-    Read(list->at(i));
-}
-
-
-void UsageComputer::ReadList(ZoneList<ObjectLiteral::Property*>* list) {
-  for (int i = list->length(); i-- > 0; )
-    Read(list->at(i)->value());
-}
-
-
-// ----------------------------------------------------------------------------
-// Implementation of WeightScaler
-
-WeightScaler::WeightScaler(UsageComputer* uc, float scale) {
-  uc_ = uc;
-  old_weight_ = uc->weight_;
-  int new_weight = static_cast<int>(uc->weight_ * scale);
-  if (new_weight <= 0) new_weight = MinWeight;
-  else if (new_weight > MaxWeight) new_weight = MaxWeight;
-  uc->weight_ = new_weight;
-}
-
-
-WeightScaler::~WeightScaler() {
-  uc_->weight_ = old_weight_;
-}
-
-
-// ----------------------------------------------------------------------------
-// Interface to variable usage analysis
-
-bool AnalyzeVariableUsage(FunctionLiteral* lit) {
-  if (!FLAG_usage_computation) return true;
-  HistogramTimerScope timer(&Counters::usage_analysis);
-  return UsageComputer::Traverse(lit);
-}
-
-} }  // namespace v8::internal
diff --git a/src/usage-analyzer.h b/src/usage-analyzer.h
deleted file mode 100644 (file)
index 1b0ea4a..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//     * Redistributions of source code must retain the above copyright
-//       notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-//       copyright notice, this list of conditions and the following
-//       disclaimer in the documentation and/or other materials provided
-//       with the distribution.
-//     * Neither the name of Google Inc. nor the names of its
-//       contributors may be used to endorse or promote products derived
-//       from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#ifndef V8_USAGE_ANALYZER_H_
-#define V8_USAGE_ANALYZER_H_
-
-namespace v8 {
-namespace internal {
-
-// Compute usage counts for all variables.
-// Used for variable allocation.
-bool AnalyzeVariableUsage(FunctionLiteral* lit);
-
-} }  // namespace v8::internal
-
-#endif  // V8_USAGE_ANALYZER_H_
index 3bcd48a8b28d9956f43cd8721f85d86afd3e9255..d7c25320bcc1f9da6d1df3dbc00461f78948ae1d 100644 (file)
 namespace v8 {
 namespace internal {
 
-// ----------------------------------------------------------------------------
-// Implementation UseCount.
-
-UseCount::UseCount()
-  : nreads_(0),
-    nwrites_(0) {
-}
-
-
-void UseCount::RecordRead(int weight) {
-  ASSERT(weight > 0);
-  nreads_ += weight;
-  // We must have a positive nreads_ here. Handle
-  // any kind of overflow by setting nreads_ to
-  // some large-ish value.
-  if (nreads_ <= 0) nreads_ = 1000000;
-  ASSERT(is_read() & is_used());
-}
-
-
-void UseCount::RecordWrite(int weight) {
-  ASSERT(weight > 0);
-  nwrites_ += weight;
-  // We must have a positive nwrites_ here. Handle
-  // any kind of overflow by setting nwrites_ to
-  // some large-ish value.
-  if (nwrites_ <= 0) nwrites_ = 1000000;
-  ASSERT(is_written() && is_used());
-}
-
-
-void UseCount::RecordAccess(int weight) {
-  RecordRead(weight);
-  RecordWrite(weight);
-}
-
-
-void UseCount::RecordUses(UseCount* uses) {
-  if (uses->nreads() > 0) RecordRead(uses->nreads());
-  if (uses->nwrites() > 0) RecordWrite(uses->nwrites());
-}
-
-
-#ifdef DEBUG
-void UseCount::Print() {
-  // PrintF("r = %d, w = %d", nreads_, nwrites_);
-  PrintF("%du = %dr + %dw", nuses(), nreads(), nwrites());
-}
-#endif
-
-
 // ----------------------------------------------------------------------------
 // Implementation StaticType.
 
@@ -148,6 +97,7 @@ Variable::Variable(Scope* scope,
     kind_(kind),
     local_if_not_shadowed_(NULL),
     is_accessed_from_inner_scope_(false),
+    is_used_(false),
     rewrite_(NULL) {
   // names must be canonicalized for fast equality checks
   ASSERT(name->IsSymbol());
index ac7f2940dd67e9b073d4f076e67b8872b1dbf91f..1751f1285dd7dbaf1817411c8da3ccb1e182115b 100644 (file)
 namespace v8 {
 namespace internal {
 
-class UseCount BASE_EMBEDDED {
- public:
-  UseCount();
-
-  // Inform the node of a "use". The weight can be used to indicate
-  // heavier use, for instance if the variable is accessed inside a loop.
-  void RecordRead(int weight);
-  void RecordWrite(int weight);
-  void RecordAccess(int weight);  // records a read & write
-  void RecordUses(UseCount* uses);
-
-  int nreads() const  { return nreads_; }
-  int nwrites() const  { return nwrites_; }
-  int nuses() const  { return nreads_ + nwrites_; }
-
-  bool is_read() const  { return nreads() > 0; }
-  bool is_written() const  { return nwrites() > 0; }
-  bool is_used() const  { return nuses() > 0; }
-
-#ifdef DEBUG
-  void Print();
-#endif
-
- private:
-  int nreads_;
-  int nwrites_;
-};
-
-
 // Variables and AST expression nodes can track their "type" to enable
 // optimizations and removal of redundant checks when generating code.
 
@@ -168,8 +139,8 @@ class Variable: public ZoneObject {
   bool is_accessed_from_inner_scope() const  {
     return is_accessed_from_inner_scope_;
   }
-  UseCount* var_uses()  { return &var_uses_; }
-  UseCount* obj_uses()  { return &obj_uses_; }
+  bool is_used() { return is_used_; }
+  void set_is_used(bool flag) { is_used_ = flag; }
 
   bool IsVariable(Handle<String> n) const {
     return !is_this() && name().is_identical_to(n);
@@ -216,8 +187,7 @@ class Variable: public ZoneObject {
 
   // Usage info.
   bool is_accessed_from_inner_scope_;  // set by variable resolver
-  UseCount var_uses_;  // uses of the variable value
-  UseCount obj_uses_;  // uses of the object the variable points to
+  bool is_used_;
 
   // Static type information
   StaticType type_;
index 7882d6a8edf44a359354ea9f844280a0cd5e8613..59ec566d5723d2956f507de05d24ddd280e60683 100644 (file)
         '../../src/unicode-inl.h',
         '../../src/unicode.cc',
         '../../src/unicode.h',
-        '../../src/usage-analyzer.cc',
-        '../../src/usage-analyzer.h',
         '../../src/utils.cc',
         '../../src/utils.h',
         '../../src/v8-counters.cc',
         '../../src/variables.h',
         '../../src/version.cc',
         '../../src/version.h',
-        '../../src/virtual-frame-inl.h',       
-        '../../src/virtual-frame.h',
+        '../../src/virtual-frame-inl.h',
         '../../src/virtual-frame.cc',
+        '../../src/virtual-frame.h',
         '../../src/zone-inl.h',
         '../../src/zone.cc',
         '../../src/zone.h',
index 6238044611b474c6c8b11d1403d11415bce274a2..1a7e14c3a58078443cf8544e0e689555849cf83c 100644 (file)
                                RelativePath="..\..\src\unicode.h"
                                >
                        </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.cc"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.h"
-                               >
-                       </File>
                        <File
                                RelativePath="..\..\src\utils.cc"
                                >
index 7f97da674effbf06d4588a1c7b81a8ab72a8d254..346c5eb19c98a27c153829fc2d3a123d76b9b8ef 100644 (file)
                                RelativePath="..\..\src\unicode.h"
                                >
                        </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.cc"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.h"
-                               >
-                       </File>
                        <File
                                RelativePath="..\..\src\utils.cc"
                                >
index b7ad20d5d94cf216baff476aa1c49a43ebf7c1f3..120dd190d7586dca23ad88b1898ac3097afb7331 100644 (file)
                                RelativePath="..\..\src\unicode.h"
                                >
                        </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.cc"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\src\usage-analyzer.h"
-                               >
-                       </File>
                        <File
                                RelativePath="..\..\src\utils.cc"
                                >