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

Side by Side Diff: src/compiler/js-graph.cc

Issue 1080023002: [turbofan] Clean up cached nodes in JSGraph. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 months 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
« no previous file with comments | « src/compiler/js-graph.h ('k') | test/cctest/compiler/test-control-reducer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/code-stubs.h" 5 #include "src/code-stubs.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/node-properties.h" 7 #include "src/compiler/node-properties.h"
8 #include "src/compiler/typer.h" 8 #include "src/compiler/typer.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> object) { 14 Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> object) {
15 Unique<HeapObject> unique = Unique<HeapObject>::CreateImmovable(object); 15 Unique<HeapObject> unique = Unique<HeapObject>::CreateImmovable(object);
16 return graph()->NewNode(common()->HeapConstant(unique)); 16 return graph()->NewNode(common()->HeapConstant(unique));
17 } 17 }
18 18
19 19
20 #define CACHED(name, expr) \
21 cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr))
22
23
20 Node* JSGraph::CEntryStubConstant(int result_size) { 24 Node* JSGraph::CEntryStubConstant(int result_size) {
21 if (result_size == 1) { 25 if (result_size == 1) {
22 if (!c_entry_stub_constant_.is_set()) { 26 return CACHED(kCEntryStubConstant,
23 c_entry_stub_constant_.set( 27 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode()));
24 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode()));
25 }
26 return c_entry_stub_constant_.get();
27 } 28 }
28
29 return ImmovableHeapConstant(CEntryStub(isolate(), result_size).GetCode()); 29 return ImmovableHeapConstant(CEntryStub(isolate(), result_size).GetCode());
30 } 30 }
31 31
32 32
33 Node* JSGraph::UndefinedConstant() { 33 Node* JSGraph::UndefinedConstant() {
34 if (!undefined_constant_.is_set()) { 34 return CACHED(kUndefinedConstant,
35 undefined_constant_.set( 35 ImmovableHeapConstant(factory()->undefined_value()));
36 ImmovableHeapConstant(factory()->undefined_value()));
37 }
38 return undefined_constant_.get();
39 } 36 }
40 37
41 38
42 Node* JSGraph::TheHoleConstant() { 39 Node* JSGraph::TheHoleConstant() {
43 if (!the_hole_constant_.is_set()) { 40 return CACHED(kTheHoleConstant,
44 the_hole_constant_.set(ImmovableHeapConstant(factory()->the_hole_value())); 41 ImmovableHeapConstant(factory()->the_hole_value()));
45 }
46 return the_hole_constant_.get();
47 } 42 }
48 43
49 44
50 Node* JSGraph::TrueConstant() { 45 Node* JSGraph::TrueConstant() {
51 if (!true_constant_.is_set()) { 46 return CACHED(kTrueConstant, ImmovableHeapConstant(factory()->true_value()));
52 true_constant_.set(ImmovableHeapConstant(factory()->true_value()));
53 }
54 return true_constant_.get();
55 } 47 }
56 48
57 49
58 Node* JSGraph::FalseConstant() { 50 Node* JSGraph::FalseConstant() {
59 if (!false_constant_.is_set()) { 51 return CACHED(kFalseConstant,
60 false_constant_.set(ImmovableHeapConstant(factory()->false_value())); 52 ImmovableHeapConstant(factory()->false_value()));
61 }
62 return false_constant_.get();
63 } 53 }
64 54
65 55
66 Node* JSGraph::NullConstant() { 56 Node* JSGraph::NullConstant() {
67 if (!null_constant_.is_set()) { 57 return CACHED(kNullConstant, ImmovableHeapConstant(factory()->null_value()));
68 null_constant_.set(ImmovableHeapConstant(factory()->null_value()));
69 }
70 return null_constant_.get();
71 } 58 }
72 59
73 60
74 Node* JSGraph::ZeroConstant() { 61 Node* JSGraph::ZeroConstant() {
75 if (!zero_constant_.is_set()) zero_constant_.set(NumberConstant(0.0)); 62 return CACHED(kZeroConstant, NumberConstant(0.0));
76 return zero_constant_.get();
77 } 63 }
78 64
79 65
80 Node* JSGraph::OneConstant() { 66 Node* JSGraph::OneConstant() {
81 if (!one_constant_.is_set()) one_constant_.set(NumberConstant(1.0)); 67 return CACHED(kOneConstant, NumberConstant(1.0));
82 return one_constant_.get();
83 } 68 }
84 69
85 70
86 Node* JSGraph::NaNConstant() { 71 Node* JSGraph::NaNConstant() {
87 if (!nan_constant_.is_set()) { 72 return CACHED(kNaNConstant,
88 nan_constant_.set(NumberConstant(std::numeric_limits<double>::quiet_NaN())); 73 NumberConstant(std::numeric_limits<double>::quiet_NaN()));
89 }
90 return nan_constant_.get();
91 } 74 }
92 75
93 76
94 Node* JSGraph::HeapConstant(Unique<HeapObject> value) { 77 Node* JSGraph::HeapConstant(Unique<HeapObject> value) {
95 // TODO(turbofan): canonicalize heap constants using Unique<T> 78 // TODO(turbofan): canonicalize heap constants using Unique<T>
96 return graph()->NewNode(common()->HeapConstant(value)); 79 return graph()->NewNode(common()->HeapConstant(value));
97 } 80 }
98 81
99 82
100 Node* JSGraph::HeapConstant(Handle<HeapObject> value) { 83 Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 Node* JSGraph::ExternalConstant(ExternalReference reference) { 177 Node* JSGraph::ExternalConstant(ExternalReference reference) {
195 Node** loc = cache_.FindExternalConstant(reference); 178 Node** loc = cache_.FindExternalConstant(reference);
196 if (*loc == NULL) { 179 if (*loc == NULL) {
197 *loc = graph()->NewNode(common()->ExternalConstant(reference)); 180 *loc = graph()->NewNode(common()->ExternalConstant(reference));
198 } 181 }
199 return *loc; 182 return *loc;
200 } 183 }
201 184
202 185
203 Node* JSGraph::EmptyFrameState() { 186 Node* JSGraph::EmptyFrameState() {
204 if (!empty_frame_state_.is_set()) { 187 if (cached_nodes_[kEmptyFrameState] == nullptr) {
205 Node* values = graph()->NewNode(common()->StateValues(0)); 188 Node* values = graph()->NewNode(common()->StateValues(0));
206 Node* state_node = graph()->NewNode( 189 Node* state_node = graph()->NewNode(
207 common()->FrameState(JS_FRAME, BailoutId::None(), 190 common()->FrameState(JS_FRAME, BailoutId::None(),
208 OutputFrameStateCombine::Ignore()), 191 OutputFrameStateCombine::Ignore()),
209 values, values, values, NoContextConstant(), UndefinedConstant()); 192 values, values, values, NoContextConstant(), UndefinedConstant());
210 empty_frame_state_.set(state_node); 193 cached_nodes_[kEmptyFrameState] = state_node;
211 } 194 }
212 return empty_frame_state_.get(); 195 return cached_nodes_[kEmptyFrameState];
213 } 196 }
214 197
215 198
216 Node* JSGraph::DeadControl() { 199 Node* JSGraph::DeadControl() {
217 if (!dead_control_.is_set()) { 200 return CACHED(kDeadControl, graph()->NewNode(common()->Dead()));
218 Node* dead_node = graph()->NewNode(common()->Dead());
219 dead_control_.set(dead_node);
220 }
221 return dead_control_.get();
222 } 201 }
223 202
224 203
225 void JSGraph::GetCachedNodes(NodeVector* nodes) { 204 void JSGraph::GetCachedNodes(NodeVector* nodes) {
226 cache_.GetCachedNodes(nodes); 205 cache_.GetCachedNodes(nodes);
227 SetOncePointer<Node>* ptrs[] = { 206 for (size_t i = 0; i < arraysize(cached_nodes_); i++) {
228 &c_entry_stub_constant_, &undefined_constant_, &the_hole_constant_, 207 if (cached_nodes_[i]) nodes->push_back(cached_nodes_[i]);
229 &true_constant_, &false_constant_, &null_constant_,
230 &zero_constant_, &one_constant_, &nan_constant_};
231 for (size_t i = 0; i < arraysize(ptrs); i++) {
232 if (ptrs[i]->is_set()) nodes->push_back(ptrs[i]->get());
233 } 208 }
234 } 209 }
235 210
236 } // namespace compiler 211 } // namespace compiler
237 } // namespace internal 212 } // namespace internal
238 } // namespace v8 213 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-graph.h ('k') | test/cctest/compiler/test-control-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698