OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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-type-feedback.h" | 5 #include "src/compiler/js-type-feedback.h" |
6 | 6 |
7 #include "src/property-details.h" | 7 #include "src/property-details.h" |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/ast.h" | 10 #include "src/ast.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 feedback_vector_ic_slot_map_.insert(std::make_pair(node->id(), slot)); | 45 feedback_vector_ic_slot_map_.insert(std::make_pair(node->id(), slot)); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 Reduction JSTypeFeedbackSpecializer::Reduce(Node* node) { | 49 Reduction JSTypeFeedbackSpecializer::Reduce(Node* node) { |
50 switch (node->opcode()) { | 50 switch (node->opcode()) { |
51 case IrOpcode::kJSLoadProperty: | 51 case IrOpcode::kJSLoadProperty: |
52 return ReduceJSLoadProperty(node); | 52 return ReduceJSLoadProperty(node); |
53 case IrOpcode::kJSLoadNamed: | 53 case IrOpcode::kJSLoadNamed: |
54 return ReduceJSLoadNamed(node); | 54 return ReduceJSLoadNamed(node); |
| 55 case IrOpcode::kJSLoadGlobal: |
| 56 return ReduceJSLoadGlobal(node); |
55 case IrOpcode::kJSStoreNamed: | 57 case IrOpcode::kJSStoreNamed: |
56 return ReduceJSStoreNamed(node); | 58 return ReduceJSStoreNamed(node); |
57 case IrOpcode::kJSStoreProperty: | 59 case IrOpcode::kJSStoreProperty: |
58 return ReduceJSStoreProperty(node); | 60 return ReduceJSStoreProperty(node); |
59 default: | 61 default: |
60 break; | 62 break; |
61 } | 63 } |
62 return NoChange(); | 64 return NoChange(); |
63 } | 65 } |
64 | 66 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 132 } |
131 access->offset = field_index.offset(); | 133 access->offset = field_index.offset(); |
132 return true; | 134 return true; |
133 } | 135 } |
134 | 136 |
135 // TODO(turbofan): handle out of object properties. | 137 // TODO(turbofan): handle out of object properties. |
136 return false; | 138 return false; |
137 } | 139 } |
138 | 140 |
139 | 141 |
140 static bool IsGlobalObject(Node* node) { | |
141 return NodeProperties::IsTyped(node) && | |
142 NodeProperties::GetBounds(node).upper->Is(Type::GlobalObject()); | |
143 } | |
144 | |
145 | |
146 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadNamed(Node* node) { | 142 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadNamed(Node* node) { |
147 DCHECK(node->opcode() == IrOpcode::kJSLoadNamed); | 143 DCHECK(node->opcode() == IrOpcode::kJSLoadNamed); |
148 Node* receiver = node->InputAt(0); | |
149 if (IsGlobalObject(receiver)) { | |
150 return ReduceJSLoadNamedForGlobalVariable(node); | |
151 } | |
152 | |
153 if (mode() != kDeoptimizationEnabled) return NoChange(); | 144 if (mode() != kDeoptimizationEnabled) return NoChange(); |
154 Node* frame_state_before = GetFrameStateBefore(node); | 145 Node* frame_state_before = GetFrameStateBefore(node); |
155 if (frame_state_before == nullptr) return NoChange(); | 146 if (frame_state_before == nullptr) return NoChange(); |
156 | 147 |
157 const LoadNamedParameters& p = LoadNamedParametersOf(node->op()); | 148 const LoadNamedParameters& p = LoadNamedParametersOf(node->op()); |
158 Handle<Name> name = p.name().handle(); | 149 Handle<Name> name = p.name().handle(); |
159 SmallMapList maps; | 150 SmallMapList maps; |
160 | 151 |
161 FeedbackVectorICSlot slot = js_type_feedback_->FindFeedbackVectorICSlot(node); | 152 FeedbackVectorICSlot slot = js_type_feedback_->FindFeedbackVectorICSlot(node); |
162 if (slot.IsInvalid() || | 153 if (slot.IsInvalid() || |
163 oracle()->LoadInlineCacheState(slot) == UNINITIALIZED) { | 154 oracle()->LoadInlineCacheState(slot) == UNINITIALIZED) { |
164 // No type feedback ids or the load is uninitialized. | 155 // No type feedback ids or the load is uninitialized. |
165 return NoChange(); | 156 return NoChange(); |
166 } | 157 } |
167 oracle()->PropertyReceiverTypes(slot, name, &maps); | 158 oracle()->PropertyReceiverTypes(slot, name, &maps); |
168 | 159 |
| 160 Node* receiver = node->InputAt(0); |
169 Node* effect = NodeProperties::GetEffectInput(node); | 161 Node* effect = NodeProperties::GetEffectInput(node); |
170 | 162 |
171 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism | 163 if (maps.length() != 1) return NoChange(); // TODO(turbofan): polymorphism |
172 if (!ENABLE_FAST_PROPERTY_LOADS) return NoChange(); | 164 if (!ENABLE_FAST_PROPERTY_LOADS) return NoChange(); |
173 | 165 |
174 Handle<Map> map = maps.first(); | 166 Handle<Map> map = maps.first(); |
175 FieldAccess field_access; | 167 FieldAccess field_access; |
176 if (!GetInObjectFieldAccess(LOAD, map, name, &field_access)) { | 168 if (!GetInObjectFieldAccess(LOAD, map, name, &field_access)) { |
177 return NoChange(); | 169 return NoChange(); |
178 } | 170 } |
(...skipping 10 matching lines...) Expand all Loading... |
189 | 181 |
190 // TODO(turbofan): handle slow case instead of deoptimizing. | 182 // TODO(turbofan): handle slow case instead of deoptimizing. |
191 Node* deopt = graph()->NewNode(common()->Deoptimize(), frame_state_before, | 183 Node* deopt = graph()->NewNode(common()->Deoptimize(), frame_state_before, |
192 effect, check_failed); | 184 effect, check_failed); |
193 NodeProperties::MergeControlToEnd(graph(), common(), deopt); | 185 NodeProperties::MergeControlToEnd(graph(), common(), deopt); |
194 ReplaceWithValue(node, load, load, check_success); | 186 ReplaceWithValue(node, load, load, check_success); |
195 return Replace(load); | 187 return Replace(load); |
196 } | 188 } |
197 | 189 |
198 | 190 |
199 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadNamedForGlobalVariable( | 191 Reduction JSTypeFeedbackSpecializer::ReduceJSLoadGlobal(Node* node) { |
200 Node* node) { | 192 DCHECK(node->opcode() == IrOpcode::kJSLoadGlobal); |
201 Handle<String> name = | 193 Handle<String> name = |
202 Handle<String>::cast(LoadNamedParametersOf(node->op()).name().handle()); | 194 Handle<String>::cast(LoadGlobalParametersOf(node->op()).name().handle()); |
203 // Try to optimize loads from the global object. | 195 // Try to optimize loads from the global object. |
204 Handle<Object> constant_value = | 196 Handle<Object> constant_value = |
205 jsgraph()->isolate()->factory()->GlobalConstantFor(name); | 197 jsgraph()->isolate()->factory()->GlobalConstantFor(name); |
206 if (!constant_value.is_null()) { | 198 if (!constant_value.is_null()) { |
207 // Always optimize global constants. | 199 // Always optimize global constants. |
208 Node* constant = jsgraph()->Constant(constant_value); | 200 Node* constant = jsgraph()->Constant(constant_value); |
209 ReplaceWithValue(node, constant); | 201 ReplaceWithValue(node, constant); |
210 return Replace(constant); | 202 return Replace(constant); |
211 } | 203 } |
212 | 204 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 BailoutId id = OpParameter<FrameStateInfo>(node).bailout_id(); | 357 BailoutId id = OpParameter<FrameStateInfo>(node).bailout_id(); |
366 if (id != BailoutId::None()) return frame_state; | 358 if (id != BailoutId::None()) return frame_state; |
367 } | 359 } |
368 } | 360 } |
369 return nullptr; | 361 return nullptr; |
370 } | 362 } |
371 | 363 |
372 } // namespace compiler | 364 } // namespace compiler |
373 } // namespace internal | 365 } // namespace internal |
374 } // namespace v8 | 366 } // namespace v8 |
OLD | NEW |