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 7600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7611 HInvokeFunction* call = New<HInvokeFunction>(function, | 7611 HInvokeFunction* call = New<HInvokeFunction>(function, |
7612 known_function, | 7612 known_function, |
7613 arguments_count); | 7613 arguments_count); |
7614 Drop(arguments_count); | 7614 Drop(arguments_count); |
7615 ast_context()->ReturnInstruction(call, expr->id()); | 7615 ast_context()->ReturnInstruction(call, expr->id()); |
7616 return true; | 7616 return true; |
7617 } | 7617 } |
7618 } | 7618 } |
7619 | 7619 |
7620 | 7620 |
| 7621 void HOptimizedGraphBuilder::InstallGlobalReceiverInExpressionStack( |
| 7622 int receiver_index, |
| 7623 Handle<JSFunction> function) { |
| 7624 // TODO(dcarney): Fix deserializer to be able to hookup the global receiver |
| 7625 // and object during deserialization and embed the global receiver here |
| 7626 // directly. |
| 7627 // Install global receiver on stack. |
| 7628 HValue* function_constant = Add<HConstant>(function); |
| 7629 HValue* context = Add<HLoadNamedField>( |
| 7630 function_constant, |
| 7631 HObjectAccess::ForJSObjectOffset(JSFunction::kContextOffset)); |
| 7632 HValue* global_object = Add<HLoadNamedField>( |
| 7633 context, |
| 7634 HObjectAccess::ForContextSlot(Context::GLOBAL_OBJECT_INDEX)); |
| 7635 HValue* global_receiver = Add<HLoadNamedField>( |
| 7636 global_object, |
| 7637 HObjectAccess::ForJSObjectOffset(GlobalObject::kGlobalReceiverOffset)); |
| 7638 environment()->SetExpressionStackAt(receiver_index, global_receiver); |
| 7639 } |
| 7640 |
| 7641 |
7621 void HOptimizedGraphBuilder::VisitCall(Call* expr) { | 7642 void HOptimizedGraphBuilder::VisitCall(Call* expr) { |
7622 ASSERT(!HasStackOverflow()); | 7643 ASSERT(!HasStackOverflow()); |
7623 ASSERT(current_block() != NULL); | 7644 ASSERT(current_block() != NULL); |
7624 ASSERT(current_block()->HasPredecessor()); | 7645 ASSERT(current_block()->HasPredecessor()); |
7625 Expression* callee = expr->expression(); | 7646 Expression* callee = expr->expression(); |
7626 int argument_count = expr->arguments()->length() + 1; // Plus receiver. | 7647 int argument_count = expr->arguments()->length() + 1; // Plus receiver. |
7627 HInstruction* call = NULL; | 7648 HInstruction* call = NULL; |
7628 | 7649 |
7629 Property* prop = callee->AsProperty(); | 7650 Property* prop = callee->AsProperty(); |
7630 if (prop != NULL) { | 7651 if (prop != NULL) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7731 // Push the global object instead of the global receiver because | 7752 // Push the global object instead of the global receiver because |
7732 // code generated by the full code generator expects it. | 7753 // code generated by the full code generator expects it. |
7733 HGlobalObject* global_object = Add<HGlobalObject>(); | 7754 HGlobalObject* global_object = Add<HGlobalObject>(); |
7734 Push(global_object); | 7755 Push(global_object); |
7735 CHECK_ALIVE(VisitExpressions(expr->arguments())); | 7756 CHECK_ALIVE(VisitExpressions(expr->arguments())); |
7736 | 7757 |
7737 CHECK_ALIVE(VisitForValue(expr->expression())); | 7758 CHECK_ALIVE(VisitForValue(expr->expression())); |
7738 HValue* function = Pop(); | 7759 HValue* function = Pop(); |
7739 Add<HCheckValue>(function, expr->target()); | 7760 Add<HCheckValue>(function, expr->target()); |
7740 | 7761 |
7741 // Replace the global object with the global receiver. | 7762 // Install global receiver on stack. |
7742 HGlobalReceiver* global_receiver = Add<HGlobalReceiver>(global_object); | |
7743 // Index of the receiver from the top of the expression stack. | |
7744 const int receiver_index = argument_count - 1; | 7763 const int receiver_index = argument_count - 1; |
7745 ASSERT(environment()->ExpressionStackAt(receiver_index)-> | 7764 ASSERT(environment()->ExpressionStackAt(receiver_index)-> |
7746 IsGlobalObject()); | 7765 IsGlobalObject()); |
7747 environment()->SetExpressionStackAt(receiver_index, global_receiver); | 7766 InstallGlobalReceiverInExpressionStack(receiver_index, expr->target()); |
7748 | 7767 |
7749 if (TryInlineBuiltinFunctionCall(expr, false)) { // Nothing to drop. | 7768 if (TryInlineBuiltinFunctionCall(expr, false)) { // Nothing to drop. |
7750 if (FLAG_trace_inlining) { | 7769 if (FLAG_trace_inlining) { |
7751 PrintF("Inlining builtin "); | 7770 PrintF("Inlining builtin "); |
7752 expr->target()->ShortPrint(); | 7771 expr->target()->ShortPrint(); |
7753 PrintF("\n"); | 7772 PrintF("\n"); |
7754 } | 7773 } |
7755 return; | 7774 return; |
7756 } | 7775 } |
7757 if (TryInlineCall(expr)) return; | 7776 if (TryInlineCall(expr)) return; |
7758 | 7777 |
7759 if (expr->target().is_identical_to(current_info()->closure())) { | 7778 if (expr->target().is_identical_to(current_info()->closure())) { |
7760 graph()->MarkRecursive(); | 7779 graph()->MarkRecursive(); |
7761 } | 7780 } |
7762 | 7781 |
7763 if (CallStubCompiler::HasCustomCallGenerator(expr->target())) { | 7782 if (CallStubCompiler::HasCustomCallGenerator(expr->target())) { |
| 7783 // We're about to install a contextual IC, which expects the global |
| 7784 // object as receiver rather than the global proxy. |
| 7785 environment()->SetExpressionStackAt(receiver_index, global_object); |
7764 // When the target has a custom call IC generator, use the IC, | 7786 // When the target has a custom call IC generator, use the IC, |
7765 // because it is likely to generate better code. | 7787 // because it is likely to generate better code. |
7766 call = PreProcessCall(New<HCallNamed>(var->name(), argument_count)); | 7788 call = PreProcessCall(New<HCallGlobal>(var->name(), argument_count)); |
7767 } else { | 7789 } else { |
7768 call = PreProcessCall(New<HCallKnownGlobal>( | 7790 call = PreProcessCall(New<HCallKnownGlobal>( |
7769 expr->target(), argument_count)); | 7791 expr->target(), argument_count)); |
7770 } | 7792 } |
7771 } else { | 7793 } else { |
7772 HGlobalObject* receiver = Add<HGlobalObject>(); | 7794 HGlobalObject* receiver = Add<HGlobalObject>(); |
7773 Push(Add<HPushArgument>(receiver)); | 7795 Push(Add<HPushArgument>(receiver)); |
7774 CHECK_ALIVE(VisitArgumentList(expr->arguments())); | 7796 CHECK_ALIVE(VisitArgumentList(expr->arguments())); |
7775 | 7797 |
7776 call = New<HCallGlobal>(var->name(), argument_count); | 7798 call = New<HCallGlobal>(var->name(), argument_count); |
7777 Drop(argument_count); | 7799 Drop(argument_count); |
7778 } | 7800 } |
7779 | 7801 |
7780 } else if (expr->IsMonomorphic()) { | 7802 } else if (expr->IsMonomorphic()) { |
7781 // The function is on the stack in the unoptimized code during | 7803 // The function is on the stack in the unoptimized code during |
7782 // evaluation of the arguments. | 7804 // evaluation of the arguments. |
7783 CHECK_ALIVE(VisitForValue(expr->expression())); | 7805 CHECK_ALIVE(VisitForValue(expr->expression())); |
7784 HValue* function = Top(); | 7806 HValue* function = Top(); |
7785 HGlobalObject* global = Add<HGlobalObject>(); | 7807 HGlobalObject* global = Add<HGlobalObject>(); |
7786 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global); | 7808 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global); |
7787 Push(receiver); | 7809 Push(receiver); |
7788 CHECK_ALIVE(VisitExpressions(expr->arguments())); | 7810 CHECK_ALIVE(VisitExpressions(expr->arguments())); |
7789 Add<HCheckValue>(function, expr->target()); | 7811 Add<HCheckValue>(function, expr->target()); |
7790 | 7812 |
| 7813 // Install global receiver on stack. |
| 7814 const int receiver_index = argument_count - 1; |
| 7815 ASSERT(environment()->ExpressionStackAt(receiver_index)-> |
| 7816 IsGlobalReceiver()); |
| 7817 InstallGlobalReceiverInExpressionStack(receiver_index, expr->target()); |
| 7818 |
7791 if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function. | 7819 if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function. |
7792 if (FLAG_trace_inlining) { | 7820 if (FLAG_trace_inlining) { |
7793 PrintF("Inlining builtin "); | 7821 PrintF("Inlining builtin "); |
7794 expr->target()->ShortPrint(); | 7822 expr->target()->ShortPrint(); |
7795 PrintF("\n"); | 7823 PrintF("\n"); |
7796 } | 7824 } |
7797 return; | 7825 return; |
7798 } | 7826 } |
7799 | 7827 |
7800 if (TryInlineCall(expr, true)) { // Drop function from environment. | 7828 if (TryInlineCall(expr, true)) { // Drop function from environment. |
7801 return; | 7829 return; |
7802 } else { | 7830 } else { |
7803 call = PreProcessCall(New<HInvokeFunction>(function, expr->target(), | 7831 call = PreProcessCall(New<HInvokeFunction>(function, expr->target(), |
7804 argument_count)); | 7832 argument_count)); |
7805 Drop(1); // The function. | 7833 Drop(1); // The function. |
7806 } | 7834 } |
7807 | 7835 |
7808 } else { | 7836 } else { |
7809 CHECK_ALIVE(VisitForValue(expr->expression())); | 7837 CHECK_ALIVE(VisitForValue(expr->expression())); |
7810 HValue* function = Top(); | 7838 HValue* function = Top(); |
7811 HGlobalObject* global_object = Add<HGlobalObject>(); | 7839 HValue* receiver = graph()->GetConstantHole(); |
7812 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global_object); | |
7813 Push(Add<HPushArgument>(receiver)); | 7840 Push(Add<HPushArgument>(receiver)); |
7814 CHECK_ALIVE(VisitArgumentList(expr->arguments())); | 7841 CHECK_ALIVE(VisitArgumentList(expr->arguments())); |
7815 | 7842 call = New<HCallFunction>( |
7816 call = New<HCallFunction>(function, argument_count); | 7843 function, argument_count, NORMAL_CONTEXTUAL_CALL); |
7817 Drop(argument_count + 1); | 7844 Drop(argument_count + 1); |
7818 } | 7845 } |
7819 } | 7846 } |
7820 | 7847 |
7821 return ast_context()->ReturnInstruction(call, expr->id()); | 7848 return ast_context()->ReturnInstruction(call, expr->id()); |
7822 } | 7849 } |
7823 | 7850 |
7824 | 7851 |
7825 void HOptimizedGraphBuilder::BuildInlinedCallNewArray(CallNew* expr) { | 7852 void HOptimizedGraphBuilder::BuildInlinedCallNewArray(CallNew* expr) { |
7826 NoObservableSideEffectsScope no_effects(this); | 7853 NoObservableSideEffectsScope no_effects(this); |
(...skipping 3064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10891 if (ShouldProduceTraceOutput()) { | 10918 if (ShouldProduceTraceOutput()) { |
10892 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 10919 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
10893 } | 10920 } |
10894 | 10921 |
10895 #ifdef DEBUG | 10922 #ifdef DEBUG |
10896 graph_->Verify(false); // No full verify. | 10923 graph_->Verify(false); // No full verify. |
10897 #endif | 10924 #endif |
10898 } | 10925 } |
10899 | 10926 |
10900 } } // namespace v8::internal | 10927 } } // namespace v8::internal |
OLD | NEW |