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 | |
36 | namespace JSC { |
37 | |
38 | class CodeBlock; |
39 | class StructureStubInfo; |
40 | |
41 | struct CallSiteIndex; |
42 | |
43 | enum class AccessType : int8_t; |
44 | |
45 | class JITInlineCacheGenerator { |
46 | protected: |
47 | JITInlineCacheGenerator() { } |
48 | JITInlineCacheGenerator( |
49 | CodeBlock*, CodeOrigin, CallSiteIndex, AccessType, const RegisterSet& usedRegisters); |
50 | |
51 | public: |
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 | |
66 | protected: |
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 | |
75 | class JITByIdGenerator : public JITInlineCacheGenerator { |
76 | protected: |
77 | JITByIdGenerator() { } |
78 | |
79 | JITByIdGenerator( |
80 | CodeBlock*, CodeOrigin, CallSiteIndex, AccessType, const RegisterSet& usedRegisters, |
81 | JSValueRegs base, JSValueRegs value); |
82 | |
83 | public: |
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 | |
93 | protected: |
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 | |
104 | class JITGetByIdGenerator : public JITByIdGenerator { |
105 | public: |
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 | |
114 | private: |
115 | bool m_isLengthAccess; |
116 | }; |
117 | |
118 | class JITGetByIdWithThisGenerator : public JITByIdGenerator { |
119 | public: |
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 | |
129 | class JITPutByIdGenerator : public JITByIdGenerator { |
130 | public: |
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 | |
141 | private: |
142 | ECMAMode m_ecmaMode; |
143 | PutKind m_putKind; |
144 | }; |
145 | |
146 | class JITInByIdGenerator : public JITByIdGenerator { |
147 | public: |
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 | |
157 | class JITInstanceOfGenerator : public JITInlineCacheGenerator { |
158 | public: |
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 | |
170 | private: |
171 | MacroAssembler::PatchableJump m_jump; |
172 | }; |
173 | |
174 | template<typename VectorType> |
175 | void finalizeInlineCaches(VectorType& vector, LinkBuffer& fastPath, LinkBuffer& slowPath) |
176 | { |
177 | for (auto& entry : vector) |
178 | entry.finalize(fastPath, slowPath); |
179 | } |
180 | |
181 | template<typename VectorType> |
182 | void finalizeInlineCaches(VectorType& vector, LinkBuffer& linkBuffer) |
183 | { |
184 | finalizeInlineCaches(vector, linkBuffer, linkBuffer); |
185 | } |
186 | |
187 | } // namespace JSC |
188 | |
189 | #endif // ENABLE(JIT) |
190 | |