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#ifndef V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
61cb0ef41Sopenharmony_ci#define V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci#include "src/base/compiler-specific.h"
91cb0ef41Sopenharmony_ci#include "src/common/globals.h"
101cb0ef41Sopenharmony_ci#include "src/compiler/common-operator.h"
111cb0ef41Sopenharmony_ci#include "src/compiler/graph-reducer.h"
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cinamespace v8 {
141cb0ef41Sopenharmony_cinamespace internal {
151cb0ef41Sopenharmony_cinamespace compiler {
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Forward declarations.
181cb0ef41Sopenharmony_ciclass CommonOperatorBuilder;
191cb0ef41Sopenharmony_ciclass Graph;
201cb0ef41Sopenharmony_ciclass MachineOperatorBuilder;
211cb0ef41Sopenharmony_ciclass Operator;
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// Performs strength reduction on nodes that have common operators.
251cb0ef41Sopenharmony_ciclass V8_EXPORT_PRIVATE CommonOperatorReducer final
261cb0ef41Sopenharmony_ci    : public NON_EXPORTED_BASE(AdvancedReducer) {
271cb0ef41Sopenharmony_ci public:
281cb0ef41Sopenharmony_ci  CommonOperatorReducer(Editor* editor, Graph* graph, JSHeapBroker* broker,
291cb0ef41Sopenharmony_ci                        CommonOperatorBuilder* common,
301cb0ef41Sopenharmony_ci                        MachineOperatorBuilder* machine, Zone* temp_zone,
311cb0ef41Sopenharmony_ci                        BranchSemantics branch_semantics);
321cb0ef41Sopenharmony_ci  ~CommonOperatorReducer() final = default;
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  const char* reducer_name() const override { return "CommonOperatorReducer"; }
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci  Reduction Reduce(Node* node) final;
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci private:
391cb0ef41Sopenharmony_ci  Reduction ReduceBranch(Node* node);
401cb0ef41Sopenharmony_ci  Reduction ReduceDeoptimizeConditional(Node* node);
411cb0ef41Sopenharmony_ci  Reduction ReduceMerge(Node* node);
421cb0ef41Sopenharmony_ci  Reduction ReduceEffectPhi(Node* node);
431cb0ef41Sopenharmony_ci  Reduction ReducePhi(Node* node);
441cb0ef41Sopenharmony_ci  Reduction ReduceReturn(Node* node);
451cb0ef41Sopenharmony_ci  Reduction ReduceSelect(Node* node);
461cb0ef41Sopenharmony_ci  Reduction ReduceSwitch(Node* node);
471cb0ef41Sopenharmony_ci  Reduction ReduceStaticAssert(Node* node);
481cb0ef41Sopenharmony_ci  Reduction ReduceTrapConditional(Node* node);
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ci  Reduction Change(Node* node, Operator const* op, Node* a);
511cb0ef41Sopenharmony_ci  Reduction Change(Node* node, Operator const* op, Node* a, Node* b);
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  // Helper to determine if conditions are true or false.
541cb0ef41Sopenharmony_ci  Decision DecideCondition(Node* const cond);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci  Graph* graph() const { return graph_; }
571cb0ef41Sopenharmony_ci  JSHeapBroker* broker() const { return broker_; }
581cb0ef41Sopenharmony_ci  CommonOperatorBuilder* common() const { return common_; }
591cb0ef41Sopenharmony_ci  MachineOperatorBuilder* machine() const { return machine_; }
601cb0ef41Sopenharmony_ci  Node* dead() const { return dead_; }
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci  Graph* const graph_;
631cb0ef41Sopenharmony_ci  JSHeapBroker* const broker_;
641cb0ef41Sopenharmony_ci  CommonOperatorBuilder* const common_;
651cb0ef41Sopenharmony_ci  MachineOperatorBuilder* const machine_;
661cb0ef41Sopenharmony_ci  Node* const dead_;
671cb0ef41Sopenharmony_ci  Zone* zone_;
681cb0ef41Sopenharmony_ci  BranchSemantics branch_semantics_;
691cb0ef41Sopenharmony_ci};
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci}  // namespace compiler
721cb0ef41Sopenharmony_ci}  // namespace internal
731cb0ef41Sopenharmony_ci}  // namespace v8
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci#endif  // V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
76