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