select-lowering.cc 1.48 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/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 15 16 17

namespace v8 {
namespace internal {
namespace compiler {

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

21
SelectLowering::~SelectLowering() = default;
22 23 24

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

#define __ gasm()->

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

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

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

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

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

49
  if (reset_gasm) {
50
    gasm()->Reset();
51 52
  }

53
  return Changed(done.PhiAt(0));
54 55
}

56 57
#undef __

58 59 60
}  // namespace compiler
}  // namespace internal
}  // namespace v8