Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/compiler/escape-analysis.h

Issue 1457683003: [turbofan] Initial support for escape analysis. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug + small improvements Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_ESCAPE_ANALYSIS_H_
6 #define V8_COMPILER_ESCAPE_ANALYSIS_H_
7
8 #include "src/base/flags.h"
9 #include "src/compiler/graph.h"
10
11 namespace v8 {
12 namespace internal {
13 namespace compiler {
14
15 // Forward declarations.
16 class CommonOperatorBuilder;
17
18
19 class VirtualObject : public ZoneObject {
20 public:
21 enum Status { kUntracked = 0, kTracked = 1 };
22 VirtualObject(NodeId id, Zone* zone)
23 : id_(id), status_(kUntracked), fields_(zone), replacement_(nullptr) {}
24
25 VirtualObject(const VirtualObject& other)
26 : id_(other.id_),
27 status_(other.status_),
28 fields_(other.fields_),
29 replacement_(other.replacement_) {}
30
31 VirtualObject(NodeId id, Zone* zone, size_t field_number)
32 : id_(id), status_(kTracked), fields_(zone), replacement_(nullptr) {
33 fields_.resize(field_number);
34 }
35
36 Node* GetField(size_t offset) {
37 if (offset < fields_.size()) {
38 return fields_[offset];
39 }
40 return nullptr;
41 }
42
43 bool SetField(size_t offset, Node* node) {
44 bool changed = fields_[offset] != node;
45 fields_[offset] = node;
46 return changed;
47 }
48 bool IsVirtual() const { return status_ == kTracked; }
49 bool IsTracked() const { return status_ != kUntracked; }
50 Node* GetReplacement() { return replacement_; }
51 bool SetReplacement(Node* node) {
52 bool changed = replacement_ != node;
53 replacement_ = node;
54 return changed;
55 }
56
57 size_t fields() { return fields_.size(); }
58 bool ResizeFields(size_t field_number) {
59 if (field_number != fields_.size()) {
60 fields_.resize(field_number);
61 return true;
62 }
63 return false;
64 }
65
66 bool UpdateFrom(const VirtualObject& other);
67
68 NodeId id() { return id_; }
69 void id(NodeId id) { id_ = id; }
70
71 private:
72 NodeId id_;
73 Status status_;
74 ZoneVector<Node*> fields_;
75 Node* replacement_;
76 };
77
78
79 class VirtualState : public ZoneObject {
80 public:
81 VirtualState(Zone* zone, size_t size);
82 VirtualState(const VirtualState& states);
83
84 VirtualObject* GetVirtualObject(Node* node);
85 VirtualObject* GetVirtualObject(size_t id);
86 VirtualObject* GetOrCreateTrackedVirtualObject(NodeId id, Zone* zone);
87 void SetVirtualObject(NodeId id, VirtualObject* state);
88 void LastChangedAt(Node* node) { last_changed_ = node; }
89 Node* GetLastChanged() { return last_changed_; }
90 bool UpdateFrom(NodeId id, VirtualObject* state, Zone* zone);
91 Node* ResolveReplacement(Node* node);
92 bool UpdateReplacement(Node* node, Node* rep, Zone* zone);
93 bool UpdateFrom(VirtualState* state, Zone* zone);
94 bool MergeFrom(VirtualState* left, VirtualState* right, Zone* zone,
95 Graph* graph, CommonOperatorBuilder* common, Node* control);
96
97 size_t size() { return info_.size(); }
98
99 private:
100 ZoneVector<VirtualObject*> info_;
101 Node* last_changed_;
102 };
103
104
105 class EscapeObjectAnalysis;
106
107
108 // EscapeStatusAnalysis determines for each allocation whether it escapes.
109 class EscapeStatusAnalysis {
110 public:
111 EscapeStatusAnalysis(EscapeObjectAnalysis* object_analysis, Graph* graph,
112 Zone* zone);
113 ~EscapeStatusAnalysis();
114
115 enum EscapeStatusFlag {
116 kUnknown = 0u,
117 kVirtual = 1u << 0,
118 kEscaped = 1u << 1,
119 };
120 typedef base::Flags<EscapeStatusFlag> EscapeStatusFlags;
121
122 void Run();
123
124 bool HasEntry(Node* node);
125 bool IsVirtual(Node* node);
126 bool IsEscaped(Node* node);
127
128 void DebugPrint();
129
130 private:
131 void Process(Node* node);
132 void ProcessAllocate(Node* node);
133 void ProcessFinishRegion(Node* node);
134 void ProcessStoreField(Node* node);
135 bool CheckUsesForEscape(Node* node) { return CheckUsesForEscape(node, node); }
136 bool CheckUsesForEscape(Node* node, Node* rep);
137 void RevisitUses(Node* node);
138 void RevisitInputs(Node* node);
139 bool SetEscaped(Node* node);
140
141 Graph* graph() const { return graph_; }
142 Zone* zone() const { return zone_; }
143
144 EscapeObjectAnalysis* object_analysis_;
145 Graph* const graph_;
146 Zone* const zone_;
147 ZoneVector<EscapeStatusFlags> info_;
148 ZoneDeque<Node*> queue_;
149
150 DISALLOW_COPY_AND_ASSIGN(EscapeStatusAnalysis);
151 };
152
153
154 DEFINE_OPERATORS_FOR_FLAGS(EscapeStatusAnalysis::EscapeStatusFlags)
155
156
157 // EscapeObjectAnalysis simulates stores to determine values of loads if
158 // an object is virtual and eliminated.
159 class EscapeObjectAnalysis {
160 public:
161 EscapeObjectAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone);
162 ~EscapeObjectAnalysis();
163
164 void Run();
165
166 Node* GetReplacement(Node* at, NodeId id);
167
168 private:
169 bool Process(Node* node);
170 void ProcessLoadField(Node* node);
171 void ProcessStoreField(Node* node);
172 void ProcessAllocation(Node* node);
173 void ProcessFinishRegion(Node* node);
174 void ProcessCall(Node* node);
175 void ProcessStart(Node* node);
176 bool ProcessEffectPhi(Node* node);
177 void ForwardVirtualState(Node* node);
178 bool IsEffectBranchPoint(Node* node);
179 bool IsDanglingEffectNode(Node* node);
180 int OffsetFromAccess(Node* node);
181
182 void DebugPrint();
183
184 Graph* graph() const { return graph_; }
185 CommonOperatorBuilder* common() const { return common_; }
186 Zone* zone() const { return zone_; }
187
188 Graph* const graph_;
189 CommonOperatorBuilder* const common_;
190 Zone* const zone_;
191 ZoneVector<VirtualState*> virtual_states_;
192
193 DISALLOW_COPY_AND_ASSIGN(EscapeObjectAnalysis);
194 };
195
196 } // namespace compiler
197 } // namespace internal
198 } // namespace v8
199
200 #endif // V8_COMPILER_ESCAPE_ANALYSIS_H_
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | src/compiler/escape-analysis.cc » ('j') | src/compiler/escape-analysis.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698