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

Side by Side Diff: src/compiler/select-lowering.cc

Issue 694063005: Introduce Diamond, a helper for building diamond-shaped control patterns. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: newline Created 6 years, 1 month 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/machine-operator-reducer.cc ('k') | src/compiler/simplified-lowering.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/select-lowering.h" 5 #include "src/compiler/select-lowering.h"
6 6
7 #include "src/compiler/common-operator.h" 7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/diamond.h"
8 #include "src/compiler/generic-node-inl.h" 9 #include "src/compiler/generic-node-inl.h"
9 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
10 11
11 namespace v8 { 12 namespace v8 {
12 namespace internal { 13 namespace internal {
13 namespace compiler { 14 namespace compiler {
14 15
15 SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common) 16 SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common)
16 : common_(common), 17 : common_(common),
17 graph_(graph), 18 graph_(graph),
18 merges_(Merges::key_compare(), Merges::allocator_type(graph->zone())) {} 19 merges_(Merges::key_compare(), Merges::allocator_type(graph->zone())) {}
19 20
20 21
21 SelectLowering::~SelectLowering() {} 22 SelectLowering::~SelectLowering() {}
22 23
23 24
24 Reduction SelectLowering::Reduce(Node* node) { 25 Reduction SelectLowering::Reduce(Node* node) {
25 if (node->opcode() != IrOpcode::kSelect) return NoChange(); 26 if (node->opcode() != IrOpcode::kSelect) return NoChange();
26 SelectParameters const p = SelectParametersOf(node->op()); 27 SelectParameters const p = SelectParametersOf(node->op());
27 28
28 Node* const cond = node->InputAt(0); 29 Node* const cond = node->InputAt(0);
29 Node* const control = graph()->start();
30 30
31 // Check if we already have a diamond for this condition. 31 // Check if we already have a diamond for this condition.
32 auto i = merges_.find(cond); 32 auto i = merges_.find(cond);
33 if (i == merges_.end()) { 33 if (i == merges_.end()) {
34 // Create a new diamond for this condition and remember its merge node. 34 // Create a new diamond for this condition and remember its merge node.
35 Node* branch = graph()->NewNode(common()->Branch(p.hint()), cond, control); 35 Diamond d(graph(), common(), cond);
36 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); 36 i = merges_.insert(std::make_pair(cond, d.merge)).first;
37 Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
38 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
39 i = merges_.insert(std::make_pair(cond, merge)).first;
40 } 37 }
41 38
42 DCHECK_EQ(cond, i->first); 39 DCHECK_EQ(cond, i->first);
43 40
44 // Create a Phi hanging off the previously determined merge. 41 // Create a Phi hanging off the previously determined merge.
45 node->set_op(common()->Phi(p.type(), 2)); 42 node->set_op(common()->Phi(p.type(), 2));
46 node->ReplaceInput(0, node->InputAt(1)); 43 node->ReplaceInput(0, node->InputAt(1));
47 node->ReplaceInput(1, node->InputAt(2)); 44 node->ReplaceInput(1, node->InputAt(2));
48 node->ReplaceInput(2, i->second); 45 node->ReplaceInput(2, i->second);
49 return Changed(node); 46 return Changed(node);
50 } 47 }
51 48
52 } // namespace compiler 49 } // namespace compiler
53 } // namespace internal 50 } // namespace internal
54 } // namespace v8 51 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698