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

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

Issue 676673002: Reland 'Simplify TurboFan's c1visualizer file handling.' (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/compiler/pipeline.h ('k') | src/isolate.h » ('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"
6
7 #include <fstream> // NOLINT(readability/streams)
5 #include <sstream> 8 #include <sstream>
6 9
7 #include "src/base/platform/elapsed-timer.h" 10 #include "src/base/platform/elapsed-timer.h"
8 #include "src/compiler/ast-graph-builder.h" 11 #include "src/compiler/ast-graph-builder.h"
9 #include "src/compiler/basic-block-instrumentor.h" 12 #include "src/compiler/basic-block-instrumentor.h"
10 #include "src/compiler/change-lowering.h" 13 #include "src/compiler/change-lowering.h"
11 #include "src/compiler/code-generator.h" 14 #include "src/compiler/code-generator.h"
12 #include "src/compiler/control-reducer.h" 15 #include "src/compiler/control-reducer.h"
13 #include "src/compiler/graph-replay.h" 16 #include "src/compiler/graph-replay.h"
14 #include "src/compiler/graph-visualizer.h" 17 #include "src/compiler/graph-visualizer.h"
15 #include "src/compiler/instruction.h" 18 #include "src/compiler/instruction.h"
16 #include "src/compiler/instruction-selector.h" 19 #include "src/compiler/instruction-selector.h"
17 #include "src/compiler/js-context-specialization.h" 20 #include "src/compiler/js-context-specialization.h"
18 #include "src/compiler/js-generic-lowering.h" 21 #include "src/compiler/js-generic-lowering.h"
19 #include "src/compiler/js-inlining.h" 22 #include "src/compiler/js-inlining.h"
20 #include "src/compiler/js-typed-lowering.h" 23 #include "src/compiler/js-typed-lowering.h"
21 #include "src/compiler/machine-operator-reducer.h" 24 #include "src/compiler/machine-operator-reducer.h"
22 #include "src/compiler/phi-reducer.h" 25 #include "src/compiler/phi-reducer.h"
23 #include "src/compiler/pipeline.h"
24 #include "src/compiler/pipeline-statistics.h" 26 #include "src/compiler/pipeline-statistics.h"
25 #include "src/compiler/register-allocator.h" 27 #include "src/compiler/register-allocator.h"
26 #include "src/compiler/schedule.h" 28 #include "src/compiler/schedule.h"
27 #include "src/compiler/scheduler.h" 29 #include "src/compiler/scheduler.h"
28 #include "src/compiler/simplified-lowering.h" 30 #include "src/compiler/simplified-lowering.h"
29 #include "src/compiler/simplified-operator-reducer.h" 31 #include "src/compiler/simplified-operator-reducer.h"
30 #include "src/compiler/typer.h" 32 #include "src/compiler/typer.h"
31 #include "src/compiler/value-numbering-reducer.h" 33 #include "src/compiler/value-numbering-reducer.h"
32 #include "src/compiler/verifier.h" 34 #include "src/compiler/verifier.h"
33 #include "src/compiler/zone-pool.h" 35 #include "src/compiler/zone-pool.h"
34 #include "src/ostreams.h" 36 #include "src/ostreams.h"
35 #include "src/utils.h" 37 #include "src/utils.h"
36 38
37 namespace v8 { 39 namespace v8 {
38 namespace internal { 40 namespace internal {
39 namespace compiler { 41 namespace compiler {
40 42
41 static inline bool VerifyGraphs() { 43 static inline bool VerifyGraphs() {
42 #ifdef DEBUG 44 #ifdef DEBUG
43 return true; 45 return true;
44 #else 46 #else
45 return FLAG_turbo_verify; 47 return FLAG_turbo_verify;
46 #endif 48 #endif
47 } 49 }
48 50
49 51
50 void Pipeline::PrintCompilationStart() { 52 struct TurboCfgFile : public std::ofstream {
51 std::ofstream turbo_cfg_stream; 53 explicit TurboCfgFile(Isolate* isolate)
52 OpenTurboCfgFile(&turbo_cfg_stream); 54 : std::ofstream(isolate->GetTurboCfgFileName().c_str(),
53 turbo_cfg_stream << AsC1VCompilation(info()); 55 std::ios_base::app) {}
54 } 56 };
55
56
57 void Pipeline::OpenTurboCfgFile(std::ofstream* stream) {
58 char buffer[512];
59 Vector<char> filename(buffer, sizeof(buffer));
60 isolate()->GetTurboCfgFileName(filename);
61 stream->open(filename.start(), std::fstream::out | std::fstream::app);
62 }
63 57
64 58
65 void Pipeline::VerifyAndPrintGraph( 59 void Pipeline::VerifyAndPrintGraph(
66 Graph* graph, const char* phase, bool untyped) { 60 Graph* graph, const char* phase, bool untyped) {
67 if (FLAG_trace_turbo) { 61 if (FLAG_trace_turbo) {
68 char buffer[256]; 62 char buffer[256];
69 Vector<char> filename(buffer, sizeof(buffer)); 63 Vector<char> filename(buffer, sizeof(buffer));
70 SmartArrayPointer<char> functionname; 64 SmartArrayPointer<char> functionname;
71 if (!info_->shared_info().is_null()) { 65 if (!info_->shared_info().is_null()) {
72 functionname = info_->shared_info()->DebugName()->ToCString(); 66 functionname = info_->shared_info()->DebugName()->ToCString();
(...skipping 28 matching lines...) Expand all
101 os << "-- " << phase << " graph printed to file " << filename.start() 95 os << "-- " << phase << " graph printed to file " << filename.start()
102 << "\n"; 96 << "\n";
103 } 97 }
104 if (VerifyGraphs()) { 98 if (VerifyGraphs()) {
105 Verifier::Run(graph, 99 Verifier::Run(graph,
106 FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED); 100 FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED);
107 } 101 }
108 } 102 }
109 103
110 104
111 void Pipeline::PrintScheduleAndInstructions(
112 const char* phase, const Schedule* schedule,
113 const SourcePositionTable* positions,
114 const InstructionSequence* instructions) {
115 std::ofstream turbo_cfg_stream;
116 OpenTurboCfgFile(&turbo_cfg_stream);
117 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions);
118 }
119
120
121 void Pipeline::PrintAllocator(const char* phase,
122 const RegisterAllocator* allocator) {
123 std::ofstream turbo_cfg_stream;
124 OpenTurboCfgFile(&turbo_cfg_stream);
125 turbo_cfg_stream << AsC1VAllocator(phase, allocator);
126 }
127
128
129 class AstGraphBuilderWithPositions : public AstGraphBuilder { 105 class AstGraphBuilderWithPositions : public AstGraphBuilder {
130 public: 106 public:
131 explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info, 107 explicit AstGraphBuilderWithPositions(Zone* local_zone, CompilationInfo* info,
132 JSGraph* jsgraph, 108 JSGraph* jsgraph,
133 SourcePositionTable* source_positions) 109 SourcePositionTable* source_positions)
134 : AstGraphBuilder(local_zone, info, jsgraph), 110 : AstGraphBuilder(local_zone, info, jsgraph),
135 source_positions_(source_positions) {} 111 source_positions_(source_positions) {}
136 112
137 bool CreateGraph() { 113 bool CreateGraph() {
138 SourcePositionTable::Scope pos(source_positions_, 114 SourcePositionTable::Scope pos(source_positions_,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool)); 159 pipeline_statistics.Reset(new PipelineStatistics(info(), &zone_pool));
184 pipeline_statistics->BeginPhaseKind("create graph"); 160 pipeline_statistics->BeginPhaseKind("create graph");
185 } 161 }
186 162
187 if (FLAG_trace_turbo) { 163 if (FLAG_trace_turbo) {
188 OFStream os(stdout); 164 OFStream os(stdout);
189 os << "---------------------------------------------------\n" 165 os << "---------------------------------------------------\n"
190 << "Begin compiling method " 166 << "Begin compiling method "
191 << info()->function()->debug_name()->ToCString().get() 167 << info()->function()->debug_name()->ToCString().get()
192 << " using Turbofan" << std::endl; 168 << " using Turbofan" << std::endl;
193 PrintCompilationStart(); 169 TurboCfgFile tcf(isolate());
170 tcf << AsC1VCompilation(info());
194 } 171 }
195 172
196 // Build the graph. 173 // Build the graph.
197 Graph graph(zone()); 174 Graph graph(zone());
198 SourcePositionTable source_positions(&graph); 175 SourcePositionTable source_positions(&graph);
199 source_positions.AddDecorator(); 176 source_positions.AddDecorator();
200 // TODO(turbofan): there is no need to type anything during initial graph 177 // TODO(turbofan): there is no need to type anything during initial graph
201 // construction. This is currently only needed for the node cache, which the 178 // construction. This is currently only needed for the node cache, which the
202 // typer could sweep over later. 179 // typer could sweep over later.
203 Typer typer(&graph, info()->context()); 180 Typer typer(&graph, info()->context());
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 ZonePool::Scope zone_scope(zone_pool); 418 ZonePool::Scope zone_scope(zone_pool);
442 InstructionSelector selector(zone_scope.zone(), linkage, &sequence, 419 InstructionSelector selector(zone_scope.zone(), linkage, &sequence,
443 schedule, source_positions); 420 schedule, source_positions);
444 selector.SelectInstructions(); 421 selector.SelectInstructions();
445 } 422 }
446 423
447 if (FLAG_trace_turbo) { 424 if (FLAG_trace_turbo) {
448 OFStream os(stdout); 425 OFStream os(stdout);
449 os << "----- Instruction sequence before register allocation -----\n" 426 os << "----- Instruction sequence before register allocation -----\n"
450 << sequence; 427 << sequence;
451 PrintScheduleAndInstructions("CodeGen", schedule, source_positions, 428 TurboCfgFile tcf(isolate());
452 &sequence); 429 tcf << AsC1V("CodeGen", schedule, source_positions, &sequence);
453 } 430 }
454 431
455 // Allocate registers. 432 // Allocate registers.
456 Frame frame; 433 Frame frame;
457 { 434 {
458 int node_count = graph->NodeCount(); 435 int node_count = graph->NodeCount();
459 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) { 436 if (node_count > UnallocatedOperand::kMaxVirtualRegisters) {
460 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues); 437 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersForValues);
461 return Handle<Code>::null(); 438 return Handle<Code>::null();
462 } 439 }
463 ZonePool::Scope zone_scope(zone_pool); 440 ZonePool::Scope zone_scope(zone_pool);
464 RegisterAllocator allocator(zone_scope.zone(), &frame, linkage->info(), 441 RegisterAllocator allocator(zone_scope.zone(), &frame, linkage->info(),
465 &sequence); 442 &sequence);
466 if (!allocator.Allocate(pipeline_statistics)) { 443 if (!allocator.Allocate(pipeline_statistics)) {
467 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc); 444 linkage->info()->AbortOptimization(kNotEnoughVirtualRegistersRegalloc);
468 return Handle<Code>::null(); 445 return Handle<Code>::null();
469 } 446 }
470 if (FLAG_trace_turbo) { 447 if (FLAG_trace_turbo) {
471 PrintAllocator("CodeGen", &allocator); 448 TurboCfgFile tcf(isolate());
449 tcf << AsC1VAllocator("CodeGen", &allocator);
472 } 450 }
473 } 451 }
474 452
475 if (FLAG_trace_turbo) { 453 if (FLAG_trace_turbo) {
476 OFStream os(stdout); 454 OFStream os(stdout);
477 os << "----- Instruction sequence after register allocation -----\n" 455 os << "----- Instruction sequence after register allocation -----\n"
478 << sequence; 456 << sequence;
479 } 457 }
480 458
481 // Generate native sequence. 459 // Generate native sequence.
(...skipping 19 matching lines...) Expand all
501 } 479 }
502 480
503 481
504 void Pipeline::TearDown() { 482 void Pipeline::TearDown() {
505 InstructionOperand::TearDownCaches(); 483 InstructionOperand::TearDownCaches();
506 } 484 }
507 485
508 } // namespace compiler 486 } // namespace compiler
509 } // namespace internal 487 } // namespace internal
510 } // namespace v8 488 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/pipeline.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698