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
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16// Forward declarations.
17class 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.
39 : public NON_EXPORTED_BASE(AdvancedReducer) {
40 public:
41 DeadCodeElimination(Editor* editor, TFGraph* graph,
42 CommonOperatorBuilder* common, Zone* temp_zone);
43 ~DeadCodeElimination() final = default;
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
78 Node* const dead_;
80};
81
82} // namespace compiler
83} // namespace internal
84} // namespace v8
85
86#endif // V8_COMPILER_DEAD_CODE_ELIMINATION_H_
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
TFGraph * graph_