1/*
2 * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
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#pragma once
27
28#if ENABLE(JIT)
29
30#include "CodeOrigin.h"
31#include "JITOperations.h"
32#include "JSCJSValue.h"
33#include "PutKind.h"
34#include "RegisterSet.h"
35
36namespace JSC {
37
38class CodeBlock;
39class StructureStubInfo;
40
41struct CallSiteIndex;
42
43enum class AccessType : int8_t;
44
45class JITInlineCacheGenerator {
46protected:
47 JITInlineCacheGenerator() { }
48 JITInlineCacheGenerator(
49 CodeBlock*, CodeOrigin, CallSiteIndex, AccessType, const RegisterSet& usedRegisters);
50
51public:
52 StructureStubInfo* stubInfo() const { return m_stubInfo; }
53
54 void reportSlowPathCall(MacroAssembler::Label slowPathBegin, MacroAssembler::Call call)
55 {
56 m_slowPathBegin = slowPathBegin;
57 m_slowPathCall = call;
58 }
59
60 MacroAssembler::Label slowPathBegin() const { return m_slowPathBegin; }
61
62 void finalize(
63 LinkBuffer& fastPathLinkBuffer, LinkBuffer& slowPathLinkBuffer,
64 CodeLocationLabel<JITStubRoutinePtrTag> start);
65
66protected:
67 CodeBlock* m_codeBlock;
68 StructureStubInfo* m_stubInfo;
69
70 MacroAssembler::Label m_done;
71 MacroAssembler::Label m_slowPathBegin;
72 MacroAssembler::Call m_slowPathCall;
73};
74
75class JITByIdGenerator : public JITInlineCacheGenerator {
76protected:
77 JITByIdGenerator() { }
78
79 JITByIdGenerator(
80 CodeBlock*, CodeOrigin, CallSiteIndex, AccessType, const RegisterSet& usedRegisters,
81 JSValueRegs base, JSValueRegs value);
82
83public:
84 MacroAssembler::Jump slowPathJump() const
85 {
86 ASSERT(m_slowPathJump.isSet());
87 return m_slowPathJump;
88 }
89
90 void finalize(
91 LinkBuffer& fastPathLinkBuffer, LinkBuffer& slowPathLinkBuffer);
92
93protected:
94
95 void generateFastCommon(MacroAssembler&, size_t size);
96
97 JSValueRegs m_base;
98 JSValueRegs m_value;
99
100 MacroAssembler::Label m_start;
101 MacroAssembler::Jump m_slowPathJump;
102};
103
104class JITGetByIdGenerator : public JITByIdGenerator {
105public:
106 JITGetByIdGenerator() { }
107
108 JITGetByIdGenerator(
109 CodeBlock*, CodeOrigin, CallSiteIndex, const RegisterSet& usedRegisters, UniquedStringImpl* propertyName,
110 JSValueRegs base, JSValueRegs value, AccessType);
111
112 void generateFastPath(MacroAssembler&);
113
114private:
115 bool m_isLengthAccess;
116};
117
118class JITGetByIdWithThisGenerator : public JITByIdGenerator {
119public:
120 JITGetByIdWithThisGenerator() { }
121
122 JITGetByIdWithThisGenerator(
123 CodeBlock*, CodeOrigin, CallSiteIndex, const RegisterSet& usedRegisters, UniquedStringImpl* propertyName,
124 JSValueRegs value, JSValueRegs base, JSValueRegs thisRegs, AccessType);
125
126 void generateFastPath(MacroAssembler&);
127};
128
129class JITPutByIdGenerator : public JITByIdGenerator {
130public:
131 JITPutByIdGenerator() { }
132
133 JITPutByIdGenerator(
134 CodeBlock*, CodeOrigin, CallSiteIndex, const RegisterSet& usedRegisters, JSValueRegs base,
135 JSValueRegs value, GPRReg scratch, ECMAMode, PutKind);
136
137 void generateFastPath(MacroAssembler&);
138
139 V_JITOperation_ESsiJJI slowPathFunction();
140
141private:
142 ECMAMode m_ecmaMode;
143 PutKind m_putKind;
144};
145
146class JITInByIdGenerator : public JITByIdGenerator {
147public:
148 JITInByIdGenerator() { }
149
150 JITInByIdGenerator(
151 CodeBlock*, CodeOrigin, CallSiteIndex, const RegisterSet& usedRegisters, UniquedStringImpl* propertyName,
152 JSValueRegs base, JSValueRegs value);
153
154 void generateFastPath(MacroAssembler&);
155};
156
157class JITInstanceOfGenerator : public JITInlineCacheGenerator {
158public:
159 JITInstanceOfGenerator() { }
160
161 JITInstanceOfGenerator(
162 CodeBlock*, CodeOrigin, CallSiteIndex, const RegisterSet& usedRegisters, GPRReg result,
163 GPRReg value, GPRReg prototype, GPRReg scratch1, GPRReg scratch2,
164 bool prototypeIsKnownObject = false);
165
166 void generateFastPath(MacroAssembler&);
167
168 void finalize(LinkBuffer& fastPathLinkBuffer, LinkBuffer& slowPathLinkBuffer);
169
170private:
171 MacroAssembler::PatchableJump m_jump;
172};
173
174template<typename VectorType>
175void finalizeInlineCaches(VectorType& vector, LinkBuffer& fastPath, LinkBuffer& slowPath)
176{
177 for (auto& entry : vector)
178 entry.finalize(fastPath, slowPath);
179}
180
181template<typename VectorType>
182void finalizeInlineCaches(VectorType& vector, LinkBuffer& linkBuffer)
183{
184 finalizeInlineCaches(vector, linkBuffer, linkBuffer);
185}
186
187} // namespace JSC
188
189#endif // ENABLE(JIT)
190