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

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

Issue 658543002: Better typing and type verification (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments 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/compiler/schedule.cc » ('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" 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
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, bool untyped) {
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
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,
149 FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED);
150 }
147 } 151 }
148 152
149 153
150 void Pipeline::PrintScheduleAndInstructions( 154 void Pipeline::PrintScheduleAndInstructions(
151 const char* phase, const Schedule* schedule, 155 const char* phase, const Schedule* schedule,
152 const SourcePositionTable* positions, 156 const SourcePositionTable* positions,
153 const InstructionSequence* instructions) { 157 const InstructionSequence* instructions) {
154 std::ofstream turbo_cfg_stream; 158 std::ofstream turbo_cfg_stream;
155 OpenTurboCfgFile(&turbo_cfg_stream); 159 OpenTurboCfgFile(&turbo_cfg_stream);
156 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions); 160 turbo_cfg_stream << AsC1V(phase, schedule, positions, instructions);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 PrintCompilationStart(); 228 PrintCompilationStart();
225 } 229 }
226 230
227 // Build the graph. 231 // Build the graph.
228 Graph graph(zone()); 232 Graph graph(zone());
229 SourcePositionTable source_positions(&graph); 233 SourcePositionTable source_positions(&graph);
230 source_positions.AddDecorator(); 234 source_positions.AddDecorator();
231 // TODO(turbofan): there is no need to type anything during initial graph 235 // 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 236 // construction. This is currently only needed for the node cache, which the
233 // typer could sweep over later. 237 // typer could sweep over later.
234 Typer typer(zone()); 238 Typer typer(&graph, info()->context());
235 MachineOperatorBuilder machine; 239 MachineOperatorBuilder machine;
236 CommonOperatorBuilder common(zone()); 240 CommonOperatorBuilder common(zone());
237 JSOperatorBuilder javascript(zone()); 241 JSOperatorBuilder javascript(zone());
238 JSGraph jsgraph(&graph, &common, &javascript, &typer, &machine); 242 JSGraph jsgraph(&graph, &common, &javascript, &machine);
239 Node* context_node; 243 Node* context_node;
240 { 244 {
241 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH, 245 PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH,
242 "graph builder"); 246 "graph builder");
243 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph, 247 AstGraphBuilderWithPositions graph_builder(info(), &jsgraph,
244 &source_positions); 248 &source_positions);
245 graph_builder.CreateGraph(); 249 graph_builder.CreateGraph();
246 context_node = graph_builder.GetFunctionContext(); 250 context_node = graph_builder.GetFunctionContext();
247 } 251 }
248 { 252 {
249 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH, 253 PhaseStats phi_reducer_stats(info(), PhaseStats::CREATE_GRAPH,
250 "phi reduction"); 254 "phi reduction");
251 PhiReducer phi_reducer; 255 PhiReducer phi_reducer;
252 GraphReducer graph_reducer(&graph); 256 GraphReducer graph_reducer(&graph);
253 graph_reducer.AddReducer(&phi_reducer); 257 graph_reducer.AddReducer(&phi_reducer);
254 graph_reducer.ReduceGraph(); 258 graph_reducer.ReduceGraph();
255 // TODO(mstarzinger): Running reducer once ought to be enough for everyone. 259 // TODO(mstarzinger): Running reducer once ought to be enough for everyone.
256 graph_reducer.ReduceGraph(); 260 graph_reducer.ReduceGraph();
257 graph_reducer.ReduceGraph(); 261 graph_reducer.ReduceGraph();
258 } 262 }
259 263
260 VerifyAndPrintGraph(&graph, "Initial untyped"); 264 VerifyAndPrintGraph(&graph, "Initial untyped", true);
261 265
262 if (info()->is_context_specializing()) { 266 if (info()->is_context_specializing()) {
263 SourcePositionTable::Scope pos(&source_positions, 267 SourcePositionTable::Scope pos(&source_positions,
264 SourcePosition::Unknown()); 268 SourcePosition::Unknown());
265 // Specialize the code to the context as aggressively as possible. 269 // Specialize the code to the context as aggressively as possible.
266 JSContextSpecializer spec(info(), &jsgraph, context_node); 270 JSContextSpecializer spec(info(), &jsgraph, context_node);
267 spec.SpecializeToContext(); 271 spec.SpecializeToContext();
268 VerifyAndPrintGraph(&graph, "Context specialized"); 272 VerifyAndPrintGraph(&graph, "Context specialized", true);
269 } 273 }
270 274
271 if (info()->is_inlining_enabled()) { 275 if (info()->is_inlining_enabled()) {
272 SourcePositionTable::Scope pos(&source_positions, 276 SourcePositionTable::Scope pos(&source_positions,
273 SourcePosition::Unknown()); 277 SourcePosition::Unknown());
274 JSInliner inliner(info(), &jsgraph); 278 JSInliner inliner(info(), &jsgraph);
275 inliner.Inline(); 279 inliner.Inline();
276 VerifyAndPrintGraph(&graph, "Inlined"); 280 VerifyAndPrintGraph(&graph, "Inlined", true);
277 } 281 }
278 282
279 // Print a replay of the initial graph. 283 // Print a replay of the initial graph.
280 if (FLAG_print_turbo_replay) { 284 if (FLAG_print_turbo_replay) {
281 GraphReplayPrinter::PrintReplay(&graph); 285 GraphReplayPrinter::PrintReplay(&graph);
282 } 286 }
283 287
284 // Bailout here in case target architecture is not supported. 288 // Bailout here in case target architecture is not supported.
285 if (!SupportedTarget()) return Handle<Code>::null(); 289 if (!SupportedTarget()) return Handle<Code>::null();
286 290
287 if (info()->is_typing_enabled()) { 291 if (info()->is_typing_enabled()) {
288 { 292 {
289 // Type the graph. 293 // Type the graph.
290 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer"); 294 PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer");
291 typer.Run(&graph, info()->context()); 295 typer.Run();
292 VerifyAndPrintGraph(&graph, "Typed"); 296 VerifyAndPrintGraph(&graph, "Typed");
293 } 297 }
294 // All new nodes must be typed.
295 typer.DecorateGraph(&graph);
296 { 298 {
297 // Lower JSOperators where we can determine types. 299 // Lower JSOperators where we can determine types.
298 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, 300 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH,
299 "typed lowering"); 301 "typed lowering");
300 SourcePositionTable::Scope pos(&source_positions, 302 SourcePositionTable::Scope pos(&source_positions,
301 SourcePosition::Unknown()); 303 SourcePosition::Unknown());
302 JSTypedLowering lowering(&jsgraph); 304 JSTypedLowering lowering(&jsgraph);
303 GraphReducer graph_reducer(&graph); 305 GraphReducer graph_reducer(&graph);
304 graph_reducer.AddReducer(&lowering); 306 graph_reducer.AddReducer(&lowering);
305 graph_reducer.ReduceGraph(); 307 graph_reducer.ReduceGraph();
(...skipping 23 matching lines...) Expand all
329 ChangeLowering lowering(&jsgraph, &linkage); 331 ChangeLowering lowering(&jsgraph, &linkage);
330 MachineOperatorReducer mach_reducer(&jsgraph); 332 MachineOperatorReducer mach_reducer(&jsgraph);
331 GraphReducer graph_reducer(&graph); 333 GraphReducer graph_reducer(&graph);
332 // TODO(titzer): Figure out if we should run all reducers at once here. 334 // TODO(titzer): Figure out if we should run all reducers at once here.
333 graph_reducer.AddReducer(&vn_reducer); 335 graph_reducer.AddReducer(&vn_reducer);
334 graph_reducer.AddReducer(&simple_reducer); 336 graph_reducer.AddReducer(&simple_reducer);
335 graph_reducer.AddReducer(&lowering); 337 graph_reducer.AddReducer(&lowering);
336 graph_reducer.AddReducer(&mach_reducer); 338 graph_reducer.AddReducer(&mach_reducer);
337 graph_reducer.ReduceGraph(); 339 graph_reducer.ReduceGraph();
338 340
339 VerifyAndPrintGraph(&graph, "Lowered changes"); 341 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works.
342 VerifyAndPrintGraph(&graph, "Lowered changes", true);
340 } 343 }
341 } 344 }
342 345
343 { 346 {
344 // Lower any remaining generic JSOperators. 347 // Lower any remaining generic JSOperators.
345 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH, 348 PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH,
346 "generic lowering"); 349 "generic lowering");
347 SourcePositionTable::Scope pos(&source_positions, 350 SourcePositionTable::Scope pos(&source_positions,
348 SourcePosition::Unknown()); 351 SourcePosition::Unknown());
349 JSGenericLowering lowering(info(), &jsgraph); 352 JSGenericLowering lowering(info(), &jsgraph);
350 GraphReducer graph_reducer(&graph); 353 GraphReducer graph_reducer(&graph);
351 graph_reducer.AddReducer(&lowering); 354 graph_reducer.AddReducer(&lowering);
352 graph_reducer.ReduceGraph(); 355 graph_reducer.ReduceGraph();
353 356
354 VerifyAndPrintGraph(&graph, "Lowered generic"); 357 // TODO(jarin, rossberg): Remove UNTYPED once machine typing works.
358 VerifyAndPrintGraph(&graph, "Lowered generic", true);
355 } 359 }
356 360
357 source_positions.RemoveDecorator(); 361 source_positions.RemoveDecorator();
358 362
359 Handle<Code> code = Handle<Code>::null(); 363 Handle<Code> code = Handle<Code>::null();
360 { 364 {
361 // Compute a schedule. 365 // Compute a schedule.
362 Schedule* schedule = ComputeSchedule(&graph); 366 Schedule* schedule = ComputeSchedule(&graph);
363 // Generate optimized code. 367 // Generate optimized code.
364 PhaseStats codegen_stats(info(), PhaseStats::CODEGEN, "codegen"); 368 PhaseStats codegen_stats(info(), PhaseStats::CODEGEN, "codegen");
(...skipping 24 matching lines...) Expand all
389 if (VerifyGraphs()) ScheduleVerifier::Run(schedule); 393 if (VerifyGraphs()) ScheduleVerifier::Run(schedule);
390 return schedule; 394 return schedule;
391 } 395 }
392 396
393 397
394 Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage, 398 Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage,
395 Graph* graph, 399 Graph* graph,
396 Schedule* schedule) { 400 Schedule* schedule) {
397 CHECK(SupportedBackend()); 401 CHECK(SupportedBackend());
398 if (schedule == NULL) { 402 if (schedule == NULL) {
399 VerifyAndPrintGraph(graph, "Machine"); 403 // TODO(rossberg): Should this really be untyped?
404 VerifyAndPrintGraph(graph, "Machine", true);
400 schedule = ComputeSchedule(graph); 405 schedule = ComputeSchedule(graph);
401 } 406 }
402 TraceSchedule(schedule); 407 TraceSchedule(schedule);
403 408
404 SourcePositionTable source_positions(graph); 409 SourcePositionTable source_positions(graph);
405 Handle<Code> code = GenerateCode(linkage, graph, schedule, &source_positions); 410 Handle<Code> code = GenerateCode(linkage, graph, schedule, &source_positions);
406 #if ENABLE_DISASSEMBLER 411 #if ENABLE_DISASSEMBLER
407 if (!code.is_null() && FLAG_print_opt_code) { 412 if (!code.is_null() && FLAG_print_opt_code) {
408 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer()); 413 CodeTracer::Scope tracing_scope(isolate()->GetCodeTracer());
409 OFStream os(tracing_scope.file()); 414 OFStream os(tracing_scope.file());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 } 490 }
486 491
487 492
488 void Pipeline::TearDown() { 493 void Pipeline::TearDown() {
489 InstructionOperand::TearDownCaches(); 494 InstructionOperand::TearDownCaches();
490 } 495 }
491 496
492 } // namespace compiler 497 } // namespace compiler
493 } // namespace internal 498 } // namespace internal
494 } // namespace v8 499 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/pipeline.h ('k') | src/compiler/schedule.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698