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