v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
escape-analysis-reducer.h
Go to the documentation of this file.
1// Copyright 2017 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_ESCAPE_ANALYSIS_REDUCER_H_
6#define V8_COMPILER_ESCAPE_ANALYSIS_REDUCER_H_
7
12
13namespace v8 {
14namespace internal {
15namespace compiler {
16
17class Deduplicator;
18class JSGraph;
19
20// Perform hash-consing when creating or mutating nodes. Used to avoid duplicate
21// nodes when creating ObjectState, StateValues and FrameState nodes
23 public:
24 NodeHashCache(TFGraph* graph, Zone* zone)
25 : graph_(graph), cache_(zone), temp_nodes_(zone) {}
26
27 // Handle to a conceptually new mutable node. Tries to reuse existing nodes
28 // and to recycle memory if possible.
30 public:
31 // Construct a new node as a clone of [from].
33 : node_cache_(cache), from_(from), tmp_(nullptr) {}
34 // Construct a new node from scratch.
35 Constructor(NodeHashCache* cache, const Operator* op, int input_count,
36 Node** inputs, Type type);
37
38 // Modify the new node.
39 void ReplaceValueInput(Node* input, int i) {
40 if (!tmp_ && input == NodeProperties::GetValueInput(from_, i)) return;
41 Node* node = MutableNode();
43 }
44 void ReplaceInput(Node* input, int i) {
45 if (!tmp_ && input == from_->InputAt(i)) return;
46 Node* node = MutableNode();
47 node->ReplaceInput(i, input);
48 }
49
50 // Obtain the mutated node or a cached copy. Invalidates the [Constructor].
51 Node* Get();
52
53 private:
55
57 // Original node, copied on write.
59 // Temporary node used for mutations, can be recycled if cache is hit.
61 };
62
63 private:
64 Node* Query(Node* node);
65 void Insert(Node* node) { cache_.insert(node); }
66
68 struct NodeEquals {
69 bool operator()(Node* a, Node* b) const {
70 return NodeProperties::Equals(a, b);
71 }
72 };
73 struct NodeHashCode {
74 size_t operator()(Node* n) const { return NodeProperties::HashCode(n); }
75 };
77 // Unused nodes whose memory can be recycled.
79};
80
81// Modify the graph according to the information computed in the previous phase.
83 : public NON_EXPORTED_BASE(AdvancedReducer) {
84 public:
86 EscapeAnalysisResult analysis_result, Zone* zone);
89
90 Reduction Reduce(Node* node) override;
91 const char* reducer_name() const override { return "EscapeAnalysisReducer"; }
92 void Finalize() override;
93
94 // Verifies that all virtual allocation nodes have been dealt with. Run it
95 // after this reducer has been applied.
96 void VerifyReplacement() const;
97
98 private:
99 void ReduceFrameStateInputs(Node* node);
100 Node* ReduceDeoptState(Node* node, Node* effect, Deduplicator* deduplicator);
101 Node* ObjectIdNode(const VirtualObject* vobject);
102 Reduction ReplaceNode(Node* original, Node* replacement);
103
104 JSGraph* jsgraph() const { return jsgraph_; }
105 Isolate* isolate() const { return jsgraph_->isolate(); }
106 EscapeAnalysisResult analysis_result() const { return analysis_result_; }
107 Zone* zone() const { return zone_; }
108
115 Zone* const zone_;
116};
117
118} // namespace compiler
119} // namespace internal
120} // namespace v8
121
122#endif // V8_COMPILER_ESCAPE_ANALYSIS_REDUCER_H_
JSGraph * jsgraph
Isolate * isolate() const
Definition factory.h:1281
EscapeAnalysisReducer & operator=(const EscapeAnalysisReducer &)=delete
EscapeAnalysisReducer(const EscapeAnalysisReducer &)=delete
ZoneUnorderedSet< Node *, NodeHashCode, NodeEquals > cache_
static Node * GetValueInput(Node *node, int index)
static bool Equals(Node *a, Node *b)
static void ReplaceValueInput(Node *node, Node *value, int index)
Node * InputAt(int index) const
Definition node.h:70
Zone * zone_
JSHeapBroker * broker
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460