OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 | 9 |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 5679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5690 summary->set_in(0, Location::RequiresRegister()); | 5690 summary->set_in(0, Location::RequiresRegister()); |
5691 return summary; | 5691 return summary; |
5692 } | 5692 } |
5693 | 5693 |
5694 | 5694 |
5695 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 5695 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
5696 Register value = locs()->in(0).reg(); | 5696 Register value = locs()->in(0).reg(); |
5697 Label* deopt = compiler->AddDeoptStub(deopt_id(), | 5697 Label* deopt = compiler->AddDeoptStub(deopt_id(), |
5698 ICData::kDeoptCheckSmi, | 5698 ICData::kDeoptCheckSmi, |
5699 licm_hoisted_ ? ICData::kHoisted : 0); | 5699 licm_hoisted_ ? ICData::kHoisted : 0); |
5700 __ testq(value, Immediate(kSmiTagMask)); | 5700 __ BranchIfNotSmi(value, deopt); |
5701 __ j(NOT_ZERO, deopt); | |
5702 } | 5701 } |
5703 | 5702 |
5704 | 5703 |
5705 LocationSummary* CheckClassIdInstr::MakeLocationSummary(Zone* zone, | 5704 LocationSummary* CheckClassIdInstr::MakeLocationSummary(Zone* zone, |
5706 bool opt) const { | 5705 bool opt) const { |
5707 const intptr_t kNumInputs = 1; | 5706 const intptr_t kNumInputs = 1; |
5708 const intptr_t kNumTemps = 0; | 5707 const intptr_t kNumTemps = 0; |
5709 LocationSummary* summary = new(zone) LocationSummary( | 5708 LocationSummary* summary = new(zone) LocationSummary( |
5710 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); | 5709 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
5711 summary->set_in(0, Location::RequiresRegister()); | 5710 summary->set_in(0, Location::RequiresRegister()); |
5712 return summary; | 5711 return summary; |
5713 } | 5712 } |
5714 | 5713 |
5715 | 5714 |
5716 void CheckClassIdInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 5715 void CheckClassIdInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
5717 Register value = locs()->in(0).reg(); | 5716 Register value = locs()->in(0).reg(); |
5718 Label* deopt = compiler->AddDeoptStub(deopt_id(), ICData::kDeoptCheckClass); | 5717 Label* deopt = compiler->AddDeoptStub(deopt_id(), ICData::kDeoptCheckClass); |
5719 __ CompareImmediate(value, Immediate(Smi::RawValue(cid_))); | 5718 __ CompareImmediate(value, Immediate(Smi::RawValue(cid_))); |
5720 __ j(NOT_ZERO, deopt); | 5719 __ j(NOT_ZERO, deopt); |
5721 } | 5720 } |
5722 | 5721 |
5723 | 5722 |
| 5723 LocationSummary* GenericCheckBoundInstr::MakeLocationSummary(Zone* zone, |
| 5724 bool opt) const { |
| 5725 const intptr_t kNumInputs = 2; |
| 5726 const intptr_t kNumTemps = 0; |
| 5727 LocationSummary* locs = new(zone) LocationSummary( |
| 5728 zone, kNumInputs, kNumTemps, LocationSummary::kCallOnSlowPath); |
| 5729 locs->set_in(kLengthPos, Location::RequiresRegister()); |
| 5730 locs->set_in(kIndexPos, Location::RequiresRegister()); |
| 5731 return locs; |
| 5732 } |
| 5733 |
| 5734 |
| 5735 class RangeErrorSlowPath : public SlowPathCode { |
| 5736 public: |
| 5737 RangeErrorSlowPath(GenericCheckBoundInstr* instruction, intptr_t try_index) |
| 5738 : instruction_(instruction), try_index_(try_index) { } |
| 5739 |
| 5740 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5741 if (Assembler::EmittingComments()) { |
| 5742 __ Comment("slow path check bound operation"); |
| 5743 } |
| 5744 __ Bind(entry_label()); |
| 5745 LocationSummary* locs = instruction_->locs(); |
| 5746 __ pushq(locs->in(0).reg()); |
| 5747 __ pushq(locs->in(1).reg()); |
| 5748 __ CallRuntime(kRangeErrorRuntimeEntry, 2); |
| 5749 compiler->pc_descriptors_list()->AddDescriptor( |
| 5750 RawPcDescriptors::kOther, |
| 5751 compiler->assembler()->CodeSize(), |
| 5752 instruction_->deopt_id(), |
| 5753 instruction_->token_pos(), |
| 5754 try_index_); |
| 5755 compiler->RecordSafepoint(locs, 2); |
| 5756 __ int3(); |
| 5757 } |
| 5758 |
| 5759 private: |
| 5760 GenericCheckBoundInstr* instruction_; |
| 5761 intptr_t try_index_; |
| 5762 }; |
| 5763 |
| 5764 |
| 5765 void GenericCheckBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5766 RangeErrorSlowPath* slow_path = |
| 5767 new RangeErrorSlowPath(this, compiler->CurrentTryIndex()); |
| 5768 compiler->AddSlowPathCode(slow_path); |
| 5769 |
| 5770 Location length_loc = locs()->in(kLengthPos); |
| 5771 Location index_loc = locs()->in(kIndexPos); |
| 5772 Register length = length_loc.reg(); |
| 5773 Register index = index_loc.reg(); |
| 5774 const intptr_t index_cid = this->index()->Type()->ToCid(); |
| 5775 if (index_cid != kSmiCid) { |
| 5776 __ BranchIfNotSmi(index, slow_path->entry_label()); |
| 5777 } |
| 5778 __ cmpq(index, length); |
| 5779 __ j(ABOVE_EQUAL, slow_path->entry_label()); |
| 5780 } |
| 5781 |
| 5782 |
5724 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone, | 5783 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone, |
5725 bool opt) const { | 5784 bool opt) const { |
5726 const intptr_t kNumInputs = 2; | 5785 const intptr_t kNumInputs = 2; |
5727 const intptr_t kNumTemps = 0; | 5786 const intptr_t kNumTemps = 0; |
5728 LocationSummary* locs = new(zone) LocationSummary( | 5787 LocationSummary* locs = new(zone) LocationSummary( |
5729 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); | 5788 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
5730 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length())); | 5789 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length())); |
5731 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index())); | 5790 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index())); |
5732 return locs; | 5791 return locs; |
5733 } | 5792 } |
(...skipping 13 matching lines...) Expand all Loading... |
5747 if (length_loc.IsConstant() && index_loc.IsConstant()) { | 5806 if (length_loc.IsConstant() && index_loc.IsConstant()) { |
5748 ASSERT((Smi::Cast(length_loc.constant()).Value() <= | 5807 ASSERT((Smi::Cast(length_loc.constant()).Value() <= |
5749 Smi::Cast(index_loc.constant()).Value()) || | 5808 Smi::Cast(index_loc.constant()).Value()) || |
5750 (Smi::Cast(index_loc.constant()).Value() < 0)); | 5809 (Smi::Cast(index_loc.constant()).Value() < 0)); |
5751 // Unconditionally deoptimize for constant bounds checks because they | 5810 // Unconditionally deoptimize for constant bounds checks because they |
5752 // only occur only when index is out-of-bounds. | 5811 // only occur only when index is out-of-bounds. |
5753 __ jmp(deopt); | 5812 __ jmp(deopt); |
5754 return; | 5813 return; |
5755 } | 5814 } |
5756 | 5815 |
| 5816 const intptr_t index_cid = index()->Type()->ToCid(); |
5757 if (index_loc.IsConstant()) { | 5817 if (index_loc.IsConstant()) { |
5758 Register length = length_loc.reg(); | 5818 Register length = length_loc.reg(); |
5759 const Smi& index = Smi::Cast(index_loc.constant()); | 5819 const Smi& index = Smi::Cast(index_loc.constant()); |
5760 __ CompareImmediate( | 5820 __ CompareImmediate( |
5761 length, Immediate(reinterpret_cast<int64_t>(index.raw()))); | 5821 length, Immediate(reinterpret_cast<int64_t>(index.raw()))); |
5762 __ j(BELOW_EQUAL, deopt); | 5822 __ j(BELOW_EQUAL, deopt); |
5763 } else if (length_loc.IsConstant()) { | 5823 } else if (length_loc.IsConstant()) { |
5764 const Smi& length = Smi::Cast(length_loc.constant()); | 5824 const Smi& length = Smi::Cast(length_loc.constant()); |
5765 Register index = index_loc.reg(); | 5825 Register index = index_loc.reg(); |
| 5826 if (index_cid != kSmiCid) { |
| 5827 __ BranchIfNotSmi(index, deopt); |
| 5828 } |
5766 if (length.Value() == Smi::kMaxValue) { | 5829 if (length.Value() == Smi::kMaxValue) { |
5767 __ testq(index, index); | 5830 __ testq(index, index); |
5768 __ j(NEGATIVE, deopt); | 5831 __ j(NEGATIVE, deopt); |
5769 } else { | 5832 } else { |
5770 __ CompareImmediate( | 5833 __ CompareImmediate( |
5771 index, Immediate(reinterpret_cast<int64_t>(length.raw()))); | 5834 index, Immediate(reinterpret_cast<int64_t>(length.raw()))); |
5772 __ j(ABOVE_EQUAL, deopt); | 5835 __ j(ABOVE_EQUAL, deopt); |
5773 } | 5836 } |
5774 } else { | 5837 } else { |
5775 Register length = length_loc.reg(); | 5838 Register length = length_loc.reg(); |
5776 Register index = index_loc.reg(); | 5839 Register index = index_loc.reg(); |
| 5840 if (index_cid != kSmiCid) { |
| 5841 __ BranchIfNotSmi(index, deopt); |
| 5842 } |
5777 __ cmpq(index, length); | 5843 __ cmpq(index, length); |
5778 __ j(ABOVE_EQUAL, deopt); | 5844 __ j(ABOVE_EQUAL, deopt); |
5779 } | 5845 } |
5780 } | 5846 } |
5781 | 5847 |
5782 | 5848 |
5783 template<typename OperandType> | 5849 template<typename OperandType> |
5784 static void EmitInt64Arithmetic(FlowGraphCompiler* compiler, | 5850 static void EmitInt64Arithmetic(FlowGraphCompiler* compiler, |
5785 Token::Kind op_kind, | 5851 Token::Kind op_kind, |
5786 Register left, | 5852 Register left, |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6552 __ Drop(1); | 6618 __ Drop(1); |
6553 __ popq(result); | 6619 __ popq(result); |
6554 } | 6620 } |
6555 | 6621 |
6556 | 6622 |
6557 } // namespace dart | 6623 } // namespace dart |
6558 | 6624 |
6559 #undef __ | 6625 #undef __ |
6560 | 6626 |
6561 #endif // defined TARGET_ARCH_X64 | 6627 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |