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

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

Issue 10911277: Optimize code for bound checks if array is constant. Skip unnecessary Smi checks if they still surv… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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_ia32.cc ('k') | tests/language/optimized_lists.dart » ('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) 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/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 2212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 } else { 2223 } else {
2224 __ j(EQUAL, &is_ok); 2224 __ j(EQUAL, &is_ok);
2225 } 2225 }
2226 } 2226 }
2227 } 2227 }
2228 __ Bind(&is_ok); 2228 __ Bind(&is_ok);
2229 } 2229 }
2230 2230
2231 2231
2232 LocationSummary* CheckSmiInstr::MakeLocationSummary() const { 2232 LocationSummary* CheckSmiInstr::MakeLocationSummary() const {
2233 // TODO(srdjan): Check if we can remove this by reordering CSE and LICM.
2234 if (value()->ResultCid() == kSmiCid) {
2235 return new LocationSummary(0, 0, LocationSummary::kNoCall);
2236 }
2233 const intptr_t kNumInputs = 1; 2237 const intptr_t kNumInputs = 1;
2234 const intptr_t kNumTemps = 0; 2238 const intptr_t kNumTemps = 0;
2235 LocationSummary* summary = 2239 LocationSummary* summary =
2236 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2240 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2237 summary->set_in(0, Location::RequiresRegister()); 2241 summary->set_in(0, Location::RequiresRegister());
2238 return summary; 2242 return summary;
2239 } 2243 }
2240 2244
2241 2245
2242 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2246 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2247 // TODO(srdjan): Check if we can remove this by reordering CSE and LICM.
2248 if (value()->ResultCid() == kSmiCid) return;
2243 Register value = locs()->in(0).reg(); 2249 Register value = locs()->in(0).reg();
2244 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2250 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2245 kDeoptCheckSmi); 2251 kDeoptCheckSmi);
2246 __ testq(value, Immediate(kSmiTagMask)); 2252 __ testq(value, Immediate(kSmiTagMask));
2247 __ j(NOT_ZERO, deopt); 2253 __ j(NOT_ZERO, deopt);
2248 } 2254 }
2249 2255
2250 2256
2251 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const { 2257 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const {
2252 const intptr_t kNumInputs = 2; 2258 const intptr_t kNumInputs = 2;
2253 const intptr_t kNumTemps = 0; 2259 const intptr_t kNumTemps = 0;
2254 LocationSummary* locs = 2260 LocationSummary* locs =
2255 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2261 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2256 locs->set_in(0, Location::RequiresRegister()); 2262 locs->set_in(0, Location::RequiresRegister());
2257 locs->set_in(1, Location::RegisterOrConstant(index())); 2263 locs->set_in(1, Location::RegisterOrConstant(index()));
2258 return locs; 2264 return locs;
2259 } 2265 }
2260 2266
2261 2267
2262 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2268 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2263 Register receiver = locs()->in(0).reg();
2264
2265 const DeoptReasonId deopt_reason = 2269 const DeoptReasonId deopt_reason =
2266 (array_type() == kGrowableObjectArrayCid) ? 2270 (array_type() == kGrowableObjectArrayCid) ?
2267 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray; 2271 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2268 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2272 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2269 deopt_reason); 2273 deopt_reason);
2270 ASSERT(array_type() == kArrayCid || 2274 ASSERT(array_type() == kArrayCid ||
2271 array_type() == kImmutableArrayCid || 2275 array_type() == kImmutableArrayCid ||
2272 array_type() == kGrowableObjectArrayCid); 2276 array_type() == kGrowableObjectArrayCid);
2273 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid) 2277 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid)
2274 ? GrowableObjectArray::length_offset() 2278 ? GrowableObjectArray::length_offset()
2275 : Array::length_offset(); 2279 : Array::length_offset();
2276 2280
2281 // This case should not have created a bound check instruction.
2282 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2283
2277 if (locs()->in(1).IsConstant()) { 2284 if (locs()->in(1).IsConstant()) {
2285 Register receiver = locs()->in(0).reg();
2278 const Object& constant = locs()->in(1).constant(); 2286 const Object& constant = locs()->in(1).constant();
2279 ASSERT(constant.IsSmi()); 2287 ASSERT(constant.IsSmi());
2280 const int64_t imm = 2288 const int64_t imm =
2281 reinterpret_cast<int64_t>(constant.raw()); 2289 reinterpret_cast<int64_t>(constant.raw());
2282 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm)); 2290 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm));
2283 __ j(BELOW_EQUAL, deopt); 2291 __ j(BELOW_EQUAL, deopt);
2292 } else if (locs()->in(0).IsConstant()) {
2293 const Object& constant = locs()->in(0).constant();
2294 ASSERT(constant.IsArray());
2295 const Array& array = Array::Cast(constant);
2296 Register index = locs()->in(1).reg();
2297 __ cmpq(index, Immediate(array.Length()));
2298 __ j(ABOVE_EQUAL, deopt);
2284 } else { 2299 } else {
2300 Register receiver = locs()->in(0).reg();
2285 Register index = locs()->in(1).reg(); 2301 Register index = locs()->in(1).reg();
2286 __ cmpq(index, FieldAddress(receiver, length_offset)); 2302 __ cmpq(index, FieldAddress(receiver, length_offset));
2287 __ j(ABOVE_EQUAL, deopt); 2303 __ j(ABOVE_EQUAL, deopt);
2288 } 2304 }
2289 } 2305 }
2290 2306
2291 2307
2292 } // namespace dart 2308 } // namespace dart
2293 2309
2294 #undef __ 2310 #undef __
2295 2311
2296 #endif // defined TARGET_ARCH_X64 2312 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_ia32.cc ('k') | tests/language/optimized_lists.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698