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 <sstream> | 8 #include <sstream> |
8 | 9 |
9 #include "src/base/platform/elapsed-timer.h" | 10 #include "src/base/platform/elapsed-timer.h" |
10 #include "src/compiler/ast-graph-builder.h" | 11 #include "src/compiler/ast-graph-builder.h" |
11 #include "src/compiler/basic-block-instrumentor.h" | 12 #include "src/compiler/basic-block-instrumentor.h" |
12 #include "src/compiler/change-lowering.h" | 13 #include "src/compiler/change-lowering.h" |
13 #include "src/compiler/code-generator.h" | 14 #include "src/compiler/code-generator.h" |
14 #include "src/compiler/graph-replay.h" | 15 #include "src/compiler/graph-replay.h" |
15 #include "src/compiler/graph-visualizer.h" | 16 #include "src/compiler/graph-visualizer.h" |
16 #include "src/compiler/instruction.h" | 17 #include "src/compiler/instruction.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 84 |
84 static inline bool VerifyGraphs() { | 85 static inline bool VerifyGraphs() { |
85 #ifdef DEBUG | 86 #ifdef DEBUG |
86 return true; | 87 return true; |
87 #else | 88 #else |
88 return FLAG_turbo_verify; | 89 return FLAG_turbo_verify; |
89 #endif | 90 #endif |
90 } | 91 } |
91 | 92 |
92 | 93 |
94 void Pipeline::PrintCompilationStart() { | |
95 std::ofstream turbo_cfg_stream("turbo.cfg", | |
Vyacheslav Egorov (Google)
2014/10/13 07:42:10
consider mangling the name with PID so it works fr
| |
96 std::fstream::out | std::fstream::app); | |
97 turbo_cfg_stream << AsC1VCompilation(info()); | |
98 } | |
99 | |
100 | |
93 void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) { | 101 void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) { |
94 if (FLAG_trace_turbo) { | 102 if (FLAG_trace_turbo) { |
95 char buffer[256]; | 103 char buffer[256]; |
96 Vector<char> filename(buffer, sizeof(buffer)); | 104 Vector<char> filename(buffer, sizeof(buffer)); |
105 SmartArrayPointer<char> functionname; | |
97 if (!info_->shared_info().is_null()) { | 106 if (!info_->shared_info().is_null()) { |
98 SmartArrayPointer<char> functionname = | 107 functionname = info_->shared_info()->DebugName()->ToCString(); |
99 info_->shared_info()->DebugName()->ToCString(); | |
100 if (strlen(functionname.get()) > 0) { | 108 if (strlen(functionname.get()) > 0) { |
101 SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase); | 109 SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase); |
102 } else { | 110 } else { |
103 SNPrintF(filename, "turbo-%p-%s", static_cast<void*>(info_), phase); | 111 SNPrintF(filename, "turbo-%p-%s", static_cast<void*>(info_), phase); |
104 } | 112 } |
105 } else { | 113 } else { |
106 SNPrintF(filename, "turbo-none-%s", phase); | 114 SNPrintF(filename, "turbo-none-%s", phase); |
107 } | 115 } |
108 std::replace(filename.start(), filename.start() + filename.length(), ' ', | 116 std::replace(filename.start(), filename.start() + filename.length(), ' ', |
109 '_'); | 117 '_'); |
(...skipping 15 matching lines...) Expand all Loading... | |
125 fclose(json_file); | 133 fclose(json_file); |
126 | 134 |
127 OFStream os(stdout); | 135 OFStream os(stdout); |
128 os << "-- " << phase << " graph printed to file " << filename.start() | 136 os << "-- " << phase << " graph printed to file " << filename.start() |
129 << "\n"; | 137 << "\n"; |
130 } | 138 } |
131 if (VerifyGraphs()) Verifier::Run(graph); | 139 if (VerifyGraphs()) Verifier::Run(graph); |
132 } | 140 } |
133 | 141 |
134 | 142 |
143 void Pipeline::PrintScheduleAndInstructions( | |
144 const char* phase, const Schedule* schedule, | |
145 const InstructionSequence* instructions) { | |
146 std::ofstream turbo_cfg_stream("turbo.cfg", | |
147 std::fstream::out | std::fstream::app); | |
148 turbo_cfg_stream << AsC1V(phase, schedule, instructions); | |
149 } | |
150 | |
151 | |
152 void Pipeline::PrintAllocator(const char* phase, | |
153 const RegisterAllocator* allocator) { | |
154 std::ofstream turbo_cfg_stream("turbo.cfg", | |
155 std::fstream::out | std::fstream::app); | |
156 turbo_cfg_stream << AsC1VAllocator(phase, allocator); | |
157 } | |
158 | |
159 | |
135 class AstGraphBuilderWithPositions : public AstGraphBuilder { | 160 class AstGraphBuilderWithPositions : public AstGraphBuilder { |
136 public: | 161 public: |
137 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, | 162 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, |
138 SourcePositionTable* source_positions) | 163 SourcePositionTable* source_positions) |
139 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} | 164 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} |
140 | 165 |
141 bool CreateGraph() { | 166 bool CreateGraph() { |
142 SourcePositionTable::Scope pos(source_positions_, | 167 SourcePositionTable::Scope pos(source_positions_, |
143 SourcePosition::Unknown()); | 168 SourcePosition::Unknown()); |
144 return AstGraphBuilder::CreateGraph(); | 169 return AstGraphBuilder::CreateGraph(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 } | 206 } |
182 | 207 |
183 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); | 208 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); |
184 | 209 |
185 if (FLAG_trace_turbo) { | 210 if (FLAG_trace_turbo) { |
186 OFStream os(stdout); | 211 OFStream os(stdout); |
187 os << "---------------------------------------------------\n" | 212 os << "---------------------------------------------------\n" |
188 << "Begin compiling method " | 213 << "Begin compiling method " |
189 << info()->function()->debug_name()->ToCString().get() | 214 << info()->function()->debug_name()->ToCString().get() |
190 << " using Turbofan" << std::endl; | 215 << " using Turbofan" << std::endl; |
216 PrintCompilationStart(); | |
191 } | 217 } |
192 | 218 |
193 // Build the graph. | 219 // Build the graph. |
194 Graph graph(zone()); | 220 Graph graph(zone()); |
195 SourcePositionTable source_positions(&graph); | 221 SourcePositionTable source_positions(&graph); |
196 source_positions.AddDecorator(); | 222 source_positions.AddDecorator(); |
197 // TODO(turbofan): there is no need to type anything during initial graph | 223 // TODO(turbofan): there is no need to type anything during initial graph |
198 // construction. This is currently only needed for the node cache, which the | 224 // construction. This is currently only needed for the node cache, which the |
199 // typer could sweep over later. | 225 // typer could sweep over later. |
200 Typer typer(zone()); | 226 Typer typer(zone()); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 // Select and schedule instructions covering the scheduled graph. | 424 // Select and schedule instructions covering the scheduled graph. |
399 { | 425 { |
400 InstructionSelector selector(&sequence, source_positions); | 426 InstructionSelector selector(&sequence, source_positions); |
401 selector.SelectInstructions(); | 427 selector.SelectInstructions(); |
402 } | 428 } |
403 | 429 |
404 if (FLAG_trace_turbo) { | 430 if (FLAG_trace_turbo) { |
405 OFStream os(stdout); | 431 OFStream os(stdout); |
406 os << "----- Instruction sequence before register allocation -----\n" | 432 os << "----- Instruction sequence before register allocation -----\n" |
407 << sequence; | 433 << sequence; |
434 PrintScheduleAndInstructions("CodeGen", schedule, &sequence); | |
408 } | 435 } |
409 | 436 |
410 // Allocate registers. | 437 // Allocate registers. |
411 { | 438 { |
412 int node_count = graph->NodeCount(); | 439 int node_count = graph->NodeCount(); |
413 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { | 440 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { |
414 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); | 441 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); |
415 return Handle<Code>::null(); | 442 return Handle<Code>::null(); |
416 } | 443 } |
417 RegisterAllocator allocator(&sequence); | 444 RegisterAllocator allocator(&sequence); |
418 if (!allocator.Allocate()) { | 445 if (!allocator.Allocate()) { |
419 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); | 446 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
420 return Handle<Code>::null(); | 447 return Handle<Code>::null(); |
421 } | 448 } |
449 if (FLAG_trace_turbo) { | |
450 PrintAllocator("CodeGen", &allocator); | |
451 } | |
422 } | 452 } |
423 | 453 |
424 if (FLAG_trace_turbo) { | 454 if (FLAG_trace_turbo) { |
425 OFStream os(stdout); | 455 OFStream os(stdout); |
426 os << "----- Instruction sequence after register allocation -----\n" | 456 os << "----- Instruction sequence after register allocation -----\n" |
427 << sequence; | 457 << sequence; |
428 } | 458 } |
429 | 459 |
430 // Generate native sequence. | 460 // Generate native sequence. |
431 CodeGenerator generator(&sequence); | 461 CodeGenerator generator(&sequence); |
(...skipping 14 matching lines...) Expand all Loading... | |
446 } | 476 } |
447 | 477 |
448 | 478 |
449 void Pipeline::TearDown() { | 479 void Pipeline::TearDown() { |
450 InstructionOperand::TearDownCaches(); | 480 InstructionOperand::TearDownCaches(); |
451 } | 481 } |
452 | 482 |
453 } // namespace compiler | 483 } // namespace compiler |
454 } // namespace internal | 484 } // namespace internal |
455 } // namespace v8 | 485 } // namespace v8 |
OLD | NEW |