Chromium Code Reviews| 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 FILE* turbo_cfg_file = base::OS::FOpen("turbo.cfg", "a+"); | |
|
Benedikt Meurer
2014/10/13 04:02:12
Please use std::ofstream here.
Jarin
2014/10/13 07:35:53
Done.
| |
| 95 OFStream turbo_cfg_of(turbo_cfg_file); | |
| 96 turbo_cfg_of << AsC1VCompilation(info()); | |
| 97 fclose(turbo_cfg_file); | |
| 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 FILE* turbo_cfg_file = base::OS::FOpen("turbo.cfg", "a+"); | |
|
Benedikt Meurer
2014/10/13 04:02:12
Please use std::ofstream here.
Jarin
2014/10/13 07:35:52
Done.
| |
| 147 OFStream turbo_cfg_of(turbo_cfg_file); | |
| 148 turbo_cfg_of << AsC1V(phase, schedule, instructions); | |
| 149 fclose(turbo_cfg_file); | |
| 150 } | |
| 151 | |
| 152 | |
| 153 void Pipeline::PrintAllocator(const char* phase, | |
| 154 const RegisterAllocator* allocator) { | |
| 155 FILE* turbo_cfg_file = base::OS::FOpen("turbo.cfg", "a+"); | |
|
Benedikt Meurer
2014/10/13 04:02:12
Please use std::ofstream here.
Jarin
2014/10/13 07:35:53
Done.
| |
| 156 OFStream turbo_cfg_of(turbo_cfg_file); | |
| 157 turbo_cfg_of << AsC1VAllocator(phase, allocator); | |
| 158 fclose(turbo_cfg_file); | |
| 159 } | |
| 160 | |
| 161 | |
| 135 class AstGraphBuilderWithPositions : public AstGraphBuilder { | 162 class AstGraphBuilderWithPositions : public AstGraphBuilder { |
| 136 public: | 163 public: |
| 137 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, | 164 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, |
| 138 SourcePositionTable* source_positions) | 165 SourcePositionTable* source_positions) |
| 139 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} | 166 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} |
| 140 | 167 |
| 141 bool CreateGraph() { | 168 bool CreateGraph() { |
| 142 SourcePositionTable::Scope pos(source_positions_, | 169 SourcePositionTable::Scope pos(source_positions_, |
| 143 SourcePosition::Unknown()); | 170 SourcePosition::Unknown()); |
| 144 return AstGraphBuilder::CreateGraph(); | 171 return AstGraphBuilder::CreateGraph(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } | 208 } |
| 182 | 209 |
| 183 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); | 210 if (FLAG_turbo_stats) isolate()->GetTStatistics()->Initialize(info_); |
| 184 | 211 |
| 185 if (FLAG_trace_turbo) { | 212 if (FLAG_trace_turbo) { |
| 186 OFStream os(stdout); | 213 OFStream os(stdout); |
| 187 os << "---------------------------------------------------\n" | 214 os << "---------------------------------------------------\n" |
| 188 << "Begin compiling method " | 215 << "Begin compiling method " |
| 189 << info()->function()->debug_name()->ToCString().get() | 216 << info()->function()->debug_name()->ToCString().get() |
| 190 << " using Turbofan" << std::endl; | 217 << " using Turbofan" << std::endl; |
| 218 PrintCompilationStart(); | |
| 191 } | 219 } |
| 192 | 220 |
| 193 // Build the graph. | 221 // Build the graph. |
| 194 Graph graph(zone()); | 222 Graph graph(zone()); |
| 195 SourcePositionTable source_positions(&graph); | 223 SourcePositionTable source_positions(&graph); |
| 196 source_positions.AddDecorator(); | 224 source_positions.AddDecorator(); |
| 197 // TODO(turbofan): there is no need to type anything during initial graph | 225 // 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 | 226 // construction. This is currently only needed for the node cache, which the |
| 199 // typer could sweep over later. | 227 // typer could sweep over later. |
| 200 Typer typer(zone()); | 228 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. | 426 // Select and schedule instructions covering the scheduled graph. |
| 399 { | 427 { |
| 400 InstructionSelector selector(&sequence, source_positions); | 428 InstructionSelector selector(&sequence, source_positions); |
| 401 selector.SelectInstructions(); | 429 selector.SelectInstructions(); |
| 402 } | 430 } |
| 403 | 431 |
| 404 if (FLAG_trace_turbo) { | 432 if (FLAG_trace_turbo) { |
| 405 OFStream os(stdout); | 433 OFStream os(stdout); |
| 406 os << "----- Instruction sequence before register allocation -----\n" | 434 os << "----- Instruction sequence before register allocation -----\n" |
| 407 << sequence; | 435 << sequence; |
| 436 PrintScheduleAndInstructions("CodeGen", schedule, &sequence); | |
| 408 } | 437 } |
| 409 | 438 |
| 410 // Allocate registers. | 439 // Allocate registers. |
| 411 { | 440 { |
| 412 int node_count = graph->NodeCount(); | 441 int node_count = graph->NodeCount(); |
| 413 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { | 442 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { |
| 414 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); | 443 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); |
| 415 return Handle<Code>::null(); | 444 return Handle<Code>::null(); |
| 416 } | 445 } |
| 417 RegisterAllocator allocator(&sequence); | 446 RegisterAllocator allocator(&sequence); |
| 418 if (!allocator.Allocate()) { | 447 if (!allocator.Allocate()) { |
| 419 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); | 448 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); |
| 420 return Handle<Code>::null(); | 449 return Handle<Code>::null(); |
| 421 } | 450 } |
| 451 if (FLAG_trace_turbo) { | |
| 452 PrintAllocator("CodeGen", &allocator); | |
| 453 } | |
| 422 } | 454 } |
| 423 | 455 |
| 424 if (FLAG_trace_turbo) { | 456 if (FLAG_trace_turbo) { |
| 425 OFStream os(stdout); | 457 OFStream os(stdout); |
| 426 os << "----- Instruction sequence after register allocation -----\n" | 458 os << "----- Instruction sequence after register allocation -----\n" |
| 427 << sequence; | 459 << sequence; |
| 428 } | 460 } |
| 429 | 461 |
| 430 // Generate native sequence. | 462 // Generate native sequence. |
| 431 CodeGenerator generator(&sequence); | 463 CodeGenerator generator(&sequence); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 446 } | 478 } |
| 447 | 479 |
| 448 | 480 |
| 449 void Pipeline::TearDown() { | 481 void Pipeline::TearDown() { |
| 450 InstructionOperand::TearDownCaches(); | 482 InstructionOperand::TearDownCaches(); |
| 451 } | 483 } |
| 452 | 484 |
| 453 } // namespace compiler | 485 } // namespace compiler |
| 454 } // namespace internal | 486 } // namespace internal |
| 455 } // namespace v8 | 487 } // namespace v8 |
| OLD | NEW |