| 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 3197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3208 instruction->DeleteAndReplaceWith(instruction->RedefinedOperand()); | 3208 instruction->DeleteAndReplaceWith(instruction->RedefinedOperand()); |
| 3209 } else { | 3209 } else { |
| 3210 instruction->ReplaceAllUsesWith(instruction->ActualValue()); | 3210 instruction->ReplaceAllUsesWith(instruction->ActualValue()); |
| 3211 } | 3211 } |
| 3212 } | 3212 } |
| 3213 } | 3213 } |
| 3214 } | 3214 } |
| 3215 } | 3215 } |
| 3216 | 3216 |
| 3217 | 3217 |
| 3218 void HGraphBuilder::PushAndAdd(HInstruction* instr) { | |
| 3219 Push(instr); | |
| 3220 AddInstruction(instr); | |
| 3221 } | |
| 3222 | |
| 3223 | |
| 3224 template <class Instruction> | 3218 template <class Instruction> |
| 3225 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { | 3219 HInstruction* HOptimizedGraphBuilder::PreProcessCall(Instruction* call) { |
| 3226 int count = call->argument_count(); | 3220 int count = call->argument_count(); |
| 3227 ZoneList<HValue*> arguments(count, zone()); | 3221 ZoneList<HValue*> arguments(count, zone()); |
| 3228 for (int i = 0; i < count; ++i) { | 3222 for (int i = 0; i < count; ++i) { |
| 3229 arguments.Add(Pop(), zone()); | 3223 arguments.Add(Pop(), zone()); |
| 3230 } | 3224 } |
| 3231 | 3225 |
| 3232 while (!arguments.is_empty()) { | 3226 while (!arguments.is_empty()) { |
| 3233 Add<HPushArgument>(arguments.RemoveLast()); | 3227 Add<HPushArgument>(arguments.RemoveLast()); |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3891 BreakAndContinueInfo break_info(stmt, 5); | 3885 BreakAndContinueInfo break_info(stmt, 5); |
| 3892 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); | 3886 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); |
| 3893 | 3887 |
| 3894 HBasicBlock* body_exit = | 3888 HBasicBlock* body_exit = |
| 3895 JoinContinue(stmt, current_block(), break_info.continue_block()); | 3889 JoinContinue(stmt, current_block(), break_info.continue_block()); |
| 3896 | 3890 |
| 3897 if (body_exit != NULL) { | 3891 if (body_exit != NULL) { |
| 3898 set_current_block(body_exit); | 3892 set_current_block(body_exit); |
| 3899 | 3893 |
| 3900 HValue* current_index = Pop(); | 3894 HValue* current_index = Pop(); |
| 3901 HInstruction* new_index = New<HAdd>(current_index, | 3895 Push(Add<HAdd>(current_index, graph()->GetConstant1())); |
| 3902 graph()->GetConstant1()); | |
| 3903 PushAndAdd(new_index); | |
| 3904 body_exit = current_block(); | 3896 body_exit = current_block(); |
| 3905 } | 3897 } |
| 3906 | 3898 |
| 3907 HBasicBlock* loop_exit = CreateLoop(stmt, | 3899 HBasicBlock* loop_exit = CreateLoop(stmt, |
| 3908 loop_entry, | 3900 loop_entry, |
| 3909 body_exit, | 3901 body_exit, |
| 3910 loop_successor, | 3902 loop_successor, |
| 3911 break_info.break_block()); | 3903 break_info.break_block()); |
| 3912 | 3904 |
| 3913 set_current_block(loop_exit); | 3905 set_current_block(loop_exit); |
| (...skipping 1406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5320 key = Top(); | 5312 key = Top(); |
| 5321 } | 5313 } |
| 5322 | 5314 |
| 5323 CHECK_ALIVE(PushLoad(prop, object, key)); | 5315 CHECK_ALIVE(PushLoad(prop, object, key)); |
| 5324 | 5316 |
| 5325 CHECK_ALIVE(VisitForValue(expr->value())); | 5317 CHECK_ALIVE(VisitForValue(expr->value())); |
| 5326 HValue* right = Pop(); | 5318 HValue* right = Pop(); |
| 5327 HValue* left = Pop(); | 5319 HValue* left = Pop(); |
| 5328 | 5320 |
| 5329 HInstruction* instr = BuildBinaryOperation(operation, left, right); | 5321 HInstruction* instr = BuildBinaryOperation(operation, left, right); |
| 5330 PushAndAdd(instr); | 5322 AddInstruction(instr); |
| 5323 Push(instr); |
| 5331 if (instr->HasObservableSideEffects()) { | 5324 if (instr->HasObservableSideEffects()) { |
| 5332 Add<HSimulate>(operation->id(), REMOVABLE_SIMULATE); | 5325 Add<HSimulate>(operation->id(), REMOVABLE_SIMULATE); |
| 5333 } | 5326 } |
| 5334 BuildStore(expr, prop, expr->id(), | 5327 BuildStore(expr, prop, expr->id(), |
| 5335 expr->AssignmentId(), expr->IsUninitialized()); | 5328 expr->AssignmentId(), expr->IsUninitialized()); |
| 5336 } else { | 5329 } else { |
| 5337 return Bailout(kInvalidLhsInCompoundAssignment); | 5330 return Bailout(kInvalidLhsInCompoundAssignment); |
| 5338 } | 5331 } |
| 5339 } | 5332 } |
| 5340 | 5333 |
| (...skipping 1613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6954 Handle<JSFunction> known_function; | 6947 Handle<JSFunction> known_function; |
| 6955 if (function->IsConstant()) { | 6948 if (function->IsConstant()) { |
| 6956 HConstant* constant_function = HConstant::cast(function); | 6949 HConstant* constant_function = HConstant::cast(function); |
| 6957 known_function = Handle<JSFunction>::cast( | 6950 known_function = Handle<JSFunction>::cast( |
| 6958 constant_function->handle(isolate())); | 6951 constant_function->handle(isolate())); |
| 6959 int args_count = arguments_count - 1; // Excluding receiver. | 6952 int args_count = arguments_count - 1; // Excluding receiver. |
| 6960 if (TryInlineApply(known_function, expr, args_count)) return true; | 6953 if (TryInlineApply(known_function, expr, args_count)) return true; |
| 6961 } | 6954 } |
| 6962 | 6955 |
| 6963 Drop(arguments_count - 1); | 6956 Drop(arguments_count - 1); |
| 6964 PushAndAdd(New<HPushArgument>(Pop())); | 6957 Push(Add<HPushArgument>(Pop())); |
| 6965 for (int i = 1; i < arguments_count; i++) { | 6958 for (int i = 1; i < arguments_count; i++) { |
| 6966 PushAndAdd(New<HPushArgument>(arguments_values->at(i))); | 6959 Push(Add<HPushArgument>(arguments_values->at(i))); |
| 6967 } | 6960 } |
| 6968 | 6961 |
| 6969 HInvokeFunction* call = New<HInvokeFunction>(function, | 6962 HInvokeFunction* call = New<HInvokeFunction>(function, |
| 6970 known_function, | 6963 known_function, |
| 6971 arguments_count); | 6964 arguments_count); |
| 6972 Drop(arguments_count); | 6965 Drop(arguments_count); |
| 6973 ast_context()->ReturnInstruction(call, expr->id()); | 6966 ast_context()->ReturnInstruction(call, expr->id()); |
| 6974 return true; | 6967 return true; |
| 6975 } | 6968 } |
| 6976 } | 6969 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7069 LookupResult lookup(isolate()); | 7062 LookupResult lookup(isolate()); |
| 7070 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, false); | 7063 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, false); |
| 7071 if (type == kUseCell && | 7064 if (type == kUseCell && |
| 7072 !current_info()->global_object()->IsAccessCheckNeeded()) { | 7065 !current_info()->global_object()->IsAccessCheckNeeded()) { |
| 7073 Handle<GlobalObject> global(current_info()->global_object()); | 7066 Handle<GlobalObject> global(current_info()->global_object()); |
| 7074 known_global_function = expr->ComputeGlobalTarget(global, &lookup); | 7067 known_global_function = expr->ComputeGlobalTarget(global, &lookup); |
| 7075 } | 7068 } |
| 7076 if (known_global_function) { | 7069 if (known_global_function) { |
| 7077 // Push the global object instead of the global receiver because | 7070 // Push the global object instead of the global receiver because |
| 7078 // code generated by the full code generator expects it. | 7071 // code generated by the full code generator expects it. |
| 7079 HGlobalObject* global_object = New<HGlobalObject>(); | 7072 HGlobalObject* global_object = Add<HGlobalObject>(); |
| 7080 PushAndAdd(global_object); | 7073 Push(global_object); |
| 7081 CHECK_ALIVE(VisitExpressions(expr->arguments())); | 7074 CHECK_ALIVE(VisitExpressions(expr->arguments())); |
| 7082 | 7075 |
| 7083 CHECK_ALIVE(VisitForValue(expr->expression())); | 7076 CHECK_ALIVE(VisitForValue(expr->expression())); |
| 7084 HValue* function = Pop(); | 7077 HValue* function = Pop(); |
| 7085 Add<HCheckValue>(function, expr->target()); | 7078 Add<HCheckValue>(function, expr->target()); |
| 7086 | 7079 |
| 7087 // Replace the global object with the global receiver. | 7080 // Replace the global object with the global receiver. |
| 7088 HGlobalReceiver* global_receiver = Add<HGlobalReceiver>(global_object); | 7081 HGlobalReceiver* global_receiver = Add<HGlobalReceiver>(global_object); |
| 7089 // Index of the receiver from the top of the expression stack. | 7082 // Index of the receiver from the top of the expression stack. |
| 7090 const int receiver_index = argument_count - 1; | 7083 const int receiver_index = argument_count - 1; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 7109 if (CallStubCompiler::HasCustomCallGenerator(expr->target())) { | 7102 if (CallStubCompiler::HasCustomCallGenerator(expr->target())) { |
| 7110 // When the target has a custom call IC generator, use the IC, | 7103 // When the target has a custom call IC generator, use the IC, |
| 7111 // because it is likely to generate better code. | 7104 // because it is likely to generate better code. |
| 7112 call = PreProcessCall(New<HCallNamed>(var->name(), argument_count)); | 7105 call = PreProcessCall(New<HCallNamed>(var->name(), argument_count)); |
| 7113 } else { | 7106 } else { |
| 7114 call = PreProcessCall(New<HCallKnownGlobal>( | 7107 call = PreProcessCall(New<HCallKnownGlobal>( |
| 7115 expr->target(), argument_count)); | 7108 expr->target(), argument_count)); |
| 7116 } | 7109 } |
| 7117 } else { | 7110 } else { |
| 7118 HGlobalObject* receiver = Add<HGlobalObject>(); | 7111 HGlobalObject* receiver = Add<HGlobalObject>(); |
| 7119 PushAndAdd(New<HPushArgument>(receiver)); | 7112 Push(Add<HPushArgument>(receiver)); |
| 7120 CHECK_ALIVE(VisitArgumentList(expr->arguments())); | 7113 CHECK_ALIVE(VisitArgumentList(expr->arguments())); |
| 7121 | 7114 |
| 7122 call = New<HCallGlobal>(var->name(), argument_count); | 7115 call = New<HCallGlobal>(var->name(), argument_count); |
| 7123 Drop(argument_count); | 7116 Drop(argument_count); |
| 7124 } | 7117 } |
| 7125 | 7118 |
| 7126 } else if (expr->IsMonomorphic()) { | 7119 } else if (expr->IsMonomorphic()) { |
| 7127 // The function is on the stack in the unoptimized code during | 7120 // The function is on the stack in the unoptimized code during |
| 7128 // evaluation of the arguments. | 7121 // evaluation of the arguments. |
| 7129 CHECK_ALIVE(VisitForValue(expr->expression())); | 7122 CHECK_ALIVE(VisitForValue(expr->expression())); |
| 7130 HValue* function = Top(); | 7123 HValue* function = Top(); |
| 7131 HGlobalObject* global = Add<HGlobalObject>(); | 7124 HGlobalObject* global = Add<HGlobalObject>(); |
| 7132 HGlobalReceiver* receiver = New<HGlobalReceiver>(global); | 7125 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global); |
| 7133 PushAndAdd(receiver); | 7126 Push(receiver); |
| 7134 CHECK_ALIVE(VisitExpressions(expr->arguments())); | 7127 CHECK_ALIVE(VisitExpressions(expr->arguments())); |
| 7135 Add<HCheckValue>(function, expr->target()); | 7128 Add<HCheckValue>(function, expr->target()); |
| 7136 | 7129 |
| 7137 if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function. | 7130 if (TryInlineBuiltinFunctionCall(expr, true)) { // Drop the function. |
| 7138 if (FLAG_trace_inlining) { | 7131 if (FLAG_trace_inlining) { |
| 7139 PrintF("Inlining builtin "); | 7132 PrintF("Inlining builtin "); |
| 7140 expr->target()->ShortPrint(); | 7133 expr->target()->ShortPrint(); |
| 7141 PrintF("\n"); | 7134 PrintF("\n"); |
| 7142 } | 7135 } |
| 7143 return; | 7136 return; |
| 7144 } | 7137 } |
| 7145 | 7138 |
| 7146 if (TryInlineCall(expr, true)) { // Drop function from environment. | 7139 if (TryInlineCall(expr, true)) { // Drop function from environment. |
| 7147 return; | 7140 return; |
| 7148 } else { | 7141 } else { |
| 7149 call = PreProcessCall(New<HInvokeFunction>(function, expr->target(), | 7142 call = PreProcessCall(New<HInvokeFunction>(function, expr->target(), |
| 7150 argument_count)); | 7143 argument_count)); |
| 7151 Drop(1); // The function. | 7144 Drop(1); // The function. |
| 7152 } | 7145 } |
| 7153 | 7146 |
| 7154 } else { | 7147 } else { |
| 7155 CHECK_ALIVE(VisitForValue(expr->expression())); | 7148 CHECK_ALIVE(VisitForValue(expr->expression())); |
| 7156 HValue* function = Top(); | 7149 HValue* function = Top(); |
| 7157 HGlobalObject* global_object = Add<HGlobalObject>(); | 7150 HGlobalObject* global_object = Add<HGlobalObject>(); |
| 7158 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global_object); | 7151 HGlobalReceiver* receiver = Add<HGlobalReceiver>(global_object); |
| 7159 PushAndAdd(New<HPushArgument>(receiver)); | 7152 Push(Add<HPushArgument>(receiver)); |
| 7160 CHECK_ALIVE(VisitArgumentList(expr->arguments())); | 7153 CHECK_ALIVE(VisitArgumentList(expr->arguments())); |
| 7161 | 7154 |
| 7162 call = New<HCallFunction>(function, argument_count); | 7155 call = New<HCallFunction>(function, argument_count); |
| 7163 Drop(argument_count + 1); | 7156 Drop(argument_count + 1); |
| 7164 } | 7157 } |
| 7165 } | 7158 } |
| 7166 | 7159 |
| 7167 return ast_context()->ReturnInstruction(call, expr->id()); | 7160 return ast_context()->ReturnInstruction(call, expr->id()); |
| 7168 } | 7161 } |
| 7169 | 7162 |
| (...skipping 2652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9822 if (ShouldProduceTraceOutput()) { | 9815 if (ShouldProduceTraceOutput()) { |
| 9823 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 9816 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
| 9824 } | 9817 } |
| 9825 | 9818 |
| 9826 #ifdef DEBUG | 9819 #ifdef DEBUG |
| 9827 graph_->Verify(false); // No full verify. | 9820 graph_->Verify(false); // No full verify. |
| 9828 #endif | 9821 #endif |
| 9829 } | 9822 } |
| 9830 | 9823 |
| 9831 } } // namespace v8::internal | 9824 } } // namespace v8::internal |
| OLD | NEW |