OLD | NEW |
1 | 1 |
2 // Copyright 2015 the V8 project authors. All rights reserved. | 2 // Copyright 2015 the V8 project authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 | 5 |
6 #include "src/compiler/js-intrinsic-lowering.h" | 6 #include "src/compiler/js-intrinsic-lowering.h" |
7 | 7 |
8 #include <stack> | 8 #include <stack> |
9 | 9 |
| 10 #include "src/code-factory.h" |
10 #include "src/compiler/access-builder.h" | 11 #include "src/compiler/access-builder.h" |
11 #include "src/compiler/js-graph.h" | 12 #include "src/compiler/js-graph.h" |
| 13 #include "src/compiler/linkage.h" |
12 #include "src/compiler/node-matchers.h" | 14 #include "src/compiler/node-matchers.h" |
13 #include "src/compiler/node-properties.h" | 15 #include "src/compiler/node-properties.h" |
14 | 16 |
15 namespace v8 { | 17 namespace v8 { |
16 namespace internal { | 18 namespace internal { |
17 namespace compiler { | 19 namespace compiler { |
18 | 20 |
19 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) | 21 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) |
20 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} | 22 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
21 | 23 |
22 | 24 |
23 Reduction JSIntrinsicLowering::Reduce(Node* node) { | 25 Reduction JSIntrinsicLowering::Reduce(Node* node) { |
24 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); | 26 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); |
25 const Runtime::Function* const f = | 27 const Runtime::Function* const f = |
26 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); | 28 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); |
27 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); | 29 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); |
28 switch (f->function_id) { | 30 switch (f->function_id) { |
29 case Runtime::kInlineConstructDouble: | 31 case Runtime::kInlineConstructDouble: |
30 return ReduceConstructDouble(node); | 32 return ReduceConstructDouble(node); |
| 33 case Runtime::kInlineCreateArrayLiteral: |
| 34 return ReduceCreateArrayLiteral(node); |
| 35 case Runtime::kInlineCreateObjectLiteral: |
| 36 return ReduceCreateObjectLiteral(node); |
31 case Runtime::kInlineDeoptimizeNow: | 37 case Runtime::kInlineDeoptimizeNow: |
32 return ReduceDeoptimizeNow(node); | 38 return ReduceDeoptimizeNow(node); |
33 case Runtime::kInlineDoubleHi: | 39 case Runtime::kInlineDoubleHi: |
34 return ReduceDoubleHi(node); | 40 return ReduceDoubleHi(node); |
35 case Runtime::kInlineDoubleLo: | 41 case Runtime::kInlineDoubleLo: |
36 return ReduceDoubleLo(node); | 42 return ReduceDoubleLo(node); |
37 case Runtime::kInlineHeapObjectGetMap: | 43 case Runtime::kInlineHeapObjectGetMap: |
38 return ReduceHeapObjectGetMap(node); | 44 return ReduceHeapObjectGetMap(node); |
39 case Runtime::kInlineIncrementStatsCounter: | 45 case Runtime::kInlineIncrementStatsCounter: |
40 return ReduceIncrementStatsCounter(node); | 46 return ReduceIncrementStatsCounter(node); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 Node* value = | 93 Node* value = |
88 graph()->NewNode(machine()->Float64InsertHighWord32(), | 94 graph()->NewNode(machine()->Float64InsertHighWord32(), |
89 graph()->NewNode(machine()->Float64InsertLowWord32(), | 95 graph()->NewNode(machine()->Float64InsertLowWord32(), |
90 jsgraph()->Constant(0), low), | 96 jsgraph()->Constant(0), low), |
91 high); | 97 high); |
92 NodeProperties::ReplaceWithValue(node, value); | 98 NodeProperties::ReplaceWithValue(node, value); |
93 return Replace(value); | 99 return Replace(value); |
94 } | 100 } |
95 | 101 |
96 | 102 |
| 103 Reduction JSIntrinsicLowering::ReduceCreateArrayLiteral(Node* node) { |
| 104 HeapObjectMatcher<FixedArray> mconst(NodeProperties::GetValueInput(node, 2)); |
| 105 NumberMatcher mflags(NodeProperties::GetValueInput(node, 3)); |
| 106 int length = mconst.Value().handle()->length(); |
| 107 int flags = FastD2I(mflags.Value()); |
| 108 |
| 109 // Use the FastCloneShallowArrayStub only for shallow boilerplates up to the |
| 110 // initial length limit for arrays with "fast" elements kind. |
| 111 if ((flags & ArrayLiteral::kShallowElements) != 0 && |
| 112 length < JSObject::kInitialMaxFastElementArray) { |
| 113 Isolate* isolate = jsgraph()->isolate(); |
| 114 Callable callable = CodeFactory::FastCloneShallowArray(isolate); |
| 115 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 116 isolate, graph()->zone(), callable.descriptor(), 0, |
| 117 FLAG_turbo_deoptimization ? CallDescriptor::kNeedsFrameState |
| 118 : CallDescriptor::kNoFlags); |
| 119 const Operator* new_op = common()->Call(desc); |
| 120 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
| 121 node->RemoveInput(3); // Remove flags input from node. |
| 122 node->InsertInput(graph()->zone(), 0, stub_code); |
| 123 node->set_op(new_op); |
| 124 return Changed(node); |
| 125 } |
| 126 |
| 127 return NoChange(); |
| 128 } |
| 129 |
| 130 |
| 131 Reduction JSIntrinsicLowering::ReduceCreateObjectLiteral(Node* node) { |
| 132 HeapObjectMatcher<FixedArray> mconst(NodeProperties::GetValueInput(node, 2)); |
| 133 NumberMatcher mflags(NodeProperties::GetValueInput(node, 3)); |
| 134 // Constants are pairs, see ObjectLiteral::properties_count(). |
| 135 int length = mconst.Value().handle()->length() / 2; |
| 136 int flags = FastD2I(mflags.Value()); |
| 137 |
| 138 // Use the FastCloneShallowObjectStub only for shallow boilerplates without |
| 139 // elements up to the number of properties that the stubs can handle. |
| 140 if ((flags & ObjectLiteral::kShallowProperties) != 0 && |
| 141 length <= FastCloneShallowObjectStub::kMaximumClonedProperties) { |
| 142 Isolate* isolate = jsgraph()->isolate(); |
| 143 Callable callable = CodeFactory::FastCloneShallowObject(isolate, length); |
| 144 CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
| 145 isolate, graph()->zone(), callable.descriptor(), 0, |
| 146 FLAG_turbo_deoptimization ? CallDescriptor::kNeedsFrameState |
| 147 : CallDescriptor::kNoFlags); |
| 148 const Operator* new_op = common()->Call(desc); |
| 149 Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
| 150 node->InsertInput(graph()->zone(), 0, stub_code); |
| 151 node->set_op(new_op); |
| 152 return Changed(node); |
| 153 } |
| 154 |
| 155 return NoChange(); |
| 156 } |
| 157 |
| 158 |
97 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { | 159 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { |
98 if (!FLAG_turbo_deoptimization) return NoChange(); | 160 if (!FLAG_turbo_deoptimization) return NoChange(); |
99 | 161 |
100 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); | 162 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); |
101 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); | 163 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); |
102 | 164 |
103 Node* effect = NodeProperties::GetEffectInput(node); | 165 Node* effect = NodeProperties::GetEffectInput(node); |
104 Node* control = NodeProperties::GetControlInput(node); | 166 Node* control = NodeProperties::GetControlInput(node); |
105 | 167 |
106 // We are making the continuation after the call dead. To | 168 // We are making the continuation after the call dead. To |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 486 } |
425 | 487 |
426 | 488 |
427 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 489 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
428 return jsgraph()->machine(); | 490 return jsgraph()->machine(); |
429 } | 491 } |
430 | 492 |
431 } // namespace compiler | 493 } // namespace compiler |
432 } // namespace internal | 494 } // namespace internal |
433 } // namespace v8 | 495 } // namespace v8 |
OLD | NEW |