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/diamond.h"
9 #include "src/compiler/graph.h"
10 #include "src/compiler/node.h"
11 #include "src/compiler/node-properties.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace compiler {
16
SelectLowering(Graph * graph,CommonOperatorBuilder * common)17 SelectLowering::SelectLowering(Graph* graph, CommonOperatorBuilder* common)
18 : common_(common), graph_(graph) {}
19
~SelectLowering()20 SelectLowering::~SelectLowering() {}
21
22
Reduce(Node * node)23 Reduction SelectLowering::Reduce(Node* node) {
24 if (node->opcode() != IrOpcode::kSelect) return NoChange();
25 SelectParameters const p = SelectParametersOf(node->op());
26
27 Node* cond = node->InputAt(0);
28 Node* vthen = node->InputAt(1);
29 Node* velse = node->InputAt(2);
30
31 // Create a diamond and a phi.
32 Diamond d(graph(), common(), cond, p.hint());
33 node->ReplaceInput(0, vthen);
34 node->ReplaceInput(1, velse);
35 node->ReplaceInput(2, d.merge);
36 NodeProperties::ChangeOp(node, common()->Phi(p.representation(), 2));
37 return Changed(node);
38 }
39
40 } // namespace compiler
41 } // namespace internal
42 } // namespace v8
43