blob: 26338dcbdb90574e5199fca3198b485b73c4955b [file] [log] [blame]
mrowe@apple.comf88a4632008-09-07 05:44:58 +00001/*
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 CTI_h
27#define CTI_h
28
29#if ENABLE(CTI)
30
barraclough@apple.com71500d52008-09-15 02:18:13 +000031#define WTF_USE_CTI_REPATCH_PIC 1
32
alp@webkit.org7e2b6cd2008-10-10 00:50:25 +000033#include "Machine.h"
mrowe@apple.comf88a4632008-09-07 05:44:58 +000034#include "Opcode.h"
mrowe@apple.comf88a4632008-09-07 05:44:58 +000035#include "RegisterFile.h"
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +000036#include <masm/X86Assembler.h>
mrowe@apple.comf88a4632008-09-07 05:44:58 +000037#include <profiler/Profiler.h>
38#include <wtf/AlwaysInline.h>
39#include <wtf/Vector.h>
40
mrowe@apple.comf88a4632008-09-07 05:44:58 +000041#define CTI_ARGS_code 0x0C
darin@apple.comd3f46402008-10-04 21:12:54 +000042#define CTI_ARGS_registerFile 0x0D
darin@apple.com8c2bac02008-10-09 00:40:43 +000043#define CTI_ARGS_callFrame 0x0E
darin@apple.comd3f46402008-10-04 21:12:54 +000044#define CTI_ARGS_exception 0x0F
45#define CTI_ARGS_profilerReference 0x10
46#define CTI_ARGS_globalData 0x11
mjs@apple.com36f4f422008-10-15 02:39:52 +000047#define ARG_callFrame ((CallFrame*)(ARGS)[CTI_ARGS_callFrame])
mjs@apple.com0d68a332008-10-17 09:06:42 +000048#define ARG_registerFile ((RegisterFile*)(ARGS)[CTI_ARGS_registerFile])
mjs@apple.com36f4f422008-10-15 02:39:52 +000049#define ARG_exception ((JSValue**)(ARGS)[CTI_ARGS_exception])
50#define ARG_profilerReference ((Profiler**)(ARGS)[CTI_ARGS_profilerReference])
51#define ARG_globalData ((JSGlobalData*)(ARGS)[CTI_ARGS_globalData])
mrowe@apple.comf88a4632008-09-07 05:44:58 +000052
mjs@apple.com36f4f422008-10-15 02:39:52 +000053#define ARG_setCallFrame(newCallFrame) (*(CallFrame**)&(ARGS)[CTI_ARGS_callFrame] = (newCallFrame))
mrowe@apple.comf88a4632008-09-07 05:44:58 +000054
mjs@apple.com36f4f422008-10-15 02:39:52 +000055#define ARG_src1 ((JSValue*)((ARGS)[1]))
56#define ARG_src2 ((JSValue*)((ARGS)[2]))
57#define ARG_src3 ((JSValue*)((ARGS)[3]))
58#define ARG_src4 ((JSValue*)((ARGS)[4]))
59#define ARG_src5 ((JSValue*)((ARGS)[5]))
60#define ARG_id1 ((Identifier*)((ARGS)[1]))
61#define ARG_id2 ((Identifier*)((ARGS)[2]))
62#define ARG_id3 ((Identifier*)((ARGS)[3]))
63#define ARG_id4 ((Identifier*)((ARGS)[4]))
64#define ARG_int1 ((int)((ARGS)[1]))
65#define ARG_int2 ((int)((ARGS)[2]))
66#define ARG_int3 ((int)((ARGS)[3]))
67#define ARG_int4 ((int)((ARGS)[4]))
68#define ARG_int5 ((int)((ARGS)[5]))
69#define ARG_func1 ((FuncDeclNode*)((ARGS)[1]))
70#define ARG_funcexp1 ((FuncExprNode*)((ARGS)[1]))
71#define ARG_registers1 ((Register*)((ARGS)[1]))
72#define ARG_regexp1 ((RegExp*)((ARGS)[1]))
73#define ARG_pni1 ((JSPropertyNameIterator*)((ARGS)[1]))
74#define ARG_instr1 ((Instruction*)((ARGS)[1]))
75#define ARG_instr2 ((Instruction*)((ARGS)[2]))
76#define ARG_instr3 ((Instruction*)((ARGS)[3]))
77#define ARG_instr4 ((Instruction*)((ARGS)[4]))
78#define ARG_instr5 ((Instruction*)((ARGS)[5]))
79#define ARG_instr6 ((Instruction*)((ARGS)[6]))
mrowe@apple.comf88a4632008-09-07 05:44:58 +000080
mjs@apple.com36f4f422008-10-15 02:39:52 +000081#define CTI_RETURN_ADDRESS ((ARGS)[-1])
mrowe@apple.comf88a4632008-09-07 05:44:58 +000082
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000083namespace JSC {
mrowe@apple.comf88a4632008-09-07 05:44:58 +000084
85 class CodeBlock;
mrowe@apple.comf88a4632008-09-07 05:44:58 +000086 class JSPropertyNameIterator;
87 class JSValue;
88 class Machine;
89 class Register;
90 class RegisterFile;
91 class ScopeChainNode;
92 class SimpleJumpTable;
93 class StringJumpTable;
94 class StructureIDChain;
95 struct Instruction;
barraclough@apple.comb8b15e22008-09-27 01:44:15 +000096 struct OperandTypes;
mrowe@apple.comf88a4632008-09-07 05:44:58 +000097
mjs@apple.com36f4f422008-10-15 02:39:52 +000098 typedef JSValue* (SFX_CALL *CTIHelper_j)(CTI_ARGS);
99 typedef JSPropertyNameIterator* (SFX_CALL *CTIHelper_p)(CTI_ARGS);
100 typedef void (SFX_CALL *CTIHelper_v)(CTI_ARGS);
101 typedef void* (SFX_CALL *CTIHelper_s)(CTI_ARGS);
102 typedef int (SFX_CALL *CTIHelper_b)(CTI_ARGS);
103 typedef VoidPtrPair (SFX_CALL *CTIHelper_2)(CTI_ARGS);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000104
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000105 struct CallRecord {
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000106 X86Assembler::JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000107 void* to;
108 unsigned opcodeIndex;
109
110 CallRecord()
111 {
112 }
113
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000114 CallRecord(X86Assembler::JmpSrc f, CTIHelper_j t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000115 : from(f)
116 , to((void*)t)
117 , opcodeIndex(i)
118 {
119 }
120
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000121 CallRecord(X86Assembler::JmpSrc f, CTIHelper_p t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000122 : from(f)
123 , to((void*)t)
124 , opcodeIndex(i)
125 {
126 }
127
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000128 CallRecord(X86Assembler::JmpSrc f, CTIHelper_v t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000129 : from(f)
130 , to((void*)t)
131 , opcodeIndex(i)
132 {
133 }
134
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000135 CallRecord(X86Assembler::JmpSrc f, CTIHelper_s t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000136 : from(f)
137 , to((void*)t)
138 , opcodeIndex(i)
139 {
140 }
141
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000142 CallRecord(X86Assembler::JmpSrc f, CTIHelper_b t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000143 : from(f)
144 , to((void*)t)
145 , opcodeIndex(i)
146 {
147 }
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000148
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000149 CallRecord(X86Assembler::JmpSrc f, CTIHelper_2 t, unsigned i)
150 : from(f)
151 , to((void*)t)
152 , opcodeIndex(i)
153 {
154 }
155
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000156 CallRecord(X86Assembler::JmpSrc f, unsigned i)
157 : from(f)
158 , to(0)
159 , opcodeIndex(i)
160 {
161 }
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000162 };
163
164 struct JmpTable {
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000165 X86Assembler::JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000166 unsigned to;
167
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000168 JmpTable(X86Assembler::JmpSrc f, unsigned t)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000169 : from(f)
170 , to(t)
171 {
172 }
173 };
174
175 struct SlowCaseEntry {
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000176 X86Assembler::JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000177 unsigned to;
178 unsigned hint;
179
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000180 SlowCaseEntry(X86Assembler::JmpSrc f, unsigned t, unsigned h = 0)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000181 : from(f)
182 , to(t)
183 , hint(h)
184 {
185 }
186 };
187
188 struct SwitchRecord {
189 enum Type {
190 Immediate,
191 Character,
192 String
193 };
194
195 Type m_type;
196
197 union {
198 SimpleJumpTable* m_simpleJumpTable;
199 StringJumpTable* m_stringJumpTable;
200 } m_jumpTable;
201
202 unsigned m_opcodeIndex;
203 unsigned m_defaultOffset;
204
205 SwitchRecord(SimpleJumpTable* jumpTable, unsigned opcodeIndex, unsigned defaultOffset, Type type)
206 : m_type(type)
207 , m_opcodeIndex(opcodeIndex)
208 , m_defaultOffset(defaultOffset)
209 {
210 m_jumpTable.m_simpleJumpTable = jumpTable;
211 }
212
213 SwitchRecord(StringJumpTable* jumpTable, unsigned opcodeIndex, unsigned defaultOffset)
214 : m_type(String)
215 , m_opcodeIndex(opcodeIndex)
216 , m_defaultOffset(defaultOffset)
217 {
218 m_jumpTable.m_stringJumpTable = jumpTable;
219 }
220 };
221
barraclough@apple.com71500d52008-09-15 02:18:13 +0000222 struct StructureStubCompilationInfo {
223 X86Assembler::JmpSrc callReturnLocation;
224 X86Assembler::JmpDst hotPathBegin;
225 };
226
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000227 extern "C" {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000228 JSValue* ctiTrampoline(void* code, RegisterFile*, CallFrame*, JSValue** exception, Profiler**, JSGlobalData*);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000229 void ctiVMThrowTrampoline();
230 };
231
232 void ctiSetReturnAddress(void** where, void* what);
233 void ctiRepatchCallByReturnAddress(void* where, void* what);
234
235 class CTI {
barraclough@apple.com71500d52008-09-15 02:18:13 +0000236 static const int repatchGetByIdDefaultStructureID = -1;
237 // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler
238 // will compress the displacement, and we may not be able to fit a repatched offset.
239 static const int repatchGetByIdDefaultOffset = 256;
240
mjs@apple.com36f4f422008-10-15 02:39:52 +0000241#if USE(FAST_CALL_CTI_ARGUMENT)
oliver@apple.com6dc83fb2008-10-08 04:56:38 +0000242 static const int ctiArgumentInitSize = 2;
mjs@apple.com36f4f422008-10-15 02:39:52 +0000243#elif USE(CTI_ARGUMENT)
244 static const int ctiArgumentInitSize = 4;
245#else
246 static const int ctiArgumentInitSize = 0;
247#endif
barraclough@apple.com71500d52008-09-15 02:18:13 +0000248 // These architecture specific value are used to enable repatching - see comment on op_put_by_id.
249 static const int repatchOffsetPutByIdStructureID = 19;
250 static const int repatchOffsetPutByIdPropertyMapOffset = 34;
251 // These architecture specific value are used to enable repatching - see comment on op_get_by_id.
252 static const int repatchOffsetGetByIdStructureID = 19;
253 static const int repatchOffsetGetByIdBranchToSlowCase = 25;
254 static const int repatchOffsetGetByIdPropertyMapOffset = 34;
barraclough@apple.com6bd3e1652008-10-05 17:38:32 +0000255#if ENABLE(SAMPLING_TOOL)
mjs@apple.com0d68a332008-10-17 09:06:42 +0000256 static const int repatchOffsetGetByIdSlowCaseCall = 27 + 4 + ctiArgumentInitSize;
barraclough@apple.com6bd3e1652008-10-05 17:38:32 +0000257#else
mjs@apple.com0d68a332008-10-17 09:06:42 +0000258 static const int repatchOffsetGetByIdSlowCaseCall = 17 + 4 + ctiArgumentInitSize;
barraclough@apple.com6bd3e1652008-10-05 17:38:32 +0000259#endif
barraclough@apple.com71500d52008-09-15 02:18:13 +0000260
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000261 public:
darin@apple.com8c2bac02008-10-09 00:40:43 +0000262 static void compile(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000263 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000264 CTI cti(machine, callFrame, codeBlock);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000265 cti.privateCompile();
266 }
267
cwzwarich@webkit.org56a4aeb12008-09-09 01:05:06 +0000268#if ENABLE(WREC)
darin@apple.com8c2bac02008-10-09 00:40:43 +0000269 static void* compileRegExp(Machine*, const UString& pattern, unsigned* numSubpatterns_ptr, const char** error_ptr, bool ignoreCase = false, bool multiline = false);
cwzwarich@webkit.org56a4aeb12008-09-09 01:05:06 +0000270#endif
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000271
darin@apple.com8c2bac02008-10-09 00:40:43 +0000272 static void compileGetByIdSelf(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000273 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000274 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000275 cti.privateCompileGetByIdSelf(structureID, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000276 }
277
darin@apple.com8c2bac02008-10-09 00:40:43 +0000278 static void compileGetByIdProto(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, StructureID* prototypeStructureID, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000279 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000280 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000281 cti.privateCompileGetByIdProto(structureID, prototypeStructureID, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000282 }
283
darin@apple.com8c2bac02008-10-09 00:40:43 +0000284 static void compileGetByIdChain(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, StructureIDChain* chain, size_t count, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000285 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000286 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000287 cti.privateCompileGetByIdChain(structureID, chain, count, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000288 }
289
darin@apple.com8c2bac02008-10-09 00:40:43 +0000290 static void compilePutByIdReplace(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000291 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000292 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000293 cti.privateCompilePutByIdReplace(structureID, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000294 }
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000295
darin@apple.com8c2bac02008-10-09 00:40:43 +0000296 static void compilePutByIdTransition(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, StructureID* oldStructureID, StructureID* newStructureID, size_t cachedOffset, StructureIDChain* sIDC, void* returnAddress)
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000297 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000298 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000299 cti.privateCompilePutByIdTransition(oldStructureID, newStructureID, cachedOffset, sIDC, returnAddress);
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000300 }
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000301
darin@apple.com8c2bac02008-10-09 00:40:43 +0000302 static void* compileArrayLengthTrampoline(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000303 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000304 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000305 return cti.privateCompileArrayLengthTrampoline();
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000306 }
307
darin@apple.com8c2bac02008-10-09 00:40:43 +0000308 static void* compileStringLengthTrampoline(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000309 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000310 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000311 return cti.privateCompileStringLengthTrampoline();
312 }
313
314 static void patchGetByIdSelf(CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress);
315 static void patchPutByIdReplace(CodeBlock* codeBlock, StructureID* structureID, size_t cachedOffset, void* returnAddress);
316
darin@apple.com8c2bac02008-10-09 00:40:43 +0000317 static void compilePatchGetArrayLength(Machine* machine, CallFrame* callFrame, CodeBlock* codeBlock, void* returnAddress)
barraclough@apple.com71500d52008-09-15 02:18:13 +0000318 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000319 CTI cti(machine, callFrame, codeBlock);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000320 return cti.privateCompilePatchGetArrayLength(returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000321 }
322
darin@apple.com8c2bac02008-10-09 00:40:43 +0000323 inline static JSValue* execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValue** exception)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000324 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000325 return ctiTrampoline(code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000326 }
327
328 private:
darin@apple.com8c2bac02008-10-09 00:40:43 +0000329 CTI(Machine*, CallFrame*, CodeBlock*);
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000330
331 bool isConstant(int src);
darin@apple.com8c2bac02008-10-09 00:40:43 +0000332 JSValue* getConstant(CallFrame*, int src);
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000333
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000334 void privateCompileMainPass();
335 void privateCompileLinkPass();
336 void privateCompileSlowCases();
337 void privateCompile();
barraclough@apple.com71500d52008-09-15 02:18:13 +0000338 void privateCompileGetByIdSelf(StructureID*, size_t cachedOffset, void* returnAddress);
339 void privateCompileGetByIdProto(StructureID*, StructureID* prototypeStructureID, size_t cachedOffset, void* returnAddress);
340 void privateCompileGetByIdChain(StructureID*, StructureIDChain*, size_t count, size_t cachedOffset, void* returnAddress);
341 void privateCompilePutByIdReplace(StructureID*, size_t cachedOffset, void* returnAddress);
342 void privateCompilePutByIdTransition(StructureID*, StructureID*, size_t cachedOffset, StructureIDChain*, void* returnAddress);
343
344 void* privateCompileArrayLengthTrampoline();
345 void* privateCompileStringLengthTrampoline();
346 void privateCompilePatchGetArrayLength(void* returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000347
348 enum CompileOpCallType { OpCallNormal, OpCallEval, OpConstruct };
349 void compileOpCall(Instruction* instruction, unsigned i, CompileOpCallType type = OpCallNormal);
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000350 void compileOpCallInitializeCallFrame(unsigned callee, unsigned argCount);
mjs@apple.comdb29af22008-09-23 13:20:23 +0000351 enum CompileOpStrictEqType { OpStrictEq, OpNStrictEq };
352 void compileOpStrictEq(Instruction* instruction, unsigned i, CompileOpStrictEqType type);
barraclough@apple.comb8b15e22008-09-27 01:44:15 +0000353 void putDoubleResultToJSNumberCellOrJSImmediate(X86::XMMRegisterID xmmSource, X86::RegisterID jsNumberCell, unsigned dst, X86Assembler::JmpSrc* wroteJSNumberCell, X86::XMMRegisterID tempXmm, X86::RegisterID tempReg1, X86::RegisterID tempReg2);
354 void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i);
355 void compileBinaryArithOpSlowCase(OpcodeID, Vector<SlowCaseEntry>::iterator& iter, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000356
ggaren@apple.com0c677732008-09-30 00:46:25 +0000357 void emitGetArg(int src, X86Assembler::RegisterID dst);
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000358 void emitGetPutArg(unsigned src, unsigned offset, X86Assembler::RegisterID scratch);
359 void emitPutArg(X86Assembler::RegisterID src, unsigned offset);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000360 void emitPutArgConstant(unsigned value, unsigned offset);
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000361 void emitPutResult(unsigned dst, X86Assembler::RegisterID from = X86::eax);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000362
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000363 void emitInitRegister(unsigned dst);
oliver@apple.comecfd2242008-09-20 03:00:43 +0000364
barraclough@apple.comce5a0b32008-09-16 17:40:01 +0000365 void emitPutCTIParam(void* value, unsigned name);
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000366 void emitPutCTIParam(X86Assembler::RegisterID from, unsigned name);
367 void emitGetCTIParam(unsigned name, X86Assembler::RegisterID to);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000368
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000369 void emitPutToCallFrameHeader(X86Assembler::RegisterID from, RegisterFile::CallFrameHeaderEntry entry);
370 void emitGetFromCallFrameHeader(RegisterFile::CallFrameHeaderEntry entry, X86Assembler::RegisterID to);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000371
372 JSValue* getConstantImmediateNumericArg(unsigned src);
373 unsigned getDeTaggedConstantImmediate(JSValue* imm);
374
mrowe@apple.comf73971a2008-09-16 01:34:20 +0000375 void emitJumpSlowCaseIfIsJSCell(X86Assembler::RegisterID reg, unsigned opcodeIndex);
376 void emitJumpSlowCaseIfNotJSCell(X86Assembler::RegisterID reg, unsigned opcodeIndex);
weinig@apple.com262302f2008-09-16 03:46:58 +0000377
darin@apple.com71610912008-09-21 23:08:15 +0000378 void emitJumpSlowCaseIfNotImmNum(X86Assembler::RegisterID, unsigned opcodeIndex);
379 void emitJumpSlowCaseIfNotImmNums(X86Assembler::RegisterID, X86Assembler::RegisterID, unsigned opcodeIndex);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000380
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000381 void emitFastArithDeTagImmediate(X86Assembler::RegisterID);
barraclough@apple.comc8c2bb22008-10-09 23:59:26 +0000382 X86Assembler::JmpSrc emitFastArithDeTagImmediateJumpIfZero(X86Assembler::RegisterID);
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000383 void emitFastArithReTagImmediate(X86Assembler::RegisterID);
384 void emitFastArithPotentiallyReTagImmediate(X86Assembler::RegisterID);
385 void emitFastArithImmToInt(X86Assembler::RegisterID);
386 void emitFastArithIntToImmOrSlowCase(X86Assembler::RegisterID, unsigned opcodeIndex);
387 void emitFastArithIntToImmNoCheck(X86Assembler::RegisterID);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000388
mjs@apple.com40328732008-09-21 10:39:29 +0000389 void emitTagAsBoolImmediate(X86Assembler::RegisterID reg);
390
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000391 X86Assembler::JmpSrc emitCall(unsigned opcodeIndex, X86::RegisterID);
mjs@apple.com0d68a332008-10-17 09:06:42 +0000392 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_j);
393 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_p);
394 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_v);
395 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_s);
396 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_b);
397 X86Assembler::JmpSrc emitCTICall(unsigned opcodeIndex, CTIHelper_2);
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000398
oliver@apple.com957eefc2008-09-10 09:23:35 +0000399 void emitGetVariableObjectRegister(X86Assembler::RegisterID variableObject, int index, X86Assembler::RegisterID dst);
400 void emitPutVariableObjectRegister(X86Assembler::RegisterID src, X86Assembler::RegisterID variableObject, int index);
401
oliver@apple.comffa76922008-09-09 04:43:25 +0000402 void emitSlowScriptCheck(unsigned opcodeIndex);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000403#ifndef NDEBUG
404 void printOpcodeOperandTypes(unsigned src1, unsigned src2);
405#endif
406
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000407 X86Assembler m_jit;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000408 Machine* m_machine;
darin@apple.com8c2bac02008-10-09 00:40:43 +0000409 CallFrame* m_callFrame;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000410 CodeBlock* m_codeBlock;
411
412 Vector<CallRecord> m_calls;
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000413 Vector<X86Assembler::JmpDst> m_labels;
barraclough@apple.com71500d52008-09-15 02:18:13 +0000414 Vector<StructureStubCompilationInfo> m_structureStubCompilationInfo;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000415 Vector<JmpTable> m_jmpTable;
416
417 struct JSRInfo {
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000418 X86Assembler::JmpDst addrPosition;
419 X86Assembler::JmpDst target;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000420
cwzwarich@webkit.org8a334572008-09-10 03:22:04 +0000421 JSRInfo(const X86Assembler::JmpDst& storeLocation, const X86Assembler::JmpDst& targetLocation)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000422 : addrPosition(storeLocation)
423 , target(targetLocation)
424 {
425 }
426 };
427
428 Vector<JSRInfo> m_jsrSites;
429 Vector<SlowCaseEntry> m_slowCases;
430 Vector<SwitchRecord> m_switches;
431
432 // This limit comes from the limit set in PCRE
433 static const int MaxPatternSize = (1 << 16);
434
435 };
436}
437
438#endif // ENABLE(CTI)
439
440#endif // CTI_h