From: whesse@chromium.org Date: Thu, 29 Oct 2009 11:55:03 +0000 (+0000) Subject: Add binary operations to fast compiler. X-Git-Tag: upstream/4.7.83~23049 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=05d6294e98068aca8f5a91effc13b62448dc5a53;p=platform%2Fupstream%2Fv8.git Add binary operations to fast compiler. Review URL: http://codereview.chromium.org/342019 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3172 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/arm/fast-codegen-arm.cc b/src/arm/fast-codegen-arm.cc index 49b25746b..a50075384 100644 --- a/src/arm/fast-codegen-arm.cc +++ b/src/arm/fast-codegen-arm.cc @@ -607,7 +607,7 @@ void FastCodeGenerator::VisitCallNew(CallNew* node) { for (int i = 0; i < arg_count; i++) { Visit(args->at(i)); ASSERT(args->at(i)->location().is_value()); - // If location is temporary, it is already on the stack, + // If location is value, it is already on the stack, // so nothing to do here. } @@ -648,11 +648,57 @@ void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) { void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { - // Compile a short-circuited boolean or operation in a non-test - // context. - ASSERT(expr->op() == Token::OR); + switch (expr->op()) { + case Token::COMMA: + ASSERT(expr->left()->location().is_effect()); + ASSERT_EQ(expr->right()->location().type(), expr->location().type()); + Visit(expr->left()); + Visit(expr->right()); + break; + + case Token::OR: + case Token::AND: + EmitLogicalOperation(expr); + break; + + case Token::ADD: + case Token::SUB: + case Token::DIV: + case Token::MOD: + case Token::MUL: + case Token::BIT_OR: + case Token::BIT_AND: + case Token::BIT_XOR: + case Token::SHL: + case Token::SHR: + case Token::SAR: { + ASSERT(expr->left()->location().is_value()); + ASSERT(expr->right()->location().is_value()); + + Visit(expr->left()); + Visit(expr->right()); + __ pop(r0); + __ pop(r1); + GenericBinaryOpStub stub(expr->op(), + NO_OVERWRITE); + __ CallStub(&stub); + Move(expr->location(), r0); + + break; + } + default: + UNREACHABLE(); + } +} + + +void FastCodeGenerator::EmitLogicalOperation(BinaryOperation* expr) { + // Compile a short-circuited boolean operation in a non-test context. + // Compile (e0 || e1) as if it were // (let (temp = e0) temp ? temp : e1). + // Compile (e0 && e1) as if it were + // (let (temp = e0) !temp ? temp : e1). Label done; Location destination = expr->location(); @@ -675,9 +721,13 @@ void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { } } // The left-hand value is in on top of the stack. It is duplicated on the - // stack iff the destination location is temporary. + // stack iff the destination location is value. __ CallRuntime(Runtime::kToBool, 1); - __ LoadRoot(ip, Heap::kTrueValueRootIndex); + if (expr->op() == Token::OR) { + __ LoadRoot(ip, Heap::kTrueValueRootIndex); + } else { + __ LoadRoot(ip, Heap::kFalseValueRootIndex); + } __ cmp(r0, ip); __ b(eq, &done); diff --git a/src/compiler.cc b/src/compiler.cc index 63bf2ecad..129f1aac1 100644 --- a/src/compiler.cc +++ b/src/compiler.cc @@ -849,6 +849,12 @@ void CodeGenSelector::VisitCountOperation(CountOperation* expr) { void CodeGenSelector::VisitBinaryOperation(BinaryOperation* expr) { switch (expr->op()) { + case Token::COMMA: + VisitAsEffect(expr->left()); + CHECK_BAILOUT; + Visit(expr->right()); // Location is the same as the parent location. + break; + case Token::OR: VisitAsValue(expr->left()); CHECK_BAILOUT; @@ -857,6 +863,22 @@ void CodeGenSelector::VisitBinaryOperation(BinaryOperation* expr) { Visit(expr->right()); break; + case Token::ADD: + case Token::SUB: + case Token::DIV: + case Token::MOD: + case Token::MUL: + case Token::BIT_OR: + case Token::BIT_AND: + case Token::BIT_XOR: + case Token::SHL: + case Token::SHR: + case Token::SAR: + VisitAsValue(expr->left()); + CHECK_BAILOUT; + VisitAsValue(expr->right()); + break; + default: BAILOUT("Unsupported binary operation"); } diff --git a/src/fast-codegen.h b/src/fast-codegen.h index a718157b3..33e6b9b7a 100644 --- a/src/fast-codegen.h +++ b/src/fast-codegen.h @@ -78,6 +78,9 @@ class FastCodeGenerator: public AstVisitor { AST_NODE_LIST(DECLARE_VISIT) #undef DECLARE_VISIT + // Handles the shortcutted logical binary operations in VisitBinaryOperation. + void EmitLogicalOperation(BinaryOperation* expr); + MacroAssembler* masm_; FunctionLiteral* function_; Handle