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
8
#include "
src/base/compiler-specific.h
"
9
#include "
src/compiler/control-path-state.h
"
10
#include "
src/compiler/graph-reducer.h
"
11
12
namespace
v8
{
13
namespace
internal
{
14
namespace
compiler {
15
16
// Forward declarations.
17
class
CommonOperatorBuilder;
18
class
JSGraph;
19
class
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.
23
struct
BranchCondition
{
24
BranchCondition
() : node(nullptr),
branch
(nullptr),
is_true
(false) {}
25
BranchCondition
(
Node
*
condition
,
Node
*
branch
,
bool
is_true
)
26
: node(
condition
),
branch
(
branch
),
is_true
(
is_true
) {}
27
Node
*
node
;
28
Node
*
branch
;
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
42
class
V8_EXPORT_PRIVATE
BranchElimination
final
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
{
49
kEARLY
,
50
kLATE
,
51
};
52
BranchElimination
(Editor* editor,
JSGraph
* js_graph,
Zone
* zone,
53
Phase
phase = kLATE);
54
~BranchElimination
() final;
55
56
const
char
* reducer_name()
const override
{
return
"BranchElimination"
; }
57
58
Reduction
Reduce(
Node
* node)
final
;
59
60
private
:
61
using
ControlPathConditions
=
62
ControlPathState<BranchCondition, kUniqueInstance>
;
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);
74
Reduction
UpdateStatesHelper
(
Node
* node,
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
90
JSGraph
*
const
jsgraph_
;
91
92
Node
*
dead_
;
93
Phase
phase_
;
94
};
95
96
}
// namespace compiler
97
}
// namespace internal
98
}
// namespace v8
99
100
#endif
// V8_COMPILER_BRANCH_ELIMINATION_H_
graph
TFGraph * graph
Definition
add-type-assertions-reducer.cc:21
v8::internal::Isolate
Definition
isolate.h:586
v8::internal::Zone
Definition
zone.h:43
v8::internal::compiler::BranchElimination
Definition
branch-elimination.h:44
v8::internal::compiler::BranchElimination::UpdateStatesHelper
Reduction UpdateStatesHelper(Node *node, ControlPathConditions prev_conditions, Node *current_condition, Node *current_branch, bool is_true_branch, bool in_new_block)
Definition
branch-elimination.h:74
v8::internal::compiler::BranchElimination::Phase
Phase
Definition
branch-elimination.h:48
v8::internal::compiler::BranchElimination::kEARLY
@ kEARLY
Definition
branch-elimination.h:49
v8::internal::compiler::BranchElimination::kLATE
@ kLATE
Definition
branch-elimination.h:50
v8::internal::compiler::BranchElimination::jsgraph_
JSGraph *const jsgraph_
Definition
branch-elimination.h:90
v8::internal::compiler::BranchElimination::dead
Node * dead() const
Definition
branch-elimination.h:84
v8::internal::compiler::BranchElimination::phase_
Phase phase_
Definition
branch-elimination.h:93
v8::internal::compiler::BranchElimination::jsgraph
JSGraph * jsgraph() const
Definition
branch-elimination.h:86
v8::internal::compiler::BranchElimination::dead_
Node * dead_
Definition
branch-elimination.h:92
v8::internal::compiler::BranchElimination::~BranchElimination
~BranchElimination() final
v8::internal::compiler::CommonOperatorBuilder
Definition
common-operator.h:543
v8::internal::compiler::ControlPathState
Definition
control-path-state.h:31
v8::internal::compiler::JSGraph
Definition
js-graph.h:27
v8::internal::compiler::Node
Definition
node.h:41
v8::internal::compiler::Reduction
Definition
graph-reducer.h:34
v8::internal::compiler::TFGraph
Definition
turbofan-graph.h:32
control-path-state.h
isolate
Isolate * isolate
Definition
graph-builder.cc:67
graph-reducer.h
condition
Node * condition
Definition
machine-operator-reducer.cc:2792
v8::internal::compiler::Phase
Phase
Definition
simplified-lowering.cc:61
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8
Definition
api-arguments-inl.h:19
compiler-specific.h
NON_EXPORTED_BASE
#define NON_EXPORTED_BASE(code)
Definition
compiler-specific.h:93
V8_EXPORT_PRIVATE
#define V8_EXPORT_PRIVATE
Definition
macros.h:460
v8::internal::compiler::BranchCondition
Definition
branch-elimination.h:23
v8::internal::compiler::BranchCondition::BranchCondition
BranchCondition(Node *condition, Node *branch, bool is_true)
Definition
branch-elimination.h:25
v8::internal::compiler::BranchCondition::branch
Node * branch
Definition
branch-elimination.h:28
v8::internal::compiler::BranchCondition::operator==
bool operator==(const BranchCondition &other) const
Definition
branch-elimination.h:31
v8::internal::compiler::BranchCondition::node
Node * node
Definition
branch-elimination.h:27
v8::internal::compiler::BranchCondition::BranchCondition
BranchCondition()
Definition
branch-elimination.h:24
v8::internal::compiler::BranchCondition::operator!=
bool operator!=(const BranchCondition &other) const
Definition
branch-elimination.h:35
v8::internal::compiler::BranchCondition::is_true
bool is_true
Definition
branch-elimination.h:29
v8::internal::compiler::BranchCondition::IsSet
bool IsSet()
Definition
branch-elimination.h:39
src
compiler
branch-elimination.h
Generated on Sun Apr 6 2025 21:08:51 for v8 by
1.12.0