Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: runtime/vm/intermediate_language_x64.cc

Issue 2149023002: VM: Array bounds checks that don't deoptimize for precompiled code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix dbc build Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 5703 matching lines...) Expand 10 before | Expand all | Expand 10 after
5714 5714
5715 5715
5716 void CheckClassIdInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 5716 void CheckClassIdInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
5717 Register value = locs()->in(0).reg(); 5717 Register value = locs()->in(0).reg();
5718 Label* deopt = compiler->AddDeoptStub(deopt_id(), ICData::kDeoptCheckClass); 5718 Label* deopt = compiler->AddDeoptStub(deopt_id(), ICData::kDeoptCheckClass);
5719 __ CompareImmediate(value, Immediate(Smi::RawValue(cid_))); 5719 __ CompareImmediate(value, Immediate(Smi::RawValue(cid_)));
5720 __ j(NOT_ZERO, deopt); 5720 __ j(NOT_ZERO, deopt);
5721 } 5721 }
5722 5722
5723 5723
5724 LocationSummary* GenericCheckBoundInstr::MakeLocationSummary(Zone* zone,
5725 bool opt) const {
5726 const intptr_t kNumInputs = 2;
5727 const intptr_t kNumTemps = 0;
5728 LocationSummary* locs = new(zone) LocationSummary(
5729 zone, kNumInputs, kNumTemps, LocationSummary::kCallOnSlowPath);
5730 locs->set_in(kLengthPos, Location::RequiresRegister());
5731 locs->set_in(kIndexPos, Location::RequiresRegister());
5732 return locs;
5733 }
5734
5735
5736 class RangeErrorSlowPath : public SlowPathCode {
5737 public:
5738 RangeErrorSlowPath(GenericCheckBoundInstr* instruction, intptr_t try_index)
5739 : instruction_(instruction), try_index_(try_index) { }
5740
5741 virtual void EmitNativeCode(FlowGraphCompiler* compiler) {
5742 if (Assembler::EmittingComments()) {
5743 __ Comment("slow path check bound operation");
5744 }
5745 __ Bind(entry_label());
5746 LocationSummary* locs = instruction_->locs();
5747 __ pushq(locs->in(0).reg());
5748 __ pushq(locs->in(1).reg());
5749 compiler->GenerateRuntimeCall(instruction_->token_pos(),
5750 instruction_->deopt_id(),
5751 kRangeErrorRuntimeEntry,
5752 2,
5753 instruction_->locs());
5754 compiler->RecordSafepoint(locs, /* slow_path_argument_count = */ 2);
5755 compiler->pc_descriptors_list()->AddDescriptor(
5756 RawPcDescriptors::kOther,
5757 compiler->assembler()->CodeSize(),
5758 instruction_->deopt_id(),
5759 instruction_->token_pos(),
5760 try_index_);
5761 __ int3();
5762 }
5763
5764 private:
5765 GenericCheckBoundInstr* instruction_;
5766 intptr_t try_index_;
5767 };
5768
5769
5770 void GenericCheckBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
5771 RangeErrorSlowPath* slow_path =
5772 new RangeErrorSlowPath(this, compiler->CurrentTryIndex());
5773 compiler->AddSlowPathCode(slow_path);
5774
5775 Location length_loc = locs()->in(kLengthPos);
5776 Location index_loc = locs()->in(kIndexPos);
5777 Register length = length_loc.reg();
5778 Register index = index_loc.reg();
5779 const intptr_t index_cid = this->index()->Type()->ToCid();
5780 if (index_cid != kSmiCid) {
5781 __ testq(index, Immediate(kSmiTagMask));
5782 __ j(NOT_ZERO, slow_path->entry_label());
5783 }
5784 __ cmpq(index, length);
5785 __ j(ABOVE_EQUAL, slow_path->entry_label());
5786 }
5787
5788
5724 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone, 5789 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone,
5725 bool opt) const { 5790 bool opt) const {
5726 const intptr_t kNumInputs = 2; 5791 const intptr_t kNumInputs = 2;
5727 const intptr_t kNumTemps = 0; 5792 const intptr_t kNumTemps = 0;
5728 LocationSummary* locs = new(zone) LocationSummary( 5793 LocationSummary* locs = new(zone) LocationSummary(
5729 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); 5794 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
5730 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length())); 5795 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length()));
5731 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index())); 5796 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index()));
5732 return locs; 5797 return locs;
5733 } 5798 }
(...skipping 13 matching lines...) Expand all
5747 if (length_loc.IsConstant() && index_loc.IsConstant()) { 5812 if (length_loc.IsConstant() && index_loc.IsConstant()) {
5748 ASSERT((Smi::Cast(length_loc.constant()).Value() <= 5813 ASSERT((Smi::Cast(length_loc.constant()).Value() <=
5749 Smi::Cast(index_loc.constant()).Value()) || 5814 Smi::Cast(index_loc.constant()).Value()) ||
5750 (Smi::Cast(index_loc.constant()).Value() < 0)); 5815 (Smi::Cast(index_loc.constant()).Value() < 0));
5751 // Unconditionally deoptimize for constant bounds checks because they 5816 // Unconditionally deoptimize for constant bounds checks because they
5752 // only occur only when index is out-of-bounds. 5817 // only occur only when index is out-of-bounds.
5753 __ jmp(deopt); 5818 __ jmp(deopt);
5754 return; 5819 return;
5755 } 5820 }
5756 5821
5822 const intptr_t index_cid = index()->Type()->ToCid();
5757 if (index_loc.IsConstant()) { 5823 if (index_loc.IsConstant()) {
5758 Register length = length_loc.reg(); 5824 Register length = length_loc.reg();
5759 const Smi& index = Smi::Cast(index_loc.constant()); 5825 const Smi& index = Smi::Cast(index_loc.constant());
5760 __ CompareImmediate( 5826 __ CompareImmediate(
5761 length, Immediate(reinterpret_cast<int64_t>(index.raw()))); 5827 length, Immediate(reinterpret_cast<int64_t>(index.raw())));
5762 __ j(BELOW_EQUAL, deopt); 5828 __ j(BELOW_EQUAL, deopt);
5763 } else if (length_loc.IsConstant()) { 5829 } else if (length_loc.IsConstant()) {
5764 const Smi& length = Smi::Cast(length_loc.constant()); 5830 const Smi& length = Smi::Cast(length_loc.constant());
5765 Register index = index_loc.reg(); 5831 Register index = index_loc.reg();
5832 if (index_cid != kSmiCid) {
5833 __ testq(index, Immediate(kSmiTagMask));
5834 __ j(NOT_ZERO, deopt);
5835 }
5766 if (length.Value() == Smi::kMaxValue) { 5836 if (length.Value() == Smi::kMaxValue) {
5767 __ testq(index, index); 5837 __ testq(index, index);
5768 __ j(NEGATIVE, deopt); 5838 __ j(NEGATIVE, deopt);
5769 } else { 5839 } else {
5770 __ CompareImmediate( 5840 __ CompareImmediate(
5771 index, Immediate(reinterpret_cast<int64_t>(length.raw()))); 5841 index, Immediate(reinterpret_cast<int64_t>(length.raw())));
5772 __ j(ABOVE_EQUAL, deopt); 5842 __ j(ABOVE_EQUAL, deopt);
5773 } 5843 }
5774 } else { 5844 } else {
5775 Register length = length_loc.reg(); 5845 Register length = length_loc.reg();
5776 Register index = index_loc.reg(); 5846 Register index = index_loc.reg();
5847 if (index_cid != kSmiCid) {
5848 __ testq(index, Immediate(kSmiTagMask));
5849 __ j(NOT_ZERO, deopt);
5850 }
5777 __ cmpq(index, length); 5851 __ cmpq(index, length);
5778 __ j(ABOVE_EQUAL, deopt); 5852 __ j(ABOVE_EQUAL, deopt);
5779 } 5853 }
5780 } 5854 }
5781 5855
5782 5856
5783 template<typename OperandType> 5857 template<typename OperandType>
5784 static void EmitInt64Arithmetic(FlowGraphCompiler* compiler, 5858 static void EmitInt64Arithmetic(FlowGraphCompiler* compiler,
5785 Token::Kind op_kind, 5859 Token::Kind op_kind,
5786 Register left, 5860 Register left,
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
6552 __ Drop(1); 6626 __ Drop(1);
6553 __ popq(result); 6627 __ popq(result);
6554 } 6628 }
6555 6629
6556 6630
6557 } // namespace dart 6631 } // namespace dart
6558 6632
6559 #undef __ 6633 #undef __
6560 6634
6561 #endif // defined TARGET_ARCH_X64 6635 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698