Remove unnecessary AST node for ++ and -- operations.

Instead of adding an extra AST node we can just use an auxiliary
bailout id for named and keyed property count operations.
Review URL: http://codereview.chromium.org/6810015

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7524 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 68482dbc
...@@ -3885,7 +3885,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -3885,7 +3885,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
if (assign_type == VARIABLE) { if (assign_type == VARIABLE) {
PrepareForBailout(expr->expression(), TOS_REG); PrepareForBailout(expr->expression(), TOS_REG);
} else { } else {
PrepareForBailout(expr->increment(), TOS_REG); PrepareForBailoutForId(expr->CountId(), TOS_REG);
} }
// Call ToNumber only if operand is not a smi. // Call ToNumber only if operand is not a smi.
......
...@@ -88,7 +88,6 @@ namespace internal { ...@@ -88,7 +88,6 @@ namespace internal {
V(CallNew) \ V(CallNew) \
V(CallRuntime) \ V(CallRuntime) \
V(UnaryOperation) \ V(UnaryOperation) \
V(IncrementOperation) \
V(CountOperation) \ V(CountOperation) \
V(BinaryOperation) \ V(BinaryOperation) \
V(CompareOperation) \ V(CompareOperation) \
...@@ -1487,45 +1486,27 @@ class BinaryOperation: public Expression { ...@@ -1487,45 +1486,27 @@ class BinaryOperation: public Expression {
}; };
class IncrementOperation: public Expression {
public:
IncrementOperation(Token::Value op, Expression* expr)
: op_(op), expression_(expr) {
ASSERT(Token::IsCountOp(op));
}
DECLARE_NODE_TYPE(IncrementOperation)
Token::Value op() const { return op_; }
bool is_increment() { return op_ == Token::INC; }
Expression* expression() const { return expression_; }
private:
Token::Value op_;
Expression* expression_;
int pos_;
};
class CountOperation: public Expression { class CountOperation: public Expression {
public: public:
CountOperation(bool is_prefix, IncrementOperation* increment, int pos) CountOperation(Token::Value op, bool is_prefix, Expression* expr, int pos)
: is_prefix_(is_prefix), increment_(increment), pos_(pos), : op_(op),
assignment_id_(GetNextId()) { is_prefix_(is_prefix),
} expression_(expr),
pos_(pos),
assignment_id_(GetNextId()),
count_id_(GetNextId()) { }
DECLARE_NODE_TYPE(CountOperation) DECLARE_NODE_TYPE(CountOperation)
bool is_prefix() const { return is_prefix_; } bool is_prefix() const { return is_prefix_; }
bool is_postfix() const { return !is_prefix_; } bool is_postfix() const { return !is_prefix_; }
Token::Value op() const { return increment_->op(); } Token::Value op() const { return op_; }
Token::Value binary_op() { Token::Value binary_op() {
return (op() == Token::INC) ? Token::ADD : Token::SUB; return (op() == Token::INC) ? Token::ADD : Token::SUB;
} }
Expression* expression() const { return increment_->expression(); } Expression* expression() const { return expression_; }
IncrementOperation* increment() const { return increment_; }
int position() const { return pos_; } int position() const { return pos_; }
virtual void MarkAsStatement() { is_prefix_ = true; } virtual void MarkAsStatement() { is_prefix_ = true; }
...@@ -1534,12 +1515,15 @@ class CountOperation: public Expression { ...@@ -1534,12 +1515,15 @@ class CountOperation: public Expression {
// Bailout support. // Bailout support.
int AssignmentId() const { return assignment_id_; } int AssignmentId() const { return assignment_id_; }
int CountId() const { return count_id_; }
private: private:
Token::Value op_;
bool is_prefix_; bool is_prefix_;
IncrementOperation* increment_; Expression* expression_;
int pos_; int pos_;
int assignment_id_; int assignment_id_;
int count_id_;
}; };
......
...@@ -358,11 +358,6 @@ void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) { ...@@ -358,11 +358,6 @@ void CodeGenerator::ProcessDeclarations(ZoneList<Declaration*>* declarations) {
} }
void CodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
UNREACHABLE();
}
// Lookup table for code generators for special runtime calls which are // Lookup table for code generators for special runtime calls which are
// generated inline. // generated inline.
#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \ #define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
......
...@@ -490,12 +490,6 @@ void AssignedVariablesAnalyzer::VisitUnaryOperation(UnaryOperation* expr) { ...@@ -490,12 +490,6 @@ void AssignedVariablesAnalyzer::VisitUnaryOperation(UnaryOperation* expr) {
} }
void AssignedVariablesAnalyzer::VisitIncrementOperation(
IncrementOperation* expr) {
UNREACHABLE();
}
void AssignedVariablesAnalyzer::VisitCountOperation(CountOperation* expr) { void AssignedVariablesAnalyzer::VisitCountOperation(CountOperation* expr) {
ASSERT(av_.IsEmpty()); ASSERT(av_.IsEmpty());
if (expr->is_prefix()) MarkIfTrivial(expr->expression()); if (expr->is_prefix()) MarkIfTrivial(expr->expression());
......
...@@ -213,12 +213,6 @@ void BreakableStatementChecker::VisitThrow(Throw* expr) { ...@@ -213,12 +213,6 @@ void BreakableStatementChecker::VisitThrow(Throw* expr) {
} }
void BreakableStatementChecker::VisitIncrementOperation(
IncrementOperation* expr) {
UNREACHABLE();
}
void BreakableStatementChecker::VisitProperty(Property* expr) { void BreakableStatementChecker::VisitProperty(Property* expr) {
// Property load is breakable. // Property load is breakable.
is_breakable_ = true; is_breakable_ = true;
...@@ -1357,11 +1351,6 @@ void FullCodeGenerator::VisitThrow(Throw* expr) { ...@@ -1357,11 +1351,6 @@ void FullCodeGenerator::VisitThrow(Throw* expr) {
} }
void FullCodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
UNREACHABLE();
}
int FullCodeGenerator::TryFinally::Exit(int stack_depth) { int FullCodeGenerator::TryFinally::Exit(int stack_depth) {
// The macros used here must preserve the result register. // The macros used here must preserve the result register.
__ Drop(stack_depth); __ Drop(stack_depth);
......
...@@ -4612,13 +4612,6 @@ void HGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) { ...@@ -4612,13 +4612,6 @@ void HGraphBuilder::VisitUnaryOperation(UnaryOperation* expr) {
} }
void HGraphBuilder::VisitIncrementOperation(IncrementOperation* expr) {
// IncrementOperation is never visited by the visitor. It only
// occurs as a subexpression of CountOperation.
UNREACHABLE();
}
HInstruction* HGraphBuilder::BuildIncrement(HValue* value, bool increment) { HInstruction* HGraphBuilder::BuildIncrement(HValue* value, bool increment) {
HConstant* delta = increment HConstant* delta = increment
? graph_->GetConstant1() ? graph_->GetConstant1()
...@@ -4630,8 +4623,7 @@ HInstruction* HGraphBuilder::BuildIncrement(HValue* value, bool increment) { ...@@ -4630,8 +4623,7 @@ HInstruction* HGraphBuilder::BuildIncrement(HValue* value, bool increment) {
void HGraphBuilder::VisitCountOperation(CountOperation* expr) { void HGraphBuilder::VisitCountOperation(CountOperation* expr) {
IncrementOperation* increment = expr->increment(); Expression* target = expr->expression();
Expression* target = increment->expression();
VariableProxy* proxy = target->AsVariableProxy(); VariableProxy* proxy = target->AsVariableProxy();
Variable* var = proxy->AsVariable(); Variable* var = proxy->AsVariable();
Property* prop = target->AsProperty(); Property* prop = target->AsProperty();
...@@ -4692,7 +4684,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -4692,7 +4684,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) {
load = BuildLoadNamedGeneric(obj, prop); load = BuildLoadNamedGeneric(obj, prop);
} }
PushAndAdd(load); PushAndAdd(load);
if (load->HasSideEffects()) AddSimulate(increment->id()); if (load->HasSideEffects()) AddSimulate(expr->CountId());
HValue* before = Pop(); HValue* before = Pop();
// There is no deoptimization to after the increment, so we don't need // There is no deoptimization to after the increment, so we don't need
...@@ -4733,7 +4725,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -4733,7 +4725,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) {
? BuildLoadKeyedFastElement(obj, key, prop) ? BuildLoadKeyedFastElement(obj, key, prop)
: BuildLoadKeyedGeneric(obj, key); : BuildLoadKeyedGeneric(obj, key);
PushAndAdd(load); PushAndAdd(load);
if (load->HasSideEffects()) AddSimulate(increment->id()); if (load->HasSideEffects()) AddSimulate(expr->CountId());
HValue* before = Pop(); HValue* before = Pop();
// There is no deoptimization to after the increment, so we don't need // There is no deoptimization to after the increment, so we don't need
......
...@@ -3835,7 +3835,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -3835,7 +3835,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
if (assign_type == VARIABLE) { if (assign_type == VARIABLE) {
PrepareForBailout(expr->expression(), TOS_REG); PrepareForBailout(expr->expression(), TOS_REG);
} else { } else {
PrepareForBailout(expr->increment(), TOS_REG); PrepareForBailoutForId(expr->CountId(), TOS_REG);
} }
// Call ToNumber only if operand is not a smi. // Call ToNumber only if operand is not a smi.
......
...@@ -2593,9 +2593,10 @@ Expression* Parser::ParseUnaryExpression(bool* ok) { ...@@ -2593,9 +2593,10 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
} }
int position = scanner().location().beg_pos; int position = scanner().location().beg_pos;
IncrementOperation* increment = return new(zone()) CountOperation(op,
new(zone()) IncrementOperation(op, expression); true /* prefix */,
return new(zone()) CountOperation(true /* prefix */, increment, position); expression,
position);
} else { } else {
return ParsePostfixExpression(ok); return ParsePostfixExpression(ok);
...@@ -2627,10 +2628,11 @@ Expression* Parser::ParsePostfixExpression(bool* ok) { ...@@ -2627,10 +2628,11 @@ Expression* Parser::ParsePostfixExpression(bool* ok) {
Token::Value next = Next(); Token::Value next = Next();
int position = scanner().location().beg_pos; int position = scanner().location().beg_pos;
IncrementOperation* increment =
new(zone()) IncrementOperation(next, expression);
expression = expression =
new(zone()) CountOperation(false /* postfix */, increment, position); new(zone()) CountOperation(next,
false /* postfix */,
expression,
position);
} }
return expression; return expression;
} }
......
...@@ -376,11 +376,6 @@ void PrettyPrinter::VisitUnaryOperation(UnaryOperation* node) { ...@@ -376,11 +376,6 @@ void PrettyPrinter::VisitUnaryOperation(UnaryOperation* node) {
} }
void PrettyPrinter::VisitIncrementOperation(IncrementOperation* node) {
UNREACHABLE();
}
void PrettyPrinter::VisitCountOperation(CountOperation* node) { void PrettyPrinter::VisitCountOperation(CountOperation* node) {
Print("("); Print("(");
if (node->is_prefix()) Print("%s", Token::String(node->op())); if (node->is_prefix()) Print("%s", Token::String(node->op()));
...@@ -1056,11 +1051,6 @@ void AstPrinter::VisitUnaryOperation(UnaryOperation* node) { ...@@ -1056,11 +1051,6 @@ void AstPrinter::VisitUnaryOperation(UnaryOperation* node) {
} }
void AstPrinter::VisitIncrementOperation(IncrementOperation* node) {
UNREACHABLE();
}
void AstPrinter::VisitCountOperation(CountOperation* node) { void AstPrinter::VisitCountOperation(CountOperation* node) {
EmbeddedVector<char, 128> buf; EmbeddedVector<char, 128> buf;
if (node->type()->IsKnown()) { if (node->type()->IsKnown()) {
...@@ -1461,11 +1451,6 @@ void JsonAstBuilder::VisitUnaryOperation(UnaryOperation* expr) { ...@@ -1461,11 +1451,6 @@ void JsonAstBuilder::VisitUnaryOperation(UnaryOperation* expr) {
} }
void JsonAstBuilder::VisitIncrementOperation(IncrementOperation* expr) {
UNREACHABLE();
}
void JsonAstBuilder::VisitCountOperation(CountOperation* expr) { void JsonAstBuilder::VisitCountOperation(CountOperation* expr) {
TagScope tag(this, "CountOperation"); TagScope tag(this, "CountOperation");
{ {
......
...@@ -432,11 +432,6 @@ void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) { ...@@ -432,11 +432,6 @@ void AstOptimizer::VisitUnaryOperation(UnaryOperation* node) {
} }
void AstOptimizer::VisitIncrementOperation(IncrementOperation* node) {
UNREACHABLE();
}
void AstOptimizer::VisitCountOperation(CountOperation* node) { void AstOptimizer::VisitCountOperation(CountOperation* node) {
// Count operations assume that they work on Smis. // Count operations assume that they work on Smis.
node->expression()->set_no_negative_zero(node->is_prefix() ? node->expression()->set_no_negative_zero(node->is_prefix() ?
...@@ -943,11 +938,6 @@ void Processor::VisitUnaryOperation(UnaryOperation* node) { ...@@ -943,11 +938,6 @@ void Processor::VisitUnaryOperation(UnaryOperation* node) {
} }
void Processor::VisitIncrementOperation(IncrementOperation* node) {
UNREACHABLE();
}
void Processor::VisitCountOperation(CountOperation* node) { void Processor::VisitCountOperation(CountOperation* node) {
USE(node); USE(node);
UNREACHABLE(); UNREACHABLE();
......
...@@ -3811,7 +3811,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -3811,7 +3811,7 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
if (assign_type == VARIABLE) { if (assign_type == VARIABLE) {
PrepareForBailout(expr->expression(), TOS_REG); PrepareForBailout(expr->expression(), TOS_REG);
} else { } else {
PrepareForBailout(expr->increment(), TOS_REG); PrepareForBailoutForId(expr->CountId(), TOS_REG);
} }
// Call ToNumber only if operand is not a smi. // Call ToNumber only if operand is not a smi.
......
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