| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
| 6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 5236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5247 summary->set_in(0, Location::RequiresRegister()); | 5247 summary->set_in(0, Location::RequiresRegister()); |
| 5248 return summary; | 5248 return summary; |
| 5249 } | 5249 } |
| 5250 | 5250 |
| 5251 | 5251 |
| 5252 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 5252 void CheckSmiInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5253 const Register value = locs()->in(0).reg(); | 5253 const Register value = locs()->in(0).reg(); |
| 5254 Label* deopt = compiler->AddDeoptStub(deopt_id(), | 5254 Label* deopt = compiler->AddDeoptStub(deopt_id(), |
| 5255 ICData::kDeoptCheckSmi, | 5255 ICData::kDeoptCheckSmi, |
| 5256 licm_hoisted_ ? ICData::kHoisted : 0); | 5256 licm_hoisted_ ? ICData::kHoisted : 0); |
| 5257 __ tsti(value, Immediate(kSmiTagMask)); | 5257 __ BranchIfNotSmi(value, deopt); |
| 5258 __ b(deopt, NE); | |
| 5259 } | 5258 } |
| 5260 | 5259 |
| 5261 | 5260 |
| 5261 |
| 5262 LocationSummary* GenericCheckBoundInstr::MakeLocationSummary(Zone* zone, |
| 5263 bool opt) const { |
| 5264 const intptr_t kNumInputs = 2; |
| 5265 const intptr_t kNumTemps = 0; |
| 5266 LocationSummary* locs = new(zone) LocationSummary( |
| 5267 zone, kNumInputs, kNumTemps, LocationSummary::kCallOnSlowPath); |
| 5268 locs->set_in(kLengthPos, Location::RequiresRegister()); |
| 5269 locs->set_in(kIndexPos, Location::RequiresRegister()); |
| 5270 return locs; |
| 5271 } |
| 5272 |
| 5273 |
| 5274 class RangeErrorSlowPath : public SlowPathCode { |
| 5275 public: |
| 5276 RangeErrorSlowPath(GenericCheckBoundInstr* instruction, intptr_t try_index) |
| 5277 : instruction_(instruction), try_index_(try_index) { } |
| 5278 |
| 5279 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5280 if (Assembler::EmittingComments()) { |
| 5281 __ Comment("slow path check bound operation"); |
| 5282 } |
| 5283 __ Bind(entry_label()); |
| 5284 LocationSummary* locs = instruction_->locs(); |
| 5285 __ Push(locs->in(0).reg()); |
| 5286 __ Push(locs->in(1).reg()); |
| 5287 __ CallRuntime(kRangeErrorRuntimeEntry, 2); |
| 5288 compiler->pc_descriptors_list()->AddDescriptor( |
| 5289 RawPcDescriptors::kOther, |
| 5290 compiler->assembler()->CodeSize(), |
| 5291 instruction_->deopt_id(), |
| 5292 instruction_->token_pos(), |
| 5293 try_index_); |
| 5294 compiler->RecordSafepoint(locs, 2); |
| 5295 __ brk(0); |
| 5296 } |
| 5297 |
| 5298 private: |
| 5299 GenericCheckBoundInstr* instruction_; |
| 5300 intptr_t try_index_; |
| 5301 }; |
| 5302 |
| 5303 |
| 5304 void GenericCheckBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5305 RangeErrorSlowPath* slow_path = |
| 5306 new RangeErrorSlowPath(this, compiler->CurrentTryIndex()); |
| 5307 compiler->AddSlowPathCode(slow_path); |
| 5308 |
| 5309 Location length_loc = locs()->in(kLengthPos); |
| 5310 Location index_loc = locs()->in(kIndexPos); |
| 5311 Register length = length_loc.reg(); |
| 5312 Register index = index_loc.reg(); |
| 5313 const intptr_t index_cid = this->index()->Type()->ToCid(); |
| 5314 if (index_cid != kSmiCid) { |
| 5315 __ BranchIfNotSmi(index, slow_path->entry_label()); |
| 5316 } |
| 5317 __ cmp(index, Operand(length)); |
| 5318 __ b(slow_path->entry_label(), CS); |
| 5319 } |
| 5320 |
| 5321 |
| 5262 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone, | 5322 LocationSummary* CheckArrayBoundInstr::MakeLocationSummary(Zone* zone, |
| 5263 bool opt) const { | 5323 bool opt) const { |
| 5264 const intptr_t kNumInputs = 2; | 5324 const intptr_t kNumInputs = 2; |
| 5265 const intptr_t kNumTemps = 0; | 5325 const intptr_t kNumTemps = 0; |
| 5266 LocationSummary* locs = new(zone) LocationSummary( | 5326 LocationSummary* locs = new(zone) LocationSummary( |
| 5267 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); | 5327 zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 5268 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length())); | 5328 locs->set_in(kLengthPos, Location::RegisterOrSmiConstant(length())); |
| 5269 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index())); | 5329 locs->set_in(kIndexPos, Location::RegisterOrSmiConstant(index())); |
| 5270 return locs; | 5330 return locs; |
| 5271 } | 5331 } |
| 5272 | 5332 |
| 5273 | 5333 |
| 5274 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 5334 void CheckArrayBoundInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 5275 uint32_t flags = generalized_ ? ICData::kGeneralized : 0; | 5335 uint32_t flags = generalized_ ? ICData::kGeneralized : 0; |
| 5276 flags |= licm_hoisted_ ? ICData::kHoisted : 0; | 5336 flags |= licm_hoisted_ ? ICData::kHoisted : 0; |
| 5277 Label* deopt = compiler->AddDeoptStub( | 5337 Label* deopt = compiler->AddDeoptStub( |
| 5278 deopt_id(), | 5338 deopt_id(), |
| 5279 ICData::kDeoptCheckArrayBound, | 5339 ICData::kDeoptCheckArrayBound, |
| 5280 flags); | 5340 flags); |
| 5281 | 5341 |
| 5282 Location length_loc = locs()->in(kLengthPos); | 5342 Location length_loc = locs()->in(kLengthPos); |
| 5283 Location index_loc = locs()->in(kIndexPos); | 5343 Location index_loc = locs()->in(kIndexPos); |
| 5284 | 5344 |
| 5345 const intptr_t index_cid = index()->Type()->ToCid(); |
| 5285 if (length_loc.IsConstant() && index_loc.IsConstant()) { | 5346 if (length_loc.IsConstant() && index_loc.IsConstant()) { |
| 5286 // TODO(srdjan): remove this code once failures are fixed. | 5347 // TODO(srdjan): remove this code once failures are fixed. |
| 5287 if ((Smi::Cast(length_loc.constant()).Value() > | 5348 if ((Smi::Cast(length_loc.constant()).Value() > |
| 5288 Smi::Cast(index_loc.constant()).Value()) && | 5349 Smi::Cast(index_loc.constant()).Value()) && |
| 5289 (Smi::Cast(index_loc.constant()).Value() >= 0)) { | 5350 (Smi::Cast(index_loc.constant()).Value() >= 0)) { |
| 5290 // This CheckArrayBoundInstr should have been eliminated. | 5351 // This CheckArrayBoundInstr should have been eliminated. |
| 5291 return; | 5352 return; |
| 5292 } | 5353 } |
| 5293 ASSERT((Smi::Cast(length_loc.constant()).Value() <= | 5354 ASSERT((Smi::Cast(length_loc.constant()).Value() <= |
| 5294 Smi::Cast(index_loc.constant()).Value()) || | 5355 Smi::Cast(index_loc.constant()).Value()) || |
| 5295 (Smi::Cast(index_loc.constant()).Value() < 0)); | 5356 (Smi::Cast(index_loc.constant()).Value() < 0)); |
| 5296 // Unconditionally deoptimize for constant bounds checks because they | 5357 // Unconditionally deoptimize for constant bounds checks because they |
| 5297 // only occur only when index is out-of-bounds. | 5358 // only occur only when index is out-of-bounds. |
| 5298 __ b(deopt); | 5359 __ b(deopt); |
| 5299 return; | 5360 return; |
| 5300 } | 5361 } |
| 5301 | 5362 |
| 5302 if (index_loc.IsConstant()) { | 5363 if (index_loc.IsConstant()) { |
| 5303 const Register length = length_loc.reg(); | 5364 const Register length = length_loc.reg(); |
| 5304 const Smi& index = Smi::Cast(index_loc.constant()); | 5365 const Smi& index = Smi::Cast(index_loc.constant()); |
| 5305 __ CompareImmediate(length, reinterpret_cast<int64_t>(index.raw())); | 5366 __ CompareImmediate(length, reinterpret_cast<int64_t>(index.raw())); |
| 5306 __ b(deopt, LS); | 5367 __ b(deopt, LS); |
| 5307 } else if (length_loc.IsConstant()) { | 5368 } else if (length_loc.IsConstant()) { |
| 5308 const Smi& length = Smi::Cast(length_loc.constant()); | 5369 const Smi& length = Smi::Cast(length_loc.constant()); |
| 5309 const Register index = index_loc.reg(); | 5370 const Register index = index_loc.reg(); |
| 5371 if (index_cid != kSmiCid) { |
| 5372 __ BranchIfNotSmi(index, deopt); |
| 5373 } |
| 5310 if (length.Value() == Smi::kMaxValue) { | 5374 if (length.Value() == Smi::kMaxValue) { |
| 5311 __ tst(index, Operand(index)); | 5375 __ tst(index, Operand(index)); |
| 5312 __ b(deopt, MI); | 5376 __ b(deopt, MI); |
| 5313 } else { | 5377 } else { |
| 5314 __ CompareImmediate(index, reinterpret_cast<int64_t>(length.raw())); | 5378 __ CompareImmediate(index, reinterpret_cast<int64_t>(length.raw())); |
| 5315 __ b(deopt, CS); | 5379 __ b(deopt, CS); |
| 5316 } | 5380 } |
| 5317 } else { | 5381 } else { |
| 5318 const Register length = length_loc.reg(); | 5382 const Register length = length_loc.reg(); |
| 5319 const Register index = index_loc.reg(); | 5383 const Register index = index_loc.reg(); |
| 5384 if (index_cid != kSmiCid) { |
| 5385 __ BranchIfNotSmi(index, deopt); |
| 5386 } |
| 5320 __ CompareRegisters(index, length); | 5387 __ CompareRegisters(index, length); |
| 5321 __ b(deopt, CS); | 5388 __ b(deopt, CS); |
| 5322 } | 5389 } |
| 5323 } | 5390 } |
| 5324 | 5391 |
| 5325 | 5392 |
| 5326 LocationSummary* BinaryMintOpInstr::MakeLocationSummary(Zone* zone, | 5393 LocationSummary* BinaryMintOpInstr::MakeLocationSummary(Zone* zone, |
| 5327 bool opt) const { | 5394 bool opt) const { |
| 5328 UNIMPLEMENTED(); | 5395 UNIMPLEMENTED(); |
| 5329 return NULL; | 5396 return NULL; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5717 1, | 5784 1, |
| 5718 locs()); | 5785 locs()); |
| 5719 __ Drop(1); | 5786 __ Drop(1); |
| 5720 __ Pop(result); | 5787 __ Pop(result); |
| 5721 } | 5788 } |
| 5722 | 5789 |
| 5723 | 5790 |
| 5724 } // namespace dart | 5791 } // namespace dart |
| 5725 | 5792 |
| 5726 #endif // defined TARGET_ARCH_ARM64 | 5793 #endif // defined TARGET_ARCH_ARM64 |
| OLD | NEW |