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

Side by Side Diff: runtime/vm/intermediate_language_ia32.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_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 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 } else { 2197 } else {
2198 __ j(EQUAL, &is_ok); 2198 __ j(EQUAL, &is_ok);
2199 } 2199 }
2200 } 2200 }
2201 } 2201 }
2202 __ Bind(&is_ok); 2202 __ Bind(&is_ok);
2203 } 2203 }
2204 2204
2205 2205
2206 LocationSummary* CheckSmiInstr::MakeLocationSummary() const { 2206 LocationSummary* CheckSmiInstr::MakeLocationSummary() const {
2207 if (value()->ResultCid() == kSmiCid) {
Vyacheslav Egorov (Google) 2012/09/13 09:27:51 Maybe we should better reorder LICM and CSE?
srdjan 2012/09/13 09:46:45 I will try this in a separate CL (added a TODO her
2208 return new LocationSummary(0, 0, LocationSummary::kNoCall);
2209 }
2207 const intptr_t kNumInputs = 1; 2210 const intptr_t kNumInputs = 1;
2208 const intptr_t kNumTemps = 0; 2211 const intptr_t kNumTemps = 0;
2209 LocationSummary* summary = 2212 LocationSummary* summary =
2210 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2213 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2211 summary->set_in(0, Location::RequiresRegister()); 2214 summary->set_in(0, Location::RequiresRegister());
2212 return summary; 2215 return summary;
2213 } 2216 }
2214 2217
2215 2218
2216 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2219 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2220 if (value()->ResultCid() == kSmiCid) return;
2217 Register value = locs()->in(0).reg(); 2221 Register value = locs()->in(0).reg();
2218 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2222 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2219 kDeoptCheckSmi); 2223 kDeoptCheckSmi);
2220 __ testl(value, Immediate(kSmiTagMask)); 2224 __ testl(value, Immediate(kSmiTagMask));
2221 __ j(NOT_ZERO, deopt); 2225 __ j(NOT_ZERO, deopt);
2222 } 2226 }
2223 2227
2224 2228
2225 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const { 2229 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const {
2226 const intptr_t kNumInputs = 2; 2230 const intptr_t kNumInputs = 2;
2227 const intptr_t kNumTemps = 0; 2231 const intptr_t kNumTemps = 0;
2228 LocationSummary* locs = 2232 LocationSummary* locs =
2229 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2233 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2230 locs->set_in(0, Location::RequiresRegister()); 2234 locs->set_in(0, Location::RegisterOrConstant(array()));
2231 locs->set_in(1, Location::RegisterOrConstant(index())); 2235 locs->set_in(1, Location::RegisterOrConstant(index()));
2232 return locs; 2236 return locs;
2233 } 2237 }
2234 2238
2235 2239
2236 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2240 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2237 Register receiver = locs()->in(0).reg();
2238
2239 const DeoptReasonId deopt_reason = 2241 const DeoptReasonId deopt_reason =
2240 (array_type() == kGrowableObjectArrayCid) ? 2242 (array_type() == kGrowableObjectArrayCid) ?
2241 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray; 2243 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2242 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2244 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2243 deopt_reason); 2245 deopt_reason);
2244 ASSERT(array_type() == kArrayCid || 2246 ASSERT(array_type() == kArrayCid ||
2245 array_type() == kImmutableArrayCid || 2247 array_type() == kImmutableArrayCid ||
2246 array_type() == kGrowableObjectArrayCid); 2248 array_type() == kGrowableObjectArrayCid);
2247 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid) 2249 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid)
2248 ? GrowableObjectArray::length_offset() 2250 ? GrowableObjectArray::length_offset()
2249 : Array::length_offset(); 2251 : Array::length_offset();
2252 // This case should not have created a bound check instruction.
2253 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2250 2254
2251 if (locs()->in(1).IsConstant()) { 2255 if (locs()->in(1).IsConstant()) {
2256 Register receiver = locs()->in(0).reg();
2252 const Object& constant = locs()->in(1).constant(); 2257 const Object& constant = locs()->in(1).constant();
2253 ASSERT(constant.IsSmi()); 2258 ASSERT(constant.IsSmi());
2254 const int32_t imm = 2259 const int32_t imm =
2255 reinterpret_cast<int32_t>(constant.raw()); 2260 reinterpret_cast<int32_t>(constant.raw());
2256 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm)); 2261 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm));
2257 __ j(BELOW_EQUAL, deopt); 2262 __ j(BELOW_EQUAL, deopt);
2263 } else if (locs()->in(0).IsConstant()) {
2264 const Object& constant = locs()->in(0).constant();
2265 ASSERT(constant.IsArray());
2266 const Array& array = Array::Cast(constant);
2267 Register index = locs()->in(1).reg();
2268 __ cmpl(index, Immediate(array.Length()));
2269 __ j(ABOVE_EQUAL, deopt);
2258 } else { 2270 } else {
2271 Register receiver = locs()->in(0).reg();
2259 Register index = locs()->in(1).reg(); 2272 Register index = locs()->in(1).reg();
2260 __ cmpl(index, FieldAddress(receiver, length_offset)); 2273 __ cmpl(index, FieldAddress(receiver, length_offset));
2261 __ j(ABOVE_EQUAL, deopt); 2274 __ j(ABOVE_EQUAL, deopt);
2262 } 2275 }
2263 } 2276 }
2264 2277
2265 2278
2266 } // namespace dart 2279 } // namespace dart
2267 2280
2268 #undef __ 2281 #undef __
2269 2282
2270 #endif // defined TARGET_ARCH_X64 2283 #endif // defined TARGET_ARCH_X64
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698