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

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
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 if (value()->ResultCid() == kSmiCid) {
2234 return new LocationSummary(0, 0, LocationSummary::kNoCall);
2235 }
2233 const intptr_t kNumInputs = 1; 2236 const intptr_t kNumInputs = 1;
2234 const intptr_t kNumTemps = 0; 2237 const intptr_t kNumTemps = 0;
2235 LocationSummary* summary = 2238 LocationSummary* summary =
2236 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2239 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2237 summary->set_in(0, Location::RequiresRegister()); 2240 summary->set_in(0, Location::RequiresRegister());
2238 return summary; 2241 return summary;
2239 } 2242 }
2240 2243
2241 2244
2242 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2245 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2246 if (value()->ResultCid() == kSmiCid) return;
2243 Register value = locs()->in(0).reg(); 2247 Register value = locs()->in(0).reg();
2244 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2248 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2245 kDeoptCheckSmi); 2249 kDeoptCheckSmi);
2246 __ testq(value, Immediate(kSmiTagMask)); 2250 __ testq(value, Immediate(kSmiTagMask));
2247 __ j(NOT_ZERO, deopt); 2251 __ j(NOT_ZERO, deopt);
2248 } 2252 }
2249 2253
2250 2254
2251 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const { 2255 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const {
2252 const intptr_t kNumInputs = 2; 2256 const intptr_t kNumInputs = 2;
2253 const intptr_t kNumTemps = 0; 2257 const intptr_t kNumTemps = 0;
2254 LocationSummary* locs = 2258 LocationSummary* locs =
2255 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2259 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2256 locs->set_in(0, Location::RequiresRegister()); 2260 locs->set_in(0, Location::RequiresRegister());
2257 locs->set_in(1, Location::RegisterOrConstant(index())); 2261 locs->set_in(1, Location::RegisterOrConstant(index()));
2258 return locs; 2262 return locs;
2259 } 2263 }
2260 2264
2261 2265
2262 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2266 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2263 Register receiver = locs()->in(0).reg();
2264
2265 const DeoptReasonId deopt_reason = 2267 const DeoptReasonId deopt_reason =
2266 (array_type() == kGrowableObjectArrayCid) ? 2268 (array_type() == kGrowableObjectArrayCid) ?
2267 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray; 2269 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2268 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2270 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2269 deopt_reason); 2271 deopt_reason);
2270 ASSERT(array_type() == kArrayCid || 2272 ASSERT(array_type() == kArrayCid ||
2271 array_type() == kImmutableArrayCid || 2273 array_type() == kImmutableArrayCid ||
2272 array_type() == kGrowableObjectArrayCid); 2274 array_type() == kGrowableObjectArrayCid);
2273 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid) 2275 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid)
2274 ? GrowableObjectArray::length_offset() 2276 ? GrowableObjectArray::length_offset()
2275 : Array::length_offset(); 2277 : Array::length_offset();
2276 2278
2279 // This case should not have created a bound check instruction.
2280 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2281
2277 if (locs()->in(1).IsConstant()) { 2282 if (locs()->in(1).IsConstant()) {
2283 Register receiver = locs()->in(0).reg();
2278 const Object& constant = locs()->in(1).constant(); 2284 const Object& constant = locs()->in(1).constant();
2279 ASSERT(constant.IsSmi()); 2285 ASSERT(constant.IsSmi());
2280 const int64_t imm = 2286 const int64_t imm =
2281 reinterpret_cast<int64_t>(constant.raw()); 2287 reinterpret_cast<int64_t>(constant.raw());
2282 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm)); 2288 __ cmpq(FieldAddress(receiver, length_offset), Immediate(imm));
2283 __ j(BELOW_EQUAL, deopt); 2289 __ j(BELOW_EQUAL, deopt);
2290 } else if (locs()->in(0).IsConstant()) {
2291 const Object& constant = locs()->in(0).constant();
2292 ASSERT(constant.IsArray());
2293 const Array& array = Array::Cast(constant);
2294 Register index = locs()->in(1).reg();
2295 __ cmpq(index, Immediate(array.Length()));
2296 __ j(ABOVE_EQUAL, deopt);
2284 } else { 2297 } else {
2298 Register receiver = locs()->in(0).reg();
2285 Register index = locs()->in(1).reg(); 2299 Register index = locs()->in(1).reg();
2286 __ cmpq(index, FieldAddress(receiver, length_offset)); 2300 __ cmpq(index, FieldAddress(receiver, length_offset));
2287 __ j(ABOVE_EQUAL, deopt); 2301 __ j(ABOVE_EQUAL, deopt);
2288 } 2302 }
2289 } 2303 }
2290 2304
2291 2305
2292 } // namespace dart 2306 } // namespace dart
2293 2307
2294 #undef __ 2308 #undef __
2295 2309
2296 #endif // defined TARGET_ARCH_X64 2310 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698