Chromium Code Reviews| 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) { | |
|
Michael Starzinger
2016/09/13 11:04:38
This case only checks whether we are storing to th
Benedikt Meurer
2016/09/13 11:05:04
Done.
| |
| 307 HeapObjectMatcher m(NodeProperties::GetValueInput(dominator, 1)); | |
| 308 if (!m.HasValue()) return true; | |
| 309 Handle<Map> const map = Handle<Map>::cast(m.Value()); | |
| 310 if (!map->IsJSReceiverMap()) return true; | |
| 311 return false; | |
| 312 } | |
| 313 break; | |
| 314 } | |
| 315 case IrOpcode::kStoreElement: | |
| 316 case IrOpcode::kStoreTypedElement: | |
| 317 break; | |
| 318 default: { | |
| 319 DCHECK_EQ(1, dominator->op()->EffectOutputCount()); | |
| 320 if (dominator->op()->EffectInputCount() != 1 || | |
| 321 !dominator->op()->HasProperty(Operator::kNoWrite)) { | |
| 322 // Didn't find any appropriate CheckMaps node. | |
| 323 return true; | |
| 324 } | |
| 325 break; | |
| 326 } | |
| 327 } | |
| 328 dominator = NodeProperties::GetEffectInput(dominator); | |
| 329 } | |
| 330 } | |
| 331 | |
| 278 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? | 332 // TODO(mstarzinger,verwaest): Move this predicate onto SharedFunctionInfo? |
| 279 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { | 333 bool NeedsImplicitReceiver(Handle<SharedFunctionInfo> shared_info) { |
| 280 DisallowHeapAllocation no_gc; | 334 DisallowHeapAllocation no_gc; |
| 281 Isolate* const isolate = shared_info->GetIsolate(); | 335 Isolate* const isolate = shared_info->GetIsolate(); |
| 282 Code* const construct_stub = shared_info->construct_stub(); | 336 Code* const construct_stub = shared_info->construct_stub(); |
| 283 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub() && | 337 return construct_stub != *isolate->builtins()->JSBuiltinsConstructStub() && |
| 284 construct_stub != | 338 construct_stub != |
| 285 *isolate->builtins()->JSBuiltinsConstructStubForDerived() && | 339 *isolate->builtins()->JSBuiltinsConstructStubForDerived() && |
| 286 construct_stub != *isolate->builtins()->JSConstructStubApi(); | 340 construct_stub != *isolate->builtins()->JSConstructStubApi(); |
| 287 } | 341 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 Node* context = jsgraph()->Constant(handle(function->context())); | 608 Node* context = jsgraph()->Constant(handle(function->context())); |
| 555 | 609 |
| 556 // Insert a JSConvertReceiver node for sloppy callees. Note that the context | 610 // 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 | 611 // 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 | 612 // 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 | 613 // 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 | 614 // in that frame state tho, as the conversion of the receiver can be repeated |
| 561 // any number of times, it's not observable. | 615 // any number of times, it's not observable. |
| 562 if (node->opcode() == IrOpcode::kJSCallFunction && | 616 if (node->opcode() == IrOpcode::kJSCallFunction && |
| 563 is_sloppy(parse_info.language_mode()) && !shared_info->native()) { | 617 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); | 618 Node* effect = NodeProperties::GetEffectInput(node); |
| 567 Node* convert = graph()->NewNode( | 619 if (NeedsConvertReceiver(call.receiver(), effect)) { |
| 568 javascript()->ConvertReceiver(p.convert_mode()), call.receiver(), | 620 const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); |
| 569 context, frame_state_before, effect, start); | 621 Node* frame_state_before = NodeProperties::FindFrameStateBefore(node); |
| 570 NodeProperties::ReplaceValueInput(node, convert, 1); | 622 Node* convert = effect = graph()->NewNode( |
| 571 NodeProperties::ReplaceEffectInput(node, convert); | 623 javascript()->ConvertReceiver(p.convert_mode()), call.receiver(), |
| 624 context, frame_state_before, effect, start); | |
| 625 NodeProperties::ReplaceValueInput(node, convert, 1); | |
| 626 NodeProperties::ReplaceEffectInput(node, effect); | |
| 627 } | |
| 572 } | 628 } |
| 573 | 629 |
| 574 // If we are inlining a JS call at tail position then we have to pop current | 630 // 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 | 631 // frame state and its potential arguments adaptor frame state in order to |
| 576 // make the call stack be consistent with non-inlining case. | 632 // make the call stack be consistent with non-inlining case. |
| 577 // After that we add a tail caller frame state which lets deoptimizer handle | 633 // 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 | 634 // the case when the outermost function inlines a tail call (it should remove |
| 579 // potential arguments adaptor frame that belongs to outermost function when | 635 // potential arguments adaptor frame that belongs to outermost function when |
| 580 // deopt happens). | 636 // deopt happens). |
| 581 if (node->opcode() == IrOpcode::kJSCallFunction) { | 637 if (node->opcode() == IrOpcode::kJSCallFunction) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 609 | 665 |
| 610 CommonOperatorBuilder* JSInliner::common() const { return jsgraph()->common(); } | 666 CommonOperatorBuilder* JSInliner::common() const { return jsgraph()->common(); } |
| 611 | 667 |
| 612 SimplifiedOperatorBuilder* JSInliner::simplified() const { | 668 SimplifiedOperatorBuilder* JSInliner::simplified() const { |
| 613 return jsgraph()->simplified(); | 669 return jsgraph()->simplified(); |
| 614 } | 670 } |
| 615 | 671 |
| 616 } // namespace compiler | 672 } // namespace compiler |
| 617 } // namespace internal | 673 } // namespace internal |
| 618 } // namespace v8 | 674 } // namespace v8 |
| OLD | NEW |