]> git.saurik.com Git - apple/javascriptcore.git/blame - jit/JITStubCall.h
JavaScriptCore-1218.35.tar.gz
[apple/javascriptcore.git] / jit / JITStubCall.h
CommitLineData
ba379fdc
A
1/*
2 * Copyright (C) 2008 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#ifndef JITStubCall_h
27#define JITStubCall_h
28
f9bf01c6 29#include "MacroAssemblerCodeRef.h"
ba379fdc
A
30
31#if ENABLE(JIT)
32
33namespace JSC {
34
35 class JITStubCall {
36 public:
37 JITStubCall(JIT* jit, JSObject* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
38 : m_jit(jit)
f9bf01c6 39 , m_stub(stub)
93a37866 40#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 41 , m_returnType(Cell)
93a37866 42#endif
f9bf01c6 43 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
44 {
45 }
46
47 JITStubCall(JIT* jit, JSPropertyNameIterator* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
48 : m_jit(jit)
f9bf01c6 49 , m_stub(stub)
93a37866 50#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 51 , m_returnType(Cell)
93a37866 52#endif
f9bf01c6 53 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
54 {
55 }
56
57 JITStubCall(JIT* jit, void* (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
58 : m_jit(jit)
f9bf01c6 59 , m_stub(stub)
93a37866 60#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 61 , m_returnType(VoidPtr)
93a37866 62#endif
f9bf01c6 63 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
64 {
65 }
66
67 JITStubCall(JIT* jit, int (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
68 : m_jit(jit)
f9bf01c6 69 , m_stub(stub)
93a37866 70#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 71 , m_returnType(Int)
93a37866 72#endif
f9bf01c6 73 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
74 {
75 }
76
77 JITStubCall(JIT* jit, bool (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
78 : m_jit(jit)
f9bf01c6 79 , m_stub(stub)
93a37866 80#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 81 , m_returnType(Int)
93a37866 82#endif
f9bf01c6 83 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
84 {
85 }
86
87 JITStubCall(JIT* jit, void (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
88 : m_jit(jit)
f9bf01c6 89 , m_stub(stub)
93a37866 90#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 91 , m_returnType(Void)
93a37866 92#endif
f9bf01c6 93 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
94 {
95 }
96
ba379fdc
A
97 JITStubCall(JIT* jit, EncodedJSValue (JIT_STUB *stub)(STUB_ARGS_DECLARATION))
98 : m_jit(jit)
f9bf01c6 99 , m_stub(stub)
93a37866 100#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 101 , m_returnType(Value)
93a37866 102#endif
f9bf01c6 103 , m_stackIndex(JITSTACKFRAME_ARGS_INDEX)
ba379fdc
A
104 {
105 }
ba379fdc
A
106
107 // Arguments are added first to last.
108
109 void skipArgument()
110 {
111 m_stackIndex += stackIndexStep;
112 }
113
14957cd0 114 void addArgument(JIT::TrustedImm32 argument)
ba379fdc
A
115 {
116 m_jit->poke(argument, m_stackIndex);
117 m_stackIndex += stackIndexStep;
118 }
6fe7ccc8
A
119
120 void addArgument(JIT::Imm32 argument)
121 {
122 m_jit->poke(argument, m_stackIndex);
123 m_stackIndex += stackIndexStep;
124 }
ba379fdc 125
14957cd0 126 void addArgument(JIT::TrustedImmPtr argument)
ba379fdc
A
127 {
128 m_jit->poke(argument, m_stackIndex);
129 m_stackIndex += stackIndexStep;
130 }
6fe7ccc8
A
131
132 void addArgument(JIT::ImmPtr argument)
133 {
134 m_jit->poke(argument, m_stackIndex);
135 m_stackIndex += stackIndexStep;
136 }
ba379fdc
A
137
138 void addArgument(JIT::RegisterID argument)
139 {
93a37866 140#if USE(JSVALUE32_64)
ba379fdc 141 m_jit->poke(argument, m_stackIndex);
93a37866
A
142#else
143 m_jit->poke64(argument, m_stackIndex);
144#endif
ba379fdc
A
145 m_stackIndex += stackIndexStep;
146 }
4e4e5a6f
A
147
148#if USE(JSVALUE32_64)
ba379fdc
A
149 void addArgument(const JSValue& value)
150 {
151 m_jit->poke(JIT::Imm32(value.payload()), m_stackIndex);
152 m_jit->poke(JIT::Imm32(value.tag()), m_stackIndex + 1);
153 m_stackIndex += stackIndexStep;
154 }
93a37866
A
155#else
156 void addArgument(JIT::TrustedImm64 argument)
157 {
158 m_jit->poke(argument, m_stackIndex);
159 m_stackIndex += stackIndexStep;
160 }
161
162 void addArgument(JIT::Imm64 argument)
163 {
164 m_jit->poke(argument, m_stackIndex);
165 m_stackIndex += stackIndexStep;
166 }
4e4e5a6f 167#endif
ba379fdc
A
168
169 void addArgument(JIT::RegisterID tag, JIT::RegisterID payload)
170 {
171 m_jit->poke(payload, m_stackIndex);
172 m_jit->poke(tag, m_stackIndex + 1);
173 m_stackIndex += stackIndexStep;
174 }
175
176#if USE(JSVALUE32_64)
177 void addArgument(unsigned srcVirtualRegister)
178 {
179 if (m_jit->m_codeBlock->isConstantRegisterIndex(srcVirtualRegister)) {
180 addArgument(m_jit->getConstantOperand(srcVirtualRegister));
181 return;
182 }
183
184 m_jit->emitLoad(srcVirtualRegister, JIT::regT1, JIT::regT0);
185 addArgument(JIT::regT1, JIT::regT0);
186 }
187
188 void getArgument(size_t argumentNumber, JIT::RegisterID tag, JIT::RegisterID payload)
189 {
f9bf01c6 190 size_t stackIndex = JITSTACKFRAME_ARGS_INDEX + (argumentNumber * stackIndexStep);
ba379fdc
A
191 m_jit->peek(payload, stackIndex);
192 m_jit->peek(tag, stackIndex + 1);
193 }
194#else
195 void addArgument(unsigned src, JIT::RegisterID scratchRegister) // src is a virtual register.
196 {
197 if (m_jit->m_codeBlock->isConstantRegisterIndex(src))
93a37866 198 addArgument(JIT::Imm64(JSValue::encode(m_jit->m_codeBlock->getConstant(src))));
ba379fdc 199 else {
93a37866 200 m_jit->load64(JIT::Address(JIT::callFrameRegister, src * sizeof(Register)), scratchRegister);
ba379fdc
A
201 addArgument(scratchRegister);
202 }
203 m_jit->killLastResultRegister();
204 }
205#endif
206
207 JIT::Call call()
208 {
209#if ENABLE(OPCODE_SAMPLING)
14957cd0
A
210 if (m_jit->m_bytecodeOffset != (unsigned)-1)
211 m_jit->sampleInstruction(m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, true);
ba379fdc
A
212#endif
213
214 m_jit->restoreArgumentReference();
6fe7ccc8 215 m_jit->updateTopCallFrame();
ba379fdc 216 JIT::Call call = m_jit->call();
14957cd0 217 m_jit->m_calls.append(CallRecord(call, m_jit->m_bytecodeOffset, m_stub.value()));
ba379fdc
A
218
219#if ENABLE(OPCODE_SAMPLING)
14957cd0
A
220 if (m_jit->m_bytecodeOffset != (unsigned)-1)
221 m_jit->sampleInstruction(m_jit->m_codeBlock->instructions().begin() + m_jit->m_bytecodeOffset, false);
ba379fdc
A
222#endif
223
224#if USE(JSVALUE32_64)
225 m_jit->unmap();
226#else
227 m_jit->killLastResultRegister();
228#endif
229 return call;
230 }
231
232#if USE(JSVALUE32_64)
233 JIT::Call call(unsigned dst) // dst is a virtual register.
234 {
235 ASSERT(m_returnType == Value || m_returnType == Cell);
236 JIT::Call call = this->call();
237 if (m_returnType == Value)
238 m_jit->emitStore(dst, JIT::regT1, JIT::regT0);
239 else
240 m_jit->emitStoreCell(dst, JIT::returnValueRegister);
241 return call;
242 }
6fe7ccc8
A
243
244 JIT::Call callWithValueProfiling(unsigned dst)
245 {
246 ASSERT(m_returnType == Value || m_returnType == Cell);
247 JIT::Call call = this->call();
248 ASSERT(JIT::returnValueRegister == JIT::regT0);
249 if (m_returnType == Cell)
250 m_jit->move(JIT::TrustedImm32(JSValue::CellTag), JIT::regT1);
251 m_jit->emitValueProfilingSite();
252 if (m_returnType == Value)
253 m_jit->emitStore(dst, JIT::regT1, JIT::regT0);
254 else
255 m_jit->emitStoreCell(dst, JIT::returnValueRegister);
256 return call;
257 }
ba379fdc
A
258#else
259 JIT::Call call(unsigned dst) // dst is a virtual register.
260 {
93a37866 261 ASSERT(m_returnType == Value || m_returnType == Cell);
ba379fdc
A
262 JIT::Call call = this->call();
263 m_jit->emitPutVirtualRegister(dst);
264 return call;
265 }
6fe7ccc8
A
266
267 JIT::Call callWithValueProfiling(unsigned dst)
268 {
93a37866 269 ASSERT(m_returnType == Value || m_returnType == Cell);
6fe7ccc8
A
270 JIT::Call call = this->call();
271 ASSERT(JIT::returnValueRegister == JIT::regT0);
272 m_jit->emitValueProfilingSite();
273 m_jit->emitPutVirtualRegister(dst);
274 return call;
275 }
ba379fdc
A
276#endif
277
278 JIT::Call call(JIT::RegisterID dst) // dst is a machine register.
279 {
93a37866 280#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 281 ASSERT(m_returnType == Value || m_returnType == VoidPtr || m_returnType == Int || m_returnType == Cell);
ba379fdc
A
282#endif
283 JIT::Call call = this->call();
284 if (dst != JIT::returnValueRegister)
285 m_jit->move(JIT::returnValueRegister, dst);
286 return call;
287 }
288
289 private:
290 static const size_t stackIndexStep = sizeof(EncodedJSValue) == 2 * sizeof(void*) ? 2 : 1;
ba379fdc
A
291
292 JIT* m_jit;
f9bf01c6 293 FunctionPtr m_stub;
93a37866 294#if USE(JSVALUE32_64) || !ASSERT_DISABLED
ba379fdc 295 enum { Void, VoidPtr, Int, Value, Cell } m_returnType;
93a37866 296#endif
ba379fdc
A
297 size_t m_stackIndex;
298 };
299}
300
301#endif // ENABLE(JIT)
302
303#endif // JITStubCall_h