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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 | 99 |
100 void Pipeline::OpenTurboCfgFile(std::ofstream* stream) { | 100 void Pipeline::OpenTurboCfgFile(std::ofstream* stream) { |
101 char buffer[512]; | 101 char buffer[512]; |
102 Vector<char> filename(buffer, sizeof(buffer)); | 102 Vector<char> filename(buffer, sizeof(buffer)); |
103 isolate()->GetTurboCfgFileName(filename); | 103 isolate()->GetTurboCfgFileName(filename); |
104 stream->open(filename.start(), std::fstream::out | std::fstream::app); | 104 stream->open(filename.start(), std::fstream::out | std::fstream::app); |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) { | 108 void Pipeline::VerifyAndPrintGraph( |
| 109 Graph* graph, const char* phase, Verifier::Typing typing) { |
109 if (FLAG_trace_turbo) { | 110 if (FLAG_trace_turbo) { |
110 char buffer[256]; | 111 char buffer[256]; |
111 Vector<char> filename(buffer, sizeof(buffer)); | 112 Vector<char> filename(buffer, sizeof(buffer)); |
112 SmartArrayPointer<char> functionname; | 113 SmartArrayPointer<char> functionname; |
113 if (!info_->shared_info().is_null()) { | 114 if (!info_->shared_info().is_null()) { |
114 functionname = info_->shared_info()->DebugName()->ToCString(); | 115 functionname = info_->shared_info()->DebugName()->ToCString(); |
115 if (strlen(functionname.get()) > 0) { | 116 if (strlen(functionname.get()) > 0) { |
116 SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase); | 117 SNPrintF(filename, "turbo-%s-%s", functionname.get(), phase); |
117 } else { | 118 } else { |
118 SNPrintF(filename, "turbo-%p-%s", static_cast<void*>(info_), phase); | 119 SNPrintF(filename, "turbo-%p-%s", static_cast<void*>(info_), phase); |
(...skipping 17 matching lines...) Expand all Loading... |
136 SNPrintF(json_filename, "%s.json", filename.start()); | 137 SNPrintF(json_filename, "%s.json", filename.start()); |
137 FILE* json_file = base::OS::FOpen(json_filename.start(), "w+"); | 138 FILE* json_file = base::OS::FOpen(json_filename.start(), "w+"); |
138 OFStream json_of(json_file); | 139 OFStream json_of(json_file); |
139 json_of << AsJSON(*graph); | 140 json_of << AsJSON(*graph); |
140 fclose(json_file); | 141 fclose(json_file); |
141 | 142 |
142 OFStream os(stdout); | 143 OFStream os(stdout); |
143 os << "-- " << phase << " graph printed to file " << filename.start() | 144 os << "-- " << phase << " graph printed to file " << filename.start() |
144 << "\n"; | 145 << "\n"; |
145 } | 146 } |
146 if (VerifyGraphs()) Verifier::Run(graph); | 147 if (VerifyGraphs()) { |
| 148 Verifier::Run(graph, FLAG_turbo_types ? typing : Verifier::UNTYPED); |
| 149 } |
147 } | 150 } |
148 | 151 |
149 | 152 |
150 void Pipeline::PrintScheduleAndInstructions( | 153 void Pipeline::PrintScheduleAndInstructions( |
151 const char* phase, const Schedule* schedule, | 154 const char* phase, const Schedule* schedule, |
152 const SourcePositionTable* positions, | 155 const SourcePositionTable* positions, |
153 const InstructionSequence* instructions) { | 156 const InstructionSequence* instructions) { |
154 std::ofstream turbo_cfg_stream; | 157 std::ofstream turbo_cfg_stream; |
155 OpenTurboCfgFile(&turbo_cfg_stream); | 158 OpenTurboCfgFile(&turbo_cfg_stream); |
156 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions); | 159 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 PrintCompilationStart(); | 227 PrintCompilationStart(); |
225 } | 228 } |
226 | 229 |
227 // Build the graph. | 230 // Build the graph. |
228 Graph graph(zone()); | 231 Graph graph(zone()); |
229 SourcePositionTable source_positions(&graph); | 232 SourcePositionTable source_positions(&graph); |
230 source_positions.AddDecorator(); | 233 source_positions.AddDecorator(); |
231 // TODO(turbofan): there is no need to type anything during initial graph | 234 // TODO(turbofan): there is no need to type anything during initial graph |
232 // construction. This is currently only needed for the node cache, which the | 235 // construction. This is currently only needed for the node cache, which the |
233 // typer could sweep over later. | 236 // typer could sweep over later. |
234 Typer typer(zone()); | 237 Typer typer(&graph, info()->context()); |
235 MachineOperatorBuilder machine; | 238 MachineOperatorBuilder machine; |
236 CommonOperatorBuilder common(zone()); | 239 CommonOperatorBuilder common(zone()); |
237 JSOperatorBuilder javascript(zone()); | 240 JSOperatorBuilder javascript(zone()); |
238 JSGraph jsgraph(&graph, &common, &javascript, &typer, &machine); | 241 JSGraph jsgraph(&graph, &common, &javascript, &machine); |
239 Node* context_node; | 242 Node* context_node; |
240 { | 243 { |
241 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH, | 244 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH, |
242 "graph builder"); | 245 "graph builder"); |
243 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph, | 246 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph, |
244 &source_positions); | 247 &source_positions); |
245 graph_builder.CreateGraph(); | 248 graph_builder.CreateGraph(); |
246 context_node = graph_builder.GetFunctionContext(); | 249 context_node = graph_builder.GetFunctionContext(); |
247 } | 250 } |
248 { | 251 { |
249 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH, | 252 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH, |
250 "phi reduction"); | 253 "phi reduction"); |
251 PhiReducer phi_reducer; | 254 PhiReducer phi_reducer; |
252 GraphReducer graph_reducer(&graph); | 255 GraphReducer graph_reducer(&graph); |
253 graph_reducer.AddReducer(&phi_reducer); | 256 graph_reducer.AddReducer(&phi_reducer); |
254 graph_reducer.ReduceGraph(); | 257 graph_reducer.ReduceGraph(); |
255 // TODO(mstarzinger): Running reducer once ought to be enough for everyone. | 258 // TODO(mstarzinger): Running reducer once ought to be enough for everyone. |
256 graph_reducer.ReduceGraph(); | 259 graph_reducer.ReduceGraph(); |
257 graph_reducer.ReduceGraph(); | 260 graph_reducer.ReduceGraph(); |
258 } | 261 } |
259 | 262 |
260 VerifyAndPrintGraph(&graph, "Initial untyped"); | 263 VerifyAndPrintGraph(&graph, "Initial untyped", Verifier::UNTYPED); |
261 | 264 |
262 if (info()->is_context_specializing()) { | 265 if (info()->is_context_specializing()) { |
263 SourcePositionTable::Scope pos(&source_positions, | 266 SourcePositionTable::Scope pos(&source_positions, |
264 SourcePosition::Unknown()); | 267 SourcePosition::Unknown()); |
265 // Specialize the code to the context as aggressively as possible. | 268 // Specialize the code to the context as aggressively as possible. |
266 JSContextSpecializer spec(info(), &jsgraph, context_node); | 269 JSContextSpecializer spec(info(), &jsgraph, context_node); |
267 spec.SpecializeToContext(); | 270 spec.SpecializeToContext(); |
268 VerifyAndPrintGraph(&graph, "Context specialized"); | 271 VerifyAndPrintGraph(&graph, "Context specialized", Verifier::UNTYPED); |
269 } | 272 } |
270 | 273 |
271 if (info()->is_inlining_enabled()) { | 274 if (info()->is_inlining_enabled()) { |
272 SourcePositionTable::Scope pos(&source_positions, | 275 SourcePositionTable::Scope pos(&source_positions, |
273 SourcePosition::Unknown()); | 276 SourcePosition::Unknown()); |
274 JSInliner inliner(info(), &jsgraph); | 277 JSInliner inliner(info(), &jsgraph); |
275 inliner.Inline(); | 278 inliner.Inline(); |
276 VerifyAndPrintGraph(&graph, "Inlined"); | 279 VerifyAndPrintGraph(&graph, "Inlined", Verifier::UNTYPED); |
277 } | 280 } |
278 | 281 |
279 // Print a replay of the initial graph. | 282 // Print a replay of the initial graph. |
280 if (FLAG_print_turbo_replay) { | 283 if (FLAG_print_turbo_replay) { |
281 GraphReplayPrinter::PrintReplay(&graph); | 284 GraphReplayPrinter::PrintReplay(&graph); |
282 } | 285 } |
283 | 286 |
284 // Bailout here in case target architecture is not supported. | 287 // Bailout here in case target architecture is not supported. |
285 if (!SupportedTarget()) return Handle<Code>::null(); | 288 if (!SupportedTarget()) return Handle<Code>::null(); |
286 | 289 |
287 if (info()->is_typing_enabled()) { | 290 if (info()->is_typing_enabled()) { |
288 { | 291 { |
289 // Type the graph. | 292 // Type the graph. |
290 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer"); | 293 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer"); |
291 typer.Run(&graph, info()->context()); | 294 typer.Run(); |
292 VerifyAndPrintGraph(&graph, "Typed"); | 295 VerifyAndPrintGraph(&graph, "Typed"); |
293 } | 296 } |
294 // All new nodes must be typed. | |
295 typer.DecorateGraph(&graph); | |
296 { | 297 { |
297 // Lower JSOperators where we can determine types. | 298 // Lower JSOperators where we can determine types. |
298 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, | 299 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, |
299 "typed lowering"); | 300 "typed lowering"); |
300 SourcePositionTable::Scope pos(&source_positions, | 301 SourcePositionTable::Scope pos(&source_positions, |
301 SourcePosition::Unknown()); | 302 SourcePosition::Unknown()); |
302 JSTypedLowering lowering(&jsgraph); | 303 JSTypedLowering lowering(&jsgraph); |
303 GraphReducer graph_reducer(&graph); | 304 GraphReducer graph_reducer(&graph); |
304 graph_reducer.AddReducer(&lowering); | 305 graph_reducer.AddReducer(&lowering); |
305 graph_reducer.ReduceGraph(); | 306 graph_reducer.ReduceGraph(); |
(...skipping 23 matching lines...) Expand all Loading... |
329 ChangeLowering lowering(&jsgraph, &linkage); | 330 ChangeLowering lowering(&jsgraph, &linkage); |
330 MachineOperatorReducer mach_reducer(&jsgraph); | 331 MachineOperatorReducer mach_reducer(&jsgraph); |
331 GraphReducer graph_reducer(&graph); | 332 GraphReducer graph_reducer(&graph); |
332 // TODO(titzer): Figure out if we should run all reducers at once here. | 333 // TODO(titzer): Figure out if we should run all reducers at once here. |
333 graph_reducer.AddReducer(&vn_reducer); | 334 graph_reducer.AddReducer(&vn_reducer); |
334 graph_reducer.AddReducer(&simple_reducer); | 335 graph_reducer.AddReducer(&simple_reducer); |
335 graph_reducer.AddReducer(&lowering); | 336 graph_reducer.AddReducer(&lowering); |
336 graph_reducer.AddReducer(&mach_reducer); | 337 graph_reducer.AddReducer(&mach_reducer); |
337 graph_reducer.ReduceGraph(); | 338 graph_reducer.ReduceGraph(); |
338 | 339 |
339 VerifyAndPrintGraph(&graph, "Lowered changes"); | 340 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 341 VerifyAndPrintGraph(&graph, "Lowered changes", Verifier::UNTYPED); |
340 } | 342 } |
341 } | 343 } |
342 | 344 |
343 { | 345 { |
344 // Lower any remaining generic JSOperators. | 346 // Lower any remaining generic JSOperators. |
345 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, | 347 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, |
346 "generic lowering"); | 348 "generic lowering"); |
347 SourcePositionTable::Scope pos(&source_positions, | 349 SourcePositionTable::Scope pos(&source_positions, |
348 SourcePosition::Unknown()); | 350 SourcePosition::Unknown()); |
349 JSGenericLowering lowering(info(), &jsgraph); | 351 JSGenericLowering lowering(info(), &jsgraph); |
350 GraphReducer graph_reducer(&graph); | 352 GraphReducer graph_reducer(&graph); |
351 graph_reducer.AddReducer(&lowering); | 353 graph_reducer.AddReducer(&lowering); |
352 graph_reducer.ReduceGraph(); | 354 graph_reducer.ReduceGraph(); |
353 | 355 |
354 VerifyAndPrintGraph(&graph, "Lowered generic"); | 356 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works. |
| 357 VerifyAndPrintGraph(&graph, "Lowered generic", Verifier::UNTYPED); |
355 } | 358 } |
356 | 359 |
357 source_positions.RemoveDecorator(); | 360 source_positions.RemoveDecorator(); |
358 | 361 |
359 Handle<Code> code = Handle<Code>::null(); | 362 Handle<Code> code = Handle<Code>::null(); |
360 { | 363 { |
361 // Compute a schedule. | 364 // Compute a schedule. |
362 Schedule* schedule = ComputeSchedule(&graph); | 365 Schedule* schedule = ComputeSchedule(&graph); |
363 // Generate optimized code. | 366 // Generate optimized code. |
364 PhaseStats codegen_stats(info(), PhaseStats::CODEGEN, "codegen"); | 367 PhaseStats codegen_stats(info(), PhaseStats::CODEGEN, "codegen"); |
(...skipping 24 matching lines...) Expand all Loading... |
389 if (VerifyGraphs()) ScheduleVerifier::Run(schedule); | 392 if (VerifyGraphs()) ScheduleVerifier::Run(schedule); |
390 return schedule; | 393 return schedule; |
391 } | 394 } |
392 | 395 |
393 | 396 |
394 Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage, | 397 Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage, |
395 Graph* graph, | 398 Graph* graph, |
396 Schedule* schedule) { | 399 Schedule* schedule) { |
397 CHECK(SupportedBackend()); | 400 CHECK(SupportedBackend()); |
398 if (schedule == NULL) { | 401 if (schedule == NULL) { |
399 VerifyAndPrintGraph(graph, "Machine"); | 402 VerifyAndPrintGraph(graph, "Machine", Verifier::UNTYPED); |
400 schedule = ComputeSchedule(graph); | 403 schedule = ComputeSchedule(graph); |
401 } | 404 } |
402 TraceSchedule(schedule); | 405 TraceSchedule(schedule); |
403 | 406 |
404 SourcePositionTable source_positions(graph); | 407 SourcePositionTable source_positions(graph); |
405 Handle<Code> code = GenerateCode(linkage, graph, schedule, &source_positions); | 408 Handle<Code> code = GenerateCode(linkage, graph, schedule, &source_positions); |
406 #if ENABLE_DISASSEMBLER | 409 #if ENABLE_DISASSEMBLER |
407 if (!code.is_null() && FLAG_print_opt_code) { | 410 if (!code.is_null() && FLAG_print_opt_code) { |
408 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); | 411 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); |
409 OFStream os(tracing_scope.file()); | 412 OFStream os(tracing_scope.file()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 } | 488 } |
486 | 489 |
487 | 490 |
488 void Pipeline::TearDown() { | 491 void Pipeline::TearDown() { |
489 InstructionOperand::TearDownCaches(); | 492 InstructionOperand::TearDownCaches(); |
490 } | 493 } |
491 | 494 |
492 } // namespace compiler | 495 } // namespace compiler |
493 } // namespace internal | 496 } // namespace internal |
494 } // namespace v8 | 497 } // namespace v8 |
OLD | NEW |