1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
|
/*
* Copyright (C) 2008-2021 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#if ENABLE(JIT)
#include "BytecodeOperandsForCheckpoint.h"
#include "CommonSlowPathsInlines.h"
#include "JIT.h"
#include "JSCInlines.h"
namespace JSC {
ALWAYS_INLINE bool JIT::isOperandConstantDouble(VirtualRegister src)
{
return src.isConstant() && getConstantOperand(src).isDouble();
}
ALWAYS_INLINE JSValue JIT::getConstantOperand(VirtualRegister src)
{
ASSERT(src.isConstant());
return m_codeBlock->getConstant(src);
}
ALWAYS_INLINE void JIT::emitPutIntToCallFrameHeader(RegisterID from, VirtualRegister entry)
{
ASSERT(entry.isHeader());
#if USE(JSVALUE32_64)
store32(TrustedImm32(JSValue::Int32Tag), tagFor(entry));
store32(from, payloadFor(entry));
#else
store64(from, addressFor(entry));
#endif
}
ALWAYS_INLINE void JIT::emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures)
{
failures.append(branchIfNotString(src));
loadPtr(MacroAssembler::Address(src, JSString::offsetOfValue()), dst);
failures.append(branchIfRopeStringImpl(dst));
failures.append(branch32(NotEqual, MacroAssembler::Address(dst, StringImpl::lengthMemoryOffset()), TrustedImm32(1)));
loadPtr(MacroAssembler::Address(dst, StringImpl::dataOffset()), regT1);
auto is16Bit = branchTest32(Zero, Address(dst, StringImpl::flagsOffset()), TrustedImm32(StringImpl::flagIs8Bit()));
load8(MacroAssembler::Address(regT1, 0), dst);
auto done = jump();
is16Bit.link(this);
load16(MacroAssembler::Address(regT1, 0), dst);
done.link(this);
}
ALWAYS_INLINE JIT::Call JIT::emitNakedNearCall(CodePtr<NoPtrTag> target)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
Call nakedCall = nearCall();
m_nearCalls.append(NearCallRecord(nakedCall, FunctionPtr<JSInternalPtrTag>(target.retagged<JSInternalPtrTag>())));
return nakedCall;
}
ALWAYS_INLINE JIT::Call JIT::emitNakedNearTailCall(CodePtr<NoPtrTag> target)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
Call nakedCall = nearTailCall();
m_nearCalls.append(NearCallRecord(nakedCall, FunctionPtr<JSInternalPtrTag>(target.retagged<JSInternalPtrTag>())));
return nakedCall;
}
ALWAYS_INLINE JIT::Jump JIT::emitNakedNearJump(CodePtr<JITThunkPtrTag> target)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
Jump nakedJump = jump();
m_nearJumps.append(NearJumpRecord(nakedJump, CodeLocationLabel(target)));
return nakedJump;
}
ALWAYS_INLINE void JIT::updateTopCallFrame()
{
uint32_t locationBits = CallSiteIndex(m_bytecodeIndex.offset()).bits();
store32(TrustedImm32(locationBits), tagFor(CallFrameSlot::argumentCountIncludingThis));
prepareCallOperation(*m_vm);
}
ALWAYS_INLINE MacroAssembler::Call JIT::appendCallWithExceptionCheck(const FunctionPtr<CFunctionPtrTag> function)
{
updateTopCallFrame();
MacroAssembler::Call call = appendCall(function);
exceptionCheck();
return call;
}
ALWAYS_INLINE void JIT::appendCallWithExceptionCheck(Address function)
{
updateTopCallFrame();
appendCall(function);
exceptionCheck();
}
#if OS(WINDOWS) && CPU(X86_64)
ALWAYS_INLINE MacroAssembler::Call JIT::appendCallWithExceptionCheckAndSlowPathReturnType(const FunctionPtr<CFunctionPtrTag> function)
{
updateTopCallFrame();
MacroAssembler::Call call = appendCallWithSlowPathReturnType(function);
exceptionCheck();
return call;
}
#endif
ALWAYS_INLINE MacroAssembler::Call JIT::appendCallWithCallFrameRollbackOnException(const FunctionPtr<CFunctionPtrTag> function)
{
updateTopCallFrame(); // The callee is responsible for setting topCallFrame to their caller
MacroAssembler::Call call = appendCall(function);
exceptionCheckWithCallFrameRollback();
return call;
}
ALWAYS_INLINE MacroAssembler::Call JIT::appendCallWithExceptionCheckSetJSValueResult(const FunctionPtr<CFunctionPtrTag> function, VirtualRegister dst)
{
MacroAssembler::Call call = appendCallWithExceptionCheck(function);
#if USE(JSVALUE64)
emitPutVirtualRegister(dst, returnValueGPR);
#else
emitStore(dst, returnValueGPR2, returnValueGPR);
#endif
return call;
}
ALWAYS_INLINE void JIT::appendCallWithExceptionCheckSetJSValueResult(Address function, VirtualRegister dst)
{
appendCallWithExceptionCheck(function);
#if USE(JSVALUE64)
emitPutVirtualRegister(dst, returnValueGPR);
#else
emitStore(dst, returnValueGPR2, returnValueGPR);
#endif
}
template<typename Metadata>
ALWAYS_INLINE MacroAssembler::Call JIT::appendCallWithExceptionCheckSetJSValueResultWithProfile(Metadata& metadata, const FunctionPtr<CFunctionPtrTag> function, VirtualRegister dst)
{
MacroAssembler::Call call = appendCallWithExceptionCheck(function);
#if USE(JSVALUE64)
emitValueProfilingSite(metadata, returnValueGPR);
emitPutVirtualRegister(dst, returnValueGPR);
#else
emitValueProfilingSite(metadata, JSValueRegs(returnValueGPR2, returnValueGPR));
emitStore(dst, returnValueGPR2, returnValueGPR);
#endif
return call;
}
template<typename Metadata>
ALWAYS_INLINE void JIT::appendCallWithExceptionCheckSetJSValueResultWithProfile(Metadata& metadata, Address function, VirtualRegister dst)
{
appendCallWithExceptionCheck(function);
#if USE(JSVALUE64)
emitValueProfilingSite(metadata, returnValueGPR);
emitPutVirtualRegister(dst, returnValueGPR);
#else
emitValueProfilingSite(metadata, JSValueRegs(returnValueGPR2, returnValueGPR));
emitStore(dst, returnValueGPR2, returnValueGPR);
#endif
}
ALWAYS_INLINE void JIT::linkSlowCaseIfNotJSCell(Vector<SlowCaseEntry>::iterator& iter, VirtualRegister reg)
{
if (!m_codeBlock->isKnownCell(reg))
linkSlowCase(iter);
}
ALWAYS_INLINE void JIT::linkAllSlowCasesForBytecodeIndex(Vector<SlowCaseEntry>& slowCases, Vector<SlowCaseEntry>::iterator& iter, BytecodeIndex bytecodeIndex)
{
while (iter != slowCases.end() && iter->to == bytecodeIndex)
linkSlowCase(iter);
}
ALWAYS_INLINE bool JIT::hasAnySlowCases(Vector<SlowCaseEntry>& slowCases, Vector<SlowCaseEntry>::iterator& iter, BytecodeIndex bytecodeIndex)
{
if (iter != slowCases.end() && iter->to == bytecodeIndex)
return true;
return false;
}
inline void JIT::advanceToNextCheckpoint()
{
ASSERT_WITH_MESSAGE(m_bytecodeIndex, "This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set");
ASSERT(m_codeBlock->instructionAt(m_bytecodeIndex)->hasCheckpoints());
m_bytecodeIndex = BytecodeIndex(m_bytecodeIndex.offset(), m_bytecodeIndex.checkpoint() + 1);
auto result = m_checkpointLabels.add(m_bytecodeIndex, label());
ASSERT_UNUSED(result, result.isNewEntry);
}
inline void JIT::emitJumpSlowToHotForCheckpoint(Jump jump)
{
ASSERT_WITH_MESSAGE(m_bytecodeIndex, "This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set");
ASSERT(m_codeBlock->instructionAt(m_bytecodeIndex)->hasCheckpoints());
m_bytecodeIndex = BytecodeIndex(m_bytecodeIndex.offset(), m_bytecodeIndex.checkpoint() + 1);
auto iter = m_checkpointLabels.find(m_bytecodeIndex);
ASSERT(iter != m_checkpointLabels.end());
jump.linkTo(iter->value, this);
}
ALWAYS_INLINE void JIT::addSlowCase(Jump jump)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
m_slowCases.append(SlowCaseEntry(jump, m_bytecodeIndex));
}
ALWAYS_INLINE void JIT::addSlowCase(const JumpList& jumpList)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
for (const Jump& jump : jumpList.jumps())
m_slowCases.append(SlowCaseEntry(jump, m_bytecodeIndex));
}
ALWAYS_INLINE void JIT::addSlowCase()
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
Jump emptyJump; // Doing it this way to make Windows happy.
m_slowCases.append(SlowCaseEntry(emptyJump, m_bytecodeIndex));
}
ALWAYS_INLINE void JIT::addJump(Jump jump, int relativeOffset)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
m_jmpTable.append(JumpTable(jump, m_bytecodeIndex.offset() + relativeOffset));
}
ALWAYS_INLINE void JIT::addJump(const JumpList& jumpList, int relativeOffset)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
for (auto& jump : jumpList.jumps())
addJump(jump, relativeOffset);
}
ALWAYS_INLINE void JIT::emitJumpSlowToHot(Jump jump, int relativeOffset)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
jump.linkTo(m_labels[m_bytecodeIndex.offset() + relativeOffset], this);
}
#if ENABLE(SAMPLING_FLAGS)
ALWAYS_INLINE void JIT::setSamplingFlag(int32_t flag)
{
ASSERT(flag >= 1);
ASSERT(flag <= 32);
or32(TrustedImm32(1u << (flag - 1)), AbsoluteAddress(SamplingFlags::addressOfFlags()));
}
ALWAYS_INLINE void JIT::clearSamplingFlag(int32_t flag)
{
ASSERT(flag >= 1);
ASSERT(flag <= 32);
and32(TrustedImm32(~(1u << (flag - 1))), AbsoluteAddress(SamplingFlags::addressOfFlags()));
}
#endif
#if ENABLE(SAMPLING_COUNTERS)
ALWAYS_INLINE void JIT::emitCount(AbstractSamplingCounter& counter, int32_t count)
{
add64(TrustedImm32(count), AbsoluteAddress(counter.addressOfCounter()));
}
#endif
ALWAYS_INLINE bool JIT::isOperandConstantChar(VirtualRegister src)
{
return src.isConstant() && getConstantOperand(src).isString() && asString(getConstantOperand(src).asCell())->length() == 1;
}
inline void JIT::emitValueProfilingSite(ValueProfile& valueProfile, JSValueRegs value)
{
ASSERT(shouldEmitProfiling());
// We're in a simple configuration: only one bucket, so we can just do a direct
// store.
#if USE(JSVALUE64)
store64(value.gpr(), valueProfile.m_buckets);
#else
EncodedValueDescriptor* descriptor = bitwise_cast<EncodedValueDescriptor*>(valueProfile.m_buckets);
store32(value.payloadGPR(), &descriptor->asBits.payload);
store32(value.tagGPR(), &descriptor->asBits.tag);
#endif
}
template<typename Op>
inline std::enable_if_t<std::is_same<decltype(Op::Metadata::m_profile), ValueProfile>::value, void> JIT::emitValueProfilingSiteIfProfiledOpcode(Op bytecode)
{
#if USE(JSVALUE64)
emitValueProfilingSite(bytecode.metadata(m_codeBlock), regT0);
#else
emitValueProfilingSite(bytecode.metadata(m_codeBlock), JSValueRegs(regT1, regT0));
#endif
}
inline void JIT::emitValueProfilingSiteIfProfiledOpcode(...) { }
template<typename Metadata>
inline void JIT::emitValueProfilingSite(Metadata& metadata, JSValueRegs value)
{
if (!shouldEmitProfiling())
return;
emitValueProfilingSite(valueProfileFor(metadata, m_bytecodeIndex.checkpoint()), value);
}
#if USE(JSVALUE64)
inline void JIT::emitValueProfilingSite(ValueProfile& valueProfile, GPRReg resultReg)
{
emitValueProfilingSite(valueProfile, JSValueRegs(resultReg));
}
template<typename Metadata>
inline void JIT::emitValueProfilingSite(Metadata& metadata, GPRReg resultReg)
{
emitValueProfilingSite(metadata, JSValueRegs(resultReg));
}
#endif
inline void JIT::emitArrayProfilingSiteWithCell(RegisterID cellGPR, ArrayProfile* arrayProfile, RegisterID scratchGPR)
{
if (shouldEmitProfiling()) {
load32(MacroAssembler::Address(cellGPR, JSCell::structureIDOffset()), scratchGPR);
store32(scratchGPR, arrayProfile->addressOfLastSeenStructureID());
}
}
inline void JIT::emitArrayProfilingSiteWithCell(RegisterID cellGPR, RegisterID arrayProfileGPR, RegisterID scratchGPR)
{
if (shouldEmitProfiling()) {
load32(MacroAssembler::Address(cellGPR, JSCell::structureIDOffset()), scratchGPR);
store32(scratchGPR, Address(arrayProfileGPR, ArrayProfile::offsetOfLastSeenStructureID()));
}
}
ALWAYS_INLINE int32_t JIT::getOperandConstantInt(VirtualRegister src)
{
return getConstantOperand(src).asInt32();
}
ALWAYS_INLINE double JIT::getOperandConstantDouble(VirtualRegister src)
{
return getConstantOperand(src).asDouble();
}
ALWAYS_INLINE void JIT::emitInitRegister(VirtualRegister dst)
{
storeTrustedValue(jsUndefined(), addressFor(dst));
}
#if USE(JSVALUE32_64)
inline void JIT::emitLoadDouble(VirtualRegister reg, FPRegisterID value)
{
if (reg.isConstant()) {
WriteBarrier<Unknown>& inConstantPool = m_codeBlock->constantRegister(reg);
loadDouble(TrustedImmPtr(&inConstantPool), value);
} else
loadDouble(addressFor(reg), value);
}
inline void JIT::emitLoadTag(VirtualRegister reg, RegisterID tag)
{
if (reg.isConstant()) {
move(Imm32(getConstantOperand(reg).tag()), tag);
return;
}
load32(tagFor(reg), tag);
}
inline void JIT::emitLoadPayload(VirtualRegister reg, RegisterID payload)
{
if (reg.isConstant()) {
move(Imm32(getConstantOperand(reg).payload()), payload);
return;
}
load32(payloadFor(reg), payload);
}
inline void JIT::emitLoad(const JSValue& v, RegisterID tag, RegisterID payload)
{
move(Imm32(v.payload()), payload);
move(Imm32(v.tag()), tag);
}
ALWAYS_INLINE void JIT::emitGetVirtualRegister(VirtualRegister src, JSValueRegs dst)
{
emitLoad(src, dst.tagGPR(), dst.payloadGPR());
}
ALWAYS_INLINE void JIT::emitPutVirtualRegister(VirtualRegister dst, JSValueRegs from)
{
emitStore(dst, from.tagGPR(), from.payloadGPR());
}
inline void JIT::emitLoad(VirtualRegister reg, RegisterID tag, RegisterID payload, RegisterID base)
{
RELEASE_ASSERT(tag != payload);
if (base == callFrameRegister) {
RELEASE_ASSERT(payload != base);
emitLoadPayload(reg, payload);
emitLoadTag(reg, tag);
return;
}
if (payload == base) { // avoid stomping base
load32(tagFor(reg, base), tag);
load32(payloadFor(reg, base), payload);
return;
}
load32(payloadFor(reg, base), payload);
load32(tagFor(reg, base), tag);
}
inline void JIT::emitLoad2(VirtualRegister reg1, RegisterID tag1, RegisterID payload1, VirtualRegister reg2, RegisterID tag2, RegisterID payload2)
{
emitLoad(reg2, tag2, payload2);
emitLoad(reg1, tag1, payload1);
}
inline void JIT::emitStore(VirtualRegister reg, RegisterID tag, RegisterID payload, RegisterID base)
{
store32(payload, payloadFor(reg, base));
store32(tag, tagFor(reg, base));
}
inline void JIT::emitStoreInt32(VirtualRegister reg, RegisterID payload, bool indexIsInt32)
{
store32(payload, payloadFor(reg));
if (!indexIsInt32)
store32(TrustedImm32(JSValue::Int32Tag), tagFor(reg));
}
inline void JIT::emitStoreInt32(VirtualRegister reg, TrustedImm32 payload, bool indexIsInt32)
{
store32(payload, payloadFor(reg));
if (!indexIsInt32)
store32(TrustedImm32(JSValue::Int32Tag), tagFor(reg));
}
inline void JIT::emitStoreCell(VirtualRegister reg, RegisterID payload, bool indexIsCell)
{
store32(payload, payloadFor(reg));
if (!indexIsCell)
store32(TrustedImm32(JSValue::CellTag), tagFor(reg));
}
inline void JIT::emitStoreBool(VirtualRegister reg, RegisterID payload, bool indexIsBool)
{
store32(payload, payloadFor(reg));
if (!indexIsBool)
store32(TrustedImm32(JSValue::BooleanTag), tagFor(reg));
}
inline void JIT::emitStoreDouble(VirtualRegister reg, FPRegisterID value)
{
storeDouble(value, addressFor(reg));
}
inline void JIT::emitStore(VirtualRegister reg, const JSValue constant, RegisterID base)
{
store32(Imm32(constant.payload()), payloadFor(reg, base));
store32(Imm32(constant.tag()), tagFor(reg, base));
}
inline void JIT::emitJumpSlowCaseIfNotJSCell(VirtualRegister reg)
{
if (!m_codeBlock->isKnownCell(reg)) {
if (reg.isConstant())
addSlowCase(jump());
else
addSlowCase(emitJumpIfNotJSCell(reg));
}
}
inline void JIT::emitJumpSlowCaseIfNotJSCell(VirtualRegister reg, RegisterID tag)
{
if (!m_codeBlock->isKnownCell(reg)) {
if (reg.isConstant())
addSlowCase(jump());
else
addSlowCase(branchIfNotCell(tag));
}
}
ALWAYS_INLINE bool JIT::isOperandConstantInt(VirtualRegister src)
{
return src.isConstant() && getConstantOperand(src).isInt32();
}
ALWAYS_INLINE bool JIT::getOperandConstantInt(VirtualRegister op1, VirtualRegister op2, VirtualRegister& op, int32_t& constant)
{
if (isOperandConstantInt(op1)) {
constant = getConstantOperand(op1).asInt32();
op = op2;
return true;
}
if (isOperandConstantInt(op2)) {
constant = getConstantOperand(op2).asInt32();
op = op1;
return true;
}
return false;
}
#else // USE(JSVALUE32_64)
// get arg puts an arg from the SF register array into a h/w register
ALWAYS_INLINE void JIT::emitGetVirtualRegister(VirtualRegister src, RegisterID dst)
{
ASSERT(m_bytecodeIndex); // This method should only be called during hot/cold path generation, so that m_bytecodeIndex is set.
if (src.isConstant()) {
JSValue value = m_codeBlock->getConstant(src);
if (!value.isNumber())
move(TrustedImm64(JSValue::encode(value)), dst);
else
move(Imm64(JSValue::encode(value)), dst);
return;
}
load64(addressFor(src), dst);
}
ALWAYS_INLINE void JIT::emitGetVirtualRegister(VirtualRegister src, JSValueRegs dst)
{
emitGetVirtualRegister(src, dst.payloadGPR());
}
ALWAYS_INLINE void JIT::emitGetVirtualRegisters(VirtualRegister src1, RegisterID dst1, VirtualRegister src2, RegisterID dst2)
{
emitGetVirtualRegister(src1, dst1);
emitGetVirtualRegister(src2, dst2);
}
ALWAYS_INLINE bool JIT::isOperandConstantInt(VirtualRegister src)
{
return src.isConstant() && getConstantOperand(src).isInt32();
}
ALWAYS_INLINE void JIT::emitPutVirtualRegister(VirtualRegister dst, RegisterID from)
{
store64(from, addressFor(dst));
}
ALWAYS_INLINE void JIT::emitPutVirtualRegister(VirtualRegister dst, JSValueRegs from)
{
emitPutVirtualRegister(dst, from.payloadGPR());
}
ALWAYS_INLINE JIT::Jump JIT::emitJumpIfBothJSCells(RegisterID reg1, RegisterID reg2, RegisterID scratch)
{
move(reg1, scratch);
or64(reg2, scratch);
return branchIfCell(scratch);
}
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfJSCell(RegisterID reg)
{
addSlowCase(branchIfCell(reg));
}
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg, VirtualRegister vReg)
{
if (!m_codeBlock->isKnownCell(vReg))
emitJumpSlowCaseIfNotJSCell(reg);
}
ALWAYS_INLINE JIT::PatchableJump JIT::emitPatchableJumpIfNotInt(RegisterID reg)
{
return patchableBranch64(Below, reg, numberTagRegister);
}
ALWAYS_INLINE JIT::Jump JIT::emitJumpIfNotInt(RegisterID reg1, RegisterID reg2, RegisterID scratch)
{
move(reg1, scratch);
and64(reg2, scratch);
return branchIfNotInt32(scratch);
}
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotInt(RegisterID reg)
{
addSlowCase(branchIfNotInt32(reg));
}
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotInt(RegisterID reg1, RegisterID reg2, RegisterID scratch)
{
addSlowCase(emitJumpIfNotInt(reg1, reg2, scratch));
}
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotNumber(RegisterID reg)
{
addSlowCase(branchIfNotNumber(reg));
}
#endif // USE(JSVALUE32_64)
ALWAYS_INLINE void JIT::emitJumpSlowCaseIfNotJSCell(RegisterID reg)
{
addSlowCase(branchIfNotCell(reg));
}
ALWAYS_INLINE int JIT::jumpTarget(const Instruction* instruction, int target)
{
if (target)
return target;
return m_codeBlock->outOfLineJumpOffset(instruction);
}
ALWAYS_INLINE GetPutInfo JIT::copiedGetPutInfo(OpPutToScope bytecode)
{
unsigned key = bytecode.m_metadataID + 1; // HashMap doesn't like 0 as a key
auto iterator = m_copiedGetPutInfos.find(key);
if (iterator != m_copiedGetPutInfos.end())
return GetPutInfo(iterator->value);
GetPutInfo getPutInfo = bytecode.metadata(m_codeBlock).m_getPutInfo;
m_copiedGetPutInfos.add(key, getPutInfo.operand());
return getPutInfo;
}
template<typename BinaryOp>
ALWAYS_INLINE BinaryArithProfile JIT::copiedArithProfile(BinaryOp bytecode)
{
uint64_t key = (static_cast<uint64_t>(BinaryOp::opcodeID) + 1) << 32 | static_cast<uint64_t>(bytecode.m_metadataID);
auto iterator = m_copiedArithProfiles.find(key);
if (iterator != m_copiedArithProfiles.end())
return iterator->value;
BinaryArithProfile arithProfile = bytecode.metadata(m_codeBlock).m_arithProfile;
m_copiedArithProfiles.add(key, arithProfile);
return arithProfile;
}
template<typename Op>
ALWAYS_INLINE ECMAMode JIT::ecmaMode(Op op)
{
return op.m_ecmaMode;
}
template<>
ALWAYS_INLINE ECMAMode JIT::ecmaMode<OpPutById>(OpPutById op)
{
return op.m_flags.ecmaMode();
}
template<>
ALWAYS_INLINE ECMAMode JIT::ecmaMode<OpPutPrivateName>(OpPutPrivateName)
{
return ECMAMode::strict();
}
} // namespace JSC
#endif // ENABLE(JIT)
|