Remove unneeded variable usage analysis.

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
parent 8528d650
...@@ -97,7 +97,6 @@ SOURCES = { ...@@ -97,7 +97,6 @@ SOURCES = {
token.cc token.cc
top.cc top.cc
unicode.cc unicode.cc
usage-analyzer.cc
utils.cc utils.cc
v8-counters.cc v8-counters.cc
v8.cc v8.cc
......
...@@ -67,8 +67,6 @@ VariableProxy::VariableProxy(Handle<String> name, ...@@ -67,8 +67,6 @@ VariableProxy::VariableProxy(Handle<String> name,
inside_with_(inside_with) { inside_with_(inside_with) {
// names must be canonicalized for fast equality checks // names must be canonicalized for fast equality checks
ASSERT(name->IsSymbol()); 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) { ...@@ -87,8 +85,7 @@ void VariableProxy::BindTo(Variable* var) {
// eval() etc. Const-ness and variable declarations are a complete mess // eval() etc. Const-ness and variable declarations are a complete mess
// in JS. Sigh... // in JS. Sigh...
var_ = var; var_ = var;
var->var_uses()->RecordUses(&var_uses_); var->set_is_used(true);
var->obj_uses()->RecordUses(&obj_uses_);
} }
......
...@@ -1006,8 +1006,6 @@ class VariableProxy: public Expression { ...@@ -1006,8 +1006,6 @@ class VariableProxy: public Expression {
Handle<String> name() const { return name_; } Handle<String> name() const { return name_; }
Variable* var() const { return var_; } 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 is_this() const { return is_this_; }
bool inside_with() const { return inside_with_; } bool inside_with() const { return inside_with_; }
...@@ -1020,10 +1018,6 @@ class VariableProxy: public Expression { ...@@ -1020,10 +1018,6 @@ class VariableProxy: public Expression {
bool is_this_; bool is_this_;
bool inside_with_; 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); VariableProxy(Handle<String> name, bool is_this, bool inside_with);
explicit VariableProxy(bool is_this); explicit VariableProxy(bool is_this);
......
...@@ -35,11 +35,10 @@ ...@@ -35,11 +35,10 @@
#include "debug.h" #include "debug.h"
#include "fast-codegen.h" #include "fast-codegen.h"
#include "full-codegen.h" #include "full-codegen.h"
#include "liveedit.h"
#include "oprofile-agent.h" #include "oprofile-agent.h"
#include "rewriter.h" #include "rewriter.h"
#include "scopes.h" #include "scopes.h"
#include "usage-analyzer.h"
#include "liveedit.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
...@@ -49,7 +48,7 @@ static Handle<Code> MakeCode(Handle<Context> context, CompilationInfo* info) { ...@@ -49,7 +48,7 @@ static Handle<Code> MakeCode(Handle<Context> context, CompilationInfo* info) {
FunctionLiteral* function = info->function(); FunctionLiteral* function = info->function();
ASSERT(function != NULL); ASSERT(function != NULL);
// Rewrite the AST by introducing .result assignments where needed. // 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 // Signal a stack overflow by returning a null handle. The stack
// overflow exception will be thrown by the caller. // overflow exception will be thrown by the caller.
return Handle<Code>::null(); return Handle<Code>::null();
......
...@@ -232,9 +232,6 @@ DEFINE_bool(trace_exception, false, ...@@ -232,9 +232,6 @@ DEFINE_bool(trace_exception, false,
DEFINE_bool(preallocate_message_memory, false, DEFINE_bool(preallocate_message_memory, false,
"preallocate some memory to build stack traces.") "preallocate some memory to build stack traces.")
// usage-analyzer.cc
DEFINE_bool(usage_computation, true, "compute variable usage counts")
// v8.cc // v8.cc
DEFINE_bool(preemption, false, DEFINE_bool(preemption, false,
"activate a 100ms timer that switches between V8 threads") "activate a 100ms timer that switches between V8 threads")
......
...@@ -3256,7 +3256,6 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) { ...@@ -3256,7 +3256,6 @@ Expression* Parser::ParsePrimaryExpression(bool* ok) {
result = VariableProxySentinel::this_proxy(); result = VariableProxySentinel::this_proxy();
} else { } else {
VariableProxy* recv = top_scope_->receiver(); VariableProxy* recv = top_scope_->receiver();
recv->var_uses()->RecordRead(1);
result = recv; result = recv;
} }
break; break;
......
...@@ -82,7 +82,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope) ...@@ -82,7 +82,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope)
List<Variable*, Allocator> heap_locals(locals.length()); List<Variable*, Allocator> heap_locals(locals.length());
for (int i = 0; i < locals.length(); i++) { for (int i = 0; i < locals.length(); i++) {
Variable* var = locals[i]; Variable* var = locals[i];
if (var->var_uses()->is_used()) { if (var->is_used()) {
Slot* slot = var->slot(); Slot* slot = var->slot();
if (slot != NULL) { if (slot != NULL) {
switch (slot->type()) { switch (slot->type()) {
...@@ -130,7 +130,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope) ...@@ -130,7 +130,7 @@ ScopeInfo<Allocator>::ScopeInfo(Scope* scope)
if (scope->is_function_scope()) { if (scope->is_function_scope()) {
Variable* var = scope->function(); Variable* var = scope->function();
if (var != NULL && if (var != NULL &&
var->var_uses()->is_used() && var->is_used() &&
var->slot()->type() == Slot::CONTEXT) { var->slot()->type() == Slot::CONTEXT) {
function_name_ = var->name(); function_name_ = var->name();
// Note that we must not find the function name in the context slot // Note that we must not find the function name in the context slot
......
...@@ -309,7 +309,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { ...@@ -309,7 +309,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
// which is the current user of this function). // which is the current user of this function).
for (int i = 0; i < temps_.length(); i++) { for (int i = 0; i < temps_.length(); i++) {
Variable* var = temps_[i]; Variable* var = temps_[i];
if (var->var_uses()->is_used()) { if (var->is_used()) {
locals->Add(var); locals->Add(var);
} }
} }
...@@ -317,7 +317,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { ...@@ -317,7 +317,7 @@ void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
p != NULL; p != NULL;
p = variables_.Next(p)) { p = variables_.Next(p)) {
Variable* var = reinterpret_cast<Variable*>(p->value); Variable* var = reinterpret_cast<Variable*>(p->value);
if (var->var_uses()->is_used()) { if (var->is_used()) {
locals->Add(var); locals->Add(var);
} }
} }
...@@ -418,17 +418,16 @@ static void PrintName(Handle<String> name) { ...@@ -418,17 +418,16 @@ static void PrintName(Handle<String> name) {
static void PrintVar(PrettyPrinter* printer, int indent, Variable* var) { 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())); Indent(indent, Variable::Mode2String(var->mode()));
PrintF(" "); PrintF(" ");
PrintName(var->name()); PrintName(var->name());
PrintF("; // "); PrintF("; // ");
if (var->rewrite() != NULL) PrintF("%s, ", printer->Print(var->rewrite())); if (var->rewrite() != NULL) {
if (var->is_accessed_from_inner_scope()) PrintF("inner scope access, "); PrintF("%s, ", printer->Print(var->rewrite()));
PrintF("var "); if (var->is_accessed_from_inner_scope()) PrintF(", ");
var->var_uses()->Print(); }
PrintF(", obj "); if (var->is_accessed_from_inner_scope()) PrintF("inner scope access");
var->obj_uses()->Print();
PrintF("\n"); PrintF("\n");
} }
} }
...@@ -738,10 +737,10 @@ bool Scope::MustAllocate(Variable* var) { ...@@ -738,10 +737,10 @@ bool Scope::MustAllocate(Variable* var) {
(var->is_accessed_from_inner_scope_ || (var->is_accessed_from_inner_scope_ ||
scope_calls_eval_ || inner_scope_calls_eval_ || scope_calls_eval_ || inner_scope_calls_eval_ ||
scope_contains_with_)) { scope_contains_with_)) {
var->var_uses()->RecordAccess(1); var->set_is_used(true);
} }
// Global variables do not need to be allocated. // 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() { ...@@ -847,7 +846,7 @@ void Scope::AllocateParameterLocals() {
new Literal(Handle<Object>(Smi::FromInt(i))), new Literal(Handle<Object>(Smi::FromInt(i))),
RelocInfo::kNoPosition, RelocInfo::kNoPosition,
Property::SYNTHETIC); Property::SYNTHETIC);
arguments_shadow->var_uses()->RecordUses(var->var_uses()); if (var->is_used()) arguments_shadow->set_is_used(true);
} }
} }
......
// 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
// 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_
...@@ -34,57 +34,6 @@ ...@@ -34,57 +34,6 @@
namespace v8 { namespace v8 {
namespace internal { 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. // Implementation StaticType.
...@@ -148,6 +97,7 @@ Variable::Variable(Scope* scope, ...@@ -148,6 +97,7 @@ Variable::Variable(Scope* scope,
kind_(kind), kind_(kind),
local_if_not_shadowed_(NULL), local_if_not_shadowed_(NULL),
is_accessed_from_inner_scope_(false), is_accessed_from_inner_scope_(false),
is_used_(false),
rewrite_(NULL) { rewrite_(NULL) {
// names must be canonicalized for fast equality checks // names must be canonicalized for fast equality checks
ASSERT(name->IsSymbol()); ASSERT(name->IsSymbol());
......
...@@ -33,35 +33,6 @@ ...@@ -33,35 +33,6 @@
namespace v8 { namespace v8 {
namespace internal { 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 // Variables and AST expression nodes can track their "type" to enable
// optimizations and removal of redundant checks when generating code. // optimizations and removal of redundant checks when generating code.
...@@ -168,8 +139,8 @@ class Variable: public ZoneObject { ...@@ -168,8 +139,8 @@ class Variable: public ZoneObject {
bool is_accessed_from_inner_scope() const { bool is_accessed_from_inner_scope() const {
return is_accessed_from_inner_scope_; return is_accessed_from_inner_scope_;
} }
UseCount* var_uses() { return &var_uses_; } bool is_used() { return is_used_; }
UseCount* obj_uses() { return &obj_uses_; } void set_is_used(bool flag) { is_used_ = flag; }
bool IsVariable(Handle<String> n) const { bool IsVariable(Handle<String> n) const {
return !is_this() && name().is_identical_to(n); return !is_this() && name().is_identical_to(n);
...@@ -216,8 +187,7 @@ class Variable: public ZoneObject { ...@@ -216,8 +187,7 @@ class Variable: public ZoneObject {
// Usage info. // Usage info.
bool is_accessed_from_inner_scope_; // set by variable resolver bool is_accessed_from_inner_scope_; // set by variable resolver
UseCount var_uses_; // uses of the variable value bool is_used_;
UseCount obj_uses_; // uses of the object the variable points to
// Static type information // Static type information
StaticType type_; StaticType type_;
......
...@@ -376,8 +376,6 @@ ...@@ -376,8 +376,6 @@
'../../src/unicode-inl.h', '../../src/unicode-inl.h',
'../../src/unicode.cc', '../../src/unicode.cc',
'../../src/unicode.h', '../../src/unicode.h',
'../../src/usage-analyzer.cc',
'../../src/usage-analyzer.h',
'../../src/utils.cc', '../../src/utils.cc',
'../../src/utils.h', '../../src/utils.h',
'../../src/v8-counters.cc', '../../src/v8-counters.cc',
...@@ -390,9 +388,9 @@ ...@@ -390,9 +388,9 @@
'../../src/variables.h', '../../src/variables.h',
'../../src/version.cc', '../../src/version.cc',
'../../src/version.h', '../../src/version.h',
'../../src/virtual-frame-inl.h', '../../src/virtual-frame-inl.h',
'../../src/virtual-frame.h',
'../../src/virtual-frame.cc', '../../src/virtual-frame.cc',
'../../src/virtual-frame.h',
'../../src/zone-inl.h', '../../src/zone-inl.h',
'../../src/zone.cc', '../../src/zone.cc',
'../../src/zone.h', '../../src/zone.h',
......
...@@ -880,14 +880,6 @@ ...@@ -880,14 +880,6 @@
RelativePath="..\..\src\unicode.h" RelativePath="..\..\src\unicode.h"
> >
</File> </File>
<File
RelativePath="..\..\src\usage-analyzer.cc"
>
</File>
<File
RelativePath="..\..\src\usage-analyzer.h"
>
</File>
<File <File
RelativePath="..\..\src\utils.cc" RelativePath="..\..\src\utils.cc"
> >
......
...@@ -892,14 +892,6 @@ ...@@ -892,14 +892,6 @@
RelativePath="..\..\src\unicode.h" RelativePath="..\..\src\unicode.h"
> >
</File> </File>
<File
RelativePath="..\..\src\usage-analyzer.cc"
>
</File>
<File
RelativePath="..\..\src\usage-analyzer.h"
>
</File>
<File <File
RelativePath="..\..\src\utils.cc" RelativePath="..\..\src\utils.cc"
> >
......
...@@ -881,14 +881,6 @@ ...@@ -881,14 +881,6 @@
RelativePath="..\..\src\unicode.h" RelativePath="..\..\src\unicode.h"
> >
</File> </File>
<File
RelativePath="..\..\src\usage-analyzer.cc"
>
</File>
<File
RelativePath="..\..\src\usage-analyzer.h"
>
</File>
<File <File
RelativePath="..\..\src\utils.cc" RelativePath="..\..\src\utils.cc"
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment