1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_BRANCH_ELIMINATION_H_
#define V8_COMPILER_BRANCH_ELIMINATION_H_
#include "src/base/compiler-specific.h"
#include "src/compiler/control-path-state.h"
#include "src/compiler/graph-reducer.h"
namespace v8 {
namespace internal {
namespace compiler {
// Forward declarations.
class CommonOperatorBuilder;
class JSGraph;
class SourcePositionTable;
// Represents a condition along with its value in the current control path.
// Also stores the node that branched on this condition.
struct BranchCondition {
BranchCondition() : node(nullptr), branch(nullptr), is_true(false) {}
BranchCondition(Node* condition, Node* branch, bool is_true)
: node(condition), branch(branch), is_true(is_true) {}
Node* node;
Node* branch;
bool is_true;
bool operator==(const BranchCondition& other) const {
return node == other.node && branch == other.branch &&
is_true == other.is_true;
}
bool operator!=(const BranchCondition& other) const {
return !(*this == other);
}
bool IsSet() { return node != nullptr; }
};
class V8_EXPORT_PRIVATE BranchElimination final
: public NON_EXPORTED_BASE(AdvancedReducerWithControlPathState)<
BranchCondition, kUniqueInstance> {
public:
// TODO(nicohartmann@): Remove {Phase} once all Branch operators have
// specified semantics.
enum Phase {
kEARLY,
kLATE,
};
BranchElimination(Editor* editor, JSGraph* js_graph, Zone* zone,
Phase phase = kLATE);
~BranchElimination() final;
const char* reducer_name() const override { return "BranchElimination"; }
Reduction Reduce(Node* node) final;
private:
using ControlPathConditions =
ControlPathState<BranchCondition, kUniqueInstance>;
Reduction ReduceBranch(Node* node);
Reduction ReduceDeoptimizeConditional(Node* node);
Reduction ReduceIf(Node* node, bool is_true_branch);
Reduction ReduceTrapConditional(Node* node);
Reduction ReduceLoop(Node* node);
Reduction ReduceMerge(Node* node);
Reduction ReduceStart(Node* node);
Reduction ReduceOtherControl(Node* node);
void SimplifyBranchCondition(Node* branch);
Reduction UpdateStatesHelper(Node* node,
ControlPathConditions prev_conditions,
Node* current_condition, Node* current_branch,
bool is_true_branch, bool in_new_block) {
return UpdateStates(
node, prev_conditions, current_condition,
BranchCondition(current_condition, current_branch, is_true_branch),
in_new_block);
}
Node* dead() const { return dead_; }
Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; }
Isolate* isolate() const;
CommonOperatorBuilder* common() const;
JSGraph* const jsgraph_;
Node* dead_;
Phase phase_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_BRANCH_ELIMINATION_H_
|