blob: f86549510e5f7fdd4971fb03d79d21ed99cff2fb [file] [log] [blame]
fpizlo@apple.com1bc68482012-10-13 03:56:09 +00001/*
mark.lam@apple.com001f25c2017-05-20 00:59:31 +00002 * Copyright (C) 2012-2017 Apple Inc. All rights reserved.
fpizlo@apple.com1bc68482012-10-13 03:56:09 +00003 *
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
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000027
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000028#if ENABLE(DFG_JIT)
29
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000030#include "DFGSlowPathGenerator.h"
fpizlo@apple.com0bef2a12014-02-10 19:26:29 +000031#include "DFGSpeculativeJIT.h"
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000032#include <wtf/Vector.h>
33
34namespace JSC { namespace DFG {
35
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +000036class CallArrayAllocatorSlowPathGenerator final : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000037public:
38 CallArrayAllocatorSlowPathGenerator(
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000039 MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_VmStZB function,
sbarati@apple.com239d20b2017-01-26 23:50:58 +000040 GPRReg resultGPR, GPRReg storageGPR, RegisteredStructure structure, size_t size)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000041 : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit)
42 , m_function(function)
43 , m_resultGPR(resultGPR)
44 , m_storageGPR(storageGPR)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000045 , m_size(size)
rmorisset@apple.com4ccbcf12019-03-12 19:07:04 +000046 , m_structure(structure)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000047 {
48 ASSERT(size < static_cast<size_t>(std::numeric_limits<int32_t>::max()));
49 jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR);
50 }
51
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +000052private:
53 void generateInternal(SpeculativeJIT* jit) final
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000054 {
55 linkFrom(jit);
56 for (unsigned i = 0; i < m_plans.size(); ++i)
57 jit->silentSpill(m_plans[i]);
ysuzuki@apple.com5aa58842022-04-06 00:54:05 +000058 jit->callOperation(m_function, m_resultGPR, SpeculativeJIT::TrustedImmPtr(&jit->vm()), m_structure, m_size, m_storageGPR);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +000059 for (unsigned i = m_plans.size(); i--;)
mark.lam@apple.com001f25c2017-05-20 00:59:31 +000060 jit->silentFill(m_plans[i]);
saambarati1@gmail.comaa599f62015-08-21 19:11:36 +000061 jit->m_jit.exceptionCheck();
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000062 jit->m_jit.loadPtr(MacroAssembler::Address(m_resultGPR, JSObject::butterflyOffset()), m_storageGPR);
63 jumpTo(jit);
64 }
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +000065
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000066 P_JITOperation_VmStZB m_function;
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000067 GPRReg m_resultGPR;
68 GPRReg m_storageGPR;
keith_miller@apple.com6c2ac2e2018-03-08 02:26:55 +000069 int m_size;
rmorisset@apple.com4ccbcf12019-03-12 19:07:04 +000070 RegisteredStructure m_structure;
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000071 Vector<SilentRegisterSavePlan, 2> m_plans;
72};
73
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +000074class CallArrayAllocatorWithVariableSizeSlowPathGenerator final : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000075public:
76 CallArrayAllocatorWithVariableSizeSlowPathGenerator(
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000077 MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_GStZB function,
ysuzuki@apple.com6866de172022-04-19 08:06:44 +000078 GPRReg resultGPR, JITCompiler::LinkableConstant globalObject, RegisteredStructure contiguousStructure, RegisteredStructure arrayStorageStructure, GPRReg sizeGPR, GPRReg storageGPR)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000079 : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit)
80 , m_function(function)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000081 , m_contiguousStructure(contiguousStructure)
sbarati@apple.com6cfefd82016-08-13 02:14:42 +000082 , m_arrayStorageOrContiguousStructure(arrayStorageStructure)
rmorisset@apple.com4ccbcf12019-03-12 19:07:04 +000083 , m_resultGPR(resultGPR)
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000084 , m_globalObject(globalObject)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000085 , m_sizeGPR(sizeGPR)
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +000086 , m_storageGPR(storageGPR)
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000087 {
88 jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR);
89 }
90
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +000091private:
92 void generateInternal(SpeculativeJIT* jit) final
fpizlo@apple.com1bc68482012-10-13 03:56:09 +000093 {
94 linkFrom(jit);
95 for (unsigned i = 0; i < m_plans.size(); ++i)
96 jit->silentSpill(m_plans[i]);
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +000097 GPRReg scratchGPR = AssemblyHelpers::selectScratchGPR(m_sizeGPR, m_storageGPR);
sbarati@apple.com239d20b2017-01-26 23:50:58 +000098 if (m_contiguousStructure.get() != m_arrayStorageOrContiguousStructure.get()) {
sbarati@apple.com6cfefd82016-08-13 02:14:42 +000099 MacroAssembler::Jump bigLength = jit->m_jit.branch32(MacroAssembler::AboveOrEqual, m_sizeGPR, MacroAssembler::TrustedImm32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH));
sbarati@apple.com239d20b2017-01-26 23:50:58 +0000100 jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_contiguousStructure), scratchGPR);
sbarati@apple.com6cfefd82016-08-13 02:14:42 +0000101 MacroAssembler::Jump done = jit->m_jit.jump();
102 bigLength.link(&jit->m_jit);
sbarati@apple.com239d20b2017-01-26 23:50:58 +0000103 jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_arrayStorageOrContiguousStructure), scratchGPR);
sbarati@apple.com6cfefd82016-08-13 02:14:42 +0000104 done.link(&jit->m_jit);
105 } else
sbarati@apple.com239d20b2017-01-26 23:50:58 +0000106 jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_contiguousStructure), scratchGPR);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000107 jit->callOperation(m_function, m_resultGPR, m_globalObject, scratchGPR, m_sizeGPR, m_storageGPR);
fpizlo@apple.com75c91a72012-11-08 22:28:25 +0000108 for (unsigned i = m_plans.size(); i--;)
mark.lam@apple.com001f25c2017-05-20 00:59:31 +0000109 jit->silentFill(m_plans[i]);
saambarati1@gmail.comaa599f62015-08-21 19:11:36 +0000110 jit->m_jit.exceptionCheck();
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000111 jumpTo(jit);
112 }
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +0000113
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000114 P_JITOperation_GStZB m_function;
sbarati@apple.com239d20b2017-01-26 23:50:58 +0000115 RegisteredStructure m_contiguousStructure;
116 RegisteredStructure m_arrayStorageOrContiguousStructure;
rmorisset@apple.com4ccbcf12019-03-12 19:07:04 +0000117 GPRReg m_resultGPR;
ysuzuki@apple.com6866de172022-04-19 08:06:44 +0000118 JITCompiler::LinkableConstant m_globalObject;
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000119 GPRReg m_sizeGPR;
fpizlo@apple.combc16ddb2016-09-06 01:02:22 +0000120 GPRReg m_storageGPR;
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000121 Vector<SilentRegisterSavePlan, 2> m_plans;
122};
123
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +0000124class CallArrayAllocatorWithVariableStructureVariableSizeSlowPathGenerator final : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000125public:
126 CallArrayAllocatorWithVariableStructureVariableSizeSlowPathGenerator(
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000127 MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_GStZB function,
ysuzuki@apple.com6866de172022-04-19 08:06:44 +0000128 GPRReg resultGPR, JITCompiler::LinkableConstant globalObject, GPRReg structureGPR, GPRReg sizeGPR, GPRReg storageGPR)
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000129 : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit)
130 , m_function(function)
131 , m_resultGPR(resultGPR)
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000132 , m_globalObject(globalObject)
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000133 , m_structureGPR(structureGPR)
134 , m_sizeGPR(sizeGPR)
135 , m_storageGPR(storageGPR)
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000136 {
mark.lam@apple.com001f25c2017-05-20 00:59:31 +0000137 jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR);
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000138 }
139
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +0000140private:
141 void generateInternal(SpeculativeJIT* jit) final
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000142 {
143 linkFrom(jit);
144 for (unsigned i = 0; i < m_plans.size(); ++i)
145 jit->silentSpill(m_plans[i]);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000146 jit->callOperation(m_function, m_resultGPR, m_globalObject, m_structureGPR, m_sizeGPR, m_storageGPR);
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000147 for (unsigned i = m_plans.size(); i--;)
mark.lam@apple.com001f25c2017-05-20 00:59:31 +0000148 jit->silentFill(m_plans[i]);
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000149 jit->m_jit.exceptionCheck();
150 jumpTo(jit);
151 }
ross.kirsling@sony.com4ddd5ef2020-05-12 19:13:18 +0000152
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000153 P_JITOperation_GStZB m_function;
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000154 GPRReg m_resultGPR;
ysuzuki@apple.com6866de172022-04-19 08:06:44 +0000155 JITCompiler::LinkableConstant m_globalObject;
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000156 GPRReg m_structureGPR;
157 GPRReg m_sizeGPR;
158 GPRReg m_storageGPR;
sbarati@apple.comfd407a52017-01-13 04:03:47 +0000159 Vector<SilentRegisterSavePlan, 2> m_plans;
160};
161
fpizlo@apple.com1bc68482012-10-13 03:56:09 +0000162} } // namespace JSC::DFG
163
164#endif // ENABLE(DFG_JIT)