v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
branch-elimination.h
Go to the documentation of this file.
1// Copyright 2015 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_BRANCH_ELIMINATION_H_
6#define V8_COMPILER_BRANCH_ELIMINATION_H_
7
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16// Forward declarations.
17class CommonOperatorBuilder;
18class JSGraph;
19class SourcePositionTable;
20
21// Represents a condition along with its value in the current control path.
22// Also stores the node that branched on this condition.
24 BranchCondition() : node(nullptr), branch(nullptr), is_true(false) {}
29 bool is_true;
30
31 bool operator==(const BranchCondition& other) const {
32 return node == other.node && branch == other.branch &&
33 is_true == other.is_true;
34 }
35 bool operator!=(const BranchCondition& other) const {
36 return !(*this == other);
37 }
38
39 bool IsSet() { return node != nullptr; }
40};
41
43 : public NON_EXPORTED_BASE(AdvancedReducerWithControlPathState)<
44 BranchCondition, kUniqueInstance> {
45 public:
46 // TODO(nicohartmann@): Remove {Phase} once all Branch operators have
47 // specified semantics.
48 enum Phase {
51 };
52 BranchElimination(Editor* editor, JSGraph* js_graph, Zone* zone,
53 Phase phase = kLATE);
55
56 const char* reducer_name() const override { return "BranchElimination"; }
57
58 Reduction Reduce(Node* node) final;
59
60 private:
63
64 Reduction ReduceBranch(Node* node);
65 Reduction ReduceDeoptimizeConditional(Node* node);
66 Reduction ReduceIf(Node* node, bool is_true_branch);
67 Reduction ReduceTrapConditional(Node* node);
68 Reduction ReduceLoop(Node* node);
69 Reduction ReduceMerge(Node* node);
70 Reduction ReduceStart(Node* node);
71 Reduction ReduceOtherControl(Node* node);
72 void SimplifyBranchCondition(Node* branch);
73 bool TryEliminateBranchWithPhiCondition(Node* branch, Node* phi, Node* merge);
75 ControlPathConditions prev_conditions,
76 Node* current_condition, Node* current_branch,
77 bool is_true_branch, bool in_new_block) {
78 return UpdateStates(
79 node, prev_conditions, current_condition,
80 BranchCondition(current_condition, current_branch, is_true_branch),
81 in_new_block);
82 }
83
84 Node* dead() const { return dead_; }
85 TFGraph* graph() const;
86 JSGraph* jsgraph() const { return jsgraph_; }
87 Isolate* isolate() const;
88 CommonOperatorBuilder* common() const;
89
91
94};
95
96} // namespace compiler
97} // namespace internal
98} // namespace v8
99
100#endif // V8_COMPILER_BRANCH_ELIMINATION_H_
TFGraph * graph
Reduction UpdateStatesHelper(Node *node, ControlPathConditions prev_conditions, Node *current_condition, Node *current_branch, bool is_true_branch, bool in_new_block)
Isolate * isolate
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
BranchCondition(Node *condition, Node *branch, bool is_true)
bool operator==(const BranchCondition &other) const
bool operator!=(const BranchCondition &other) const