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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5484 matching lines...) Expand 10 before | Expand all | Expand 10 after
5495 5495
5496 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { 5496 Representation HGraphBuilder::ToRepresentation(TypeInfo info) {
5497 if (info.IsSmi()) return Representation::Integer32(); 5497 if (info.IsSmi()) return Representation::Integer32();
5498 if (info.IsInteger32()) return Representation::Integer32(); 5498 if (info.IsInteger32()) return Representation::Integer32();
5499 if (info.IsDouble()) return Representation::Double(); 5499 if (info.IsDouble()) return Representation::Double();
5500 if (info.IsNumber()) return Representation::Double(); 5500 if (info.IsNumber()) return Representation::Double();
5501 return Representation::Tagged(); 5501 return Representation::Tagged();
5502 } 5502 }
5503 5503
5504 5504
5505 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* compare_expr,
5506 Expression* expr,
5507 Handle<String> check) {
5508 CHECK_ALIVE(VisitForTypeOf(expr));
5509 HValue* expr_value = Pop();
5510 HInstruction* instr = new(zone()) HTypeofIs(expr_value, check);
5511 instr->set_position(compare_expr->position());
5512 ast_context()->ReturnInstruction(instr, compare_expr->id());
5513 }
5514
5515
5516 void HGraphBuilder::HandleLiteralCompareUndefined(
5517 CompareOperation* compare_expr, Expression* expr) {
5518 CHECK_ALIVE(VisitForValue(expr));
5519 HValue* lhs = Pop();
5520 HValue* rhs = graph()->GetConstantUndefined();
5521 HInstruction* instr =
5522 new(zone()) HCompareSymbolEq(lhs, rhs, Token::EQ_STRICT);
5523 instr->set_position(compare_expr->position());
5524 ast_context()->ReturnInstruction(instr, compare_expr->id());
5525 }
5526
5527
5505 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { 5528 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
5506 ASSERT(!HasStackOverflow()); 5529 ASSERT(!HasStackOverflow());
5507 ASSERT(current_block() != NULL); 5530 ASSERT(current_block() != NULL);
5508 ASSERT(current_block()->HasPredecessor()); 5531 ASSERT(current_block()->HasPredecessor());
5509 if (IsClassOfTest(expr)) { 5532 if (IsClassOfTest(expr)) {
5510 CallRuntime* call = expr->left()->AsCallRuntime(); 5533 CallRuntime* call = expr->left()->AsCallRuntime();
5511 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); 5534 CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
5512 HValue* value = Pop(); 5535 HValue* value = Pop();
5513 Literal* literal = expr->right()->AsLiteral(); 5536 Literal* literal = expr->right()->AsLiteral();
5514 Handle<String> rhs = Handle<String>::cast(literal->handle()); 5537 Handle<String> rhs = Handle<String>::cast(literal->handle());
5515 HInstruction* instr = new(zone()) HClassOfTest(value, rhs); 5538 HInstruction* instr = new(zone()) HClassOfTest(value, rhs);
5516 instr->set_position(expr->position()); 5539 instr->set_position(expr->position());
5517 ast_context()->ReturnInstruction(instr, expr->id()); 5540 ast_context()->ReturnInstruction(instr, expr->id());
5518 return; 5541 return;
5519 } 5542 }
5520 5543
5521 // Check for the pattern: typeof <expression> == <string literal>. 5544 if (expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) {
5522 UnaryOperation* left_unary = expr->left()->AsUnaryOperation(); 5545 UnaryOperation* left_unary = expr->left()->AsUnaryOperation();
5523 Literal* right_literal = expr->right()->AsLiteral(); 5546 UnaryOperation* right_unary = expr->right()->AsUnaryOperation();
5524 if ((expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) && 5547 Literal* left_literal = expr->left()->AsLiteral();
5525 left_unary != NULL && left_unary->op() == Token::TYPEOF && 5548 Literal* right_literal = expr->right()->AsLiteral();
5526 right_literal != NULL && right_literal->handle()->IsString()) { 5549
5527 CHECK_ALIVE(VisitForTypeOf(left_unary->expression())); 5550 // 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.
5528 HValue* left = Pop(); 5551 if (left_unary != NULL && left_unary->op() == Token::TYPEOF &&
5529 HInstruction* instr = new(zone()) HTypeofIs(left, 5552 right_literal != NULL && right_literal->handle()->IsString()) {
5530 Handle<String>::cast(right_literal->handle())); 5553 HandleLiteralCompareTypeof(
5531 instr->set_position(expr->position()); 5554 expr, left_unary->expression(),
5532 ast_context()->ReturnInstruction(instr, expr->id()); 5555 Handle<String>::cast(right_literal->handle()));
5533 return; 5556 return;
5557 }
5558
5559 // Check for the pattern: <string literal> == typeof <expression>.
5560 if (right_unary != NULL && right_unary->op() == Token::TYPEOF &&
5561 left_literal != NULL && left_literal->handle()->IsString()) {
5562 HandleLiteralCompareTypeof(
5563 expr, right_unary->expression(),
5564 Handle<String>::cast(left_literal->handle()));
5565 return;
5566 }
5567
5568 // Check for the pattern: <expression> === void <literal>.
5569 if (expr->op() == Token::EQ_STRICT && right_unary != NULL &&
5570 right_unary->op() == Token::VOID &&
5571 right_unary->expression()->AsLiteral() != NULL) {
5572 HandleLiteralCompareUndefined(expr, expr->left());
5573 return;
5574 }
5575
5576 // Check for the pattern: void <literal> === <expression>.
5577 if (expr->op() == Token::EQ_STRICT && left_unary != NULL &&
5578 left_unary->op() == Token::VOID &&
5579 left_unary->expression()->AsLiteral() != NULL) {
5580 HandleLiteralCompareUndefined(expr, expr->right());
5581 return;
5582 }
5534 } 5583 }
5535 5584
5536 TypeInfo type_info = oracle()->CompareType(expr); 5585 TypeInfo type_info = oracle()->CompareType(expr);
5537 // Check if this expression was ever executed according to type feedback. 5586 // Check if this expression was ever executed according to type feedback.
5538 if (type_info.IsUninitialized()) { 5587 if (type_info.IsUninitialized()) {
5539 AddInstruction(new(zone()) HSoftDeoptimize); 5588 AddInstruction(new(zone()) HSoftDeoptimize);
5540 current_block()->MarkAsDeoptimizing(); 5589 current_block()->MarkAsDeoptimizing();
5541 type_info = TypeInfo::Unknown(); 5590 type_info = TypeInfo::Unknown();
5542 } 5591 }
5543 5592
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after
6574 } 6623 }
6575 } 6624 }
6576 6625
6577 #ifdef DEBUG 6626 #ifdef DEBUG
6578 if (graph_ != NULL) graph_->Verify(); 6627 if (graph_ != NULL) graph_->Verify();
6579 if (allocator_ != NULL) allocator_->Verify(); 6628 if (allocator_ != NULL) allocator_->Verify();
6580 #endif 6629 #endif
6581 } 6630 }
6582 6631
6583 } } // namespace v8::internal 6632 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698