| 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 "src/base/platform/elapsed-timer.h" | 7 #include "src/base/platform/elapsed-timer.h" |
| 8 #include "src/compiler/ast-graph-builder.h" | 8 #include "src/compiler/ast-graph-builder.h" |
| 9 #include "src/compiler/code-generator.h" | 9 #include "src/compiler/code-generator.h" |
| 10 #include "src/compiler/graph-replay.h" | 10 #include "src/compiler/graph-replay.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 static inline bool VerifyGraphs() { | 77 static inline bool VerifyGraphs() { |
| 78 #ifdef DEBUG | 78 #ifdef DEBUG |
| 79 return true; | 79 return true; |
| 80 #else | 80 #else |
| 81 return FLAG_turbo_verify; | 81 return FLAG_turbo_verify; |
| 82 #endif | 82 #endif |
| 83 } | 83 } |
| 84 | 84 |
| 85 | 85 |
| 86 void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) { | 86 void Pipeline::VerifyAndPrintGraph( |
| 87 Graph* graph, const char* phase, Verifier::Typing typing) { |
| 87 if (FLAG_trace_turbo) { | 88 if (FLAG_trace_turbo) { |
| 88 char buffer[256]; | 89 char buffer[256]; |
| 89 Vector<char> filename(buffer, sizeof(buffer)); | 90 Vector<char> filename(buffer, sizeof(buffer)); |
| 90 SmartArrayPointer<char> functionname = | 91 SmartArrayPointer<char> functionname = |
| 91 info_->shared_info()->DebugName()->ToCString(); | 92 info_->shared_info()->DebugName()->ToCString(); |
| 92 if (strlen(functionname.get()) > 0) { | 93 if (strlen(functionname.get()) > 0) { |
| 93 SNPrintF(filename, "turbo-%s-%s.dot", functionname.get(), phase); | 94 SNPrintF(filename, "turbo-%s-%s.dot", functionname.get(), phase); |
| 94 } else { | 95 } else { |
| 95 SNPrintF(filename, "turbo-%p-%s.dot", static_cast<void*>(info_), phase); | 96 SNPrintF(filename, "turbo-%p-%s.dot", static_cast<void*>(info_), phase); |
| 96 } | 97 } |
| 97 std::replace(filename.start(), filename.start() + filename.length(), ' ', | 98 std::replace(filename.start(), filename.start() + filename.length(), ' ', |
| 98 '_'); | 99 '_'); |
| 99 FILE* file = base::OS::FOpen(filename.start(), "w+"); | 100 FILE* file = base::OS::FOpen(filename.start(), "w+"); |
| 100 OFStream of(file); | 101 OFStream of(file); |
| 101 of << AsDOT(*graph); | 102 of << AsDOT(*graph); |
| 102 fclose(file); | 103 fclose(file); |
| 103 | 104 |
| 104 OFStream os(stdout); | 105 OFStream os(stdout); |
| 105 os << "-- " << phase << " graph printed to file " << filename.start() | 106 os << "-- " << phase << " graph printed to file " << filename.start() |
| 106 << "\n"; | 107 << "\n"; |
| 107 } | 108 } |
| 108 if (VerifyGraphs()) Verifier::Run(graph); | 109 if (VerifyGraphs()) { |
| 110 Verifier::Run(graph, FLAG_turbo_types ? typing : Verifier::UNTYPED); |
| 111 } |
| 109 } | 112 } |
| 110 | 113 |
| 111 | 114 |
| 112 class AstGraphBuilderWithPositions : public AstGraphBuilder { | 115 class AstGraphBuilderWithPositions : public AstGraphBuilder { |
| 113 public: | 116 public: |
| 114 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, | 117 explicit AstGraphBuilderWithPositions(CompilationInfo* info, JSGraph* jsgraph, |
| 115 SourcePositionTable* source_positions) | 118 SourcePositionTable* source_positions) |
| 116 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} | 119 : AstGraphBuilder(info, jsgraph), source_positions_(source_positions) {} |
| 117 | 120 |
| 118 bool CreateGraph() { | 121 bool CreateGraph() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 os << "---------------------------------------------------\n" | 153 os << "---------------------------------------------------\n" |
| 151 << "Begin compiling method " | 154 << "Begin compiling method " |
| 152 << info()->function()->debug_name()->ToCString().get() | 155 << info()->function()->debug_name()->ToCString().get() |
| 153 << " using Turbofan" << endl; | 156 << " using Turbofan" << endl; |
| 154 } | 157 } |
| 155 | 158 |
| 156 // Build the graph. | 159 // Build the graph. |
| 157 Graph graph(zone()); | 160 Graph graph(zone()); |
| 158 SourcePositionTable source_positions(&graph); | 161 SourcePositionTable source_positions(&graph); |
| 159 source_positions.AddDecorator(); | 162 source_positions.AddDecorator(); |
| 160 // TODO(turbofan): there is no need to type anything during initial graph | 163 Typer typer(&graph, info()->context()); |
| 161 // construction. This is currently only needed for the node cache, which the | |
| 162 // typer could sweep over later. | |
| 163 Typer typer(zone()); | |
| 164 CommonOperatorBuilder common(zone()); | 164 CommonOperatorBuilder common(zone()); |
| 165 JSGraph jsgraph(&graph, &common, &typer); | 165 JSGraph jsgraph(&graph, &common); |
| 166 Node* context_node; | 166 Node* context_node; |
| 167 { | 167 { |
| 168 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH, | 168 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH, |
| 169 "graph builder"); | 169 "graph builder"); |
| 170 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph, | 170 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph, |
| 171 &source_positions); | 171 &source_positions); |
| 172 graph_builder.CreateGraph(); | 172 graph_builder.CreateGraph(); |
| 173 context_node = graph_builder.GetFunctionContext(); | 173 context_node = graph_builder.GetFunctionContext(); |
| 174 } | 174 } |
| 175 { | 175 { |
| 176 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH, | 176 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH, |
| 177 "phi reduction"); | 177 "phi reduction"); |
| 178 PhiReducer phi_reducer; | 178 PhiReducer phi_reducer; |
| 179 GraphReducer graph_reducer(&graph); | 179 GraphReducer graph_reducer(&graph); |
| 180 graph_reducer.AddReducer(&phi_reducer); | 180 graph_reducer.AddReducer(&phi_reducer); |
| 181 graph_reducer.ReduceGraph(); | 181 graph_reducer.ReduceGraph(); |
| 182 // TODO(mstarzinger): Running reducer once ought to be enough for everyone. | 182 // TODO(mstarzinger): Running reducer once ought to be enough for everyone. |
| 183 graph_reducer.ReduceGraph(); | 183 graph_reducer.ReduceGraph(); |
| 184 graph_reducer.ReduceGraph(); | 184 graph_reducer.ReduceGraph(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 VerifyAndPrintGraph(&graph, "Initial untyped"); | 187 VerifyAndPrintGraph(&graph, "Initial untyped", Verifier::UNTYPED); |
| 188 | 188 |
| 189 if (context_specialization_) { | 189 if (context_specialization_) { |
| 190 SourcePositionTable::Scope pos(&source_positions, | 190 SourcePositionTable::Scope pos(&source_positions, |
| 191 SourcePosition::Unknown()); | 191 SourcePosition::Unknown()); |
| 192 // Specialize the code to the context as aggressively as possible. | 192 // Specialize the code to the context as aggressively as possible. |
| 193 JSContextSpecializer spec(info(), &jsgraph, context_node); | 193 JSContextSpecializer spec(info(), &jsgraph, context_node); |
| 194 spec.SpecializeToContext(); | 194 spec.SpecializeToContext(); |
| 195 VerifyAndPrintGraph(&graph, "Context specialized"); | 195 VerifyAndPrintGraph(&graph, "Context specialized", Verifier::UNTYPED); |
| 196 } | 196 } |
| 197 | 197 |
| 198 if (FLAG_turbo_inlining) { | 198 if (FLAG_turbo_inlining) { |
| 199 SourcePositionTable::Scope pos(&source_positions, | 199 SourcePositionTable::Scope pos(&source_positions, |
| 200 SourcePosition::Unknown()); | 200 SourcePosition::Unknown()); |
| 201 JSInliner inliner(info(), &jsgraph); | 201 JSInliner inliner(info(), &jsgraph); |
| 202 inliner.Inline(); | 202 inliner.Inline(); |
| 203 VerifyAndPrintGraph(&graph, "Inlined"); | 203 VerifyAndPrintGraph(&graph, "Inlined", Verifier::UNTYPED); |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Print a replay of the initial graph. | 206 // Print a replay of the initial graph. |
| 207 if (FLAG_print_turbo_replay) { | 207 if (FLAG_print_turbo_replay) { |
| 208 GraphReplayPrinter::PrintReplay(&graph); | 208 GraphReplayPrinter::PrintReplay(&graph); |
| 209 } | 209 } |
| 210 | 210 |
| 211 if (FLAG_turbo_types) { | 211 if (FLAG_turbo_types) { |
| 212 { | 212 { |
| 213 // Type the graph. | 213 // Type the graph. |
| 214 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer"); | 214 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer"); |
| 215 typer.Run(&graph, info()->context()); | 215 typer.Run(); |
| 216 } | 216 } |
| 217 // All new nodes must be typed. | |
| 218 typer.DecorateGraph(&graph); | |
| 219 { | 217 { |
| 220 // Lower JSOperators where we can determine types. | 218 // Lower JSOperators where we can determine types. |
| 221 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, | 219 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, |
| 222 "typed lowering"); | 220 "typed lowering"); |
| 223 SourcePositionTable::Scope pos(&source_positions, | 221 SourcePositionTable::Scope pos(&source_positions, |
| 224 SourcePosition::Unknown()); | 222 SourcePosition::Unknown()); |
| 225 JSTypedLowering lowering(&jsgraph); | 223 JSTypedLowering lowering(&jsgraph); |
| 226 GraphReducer graph_reducer(&graph); | 224 GraphReducer graph_reducer(&graph); |
| 227 graph_reducer.AddReducer(&lowering); | 225 graph_reducer.AddReducer(&lowering); |
| 228 graph_reducer.ReduceGraph(); | 226 graph_reducer.ReduceGraph(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 357 } |
| 360 | 358 |
| 361 | 359 |
| 362 void Pipeline::TearDown() { | 360 void Pipeline::TearDown() { |
| 363 InstructionOperand::TearDownCaches(); | 361 InstructionOperand::TearDownCaches(); |
| 364 } | 362 } |
| 365 | 363 |
| 366 } // namespace compiler | 364 } // namespace compiler |
| 367 } // namespace internal | 365 } // namespace internal |
| 368 } // namespace v8 | 366 } // namespace v8 |
| OLD | NEW |