Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(476)

Unified Diff: src/hydrogen.cc

Issue 7216008: Better codegen for '<expression> === void <literal>'. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 7550809ae105f2a6c2e598ef191a93884767ff9c..becfca9f6bb2421a8a37698f4529af6cd80045d8 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -5502,6 +5502,29 @@ Representation HGraphBuilder::ToRepresentation(TypeInfo info) {
}
+void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* compare_expr,
+ Expression* expr,
+ Handle<String> check) {
+ CHECK_ALIVE(VisitForTypeOf(expr));
+ HValue* expr_value = Pop();
+ HInstruction* instr = new(zone()) HTypeofIs(expr_value, check);
+ instr->set_position(compare_expr->position());
+ ast_context()->ReturnInstruction(instr, compare_expr->id());
+}
+
+
+void HGraphBuilder::HandleLiteralCompareUndefined(
+ CompareOperation* compare_expr, Expression* expr) {
+ CHECK_ALIVE(VisitForValue(expr));
+ HValue* lhs = Pop();
+ HValue* rhs = graph()->GetConstantUndefined();
+ HInstruction* instr =
+ new(zone()) HCompareSymbolEq(lhs, rhs, Token::EQ_STRICT);
+ instr->set_position(compare_expr->position());
+ ast_context()->ReturnInstruction(instr, compare_expr->id());
+}
+
+
void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
ASSERT(!HasStackOverflow());
ASSERT(current_block() != NULL);
@@ -5518,19 +5541,45 @@ void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
return;
}
- // Check for the pattern: typeof <expression> == <string literal>.
- UnaryOperation* left_unary = expr->left()->AsUnaryOperation();
- Literal* right_literal = expr->right()->AsLiteral();
- if ((expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) &&
- left_unary != NULL && left_unary->op() == Token::TYPEOF &&
- right_literal != NULL && right_literal->handle()->IsString()) {
- CHECK_ALIVE(VisitForTypeOf(left_unary->expression()));
- HValue* left = Pop();
- HInstruction* instr = new(zone()) HTypeofIs(left,
- Handle<String>::cast(right_literal->handle()));
- instr->set_position(expr->position());
- ast_context()->ReturnInstruction(instr, expr->id());
- return;
+ if (expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) {
+ UnaryOperation* left_unary = expr->left()->AsUnaryOperation();
+ UnaryOperation* right_unary = expr->right()->AsUnaryOperation();
+ Literal* left_literal = expr->left()->AsLiteral();
+ Literal* right_literal = expr->right()->AsLiteral();
+
+ // Check for the pattern: typeof <expression> == <string literal>.
fschneider 2011/06/21 11:36:08 Since this pattern matching code is exactly the sa
Steven 2011/06/22 10:00:53 Done.
+ if (left_unary != NULL && left_unary->op() == Token::TYPEOF &&
+ right_literal != NULL && right_literal->handle()->IsString()) {
+ HandleLiteralCompareTypeof(
+ expr, left_unary->expression(),
+ Handle<String>::cast(right_literal->handle()));
+ return;
+ }
+
+ // Check for the pattern: <string literal> == typeof <expression>.
+ if (right_unary != NULL && right_unary->op() == Token::TYPEOF &&
+ left_literal != NULL && left_literal->handle()->IsString()) {
+ HandleLiteralCompareTypeof(
+ expr, right_unary->expression(),
+ Handle<String>::cast(left_literal->handle()));
+ return;
+ }
+
+ // Check for the pattern: <expression> === void <literal>.
+ if (expr->op() == Token::EQ_STRICT && right_unary != NULL &&
+ right_unary->op() == Token::VOID &&
+ right_unary->expression()->AsLiteral() != NULL) {
+ HandleLiteralCompareUndefined(expr, expr->left());
+ return;
+ }
+
+ // Check for the pattern: void <literal> === <expression>.
+ if (expr->op() == Token::EQ_STRICT && left_unary != NULL &&
+ left_unary->op() == Token::VOID &&
+ left_unary->expression()->AsLiteral() != NULL) {
+ HandleLiteralCompareUndefined(expr, expr->right());
+ return;
+ }
}
TypeInfo type_info = oracle()->CompareType(expr);

Powered by Google App Engine
This is Rietveld 408576698