Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: src/compiler/pipeline.cc

Issue 1904723002: [wasm] Introduce ExecuteWasmCompilation and FinalizeWasmCompilation in pipeline.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@parallel-compilation
Patch Set: Rebase. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/pipeline.h ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // For main entry point. 78 // For main entry point.
79 PipelineData(ZonePool* zone_pool, CompilationInfo* info, 79 PipelineData(ZonePool* zone_pool, CompilationInfo* info,
80 PipelineStatistics* pipeline_statistics) 80 PipelineStatistics* pipeline_statistics)
81 : isolate_(info->isolate()), 81 : isolate_(info->isolate()),
82 info_(info), 82 info_(info),
83 outer_zone_(info_->zone()), 83 outer_zone_(info_->zone()),
84 zone_pool_(zone_pool), 84 zone_pool_(zone_pool),
85 pipeline_statistics_(pipeline_statistics), 85 pipeline_statistics_(pipeline_statistics),
86 compilation_failed_(false), 86 compilation_failed_(false),
87 code_(Handle<Code>::null()), 87 code_(Handle<Code>::null()),
88 profiler_data_(nullptr),
88 graph_zone_scope_(zone_pool_), 89 graph_zone_scope_(zone_pool_),
89 graph_zone_(graph_zone_scope_.zone()), 90 graph_zone_(graph_zone_scope_.zone()),
90 graph_(nullptr), 91 graph_(nullptr),
91 loop_assignment_(nullptr), 92 loop_assignment_(nullptr),
92 simplified_(nullptr), 93 simplified_(nullptr),
93 machine_(nullptr), 94 machine_(nullptr),
94 common_(nullptr), 95 common_(nullptr),
95 javascript_(nullptr), 96 javascript_(nullptr),
96 jsgraph_(nullptr), 97 jsgraph_(nullptr),
97 schedule_(nullptr), 98 schedule_(nullptr),
(...skipping 21 matching lines...) Expand all
119 // For machine graph testing entry point. 120 // For machine graph testing entry point.
120 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph, 121 PipelineData(ZonePool* zone_pool, CompilationInfo* info, Graph* graph,
121 Schedule* schedule) 122 Schedule* schedule)
122 : isolate_(info->isolate()), 123 : isolate_(info->isolate()),
123 info_(info), 124 info_(info),
124 outer_zone_(nullptr), 125 outer_zone_(nullptr),
125 zone_pool_(zone_pool), 126 zone_pool_(zone_pool),
126 pipeline_statistics_(nullptr), 127 pipeline_statistics_(nullptr),
127 compilation_failed_(false), 128 compilation_failed_(false),
128 code_(Handle<Code>::null()), 129 code_(Handle<Code>::null()),
130 profiler_data_(nullptr),
129 graph_zone_scope_(zone_pool_), 131 graph_zone_scope_(zone_pool_),
130 graph_zone_(nullptr), 132 graph_zone_(nullptr),
131 graph_(graph), 133 graph_(graph),
132 source_positions_(new (info->zone()->New(sizeof(SourcePositionTable))) 134 source_positions_(new (info->zone()->New(sizeof(SourcePositionTable)))
133 SourcePositionTable(graph_)), 135 SourcePositionTable(graph_)),
134 loop_assignment_(nullptr), 136 loop_assignment_(nullptr),
135 simplified_(nullptr), 137 simplified_(nullptr),
136 machine_(nullptr), 138 machine_(nullptr),
137 common_(nullptr), 139 common_(nullptr),
138 javascript_(nullptr), 140 javascript_(nullptr),
(...skipping 10 matching lines...) Expand all
149 // For register allocation testing entry point. 151 // For register allocation testing entry point.
150 PipelineData(ZonePool* zone_pool, CompilationInfo* info, 152 PipelineData(ZonePool* zone_pool, CompilationInfo* info,
151 InstructionSequence* sequence) 153 InstructionSequence* sequence)
152 : isolate_(info->isolate()), 154 : isolate_(info->isolate()),
153 info_(info), 155 info_(info),
154 outer_zone_(nullptr), 156 outer_zone_(nullptr),
155 zone_pool_(zone_pool), 157 zone_pool_(zone_pool),
156 pipeline_statistics_(nullptr), 158 pipeline_statistics_(nullptr),
157 compilation_failed_(false), 159 compilation_failed_(false),
158 code_(Handle<Code>::null()), 160 code_(Handle<Code>::null()),
161 profiler_data_(nullptr),
159 graph_zone_scope_(zone_pool_), 162 graph_zone_scope_(zone_pool_),
160 graph_zone_(nullptr), 163 graph_zone_(nullptr),
161 graph_(nullptr), 164 graph_(nullptr),
162 loop_assignment_(nullptr), 165 loop_assignment_(nullptr),
163 simplified_(nullptr), 166 simplified_(nullptr),
164 machine_(nullptr), 167 machine_(nullptr),
165 common_(nullptr), 168 common_(nullptr),
166 javascript_(nullptr), 169 javascript_(nullptr),
167 jsgraph_(nullptr), 170 jsgraph_(nullptr),
168 schedule_(nullptr), 171 schedule_(nullptr),
(...skipping 17 matching lines...) Expand all
186 CompilationInfo* info() const { return info_; } 189 CompilationInfo* info() const { return info_; }
187 ZonePool* zone_pool() const { return zone_pool_; } 190 ZonePool* zone_pool() const { return zone_pool_; }
188 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; } 191 PipelineStatistics* pipeline_statistics() { return pipeline_statistics_; }
189 bool compilation_failed() const { return compilation_failed_; } 192 bool compilation_failed() const { return compilation_failed_; }
190 void set_compilation_failed() { compilation_failed_ = true; } 193 void set_compilation_failed() { compilation_failed_ = true; }
191 Handle<Code> code() { return code_; } 194 Handle<Code> code() { return code_; }
192 void set_code(Handle<Code> code) { 195 void set_code(Handle<Code> code) {
193 DCHECK(code_.is_null()); 196 DCHECK(code_.is_null());
194 code_ = code; 197 code_ = code;
195 } 198 }
196 199 BasicBlockProfiler::Data* profiler_data() { return profiler_data_; }
200 void set_profiler_data(BasicBlockProfiler::Data* data) {
201 profiler_data_ = data;
202 }
203 std::ostringstream* source_position_output() {
204 return &source_position_output_;
205 }
197 // RawMachineAssembler generally produces graphs which cannot be verified. 206 // RawMachineAssembler generally produces graphs which cannot be verified.
198 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; } 207 bool MayHaveUnverifiableGraph() const { return outer_zone_ == nullptr; }
199 208
200 Zone* graph_zone() const { return graph_zone_; } 209 Zone* graph_zone() const { return graph_zone_; }
201 Graph* graph() const { return graph_; } 210 Graph* graph() const { return graph_; }
202 SourcePositionTable* source_positions() const { return source_positions_; } 211 SourcePositionTable* source_positions() const { return source_positions_; }
203 MachineOperatorBuilder* machine() const { return machine_; } 212 MachineOperatorBuilder* machine() const { return machine_; }
204 CommonOperatorBuilder* common() const { return common_; } 213 CommonOperatorBuilder* common() const { return common_; }
205 JSOperatorBuilder* javascript() const { return javascript_; } 214 JSOperatorBuilder* javascript() const { return javascript_; }
206 JSGraph* jsgraph() const { return jsgraph_; } 215 JSGraph* jsgraph() const { return jsgraph_; }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 313 }
305 314
306 private: 315 private:
307 Isolate* isolate_; 316 Isolate* isolate_;
308 CompilationInfo* info_; 317 CompilationInfo* info_;
309 Zone* outer_zone_; 318 Zone* outer_zone_;
310 ZonePool* const zone_pool_; 319 ZonePool* const zone_pool_;
311 PipelineStatistics* pipeline_statistics_; 320 PipelineStatistics* pipeline_statistics_;
312 bool compilation_failed_; 321 bool compilation_failed_;
313 Handle<Code> code_; 322 Handle<Code> code_;
323 BasicBlockProfiler::Data* profiler_data_;
324 std::ostringstream source_position_output_;
314 325
315 // All objects in the following group of fields are allocated in graph_zone_. 326 // All objects in the following group of fields are allocated in graph_zone_.
316 // They are all set to nullptr when the graph_zone_ is destroyed. 327 // They are all set to nullptr when the graph_zone_ is destroyed.
317 ZonePool::Scope graph_zone_scope_; 328 ZonePool::Scope graph_zone_scope_;
318 Zone* graph_zone_; 329 Zone* graph_zone_;
319 Graph* graph_; 330 Graph* graph_;
320 SourcePositionTable* source_positions_; 331 SourcePositionTable* source_positions_;
321 LoopAssignmentAnalysis* loop_assignment_; 332 LoopAssignmentAnalysis* loop_assignment_;
322 TypeHintAnalysis* type_hint_analysis_ = nullptr; 333 TypeHintAnalysis* type_hint_analysis_ = nullptr;
323 SimplifiedOperatorBuilder* simplified_; 334 SimplifiedOperatorBuilder* simplified_;
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1392
1382 return pipeline.ScheduleAndGenerateCode(call_descriptor); 1393 return pipeline.ScheduleAndGenerateCode(call_descriptor);
1383 } 1394 }
1384 1395
1385 void Pipeline::InitializeWasmCompilation(Zone* pipeline_zone, 1396 void Pipeline::InitializeWasmCompilation(Zone* pipeline_zone,
1386 ZonePool* zone_pool, Graph* graph) { 1397 ZonePool* zone_pool, Graph* graph) {
1387 data_ = new (pipeline_zone) PipelineData(zone_pool, info(), graph, nullptr); 1398 data_ = new (pipeline_zone) PipelineData(zone_pool, info(), graph, nullptr);
1388 RunPrintAndVerify("Machine", true); 1399 RunPrintAndVerify("Machine", true);
1389 } 1400 }
1390 1401
1391 void Pipeline::FinalizeWasmCompilation() { data_->Destroy(); } 1402 bool Pipeline::ExecuteWasmCompilation(CallDescriptor* descriptor) {
1403 return ScheduleGraph(descriptor);
1404 }
1405
1406 Handle<Code> Pipeline::FinalizeWasmCompilation(CallDescriptor* descriptor) {
1407 Handle<Code> result = GenerateCode(descriptor);
1408 data_->Destroy();
Benedikt Meurer 2016/04/26 11:47:45 This at least leaks the ostringstream that you add
1409 return result;
1410 }
1392 1411
1393 OptimizedCompileJob* Pipeline::NewCompilationJob(CompilationInfo* info) { 1412 OptimizedCompileJob* Pipeline::NewCompilationJob(CompilationInfo* info) {
1394 return new (info->zone()) PipelineCompilationJob(info); 1413 return new (info->zone()) PipelineCompilationJob(info);
1395 } 1414 }
1396 1415
1397 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config, 1416 bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
1398 InstructionSequence* sequence, 1417 InstructionSequence* sequence,
1399 bool run_verifier) { 1418 bool run_verifier) {
1400 CompilationInfo info("testing", sequence->isolate(), sequence->zone()); 1419 CompilationInfo info("testing", sequence->isolate(), sequence->zone());
1401 ZonePool zone_pool(sequence->isolate()->allocator()); 1420 ZonePool zone_pool(sequence->isolate()->allocator());
1402 PipelineData data(&zone_pool, &info, sequence); 1421 PipelineData data(&zone_pool, &info, sequence);
1403 Pipeline pipeline(&info); 1422 Pipeline pipeline(&info);
1404 pipeline.data_ = &data; 1423 pipeline.data_ = &data;
1405 pipeline.data_->InitializeFrameData(nullptr); 1424 pipeline.data_->InitializeFrameData(nullptr);
1406 pipeline.AllocateRegisters(config, nullptr, run_verifier); 1425 pipeline.AllocateRegisters(config, nullptr, run_verifier);
1407 return !data.compilation_failed(); 1426 return !data.compilation_failed();
1408 } 1427 }
1409 1428
1410
1411 Handle<Code> Pipeline::ScheduleAndGenerateCode( 1429 Handle<Code> Pipeline::ScheduleAndGenerateCode(
1412 CallDescriptor* call_descriptor) { 1430 CallDescriptor* call_descriptor) {
1431 if (ScheduleGraph(call_descriptor)) {
1432 return GenerateCode(call_descriptor);
1433 } else {
1434 return Handle<Code>::null();
1435 }
1436 }
1437
1438 bool Pipeline::ScheduleGraph(CallDescriptor* call_descriptor) {
1413 PipelineData* data = this->data_; 1439 PipelineData* data = this->data_;
1414
1415 DCHECK_NOT_NULL(data); 1440 DCHECK_NOT_NULL(data);
1416 DCHECK_NOT_NULL(data->graph()); 1441 DCHECK_NOT_NULL(data->graph());
1417 1442
1418 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>(); 1443 if (data->schedule() == nullptr) Run<ComputeSchedulePhase>();
1419 TraceSchedule(data->info(), data->schedule()); 1444 TraceSchedule(data->info(), data->schedule());
1420 1445
1421 BasicBlockProfiler::Data* profiler_data = nullptr;
1422 if (FLAG_turbo_profiling) { 1446 if (FLAG_turbo_profiling) {
1423 profiler_data = BasicBlockInstrumentor::Instrument(info(), data->graph(), 1447 data->set_profiler_data(BasicBlockInstrumentor::Instrument(
1424 data->schedule()); 1448 info(), data->graph(), data->schedule()));
1425 } 1449 }
1426 1450
1427 data->InitializeInstructionSequence(call_descriptor); 1451 data->InitializeInstructionSequence(call_descriptor);
1428 1452
1429 data->InitializeFrameData(call_descriptor); 1453 data->InitializeFrameData(call_descriptor);
1430 // Select and schedule instructions covering the scheduled graph. 1454 // Select and schedule instructions covering the scheduled graph.
1431 Linkage linkage(call_descriptor); 1455 Linkage linkage(call_descriptor);
1432 Run<InstructionSelectionPhase>(&linkage); 1456 Run<InstructionSelectionPhase>(&linkage);
1433 1457
1434 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) { 1458 if (FLAG_trace_turbo && !data->MayHaveUnverifiableGraph()) {
1435 TurboCfgFile tcf(isolate()); 1459 TurboCfgFile tcf(isolate());
1436 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(), 1460 tcf << AsC1V("CodeGen", data->schedule(), data->source_positions(),
1437 data->sequence()); 1461 data->sequence());
1438 } 1462 }
1439 1463
1440 std::ostringstream source_position_output;
1441 if (FLAG_trace_turbo) { 1464 if (FLAG_trace_turbo) {
1442 // Output source position information before the graph is deleted. 1465 // Output source position information before the graph is deleted.
1443 data_->source_positions()->Print(source_position_output); 1466 data_->source_positions()->Print(*(data->source_position_output()));
1444 } 1467 }
1445 1468
1446 data->DeleteGraphZone(); 1469 data->DeleteGraphZone();
1447 1470
1448 BeginPhaseKind("register allocation"); 1471 BeginPhaseKind("register allocation");
1449 1472
1450 bool run_verifier = FLAG_turbo_verify_allocation; 1473 bool run_verifier = FLAG_turbo_verify_allocation;
1451 1474
1452 // Allocate registers. 1475 // Allocate registers.
1453 AllocateRegisters( 1476 AllocateRegisters(
1454 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN), 1477 RegisterConfiguration::ArchDefault(RegisterConfiguration::TURBOFAN),
1455 call_descriptor, run_verifier); 1478 call_descriptor, run_verifier);
1456 Run<FrameElisionPhase>(); 1479 Run<FrameElisionPhase>();
1457 if (data->compilation_failed()) { 1480 if (data->compilation_failed()) {
1458 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); 1481 info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
1459 return Handle<Code>(); 1482 return false;
1460 } 1483 }
1461 1484
1462 BeginPhaseKind("code generation"); 1485 BeginPhaseKind("code generation");
1463 // TODO(mtrofin): move this off to the register allocator. 1486 // TODO(mtrofin): move this off to the register allocator.
1464 bool generate_frame_at_start = 1487 bool generate_frame_at_start =
1465 data_->sequence()->instruction_blocks().front()->must_construct_frame(); 1488 data_->sequence()->instruction_blocks().front()->must_construct_frame();
1466 // Optimimize jumps. 1489 // Optimimize jumps.
1467 if (FLAG_turbo_jt) { 1490 if (FLAG_turbo_jt) {
1468 Run<JumpThreadingPhase>(generate_frame_at_start); 1491 Run<JumpThreadingPhase>(generate_frame_at_start);
1469 } 1492 }
1493 return true;
1494 }
1470 1495
1496 Handle<Code> Pipeline::GenerateCode(CallDescriptor* call_descriptor) {
1497 PipelineData* data = this->data_;
1498 Linkage linkage(call_descriptor);
1471 // Generate final machine code. 1499 // Generate final machine code.
1472 Run<GenerateCodePhase>(&linkage); 1500 Run<GenerateCodePhase>(&linkage);
1473 1501
1474 Handle<Code> code = data->code(); 1502 Handle<Code> code = data->code();
1475 if (profiler_data != nullptr) { 1503 if (data->profiler_data() != nullptr) {
1476 #if ENABLE_DISASSEMBLER 1504 #if ENABLE_DISASSEMBLER
1477 std::ostringstream os; 1505 std::ostringstream os;
1478 code->Disassemble(nullptr, os); 1506 code->Disassemble(nullptr, os);
1479 profiler_data->SetCode(&os); 1507 data->profiler_data()->SetCode(&os);
1480 #endif 1508 #endif
1481 } 1509 }
1482 1510
1483 info()->SetCode(code); 1511 info()->SetCode(code);
1484 v8::internal::CodeGenerator::PrintCode(code, info()); 1512 v8::internal::CodeGenerator::PrintCode(code, info());
1485 1513
1486 if (FLAG_trace_turbo) { 1514 if (FLAG_trace_turbo) {
1487 FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "a+"); 1515 FILE* json_file = OpenVisualizerLogFile(info(), nullptr, "json", "a+");
1488 if (json_file != nullptr) { 1516 if (json_file != nullptr) {
1489 OFStream json_of(json_file); 1517 OFStream json_of(json_file);
1490 json_of 1518 json_of
1491 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\""; 1519 << "{\"name\":\"disassembly\",\"type\":\"disassembly\",\"data\":\"";
1492 #if ENABLE_DISASSEMBLER 1520 #if ENABLE_DISASSEMBLER
1493 std::stringstream disassembly_stream; 1521 std::stringstream disassembly_stream;
1494 code->Disassemble(nullptr, disassembly_stream); 1522 code->Disassemble(nullptr, disassembly_stream);
1495 std::string disassembly_string(disassembly_stream.str()); 1523 std::string disassembly_string(disassembly_stream.str());
1496 for (const auto& c : disassembly_string) { 1524 for (const auto& c : disassembly_string) {
1497 json_of << AsEscapedUC16ForJSON(c); 1525 json_of << AsEscapedUC16ForJSON(c);
1498 } 1526 }
1499 #endif // ENABLE_DISASSEMBLER 1527 #endif // ENABLE_DISASSEMBLER
1500 json_of << "\"}\n],\n"; 1528 json_of << "\"}\n],\n";
1501 json_of << "\"nodePositions\":"; 1529 json_of << "\"nodePositions\":";
1502 json_of << source_position_output.str(); 1530 json_of << data->source_position_output()->str();
1503 json_of << "}"; 1531 json_of << "}";
1504 fclose(json_file); 1532 fclose(json_file);
1505 } 1533 }
1506 OFStream os(stdout); 1534 OFStream os(stdout);
1507 os << "---------------------------------------------------\n" 1535 os << "---------------------------------------------------\n"
1508 << "Finished compiling method " << info()->GetDebugName().get() 1536 << "Finished compiling method " << info()->GetDebugName().get()
1509 << " using Turbofan" << std::endl; 1537 << " using Turbofan" << std::endl;
1510 } 1538 }
1511
1512 return code; 1539 return code;
1513 } 1540 }
1514 1541
1515
1516 void Pipeline::AllocateRegisters(const RegisterConfiguration* config, 1542 void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
1517 CallDescriptor* descriptor, 1543 CallDescriptor* descriptor,
1518 bool run_verifier) { 1544 bool run_verifier) {
1519 PipelineData* data = this->data_; 1545 PipelineData* data = this->data_;
1520 // Don't track usage for this zone in compiler stats. 1546 // Don't track usage for this zone in compiler stats.
1521 base::SmartPointer<Zone> verifier_zone; 1547 base::SmartPointer<Zone> verifier_zone;
1522 RegisterAllocatorVerifier* verifier = nullptr; 1548 RegisterAllocatorVerifier* verifier = nullptr;
1523 if (run_verifier) { 1549 if (run_verifier) {
1524 verifier_zone.Reset(new Zone(isolate()->allocator())); 1550 verifier_zone.Reset(new Zone(isolate()->allocator()));
1525 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier( 1551 verifier = new (verifier_zone.get()) RegisterAllocatorVerifier(
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 } 1628 }
1603 1629
1604 data->DeleteRegisterAllocationZone(); 1630 data->DeleteRegisterAllocationZone();
1605 } 1631 }
1606 1632
1607 Isolate* Pipeline::isolate() const { return info()->isolate(); } 1633 Isolate* Pipeline::isolate() const { return info()->isolate(); }
1608 1634
1609 } // namespace compiler 1635 } // namespace compiler
1610 } // namespace internal 1636 } // namespace internal
1611 } // namespace v8 1637 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/pipeline.h ('k') | src/compiler/wasm-compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698