| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 HPhi* phi = phi_list[i]; | 1145 HPhi* phi = phi_list[i]; |
| 1146 if (!phi->is_live()) { | 1146 if (!phi->is_live()) { |
| 1147 HBasicBlock* block = phi->block(); | 1147 HBasicBlock* block = phi->block(); |
| 1148 block->RemovePhi(phi); | 1148 block->RemovePhi(phi); |
| 1149 block->RecordDeletedPhi(phi->merged_index()); | 1149 block->RecordDeletedPhi(phi->merged_index()); |
| 1150 } | 1150 } |
| 1151 } | 1151 } |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 | 1154 |
| 1155 void HGraph::OptimizeStringCalls() { |
| 1156 HPhase phase("Optimize string calls", this); |
| 1157 |
| 1158 Handle<JSBuiltinsObject> builtins( |
| 1159 start_environment_->closure()->context()->builtins()); |
| 1160 const int kNumFunctions = 4; |
| 1161 const char* function_syms[kNumFunctions] = { |
| 1162 "RegExpExec", |
| 1163 "StringMatch", |
| 1164 "StringReplace", |
| 1165 "StringSplit", |
| 1166 }; |
| 1167 const char* function_noresult_syms[kNumFunctions] = { |
| 1168 "RegExpExecNoResult", |
| 1169 "StringMatchNoResult", |
| 1170 "StringReplaceNoResult", |
| 1171 "StringSplitNoResult", |
| 1172 }; |
| 1173 Handle<JSFunction> functions[kNumFunctions]; |
| 1174 Handle<JSFunction> noresult_functions[kNumFunctions]; |
| 1175 |
| 1176 for (int i = 0; i < kNumFunctions; ++i) { |
| 1177 Handle<String> sym = FACTORY->LookupAsciiSymbol(function_syms[i]); |
| 1178 { MaybeObject* maybe_function = builtins->GetProperty(*sym); |
| 1179 Object* obj; |
| 1180 if (!maybe_function->ToObject(&obj)) return; |
| 1181 if (!obj->IsJSFunction()) return; |
| 1182 functions[i] = Handle<JSFunction>(JSFunction::cast(obj)); |
| 1183 } |
| 1184 |
| 1185 Handle<String> noresult_sym = |
| 1186 FACTORY->LookupAsciiSymbol(function_noresult_syms[i]); |
| 1187 { MaybeObject* maybe_function = builtins->GetProperty(*noresult_sym); |
| 1188 Object* obj; |
| 1189 if (!maybe_function->ToObject(&obj)) return; |
| 1190 if (!obj->IsJSFunction()) return; |
| 1191 noresult_functions[i] = Handle<JSFunction>(JSFunction::cast(obj)); |
| 1192 } |
| 1193 } |
| 1194 |
| 1195 for (int i = 0; i < blocks_.length(); i++) { |
| 1196 for (HInstruction* instr = blocks_[i]->first(); |
| 1197 instr != NULL; |
| 1198 instr = instr->next()) { |
| 1199 if (instr->IsCallConstantFunction() && instr->HasNoUses()) { |
| 1200 HCallConstantFunction* call = HCallConstantFunction::cast(instr); |
| 1201 Handle<JSFunction> function = call->function(); |
| 1202 Handle<JSFunction> replace_function; |
| 1203 for (int i = 0; i < kNumFunctions; ++i) { |
| 1204 if (*function == *functions[i]) |
| 1205 replace_function = noresult_functions[i]; |
| 1206 } |
| 1207 if (!replace_function.is_null()) { |
| 1208 HCallConstantFunction* call_noresult = |
| 1209 new(zone()) HCallConstantFunction(replace_function, |
| 1210 call->argument_count()); |
| 1211 call_noresult->InsertBefore(call); |
| 1212 call->Unlink(); |
| 1213 } |
| 1214 } |
| 1215 } |
| 1216 } |
| 1217 } |
| 1218 |
| 1219 |
| 1155 bool HGraph::CheckArgumentsPhiUses() { | 1220 bool HGraph::CheckArgumentsPhiUses() { |
| 1156 int block_count = blocks_.length(); | 1221 int block_count = blocks_.length(); |
| 1157 for (int i = 0; i < block_count; ++i) { | 1222 for (int i = 0; i < block_count; ++i) { |
| 1158 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) { | 1223 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) { |
| 1159 HPhi* phi = blocks_[i]->phis()->at(j); | 1224 HPhi* phi = blocks_[i]->phis()->at(j); |
| 1160 // We don't support phi uses of arguments for now. | 1225 // We don't support phi uses of arguments for now. |
| 1161 if (phi->CheckFlag(HValue::kIsArguments)) return false; | 1226 if (phi->CheckFlag(HValue::kIsArguments)) return false; |
| 1162 } | 1227 } |
| 1163 } | 1228 } |
| 1164 return true; | 1229 return true; |
| (...skipping 6429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7594 expr->check_type())) { | 7659 expr->check_type())) { |
| 7595 if (FLAG_trace_inlining) { | 7660 if (FLAG_trace_inlining) { |
| 7596 PrintF("Inlining builtin "); | 7661 PrintF("Inlining builtin "); |
| 7597 expr->target()->ShortPrint(); | 7662 expr->target()->ShortPrint(); |
| 7598 PrintF("\n"); | 7663 PrintF("\n"); |
| 7599 } | 7664 } |
| 7600 return; | 7665 return; |
| 7601 } | 7666 } |
| 7602 | 7667 |
| 7603 if (CallStubCompiler::HasCustomCallGenerator(expr->target()) || | 7668 if (CallStubCompiler::HasCustomCallGenerator(expr->target()) || |
| 7604 expr->check_type() != RECEIVER_MAP_CHECK) { | 7669 (expr->check_type() != RECEIVER_MAP_CHECK && |
| 7670 expr->check_type() != STRING_CHECK)) { |
| 7605 // When the target has a custom call IC generator, use the IC, | 7671 // When the target has a custom call IC generator, use the IC, |
| 7606 // because it is likely to generate better code. Also use the IC | 7672 // because it is likely to generate better code. Also use the IC |
| 7607 // when a primitive receiver check is required. | 7673 // when a primitive receiver check is required. |
| 7608 HValue* context = environment()->LookupContext(); | 7674 HValue* context = environment()->LookupContext(); |
| 7609 call = PreProcessCall( | 7675 call = PreProcessCall( |
| 7610 new(zone()) HCallNamed(context, name, argument_count)); | 7676 new(zone()) HCallNamed(context, name, argument_count)); |
| 7611 } else { | 7677 } else { |
| 7612 AddCheckConstantFunction(expr->holder(), receiver, receiver_map, true); | 7678 AddCheckConstantFunction(expr->holder(), receiver, receiver_map, true); |
| 7613 | 7679 |
| 7614 if (TryInlineCall(expr)) return; | 7680 if (TryInlineCall(expr)) return; |
| (...skipping 2368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9983 } | 10049 } |
| 9984 } | 10050 } |
| 9985 | 10051 |
| 9986 #ifdef DEBUG | 10052 #ifdef DEBUG |
| 9987 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10053 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9988 if (allocator_ != NULL) allocator_->Verify(); | 10054 if (allocator_ != NULL) allocator_->Verify(); |
| 9989 #endif | 10055 #endif |
| 9990 } | 10056 } |
| 9991 | 10057 |
| 9992 } } // namespace v8::internal | 10058 } } // namespace v8::internal |
| OLD | NEW |