• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-assembler.h"
10 #include "src/compiler/graph.h"
11 #include "src/compiler/node-properties.h"
12 #include "src/compiler/node.h"
13 
14 namespace v8 {
15 namespace internal {
16 namespace compiler {
17 
SelectLowering(JSGraphAssembler * graph_assembler,Graph * graph)18 SelectLowering::SelectLowering(JSGraphAssembler* graph_assembler, Graph* graph)
19     : graph_assembler_(graph_assembler), start_(graph->start()) {}
20 
21 SelectLowering::~SelectLowering() = default;
22 
Reduce(Node * node)23 Reduction SelectLowering::Reduce(Node* node) {
24   if (node->opcode() != IrOpcode::kSelect) return NoChange();
25   return LowerSelect(node);
26 }
27 
28 #define __ gasm()->
29 
LowerSelect(Node * node)30 Reduction SelectLowering::LowerSelect(Node* node) {
31   SelectParameters const p = SelectParametersOf(node->op());
32 
33   Node* condition = node->InputAt(0);
34   Node* vtrue = node->InputAt(1);
35   Node* vfalse = node->InputAt(2);
36 
37   bool reset_gasm = false;
38   if (gasm()->control() == nullptr) {
39     gasm()->InitializeEffectControl(start(), start());
40     reset_gasm = true;
41   }
42 
43   auto done = __ MakeLabel(p.representation());
44 
45   __ GotoIf(condition, &done, vtrue);
46   __ Goto(&done, vfalse);
47   __ Bind(&done);
48 
49   if (reset_gasm) {
50     gasm()->Reset();
51   }
52 
53   return Changed(done.PhiAt(0));
54 }
55 
56 #undef __
57 
58 }  // namespace compiler
59 }  // namespace internal
60 }  // namespace v8
61