Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | |
| 6 | #include "src/crankshaft/s390/lithium-codegen-s390.h" |
| 7 | |
| 8 | #include "src/base/bits.h" |
| 9 | #include "src/code-factory.h" |
| 10 | #include "src/code-stubs.h" |
| 11 | #include "src/crankshaft/hydrogen-osr.h" |
| 12 | #include "src/crankshaft/s390/lithium-gap-resolver-s390.h" |
| 13 | #include "src/ic/ic.h" |
| 14 | #include "src/ic/stub-cache.h" |
| 15 | #include "src/profiler/cpu-profiler.h" |
| 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | |
| 20 | class SafepointGenerator final : public CallWrapper { |
| 21 | public: |
| 22 | SafepointGenerator(LCodeGen* codegen, LPointerMap* pointers, |
| 23 | Safepoint::DeoptMode mode) |
| 24 | : codegen_(codegen), pointers_(pointers), deopt_mode_(mode) {} |
| 25 | virtual ~SafepointGenerator() {} |
| 26 | |
| 27 | void BeforeCall(int call_size) const override {} |
| 28 | |
| 29 | void AfterCall() const override { |
| 30 | codegen_->RecordSafepoint(pointers_, deopt_mode_); |
| 31 | } |
| 32 | |
| 33 | private: |
| 34 | LCodeGen* codegen_; |
| 35 | LPointerMap* pointers_; |
| 36 | Safepoint::DeoptMode deopt_mode_; |
| 37 | }; |
| 38 | |
| 39 | #define __ masm()-> |
| 40 | |
| 41 | bool LCodeGen::GenerateCode() { |
| 42 | LPhase phase("Z_Code generation", chunk()); |
| 43 | DCHECK(is_unused()); |
| 44 | status_ = GENERATING; |
| 45 | |
| 46 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 47 | // NONE indicates that the scope shouldn't actually generate code to set up |
| 48 | // the frame (that is done in GeneratePrologue). |
| 49 | FrameScope frame_scope(masm_, StackFrame::NONE); |
| 50 | |
| 51 | return GeneratePrologue() && GenerateBody() && GenerateDeferredCode() && |
| 52 | GenerateJumpTable() && GenerateSafepointTable(); |
| 53 | } |
| 54 | |
| 55 | void LCodeGen::FinishCode(Handle<Code> code) { |
| 56 | DCHECK(is_done()); |
| 57 | code->set_stack_slots(GetTotalFrameSlotCount()); |
| 58 | code->set_safepoint_table_offset(safepoints_.GetCodeOffset()); |
| 59 | PopulateDeoptimizationData(code); |
| 60 | } |
| 61 | |
| 62 | void LCodeGen::SaveCallerDoubles() { |
| 63 | DCHECK(info()->saves_caller_doubles()); |
| 64 | DCHECK(NeedsEagerFrame()); |
| 65 | Comment(";;; Save clobbered callee double registers"); |
| 66 | int count = 0; |
| 67 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 68 | BitVector::Iterator save_iterator(doubles); |
| 69 | while (!save_iterator.Done()) { |
| 70 | __ std(DoubleRegister::from_code(save_iterator.Current()), |
| 71 | MemOperand(sp, count * kDoubleSize)); |
| 72 | save_iterator.Advance(); |
| 73 | count++; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void LCodeGen::RestoreCallerDoubles() { |
| 78 | DCHECK(info()->saves_caller_doubles()); |
| 79 | DCHECK(NeedsEagerFrame()); |
| 80 | Comment(";;; Restore clobbered callee double registers"); |
| 81 | BitVector* doubles = chunk()->allocated_double_registers(); |
| 82 | BitVector::Iterator save_iterator(doubles); |
| 83 | int count = 0; |
| 84 | while (!save_iterator.Done()) { |
| 85 | __ ld(DoubleRegister::from_code(save_iterator.Current()), |
| 86 | MemOperand(sp, count * kDoubleSize)); |
| 87 | save_iterator.Advance(); |
| 88 | count++; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | bool LCodeGen::GeneratePrologue() { |
| 93 | DCHECK(is_generating()); |
| 94 | |
| 95 | if (info()->IsOptimizing()) { |
| 96 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 97 | |
| 98 | // r3: Callee's JS function. |
| 99 | // cp: Callee's context. |
| 100 | // fp: Caller's frame pointer. |
| 101 | // lr: Caller's pc. |
| 102 | // ip: Our own function entry (required by the prologue) |
| 103 | } |
| 104 | |
| 105 | int prologue_offset = masm_->pc_offset(); |
| 106 | |
| 107 | if (prologue_offset) { |
| 108 | // Prologue logic requires its starting address in ip and the |
| 109 | // corresponding offset from the function entry. Need to add |
| 110 | // 4 bytes for the size of AHI/AGHI that AddP expands into. |
| 111 | prologue_offset += sizeof(FourByteInstr); |
| 112 | __ AddP(ip, ip, Operand(prologue_offset)); |
| 113 | } |
| 114 | info()->set_prologue_offset(prologue_offset); |
| 115 | if (NeedsEagerFrame()) { |
| 116 | if (info()->IsStub()) { |
| 117 | __ StubPrologue(StackFrame::STUB, ip, prologue_offset); |
| 118 | } else { |
| 119 | __ Prologue(info()->GeneratePreagedPrologue(), ip, prologue_offset); |
| 120 | } |
| 121 | frame_is_built_ = true; |
| 122 | } |
| 123 | |
| 124 | // Reserve space for the stack slots needed by the code. |
| 125 | int slots = GetStackSlotCount(); |
| 126 | if (slots > 0) { |
| 127 | __ lay(sp, MemOperand(sp, -(slots * kPointerSize))); |
| 128 | if (FLAG_debug_code) { |
| 129 | __ Push(r2, r3); |
| 130 | __ mov(r2, Operand(slots * kPointerSize)); |
| 131 | __ mov(r3, Operand(kSlotsZapValue)); |
| 132 | Label loop; |
| 133 | __ bind(&loop); |
| 134 | __ StoreP(r3, MemOperand(sp, r2, kPointerSize)); |
| 135 | __ lay(r2, MemOperand(r2, -kPointerSize)); |
| 136 | __ CmpP(r2, Operand::Zero()); |
| 137 | __ bne(&loop); |
| 138 | __ Pop(r2, r3); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if (info()->saves_caller_doubles()) { |
| 143 | SaveCallerDoubles(); |
| 144 | } |
| 145 | return !is_aborted(); |
| 146 | } |
| 147 | |
| 148 | void LCodeGen::DoPrologue(LPrologue* instr) { |
| 149 | Comment(";;; Prologue begin"); |
| 150 | |
| 151 | // Possibly allocate a local context. |
| 152 | if (info()->scope()->num_heap_slots() > 0) { |
| 153 | Comment(";;; Allocate local context"); |
| 154 | bool need_write_barrier = true; |
| 155 | // Argument to NewContext is the function, which is in r3. |
| 156 | int slots = info()->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 157 | Safepoint::DeoptMode deopt_mode = Safepoint::kNoLazyDeopt; |
| 158 | if (info()->scope()->is_script_scope()) { |
| 159 | __ push(r3); |
| 160 | __ Push(info()->scope()->GetScopeInfo(info()->isolate())); |
| 161 | __ CallRuntime(Runtime::kNewScriptContext); |
| 162 | deopt_mode = Safepoint::kLazyDeopt; |
| 163 | } else if (slots <= FastNewContextStub::kMaximumSlots) { |
| 164 | FastNewContextStub stub(isolate(), slots); |
| 165 | __ CallStub(&stub); |
| 166 | // Result of FastNewContextStub is always in new space. |
| 167 | need_write_barrier = false; |
| 168 | } else { |
| 169 | __ push(r3); |
| 170 | __ CallRuntime(Runtime::kNewFunctionContext); |
| 171 | } |
| 172 | RecordSafepoint(deopt_mode); |
| 173 | |
| 174 | // Context is returned in both r2 and cp. It replaces the context |
| 175 | // passed to us. It's saved in the stack and kept live in cp. |
| 176 | __ LoadRR(cp, r2); |
| 177 | __ StoreP(r2, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 178 | // Copy any necessary parameters into the context. |
| 179 | int num_parameters = scope()->num_parameters(); |
| 180 | int first_parameter = scope()->has_this_declaration() ? -1 : 0; |
| 181 | for (int i = first_parameter; i < num_parameters; i++) { |
| 182 | Variable* var = (i == -1) ? scope()->receiver() : scope()->parameter(i); |
| 183 | if (var->IsContextSlot()) { |
| 184 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 185 | (num_parameters - 1 - i) * kPointerSize; |
| 186 | // Load parameter from stack. |
| 187 | __ LoadP(r2, MemOperand(fp, parameter_offset)); |
| 188 | // Store it in the context. |
| 189 | MemOperand target = ContextMemOperand(cp, var->index()); |
| 190 | __ StoreP(r2, target); |
| 191 | // Update the write barrier. This clobbers r5 and r2. |
| 192 | if (need_write_barrier) { |
| 193 | __ RecordWriteContextSlot(cp, target.offset(), r2, r5, |
| 194 | GetLinkRegisterState(), kSaveFPRegs); |
| 195 | } else if (FLAG_debug_code) { |
| 196 | Label done; |
| 197 | __ JumpIfInNewSpace(cp, r2, &done); |
| 198 | __ Abort(kExpectedNewSpaceObject); |
| 199 | __ bind(&done); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | Comment(";;; End allocate local context"); |
| 204 | } |
| 205 | |
| 206 | Comment(";;; Prologue end"); |
| 207 | } |
| 208 | |
| 209 | void LCodeGen::GenerateOsrPrologue() { |
| 210 | // Generate the OSR entry prologue at the first unknown OSR value, or if there |
| 211 | // are none, at the OSR entrypoint instruction. |
| 212 | if (osr_pc_offset_ >= 0) return; |
| 213 | |
| 214 | osr_pc_offset_ = masm()->pc_offset(); |
| 215 | |
| 216 | // Adjust the frame size, subsuming the unoptimized frame into the |
| 217 | // optimized frame. |
| 218 | int slots = GetStackSlotCount() - graph()->osr()->UnoptimizedFrameSlots(); |
| 219 | DCHECK(slots >= 0); |
| 220 | __ lay(sp, MemOperand(sp, -slots * kPointerSize)); |
| 221 | } |
| 222 | |
| 223 | void LCodeGen::GenerateBodyInstructionPre(LInstruction* instr) { |
| 224 | if (instr->IsCall()) { |
| 225 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 226 | } |
| 227 | if (!instr->IsLazyBailout() && !instr->IsGap()) { |
| 228 | safepoints_.BumpLastLazySafepointIndex(); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | bool LCodeGen::GenerateDeferredCode() { |
| 233 | DCHECK(is_generating()); |
| 234 | if (deferred_.length() > 0) { |
| 235 | for (int i = 0; !is_aborted() && i < deferred_.length(); i++) { |
| 236 | LDeferredCode* code = deferred_[i]; |
| 237 | |
| 238 | HValue* value = |
| 239 | instructions_->at(code->instruction_index())->hydrogen_value(); |
| 240 | RecordAndWritePosition( |
| 241 | chunk()->graph()->SourcePositionToScriptPosition(value->position())); |
| 242 | |
| 243 | Comment( |
| 244 | ";;; <@%d,#%d> " |
| 245 | "-------------------- Deferred %s --------------------", |
| 246 | code->instruction_index(), code->instr()->hydrogen_value()->id(), |
| 247 | code->instr()->Mnemonic()); |
| 248 | __ bind(code->entry()); |
| 249 | if (NeedsDeferredFrame()) { |
| 250 | Comment(";;; Build frame"); |
| 251 | DCHECK(!frame_is_built_); |
| 252 | DCHECK(info()->IsStub()); |
| 253 | frame_is_built_ = true; |
| 254 | __ LoadSmiLiteral(scratch0(), Smi::FromInt(StackFrame::STUB)); |
| 255 | __ PushCommonFrame(scratch0()); |
| 256 | Comment(";;; Deferred code"); |
| 257 | } |
| 258 | code->Generate(); |
| 259 | if (NeedsDeferredFrame()) { |
| 260 | Comment(";;; Destroy frame"); |
| 261 | DCHECK(frame_is_built_); |
| 262 | __ PopCommonFrame(scratch0()); |
| 263 | frame_is_built_ = false; |
| 264 | } |
| 265 | __ b(code->exit()); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return !is_aborted(); |
| 270 | } |
| 271 | |
| 272 | bool LCodeGen::GenerateJumpTable() { |
| 273 | // Check that the jump table is accessible from everywhere in the function |
| 274 | // code, i.e. that offsets in halfworld to the table can be encoded in the |
| 275 | // 32-bit signed immediate of a branch instruction. |
| 276 | // To simplify we consider the code size from the first instruction to the |
| 277 | // end of the jump table. We also don't consider the pc load delta. |
| 278 | // Each entry in the jump table generates one instruction and inlines one |
| 279 | // 32bit data after it. |
| 280 | // TODO(joransiu): The Int24 condition can likely be relaxed for S390 |
| 281 | if (!is_int24(masm()->pc_offset() + jump_table_.length() * 7)) { |
| 282 | Abort(kGeneratedCodeIsTooLarge); |
| 283 | } |
| 284 | |
| 285 | if (jump_table_.length() > 0) { |
| 286 | Label needs_frame, call_deopt_entry; |
| 287 | |
| 288 | Comment(";;; -------------------- Jump table --------------------"); |
| 289 | Address base = jump_table_[0].address; |
| 290 | |
| 291 | Register entry_offset = scratch0(); |
| 292 | |
| 293 | int length = jump_table_.length(); |
| 294 | for (int i = 0; i < length; i++) { |
| 295 | Deoptimizer::JumpTableEntry* table_entry = &jump_table_[i]; |
| 296 | __ bind(&table_entry->label); |
| 297 | |
| 298 | DCHECK_EQ(jump_table_[0].bailout_type, table_entry->bailout_type); |
| 299 | Address entry = table_entry->address; |
| 300 | DeoptComment(table_entry->deopt_info); |
| 301 | |
| 302 | // Second-level deopt table entries are contiguous and small, so instead |
| 303 | // of loading the full, absolute address of each one, load an immediate |
| 304 | // offset which will be added to the base address later. |
| 305 | __ mov(entry_offset, Operand(entry - base)); |
| 306 | |
| 307 | if (table_entry->needs_frame) { |
| 308 | DCHECK(!info()->saves_caller_doubles()); |
| 309 | Comment(";;; call deopt with frame"); |
| 310 | __ PushCommonFrame(); |
| 311 | __ b(r14, &needs_frame); |
| 312 | } else { |
| 313 | __ b(r14, &call_deopt_entry); |
| 314 | } |
| 315 | info()->LogDeoptCallPosition(masm()->pc_offset(), |
| 316 | table_entry->deopt_info.inlining_id); |
| 317 | } |
| 318 | |
| 319 | if (needs_frame.is_linked()) { |
| 320 | __ bind(&needs_frame); |
| 321 | // This variant of deopt can only be used with stubs. Since we don't |
| 322 | // have a function pointer to install in the stack frame that we're |
| 323 | // building, install a special marker there instead. |
| 324 | DCHECK(info()->IsStub()); |
| 325 | __ LoadSmiLiteral(ip, Smi::FromInt(StackFrame::STUB)); |
| 326 | __ push(ip); |
| 327 | DCHECK(info()->IsStub()); |
| 328 | } |
| 329 | |
| 330 | Comment(";;; call deopt"); |
| 331 | __ bind(&call_deopt_entry); |
| 332 | |
| 333 | if (info()->saves_caller_doubles()) { |
| 334 | DCHECK(info()->IsStub()); |
| 335 | RestoreCallerDoubles(); |
| 336 | } |
| 337 | |
| 338 | // Add the base address to the offset previously loaded in entry_offset. |
| 339 | __ mov(ip, Operand(ExternalReference::ForDeoptEntry(base))); |
| 340 | __ AddP(ip, entry_offset, ip); |
| 341 | __ Jump(ip); |
| 342 | } |
| 343 | |
| 344 | // The deoptimization jump table is the last part of the instruction |
| 345 | // sequence. Mark the generated code as done unless we bailed out. |
| 346 | if (!is_aborted()) status_ = DONE; |
| 347 | return !is_aborted(); |
| 348 | } |
| 349 | |
| 350 | bool LCodeGen::GenerateSafepointTable() { |
| 351 | DCHECK(is_done()); |
| 352 | safepoints_.Emit(masm(), GetTotalFrameSlotCount()); |
| 353 | return !is_aborted(); |
| 354 | } |
| 355 | |
| 356 | Register LCodeGen::ToRegister(int code) const { |
| 357 | return Register::from_code(code); |
| 358 | } |
| 359 | |
| 360 | DoubleRegister LCodeGen::ToDoubleRegister(int code) const { |
| 361 | return DoubleRegister::from_code(code); |
| 362 | } |
| 363 | |
| 364 | Register LCodeGen::ToRegister(LOperand* op) const { |
| 365 | DCHECK(op->IsRegister()); |
| 366 | return ToRegister(op->index()); |
| 367 | } |
| 368 | |
| 369 | Register LCodeGen::EmitLoadRegister(LOperand* op, Register scratch) { |
| 370 | if (op->IsRegister()) { |
| 371 | return ToRegister(op->index()); |
| 372 | } else if (op->IsConstantOperand()) { |
| 373 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 374 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 375 | Handle<Object> literal = constant->handle(isolate()); |
| 376 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 377 | if (r.IsInteger32()) { |
| 378 | AllowDeferredHandleDereference get_number; |
| 379 | DCHECK(literal->IsNumber()); |
| 380 | __ LoadIntLiteral(scratch, static_cast<int32_t>(literal->Number())); |
| 381 | } else if (r.IsDouble()) { |
| 382 | Abort(kEmitLoadRegisterUnsupportedDoubleImmediate); |
| 383 | } else { |
| 384 | DCHECK(r.IsSmiOrTagged()); |
| 385 | __ Move(scratch, literal); |
| 386 | } |
| 387 | return scratch; |
| 388 | } else if (op->IsStackSlot()) { |
| 389 | __ LoadP(scratch, ToMemOperand(op)); |
| 390 | return scratch; |
| 391 | } |
| 392 | UNREACHABLE(); |
| 393 | return scratch; |
| 394 | } |
| 395 | |
| 396 | void LCodeGen::EmitLoadIntegerConstant(LConstantOperand* const_op, |
| 397 | Register dst) { |
| 398 | DCHECK(IsInteger32(const_op)); |
| 399 | HConstant* constant = chunk_->LookupConstant(const_op); |
| 400 | int32_t value = constant->Integer32Value(); |
| 401 | if (IsSmi(const_op)) { |
| 402 | __ LoadSmiLiteral(dst, Smi::FromInt(value)); |
| 403 | } else { |
| 404 | __ LoadIntLiteral(dst, value); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | DoubleRegister LCodeGen::ToDoubleRegister(LOperand* op) const { |
| 409 | DCHECK(op->IsDoubleRegister()); |
| 410 | return ToDoubleRegister(op->index()); |
| 411 | } |
| 412 | |
| 413 | Handle<Object> LCodeGen::ToHandle(LConstantOperand* op) const { |
| 414 | HConstant* constant = chunk_->LookupConstant(op); |
| 415 | DCHECK(chunk_->LookupLiteralRepresentation(op).IsSmiOrTagged()); |
| 416 | return constant->handle(isolate()); |
| 417 | } |
| 418 | |
| 419 | bool LCodeGen::IsInteger32(LConstantOperand* op) const { |
| 420 | return chunk_->LookupLiteralRepresentation(op).IsSmiOrInteger32(); |
| 421 | } |
| 422 | |
| 423 | bool LCodeGen::IsSmi(LConstantOperand* op) const { |
| 424 | return chunk_->LookupLiteralRepresentation(op).IsSmi(); |
| 425 | } |
| 426 | |
| 427 | int32_t LCodeGen::ToInteger32(LConstantOperand* op) const { |
| 428 | return ToRepresentation(op, Representation::Integer32()); |
| 429 | } |
| 430 | |
| 431 | intptr_t LCodeGen::ToRepresentation(LConstantOperand* op, |
| 432 | const Representation& r) const { |
| 433 | HConstant* constant = chunk_->LookupConstant(op); |
| 434 | int32_t value = constant->Integer32Value(); |
| 435 | if (r.IsInteger32()) return value; |
| 436 | DCHECK(r.IsSmiOrTagged()); |
| 437 | return reinterpret_cast<intptr_t>(Smi::FromInt(value)); |
| 438 | } |
| 439 | |
| 440 | Smi* LCodeGen::ToSmi(LConstantOperand* op) const { |
| 441 | HConstant* constant = chunk_->LookupConstant(op); |
| 442 | return Smi::FromInt(constant->Integer32Value()); |
| 443 | } |
| 444 | |
| 445 | double LCodeGen::ToDouble(LConstantOperand* op) const { |
| 446 | HConstant* constant = chunk_->LookupConstant(op); |
| 447 | DCHECK(constant->HasDoubleValue()); |
| 448 | return constant->DoubleValue(); |
| 449 | } |
| 450 | |
| 451 | Operand LCodeGen::ToOperand(LOperand* op) { |
| 452 | if (op->IsConstantOperand()) { |
| 453 | LConstantOperand* const_op = LConstantOperand::cast(op); |
| 454 | HConstant* constant = chunk()->LookupConstant(const_op); |
| 455 | Representation r = chunk_->LookupLiteralRepresentation(const_op); |
| 456 | if (r.IsSmi()) { |
| 457 | DCHECK(constant->HasSmiValue()); |
| 458 | return Operand(Smi::FromInt(constant->Integer32Value())); |
| 459 | } else if (r.IsInteger32()) { |
| 460 | DCHECK(constant->HasInteger32Value()); |
| 461 | return Operand(constant->Integer32Value()); |
| 462 | } else if (r.IsDouble()) { |
| 463 | Abort(kToOperandUnsupportedDoubleImmediate); |
| 464 | } |
| 465 | DCHECK(r.IsTagged()); |
| 466 | return Operand(constant->handle(isolate())); |
| 467 | } else if (op->IsRegister()) { |
| 468 | return Operand(ToRegister(op)); |
| 469 | } else if (op->IsDoubleRegister()) { |
| 470 | Abort(kToOperandIsDoubleRegisterUnimplemented); |
| 471 | return Operand::Zero(); |
| 472 | } |
| 473 | // Stack slots not implemented, use ToMemOperand instead. |
| 474 | UNREACHABLE(); |
| 475 | return Operand::Zero(); |
| 476 | } |
| 477 | |
| 478 | static int ArgumentsOffsetWithoutFrame(int index) { |
| 479 | DCHECK(index < 0); |
| 480 | return -(index + 1) * kPointerSize; |
| 481 | } |
| 482 | |
| 483 | MemOperand LCodeGen::ToMemOperand(LOperand* op) const { |
| 484 | DCHECK(!op->IsRegister()); |
| 485 | DCHECK(!op->IsDoubleRegister()); |
| 486 | DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot()); |
| 487 | if (NeedsEagerFrame()) { |
| 488 | return MemOperand(fp, FrameSlotToFPOffset(op->index())); |
| 489 | } else { |
| 490 | // Retrieve parameter without eager stack-frame relative to the |
| 491 | // stack-pointer. |
| 492 | return MemOperand(sp, ArgumentsOffsetWithoutFrame(op->index())); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | MemOperand LCodeGen::ToHighMemOperand(LOperand* op) const { |
| 497 | DCHECK(op->IsDoubleStackSlot()); |
| 498 | if (NeedsEagerFrame()) { |
| 499 | return MemOperand(fp, FrameSlotToFPOffset(op->index()) + kPointerSize); |
| 500 | } else { |
| 501 | // Retrieve parameter without eager stack-frame relative to the |
| 502 | // stack-pointer. |
| 503 | return MemOperand(sp, |
| 504 | ArgumentsOffsetWithoutFrame(op->index()) + kPointerSize); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | void LCodeGen::WriteTranslation(LEnvironment* environment, |
| 509 | Translation* translation) { |
| 510 | if (environment == NULL) return; |
| 511 | |
| 512 | // The translation includes one command per value in the environment. |
| 513 | int translation_size = environment->translation_size(); |
| 514 | |
| 515 | WriteTranslation(environment->outer(), translation); |
| 516 | WriteTranslationFrame(environment, translation); |
| 517 | |
| 518 | int object_index = 0; |
| 519 | int dematerialized_index = 0; |
| 520 | for (int i = 0; i < translation_size; ++i) { |
| 521 | LOperand* value = environment->values()->at(i); |
| 522 | AddToTranslation( |
| 523 | environment, translation, value, environment->HasTaggedValueAt(i), |
| 524 | environment->HasUint32ValueAt(i), &object_index, &dematerialized_index); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | void LCodeGen::AddToTranslation(LEnvironment* environment, |
| 529 | Translation* translation, LOperand* op, |
| 530 | bool is_tagged, bool is_uint32, |
| 531 | int* object_index_pointer, |
| 532 | int* dematerialized_index_pointer) { |
| 533 | if (op == LEnvironment::materialization_marker()) { |
| 534 | int object_index = (*object_index_pointer)++; |
| 535 | if (environment->ObjectIsDuplicateAt(object_index)) { |
| 536 | int dupe_of = environment->ObjectDuplicateOfAt(object_index); |
| 537 | translation->DuplicateObject(dupe_of); |
| 538 | return; |
| 539 | } |
| 540 | int object_length = environment->ObjectLengthAt(object_index); |
| 541 | if (environment->ObjectIsArgumentsAt(object_index)) { |
| 542 | translation->BeginArgumentsObject(object_length); |
| 543 | } else { |
| 544 | translation->BeginCapturedObject(object_length); |
| 545 | } |
| 546 | int dematerialized_index = *dematerialized_index_pointer; |
| 547 | int env_offset = environment->translation_size() + dematerialized_index; |
| 548 | *dematerialized_index_pointer += object_length; |
| 549 | for (int i = 0; i < object_length; ++i) { |
| 550 | LOperand* value = environment->values()->at(env_offset + i); |
| 551 | AddToTranslation(environment, translation, value, |
| 552 | environment->HasTaggedValueAt(env_offset + i), |
| 553 | environment->HasUint32ValueAt(env_offset + i), |
| 554 | object_index_pointer, dematerialized_index_pointer); |
| 555 | } |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | if (op->IsStackSlot()) { |
| 560 | int index = op->index(); |
| 561 | if (is_tagged) { |
| 562 | translation->StoreStackSlot(index); |
| 563 | } else if (is_uint32) { |
| 564 | translation->StoreUint32StackSlot(index); |
| 565 | } else { |
| 566 | translation->StoreInt32StackSlot(index); |
| 567 | } |
| 568 | } else if (op->IsDoubleStackSlot()) { |
| 569 | int index = op->index(); |
| 570 | translation->StoreDoubleStackSlot(index); |
| 571 | } else if (op->IsRegister()) { |
| 572 | Register reg = ToRegister(op); |
| 573 | if (is_tagged) { |
| 574 | translation->StoreRegister(reg); |
| 575 | } else if (is_uint32) { |
| 576 | translation->StoreUint32Register(reg); |
| 577 | } else { |
| 578 | translation->StoreInt32Register(reg); |
| 579 | } |
| 580 | } else if (op->IsDoubleRegister()) { |
| 581 | DoubleRegister reg = ToDoubleRegister(op); |
| 582 | translation->StoreDoubleRegister(reg); |
| 583 | } else if (op->IsConstantOperand()) { |
| 584 | HConstant* constant = chunk()->LookupConstant(LConstantOperand::cast(op)); |
| 585 | int src_index = DefineDeoptimizationLiteral(constant->handle(isolate())); |
| 586 | translation->StoreLiteral(src_index); |
| 587 | } else { |
| 588 | UNREACHABLE(); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | void LCodeGen::CallCode(Handle<Code> code, RelocInfo::Mode mode, |
| 593 | LInstruction* instr) { |
| 594 | CallCodeGeneric(code, mode, instr, RECORD_SIMPLE_SAFEPOINT); |
| 595 | } |
| 596 | |
| 597 | void LCodeGen::CallCodeGeneric(Handle<Code> code, RelocInfo::Mode mode, |
| 598 | LInstruction* instr, |
| 599 | SafepointMode safepoint_mode) { |
| 600 | DCHECK(instr != NULL); |
| 601 | __ Call(code, mode); |
| 602 | RecordSafepointWithLazyDeopt(instr, safepoint_mode); |
| 603 | |
| 604 | // Signal that we don't inline smi code before these stubs in the |
| 605 | // optimizing code generator. |
| 606 | if (code->kind() == Code::BINARY_OP_IC || code->kind() == Code::COMPARE_IC) { |
| 607 | __ nop(); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | void LCodeGen::CallRuntime(const Runtime::Function* function, int num_arguments, |
| 612 | LInstruction* instr, SaveFPRegsMode save_doubles) { |
| 613 | DCHECK(instr != NULL); |
| 614 | |
| 615 | __ CallRuntime(function, num_arguments, save_doubles); |
| 616 | |
| 617 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 618 | } |
| 619 | |
| 620 | void LCodeGen::LoadContextFromDeferred(LOperand* context) { |
| 621 | if (context->IsRegister()) { |
| 622 | __ Move(cp, ToRegister(context)); |
| 623 | } else if (context->IsStackSlot()) { |
| 624 | __ LoadP(cp, ToMemOperand(context)); |
| 625 | } else if (context->IsConstantOperand()) { |
| 626 | HConstant* constant = |
| 627 | chunk_->LookupConstant(LConstantOperand::cast(context)); |
| 628 | __ Move(cp, Handle<Object>::cast(constant->handle(isolate()))); |
| 629 | } else { |
| 630 | UNREACHABLE(); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | void LCodeGen::CallRuntimeFromDeferred(Runtime::FunctionId id, int argc, |
| 635 | LInstruction* instr, LOperand* context) { |
| 636 | LoadContextFromDeferred(context); |
| 637 | __ CallRuntimeSaveDoubles(id); |
| 638 | RecordSafepointWithRegisters(instr->pointer_map(), argc, |
| 639 | Safepoint::kNoLazyDeopt); |
| 640 | } |
| 641 | |
| 642 | void LCodeGen::RegisterEnvironmentForDeoptimization(LEnvironment* environment, |
| 643 | Safepoint::DeoptMode mode) { |
| 644 | environment->set_has_been_used(); |
| 645 | if (!environment->HasBeenRegistered()) { |
| 646 | // Physical stack frame layout: |
| 647 | // -x ............. -4 0 ..................................... y |
| 648 | // [incoming arguments] [spill slots] [pushed outgoing arguments] |
| 649 | |
| 650 | // Layout of the environment: |
| 651 | // 0 ..................................................... size-1 |
| 652 | // [parameters] [locals] [expression stack including arguments] |
| 653 | |
| 654 | // Layout of the translation: |
| 655 | // 0 ........................................................ size - 1 + 4 |
| 656 | // [expression stack including arguments] [locals] [4 words] [parameters] |
| 657 | // |>------------ translation_size ------------<| |
| 658 | |
| 659 | int frame_count = 0; |
| 660 | int jsframe_count = 0; |
| 661 | for (LEnvironment* e = environment; e != NULL; e = e->outer()) { |
| 662 | ++frame_count; |
| 663 | if (e->frame_type() == JS_FUNCTION) { |
| 664 | ++jsframe_count; |
| 665 | } |
| 666 | } |
| 667 | Translation translation(&translations_, frame_count, jsframe_count, zone()); |
| 668 | WriteTranslation(environment, &translation); |
| 669 | int deoptimization_index = deoptimizations_.length(); |
| 670 | int pc_offset = masm()->pc_offset(); |
| 671 | environment->Register(deoptimization_index, translation.index(), |
| 672 | (mode == Safepoint::kLazyDeopt) ? pc_offset : -1); |
| 673 | deoptimizations_.Add(environment, zone()); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | void LCodeGen::DeoptimizeIf(Condition cond, LInstruction* instr, |
| 678 | Deoptimizer::DeoptReason deopt_reason, |
| 679 | Deoptimizer::BailoutType bailout_type, |
| 680 | CRegister cr) { |
| 681 | LEnvironment* environment = instr->environment(); |
| 682 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 683 | DCHECK(environment->HasBeenRegistered()); |
| 684 | int id = environment->deoptimization_index(); |
| 685 | Address entry = |
| 686 | Deoptimizer::GetDeoptimizationEntry(isolate(), id, bailout_type); |
| 687 | if (entry == NULL) { |
| 688 | Abort(kBailoutWasNotPrepared); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | if (FLAG_deopt_every_n_times != 0 && !info()->IsStub()) { |
| 693 | Register scratch = scratch0(); |
| 694 | ExternalReference count = ExternalReference::stress_deopt_count(isolate()); |
| 695 | Label no_deopt; |
| 696 | |
| 697 | // Store the condition on the stack if necessary |
| 698 | if (cond != al) { |
| 699 | Label done; |
| 700 | __ LoadImmP(scratch, Operand::Zero()); |
| 701 | __ b(NegateCondition(cond), &done, Label::kNear); |
| 702 | __ LoadImmP(scratch, Operand(1)); |
| 703 | __ bind(&done); |
| 704 | __ push(scratch); |
| 705 | } |
| 706 | |
| 707 | Label done; |
| 708 | __ Push(r3); |
| 709 | __ mov(scratch, Operand(count)); |
| 710 | __ LoadW(r3, MemOperand(scratch)); |
| 711 | __ Sub32(r3, r3, Operand(1)); |
| 712 | __ Cmp32(r3, Operand::Zero()); |
| 713 | __ bne(&no_deopt, Label::kNear); |
| 714 | |
| 715 | __ LoadImmP(r3, Operand(FLAG_deopt_every_n_times)); |
| 716 | __ StoreW(r3, MemOperand(scratch)); |
| 717 | __ Pop(r3); |
| 718 | |
| 719 | if (cond != al) { |
| 720 | // Clean up the stack before the deoptimizer call |
| 721 | __ pop(scratch); |
| 722 | } |
| 723 | |
| 724 | __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
| 725 | |
| 726 | __ b(&done); |
| 727 | |
| 728 | __ bind(&no_deopt); |
| 729 | __ StoreW(r3, MemOperand(scratch)); |
| 730 | __ Pop(r3); |
| 731 | |
| 732 | if (cond != al) { |
| 733 | // Clean up the stack before the deoptimizer call |
| 734 | __ pop(scratch); |
| 735 | } |
| 736 | |
| 737 | __ bind(&done); |
| 738 | |
| 739 | if (cond != al) { |
| 740 | cond = ne; |
| 741 | __ CmpP(scratch, Operand::Zero()); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | if (info()->ShouldTrapOnDeopt()) { |
| 746 | __ stop("trap_on_deopt", cond, kDefaultStopCode, cr); |
| 747 | } |
| 748 | |
| 749 | Deoptimizer::DeoptInfo deopt_info = MakeDeoptInfo(instr, deopt_reason); |
| 750 | |
| 751 | DCHECK(info()->IsStub() || frame_is_built_); |
| 752 | // Go through jump table if we need to handle condition, build frame, or |
| 753 | // restore caller doubles. |
| 754 | if (cond == al && frame_is_built_ && !info()->saves_caller_doubles()) { |
| 755 | __ Call(entry, RelocInfo::RUNTIME_ENTRY); |
| 756 | info()->LogDeoptCallPosition(masm()->pc_offset(), deopt_info.inlining_id); |
| 757 | } else { |
| 758 | Deoptimizer::JumpTableEntry table_entry(entry, deopt_info, bailout_type, |
| 759 | !frame_is_built_); |
| 760 | // We often have several deopts to the same entry, reuse the last |
| 761 | // jump entry if this is the case. |
| 762 | if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling() || |
| 763 | jump_table_.is_empty() || |
| 764 | !table_entry.IsEquivalentTo(jump_table_.last())) { |
| 765 | jump_table_.Add(table_entry, zone()); |
| 766 | } |
| 767 | __ b(cond, &jump_table_.last().label /*, cr*/); |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | void LCodeGen::DeoptimizeIf(Condition cond, LInstruction* instr, |
| 772 | Deoptimizer::DeoptReason deopt_reason, |
| 773 | CRegister cr) { |
| 774 | Deoptimizer::BailoutType bailout_type = |
| 775 | info()->IsStub() ? Deoptimizer::LAZY : Deoptimizer::EAGER; |
| 776 | DeoptimizeIf(cond, instr, deopt_reason, bailout_type, cr); |
| 777 | } |
| 778 | |
| 779 | void LCodeGen::RecordSafepointWithLazyDeopt(LInstruction* instr, |
| 780 | SafepointMode safepoint_mode) { |
| 781 | if (safepoint_mode == RECORD_SIMPLE_SAFEPOINT) { |
| 782 | RecordSafepoint(instr->pointer_map(), Safepoint::kLazyDeopt); |
| 783 | } else { |
| 784 | DCHECK(safepoint_mode == RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 785 | RecordSafepointWithRegisters(instr->pointer_map(), 0, |
| 786 | Safepoint::kLazyDeopt); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, Safepoint::Kind kind, |
| 791 | int arguments, Safepoint::DeoptMode deopt_mode) { |
| 792 | DCHECK(expected_safepoint_kind_ == kind); |
| 793 | |
| 794 | const ZoneList<LOperand*>* operands = pointers->GetNormalizedOperands(); |
| 795 | Safepoint safepoint = |
| 796 | safepoints_.DefineSafepoint(masm(), kind, arguments, deopt_mode); |
| 797 | for (int i = 0; i < operands->length(); i++) { |
| 798 | LOperand* pointer = operands->at(i); |
| 799 | if (pointer->IsStackSlot()) { |
| 800 | safepoint.DefinePointerSlot(pointer->index(), zone()); |
| 801 | } else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) { |
| 802 | safepoint.DefinePointerRegister(ToRegister(pointer), zone()); |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | void LCodeGen::RecordSafepoint(LPointerMap* pointers, |
| 808 | Safepoint::DeoptMode deopt_mode) { |
| 809 | RecordSafepoint(pointers, Safepoint::kSimple, 0, deopt_mode); |
| 810 | } |
| 811 | |
| 812 | void LCodeGen::RecordSafepoint(Safepoint::DeoptMode deopt_mode) { |
| 813 | LPointerMap empty_pointers(zone()); |
| 814 | RecordSafepoint(&empty_pointers, deopt_mode); |
| 815 | } |
| 816 | |
| 817 | void LCodeGen::RecordSafepointWithRegisters(LPointerMap* pointers, |
| 818 | int arguments, |
| 819 | Safepoint::DeoptMode deopt_mode) { |
| 820 | RecordSafepoint(pointers, Safepoint::kWithRegisters, arguments, deopt_mode); |
| 821 | } |
| 822 | |
| 823 | void LCodeGen::RecordAndWritePosition(int position) { |
| 824 | if (position == RelocInfo::kNoPosition) return; |
| 825 | masm()->positions_recorder()->RecordPosition(position); |
| 826 | masm()->positions_recorder()->WriteRecordedPositions(); |
| 827 | } |
| 828 | |
| 829 | static const char* LabelType(LLabel* label) { |
| 830 | if (label->is_loop_header()) return " (loop header)"; |
| 831 | if (label->is_osr_entry()) return " (OSR entry)"; |
| 832 | return ""; |
| 833 | } |
| 834 | |
| 835 | void LCodeGen::DoLabel(LLabel* label) { |
| 836 | Comment(";;; <@%d,#%d> -------------------- B%d%s --------------------", |
| 837 | current_instruction_, label->hydrogen_value()->id(), |
| 838 | label->block_id(), LabelType(label)); |
| 839 | __ bind(label->label()); |
| 840 | current_block_ = label->block_id(); |
| 841 | DoGap(label); |
| 842 | } |
| 843 | |
| 844 | void LCodeGen::DoParallelMove(LParallelMove* move) { resolver_.Resolve(move); } |
| 845 | |
| 846 | void LCodeGen::DoGap(LGap* gap) { |
| 847 | for (int i = LGap::FIRST_INNER_POSITION; i <= LGap::LAST_INNER_POSITION; |
| 848 | i++) { |
| 849 | LGap::InnerPosition inner_pos = static_cast<LGap::InnerPosition>(i); |
| 850 | LParallelMove* move = gap->GetParallelMove(inner_pos); |
| 851 | if (move != NULL) DoParallelMove(move); |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | void LCodeGen::DoInstructionGap(LInstructionGap* instr) { DoGap(instr); } |
| 856 | |
| 857 | void LCodeGen::DoParameter(LParameter* instr) { |
| 858 | // Nothing to do. |
| 859 | } |
| 860 | |
| 861 | void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 862 | GenerateOsrPrologue(); |
| 863 | } |
| 864 | |
| 865 | void LCodeGen::DoModByPowerOf2I(LModByPowerOf2I* instr) { |
| 866 | Register dividend = ToRegister(instr->dividend()); |
| 867 | int32_t divisor = instr->divisor(); |
| 868 | DCHECK(dividend.is(ToRegister(instr->result()))); |
| 869 | |
| 870 | // Theoretically, a variation of the branch-free code for integer division by |
| 871 | // a power of 2 (calculating the remainder via an additional multiplication |
| 872 | // (which gets simplified to an 'and') and subtraction) should be faster, and |
| 873 | // this is exactly what GCC and clang emit. Nevertheless, benchmarks seem to |
| 874 | // indicate that positive dividends are heavily favored, so the branching |
| 875 | // version performs better. |
| 876 | HMod* hmod = instr->hydrogen(); |
| 877 | int32_t shift = WhichPowerOf2Abs(divisor); |
| 878 | Label dividend_is_not_negative, done; |
| 879 | if (hmod->CheckFlag(HValue::kLeftCanBeNegative)) { |
| 880 | __ CmpP(dividend, Operand::Zero()); |
| 881 | __ bge(÷nd_is_not_negative, Label::kNear); |
| 882 | if (shift) { |
| 883 | // Note that this is correct even for kMinInt operands. |
| 884 | __ LoadComplementRR(dividend, dividend); |
| 885 | __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
| 886 | __ LoadComplementRR(dividend, dividend); |
| 887 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 888 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 889 | } |
| 890 | } else if (!hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 891 | __ mov(dividend, Operand::Zero()); |
| 892 | } else { |
| 893 | DeoptimizeIf(al, instr, Deoptimizer::kMinusZero); |
| 894 | } |
| 895 | __ b(&done, Label::kNear); |
| 896 | } |
| 897 | |
| 898 | __ bind(÷nd_is_not_negative); |
| 899 | if (shift) { |
| 900 | __ ExtractBitRange(dividend, dividend, shift - 1, 0); |
| 901 | } else { |
| 902 | __ mov(dividend, Operand::Zero()); |
| 903 | } |
| 904 | __ bind(&done); |
| 905 | } |
| 906 | |
| 907 | void LCodeGen::DoModByConstI(LModByConstI* instr) { |
| 908 | Register dividend = ToRegister(instr->dividend()); |
| 909 | int32_t divisor = instr->divisor(); |
| 910 | Register result = ToRegister(instr->result()); |
| 911 | DCHECK(!dividend.is(result)); |
| 912 | |
| 913 | if (divisor == 0) { |
| 914 | DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero); |
| 915 | return; |
| 916 | } |
| 917 | |
| 918 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 919 | __ mov(ip, Operand(Abs(divisor))); |
| 920 | __ Mul(result, result, ip); |
| 921 | __ SubP(result, dividend, result /*, LeaveOE, SetRC*/); |
| 922 | |
| 923 | // Check for negative zero. |
| 924 | HMod* hmod = instr->hydrogen(); |
| 925 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 926 | Label remainder_not_zero; |
| 927 | __ bne(&remainder_not_zero, Label::kNear /*, cr0*/); |
| 928 | __ Cmp32(dividend, Operand::Zero()); |
| 929 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 930 | __ bind(&remainder_not_zero); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | void LCodeGen::DoModI(LModI* instr) { |
| 935 | HMod* hmod = instr->hydrogen(); |
| 936 | Register left_reg = ToRegister(instr->left()); |
| 937 | Register right_reg = ToRegister(instr->right()); |
| 938 | Register result_reg = ToRegister(instr->result()); |
| 939 | Label done; |
| 940 | |
| 941 | // Check for x % 0. |
| 942 | if (hmod->CheckFlag(HValue::kCanBeDivByZero)) { |
| 943 | __ Cmp32(right_reg, Operand::Zero()); |
| 944 | DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero); |
| 945 | } |
| 946 | |
| 947 | // Check for kMinInt % -1, dr will return undefined, which is not what we |
| 948 | // want. We have to deopt if we care about -0, because we can't return that. |
| 949 | if (hmod->CheckFlag(HValue::kCanOverflow)) { |
| 950 | Label no_overflow_possible; |
| 951 | __ Cmp32(left_reg, Operand(kMinInt)); |
| 952 | __ bne(&no_overflow_possible, Label::kNear); |
| 953 | __ Cmp32(right_reg, Operand(-1)); |
| 954 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 955 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 956 | } else { |
| 957 | __ b(ne, &no_overflow_possible, Label::kNear); |
| 958 | __ mov(result_reg, Operand::Zero()); |
| 959 | __ b(&done, Label::kNear); |
| 960 | } |
| 961 | __ bind(&no_overflow_possible); |
| 962 | } |
| 963 | |
| 964 | // Divide instruction dr will implicity use register pair |
| 965 | // r0 & r1 below. |
| 966 | DCHECK(!left_reg.is(r1)); |
| 967 | DCHECK(!right_reg.is(r1)); |
| 968 | DCHECK(!result_reg.is(r1)); |
| 969 | __ LoadRR(r0, left_reg); |
| 970 | __ srda(r0, Operand(32)); |
| 971 | __ dr(r0, right_reg); // R0:R1 = R1 / divisor - R0 remainder |
| 972 | |
| 973 | __ LoadAndTestP_ExtendSrc(result_reg, r0); // Copy remainder to resultreg |
| 974 | |
| 975 | // If we care about -0, test if the dividend is <0 and the result is 0. |
| 976 | if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 977 | __ bne(&done, Label::kNear); |
| 978 | __ Cmp32(left_reg, Operand::Zero()); |
| 979 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 980 | } |
| 981 | |
| 982 | __ bind(&done); |
| 983 | } |
| 984 | |
| 985 | void LCodeGen::DoDivByPowerOf2I(LDivByPowerOf2I* instr) { |
| 986 | Register dividend = ToRegister(instr->dividend()); |
| 987 | int32_t divisor = instr->divisor(); |
| 988 | Register result = ToRegister(instr->result()); |
| 989 | DCHECK(divisor == kMinInt || base::bits::IsPowerOfTwo32(Abs(divisor))); |
| 990 | DCHECK(!result.is(dividend)); |
| 991 | |
| 992 | // Check for (0 / -x) that will produce negative zero. |
| 993 | HDiv* hdiv = instr->hydrogen(); |
| 994 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 995 | __ Cmp32(dividend, Operand::Zero()); |
| 996 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 997 | } |
| 998 | // Check for (kMinInt / -1). |
| 999 | if (hdiv->CheckFlag(HValue::kCanOverflow) && divisor == -1) { |
| 1000 | __ Cmp32(dividend, Operand(0x80000000)); |
| 1001 | DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); |
| 1002 | } |
| 1003 | |
| 1004 | int32_t shift = WhichPowerOf2Abs(divisor); |
| 1005 | |
| 1006 | // Deoptimize if remainder will not be 0. |
| 1007 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32) && shift) { |
| 1008 | __ TestBitRange(dividend, shift - 1, 0, r0); |
| 1009 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision, cr0); |
| 1010 | } |
| 1011 | |
| 1012 | if (divisor == -1) { // Nice shortcut, not needed for correctness. |
| 1013 | __ LoadComplementRR(result, dividend); |
| 1014 | return; |
| 1015 | } |
| 1016 | if (shift == 0) { |
| 1017 | __ LoadRR(result, dividend); |
| 1018 | } else { |
| 1019 | if (shift == 1) { |
| 1020 | __ ShiftRight(result, dividend, Operand(31)); |
| 1021 | } else { |
| 1022 | __ ShiftRightArith(result, dividend, Operand(31)); |
| 1023 | __ ShiftRight(result, result, Operand(32 - shift)); |
| 1024 | } |
| 1025 | __ AddP(result, dividend, result); |
| 1026 | __ ShiftRightArith(result, result, Operand(shift)); |
| 1027 | #if V8_TARGET_ARCH_S390X |
| 1028 | __ lgfr(result, result); |
| 1029 | #endif |
| 1030 | } |
| 1031 | if (divisor < 0) __ LoadComplementRR(result, result); |
| 1032 | } |
| 1033 | |
| 1034 | void LCodeGen::DoDivByConstI(LDivByConstI* instr) { |
| 1035 | Register dividend = ToRegister(instr->dividend()); |
| 1036 | int32_t divisor = instr->divisor(); |
| 1037 | Register result = ToRegister(instr->result()); |
| 1038 | DCHECK(!dividend.is(result)); |
| 1039 | |
| 1040 | if (divisor == 0) { |
| 1041 | DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | // Check for (0 / -x) that will produce negative zero. |
| 1046 | HDiv* hdiv = instr->hydrogen(); |
| 1047 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1048 | __ Cmp32(dividend, Operand::Zero()); |
| 1049 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 1050 | } |
| 1051 | |
| 1052 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1053 | if (divisor < 0) __ LoadComplementRR(result, result); |
| 1054 | |
| 1055 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1056 | Register scratch = scratch0(); |
| 1057 | __ mov(ip, Operand(divisor)); |
| 1058 | __ Mul(scratch, result, ip); |
| 1059 | __ Cmp32(scratch, dividend); |
| 1060 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | // TODO(svenpanne) Refactor this to avoid code duplication with DoFlooringDivI. |
| 1065 | void LCodeGen::DoDivI(LDivI* instr) { |
| 1066 | HBinaryOperation* hdiv = instr->hydrogen(); |
| 1067 | const Register dividend = ToRegister(instr->dividend()); |
| 1068 | const Register divisor = ToRegister(instr->divisor()); |
| 1069 | Register result = ToRegister(instr->result()); |
| 1070 | |
| 1071 | DCHECK(!dividend.is(result)); |
| 1072 | DCHECK(!divisor.is(result)); |
| 1073 | |
| 1074 | // Check for x / 0. |
| 1075 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1076 | __ Cmp32(divisor, Operand::Zero()); |
| 1077 | DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero); |
| 1078 | } |
| 1079 | |
| 1080 | // Check for (0 / -x) that will produce negative zero. |
| 1081 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1082 | Label dividend_not_zero; |
| 1083 | __ Cmp32(dividend, Operand::Zero()); |
| 1084 | __ bne(÷nd_not_zero, Label::kNear); |
| 1085 | __ Cmp32(divisor, Operand::Zero()); |
| 1086 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 1087 | __ bind(÷nd_not_zero); |
| 1088 | } |
| 1089 | |
| 1090 | // Check for (kMinInt / -1). |
| 1091 | if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1092 | Label dividend_not_min_int; |
| 1093 | __ Cmp32(dividend, Operand(kMinInt)); |
| 1094 | __ bne(÷nd_not_min_int, Label::kNear); |
| 1095 | __ Cmp32(divisor, Operand(-1)); |
| 1096 | DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); |
| 1097 | __ bind(÷nd_not_min_int); |
| 1098 | } |
| 1099 | |
| 1100 | __ LoadRR(r0, dividend); |
| 1101 | __ srda(r0, Operand(32)); |
| 1102 | __ dr(r0, divisor); // R0:R1 = R1 / divisor - R0 remainder - R1 quotient |
| 1103 | |
| 1104 | __ LoadAndTestP_ExtendSrc(result, r1); // Move quotient to result register |
| 1105 | |
| 1106 | if (!hdiv->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) { |
| 1107 | // Deoptimize if remainder is not 0. |
| 1108 | __ Cmp32(r0, Operand::Zero()); |
| 1109 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecision); |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) { |
| 1114 | HBinaryOperation* hdiv = instr->hydrogen(); |
| 1115 | Register dividend = ToRegister(instr->dividend()); |
| 1116 | Register result = ToRegister(instr->result()); |
| 1117 | int32_t divisor = instr->divisor(); |
| 1118 | bool can_overflow = hdiv->CheckFlag(HValue::kLeftCanBeMinInt); |
| 1119 | |
| 1120 | // If the divisor is positive, things are easy: There can be no deopts and we |
| 1121 | // can simply do an arithmetic right shift. |
| 1122 | int32_t shift = WhichPowerOf2Abs(divisor); |
| 1123 | if (divisor > 0) { |
| 1124 | if (shift || !result.is(dividend)) { |
| 1125 | __ ShiftRightArith(result, dividend, Operand(shift)); |
| 1126 | #if V8_TARGET_ARCH_S390X |
| 1127 | __ lgfr(result, result); |
| 1128 | #endif |
| 1129 | } |
| 1130 | return; |
| 1131 | } |
| 1132 | |
| 1133 | // If the divisor is negative, we have to negate and handle edge cases. |
| 1134 | #if V8_TARGET_ARCH_S390X |
| 1135 | if (divisor == -1 && can_overflow) { |
| 1136 | __ Cmp32(dividend, Operand(0x80000000)); |
| 1137 | DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); |
| 1138 | } |
| 1139 | #endif |
| 1140 | |
| 1141 | __ LoadComplementRR(result, dividend); |
| 1142 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1143 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero, cr0); |
| 1144 | } |
| 1145 | |
| 1146 | // If the negation could not overflow, simply shifting is OK. |
| 1147 | #if !V8_TARGET_ARCH_S390X |
| 1148 | if (!can_overflow) { |
| 1149 | #endif |
| 1150 | if (shift) { |
| 1151 | __ ShiftRightArithP(result, result, Operand(shift)); |
| 1152 | } |
| 1153 | return; |
| 1154 | #if !V8_TARGET_ARCH_S390X |
| 1155 | } |
| 1156 | |
| 1157 | // Dividing by -1 is basically negation, unless we overflow. |
| 1158 | if (divisor == -1) { |
| 1159 | DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow, cr0); |
| 1160 | return; |
| 1161 | } |
| 1162 | |
| 1163 | Label overflow_label, done; |
| 1164 | __ b(overflow, &overflow_label, Label::kNear); |
| 1165 | __ ShiftRightArith(result, result, Operand(shift)); |
| 1166 | #if V8_TARGET_ARCH_S390X |
| 1167 | __ lgfr(result, result); |
| 1168 | #endif |
| 1169 | __ b(&done, Label::kNear); |
| 1170 | __ bind(&overflow_label); |
| 1171 | __ mov(result, Operand(kMinInt / divisor)); |
| 1172 | __ bind(&done); |
| 1173 | #endif |
| 1174 | } |
| 1175 | |
| 1176 | void LCodeGen::DoFlooringDivByConstI(LFlooringDivByConstI* instr) { |
| 1177 | Register dividend = ToRegister(instr->dividend()); |
| 1178 | int32_t divisor = instr->divisor(); |
| 1179 | Register result = ToRegister(instr->result()); |
| 1180 | DCHECK(!dividend.is(result)); |
| 1181 | |
| 1182 | if (divisor == 0) { |
| 1183 | DeoptimizeIf(al, instr, Deoptimizer::kDivisionByZero); |
| 1184 | return; |
| 1185 | } |
| 1186 | |
| 1187 | // Check for (0 / -x) that will produce negative zero. |
| 1188 | HMathFloorOfDiv* hdiv = instr->hydrogen(); |
| 1189 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) { |
| 1190 | __ Cmp32(dividend, Operand::Zero()); |
| 1191 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 1192 | } |
| 1193 | |
| 1194 | // Easy case: We need no dynamic check for the dividend and the flooring |
| 1195 | // division is the same as the truncating division. |
| 1196 | if ((divisor > 0 && !hdiv->CheckFlag(HValue::kLeftCanBeNegative)) || |
| 1197 | (divisor < 0 && !hdiv->CheckFlag(HValue::kLeftCanBePositive))) { |
| 1198 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1199 | if (divisor < 0) __ LoadComplementRR(result, result); |
| 1200 | return; |
| 1201 | } |
| 1202 | |
| 1203 | // In the general case we may need to adjust before and after the truncating |
| 1204 | // division to get a flooring division. |
| 1205 | Register temp = ToRegister(instr->temp()); |
| 1206 | DCHECK(!temp.is(dividend) && !temp.is(result)); |
| 1207 | Label needs_adjustment, done; |
| 1208 | __ Cmp32(dividend, Operand::Zero()); |
| 1209 | __ b(divisor > 0 ? lt : gt, &needs_adjustment); |
| 1210 | __ TruncatingDiv(result, dividend, Abs(divisor)); |
| 1211 | if (divisor < 0) __ LoadComplementRR(result, result); |
| 1212 | __ b(&done, Label::kNear); |
| 1213 | __ bind(&needs_adjustment); |
| 1214 | __ AddP(temp, dividend, Operand(divisor > 0 ? 1 : -1)); |
| 1215 | __ TruncatingDiv(result, temp, Abs(divisor)); |
| 1216 | if (divisor < 0) __ LoadComplementRR(result, result); |
| 1217 | __ SubP(result, result, Operand(1)); |
| 1218 | __ bind(&done); |
| 1219 | } |
| 1220 | |
| 1221 | // TODO(svenpanne) Refactor this to avoid code duplication with DoDivI. |
| 1222 | void LCodeGen::DoFlooringDivI(LFlooringDivI* instr) { |
| 1223 | HBinaryOperation* hdiv = instr->hydrogen(); |
| 1224 | const Register dividend = ToRegister(instr->dividend()); |
| 1225 | const Register divisor = ToRegister(instr->divisor()); |
| 1226 | Register result = ToRegister(instr->result()); |
| 1227 | |
| 1228 | DCHECK(!dividend.is(result)); |
| 1229 | DCHECK(!divisor.is(result)); |
| 1230 | |
| 1231 | // Check for x / 0. |
| 1232 | if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) { |
| 1233 | __ Cmp32(divisor, Operand::Zero()); |
| 1234 | DeoptimizeIf(eq, instr, Deoptimizer::kDivisionByZero); |
| 1235 | } |
| 1236 | |
| 1237 | // Check for (0 / -x) that will produce negative zero. |
| 1238 | if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1239 | Label dividend_not_zero; |
| 1240 | __ Cmp32(dividend, Operand::Zero()); |
| 1241 | __ bne(÷nd_not_zero, Label::kNear); |
| 1242 | __ Cmp32(divisor, Operand::Zero()); |
| 1243 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 1244 | __ bind(÷nd_not_zero); |
| 1245 | } |
| 1246 | |
| 1247 | // Check for (kMinInt / -1). |
| 1248 | if (hdiv->CheckFlag(HValue::kCanOverflow)) { |
| 1249 | Label no_overflow_possible; |
| 1250 | __ Cmp32(dividend, Operand(kMinInt)); |
| 1251 | __ bne(&no_overflow_possible, Label::kNear); |
| 1252 | __ Cmp32(divisor, Operand(-1)); |
| 1253 | if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) { |
| 1254 | DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); |
| 1255 | } else { |
| 1256 | __ bne(&no_overflow_possible, Label::kNear); |
| 1257 | __ LoadRR(result, dividend); |
| 1258 | } |
| 1259 | __ bind(&no_overflow_possible); |
| 1260 | } |
| 1261 | |
| 1262 | __ LoadRR(r0, dividend); |
| 1263 | __ srda(r0, Operand(32)); |
| 1264 | __ dr(r0, divisor); // R0:R1 = R1 / divisor - R0 remainder - R1 quotient |
| 1265 | |
| 1266 | __ lr(result, r1); // Move quotient to result register |
| 1267 | |
| 1268 | Label done; |
| 1269 | Register scratch = scratch0(); |
| 1270 | // If both operands have the same sign then we are done. |
| 1271 | __ Xor(scratch, dividend, divisor); |
| 1272 | __ ltr(scratch, scratch); // use 32 bit version LoadAndTestRR even in 64 bit |
| 1273 | __ bge(&done, Label::kNear); |
| 1274 | |
| 1275 | // If there is no remainder then we are done. |
| 1276 | __ lr(scratch, result); |
| 1277 | __ msr(scratch, divisor); |
| 1278 | __ Cmp32(dividend, scratch); |
| 1279 | __ beq(&done, Label::kNear); |
| 1280 | |
| 1281 | // We performed a truncating division. Correct the result. |
| 1282 | __ Sub32(result, result, Operand(1)); |
| 1283 | __ bind(&done); |
| 1284 | } |
| 1285 | |
| 1286 | void LCodeGen::DoMultiplyAddD(LMultiplyAddD* instr) { |
| 1287 | DoubleRegister addend = ToDoubleRegister(instr->addend()); |
| 1288 | DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1289 | DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1290 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1291 | |
| 1292 | // Unable to use madbr as the intermediate value is not rounded |
| 1293 | // to proper precision |
| 1294 | __ ldr(result, multiplier); |
| 1295 | __ mdbr(result, multiplicand); |
| 1296 | __ adbr(result, addend); |
| 1297 | } |
| 1298 | |
| 1299 | void LCodeGen::DoMultiplySubD(LMultiplySubD* instr) { |
| 1300 | DoubleRegister minuend = ToDoubleRegister(instr->minuend()); |
| 1301 | DoubleRegister multiplier = ToDoubleRegister(instr->multiplier()); |
| 1302 | DoubleRegister multiplicand = ToDoubleRegister(instr->multiplicand()); |
| 1303 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1304 | |
| 1305 | // Unable to use msdbr as the intermediate value is not rounded |
| 1306 | // to proper precision |
| 1307 | __ ldr(result, multiplier); |
| 1308 | __ mdbr(result, multiplicand); |
| 1309 | __ sdbr(result, minuend); |
| 1310 | } |
| 1311 | |
| 1312 | void LCodeGen::DoMulI(LMulI* instr) { |
| 1313 | Register scratch = scratch0(); |
| 1314 | Register result = ToRegister(instr->result()); |
| 1315 | // Note that result may alias left. |
| 1316 | Register left = ToRegister(instr->left()); |
| 1317 | LOperand* right_op = instr->right(); |
| 1318 | |
| 1319 | bool bailout_on_minus_zero = |
| 1320 | instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero); |
| 1321 | bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1322 | |
| 1323 | if (right_op->IsConstantOperand()) { |
| 1324 | int32_t constant = ToInteger32(LConstantOperand::cast(right_op)); |
| 1325 | |
| 1326 | if (bailout_on_minus_zero && (constant < 0)) { |
| 1327 | // The case of a null constant will be handled separately. |
| 1328 | // If constant is negative and left is null, the result should be -0. |
| 1329 | __ CmpP(left, Operand::Zero()); |
| 1330 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 1331 | } |
| 1332 | |
| 1333 | switch (constant) { |
| 1334 | case -1: |
| 1335 | if (can_overflow) { |
| 1336 | #if V8_TARGET_ARCH_S390X |
| 1337 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1338 | #endif |
| 1339 | __ LoadComplementRR(result, left); |
| 1340 | DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 1341 | #if V8_TARGET_ARCH_S390X |
| 1342 | } else { |
| 1343 | __ LoadComplementRR(result, left); |
| 1344 | __ TestIfInt32(result, r0); |
| 1345 | DeoptimizeIf(ne, instr, Deoptimizer::kOverflow); |
| 1346 | } |
| 1347 | #endif |
| 1348 | } else { |
| 1349 | __ LoadComplementRR(result, left); |
| 1350 | } |
| 1351 | break; |
| 1352 | case 0: |
| 1353 | if (bailout_on_minus_zero) { |
| 1354 | // If left is strictly negative and the constant is null, the |
| 1355 | // result is -0. Deoptimize if required, otherwise return 0. |
| 1356 | #if V8_TARGET_ARCH_S390X |
| 1357 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1358 | #endif |
| 1359 | __ Cmp32(left, Operand::Zero()); |
| 1360 | #if V8_TARGET_ARCH_S390X |
| 1361 | } else { |
| 1362 | __ Cmp32(left, Operand::Zero()); |
| 1363 | } |
| 1364 | #endif |
| 1365 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 1366 | } |
| 1367 | __ LoadImmP(result, Operand::Zero()); |
| 1368 | break; |
| 1369 | case 1: |
| 1370 | __ Move(result, left); |
| 1371 | break; |
| 1372 | default: |
| 1373 | // Multiplying by powers of two and powers of two plus or minus |
| 1374 | // one can be done faster with shifted operands. |
| 1375 | // For other constants we emit standard code. |
| 1376 | int32_t mask = constant >> 31; |
| 1377 | uint32_t constant_abs = (constant + mask) ^ mask; |
| 1378 | |
| 1379 | if (base::bits::IsPowerOfTwo32(constant_abs)) { |
| 1380 | int32_t shift = WhichPowerOf2(constant_abs); |
| 1381 | __ ShiftLeftP(result, left, Operand(shift)); |
| 1382 | // Correct the sign of the result if the constant is negative. |
| 1383 | if (constant < 0) __ LoadComplementRR(result, result); |
| 1384 | } else if (base::bits::IsPowerOfTwo32(constant_abs - 1)) { |
| 1385 | int32_t shift = WhichPowerOf2(constant_abs - 1); |
| 1386 | __ ShiftLeftP(scratch, left, Operand(shift)); |
| 1387 | __ AddP(result, scratch, left); |
| 1388 | // Correct the sign of the result if the constant is negative. |
| 1389 | if (constant < 0) __ LoadComplementRR(result, result); |
| 1390 | } else if (base::bits::IsPowerOfTwo32(constant_abs + 1)) { |
| 1391 | int32_t shift = WhichPowerOf2(constant_abs + 1); |
| 1392 | __ ShiftLeftP(scratch, left, Operand(shift)); |
| 1393 | __ SubP(result, scratch, left); |
| 1394 | // Correct the sign of the result if the constant is negative. |
| 1395 | if (constant < 0) __ LoadComplementRR(result, result); |
| 1396 | } else { |
| 1397 | // Generate standard code. |
| 1398 | __ Move(result, left); |
| 1399 | __ MulP(result, Operand(constant)); |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | } else { |
| 1404 | DCHECK(right_op->IsRegister()); |
| 1405 | Register right = ToRegister(right_op); |
| 1406 | |
| 1407 | if (can_overflow) { |
| 1408 | #if V8_TARGET_ARCH_S390X |
| 1409 | // result = left * right. |
| 1410 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1411 | __ SmiUntag(result, left); |
| 1412 | __ SmiUntag(scratch, right); |
| 1413 | __ msgr(result, scratch); |
| 1414 | } else { |
| 1415 | __ LoadRR(result, left); |
| 1416 | __ msgr(result, right); |
| 1417 | } |
| 1418 | __ TestIfInt32(result, r0); |
| 1419 | DeoptimizeIf(ne, instr, Deoptimizer::kOverflow); |
| 1420 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1421 | __ SmiTag(result); |
| 1422 | } |
| 1423 | #else |
| 1424 | // r0:scratch = scratch * right |
| 1425 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1426 | __ SmiUntag(scratch, left); |
| 1427 | __ mr_z(r0, right); |
| 1428 | __ LoadRR(result, scratch); |
| 1429 | } else { |
| 1430 | // r0:scratch = scratch * right |
| 1431 | __ LoadRR(scratch, left); |
| 1432 | __ mr_z(r0, right); |
| 1433 | __ LoadRR(result, scratch); |
| 1434 | } |
| 1435 | __ TestIfInt32(r0, result, scratch); |
| 1436 | DeoptimizeIf(ne, instr, Deoptimizer::kOverflow); |
| 1437 | #endif |
| 1438 | } else { |
| 1439 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1440 | __ SmiUntag(result, left); |
| 1441 | __ Mul(result, result, right); |
| 1442 | } else { |
| 1443 | __ Mul(result, left, right); |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | if (bailout_on_minus_zero) { |
| 1448 | Label done; |
| 1449 | #if V8_TARGET_ARCH_S390X |
| 1450 | if (instr->hydrogen()->representation().IsSmi()) { |
| 1451 | #endif |
| 1452 | __ XorP(r0, left, right); |
| 1453 | __ LoadAndTestRR(r0, r0); |
| 1454 | __ bge(&done, Label::kNear); |
| 1455 | #if V8_TARGET_ARCH_S390X |
| 1456 | } else { |
| 1457 | __ XorP(r0, left, right); |
| 1458 | __ Cmp32(r0, Operand::Zero()); |
| 1459 | __ bge(&done, Label::kNear); |
| 1460 | } |
| 1461 | #endif |
| 1462 | // Bail out if the result is minus zero. |
| 1463 | __ CmpP(result, Operand::Zero()); |
| 1464 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 1465 | __ bind(&done); |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | void LCodeGen::DoBitI(LBitI* instr) { |
| 1471 | LOperand* left_op = instr->left(); |
| 1472 | LOperand* right_op = instr->right(); |
| 1473 | DCHECK(left_op->IsRegister()); |
| 1474 | Register left = ToRegister(left_op); |
| 1475 | Register result = ToRegister(instr->result()); |
| 1476 | |
| 1477 | if (right_op->IsConstantOperand()) { |
| 1478 | switch (instr->op()) { |
| 1479 | case Token::BIT_AND: |
| 1480 | __ AndP(result, left, Operand(ToOperand(right_op))); |
| 1481 | break; |
| 1482 | case Token::BIT_OR: |
| 1483 | __ OrP(result, left, Operand(ToOperand(right_op))); |
| 1484 | break; |
| 1485 | case Token::BIT_XOR: |
| 1486 | __ XorP(result, left, Operand(ToOperand(right_op))); |
| 1487 | break; |
| 1488 | default: |
| 1489 | UNREACHABLE(); |
| 1490 | break; |
| 1491 | } |
| 1492 | } else if (right_op->IsStackSlot()) { |
| 1493 | // Reg-Mem instruction clobbers, so copy src to dst first. |
| 1494 | if (!left.is(result)) __ LoadRR(result, left); |
| 1495 | switch (instr->op()) { |
| 1496 | case Token::BIT_AND: |
| 1497 | __ AndP(result, ToMemOperand(right_op)); |
| 1498 | break; |
| 1499 | case Token::BIT_OR: |
| 1500 | __ OrP(result, ToMemOperand(right_op)); |
| 1501 | break; |
| 1502 | case Token::BIT_XOR: |
| 1503 | __ XorP(result, ToMemOperand(right_op)); |
| 1504 | break; |
| 1505 | default: |
| 1506 | UNREACHABLE(); |
| 1507 | break; |
| 1508 | } |
| 1509 | } else { |
| 1510 | DCHECK(right_op->IsRegister()); |
| 1511 | |
| 1512 | switch (instr->op()) { |
| 1513 | case Token::BIT_AND: |
| 1514 | __ AndP(result, left, ToRegister(right_op)); |
| 1515 | break; |
| 1516 | case Token::BIT_OR: |
| 1517 | __ OrP(result, left, ToRegister(right_op)); |
| 1518 | break; |
| 1519 | case Token::BIT_XOR: |
| 1520 | __ XorP(result, left, ToRegister(right_op)); |
| 1521 | break; |
| 1522 | default: |
| 1523 | UNREACHABLE(); |
| 1524 | break; |
| 1525 | } |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | void LCodeGen::DoShiftI(LShiftI* instr) { |
| 1530 | // Both 'left' and 'right' are "used at start" (see LCodeGen::DoShift), so |
| 1531 | // result may alias either of them. |
| 1532 | LOperand* right_op = instr->right(); |
| 1533 | Register left = ToRegister(instr->left()); |
| 1534 | Register result = ToRegister(instr->result()); |
| 1535 | Register scratch = scratch0(); |
| 1536 | if (right_op->IsRegister()) { |
| 1537 | // Mask the right_op operand. |
| 1538 | __ AndP(scratch, ToRegister(right_op), Operand(0x1F)); |
| 1539 | switch (instr->op()) { |
| 1540 | case Token::ROR: |
| 1541 | // rotate_right(a, b) == rotate_left(a, 32 - b) |
| 1542 | __ LoadComplementRR(scratch, scratch); |
| 1543 | __ rll(result, left, scratch, Operand(32)); |
| 1544 | #if V8_TARGET_ARCH_S390X |
| 1545 | __ lgfr(result, result); |
| 1546 | #endif |
| 1547 | break; |
| 1548 | case Token::SAR: |
| 1549 | __ ShiftRightArith(result, left, scratch); |
| 1550 | #if V8_TARGET_ARCH_S390X |
| 1551 | __ lgfr(result, result); |
| 1552 | #endif |
| 1553 | break; |
| 1554 | case Token::SHR: |
| 1555 | __ ShiftRight(result, left, scratch); |
| 1556 | #if V8_TARGET_ARCH_S390X |
| 1557 | __ lgfr(result, result); |
| 1558 | #endif |
| 1559 | if (instr->can_deopt()) { |
| 1560 | #if V8_TARGET_ARCH_S390X |
| 1561 | __ ltgfr(result, result /*, SetRC*/); |
| 1562 | #else |
| 1563 | __ ltr(result, result); // Set the <,==,> condition |
| 1564 | #endif |
| 1565 | DeoptimizeIf(lt, instr, Deoptimizer::kNegativeValue, cr0); |
| 1566 | } |
| 1567 | break; |
| 1568 | case Token::SHL: |
| 1569 | __ ShiftLeft(result, left, scratch); |
| 1570 | #if V8_TARGET_ARCH_S390X |
| 1571 | __ lgfr(result, result); |
| 1572 | #endif |
| 1573 | break; |
| 1574 | default: |
| 1575 | UNREACHABLE(); |
| 1576 | break; |
| 1577 | } |
| 1578 | } else { |
| 1579 | // Mask the right_op operand. |
| 1580 | int value = ToInteger32(LConstantOperand::cast(right_op)); |
| 1581 | uint8_t shift_count = static_cast<uint8_t>(value & 0x1F); |
| 1582 | switch (instr->op()) { |
| 1583 | case Token::ROR: |
| 1584 | if (shift_count != 0) { |
| 1585 | __ rll(result, left, Operand(32 - shift_count)); |
| 1586 | #if V8_TARGET_ARCH_S390X |
| 1587 | __ lgfr(result, result); |
| 1588 | #endif |
| 1589 | } else { |
| 1590 | __ Move(result, left); |
| 1591 | } |
| 1592 | break; |
| 1593 | case Token::SAR: |
| 1594 | if (shift_count != 0) { |
| 1595 | __ ShiftRightArith(result, left, Operand(shift_count)); |
| 1596 | #if V8_TARGET_ARCH_S390X |
| 1597 | __ lgfr(result, result); |
| 1598 | #endif |
| 1599 | } else { |
| 1600 | __ Move(result, left); |
| 1601 | } |
| 1602 | break; |
| 1603 | case Token::SHR: |
| 1604 | if (shift_count != 0) { |
| 1605 | __ ShiftRight(result, left, Operand(shift_count)); |
| 1606 | #if V8_TARGET_ARCH_S390X |
| 1607 | __ lgfr(result, result); |
| 1608 | #endif |
| 1609 | } else { |
| 1610 | if (instr->can_deopt()) { |
| 1611 | __ Cmp32(left, Operand::Zero()); |
| 1612 | DeoptimizeIf(lt, instr, Deoptimizer::kNegativeValue); |
| 1613 | } |
| 1614 | __ Move(result, left); |
| 1615 | } |
| 1616 | break; |
| 1617 | case Token::SHL: |
| 1618 | if (shift_count != 0) { |
| 1619 | #if V8_TARGET_ARCH_S390X |
| 1620 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 1621 | __ ShiftLeftP(result, left, Operand(shift_count)); |
| 1622 | #else |
| 1623 | if (instr->hydrogen_value()->representation().IsSmi() && |
| 1624 | instr->can_deopt()) { |
| 1625 | if (shift_count != 1) { |
| 1626 | __ ShiftLeft(result, left, Operand(shift_count - 1)); |
| 1627 | #if V8_TARGET_ARCH_S390X |
| 1628 | __ lgfr(result, result); |
| 1629 | #endif |
| 1630 | __ SmiTagCheckOverflow(result, result, scratch); |
| 1631 | } else { |
| 1632 | __ SmiTagCheckOverflow(result, left, scratch); |
| 1633 | } |
| 1634 | DeoptimizeIf(lt, instr, Deoptimizer::kOverflow, cr0); |
| 1635 | #endif |
| 1636 | } else { |
| 1637 | __ ShiftLeft(result, left, Operand(shift_count)); |
| 1638 | #if V8_TARGET_ARCH_S390X |
| 1639 | __ lgfr(result, result); |
| 1640 | #endif |
| 1641 | } |
| 1642 | } else { |
| 1643 | __ Move(result, left); |
| 1644 | } |
| 1645 | break; |
| 1646 | default: |
| 1647 | UNREACHABLE(); |
| 1648 | break; |
| 1649 | } |
| 1650 | } |
| 1651 | } |
| 1652 | |
| 1653 | void LCodeGen::DoSubI(LSubI* instr) { |
| 1654 | LOperand* left = instr->left(); |
| 1655 | LOperand* right = instr->right(); |
| 1656 | LOperand* result = instr->result(); |
| 1657 | |
| 1658 | bool isInteger = !(instr->hydrogen()->representation().IsSmi() || |
| 1659 | instr->hydrogen()->representation().IsExternal()); |
| 1660 | |
| 1661 | #if V8_TARGET_ARCH_S390X |
| 1662 | // The overflow detection needs to be tested on the lower 32-bits. |
| 1663 | // As a result, on 64-bit, we need to force 32-bit arithmetic operations |
| 1664 | // to set the CC overflow bit properly. The result is then sign-extended. |
| 1665 | bool checkOverflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1666 | #else |
| 1667 | bool checkOverflow = true; |
| 1668 | #endif |
| 1669 | |
| 1670 | if (right->IsConstantOperand()) { |
| 1671 | if (!isInteger || !checkOverflow) |
| 1672 | __ SubP(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1673 | else |
| 1674 | __ Sub32(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1675 | } else if (right->IsRegister()) { |
| 1676 | if (!isInteger) |
| 1677 | __ SubP(ToRegister(result), ToRegister(left), ToRegister(right)); |
| 1678 | else if (!checkOverflow) |
| 1679 | __ SubP_ExtendSrc(ToRegister(result), ToRegister(left), |
| 1680 | ToRegister(right)); |
| 1681 | else |
| 1682 | __ Sub32(ToRegister(result), ToRegister(left), ToRegister(right)); |
| 1683 | } else { |
| 1684 | if (!left->Equals(instr->result())) |
| 1685 | __ LoadRR(ToRegister(result), ToRegister(left)); |
| 1686 | |
| 1687 | MemOperand mem = ToMemOperand(right); |
| 1688 | if (!isInteger) { |
| 1689 | __ SubP(ToRegister(result), mem); |
| 1690 | } else { |
| 1691 | #if V8_TARGET_ARCH_S390X && !V8_TARGET_LITTLE_ENDIAN |
| 1692 | // We want to read the 32-bits directly from memory |
| 1693 | MemOperand Upper32Mem = MemOperand(mem.rb(), mem.rx(), mem.offset() + 4); |
| 1694 | #else |
| 1695 | MemOperand Upper32Mem = ToMemOperand(right); |
| 1696 | #endif |
| 1697 | if (checkOverflow) { |
| 1698 | __ Sub32(ToRegister(result), Upper32Mem); |
| 1699 | } else { |
| 1700 | __ SubP_ExtendSrc(ToRegister(result), Upper32Mem); |
| 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | #if V8_TARGET_ARCH_S390X |
| 1706 | if (isInteger && checkOverflow) |
| 1707 | __ lgfr(ToRegister(result), ToRegister(result)); |
| 1708 | #endif |
| 1709 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1710 | DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | void LCodeGen::DoRSubI(LRSubI* instr) { |
| 1715 | LOperand* left = instr->left(); |
| 1716 | LOperand* right = instr->right(); |
| 1717 | LOperand* result = instr->result(); |
| 1718 | |
| 1719 | DCHECK(!instr->hydrogen()->CheckFlag(HValue::kCanOverflow) && |
| 1720 | right->IsConstantOperand()); |
| 1721 | |
| 1722 | #if V8_TARGET_ARCH_S390X |
| 1723 | // The overflow detection needs to be tested on the lower 32-bits. |
| 1724 | // As a result, on 64-bit, we need to force 32-bit arithmetic operations |
| 1725 | // to set the CC overflow bit properly. The result is then sign-extended. |
| 1726 | bool checkOverflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1727 | #else |
| 1728 | bool checkOverflow = true; |
| 1729 | #endif |
| 1730 | |
| 1731 | Operand right_operand = ToOperand(right); |
| 1732 | __ mov(r0, right_operand); |
| 1733 | |
| 1734 | if (!checkOverflow) { |
| 1735 | __ SubP_ExtendSrc(ToRegister(result), r0, ToRegister(left)); |
| 1736 | } else { |
| 1737 | __ Sub32(ToRegister(result), r0, ToRegister(left)); |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | void LCodeGen::DoConstantI(LConstantI* instr) { |
| 1742 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1743 | } |
| 1744 | |
| 1745 | void LCodeGen::DoConstantS(LConstantS* instr) { |
| 1746 | __ LoadSmiLiteral(ToRegister(instr->result()), instr->value()); |
| 1747 | } |
| 1748 | |
| 1749 | void LCodeGen::DoConstantD(LConstantD* instr) { |
| 1750 | DCHECK(instr->result()->IsDoubleRegister()); |
| 1751 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1752 | uint64_t bits = instr->bits(); |
| 1753 | __ LoadDoubleLiteral(result, bits, scratch0()); |
| 1754 | } |
| 1755 | |
| 1756 | void LCodeGen::DoConstantE(LConstantE* instr) { |
| 1757 | __ mov(ToRegister(instr->result()), Operand(instr->value())); |
| 1758 | } |
| 1759 | |
| 1760 | void LCodeGen::DoConstantT(LConstantT* instr) { |
| 1761 | Handle<Object> object = instr->value(isolate()); |
| 1762 | AllowDeferredHandleDereference smi_check; |
| 1763 | __ Move(ToRegister(instr->result()), object); |
| 1764 | } |
| 1765 | |
| 1766 | MemOperand LCodeGen::BuildSeqStringOperand(Register string, LOperand* index, |
| 1767 | String::Encoding encoding) { |
| 1768 | if (index->IsConstantOperand()) { |
| 1769 | int offset = ToInteger32(LConstantOperand::cast(index)); |
| 1770 | if (encoding == String::TWO_BYTE_ENCODING) { |
| 1771 | offset *= kUC16Size; |
| 1772 | } |
| 1773 | STATIC_ASSERT(kCharSize == 1); |
| 1774 | return FieldMemOperand(string, SeqString::kHeaderSize + offset); |
| 1775 | } |
| 1776 | Register scratch = scratch0(); |
| 1777 | DCHECK(!scratch.is(string)); |
| 1778 | DCHECK(!scratch.is(ToRegister(index))); |
| 1779 | // TODO(joransiu) : Fold Add into FieldMemOperand |
| 1780 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1781 | __ AddP(scratch, string, ToRegister(index)); |
| 1782 | } else { |
| 1783 | STATIC_ASSERT(kUC16Size == 2); |
| 1784 | __ ShiftLeftP(scratch, ToRegister(index), Operand(1)); |
| 1785 | __ AddP(scratch, string, scratch); |
| 1786 | } |
| 1787 | return FieldMemOperand(scratch, SeqString::kHeaderSize); |
| 1788 | } |
| 1789 | |
| 1790 | void LCodeGen::DoSeqStringGetChar(LSeqStringGetChar* instr) { |
| 1791 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1792 | Register string = ToRegister(instr->string()); |
| 1793 | Register result = ToRegister(instr->result()); |
| 1794 | |
| 1795 | if (FLAG_debug_code) { |
| 1796 | Register scratch = scratch0(); |
| 1797 | __ LoadP(scratch, FieldMemOperand(string, HeapObject::kMapOffset)); |
| 1798 | __ llc(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 1799 | |
| 1800 | __ AndP(scratch, scratch, |
| 1801 | Operand(kStringRepresentationMask | kStringEncodingMask)); |
| 1802 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1803 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 1804 | __ CmpP(scratch, |
| 1805 | Operand(encoding == String::ONE_BYTE_ENCODING ? one_byte_seq_type |
| 1806 | : two_byte_seq_type)); |
| 1807 | __ Check(eq, kUnexpectedStringType); |
| 1808 | } |
| 1809 | |
| 1810 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1811 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1812 | __ llc(result, operand); |
| 1813 | } else { |
| 1814 | __ llh(result, operand); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | void LCodeGen::DoSeqStringSetChar(LSeqStringSetChar* instr) { |
| 1819 | String::Encoding encoding = instr->hydrogen()->encoding(); |
| 1820 | Register string = ToRegister(instr->string()); |
| 1821 | Register value = ToRegister(instr->value()); |
| 1822 | |
| 1823 | if (FLAG_debug_code) { |
| 1824 | Register index = ToRegister(instr->index()); |
| 1825 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 1826 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 1827 | int encoding_mask = |
| 1828 | instr->hydrogen()->encoding() == String::ONE_BYTE_ENCODING |
| 1829 | ? one_byte_seq_type |
| 1830 | : two_byte_seq_type; |
| 1831 | __ EmitSeqStringSetCharCheck(string, index, value, encoding_mask); |
| 1832 | } |
| 1833 | |
| 1834 | MemOperand operand = BuildSeqStringOperand(string, instr->index(), encoding); |
| 1835 | if (encoding == String::ONE_BYTE_ENCODING) { |
| 1836 | __ stc(value, operand); |
| 1837 | } else { |
| 1838 | __ sth(value, operand); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | void LCodeGen::DoAddI(LAddI* instr) { |
| 1843 | LOperand* left = instr->left(); |
| 1844 | LOperand* right = instr->right(); |
| 1845 | LOperand* result = instr->result(); |
| 1846 | bool isInteger = !(instr->hydrogen()->representation().IsSmi() || |
| 1847 | instr->hydrogen()->representation().IsExternal()); |
| 1848 | #if V8_TARGET_ARCH_S390X |
| 1849 | // The overflow detection needs to be tested on the lower 32-bits. |
| 1850 | // As a result, on 64-bit, we need to force 32-bit arithmetic operations |
| 1851 | // to set the CC overflow bit properly. The result is then sign-extended. |
| 1852 | bool checkOverflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); |
| 1853 | #else |
| 1854 | bool checkOverflow = true; |
| 1855 | #endif |
| 1856 | |
| 1857 | if (right->IsConstantOperand()) { |
| 1858 | if (!isInteger || !checkOverflow) |
| 1859 | __ AddP(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1860 | else |
| 1861 | __ Add32(ToRegister(result), ToRegister(left), ToOperand(right)); |
| 1862 | } else if (right->IsRegister()) { |
| 1863 | if (!isInteger) |
| 1864 | __ AddP(ToRegister(result), ToRegister(left), ToRegister(right)); |
| 1865 | else if (!checkOverflow) |
| 1866 | __ AddP_ExtendSrc(ToRegister(result), ToRegister(left), |
| 1867 | ToRegister(right)); |
| 1868 | else |
| 1869 | __ Add32(ToRegister(result), ToRegister(left), ToRegister(right)); |
| 1870 | } else { |
| 1871 | if (!left->Equals(instr->result())) |
| 1872 | __ LoadRR(ToRegister(result), ToRegister(left)); |
| 1873 | |
| 1874 | MemOperand mem = ToMemOperand(right); |
| 1875 | if (!isInteger) { |
| 1876 | __ AddP(ToRegister(result), mem); |
| 1877 | } else { |
| 1878 | #if V8_TARGET_ARCH_S390X && !V8_TARGET_LITTLE_ENDIAN |
| 1879 | // We want to read the 32-bits directly from memory |
| 1880 | MemOperand Upper32Mem = MemOperand(mem.rb(), mem.rx(), mem.offset() + 4); |
| 1881 | #else |
| 1882 | MemOperand Upper32Mem = ToMemOperand(right); |
| 1883 | #endif |
| 1884 | if (checkOverflow) { |
| 1885 | __ Add32(ToRegister(result), Upper32Mem); |
| 1886 | } else { |
| 1887 | __ AddP_ExtendSrc(ToRegister(result), Upper32Mem); |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | |
| 1892 | #if V8_TARGET_ARCH_S390X |
| 1893 | if (isInteger && checkOverflow) |
| 1894 | __ lgfr(ToRegister(result), ToRegister(result)); |
| 1895 | #endif |
| 1896 | // Doptimize on overflow |
| 1897 | if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
| 1898 | DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | void LCodeGen::DoMathMinMax(LMathMinMax* instr) { |
| 1903 | LOperand* left = instr->left(); |
| 1904 | LOperand* right = instr->right(); |
| 1905 | HMathMinMax::Operation operation = instr->hydrogen()->operation(); |
| 1906 | Condition cond = (operation == HMathMinMax::kMathMin) ? le : ge; |
| 1907 | if (instr->hydrogen()->representation().IsSmiOrInteger32()) { |
| 1908 | Register left_reg = ToRegister(left); |
| 1909 | Register right_reg = EmitLoadRegister(right, ip); |
| 1910 | Register result_reg = ToRegister(instr->result()); |
| 1911 | Label return_left, done; |
| 1912 | #if V8_TARGET_ARCH_S390X |
| 1913 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 1914 | #endif |
| 1915 | __ CmpP(left_reg, right_reg); |
| 1916 | #if V8_TARGET_ARCH_S390X |
| 1917 | } else { |
| 1918 | __ Cmp32(left_reg, right_reg); |
| 1919 | } |
| 1920 | #endif |
| 1921 | __ b(cond, &return_left, Label::kNear); |
| 1922 | __ Move(result_reg, right_reg); |
| 1923 | __ b(&done, Label::kNear); |
| 1924 | __ bind(&return_left); |
| 1925 | __ Move(result_reg, left_reg); |
| 1926 | __ bind(&done); |
| 1927 | } else { |
| 1928 | DCHECK(instr->hydrogen()->representation().IsDouble()); |
| 1929 | DoubleRegister left_reg = ToDoubleRegister(left); |
| 1930 | DoubleRegister right_reg = ToDoubleRegister(right); |
| 1931 | DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 1932 | Label check_nan_left, check_zero, return_left, return_right, done; |
| 1933 | __ cdbr(left_reg, right_reg); |
| 1934 | __ bunordered(&check_nan_left, Label::kNear); |
| 1935 | __ beq(&check_zero); |
| 1936 | __ b(cond, &return_left, Label::kNear); |
| 1937 | __ b(&return_right, Label::kNear); |
| 1938 | |
| 1939 | __ bind(&check_zero); |
| 1940 | __ lzdr(kDoubleRegZero); |
| 1941 | __ cdbr(left_reg, kDoubleRegZero); |
| 1942 | __ bne(&return_left, Label::kNear); // left == right != 0. |
| 1943 | |
| 1944 | // At this point, both left and right are either 0 or -0. |
| 1945 | // N.B. The following works because +0 + -0 == +0 |
| 1946 | if (operation == HMathMinMax::kMathMin) { |
| 1947 | // For min we want logical-or of sign bit: -(-L + -R) |
| 1948 | __ lcdbr(left_reg, left_reg); |
| 1949 | __ ldr(result_reg, left_reg); |
| 1950 | if (left_reg.is(right_reg)) { |
| 1951 | __ adbr(result_reg, right_reg); |
| 1952 | } else { |
| 1953 | __ sdbr(result_reg, right_reg); |
| 1954 | } |
| 1955 | __ lcdbr(result_reg, result_reg); |
| 1956 | } else { |
| 1957 | // For max we want logical-and of sign bit: (L + R) |
| 1958 | __ ldr(result_reg, left_reg); |
| 1959 | __ adbr(result_reg, right_reg); |
| 1960 | } |
| 1961 | __ b(&done, Label::kNear); |
| 1962 | |
| 1963 | __ bind(&check_nan_left); |
| 1964 | __ cdbr(left_reg, left_reg); |
| 1965 | __ bunordered(&return_left, Label::kNear); // left == NaN. |
| 1966 | |
| 1967 | __ bind(&return_right); |
| 1968 | if (!right_reg.is(result_reg)) { |
| 1969 | __ ldr(result_reg, right_reg); |
| 1970 | } |
| 1971 | __ b(&done, Label::kNear); |
| 1972 | |
| 1973 | __ bind(&return_left); |
| 1974 | if (!left_reg.is(result_reg)) { |
| 1975 | __ ldr(result_reg, left_reg); |
| 1976 | } |
| 1977 | __ bind(&done); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | void LCodeGen::DoArithmeticD(LArithmeticD* instr) { |
| 1982 | DoubleRegister left = ToDoubleRegister(instr->left()); |
| 1983 | DoubleRegister right = ToDoubleRegister(instr->right()); |
| 1984 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 1985 | // All operations except MOD are computed in-place. |
| 1986 | DCHECK(instr->op() == Token::MOD || left.is(result)); |
| 1987 | switch (instr->op()) { |
| 1988 | case Token::ADD: |
| 1989 | __ adbr(result, right); |
| 1990 | break; |
| 1991 | case Token::SUB: |
| 1992 | __ sdbr(result, right); |
| 1993 | break; |
| 1994 | case Token::MUL: |
| 1995 | __ mdbr(result, right); |
| 1996 | break; |
| 1997 | case Token::DIV: |
| 1998 | __ ddbr(result, right); |
| 1999 | break; |
| 2000 | case Token::MOD: { |
| 2001 | __ PrepareCallCFunction(0, 2, scratch0()); |
| 2002 | __ MovToFloatParameters(left, right); |
| 2003 | __ CallCFunction(ExternalReference::mod_two_doubles_operation(isolate()), |
| 2004 | 0, 2); |
| 2005 | // Move the result in the double result register. |
| 2006 | __ MovFromFloatResult(result); |
| 2007 | break; |
| 2008 | } |
| 2009 | default: |
| 2010 | UNREACHABLE(); |
| 2011 | break; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | void LCodeGen::DoArithmeticT(LArithmeticT* instr) { |
| 2016 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2017 | DCHECK(ToRegister(instr->left()).is(r3)); |
| 2018 | DCHECK(ToRegister(instr->right()).is(r2)); |
| 2019 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 2020 | |
| 2021 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), instr->op()).code(); |
| 2022 | CallCode(code, RelocInfo::CODE_TARGET, instr); |
| 2023 | } |
| 2024 | |
| 2025 | template <class InstrType> |
| 2026 | void LCodeGen::EmitBranch(InstrType instr, Condition cond) { |
| 2027 | int left_block = instr->TrueDestination(chunk_); |
| 2028 | int right_block = instr->FalseDestination(chunk_); |
| 2029 | |
| 2030 | int next_block = GetNextEmittedBlock(); |
| 2031 | |
| 2032 | if (right_block == left_block || cond == al) { |
| 2033 | EmitGoto(left_block); |
| 2034 | } else if (left_block == next_block) { |
| 2035 | __ b(NegateCondition(cond), chunk_->GetAssemblyLabel(right_block)); |
| 2036 | } else if (right_block == next_block) { |
| 2037 | __ b(cond, chunk_->GetAssemblyLabel(left_block)); |
| 2038 | } else { |
| 2039 | __ b(cond, chunk_->GetAssemblyLabel(left_block)); |
| 2040 | __ b(chunk_->GetAssemblyLabel(right_block)); |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | template <class InstrType> |
| 2045 | void LCodeGen::EmitTrueBranch(InstrType instr, Condition cond) { |
| 2046 | int true_block = instr->TrueDestination(chunk_); |
| 2047 | __ b(cond, chunk_->GetAssemblyLabel(true_block)); |
| 2048 | } |
| 2049 | |
| 2050 | template <class InstrType> |
| 2051 | void LCodeGen::EmitFalseBranch(InstrType instr, Condition cond) { |
| 2052 | int false_block = instr->FalseDestination(chunk_); |
| 2053 | __ b(cond, chunk_->GetAssemblyLabel(false_block)); |
| 2054 | } |
| 2055 | |
| 2056 | void LCodeGen::DoDebugBreak(LDebugBreak* instr) { __ stop("LBreak"); } |
| 2057 | |
| 2058 | void LCodeGen::DoBranch(LBranch* instr) { |
| 2059 | Representation r = instr->hydrogen()->value()->representation(); |
| 2060 | DoubleRegister dbl_scratch = double_scratch0(); |
| 2061 | |
| 2062 | if (r.IsInteger32()) { |
| 2063 | DCHECK(!info()->IsStub()); |
| 2064 | Register reg = ToRegister(instr->value()); |
| 2065 | __ Cmp32(reg, Operand::Zero()); |
| 2066 | EmitBranch(instr, ne); |
| 2067 | } else if (r.IsSmi()) { |
| 2068 | DCHECK(!info()->IsStub()); |
| 2069 | Register reg = ToRegister(instr->value()); |
| 2070 | __ CmpP(reg, Operand::Zero()); |
| 2071 | EmitBranch(instr, ne); |
| 2072 | } else if (r.IsDouble()) { |
| 2073 | DCHECK(!info()->IsStub()); |
| 2074 | DoubleRegister reg = ToDoubleRegister(instr->value()); |
| 2075 | __ lzdr(kDoubleRegZero); |
| 2076 | __ cdbr(reg, kDoubleRegZero); |
| 2077 | // Test the double value. Zero and NaN are false. |
| 2078 | Condition lt_gt = static_cast<Condition>(lt | gt); |
| 2079 | |
| 2080 | EmitBranch(instr, lt_gt); |
| 2081 | } else { |
| 2082 | DCHECK(r.IsTagged()); |
| 2083 | Register reg = ToRegister(instr->value()); |
| 2084 | HType type = instr->hydrogen()->value()->type(); |
| 2085 | if (type.IsBoolean()) { |
| 2086 | DCHECK(!info()->IsStub()); |
| 2087 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 2088 | EmitBranch(instr, eq); |
| 2089 | } else if (type.IsSmi()) { |
| 2090 | DCHECK(!info()->IsStub()); |
| 2091 | __ CmpP(reg, Operand::Zero()); |
| 2092 | EmitBranch(instr, ne); |
| 2093 | } else if (type.IsJSArray()) { |
| 2094 | DCHECK(!info()->IsStub()); |
| 2095 | EmitBranch(instr, al); |
| 2096 | } else if (type.IsHeapNumber()) { |
| 2097 | DCHECK(!info()->IsStub()); |
| 2098 | __ ld(dbl_scratch, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2099 | // Test the double value. Zero and NaN are false. |
| 2100 | __ lzdr(kDoubleRegZero); |
| 2101 | __ cdbr(dbl_scratch, kDoubleRegZero); |
| 2102 | Condition lt_gt = static_cast<Condition>(lt | gt); |
| 2103 | EmitBranch(instr, lt_gt); |
| 2104 | } else if (type.IsString()) { |
| 2105 | DCHECK(!info()->IsStub()); |
| 2106 | __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 2107 | __ CmpP(ip, Operand::Zero()); |
| 2108 | EmitBranch(instr, ne); |
| 2109 | } else { |
| 2110 | ToBooleanICStub::Types expected = |
| 2111 | instr->hydrogen()->expected_input_types(); |
| 2112 | // Avoid deopts in the case where we've never executed this path before. |
| 2113 | if (expected.IsEmpty()) expected = ToBooleanICStub::Types::Generic(); |
| 2114 | |
| 2115 | if (expected.Contains(ToBooleanICStub::UNDEFINED)) { |
| 2116 | // undefined -> false. |
| 2117 | __ CompareRoot(reg, Heap::kUndefinedValueRootIndex); |
| 2118 | __ beq(instr->FalseLabel(chunk_)); |
| 2119 | } |
| 2120 | if (expected.Contains(ToBooleanICStub::BOOLEAN)) { |
| 2121 | // Boolean -> its value. |
| 2122 | __ CompareRoot(reg, Heap::kTrueValueRootIndex); |
| 2123 | __ beq(instr->TrueLabel(chunk_)); |
| 2124 | __ CompareRoot(reg, Heap::kFalseValueRootIndex); |
| 2125 | __ beq(instr->FalseLabel(chunk_)); |
| 2126 | } |
| 2127 | if (expected.Contains(ToBooleanICStub::NULL_TYPE)) { |
| 2128 | // 'null' -> false. |
| 2129 | __ CompareRoot(reg, Heap::kNullValueRootIndex); |
| 2130 | __ beq(instr->FalseLabel(chunk_)); |
| 2131 | } |
| 2132 | |
| 2133 | if (expected.Contains(ToBooleanICStub::SMI)) { |
| 2134 | // Smis: 0 -> false, all other -> true. |
| 2135 | __ CmpP(reg, Operand::Zero()); |
| 2136 | __ beq(instr->FalseLabel(chunk_)); |
| 2137 | __ JumpIfSmi(reg, instr->TrueLabel(chunk_)); |
| 2138 | } else if (expected.NeedsMap()) { |
| 2139 | // If we need a map later and have a Smi -> deopt. |
| 2140 | __ TestIfSmi(reg); |
| 2141 | DeoptimizeIf(eq, instr, Deoptimizer::kSmi, cr0); |
| 2142 | } |
| 2143 | |
| 2144 | const Register map = scratch0(); |
| 2145 | if (expected.NeedsMap()) { |
| 2146 | __ LoadP(map, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2147 | |
| 2148 | if (expected.CanBeUndetectable()) { |
| 2149 | // Undetectable -> false. |
| 2150 | __ tm(FieldMemOperand(map, Map::kBitFieldOffset), |
| 2151 | Operand(1 << Map::kIsUndetectable)); |
| 2152 | __ bne(instr->FalseLabel(chunk_)); |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | if (expected.Contains(ToBooleanICStub::SPEC_OBJECT)) { |
| 2157 | // spec object -> true. |
| 2158 | __ CompareInstanceType(map, ip, FIRST_JS_RECEIVER_TYPE); |
| 2159 | __ bge(instr->TrueLabel(chunk_)); |
| 2160 | } |
| 2161 | |
| 2162 | if (expected.Contains(ToBooleanICStub::STRING)) { |
| 2163 | // String value -> false iff empty. |
| 2164 | Label not_string; |
| 2165 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
| 2166 | __ bge(¬_string, Label::kNear); |
| 2167 | __ LoadP(ip, FieldMemOperand(reg, String::kLengthOffset)); |
| 2168 | __ CmpP(ip, Operand::Zero()); |
| 2169 | __ bne(instr->TrueLabel(chunk_)); |
| 2170 | __ b(instr->FalseLabel(chunk_)); |
| 2171 | __ bind(¬_string); |
| 2172 | } |
| 2173 | |
| 2174 | if (expected.Contains(ToBooleanICStub::SYMBOL)) { |
| 2175 | // Symbol value -> true. |
| 2176 | __ CompareInstanceType(map, ip, SYMBOL_TYPE); |
| 2177 | __ beq(instr->TrueLabel(chunk_)); |
| 2178 | } |
| 2179 | |
| 2180 | if (expected.Contains(ToBooleanICStub::SIMD_VALUE)) { |
| 2181 | // SIMD value -> true. |
| 2182 | Label not_simd; |
| 2183 | __ CompareInstanceType(map, ip, SIMD128_VALUE_TYPE); |
| 2184 | __ beq(instr->TrueLabel(chunk_)); |
| 2185 | } |
| 2186 | |
| 2187 | if (expected.Contains(ToBooleanICStub::HEAP_NUMBER)) { |
| 2188 | // heap number -> false iff +0, -0, or NaN. |
| 2189 | Label not_heap_number; |
| 2190 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 2191 | __ bne(¬_heap_number, Label::kNear); |
| 2192 | __ LoadDouble(dbl_scratch, |
| 2193 | FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 2194 | __ lzdr(kDoubleRegZero); |
| 2195 | __ cdbr(dbl_scratch, kDoubleRegZero); |
| 2196 | __ bunordered(instr->FalseLabel(chunk_)); // NaN -> false. |
| 2197 | __ beq(instr->FalseLabel(chunk_)); // +0, -0 -> false. |
| 2198 | __ b(instr->TrueLabel(chunk_)); |
| 2199 | __ bind(¬_heap_number); |
| 2200 | } |
| 2201 | |
| 2202 | if (!expected.IsGeneric()) { |
| 2203 | // We've seen something for the first time -> deopt. |
| 2204 | // This can only happen if we are not generic already. |
| 2205 | DeoptimizeIf(al, instr, Deoptimizer::kUnexpectedObject); |
| 2206 | } |
| 2207 | } |
| 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | void LCodeGen::EmitGoto(int block) { |
| 2212 | if (!IsNextEmittedBlock(block)) { |
| 2213 | __ b(chunk_->GetAssemblyLabel(LookupDestination(block))); |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | void LCodeGen::DoGoto(LGoto* instr) { EmitGoto(instr->block_id()); } |
| 2218 | |
| 2219 | Condition LCodeGen::TokenToCondition(Token::Value op) { |
| 2220 | Condition cond = kNoCondition; |
| 2221 | switch (op) { |
| 2222 | case Token::EQ: |
| 2223 | case Token::EQ_STRICT: |
| 2224 | cond = eq; |
| 2225 | break; |
| 2226 | case Token::NE: |
| 2227 | case Token::NE_STRICT: |
| 2228 | cond = ne; |
| 2229 | break; |
| 2230 | case Token::LT: |
| 2231 | cond = lt; |
| 2232 | break; |
| 2233 | case Token::GT: |
| 2234 | cond = gt; |
| 2235 | break; |
| 2236 | case Token::LTE: |
| 2237 | cond = le; |
| 2238 | break; |
| 2239 | case Token::GTE: |
| 2240 | cond = ge; |
| 2241 | break; |
| 2242 | case Token::IN: |
| 2243 | case Token::INSTANCEOF: |
| 2244 | default: |
| 2245 | UNREACHABLE(); |
| 2246 | } |
| 2247 | return cond; |
| 2248 | } |
| 2249 | |
| 2250 | void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) { |
| 2251 | LOperand* left = instr->left(); |
| 2252 | LOperand* right = instr->right(); |
| 2253 | bool is_unsigned = |
| 2254 | instr->hydrogen()->left()->CheckFlag(HInstruction::kUint32) || |
| 2255 | instr->hydrogen()->right()->CheckFlag(HInstruction::kUint32); |
| 2256 | Condition cond = TokenToCondition(instr->op()); |
| 2257 | |
| 2258 | if (left->IsConstantOperand() && right->IsConstantOperand()) { |
| 2259 | // We can statically evaluate the comparison. |
| 2260 | double left_val = ToDouble(LConstantOperand::cast(left)); |
| 2261 | double right_val = ToDouble(LConstantOperand::cast(right)); |
| 2262 | int next_block = Token::EvalComparison(instr->op(), left_val, right_val) |
| 2263 | ? instr->TrueDestination(chunk_) |
| 2264 | : instr->FalseDestination(chunk_); |
| 2265 | EmitGoto(next_block); |
| 2266 | } else { |
| 2267 | if (instr->is_double()) { |
| 2268 | // Compare left and right operands as doubles and load the |
| 2269 | // resulting flags into the normal status register. |
| 2270 | __ cdbr(ToDoubleRegister(left), ToDoubleRegister(right)); |
| 2271 | // If a NaN is involved, i.e. the result is unordered, |
| 2272 | // jump to false block label. |
| 2273 | __ bunordered(instr->FalseLabel(chunk_)); |
| 2274 | } else { |
| 2275 | if (right->IsConstantOperand()) { |
| 2276 | int32_t value = ToInteger32(LConstantOperand::cast(right)); |
| 2277 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2278 | if (is_unsigned) { |
| 2279 | __ CmpLogicalSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2280 | } else { |
| 2281 | __ CmpSmiLiteral(ToRegister(left), Smi::FromInt(value), r0); |
| 2282 | } |
| 2283 | } else { |
| 2284 | if (is_unsigned) { |
| 2285 | __ CmpLogical32(ToRegister(left), ToOperand(right)); |
| 2286 | } else { |
| 2287 | __ Cmp32(ToRegister(left), ToOperand(right)); |
| 2288 | } |
| 2289 | } |
| 2290 | } else if (left->IsConstantOperand()) { |
| 2291 | int32_t value = ToInteger32(LConstantOperand::cast(left)); |
| 2292 | if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2293 | if (is_unsigned) { |
| 2294 | __ CmpLogicalSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2295 | } else { |
| 2296 | __ CmpSmiLiteral(ToRegister(right), Smi::FromInt(value), r0); |
| 2297 | } |
| 2298 | } else { |
| 2299 | if (is_unsigned) { |
| 2300 | __ CmpLogical32(ToRegister(right), ToOperand(left)); |
| 2301 | } else { |
| 2302 | __ Cmp32(ToRegister(right), ToOperand(left)); |
| 2303 | } |
| 2304 | } |
| 2305 | // We commuted the operands, so commute the condition. |
| 2306 | cond = CommuteCondition(cond); |
| 2307 | } else if (instr->hydrogen_value()->representation().IsSmi()) { |
| 2308 | if (is_unsigned) { |
| 2309 | __ CmpLogicalP(ToRegister(left), ToRegister(right)); |
| 2310 | } else { |
| 2311 | __ CmpP(ToRegister(left), ToRegister(right)); |
| 2312 | } |
| 2313 | } else { |
| 2314 | if (is_unsigned) { |
| 2315 | __ CmpLogical32(ToRegister(left), ToRegister(right)); |
| 2316 | } else { |
| 2317 | __ Cmp32(ToRegister(left), ToRegister(right)); |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | EmitBranch(instr, cond); |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | void LCodeGen::DoCmpObjectEqAndBranch(LCmpObjectEqAndBranch* instr) { |
| 2326 | Register left = ToRegister(instr->left()); |
| 2327 | Register right = ToRegister(instr->right()); |
| 2328 | |
| 2329 | __ CmpP(left, right); |
| 2330 | EmitBranch(instr, eq); |
| 2331 | } |
| 2332 | |
| 2333 | void LCodeGen::DoCmpHoleAndBranch(LCmpHoleAndBranch* instr) { |
| 2334 | if (instr->hydrogen()->representation().IsTagged()) { |
| 2335 | Register input_reg = ToRegister(instr->object()); |
| 2336 | __ CmpP(input_reg, Operand(factory()->the_hole_value())); |
| 2337 | EmitBranch(instr, eq); |
| 2338 | return; |
| 2339 | } |
| 2340 | |
| 2341 | DoubleRegister input_reg = ToDoubleRegister(instr->object()); |
| 2342 | __ cdbr(input_reg, input_reg); |
| 2343 | EmitFalseBranch(instr, ordered); |
| 2344 | |
| 2345 | Register scratch = scratch0(); |
| 2346 | // Convert to GPR and examine the upper 32 bits |
| 2347 | __ lgdr(scratch, input_reg); |
| 2348 | __ srlg(scratch, scratch, Operand(32)); |
| 2349 | __ Cmp32(scratch, Operand(kHoleNanUpper32)); |
| 2350 | EmitBranch(instr, eq); |
| 2351 | } |
| 2352 | |
| 2353 | Condition LCodeGen::EmitIsString(Register input, Register temp1, |
| 2354 | Label* is_not_string, |
| 2355 | SmiCheck check_needed = INLINE_SMI_CHECK) { |
| 2356 | if (check_needed == INLINE_SMI_CHECK) { |
| 2357 | __ JumpIfSmi(input, is_not_string); |
| 2358 | } |
| 2359 | __ CompareObjectType(input, temp1, temp1, FIRST_NONSTRING_TYPE); |
| 2360 | |
| 2361 | return lt; |
| 2362 | } |
| 2363 | |
| 2364 | void LCodeGen::DoIsStringAndBranch(LIsStringAndBranch* instr) { |
| 2365 | Register reg = ToRegister(instr->value()); |
| 2366 | Register temp1 = ToRegister(instr->temp()); |
| 2367 | |
| 2368 | SmiCheck check_needed = instr->hydrogen()->value()->type().IsHeapObject() |
| 2369 | ? OMIT_SMI_CHECK |
| 2370 | : INLINE_SMI_CHECK; |
| 2371 | Condition true_cond = |
| 2372 | EmitIsString(reg, temp1, instr->FalseLabel(chunk_), check_needed); |
| 2373 | |
| 2374 | EmitBranch(instr, true_cond); |
| 2375 | } |
| 2376 | |
| 2377 | void LCodeGen::DoIsSmiAndBranch(LIsSmiAndBranch* instr) { |
| 2378 | Register input_reg = EmitLoadRegister(instr->value(), ip); |
| 2379 | __ TestIfSmi(input_reg); |
| 2380 | EmitBranch(instr, eq); |
| 2381 | } |
| 2382 | |
| 2383 | void LCodeGen::DoIsUndetectableAndBranch(LIsUndetectableAndBranch* instr) { |
| 2384 | Register input = ToRegister(instr->value()); |
| 2385 | Register temp = ToRegister(instr->temp()); |
| 2386 | |
| 2387 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 2388 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2389 | } |
| 2390 | __ LoadP(temp, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 2391 | __ tm(FieldMemOperand(temp, Map::kBitFieldOffset), |
| 2392 | Operand(1 << Map::kIsUndetectable)); |
| 2393 | EmitBranch(instr, ne); |
| 2394 | } |
| 2395 | |
| 2396 | static Condition ComputeCompareCondition(Token::Value op) { |
| 2397 | switch (op) { |
| 2398 | case Token::EQ_STRICT: |
| 2399 | case Token::EQ: |
| 2400 | return eq; |
| 2401 | case Token::LT: |
| 2402 | return lt; |
| 2403 | case Token::GT: |
| 2404 | return gt; |
| 2405 | case Token::LTE: |
| 2406 | return le; |
| 2407 | case Token::GTE: |
| 2408 | return ge; |
| 2409 | default: |
| 2410 | UNREACHABLE(); |
| 2411 | return kNoCondition; |
| 2412 | } |
| 2413 | } |
| 2414 | |
| 2415 | void LCodeGen::DoStringCompareAndBranch(LStringCompareAndBranch* instr) { |
| 2416 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2417 | DCHECK(ToRegister(instr->left()).is(r3)); |
| 2418 | DCHECK(ToRegister(instr->right()).is(r2)); |
| 2419 | |
| 2420 | Handle<Code> code = CodeFactory::StringCompare(isolate(), instr->op()).code(); |
| 2421 | CallCode(code, RelocInfo::CODE_TARGET, instr); |
| 2422 | __ CompareRoot(r2, Heap::kTrueValueRootIndex); |
| 2423 | EmitBranch(instr, eq); |
| 2424 | } |
| 2425 | |
| 2426 | static InstanceType TestType(HHasInstanceTypeAndBranch* instr) { |
| 2427 | InstanceType from = instr->from(); |
| 2428 | InstanceType to = instr->to(); |
| 2429 | if (from == FIRST_TYPE) return to; |
| 2430 | DCHECK(from == to || to == LAST_TYPE); |
| 2431 | return from; |
| 2432 | } |
| 2433 | |
| 2434 | static Condition BranchCondition(HHasInstanceTypeAndBranch* instr) { |
| 2435 | InstanceType from = instr->from(); |
| 2436 | InstanceType to = instr->to(); |
| 2437 | if (from == to) return eq; |
| 2438 | if (to == LAST_TYPE) return ge; |
| 2439 | if (from == FIRST_TYPE) return le; |
| 2440 | UNREACHABLE(); |
| 2441 | return eq; |
| 2442 | } |
| 2443 | |
| 2444 | void LCodeGen::DoHasInstanceTypeAndBranch(LHasInstanceTypeAndBranch* instr) { |
| 2445 | Register scratch = scratch0(); |
| 2446 | Register input = ToRegister(instr->value()); |
| 2447 | |
| 2448 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 2449 | __ JumpIfSmi(input, instr->FalseLabel(chunk_)); |
| 2450 | } |
| 2451 | |
| 2452 | __ CompareObjectType(input, scratch, scratch, TestType(instr->hydrogen())); |
| 2453 | EmitBranch(instr, BranchCondition(instr->hydrogen())); |
| 2454 | } |
| 2455 | |
| 2456 | void LCodeGen::DoGetCachedArrayIndex(LGetCachedArrayIndex* instr) { |
| 2457 | Register input = ToRegister(instr->value()); |
| 2458 | Register result = ToRegister(instr->result()); |
| 2459 | |
| 2460 | __ AssertString(input); |
| 2461 | |
| 2462 | __ LoadlW(result, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2463 | __ IndexFromHash(result, result); |
| 2464 | } |
| 2465 | |
| 2466 | void LCodeGen::DoHasCachedArrayIndexAndBranch( |
| 2467 | LHasCachedArrayIndexAndBranch* instr) { |
| 2468 | Register input = ToRegister(instr->value()); |
| 2469 | Register scratch = scratch0(); |
| 2470 | |
| 2471 | __ LoadlW(scratch, FieldMemOperand(input, String::kHashFieldOffset)); |
| 2472 | __ mov(r0, Operand(String::kContainsCachedArrayIndexMask)); |
| 2473 | __ AndP(r0, scratch); |
| 2474 | EmitBranch(instr, eq); |
| 2475 | } |
| 2476 | |
| 2477 | // Branches to a label or falls through with the answer in flags. Trashes |
| 2478 | // the temp registers, but not the input. |
| 2479 | void LCodeGen::EmitClassOfTest(Label* is_true, Label* is_false, |
| 2480 | Handle<String> class_name, Register input, |
| 2481 | Register temp, Register temp2) { |
| 2482 | DCHECK(!input.is(temp)); |
| 2483 | DCHECK(!input.is(temp2)); |
| 2484 | DCHECK(!temp.is(temp2)); |
| 2485 | |
| 2486 | __ JumpIfSmi(input, is_false); |
| 2487 | |
| 2488 | __ CompareObjectType(input, temp, temp2, FIRST_FUNCTION_TYPE); |
| 2489 | STATIC_ASSERT(LAST_FUNCTION_TYPE == LAST_TYPE); |
| 2490 | if (String::Equals(isolate()->factory()->Function_string(), class_name)) { |
| 2491 | __ bge(is_true); |
| 2492 | } else { |
| 2493 | __ bge(is_false); |
| 2494 | } |
| 2495 | |
| 2496 | // Check if the constructor in the map is a function. |
| 2497 | Register instance_type = ip; |
| 2498 | __ GetMapConstructor(temp, temp, temp2, instance_type); |
| 2499 | |
| 2500 | // Objects with a non-function constructor have class 'Object'. |
| 2501 | __ CmpP(instance_type, Operand(JS_FUNCTION_TYPE)); |
| 2502 | if (String::Equals(isolate()->factory()->Object_string(), class_name)) { |
| 2503 | __ bne(is_true); |
| 2504 | } else { |
| 2505 | __ bne(is_false); |
| 2506 | } |
| 2507 | |
| 2508 | // temp now contains the constructor function. Grab the |
| 2509 | // instance class name from there. |
| 2510 | __ LoadP(temp, FieldMemOperand(temp, JSFunction::kSharedFunctionInfoOffset)); |
| 2511 | __ LoadP(temp, |
| 2512 | FieldMemOperand(temp, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2513 | // The class name we are testing against is internalized since it's a literal. |
| 2514 | // The name in the constructor is internalized because of the way the context |
| 2515 | // is booted. This routine isn't expected to work for random API-created |
| 2516 | // classes and it doesn't have to because you can't access it with natives |
| 2517 | // syntax. Since both sides are internalized it is sufficient to use an |
| 2518 | // identity comparison. |
| 2519 | __ CmpP(temp, Operand(class_name)); |
| 2520 | // End with the answer in flags. |
| 2521 | } |
| 2522 | |
| 2523 | void LCodeGen::DoClassOfTestAndBranch(LClassOfTestAndBranch* instr) { |
| 2524 | Register input = ToRegister(instr->value()); |
| 2525 | Register temp = scratch0(); |
| 2526 | Register temp2 = ToRegister(instr->temp()); |
| 2527 | Handle<String> class_name = instr->hydrogen()->class_name(); |
| 2528 | |
| 2529 | EmitClassOfTest(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), |
| 2530 | class_name, input, temp, temp2); |
| 2531 | |
| 2532 | EmitBranch(instr, eq); |
| 2533 | } |
| 2534 | |
| 2535 | void LCodeGen::DoCmpMapAndBranch(LCmpMapAndBranch* instr) { |
| 2536 | Register reg = ToRegister(instr->value()); |
| 2537 | Register temp = ToRegister(instr->temp()); |
| 2538 | |
| 2539 | __ mov(temp, Operand(instr->map())); |
| 2540 | __ CmpP(temp, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 2541 | EmitBranch(instr, eq); |
| 2542 | } |
| 2543 | |
| 2544 | void LCodeGen::DoInstanceOf(LInstanceOf* instr) { |
| 2545 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2546 | DCHECK(ToRegister(instr->left()).is(InstanceOfDescriptor::LeftRegister())); |
| 2547 | DCHECK(ToRegister(instr->right()).is(InstanceOfDescriptor::RightRegister())); |
| 2548 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 2549 | InstanceOfStub stub(isolate()); |
| 2550 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 2551 | } |
| 2552 | |
| 2553 | void LCodeGen::DoHasInPrototypeChainAndBranch( |
| 2554 | LHasInPrototypeChainAndBranch* instr) { |
| 2555 | Register const object = ToRegister(instr->object()); |
| 2556 | Register const object_map = scratch0(); |
| 2557 | Register const object_instance_type = ip; |
| 2558 | Register const object_prototype = object_map; |
| 2559 | Register const prototype = ToRegister(instr->prototype()); |
| 2560 | |
| 2561 | // The {object} must be a spec object. It's sufficient to know that {object} |
| 2562 | // is not a smi, since all other non-spec objects have {null} prototypes and |
| 2563 | // will be ruled out below. |
| 2564 | if (instr->hydrogen()->ObjectNeedsSmiCheck()) { |
| 2565 | __ TestIfSmi(object); |
| 2566 | EmitFalseBranch(instr, eq); |
| 2567 | } |
| 2568 | // Loop through the {object}s prototype chain looking for the {prototype}. |
| 2569 | __ LoadP(object_map, FieldMemOperand(object, HeapObject::kMapOffset)); |
| 2570 | Label loop; |
| 2571 | __ bind(&loop); |
| 2572 | |
| 2573 | // Deoptimize if the object needs to be access checked. |
| 2574 | __ LoadlB(object_instance_type, |
| 2575 | FieldMemOperand(object_map, Map::kBitFieldOffset)); |
| 2576 | __ TestBit(object_instance_type, Map::kIsAccessCheckNeeded, r0); |
| 2577 | DeoptimizeIf(ne, instr, Deoptimizer::kAccessCheck, cr0); |
| 2578 | // Deoptimize for proxies. |
| 2579 | __ CompareInstanceType(object_map, object_instance_type, JS_PROXY_TYPE); |
| 2580 | DeoptimizeIf(eq, instr, Deoptimizer::kProxy); |
| 2581 | __ LoadP(object_prototype, |
| 2582 | FieldMemOperand(object_map, Map::kPrototypeOffset)); |
| 2583 | __ CmpP(object_prototype, prototype); |
| 2584 | EmitTrueBranch(instr, eq); |
| 2585 | __ CompareRoot(object_prototype, Heap::kNullValueRootIndex); |
| 2586 | EmitFalseBranch(instr, eq); |
| 2587 | __ LoadP(object_map, |
| 2588 | FieldMemOperand(object_prototype, HeapObject::kMapOffset)); |
| 2589 | __ b(&loop); |
| 2590 | } |
| 2591 | |
| 2592 | void LCodeGen::DoCmpT(LCmpT* instr) { |
| 2593 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2594 | Token::Value op = instr->op(); |
| 2595 | |
| 2596 | Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code(); |
| 2597 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2598 | // This instruction also signals no smi code inlined |
| 2599 | __ CmpP(r2, Operand::Zero()); |
| 2600 | |
| 2601 | Condition condition = ComputeCompareCondition(op); |
| 2602 | Label true_value, done; |
| 2603 | |
| 2604 | __ b(condition, &true_value, Label::kNear); |
| 2605 | |
| 2606 | __ LoadRoot(ToRegister(instr->result()), Heap::kFalseValueRootIndex); |
| 2607 | __ b(&done, Label::kNear); |
| 2608 | |
| 2609 | __ bind(&true_value); |
| 2610 | __ LoadRoot(ToRegister(instr->result()), Heap::kTrueValueRootIndex); |
| 2611 | |
| 2612 | __ bind(&done); |
| 2613 | } |
| 2614 | |
| 2615 | void LCodeGen::DoReturn(LReturn* instr) { |
| 2616 | if (FLAG_trace && info()->IsOptimizing()) { |
| 2617 | // Push the return value on the stack as the parameter. |
| 2618 | // Runtime::TraceExit returns its parameter in r2. We're leaving the code |
| 2619 | // managed by the register allocator and tearing down the frame, it's |
| 2620 | // safe to write to the context register. |
| 2621 | __ push(r2); |
| 2622 | __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 2623 | __ CallRuntime(Runtime::kTraceExit); |
| 2624 | } |
| 2625 | if (info()->saves_caller_doubles()) { |
| 2626 | RestoreCallerDoubles(); |
| 2627 | } |
| 2628 | if (instr->has_constant_parameter_count()) { |
| 2629 | int parameter_count = ToInteger32(instr->constant_parameter_count()); |
| 2630 | int32_t sp_delta = (parameter_count + 1) * kPointerSize; |
| 2631 | if (NeedsEagerFrame()) { |
| 2632 | masm_->LeaveFrame(StackFrame::JAVA_SCRIPT, sp_delta); |
| 2633 | } else if (sp_delta != 0) { |
| 2634 | // TODO(joransiu): Clean this up into Macro Assembler |
| 2635 | if (sp_delta >= 0 && sp_delta < 4096) |
| 2636 | __ la(sp, MemOperand(sp, sp_delta)); |
| 2637 | else |
| 2638 | __ lay(sp, MemOperand(sp, sp_delta)); |
| 2639 | } |
| 2640 | } else { |
| 2641 | DCHECK(info()->IsStub()); // Functions would need to drop one more value. |
| 2642 | Register reg = ToRegister(instr->parameter_count()); |
| 2643 | // The argument count parameter is a smi |
| 2644 | if (NeedsEagerFrame()) { |
| 2645 | masm_->LeaveFrame(StackFrame::JAVA_SCRIPT); |
| 2646 | } |
| 2647 | __ SmiToPtrArrayOffset(r0, reg); |
| 2648 | __ AddP(sp, sp, r0); |
| 2649 | } |
| 2650 | |
| 2651 | __ Ret(); |
| 2652 | } |
| 2653 | |
| 2654 | template <class T> |
| 2655 | void LCodeGen::EmitVectorLoadICRegisters(T* instr) { |
| 2656 | Register vector_register = ToRegister(instr->temp_vector()); |
| 2657 | Register slot_register = LoadDescriptor::SlotRegister(); |
| 2658 | DCHECK(vector_register.is(LoadWithVectorDescriptor::VectorRegister())); |
| 2659 | DCHECK(slot_register.is(r2)); |
| 2660 | |
| 2661 | AllowDeferredHandleDereference vector_structure_check; |
| 2662 | Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector(); |
| 2663 | __ Move(vector_register, vector); |
| 2664 | // No need to allocate this register. |
| 2665 | FeedbackVectorSlot slot = instr->hydrogen()->slot(); |
| 2666 | int index = vector->GetIndex(slot); |
| 2667 | __ LoadSmiLiteral(slot_register, Smi::FromInt(index)); |
| 2668 | } |
| 2669 | |
| 2670 | template <class T> |
| 2671 | void LCodeGen::EmitVectorStoreICRegisters(T* instr) { |
| 2672 | Register vector_register = ToRegister(instr->temp_vector()); |
| 2673 | Register slot_register = ToRegister(instr->temp_slot()); |
| 2674 | |
| 2675 | AllowDeferredHandleDereference vector_structure_check; |
| 2676 | Handle<TypeFeedbackVector> vector = instr->hydrogen()->feedback_vector(); |
| 2677 | __ Move(vector_register, vector); |
| 2678 | FeedbackVectorSlot slot = instr->hydrogen()->slot(); |
| 2679 | int index = vector->GetIndex(slot); |
| 2680 | __ LoadSmiLiteral(slot_register, Smi::FromInt(index)); |
| 2681 | } |
| 2682 | |
| 2683 | void LCodeGen::DoLoadGlobalGeneric(LLoadGlobalGeneric* instr) { |
| 2684 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2685 | DCHECK(ToRegister(instr->global_object()) |
| 2686 | .is(LoadDescriptor::ReceiverRegister())); |
| 2687 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 2688 | |
| 2689 | __ mov(LoadDescriptor::NameRegister(), Operand(instr->name())); |
| 2690 | EmitVectorLoadICRegisters<LLoadGlobalGeneric>(instr); |
| 2691 | Handle<Code> ic = CodeFactory::LoadICInOptimizedCode( |
| 2692 | isolate(), instr->typeof_mode(), PREMONOMORPHIC) |
| 2693 | .code(); |
| 2694 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2695 | } |
| 2696 | |
| 2697 | void LCodeGen::DoLoadContextSlot(LLoadContextSlot* instr) { |
| 2698 | Register context = ToRegister(instr->context()); |
| 2699 | Register result = ToRegister(instr->result()); |
| 2700 | __ LoadP(result, ContextMemOperand(context, instr->slot_index())); |
| 2701 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2702 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 2703 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2704 | DeoptimizeIf(eq, instr, Deoptimizer::kHole); |
| 2705 | } else { |
| 2706 | Label skip; |
| 2707 | __ bne(&skip, Label::kNear); |
| 2708 | __ mov(result, Operand(factory()->undefined_value())); |
| 2709 | __ bind(&skip); |
| 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | void LCodeGen::DoStoreContextSlot(LStoreContextSlot* instr) { |
| 2715 | Register context = ToRegister(instr->context()); |
| 2716 | Register value = ToRegister(instr->value()); |
| 2717 | Register scratch = scratch0(); |
| 2718 | MemOperand target = ContextMemOperand(context, instr->slot_index()); |
| 2719 | |
| 2720 | Label skip_assignment; |
| 2721 | |
| 2722 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 2723 | __ LoadP(scratch, target); |
| 2724 | __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 2725 | if (instr->hydrogen()->DeoptimizesOnHole()) { |
| 2726 | DeoptimizeIf(eq, instr, Deoptimizer::kHole); |
| 2727 | } else { |
| 2728 | __ bne(&skip_assignment); |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | __ StoreP(value, target); |
| 2733 | if (instr->hydrogen()->NeedsWriteBarrier()) { |
| 2734 | SmiCheck check_needed = instr->hydrogen()->value()->type().IsHeapObject() |
| 2735 | ? OMIT_SMI_CHECK |
| 2736 | : INLINE_SMI_CHECK; |
| 2737 | __ RecordWriteContextSlot(context, target.offset(), value, scratch, |
| 2738 | GetLinkRegisterState(), kSaveFPRegs, |
| 2739 | EMIT_REMEMBERED_SET, check_needed); |
| 2740 | } |
| 2741 | |
| 2742 | __ bind(&skip_assignment); |
| 2743 | } |
| 2744 | |
| 2745 | void LCodeGen::DoLoadNamedField(LLoadNamedField* instr) { |
| 2746 | HObjectAccess access = instr->hydrogen()->access(); |
| 2747 | int offset = access.offset(); |
| 2748 | Register object = ToRegister(instr->object()); |
| 2749 | |
| 2750 | if (access.IsExternalMemory()) { |
| 2751 | Register result = ToRegister(instr->result()); |
| 2752 | MemOperand operand = MemOperand(object, offset); |
| 2753 | __ LoadRepresentation(result, operand, access.representation(), r0); |
| 2754 | return; |
| 2755 | } |
| 2756 | |
| 2757 | if (instr->hydrogen()->representation().IsDouble()) { |
| 2758 | DCHECK(access.IsInobject()); |
| 2759 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2760 | __ ld(result, FieldMemOperand(object, offset)); |
| 2761 | return; |
| 2762 | } |
| 2763 | |
| 2764 | Register result = ToRegister(instr->result()); |
| 2765 | if (!access.IsInobject()) { |
| 2766 | __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 2767 | object = result; |
| 2768 | } |
| 2769 | |
| 2770 | Representation representation = access.representation(); |
| 2771 | |
| 2772 | #if V8_TARGET_ARCH_S390X |
| 2773 | // 64-bit Smi optimization |
| 2774 | if (representation.IsSmi() && |
| 2775 | instr->hydrogen()->representation().IsInteger32()) { |
| 2776 | // Read int value directly from upper half of the smi. |
| 2777 | offset = SmiWordOffset(offset); |
| 2778 | representation = Representation::Integer32(); |
| 2779 | } |
| 2780 | #endif |
| 2781 | |
| 2782 | __ LoadRepresentation(result, FieldMemOperand(object, offset), representation, |
| 2783 | r0); |
| 2784 | } |
| 2785 | |
| 2786 | void LCodeGen::DoLoadNamedGeneric(LLoadNamedGeneric* instr) { |
| 2787 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 2788 | DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister())); |
| 2789 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 2790 | |
| 2791 | // Name is always in r4. |
| 2792 | __ mov(LoadDescriptor::NameRegister(), Operand(instr->name())); |
| 2793 | EmitVectorLoadICRegisters<LLoadNamedGeneric>(instr); |
| 2794 | Handle<Code> ic = CodeFactory::LoadICInOptimizedCode( |
| 2795 | isolate(), NOT_INSIDE_TYPEOF, |
| 2796 | instr->hydrogen()->initialization_state()) |
| 2797 | .code(); |
| 2798 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 2799 | } |
| 2800 | |
| 2801 | void LCodeGen::DoLoadFunctionPrototype(LLoadFunctionPrototype* instr) { |
| 2802 | Register scratch = scratch0(); |
| 2803 | Register function = ToRegister(instr->function()); |
| 2804 | Register result = ToRegister(instr->result()); |
| 2805 | |
| 2806 | // Get the prototype or initial map from the function. |
| 2807 | __ LoadP(result, |
| 2808 | FieldMemOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2809 | |
| 2810 | // Check that the function has a prototype or an initial map. |
| 2811 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 2812 | DeoptimizeIf(eq, instr, Deoptimizer::kHole); |
| 2813 | |
| 2814 | // If the function does not have an initial map, we're done. |
| 2815 | Label done; |
| 2816 | __ CompareObjectType(result, scratch, scratch, MAP_TYPE); |
| 2817 | __ bne(&done, Label::kNear); |
| 2818 | |
| 2819 | // Get the prototype from the initial map. |
| 2820 | __ LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 2821 | |
| 2822 | // All done. |
| 2823 | __ bind(&done); |
| 2824 | } |
| 2825 | |
| 2826 | void LCodeGen::DoLoadRoot(LLoadRoot* instr) { |
| 2827 | Register result = ToRegister(instr->result()); |
| 2828 | __ LoadRoot(result, instr->index()); |
| 2829 | } |
| 2830 | |
| 2831 | void LCodeGen::DoAccessArgumentsAt(LAccessArgumentsAt* instr) { |
| 2832 | Register arguments = ToRegister(instr->arguments()); |
| 2833 | Register result = ToRegister(instr->result()); |
| 2834 | // There are two words between the frame pointer and the last argument. |
| 2835 | // Subtracting from length accounts for one of them add one more. |
| 2836 | if (instr->length()->IsConstantOperand()) { |
| 2837 | int const_length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 2838 | if (instr->index()->IsConstantOperand()) { |
| 2839 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2840 | int index = (const_length - const_index) + 1; |
| 2841 | __ LoadP(result, MemOperand(arguments, index * kPointerSize)); |
| 2842 | } else { |
| 2843 | Register index = ToRegister(instr->index()); |
| 2844 | __ SubP(result, index, Operand(const_length + 1)); |
| 2845 | __ LoadComplementRR(result, result); |
| 2846 | __ ShiftLeftP(result, result, Operand(kPointerSizeLog2)); |
| 2847 | __ LoadP(result, MemOperand(arguments, result)); |
| 2848 | } |
| 2849 | } else if (instr->index()->IsConstantOperand()) { |
| 2850 | Register length = ToRegister(instr->length()); |
| 2851 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 2852 | int loc = const_index - 1; |
| 2853 | if (loc != 0) { |
| 2854 | __ SubP(result, length, Operand(loc)); |
| 2855 | __ ShiftLeftP(result, result, Operand(kPointerSizeLog2)); |
| 2856 | __ LoadP(result, MemOperand(arguments, result)); |
| 2857 | } else { |
| 2858 | __ ShiftLeftP(result, length, Operand(kPointerSizeLog2)); |
| 2859 | __ LoadP(result, MemOperand(arguments, result)); |
| 2860 | } |
| 2861 | } else { |
| 2862 | Register length = ToRegister(instr->length()); |
| 2863 | Register index = ToRegister(instr->index()); |
| 2864 | __ SubP(result, length, index); |
| 2865 | __ AddP(result, result, Operand(1)); |
| 2866 | __ ShiftLeftP(result, result, Operand(kPointerSizeLog2)); |
| 2867 | __ LoadP(result, MemOperand(arguments, result)); |
| 2868 | } |
| 2869 | } |
| 2870 | |
| 2871 | void LCodeGen::DoLoadKeyedExternalArray(LLoadKeyed* instr) { |
| 2872 | Register external_pointer = ToRegister(instr->elements()); |
| 2873 | Register key = no_reg; |
| 2874 | ElementsKind elements_kind = instr->elements_kind(); |
| 2875 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2876 | int constant_key = 0; |
| 2877 | if (key_is_constant) { |
| 2878 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2879 | if (constant_key & 0xF0000000) { |
| 2880 | Abort(kArrayIndexConstantValueTooBig); |
| 2881 | } |
| 2882 | } else { |
| 2883 | key = ToRegister(instr->key()); |
| 2884 | } |
| 2885 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 2886 | bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 2887 | int base_offset = instr->base_offset(); |
| 2888 | bool use_scratch = false; |
| 2889 | |
| 2890 | if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) { |
| 2891 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2892 | if (key_is_constant) { |
| 2893 | base_offset += constant_key << element_size_shift; |
| 2894 | if (!is_int20(base_offset)) { |
| 2895 | __ mov(scratch0(), Operand(base_offset)); |
| 2896 | base_offset = 0; |
| 2897 | use_scratch = true; |
| 2898 | } |
| 2899 | } else { |
| 2900 | __ IndexToArrayOffset(scratch0(), key, element_size_shift, key_is_smi); |
| 2901 | use_scratch = true; |
| 2902 | } |
| 2903 | if (elements_kind == FLOAT32_ELEMENTS) { |
| 2904 | if (!use_scratch) { |
| 2905 | __ ldeb(result, MemOperand(external_pointer, base_offset)); |
| 2906 | } else { |
| 2907 | __ ldeb(result, MemOperand(scratch0(), external_pointer, base_offset)); |
| 2908 | } |
| 2909 | } else { // i.e. elements_kind == EXTERNAL_DOUBLE_ELEMENTS |
| 2910 | if (!use_scratch) { |
| 2911 | __ ld(result, MemOperand(external_pointer, base_offset)); |
| 2912 | } else { |
| 2913 | __ ld(result, MemOperand(scratch0(), external_pointer, base_offset)); |
| 2914 | } |
| 2915 | } |
| 2916 | } else { |
| 2917 | Register result = ToRegister(instr->result()); |
| 2918 | MemOperand mem_operand = |
| 2919 | PrepareKeyedOperand(key, external_pointer, key_is_constant, key_is_smi, |
| 2920 | constant_key, element_size_shift, base_offset); |
| 2921 | switch (elements_kind) { |
| 2922 | case INT8_ELEMENTS: |
| 2923 | __ LoadB(result, mem_operand); |
| 2924 | break; |
| 2925 | case UINT8_ELEMENTS: |
| 2926 | case UINT8_CLAMPED_ELEMENTS: |
| 2927 | __ LoadlB(result, mem_operand); |
| 2928 | break; |
| 2929 | case INT16_ELEMENTS: |
| 2930 | __ LoadHalfWordP(result, mem_operand); |
| 2931 | break; |
| 2932 | case UINT16_ELEMENTS: |
| 2933 | __ LoadLogicalHalfWordP(result, mem_operand); |
| 2934 | break; |
| 2935 | case INT32_ELEMENTS: |
| 2936 | __ LoadW(result, mem_operand, r0); |
| 2937 | break; |
| 2938 | case UINT32_ELEMENTS: |
| 2939 | __ LoadlW(result, mem_operand, r0); |
| 2940 | if (!instr->hydrogen()->CheckFlag(HInstruction::kUint32)) { |
| 2941 | __ CmpLogical32(result, Operand(0x80000000)); |
| 2942 | DeoptimizeIf(ge, instr, Deoptimizer::kNegativeValue); |
| 2943 | } |
| 2944 | break; |
| 2945 | case FLOAT32_ELEMENTS: |
| 2946 | case FLOAT64_ELEMENTS: |
| 2947 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 2948 | case FAST_HOLEY_ELEMENTS: |
| 2949 | case FAST_HOLEY_SMI_ELEMENTS: |
| 2950 | case FAST_DOUBLE_ELEMENTS: |
| 2951 | case FAST_ELEMENTS: |
| 2952 | case FAST_SMI_ELEMENTS: |
| 2953 | case DICTIONARY_ELEMENTS: |
| 2954 | case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
| 2955 | case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: |
| 2956 | case FAST_STRING_WRAPPER_ELEMENTS: |
| 2957 | case SLOW_STRING_WRAPPER_ELEMENTS: |
| 2958 | case NO_ELEMENTS: |
| 2959 | UNREACHABLE(); |
| 2960 | break; |
| 2961 | } |
| 2962 | } |
| 2963 | } |
| 2964 | |
| 2965 | void LCodeGen::DoLoadKeyedFixedDoubleArray(LLoadKeyed* instr) { |
| 2966 | Register elements = ToRegister(instr->elements()); |
| 2967 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 2968 | Register key = no_reg; |
| 2969 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 2970 | Register scratch = scratch0(); |
| 2971 | |
| 2972 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 2973 | bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 2974 | int constant_key = 0; |
| 2975 | if (key_is_constant) { |
| 2976 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 2977 | if (constant_key & 0xF0000000) { |
| 2978 | Abort(kArrayIndexConstantValueTooBig); |
| 2979 | } |
| 2980 | } else { |
| 2981 | key = ToRegister(instr->key()); |
| 2982 | } |
| 2983 | |
| 2984 | bool use_scratch = false; |
| 2985 | intptr_t base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 2986 | if (!key_is_constant) { |
| 2987 | use_scratch = true; |
| 2988 | __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 2989 | } |
| 2990 | |
| 2991 | // Memory references support up to 20-bits signed displacement in RXY form |
| 2992 | // Include Register::kExponentOffset in check, so we are guaranteed not to |
| 2993 | // overflow displacement later. |
| 2994 | if (!is_int20(base_offset + Register::kExponentOffset)) { |
| 2995 | use_scratch = true; |
| 2996 | if (key_is_constant) { |
| 2997 | __ mov(scratch, Operand(base_offset)); |
| 2998 | } else { |
| 2999 | __ AddP(scratch, Operand(base_offset)); |
| 3000 | } |
| 3001 | base_offset = 0; |
| 3002 | } |
| 3003 | |
| 3004 | if (!use_scratch) { |
| 3005 | __ ld(result, MemOperand(elements, base_offset)); |
| 3006 | } else { |
| 3007 | __ ld(result, MemOperand(scratch, elements, base_offset)); |
| 3008 | } |
| 3009 | |
| 3010 | if (instr->hydrogen()->RequiresHoleCheck()) { |
| 3011 | if (!use_scratch) { |
| 3012 | __ LoadlW(r0, |
| 3013 | MemOperand(elements, base_offset + Register::kExponentOffset)); |
| 3014 | } else { |
| 3015 | __ LoadlW(r0, MemOperand(scratch, elements, |
| 3016 | base_offset + Register::kExponentOffset)); |
| 3017 | } |
| 3018 | __ Cmp32(r0, Operand(kHoleNanUpper32)); |
| 3019 | DeoptimizeIf(eq, instr, Deoptimizer::kHole); |
| 3020 | } |
| 3021 | } |
| 3022 | |
| 3023 | void LCodeGen::DoLoadKeyedFixedArray(LLoadKeyed* instr) { |
| 3024 | HLoadKeyed* hinstr = instr->hydrogen(); |
| 3025 | Register elements = ToRegister(instr->elements()); |
| 3026 | Register result = ToRegister(instr->result()); |
| 3027 | Register scratch = scratch0(); |
| 3028 | int offset = instr->base_offset(); |
| 3029 | |
| 3030 | if (instr->key()->IsConstantOperand()) { |
| 3031 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 3032 | offset += ToInteger32(const_operand) * kPointerSize; |
| 3033 | } else { |
| 3034 | Register key = ToRegister(instr->key()); |
| 3035 | // Even though the HLoadKeyed instruction forces the input |
| 3036 | // representation for the key to be an integer, the input gets replaced |
| 3037 | // during bound check elimination with the index argument to the bounds |
| 3038 | // check, which can be tagged, so that case must be handled here, too. |
| 3039 | if (hinstr->key()->representation().IsSmi()) { |
| 3040 | __ SmiToPtrArrayOffset(scratch, key); |
| 3041 | } else { |
| 3042 | __ ShiftLeftP(scratch, key, Operand(kPointerSizeLog2)); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | bool requires_hole_check = hinstr->RequiresHoleCheck(); |
| 3047 | Representation representation = hinstr->representation(); |
| 3048 | |
| 3049 | #if V8_TARGET_ARCH_S390X |
| 3050 | // 64-bit Smi optimization |
| 3051 | if (representation.IsInteger32() && |
| 3052 | hinstr->elements_kind() == FAST_SMI_ELEMENTS) { |
| 3053 | DCHECK(!requires_hole_check); |
| 3054 | // Read int value directly from upper half of the smi. |
| 3055 | offset = SmiWordOffset(offset); |
| 3056 | } |
| 3057 | #endif |
| 3058 | |
| 3059 | if (instr->key()->IsConstantOperand()) { |
| 3060 | __ LoadRepresentation(result, MemOperand(elements, offset), representation, |
| 3061 | r1); |
| 3062 | } else { |
| 3063 | __ LoadRepresentation(result, MemOperand(scratch, elements, offset), |
| 3064 | representation, r1); |
| 3065 | } |
| 3066 | |
| 3067 | // Check for the hole value. |
| 3068 | if (requires_hole_check) { |
| 3069 | if (IsFastSmiElementsKind(hinstr->elements_kind())) { |
| 3070 | __ TestIfSmi(result); |
| 3071 | DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi, cr0); |
| 3072 | } else { |
| 3073 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 3074 | DeoptimizeIf(eq, instr, Deoptimizer::kHole); |
| 3075 | } |
| 3076 | } else if (instr->hydrogen()->hole_mode() == CONVERT_HOLE_TO_UNDEFINED) { |
| 3077 | DCHECK(instr->hydrogen()->elements_kind() == FAST_HOLEY_ELEMENTS); |
| 3078 | Label done; |
| 3079 | __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 3080 | __ CmpP(result, scratch); |
| 3081 | __ bne(&done); |
| 3082 | if (info()->IsStub()) { |
| 3083 | // A stub can safely convert the hole to undefined only if the array |
| 3084 | // protector cell contains (Smi) Isolate::kArrayProtectorValid. Otherwise |
| 3085 | // it needs to bail out. |
| 3086 | __ LoadRoot(result, Heap::kArrayProtectorRootIndex); |
| 3087 | __ LoadP(result, FieldMemOperand(result, Cell::kValueOffset)); |
| 3088 | __ CmpSmiLiteral(result, Smi::FromInt(Isolate::kArrayProtectorValid), r0); |
| 3089 | DeoptimizeIf(ne, instr, Deoptimizer::kHole); |
| 3090 | } |
| 3091 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 3092 | __ bind(&done); |
| 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | void LCodeGen::DoLoadKeyed(LLoadKeyed* instr) { |
| 3097 | if (instr->is_fixed_typed_array()) { |
| 3098 | DoLoadKeyedExternalArray(instr); |
| 3099 | } else if (instr->hydrogen()->representation().IsDouble()) { |
| 3100 | DoLoadKeyedFixedDoubleArray(instr); |
| 3101 | } else { |
| 3102 | DoLoadKeyedFixedArray(instr); |
| 3103 | } |
| 3104 | } |
| 3105 | |
| 3106 | MemOperand LCodeGen::PrepareKeyedOperand(Register key, Register base, |
| 3107 | bool key_is_constant, bool key_is_smi, |
| 3108 | int constant_key, |
| 3109 | int element_size_shift, |
| 3110 | int base_offset) { |
| 3111 | Register scratch = scratch0(); |
| 3112 | |
| 3113 | if (key_is_constant) { |
| 3114 | int offset = (base_offset + (constant_key << element_size_shift)); |
| 3115 | if (!is_int20(offset)) { |
| 3116 | __ mov(scratch, Operand(offset)); |
| 3117 | return MemOperand(base, scratch); |
| 3118 | } else { |
| 3119 | return MemOperand(base, |
| 3120 | (constant_key << element_size_shift) + base_offset); |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | bool needs_shift = |
| 3125 | (element_size_shift != (key_is_smi ? kSmiTagSize + kSmiShiftSize : 0)); |
| 3126 | |
| 3127 | if (needs_shift) { |
| 3128 | __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 3129 | } else { |
| 3130 | scratch = key; |
| 3131 | } |
| 3132 | |
| 3133 | if (!is_int20(base_offset)) { |
| 3134 | __ AddP(scratch, Operand(base_offset)); |
| 3135 | base_offset = 0; |
| 3136 | } |
| 3137 | return MemOperand(scratch, base, base_offset); |
| 3138 | } |
| 3139 | |
| 3140 | void LCodeGen::DoLoadKeyedGeneric(LLoadKeyedGeneric* instr) { |
| 3141 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 3142 | DCHECK(ToRegister(instr->object()).is(LoadDescriptor::ReceiverRegister())); |
| 3143 | DCHECK(ToRegister(instr->key()).is(LoadDescriptor::NameRegister())); |
| 3144 | |
| 3145 | if (instr->hydrogen()->HasVectorAndSlot()) { |
| 3146 | EmitVectorLoadICRegisters<LLoadKeyedGeneric>(instr); |
| 3147 | } |
| 3148 | |
| 3149 | Handle<Code> ic = CodeFactory::KeyedLoadICInOptimizedCode( |
| 3150 | isolate(), instr->hydrogen()->initialization_state()) |
| 3151 | .code(); |
| 3152 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 3153 | } |
| 3154 | |
| 3155 | void LCodeGen::DoArgumentsElements(LArgumentsElements* instr) { |
| 3156 | Register scratch = scratch0(); |
| 3157 | Register result = ToRegister(instr->result()); |
| 3158 | |
| 3159 | if (instr->hydrogen()->from_inlined()) { |
| 3160 | __ lay(result, MemOperand(sp, -2 * kPointerSize)); |
| 3161 | } else if (instr->hydrogen()->arguments_adaptor()) { |
| 3162 | // Check if the calling frame is an arguments adaptor frame. |
| 3163 | Label done, adapted; |
| 3164 | __ LoadP(scratch, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3165 | __ LoadP( |
| 3166 | result, |
| 3167 | MemOperand(scratch, CommonFrameConstants::kContextOrFrameTypeOffset)); |
| 3168 | __ CmpSmiLiteral(result, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
| 3169 | |
| 3170 | // Result is the frame pointer for the frame if not adapted and for the real |
| 3171 | // frame below the adaptor frame if adapted. |
| 3172 | __ beq(&adapted, Label::kNear); |
| 3173 | __ LoadRR(result, fp); |
| 3174 | __ b(&done, Label::kNear); |
| 3175 | |
| 3176 | __ bind(&adapted); |
| 3177 | __ LoadRR(result, scratch); |
| 3178 | __ bind(&done); |
| 3179 | } else { |
| 3180 | __ LoadRR(result, fp); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | void LCodeGen::DoArgumentsLength(LArgumentsLength* instr) { |
| 3185 | Register elem = ToRegister(instr->elements()); |
| 3186 | Register result = ToRegister(instr->result()); |
| 3187 | |
| 3188 | Label done; |
| 3189 | |
| 3190 | // If no arguments adaptor frame the number of arguments is fixed. |
| 3191 | __ CmpP(fp, elem); |
| 3192 | __ mov(result, Operand(scope()->num_parameters())); |
| 3193 | __ beq(&done, Label::kNear); |
| 3194 | |
| 3195 | // Arguments adaptor frame present. Get argument length from there. |
| 3196 | __ LoadP(result, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3197 | __ LoadP(result, |
| 3198 | MemOperand(result, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3199 | __ SmiUntag(result); |
| 3200 | |
| 3201 | // Argument length is in result register. |
| 3202 | __ bind(&done); |
| 3203 | } |
| 3204 | |
| 3205 | void LCodeGen::DoWrapReceiver(LWrapReceiver* instr) { |
| 3206 | Register receiver = ToRegister(instr->receiver()); |
| 3207 | Register function = ToRegister(instr->function()); |
| 3208 | Register result = ToRegister(instr->result()); |
| 3209 | Register scratch = scratch0(); |
| 3210 | |
| 3211 | // If the receiver is null or undefined, we have to pass the global |
| 3212 | // object as a receiver to normal functions. Values have to be |
| 3213 | // passed unchanged to builtins and strict-mode functions. |
| 3214 | Label global_object, result_in_receiver; |
| 3215 | |
| 3216 | if (!instr->hydrogen()->known_function()) { |
| 3217 | // Do not transform the receiver to object for strict mode |
| 3218 | // functions or builtins. |
| 3219 | __ LoadP(scratch, |
| 3220 | FieldMemOperand(function, JSFunction::kSharedFunctionInfoOffset)); |
| 3221 | __ LoadlW(scratch, FieldMemOperand( |
| 3222 | scratch, SharedFunctionInfo::kCompilerHintsOffset)); |
| 3223 | __ AndP(r0, scratch, Operand((1 << SharedFunctionInfo::kStrictModeBit) | |
| 3224 | (1 << SharedFunctionInfo::kNativeBit))); |
| 3225 | __ bne(&result_in_receiver, Label::kNear); |
| 3226 | } |
| 3227 | |
| 3228 | // Normal function. Replace undefined or null with global receiver. |
| 3229 | __ CompareRoot(receiver, Heap::kNullValueRootIndex); |
| 3230 | __ beq(&global_object, Label::kNear); |
| 3231 | __ CompareRoot(receiver, Heap::kUndefinedValueRootIndex); |
| 3232 | __ beq(&global_object, Label::kNear); |
| 3233 | |
| 3234 | // Deoptimize if the receiver is not a JS object. |
| 3235 | __ TestIfSmi(receiver); |
| 3236 | DeoptimizeIf(eq, instr, Deoptimizer::kSmi, cr0); |
| 3237 | __ CompareObjectType(receiver, scratch, scratch, FIRST_JS_RECEIVER_TYPE); |
| 3238 | DeoptimizeIf(lt, instr, Deoptimizer::kNotAJavaScriptObject); |
| 3239 | |
| 3240 | __ b(&result_in_receiver, Label::kNear); |
| 3241 | __ bind(&global_object); |
| 3242 | __ LoadP(result, FieldMemOperand(function, JSFunction::kContextOffset)); |
| 3243 | __ LoadP(result, ContextMemOperand(result, Context::NATIVE_CONTEXT_INDEX)); |
| 3244 | __ LoadP(result, ContextMemOperand(result, Context::GLOBAL_PROXY_INDEX)); |
| 3245 | |
| 3246 | if (result.is(receiver)) { |
| 3247 | __ bind(&result_in_receiver); |
| 3248 | } else { |
| 3249 | Label result_ok; |
| 3250 | __ b(&result_ok, Label::kNear); |
| 3251 | __ bind(&result_in_receiver); |
| 3252 | __ LoadRR(result, receiver); |
| 3253 | __ bind(&result_ok); |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | void LCodeGen::DoApplyArguments(LApplyArguments* instr) { |
| 3258 | Register receiver = ToRegister(instr->receiver()); |
| 3259 | Register function = ToRegister(instr->function()); |
| 3260 | Register length = ToRegister(instr->length()); |
| 3261 | Register elements = ToRegister(instr->elements()); |
| 3262 | Register scratch = scratch0(); |
| 3263 | DCHECK(receiver.is(r2)); // Used for parameter count. |
| 3264 | DCHECK(function.is(r3)); // Required by InvokeFunction. |
| 3265 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 3266 | |
| 3267 | // Copy the arguments to this function possibly from the |
| 3268 | // adaptor frame below it. |
| 3269 | const uint32_t kArgumentsLimit = 1 * KB; |
| 3270 | __ CmpLogicalP(length, Operand(kArgumentsLimit)); |
| 3271 | DeoptimizeIf(gt, instr, Deoptimizer::kTooManyArguments); |
| 3272 | |
| 3273 | // Push the receiver and use the register to keep the original |
| 3274 | // number of arguments. |
| 3275 | __ push(receiver); |
| 3276 | __ LoadRR(receiver, length); |
| 3277 | // The arguments are at a one pointer size offset from elements. |
| 3278 | __ AddP(elements, Operand(1 * kPointerSize)); |
| 3279 | |
| 3280 | // Loop through the arguments pushing them onto the execution |
| 3281 | // stack. |
| 3282 | Label invoke, loop; |
| 3283 | // length is a small non-negative integer, due to the test above. |
| 3284 | __ CmpP(length, Operand::Zero()); |
| 3285 | __ beq(&invoke, Label::kNear); |
| 3286 | __ bind(&loop); |
| 3287 | __ ShiftLeftP(r1, length, Operand(kPointerSizeLog2)); |
| 3288 | __ LoadP(scratch, MemOperand(elements, r1)); |
| 3289 | __ push(scratch); |
| 3290 | __ BranchOnCount(length, &loop); |
| 3291 | |
| 3292 | __ bind(&invoke); |
| 3293 | |
| 3294 | InvokeFlag flag = CALL_FUNCTION; |
| 3295 | if (instr->hydrogen()->tail_call_mode() == TailCallMode::kAllow) { |
| 3296 | DCHECK(!info()->saves_caller_doubles()); |
| 3297 | // TODO(ishell): drop current frame before pushing arguments to the stack. |
| 3298 | flag = JUMP_FUNCTION; |
| 3299 | ParameterCount actual(r2); |
| 3300 | // It is safe to use r5, r6 and r7 as scratch registers here given that |
| 3301 | // 1) we are not going to return to caller function anyway, |
| 3302 | // 2) r5 (new.target) will be initialized below. |
| 3303 | PrepareForTailCall(actual, r5, r6, r7); |
| 3304 | } |
| 3305 | |
| 3306 | DCHECK(instr->HasPointerMap()); |
| 3307 | LPointerMap* pointers = instr->pointer_map(); |
| 3308 | SafepointGenerator safepoint_generator(this, pointers, Safepoint::kLazyDeopt); |
| 3309 | // The number of arguments is stored in receiver which is r2, as expected |
| 3310 | // by InvokeFunction. |
| 3311 | ParameterCount actual(receiver); |
| 3312 | __ InvokeFunction(function, no_reg, actual, flag, safepoint_generator); |
| 3313 | } |
| 3314 | |
| 3315 | void LCodeGen::DoPushArgument(LPushArgument* instr) { |
| 3316 | LOperand* argument = instr->value(); |
| 3317 | if (argument->IsDoubleRegister() || argument->IsDoubleStackSlot()) { |
| 3318 | Abort(kDoPushArgumentNotImplementedForDoubleType); |
| 3319 | } else { |
| 3320 | Register argument_reg = EmitLoadRegister(argument, ip); |
| 3321 | __ push(argument_reg); |
| 3322 | } |
| 3323 | } |
| 3324 | |
| 3325 | void LCodeGen::DoDrop(LDrop* instr) { __ Drop(instr->count()); } |
| 3326 | |
| 3327 | void LCodeGen::DoThisFunction(LThisFunction* instr) { |
| 3328 | Register result = ToRegister(instr->result()); |
| 3329 | __ LoadP(result, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 3330 | } |
| 3331 | |
| 3332 | void LCodeGen::DoContext(LContext* instr) { |
| 3333 | // If there is a non-return use, the context must be moved to a register. |
| 3334 | Register result = ToRegister(instr->result()); |
| 3335 | if (info()->IsOptimizing()) { |
| 3336 | __ LoadP(result, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 3337 | } else { |
| 3338 | // If there is no frame, the context must be in cp. |
| 3339 | DCHECK(result.is(cp)); |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | void LCodeGen::DoDeclareGlobals(LDeclareGlobals* instr) { |
| 3344 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 3345 | __ Move(scratch0(), instr->hydrogen()->pairs()); |
| 3346 | __ push(scratch0()); |
| 3347 | __ LoadSmiLiteral(scratch0(), Smi::FromInt(instr->hydrogen()->flags())); |
| 3348 | __ push(scratch0()); |
| 3349 | CallRuntime(Runtime::kDeclareGlobals, instr); |
| 3350 | } |
| 3351 | |
| 3352 | void LCodeGen::CallKnownFunction(Handle<JSFunction> function, |
| 3353 | int formal_parameter_count, int arity, |
| 3354 | bool is_tail_call, LInstruction* instr) { |
| 3355 | bool dont_adapt_arguments = |
| 3356 | formal_parameter_count == SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 3357 | bool can_invoke_directly = |
| 3358 | dont_adapt_arguments || formal_parameter_count == arity; |
| 3359 | |
| 3360 | Register function_reg = r3; |
| 3361 | |
| 3362 | LPointerMap* pointers = instr->pointer_map(); |
| 3363 | |
| 3364 | if (can_invoke_directly) { |
| 3365 | // Change context. |
| 3366 | __ LoadP(cp, FieldMemOperand(function_reg, JSFunction::kContextOffset)); |
| 3367 | |
| 3368 | // Always initialize new target and number of actual arguments. |
| 3369 | __ LoadRoot(r5, Heap::kUndefinedValueRootIndex); |
| 3370 | __ mov(r2, Operand(arity)); |
| 3371 | |
| 3372 | bool is_self_call = function.is_identical_to(info()->closure()); |
| 3373 | |
| 3374 | // Invoke function. |
| 3375 | if (is_self_call) { |
| 3376 | Handle<Code> self(reinterpret_cast<Code**>(__ CodeObject().location())); |
| 3377 | if (is_tail_call) { |
| 3378 | __ Jump(self, RelocInfo::CODE_TARGET); |
| 3379 | } else { |
| 3380 | __ Call(self, RelocInfo::CODE_TARGET); |
| 3381 | } |
| 3382 | } else { |
| 3383 | __ LoadP(ip, FieldMemOperand(function_reg, JSFunction::kCodeEntryOffset)); |
| 3384 | if (is_tail_call) { |
| 3385 | __ JumpToJSEntry(ip); |
| 3386 | } else { |
| 3387 | __ CallJSEntry(ip); |
| 3388 | } |
| 3389 | } |
| 3390 | |
| 3391 | if (!is_tail_call) { |
| 3392 | // Set up deoptimization. |
| 3393 | RecordSafepointWithLazyDeopt(instr, RECORD_SIMPLE_SAFEPOINT); |
| 3394 | } |
| 3395 | } else { |
| 3396 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3397 | ParameterCount actual(arity); |
| 3398 | ParameterCount expected(formal_parameter_count); |
| 3399 | InvokeFlag flag = is_tail_call ? JUMP_FUNCTION : CALL_FUNCTION; |
| 3400 | __ InvokeFunction(function_reg, expected, actual, flag, generator); |
| 3401 | } |
| 3402 | } |
| 3403 | |
| 3404 | void LCodeGen::DoDeferredMathAbsTaggedHeapNumber(LMathAbs* instr) { |
| 3405 | DCHECK(instr->context() != NULL); |
| 3406 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 3407 | Register input = ToRegister(instr->value()); |
| 3408 | Register result = ToRegister(instr->result()); |
| 3409 | Register scratch = scratch0(); |
| 3410 | |
| 3411 | // Deoptimize if not a heap number. |
| 3412 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 3413 | __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 3414 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber); |
| 3415 | |
| 3416 | Label done; |
| 3417 | Register exponent = scratch0(); |
| 3418 | scratch = no_reg; |
| 3419 | __ LoadlW(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3420 | // Check the sign of the argument. If the argument is positive, just |
| 3421 | // return it. |
| 3422 | __ Cmp32(exponent, Operand::Zero()); |
| 3423 | // Move the input to the result if necessary. |
| 3424 | __ Move(result, input); |
| 3425 | __ bge(&done); |
| 3426 | |
| 3427 | // Input is negative. Reverse its sign. |
| 3428 | // Preserve the value of all registers. |
| 3429 | { |
| 3430 | PushSafepointRegistersScope scope(this); |
| 3431 | |
| 3432 | // Registers were saved at the safepoint, so we can use |
| 3433 | // many scratch registers. |
| 3434 | Register tmp1 = input.is(r3) ? r2 : r3; |
| 3435 | Register tmp2 = input.is(r4) ? r2 : r4; |
| 3436 | Register tmp3 = input.is(r5) ? r2 : r5; |
| 3437 | Register tmp4 = input.is(r6) ? r2 : r6; |
| 3438 | |
| 3439 | // exponent: floating point exponent value. |
| 3440 | |
| 3441 | Label allocated, slow; |
| 3442 | __ LoadRoot(tmp4, Heap::kHeapNumberMapRootIndex); |
| 3443 | __ AllocateHeapNumber(tmp1, tmp2, tmp3, tmp4, &slow); |
| 3444 | __ b(&allocated); |
| 3445 | |
| 3446 | // Slow case: Call the runtime system to do the number allocation. |
| 3447 | __ bind(&slow); |
| 3448 | |
| 3449 | CallRuntimeFromDeferred(Runtime::kAllocateHeapNumber, 0, instr, |
| 3450 | instr->context()); |
| 3451 | // Set the pointer to the new heap number in tmp. |
| 3452 | if (!tmp1.is(r2)) __ LoadRR(tmp1, r2); |
| 3453 | // Restore input_reg after call to runtime. |
| 3454 | __ LoadFromSafepointRegisterSlot(input, input); |
| 3455 | __ LoadlW(exponent, FieldMemOperand(input, HeapNumber::kExponentOffset)); |
| 3456 | |
| 3457 | __ bind(&allocated); |
| 3458 | // exponent: floating point exponent value. |
| 3459 | // tmp1: allocated heap number. |
| 3460 | |
| 3461 | // Clear the sign bit. |
| 3462 | __ nilf(exponent, Operand(~HeapNumber::kSignMask)); |
| 3463 | __ StoreW(exponent, FieldMemOperand(tmp1, HeapNumber::kExponentOffset)); |
| 3464 | __ LoadlW(tmp2, FieldMemOperand(input, HeapNumber::kMantissaOffset)); |
| 3465 | __ StoreW(tmp2, FieldMemOperand(tmp1, HeapNumber::kMantissaOffset)); |
| 3466 | |
| 3467 | __ StoreToSafepointRegisterSlot(tmp1, result); |
| 3468 | } |
| 3469 | |
| 3470 | __ bind(&done); |
| 3471 | } |
| 3472 | |
| 3473 | void LCodeGen::EmitMathAbs(LMathAbs* instr) { |
| 3474 | Register input = ToRegister(instr->value()); |
| 3475 | Register result = ToRegister(instr->result()); |
| 3476 | Label done; |
| 3477 | __ CmpP(input, Operand::Zero()); |
| 3478 | __ Move(result, input); |
| 3479 | __ bge(&done, Label::kNear); |
| 3480 | __ LoadComplementRR(result, result); |
| 3481 | // Deoptimize on overflow. |
| 3482 | DeoptimizeIf(overflow, instr, Deoptimizer::kOverflow, cr0); |
| 3483 | __ bind(&done); |
| 3484 | } |
| 3485 | |
| 3486 | #if V8_TARGET_ARCH_S390X |
| 3487 | void LCodeGen::EmitInteger32MathAbs(LMathAbs* instr) { |
| 3488 | Register input = ToRegister(instr->value()); |
| 3489 | Register result = ToRegister(instr->result()); |
| 3490 | Label done; |
| 3491 | __ Cmp32(input, Operand::Zero()); |
| 3492 | __ Move(result, input); |
| 3493 | __ bge(&done, Label::kNear); |
| 3494 | |
| 3495 | // Deoptimize on overflow. |
| 3496 | __ Cmp32(input, Operand(0x80000000)); |
| 3497 | DeoptimizeIf(eq, instr, Deoptimizer::kOverflow); |
| 3498 | |
| 3499 | __ LoadComplementRR(result, result); |
| 3500 | __ bind(&done); |
| 3501 | } |
| 3502 | #endif |
| 3503 | |
| 3504 | void LCodeGen::DoMathAbs(LMathAbs* instr) { |
| 3505 | // Class for deferred case. |
| 3506 | class DeferredMathAbsTaggedHeapNumber final : public LDeferredCode { |
| 3507 | public: |
| 3508 | DeferredMathAbsTaggedHeapNumber(LCodeGen* codegen, LMathAbs* instr) |
| 3509 | : LDeferredCode(codegen), instr_(instr) {} |
| 3510 | void Generate() override { |
| 3511 | codegen()->DoDeferredMathAbsTaggedHeapNumber(instr_); |
| 3512 | } |
| 3513 | LInstruction* instr() override { return instr_; } |
| 3514 | |
| 3515 | private: |
| 3516 | LMathAbs* instr_; |
| 3517 | }; |
| 3518 | |
| 3519 | Representation r = instr->hydrogen()->value()->representation(); |
| 3520 | if (r.IsDouble()) { |
| 3521 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3522 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3523 | __ lpdbr(result, input); |
| 3524 | #if V8_TARGET_ARCH_S390X |
| 3525 | } else if (r.IsInteger32()) { |
| 3526 | EmitInteger32MathAbs(instr); |
| 3527 | } else if (r.IsSmi()) { |
| 3528 | #else |
| 3529 | } else if (r.IsSmiOrInteger32()) { |
| 3530 | #endif |
| 3531 | EmitMathAbs(instr); |
| 3532 | } else { |
| 3533 | // Representation is tagged. |
| 3534 | DeferredMathAbsTaggedHeapNumber* deferred = |
| 3535 | new (zone()) DeferredMathAbsTaggedHeapNumber(this, instr); |
| 3536 | Register input = ToRegister(instr->value()); |
| 3537 | // Smi check. |
| 3538 | __ JumpIfNotSmi(input, deferred->entry()); |
| 3539 | // If smi, handle it directly. |
| 3540 | EmitMathAbs(instr); |
| 3541 | __ bind(deferred->exit()); |
| 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | void LCodeGen::DoMathFloor(LMathFloor* instr) { |
| 3546 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3547 | Register result = ToRegister(instr->result()); |
| 3548 | Register input_high = scratch0(); |
| 3549 | Register scratch = ip; |
| 3550 | Label done, exact; |
| 3551 | |
| 3552 | __ TryInt32Floor(result, input, input_high, scratch, double_scratch0(), &done, |
| 3553 | &exact); |
| 3554 | DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 3555 | |
| 3556 | __ bind(&exact); |
| 3557 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3558 | // Test for -0. |
| 3559 | __ CmpP(result, Operand::Zero()); |
| 3560 | __ bne(&done, Label::kNear); |
| 3561 | __ Cmp32(input_high, Operand::Zero()); |
| 3562 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 3563 | } |
| 3564 | __ bind(&done); |
| 3565 | } |
| 3566 | |
| 3567 | void LCodeGen::DoMathRound(LMathRound* instr) { |
| 3568 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3569 | Register result = ToRegister(instr->result()); |
| 3570 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->temp()); |
| 3571 | DoubleRegister input_plus_dot_five = double_scratch1; |
| 3572 | Register scratch1 = scratch0(); |
| 3573 | Register scratch2 = ip; |
| 3574 | DoubleRegister dot_five = double_scratch0(); |
| 3575 | Label convert, done; |
| 3576 | |
| 3577 | __ LoadDoubleLiteral(dot_five, 0.5, r0); |
| 3578 | __ lpdbr(double_scratch1, input); |
| 3579 | __ cdbr(double_scratch1, dot_five); |
| 3580 | DeoptimizeIf(unordered, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 3581 | // If input is in [-0.5, -0], the result is -0. |
| 3582 | // If input is in [+0, +0.5[, the result is +0. |
| 3583 | // If the input is +0.5, the result is 1. |
| 3584 | __ bgt(&convert, Label::kNear); // Out of [-0.5, +0.5]. |
| 3585 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 3586 | // [-0.5, -0] (negative) yields minus zero. |
| 3587 | __ TestDoubleSign(input, scratch1); |
| 3588 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 3589 | } |
| 3590 | Label return_zero; |
| 3591 | __ cdbr(input, dot_five); |
| 3592 | __ bne(&return_zero, Label::kNear); |
| 3593 | __ LoadImmP(result, Operand(1)); // +0.5. |
| 3594 | __ b(&done, Label::kNear); |
| 3595 | // Remaining cases: [+0, +0.5[ or [-0.5, +0.5[, depending on |
| 3596 | // flag kBailoutOnMinusZero. |
| 3597 | __ bind(&return_zero); |
| 3598 | __ LoadImmP(result, Operand::Zero()); |
| 3599 | __ b(&done, Label::kNear); |
| 3600 | |
| 3601 | __ bind(&convert); |
| 3602 | __ ldr(input_plus_dot_five, input); |
| 3603 | __ adbr(input_plus_dot_five, dot_five); |
| 3604 | // Reuse dot_five (double_scratch0) as we no longer need this value. |
| 3605 | __ TryInt32Floor(result, input_plus_dot_five, scratch1, scratch2, |
| 3606 | double_scratch0(), &done, &done); |
| 3607 | DeoptimizeIf(al, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 3608 | __ bind(&done); |
| 3609 | } |
| 3610 | |
| 3611 | void LCodeGen::DoMathFround(LMathFround* instr) { |
| 3612 | DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
| 3613 | DoubleRegister output_reg = ToDoubleRegister(instr->result()); |
| 3614 | |
| 3615 | // Round double to float |
| 3616 | __ ledbr(output_reg, input_reg); |
| 3617 | // Extend from float to double |
| 3618 | __ ldebr(output_reg, output_reg); |
| 3619 | } |
| 3620 | |
| 3621 | void LCodeGen::DoMathSqrt(LMathSqrt* instr) { |
| 3622 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3623 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3624 | __ sqdbr(result, input); |
| 3625 | } |
| 3626 | |
| 3627 | void LCodeGen::DoMathPowHalf(LMathPowHalf* instr) { |
| 3628 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3629 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3630 | DoubleRegister temp = double_scratch0(); |
| 3631 | |
| 3632 | // Note that according to ECMA-262 15.8.2.13: |
| 3633 | // Math.pow(-Infinity, 0.5) == Infinity |
| 3634 | // Math.sqrt(-Infinity) == NaN |
| 3635 | Label skip, done; |
| 3636 | |
| 3637 | __ LoadDoubleLiteral(temp, -V8_INFINITY, scratch0()); |
| 3638 | __ cdbr(input, temp); |
| 3639 | __ bne(&skip, Label::kNear); |
| 3640 | __ lcdbr(result, temp); |
| 3641 | __ b(&done, Label::kNear); |
| 3642 | |
| 3643 | // Add +0 to convert -0 to +0. |
| 3644 | __ bind(&skip); |
| 3645 | __ ldr(result, input); |
| 3646 | __ lzdr(kDoubleRegZero); |
| 3647 | __ adbr(result, kDoubleRegZero); |
| 3648 | __ sqdbr(result, result); |
| 3649 | __ bind(&done); |
| 3650 | } |
| 3651 | |
| 3652 | void LCodeGen::DoPower(LPower* instr) { |
| 3653 | Representation exponent_type = instr->hydrogen()->right()->representation(); |
| 3654 | // Having marked this as a call, we can use any registers. |
| 3655 | // Just make sure that the input/output registers are the expected ones. |
| 3656 | Register tagged_exponent = MathPowTaggedDescriptor::exponent(); |
| 3657 | DCHECK(!instr->right()->IsDoubleRegister() || |
| 3658 | ToDoubleRegister(instr->right()).is(d2)); |
| 3659 | DCHECK(!instr->right()->IsRegister() || |
| 3660 | ToRegister(instr->right()).is(tagged_exponent)); |
| 3661 | DCHECK(ToDoubleRegister(instr->left()).is(d1)); |
| 3662 | DCHECK(ToDoubleRegister(instr->result()).is(d3)); |
| 3663 | |
| 3664 | if (exponent_type.IsSmi()) { |
| 3665 | MathPowStub stub(isolate(), MathPowStub::TAGGED); |
| 3666 | __ CallStub(&stub); |
| 3667 | } else if (exponent_type.IsTagged()) { |
| 3668 | Label no_deopt; |
| 3669 | __ JumpIfSmi(tagged_exponent, &no_deopt); |
| 3670 | __ LoadP(r9, FieldMemOperand(tagged_exponent, HeapObject::kMapOffset)); |
| 3671 | __ CompareRoot(r9, Heap::kHeapNumberMapRootIndex); |
| 3672 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber); |
| 3673 | __ bind(&no_deopt); |
| 3674 | MathPowStub stub(isolate(), MathPowStub::TAGGED); |
| 3675 | __ CallStub(&stub); |
| 3676 | } else if (exponent_type.IsInteger32()) { |
| 3677 | MathPowStub stub(isolate(), MathPowStub::INTEGER); |
| 3678 | __ CallStub(&stub); |
| 3679 | } else { |
| 3680 | DCHECK(exponent_type.IsDouble()); |
| 3681 | MathPowStub stub(isolate(), MathPowStub::DOUBLE); |
| 3682 | __ CallStub(&stub); |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | void LCodeGen::DoMathExp(LMathExp* instr) { |
| 3687 | DoubleRegister input = ToDoubleRegister(instr->value()); |
| 3688 | DoubleRegister result = ToDoubleRegister(instr->result()); |
| 3689 | DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); |
| 3690 | DoubleRegister double_scratch2 = double_scratch0(); |
| 3691 | Register temp1 = ToRegister(instr->temp1()); |
| 3692 | Register temp2 = ToRegister(instr->temp2()); |
| 3693 | |
| 3694 | MathExpGenerator::EmitMathExp(masm(), input, result, double_scratch1, |
| 3695 | double_scratch2, temp1, temp2, scratch0()); |
| 3696 | } |
| 3697 | |
| 3698 | void LCodeGen::DoMathLog(LMathLog* instr) { |
| 3699 | __ PrepareCallCFunction(0, 1, scratch0()); |
| 3700 | __ MovToFloatParameter(ToDoubleRegister(instr->value())); |
| 3701 | __ CallCFunction(ExternalReference::math_log_double_function(isolate()), 0, |
| 3702 | 1); |
| 3703 | __ MovFromFloatResult(ToDoubleRegister(instr->result())); |
| 3704 | } |
| 3705 | |
| 3706 | void LCodeGen::DoMathClz32(LMathClz32* instr) { |
| 3707 | Register input = ToRegister(instr->value()); |
| 3708 | Register result = ToRegister(instr->result()); |
| 3709 | Label done; |
| 3710 | __ llgfr(result, input); |
| 3711 | __ flogr(r0, result); |
| 3712 | __ LoadRR(result, r0); |
| 3713 | __ CmpP(r0, Operand::Zero()); |
| 3714 | __ beq(&done, Label::kNear); |
| 3715 | __ SubP(result, Operand(32)); |
| 3716 | __ bind(&done); |
| 3717 | } |
| 3718 | |
| 3719 | void LCodeGen::PrepareForTailCall(const ParameterCount& actual, |
| 3720 | Register scratch1, Register scratch2, |
| 3721 | Register scratch3) { |
| 3722 | #if DEBUG |
| 3723 | if (actual.is_reg()) { |
| 3724 | DCHECK(!AreAliased(actual.reg(), scratch1, scratch2, scratch3)); |
| 3725 | } else { |
| 3726 | DCHECK(!AreAliased(scratch1, scratch2, scratch3)); |
| 3727 | } |
| 3728 | #endif |
| 3729 | if (FLAG_code_comments) { |
| 3730 | if (actual.is_reg()) { |
| 3731 | Comment(";;; PrepareForTailCall, actual: %s {", actual.reg().ToString()); |
| 3732 | } else { |
| 3733 | Comment(";;; PrepareForTailCall, actual: %d {", actual.immediate()); |
| 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | // Check if next frame is an arguments adaptor frame. |
| 3738 | Register caller_args_count_reg = scratch1; |
| 3739 | Label no_arguments_adaptor, formal_parameter_count_loaded; |
| 3740 | __ LoadP(scratch2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3741 | __ LoadP(scratch3, |
| 3742 | MemOperand(scratch2, StandardFrameConstants::kContextOffset)); |
| 3743 | __ CmpSmiLiteral(scratch3, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR), r0); |
| 3744 | __ bne(&no_arguments_adaptor); |
| 3745 | |
| 3746 | // Drop current frame and load arguments count from arguments adaptor frame. |
| 3747 | __ LoadRR(fp, scratch2); |
| 3748 | __ LoadP(caller_args_count_reg, |
| 3749 | MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3750 | __ SmiUntag(caller_args_count_reg); |
| 3751 | __ b(&formal_parameter_count_loaded); |
| 3752 | |
| 3753 | __ bind(&no_arguments_adaptor); |
| 3754 | // Load caller's formal parameter count |
| 3755 | __ mov(caller_args_count_reg, Operand(info()->literal()->parameter_count())); |
| 3756 | |
| 3757 | __ bind(&formal_parameter_count_loaded); |
| 3758 | __ PrepareForTailCall(actual, caller_args_count_reg, scratch2, scratch3); |
| 3759 | |
| 3760 | Comment(";;; }"); |
| 3761 | } |
| 3762 | |
| 3763 | void LCodeGen::DoInvokeFunction(LInvokeFunction* instr) { |
| 3764 | HInvokeFunction* hinstr = instr->hydrogen(); |
| 3765 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 3766 | DCHECK(ToRegister(instr->function()).is(r3)); |
| 3767 | DCHECK(instr->HasPointerMap()); |
| 3768 | |
| 3769 | bool is_tail_call = hinstr->tail_call_mode() == TailCallMode::kAllow; |
| 3770 | |
| 3771 | if (is_tail_call) { |
| 3772 | DCHECK(!info()->saves_caller_doubles()); |
| 3773 | ParameterCount actual(instr->arity()); |
| 3774 | // It is safe to use r5, r6 and r7 as scratch registers here given that |
| 3775 | // 1) we are not going to return to caller function anyway, |
| 3776 | // 2) r5 (new.target) will be initialized below. |
| 3777 | PrepareForTailCall(actual, r5, r6, r7); |
| 3778 | } |
| 3779 | |
| 3780 | Handle<JSFunction> known_function = hinstr->known_function(); |
| 3781 | if (known_function.is_null()) { |
| 3782 | LPointerMap* pointers = instr->pointer_map(); |
| 3783 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3784 | ParameterCount actual(instr->arity()); |
| 3785 | InvokeFlag flag = is_tail_call ? JUMP_FUNCTION : CALL_FUNCTION; |
| 3786 | __ InvokeFunction(r3, no_reg, actual, flag, generator); |
| 3787 | } else { |
| 3788 | CallKnownFunction(known_function, hinstr->formal_parameter_count(), |
| 3789 | instr->arity(), is_tail_call, instr); |
| 3790 | } |
| 3791 | } |
| 3792 | |
| 3793 | void LCodeGen::DoCallWithDescriptor(LCallWithDescriptor* instr) { |
| 3794 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 3795 | |
| 3796 | if (instr->hydrogen()->IsTailCall()) { |
| 3797 | if (NeedsEagerFrame()) __ LeaveFrame(StackFrame::INTERNAL); |
| 3798 | |
| 3799 | if (instr->target()->IsConstantOperand()) { |
| 3800 | LConstantOperand* target = LConstantOperand::cast(instr->target()); |
| 3801 | Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
| 3802 | __ Jump(code, RelocInfo::CODE_TARGET); |
| 3803 | } else { |
| 3804 | DCHECK(instr->target()->IsRegister()); |
| 3805 | Register target = ToRegister(instr->target()); |
| 3806 | __ AddP(ip, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3807 | __ JumpToJSEntry(ip); |
| 3808 | } |
| 3809 | } else { |
| 3810 | LPointerMap* pointers = instr->pointer_map(); |
| 3811 | SafepointGenerator generator(this, pointers, Safepoint::kLazyDeopt); |
| 3812 | |
| 3813 | if (instr->target()->IsConstantOperand()) { |
| 3814 | LConstantOperand* target = LConstantOperand::cast(instr->target()); |
| 3815 | Handle<Code> code = Handle<Code>::cast(ToHandle(target)); |
| 3816 | generator.BeforeCall(__ CallSize(code, RelocInfo::CODE_TARGET)); |
| 3817 | __ Call(code, RelocInfo::CODE_TARGET); |
| 3818 | } else { |
| 3819 | DCHECK(instr->target()->IsRegister()); |
| 3820 | Register target = ToRegister(instr->target()); |
| 3821 | generator.BeforeCall(__ CallSize(target)); |
| 3822 | __ AddP(ip, target, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3823 | __ CallJSEntry(ip); |
| 3824 | } |
| 3825 | generator.AfterCall(); |
| 3826 | } |
| 3827 | } |
| 3828 | |
| 3829 | void LCodeGen::DoCallNewArray(LCallNewArray* instr) { |
| 3830 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 3831 | DCHECK(ToRegister(instr->constructor()).is(r3)); |
| 3832 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 3833 | |
| 3834 | __ mov(r2, Operand(instr->arity())); |
| 3835 | if (instr->arity() == 1) { |
| 3836 | // We only need the allocation site for the case we have a length argument. |
| 3837 | // The case may bail out to the runtime, which will determine the correct |
| 3838 | // elements kind with the site. |
| 3839 | __ Move(r4, instr->hydrogen()->site()); |
| 3840 | } else { |
| 3841 | __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); |
| 3842 | } |
| 3843 | ElementsKind kind = instr->hydrogen()->elements_kind(); |
| 3844 | AllocationSiteOverrideMode override_mode = |
| 3845 | (AllocationSite::GetMode(kind) == TRACK_ALLOCATION_SITE) |
| 3846 | ? DISABLE_ALLOCATION_SITES |
| 3847 | : DONT_OVERRIDE; |
| 3848 | |
| 3849 | if (instr->arity() == 0) { |
| 3850 | ArrayNoArgumentConstructorStub stub(isolate(), kind, override_mode); |
| 3851 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3852 | } else if (instr->arity() == 1) { |
| 3853 | Label done; |
| 3854 | if (IsFastPackedElementsKind(kind)) { |
| 3855 | Label packed_case; |
| 3856 | // We might need a change here |
| 3857 | // look at the first argument |
| 3858 | __ LoadP(r7, MemOperand(sp, 0)); |
| 3859 | __ CmpP(r7, Operand::Zero()); |
| 3860 | __ beq(&packed_case, Label::kNear); |
| 3861 | |
| 3862 | ElementsKind holey_kind = GetHoleyElementsKind(kind); |
| 3863 | ArraySingleArgumentConstructorStub stub(isolate(), holey_kind, |
| 3864 | override_mode); |
| 3865 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3866 | __ b(&done, Label::kNear); |
| 3867 | __ bind(&packed_case); |
| 3868 | } |
| 3869 | |
| 3870 | ArraySingleArgumentConstructorStub stub(isolate(), kind, override_mode); |
| 3871 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3872 | __ bind(&done); |
| 3873 | } else { |
| 3874 | ArrayNArgumentsConstructorStub stub(isolate(), kind, override_mode); |
| 3875 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 3876 | } |
| 3877 | } |
| 3878 | |
| 3879 | void LCodeGen::DoCallRuntime(LCallRuntime* instr) { |
| 3880 | CallRuntime(instr->function(), instr->arity(), instr); |
| 3881 | } |
| 3882 | |
| 3883 | void LCodeGen::DoStoreCodeEntry(LStoreCodeEntry* instr) { |
| 3884 | Register function = ToRegister(instr->function()); |
| 3885 | Register code_object = ToRegister(instr->code_object()); |
| 3886 | __ lay(code_object, |
| 3887 | MemOperand(code_object, Code::kHeaderSize - kHeapObjectTag)); |
| 3888 | __ StoreP(code_object, |
| 3889 | FieldMemOperand(function, JSFunction::kCodeEntryOffset), r0); |
| 3890 | } |
| 3891 | |
| 3892 | void LCodeGen::DoInnerAllocatedObject(LInnerAllocatedObject* instr) { |
| 3893 | Register result = ToRegister(instr->result()); |
| 3894 | Register base = ToRegister(instr->base_object()); |
| 3895 | if (instr->offset()->IsConstantOperand()) { |
| 3896 | LConstantOperand* offset = LConstantOperand::cast(instr->offset()); |
| 3897 | __ lay(result, MemOperand(base, ToInteger32(offset))); |
| 3898 | } else { |
| 3899 | Register offset = ToRegister(instr->offset()); |
| 3900 | __ lay(result, MemOperand(base, offset)); |
| 3901 | } |
| 3902 | } |
| 3903 | |
| 3904 | void LCodeGen::DoStoreNamedField(LStoreNamedField* instr) { |
| 3905 | HStoreNamedField* hinstr = instr->hydrogen(); |
| 3906 | Representation representation = instr->representation(); |
| 3907 | |
| 3908 | Register object = ToRegister(instr->object()); |
| 3909 | Register scratch = scratch0(); |
| 3910 | HObjectAccess access = hinstr->access(); |
| 3911 | int offset = access.offset(); |
| 3912 | |
| 3913 | if (access.IsExternalMemory()) { |
| 3914 | Register value = ToRegister(instr->value()); |
| 3915 | MemOperand operand = MemOperand(object, offset); |
| 3916 | __ StoreRepresentation(value, operand, representation, r0); |
| 3917 | return; |
| 3918 | } |
| 3919 | |
| 3920 | __ AssertNotSmi(object); |
| 3921 | |
| 3922 | #if V8_TARGET_ARCH_S390X |
| 3923 | DCHECK(!representation.IsSmi() || !instr->value()->IsConstantOperand() || |
| 3924 | IsInteger32(LConstantOperand::cast(instr->value()))); |
| 3925 | #else |
| 3926 | DCHECK(!representation.IsSmi() || !instr->value()->IsConstantOperand() || |
| 3927 | IsSmi(LConstantOperand::cast(instr->value()))); |
| 3928 | #endif |
| 3929 | if (!FLAG_unbox_double_fields && representation.IsDouble()) { |
| 3930 | DCHECK(access.IsInobject()); |
| 3931 | DCHECK(!hinstr->has_transition()); |
| 3932 | DCHECK(!hinstr->NeedsWriteBarrier()); |
| 3933 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 3934 | DCHECK(offset >= 0); |
| 3935 | __ std(value, FieldMemOperand(object, offset)); |
| 3936 | return; |
| 3937 | } |
| 3938 | |
| 3939 | if (hinstr->has_transition()) { |
| 3940 | Handle<Map> transition = hinstr->transition_map(); |
| 3941 | AddDeprecationDependency(transition); |
| 3942 | __ mov(scratch, Operand(transition)); |
| 3943 | __ StoreP(scratch, FieldMemOperand(object, HeapObject::kMapOffset), r0); |
| 3944 | if (hinstr->NeedsWriteBarrierForMap()) { |
| 3945 | Register temp = ToRegister(instr->temp()); |
| 3946 | // Update the write barrier for the map field. |
| 3947 | __ RecordWriteForMap(object, scratch, temp, GetLinkRegisterState(), |
| 3948 | kSaveFPRegs); |
| 3949 | } |
| 3950 | } |
| 3951 | |
| 3952 | // Do the store. |
| 3953 | Register record_dest = object; |
| 3954 | Register record_value = no_reg; |
| 3955 | Register record_scratch = scratch; |
| 3956 | #if V8_TARGET_ARCH_S390X |
| 3957 | if (FLAG_unbox_double_fields && representation.IsDouble()) { |
| 3958 | DCHECK(access.IsInobject()); |
| 3959 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 3960 | __ std(value, FieldMemOperand(object, offset)); |
| 3961 | if (hinstr->NeedsWriteBarrier()) { |
| 3962 | record_value = ToRegister(instr->value()); |
| 3963 | } |
| 3964 | } else { |
| 3965 | if (representation.IsSmi() && |
| 3966 | hinstr->value()->representation().IsInteger32()) { |
| 3967 | DCHECK(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 3968 | // 64-bit Smi optimization |
| 3969 | // Store int value directly to upper half of the smi. |
| 3970 | offset = SmiWordOffset(offset); |
| 3971 | representation = Representation::Integer32(); |
| 3972 | } |
| 3973 | #endif |
| 3974 | if (access.IsInobject()) { |
| 3975 | Register value = ToRegister(instr->value()); |
| 3976 | MemOperand operand = FieldMemOperand(object, offset); |
| 3977 | __ StoreRepresentation(value, operand, representation, r0); |
| 3978 | record_value = value; |
| 3979 | } else { |
| 3980 | Register value = ToRegister(instr->value()); |
| 3981 | __ LoadP(scratch, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 3982 | MemOperand operand = FieldMemOperand(scratch, offset); |
| 3983 | __ StoreRepresentation(value, operand, representation, r0); |
| 3984 | record_dest = scratch; |
| 3985 | record_value = value; |
| 3986 | record_scratch = object; |
| 3987 | } |
| 3988 | #if V8_TARGET_ARCH_S390X |
| 3989 | } |
| 3990 | #endif |
| 3991 | |
| 3992 | if (hinstr->NeedsWriteBarrier()) { |
| 3993 | __ RecordWriteField(record_dest, offset, record_value, record_scratch, |
| 3994 | GetLinkRegisterState(), kSaveFPRegs, |
| 3995 | EMIT_REMEMBERED_SET, hinstr->SmiCheckForWriteBarrier(), |
| 3996 | hinstr->PointersToHereCheckForValue()); |
| 3997 | } |
| 3998 | } |
| 3999 | |
| 4000 | void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) { |
| 4001 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 4002 | DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister())); |
| 4003 | DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); |
| 4004 | |
| 4005 | if (instr->hydrogen()->HasVectorAndSlot()) { |
| 4006 | EmitVectorStoreICRegisters<LStoreNamedGeneric>(instr); |
| 4007 | } |
| 4008 | |
| 4009 | __ mov(StoreDescriptor::NameRegister(), Operand(instr->name())); |
| 4010 | Handle<Code> ic = CodeFactory::StoreICInOptimizedCode( |
| 4011 | isolate(), instr->language_mode(), |
| 4012 | instr->hydrogen()->initialization_state()) |
| 4013 | .code(); |
| 4014 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4015 | } |
| 4016 | |
| 4017 | void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) { |
| 4018 | Representation representation = instr->hydrogen()->length()->representation(); |
| 4019 | DCHECK(representation.Equals(instr->hydrogen()->index()->representation())); |
| 4020 | DCHECK(representation.IsSmiOrInteger32()); |
| 4021 | |
| 4022 | Condition cc = instr->hydrogen()->allow_equality() ? lt : le; |
| 4023 | if (instr->length()->IsConstantOperand()) { |
| 4024 | int32_t length = ToInteger32(LConstantOperand::cast(instr->length())); |
| 4025 | Register index = ToRegister(instr->index()); |
| 4026 | if (representation.IsSmi()) { |
| 4027 | __ CmpLogicalP(index, Operand(Smi::FromInt(length))); |
| 4028 | } else { |
| 4029 | __ CmpLogical32(index, Operand(length)); |
| 4030 | } |
| 4031 | cc = CommuteCondition(cc); |
| 4032 | } else if (instr->index()->IsConstantOperand()) { |
| 4033 | int32_t index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4034 | Register length = ToRegister(instr->length()); |
| 4035 | if (representation.IsSmi()) { |
| 4036 | __ CmpLogicalP(length, Operand(Smi::FromInt(index))); |
| 4037 | } else { |
| 4038 | __ CmpLogical32(length, Operand(index)); |
| 4039 | } |
| 4040 | } else { |
| 4041 | Register index = ToRegister(instr->index()); |
| 4042 | Register length = ToRegister(instr->length()); |
| 4043 | if (representation.IsSmi()) { |
| 4044 | __ CmpLogicalP(length, index); |
| 4045 | } else { |
| 4046 | __ CmpLogical32(length, index); |
| 4047 | } |
| 4048 | } |
| 4049 | if (FLAG_debug_code && instr->hydrogen()->skip_check()) { |
| 4050 | Label done; |
| 4051 | __ b(NegateCondition(cc), &done, Label::kNear); |
| 4052 | __ stop("eliminated bounds check failed"); |
| 4053 | __ bind(&done); |
| 4054 | } else { |
| 4055 | DeoptimizeIf(cc, instr, Deoptimizer::kOutOfBounds); |
| 4056 | } |
| 4057 | } |
| 4058 | |
| 4059 | void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) { |
| 4060 | Register external_pointer = ToRegister(instr->elements()); |
| 4061 | Register key = no_reg; |
| 4062 | ElementsKind elements_kind = instr->elements_kind(); |
| 4063 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4064 | int constant_key = 0; |
| 4065 | if (key_is_constant) { |
| 4066 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4067 | if (constant_key & 0xF0000000) { |
| 4068 | Abort(kArrayIndexConstantValueTooBig); |
| 4069 | } |
| 4070 | } else { |
| 4071 | key = ToRegister(instr->key()); |
| 4072 | } |
| 4073 | int element_size_shift = ElementsKindToShiftSize(elements_kind); |
| 4074 | bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 4075 | int base_offset = instr->base_offset(); |
| 4076 | |
| 4077 | if (elements_kind == FLOAT32_ELEMENTS || elements_kind == FLOAT64_ELEMENTS) { |
| 4078 | Register address = scratch0(); |
| 4079 | DoubleRegister value(ToDoubleRegister(instr->value())); |
| 4080 | if (key_is_constant) { |
| 4081 | if (constant_key != 0) { |
| 4082 | base_offset += constant_key << element_size_shift; |
| 4083 | if (!is_int20(base_offset)) { |
| 4084 | __ mov(address, Operand(base_offset)); |
| 4085 | __ AddP(address, external_pointer); |
| 4086 | } else { |
| 4087 | __ AddP(address, external_pointer, Operand(base_offset)); |
| 4088 | } |
| 4089 | base_offset = 0; |
| 4090 | } else { |
| 4091 | address = external_pointer; |
| 4092 | } |
| 4093 | } else { |
| 4094 | __ IndexToArrayOffset(address, key, element_size_shift, key_is_smi); |
| 4095 | __ AddP(address, external_pointer); |
| 4096 | } |
| 4097 | if (elements_kind == FLOAT32_ELEMENTS) { |
| 4098 | __ ledbr(double_scratch0(), value); |
| 4099 | __ StoreFloat32(double_scratch0(), MemOperand(address, base_offset)); |
| 4100 | } else { // Storing doubles, not floats. |
| 4101 | __ StoreDouble(value, MemOperand(address, base_offset)); |
| 4102 | } |
| 4103 | } else { |
| 4104 | Register value(ToRegister(instr->value())); |
| 4105 | MemOperand mem_operand = |
| 4106 | PrepareKeyedOperand(key, external_pointer, key_is_constant, key_is_smi, |
| 4107 | constant_key, element_size_shift, base_offset); |
| 4108 | switch (elements_kind) { |
| 4109 | case UINT8_ELEMENTS: |
| 4110 | case UINT8_CLAMPED_ELEMENTS: |
| 4111 | case INT8_ELEMENTS: |
| 4112 | if (key_is_constant) { |
| 4113 | __ StoreByte(value, mem_operand, r0); |
| 4114 | } else { |
| 4115 | __ StoreByte(value, mem_operand); |
| 4116 | } |
| 4117 | break; |
| 4118 | case INT16_ELEMENTS: |
| 4119 | case UINT16_ELEMENTS: |
| 4120 | if (key_is_constant) { |
| 4121 | __ StoreHalfWord(value, mem_operand, r0); |
| 4122 | } else { |
| 4123 | __ StoreHalfWord(value, mem_operand); |
| 4124 | } |
| 4125 | break; |
| 4126 | case INT32_ELEMENTS: |
| 4127 | case UINT32_ELEMENTS: |
| 4128 | if (key_is_constant) { |
| 4129 | __ StoreW(value, mem_operand, r0); |
| 4130 | } else { |
| 4131 | __ StoreW(value, mem_operand); |
| 4132 | } |
| 4133 | break; |
| 4134 | case FLOAT32_ELEMENTS: |
| 4135 | case FLOAT64_ELEMENTS: |
| 4136 | case FAST_DOUBLE_ELEMENTS: |
| 4137 | case FAST_ELEMENTS: |
| 4138 | case FAST_SMI_ELEMENTS: |
| 4139 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 4140 | case FAST_HOLEY_ELEMENTS: |
| 4141 | case FAST_HOLEY_SMI_ELEMENTS: |
| 4142 | case DICTIONARY_ELEMENTS: |
| 4143 | case FAST_SLOPPY_ARGUMENTS_ELEMENTS: |
| 4144 | case SLOW_SLOPPY_ARGUMENTS_ELEMENTS: |
| 4145 | case FAST_STRING_WRAPPER_ELEMENTS: |
| 4146 | case SLOW_STRING_WRAPPER_ELEMENTS: |
| 4147 | case NO_ELEMENTS: |
| 4148 | UNREACHABLE(); |
| 4149 | break; |
| 4150 | } |
| 4151 | } |
| 4152 | } |
| 4153 | |
| 4154 | void LCodeGen::DoStoreKeyedFixedDoubleArray(LStoreKeyed* instr) { |
| 4155 | DoubleRegister value = ToDoubleRegister(instr->value()); |
| 4156 | Register elements = ToRegister(instr->elements()); |
| 4157 | Register key = no_reg; |
| 4158 | Register scratch = scratch0(); |
| 4159 | DoubleRegister double_scratch = double_scratch0(); |
| 4160 | bool key_is_constant = instr->key()->IsConstantOperand(); |
| 4161 | int constant_key = 0; |
| 4162 | |
| 4163 | // Calculate the effective address of the slot in the array to store the |
| 4164 | // double value. |
| 4165 | if (key_is_constant) { |
| 4166 | constant_key = ToInteger32(LConstantOperand::cast(instr->key())); |
| 4167 | if (constant_key & 0xF0000000) { |
| 4168 | Abort(kArrayIndexConstantValueTooBig); |
| 4169 | } |
| 4170 | } else { |
| 4171 | key = ToRegister(instr->key()); |
| 4172 | } |
| 4173 | int element_size_shift = ElementsKindToShiftSize(FAST_DOUBLE_ELEMENTS); |
| 4174 | bool key_is_smi = instr->hydrogen()->key()->representation().IsSmi(); |
| 4175 | int base_offset = instr->base_offset() + constant_key * kDoubleSize; |
| 4176 | bool use_scratch = false; |
| 4177 | intptr_t address_offset = base_offset; |
| 4178 | |
| 4179 | if (key_is_constant) { |
| 4180 | // Memory references support up to 20-bits signed displacement in RXY form |
| 4181 | if (!is_int20((address_offset))) { |
| 4182 | __ mov(scratch, Operand(address_offset)); |
| 4183 | address_offset = 0; |
| 4184 | use_scratch = true; |
| 4185 | } |
| 4186 | } else { |
| 4187 | use_scratch = true; |
| 4188 | __ IndexToArrayOffset(scratch, key, element_size_shift, key_is_smi); |
| 4189 | // Memory references support up to 20-bits signed displacement in RXY form |
| 4190 | if (!is_int20((address_offset))) { |
| 4191 | __ AddP(scratch, Operand(address_offset)); |
| 4192 | address_offset = 0; |
| 4193 | } |
| 4194 | } |
| 4195 | |
| 4196 | if (instr->NeedsCanonicalization()) { |
| 4197 | // Turn potential sNaN value into qNaN. |
| 4198 | __ CanonicalizeNaN(double_scratch, value); |
| 4199 | DCHECK(address_offset >= 0); |
| 4200 | if (use_scratch) |
| 4201 | __ std(double_scratch, MemOperand(scratch, elements, address_offset)); |
| 4202 | else |
| 4203 | __ std(double_scratch, MemOperand(elements, address_offset)); |
| 4204 | } else { |
| 4205 | if (use_scratch) |
| 4206 | __ std(value, MemOperand(scratch, elements, address_offset)); |
| 4207 | else |
| 4208 | __ std(value, MemOperand(elements, address_offset)); |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | void LCodeGen::DoStoreKeyedFixedArray(LStoreKeyed* instr) { |
| 4213 | HStoreKeyed* hinstr = instr->hydrogen(); |
| 4214 | Register value = ToRegister(instr->value()); |
| 4215 | Register elements = ToRegister(instr->elements()); |
| 4216 | Register key = instr->key()->IsRegister() ? ToRegister(instr->key()) : no_reg; |
| 4217 | Register scratch = scratch0(); |
| 4218 | int offset = instr->base_offset(); |
| 4219 | |
| 4220 | // Do the store. |
| 4221 | if (instr->key()->IsConstantOperand()) { |
| 4222 | DCHECK(!hinstr->NeedsWriteBarrier()); |
| 4223 | LConstantOperand* const_operand = LConstantOperand::cast(instr->key()); |
| 4224 | offset += ToInteger32(const_operand) * kPointerSize; |
| 4225 | } else { |
| 4226 | // Even though the HLoadKeyed instruction forces the input |
| 4227 | // representation for the key to be an integer, the input gets replaced |
| 4228 | // during bound check elimination with the index argument to the bounds |
| 4229 | // check, which can be tagged, so that case must be handled here, too. |
| 4230 | if (hinstr->key()->representation().IsSmi()) { |
| 4231 | __ SmiToPtrArrayOffset(scratch, key); |
| 4232 | } else { |
| 4233 | if (instr->hydrogen()->IsDehoisted() || |
| 4234 | !CpuFeatures::IsSupported(GENERAL_INSTR_EXT)) { |
| 4235 | #if V8_TARGET_ARCH_S390X |
| 4236 | // If array access is dehoisted, the key, being an int32, can contain |
| 4237 | // a negative value, as needs to be sign-extended to 64-bit for |
| 4238 | // memory access. |
| 4239 | __ lgfr(key, key); |
| 4240 | #endif |
| 4241 | __ ShiftLeftP(scratch, key, Operand(kPointerSizeLog2)); |
| 4242 | } else { |
| 4243 | // Small optimization to reduce pathlength. After Bounds Check, |
| 4244 | // the key is guaranteed to be non-negative. Leverage RISBG, |
| 4245 | // which also performs zero-extension. |
| 4246 | __ risbg(scratch, key, Operand(32 - kPointerSizeLog2), |
| 4247 | Operand(63 - kPointerSizeLog2), Operand(kPointerSizeLog2), |
| 4248 | true); |
| 4249 | } |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | Representation representation = hinstr->value()->representation(); |
| 4254 | |
| 4255 | #if V8_TARGET_ARCH_S390X |
| 4256 | // 64-bit Smi optimization |
| 4257 | if (representation.IsInteger32()) { |
| 4258 | DCHECK(hinstr->store_mode() == STORE_TO_INITIALIZED_ENTRY); |
| 4259 | DCHECK(hinstr->elements_kind() == FAST_SMI_ELEMENTS); |
| 4260 | // Store int value directly to upper half of the smi. |
| 4261 | offset = SmiWordOffset(offset); |
| 4262 | } |
| 4263 | #endif |
| 4264 | |
| 4265 | if (instr->key()->IsConstantOperand()) { |
| 4266 | __ StoreRepresentation(value, MemOperand(elements, offset), representation, |
| 4267 | scratch); |
| 4268 | } else { |
| 4269 | __ StoreRepresentation(value, MemOperand(scratch, elements, offset), |
| 4270 | representation, r0); |
| 4271 | } |
| 4272 | |
| 4273 | if (hinstr->NeedsWriteBarrier()) { |
| 4274 | SmiCheck check_needed = hinstr->value()->type().IsHeapObject() |
| 4275 | ? OMIT_SMI_CHECK |
| 4276 | : INLINE_SMI_CHECK; |
| 4277 | // Compute address of modified element and store it into key register. |
| 4278 | if (instr->key()->IsConstantOperand()) { |
| 4279 | __ lay(key, MemOperand(elements, offset)); |
| 4280 | } else { |
| 4281 | __ lay(key, MemOperand(scratch, elements, offset)); |
| 4282 | } |
| 4283 | __ RecordWrite(elements, key, value, GetLinkRegisterState(), kSaveFPRegs, |
| 4284 | EMIT_REMEMBERED_SET, check_needed, |
| 4285 | hinstr->PointersToHereCheckForValue()); |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | void LCodeGen::DoStoreKeyed(LStoreKeyed* instr) { |
| 4290 | // By cases: external, fast double |
| 4291 | if (instr->is_fixed_typed_array()) { |
| 4292 | DoStoreKeyedExternalArray(instr); |
| 4293 | } else if (instr->hydrogen()->value()->representation().IsDouble()) { |
| 4294 | DoStoreKeyedFixedDoubleArray(instr); |
| 4295 | } else { |
| 4296 | DoStoreKeyedFixedArray(instr); |
| 4297 | } |
| 4298 | } |
| 4299 | |
| 4300 | void LCodeGen::DoStoreKeyedGeneric(LStoreKeyedGeneric* instr) { |
| 4301 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 4302 | DCHECK(ToRegister(instr->object()).is(StoreDescriptor::ReceiverRegister())); |
| 4303 | DCHECK(ToRegister(instr->key()).is(StoreDescriptor::NameRegister())); |
| 4304 | DCHECK(ToRegister(instr->value()).is(StoreDescriptor::ValueRegister())); |
| 4305 | |
| 4306 | if (instr->hydrogen()->HasVectorAndSlot()) { |
| 4307 | EmitVectorStoreICRegisters<LStoreKeyedGeneric>(instr); |
| 4308 | } |
| 4309 | |
| 4310 | Handle<Code> ic = CodeFactory::KeyedStoreICInOptimizedCode( |
| 4311 | isolate(), instr->language_mode(), |
| 4312 | instr->hydrogen()->initialization_state()) |
| 4313 | .code(); |
| 4314 | CallCode(ic, RelocInfo::CODE_TARGET, instr); |
| 4315 | } |
| 4316 | |
| 4317 | void LCodeGen::DoMaybeGrowElements(LMaybeGrowElements* instr) { |
| 4318 | class DeferredMaybeGrowElements final : public LDeferredCode { |
| 4319 | public: |
| 4320 | DeferredMaybeGrowElements(LCodeGen* codegen, LMaybeGrowElements* instr) |
| 4321 | : LDeferredCode(codegen), instr_(instr) {} |
| 4322 | void Generate() override { codegen()->DoDeferredMaybeGrowElements(instr_); } |
| 4323 | LInstruction* instr() override { return instr_; } |
| 4324 | |
| 4325 | private: |
| 4326 | LMaybeGrowElements* instr_; |
| 4327 | }; |
| 4328 | |
| 4329 | Register result = r2; |
| 4330 | DeferredMaybeGrowElements* deferred = |
| 4331 | new (zone()) DeferredMaybeGrowElements(this, instr); |
| 4332 | LOperand* key = instr->key(); |
| 4333 | LOperand* current_capacity = instr->current_capacity(); |
| 4334 | |
| 4335 | DCHECK(instr->hydrogen()->key()->representation().IsInteger32()); |
| 4336 | DCHECK(instr->hydrogen()->current_capacity()->representation().IsInteger32()); |
| 4337 | DCHECK(key->IsConstantOperand() || key->IsRegister()); |
| 4338 | DCHECK(current_capacity->IsConstantOperand() || |
| 4339 | current_capacity->IsRegister()); |
| 4340 | |
| 4341 | if (key->IsConstantOperand() && current_capacity->IsConstantOperand()) { |
| 4342 | int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); |
| 4343 | int32_t constant_capacity = |
| 4344 | ToInteger32(LConstantOperand::cast(current_capacity)); |
| 4345 | if (constant_key >= constant_capacity) { |
| 4346 | // Deferred case. |
| 4347 | __ b(deferred->entry()); |
| 4348 | } |
| 4349 | } else if (key->IsConstantOperand()) { |
| 4350 | int32_t constant_key = ToInteger32(LConstantOperand::cast(key)); |
| 4351 | __ Cmp32(ToRegister(current_capacity), Operand(constant_key)); |
| 4352 | __ ble(deferred->entry()); |
| 4353 | } else if (current_capacity->IsConstantOperand()) { |
| 4354 | int32_t constant_capacity = |
| 4355 | ToInteger32(LConstantOperand::cast(current_capacity)); |
| 4356 | __ Cmp32(ToRegister(key), Operand(constant_capacity)); |
| 4357 | __ bge(deferred->entry()); |
| 4358 | } else { |
| 4359 | __ Cmp32(ToRegister(key), ToRegister(current_capacity)); |
| 4360 | __ bge(deferred->entry()); |
| 4361 | } |
| 4362 | |
| 4363 | if (instr->elements()->IsRegister()) { |
| 4364 | __ Move(result, ToRegister(instr->elements())); |
| 4365 | } else { |
| 4366 | __ LoadP(result, ToMemOperand(instr->elements())); |
| 4367 | } |
| 4368 | |
| 4369 | __ bind(deferred->exit()); |
| 4370 | } |
| 4371 | |
| 4372 | void LCodeGen::DoDeferredMaybeGrowElements(LMaybeGrowElements* instr) { |
| 4373 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4374 | // result register contain a valid pointer because it is already |
| 4375 | // contained in the register pointer map. |
| 4376 | Register result = r2; |
| 4377 | __ LoadImmP(result, Operand::Zero()); |
| 4378 | |
| 4379 | // We have to call a stub. |
| 4380 | { |
| 4381 | PushSafepointRegistersScope scope(this); |
| 4382 | if (instr->object()->IsRegister()) { |
| 4383 | __ Move(result, ToRegister(instr->object())); |
| 4384 | } else { |
| 4385 | __ LoadP(result, ToMemOperand(instr->object())); |
| 4386 | } |
| 4387 | |
| 4388 | LOperand* key = instr->key(); |
| 4389 | if (key->IsConstantOperand()) { |
| 4390 | __ LoadSmiLiteral(r5, ToSmi(LConstantOperand::cast(key))); |
| 4391 | } else { |
| 4392 | __ SmiTag(r5, ToRegister(key)); |
| 4393 | } |
| 4394 | |
| 4395 | GrowArrayElementsStub stub(isolate(), instr->hydrogen()->is_js_array(), |
| 4396 | instr->hydrogen()->kind()); |
| 4397 | __ CallStub(&stub); |
| 4398 | RecordSafepointWithLazyDeopt( |
| 4399 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 4400 | __ StoreToSafepointRegisterSlot(result, result); |
| 4401 | } |
| 4402 | |
| 4403 | // Deopt on smi, which means the elements array changed to dictionary mode. |
| 4404 | __ TestIfSmi(result); |
| 4405 | DeoptimizeIf(eq, instr, Deoptimizer::kSmi, cr0); |
| 4406 | } |
| 4407 | |
| 4408 | void LCodeGen::DoTransitionElementsKind(LTransitionElementsKind* instr) { |
| 4409 | Register object_reg = ToRegister(instr->object()); |
| 4410 | Register scratch = scratch0(); |
| 4411 | |
| 4412 | Handle<Map> from_map = instr->original_map(); |
| 4413 | Handle<Map> to_map = instr->transitioned_map(); |
| 4414 | ElementsKind from_kind = instr->from_kind(); |
| 4415 | ElementsKind to_kind = instr->to_kind(); |
| 4416 | |
| 4417 | Label not_applicable; |
| 4418 | __ LoadP(scratch, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4419 | __ CmpP(scratch, Operand(from_map)); |
| 4420 | __ bne(¬_applicable); |
| 4421 | |
| 4422 | if (IsSimpleMapChangeTransition(from_kind, to_kind)) { |
| 4423 | Register new_map_reg = ToRegister(instr->new_map_temp()); |
| 4424 | __ mov(new_map_reg, Operand(to_map)); |
| 4425 | __ StoreP(new_map_reg, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 4426 | // Write barrier. |
| 4427 | __ RecordWriteForMap(object_reg, new_map_reg, scratch, |
| 4428 | GetLinkRegisterState(), kDontSaveFPRegs); |
| 4429 | } else { |
| 4430 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 4431 | DCHECK(object_reg.is(r2)); |
| 4432 | PushSafepointRegistersScope scope(this); |
| 4433 | __ Move(r3, to_map); |
| 4434 | bool is_js_array = from_map->instance_type() == JS_ARRAY_TYPE; |
| 4435 | TransitionElementsKindStub stub(isolate(), from_kind, to_kind, is_js_array); |
| 4436 | __ CallStub(&stub); |
| 4437 | RecordSafepointWithRegisters(instr->pointer_map(), 0, |
| 4438 | Safepoint::kLazyDeopt); |
| 4439 | } |
| 4440 | __ bind(¬_applicable); |
| 4441 | } |
| 4442 | |
| 4443 | void LCodeGen::DoTrapAllocationMemento(LTrapAllocationMemento* instr) { |
| 4444 | Register object = ToRegister(instr->object()); |
| 4445 | Register temp1 = ToRegister(instr->temp1()); |
| 4446 | Register temp2 = ToRegister(instr->temp2()); |
| 4447 | Label no_memento_found; |
| 4448 | __ TestJSArrayForAllocationMemento(object, temp1, temp2, &no_memento_found); |
| 4449 | DeoptimizeIf(eq, instr, Deoptimizer::kMementoFound); |
| 4450 | __ bind(&no_memento_found); |
| 4451 | } |
| 4452 | |
| 4453 | void LCodeGen::DoStringAdd(LStringAdd* instr) { |
| 4454 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 4455 | DCHECK(ToRegister(instr->left()).is(r3)); |
| 4456 | DCHECK(ToRegister(instr->right()).is(r2)); |
| 4457 | StringAddStub stub(isolate(), instr->hydrogen()->flags(), |
| 4458 | instr->hydrogen()->pretenure_flag()); |
| 4459 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 4460 | } |
| 4461 | |
| 4462 | void LCodeGen::DoStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4463 | class DeferredStringCharCodeAt final : public LDeferredCode { |
| 4464 | public: |
| 4465 | DeferredStringCharCodeAt(LCodeGen* codegen, LStringCharCodeAt* instr) |
| 4466 | : LDeferredCode(codegen), instr_(instr) {} |
| 4467 | void Generate() override { codegen()->DoDeferredStringCharCodeAt(instr_); } |
| 4468 | LInstruction* instr() override { return instr_; } |
| 4469 | |
| 4470 | private: |
| 4471 | LStringCharCodeAt* instr_; |
| 4472 | }; |
| 4473 | |
| 4474 | DeferredStringCharCodeAt* deferred = |
| 4475 | new (zone()) DeferredStringCharCodeAt(this, instr); |
| 4476 | |
| 4477 | StringCharLoadGenerator::Generate( |
| 4478 | masm(), ToRegister(instr->string()), ToRegister(instr->index()), |
| 4479 | ToRegister(instr->result()), deferred->entry()); |
| 4480 | __ bind(deferred->exit()); |
| 4481 | } |
| 4482 | |
| 4483 | void LCodeGen::DoDeferredStringCharCodeAt(LStringCharCodeAt* instr) { |
| 4484 | Register string = ToRegister(instr->string()); |
| 4485 | Register result = ToRegister(instr->result()); |
| 4486 | Register scratch = scratch0(); |
| 4487 | |
| 4488 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4489 | // result register contain a valid pointer because it is already |
| 4490 | // contained in the register pointer map. |
| 4491 | __ LoadImmP(result, Operand::Zero()); |
| 4492 | |
| 4493 | PushSafepointRegistersScope scope(this); |
| 4494 | __ push(string); |
| 4495 | // Push the index as a smi. This is safe because of the checks in |
| 4496 | // DoStringCharCodeAt above. |
| 4497 | if (instr->index()->IsConstantOperand()) { |
| 4498 | int const_index = ToInteger32(LConstantOperand::cast(instr->index())); |
| 4499 | __ LoadSmiLiteral(scratch, Smi::FromInt(const_index)); |
| 4500 | __ push(scratch); |
| 4501 | } else { |
| 4502 | Register index = ToRegister(instr->index()); |
| 4503 | __ SmiTag(index); |
| 4504 | __ push(index); |
| 4505 | } |
| 4506 | CallRuntimeFromDeferred(Runtime::kStringCharCodeAtRT, 2, instr, |
| 4507 | instr->context()); |
| 4508 | __ AssertSmi(r2); |
| 4509 | __ SmiUntag(r2); |
| 4510 | __ StoreToSafepointRegisterSlot(r2, result); |
| 4511 | } |
| 4512 | |
| 4513 | void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 4514 | class DeferredStringCharFromCode final : public LDeferredCode { |
| 4515 | public: |
| 4516 | DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 4517 | : LDeferredCode(codegen), instr_(instr) {} |
| 4518 | void Generate() override { |
| 4519 | codegen()->DoDeferredStringCharFromCode(instr_); |
| 4520 | } |
| 4521 | LInstruction* instr() override { return instr_; } |
| 4522 | |
| 4523 | private: |
| 4524 | LStringCharFromCode* instr_; |
| 4525 | }; |
| 4526 | |
| 4527 | DeferredStringCharFromCode* deferred = |
| 4528 | new (zone()) DeferredStringCharFromCode(this, instr); |
| 4529 | |
| 4530 | DCHECK(instr->hydrogen()->value()->representation().IsInteger32()); |
| 4531 | Register char_code = ToRegister(instr->char_code()); |
| 4532 | Register result = ToRegister(instr->result()); |
| 4533 | DCHECK(!char_code.is(result)); |
| 4534 | |
| 4535 | __ CmpLogicalP(char_code, Operand(String::kMaxOneByteCharCode)); |
| 4536 | __ bgt(deferred->entry()); |
| 4537 | __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 4538 | __ ShiftLeftP(r0, char_code, Operand(kPointerSizeLog2)); |
| 4539 | __ AddP(result, r0); |
| 4540 | __ LoadP(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 4541 | __ CompareRoot(result, Heap::kUndefinedValueRootIndex); |
| 4542 | __ beq(deferred->entry()); |
| 4543 | __ bind(deferred->exit()); |
| 4544 | } |
| 4545 | |
| 4546 | void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 4547 | Register char_code = ToRegister(instr->char_code()); |
| 4548 | Register result = ToRegister(instr->result()); |
| 4549 | |
| 4550 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4551 | // result register contain a valid pointer because it is already |
| 4552 | // contained in the register pointer map. |
| 4553 | __ LoadImmP(result, Operand::Zero()); |
| 4554 | |
| 4555 | PushSafepointRegistersScope scope(this); |
| 4556 | __ SmiTag(char_code); |
| 4557 | __ push(char_code); |
| 4558 | CallRuntimeFromDeferred(Runtime::kStringCharFromCode, 1, instr, |
| 4559 | instr->context()); |
| 4560 | __ StoreToSafepointRegisterSlot(r2, result); |
| 4561 | } |
| 4562 | |
| 4563 | void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
| 4564 | LOperand* input = instr->value(); |
| 4565 | DCHECK(input->IsRegister() || input->IsStackSlot()); |
| 4566 | LOperand* output = instr->result(); |
| 4567 | DCHECK(output->IsDoubleRegister()); |
| 4568 | if (input->IsStackSlot()) { |
| 4569 | Register scratch = scratch0(); |
| 4570 | __ LoadP(scratch, ToMemOperand(input)); |
| 4571 | __ ConvertIntToDouble(scratch, ToDoubleRegister(output)); |
| 4572 | } else { |
| 4573 | __ ConvertIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | void LCodeGen::DoUint32ToDouble(LUint32ToDouble* instr) { |
| 4578 | LOperand* input = instr->value(); |
| 4579 | LOperand* output = instr->result(); |
| 4580 | __ ConvertUnsignedIntToDouble(ToRegister(input), ToDoubleRegister(output)); |
| 4581 | } |
| 4582 | |
| 4583 | void LCodeGen::DoNumberTagI(LNumberTagI* instr) { |
| 4584 | class DeferredNumberTagI final : public LDeferredCode { |
| 4585 | public: |
| 4586 | DeferredNumberTagI(LCodeGen* codegen, LNumberTagI* instr) |
| 4587 | : LDeferredCode(codegen), instr_(instr) {} |
| 4588 | void Generate() override { |
| 4589 | codegen()->DoDeferredNumberTagIU(instr_, instr_->value(), instr_->temp1(), |
| 4590 | instr_->temp2(), SIGNED_INT32); |
| 4591 | } |
| 4592 | LInstruction* instr() override { return instr_; } |
| 4593 | |
| 4594 | private: |
| 4595 | LNumberTagI* instr_; |
| 4596 | }; |
| 4597 | |
| 4598 | Register src = ToRegister(instr->value()); |
| 4599 | Register dst = ToRegister(instr->result()); |
| 4600 | |
| 4601 | DeferredNumberTagI* deferred = new (zone()) DeferredNumberTagI(this, instr); |
| 4602 | #if V8_TARGET_ARCH_S390X |
| 4603 | __ SmiTag(dst, src); |
| 4604 | #else |
| 4605 | // Add src to itself to defect SMI overflow. |
| 4606 | __ Add32(dst, src, src); |
| 4607 | __ b(overflow, deferred->entry()); |
| 4608 | #endif |
| 4609 | __ bind(deferred->exit()); |
| 4610 | } |
| 4611 | |
| 4612 | void LCodeGen::DoNumberTagU(LNumberTagU* instr) { |
| 4613 | class DeferredNumberTagU final : public LDeferredCode { |
| 4614 | public: |
| 4615 | DeferredNumberTagU(LCodeGen* codegen, LNumberTagU* instr) |
| 4616 | : LDeferredCode(codegen), instr_(instr) {} |
| 4617 | void Generate() override { |
| 4618 | codegen()->DoDeferredNumberTagIU(instr_, instr_->value(), instr_->temp1(), |
| 4619 | instr_->temp2(), UNSIGNED_INT32); |
| 4620 | } |
| 4621 | LInstruction* instr() override { return instr_; } |
| 4622 | |
| 4623 | private: |
| 4624 | LNumberTagU* instr_; |
| 4625 | }; |
| 4626 | |
| 4627 | Register input = ToRegister(instr->value()); |
| 4628 | Register result = ToRegister(instr->result()); |
| 4629 | |
| 4630 | DeferredNumberTagU* deferred = new (zone()) DeferredNumberTagU(this, instr); |
| 4631 | __ CmpLogicalP(input, Operand(Smi::kMaxValue)); |
| 4632 | __ bgt(deferred->entry()); |
| 4633 | __ SmiTag(result, input); |
| 4634 | __ bind(deferred->exit()); |
| 4635 | } |
| 4636 | |
| 4637 | void LCodeGen::DoDeferredNumberTagIU(LInstruction* instr, LOperand* value, |
| 4638 | LOperand* temp1, LOperand* temp2, |
| 4639 | IntegerSignedness signedness) { |
| 4640 | Label done, slow; |
| 4641 | Register src = ToRegister(value); |
| 4642 | Register dst = ToRegister(instr->result()); |
| 4643 | Register tmp1 = scratch0(); |
| 4644 | Register tmp2 = ToRegister(temp1); |
| 4645 | Register tmp3 = ToRegister(temp2); |
| 4646 | DoubleRegister dbl_scratch = double_scratch0(); |
| 4647 | |
| 4648 | if (signedness == SIGNED_INT32) { |
| 4649 | // There was overflow, so bits 30 and 31 of the original integer |
| 4650 | // disagree. Try to allocate a heap number in new space and store |
| 4651 | // the value in there. If that fails, call the runtime system. |
| 4652 | if (dst.is(src)) { |
| 4653 | __ SmiUntag(src, dst); |
| 4654 | __ xilf(src, Operand(HeapNumber::kSignMask)); |
| 4655 | } |
| 4656 | __ ConvertIntToDouble(src, dbl_scratch); |
| 4657 | } else { |
| 4658 | __ ConvertUnsignedIntToDouble(src, dbl_scratch); |
| 4659 | } |
| 4660 | |
| 4661 | if (FLAG_inline_new) { |
| 4662 | __ LoadRoot(tmp3, Heap::kHeapNumberMapRootIndex); |
| 4663 | __ AllocateHeapNumber(dst, tmp1, tmp2, tmp3, &slow); |
| 4664 | __ b(&done); |
| 4665 | } |
| 4666 | |
| 4667 | // Slow case: Call the runtime system to do the number allocation. |
| 4668 | __ bind(&slow); |
| 4669 | { |
| 4670 | // TODO(3095996): Put a valid pointer value in the stack slot where the |
| 4671 | // result register is stored, as this register is in the pointer map, but |
| 4672 | // contains an integer value. |
| 4673 | __ LoadImmP(dst, Operand::Zero()); |
| 4674 | |
| 4675 | // Preserve the value of all registers. |
| 4676 | PushSafepointRegistersScope scope(this); |
| 4677 | |
| 4678 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4679 | // the environment's HContext or HInlinedContext value. |
| 4680 | // They only call Runtime::kAllocateHeapNumber. |
| 4681 | // The corresponding HChange instructions are added in a phase that does |
| 4682 | // not have easy access to the local context. |
| 4683 | __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4684 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4685 | RecordSafepointWithRegisters(instr->pointer_map(), 0, |
| 4686 | Safepoint::kNoLazyDeopt); |
| 4687 | __ StoreToSafepointRegisterSlot(r2, dst); |
| 4688 | } |
| 4689 | |
| 4690 | // Done. Put the value in dbl_scratch into the value of the allocated heap |
| 4691 | // number. |
| 4692 | __ bind(&done); |
| 4693 | __ StoreDouble(dbl_scratch, FieldMemOperand(dst, HeapNumber::kValueOffset)); |
| 4694 | } |
| 4695 | |
| 4696 | void LCodeGen::DoNumberTagD(LNumberTagD* instr) { |
| 4697 | class DeferredNumberTagD final : public LDeferredCode { |
| 4698 | public: |
| 4699 | DeferredNumberTagD(LCodeGen* codegen, LNumberTagD* instr) |
| 4700 | : LDeferredCode(codegen), instr_(instr) {} |
| 4701 | void Generate() override { codegen()->DoDeferredNumberTagD(instr_); } |
| 4702 | LInstruction* instr() override { return instr_; } |
| 4703 | |
| 4704 | private: |
| 4705 | LNumberTagD* instr_; |
| 4706 | }; |
| 4707 | |
| 4708 | DoubleRegister input_reg = ToDoubleRegister(instr->value()); |
| 4709 | Register scratch = scratch0(); |
| 4710 | Register reg = ToRegister(instr->result()); |
| 4711 | Register temp1 = ToRegister(instr->temp()); |
| 4712 | Register temp2 = ToRegister(instr->temp2()); |
| 4713 | |
| 4714 | DeferredNumberTagD* deferred = new (zone()) DeferredNumberTagD(this, instr); |
| 4715 | if (FLAG_inline_new) { |
| 4716 | __ LoadRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 4717 | __ AllocateHeapNumber(reg, temp1, temp2, scratch, deferred->entry()); |
| 4718 | } else { |
| 4719 | __ b(deferred->entry()); |
| 4720 | } |
| 4721 | __ bind(deferred->exit()); |
| 4722 | __ StoreDouble(input_reg, FieldMemOperand(reg, HeapNumber::kValueOffset)); |
| 4723 | } |
| 4724 | |
| 4725 | void LCodeGen::DoDeferredNumberTagD(LNumberTagD* instr) { |
| 4726 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 4727 | // result register contain a valid pointer because it is already |
| 4728 | // contained in the register pointer map. |
| 4729 | Register reg = ToRegister(instr->result()); |
| 4730 | __ LoadImmP(reg, Operand::Zero()); |
| 4731 | |
| 4732 | PushSafepointRegistersScope scope(this); |
| 4733 | // NumberTagI and NumberTagD use the context from the frame, rather than |
| 4734 | // the environment's HContext or HInlinedContext value. |
| 4735 | // They only call Runtime::kAllocateHeapNumber. |
| 4736 | // The corresponding HChange instructions are added in a phase that does |
| 4737 | // not have easy access to the local context. |
| 4738 | __ LoadP(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 4739 | __ CallRuntimeSaveDoubles(Runtime::kAllocateHeapNumber); |
| 4740 | RecordSafepointWithRegisters(instr->pointer_map(), 0, |
| 4741 | Safepoint::kNoLazyDeopt); |
| 4742 | __ StoreToSafepointRegisterSlot(r2, reg); |
| 4743 | } |
| 4744 | |
| 4745 | void LCodeGen::DoSmiTag(LSmiTag* instr) { |
| 4746 | HChange* hchange = instr->hydrogen(); |
| 4747 | Register input = ToRegister(instr->value()); |
| 4748 | Register output = ToRegister(instr->result()); |
| 4749 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4750 | hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4751 | __ TestUnsignedSmiCandidate(input, r0); |
| 4752 | DeoptimizeIf(ne, instr, Deoptimizer::kOverflow, cr0); |
| 4753 | } |
| 4754 | #if !V8_TARGET_ARCH_S390X |
| 4755 | if (hchange->CheckFlag(HValue::kCanOverflow) && |
| 4756 | !hchange->value()->CheckFlag(HValue::kUint32)) { |
| 4757 | __ SmiTagCheckOverflow(output, input, r0); |
| 4758 | DeoptimizeIf(lt, instr, Deoptimizer::kOverflow, cr0); |
| 4759 | } else { |
| 4760 | #endif |
| 4761 | __ SmiTag(output, input); |
| 4762 | #if !V8_TARGET_ARCH_S390X |
| 4763 | } |
| 4764 | #endif |
| 4765 | } |
| 4766 | |
| 4767 | void LCodeGen::DoSmiUntag(LSmiUntag* instr) { |
| 4768 | Register input = ToRegister(instr->value()); |
| 4769 | Register result = ToRegister(instr->result()); |
| 4770 | if (instr->needs_check()) { |
| 4771 | __ tmll(input, Operand(kHeapObjectTag)); |
| 4772 | DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi, cr0); |
| 4773 | __ SmiUntag(result, input); |
| 4774 | } else { |
| 4775 | __ SmiUntag(result, input); |
| 4776 | } |
| 4777 | } |
| 4778 | |
| 4779 | void LCodeGen::EmitNumberUntagD(LNumberUntagD* instr, Register input_reg, |
| 4780 | DoubleRegister result_reg, |
| 4781 | NumberUntagDMode mode) { |
| 4782 | bool can_convert_undefined_to_nan = |
| 4783 | instr->hydrogen()->can_convert_undefined_to_nan(); |
| 4784 | bool deoptimize_on_minus_zero = instr->hydrogen()->deoptimize_on_minus_zero(); |
| 4785 | |
| 4786 | Register scratch = scratch0(); |
| 4787 | DCHECK(!result_reg.is(double_scratch0())); |
| 4788 | |
| 4789 | Label convert, load_smi, done; |
| 4790 | |
| 4791 | if (mode == NUMBER_CANDIDATE_IS_ANY_TAGGED) { |
| 4792 | // Smi check. |
| 4793 | __ UntagAndJumpIfSmi(scratch, input_reg, &load_smi); |
| 4794 | |
| 4795 | // Heap number map check. |
| 4796 | __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4797 | __ CmpP(scratch, RootMemOperand(Heap::kHeapNumberMapRootIndex)); |
| 4798 | |
| 4799 | if (can_convert_undefined_to_nan) { |
| 4800 | __ bne(&convert, Label::kNear); |
| 4801 | } else { |
| 4802 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber); |
| 4803 | } |
| 4804 | // load heap number |
| 4805 | __ ld(result_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4806 | if (deoptimize_on_minus_zero) { |
| 4807 | __ TestDoubleIsMinusZero(result_reg, scratch, ip); |
| 4808 | DeoptimizeIf(eq, instr, Deoptimizer::kMinusZero); |
| 4809 | } |
| 4810 | __ b(&done, Label::kNear); |
| 4811 | if (can_convert_undefined_to_nan) { |
| 4812 | __ bind(&convert); |
| 4813 | // Convert undefined (and hole) to NaN. |
| 4814 | __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); |
| 4815 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined); |
| 4816 | __ LoadRoot(scratch, Heap::kNanValueRootIndex); |
| 4817 | __ ld(result_reg, FieldMemOperand(scratch, HeapNumber::kValueOffset)); |
| 4818 | __ b(&done, Label::kNear); |
| 4819 | } |
| 4820 | } else { |
| 4821 | __ SmiUntag(scratch, input_reg); |
| 4822 | DCHECK(mode == NUMBER_CANDIDATE_IS_SMI); |
| 4823 | } |
| 4824 | // Smi to double register conversion |
| 4825 | __ bind(&load_smi); |
| 4826 | // scratch: untagged value of input_reg |
| 4827 | __ ConvertIntToDouble(scratch, result_reg); |
| 4828 | __ bind(&done); |
| 4829 | } |
| 4830 | |
| 4831 | void LCodeGen::DoDeferredTaggedToI(LTaggedToI* instr) { |
| 4832 | Register input_reg = ToRegister(instr->value()); |
| 4833 | Register scratch1 = scratch0(); |
| 4834 | Register scratch2 = ToRegister(instr->temp()); |
| 4835 | DoubleRegister double_scratch = double_scratch0(); |
| 4836 | DoubleRegister double_scratch2 = ToDoubleRegister(instr->temp2()); |
| 4837 | |
| 4838 | DCHECK(!scratch1.is(input_reg) && !scratch1.is(scratch2)); |
| 4839 | DCHECK(!scratch2.is(input_reg) && !scratch2.is(scratch1)); |
| 4840 | |
| 4841 | Label done; |
| 4842 | |
| 4843 | // Heap number map check. |
| 4844 | __ LoadP(scratch1, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 4845 | __ CompareRoot(scratch1, Heap::kHeapNumberMapRootIndex); |
| 4846 | |
| 4847 | if (instr->truncating()) { |
| 4848 | // Performs a truncating conversion of a floating point number as used by |
| 4849 | // the JS bitwise operations. |
| 4850 | Label no_heap_number, check_bools, check_false; |
| 4851 | __ bne(&no_heap_number, Label::kNear); |
| 4852 | __ LoadRR(scratch2, input_reg); |
| 4853 | __ TruncateHeapNumberToI(input_reg, scratch2); |
| 4854 | __ b(&done, Label::kNear); |
| 4855 | |
| 4856 | // Check for Oddballs. Undefined/False is converted to zero and True to one |
| 4857 | // for truncating conversions. |
| 4858 | __ bind(&no_heap_number); |
| 4859 | __ CompareRoot(input_reg, Heap::kUndefinedValueRootIndex); |
| 4860 | __ bne(&check_bools); |
| 4861 | __ LoadImmP(input_reg, Operand::Zero()); |
| 4862 | __ b(&done, Label::kNear); |
| 4863 | |
| 4864 | __ bind(&check_bools); |
| 4865 | __ CompareRoot(input_reg, Heap::kTrueValueRootIndex); |
| 4866 | __ bne(&check_false, Label::kNear); |
| 4867 | __ LoadImmP(input_reg, Operand(1)); |
| 4868 | __ b(&done, Label::kNear); |
| 4869 | |
| 4870 | __ bind(&check_false); |
| 4871 | __ CompareRoot(input_reg, Heap::kFalseValueRootIndex); |
| 4872 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefinedBoolean); |
| 4873 | __ LoadImmP(input_reg, Operand::Zero()); |
| 4874 | } else { |
| 4875 | // Deoptimize if we don't have a heap number. |
| 4876 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumber); |
| 4877 | |
| 4878 | __ ld(double_scratch2, |
| 4879 | FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 4880 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4881 | // preserve heap number pointer in scratch2 for minus zero check below |
| 4882 | __ LoadRR(scratch2, input_reg); |
| 4883 | } |
| 4884 | __ TryDoubleToInt32Exact(input_reg, double_scratch2, scratch1, |
| 4885 | double_scratch); |
| 4886 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 4887 | |
| 4888 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4889 | __ CmpP(input_reg, Operand::Zero()); |
| 4890 | __ bne(&done, Label::kNear); |
| 4891 | __ TestHeapNumberSign(scratch2, scratch1); |
| 4892 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 4893 | } |
| 4894 | } |
| 4895 | __ bind(&done); |
| 4896 | } |
| 4897 | |
| 4898 | void LCodeGen::DoTaggedToI(LTaggedToI* instr) { |
| 4899 | class DeferredTaggedToI final : public LDeferredCode { |
| 4900 | public: |
| 4901 | DeferredTaggedToI(LCodeGen* codegen, LTaggedToI* instr) |
| 4902 | : LDeferredCode(codegen), instr_(instr) {} |
| 4903 | void Generate() override { codegen()->DoDeferredTaggedToI(instr_); } |
| 4904 | LInstruction* instr() override { return instr_; } |
| 4905 | |
| 4906 | private: |
| 4907 | LTaggedToI* instr_; |
| 4908 | }; |
| 4909 | |
| 4910 | LOperand* input = instr->value(); |
| 4911 | DCHECK(input->IsRegister()); |
| 4912 | DCHECK(input->Equals(instr->result())); |
| 4913 | |
| 4914 | Register input_reg = ToRegister(input); |
| 4915 | |
| 4916 | if (instr->hydrogen()->value()->representation().IsSmi()) { |
| 4917 | __ SmiUntag(input_reg); |
| 4918 | } else { |
| 4919 | DeferredTaggedToI* deferred = new (zone()) DeferredTaggedToI(this, instr); |
| 4920 | |
| 4921 | // Branch to deferred code if the input is a HeapObject. |
| 4922 | __ JumpIfNotSmi(input_reg, deferred->entry()); |
| 4923 | |
| 4924 | __ SmiUntag(input_reg); |
| 4925 | __ bind(deferred->exit()); |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | void LCodeGen::DoNumberUntagD(LNumberUntagD* instr) { |
| 4930 | LOperand* input = instr->value(); |
| 4931 | DCHECK(input->IsRegister()); |
| 4932 | LOperand* result = instr->result(); |
| 4933 | DCHECK(result->IsDoubleRegister()); |
| 4934 | |
| 4935 | Register input_reg = ToRegister(input); |
| 4936 | DoubleRegister result_reg = ToDoubleRegister(result); |
| 4937 | |
| 4938 | HValue* value = instr->hydrogen()->value(); |
| 4939 | NumberUntagDMode mode = value->representation().IsSmi() |
| 4940 | ? NUMBER_CANDIDATE_IS_SMI |
| 4941 | : NUMBER_CANDIDATE_IS_ANY_TAGGED; |
| 4942 | |
| 4943 | EmitNumberUntagD(instr, input_reg, result_reg, mode); |
| 4944 | } |
| 4945 | |
| 4946 | void LCodeGen::DoDoubleToI(LDoubleToI* instr) { |
| 4947 | Register result_reg = ToRegister(instr->result()); |
| 4948 | Register scratch1 = scratch0(); |
| 4949 | DoubleRegister double_input = ToDoubleRegister(instr->value()); |
| 4950 | DoubleRegister double_scratch = double_scratch0(); |
| 4951 | |
| 4952 | if (instr->truncating()) { |
| 4953 | __ TruncateDoubleToI(result_reg, double_input); |
| 4954 | } else { |
| 4955 | __ TryDoubleToInt32Exact(result_reg, double_input, scratch1, |
| 4956 | double_scratch); |
| 4957 | // Deoptimize if the input wasn't a int32 (inside a double). |
| 4958 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 4959 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4960 | Label done; |
| 4961 | __ CmpP(result_reg, Operand::Zero()); |
| 4962 | __ bne(&done, Label::kNear); |
| 4963 | __ TestDoubleSign(double_input, scratch1); |
| 4964 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 4965 | __ bind(&done); |
| 4966 | } |
| 4967 | } |
| 4968 | } |
| 4969 | |
| 4970 | void LCodeGen::DoDoubleToSmi(LDoubleToSmi* instr) { |
| 4971 | Register result_reg = ToRegister(instr->result()); |
| 4972 | Register scratch1 = scratch0(); |
| 4973 | DoubleRegister double_input = ToDoubleRegister(instr->value()); |
| 4974 | DoubleRegister double_scratch = double_scratch0(); |
| 4975 | |
| 4976 | if (instr->truncating()) { |
| 4977 | __ TruncateDoubleToI(result_reg, double_input); |
| 4978 | } else { |
| 4979 | __ TryDoubleToInt32Exact(result_reg, double_input, scratch1, |
| 4980 | double_scratch); |
| 4981 | // Deoptimize if the input wasn't a int32 (inside a double). |
| 4982 | DeoptimizeIf(ne, instr, Deoptimizer::kLostPrecisionOrNaN); |
| 4983 | if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 4984 | Label done; |
| 4985 | __ CmpP(result_reg, Operand::Zero()); |
| 4986 | __ bne(&done, Label::kNear); |
| 4987 | __ TestDoubleSign(double_input, scratch1); |
| 4988 | DeoptimizeIf(lt, instr, Deoptimizer::kMinusZero); |
| 4989 | __ bind(&done); |
| 4990 | } |
| 4991 | } |
| 4992 | #if V8_TARGET_ARCH_S390X |
| 4993 | __ SmiTag(result_reg); |
| 4994 | #else |
| 4995 | __ SmiTagCheckOverflow(result_reg, r0); |
| 4996 | DeoptimizeIf(lt, instr, Deoptimizer::kOverflow, cr0); |
| 4997 | #endif |
| 4998 | } |
| 4999 | |
| 5000 | void LCodeGen::DoCheckSmi(LCheckSmi* instr) { |
| 5001 | LOperand* input = instr->value(); |
| 5002 | __ TestIfSmi(ToRegister(input)); |
| 5003 | DeoptimizeIf(ne, instr, Deoptimizer::kNotASmi, cr0); |
| 5004 | } |
| 5005 | |
| 5006 | void LCodeGen::DoCheckNonSmi(LCheckNonSmi* instr) { |
| 5007 | if (!instr->hydrogen()->value()->type().IsHeapObject()) { |
| 5008 | LOperand* input = instr->value(); |
| 5009 | __ TestIfSmi(ToRegister(input)); |
| 5010 | DeoptimizeIf(eq, instr, Deoptimizer::kSmi, cr0); |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | void LCodeGen::DoCheckArrayBufferNotNeutered( |
| 5015 | LCheckArrayBufferNotNeutered* instr) { |
| 5016 | Register view = ToRegister(instr->view()); |
| 5017 | Register scratch = scratch0(); |
| 5018 | |
| 5019 | __ LoadP(scratch, FieldMemOperand(view, JSArrayBufferView::kBufferOffset)); |
| 5020 | __ LoadlW(scratch, FieldMemOperand(scratch, JSArrayBuffer::kBitFieldOffset)); |
| 5021 | __ And(r0, scratch, Operand(1 << JSArrayBuffer::WasNeutered::kShift)); |
| 5022 | DeoptimizeIf(ne, instr, Deoptimizer::kOutOfBounds, cr0); |
| 5023 | } |
| 5024 | |
| 5025 | void LCodeGen::DoCheckInstanceType(LCheckInstanceType* instr) { |
| 5026 | Register input = ToRegister(instr->value()); |
| 5027 | Register scratch = scratch0(); |
| 5028 | |
| 5029 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5030 | |
| 5031 | if (instr->hydrogen()->is_interval_check()) { |
| 5032 | InstanceType first; |
| 5033 | InstanceType last; |
| 5034 | instr->hydrogen()->GetCheckInterval(&first, &last); |
| 5035 | |
| 5036 | __ CmpLogicalByte(FieldMemOperand(scratch, Map::kInstanceTypeOffset), |
| 5037 | Operand(first)); |
| 5038 | |
| 5039 | // If there is only one type in the interval check for equality. |
| 5040 | if (first == last) { |
| 5041 | DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType); |
| 5042 | } else { |
| 5043 | DeoptimizeIf(lt, instr, Deoptimizer::kWrongInstanceType); |
| 5044 | // Omit check for the last type. |
| 5045 | if (last != LAST_TYPE) { |
| 5046 | __ CmpLogicalByte(FieldMemOperand(scratch, Map::kInstanceTypeOffset), |
| 5047 | Operand(last)); |
| 5048 | DeoptimizeIf(gt, instr, Deoptimizer::kWrongInstanceType); |
| 5049 | } |
| 5050 | } |
| 5051 | } else { |
| 5052 | uint8_t mask; |
| 5053 | uint8_t tag; |
| 5054 | instr->hydrogen()->GetCheckMaskAndTag(&mask, &tag); |
| 5055 | |
| 5056 | __ LoadlB(scratch, FieldMemOperand(scratch, Map::kInstanceTypeOffset)); |
| 5057 | |
| 5058 | if (base::bits::IsPowerOfTwo32(mask)) { |
| 5059 | DCHECK(tag == 0 || base::bits::IsPowerOfTwo32(tag)); |
| 5060 | __ AndP(scratch, Operand(mask)); |
| 5061 | DeoptimizeIf(tag == 0 ? ne : eq, instr, Deoptimizer::kWrongInstanceType); |
| 5062 | } else { |
| 5063 | __ AndP(scratch, Operand(mask)); |
| 5064 | __ CmpP(scratch, Operand(tag)); |
| 5065 | DeoptimizeIf(ne, instr, Deoptimizer::kWrongInstanceType); |
| 5066 | } |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | void LCodeGen::DoCheckValue(LCheckValue* instr) { |
| 5071 | Register reg = ToRegister(instr->value()); |
| 5072 | Handle<HeapObject> object = instr->hydrogen()->object().handle(); |
| 5073 | AllowDeferredHandleDereference smi_check; |
| 5074 | if (isolate()->heap()->InNewSpace(*object)) { |
| 5075 | Register reg = ToRegister(instr->value()); |
| 5076 | Handle<Cell> cell = isolate()->factory()->NewCell(object); |
| 5077 | __ mov(ip, Operand(cell)); |
| 5078 | __ CmpP(reg, FieldMemOperand(ip, Cell::kValueOffset)); |
| 5079 | } else { |
| 5080 | __ CmpP(reg, Operand(object)); |
| 5081 | } |
| 5082 | DeoptimizeIf(ne, instr, Deoptimizer::kValueMismatch); |
| 5083 | } |
| 5084 | |
| 5085 | void LCodeGen::DoDeferredInstanceMigration(LCheckMaps* instr, Register object) { |
| 5086 | Register temp = ToRegister(instr->temp()); |
| 5087 | { |
| 5088 | PushSafepointRegistersScope scope(this); |
| 5089 | __ push(object); |
| 5090 | __ LoadImmP(cp, Operand::Zero()); |
| 5091 | __ CallRuntimeSaveDoubles(Runtime::kTryMigrateInstance); |
| 5092 | RecordSafepointWithRegisters(instr->pointer_map(), 1, |
| 5093 | Safepoint::kNoLazyDeopt); |
| 5094 | __ StoreToSafepointRegisterSlot(r2, temp); |
| 5095 | } |
| 5096 | __ TestIfSmi(temp); |
| 5097 | DeoptimizeIf(eq, instr, Deoptimizer::kInstanceMigrationFailed, cr0); |
| 5098 | } |
| 5099 | |
| 5100 | void LCodeGen::DoCheckMaps(LCheckMaps* instr) { |
| 5101 | class DeferredCheckMaps final : public LDeferredCode { |
| 5102 | public: |
| 5103 | DeferredCheckMaps(LCodeGen* codegen, LCheckMaps* instr, Register object) |
| 5104 | : LDeferredCode(codegen), instr_(instr), object_(object) { |
| 5105 | SetExit(check_maps()); |
| 5106 | } |
| 5107 | void Generate() override { |
| 5108 | codegen()->DoDeferredInstanceMigration(instr_, object_); |
| 5109 | } |
| 5110 | Label* check_maps() { return &check_maps_; } |
| 5111 | LInstruction* instr() override { return instr_; } |
| 5112 | |
| 5113 | private: |
| 5114 | LCheckMaps* instr_; |
| 5115 | Label check_maps_; |
| 5116 | Register object_; |
| 5117 | }; |
| 5118 | |
| 5119 | if (instr->hydrogen()->IsStabilityCheck()) { |
| 5120 | const UniqueSet<Map>* maps = instr->hydrogen()->maps(); |
| 5121 | for (int i = 0; i < maps->size(); ++i) { |
| 5122 | AddStabilityDependency(maps->at(i).handle()); |
| 5123 | } |
| 5124 | return; |
| 5125 | } |
| 5126 | |
| 5127 | LOperand* input = instr->value(); |
| 5128 | DCHECK(input->IsRegister()); |
| 5129 | Register reg = ToRegister(input); |
| 5130 | |
| 5131 | DeferredCheckMaps* deferred = NULL; |
| 5132 | if (instr->hydrogen()->HasMigrationTarget()) { |
| 5133 | deferred = new (zone()) DeferredCheckMaps(this, instr, reg); |
| 5134 | __ bind(deferred->check_maps()); |
| 5135 | } |
| 5136 | |
| 5137 | const UniqueSet<Map>* maps = instr->hydrogen()->maps(); |
| 5138 | Label success; |
| 5139 | for (int i = 0; i < maps->size() - 1; i++) { |
| 5140 | Handle<Map> map = maps->at(i).handle(); |
| 5141 | __ CompareMap(reg, map, &success); |
| 5142 | __ beq(&success); |
| 5143 | } |
| 5144 | |
| 5145 | Handle<Map> map = maps->at(maps->size() - 1).handle(); |
| 5146 | __ CompareMap(reg, map, &success); |
| 5147 | if (instr->hydrogen()->HasMigrationTarget()) { |
| 5148 | __ bne(deferred->entry()); |
| 5149 | } else { |
| 5150 | DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap); |
| 5151 | } |
| 5152 | |
| 5153 | __ bind(&success); |
| 5154 | } |
| 5155 | |
| 5156 | void LCodeGen::DoClampDToUint8(LClampDToUint8* instr) { |
| 5157 | DoubleRegister value_reg = ToDoubleRegister(instr->unclamped()); |
| 5158 | Register result_reg = ToRegister(instr->result()); |
| 5159 | __ ClampDoubleToUint8(result_reg, value_reg, double_scratch0()); |
| 5160 | } |
| 5161 | |
| 5162 | void LCodeGen::DoClampIToUint8(LClampIToUint8* instr) { |
| 5163 | Register unclamped_reg = ToRegister(instr->unclamped()); |
| 5164 | Register result_reg = ToRegister(instr->result()); |
| 5165 | __ ClampUint8(result_reg, unclamped_reg); |
| 5166 | } |
| 5167 | |
| 5168 | void LCodeGen::DoClampTToUint8(LClampTToUint8* instr) { |
| 5169 | Register scratch = scratch0(); |
| 5170 | Register input_reg = ToRegister(instr->unclamped()); |
| 5171 | Register result_reg = ToRegister(instr->result()); |
| 5172 | DoubleRegister temp_reg = ToDoubleRegister(instr->temp()); |
| 5173 | Label is_smi, done, heap_number; |
| 5174 | |
| 5175 | // Both smi and heap number cases are handled. |
| 5176 | __ UntagAndJumpIfSmi(result_reg, input_reg, &is_smi); |
| 5177 | |
| 5178 | // Check for heap number |
| 5179 | __ LoadP(scratch, FieldMemOperand(input_reg, HeapObject::kMapOffset)); |
| 5180 | __ CmpP(scratch, Operand(factory()->heap_number_map())); |
| 5181 | __ beq(&heap_number, Label::kNear); |
| 5182 | |
| 5183 | // Check for undefined. Undefined is converted to zero for clamping |
| 5184 | // conversions. |
| 5185 | __ CmpP(input_reg, Operand(factory()->undefined_value())); |
| 5186 | DeoptimizeIf(ne, instr, Deoptimizer::kNotAHeapNumberUndefined); |
| 5187 | __ LoadImmP(result_reg, Operand::Zero()); |
| 5188 | __ b(&done, Label::kNear); |
| 5189 | |
| 5190 | // Heap number |
| 5191 | __ bind(&heap_number); |
| 5192 | __ ld(temp_reg, FieldMemOperand(input_reg, HeapNumber::kValueOffset)); |
| 5193 | __ ClampDoubleToUint8(result_reg, temp_reg, double_scratch0()); |
| 5194 | __ b(&done, Label::kNear); |
| 5195 | |
| 5196 | // smi |
| 5197 | __ bind(&is_smi); |
| 5198 | __ ClampUint8(result_reg, result_reg); |
| 5199 | |
| 5200 | __ bind(&done); |
| 5201 | } |
| 5202 | |
| 5203 | void LCodeGen::DoDoubleBits(LDoubleBits* instr) { |
| 5204 | DoubleRegister value_reg = ToDoubleRegister(instr->value()); |
| 5205 | Register result_reg = ToRegister(instr->result()); |
| 5206 | __ lgdr(result_reg, value_reg); |
| 5207 | if (instr->hydrogen()->bits() == HDoubleBits::HIGH) { |
| 5208 | __ srlg(result_reg, result_reg, Operand(32)); |
| 5209 | } else { |
| 5210 | __ llgfr(result_reg, result_reg); |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | void LCodeGen::DoConstructDouble(LConstructDouble* instr) { |
| 5215 | Register hi_reg = ToRegister(instr->hi()); |
| 5216 | Register lo_reg = ToRegister(instr->lo()); |
| 5217 | DoubleRegister result_reg = ToDoubleRegister(instr->result()); |
| 5218 | Register scratch = scratch0(); |
| 5219 | |
| 5220 | // Combine hi_reg:lo_reg into a single 64-bit register. |
| 5221 | __ sllg(scratch, hi_reg, Operand(32)); |
| 5222 | __ lr(scratch, lo_reg); |
| 5223 | |
| 5224 | // Bitwise convert from GPR to FPR |
| 5225 | __ ldgr(result_reg, scratch); |
| 5226 | } |
| 5227 | |
| 5228 | void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5229 | class DeferredAllocate final : public LDeferredCode { |
| 5230 | public: |
| 5231 | DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5232 | : LDeferredCode(codegen), instr_(instr) {} |
| 5233 | void Generate() override { codegen()->DoDeferredAllocate(instr_); } |
| 5234 | LInstruction* instr() override { return instr_; } |
| 5235 | |
| 5236 | private: |
| 5237 | LAllocate* instr_; |
| 5238 | }; |
| 5239 | |
| 5240 | DeferredAllocate* deferred = new (zone()) DeferredAllocate(this, instr); |
| 5241 | |
| 5242 | Register result = ToRegister(instr->result()); |
| 5243 | Register scratch = ToRegister(instr->temp1()); |
| 5244 | Register scratch2 = ToRegister(instr->temp2()); |
| 5245 | |
| 5246 | // Allocate memory for the object. |
| 5247 | AllocationFlags flags = TAG_OBJECT; |
| 5248 | if (instr->hydrogen()->MustAllocateDoubleAligned()) { |
| 5249 | flags = static_cast<AllocationFlags>(flags | DOUBLE_ALIGNMENT); |
| 5250 | } |
| 5251 | if (instr->hydrogen()->IsOldSpaceAllocation()) { |
| 5252 | DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
| 5253 | flags = static_cast<AllocationFlags>(flags | PRETENURE); |
| 5254 | } |
| 5255 | |
| 5256 | if (instr->size()->IsConstantOperand()) { |
| 5257 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5258 | CHECK(size <= Page::kMaxRegularHeapObjectSize); |
| 5259 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
| 5260 | } else { |
| 5261 | Register size = ToRegister(instr->size()); |
| 5262 | __ Allocate(size, result, scratch, scratch2, deferred->entry(), flags); |
| 5263 | } |
| 5264 | |
| 5265 | __ bind(deferred->exit()); |
| 5266 | |
| 5267 | if (instr->hydrogen()->MustPrefillWithFiller()) { |
| 5268 | if (instr->size()->IsConstantOperand()) { |
| 5269 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5270 | __ LoadIntLiteral(scratch, size); |
| 5271 | } else { |
| 5272 | scratch = ToRegister(instr->size()); |
| 5273 | } |
| 5274 | __ lay(scratch, MemOperand(scratch, -kPointerSize)); |
| 5275 | Label loop; |
| 5276 | __ mov(scratch2, Operand(isolate()->factory()->one_pointer_filler_map())); |
| 5277 | __ bind(&loop); |
| 5278 | __ StoreP(scratch2, MemOperand(scratch, result, -kHeapObjectTag)); |
| 5279 | #if V8_TARGET_ARCH_S390X |
| 5280 | __ lay(scratch, MemOperand(scratch, -kPointerSize)); |
| 5281 | #else |
| 5282 | // TODO(joransiu): Improve the following sequence. |
| 5283 | // Need to use AHI instead of LAY as top nibble is not set with LAY, causing |
| 5284 | // incorrect result with the signed compare |
| 5285 | __ AddP(scratch, Operand(-kPointerSize)); |
| 5286 | #endif |
| 5287 | __ CmpP(scratch, Operand::Zero()); |
| 5288 | __ bge(&loop); |
| 5289 | } |
| 5290 | } |
| 5291 | |
| 5292 | void LCodeGen::DoDeferredAllocate(LAllocate* instr) { |
| 5293 | Register result = ToRegister(instr->result()); |
| 5294 | |
| 5295 | // TODO(3095996): Get rid of this. For now, we need to make the |
| 5296 | // result register contain a valid pointer because it is already |
| 5297 | // contained in the register pointer map. |
| 5298 | __ LoadSmiLiteral(result, Smi::FromInt(0)); |
| 5299 | |
| 5300 | PushSafepointRegistersScope scope(this); |
| 5301 | if (instr->size()->IsRegister()) { |
| 5302 | Register size = ToRegister(instr->size()); |
| 5303 | DCHECK(!size.is(result)); |
| 5304 | __ SmiTag(size); |
| 5305 | __ push(size); |
| 5306 | } else { |
| 5307 | int32_t size = ToInteger32(LConstantOperand::cast(instr->size())); |
| 5308 | #if !V8_TARGET_ARCH_S390X |
| 5309 | if (size >= 0 && size <= Smi::kMaxValue) { |
| 5310 | #endif |
| 5311 | __ Push(Smi::FromInt(size)); |
| 5312 | #if !V8_TARGET_ARCH_S390X |
| 5313 | } else { |
| 5314 | // We should never get here at runtime => abort |
| 5315 | __ stop("invalid allocation size"); |
| 5316 | return; |
| 5317 | } |
| 5318 | #endif |
| 5319 | } |
| 5320 | |
| 5321 | int flags = AllocateDoubleAlignFlag::encode( |
| 5322 | instr->hydrogen()->MustAllocateDoubleAligned()); |
| 5323 | if (instr->hydrogen()->IsOldSpaceAllocation()) { |
| 5324 | DCHECK(!instr->hydrogen()->IsNewSpaceAllocation()); |
| 5325 | flags = AllocateTargetSpace::update(flags, OLD_SPACE); |
| 5326 | } else { |
| 5327 | flags = AllocateTargetSpace::update(flags, NEW_SPACE); |
| 5328 | } |
| 5329 | __ Push(Smi::FromInt(flags)); |
| 5330 | |
| 5331 | CallRuntimeFromDeferred(Runtime::kAllocateInTargetSpace, 2, instr, |
| 5332 | instr->context()); |
| 5333 | __ StoreToSafepointRegisterSlot(r2, result); |
| 5334 | } |
| 5335 | |
| 5336 | void LCodeGen::DoTypeof(LTypeof* instr) { |
| 5337 | DCHECK(ToRegister(instr->value()).is(r5)); |
| 5338 | DCHECK(ToRegister(instr->result()).is(r2)); |
| 5339 | Label end, do_call; |
| 5340 | Register value_register = ToRegister(instr->value()); |
| 5341 | __ JumpIfNotSmi(value_register, &do_call); |
| 5342 | __ mov(r2, Operand(isolate()->factory()->number_string())); |
| 5343 | __ b(&end); |
| 5344 | __ bind(&do_call); |
| 5345 | TypeofStub stub(isolate()); |
| 5346 | CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
| 5347 | __ bind(&end); |
| 5348 | } |
| 5349 | |
| 5350 | void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) { |
| 5351 | Register input = ToRegister(instr->value()); |
| 5352 | |
| 5353 | Condition final_branch_condition = |
| 5354 | EmitTypeofIs(instr->TrueLabel(chunk_), instr->FalseLabel(chunk_), input, |
| 5355 | instr->type_literal()); |
| 5356 | if (final_branch_condition != kNoCondition) { |
| 5357 | EmitBranch(instr, final_branch_condition); |
| 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | Condition LCodeGen::EmitTypeofIs(Label* true_label, Label* false_label, |
| 5362 | Register input, Handle<String> type_name) { |
| 5363 | Condition final_branch_condition = kNoCondition; |
| 5364 | Register scratch = scratch0(); |
| 5365 | Factory* factory = isolate()->factory(); |
| 5366 | if (String::Equals(type_name, factory->number_string())) { |
| 5367 | __ JumpIfSmi(input, true_label); |
| 5368 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5369 | __ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex); |
| 5370 | final_branch_condition = eq; |
| 5371 | |
| 5372 | } else if (String::Equals(type_name, factory->string_string())) { |
| 5373 | __ JumpIfSmi(input, false_label); |
| 5374 | __ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE); |
| 5375 | final_branch_condition = lt; |
| 5376 | |
| 5377 | } else if (String::Equals(type_name, factory->symbol_string())) { |
| 5378 | __ JumpIfSmi(input, false_label); |
| 5379 | __ CompareObjectType(input, scratch, no_reg, SYMBOL_TYPE); |
| 5380 | final_branch_condition = eq; |
| 5381 | |
| 5382 | } else if (String::Equals(type_name, factory->boolean_string())) { |
| 5383 | __ CompareRoot(input, Heap::kTrueValueRootIndex); |
| 5384 | __ beq(true_label); |
| 5385 | __ CompareRoot(input, Heap::kFalseValueRootIndex); |
| 5386 | final_branch_condition = eq; |
| 5387 | |
| 5388 | } else if (String::Equals(type_name, factory->undefined_string())) { |
| 5389 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5390 | __ beq(false_label); |
| 5391 | __ JumpIfSmi(input, false_label); |
| 5392 | // Check for undetectable objects => true. |
| 5393 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5394 | __ LoadlB(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5395 | __ ExtractBit(r0, scratch, Map::kIsUndetectable); |
| 5396 | __ CmpP(r0, Operand::Zero()); |
| 5397 | final_branch_condition = ne; |
| 5398 | |
| 5399 | } else if (String::Equals(type_name, factory->function_string())) { |
| 5400 | __ JumpIfSmi(input, false_label); |
| 5401 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); |
| 5402 | __ LoadlB(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5403 | __ AndP(scratch, scratch, |
| 5404 | Operand((1 << Map::kIsCallable) | (1 << Map::kIsUndetectable))); |
| 5405 | __ CmpP(scratch, Operand(1 << Map::kIsCallable)); |
| 5406 | final_branch_condition = eq; |
| 5407 | |
| 5408 | } else if (String::Equals(type_name, factory->object_string())) { |
| 5409 | __ JumpIfSmi(input, false_label); |
| 5410 | __ CompareRoot(input, Heap::kNullValueRootIndex); |
| 5411 | __ beq(true_label); |
| 5412 | STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
| 5413 | __ CompareObjectType(input, scratch, ip, FIRST_JS_RECEIVER_TYPE); |
| 5414 | __ blt(false_label); |
| 5415 | // Check for callable or undetectable objects => false. |
| 5416 | __ LoadlB(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5417 | __ AndP(r0, scratch, |
| 5418 | Operand((1 << Map::kIsCallable) | (1 << Map::kIsUndetectable))); |
| 5419 | __ CmpP(r0, Operand::Zero()); |
| 5420 | final_branch_condition = eq; |
| 5421 | |
| 5422 | // clang-format off |
| 5423 | #define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \ |
| 5424 | } else if (String::Equals(type_name, factory->type##_string())) { \ |
| 5425 | __ JumpIfSmi(input, false_label); \ |
| 5426 | __ LoadP(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); \ |
| 5427 | __ CompareRoot(scratch, Heap::k##Type##MapRootIndex); \ |
| 5428 | final_branch_condition = eq; |
| 5429 | SIMD128_TYPES(SIMD128_TYPE) |
| 5430 | #undef SIMD128_TYPE |
| 5431 | // clang-format on |
| 5432 | |
| 5433 | } else { |
| 5434 | __ b(false_label); |
| 5435 | } |
| 5436 | |
| 5437 | return final_branch_condition; |
| 5438 | } |
| 5439 | |
| 5440 | void LCodeGen::EnsureSpaceForLazyDeopt(int space_needed) { |
| 5441 | if (info()->ShouldEnsureSpaceForLazyDeopt()) { |
| 5442 | // Ensure that we have enough space after the previous lazy-bailout |
| 5443 | // instruction for patching the code here. |
| 5444 | int current_pc = masm()->pc_offset(); |
| 5445 | if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
| 5446 | int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
| 5447 | DCHECK_EQ(0, padding_size % 2); |
| 5448 | while (padding_size > 0) { |
| 5449 | __ nop(); |
| 5450 | padding_size -= 2; |
| 5451 | } |
| 5452 | } |
| 5453 | } |
| 5454 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
| 5455 | } |
| 5456 | |
| 5457 | void LCodeGen::DoLazyBailout(LLazyBailout* instr) { |
| 5458 | last_lazy_deopt_pc_ = masm()->pc_offset(); |
| 5459 | DCHECK(instr->HasEnvironment()); |
| 5460 | LEnvironment* env = instr->environment(); |
| 5461 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5462 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 5463 | } |
| 5464 | |
| 5465 | void LCodeGen::DoDeoptimize(LDeoptimize* instr) { |
| 5466 | Deoptimizer::BailoutType type = instr->hydrogen()->type(); |
| 5467 | // TODO(danno): Stubs expect all deopts to be lazy for historical reasons (the |
| 5468 | // needed return address), even though the implementation of LAZY and EAGER is |
| 5469 | // now identical. When LAZY is eventually completely folded into EAGER, remove |
| 5470 | // the special case below. |
| 5471 | if (info()->IsStub() && type == Deoptimizer::EAGER) { |
| 5472 | type = Deoptimizer::LAZY; |
| 5473 | } |
| 5474 | |
| 5475 | DeoptimizeIf(al, instr, instr->hydrogen()->reason(), type); |
| 5476 | } |
| 5477 | |
| 5478 | void LCodeGen::DoDummy(LDummy* instr) { |
| 5479 | // Nothing to see here, move on! |
| 5480 | } |
| 5481 | |
| 5482 | void LCodeGen::DoDummyUse(LDummyUse* instr) { |
| 5483 | // Nothing to see here, move on! |
| 5484 | } |
| 5485 | |
| 5486 | void LCodeGen::DoDeferredStackCheck(LStackCheck* instr) { |
| 5487 | PushSafepointRegistersScope scope(this); |
| 5488 | LoadContextFromDeferred(instr->context()); |
| 5489 | __ CallRuntimeSaveDoubles(Runtime::kStackGuard); |
| 5490 | RecordSafepointWithLazyDeopt( |
| 5491 | instr, RECORD_SAFEPOINT_WITH_REGISTERS_AND_NO_ARGUMENTS); |
| 5492 | DCHECK(instr->HasEnvironment()); |
| 5493 | LEnvironment* env = instr->environment(); |
| 5494 | safepoints_.RecordLazyDeoptimizationIndex(env->deoptimization_index()); |
| 5495 | } |
| 5496 | |
| 5497 | void LCodeGen::DoStackCheck(LStackCheck* instr) { |
| 5498 | class DeferredStackCheck final : public LDeferredCode { |
| 5499 | public: |
| 5500 | DeferredStackCheck(LCodeGen* codegen, LStackCheck* instr) |
| 5501 | : LDeferredCode(codegen), instr_(instr) {} |
| 5502 | void Generate() override { codegen()->DoDeferredStackCheck(instr_); } |
| 5503 | LInstruction* instr() override { return instr_; } |
| 5504 | |
| 5505 | private: |
| 5506 | LStackCheck* instr_; |
| 5507 | }; |
| 5508 | |
| 5509 | DCHECK(instr->HasEnvironment()); |
| 5510 | LEnvironment* env = instr->environment(); |
| 5511 | // There is no LLazyBailout instruction for stack-checks. We have to |
| 5512 | // prepare for lazy deoptimization explicitly here. |
| 5513 | if (instr->hydrogen()->is_function_entry()) { |
| 5514 | // Perform stack overflow check. |
| 5515 | Label done; |
| 5516 | __ CmpLogicalP(sp, RootMemOperand(Heap::kStackLimitRootIndex)); |
| 5517 | __ bge(&done, Label::kNear); |
| 5518 | DCHECK(instr->context()->IsRegister()); |
| 5519 | DCHECK(ToRegister(instr->context()).is(cp)); |
| 5520 | CallCode(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET, |
| 5521 | instr); |
| 5522 | __ bind(&done); |
| 5523 | } else { |
| 5524 | DCHECK(instr->hydrogen()->is_backwards_branch()); |
| 5525 | // Perform stack overflow check if this goto needs it before jumping. |
| 5526 | DeferredStackCheck* deferred_stack_check = |
| 5527 | new (zone()) DeferredStackCheck(this, instr); |
| 5528 | __ CmpLogicalP(sp, RootMemOperand(Heap::kStackLimitRootIndex)); |
| 5529 | __ blt(deferred_stack_check->entry()); |
| 5530 | EnsureSpaceForLazyDeopt(Deoptimizer::patch_size()); |
| 5531 | __ bind(instr->done_label()); |
| 5532 | deferred_stack_check->SetExit(instr->done_label()); |
| 5533 | RegisterEnvironmentForDeoptimization(env, Safepoint::kLazyDeopt); |
| 5534 | // Don't record a deoptimization index for the safepoint here. |
| 5535 | // This will be done explicitly when emitting call and the safepoint in |
| 5536 | // the deferred code. |
| 5537 | } |
| 5538 | } |
| 5539 | |
| 5540 | void LCodeGen::DoOsrEntry(LOsrEntry* instr) { |
| 5541 | // This is a pseudo-instruction that ensures that the environment here is |
| 5542 | // properly registered for deoptimization and records the assembler's PC |
| 5543 | // offset. |
| 5544 | LEnvironment* environment = instr->environment(); |
| 5545 | |
| 5546 | // If the environment were already registered, we would have no way of |
| 5547 | // backpatching it with the spill slot operands. |
| 5548 | DCHECK(!environment->HasBeenRegistered()); |
| 5549 | RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 5550 | |
| 5551 | GenerateOsrPrologue(); |
| 5552 | } |
| 5553 | |
| 5554 | void LCodeGen::DoForInPrepareMap(LForInPrepareMap* instr) { |
| 5555 | Label use_cache, call_runtime; |
| 5556 | __ CheckEnumCache(&call_runtime); |
| 5557 | |
| 5558 | __ LoadP(r2, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 5559 | __ b(&use_cache); |
| 5560 | |
| 5561 | // Get the set of properties to enumerate. |
| 5562 | __ bind(&call_runtime); |
| 5563 | __ push(r2); |
| 5564 | CallRuntime(Runtime::kForInEnumerate, instr); |
| 5565 | __ bind(&use_cache); |
| 5566 | } |
| 5567 | |
| 5568 | void LCodeGen::DoForInCacheArray(LForInCacheArray* instr) { |
| 5569 | Register map = ToRegister(instr->map()); |
| 5570 | Register result = ToRegister(instr->result()); |
| 5571 | Label load_cache, done; |
| 5572 | __ EnumLength(result, map); |
| 5573 | __ CmpSmiLiteral(result, Smi::FromInt(0), r0); |
| 5574 | __ bne(&load_cache, Label::kNear); |
| 5575 | __ mov(result, Operand(isolate()->factory()->empty_fixed_array())); |
| 5576 | __ b(&done, Label::kNear); |
| 5577 | |
| 5578 | __ bind(&load_cache); |
| 5579 | __ LoadInstanceDescriptors(map, result); |
| 5580 | __ LoadP(result, FieldMemOperand(result, DescriptorArray::kEnumCacheOffset)); |
| 5581 | __ LoadP(result, FieldMemOperand(result, FixedArray::SizeFor(instr->idx()))); |
| 5582 | __ CmpP(result, Operand::Zero()); |
| 5583 | DeoptimizeIf(eq, instr, Deoptimizer::kNoCache); |
| 5584 | |
| 5585 | __ bind(&done); |
| 5586 | } |
| 5587 | |
| 5588 | void LCodeGen::DoCheckMapValue(LCheckMapValue* instr) { |
| 5589 | Register object = ToRegister(instr->value()); |
| 5590 | Register map = ToRegister(instr->map()); |
| 5591 | __ LoadP(scratch0(), FieldMemOperand(object, HeapObject::kMapOffset)); |
| 5592 | __ CmpP(map, scratch0()); |
| 5593 | DeoptimizeIf(ne, instr, Deoptimizer::kWrongMap); |
| 5594 | } |
| 5595 | |
| 5596 | void LCodeGen::DoDeferredLoadMutableDouble(LLoadFieldByIndex* instr, |
| 5597 | Register result, Register object, |
| 5598 | Register index) { |
| 5599 | PushSafepointRegistersScope scope(this); |
| 5600 | __ Push(object, index); |
| 5601 | __ LoadImmP(cp, Operand::Zero()); |
| 5602 | __ CallRuntimeSaveDoubles(Runtime::kLoadMutableDouble); |
| 5603 | RecordSafepointWithRegisters(instr->pointer_map(), 2, |
| 5604 | Safepoint::kNoLazyDeopt); |
| 5605 | __ StoreToSafepointRegisterSlot(r2, result); |
| 5606 | } |
| 5607 | |
| 5608 | void LCodeGen::DoLoadFieldByIndex(LLoadFieldByIndex* instr) { |
| 5609 | class DeferredLoadMutableDouble final : public LDeferredCode { |
| 5610 | public: |
| 5611 | DeferredLoadMutableDouble(LCodeGen* codegen, LLoadFieldByIndex* instr, |
| 5612 | Register result, Register object, Register index) |
| 5613 | : LDeferredCode(codegen), |
| 5614 | instr_(instr), |
| 5615 | result_(result), |
| 5616 | object_(object), |
| 5617 | index_(index) {} |
| 5618 | void Generate() override { |
| 5619 | codegen()->DoDeferredLoadMutableDouble(instr_, result_, object_, index_); |
| 5620 | } |
| 5621 | LInstruction* instr() override { return instr_; } |
| 5622 | |
| 5623 | private: |
| 5624 | LLoadFieldByIndex* instr_; |
| 5625 | Register result_; |
| 5626 | Register object_; |
| 5627 | Register index_; |
| 5628 | }; |
| 5629 | |
| 5630 | Register object = ToRegister(instr->object()); |
| 5631 | Register index = ToRegister(instr->index()); |
| 5632 | Register result = ToRegister(instr->result()); |
| 5633 | Register scratch = scratch0(); |
| 5634 | |
| 5635 | DeferredLoadMutableDouble* deferred; |
| 5636 | deferred = new (zone()) |
| 5637 | DeferredLoadMutableDouble(this, instr, result, object, index); |
| 5638 | |
| 5639 | Label out_of_object, done; |
| 5640 | |
| 5641 | __ TestBitMask(index, reinterpret_cast<uintptr_t>(Smi::FromInt(1)), r0); |
| 5642 | __ bne(deferred->entry()); |
| 5643 | __ ShiftRightArithP(index, index, Operand(1)); |
| 5644 | |
| 5645 | __ CmpP(index, Operand::Zero()); |
| 5646 | __ blt(&out_of_object, Label::kNear); |
| 5647 | |
| 5648 | __ SmiToPtrArrayOffset(r0, index); |
| 5649 | __ AddP(scratch, object, r0); |
| 5650 | __ LoadP(result, FieldMemOperand(scratch, JSObject::kHeaderSize)); |
| 5651 | |
| 5652 | __ b(&done, Label::kNear); |
| 5653 | |
| 5654 | __ bind(&out_of_object); |
| 5655 | __ LoadP(result, FieldMemOperand(object, JSObject::kPropertiesOffset)); |
| 5656 | // Index is equal to negated out of object property index plus 1. |
| 5657 | __ SmiToPtrArrayOffset(r0, index); |
| 5658 | __ SubP(scratch, result, r0); |
| 5659 | __ LoadP(result, |
| 5660 | FieldMemOperand(scratch, FixedArray::kHeaderSize - kPointerSize)); |
| 5661 | __ bind(deferred->exit()); |
| 5662 | __ bind(&done); |
| 5663 | } |
| 5664 | |
| 5665 | #undef __ |
| 5666 | |
| 5667 | } // namespace internal |
| 5668 | } // namespace v8 |