barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | 97d3f45 | 2019-01-16 18:44:25 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2019 Apple Inc. All rights reserved. |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 27 | |
| 28 | #if ENABLE(JIT) |
oliver@apple.com | 0cc25c3 | 2010-10-19 23:55:08 +0000 | [diff] [blame] | 29 | #if USE(JSVALUE64) |
ggaren@apple.com | 7214b5a | 2010-05-21 20:52:30 +0000 | [diff] [blame] | 30 | #include "JIT.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 31 | |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 32 | #include "BytecodeOperandsForCheckpoint.h" |
| 33 | #include "CacheableIdentifierInlines.h" |
msaboff@apple.com | 4cd77e6 | 2015-09-18 23:51:41 +0000 | [diff] [blame] | 34 | #include "CallFrameShuffler.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 35 | #include "CodeBlock.h" |
mark.lam@apple.com | a4fe7ab | 2012-11-09 03:03:44 +0000 | [diff] [blame] | 36 | #include "JITInlines.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 37 | #include "JSArray.h" |
| 38 | #include "JSFunction.h" |
| 39 | #include "Interpreter.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 40 | #include "JSCInlines.h" |
benjamin@webkit.org | f766fd9 | 2014-07-08 04:23:30 +0000 | [diff] [blame] | 41 | #include "LinkBuffer.h" |
mark.lam@apple.com | 8a73712 | 2018-09-08 06:29:41 +0000 | [diff] [blame] | 42 | #include "OpcodeInlines.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 43 | #include "ResultType.h" |
fpizlo@apple.com | 74485fb | 2015-02-10 03:27:43 +0000 | [diff] [blame] | 44 | #include "SetupVarargsFrame.h" |
aperez@igalia.com | b1016a1 | 2020-04-21 07:48:52 +0000 | [diff] [blame] | 45 | #include "SlowPathCall.h" |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 46 | #include "StackAlignment.h" |
fpizlo@apple.com | 947ec62 | 2013-01-02 08:48:18 +0000 | [diff] [blame] | 47 | #include "ThunkGenerators.h" |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 48 | |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 49 | #include <wtf/StringPrintStream.h> |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 50 | |
| 51 | namespace JSC { |
| 52 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 53 | template<typename Op> |
| 54 | void JIT::emitPutCallResult(const Op& bytecode) |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 55 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 56 | emitValueProfilingSite(bytecode.metadata(m_codeBlock)); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 57 | emitPutVirtualRegister(destinationFor(bytecode, m_bytecodeIndex.checkpoint()).virtualRegister(), regT0); |
barraclough@apple.com | c73ede7 | 2010-05-20 20:12:44 +0000 | [diff] [blame] | 58 | } |
| 59 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 60 | template<typename Op> |
| 61 | std::enable_if_t< |
| 62 | Op::opcodeID != op_call_varargs && Op::opcodeID != op_construct_varargs |
| 63 | && Op::opcodeID != op_tail_call_varargs && Op::opcodeID != op_tail_call_forward_arguments |
| 64 | , void> |
| 65 | JIT::compileSetupFrame(const Op& bytecode, CallLinkInfo*) |
barraclough@apple.com | c73ede7 | 2010-05-20 20:12:44 +0000 | [diff] [blame] | 66 | { |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 67 | unsigned checkpoint = m_bytecodeIndex.checkpoint(); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 68 | auto& metadata = bytecode.metadata(m_codeBlock); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 69 | int argCountIncludingThis = argumentCountIncludingThisFor(bytecode, checkpoint); |
| 70 | int registerOffset = -static_cast<int>(stackOffsetInRegistersForCall(bytecode, checkpoint)); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 71 | |
| 72 | if (Op::opcodeID == op_call && shouldEmitProfiling()) { |
keith_miller@apple.com | a1c17ed | 2020-01-17 04:09:32 +0000 | [diff] [blame] | 73 | emitGetVirtualRegister(VirtualRegister(registerOffset + CallFrame::argumentOffsetIncludingThis(0)), regT0); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 74 | Jump done = branchIfNotCell(regT0); |
| 75 | load32(Address(regT0, JSCell::structureIDOffset()), regT0); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 76 | store32(regT0, arrayProfileFor(metadata, checkpoint).addressOfLastSeenStructureID()); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 77 | done.link(this); |
| 78 | } |
| 79 | |
| 80 | addPtr(TrustedImm32(registerOffset * sizeof(Register) + sizeof(CallerFrameAndPC)), callFrameRegister, stackPointerRegister); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 81 | store32(TrustedImm32(argCountIncludingThis), Address(stackPointerRegister, CallFrameSlot::argumentCountIncludingThis * static_cast<int>(sizeof(Register)) + PayloadOffset - sizeof(CallerFrameAndPC))); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
| 85 | template<typename Op> |
| 86 | std::enable_if_t< |
| 87 | Op::opcodeID == op_call_varargs || Op::opcodeID == op_construct_varargs |
| 88 | || Op::opcodeID == op_tail_call_varargs || Op::opcodeID == op_tail_call_forward_arguments |
| 89 | , void> |
| 90 | JIT::compileSetupFrame(const Op& bytecode, CallLinkInfo* info) |
| 91 | { |
keith_miller@apple.com | a1c17ed | 2020-01-17 04:09:32 +0000 | [diff] [blame] | 92 | VirtualRegister thisValue = bytecode.m_thisValue; |
| 93 | VirtualRegister arguments = bytecode.m_arguments; |
| 94 | int firstFreeRegister = bytecode.m_firstFree.offset(); // FIXME: Why is this a virtual register if we never use it as one... |
mark.lam@apple.com | 97d3f45 | 2019-01-16 18:44:25 +0000 | [diff] [blame] | 95 | int firstVarArgOffset = bytecode.m_firstVarArg; |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 96 | |
mark.lam@apple.com | 03944a0 | 2013-10-14 16:42:22 +0000 | [diff] [blame] | 97 | emitGetVirtualRegister(arguments, regT1); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 98 | Z_JITOperation_GJZZ sizeOperation; |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 99 | if (Op::opcodeID == op_tail_call_forward_arguments) |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 100 | sizeOperation = operationSizeFrameForForwardArguments; |
| 101 | else |
| 102 | sizeOperation = operationSizeFrameForVarargs; |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 103 | callOperation(sizeOperation, TrustedImmPtr(m_codeBlock->globalObject()), regT1, -firstFreeRegister, firstVarArgOffset); |
fpizlo@apple.com | bcfd39e | 2015-02-10 23:16:36 +0000 | [diff] [blame] | 104 | move(TrustedImm32(-firstFreeRegister), regT1); |
| 105 | emitSetVarargsFrame(*this, returnValueGPR, false, regT1, regT1); |
| 106 | addPtr(TrustedImm32(-(sizeof(CallerFrameAndPC) + WTF::roundUpToMultipleOf(stackAlignmentBytes(), 5 * sizeof(void*)))), regT1, stackPointerRegister); |
| 107 | emitGetVirtualRegister(arguments, regT2); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 108 | F_JITOperation_GFJZZ setupOperation; |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 109 | if (Op::opcodeID == op_tail_call_forward_arguments) |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 110 | setupOperation = operationSetupForwardArgumentsFrame; |
| 111 | else |
| 112 | setupOperation = operationSetupVarargsFrame; |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 113 | callOperation(setupOperation, TrustedImmPtr(m_codeBlock->globalObject()), regT1, regT2, firstVarArgOffset, regT0); |
mark.lam@apple.com | ab6b5eb | 2013-11-08 04:05:27 +0000 | [diff] [blame] | 114 | move(returnValueGPR, regT1); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 115 | |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 116 | // Profile the argument count. |
ysuzuki@apple.com | 88da11f | 2019-12-22 03:12:00 +0000 | [diff] [blame] | 117 | load32(Address(regT1, CallFrameSlot::argumentCountIncludingThis * static_cast<int>(sizeof(Register)) + PayloadOffset), regT2); |
ysuzuki@apple.com | d3c7bf2 | 2019-09-20 02:31:45 +0000 | [diff] [blame] | 118 | load32(info->addressOfMaxArgumentCountIncludingThis(), regT0); |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 119 | Jump notBiggest = branch32(Above, regT0, regT2); |
ysuzuki@apple.com | d3c7bf2 | 2019-09-20 02:31:45 +0000 | [diff] [blame] | 120 | store32(regT2, info->addressOfMaxArgumentCountIncludingThis()); |
fpizlo@apple.com | 8fefdd3 | 2015-02-18 19:55:47 +0000 | [diff] [blame] | 121 | notBiggest.link(this); |
| 122 | |
fpizlo@apple.com | 74485fb | 2015-02-10 03:27:43 +0000 | [diff] [blame] | 123 | // Initialize 'this'. |
| 124 | emitGetVirtualRegister(thisValue, regT0); |
| 125 | store64(regT0, Address(regT1, CallFrame::thisArgumentOffset() * static_cast<int>(sizeof(Register)))); |
| 126 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 127 | addPtr(TrustedImm32(sizeof(CallerFrameAndPC)), regT1, stackPointerRegister); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 128 | } |
| 129 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 130 | template<typename Op> |
| 131 | bool JIT::compileCallEval(const Op&) |
| 132 | { |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | template<> |
| 137 | bool JIT::compileCallEval(const OpCallEval& bytecode) |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 138 | { |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 139 | addPtr(TrustedImm32(-static_cast<ptrdiff_t>(sizeof(CallerFrameAndPC))), stackPointerRegister, regT1); |
msaboff@apple.com | 2906e8b | 2014-09-04 21:23:38 +0000 | [diff] [blame] | 140 | storePtr(callFrameRegister, Address(regT1, CallFrame::callerFrameOffset())); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 141 | |
| 142 | addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister); |
| 143 | checkStackPointerAlignment(); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 144 | |
tzagallo@apple.com | a6b8c34 | 2020-04-07 22:32:21 +0000 | [diff] [blame] | 145 | move(TrustedImm32(bytecode.m_ecmaMode.value()), regT2); |
| 146 | callOperation(operationCallEval, m_codeBlock->globalObject(), regT1, regT2); |
msaboff@apple.com | 2906e8b | 2014-09-04 21:23:38 +0000 | [diff] [blame] | 147 | |
utatane.tea@gmail.com | c940ae5 | 2018-05-17 16:18:24 +0000 | [diff] [blame] | 148 | addSlowCase(branchIfEmpty(regT0)); |
msaboff@apple.com | 2906e8b | 2014-09-04 21:23:38 +0000 | [diff] [blame] | 149 | |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 150 | sampleCodeBlock(m_codeBlock); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 151 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 152 | emitPutCallResult(bytecode); |
| 153 | |
| 154 | return true; |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 155 | } |
| 156 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 157 | void JIT::compileCallEvalSlowCase(const Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter) |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 158 | { |
utatane.tea@gmail.com | 96c8e18 | 2017-10-22 18:28:16 +0000 | [diff] [blame] | 159 | linkAllSlowCases(iter); |
| 160 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 161 | auto bytecode = instruction->as<OpCallEval>(); |
basile_clement@apple.com | 7d9a709 | 2015-07-28 20:12:33 +0000 | [diff] [blame] | 162 | CallLinkInfo* info = m_codeBlock->addCallLinkInfo(); |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 163 | info->setUpCall(CallLinkInfo::Call, CodeOrigin(m_bytecodeIndex), regT0); |
basile_clement@apple.com | 7d9a709 | 2015-07-28 20:12:33 +0000 | [diff] [blame] | 164 | |
mark.lam@apple.com | 97d3f45 | 2019-01-16 18:44:25 +0000 | [diff] [blame] | 165 | int registerOffset = -bytecode.m_argv; |
msaboff@apple.com | 2906e8b | 2014-09-04 21:23:38 +0000 | [diff] [blame] | 166 | |
| 167 | addPtr(TrustedImm32(registerOffset * sizeof(Register) + sizeof(CallerFrameAndPC)), callFrameRegister, stackPointerRegister); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 168 | |
mark.lam@apple.com | 2bd8934 | 2016-07-08 22:58:15 +0000 | [diff] [blame] | 169 | load64(Address(stackPointerRegister, sizeof(Register) * CallFrameSlot::callee - sizeof(CallerFrameAndPC)), regT0); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 170 | emitDumbVirtualCall(vm(), m_codeBlock->globalObject(), info); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 171 | addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister); |
| 172 | checkStackPointerAlignment(); |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 173 | |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 174 | sampleCodeBlock(m_codeBlock); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 175 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 176 | emitPutCallResult(bytecode); |
ggaren@apple.com | 2949660 | 2009-05-12 04:20:29 +0000 | [diff] [blame] | 177 | } |
| 178 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 179 | template<typename Op> |
| 180 | bool JIT::compileTailCall(const Op&, CallLinkInfo*, unsigned) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 181 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | |
| 185 | template<> |
| 186 | bool JIT::compileTailCall(const OpTailCall& bytecode, CallLinkInfo* info, unsigned callLinkInfoIndex) |
| 187 | { |
| 188 | CallFrameShuffleData shuffleData; |
mark.lam@apple.com | 97d3f45 | 2019-01-16 18:44:25 +0000 | [diff] [blame] | 189 | shuffleData.numPassedArgs = bytecode.m_argc; |
mark.lam@apple.com | 9ed9150 | 2019-09-19 16:14:47 +0000 | [diff] [blame] | 190 | shuffleData.numberTagRegister = GPRInfo::numberTagRegister; |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 191 | shuffleData.numLocals = |
mark.lam@apple.com | 97d3f45 | 2019-01-16 18:44:25 +0000 | [diff] [blame] | 192 | bytecode.m_argv - sizeof(CallerFrameAndPC) / sizeof(Register); |
| 193 | shuffleData.args.resize(bytecode.m_argc); |
| 194 | for (unsigned i = 0; i < bytecode.m_argc; ++i) { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 195 | shuffleData.args[i] = |
| 196 | ValueRecovery::displacedInJSStack( |
keith_miller@apple.com | a1c17ed | 2020-01-17 04:09:32 +0000 | [diff] [blame] | 197 | virtualRegisterForArgumentIncludingThis(i) - bytecode.m_argv, |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 198 | DataFormatJS); |
| 199 | } |
| 200 | shuffleData.callee = |
| 201 | ValueRecovery::inGPR(regT0, DataFormatJS); |
| 202 | shuffleData.setupCalleeSaveRegisters(m_codeBlock); |
| 203 | info->setFrameShuffleData(shuffleData); |
| 204 | CallFrameShuffler(*this, shuffleData).prepareForTailCall(); |
| 205 | m_callCompilationInfo[callLinkInfoIndex].hotPathOther = emitNakedTailCall(); |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | template<typename Op> |
| 210 | void JIT::compileOpCall(const Instruction* instruction, unsigned callLinkInfoIndex) |
| 211 | { |
| 212 | OpcodeID opcodeID = Op::opcodeID; |
| 213 | auto bytecode = instruction->as<Op>(); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 214 | VirtualRegister callee = calleeFor(bytecode, m_bytecodeIndex.checkpoint()); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 215 | |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 216 | /* Caller always: |
| 217 | - Updates callFrameRegister to callee callFrame. |
| 218 | - Initializes ArgumentCount; CallerFrame; Callee. |
| 219 | |
| 220 | For a JS call: |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 221 | - Callee initializes ReturnPC; CodeBlock. |
| 222 | - Callee restores callFrameRegister before return. |
| 223 | |
| 224 | For a non-JS call: |
msaboff@apple.com | 217b2c7 | 2015-01-21 21:43:55 +0000 | [diff] [blame] | 225 | - Caller initializes ReturnPC; CodeBlock. |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 226 | - Caller restores callFrameRegister after return. |
| 227 | */ |
pvollan@apple.com | 415da95 | 2016-09-08 09:09:59 +0000 | [diff] [blame] | 228 | CallLinkInfo* info = nullptr; |
basile_clement@apple.com | 7d9a709 | 2015-07-28 20:12:33 +0000 | [diff] [blame] | 229 | if (opcodeID != op_call_eval) |
| 230 | info = m_codeBlock->addCallLinkInfo(); |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 231 | compileSetupFrame(bytecode, info); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 232 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 233 | // SP holds newCallFrame + sizeof(CallerFrameAndPC), with ArgumentCount initialized. |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 234 | auto bytecodeIndex = m_codeBlock->bytecodeIndex(instruction); |
| 235 | uint32_t locationBits = CallSiteIndex(bytecodeIndex).bits(); |
ysuzuki@apple.com | 88da11f | 2019-12-22 03:12:00 +0000 | [diff] [blame] | 236 | store32(TrustedImm32(locationBits), Address(callFrameRegister, CallFrameSlot::argumentCountIncludingThis * static_cast<int>(sizeof(Register)) + TagOffset)); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 237 | |
commit-queue@webkit.org | 2cb9c25 | 2016-12-13 19:38:13 +0000 | [diff] [blame] | 238 | emitGetVirtualRegister(callee, regT0); // regT0 holds callee. |
| 239 | store64(regT0, Address(stackPointerRegister, CallFrameSlot::callee * static_cast<int>(sizeof(Register)) - sizeof(CallerFrameAndPC))); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 240 | |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 241 | if (compileCallEval(bytecode)) |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 242 | return; |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 243 | |
barraclough@apple.com | 289318a | 2008-12-22 01:00:07 +0000 | [diff] [blame] | 244 | DataLabelPtr addressOfLinkedFunctionCheck; |
keith_miller@apple.com | 308f2ba | 2018-02-28 05:41:18 +0000 | [diff] [blame] | 245 | Jump slowCase = branchPtrWithPatch(NotEqual, regT0, addressOfLinkedFunctionCheck, TrustedImmPtr(nullptr)); |
ggaren@apple.com | 539d1bb | 2011-11-14 19:21:40 +0000 | [diff] [blame] | 246 | addSlowCase(slowCase); |
barraclough@apple.com | 970af2c | 2009-08-13 05:58:36 +0000 | [diff] [blame] | 247 | |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 248 | ASSERT(m_callCompilationInfo.size() == callLinkInfoIndex); |
keith_miller@apple.com | 0f985ec | 2019-10-23 00:55:38 +0000 | [diff] [blame] | 249 | info->setUpCall(CallLinkInfo::callTypeFor(opcodeID), CodeOrigin(m_bytecodeIndex), regT0); |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 250 | m_callCompilationInfo.append(CallCompilationInfo()); |
| 251 | m_callCompilationInfo[callLinkInfoIndex].hotPathBegin = addressOfLinkedFunctionCheck; |
| 252 | m_callCompilationInfo[callLinkInfoIndex].callLinkInfo = info; |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 253 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 254 | if (compileTailCall(bytecode, info, callLinkInfoIndex)) { |
msaboff@apple.com | 4cd77e6 | 2015-09-18 23:51:41 +0000 | [diff] [blame] | 255 | return; |
| 256 | } |
| 257 | |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 258 | if (opcodeID == op_tail_call_varargs || opcodeID == op_tail_call_forward_arguments) { |
msaboff@apple.com | 4cd77e6 | 2015-09-18 23:51:41 +0000 | [diff] [blame] | 259 | emitRestoreCalleeSaves(); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 260 | prepareForTailCallSlow(); |
| 261 | m_callCompilationInfo[callLinkInfoIndex].hotPathOther = emitNakedTailCall(); |
| 262 | return; |
| 263 | } |
| 264 | |
fpizlo@apple.com | ba262b2 | 2014-03-23 04:34:38 +0000 | [diff] [blame] | 265 | m_callCompilationInfo[callLinkInfoIndex].hotPathOther = emitNakedCall(); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 266 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 267 | addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister); |
| 268 | checkStackPointerAlignment(); |
| 269 | |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 270 | sampleCodeBlock(m_codeBlock); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 271 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 272 | emitPutCallResult(bytecode); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 273 | } |
| 274 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 275 | template<typename Op> |
| 276 | void JIT::compileOpCallSlowCase(const Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter, unsigned callLinkInfoIndex) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 277 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 278 | OpcodeID opcodeID = Op::opcodeID; |
| 279 | ASSERT(opcodeID != op_call_eval); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 280 | |
utatane.tea@gmail.com | 96c8e18 | 2017-10-22 18:28:16 +0000 | [diff] [blame] | 281 | linkAllSlowCases(iter); |
msaboff@apple.com | 2b95ada | 2013-10-09 13:29:00 +0000 | [diff] [blame] | 282 | |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 283 | if (opcodeID == op_tail_call || opcodeID == op_tail_call_varargs || opcodeID == op_tail_call_forward_arguments) |
msaboff@apple.com | 4cd77e6 | 2015-09-18 23:51:41 +0000 | [diff] [blame] | 284 | emitRestoreCalleeSaves(); |
| 285 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 286 | move(TrustedImmPtr(m_codeBlock->globalObject()), regT3); |
commit-queue@webkit.org | 2cb9c25 | 2016-12-13 19:38:13 +0000 | [diff] [blame] | 287 | move(TrustedImmPtr(m_callCompilationInfo[callLinkInfoIndex].callLinkInfo), regT2); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 288 | |
mark.lam@apple.com | bbf313e | 2018-04-05 04:30:17 +0000 | [diff] [blame] | 289 | m_callCompilationInfo[callLinkInfoIndex].callReturnLocation = |
mark.lam@apple.com | de0dba7 | 2018-04-18 03:31:09 +0000 | [diff] [blame] | 290 | emitNakedCall(m_vm->getCTIStub(linkCallThunkGenerator).retaggedCode<NoPtrTag>()); |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 291 | |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 292 | if (opcodeID == op_tail_call || opcodeID == op_tail_call_varargs) { |
| 293 | abortWithReason(JITDidReturnFromTailCall); |
| 294 | return; |
| 295 | } |
| 296 | |
msaboff@apple.com | 9589433 | 2014-01-29 19:18:54 +0000 | [diff] [blame] | 297 | addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister); |
| 298 | checkStackPointerAlignment(); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 299 | |
barraclough@apple.com | 24a7abb | 2009-01-16 23:34:46 +0000 | [diff] [blame] | 300 | sampleCodeBlock(m_codeBlock); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 301 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 302 | auto bytecode = instruction->as<Op>(); |
| 303 | emitPutCallResult(bytecode); |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 304 | } |
| 305 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 306 | void JIT::emit_op_call(const Instruction* currentInstruction) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 307 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 308 | compileOpCall<OpCall>(currentInstruction, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 309 | } |
| 310 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 311 | void JIT::emit_op_tail_call(const Instruction* currentInstruction) |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 312 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 313 | compileOpCall<OpTailCall>(currentInstruction, m_callLinkInfoIndex++); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 314 | } |
| 315 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 316 | void JIT::emit_op_call_eval(const Instruction* currentInstruction) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 317 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 318 | compileOpCall<OpCallEval>(currentInstruction, m_callLinkInfoIndex); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 319 | } |
| 320 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 321 | void JIT::emit_op_call_varargs(const Instruction* currentInstruction) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 322 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 323 | compileOpCall<OpCallVarargs>(currentInstruction, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 324 | } |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 325 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 326 | void JIT::emit_op_tail_call_varargs(const Instruction* currentInstruction) |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 327 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 328 | compileOpCall<OpTailCallVarargs>(currentInstruction, m_callLinkInfoIndex++); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 329 | } |
| 330 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 331 | void JIT::emit_op_tail_call_forward_arguments(const Instruction* currentInstruction) |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 332 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 333 | compileOpCall<OpTailCallForwardArguments>(currentInstruction, m_callLinkInfoIndex++); |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 334 | } |
| 335 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 336 | void JIT::emit_op_construct_varargs(const Instruction* currentInstruction) |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 337 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 338 | compileOpCall<OpConstructVarargs>(currentInstruction, m_callLinkInfoIndex++); |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 339 | } |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 340 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 341 | void JIT::emit_op_construct(const Instruction* currentInstruction) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 342 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 343 | compileOpCall<OpConstruct>(currentInstruction, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 344 | } |
| 345 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 346 | void JIT::emitSlow_op_call(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 347 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 348 | compileOpCallSlowCase<OpCall>(currentInstruction, iter, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 349 | } |
| 350 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 351 | void JIT::emitSlow_op_tail_call(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 352 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 353 | compileOpCallSlowCase<OpTailCall>(currentInstruction, iter, m_callLinkInfoIndex++); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 354 | } |
| 355 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 356 | void JIT::emitSlow_op_call_eval(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 357 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 358 | compileCallEvalSlowCase(currentInstruction, iter); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 359 | } |
| 360 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 361 | void JIT::emitSlow_op_call_varargs(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 362 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 363 | compileOpCallSlowCase<OpCallVarargs>(currentInstruction, iter, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 364 | } |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 365 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 366 | void JIT::emitSlow_op_tail_call_varargs(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 367 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 368 | compileOpCallSlowCase<OpTailCallVarargs>(currentInstruction, iter, m_callLinkInfoIndex++); |
msaboff@apple.com | c15ae7e | 2015-09-16 23:40:35 +0000 | [diff] [blame] | 369 | } |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 370 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 371 | void JIT::emitSlow_op_tail_call_forward_arguments(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 372 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 373 | compileOpCallSlowCase<OpTailCallForwardArguments>(currentInstruction, iter, m_callLinkInfoIndex++); |
keith_miller@apple.com | e497e20 | 2016-06-13 21:05:36 +0000 | [diff] [blame] | 374 | } |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 375 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 376 | void JIT::emitSlow_op_construct_varargs(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 377 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 378 | compileOpCallSlowCase<OpConstructVarargs>(currentInstruction, iter, m_callLinkInfoIndex++); |
oliver@apple.com | 177c2b9 | 2014-03-28 01:10:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 381 | void JIT::emitSlow_op_construct(const Instruction* currentInstruction, Vector<SlowCaseEntry>::iterator& iter) |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 382 | { |
tzagallo@apple.com | 3474dd0 | 2018-10-29 13:16:03 +0000 | [diff] [blame] | 383 | compileOpCallSlowCase<OpConstruct>(currentInstruction, iter, m_callLinkInfoIndex++); |
oliver@apple.com | cf0e6c4 | 2013-07-25 04:01:45 +0000 | [diff] [blame] | 384 | } |
| 385 | |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 386 | void JIT::emit_op_iterator_open(const Instruction* instruction) |
| 387 | { |
| 388 | auto bytecode = instruction->as<OpIteratorOpen>(); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 389 | auto* tryFastFunction = ([&] () { |
| 390 | switch (instruction->width()) { |
| 391 | case Narrow: return iterator_open_try_fast_narrow; |
| 392 | case Wide16: return iterator_open_try_fast_wide16; |
| 393 | case Wide32: return iterator_open_try_fast_wide32; |
| 394 | default: RELEASE_ASSERT_NOT_REACHED(); |
| 395 | } |
| 396 | })(); |
ysuzuki@apple.com | db92164 | 2020-04-20 01:56:24 +0000 | [diff] [blame] | 397 | |
| 398 | JITSlowPathCall slowPathCall(this, instruction, tryFastFunction); |
| 399 | slowPathCall.call(); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 400 | Jump fastCase = branch32(NotEqual, GPRInfo::returnValueGPR2, TrustedImm32(static_cast<uint32_t>(IterationMode::Generic))); |
| 401 | |
| 402 | compileOpCall<OpIteratorOpen>(instruction, m_callLinkInfoIndex++); |
| 403 | advanceToNextCheckpoint(); |
| 404 | // call result (iterator) is in regT0 |
| 405 | |
| 406 | const Identifier* ident = &vm().propertyNames->next; |
| 407 | |
| 408 | emitJumpSlowCaseIfNotJSCell(regT0); |
| 409 | |
| 410 | JITGetByIdGenerator gen( |
| 411 | m_codeBlock, CodeOrigin(m_bytecodeIndex), CallSiteIndex(BytecodeIndex(m_bytecodeIndex.offset())), RegisterSet::stubUnavailableRegisters(), |
| 412 | CacheableIdentifier::createFromImmortalIdentifier(ident->impl()), JSValueRegs(regT0), JSValueRegs(regT0), AccessType::GetById); |
| 413 | gen.generateFastPath(*this); |
| 414 | addSlowCase(gen.slowPathJump()); |
| 415 | m_getByIds.append(gen); |
| 416 | |
| 417 | emitValueProfilingSite(bytecode.metadata(m_codeBlock)); |
| 418 | emitPutVirtualRegister(bytecode.m_next); |
| 419 | |
| 420 | fastCase.link(this); |
| 421 | } |
| 422 | |
| 423 | void JIT::emitSlow_op_iterator_open(const Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter) |
| 424 | { |
| 425 | linkAllSlowCases(iter); |
| 426 | compileOpCallSlowCase<OpIteratorOpen>(instruction, iter, m_callLinkInfoIndex++); |
| 427 | emitJumpSlowToHotForCheckpoint(jump()); |
| 428 | |
| 429 | |
| 430 | linkAllSlowCases(iter); |
keith_miller@apple.com | a9043a6 | 2020-04-23 18:56:51 +0000 | [diff] [blame] | 431 | |
| 432 | GPRReg iteratorGPR = regT0; |
| 433 | JumpList notObject; |
| 434 | notObject.append(branchIfNotCell(iteratorGPR)); |
| 435 | notObject.append(branchIfNotObject(iteratorGPR)); |
| 436 | |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 437 | auto bytecode = instruction->as<OpIteratorOpen>(); |
| 438 | VirtualRegister nextVReg = bytecode.m_next; |
| 439 | UniquedStringImpl* ident = vm().propertyNames->next.impl(); |
| 440 | |
| 441 | JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++]; |
| 442 | |
| 443 | Label coldPathBegin = label(); |
| 444 | |
keith_miller@apple.com | a9043a6 | 2020-04-23 18:56:51 +0000 | [diff] [blame] | 445 | Call call = callOperationWithProfile(bytecode.metadata(m_codeBlock), operationGetByIdOptimize, nextVReg, TrustedImmPtr(m_codeBlock->globalObject()), gen.stubInfo(), iteratorGPR, CacheableIdentifier::createFromImmortalIdentifier(ident).rawBits()); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 446 | gen.reportSlowPathCall(coldPathBegin, call); |
keith_miller@apple.com | a9043a6 | 2020-04-23 18:56:51 +0000 | [diff] [blame] | 447 | auto done = jump(); |
| 448 | |
| 449 | notObject.link(this); |
| 450 | callOperation(operationThrowIteratorResultIsNotObject, TrustedImmPtr(m_codeBlock->globalObject())); |
| 451 | |
| 452 | done.link(this); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void JIT::emit_op_iterator_next(const Instruction* instruction) |
| 456 | { |
| 457 | auto bytecode = instruction->as<OpIteratorNext>(); |
| 458 | auto& metadata = bytecode.metadata(m_codeBlock); |
| 459 | auto* tryFastFunction = ([&] () { |
| 460 | switch (instruction->width()) { |
| 461 | case Narrow: return iterator_next_try_fast_narrow; |
| 462 | case Wide16: return iterator_next_try_fast_wide16; |
| 463 | case Wide32: return iterator_next_try_fast_wide32; |
| 464 | default: RELEASE_ASSERT_NOT_REACHED(); |
| 465 | } |
| 466 | })(); |
| 467 | |
| 468 | emitGetVirtualRegister(bytecode.m_next, regT0); |
| 469 | Jump genericCase = branchIfNotEmpty(regT0); |
ysuzuki@apple.com | db92164 | 2020-04-20 01:56:24 +0000 | [diff] [blame] | 470 | |
| 471 | JITSlowPathCall slowPathCall(this, instruction, tryFastFunction); |
| 472 | slowPathCall.call(); |
keith_miller@apple.com | d06760d | 2020-04-18 21:45:34 +0000 | [diff] [blame] | 473 | Jump fastCase = branch32(NotEqual, GPRInfo::returnValueGPR2, TrustedImm32(static_cast<uint32_t>(IterationMode::Generic))); |
| 474 | |
| 475 | genericCase.link(this); |
| 476 | or8(TrustedImm32(static_cast<uint8_t>(IterationMode::Generic)), AbsoluteAddress(&metadata.m_iterationMetadata.seenModes)); |
| 477 | compileOpCall<OpIteratorNext>(instruction, m_callLinkInfoIndex++); |
| 478 | advanceToNextCheckpoint(); |
| 479 | // call result ({ done, value } JSObject) in regT0 |
| 480 | |
| 481 | GPRReg valueGPR = regT0; |
| 482 | GPRReg iterResultGPR = regT2; |
| 483 | GPRReg doneGPR = regT1; |
| 484 | // iterResultGPR will get trashed by the first get by id below. |
| 485 | move(valueGPR, iterResultGPR); |
| 486 | |
| 487 | { |
| 488 | emitJumpSlowCaseIfNotJSCell(iterResultGPR); |
| 489 | |
| 490 | RegisterSet preservedRegs = RegisterSet::stubUnavailableRegisters(); |
| 491 | preservedRegs.add(valueGPR); |
| 492 | JITGetByIdGenerator gen( |
| 493 | m_codeBlock, CodeOrigin(m_bytecodeIndex), CallSiteIndex(BytecodeIndex(m_bytecodeIndex.offset())), preservedRegs, |
| 494 | CacheableIdentifier::createFromImmortalIdentifier(vm().propertyNames->next.impl()), JSValueRegs(iterResultGPR), JSValueRegs(doneGPR), AccessType::GetById); |
| 495 | gen.generateFastPath(*this); |
| 496 | addSlowCase(gen.slowPathJump()); |
| 497 | m_getByIds.append(gen); |
| 498 | |
| 499 | emitValueProfilingSite(metadata); |
| 500 | emitPutVirtualRegister(bytecode.m_done, doneGPR); |
| 501 | advanceToNextCheckpoint(); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | { |
| 506 | GPRReg scratch1 = regT2; |
| 507 | GPRReg scratch2 = regT3; |
| 508 | const bool shouldCheckMasqueradesAsUndefined = false; |
| 509 | JumpList iterationDone = branchIfTruthy(vm(), JSValueRegs(doneGPR), scratch1, scratch2, fpRegT0, fpRegT1, shouldCheckMasqueradesAsUndefined, m_codeBlock->globalObject()); |
| 510 | |
| 511 | JITGetByIdGenerator gen( |
| 512 | m_codeBlock, CodeOrigin(m_bytecodeIndex), CallSiteIndex(BytecodeIndex(m_bytecodeIndex.offset())), RegisterSet::stubUnavailableRegisters(), |
| 513 | CacheableIdentifier::createFromImmortalIdentifier(vm().propertyNames->value.impl()), JSValueRegs(valueGPR), JSValueRegs(valueGPR), AccessType::GetById); |
| 514 | gen.generateFastPath(*this); |
| 515 | addSlowCase(gen.slowPathJump()); |
| 516 | m_getByIds.append(gen); |
| 517 | |
| 518 | emitValueProfilingSite(metadata); |
| 519 | emitPutVirtualRegister(bytecode.m_value, valueGPR); |
| 520 | |
| 521 | iterationDone.link(this); |
| 522 | } |
| 523 | |
| 524 | fastCase.link(this); |
| 525 | } |
| 526 | |
| 527 | void JIT::emitSlow_op_iterator_next(const Instruction* instruction, Vector<SlowCaseEntry>::iterator& iter) |
| 528 | { |
| 529 | linkAllSlowCases(iter); |
| 530 | compileOpCallSlowCase<OpIteratorNext>(instruction, iter, m_callLinkInfoIndex++); |
| 531 | emitJumpSlowToHotForCheckpoint(jump()); |
| 532 | |
| 533 | auto bytecode = instruction->as<OpIteratorNext>(); |
| 534 | { |
| 535 | VirtualRegister doneVReg = bytecode.m_done; |
| 536 | GPRReg iterResultGPR = regT2; |
| 537 | |
| 538 | linkAllSlowCases(iter); |
| 539 | JumpList notObject; |
| 540 | notObject.append(branchIfNotCell(iterResultGPR)); |
| 541 | notObject.append(branchIfNotObject(iterResultGPR)); |
| 542 | |
| 543 | UniquedStringImpl* ident = vm().propertyNames->done.impl(); |
| 544 | JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++]; |
| 545 | |
| 546 | Label coldPathBegin = label(); |
| 547 | |
| 548 | Call call = callOperationWithProfile(bytecode.metadata(m_codeBlock), operationGetByIdOptimize, doneVReg, TrustedImmPtr(m_codeBlock->globalObject()), gen.stubInfo(), iterResultGPR, CacheableIdentifier::createFromImmortalIdentifier(ident).rawBits()); |
| 549 | |
| 550 | gen.reportSlowPathCall(coldPathBegin, call); |
| 551 | emitGetVirtualRegister(doneVReg, regT1); |
| 552 | emitGetVirtualRegister(bytecode.m_value, regT0); |
| 553 | emitJumpSlowToHotForCheckpoint(jump()); |
| 554 | |
| 555 | notObject.link(this); |
| 556 | callOperation(operationThrowIteratorResultIsNotObject, TrustedImmPtr(m_codeBlock->globalObject())); |
| 557 | } |
| 558 | |
| 559 | { |
| 560 | linkAllSlowCases(iter); |
| 561 | VirtualRegister valueVReg = bytecode.m_value; |
| 562 | GPRReg iterResultGPR = regT0; |
| 563 | |
| 564 | UniquedStringImpl* ident = vm().propertyNames->value.impl(); |
| 565 | JITGetByIdGenerator& gen = m_getByIds[m_getByIdIndex++]; |
| 566 | |
| 567 | Label coldPathBegin = label(); |
| 568 | |
| 569 | Call call = callOperationWithProfile(bytecode.metadata(m_codeBlock), operationGetByIdOptimize, valueVReg, TrustedImmPtr(m_codeBlock->globalObject()), gen.stubInfo(), iterResultGPR, CacheableIdentifier::createFromImmortalIdentifier(ident).rawBits()); |
| 570 | |
| 571 | gen.reportSlowPathCall(coldPathBegin, call); |
| 572 | } |
| 573 | |
| 574 | } |
| 575 | |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 576 | } // namespace JSC |
| 577 | |
oliver@apple.com | 0cc25c3 | 2010-10-19 23:55:08 +0000 | [diff] [blame] | 578 | #endif // USE(JSVALUE64) |
barraclough@apple.com | e367b00 | 2008-12-04 05:43:14 +0000 | [diff] [blame] | 579 | #endif // ENABLE(JIT) |