From: fschneider@chromium.org Date: Fri, 19 Mar 2010 12:54:35 +0000 (+0000) Subject: Remove unused LivenessAnalyzer class. X-Git-Tag: upstream/4.7.83~22196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ebf9e6e8e24786e48f55e910524f0ee186ad4550;p=platform%2Fupstream%2Fv8.git Remove unused LivenessAnalyzer class. Also remove unused attributes related to it from the ast. Review URL: http://codereview.chromium.org/1117003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4194 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/ast.h b/src/ast.h index 262bf17c7..8248f62a8 100644 --- a/src/ast.h +++ b/src/ast.h @@ -196,10 +196,7 @@ class Expression: public AstNode { kTestValue }; - Expression() - : bitfields_(0), - def_(NULL), - defined_vars_(NULL) {} + Expression() : bitfields_(0) {} virtual Expression* AsExpression() { return this; } @@ -233,15 +230,6 @@ class Expression: public AstNode { // Static type information for this expression. StaticType* type() { return &type_; } - // Data flow information. - DefinitionInfo* var_def() { return def_; } - void set_var_def(DefinitionInfo* def) { def_ = def; } - - ZoneList* defined_vars() { return defined_vars_; } - void set_defined_vars(ZoneList* defined_vars) { - defined_vars_ = defined_vars; - } - // AST analysis results // True if the expression rooted at this node can be compiled by the @@ -284,9 +272,6 @@ class Expression: public AstNode { uint32_t bitfields_; StaticType type_; - DefinitionInfo* def_; - ZoneList* defined_vars_; - // Using template BitField. class SideEffectFreeField : public BitField {}; class NoNegativeZeroField : public BitField {}; diff --git a/src/data-flow.cc b/src/data-flow.cc index 278b82bc6..141718dc8 100644 --- a/src/data-flow.cc +++ b/src/data-flow.cc @@ -770,293 +770,6 @@ void AstLabeler::VisitDeclaration(Declaration* decl) { } -ZoneList* VarUseMap::Lookup(Variable* var) { - HashMap::Entry* entry = HashMap::Lookup(var, var->name()->Hash(), true); - if (entry->value == NULL) { - entry->value = new ZoneList(1); - } - return reinterpret_cast*>(entry->value); -} - - -void LivenessAnalyzer::Analyze(FunctionLiteral* fun) { - // Process the function body. - VisitStatements(fun->body()); - - // All variables are implicitly defined at the function start. - // Record a definition of all variables live at function entry. - for (HashMap::Entry* p = live_vars_.Start(); - p != NULL; - p = live_vars_.Next(p)) { - Variable* var = reinterpret_cast(p->key); - RecordDef(var, fun); - } -} - - -void LivenessAnalyzer::VisitStatements(ZoneList* stmts) { - // Visit statements right-to-left. - for (int i = stmts->length() - 1; i >= 0; i--) { - Visit(stmts->at(i)); - } -} - - -void LivenessAnalyzer::RecordUse(Variable* var, Expression* expr) { - ASSERT(var->is_global() || var->is_this()); - ZoneList* uses = live_vars_.Lookup(var); - uses->Add(expr); -} - - -void LivenessAnalyzer::RecordDef(Variable* var, Expression* expr) { - ASSERT(var->is_global() || var->is_this()); - - // We do not support other expressions that can define variables. - ASSERT(expr->AsFunctionLiteral() != NULL); - - // Add the variable to the list of defined variables. - if (expr->defined_vars() == NULL) { - expr->set_defined_vars(new ZoneList(1)); - } - DefinitionInfo* def = new DefinitionInfo(); - expr->AsFunctionLiteral()->defined_vars()->Add(def); - - // Compute the last use of the definition. The variable uses are - // inserted in reversed evaluation order. The first element - // in the list of live uses is the last use. - ZoneList* uses = live_vars_.Lookup(var); - while (uses->length() > 0) { - Expression* use_site = uses->RemoveLast(); - use_site->set_var_def(def); - if (uses->length() == 0) { - def->set_last_use(use_site); - } - } -} - - -// Visitor functions for live variable analysis. -void LivenessAnalyzer::VisitDeclaration(Declaration* decl) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitBlock(Block* stmt) { - VisitStatements(stmt->statements()); -} - - -void LivenessAnalyzer::VisitExpressionStatement( - ExpressionStatement* stmt) { - Visit(stmt->expression()); -} - - -void LivenessAnalyzer::VisitEmptyStatement(EmptyStatement* stmt) { - // Do nothing. -} - - -void LivenessAnalyzer::VisitIfStatement(IfStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitContinueStatement(ContinueStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitBreakStatement(BreakStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitReturnStatement(ReturnStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitWithEnterStatement( - WithEnterStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitWithExitStatement(WithExitStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitSwitchStatement(SwitchStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitDoWhileStatement(DoWhileStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitWhileStatement(WhileStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitForStatement(ForStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitForInStatement(ForInStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitTryCatchStatement(TryCatchStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitTryFinallyStatement( - TryFinallyStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitDebuggerStatement( - DebuggerStatement* stmt) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitFunctionLiteral(FunctionLiteral* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitFunctionBoilerplateLiteral( - FunctionBoilerplateLiteral* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitConditional(Conditional* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitSlot(Slot* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitVariableProxy(VariableProxy* expr) { - Variable* var = expr->var(); - ASSERT(var->is_global()); - ASSERT(!var->is_this()); - RecordUse(var, expr); -} - - -void LivenessAnalyzer::VisitLiteral(Literal* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitRegExpLiteral(RegExpLiteral* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitObjectLiteral(ObjectLiteral* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitArrayLiteral(ArrayLiteral* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitCatchExtensionObject( - CatchExtensionObject* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitAssignment(Assignment* expr) { - Property* prop = expr->target()->AsProperty(); - ASSERT(prop != NULL); - ASSERT(prop->key()->IsPropertyName()); - VariableProxy* proxy = prop->obj()->AsVariableProxy(); - ASSERT(proxy != NULL && proxy->var()->is_this()); - - // Record use of this at the assignment node. Assignments to - // this-properties are treated like unary operations. - RecordUse(proxy->var(), expr); - - // Visit right-hand side. - Visit(expr->value()); -} - - -void LivenessAnalyzer::VisitThrow(Throw* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitProperty(Property* expr) { - ASSERT(expr->key()->IsPropertyName()); - VariableProxy* proxy = expr->obj()->AsVariableProxy(); - ASSERT(proxy != NULL && proxy->var()->is_this()); - RecordUse(proxy->var(), expr); -} - - -void LivenessAnalyzer::VisitCall(Call* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitCallNew(CallNew* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitCallRuntime(CallRuntime* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitUnaryOperation(UnaryOperation* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitCountOperation(CountOperation* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitBinaryOperation(BinaryOperation* expr) { - // Visit child nodes in reverse evaluation order. - Visit(expr->right()); - Visit(expr->left()); -} - - -void LivenessAnalyzer::VisitCompareOperation(CompareOperation* expr) { - UNREACHABLE(); -} - - -void LivenessAnalyzer::VisitThisFunction(ThisFunction* expr) { - UNREACHABLE(); -} - - AssignedVariablesAnalyzer::AssignedVariablesAnalyzer(FunctionLiteral* fun) : fun_(fun), av_(fun->scope()->num_parameters() + fun->scope()->num_stack_slots()) {} diff --git a/src/data-flow.h b/src/data-flow.h index 97020137a..74a370c0d 100644 --- a/src/data-flow.h +++ b/src/data-flow.h @@ -550,55 +550,6 @@ class AstLabeler: public AstVisitor { }; -class VarUseMap : public HashMap { - public: - VarUseMap() : HashMap(VarMatch) {} - - ZoneList* Lookup(Variable* var); - - private: - static bool VarMatch(void* key1, void* key2) { return key1 == key2; } -}; - - -class DefinitionInfo : public ZoneObject { - public: - explicit DefinitionInfo() : last_use_(NULL) {} - - Expression* last_use() { return last_use_; } - void set_last_use(Expression* expr) { last_use_ = expr; } - - private: - Expression* last_use_; - Register location_; -}; - - -class LivenessAnalyzer : public AstVisitor { - public: - LivenessAnalyzer() {} - - void Analyze(FunctionLiteral* fun); - - private: - void VisitStatements(ZoneList* stmts); - - void RecordUse(Variable* var, Expression* expr); - void RecordDef(Variable* var, Expression* expr); - - - // AST node visit functions. -#define DECLARE_VISIT(type) virtual void Visit##type(type* node); - AST_NODE_LIST(DECLARE_VISIT) -#undef DECLARE_VISIT - - // Map for tracking the live variables. - VarUseMap live_vars_; - - DISALLOW_COPY_AND_ASSIGN(LivenessAnalyzer); -}; - - // Computes the set of assigned variables and annotates variables proxies // that are trivial sub-expressions and for-loops where the loop variable // is guaranteed to be a smi. diff --git a/src/fast-codegen.cc b/src/fast-codegen.cc index 602d6b88c..5d0b9c1db 100644 --- a/src/fast-codegen.cc +++ b/src/fast-codegen.cc @@ -436,9 +436,6 @@ Handle FastCodeGenerator::MakeCode(CompilationInfo* info) { AstLabeler labeler; labeler.Label(info); - LivenessAnalyzer analyzer; - analyzer.Analyze(info->function()); - CodeGenerator::MakeCodePrologue(info); const int kInitialBufferSize = 4 * KB; @@ -598,8 +595,8 @@ void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { Comment cmnt(masm(), ";; Global"); if (FLAG_print_ir) { SmartPointer name = expr->name()->ToCString(); - PrintF("%d: t%d = Global(%s) // last_use = %d\n", expr->num(), - expr->num(), *name, expr->var_def()->last_use()->num()); + PrintF("%d: t%d = Global(%s)\n", expr->num(), + expr->num(), *name); } EmitGlobalVariableLoad(cell); } @@ -653,9 +650,8 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { SmartPointer name_string = name->ToCString(); PrintF("%d: ", expr->num()); if (!destination().is(no_reg)) PrintF("t%d = ", expr->num()); - PrintF("Store(this, \"%s\", t%d) // last_use(this) = %d\n", *name_string, - expr->value()->num(), - expr->var_def()->last_use()->num()); + PrintF("Store(this, \"%s\", t%d)\n", *name_string, + expr->value()->num()); } EmitThisPropertyStore(name); @@ -678,9 +674,8 @@ void FastCodeGenerator::VisitProperty(Property* expr) { Comment cmnt(masm(), ";; Load from this"); if (FLAG_print_ir) { SmartPointer name_string = name->ToCString(); - PrintF("%d: t%d = Load(this, \"%s\") // last_use(this) = %d\n", - expr->num(), expr->num(), *name_string, - expr->var_def()->last_use()->num()); + PrintF("%d: t%d = Load(this, \"%s\")\n", + expr->num(), expr->num(), *name_string); } EmitThisPropertyLoad(name); } diff --git a/src/ia32/fast-codegen-ia32.cc b/src/ia32/fast-codegen-ia32.cc index 4dcf2329a..01190a598 100644 --- a/src/ia32/fast-codegen-ia32.cc +++ b/src/ia32/fast-codegen-ia32.cc @@ -436,9 +436,6 @@ Handle FastCodeGenerator::MakeCode(CompilationInfo* info) { AstLabeler labeler; labeler.Label(info); - LivenessAnalyzer analyzer; - analyzer.Analyze(info->function()); - CodeGenerator::MakeCodePrologue(info); const int kInitialBufferSize = 4 * KB; @@ -802,8 +799,8 @@ void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { Comment cmnt(masm(), ";; Global"); if (FLAG_print_ir) { SmartPointer name = expr->name()->ToCString(); - PrintF("%d: t%d = Global(%s) // last_use = %d\n", expr->num(), - expr->num(), *name, expr->var_def()->last_use()->num()); + PrintF("%d: t%d = Global(%s)\n", expr->num(), + expr->num(), *name); } EmitGlobalVariableLoad(cell); } @@ -857,9 +854,8 @@ void FastCodeGenerator::VisitAssignment(Assignment* expr) { SmartPointer name_string = name->ToCString(); PrintF("%d: ", expr->num()); if (!destination().is(no_reg)) PrintF("t%d = ", expr->num()); - PrintF("Store(this, \"%s\", t%d) // last_use(this) = %d\n", *name_string, - expr->value()->num(), - expr->var_def()->last_use()->num()); + PrintF("Store(this, \"%s\", t%d)\n", *name_string, + expr->value()->num()); } EmitThisPropertyStore(name); @@ -882,9 +878,8 @@ void FastCodeGenerator::VisitProperty(Property* expr) { Comment cmnt(masm(), ";; Load from this"); if (FLAG_print_ir) { SmartPointer name_string = name->ToCString(); - PrintF("%d: t%d = Load(this, \"%s\") // last_use(this) = %d\n", - expr->num(), expr->num(), *name_string, - expr->var_def()->last_use()->num()); + PrintF("%d: t%d = Load(this, \"%s\")\n", + expr->num(), expr->num(), *name_string); } EmitThisPropertyLoad(name); }