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

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

Issue 1193833002: [turbofan] Proper dead code elimination as regular reducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Renamed DeadControl to Dead. Created 5 years, 6 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
« no previous file with comments | « src/compiler/operator-properties.cc ('k') | src/compiler/pipeline.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.h" 5 #include "src/compiler.h"
6 #include "src/compiler/all-nodes.h" 6 #include "src/compiler/all-nodes.h"
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/control-reducer.h" 8 #include "src/compiler/common-operator-reducer.h"
9 #include "src/compiler/dead-code-elimination.h"
9 #include "src/compiler/frame.h" 10 #include "src/compiler/frame.h"
10 #include "src/compiler/graph.h" 11 #include "src/compiler/graph.h"
12 #include "src/compiler/graph-reducer.h"
11 #include "src/compiler/graph-trimmer.h" 13 #include "src/compiler/graph-trimmer.h"
12 #include "src/compiler/graph-visualizer.h" 14 #include "src/compiler/graph-visualizer.h"
13 #include "src/compiler/js-graph.h" 15 #include "src/compiler/js-graph.h"
14 #include "src/compiler/loop-analysis.h" 16 #include "src/compiler/loop-analysis.h"
15 #include "src/compiler/node.h" 17 #include "src/compiler/node.h"
16 #include "src/compiler/node-marker.h" 18 #include "src/compiler/node-marker.h"
17 #include "src/compiler/osr.h" 19 #include "src/compiler/osr.h"
18 #include "src/scopes.h" 20 #include "src/scopes.h"
19 21
20 namespace v8 { 22 namespace v8 {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 312 }
311 313
312 CHECK(osr_loop); // Should have found the OSR loop. 314 CHECK(osr_loop); // Should have found the OSR loop.
313 315
314 // Transfer the types from loop phis to the OSR values which flow into them. 316 // Transfer the types from loop phis to the OSR values which flow into them.
315 TransferOsrValueTypesFromLoopPhis(graph->zone(), osr_loop_entry, osr_loop); 317 TransferOsrValueTypesFromLoopPhis(graph->zone(), osr_loop_entry, osr_loop);
316 318
317 // Analyze the graph to determine how deeply nested the OSR loop is. 319 // Analyze the graph to determine how deeply nested the OSR loop is.
318 LoopTree* loop_tree = LoopFinder::BuildLoopTree(graph, tmp_zone); 320 LoopTree* loop_tree = LoopFinder::BuildLoopTree(graph, tmp_zone);
319 321
320 Node* dead = jsgraph->DeadControl(); 322 Node* dead = jsgraph->Dead();
321 LoopTree::Loop* loop = loop_tree->ContainingLoop(osr_loop); 323 LoopTree::Loop* loop = loop_tree->ContainingLoop(osr_loop);
322 if (loop->depth() > 0) { 324 if (loop->depth() > 0) {
323 PeelOuterLoopsForOsr(graph, common, tmp_zone, dead, loop_tree, loop, 325 PeelOuterLoopsForOsr(graph, common, tmp_zone, dead, loop_tree, loop,
324 osr_normal_entry, osr_loop_entry); 326 osr_normal_entry, osr_loop_entry);
325 } 327 }
326 328
327 // Replace the normal entry with {Dead} and the loop entry with {Start} 329 // Replace the normal entry with {Dead} and the loop entry with {Start}
328 // and run the control reducer to clean up the graph. 330 // and run the control reducer to clean up the graph.
329 osr_normal_entry->ReplaceUses(dead); 331 osr_normal_entry->ReplaceUses(dead);
330 osr_normal_entry->Kill(); 332 osr_normal_entry->Kill();
331 osr_loop_entry->ReplaceUses(graph->start()); 333 osr_loop_entry->ReplaceUses(graph->start());
332 osr_loop_entry->Kill(); 334 osr_loop_entry->Kill();
333 335
334 // Normally the control reducer removes loops whose first input is dead, 336 // Remove the first input to the {osr_loop}.
335 // but we need to avoid that because the osr_loop is reachable through 337 int const live_input_count = osr_loop->InputCount() - 1;
336 // the second input, so reduce it and its phis manually. 338 CHECK_NE(0, live_input_count);
337 osr_loop->ReplaceInput(0, dead); 339 for (Node* const use : osr_loop->uses()) {
338 Node* node = ControlReducer::ReduceMerge(jsgraph, osr_loop); 340 if (NodeProperties::IsPhi(use)) {
339 if (node != osr_loop) osr_loop->ReplaceUses(node); 341 use->set_op(common->ResizeMergeOrPhi(use->op(), live_input_count));
342 use->RemoveInput(0);
343 }
344 }
345 osr_loop->set_op(common->ResizeMergeOrPhi(osr_loop->op(), live_input_count));
346 osr_loop->RemoveInput(0);
340 347
341 // Run control reduction and graph trimming. 348 // Run control reduction and graph trimming.
342 ControlReducer::ReduceGraph(tmp_zone, jsgraph); 349 // TODO(bmeurer): The OSR deconstruction could be a regular reducer and play
343 GraphTrimmer trimmer(tmp_zone, jsgraph->graph()); 350 // nice together with the rest, instead of having this custom stuff here.
351 GraphReducer graph_reducer(tmp_zone, graph);
352 DeadCodeElimination dce(&graph_reducer, graph, common);
353 CommonOperatorReducer cor(&graph_reducer, graph, common, jsgraph->machine());
354 graph_reducer.AddReducer(&dce);
355 graph_reducer.AddReducer(&cor);
356 graph_reducer.ReduceGraph();
357 GraphTrimmer trimmer(tmp_zone, graph);
344 NodeVector roots(tmp_zone); 358 NodeVector roots(tmp_zone);
345 jsgraph->GetCachedNodes(&roots); 359 jsgraph->GetCachedNodes(&roots);
346 trimmer.TrimGraph(roots.begin(), roots.end()); 360 trimmer.TrimGraph(roots.begin(), roots.end());
347 } 361 }
348 362
349 363
350 void OsrHelper::SetupFrame(Frame* frame) { 364 void OsrHelper::SetupFrame(Frame* frame) {
351 // The optimized frame will subsume the unoptimized frame. Do so by reserving 365 // The optimized frame will subsume the unoptimized frame. Do so by reserving
352 // the first spill slots. 366 // the first spill slots.
353 frame->ReserveSpillSlots(UnoptimizedFrameSlots()); 367 frame->ReserveSpillSlots(UnoptimizedFrameSlots());
354 // The frame needs to be adjusted by the number of unoptimized frame slots. 368 // The frame needs to be adjusted by the number of unoptimized frame slots.
355 frame->SetOsrStackSlotCount(static_cast<int>(UnoptimizedFrameSlots())); 369 frame->SetOsrStackSlotCount(static_cast<int>(UnoptimizedFrameSlots()));
356 } 370 }
357 371
358 } // namespace compiler 372 } // namespace compiler
359 } // namespace internal 373 } // namespace internal
360 } // namespace v8 374 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/operator-properties.cc ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698