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);
} }
} }
......
This diff is collapsed.
// 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',
...@@ -391,8 +389,8 @@ ...@@ -391,8 +389,8 @@
'../../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