11cb0ef41Sopenharmony_ci// Copyright 2014 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci#include "src/compiler/select-lowering.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci#include "src/compiler/common-operator.h" 81cb0ef41Sopenharmony_ci#include "src/compiler/diamond.h" 91cb0ef41Sopenharmony_ci#include "src/compiler/graph-assembler.h" 101cb0ef41Sopenharmony_ci#include "src/compiler/graph.h" 111cb0ef41Sopenharmony_ci#include "src/compiler/node-properties.h" 121cb0ef41Sopenharmony_ci#include "src/compiler/node.h" 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cinamespace v8 { 151cb0ef41Sopenharmony_cinamespace internal { 161cb0ef41Sopenharmony_cinamespace compiler { 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ciSelectLowering::SelectLowering(JSGraphAssembler* graph_assembler, Graph* graph) 191cb0ef41Sopenharmony_ci : graph_assembler_(graph_assembler), start_(graph->start()) {} 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ciSelectLowering::~SelectLowering() = default; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciReduction SelectLowering::Reduce(Node* node) { 241cb0ef41Sopenharmony_ci if (node->opcode() != IrOpcode::kSelect) return NoChange(); 251cb0ef41Sopenharmony_ci return LowerSelect(node); 261cb0ef41Sopenharmony_ci} 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci#define __ gasm()-> 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciReduction SelectLowering::LowerSelect(Node* node) { 311cb0ef41Sopenharmony_ci SelectParameters const p = SelectParametersOf(node->op()); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci Node* condition = node->InputAt(0); 341cb0ef41Sopenharmony_ci Node* vtrue = node->InputAt(1); 351cb0ef41Sopenharmony_ci Node* vfalse = node->InputAt(2); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci bool reset_gasm = false; 381cb0ef41Sopenharmony_ci if (gasm()->control() == nullptr) { 391cb0ef41Sopenharmony_ci gasm()->InitializeEffectControl(start(), start()); 401cb0ef41Sopenharmony_ci reset_gasm = true; 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci auto done = __ MakeLabel(p.representation()); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci __ GotoIf(condition, &done, vtrue); 461cb0ef41Sopenharmony_ci __ Goto(&done, vfalse); 471cb0ef41Sopenharmony_ci __ Bind(&done); 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci if (reset_gasm) { 501cb0ef41Sopenharmony_ci gasm()->Reset(); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci return Changed(done.PhiAt(0)); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci#undef __ 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci} // namespace compiler 591cb0ef41Sopenharmony_ci} // namespace internal 601cb0ef41Sopenharmony_ci} // namespace v8 61