]>
Commit | Line | Data |
---|---|---|
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 | ||
29 | #include <wtf/Platform.h> | |
30 | ||
31 | #if ENABLE(JIT) | |
32 | ||
33 | #include "ClassInfo.h" | |
34 | #include "CodeLocation.h" | |
35 | #include "IndexingType.h" | |
36 | #include "JITStubRoutine.h" | |
37 | #include "Structure.h" | |
38 | ||
39 | namespace JSC { | |
40 | ||
41 | enum JITArrayMode { | |
42 | JITInt32, | |
43 | JITDouble, | |
44 | JITContiguous, | |
45 | JITArrayStorage, | |
46 | JITInt8Array, | |
47 | JITInt16Array, | |
48 | JITInt32Array, | |
49 | JITUint8Array, | |
50 | JITUint8ClampedArray, | |
51 | JITUint16Array, | |
52 | JITUint32Array, | |
53 | JITFloat32Array, | |
54 | JITFloat64Array | |
55 | }; | |
56 | ||
57 | inline 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 | ||
70 | inline bool hasOptimizableIndexingForClassInfo(const ClassInfo* classInfo) | |
71 | { | |
72 | return classInfo->typedArrayStorageType != TypedArrayNone; | |
73 | } | |
74 | ||
75 | inline bool hasOptimizableIndexing(Structure* structure) | |
76 | { | |
77 | return isOptimizableIndexingType(structure->indexingType()) | |
78 | || hasOptimizableIndexingForClassInfo(structure->classInfo()); | |
79 | } | |
80 | ||
81 | inline JITArrayMode jitArrayModeForIndexingType(IndexingType indexingType) | |
82 | { | |
83 | switch (indexingType) { | |
84 | case ALL_INT32_INDEXING_TYPES: | |
85 | return JITInt32; | |
86 | case ALL_DOUBLE_INDEXING_TYPES: | |
87 | return JITDouble; | |
88 | case ALL_CONTIGUOUS_INDEXING_TYPES: | |
89 | return JITContiguous; | |
90 | case ARRAY_WITH_ARRAY_STORAGE_INDEXING_TYPES: | |
91 | return JITArrayStorage; | |
92 | default: | |
93 | CRASH(); | |
94 | return JITContiguous; | |
95 | } | |
96 | } | |
97 | ||
98 | inline JITArrayMode jitArrayModeForClassInfo(const ClassInfo* classInfo) | |
99 | { | |
100 | switch (classInfo->typedArrayStorageType) { | |
101 | case TypedArrayInt8: | |
102 | return JITInt8Array; | |
103 | case TypedArrayInt16: | |
104 | return JITInt16Array; | |
105 | case TypedArrayInt32: | |
106 | return JITInt32Array; | |
107 | case TypedArrayUint8: | |
108 | return JITUint8Array; | |
109 | case TypedArrayUint8Clamped: | |
110 | return JITUint8ClampedArray; | |
111 | case TypedArrayUint16: | |
112 | return JITUint16Array; | |
113 | case TypedArrayUint32: | |
114 | return JITUint32Array; | |
115 | case TypedArrayFloat32: | |
116 | return JITFloat32Array; | |
117 | case TypedArrayFloat64: | |
118 | return JITFloat64Array; | |
119 | default: | |
120 | CRASH(); | |
121 | return JITContiguous; | |
122 | } | |
123 | } | |
124 | ||
125 | inline JITArrayMode jitArrayModeForStructure(Structure* structure) | |
126 | { | |
127 | if (isOptimizableIndexingType(structure->indexingType())) | |
128 | return jitArrayModeForIndexingType(structure->indexingType()); | |
129 | ||
130 | ASSERT(hasOptimizableIndexingForClassInfo(structure->classInfo())); | |
131 | return jitArrayModeForClassInfo(structure->classInfo()); | |
132 | } | |
133 | ||
134 | struct ByValInfo { | |
135 | ByValInfo() { } | |
136 | ||
137 | ByValInfo(unsigned bytecodeIndex, CodeLocationJump badTypeJump, JITArrayMode arrayMode, int16_t badTypeJumpToDone, int16_t returnAddressToSlowPath) | |
138 | : bytecodeIndex(bytecodeIndex) | |
139 | , badTypeJump(badTypeJump) | |
140 | , arrayMode(arrayMode) | |
141 | , badTypeJumpToDone(badTypeJumpToDone) | |
142 | , returnAddressToSlowPath(returnAddressToSlowPath) | |
143 | , slowPathCount(0) | |
144 | { | |
145 | } | |
146 | ||
147 | unsigned bytecodeIndex; | |
148 | CodeLocationJump badTypeJump; | |
149 | JITArrayMode arrayMode; // The array mode that was baked into the inline JIT code. | |
150 | int16_t badTypeJumpToDone; | |
151 | int16_t returnAddressToSlowPath; | |
152 | unsigned slowPathCount; | |
153 | RefPtr<JITStubRoutine> stubRoutine; | |
154 | }; | |
155 | ||
156 | inline unsigned getByValInfoBytecodeIndex(ByValInfo* info) | |
157 | { | |
158 | return info->bytecodeIndex; | |
159 | } | |
160 | ||
161 | } // namespace JSC | |
162 | ||
163 | #endif // ENABLE(JIT) | |
164 | ||
165 | #endif // ByValInfo_h | |
166 |