OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/pipeline.h" | 5 #include "src/compiler/pipeline.h" |
6 | 6 |
7 #include <fstream> // NOLINT(readability/streams) | 7 #include <fstream> // NOLINT(readability/streams) |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/base/adapters.h" | 10 #include "src/base/adapters.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 json_of << "\"},\n"; | 342 json_of << "\"},\n"; |
343 fclose(json_file); | 343 fclose(json_file); |
344 } | 344 } |
345 } | 345 } |
346 if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return; | 346 if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return; |
347 OFStream os(stdout); | 347 OFStream os(stdout); |
348 os << "-- Schedule --------------------------------------\n" << *schedule; | 348 os << "-- Schedule --------------------------------------\n" << *schedule; |
349 } | 349 } |
350 | 350 |
351 | 351 |
352 base::SmartArrayPointer<char> GetDebugName(CompilationInfo* info) { | |
353 if (info->code_stub() != NULL) { | |
354 CodeStub::Major major_key = info->code_stub()->MajorKey(); | |
355 const char* major_name = CodeStub::MajorName(major_key, false); | |
356 size_t len = strlen(major_name) + 1; | |
357 base::SmartArrayPointer<char> name(new char[len]); | |
358 memcpy(name.get(), major_name, len); | |
359 return name; | |
360 } else { | |
361 AllowHandleDereference allow_deref; | |
362 return info->literal()->debug_name()->ToCString(); | |
363 } | |
364 } | |
365 | |
366 | |
367 class AstGraphBuilderWithPositions final : public AstGraphBuilder { | 352 class AstGraphBuilderWithPositions final : public AstGraphBuilder { |
368 public: | 353 public: |
369 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, | 354 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, |
370 JSGraph* jsgraph, | 355 JSGraph* jsgraph, |
371 LoopAssignmentAnalysis* loop_assignment, | 356 LoopAssignmentAnalysis* loop_assignment, |
372 JSTypeFeedbackTable* js_type_feedback, | 357 JSTypeFeedbackTable* js_type_feedback, |
373 SourcePositionTable* source_positions) | 358 SourcePositionTable* source_positions) |
374 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, | 359 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, |
375 js_type_feedback), | 360 js_type_feedback), |
376 source_positions_(source_positions), | 361 source_positions_(source_positions), |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); | 993 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); |
1009 pipeline_statistics->BeginPhaseKind("initializing"); | 994 pipeline_statistics->BeginPhaseKind("initializing"); |
1010 } | 995 } |
1011 | 996 |
1012 if (FLAG_trace_turbo) { | 997 if (FLAG_trace_turbo) { |
1013 FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "w+"); | 998 FILE* json_file = OpenVisualizerLogFile(info(), NULL, "json", "w+"); |
1014 if (json_file != nullptr) { | 999 if (json_file != nullptr) { |
1015 OFStream json_of(json_file); | 1000 OFStream json_of(json_file); |
1016 Handle<Script> script = info()->script(); | 1001 Handle<Script> script = info()->script(); |
1017 FunctionLiteral* function = info()->literal(); | 1002 FunctionLiteral* function = info()->literal(); |
1018 base::SmartArrayPointer<char> function_name = | 1003 base::SmartArrayPointer<char> function_name = info()->GetDebugName(); |
1019 info()->shared_info()->DebugName()->ToCString(); | |
1020 int pos = info()->shared_info()->start_position(); | 1004 int pos = info()->shared_info()->start_position(); |
1021 json_of << "{\"function\":\"" << function_name.get() | 1005 json_of << "{\"function\":\"" << function_name.get() |
1022 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; | 1006 << "\", \"sourcePosition\":" << pos << ", \"source\":\""; |
1023 if (!script->IsUndefined() && !script->source()->IsUndefined()) { | 1007 if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
1024 DisallowHeapAllocation no_allocation; | 1008 DisallowHeapAllocation no_allocation; |
1025 int start = function->start_position(); | 1009 int start = function->start_position(); |
1026 int len = function->end_position() - start; | 1010 int len = function->end_position() - start; |
1027 String::SubStringRange source(String::cast(script->source()), start, | 1011 String::SubStringRange source(String::cast(script->source()), start, |
1028 len); | 1012 len); |
1029 for (const auto& c : source) { | 1013 for (const auto& c : source) { |
(...skipping 11 matching lines...) Expand all Loading... |
1041 if (info()->is_type_feedback_enabled()) { | 1025 if (info()->is_type_feedback_enabled()) { |
1042 data.set_js_type_feedback(new (data.graph_zone()) | 1026 data.set_js_type_feedback(new (data.graph_zone()) |
1043 JSTypeFeedbackTable(data.graph_zone())); | 1027 JSTypeFeedbackTable(data.graph_zone())); |
1044 } | 1028 } |
1045 | 1029 |
1046 BeginPhaseKind("graph creation"); | 1030 BeginPhaseKind("graph creation"); |
1047 | 1031 |
1048 if (FLAG_trace_turbo) { | 1032 if (FLAG_trace_turbo) { |
1049 OFStream os(stdout); | 1033 OFStream os(stdout); |
1050 os << "---------------------------------------------------\n" | 1034 os << "---------------------------------------------------\n" |
1051 << "Begin compiling method " << GetDebugName(info()).get() | 1035 << "Begin compiling method " << info()->GetDebugName().get() |
1052 << " using Turbofan" << std::endl; | 1036 << " using Turbofan" << std::endl; |
1053 TurboCfgFile tcf(isolate()); | 1037 TurboCfgFile tcf(isolate()); |
1054 tcf << AsC1VCompilation(info()); | 1038 tcf << AsC1VCompilation(info()); |
1055 } | 1039 } |
1056 | 1040 |
1057 data.source_positions()->AddDecorator(); | 1041 data.source_positions()->AddDecorator(); |
1058 | 1042 |
1059 if (FLAG_loop_assignment_analysis) { | 1043 if (FLAG_loop_assignment_analysis) { |
1060 Run<LoopAssignmentAnalysisPhase>(); | 1044 Run<LoopAssignmentAnalysisPhase>(); |
1061 } | 1045 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 CallDescriptor* call_descriptor = | 1135 CallDescriptor* call_descriptor = |
1152 Linkage::ComputeIncoming(info->zone(), info); | 1136 Linkage::ComputeIncoming(info->zone(), info); |
1153 return GenerateCodeForTesting(info, call_descriptor, graph, schedule); | 1137 return GenerateCodeForTesting(info, call_descriptor, graph, schedule); |
1154 } | 1138 } |
1155 | 1139 |
1156 | 1140 |
1157 Handle<Code> Pipeline::GenerateCodeForTesting(Isolate* isolate, | 1141 Handle<Code> Pipeline::GenerateCodeForTesting(Isolate* isolate, |
1158 CallDescriptor* call_descriptor, | 1142 CallDescriptor* call_descriptor, |
1159 Graph* graph, | 1143 Graph* graph, |
1160 Schedule* schedule) { | 1144 Schedule* schedule) { |
1161 FakeStubForTesting stub(isolate); | 1145 CompilationInfo info("testing", isolate, graph->zone()); |
1162 CompilationInfo info(&stub, isolate, graph->zone()); | |
1163 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); | 1146 return GenerateCodeForTesting(&info, call_descriptor, graph, schedule); |
1164 } | 1147 } |
1165 | 1148 |
1166 | 1149 |
1167 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, | 1150 Handle<Code> Pipeline::GenerateCodeForTesting(CompilationInfo* info, |
1168 CallDescriptor* call_descriptor, | 1151 CallDescriptor* call_descriptor, |
1169 Graph* graph, | 1152 Graph* graph, |
1170 Schedule* schedule) { | 1153 Schedule* schedule) { |
1171 // Construct a pipeline for scheduling and code generation. | 1154 // Construct a pipeline for scheduling and code generation. |
1172 ZonePool zone_pool; | 1155 ZonePool zone_pool; |
(...skipping 11 matching lines...) Expand all Loading... |
1184 pipeline.RunPrintAndVerify("Machine", true); | 1167 pipeline.RunPrintAndVerify("Machine", true); |
1185 } | 1168 } |
1186 | 1169 |
1187 return pipeline.ScheduleAndGenerateCode(call_descriptor); | 1170 return pipeline.ScheduleAndGenerateCode(call_descriptor); |
1188 } | 1171 } |
1189 | 1172 |
1190 | 1173 |
1191 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, | 1174 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, |
1192 InstructionSequence* sequence, | 1175 InstructionSequence* sequence, |
1193 bool run_verifier) { | 1176 bool run_verifier) { |
1194 FakeStubForTesting stub(sequence->isolate()); | 1177 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); |
1195 CompilationInfo info(&stub, sequence->isolate(), sequence->zone()); | |
1196 ZonePool zone_pool; | 1178 ZonePool zone_pool; |
1197 PipelineData data(&zone_pool, &info, sequence); | 1179 PipelineData data(&zone_pool, &info, sequence); |
1198 Pipeline pipeline(&info); | 1180 Pipeline pipeline(&info); |
1199 pipeline.data_ = &data; | 1181 pipeline.data_ = &data; |
1200 pipeline.AllocateRegisters(config, nullptr, run_verifier); | 1182 pipeline.AllocateRegisters(config, nullptr, run_verifier); |
1201 return !data.compilation_failed(); | 1183 return !data.compilation_failed(); |
1202 } | 1184 } |
1203 | 1185 |
1204 | 1186 |
1205 Handle<Code> Pipeline::ScheduleAndGenerateCode( | 1187 Handle<Code> Pipeline::ScheduleAndGenerateCode( |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 } | 1267 } |
1286 #endif // ENABLE_DISASSEMBLER | 1268 #endif // ENABLE_DISASSEMBLER |
1287 json_of << "\"}\n],\n"; | 1269 json_of << "\"}\n],\n"; |
1288 json_of << "\"nodePositions\":"; | 1270 json_of << "\"nodePositions\":"; |
1289 json_of << source_position_output.str(); | 1271 json_of << source_position_output.str(); |
1290 json_of << "}"; | 1272 json_of << "}"; |
1291 fclose(json_file); | 1273 fclose(json_file); |
1292 } | 1274 } |
1293 OFStream os(stdout); | 1275 OFStream os(stdout); |
1294 os << "---------------------------------------------------\n" | 1276 os << "---------------------------------------------------\n" |
1295 << "Finished compiling method " << GetDebugName(info()).get() | 1277 << "Finished compiling method " << info()->GetDebugName().get() |
1296 << " using Turbofan" << std::endl; | 1278 << " using Turbofan" << std::endl; |
1297 } | 1279 } |
1298 | 1280 |
1299 return code; | 1281 return code; |
1300 } | 1282 } |
1301 | 1283 |
1302 | 1284 |
1303 void Pipeline::AllocateRegisters(const RegisterConfiguration* config, | 1285 void Pipeline::AllocateRegisters(const RegisterConfiguration* config, |
1304 CallDescriptor* descriptor, | 1286 CallDescriptor* descriptor, |
1305 bool run_verifier) { | 1287 bool run_verifier) { |
1306 PipelineData* data = this->data_; | 1288 PipelineData* data = this->data_; |
1307 | 1289 |
1308 // Don't track usage for this zone in compiler stats. | 1290 // Don't track usage for this zone in compiler stats. |
1309 base::SmartPointer<Zone> verifier_zone; | 1291 base::SmartPointer<Zone> verifier_zone; |
1310 RegisterAllocatorVerifier* verifier = nullptr; | 1292 RegisterAllocatorVerifier* verifier = nullptr; |
1311 if (run_verifier) { | 1293 if (run_verifier) { |
1312 verifier_zone.Reset(new Zone()); | 1294 verifier_zone.Reset(new Zone()); |
1313 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( | 1295 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( |
1314 verifier_zone.get(), config, data->sequence()); | 1296 verifier_zone.get(), config, data->sequence()); |
1315 } | 1297 } |
1316 | 1298 |
1317 base::SmartArrayPointer<char> debug_name; | 1299 base::SmartArrayPointer<char> debug_name; |
1318 #ifdef DEBUG | 1300 #ifdef DEBUG |
1319 debug_name = GetDebugName(data->info()); | 1301 debug_name = info()->GetDebugName(); |
1320 #endif | 1302 #endif |
1321 | 1303 |
1322 data->InitializeRegisterAllocationData(config, descriptor, debug_name.get()); | 1304 data->InitializeRegisterAllocationData(config, descriptor, debug_name.get()); |
1323 if (info()->is_osr()) { | 1305 if (info()->is_osr()) { |
1324 OsrHelper osr_helper(info()); | 1306 OsrHelper osr_helper(info()); |
1325 osr_helper.SetupFrame(data->frame()); | 1307 osr_helper.SetupFrame(data->frame()); |
1326 } | 1308 } |
1327 | 1309 |
1328 Run<MeetRegisterConstraintsPhase>(); | 1310 Run<MeetRegisterConstraintsPhase>(); |
1329 Run<ResolvePhisPhase>(); | 1311 Run<ResolvePhisPhase>(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 tcf << AsC1VRegisterAllocationData("CodeGen", | 1360 tcf << AsC1VRegisterAllocationData("CodeGen", |
1379 data->register_allocation_data()); | 1361 data->register_allocation_data()); |
1380 } | 1362 } |
1381 | 1363 |
1382 data->DeleteRegisterAllocationZone(); | 1364 data->DeleteRegisterAllocationZone(); |
1383 } | 1365 } |
1384 | 1366 |
1385 } // namespace compiler | 1367 } // namespace compiler |
1386 } // namespace internal | 1368 } // namespace internal |
1387 } // namespace v8 | 1369 } // namespace v8 |
OLD | NEW |