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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/js-typed-lowering.h" | 8 #include "src/compiler/js-typed-lowering.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 AllocationBuilder(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, | 39 AllocationBuilder(JSGraph* jsgraph, SimplifiedOperatorBuilder* simplified, |
40 Node* effect, Node* control) | 40 Node* effect, Node* control) |
41 : jsgraph_(jsgraph), | 41 : jsgraph_(jsgraph), |
42 simplified_(simplified), | 42 simplified_(simplified), |
43 allocation_(nullptr), | 43 allocation_(nullptr), |
44 effect_(effect), | 44 effect_(effect), |
45 control_(control) {} | 45 control_(control) {} |
46 | 46 |
47 // Primitive allocation of static size. | 47 // Primitive allocation of static size. |
48 void Allocate(int size) { | 48 void Allocate(int size) { |
| 49 effect_ = graph()->NewNode(jsgraph()->common()->BeginRegion(), effect_); |
49 allocation_ = graph()->NewNode( | 50 allocation_ = graph()->NewNode( |
50 simplified()->Allocate(), jsgraph()->Constant(size), effect_, control_); | 51 simplified()->Allocate(), jsgraph()->Constant(size), effect_, control_); |
51 effect_ = allocation_; | 52 effect_ = allocation_; |
52 } | 53 } |
53 | 54 |
54 // Primitive store into a field. | 55 // Primitive store into a field. |
55 void Store(const FieldAccess& access, Node* value) { | 56 void Store(const FieldAccess& access, Node* value) { |
56 effect_ = graph()->NewNode(simplified()->StoreField(access), allocation_, | 57 effect_ = graph()->NewNode(simplified()->StoreField(access), allocation_, |
57 value, effect_, control_); | 58 value, effect_, control_); |
58 } | 59 } |
59 | 60 |
60 // Compound allocation of a FixedArray. | 61 // Compound allocation of a FixedArray. |
61 void AllocateArray(int length, Handle<Map> map) { | 62 void AllocateArray(int length, Handle<Map> map) { |
62 Allocate(FixedArray::SizeFor(length)); | 63 Allocate(FixedArray::SizeFor(length)); |
63 Store(AccessBuilder::ForMap(), map); | 64 Store(AccessBuilder::ForMap(), map); |
64 Store(AccessBuilder::ForFixedArrayLength(graph()->zone()), | 65 Store(AccessBuilder::ForFixedArrayLength(graph()->zone()), |
65 jsgraph()->Constant(length)); | 66 jsgraph()->Constant(length)); |
66 } | 67 } |
67 | 68 |
68 // Compound store of a constant into a field. | 69 // Compound store of a constant into a field. |
69 void Store(const FieldAccess& access, Handle<Object> value) { | 70 void Store(const FieldAccess& access, Handle<Object> value) { |
70 Store(access, jsgraph()->Constant(value)); | 71 Store(access, jsgraph()->Constant(value)); |
71 } | 72 } |
72 | 73 |
73 Node* allocation() const { return allocation_; } | 74 void Finish(Node* node) { |
74 Node* effect() const { return effect_; } | 75 NodeProperties::SetType(allocation_, NodeProperties::GetType(node)); |
| 76 node->ReplaceInput(0, allocation_); |
| 77 node->ReplaceInput(1, effect_); |
| 78 node->TrimInputCount(2); |
| 79 NodeProperties::ChangeOp(node, jsgraph()->common()->FinishRegion()); |
| 80 } |
75 | 81 |
76 protected: | 82 protected: |
77 JSGraph* jsgraph() { return jsgraph_; } | 83 JSGraph* jsgraph() { return jsgraph_; } |
78 Graph* graph() { return jsgraph_->graph(); } | 84 Graph* graph() { return jsgraph_->graph(); } |
79 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 85 SimplifiedOperatorBuilder* simplified() { return simplified_; } |
80 | 86 |
81 private: | 87 private: |
82 JSGraph* const jsgraph_; | 88 JSGraph* const jsgraph_; |
83 SimplifiedOperatorBuilder* simplified_; | 89 SimplifiedOperatorBuilder* simplified_; |
84 Node* allocation_; | 90 Node* allocation_; |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. | 1273 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. |
1268 int context_length = slot_count + Context::MIN_CONTEXT_SLOTS; | 1274 int context_length = slot_count + Context::MIN_CONTEXT_SLOTS; |
1269 a.AllocateArray(context_length, factory()->function_context_map()); | 1275 a.AllocateArray(context_length, factory()->function_context_map()); |
1270 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); | 1276 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); |
1271 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); | 1277 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); |
1272 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), extension); | 1278 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), extension); |
1273 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); | 1279 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); |
1274 for (int i = Context::MIN_CONTEXT_SLOTS; i < context_length; ++i) { | 1280 for (int i = Context::MIN_CONTEXT_SLOTS; i < context_length; ++i) { |
1275 a.Store(AccessBuilder::ForContextSlot(i), jsgraph()->TheHoleConstant()); | 1281 a.Store(AccessBuilder::ForContextSlot(i), jsgraph()->TheHoleConstant()); |
1276 } | 1282 } |
1277 // TODO(mstarzinger): We could mutate {node} into the allocation instead. | 1283 RelaxControls(node); |
1278 NodeProperties::SetType(a.allocation(), NodeProperties::GetType(node)); | 1284 a.Finish(node); |
1279 ReplaceWithValue(node, node, a.effect()); | |
1280 node->ReplaceInput(0, a.allocation()); | |
1281 node->ReplaceInput(1, a.effect()); | |
1282 node->TrimInputCount(2); | |
1283 NodeProperties::ChangeOp(node, common()->Finish(1)); | |
1284 return Changed(node); | 1285 return Changed(node); |
1285 } | 1286 } |
1286 | 1287 |
1287 // Use the FastNewContextStub only for function contexts up maximum size. | 1288 // Use the FastNewContextStub only for function contexts up maximum size. |
1288 if (slot_count <= FastNewContextStub::kMaximumSlots) { | 1289 if (slot_count <= FastNewContextStub::kMaximumSlots) { |
1289 Isolate* isolate = jsgraph()->isolate(); | 1290 Isolate* isolate = jsgraph()->isolate(); |
1290 Callable callable = CodeFactory::FastNewContext(isolate, slot_count); | 1291 Callable callable = CodeFactory::FastNewContext(isolate, slot_count); |
1291 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | 1292 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
1292 isolate, graph()->zone(), callable.descriptor(), 0, | 1293 isolate, graph()->zone(), callable.descriptor(), 0, |
1293 CallDescriptor::kNoFlags); | 1294 CallDescriptor::kNoFlags); |
(...skipping 24 matching lines...) Expand all Loading... |
1318 simplified()->LoadField( | 1319 simplified()->LoadField( |
1319 AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX)), | 1320 AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX)), |
1320 context, effect, control); | 1321 context, effect, control); |
1321 AllocationBuilder a(jsgraph(), simplified(), effect, control); | 1322 AllocationBuilder a(jsgraph(), simplified(), effect, control); |
1322 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. | 1323 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. |
1323 a.AllocateArray(Context::MIN_CONTEXT_SLOTS, factory()->with_context_map()); | 1324 a.AllocateArray(Context::MIN_CONTEXT_SLOTS, factory()->with_context_map()); |
1324 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); | 1325 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); |
1325 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); | 1326 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); |
1326 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), input); | 1327 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), input); |
1327 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); | 1328 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); |
1328 // TODO(mstarzinger): We could mutate {node} into the allocation instead. | 1329 RelaxControls(node); |
1329 NodeProperties::SetType(a.allocation(), NodeProperties::GetType(node)); | 1330 a.Finish(node); |
1330 ReplaceWithValue(node, node, a.effect()); | |
1331 node->ReplaceInput(0, a.allocation()); | |
1332 node->ReplaceInput(1, a.effect()); | |
1333 node->TrimInputCount(2); | |
1334 NodeProperties::ChangeOp(node, common()->Finish(1)); | |
1335 return Changed(node); | 1331 return Changed(node); |
1336 } | 1332 } |
1337 | 1333 |
1338 return NoChange(); | 1334 return NoChange(); |
1339 } | 1335 } |
1340 | 1336 |
1341 | 1337 |
1342 Reduction JSTypedLowering::ReduceJSCreateBlockContext(Node* node) { | 1338 Reduction JSTypedLowering::ReduceJSCreateBlockContext(Node* node) { |
1343 DCHECK_EQ(IrOpcode::kJSCreateBlockContext, node->opcode()); | 1339 DCHECK_EQ(IrOpcode::kJSCreateBlockContext, node->opcode()); |
1344 Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node); | 1340 Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node); |
(...skipping 14 matching lines...) Expand all Loading... |
1359 AllocationBuilder a(jsgraph(), simplified(), effect, control); | 1355 AllocationBuilder a(jsgraph(), simplified(), effect, control); |
1360 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. | 1356 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); // Ensure fully covered. |
1361 a.AllocateArray(context_length, factory()->block_context_map()); | 1357 a.AllocateArray(context_length, factory()->block_context_map()); |
1362 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); | 1358 a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure); |
1363 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); | 1359 a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context); |
1364 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), extension); | 1360 a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), extension); |
1365 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); | 1361 a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load); |
1366 for (int i = Context::MIN_CONTEXT_SLOTS; i < context_length; ++i) { | 1362 for (int i = Context::MIN_CONTEXT_SLOTS; i < context_length; ++i) { |
1367 a.Store(AccessBuilder::ForContextSlot(i), jsgraph()->TheHoleConstant()); | 1363 a.Store(AccessBuilder::ForContextSlot(i), jsgraph()->TheHoleConstant()); |
1368 } | 1364 } |
1369 // TODO(mstarzinger): We could mutate {node} into the allocation instead. | 1365 RelaxControls(node); |
1370 NodeProperties::SetType(a.allocation(), NodeProperties::GetType(node)); | 1366 a.Finish(node); |
1371 ReplaceWithValue(node, node, a.effect()); | |
1372 node->ReplaceInput(0, a.allocation()); | |
1373 node->ReplaceInput(1, a.effect()); | |
1374 node->TrimInputCount(2); | |
1375 NodeProperties::ChangeOp(node, common()->Finish(1)); | |
1376 return Changed(node); | 1367 return Changed(node); |
1377 } | 1368 } |
1378 | 1369 |
1379 return NoChange(); | 1370 return NoChange(); |
1380 } | 1371 } |
1381 | 1372 |
1382 | 1373 |
1383 Reduction JSTypedLowering::ReduceJSCallFunction(Node* node) { | 1374 Reduction JSTypedLowering::ReduceJSCallFunction(Node* node) { |
1384 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); | 1375 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); |
1385 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); | 1376 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1830 } | 1821 } |
1831 | 1822 |
1832 | 1823 |
1833 MachineOperatorBuilder* JSTypedLowering::machine() const { | 1824 MachineOperatorBuilder* JSTypedLowering::machine() const { |
1834 return jsgraph()->machine(); | 1825 return jsgraph()->machine(); |
1835 } | 1826 } |
1836 | 1827 |
1837 } // namespace compiler | 1828 } // namespace compiler |
1838 } // namespace internal | 1829 } // namespace internal |
1839 } // namespace v8 | 1830 } // namespace v8 |
OLD | NEW |