OLD | NEW |
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 5472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5483 | 5483 |
5484 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { | 5484 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { |
5485 if (info.IsSmi()) return Representation::Integer32(); | 5485 if (info.IsSmi()) return Representation::Integer32(); |
5486 if (info.IsInteger32()) return Representation::Integer32(); | 5486 if (info.IsInteger32()) return Representation::Integer32(); |
5487 if (info.IsDouble()) return Representation::Double(); | 5487 if (info.IsDouble()) return Representation::Double(); |
5488 if (info.IsNumber()) return Representation::Double(); | 5488 if (info.IsNumber()) return Representation::Double(); |
5489 return Representation::Tagged(); | 5489 return Representation::Tagged(); |
5490 } | 5490 } |
5491 | 5491 |
5492 | 5492 |
| 5493 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* compare_expr, |
| 5494 Expression* expr, |
| 5495 Handle<String> check) { |
| 5496 CHECK_ALIVE(VisitForTypeOf(expr)); |
| 5497 HValue* expr_value = Pop(); |
| 5498 HInstruction* instr = new(zone()) HTypeofIs(expr_value, check); |
| 5499 instr->set_position(compare_expr->position()); |
| 5500 ast_context()->ReturnInstruction(instr, compare_expr->id()); |
| 5501 } |
| 5502 |
| 5503 |
| 5504 void HGraphBuilder::HandleLiteralCompareUndefined( |
| 5505 CompareOperation* compare_expr, Expression* expr) { |
| 5506 CHECK_ALIVE(VisitForValue(expr)); |
| 5507 HValue* lhs = Pop(); |
| 5508 HValue* rhs = graph()->GetConstantUndefined(); |
| 5509 HInstruction* instr = |
| 5510 new(zone()) HCompareObjectEq(lhs, rhs); |
| 5511 instr->set_position(compare_expr->position()); |
| 5512 ast_context()->ReturnInstruction(instr, compare_expr->id()); |
| 5513 } |
| 5514 |
| 5515 |
5493 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { | 5516 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { |
5494 ASSERT(!HasStackOverflow()); | 5517 ASSERT(!HasStackOverflow()); |
5495 ASSERT(current_block() != NULL); | 5518 ASSERT(current_block() != NULL); |
5496 ASSERT(current_block()->HasPredecessor()); | 5519 ASSERT(current_block()->HasPredecessor()); |
5497 if (IsClassOfTest(expr)) { | 5520 if (IsClassOfTest(expr)) { |
5498 CallRuntime* call = expr->left()->AsCallRuntime(); | 5521 CallRuntime* call = expr->left()->AsCallRuntime(); |
5499 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 5522 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
5500 HValue* value = Pop(); | 5523 HValue* value = Pop(); |
5501 Literal* literal = expr->right()->AsLiteral(); | 5524 Literal* literal = expr->right()->AsLiteral(); |
5502 Handle<String> rhs = Handle<String>::cast(literal->handle()); | 5525 Handle<String> rhs = Handle<String>::cast(literal->handle()); |
5503 HInstruction* instr = new(zone()) HClassOfTest(value, rhs); | 5526 HInstruction* instr = new(zone()) HClassOfTest(value, rhs); |
5504 instr->set_position(expr->position()); | 5527 instr->set_position(expr->position()); |
5505 ast_context()->ReturnInstruction(instr, expr->id()); | 5528 ast_context()->ReturnInstruction(instr, expr->id()); |
5506 return; | 5529 return; |
5507 } | 5530 } |
5508 | 5531 |
5509 // Check for the pattern: typeof <expression> == <string literal>. | 5532 // Check for special cases that compare against literals. |
5510 UnaryOperation* left_unary = expr->left()->AsUnaryOperation(); | 5533 Expression *sub_expr; |
5511 Literal* right_literal = expr->right()->AsLiteral(); | 5534 Handle<String> check; |
5512 if ((expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT) && | 5535 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) { |
5513 left_unary != NULL && left_unary->op() == Token::TYPEOF && | 5536 HandleLiteralCompareTypeof(expr, sub_expr, check); |
5514 right_literal != NULL && right_literal->handle()->IsString()) { | |
5515 CHECK_ALIVE(VisitForTypeOf(left_unary->expression())); | |
5516 HValue* left = Pop(); | |
5517 HInstruction* instr = new(zone()) HTypeofIs(left, | |
5518 Handle<String>::cast(right_literal->handle())); | |
5519 instr->set_position(expr->position()); | |
5520 ast_context()->ReturnInstruction(instr, expr->id()); | |
5521 return; | 5537 return; |
5522 } | 5538 } |
5523 | 5539 |
| 5540 if (expr->IsLiteralCompareUndefined(&sub_expr)) { |
| 5541 HandleLiteralCompareUndefined(expr, sub_expr); |
| 5542 return; |
| 5543 } |
| 5544 |
5524 TypeInfo type_info = oracle()->CompareType(expr); | 5545 TypeInfo type_info = oracle()->CompareType(expr); |
5525 // Check if this expression was ever executed according to type feedback. | 5546 // Check if this expression was ever executed according to type feedback. |
5526 if (type_info.IsUninitialized()) { | 5547 if (type_info.IsUninitialized()) { |
5527 AddInstruction(new(zone()) HSoftDeoptimize); | 5548 AddInstruction(new(zone()) HSoftDeoptimize); |
5528 current_block()->MarkAsDeoptimizing(); | 5549 current_block()->MarkAsDeoptimizing(); |
5529 type_info = TypeInfo::Unknown(); | 5550 type_info = TypeInfo::Unknown(); |
5530 } | 5551 } |
5531 | 5552 |
5532 CHECK_ALIVE(VisitForValue(expr->left())); | 5553 CHECK_ALIVE(VisitForValue(expr->left())); |
5533 CHECK_ALIVE(VisitForValue(expr->right())); | 5554 CHECK_ALIVE(VisitForValue(expr->right())); |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6566 } | 6587 } |
6567 } | 6588 } |
6568 | 6589 |
6569 #ifdef DEBUG | 6590 #ifdef DEBUG |
6570 if (graph_ != NULL) graph_->Verify(); | 6591 if (graph_ != NULL) graph_->Verify(); |
6571 if (allocator_ != NULL) allocator_->Verify(); | 6592 if (allocator_ != NULL) allocator_->Verify(); |
6572 #endif | 6593 #endif |
6573 } | 6594 } |
6574 | 6595 |
6575 } } // namespace v8::internal | 6596 } } // namespace v8::internal |
OLD | NEW |