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

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: Add more DCHECKS 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
49 bool IsVirtual() const { return status_ == kTracked; }
50 bool IsTracked() const { return status_ != kUntracked; }
51 Node* GetReplacement() { return replacement_; }
52 bool SetReplacement(Node* node) {
53 bool changed = replacement_ != node;
54 replacement_ = node;
55 return changed;
56 }
57
58 size_t fields() { return fields_.size(); }
59 bool ResizeFields(size_t field_number) {
60 if (field_number != fields_.size()) {
61 fields_.resize(field_number);
62 return true;
63 }
64 return false;
65 }
66
67 bool UpdateFrom(const VirtualObject& other);
68
69 NodeId id() { return id_; }
70 void id(NodeId id) { id_ = id; }
71
72 private:
73 NodeId id_;
74 Status status_;
75 ZoneVector<Node*> fields_;
76 Node* replacement_;
77 };
78
79
80 class VirtualState : public ZoneObject {
81 public:
82 VirtualState(Zone* zone, size_t size);
83 VirtualState(const VirtualState& states);
84
85 VirtualObject* GetVirtualObject(Node* node);
86 VirtualObject* GetVirtualObject(size_t id);
87 VirtualObject* GetOrCreateTrackedVirtualObject(NodeId id, Zone* zone);
88 void SetVirtualObject(NodeId id, VirtualObject* state);
89 void LastChangedAt(Node* node) { last_changed_ = node; }
90 Node* GetLastChanged() { return last_changed_; }
91 bool UpdateFrom(NodeId id, VirtualObject* state, Zone* zone);
92 Node* ResolveReplacement(Node* node);
93 bool UpdateReplacement(Node* node, Node* rep, Zone* zone);
94 bool UpdateFrom(VirtualState* state, Zone* zone);
95 bool MergeFrom(VirtualState* left, VirtualState* right, Zone* zone,
96 Graph* graph, CommonOperatorBuilder* common, Node* control);
97
98 size_t size() { return info_.size(); }
99
100 private:
101 ZoneVector<VirtualObject*> info_;
102 Node* last_changed_;
103 };
104
105
106 // EscapeStatusAnalysis determines for each allocation whether it escapes.
107 class EscapeStatusAnalysis {
108 public:
109 EscapeStatusAnalysis(Graph* graph, Zone* zone);
110 ~EscapeStatusAnalysis();
111
112 enum EscapeStatusFlag {
113 kUnknown = 0u,
114 kVirtual = 1u << 0,
115 kEscaped = 1u << 1,
116 };
117 typedef base::Flags<EscapeStatusFlag> EscapeStatusFlags;
118
119 void Run();
120
121 bool HasEntry(Node* node);
122 bool IsVirtual(Node* node);
123 bool IsEscaped(Node* node);
124
125 void DebugPrint();
126
127 private:
128 void Process(Node* node);
129 void ProcessAllocate(Node* node);
130 void ProcessFinishRegion(Node* node);
131 void ProcessStoreField(Node* node);
132 bool CheckUsesForEscape(Node* node);
133 void RevisitUses(Node* node);
134 void RevisitInputs(Node* node);
135 bool SetEscaped(Node* node);
136
137 Graph* graph() const { return graph_; }
138 Zone* zone() const { return zone_; }
139
140 Graph* const graph_;
141 Zone* const zone_;
142 ZoneVector<EscapeStatusFlags> info_;
143 ZoneDeque<Node*> queue_;
144 };
145
146
147 DEFINE_OPERATORS_FOR_FLAGS(EscapeStatusAnalysis::EscapeStatusFlags)
148
149
150 // EscapeObjectAnalysis simulates stores to determine values of loads if
151 // an object is virtual and eliminated.
152 class EscapeObjectAnalysis {
153 public:
154 EscapeObjectAnalysis(Graph* graph, CommonOperatorBuilder* common, Zone* zone);
155 ~EscapeObjectAnalysis();
156
157 void Run();
158
159 Node* GetReplacement(Node* at, NodeId id);
160
161 private:
162 bool Process(Node* node);
163 void ProcessLoadField(Node* node);
164 void ProcessStoreField(Node* node);
165 void ProcessAllocation(Node* node);
166 void ProcessFinishRegion(Node* node);
167 void ProcessCall(Node* node);
168 void ProcessStart(Node* node);
169 bool ProcessEffectPhi(Node* node);
170 void ForwardVirtualState(Node* node);
171 bool IsEffectBranchPoint(Node* node);
172 bool IsDanglingEffectNode(Node* node);
173
174 void DebugPrint();
175
176 Graph* graph() const { return graph_; }
177 CommonOperatorBuilder* common() const { return common_; }
178 Zone* zone() const { return zone_; }
179
180 Graph* const graph_;
181 CommonOperatorBuilder* const common_;
182 Zone* const zone_;
183 ZoneVector<VirtualState*> virtual_states_;
184
185 DISALLOW_COPY_AND_ASSIGN(EscapeObjectAnalysis);
186 };
187
188 } // namespace compiler
189 } // namespace internal
190 } // namespace v8
191
192 #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