select-lowering.cc 1.4 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/select-lowering.h"

#include "src/compiler/common-operator.h"
8
#include "src/compiler/graph-assembler.h"
9
#include "src/compiler/graph.h"
10
#include "src/compiler/node.h"
11 12 13 14 15

namespace v8 {
namespace internal {
namespace compiler {

16
SelectLowering::SelectLowering(JSGraphAssembler* graph_assembler, Graph* graph)
17
    : graph_assembler_(graph_assembler), start_(graph->start()) {}
18

19
SelectLowering::~SelectLowering() = default;
20 21 22

Reduction SelectLowering::Reduce(Node* node) {
  if (node->opcode() != IrOpcode::kSelect) return NoChange();
23
  return LowerSelect(node);
24 25 26 27
}

#define __ gasm()->

28
Reduction SelectLowering::LowerSelect(Node* node) {
29 30
  SelectParameters const p = SelectParametersOf(node->op());

31 32 33 34
  Node* condition = node->InputAt(0);
  Node* vtrue = node->InputAt(1);
  Node* vfalse = node->InputAt(2);

35 36 37 38 39
  bool reset_gasm = false;
  if (gasm()->control() == nullptr) {
    gasm()->InitializeEffectControl(start(), start());
    reset_gasm = true;
  }
40 41 42 43 44 45 46

  auto done = __ MakeLabel(p.representation());

  __ GotoIf(condition, &done, vtrue);
  __ Goto(&done, vfalse);
  __ Bind(&done);

47
  if (reset_gasm) {
48
    gasm()->Reset();
49 50
  }

51
  return Changed(done.PhiAt(0));
52 53
}

54 55
#undef __

56 57 58
}  // namespace compiler
}  // namespace internal
}  // namespace v8