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

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
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('k') | runtime/vm/intermediate_language_x64.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) 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 // TODO(srdjan): Check if we can remove this by reordering CSE and LICM.
2208 if (value()->ResultCid() == kSmiCid) {
2209 return new LocationSummary(0, 0, LocationSummary::kNoCall);
2210 }
2207 const intptr_t kNumInputs = 1; 2211 const intptr_t kNumInputs = 1;
2208 const intptr_t kNumTemps = 0; 2212 const intptr_t kNumTemps = 0;
2209 LocationSummary* summary = 2213 LocationSummary* summary =
2210 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2214 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2211 summary->set_in(0, Location::RequiresRegister()); 2215 summary->set_in(0, Location::RequiresRegister());
2212 return summary; 2216 return summary;
2213 } 2217 }
2214 2218
2215 2219
2216 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2220 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2221 // TODO(srdjan): Check if we can remove this by reordering CSE and LICM.
2222 if (value()->ResultCid() == kSmiCid) return;
2217 Register value = locs()->in(0).reg(); 2223 Register value = locs()->in(0).reg();
2218 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2224 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2219 kDeoptCheckSmi); 2225 kDeoptCheckSmi);
2220 __ testl(value, Immediate(kSmiTagMask)); 2226 __ testl(value, Immediate(kSmiTagMask));
2221 __ j(NOT_ZERO, deopt); 2227 __ j(NOT_ZERO, deopt);
2222 } 2228 }
2223 2229
2224 2230
2225 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const { 2231 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary() const {
2226 const intptr_t kNumInputs = 2; 2232 const intptr_t kNumInputs = 2;
2227 const intptr_t kNumTemps = 0; 2233 const intptr_t kNumTemps = 0;
2228 LocationSummary* locs = 2234 LocationSummary* locs =
2229 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 2235 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
2230 locs->set_in(0, Location::RequiresRegister()); 2236 locs->set_in(0, Location::RegisterOrConstant(array()));
2231 locs->set_in(1, Location::RegisterOrConstant(index())); 2237 locs->set_in(1, Location::RegisterOrConstant(index()));
2232 return locs; 2238 return locs;
2233 } 2239 }
2234 2240
2235 2241
2236 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 2242 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
2237 Register receiver = locs()->in(0).reg();
2238
2239 const DeoptReasonId deopt_reason = 2243 const DeoptReasonId deopt_reason =
2240 (array_type() == kGrowableObjectArrayCid) ? 2244 (array_type() == kGrowableObjectArrayCid) ?
2241 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray; 2245 kDeoptLoadIndexedGrowableArray : kDeoptLoadIndexedFixedArray;
2242 Label* deopt = compiler->AddDeoptStub(deopt_id(), 2246 Label* deopt = compiler->AddDeoptStub(deopt_id(),
2243 deopt_reason); 2247 deopt_reason);
2244 ASSERT(array_type() == kArrayCid || 2248 ASSERT(array_type() == kArrayCid ||
2245 array_type() == kImmutableArrayCid || 2249 array_type() == kImmutableArrayCid ||
2246 array_type() == kGrowableObjectArrayCid); 2250 array_type() == kGrowableObjectArrayCid);
2247 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid) 2251 intptr_t length_offset = (array_type() == kGrowableObjectArrayCid)
2248 ? GrowableObjectArray::length_offset() 2252 ? GrowableObjectArray::length_offset()
2249 : Array::length_offset(); 2253 : Array::length_offset();
2254 // This case should not have created a bound check instruction.
2255 ASSERT(!(locs()->in(0).IsConstant() && locs()->in(1).IsConstant()));
2250 2256
2251 if (locs()->in(1).IsConstant()) { 2257 if (locs()->in(1).IsConstant()) {
2258 Register receiver = locs()->in(0).reg();
2252 const Object& constant = locs()->in(1).constant(); 2259 const Object& constant = locs()->in(1).constant();
2253 ASSERT(constant.IsSmi()); 2260 ASSERT(constant.IsSmi());
2254 const int32_t imm = 2261 const int32_t imm =
2255 reinterpret_cast<int32_t>(constant.raw()); 2262 reinterpret_cast<int32_t>(constant.raw());
2256 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm)); 2263 __ cmpl(FieldAddress(receiver, length_offset), Immediate(imm));
2257 __ j(BELOW_EQUAL, deopt); 2264 __ j(BELOW_EQUAL, deopt);
2265 } else if (locs()->in(0).IsConstant()) {
2266 const Object& constant = locs()->in(0).constant();
2267 ASSERT(constant.IsArray());
2268 const Array& array = Array::Cast(constant);
2269 Register index = locs()->in(1).reg();
2270 __ cmpl(index, Immediate(array.Length()));
2271 __ j(ABOVE_EQUAL, deopt);
2258 } else { 2272 } else {
2273 Register receiver = locs()->in(0).reg();
2259 Register index = locs()->in(1).reg(); 2274 Register index = locs()->in(1).reg();
2260 __ cmpl(index, FieldAddress(receiver, length_offset)); 2275 __ cmpl(index, FieldAddress(receiver, length_offset));
2261 __ j(ABOVE_EQUAL, deopt); 2276 __ j(ABOVE_EQUAL, deopt);
2262 } 2277 }
2263 } 2278 }
2264 2279
2265 2280
2266 } // namespace dart 2281 } // namespace dart
2267 2282
2268 #undef __ 2283 #undef __
2269 2284
2270 #endif // defined TARGET_ARCH_X64 2285 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_optimizer.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698