- if (numberOfDisplacedVirtualRegisters) {
- if (numberOfDisplacedVirtualRegisters <= GPRInfo::numberOfRegisters) {
- // So far this appears to be the case that triggers all the time, but
- // that is far from guaranteed.
-
- unsigned displacementIndex = 0;
- for (int index = 0; index < exit.numberOfRecoveries(); ++index) {
- const ValueRecovery& recovery = exit.valueRecovery(index);
- switch (recovery.technique()) {
- case DisplacedInRegisterFile:
- m_jit.loadPtr(AssemblyHelpers::addressFor(recovery.virtualRegister()), GPRInfo::toRegister(displacementIndex++));
- break;
-
- case Int32DisplacedInRegisterFile: {
- GPRReg gpr = GPRInfo::toRegister(displacementIndex++);
- m_jit.load32(AssemblyHelpers::addressFor(recovery.virtualRegister()), gpr);
- m_jit.orPtr(GPRInfo::tagTypeNumberRegister, gpr);
- break;
- }
-
- case DoubleDisplacedInRegisterFile: {
- GPRReg gpr = GPRInfo::toRegister(displacementIndex++);
- m_jit.loadPtr(AssemblyHelpers::addressFor(recovery.virtualRegister()), gpr);
- m_jit.subPtr(GPRInfo::tagTypeNumberRegister, gpr);
- break;
- }
-
- default:
- break;
- }
- }
-
- displacementIndex = 0;
- for (int index = 0; index < exit.numberOfRecoveries(); ++index) {
- const ValueRecovery& recovery = exit.valueRecovery(index);
- switch (recovery.technique()) {
- case DisplacedInRegisterFile:
- case Int32DisplacedInRegisterFile:
- case DoubleDisplacedInRegisterFile:
- m_jit.storePtr(GPRInfo::toRegister(displacementIndex++), AssemblyHelpers::addressFor((VirtualRegister)exit.operandForIndex(index)));
- break;
-
- default:
- break;
- }
- }
- } else {
- // FIXME: This should use the shuffling algorithm that we use
- // for speculative->non-speculative jumps, if we ever discover that
- // some hot code with lots of live values that get displaced and
- // spilled really enjoys frequently failing speculation.
-
- // For now this code is engineered to be correct but probably not
- // super. In particular, it correctly handles cases where for example
- // the displacements are a permutation of the destination values, like
- //
- // 1 -> 2
- // 2 -> 1
- //
- // It accomplishes this by simply lifting all of the virtual registers
- // from their old (DFG JIT) locations and dropping them in a scratch
- // location in memory, and then transferring from that scratch location
- // to their new (old JIT) locations.
-
- unsigned scratchIndex = numberOfPoisonedVirtualRegisters;
- for (int index = 0; index < exit.numberOfRecoveries(); ++index) {
- const ValueRecovery& recovery = exit.valueRecovery(index);
-
- switch (recovery.technique()) {
- case DisplacedInRegisterFile:
- m_jit.loadPtr(AssemblyHelpers::addressFor(recovery.virtualRegister()), GPRInfo::regT0);
- m_jit.storePtr(GPRInfo::regT0, scratchDataBuffer + scratchIndex++);
- break;
-
- case Int32DisplacedInRegisterFile: {
- m_jit.load32(AssemblyHelpers::addressFor(recovery.virtualRegister()), GPRInfo::regT0);
- m_jit.orPtr(GPRInfo::tagTypeNumberRegister, GPRInfo::regT0);
- m_jit.storePtr(GPRInfo::regT0, scratchDataBuffer + scratchIndex++);
- break;
- }
-
- case DoubleDisplacedInRegisterFile: {
- m_jit.loadPtr(AssemblyHelpers::addressFor(recovery.virtualRegister()), GPRInfo::regT0);
- m_jit.subPtr(GPRInfo::tagTypeNumberRegister, GPRInfo::regT0);
- m_jit.storePtr(GPRInfo::regT0, scratchDataBuffer + scratchIndex++);
- break;
- }
-
- default:
- break;
- }
- }
-
- scratchIndex = numberOfPoisonedVirtualRegisters;
- for (int index = 0; index < exit.numberOfRecoveries(); ++index) {
- const ValueRecovery& recovery = exit.valueRecovery(index);
- switch (recovery.technique()) {
- case DisplacedInRegisterFile:
- case Int32DisplacedInRegisterFile:
- case DoubleDisplacedInRegisterFile:
- m_jit.loadPtr(scratchDataBuffer + scratchIndex++, GPRInfo::regT0);
- m_jit.storePtr(GPRInfo::regT0, AssemblyHelpers::addressFor((VirtualRegister)exit.operandForIndex(index)));
- break;
-
- default:
- break;
- }
- }