Chromium Code Reviews| 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 int length = mconst.Value().handle()->length() / 2; | |
|
titzer
2015/04/21 14:02:26
Can we have a comment that this thing takes an arr
Michael Starzinger
2015/04/21 14:35:41
Done.
| |
| 135 int flags = FastD2I(mflags.Value()); | |
| 136 | |
| 137 // Use the FastCloneShallowObjectStub only for shallow boilerplates without | |
| 138 // elements up to the number of properties that the stubs can handle. | |
| 139 if ((flags & ObjectLiteral::kShallowProperties) != 0 && | |
| 140 length <= FastCloneShallowObjectStub::kMaximumClonedProperties) { | |
| 141 Isolate* isolate = jsgraph()->isolate(); | |
| 142 Callable callable = CodeFactory::FastCloneShallowObject(isolate, length); | |
| 143 CallDescriptor* desc = Linkage::GetStubCallDescriptor( | |
| 144 isolate, graph()->zone(), callable.descriptor(), 0, | |
| 145 FLAG_turbo_deoptimization ? CallDescriptor::kNeedsFrameState | |
| 146 : CallDescriptor::kNoFlags); | |
| 147 const Operator* new_op = common()->Call(desc); | |
| 148 Node* stub_code = jsgraph()->HeapConstant(callable.code()); | |
| 149 node->InsertInput(graph()->zone(), 0, stub_code); | |
| 150 node->set_op(new_op); | |
| 151 return Changed(node); | |
| 152 } | |
| 153 | |
| 154 return NoChange(); | |
| 155 } | |
| 156 | |
| 157 | |
| 97 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { | 158 Reduction JSIntrinsicLowering::ReduceDeoptimizeNow(Node* node) { |
| 98 if (!FLAG_turbo_deoptimization) return NoChange(); | 159 if (!FLAG_turbo_deoptimization) return NoChange(); |
| 99 | 160 |
| 100 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); | 161 Node* frame_state = NodeProperties::GetFrameStateInput(node, 0); |
| 101 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); | 162 DCHECK_EQ(frame_state->opcode(), IrOpcode::kFrameState); |
| 102 | 163 |
| 103 Node* effect = NodeProperties::GetEffectInput(node); | 164 Node* effect = NodeProperties::GetEffectInput(node); |
| 104 Node* control = NodeProperties::GetControlInput(node); | 165 Node* control = NodeProperties::GetControlInput(node); |
| 105 | 166 |
| 106 // We are making the continuation after the call dead. To | 167 // We are making the continuation after the call dead. To |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 } | 485 } |
| 425 | 486 |
| 426 | 487 |
| 427 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { | 488 MachineOperatorBuilder* JSIntrinsicLowering::machine() const { |
| 428 return jsgraph()->machine(); | 489 return jsgraph()->machine(); |
| 429 } | 490 } |
| 430 | 491 |
| 431 } // namespace compiler | 492 } // namespace compiler |
| 432 } // namespace internal | 493 } // namespace internal |
| 433 } // namespace v8 | 494 } // namespace v8 |
| OLD | NEW |