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/compiler/js-inlining.h" | 5 #include "src/compiler/js-inlining.h" |
6 | 6 |
7 #include "src/ast/ast-numbering.h" | 7 #include "src/ast/ast-numbering.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/compilation-info.h" | 9 #include "src/compilation-info.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); | 268 BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); |
269 const Operator* op0 = common()->StateValues(0); | 269 const Operator* op0 = common()->StateValues(0); |
270 Node* node0 = graph()->NewNode(op0); | 270 Node* node0 = graph()->NewNode(op0); |
271 return graph()->NewNode(op, node0, node0, node0, | 271 return graph()->NewNode(op, node0, node0, node0, |
272 jsgraph()->UndefinedConstant(), function, | 272 jsgraph()->UndefinedConstant(), function, |
273 frame_state); | 273 frame_state); |
274 } | 274 } |
275 | 275 |
276 namespace { | 276 namespace { |
277 | 277 |
| 278 // TODO(bmeurer): Unify this with the witness helper functions in the |
| 279 // js-builtin-reducer.cc once we have a better understanding of the |
| 280 // map tracking we want to do, and eventually changed the CheckMaps |
| 281 // operator to carry map constants on the operator instead of inputs. |
| 282 // I.e. if the CheckMaps has some kind of SmallMapSet as operator |
| 283 // parameter, then this could be changed to call a generic |
| 284 // |
| 285 // SmallMapSet NodeProperties::CollectMapWitness(receiver, effect) |
| 286 // |
| 287 // function, which either returns the map set from the CheckMaps or |
| 288 // a singleton set from a StoreField. |
| 289 bool NeedsConvertReceiver(Node* receiver, Node* effect) { |
| 290 for (Node* dominator = effect;;) { |
| 291 if (dominator->opcode() == IrOpcode::kCheckMaps && |
| 292 dominator->InputAt(0) == receiver) { |
| 293 // Check if all maps have the given {instance_type}. |
| 294 for (int i = 1; i < dominator->op()->ValueInputCount(); ++i) { |
| 295 HeapObjectMatcher m(NodeProperties::GetValueInput(dominator, i)); |
| 296 if (!m.HasValue()) return true; |
| 297 Handle<Map> const map = Handle<Map>::cast(m.Value()); |
| 298 if (!map->IsJSReceiverMap()) return true; |
| 299 } |
| 300 return false; |
| 301 } |
| 302 switch (dominator->opcode()) { |
| 303 case IrOpcode::kStoreField: { |
| 304 FieldAccess const& access = FieldAccessOf(dominator->op()); |
| 305 if (access.base_is_tagged == kTaggedBase && |
| 306 access.offset == HeapObject::kMapOffset) { |
| 307 return true; |
| 308 } |
| 309 break; |
| 310 } |
| 311 case IrOpcode::kStoreElement: |
| 312 case IrOpcode::kStoreTypedElement: |
| 313 break; |
| 314 default: { |
| 315 DCHECK_EQ(1, dominator->op()->EffectOutputCount()); |
| 316 if (dominator->op()->EffectInputCount() != 1 || |
| 317 !dominator->op()->HasProperty(Operator::kNoWrite)) { |
| 318 // Didn't find any appropriate CheckMaps node. |
| 319 return true; |
| 320 } |
| 321 break; |
| 322 } |
| 323 } |
| 324 dominator = NodeProperties::GetEffectInput(dominator); |
| 325 } |
| 326 } |
| 327 |
278 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? | 328 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? |
279 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { | 329 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { |
280 DisallowHeapAllocation no_gc; | 330 DisallowHeapAllocation no_gc; |
281 Isolate* const isolate = shared_info->GetIsolate(); | 331 Isolate* const isolate = shared_info->GetIsolate(); |
282 Code* const construct_stub = shared_info->construct_stub(); | 332 Code* const construct_stub = shared_info->construct_stub(); |
283 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub() && | 333 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub() && |
284 construct_stub != | 334 construct_stub != |
285 *isolate->builtins()->JSBuiltinsConstructStubForDerived() && | 335 *isolate->builtins()->JSBuiltinsConstructStubForDerived() && |
286 construct_stub != *isolate->builtins()->JSConstructStubApi(); | 336 construct_stub != *isolate->builtins()->JSConstructStubApi(); |
287 } | 337 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 Node* context = jsgraph()->Constant(handle(function->context())); | 604 Node* context = jsgraph()->Constant(handle(function->context())); |
555 | 605 |
556 // Insert a JSConvertReceiver node for sloppy callees. Note that the context | 606 // Insert a JSConvertReceiver node for sloppy callees. Note that the context |
557 // passed into this node has to be the callees context (loaded above). Note | 607 // passed into this node has to be the callees context (loaded above). Note |
558 // that the frame state passed to the JSConvertReceiver must be the frame | 608 // that the frame state passed to the JSConvertReceiver must be the frame |
559 // state _before_ the call; it is not necessary to fiddle with the receiver | 609 // state _before_ the call; it is not necessary to fiddle with the receiver |
560 // in that frame state tho, as the conversion of the receiver can be repeated | 610 // in that frame state tho, as the conversion of the receiver can be repeated |
561 // any number of times, it's not observable. | 611 // any number of times, it's not observable. |
562 if (node->opcode() == IrOpcode::kJSCallFunction && | 612 if (node->opcode() == IrOpcode::kJSCallFunction && |
563 is_sloppy(parse_info.language_mode()) && !shared_info->native()) { | 613 is_sloppy(parse_info.language_mode()) && !shared_info->native()) { |
564 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); | |
565 Node* frame_state_before = NodeProperties::FindFrameStateBefore(node); | |
566 Node* effect = NodeProperties::GetEffectInput(node); | 614 Node* effect = NodeProperties::GetEffectInput(node); |
567 Node* convert = graph()->NewNode( | 615 if (NeedsConvertReceiver(call.receiver(), effect)) { |
568 javascript()->ConvertReceiver(p.convert_mode()), call.receiver(), | 616 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
569 context, frame_state_before, effect, start); | 617 Node* frame_state_before = NodeProperties::FindFrameStateBefore(node); |
570 NodeProperties::ReplaceValueInput(node, convert, 1); | 618 Node* convert = effect = graph()->NewNode( |
571 NodeProperties::ReplaceEffectInput(node, convert); | 619 javascript()->ConvertReceiver(p.convert_mode()), call.receiver(), |
| 620 context, frame_state_before, effect, start); |
| 621 NodeProperties::ReplaceValueInput(node, convert, 1); |
| 622 NodeProperties::ReplaceEffectInput(node, effect); |
| 623 } |
572 } | 624 } |
573 | 625 |
574 // If we are inlining a JS call at tail position then we have to pop current | 626 // If we are inlining a JS call at tail position then we have to pop current |
575 // frame state and its potential arguments adaptor frame state in order to | 627 // frame state and its potential arguments adaptor frame state in order to |
576 // make the call stack be consistent with non-inlining case. | 628 // make the call stack be consistent with non-inlining case. |
577 // After that we add a tail caller frame state which lets deoptimizer handle | 629 // After that we add a tail caller frame state which lets deoptimizer handle |
578 // the case when the outermost function inlines a tail call (it should remove | 630 // the case when the outermost function inlines a tail call (it should remove |
579 // potential arguments adaptor frame that belongs to outermost function when | 631 // potential arguments adaptor frame that belongs to outermost function when |
580 // deopt happens). | 632 // deopt happens). |
581 if (node->opcode() == IrOpcode::kJSCallFunction) { | 633 if (node->opcode() == IrOpcode::kJSCallFunction) { |
(...skipping 27 matching lines...) Expand all Loading... |
609 | 661 |
610 CommonOperatorBuilder* JSInliner::common() const { return jsgraph()->common(); } | 662 CommonOperatorBuilder* JSInliner::common() const { return jsgraph()->common(); } |
611 | 663 |
612 SimplifiedOperatorBuilder* JSInliner::simplified() const { | 664 SimplifiedOperatorBuilder* JSInliner::simplified() const { |
613 return jsgraph()->simplified(); | 665 return jsgraph()->simplified(); |
614 } | 666 } |
615 | 667 |
616 } // namespace compiler | 668 } // namespace compiler |
617 } // namespace internal | 669 } // namespace internal |
618 } // namespace v8 | 670 } // namespace v8 |
OLD | NEW |