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) | |
8 #include <sstream> | 7 #include <sstream> |
9 | 8 |
10 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
11 #include "src/compiler/ast-graph-builder.h" | 10 #include "src/compiler/ast-graph-builder.h" |
12 #include "src/compiler/basic-block-instrumentor.h" | 11 #include "src/compiler/basic-block-instrumentor.h" |
13 #include "src/compiler/change-lowering.h" | 12 #include "src/compiler/change-lowering.h" |
14 #include "src/compiler/code-generator.h" | 13 #include "src/compiler/code-generator.h" |
15 #include "src/compiler/control-reducer.h" | 14 #include "src/compiler/control-reducer.h" |
16 #include "src/compiler/graph-replay.h" | 15 #include "src/compiler/graph-replay.h" |
17 #include "src/compiler/graph-visualizer.h" | 16 #include "src/compiler/graph-visualizer.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 90 |
92 static inline bool VerifyGraphs() { | 91 static inline bool VerifyGraphs() { |
93 #ifdef DEBUG | 92 #ifdef DEBUG |
94 return true; | 93 return true; |
95 #else | 94 #else |
96 return FLAG_turbo_verify; | 95 return FLAG_turbo_verify; |
97 #endif | 96 #endif |
98 } | 97 } |
99 | 98 |
100 | 99 |
101 struct TurboCfgFile : public std::ofstream { | 100 void Pipeline::PrintCompilationStart() { |
102 explicit TurboCfgFile(Isolate* isolate) | 101 std::ofstream turbo_cfg_stream; |
103 : std::ofstream(isolate->GetTurboCfgFileName(), std::ios_base::app) {} | 102 OpenTurboCfgFile(&turbo_cfg_stream); |
104 }; | 103 turbo_cfg_stream << AsC1VCompilation(info()); |
| 104 } |
| 105 |
| 106 |
| 107 void Pipeline::OpenTurboCfgFile(std::ofstream* stream) { |
| 108 char buffer[512]; |
| 109 Vector<char> filename(buffer, sizeof(buffer)); |
| 110 isolate()->GetTurboCfgFileName(filename); |
| 111 stream->open(filename.start(), std::fstream::out | std::fstream::app); |
| 112 } |
105 | 113 |
106 | 114 |
107 void Pipeline::VerifyAndPrintGraph( | 115 void Pipeline::VerifyAndPrintGraph( |
108 Graph* graph, const char* phase, bool untyped) { | 116 Graph* graph, const char* phase, bool untyped) { |
109 if (FLAG_trace_turbo) { | 117 if (FLAG_trace_turbo) { |
110 char buffer[256]; | 118 char buffer[256]; |
111 Vector<char> filename(buffer, sizeof(buffer)); | 119 Vector<char> filename(buffer, sizeof(buffer)); |
112 SmartArrayPointer<char> functionname; | 120 SmartArrayPointer<char> functionname; |
113 if (!info_->shared_info().is_null()) { | 121 if (!info_->shared_info().is_null()) { |
114 functionname = info_->shared_info()->DebugName()->ToCString(); | 122 functionname = info_->shared_info()->DebugName()->ToCString(); |
(...skipping 28 matching lines...) Expand all Loading... |
143 os << "-- " << phase << " graph printed to file " << filename.start() | 151 os << "-- " << phase << " graph printed to file " << filename.start() |
144 << "\n"; | 152 << "\n"; |
145 } | 153 } |
146 if (VerifyGraphs()) { | 154 if (VerifyGraphs()) { |
147 Verifier::Run(graph, | 155 Verifier::Run(graph, |
148 FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED); | 156 FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED); |
149 } | 157 } |
150 } | 158 } |
151 | 159 |
152 | 160 |
| 161 void Pipeline::PrintScheduleAndInstructions( |
| 162 const char* phase, const Schedule* schedule, |
| 163 const SourcePositionTable* positions, |
| 164 const InstructionSequence* instructions) { |
| 165 std::ofstream turbo_cfg_stream; |
| 166 OpenTurboCfgFile(&turbo_cfg_stream); |
| 167 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions); |
| 168 } |
| 169 |
| 170 |
| 171 void Pipeline::PrintAllocator(const char* phase, |
| 172 const RegisterAllocator* allocator) { |
| 173 std::ofstream turbo_cfg_stream; |
| 174 OpenTurboCfgFile(&turbo_cfg_stream); |
| 175 turbo_cfg_stream << AsC1VAllocator(phase, allocator); |
| 176 } |
| 177 |
| 178 |
153 class AstGraphBuilderWithPositions : public AstGraphBuilder { | 179 class AstGraphBuilderWithPositions : public AstGraphBuilder { |
154 public: | 180 public: |
155 explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, | 181 explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, |
156 JSGraph* jsgraph, | 182 JSGraph* jsgraph, |
157 SourcePositionTable* source_positions) | 183 SourcePositionTable* source_positions) |
158 : AstGraphBuilder(local_zone, info, jsgraph), | 184 : AstGraphBuilder(local_zone, info, jsgraph), |
159 source_positions_(source_positions) {} | 185 source_positions_(source_positions) {} |
160 | 186 |
161 bool CreateGraph() { | 187 bool CreateGraph() { |
162 SourcePositionTable::Scope pos(source_positions_, | 188 SourcePositionTable::Scope pos(source_positions_, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 } | 227 } |
202 | 228 |
203 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); | 229 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); |
204 | 230 |
205 if (FLAG_trace_turbo) { | 231 if (FLAG_trace_turbo) { |
206 OFStream os(stdout); | 232 OFStream os(stdout); |
207 os << "---------------------------------------------------\n" | 233 os << "---------------------------------------------------\n" |
208 << "Begin compiling method " | 234 << "Begin compiling method " |
209 << info()->function()->debug_name()->ToCString().get() | 235 << info()->function()->debug_name()->ToCString().get() |
210 << " using Turbofan" << std::endl; | 236 << " using Turbofan" << std::endl; |
211 TurboCfgFile(isolate()) << AsC1VCompilation(info()); | 237 PrintCompilationStart(); |
212 } | 238 } |
213 | 239 |
214 ZonePool zone_pool(isolate()); | 240 ZonePool zone_pool(isolate()); |
215 | 241 |
216 // Build the graph. | 242 // Build the graph. |
217 Graph graph(zone()); | 243 Graph graph(zone()); |
218 SourcePositionTable source_positions(&graph); | 244 SourcePositionTable source_positions(&graph); |
219 source_positions.AddDecorator(); | 245 source_positions.AddDecorator(); |
220 // TODO(turbofan): there is no need to type anything during initial graph | 246 // TODO(turbofan): there is no need to type anything during initial graph |
221 // construction. This is currently only needed for the node cache, which the | 247 // construction. This is currently only needed for the node cache, which the |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 ZonePool::Scope zone_scope(zone_pool); | 480 ZonePool::Scope zone_scope(zone_pool); |
455 InstructionSelector selector(zone_scope.zone(), linkage, &sequence, | 481 InstructionSelector selector(zone_scope.zone(), linkage, &sequence, |
456 schedule, source_positions); | 482 schedule, source_positions); |
457 selector.SelectInstructions(); | 483 selector.SelectInstructions(); |
458 } | 484 } |
459 | 485 |
460 if (FLAG_trace_turbo) { | 486 if (FLAG_trace_turbo) { |
461 OFStream os(stdout); | 487 OFStream os(stdout); |
462 os << "----- Instruction sequence before register allocation -----\n" | 488 os << "----- Instruction sequence before register allocation -----\n" |
463 << sequence; | 489 << sequence; |
464 TurboCfgFile(isolate()) | 490 PrintScheduleAndInstructions("CodeGen", schedule, source_positions, |
465 << AsC1V("CodeGen", schedule, source_positions, &sequence); | 491 &sequence); |
466 } | 492 } |
467 | 493 |
468 // Allocate registers. | 494 // Allocate registers. |
469 Frame frame; | 495 Frame frame; |
470 { | 496 { |
471 int node_count = graph->NodeCount(); | 497 int node_count = graph->NodeCount(); |
472 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { | 498 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { |
473 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); | 499 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); |
474 return Handle<Code>::null(); | 500 return Handle<Code>::null(); |
475 } | 501 } |
476 ZonePool::Scope zone_scope(zone_pool); | 502 ZonePool::Scope zone_scope(zone_pool); |
477 RegisterAllocator allocator(zone_scope.zone(), &frame, linkage->info(), | 503 RegisterAllocator allocator(zone_scope.zone(), &frame, linkage->info(), |
478 &sequence); | 504 &sequence); |
479 if (!allocator.Allocate(zone_pool)) { | 505 if (!allocator.Allocate(zone_pool)) { |
480 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); | 506 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
481 return Handle<Code>::null(); | 507 return Handle<Code>::null(); |
482 } | 508 } |
483 if (FLAG_trace_turbo) { | 509 if (FLAG_trace_turbo) { |
484 TurboCfgFile(isolate()) << AsC1VAllocator("CodeGen", &allocator); | 510 PrintAllocator("CodeGen", &allocator); |
485 } | 511 } |
486 } | 512 } |
487 | 513 |
488 if (FLAG_trace_turbo) { | 514 if (FLAG_trace_turbo) { |
489 OFStream os(stdout); | 515 OFStream os(stdout); |
490 os << "----- Instruction sequence after register allocation -----\n" | 516 os << "----- Instruction sequence after register allocation -----\n" |
491 << sequence; | 517 << sequence; |
492 } | 518 } |
493 | 519 |
494 // Generate native sequence. | 520 // Generate native sequence. |
(...skipping 15 matching lines...) Expand all Loading... |
510 } | 536 } |
511 | 537 |
512 | 538 |
513 void Pipeline::TearDown() { | 539 void Pipeline::TearDown() { |
514 InstructionOperand::TearDownCaches(); | 540 InstructionOperand::TearDownCaches(); |
515 } | 541 } |
516 | 542 |
517 } // namespace compiler | 543 } // namespace compiler |
518 } // namespace internal | 544 } // namespace internal |
519 } // namespace v8 | 545 } // namespace v8 |
OLD | NEW |