v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
dead-code-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_DEAD_CODE_ELIMINATION_H_
6
#define V8_COMPILER_DEAD_CODE_ELIMINATION_H_
7
8
#include "
src/base/compiler-specific.h
"
9
#include "
src/codegen/machine-type.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
19
// Propagates {Dead} control and {DeadValue} values through the graph and
20
// thereby removes dead code.
21
// We detect dead values based on types, replacing uses of nodes with
22
// {Type::None()} with {DeadValue}. A pure node (other than a phi) using
23
// {DeadValue} is replaced by {DeadValue}. When {DeadValue} hits the effect
24
// chain, a crashing {Unreachable} node is inserted and the rest of the effect
25
// chain is collapsed. We wait for the {EffectControlLinearizer} to connect
26
// {Unreachable} nodes to the graph end, since this is much easier if there is
27
// no floating control.
28
// {DeadValue} has an input, which has to have {Type::None()}. This input is
29
// important to maintain the dependency on the cause of the unreachable code.
30
// {Unreachable} has a value output and {Type::None()} so it can be used by
31
// {DeadValue}.
32
// {DeadValue} nodes track a {MachineRepresentation} so they can be lowered to a
33
// value-producing node. {DeadValue} has the runtime semantics of crashing and
34
// behaves like a constant of its representation so it can be used in gap moves.
35
// Since phi nodes are the only remaining use of {DeadValue}, this
36
// representation is only adjusted for uses by phi nodes.
37
// In contrast to {DeadValue}, {Dead} can never remain in the graph.
38
class
V8_EXPORT_PRIVATE
DeadCodeElimination
final
39
:
public
NON_EXPORTED_BASE
(AdvancedReducer) {
40
public
:
41
DeadCodeElimination
(Editor* editor,
TFGraph
* graph,
42
CommonOperatorBuilder
* common,
Zone
* temp_zone);
43
~DeadCodeElimination
() final = default;
44
DeadCodeElimination
(const
DeadCodeElimination
&) = delete;
45
DeadCodeElimination
& operator=(const
DeadCodeElimination
&) = delete;
46
47
const
char
* reducer_name()
const override
{
return
"DeadCodeElimination"
; }
48
49
Reduction
Reduce(
Node
* node)
final
;
50
51
private
:
52
Reduction
ReduceEnd(
Node
* node);
53
Reduction
ReduceLoopOrMerge(
Node
* node);
54
Reduction
ReduceLoopExit(
Node
* node);
55
Reduction
ReduceNode(
Node
* node);
56
Reduction
ReducePhi(
Node
* node);
57
Reduction
ReduceEffectPhi(
Node
* node);
58
Reduction
ReducePureNode(
Node
* node);
59
Reduction
ReduceUnreachableOrIfException(
Node
* node);
60
Reduction
ReduceEffectNode(
Node
* node);
61
Reduction
ReduceDeoptimizeOrReturnOrTerminateOrTailCall(
Node
* node);
62
Reduction
ReduceBranchOrSwitch(
Node
* node);
63
64
Reduction
RemoveLoopExit(
Node
* node);
65
Reduction
PropagateDeadControl(
Node
* node);
66
67
void
TrimMergeOrPhi(
Node
* node,
int
size);
68
69
Node
* DeadValue(
Node
* none_node,
70
MachineRepresentation
rep = MachineRepresentation::kNone);
71
72
TFGraph
*
graph
()
const
{
return
graph_
; }
73
CommonOperatorBuilder
*
common
()
const
{
return
common_; }
74
Node
*
dead
()
const
{
return
dead_; }
75
76
TFGraph
*
const
graph_
;
77
CommonOperatorBuilder
*
const
common_
;
78
Node
*
const
dead_
;
79
Zone
*
zone_
;
80
};
81
82
}
// namespace compiler
83
}
// namespace internal
84
}
// namespace v8
85
86
#endif
// V8_COMPILER_DEAD_CODE_ELIMINATION_H_
v8::internal::Zone
Definition
zone.h:43
v8::internal::compiler::CommonOperatorBuilder
Definition
common-operator.h:543
v8::internal::compiler::DeadCodeElimination
Definition
dead-code-elimination.h:39
v8::internal::compiler::DeadCodeElimination::common_
CommonOperatorBuilder *const common_
Definition
dead-code-elimination.h:77
v8::internal::compiler::DeadCodeElimination::zone_
Zone * zone_
Definition
dead-code-elimination.h:79
v8::internal::compiler::DeadCodeElimination::graph_
TFGraph *const graph_
Definition
dead-code-elimination.h:76
v8::internal::compiler::DeadCodeElimination::dead
Node * dead() const
Definition
dead-code-elimination.h:74
v8::internal::compiler::DeadCodeElimination::common
CommonOperatorBuilder * common() const
Definition
dead-code-elimination.h:73
v8::internal::compiler::DeadCodeElimination::dead_
Node *const dead_
Definition
dead-code-elimination.h:78
v8::internal::compiler::DeadCodeElimination::graph
TFGraph * graph() const
Definition
dead-code-elimination.h:72
v8::internal::compiler::DeadCodeElimination::~DeadCodeElimination
~DeadCodeElimination() final=default
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
graph-reducer.h
machine-type.h
v8::internal::internal
internal
Definition
wasm-objects-inl.h:458
v8::internal::MachineRepresentation
MachineRepresentation
Definition
machine-type.h:19
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
graph_
TFGraph * graph_
Definition
wasm-inlining-into-js.cc:372
src
compiler
dead-code-elimination.h
Generated on Sun Apr 6 2025 21:08:51 for v8 by
1.12.0