| 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 18 matching lines...) Expand all Loading... |
| 29 // allocated object and also provides helpers for commonly allocated objects. | 29 // allocated object and also provides helpers for commonly allocated objects. |
| 30 class AllocationBuilder final { | 30 class AllocationBuilder final { |
| 31 public: | 31 public: |
| 32 AllocationBuilder(JSGraph* jsgraph, Node* effect, Node* control) | 32 AllocationBuilder(JSGraph* jsgraph, Node* effect, Node* control) |
| 33 : jsgraph_(jsgraph), | 33 : jsgraph_(jsgraph), |
| 34 allocation_(nullptr), | 34 allocation_(nullptr), |
| 35 effect_(effect), | 35 effect_(effect), |
| 36 control_(control) {} | 36 control_(control) {} |
| 37 | 37 |
| 38 // Primitive allocation of static size. | 38 // Primitive allocation of static size. |
| 39 void Allocate(int size, PretenureFlag pretenure = NOT_TENURED) { | 39 void Allocate(int size, PretenureFlag pretenure = NOT_TENURED, |
| 40 Type* type = Type::Any()) { |
| 40 effect_ = graph()->NewNode( | 41 effect_ = graph()->NewNode( |
| 41 common()->BeginRegion(RegionObservability::kNotObservable), effect_); | 42 common()->BeginRegion(RegionObservability::kNotObservable), effect_); |
| 42 allocation_ = | 43 allocation_ = |
| 43 graph()->NewNode(simplified()->Allocate(pretenure), | 44 graph()->NewNode(simplified()->Allocate(pretenure), |
| 44 jsgraph()->Constant(size), effect_, control_); | 45 jsgraph()->Constant(size), effect_, control_); |
| 46 // TODO(turbofan): Maybe we should put the Type* onto the Allocate operator |
| 47 // at some point, or maybe we should have a completely differnt story. |
| 48 NodeProperties::SetType(allocation_, type); |
| 45 effect_ = allocation_; | 49 effect_ = allocation_; |
| 46 } | 50 } |
| 47 | 51 |
| 48 // Primitive store into a field. | 52 // Primitive store into a field. |
| 49 void Store(const FieldAccess& access, Node* value) { | 53 void Store(const FieldAccess& access, Node* value) { |
| 50 effect_ = graph()->NewNode(simplified()->StoreField(access), allocation_, | 54 effect_ = graph()->NewNode(simplified()->StoreField(access), allocation_, |
| 51 value, effect_, control_); | 55 value, effect_, control_); |
| 52 } | 56 } |
| 53 | 57 |
| 54 // Primitive store into an element. | 58 // Primitive store into an element. |
| 55 void Store(ElementAccess const& access, Node* index, Node* value) { | 59 void Store(ElementAccess const& access, Node* index, Node* value) { |
| 56 effect_ = graph()->NewNode(simplified()->StoreElement(access), allocation_, | 60 effect_ = graph()->NewNode(simplified()->StoreElement(access), allocation_, |
| 57 index, value, effect_, control_); | 61 index, value, effect_, control_); |
| 58 } | 62 } |
| 59 | 63 |
| 60 // Compound allocation of a FixedArray. | 64 // Compound allocation of a FixedArray. |
| 61 void AllocateArray(int length, Handle<Map> map, | 65 void AllocateArray(int length, Handle<Map> map, |
| 62 PretenureFlag pretenure = NOT_TENURED) { | 66 PretenureFlag pretenure = NOT_TENURED) { |
| 63 DCHECK(map->instance_type() == FIXED_ARRAY_TYPE || | 67 DCHECK(map->instance_type() == FIXED_ARRAY_TYPE || |
| 64 map->instance_type() == FIXED_DOUBLE_ARRAY_TYPE); | 68 map->instance_type() == FIXED_DOUBLE_ARRAY_TYPE); |
| 65 int size = (map->instance_type() == FIXED_ARRAY_TYPE) | 69 int size = (map->instance_type() == FIXED_ARRAY_TYPE) |
| 66 ? FixedArray::SizeFor(length) | 70 ? FixedArray::SizeFor(length) |
| 67 : FixedDoubleArray::SizeFor(length); | 71 : FixedDoubleArray::SizeFor(length); |
| 68 Allocate(size, pretenure); | 72 Allocate(size, pretenure, Type::OtherInternal()); |
| 69 Store(AccessBuilder::ForMap(), map); | 73 Store(AccessBuilder::ForMap(), map); |
| 70 Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length)); | 74 Store(AccessBuilder::ForFixedArrayLength(), jsgraph()->Constant(length)); |
| 71 } | 75 } |
| 72 | 76 |
| 73 // Compound store of a constant into a field. | 77 // Compound store of a constant into a field. |
| 74 void Store(const FieldAccess& access, Handle<Object> value) { | 78 void Store(const FieldAccess& access, Handle<Object> value) { |
| 75 Store(access, jsgraph()->Constant(value)); | 79 Store(access, jsgraph()->Constant(value)); |
| 76 } | 80 } |
| 77 | 81 |
| 78 void FinishAndChange(Node* node) { | 82 void FinishAndChange(Node* node) { |
| (...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 for (int index = static_cast<int>(inobject_fields.size()); | 1106 for (int index = static_cast<int>(inobject_fields.size()); |
| 1103 index < boilerplate_length; ++index) { | 1107 index < boilerplate_length; ++index) { |
| 1104 FieldAccess access = | 1108 FieldAccess access = |
| 1105 AccessBuilder::ForJSObjectInObjectProperty(boilerplate_map, index); | 1109 AccessBuilder::ForJSObjectInObjectProperty(boilerplate_map, index); |
| 1106 Node* value = jsgraph()->HeapConstant(factory()->one_pointer_filler_map()); | 1110 Node* value = jsgraph()->HeapConstant(factory()->one_pointer_filler_map()); |
| 1107 inobject_fields.push_back(std::make_pair(access, value)); | 1111 inobject_fields.push_back(std::make_pair(access, value)); |
| 1108 } | 1112 } |
| 1109 | 1113 |
| 1110 // Actually allocate and initialize the object. | 1114 // Actually allocate and initialize the object. |
| 1111 AllocationBuilder builder(jsgraph(), effect, control); | 1115 AllocationBuilder builder(jsgraph(), effect, control); |
| 1112 builder.Allocate(boilerplate_map->instance_size(), pretenure); | 1116 builder.Allocate(boilerplate_map->instance_size(), pretenure, |
| 1117 Type::OtherObject()); |
| 1113 builder.Store(AccessBuilder::ForMap(), boilerplate_map); | 1118 builder.Store(AccessBuilder::ForMap(), boilerplate_map); |
| 1114 builder.Store(AccessBuilder::ForJSObjectProperties(), properties); | 1119 builder.Store(AccessBuilder::ForJSObjectProperties(), properties); |
| 1115 builder.Store(AccessBuilder::ForJSObjectElements(), elements); | 1120 builder.Store(AccessBuilder::ForJSObjectElements(), elements); |
| 1116 if (boilerplate_map->IsJSArrayMap()) { | 1121 if (boilerplate_map->IsJSArrayMap()) { |
| 1117 Handle<JSArray> boilerplate_array = Handle<JSArray>::cast(boilerplate); | 1122 Handle<JSArray> boilerplate_array = Handle<JSArray>::cast(boilerplate); |
| 1118 builder.Store( | 1123 builder.Store( |
| 1119 AccessBuilder::ForJSArrayLength(boilerplate_array->GetElementsKind()), | 1124 AccessBuilder::ForJSArrayLength(boilerplate_array->GetElementsKind()), |
| 1120 handle(boilerplate_array->length(), isolate())); | 1125 handle(boilerplate_array->length(), isolate())); |
| 1121 } | 1126 } |
| 1122 for (auto const inobject_field : inobject_fields) { | 1127 for (auto const inobject_field : inobject_fields) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 return jsgraph()->simplified(); | 1252 return jsgraph()->simplified(); |
| 1248 } | 1253 } |
| 1249 | 1254 |
| 1250 MachineOperatorBuilder* JSCreateLowering::machine() const { | 1255 MachineOperatorBuilder* JSCreateLowering::machine() const { |
| 1251 return jsgraph()->machine(); | 1256 return jsgraph()->machine(); |
| 1252 } | 1257 } |
| 1253 | 1258 |
| 1254 } // namespace compiler | 1259 } // namespace compiler |
| 1255 } // namespace internal | 1260 } // namespace internal |
| 1256 } // namespace v8 | 1261 } // namespace v8 |
| OLD | NEW |