blob: e92c632d6ad152301e3ef81a206dd79270f99678 [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
ggaren@apple.comf272d2d2008-11-17 04:25:37 +000029#include <wtf/Platform.h>
30
31#if ENABLE(JIT)
mrowe@apple.comf88a4632008-09-07 05:44:58 +000032
barraclough@apple.com71500d52008-09-15 02:18:13 +000033#define WTF_USE_CTI_REPATCH_PIC 1
34
alp@webkit.org7e2b6cd2008-10-10 00:50:25 +000035#include "Machine.h"
mrowe@apple.comf88a4632008-09-07 05:44:58 +000036#include "Opcode.h"
mrowe@apple.comf88a4632008-09-07 05:44:58 +000037#include "RegisterFile.h"
ggaren@apple.comf272d2d2008-11-17 04:25:37 +000038#include "X86Assembler.h"
39#include "Profiler.h"
mrowe@apple.comf88a4632008-09-07 05:44:58 +000040#include <wtf/AlwaysInline.h>
41#include <wtf/Vector.h>
42
mrowe@apple.comf88a4632008-09-07 05:44:58 +000043#define CTI_ARGS_code 0x0C
darin@apple.comd3f46402008-10-04 21:12:54 +000044#define CTI_ARGS_registerFile 0x0D
darin@apple.com8c2bac02008-10-09 00:40:43 +000045#define CTI_ARGS_callFrame 0x0E
darin@apple.comd3f46402008-10-04 21:12:54 +000046#define CTI_ARGS_exception 0x0F
47#define CTI_ARGS_profilerReference 0x10
48#define CTI_ARGS_globalData 0x11
mrowe@apple.comf88a4632008-09-07 05:44:58 +000049
darin@apple.com5a494422008-10-18 23:08:12 +000050#define ARG_callFrame static_cast<CallFrame*>(ARGS[CTI_ARGS_callFrame])
51#define ARG_registerFile static_cast<RegisterFile*>(ARGS[CTI_ARGS_registerFile])
darin@apple.com44331f82008-10-24 16:22:51 +000052#define ARG_exception static_cast<JSValue**>(ARGS[CTI_ARGS_exception])
darin@apple.com5a494422008-10-18 23:08:12 +000053#define ARG_profilerReference static_cast<Profiler**>(ARGS[CTI_ARGS_profilerReference])
54#define ARG_globalData static_cast<JSGlobalData*>(ARGS[CTI_ARGS_globalData])
mrowe@apple.comf88a4632008-09-07 05:44:58 +000055
darin@apple.com5a494422008-10-18 23:08:12 +000056#define ARG_setCallFrame(newCallFrame) (ARGS[CTI_ARGS_callFrame] = (newCallFrame))
mrowe@apple.comf88a4632008-09-07 05:44:58 +000057
darin@apple.com5c465b02008-10-19 16:58:58 +000058#define ARG_src1 static_cast<JSValue*>(ARGS[1])
59#define ARG_src2 static_cast<JSValue*>(ARGS[2])
60#define ARG_src3 static_cast<JSValue*>(ARGS[3])
61#define ARG_src4 static_cast<JSValue*>(ARGS[4])
62#define ARG_src5 static_cast<JSValue*>(ARGS[5])
darin@apple.com5a494422008-10-18 23:08:12 +000063#define ARG_id1 static_cast<Identifier*>(ARGS[1])
64#define ARG_id2 static_cast<Identifier*>(ARGS[2])
65#define ARG_id3 static_cast<Identifier*>(ARGS[3])
66#define ARG_id4 static_cast<Identifier*>(ARGS[4])
67#define ARG_int1 reinterpret_cast<intptr_t>(ARGS[1])
68#define ARG_int2 reinterpret_cast<intptr_t>(ARGS[2])
69#define ARG_int3 reinterpret_cast<intptr_t>(ARGS[3])
70#define ARG_int4 reinterpret_cast<intptr_t>(ARGS[4])
71#define ARG_int5 reinterpret_cast<intptr_t>(ARGS[5])
72#define ARG_int6 reinterpret_cast<intptr_t>(ARGS[6])
73#define ARG_func1 static_cast<FuncDeclNode*>(ARGS[1])
74#define ARG_funcexp1 static_cast<FuncExprNode*>(ARGS[1])
75#define ARG_registers1 static_cast<Register*>(ARGS[1])
76#define ARG_regexp1 static_cast<RegExp*>(ARGS[1])
77#define ARG_pni1 static_cast<JSPropertyNameIterator*>(ARGS[1])
78#define ARG_instr1 static_cast<Instruction*>(ARGS[1])
79#define ARG_instr2 static_cast<Instruction*>(ARGS[2])
80#define ARG_instr3 static_cast<Instruction*>(ARGS[3])
81#define ARG_instr4 static_cast<Instruction*>(ARGS[4])
82#define ARG_instr5 static_cast<Instruction*>(ARGS[5])
83#define ARG_instr6 static_cast<Instruction*>(ARGS[6])
barraclough@apple.com1bab56d2008-11-15 01:33:36 +000084#define ARG_returnAddress2 static_cast<void*>(ARGS[2])
barraclough@apple.com52eea522008-11-07 01:30:03 +000085#define ARG_codeBlock4 static_cast<CodeBlock*>(ARGS[4])
darin@apple.com5a494422008-10-18 23:08:12 +000086
87#define CTI_RETURN_ADDRESS_SLOT (ARGS[-1])
mrowe@apple.comf88a4632008-09-07 05:44:58 +000088
oliver@apple.com487b61b2008-10-30 04:33:21 +000089#if COMPILER(MSVC)
90#define FASTCALL __fastcall
91#elif COMPILER(GCC)
92#define FASTCALL __attribute__ ((fastcall))
93#else
94#error Need to support fastcall calling convention in this compiler
95#endif
96
cwzwarich@webkit.org3f782f62008-09-08 01:28:33 +000097namespace JSC {
mrowe@apple.comf88a4632008-09-07 05:44:58 +000098
99 class CodeBlock;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000100 class JSPropertyNameIterator;
ggaren@apple.com031563e2008-11-17 02:21:16 +0000101 class Interpreter;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000102 class Register;
103 class RegisterFile;
104 class ScopeChainNode;
105 class SimpleJumpTable;
106 class StringJumpTable;
darin@apple.coma9778f92008-11-16 04:40:06 +0000107 class StructureChain;
darin@apple.com5a494422008-10-18 23:08:12 +0000108
barraclough@apple.come9642652008-10-23 22:29:54 +0000109 struct CallLinkInfo;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000110 struct Instruction;
barraclough@apple.comb8b15e22008-09-27 01:44:15 +0000111 struct OperandTypes;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000112
darin@apple.com40d7c812008-10-20 16:22:55 +0000113 typedef JSValue* (SFX_CALL *CTIHelper_j)(CTI_ARGS);
114 typedef JSObject* (SFX_CALL *CTIHelper_o)(CTI_ARGS);
mjs@apple.com36f4f422008-10-15 02:39:52 +0000115 typedef JSPropertyNameIterator* (SFX_CALL *CTIHelper_p)(CTI_ARGS);
116 typedef void (SFX_CALL *CTIHelper_v)(CTI_ARGS);
117 typedef void* (SFX_CALL *CTIHelper_s)(CTI_ARGS);
118 typedef int (SFX_CALL *CTIHelper_b)(CTI_ARGS);
119 typedef VoidPtrPair (SFX_CALL *CTIHelper_2)(CTI_ARGS);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000120
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000121 struct CallRecord {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000122 typedef X86Assembler::JmpSrc JmpSrc;
123
124 JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000125 void* to;
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000126 unsigned bytecodeIndex;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000127
128 CallRecord()
129 {
130 }
131
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000132 CallRecord(JmpSrc f, CTIHelper_j t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000133 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000134 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000135 , bytecodeIndex(i)
darin@apple.com40d7c812008-10-20 16:22:55 +0000136 {
137 }
138
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000139 CallRecord(JmpSrc f, CTIHelper_o t, unsigned i)
darin@apple.com40d7c812008-10-20 16:22:55 +0000140 : from(f)
141 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000142 , bytecodeIndex(i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000143 {
144 }
145
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000146 CallRecord(JmpSrc f, CTIHelper_p t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000147 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000148 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000149 , bytecodeIndex(i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000150 {
151 }
152
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000153 CallRecord(JmpSrc f, CTIHelper_v t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000154 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000155 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000156 , bytecodeIndex(i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000157 {
158 }
159
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000160 CallRecord(JmpSrc f, CTIHelper_s t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000161 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000162 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000163 , bytecodeIndex(i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000164 {
165 }
166
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000167 CallRecord(JmpSrc f, CTIHelper_b t, unsigned i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000168 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000169 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000170 , bytecodeIndex(i)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000171 {
172 }
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000173
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000174 CallRecord(JmpSrc f, CTIHelper_2 t, unsigned i)
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000175 : from(f)
darin@apple.com40d7c812008-10-20 16:22:55 +0000176 , to(reinterpret_cast<void*>(t))
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000177 , bytecodeIndex(i)
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000178 {
179 }
180
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000181 CallRecord(JmpSrc f, unsigned i)
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000182 : from(f)
183 , to(0)
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000184 , bytecodeIndex(i)
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000185 {
186 }
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000187 };
188
189 struct JmpTable {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000190 typedef X86Assembler::JmpSrc JmpSrc;
191
192 JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000193 unsigned to;
194
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000195 JmpTable(JmpSrc f, unsigned t)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000196 : from(f)
197 , to(t)
198 {
199 }
200 };
201
202 struct SlowCaseEntry {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000203 typedef X86Assembler::JmpSrc JmpSrc;
204
205 JmpSrc from;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000206 unsigned to;
207 unsigned hint;
208
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000209 SlowCaseEntry(JmpSrc f, unsigned t, unsigned h = 0)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000210 : from(f)
211 , to(t)
212 , hint(h)
213 {
214 }
215 };
216
217 struct SwitchRecord {
218 enum Type {
219 Immediate,
220 Character,
221 String
222 };
223
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000224 Type type;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000225
226 union {
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000227 SimpleJumpTable* simpleJumpTable;
228 StringJumpTable* stringJumpTable;
229 } jumpTable;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000230
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000231 unsigned bytecodeIndex;
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000232 unsigned defaultOffset;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000233
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000234 SwitchRecord(SimpleJumpTable* jumpTable, unsigned bytecodeIndex, unsigned defaultOffset, Type type)
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000235 : type(type)
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000236 , bytecodeIndex(bytecodeIndex)
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000237 , defaultOffset(defaultOffset)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000238 {
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000239 this->jumpTable.simpleJumpTable = jumpTable;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000240 }
241
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000242 SwitchRecord(StringJumpTable* jumpTable, unsigned bytecodeIndex, unsigned defaultOffset)
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000243 : type(String)
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000244 , bytecodeIndex(bytecodeIndex)
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000245 , defaultOffset(defaultOffset)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000246 {
cwzwarich@webkit.orge8827732008-11-11 18:31:51 +0000247 this->jumpTable.stringJumpTable = jumpTable;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000248 }
249 };
250
barraclough@apple.com71500d52008-09-15 02:18:13 +0000251 struct StructureStubCompilationInfo {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000252 typedef X86Assembler::JmpSrc JmpSrc;
253 typedef X86Assembler::JmpDst JmpDst;
254
255 JmpSrc callReturnLocation;
256 JmpDst hotPathBegin;
257 JmpSrc hotPathOther;
258 JmpDst coldPathOther;
barraclough@apple.com71500d52008-09-15 02:18:13 +0000259 };
260
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000261 extern "C" {
darin@apple.com44331f82008-10-24 16:22:51 +0000262 JSValue* ctiTrampoline(void* code, RegisterFile*, CallFrame*, JSValue** exception, Profiler**, JSGlobalData*);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000263 void ctiVMThrowTrampoline();
264 };
265
266 void ctiSetReturnAddress(void** where, void* what);
267 void ctiRepatchCallByReturnAddress(void* where, void* what);
268
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000269 class JIT {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000270 typedef X86Assembler::RegisterID RegisterID;
271 typedef X86Assembler::XMMRegisterID XMMRegisterID;
272 typedef X86Assembler::JmpSrc JmpSrc;
273 typedef X86Assembler::JmpDst JmpDst;
274
darin@apple.coma9778f92008-11-16 04:40:06 +0000275 static const int repatchGetByIdDefaultStructure = -1;
barraclough@apple.com71500d52008-09-15 02:18:13 +0000276 // Magic number - initial offset cannot be representable as a signed 8bit value, or the X86Assembler
277 // will compress the displacement, and we may not be able to fit a repatched offset.
278 static const int repatchGetByIdDefaultOffset = 256;
279
mjs@apple.com36f4f422008-10-15 02:39:52 +0000280#if USE(FAST_CALL_CTI_ARGUMENT)
oliver@apple.com6dc83fb2008-10-08 04:56:38 +0000281 static const int ctiArgumentInitSize = 2;
mjs@apple.com36f4f422008-10-15 02:39:52 +0000282#elif USE(CTI_ARGUMENT)
283 static const int ctiArgumentInitSize = 4;
284#else
285 static const int ctiArgumentInitSize = 0;
286#endif
barraclough@apple.com71500d52008-09-15 02:18:13 +0000287 // These architecture specific value are used to enable repatching - see comment on op_put_by_id.
darin@apple.coma9778f92008-11-16 04:40:06 +0000288 static const int repatchOffsetPutByIdStructure = 7;
mjs@apple.come32adbc2008-11-13 12:53:35 +0000289 static const int repatchOffsetPutByIdPropertyMapOffset = 22;
barraclough@apple.com71500d52008-09-15 02:18:13 +0000290 // These architecture specific value are used to enable repatching - see comment on op_get_by_id.
darin@apple.coma9778f92008-11-16 04:40:06 +0000291 static const int repatchOffsetGetByIdStructure = 7;
mjs@apple.come32adbc2008-11-13 12:53:35 +0000292 static const int repatchOffsetGetByIdBranchToSlowCase = 13;
293 static const int repatchOffsetGetByIdPropertyMapOffset = 22;
ggaren@apple.com47d3f052008-11-15 21:37:49 +0000294#if ENABLE(OPCODE_SAMPLING)
mjs@apple.com0d68a332008-10-17 09:06:42 +0000295 static const int repatchOffsetGetByIdSlowCaseCall = 27 + 4 + ctiArgumentInitSize;
barraclough@apple.com6bd3e1652008-10-05 17:38:32 +0000296#else
mjs@apple.com0d68a332008-10-17 09:06:42 +0000297 static const int repatchOffsetGetByIdSlowCaseCall = 17 + 4 + ctiArgumentInitSize;
barraclough@apple.com6bd3e1652008-10-05 17:38:32 +0000298#endif
barraclough@apple.com3a4eb9b2008-10-18 02:51:52 +0000299 static const int repatchOffsetOpCallCall = 6;
barraclough@apple.com71500d52008-09-15 02:18:13 +0000300
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000301 public:
barraclough@apple.com7c876fc2008-11-11 05:09:46 +0000302 static void compile(JSGlobalData* globalData, CodeBlock* codeBlock)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000303 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000304 JIT jit(globalData, codeBlock);
305 jit.privateCompile();
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000306 }
307
darin@apple.coma9778f92008-11-16 04:40:06 +0000308 static void compileGetByIdSelf(JSGlobalData* globalData, CodeBlock* codeBlock, Structure* structure, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000309 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000310 JIT jit(globalData, codeBlock);
311 jit.privateCompileGetByIdSelf(structure, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000312 }
313
darin@apple.coma9778f92008-11-16 04:40:06 +0000314 static void compileGetByIdProto(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, Structure* structure, Structure* prototypeStructure, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000315 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000316 JIT jit(globalData, codeBlock);
317 jit.privateCompileGetByIdProto(structure, prototypeStructure, cachedOffset, returnAddress, callFrame);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000318 }
319
darin@apple.coma9778f92008-11-16 04:40:06 +0000320 static void compileGetByIdChain(JSGlobalData* globalData, CallFrame* callFrame, CodeBlock* codeBlock, Structure* structure, StructureChain* chain, size_t count, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000321 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000322 JIT jit(globalData, codeBlock);
323 jit.privateCompileGetByIdChain(structure, chain, count, cachedOffset, returnAddress, callFrame);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000324 }
325
darin@apple.coma9778f92008-11-16 04:40:06 +0000326 static void compilePutByIdReplace(JSGlobalData* globalData, CodeBlock* codeBlock, Structure* structure, size_t cachedOffset, void* returnAddress)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000327 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000328 JIT jit(globalData, codeBlock);
329 jit.privateCompilePutByIdReplace(structure, cachedOffset, returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000330 }
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000331
darin@apple.coma9778f92008-11-16 04:40:06 +0000332 static void compilePutByIdTransition(JSGlobalData* globalData, CodeBlock* codeBlock, Structure* oldStructure, Structure* newStructure, size_t cachedOffset, StructureChain* chain, void* returnAddress)
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000333 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000334 JIT jit(globalData, codeBlock);
335 jit.privateCompilePutByIdTransition(oldStructure, newStructure, cachedOffset, chain, returnAddress);
oliver@apple.come3c5d0e2008-09-14 08:18:49 +0000336 }
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000337
barraclough@apple.com7c876fc2008-11-11 05:09:46 +0000338 static void compileCTIMachineTrampolines(JSGlobalData* globalData)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000339 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000340 JIT jit(globalData);
341 jit.privateCompileCTIMachineTrampolines();
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000342 }
ggaren@apple.com031563e2008-11-17 02:21:16 +0000343 static void freeCTIMachineTrampolines(Interpreter*);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000344
darin@apple.coma9778f92008-11-16 04:40:06 +0000345 static void patchGetByIdSelf(CodeBlock* codeBlock, Structure* structure, size_t cachedOffset, void* returnAddress);
346 static void patchPutByIdReplace(CodeBlock* codeBlock, Structure* structure, size_t cachedOffset, void* returnAddress);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000347
barraclough@apple.com7c876fc2008-11-11 05:09:46 +0000348 static void compilePatchGetArrayLength(JSGlobalData* globalData, CodeBlock* codeBlock, void* returnAddress)
barraclough@apple.com71500d52008-09-15 02:18:13 +0000349 {
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000350 JIT jit(globalData, codeBlock);
351 return jit.privateCompilePatchGetArrayLength(returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000352 }
353
barraclough@apple.come9642652008-10-23 22:29:54 +0000354 static void linkCall(JSFunction* callee, CodeBlock* calleeCodeBlock, void* ctiCode, CallLinkInfo* callLinkInfo, int callerArgCount);
355 static void unlinkCall(CallLinkInfo*);
barraclough@apple.com3a4eb9b2008-10-18 02:51:52 +0000356
darin@apple.com44331f82008-10-24 16:22:51 +0000357 inline static JSValue* execute(void* code, RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData, JSValue** exception)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000358 {
darin@apple.com8c2bac02008-10-09 00:40:43 +0000359 return ctiTrampoline(code, registerFile, callFrame, exception, Profiler::enabledProfilerReference(), globalData);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000360 }
361
362 private:
ggaren@apple.com4f7d7a92008-11-17 03:34:05 +0000363 JIT(JSGlobalData*, CodeBlock* = 0);
darin@apple.com5a494422008-10-18 23:08:12 +0000364
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000365 void privateCompileMainPass();
366 void privateCompileLinkPass();
367 void privateCompileSlowCases();
368 void privateCompile();
darin@apple.coma9778f92008-11-16 04:40:06 +0000369 void privateCompileGetByIdSelf(Structure*, size_t cachedOffset, void* returnAddress);
370 void privateCompileGetByIdProto(Structure*, Structure* prototypeStructure, size_t cachedOffset, void* returnAddress, CallFrame* callFrame);
371 void privateCompileGetByIdChain(Structure*, StructureChain*, size_t count, size_t cachedOffset, void* returnAddress, CallFrame* callFrame);
372 void privateCompilePutByIdReplace(Structure*, size_t cachedOffset, void* returnAddress);
373 void privateCompilePutByIdTransition(Structure*, Structure*, size_t cachedOffset, StructureChain*, void* returnAddress);
barraclough@apple.com71500d52008-09-15 02:18:13 +0000374
barraclough@apple.com7c876fc2008-11-11 05:09:46 +0000375 void privateCompileCTIMachineTrampolines();
barraclough@apple.com71500d52008-09-15 02:18:13 +0000376 void privateCompilePatchGetArrayLength(void* returnAddress);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000377
ggaren@apple.com47d3f052008-11-15 21:37:49 +0000378 void compileOpCall(OpcodeID, Instruction* instruction, unsigned i, unsigned callLinkInfoIndex);
barraclough@apple.com1bab56d2008-11-15 01:33:36 +0000379 void compileOpCallInitializeCallFrame();
ggaren@apple.com68313b02008-11-13 00:48:23 +0000380 void compileOpCallSetupArgs(Instruction*);
381 void compileOpCallEvalSetupArgs(Instruction*);
382 void compileOpConstructSetupArgs(Instruction*);
mjs@apple.comdb29af22008-09-23 13:20:23 +0000383 enum CompileOpStrictEqType { OpStrictEq, OpNStrictEq };
384 void compileOpStrictEq(Instruction* instruction, unsigned i, CompileOpStrictEqType type);
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000385 void putDoubleResultToJSNumberCellOrJSImmediate(XMMRegisterID xmmSource, RegisterID jsNumberCell, unsigned dst, JmpSrc* wroteJSNumberCell, XMMRegisterID tempXmm, RegisterID tempReg1, RegisterID tempReg2);
ggaren@apple.com47d3f052008-11-15 21:37:49 +0000386 void compileBinaryArithOp(OpcodeID, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i);
387 void compileBinaryArithOpSlowCase(Instruction*, OpcodeID, Vector<SlowCaseEntry>::iterator& iter, unsigned dst, unsigned src1, unsigned src2, OperandTypes opi, unsigned i);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000388
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000389 void emitGetVirtualRegister(int src, RegisterID dst, unsigned i);
390 void emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2, unsigned i);
391 void emitPutVirtualRegister(unsigned dst, RegisterID from = X86::eax);
barraclough@apple.coma5524512008-11-15 02:51:39 +0000392
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000393 void emitPutCTIArg(RegisterID src, unsigned offset);
394 void emitPutCTIArgFromVirtualRegister(unsigned src, unsigned offset, RegisterID scratch);
barraclough@apple.coma5524512008-11-15 02:51:39 +0000395 void emitPutCTIArgConstant(unsigned value, unsigned offset);
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000396 void emitGetCTIArg(unsigned offset, RegisterID dst);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000397
ggaren@apple.com107bd0e2008-09-24 00:27:18 +0000398 void emitInitRegister(unsigned dst);
oliver@apple.comecfd2242008-09-20 03:00:43 +0000399
barraclough@apple.comce5a0b32008-09-16 17:40:01 +0000400 void emitPutCTIParam(void* value, unsigned name);
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000401 void emitPutCTIParam(RegisterID from, unsigned name);
402 void emitGetCTIParam(unsigned name, RegisterID to);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000403
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000404 void emitPutToCallFrameHeader(RegisterID from, RegisterFile::CallFrameHeaderEntry entry);
405 void emitGetFromCallFrameHeader(RegisterFile::CallFrameHeaderEntry entry, RegisterID to);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000406
darin@apple.com44331f82008-10-24 16:22:51 +0000407 JSValue* getConstantImmediateNumericArg(unsigned src);
408 unsigned getDeTaggedConstantImmediate(JSValue* imm);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000409
mjs@apple.come32adbc2008-11-13 12:53:35 +0000410 bool linkSlowCaseIfNotJSCell(const Vector<SlowCaseEntry>::iterator&, int vReg);
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000411 void emitJumpSlowCaseIfNotJSCell(RegisterID, unsigned bytecodeIndex);
412 void emitJumpSlowCaseIfNotJSCell(RegisterID, unsigned bytecodeIndex, int VReg);
weinig@apple.com262302f2008-09-16 03:46:58 +0000413
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000414 void emitJumpSlowCaseIfNotImmNum(RegisterID, unsigned bytecodeIndex);
415 void emitJumpSlowCaseIfNotImmNums(RegisterID, RegisterID, unsigned bytecodeIndex);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000416
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000417 void emitFastArithDeTagImmediate(RegisterID);
418 JmpSrc emitFastArithDeTagImmediateJumpIfZero(RegisterID);
419 void emitFastArithReTagImmediate(RegisterID);
420 void emitFastArithPotentiallyReTagImmediate(RegisterID);
421 void emitFastArithImmToInt(RegisterID);
422 void emitFastArithIntToImmOrSlowCase(RegisterID, unsigned bytecodeIndex);
423 void emitFastArithIntToImmNoCheck(RegisterID);
424 JmpSrc emitArithIntToImmWithJump(RegisterID reg);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000425
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000426 void emitTagAsBoolImmediate(RegisterID reg);
mjs@apple.com40328732008-09-21 10:39:29 +0000427
oliver@apple.com487b61b2008-10-30 04:33:21 +0000428 void emitAllocateNumber(JSGlobalData*, unsigned);
429
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000430 JmpSrc emitNakedCall(unsigned bytecodeIndex, RegisterID);
431 JmpSrc emitNakedCall(unsigned bytecodeIndex, void* function);
432 JmpSrc emitNakedFastCall(unsigned bytecodeIndex, void*);
433 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_j);
434 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_o);
435 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_p);
436 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_v);
437 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_s);
438 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_b);
439 JmpSrc emitCTICall(Instruction*, unsigned bytecodeIndex, CTIHelper_2);
barraclough@apple.com79c9ae12008-10-07 20:27:50 +0000440
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000441 void emitGetVariableObjectRegister(RegisterID variableObject, int index, RegisterID dst);
442 void emitPutVariableObjectRegister(RegisterID src, RegisterID variableObject, int index);
oliver@apple.com957eefc2008-09-10 09:23:35 +0000443
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000444 void emitSlowScriptCheck(Instruction*, unsigned bytecodeIndex);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000445#ifndef NDEBUG
ggaren@apple.com77dd3c62008-11-15 20:34:40 +0000446 void printBytecodeOperandTypes(unsigned src1, unsigned src2);
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000447#endif
448
cwzwarich@webkit.orgeacadfb2008-11-13 11:26:38 +0000449 void killLastResultRegister();
450
ggaren@apple.com4d997cb2008-11-15 22:43:27 +0000451 X86Assembler m_assembler;
ggaren@apple.com031563e2008-11-17 02:21:16 +0000452 Interpreter* m_interpreter;
barraclough@apple.com7c876fc2008-11-11 05:09:46 +0000453 JSGlobalData* m_globalData;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000454 CodeBlock* m_codeBlock;
455
456 Vector<CallRecord> m_calls;
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000457 Vector<JmpDst> m_labels;
barraclough@apple.come9642652008-10-23 22:29:54 +0000458 Vector<StructureStubCompilationInfo> m_propertyAccessCompilationInfo;
459 Vector<StructureStubCompilationInfo> m_callStructureStubCompilationInfo;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000460 Vector<JmpTable> m_jmpTable;
461
462 struct JSRInfo {
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000463 JmpDst addrPosition;
464 JmpDst target;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000465
ggaren@apple.com0bbea112008-11-17 03:21:12 +0000466 JSRInfo(const JmpDst& storeLocation, const JmpDst& targetLocation)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000467 : addrPosition(storeLocation)
468 , target(targetLocation)
469 {
470 }
471 };
472
473 Vector<JSRInfo> m_jsrSites;
474 Vector<SlowCaseEntry> m_slowCases;
475 Vector<SwitchRecord> m_switches;
476
cwzwarich@webkit.orgeacadfb2008-11-13 11:26:38 +0000477 int m_lastResultBytecodeRegister;
478 unsigned m_jumpTargetsPosition;
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000479 };
480}
481
ggaren@apple.comf272d2d2008-11-17 04:25:37 +0000482#endif // ENABLE(JIT)
mrowe@apple.comf88a4632008-09-07 05:44:58 +0000483
484#endif // CTI_h