]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/ByValInfo.h
JavaScriptCore-7600.1.4.11.8.tar.gz
[apple/javascriptcore.git] / bytecode / ByValInfo.h
CommitLineData
93a37866
A
1/*
2 * Copyright (C) 2012 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 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,
44 JITInt8Array,
45 JITInt16Array,
46 JITInt32Array,
47 JITUint8Array,
48 JITUint8ClampedArray,
49 JITUint16Array,
50 JITUint32Array,
51 JITFloat32Array,
52 JITFloat64Array
53};
54
55inline bool isOptimizableIndexingType(IndexingType indexingType)
56{
57 switch (indexingType) {
58 case ALL_INT32_INDEXING_TYPES:
59 case ALL_DOUBLE_INDEXING_TYPES:
60 case ALL_CONTIGUOUS_INDEXING_TYPES:
61 case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
62 return true;
63 default:
64 return false;
65 }
66}
67
68inline bool hasOptimizableIndexingForClassInfo(const ClassInfo* classInfo)
69{
81345200 70 return isTypedView(classInfo->typedArrayStorageType);
93a37866
A
71}
72
73inline bool hasOptimizableIndexing(Structure* structure)
74{
75 return isOptimizableIndexingType(structure->indexingType())
76 || hasOptimizableIndexingForClassInfo(structure->classInfo());
77}
78
79inline JITArrayMode jitArrayModeForIndexingType(IndexingType indexingType)
80{
81 switch (indexingType) {
82 case ALL_INT32_INDEXING_TYPES:
83 return JITInt32;
84 case ALL_DOUBLE_INDEXING_TYPES:
85 return JITDouble;
86 case ALL_CONTIGUOUS_INDEXING_TYPES:
87 return JITContiguous;
88 case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES:
89 return JITArrayStorage;
90 default:
91 CRASH();
92 return JITContiguous;
93 }
94}
95
96inline JITArrayMode jitArrayModeForClassInfo(const ClassInfo* classInfo)
97{
98 switch (classInfo->typedArrayStorageType) {
81345200 99 case TypeInt8:
93a37866 100 return JITInt8Array;
81345200 101 case TypeInt16:
93a37866 102 return JITInt16Array;
81345200 103 case TypeInt32:
93a37866 104 return JITInt32Array;
81345200 105 case TypeUint8:
93a37866 106 return JITUint8Array;
81345200 107 case TypeUint8Clamped:
93a37866 108 return JITUint8ClampedArray;
81345200 109 case TypeUint16:
93a37866 110 return JITUint16Array;
81345200 111 case TypeUint32:
93a37866 112 return JITUint32Array;
81345200 113 case TypeFloat32:
93a37866 114 return JITFloat32Array;
81345200 115 case TypeFloat64:
93a37866
A
116 return JITFloat64Array;
117 default:
118 CRASH();
119 return JITContiguous;
120 }
121}
122
81345200
A
123inline TypedArrayType typedArrayTypeForJITArrayMode(JITArrayMode mode)
124{
125 switch (mode) {
126 case JITInt8Array:
127 return TypeInt8;
128 case JITInt16Array:
129 return TypeInt16;
130 case JITInt32Array:
131 return TypeInt32;
132 case JITUint8Array:
133 return TypeUint8;
134 case JITUint8ClampedArray:
135 return TypeUint8Clamped;
136 case JITUint16Array:
137 return TypeUint16;
138 case JITUint32Array:
139 return TypeUint32;
140 case JITFloat32Array:
141 return TypeFloat32;
142 case JITFloat64Array:
143 return TypeFloat64;
144 default:
145 CRASH();
146 return NotTypedArray;
147 }
148}
149
93a37866
A
150inline JITArrayMode jitArrayModeForStructure(Structure* structure)
151{
152 if (isOptimizableIndexingType(structure->indexingType()))
153 return jitArrayModeForIndexingType(structure->indexingType());
154
155 ASSERT(hasOptimizableIndexingForClassInfo(structure->classInfo()));
156 return jitArrayModeForClassInfo(structure->classInfo());
157}
158
159struct ByValInfo {
160 ByValInfo() { }
161
162 ByValInfo(unsigned bytecodeIndex, CodeLocationJump badTypeJump, JITArrayMode arrayMode, int16_t badTypeJumpToDone, int16_t returnAddressToSlowPath)
163 : bytecodeIndex(bytecodeIndex)
164 , badTypeJump(badTypeJump)
165 , arrayMode(arrayMode)
166 , badTypeJumpToDone(badTypeJumpToDone)
167 , returnAddressToSlowPath(returnAddressToSlowPath)
168 , slowPathCount(0)
169 {
170 }
171
172 unsigned bytecodeIndex;
173 CodeLocationJump badTypeJump;
174 JITArrayMode arrayMode; // The array mode that was baked into the inline JIT code.
175 int16_t badTypeJumpToDone;
176 int16_t returnAddressToSlowPath;
177 unsigned slowPathCount;
178 RefPtr<JITStubRoutine> stubRoutine;
179};
180
181inline unsigned getByValInfoBytecodeIndex(ByValInfo* info)
182{
183 return info->bytecodeIndex;
184}
185
186} // namespace JSC
187
188#endif // ENABLE(JIT)
189
190#endif // ByValInfo_h
191