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

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

Issue 14979007: - Canonicalize array bounds checks to avoid deopting when comparing (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 3875 matching lines...) Expand 10 before | Expand all | Expand 10 after
3886 __ testl(value, Immediate(kSmiTagMask)); 3886 __ testl(value, Immediate(kSmiTagMask));
3887 __ j(NOT_ZERO, deopt); 3887 __ j(NOT_ZERO, deopt);
3888 } 3888 }
3889 3889
3890 3890
3891 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const { 3891 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const {
3892 const intptr_t kNumInputs = 2; 3892 const intptr_t kNumInputs = 2;
3893 const intptr_t kNumTemps = 0; 3893 const intptr_t kNumTemps = 0;
3894 LocationSummary* locs = 3894 LocationSummary* locs =
3895 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 3895 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
3896 locs->set_in(0, Location::RegisterOrSmiConstant(length())); 3896 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length()));
3897 locs->set_in(1, Location::RegisterOrSmiConstant(index())); 3897 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index()));
3898 return locs; 3898 return locs;
3899 } 3899 }
3900 3900
3901 3901
3902 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 3902 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
3903 Label* deopt = compiler->AddDeoptStub(deopt_id(), 3903 Label* deopt = compiler->AddDeoptStub(deopt_id(), kDeoptCheckArrayBound);
3904 kDeoptCheckArrayBound); 3904
3905 if (locs()->in(0).IsConstant() && locs()->in(1).IsConstant()) { 3905 Location length_loc = locs()->in(kLengthPos);
3906 Location index_loc = locs()->in(kIndexPos);
3907
3908 if (length_loc.IsConstant() && index_loc.IsConstant()) {
3909 ASSERT((Smi::Cast(length_loc.constant()).Value() <=
3910 Smi::Cast(index_loc.constant()).Value()) ||
3911 (Smi::Cast(index_loc.constant()).Value() < 0));
3906 // Unconditionally deoptimize for constant bounds checks because they 3912 // Unconditionally deoptimize for constant bounds checks because they
3907 // only occur only when index is out-of-bounds. 3913 // only occur only when index is out-of-bounds.
3908 __ jmp(deopt); 3914 __ jmp(deopt);
3909 return; 3915 return;
3910 } 3916 }
3911 3917
3912 if (locs()->in(1).IsConstant()) { 3918 if (index_loc.IsConstant()) {
3913 Register length = locs()->in(0).reg(); 3919 Register length = length_loc.reg();
3914 const Object& constant = locs()->in(1).constant(); 3920 const Object& index = Smi::Cast(index_loc.constant());
3915 ASSERT(constant.IsSmi()); 3921 __ cmpl(length, Immediate(reinterpret_cast<int32_t>(index.raw())));
3916 const int32_t imm =
3917 reinterpret_cast<int32_t>(constant.raw());
3918 __ cmpl(length, Immediate(imm));
3919 __ j(BELOW_EQUAL, deopt); 3922 __ j(BELOW_EQUAL, deopt);
3920 } else if (locs()->in(0).IsConstant()) { 3923 } else if (length_loc.IsConstant()) {
3921 ASSERT(locs()->in(0).constant().IsSmi()); 3924 const Smi& length = Smi::Cast(length_loc.constant());
3922 const Smi& smi_const = Smi::Cast(locs()->in(0).constant()); 3925 Register index = index_loc.reg();
3923 Register index = locs()->in(1).reg(); 3926 __ cmpl(index, Immediate(reinterpret_cast<int32_t>(length.raw())));
3924 __ cmpl(index, Immediate(reinterpret_cast<int32_t>(smi_const.raw())));
3925 __ j(ABOVE_EQUAL, deopt); 3927 __ j(ABOVE_EQUAL, deopt);
3926 } else { 3928 } else {
3927 Register length = locs()->in(0).reg(); 3929 Register length = length_loc.reg();
3928 Register index = locs()->in(1).reg(); 3930 Register index = index_loc.reg();
3929 __ cmpl(index, length); 3931 __ cmpl(index, length);
3930 __ j(ABOVE_EQUAL, deopt); 3932 __ j(ABOVE_EQUAL, deopt);
3931 } 3933 }
3932 } 3934 }
3933 3935
3934 3936
3935 LocationSummary* UnboxIntegerInstr::MakeLocationSummary() const { 3937 LocationSummary* UnboxIntegerInstr::MakeLocationSummary() const {
3936 const intptr_t kNumInputs = 1; 3938 const intptr_t kNumInputs = 1;
3937 const intptr_t value_cid = value()->Type()->ToCid(); 3939 const intptr_t value_cid = value()->Type()->ToCid();
3938 const bool needs_temp = ((value_cid != kSmiCid) && (value_cid != kMintCid)); 3940 const bool needs_temp = ((value_cid != kSmiCid) && (value_cid != kMintCid));
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
4674 PcDescriptors::kOther, 4676 PcDescriptors::kOther,
4675 locs()); 4677 locs());
4676 __ Drop(2); // Discard type arguments and receiver. 4678 __ Drop(2); // Discard type arguments and receiver.
4677 } 4679 }
4678 4680
4679 } // namespace dart 4681 } // namespace dart
4680 4682
4681 #undef __ 4683 #undef __
4682 4684
4683 #endif // defined TARGET_ARCH_IA32 4685 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698