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-intrinsic-lowering.h" | 5 #include "src/compiler/js-intrinsic-lowering.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "src/code-factory.h" | |
10 #include "src/compiler/access-builder.h" | 9 #include "src/compiler/access-builder.h" |
11 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
12 #include "src/compiler/linkage.h" | |
13 #include "src/compiler/node-matchers.h" | 11 #include "src/compiler/node-matchers.h" |
14 #include "src/compiler/node-properties.h" | 12 #include "src/compiler/node-properties.h" |
15 #include "src/compiler/operator-properties.h" | 13 #include "src/compiler/operator-properties.h" |
16 | 14 |
17 namespace v8 { | 15 namespace v8 { |
18 namespace internal { | 16 namespace internal { |
19 namespace compiler { | 17 namespace compiler { |
20 | 18 |
21 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) | 19 JSIntrinsicLowering::JSIntrinsicLowering(JSGraph* jsgraph) |
22 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} | 20 : jsgraph_(jsgraph), simplified_(jsgraph->zone()) {} |
23 | 21 |
24 | 22 |
25 Reduction JSIntrinsicLowering::Reduce(Node* node) { | 23 Reduction JSIntrinsicLowering::Reduce(Node* node) { |
26 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); | 24 if (node->opcode() != IrOpcode::kJSCallRuntime) return NoChange(); |
27 const Runtime::Function* const f = | 25 const Runtime::Function* const f = |
28 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); | 26 Runtime::FunctionForId(CallRuntimeParametersOf(node->op()).id()); |
29 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); | 27 if (f->intrinsic_type != Runtime::IntrinsicType::INLINE) return NoChange(); |
30 switch (f->function_id) { | 28 switch (f->function_id) { |
31 case Runtime::kInlineConstructDouble: | 29 case Runtime::kInlineConstructDouble: |
32 return ReduceConstructDouble(node); | 30 return ReduceConstructDouble(node); |
33 case Runtime::kInlineCreateArrayLiteral: | |
34 return ReduceCreateArrayLiteral(node); | |
35 case Runtime::kInlineCreateObjectLiteral: | |
36 return ReduceCreateObjectLiteral(node); | |
37 case Runtime::kInlineDeoptimizeNow: | 31 case Runtime::kInlineDeoptimizeNow: |
38 return ReduceDeoptimizeNow(node); | 32 return ReduceDeoptimizeNow(node); |
39 case Runtime::kInlineDoubleHi: | 33 case Runtime::kInlineDoubleHi: |
40 return ReduceDoubleHi(node); | 34 return ReduceDoubleHi(node); |
41 case Runtime::kInlineDoubleLo: | 35 case Runtime::kInlineDoubleLo: |
42 return ReduceDoubleLo(node); | 36 return ReduceDoubleLo(node); |
43 case Runtime::kInlineHeapObjectGetMap: | 37 case Runtime::kInlineHeapObjectGetMap: |
44 return ReduceHeapObjectGetMap(node); | 38 return ReduceHeapObjectGetMap(node); |
45 case Runtime::kInlineIncrementStatsCounter: | 39 case Runtime::kInlineIncrementStatsCounter: |
46 return ReduceIncrementStatsCounter(node); | 40 return ReduceIncrementStatsCounter(node); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 Node* value = | 87 Node* value = |
94 graph()->NewNode(machine()->Float64InsertHighWord32(), | 88 graph()->NewNode(machine()->Float64InsertHighWord32(), |
95 graph()->NewNode(machine()->Float64InsertLowWord32(), | 89 graph()->NewNode(machine()->Float64InsertLowWord32(), |
96 jsgraph()->Constant(0), low), | 90 jsgraph()->Constant(0), low), |
97 high); | 91 high); |
98 NodeProperties::ReplaceWithValue(node, value); | 92 NodeProperties::ReplaceWithValue(node, value); |
99 return Replace(value); | 93 return Replace(value); |
100 } | 94 } |
101 | 95 |
102 | 96 |
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 (OperatorProperties::GetFrameStateInputCount(node->op()) != 0) | |
118 ? CallDescriptor::kNeedsFrameState | |
119 : CallDescriptor::kNoFlags); | |
120 const Operator* new_op = common()->Call(desc); | |
121 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | |
122 node->RemoveInput(3); // Remove flags input from node. | |
123 node->InsertInput(graph()->zone(), 0, stub_code); | |
124 node->set_op(new_op); | |
125 return Changed(node); | |
126 } | |
127 | |
128 return NoChange(); | |
129 } | |
130 | |
131 | |
132 Reduction JSIntrinsicLowering::ReduceCreateObjectLiteral(Node* node) { | |
133 HeapObjectMatcher<FixedArray> mconst(NodeProperties::GetValueInput(node, 2)); | |
134 NumberMatcher mflags(NodeProperties::GetValueInput(node, 3)); | |
135 // Constants are pairs, see ObjectLiteral::properties_count(). | |
136 int length = mconst.Value().handle()->length() / 2; | |
137 int flags = FastD2I(mflags.Value()); | |
138 | |
139 // Use the FastCloneShallowObjectStub only for shallow boilerplates without | |
140 // elements up to the number of properties that the stubs can handle. | |
141 if ((flags & ObjectLiteral::kShallowProperties) != 0 && | |
142 length <= FastCloneShallowObjectStub::kMaximumClonedProperties) { | |
143 Isolate* isolate = jsgraph()->isolate(); | |
144 Callable callable = CodeFactory::FastCloneShallowObject(isolate, length); | |
145 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
146 isolate, graph()->zone(), callable.descriptor(), 0, | |
147 (OperatorProperties::GetFrameStateInputCount(node->op()) != 0) | |
148 ? CallDescriptor::kNeedsFrameState | |
149 : CallDescriptor::kNoFlags); | |
150 const Operator* new_op = common()->Call(desc); | |
151 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | |
152 node->InsertInput(graph()->zone(), 0, stub_code); | |
153 node->set_op(new_op); | |
154 return Changed(node); | |
155 } | |
156 | |
157 return NoChange(); | |
158 } | |
159 | |
160 | |
161 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { | 97 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { |
162 // TODO(jarin): This should not depend on the global flag. | 98 // TODO(jarin): This should not depend on the global flag. |
163 if (!FLAG_turbo_deoptimization) return NoChange(); | 99 if (!FLAG_turbo_deoptimization) return NoChange(); |
164 | 100 |
165 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); | 101 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); |
166 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); | 102 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); |
167 | 103 |
168 Node* effect = NodeProperties::GetEffectInput(node); | 104 Node* effect = NodeProperties::GetEffectInput(node); |
169 Node* control = NodeProperties::GetControlInput(node); | 105 Node* control = NodeProperties::GetControlInput(node); |
170 | 106 |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 } | 425 } |
490 | 426 |
491 | 427 |
492 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 428 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
493 return jsgraph()->machine(); | 429 return jsgraph()->machine(); |
494 } | 430 } |
495 | 431 |
496 } // namespace compiler | 432 } // namespace compiler |
497 } // namespace internal | 433 } // namespace internal |
498 } // namespace v8 | 434 } // namespace v8 |
OLD | NEW |