]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/ByValInfo.h
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / bytecode / ByValInfo.h
CommitLineData
93a37866 1/*
ed1e77d3 2 * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
93a37866
A
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 ByValInfo_h
27#define ByValInfo_h
28
93a37866
A
29#if ENABLE(JIT)
30
31#include "ClassInfo.h"
32#include "CodeLocation.h"
33#include "IndexingType.h"
34#include "JITStubRoutine.h"
35#include "Structure.h"
36
37namespace JSC {
38
39enum JITArrayMode {
40 JITInt32,
41 JITDouble,
42 JITContiguous,
43 JITArrayStorage,
ed1e77d3
A
44 JITDirectArguments,
45 JITScopedArguments,
93a37866
A
46 JITInt8Array,
47 JITInt16Array,
48 JITInt32Array,
49 JITUint8Array,
50 JITUint8ClampedArray,
51 JITUint16Array,
52 JITUint32Array,
53 JITFloat32Array,
54 JITFloat64Array
55};
56
57inline bool isOptimizableIndexingType(IndexingType indexingType)
58{
59 switch (indexingType) {
60 case ALL_INT32_INDEXING_TYPES:
61 case ALL_DOUBLE_INDEXING_TYPES:
62 case ALL_CONTIGUOUS_INDEXING_TYPES:
63 case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
64 return true;
65 default:
66 return false;
67 }
68}
69
ed1e77d3
A
70inline bool hasOptimizableIndexingForJSType(JSType type)
71{
72 switch (type) {
73 case DirectArgumentsType:
74 case ScopedArgumentsType:
75 return true;
76 default:
77 return false;
78 }
79}
80
93a37866
A
81inline bool hasOptimizableIndexingForClassInfo(const ClassInfo* classInfo)
82{
81345200 83 return isTypedView(classInfo->typedArrayStorageType);
93a37866
A
84}
85
86inline bool hasOptimizableIndexing(Structure* structure)
87{
88 return isOptimizableIndexingType(structure->indexingType())
ed1e77d3 89 || hasOptimizableIndexingForJSType(structure->typeInfo().type())
93a37866
A
90 || hasOptimizableIndexingForClassInfo(structure->classInfo());
91}
92
93inline JITArrayMode jitArrayModeForIndexingType(IndexingType indexingType)
94{
95 switch (indexingType) {
96 case ALL_INT32_INDEXING_TYPES:
97 return JITInt32;
98 case ALL_DOUBLE_INDEXING_TYPES:
99 return JITDouble;
100 case ALL_CONTIGUOUS_INDEXING_TYPES:
101 return JITContiguous;
102 case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
103 return JITArrayStorage;
104 default:
105 CRASH();
106 return JITContiguous;
107 }
108}
109
ed1e77d3
A
110inline JITArrayMode jitArrayModeForJSType(JSType type)
111{
112 switch (type) {
113 case DirectArgumentsType:
114 return JITDirectArguments;
115 case ScopedArgumentsType:
116 return JITScopedArguments;
117 default:
118 RELEASE_ASSERT_NOT_REACHED();
119 return JITContiguous;
120 }
121}
122
93a37866
A
123inline JITArrayMode jitArrayModeForClassInfo(const ClassInfo* classInfo)
124{
125 switch (classInfo->typedArrayStorageType) {
81345200 126 case TypeInt8:
93a37866 127 return JITInt8Array;
81345200 128 case TypeInt16:
93a37866 129 return JITInt16Array;
81345200 130 case TypeInt32:
93a37866 131 return JITInt32Array;
81345200 132 case TypeUint8:
93a37866 133 return JITUint8Array;
81345200 134 case TypeUint8Clamped:
93a37866 135 return JITUint8ClampedArray;
81345200 136 case TypeUint16:
93a37866 137 return JITUint16Array;
81345200 138 case TypeUint32:
93a37866 139 return JITUint32Array;
81345200 140 case TypeFloat32:
93a37866 141 return JITFloat32Array;
81345200 142 case TypeFloat64:
93a37866
A
143 return JITFloat64Array;
144 default:
145 CRASH();
146 return JITContiguous;
147 }
148}
149
ed1e77d3
A
150inline bool jitArrayModePermitsPut(JITArrayMode mode)
151{
152 switch (mode) {
153 case JITDirectArguments:
154 case JITScopedArguments:
155 // We could support put_by_val on these at some point, but it's just not that profitable
156 // at the moment.
157 return false;
158 default:
159 return true;
160 }
161}
162
81345200
A
163inline TypedArrayType typedArrayTypeForJITArrayMode(JITArrayMode mode)
164{
165 switch (mode) {
166 case JITInt8Array:
167 return TypeInt8;
168 case JITInt16Array:
169 return TypeInt16;
170 case JITInt32Array:
171 return TypeInt32;
172 case JITUint8Array:
173 return TypeUint8;
174 case JITUint8ClampedArray:
175 return TypeUint8Clamped;
176 case JITUint16Array:
177 return TypeUint16;
178 case JITUint32Array:
179 return TypeUint32;
180 case JITFloat32Array:
181 return TypeFloat32;
182 case JITFloat64Array:
183 return TypeFloat64;
184 default:
185 CRASH();
186 return NotTypedArray;
187 }
188}
189
93a37866
A
190inline JITArrayMode jitArrayModeForStructure(Structure* structure)
191{
192 if (isOptimizableIndexingType(structure->indexingType()))
193 return jitArrayModeForIndexingType(structure->indexingType());
194
ed1e77d3
A
195 if (hasOptimizableIndexingForJSType(structure->typeInfo().type()))
196 return jitArrayModeForJSType(structure->typeInfo().type());
197
93a37866
A
198 ASSERT(hasOptimizableIndexingForClassInfo(structure->classInfo()));
199 return jitArrayModeForClassInfo(structure->classInfo());
200}
201
202struct ByValInfo {
203 ByValInfo() { }
204
205 ByValInfo(unsigned bytecodeIndex, CodeLocationJump badTypeJump, JITArrayMode arrayMode, int16_t badTypeJumpToDone, int16_t returnAddressToSlowPath)
206 : bytecodeIndex(bytecodeIndex)
207 , badTypeJump(badTypeJump)
208 , arrayMode(arrayMode)
209 , badTypeJumpToDone(badTypeJumpToDone)
210 , returnAddressToSlowPath(returnAddressToSlowPath)
211 , slowPathCount(0)
212 {
213 }
214
215 unsigned bytecodeIndex;
216 CodeLocationJump badTypeJump;
217 JITArrayMode arrayMode; // The array mode that was baked into the inline JIT code.
218 int16_t badTypeJumpToDone;
219 int16_t returnAddressToSlowPath;
220 unsigned slowPathCount;
221 RefPtr<JITStubRoutine> stubRoutine;
222};
223
224inline unsigned getByValInfoBytecodeIndex(ByValInfo* info)
225{
226 return info->bytecodeIndex;
227}
228
229} // namespace JSC
230
231#endif // ENABLE(JIT)
232
233#endif // ByValInfo_h
234