| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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-create-lowering.h" | 5 #include "src/compiler/js-create-lowering.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 return NoChange(); | 233 return NoChange(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 Reduction JSCreateLowering::ReduceJSCreate(Node* node) { | 236 Reduction JSCreateLowering::ReduceJSCreate(Node* node) { |
| 237 DCHECK_EQ(IrOpcode::kJSCreate, node->opcode()); | 237 DCHECK_EQ(IrOpcode::kJSCreate, node->opcode()); |
| 238 Node* const target = NodeProperties::GetValueInput(node, 0); | 238 Node* const target = NodeProperties::GetValueInput(node, 0); |
| 239 Type* const target_type = NodeProperties::GetType(target); | 239 Type* const target_type = NodeProperties::GetType(target); |
| 240 Node* const new_target = NodeProperties::GetValueInput(node, 1); | 240 Node* const new_target = NodeProperties::GetValueInput(node, 1); |
| 241 Type* const new_target_type = NodeProperties::GetType(new_target); | 241 Type* const new_target_type = NodeProperties::GetType(new_target); |
| 242 Node* const effect = NodeProperties::GetEffectInput(node); | 242 Node* const effect = NodeProperties::GetEffectInput(node); |
| 243 Node* const control = NodeProperties::GetControlInput(node); |
| 243 // Extract constructor and original constructor function. | 244 // Extract constructor and original constructor function. |
| 244 if (target_type->IsHeapConstant() && new_target_type->IsHeapConstant() && | 245 if (target_type->IsHeapConstant() && new_target_type->IsHeapConstant() && |
| 245 new_target_type->AsHeapConstant()->Value()->IsJSFunction()) { | 246 new_target_type->AsHeapConstant()->Value()->IsJSFunction()) { |
| 246 Handle<JSFunction> constructor = | 247 Handle<JSFunction> constructor = |
| 247 Handle<JSFunction>::cast(target_type->AsHeapConstant()->Value()); | 248 Handle<JSFunction>::cast(target_type->AsHeapConstant()->Value()); |
| 248 Handle<JSFunction> original_constructor = | 249 Handle<JSFunction> original_constructor = |
| 249 Handle<JSFunction>::cast(new_target_type->AsHeapConstant()->Value()); | 250 Handle<JSFunction>::cast(new_target_type->AsHeapConstant()->Value()); |
| 250 DCHECK(constructor->IsConstructor()); | 251 DCHECK(constructor->IsConstructor()); |
| 251 DCHECK(original_constructor->IsConstructor()); | 252 DCHECK(original_constructor->IsConstructor()); |
| 252 | 253 |
| 253 // Check if we can inline the allocation. | 254 // Check if we can inline the allocation. |
| 254 if (IsAllocationInlineable(constructor, original_constructor)) { | 255 if (IsAllocationInlineable(constructor, original_constructor)) { |
| 255 // Force completion of inobject slack tracking before | 256 // Force completion of inobject slack tracking before |
| 256 // generating code to finalize the instance size. | 257 // generating code to finalize the instance size. |
| 257 original_constructor->CompleteInobjectSlackTrackingIfActive(); | 258 original_constructor->CompleteInobjectSlackTrackingIfActive(); |
| 258 | 259 |
| 259 // Compute instance size from initial map of {original_constructor}. | 260 // Compute instance size from initial map of {original_constructor}. |
| 260 Handle<Map> initial_map(original_constructor->initial_map(), isolate()); | 261 Handle<Map> initial_map(original_constructor->initial_map(), isolate()); |
| 261 int const instance_size = initial_map->instance_size(); | 262 int const instance_size = initial_map->instance_size(); |
| 262 | 263 |
| 263 // Add a dependency on the {initial_map} to make sure that this code is | 264 // Add a dependency on the {initial_map} to make sure that this code is |
| 264 // deoptimized whenever the {initial_map} of the {original_constructor} | 265 // deoptimized whenever the {initial_map} of the {original_constructor} |
| 265 // changes. | 266 // changes. |
| 266 dependencies()->AssumeInitialMapCantChange(initial_map); | 267 dependencies()->AssumeInitialMapCantChange(initial_map); |
| 267 | 268 |
| 268 // Emit code to allocate the JSObject instance for the | 269 // Emit code to allocate the JSObject instance for the |
| 269 // {original_constructor}. | 270 // {original_constructor}. |
| 270 AllocationBuilder a(jsgraph(), effect, graph()->start()); | 271 AllocationBuilder a(jsgraph(), effect, control); |
| 271 a.Allocate(instance_size); | 272 a.Allocate(instance_size); |
| 272 a.Store(AccessBuilder::ForMap(), initial_map); | 273 a.Store(AccessBuilder::ForMap(), initial_map); |
| 273 a.Store(AccessBuilder::ForJSObjectProperties(), | 274 a.Store(AccessBuilder::ForJSObjectProperties(), |
| 274 jsgraph()->EmptyFixedArrayConstant()); | 275 jsgraph()->EmptyFixedArrayConstant()); |
| 275 a.Store(AccessBuilder::ForJSObjectElements(), | 276 a.Store(AccessBuilder::ForJSObjectElements(), |
| 276 jsgraph()->EmptyFixedArrayConstant()); | 277 jsgraph()->EmptyFixedArrayConstant()); |
| 277 for (int i = 0; i < initial_map->GetInObjectProperties(); ++i) { | 278 for (int i = 0; i < initial_map->GetInObjectProperties(); ++i) { |
| 278 a.Store(AccessBuilder::ForJSObjectInObjectProperty(initial_map, i), | 279 a.Store(AccessBuilder::ForJSObjectInObjectProperty(initial_map, i), |
| 279 jsgraph()->UndefinedConstant()); | 280 jsgraph()->UndefinedConstant()); |
| 280 } | 281 } |
| 282 RelaxControls(node); |
| 281 a.FinishAndChange(node); | 283 a.FinishAndChange(node); |
| 282 return Changed(node); | 284 return Changed(node); |
| 283 } | 285 } |
| 284 } | 286 } |
| 285 return NoChange(); | 287 return NoChange(); |
| 286 } | 288 } |
| 287 | 289 |
| 288 Reduction JSCreateLowering::ReduceJSCreateArguments(Node* node) { | 290 Reduction JSCreateLowering::ReduceJSCreateArguments(Node* node) { |
| 289 DCHECK_EQ(IrOpcode::kJSCreateArguments, node->opcode()); | 291 DCHECK_EQ(IrOpcode::kJSCreateArguments, node->opcode()); |
| 290 CreateArgumentsType type = CreateArgumentsTypeOf(node->op()); | 292 CreateArgumentsType type = CreateArgumentsTypeOf(node->op()); |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1389 return jsgraph()->simplified(); | 1391 return jsgraph()->simplified(); |
| 1390 } | 1392 } |
| 1391 | 1393 |
| 1392 MachineOperatorBuilder* JSCreateLowering::machine() const { | 1394 MachineOperatorBuilder* JSCreateLowering::machine() const { |
| 1393 return jsgraph()->machine(); | 1395 return jsgraph()->machine(); |
| 1394 } | 1396 } |
| 1395 | 1397 |
| 1396 } // namespace compiler | 1398 } // namespace compiler |
| 1397 } // namespace internal | 1399 } // namespace internal |
| 1398 } // namespace v8 | 1400 } // namespace v8 |
| OLD | NEW |