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