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