1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
6#define V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
7
8#include "src/base/compiler-specific.h"
9#include "src/common/globals.h"
10#include "src/compiler/common-operator.h"
11#include "src/compiler/graph-reducer.h"
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17// Forward declarations.
18class CommonOperatorBuilder;
19class Graph;
20class MachineOperatorBuilder;
21class Operator;
22
23
24// Performs strength reduction on nodes that have common operators.
25class V8_EXPORT_PRIVATE CommonOperatorReducer final
26    : public NON_EXPORTED_BASE(AdvancedReducer) {
27 public:
28  CommonOperatorReducer(Editor* editor, Graph* graph, JSHeapBroker* broker,
29                        CommonOperatorBuilder* common,
30                        MachineOperatorBuilder* machine, Zone* temp_zone,
31                        BranchSemantics branch_semantics);
32  ~CommonOperatorReducer() final = default;
33
34  const char* reducer_name() const override { return "CommonOperatorReducer"; }
35
36  Reduction Reduce(Node* node) final;
37
38 private:
39  Reduction ReduceBranch(Node* node);
40  Reduction ReduceDeoptimizeConditional(Node* node);
41  Reduction ReduceMerge(Node* node);
42  Reduction ReduceEffectPhi(Node* node);
43  Reduction ReducePhi(Node* node);
44  Reduction ReduceReturn(Node* node);
45  Reduction ReduceSelect(Node* node);
46  Reduction ReduceSwitch(Node* node);
47  Reduction ReduceStaticAssert(Node* node);
48  Reduction ReduceTrapConditional(Node* node);
49
50  Reduction Change(Node* node, Operator const* op, Node* a);
51  Reduction Change(Node* node, Operator const* op, Node* a, Node* b);
52
53  // Helper to determine if conditions are true or false.
54  Decision DecideCondition(Node* const cond);
55
56  Graph* graph() const { return graph_; }
57  JSHeapBroker* broker() const { return broker_; }
58  CommonOperatorBuilder* common() const { return common_; }
59  MachineOperatorBuilder* machine() const { return machine_; }
60  Node* dead() const { return dead_; }
61
62  Graph* const graph_;
63  JSHeapBroker* const broker_;
64  CommonOperatorBuilder* const common_;
65  MachineOperatorBuilder* const machine_;
66  Node* const dead_;
67  Zone* zone_;
68  BranchSemantics branch_semantics_;
69};
70
71}  // namespace compiler
72}  // namespace internal
73}  // namespace v8
74
75#endif  // V8_COMPILER_COMMON_OPERATOR_REDUCER_H_
76