OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 #include "vm/locations.h" | 9 #include "vm/locations.h" |
| 10 #include "vm/object_store.h" |
10 #include "vm/stub_code.h" | 11 #include "vm/stub_code.h" |
11 | 12 |
12 #define __ compiler->assembler()-> | 13 #define __ compiler->assembler()-> |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
16 | 17 |
17 // True iff. the arguments to a call will be properly pushed and can | 18 // True iff. the arguments to a call will be properly pushed and can |
18 // be popped after the call. | 19 // be popped after the call. |
19 template <typename T> static bool VerifyCallComputation(T* comp) { | 20 template <typename T> static bool VerifyCallComputation(T* comp) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 } | 131 } |
131 | 132 |
132 | 133 |
133 LocationSummary* InstanceCallComp::MakeLocationSummary() const { | 134 LocationSummary* InstanceCallComp::MakeLocationSummary() const { |
134 return MakeCallSummary(); | 135 return MakeCallSummary(); |
135 } | 136 } |
136 | 137 |
137 | 138 |
138 void InstanceCallComp::EmitNativeCode(FlowGraphCompiler* compiler) { | 139 void InstanceCallComp::EmitNativeCode(FlowGraphCompiler* compiler) { |
139 ASSERT(VerifyCallComputation(this)); | 140 ASSERT(VerifyCallComputation(this)); |
| 141 compiler->AddCurrentDescriptor(PcDescriptors::kDeopt, |
| 142 cid(), |
| 143 token_index(), |
| 144 try_index()); |
140 compiler->EmitInstanceCall(cid(), | 145 compiler->EmitInstanceCall(cid(), |
141 token_index(), | 146 token_index(), |
142 try_index(), | 147 try_index(), |
143 function_name(), | 148 function_name(), |
144 ArgumentCount(), | 149 ArgumentCount(), |
145 argument_names(), | 150 argument_names(), |
146 checked_argument_count()); | 151 checked_argument_count()); |
147 } | 152 } |
148 | 153 |
149 | 154 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 void CatchEntryComp::EmitNativeCode(FlowGraphCompiler* compiler) { | 482 void CatchEntryComp::EmitNativeCode(FlowGraphCompiler* compiler) { |
478 UNIMPLEMENTED(); | 483 UNIMPLEMENTED(); |
479 } | 484 } |
480 | 485 |
481 | 486 |
482 LocationSummary* CatchEntryComp::MakeLocationSummary() const { | 487 LocationSummary* CatchEntryComp::MakeLocationSummary() const { |
483 return NULL; | 488 return NULL; |
484 } | 489 } |
485 | 490 |
486 | 491 |
| 492 LocationSummary* BinaryOpComp::MakeLocationSummary() const { |
| 493 return MakeSimpleLocationSummary(2, Location::RequiresRegister()); |
| 494 } |
| 495 |
| 496 |
| 497 // TODO(srdjan): Implement variations. |
| 498 static bool EmitSmiBinaryOp(FlowGraphCompiler* compiler, |
| 499 BinaryOpComp* comp) { |
| 500 ASSERT((comp->ic_data() != NULL)); |
| 501 const ICData& ic_data = *comp->ic_data(); |
| 502 if (ic_data.IsNull()) return false; |
| 503 if (ic_data.num_args_tested() != 2) return false; |
| 504 if (ic_data.NumberOfChecks() != 1) return false; |
| 505 Function& target = Function::Handle(); |
| 506 GrowableArray<const Class*> classes; |
| 507 ic_data.GetCheckAt(0, &classes, &target); |
| 508 const Class& smi_class = |
| 509 Class::Handle(Isolate::Current()->object_store()->smi_class()); |
| 510 if ((classes[0]->raw() != smi_class.raw()) || |
| 511 (classes[1]->raw() != smi_class.raw())) { |
| 512 return false; |
| 513 } |
| 514 // TODO(srdjan): need to allocate a temporary register (now using r10) |
| 515 Register left = comp->locs()->in(0).reg(); |
| 516 Register right = comp->locs()->in(1).reg(); |
| 517 Register result = comp->locs()->out().reg(); |
| 518 Register kTemp = R10; |
| 519 Label* deopt = compiler->AddDeoptStub(comp->instance_call()->cid(), |
| 520 comp->instance_call()->token_index(), |
| 521 comp->instance_call()->try_index(), |
| 522 kDeoptSmiBinaryOp, |
| 523 kTemp, |
| 524 right); |
| 525 __ movq(kTemp, left); |
| 526 __ orq(left, right); |
| 527 __ testq(left, Immediate(kSmiTagMask)); |
| 528 __ j(NOT_ZERO, deopt); |
| 529 __ movq(left, kTemp); |
| 530 switch (comp->op_kind()) { |
| 531 case Token::kADD: { |
| 532 __ addq(left, right); |
| 533 __ j(OVERFLOW, deopt); |
| 534 if (result != left) { |
| 535 __ movq(result, left); |
| 536 } |
| 537 break; |
| 538 } |
| 539 default: |
| 540 UNREACHABLE(); |
| 541 } |
| 542 return true; |
| 543 } |
| 544 |
| 545 void BinaryOpComp::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 546 if (EmitSmiBinaryOp(compiler, this)) { |
| 547 // Operation inlined. |
| 548 return; |
| 549 } |
| 550 Register left = locs()->in(0).reg(); |
| 551 Register right = locs()->in(1).reg(); |
| 552 __ pushq(left); |
| 553 __ pushq(right); |
| 554 InstanceCallComp* instance_call_comp = instance_call(); |
| 555 instance_call_comp->EmitNativeCode(compiler); |
| 556 if (locs()->out().reg() != RAX) { |
| 557 __ movq(locs()->out().reg(), RAX); |
| 558 } |
| 559 } |
| 560 |
487 } // namespace dart | 561 } // namespace dart |
488 | 562 |
489 #undef __ | 563 #undef __ |
490 | 564 |
491 #endif // defined TARGET_ARCH_X64 | 565 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |