11cb0ef41Sopenharmony_ci// Copyright 2015 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/node-matchers.h" 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cinamespace v8 { 81cb0ef41Sopenharmony_cinamespace internal { 91cb0ef41Sopenharmony_cinamespace compiler { 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cibool NodeMatcher::IsComparison() const { 121cb0ef41Sopenharmony_ci return IrOpcode::IsComparisonOpcode(opcode()); 131cb0ef41Sopenharmony_ci} 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciBranchMatcher::BranchMatcher(Node* branch) 171cb0ef41Sopenharmony_ci : NodeMatcher(branch), if_true_(nullptr), if_false_(nullptr) { 181cb0ef41Sopenharmony_ci if (branch->opcode() != IrOpcode::kBranch) return; 191cb0ef41Sopenharmony_ci for (Node* use : branch->uses()) { 201cb0ef41Sopenharmony_ci if (use->opcode() == IrOpcode::kIfTrue) { 211cb0ef41Sopenharmony_ci DCHECK_NULL(if_true_); 221cb0ef41Sopenharmony_ci if_true_ = use; 231cb0ef41Sopenharmony_ci } else if (use->opcode() == IrOpcode::kIfFalse) { 241cb0ef41Sopenharmony_ci DCHECK_NULL(if_false_); 251cb0ef41Sopenharmony_ci if_false_ = use; 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciDiamondMatcher::DiamondMatcher(Node* merge) 321cb0ef41Sopenharmony_ci : NodeMatcher(merge), 331cb0ef41Sopenharmony_ci branch_(nullptr), 341cb0ef41Sopenharmony_ci if_true_(nullptr), 351cb0ef41Sopenharmony_ci if_false_(nullptr) { 361cb0ef41Sopenharmony_ci if (merge->InputCount() != 2) return; 371cb0ef41Sopenharmony_ci if (merge->opcode() != IrOpcode::kMerge) return; 381cb0ef41Sopenharmony_ci Node* input0 = merge->InputAt(0); 391cb0ef41Sopenharmony_ci if (input0->InputCount() != 1) return; 401cb0ef41Sopenharmony_ci Node* input1 = merge->InputAt(1); 411cb0ef41Sopenharmony_ci if (input1->InputCount() != 1) return; 421cb0ef41Sopenharmony_ci Node* branch = input0->InputAt(0); 431cb0ef41Sopenharmony_ci if (branch != input1->InputAt(0)) return; 441cb0ef41Sopenharmony_ci if (branch->opcode() != IrOpcode::kBranch) return; 451cb0ef41Sopenharmony_ci if (input0->opcode() == IrOpcode::kIfTrue && 461cb0ef41Sopenharmony_ci input1->opcode() == IrOpcode::kIfFalse) { 471cb0ef41Sopenharmony_ci branch_ = branch; 481cb0ef41Sopenharmony_ci if_true_ = input0; 491cb0ef41Sopenharmony_ci if_false_ = input1; 501cb0ef41Sopenharmony_ci } else if (input0->opcode() == IrOpcode::kIfFalse && 511cb0ef41Sopenharmony_ci input1->opcode() == IrOpcode::kIfTrue) { 521cb0ef41Sopenharmony_ci branch_ = branch; 531cb0ef41Sopenharmony_ci if_true_ = input1; 541cb0ef41Sopenharmony_ci if_false_ = input0; 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci} 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci} // namespace compiler 591cb0ef41Sopenharmony_ci} // namespace internal 601cb0ef41Sopenharmony_ci} // namespace v8 61