| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 6617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6628 HInstruction* length = Add<HConstant>(argument_count); | 6628 HInstruction* length = Add<HConstant>(argument_count); |
| 6629 HInstruction* checked_key = Add<HBoundsCheck>(key, length); | 6629 HInstruction* checked_key = Add<HBoundsCheck>(key, length); |
| 6630 result = New<HAccessArgumentsAt>(elements, length, checked_key); | 6630 result = New<HAccessArgumentsAt>(elements, length, checked_key); |
| 6631 } | 6631 } |
| 6632 } | 6632 } |
| 6633 ast_context()->ReturnInstruction(result, expr->id()); | 6633 ast_context()->ReturnInstruction(result, expr->id()); |
| 6634 return true; | 6634 return true; |
| 6635 } | 6635 } |
| 6636 | 6636 |
| 6637 | 6637 |
| 6638 bool HOptimizedGraphBuilder::TryMathConstant(Property* expr) { |
| 6639 // Should be either .PI or ["PI"] etc |
| 6640 if (!expr->key()->IsPropertyName()) return false; |
| 6641 // Must refer to a variable called "Math" that is a global variable |
| 6642 VariableProxy* proxy = expr->obj()->AsVariableProxy(); |
| 6643 if (proxy == NULL) return false; |
| 6644 if (!proxy->var()->IsUnallocated()) return false; |
| 6645 if (!(proxy->var()->name()->IsOneByteEqualTo( |
| 6646 STATIC_ASCII_VECTOR("Math")))) return false; |
| 6647 // The global Math property must still be |
| 6648 // pointing to the instance of MathConstructor object |
| 6649 if (!current_info()->has_global_object() || |
| 6650 current_info()->global_object()->IsAccessCheckNeeded()) { |
| 6651 return false; |
| 6652 } |
| 6653 Handle<GlobalObject> global(current_info()->global_object()); |
| 6654 LookupResult lookup(isolate()); |
| 6655 global->Lookup(*proxy->var()->name(), &lookup); |
| 6656 |
| 6657 if (!lookup.IsNormal() || !lookup.GetValue()->IsJSObject()) { |
| 6658 return false; |
| 6659 } |
| 6660 |
| 6661 Handle<JSObject> mathObject(JSObject::cast(lookup.GetValue())); |
| 6662 |
| 6663 if (!mathObject->map()->constructor()->IsJSFunction()) { |
| 6664 return false; |
| 6665 } |
| 6666 |
| 6667 Handle<JSFunction> constructor( |
| 6668 JSFunction::cast(mathObject->map()->constructor())); |
| 6669 |
| 6670 // Users cannot set instance_class_name so this can be trusted |
| 6671 Handle<String> instance_name( |
| 6672 String::cast(constructor->shared()->instance_class_name())); |
| 6673 if (!instance_name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("Math"))) { |
| 6674 return false; |
| 6675 } |
| 6676 |
| 6677 Handle<String> name = expr->key()->AsLiteral()->AsPropertyName(); |
| 6678 HConstant* constant = NULL; |
| 6679 |
| 6680 if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("SQRT2"))) { |
| 6681 constant = New<HConstant>(1.4142135623730951); |
| 6682 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("E"))) { |
| 6683 constant = New<HConstant>(2.718281828459045); |
| 6684 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("LN2"))) { |
| 6685 constant = New<HConstant>(0.6931471805599453); |
| 6686 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("LN10"))) { |
| 6687 constant = New<HConstant>(2.302585092994046); |
| 6688 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("LOG2E"))) { |
| 6689 constant = New<HConstant>(1.4426950408889634); |
| 6690 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("LOG10E"))) { |
| 6691 constant = New<HConstant>(0.4342944819032518); |
| 6692 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("PI"))) { |
| 6693 constant = New<HConstant>(3.141592653589793); |
| 6694 } else if (name->IsOneByteEqualTo(STATIC_ASCII_VECTOR("SQRT1_2"))) { |
| 6695 constant = New<HConstant>(0.7071067811865476); |
| 6696 } |
| 6697 |
| 6698 if (constant != NULL) { |
| 6699 Handle<Map> map(current_info()->global_object()->map()); |
| 6700 map->AddDependentCompilationInfo(DependentCode::kMathConstantGroup, |
| 6701 current_info()); |
| 6702 ast_context()->ReturnInstruction(constant, expr->id()); |
| 6703 return true; |
| 6704 } |
| 6705 return false; |
| 6706 } |
| 6707 |
| 6708 |
| 6638 HInstruction* HOptimizedGraphBuilder::BuildNamedAccess( | 6709 HInstruction* HOptimizedGraphBuilder::BuildNamedAccess( |
| 6639 PropertyAccessType access, | 6710 PropertyAccessType access, |
| 6640 BailoutId ast_id, | 6711 BailoutId ast_id, |
| 6641 BailoutId return_id, | 6712 BailoutId return_id, |
| 6642 Expression* expr, | 6713 Expression* expr, |
| 6643 HValue* object, | 6714 HValue* object, |
| 6644 Handle<String> name, | 6715 Handle<String> name, |
| 6645 HValue* value, | 6716 HValue* value, |
| 6646 bool is_uninitialized) { | 6717 bool is_uninitialized) { |
| 6647 SmallMapList* types; | 6718 SmallMapList* types; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6728 } | 6799 } |
| 6729 return ast_context()->ReturnInstruction(instr, ast_id); | 6800 return ast_context()->ReturnInstruction(instr, ast_id); |
| 6730 } | 6801 } |
| 6731 | 6802 |
| 6732 | 6803 |
| 6733 void HOptimizedGraphBuilder::VisitProperty(Property* expr) { | 6804 void HOptimizedGraphBuilder::VisitProperty(Property* expr) { |
| 6734 ASSERT(!HasStackOverflow()); | 6805 ASSERT(!HasStackOverflow()); |
| 6735 ASSERT(current_block() != NULL); | 6806 ASSERT(current_block() != NULL); |
| 6736 ASSERT(current_block()->HasPredecessor()); | 6807 ASSERT(current_block()->HasPredecessor()); |
| 6737 | 6808 |
| 6738 if (TryArgumentsAccess(expr)) return; | 6809 if (TryArgumentsAccess(expr) || TryMathConstant(expr)) return; |
| 6739 | 6810 |
| 6740 CHECK_ALIVE(VisitForValue(expr->obj())); | 6811 CHECK_ALIVE(VisitForValue(expr->obj())); |
| 6741 if ((!expr->IsFunctionPrototype() && !expr->key()->IsPropertyName()) || | 6812 if ((!expr->IsFunctionPrototype() && !expr->key()->IsPropertyName()) || |
| 6742 expr->IsStringAccess()) { | 6813 expr->IsStringAccess()) { |
| 6743 CHECK_ALIVE(VisitForValue(expr->key())); | 6814 CHECK_ALIVE(VisitForValue(expr->key())); |
| 6744 } | 6815 } |
| 6745 | 6816 |
| 6746 BuildLoad(expr, expr->id()); | 6817 BuildLoad(expr, expr->id()); |
| 6747 } | 6818 } |
| 6748 | 6819 |
| (...skipping 4557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11306 if (ShouldProduceTraceOutput()) { | 11377 if (ShouldProduceTraceOutput()) { |
| 11307 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 11378 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 11308 } | 11379 } |
| 11309 | 11380 |
| 11310 #ifdef DEBUG | 11381 #ifdef DEBUG |
| 11311 graph_->Verify(false); // No full verify. | 11382 graph_->Verify(false); // No full verify. |
| 11312 #endif | 11383 #endif |
| 11313 } | 11384 } |
| 11314 | 11385 |
| 11315 } } // namespace v8::internal | 11386 } } // namespace v8::internal |
| OLD | NEW |