OLD | NEW |
---|---|
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/compiler/js-graph.h" | 5 #include "src/compiler/js-graph.h" |
6 #include "src/compiler/node-properties-inl.h" | 6 #include "src/compiler/node-properties-inl.h" |
7 #include "src/compiler/typer.h" | 7 #include "src/compiler/typer.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
11 namespace compiler { | 11 namespace compiler { |
12 | 12 |
13 Node* JSGraph::ImmovableHeapConstant(Handle<Object> object) { | 13 Node* JSGraph::ImmovableHeapConstant(Handle<Object> object) { |
14 PrintableUnique<Object> unique = | 14 PrintableUnique<Object> unique = |
15 PrintableUnique<Object>::CreateImmovable(zone(), object); | 15 PrintableUnique<Object>::CreateImmovable(zone(), object); |
16 return NewNode(common()->HeapConstant(unique)); | 16 return graph()->NewNode(common()->HeapConstant(unique)); |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 Node* JSGraph::NewNode(Operator* op) { | 20 Node* JSGraph::CacheNode(SetOncePointer<Node>* cache, Node* node) { |
titzer
2014/10/08 10:39:43
You can inline these methods now, and then you are
rossberg
2014/10/08 11:30:18
Done.
| |
21 Node* node = graph()->NewNode(op); | 21 cache->set(node); |
22 typer_->Init(node); | |
23 return node; | 22 return node; |
24 } | 23 } |
25 | 24 |
26 | 25 |
26 Node* JSGraph::CachedNode(SetOncePointer<Node>* cache) { | |
27 return cache->get(); | |
28 } | |
29 | |
30 | |
27 Node* JSGraph::CEntryStubConstant() { | 31 Node* JSGraph::CEntryStubConstant() { |
28 if (!c_entry_stub_constant_.is_set()) { | 32 return c_entry_stub_constant_.is_set() |
29 c_entry_stub_constant_.set( | 33 ? CachedNode(&c_entry_stub_constant_) |
30 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode())); | 34 : CacheNode(&c_entry_stub_constant_, |
31 } | 35 ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode())); |
32 return c_entry_stub_constant_.get(); | |
33 } | 36 } |
34 | 37 |
35 | 38 |
36 Node* JSGraph::UndefinedConstant() { | 39 Node* JSGraph::UndefinedConstant() { |
37 if (!undefined_constant_.is_set()) { | 40 return undefined_constant_.is_set() |
38 undefined_constant_.set( | 41 ? CachedNode(&undefined_constant_) |
39 ImmovableHeapConstant(factory()->undefined_value())); | 42 : CacheNode(&undefined_constant_, |
40 } | 43 ImmovableHeapConstant(factory()->undefined_value())); |
41 return undefined_constant_.get(); | |
42 } | 44 } |
43 | 45 |
44 | 46 |
45 Node* JSGraph::TheHoleConstant() { | 47 Node* JSGraph::TheHoleConstant() { |
46 if (!the_hole_constant_.is_set()) { | 48 return the_hole_constant_.is_set() |
47 the_hole_constant_.set(ImmovableHeapConstant(factory()->the_hole_value())); | 49 ? CachedNode(&the_hole_constant_) |
48 } | 50 : CacheNode(&the_hole_constant_, |
49 return the_hole_constant_.get(); | 51 ImmovableHeapConstant(factory()->the_hole_value())); |
50 } | 52 } |
51 | 53 |
52 | 54 |
53 Node* JSGraph::TrueConstant() { | 55 Node* JSGraph::TrueConstant() { |
54 if (!true_constant_.is_set()) { | 56 return true_constant_.is_set() |
55 true_constant_.set(ImmovableHeapConstant(factory()->true_value())); | 57 ? CachedNode(&true_constant_) |
56 } | 58 : CacheNode(&true_constant_, |
57 return true_constant_.get(); | 59 ImmovableHeapConstant(factory()->true_value())); |
58 } | 60 } |
59 | 61 |
60 | 62 |
61 Node* JSGraph::FalseConstant() { | 63 Node* JSGraph::FalseConstant() { |
62 if (!false_constant_.is_set()) { | 64 return false_constant_.is_set() |
63 false_constant_.set(ImmovableHeapConstant(factory()->false_value())); | 65 ? CachedNode(&false_constant_) |
64 } | 66 : CacheNode(&false_constant_, |
65 return false_constant_.get(); | 67 ImmovableHeapConstant(factory()->false_value())); |
66 } | 68 } |
67 | 69 |
68 | 70 |
69 Node* JSGraph::NullConstant() { | 71 Node* JSGraph::NullConstant() { |
70 if (!null_constant_.is_set()) { | 72 return null_constant_.is_set() |
71 null_constant_.set(ImmovableHeapConstant(factory()->null_value())); | 73 ? CachedNode(&null_constant_) |
72 } | 74 : CacheNode(&null_constant_, |
73 return null_constant_.get(); | 75 ImmovableHeapConstant(factory()->null_value())); |
74 } | 76 } |
75 | 77 |
76 | 78 |
77 Node* JSGraph::ZeroConstant() { | 79 Node* JSGraph::ZeroConstant() { |
78 if (!zero_constant_.is_set()) zero_constant_.set(NumberConstant(0.0)); | 80 return zero_constant_.is_set() |
79 return zero_constant_.get(); | 81 ? CachedNode(&zero_constant_) |
82 : CacheNode(&zero_constant_, NumberConstant(0.0)); | |
80 } | 83 } |
81 | 84 |
82 | 85 |
83 Node* JSGraph::OneConstant() { | 86 Node* JSGraph::OneConstant() { |
84 if (!one_constant_.is_set()) one_constant_.set(NumberConstant(1.0)); | 87 return one_constant_.is_set() |
85 return one_constant_.get(); | 88 ? CachedNode(&one_constant_) |
89 : CacheNode(&one_constant_, NumberConstant(1.0)); | |
86 } | 90 } |
87 | 91 |
88 | 92 |
89 Node* JSGraph::NaNConstant() { | 93 Node* JSGraph::NaNConstant() { |
90 if (!nan_constant_.is_set()) { | 94 return nan_constant_.is_set() |
91 nan_constant_.set(NumberConstant(base::OS::nan_value())); | 95 ? CachedNode(&nan_constant_) |
92 } | 96 : CacheNode(&nan_constant_, NumberConstant(base::OS::nan_value())); |
93 return nan_constant_.get(); | |
94 } | 97 } |
95 | 98 |
96 | 99 |
97 Node* JSGraph::HeapConstant(PrintableUnique<Object> value) { | 100 Node* JSGraph::HeapConstant(PrintableUnique<Object> value) { |
98 // TODO(turbofan): canonicalize heap constants using Unique<T> | 101 // TODO(turbofan): canonicalize heap constants using Unique<T> |
99 return NewNode(common()->HeapConstant(value)); | 102 return graph()->NewNode(common()->HeapConstant(value)); |
100 } | 103 } |
101 | 104 |
102 | 105 |
103 Node* JSGraph::HeapConstant(Handle<Object> value) { | 106 Node* JSGraph::HeapConstant(Handle<Object> value) { |
104 // TODO(titzer): We could also match against the addresses of immortable | 107 // TODO(titzer): We could also match against the addresses of immortable |
105 // immovables here, even without access to the heap, thus always | 108 // immovables here, even without access to the heap, thus always |
106 // canonicalizing references to them. | 109 // canonicalizing references to them. |
107 return HeapConstant( | 110 return HeapConstant( |
108 PrintableUnique<Object>::CreateUninitialized(zone(), value)); | 111 PrintableUnique<Object>::CreateUninitialized(zone(), value)); |
109 } | 112 } |
(...skipping 30 matching lines...) Expand all Loading... | |
140 Node* JSGraph::Constant(int32_t value) { | 143 Node* JSGraph::Constant(int32_t value) { |
141 if (value == 0) return ZeroConstant(); | 144 if (value == 0) return ZeroConstant(); |
142 if (value == 1) return OneConstant(); | 145 if (value == 1) return OneConstant(); |
143 return NumberConstant(value); | 146 return NumberConstant(value); |
144 } | 147 } |
145 | 148 |
146 | 149 |
147 Node* JSGraph::Int32Constant(int32_t value) { | 150 Node* JSGraph::Int32Constant(int32_t value) { |
148 Node** loc = cache_.FindInt32Constant(value); | 151 Node** loc = cache_.FindInt32Constant(value); |
149 if (*loc == NULL) { | 152 if (*loc == NULL) { |
150 *loc = NewNode(common()->Int32Constant(value)); | 153 *loc = graph()->NewNode(common()->Int32Constant(value)); |
151 } | 154 } |
152 return *loc; | 155 return *loc; |
153 } | 156 } |
154 | 157 |
155 | 158 |
156 Node* JSGraph::NumberConstant(double value) { | 159 Node* JSGraph::NumberConstant(double value) { |
157 Node** loc = cache_.FindNumberConstant(value); | 160 Node** loc = cache_.FindNumberConstant(value); |
158 if (*loc == NULL) { | 161 if (*loc == NULL) { |
159 *loc = NewNode(common()->NumberConstant(value)); | 162 *loc = graph()->NewNode(common()->NumberConstant(value)); |
160 } | 163 } |
161 return *loc; | 164 return *loc; |
162 } | 165 } |
163 | 166 |
164 | 167 |
165 Node* JSGraph::Float64Constant(double value) { | 168 Node* JSGraph::Float64Constant(double value) { |
166 Node** loc = cache_.FindFloat64Constant(value); | 169 Node** loc = cache_.FindFloat64Constant(value); |
167 if (*loc == NULL) { | 170 if (*loc == NULL) { |
168 *loc = NewNode(common()->Float64Constant(value)); | 171 *loc = graph()->NewNode(common()->Float64Constant(value)); |
169 } | 172 } |
170 return *loc; | 173 return *loc; |
171 } | 174 } |
172 | 175 |
173 | 176 |
174 Node* JSGraph::ExternalConstant(ExternalReference reference) { | 177 Node* JSGraph::ExternalConstant(ExternalReference reference) { |
175 Node** loc = cache_.FindExternalConstant(reference); | 178 Node** loc = cache_.FindExternalConstant(reference); |
176 if (*loc == NULL) { | 179 if (*loc == NULL) { |
177 *loc = NewNode(common()->ExternalConstant(reference)); | 180 *loc = graph()->NewNode(common()->ExternalConstant(reference)); |
178 } | 181 } |
179 return *loc; | 182 return *loc; |
180 } | 183 } |
181 } // namespace compiler | 184 } // namespace compiler |
182 } // namespace internal | 185 } // namespace internal |
183 } // namespace v8 | 186 } // namespace v8 |
OLD | NEW |