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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // register_allocation_zone_. They are all set to NULL when the zone is | 305 // register_allocation_zone_. They are all set to NULL when the zone is |
306 // destroyed. | 306 // destroyed. |
307 ZonePool::Scope register_allocation_zone_scope_; | 307 ZonePool::Scope register_allocation_zone_scope_; |
308 Zone* register_allocation_zone_; | 308 Zone* register_allocation_zone_; |
309 RegisterAllocationData* register_allocation_data_; | 309 RegisterAllocationData* register_allocation_data_; |
310 | 310 |
311 DISALLOW_COPY_AND_ASSIGN(PipelineData); | 311 DISALLOW_COPY_AND_ASSIGN(PipelineData); |
312 }; | 312 }; |
313 | 313 |
314 | 314 |
| 315 namespace { |
| 316 |
315 struct TurboCfgFile : public std::ofstream { | 317 struct TurboCfgFile : public std::ofstream { |
316 explicit TurboCfgFile(Isolate* isolate) | 318 explicit TurboCfgFile(Isolate* isolate) |
317 : std::ofstream(isolate->GetTurboCfgFileName().c_str(), | 319 : std::ofstream(isolate->GetTurboCfgFileName().c_str(), |
318 std::ios_base::app) {} | 320 std::ios_base::app) {} |
319 }; | 321 }; |
320 | 322 |
321 | 323 |
322 static void TraceSchedule(CompilationInfo* info, Schedule* schedule) { | 324 void TraceSchedule(CompilationInfo* info, Schedule* schedule) { |
323 if (FLAG_trace_turbo) { | 325 if (FLAG_trace_turbo) { |
324 FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+"); | 326 FILE* json_file = OpenVisualizerLogFile(info, NULL, "json", "a+"); |
325 if (json_file != nullptr) { | 327 if (json_file != nullptr) { |
326 OFStream json_of(json_file); | 328 OFStream json_of(json_file); |
327 json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; | 329 json_of << "{\"name\":\"Schedule\",\"type\":\"schedule\",\"data\":\""; |
328 std::stringstream schedule_stream; | 330 std::stringstream schedule_stream; |
329 schedule_stream << *schedule; | 331 schedule_stream << *schedule; |
330 std::string schedule_string(schedule_stream.str()); | 332 std::string schedule_string(schedule_stream.str()); |
331 for (const auto& c : schedule_string) { | 333 for (const auto& c : schedule_string) { |
332 json_of << AsEscapedUC16ForJSON(c); | 334 json_of << AsEscapedUC16ForJSON(c); |
333 } | 335 } |
334 json_of << "\"},\n"; | 336 json_of << "\"},\n"; |
335 fclose(json_file); | 337 fclose(json_file); |
336 } | 338 } |
337 } | 339 } |
338 if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return; | 340 if (!FLAG_trace_turbo_graph && !FLAG_trace_turbo_scheduler) return; |
339 OFStream os(stdout); | 341 OFStream os(stdout); |
340 os << "-- Schedule --------------------------------------\n" << *schedule; | 342 os << "-- Schedule --------------------------------------\n" << *schedule; |
341 } | 343 } |
342 | 344 |
343 | 345 |
344 static SmartArrayPointer<char> GetDebugName(CompilationInfo* info) { | 346 SmartArrayPointer<char> GetDebugName(CompilationInfo* info) { |
345 if (info->code_stub() != NULL) { | 347 if (info->code_stub() != NULL) { |
346 CodeStub::Major major_key = info->code_stub()->MajorKey(); | 348 CodeStub::Major major_key = info->code_stub()->MajorKey(); |
347 const char* major_name = CodeStub::MajorName(major_key, false); | 349 const char* major_name = CodeStub::MajorName(major_key, false); |
348 size_t len = strlen(major_name) + 1; | 350 size_t len = strlen(major_name) + 1; |
349 SmartArrayPointer<char> name(new char[len]); | 351 SmartArrayPointer<char> name(new char[len]); |
350 memcpy(name.get(), major_name, len); | 352 memcpy(name.get(), major_name, len); |
351 return name; | 353 return name; |
352 } else { | 354 } else { |
353 AllowHandleDereference allow_deref; | 355 AllowHandleDereference allow_deref; |
354 return info->function()->debug_name()->ToCString(); | 356 return info->function()->debug_name()->ToCString(); |
355 } | 357 } |
356 } | 358 } |
357 | 359 |
358 | 360 |
359 class AstGraphBuilderWithPositions : public AstGraphBuilder { | 361 class AstGraphBuilderWithPositions final : public AstGraphBuilder { |
360 public: | 362 public: |
361 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, | 363 AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, |
362 JSGraph* jsgraph, | 364 JSGraph* jsgraph, |
363 LoopAssignmentAnalysis* loop_assignment, | 365 LoopAssignmentAnalysis* loop_assignment, |
364 JSTypeFeedbackTable* js_type_feedback, | 366 JSTypeFeedbackTable* js_type_feedback, |
365 SourcePositionTable* source_positions) | 367 SourcePositionTable* source_positions) |
366 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, | 368 : AstGraphBuilder(local_zone, info, jsgraph, loop_assignment, |
367 js_type_feedback), | 369 js_type_feedback), |
368 source_positions_(source_positions), | 370 source_positions_(source_positions), |
369 start_position_(info->shared_info()->start_position()) {} | 371 start_position_(info->shared_info()->start_position()) {} |
370 | 372 |
371 bool CreateGraph(bool constant_context, bool stack_check) { | 373 bool CreateGraph(bool constant_context, bool stack_check) { |
372 SourcePositionTable::Scope pos_scope(source_positions_, start_position_); | 374 SourcePositionTable::Scope pos_scope(source_positions_, start_position_); |
373 return AstGraphBuilder::CreateGraph(constant_context, stack_check); | 375 return AstGraphBuilder::CreateGraph(constant_context, stack_check); |
374 } | 376 } |
375 | 377 |
376 #define DEF_VISIT(type) \ | 378 #define DEF_VISIT(type) \ |
377 void Visit##type(type* node) override { \ | 379 void Visit##type(type* node) override { \ |
378 SourcePositionTable::Scope pos(source_positions_, \ | 380 SourcePositionTable::Scope pos(source_positions_, \ |
379 SourcePosition(node->position())); \ | 381 SourcePosition(node->position())); \ |
380 AstGraphBuilder::Visit##type(node); \ | 382 AstGraphBuilder::Visit##type(node); \ |
381 } | 383 } |
382 AST_NODE_LIST(DEF_VISIT) | 384 AST_NODE_LIST(DEF_VISIT) |
383 #undef DEF_VISIT | 385 #undef DEF_VISIT |
384 | 386 |
385 private: | 387 private: |
386 SourcePositionTable* source_positions_; | 388 SourcePositionTable* const source_positions_; |
387 SourcePosition start_position_; | 389 SourcePosition const start_position_; |
388 }; | 390 }; |
389 | 391 |
390 | 392 |
391 namespace { | 393 class SourcePositionWrapper final : public Reducer { |
392 | |
393 class SourcePositionWrapper : public Reducer { | |
394 public: | 394 public: |
395 SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table) | 395 SourcePositionWrapper(Reducer* reducer, SourcePositionTable* table) |
396 : reducer_(reducer), table_(table) {} | 396 : reducer_(reducer), table_(table) {} |
397 virtual ~SourcePositionWrapper() {} | 397 ~SourcePositionWrapper() final {} |
398 | 398 |
399 virtual Reduction Reduce(Node* node) { | 399 Reduction Reduce(Node* node) final { |
400 SourcePosition pos = table_->GetSourcePosition(node); | 400 SourcePosition const pos = table_->GetSourcePosition(node); |
401 SourcePositionTable::Scope position(table_, pos); | 401 SourcePositionTable::Scope position(table_, pos); |
402 return reducer_->Reduce(node); | 402 return reducer_->Reduce(node); |
403 } | 403 } |
404 | 404 |
405 private: | 405 private: |
406 Reducer* reducer_; | 406 Reducer* const reducer_; |
407 SourcePositionTable* table_; | 407 SourcePositionTable* const table_; |
408 | 408 |
409 DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper); | 409 DISALLOW_COPY_AND_ASSIGN(SourcePositionWrapper); |
410 }; | 410 }; |
411 | 411 |
412 | 412 |
413 static void AddReducer(PipelineData* data, GraphReducer* graph_reducer, | 413 void AddReducer(PipelineData* data, GraphReducer* graph_reducer, |
414 Reducer* reducer) { | 414 Reducer* reducer) { |
415 if (FLAG_turbo_source_positions) { | 415 if (data->info()->is_source_positions_enabled()) { |
416 void* buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper)); | 416 void* const buffer = data->graph_zone()->New(sizeof(SourcePositionWrapper)); |
417 SourcePositionWrapper* wrapper = | 417 SourcePositionWrapper* const wrapper = |
418 new (buffer) SourcePositionWrapper(reducer, data->source_positions()); | 418 new (buffer) SourcePositionWrapper(reducer, data->source_positions()); |
419 graph_reducer->AddReducer(wrapper); | 419 graph_reducer->AddReducer(wrapper); |
420 } else { | 420 } else { |
421 graph_reducer->AddReducer(reducer); | 421 graph_reducer->AddReducer(reducer); |
422 } | 422 } |
423 } | 423 } |
424 } // namespace | 424 |
425 | 425 |
426 class PipelineRunScope { | 426 class PipelineRunScope { |
427 public: | 427 public: |
428 PipelineRunScope(PipelineData* data, const char* phase_name) | 428 PipelineRunScope(PipelineData* data, const char* phase_name) |
429 : phase_scope_( | 429 : phase_scope_( |
430 phase_name == nullptr ? nullptr : data->pipeline_statistics(), | 430 phase_name == nullptr ? nullptr : data->pipeline_statistics(), |
431 phase_name), | 431 phase_name), |
432 zone_scope_(data->zone_pool()) {} | 432 zone_scope_(data->zone_pool()) {} |
433 | 433 |
434 Zone* zone() { return zone_scope_.zone(); } | 434 Zone* zone() { return zone_scope_.zone(); } |
435 | 435 |
436 private: | 436 private: |
437 PhaseScope phase_scope_; | 437 PhaseScope phase_scope_; |
438 ZonePool::Scope zone_scope_; | 438 ZonePool::Scope zone_scope_; |
439 }; | 439 }; |
440 | 440 |
| 441 } // namespace |
| 442 |
441 | 443 |
442 template <typename Phase> | 444 template <typename Phase> |
443 void Pipeline::Run() { | 445 void Pipeline::Run() { |
444 PipelineRunScope scope(this->data_, Phase::phase_name()); | 446 PipelineRunScope scope(this->data_, Phase::phase_name()); |
445 Phase phase; | 447 Phase phase; |
446 phase.Run(this->data_, scope.zone()); | 448 phase.Run(this->data_, scope.zone()); |
447 } | 449 } |
448 | 450 |
449 | 451 |
450 template <typename Phase, typename Arg0> | 452 template <typename Phase, typename Arg0> |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); | 707 if (FLAG_turbo_verify) ScheduleVerifier::Run(schedule); |
706 data->set_schedule(schedule); | 708 data->set_schedule(schedule); |
707 } | 709 } |
708 }; | 710 }; |
709 | 711 |
710 | 712 |
711 struct InstructionSelectionPhase { | 713 struct InstructionSelectionPhase { |
712 static const char* phase_name() { return "select instructions"; } | 714 static const char* phase_name() { return "select instructions"; } |
713 | 715 |
714 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { | 716 void Run(PipelineData* data, Zone* temp_zone, Linkage* linkage) { |
715 InstructionSelector selector(temp_zone, data->graph()->NodeCount(), linkage, | 717 InstructionSelector selector( |
716 data->sequence(), data->schedule(), | 718 temp_zone, data->graph()->NodeCount(), linkage, data->sequence(), |
717 data->source_positions()); | 719 data->schedule(), data->source_positions(), |
| 720 data->info()->is_source_positions_enabled() |
| 721 ? InstructionSelector::kAllSourcePositions |
| 722 : InstructionSelector::kCallSourcePositions); |
718 selector.SelectInstructions(); | 723 selector.SelectInstructions(); |
719 } | 724 } |
720 }; | 725 }; |
721 | 726 |
722 | 727 |
723 struct MeetRegisterConstraintsPhase { | 728 struct MeetRegisterConstraintsPhase { |
724 static const char* phase_name() { return "meet register constraints"; } | 729 static const char* phase_name() { return "meet register constraints"; } |
725 | 730 |
726 void Run(PipelineData* data, Zone* temp_zone) { | 731 void Run(PipelineData* data, Zone* temp_zone) { |
727 ConstraintBuilder builder(data->register_allocation_data()); | 732 ConstraintBuilder builder(data->register_allocation_data()); |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 tcf << AsC1VRegisterAllocationData("CodeGen", | 1326 tcf << AsC1VRegisterAllocationData("CodeGen", |
1322 data->register_allocation_data()); | 1327 data->register_allocation_data()); |
1323 } | 1328 } |
1324 | 1329 |
1325 data->DeleteRegisterAllocationZone(); | 1330 data->DeleteRegisterAllocationZone(); |
1326 } | 1331 } |
1327 | 1332 |
1328 } // namespace compiler | 1333 } // namespace compiler |
1329 } // namespace internal | 1334 } // namespace internal |
1330 } // namespace v8 | 1335 } // namespace v8 |
OLD | NEW |