OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "src/compiler/select-lowering.h" |
| 6 |
| 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/generic-node-inl.h" |
| 9 #include "src/compiler/graph.h" |
| 10 |
| 11 namespace v8 { |
| 12 namespace internal { |
| 13 namespace compiler { |
| 14 |
| 15 SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common) |
| 16 : common_(common), |
| 17 graph_(graph), |
| 18 merges_(Merges::key_compare(), Merges::allocator_type(graph->zone())) {} |
| 19 |
| 20 |
| 21 SelectLowering::~SelectLowering() {} |
| 22 |
| 23 |
| 24 Reduction SelectLowering::Reduce(Node* node) { |
| 25 if (node->opcode() != IrOpcode::kSelect) return NoChange(); |
| 26 SelectParameters const p = SelectParametersOf(node->op()); |
| 27 |
| 28 Node* const cond = node->InputAt(0); |
| 29 Node* const control = graph()->start(); |
| 30 |
| 31 // Check if we already have a diamond for this condition. |
| 32 auto i = merges_.find(cond); |
| 33 if (i == merges_.end()) { |
| 34 // Create a new diamond for this condition and remember its merge node. |
| 35 Node* branch = graph()->NewNode(common()->Branch(p.hint()), cond, control); |
| 36 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 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 } |
| 41 |
| 42 DCHECK_EQ(cond, i->first); |
| 43 |
| 44 // Create a Phi hanging off the previously determined merge. |
| 45 node->set_op(common()->Phi(p.type(), 2)); |
| 46 node->ReplaceInput(0, node->InputAt(1)); |
| 47 node->ReplaceInput(1, node->InputAt(2)); |
| 48 node->ReplaceInput(2, i->second); |
| 49 return Changed(node); |
| 50 } |
| 51 |
| 52 } // namespace compiler |
| 53 } // namespace internal |
| 54 } // namespace v8 |
OLD | NEW |