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.
5 #include "src/compiler/select-lowering.h"
7 #include "src/compiler/common-operator.h"
8 #include "src/compiler/diamond.h"
9 #include "src/compiler/generic-node-inl.h"
10 #include "src/compiler/graph.h"
16 SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common)
19 merges_(Merges::key_compare(), Merges::allocator_type(graph->zone())) {}
22 SelectLowering::~SelectLowering() {}
25 Reduction SelectLowering::Reduce(Node* node) {
26 if (node->opcode() != IrOpcode::kSelect) return NoChange();
27 SelectParameters const p = SelectParametersOf(node->op());
29 Node* const cond = node->InputAt(0);
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 Diamond d(graph(), common(), cond, p.hint());
36 i = merges_.insert(std::make_pair(cond, d.merge)).first;
39 DCHECK_EQ(cond, i->first);
41 // Create a Phi hanging off the previously determined merge.
42 node->set_op(common()->Phi(p.type(), 2));
43 node->ReplaceInput(0, node->InputAt(1));
44 node->ReplaceInput(1, node->InputAt(2));
45 node->ReplaceInput(2, i->second);
49 } // namespace compiler
50 } // namespace internal