Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / js / src / jit / InlinableNatives.cpp
blob3d74e40278838b9c21db8f79ef36d11eb1e46667
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "jit/InlinableNatives.h"
9 #ifdef JS_HAS_INTL_API
10 # include "builtin/intl/Collator.h"
11 # include "builtin/intl/DateTimeFormat.h"
12 # include "builtin/intl/DisplayNames.h"
13 # include "builtin/intl/ListFormat.h"
14 # include "builtin/intl/NumberFormat.h"
15 # include "builtin/intl/PluralRules.h"
16 # include "builtin/intl/RelativeTimeFormat.h"
17 # include "builtin/intl/Segmenter.h"
18 #endif
19 #include "builtin/MapObject.h"
20 #include "js/experimental/JitInfo.h"
21 #include "vm/ArrayBufferObject.h"
22 #include "vm/AsyncIteration.h"
23 #include "vm/Iteration.h"
24 #include "vm/SharedArrayObject.h"
26 using namespace js;
27 using namespace js::jit;
29 #define ADD_NATIVE(native) \
30 const JSJitInfo js::jit::JitInfo_##native{ \
31 {nullptr}, \
32 {uint16_t(InlinableNative::native)}, \
33 {0}, \
34 JSJitInfo::InlinableNative};
35 INLINABLE_NATIVE_LIST(ADD_NATIVE)
36 #undef ADD_NATIVE
38 const JSClass* js::jit::InlinableNativeGuardToClass(InlinableNative native) {
39 switch (native) {
40 #ifdef JS_HAS_INTL_API
41 // Intl natives.
42 case InlinableNative::IntlGuardToCollator:
43 return &CollatorObject::class_;
44 case InlinableNative::IntlGuardToDateTimeFormat:
45 return &DateTimeFormatObject::class_;
46 case InlinableNative::IntlGuardToDisplayNames:
47 return &DisplayNamesObject::class_;
48 case InlinableNative::IntlGuardToListFormat:
49 return &ListFormatObject::class_;
50 case InlinableNative::IntlGuardToNumberFormat:
51 return &NumberFormatObject::class_;
52 case InlinableNative::IntlGuardToPluralRules:
53 return &PluralRulesObject::class_;
54 case InlinableNative::IntlGuardToRelativeTimeFormat:
55 return &RelativeTimeFormatObject::class_;
56 case InlinableNative::IntlGuardToSegmenter:
57 return &SegmenterObject::class_;
58 case InlinableNative::IntlGuardToSegments:
59 return &SegmentsObject::class_;
60 case InlinableNative::IntlGuardToSegmentIterator:
61 return &SegmentIteratorObject::class_;
62 #else
63 case InlinableNative::IntlGuardToCollator:
64 case InlinableNative::IntlGuardToDateTimeFormat:
65 case InlinableNative::IntlGuardToDisplayNames:
66 case InlinableNative::IntlGuardToListFormat:
67 case InlinableNative::IntlGuardToNumberFormat:
68 case InlinableNative::IntlGuardToPluralRules:
69 case InlinableNative::IntlGuardToRelativeTimeFormat:
70 case InlinableNative::IntlGuardToSegmenter:
71 case InlinableNative::IntlGuardToSegments:
72 case InlinableNative::IntlGuardToSegmentIterator:
73 MOZ_CRASH("Intl API disabled");
74 #endif
76 // Utility intrinsics.
77 case InlinableNative::IntrinsicGuardToArrayIterator:
78 return &ArrayIteratorObject::class_;
79 case InlinableNative::IntrinsicGuardToMapIterator:
80 return &MapIteratorObject::class_;
81 case InlinableNative::IntrinsicGuardToSetIterator:
82 return &SetIteratorObject::class_;
83 case InlinableNative::IntrinsicGuardToStringIterator:
84 return &StringIteratorObject::class_;
85 case InlinableNative::IntrinsicGuardToRegExpStringIterator:
86 return &RegExpStringIteratorObject::class_;
87 case InlinableNative::IntrinsicGuardToWrapForValidIterator:
88 return &WrapForValidIteratorObject::class_;
89 case InlinableNative::IntrinsicGuardToIteratorHelper:
90 return &IteratorHelperObject::class_;
91 case InlinableNative::IntrinsicGuardToAsyncIteratorHelper:
92 return &AsyncIteratorHelperObject::class_;
94 case InlinableNative::IntrinsicGuardToMapObject:
95 return &MapObject::class_;
96 case InlinableNative::IntrinsicGuardToSetObject:
97 return &SetObject::class_;
98 case InlinableNative::IntrinsicGuardToArrayBuffer:
99 return &FixedLengthArrayBufferObject::class_;
100 case InlinableNative::IntrinsicGuardToSharedArrayBuffer:
101 return &FixedLengthSharedArrayBufferObject::class_;
103 default:
104 MOZ_CRASH("Not a GuardTo instruction");
108 // Returns true if |native| can be inlined cross-realm. Especially inlined
109 // natives that can allocate objects or throw exceptions shouldn't be inlined
110 // cross-realm without a careful analysis because we might use the wrong realm!
112 // Note that self-hosting intrinsics are never called cross-realm. See the
113 // MOZ_CRASH below.
115 // If you are adding a new inlinable native, the safe thing is to |return false|
116 // here.
117 bool js::jit::CanInlineNativeCrossRealm(InlinableNative native) {
118 switch (native) {
119 case InlinableNative::MathAbs:
120 case InlinableNative::MathFloor:
121 case InlinableNative::MathCeil:
122 case InlinableNative::MathRound:
123 case InlinableNative::MathClz32:
124 case InlinableNative::MathSqrt:
125 case InlinableNative::MathATan2:
126 case InlinableNative::MathHypot:
127 case InlinableNative::MathMax:
128 case InlinableNative::MathMin:
129 case InlinableNative::MathPow:
130 case InlinableNative::MathImul:
131 case InlinableNative::MathFRound:
132 case InlinableNative::MathTrunc:
133 case InlinableNative::MathSign:
134 case InlinableNative::MathSin:
135 case InlinableNative::MathTan:
136 case InlinableNative::MathCos:
137 case InlinableNative::MathExp:
138 case InlinableNative::MathLog:
139 case InlinableNative::MathASin:
140 case InlinableNative::MathATan:
141 case InlinableNative::MathACos:
142 case InlinableNative::MathLog10:
143 case InlinableNative::MathLog2:
144 case InlinableNative::MathLog1P:
145 case InlinableNative::MathExpM1:
146 case InlinableNative::MathCosH:
147 case InlinableNative::MathSinH:
148 case InlinableNative::MathTanH:
149 case InlinableNative::MathACosH:
150 case InlinableNative::MathASinH:
151 case InlinableNative::MathATanH:
152 case InlinableNative::MathCbrt:
153 case InlinableNative::Boolean:
154 return true;
156 case InlinableNative::Array:
157 // Cross-realm case handled by inlineArray.
158 return true;
160 case InlinableNative::MathRandom:
161 // RNG state is per-realm.
162 return false;
164 case InlinableNative::IntlGuardToCollator:
165 case InlinableNative::IntlGuardToDateTimeFormat:
166 case InlinableNative::IntlGuardToDisplayNames:
167 case InlinableNative::IntlGuardToListFormat:
168 case InlinableNative::IntlGuardToNumberFormat:
169 case InlinableNative::IntlGuardToPluralRules:
170 case InlinableNative::IntlGuardToRelativeTimeFormat:
171 case InlinableNative::IntlGuardToSegmenter:
172 case InlinableNative::IntlGuardToSegments:
173 case InlinableNative::IntlGuardToSegmentIterator:
174 case InlinableNative::IsRegExpObject:
175 case InlinableNative::IsPossiblyWrappedRegExpObject:
176 case InlinableNative::RegExpMatcher:
177 case InlinableNative::RegExpSearcher:
178 case InlinableNative::RegExpSearcherLastLimit:
179 case InlinableNative::RegExpHasCaptureGroups:
180 case InlinableNative::RegExpPrototypeOptimizable:
181 case InlinableNative::RegExpInstanceOptimizable:
182 case InlinableNative::GetFirstDollarIndex:
183 case InlinableNative::IntrinsicNewArrayIterator:
184 case InlinableNative::IntrinsicNewStringIterator:
185 case InlinableNative::IntrinsicNewRegExpStringIterator:
186 case InlinableNative::IntrinsicStringReplaceString:
187 case InlinableNative::IntrinsicStringSplitString:
188 case InlinableNative::IntrinsicUnsafeSetReservedSlot:
189 case InlinableNative::IntrinsicUnsafeGetReservedSlot:
190 case InlinableNative::IntrinsicUnsafeGetObjectFromReservedSlot:
191 case InlinableNative::IntrinsicUnsafeGetInt32FromReservedSlot:
192 case InlinableNative::IntrinsicUnsafeGetStringFromReservedSlot:
193 case InlinableNative::IntrinsicIsCallable:
194 case InlinableNative::IntrinsicIsConstructor:
195 case InlinableNative::IntrinsicToObject:
196 case InlinableNative::IntrinsicIsObject:
197 case InlinableNative::IntrinsicIsCrossRealmArrayConstructor:
198 case InlinableNative::IntrinsicToInteger:
199 case InlinableNative::IntrinsicToLength:
200 case InlinableNative::IntrinsicIsConstructing:
201 case InlinableNative::IntrinsicIsSuspendedGenerator:
202 case InlinableNative::IntrinsicSubstringKernel:
203 case InlinableNative::IntrinsicGuardToArrayIterator:
204 case InlinableNative::IntrinsicGuardToMapIterator:
205 case InlinableNative::IntrinsicGuardToSetIterator:
206 case InlinableNative::IntrinsicGuardToStringIterator:
207 case InlinableNative::IntrinsicGuardToRegExpStringIterator:
208 case InlinableNative::IntrinsicGuardToWrapForValidIterator:
209 case InlinableNative::IntrinsicGuardToIteratorHelper:
210 case InlinableNative::IntrinsicGuardToAsyncIteratorHelper:
211 case InlinableNative::IntrinsicObjectHasPrototype:
212 case InlinableNative::IntrinsicIsPackedArray:
213 case InlinableNative::IntrinsicGuardToMapObject:
214 case InlinableNative::IntrinsicGetNextMapEntryForIterator:
215 case InlinableNative::IntrinsicGuardToSetObject:
216 case InlinableNative::IntrinsicGetNextSetEntryForIterator:
217 case InlinableNative::IntrinsicGuardToArrayBuffer:
218 case InlinableNative::IntrinsicArrayBufferByteLength:
219 case InlinableNative::IntrinsicPossiblyWrappedArrayBufferByteLength:
220 case InlinableNative::IntrinsicGuardToSharedArrayBuffer:
221 case InlinableNative::IntrinsicIsTypedArrayConstructor:
222 case InlinableNative::IntrinsicIsTypedArray:
223 case InlinableNative::IntrinsicIsPossiblyWrappedTypedArray:
224 case InlinableNative::IntrinsicPossiblyWrappedTypedArrayLength:
225 case InlinableNative::IntrinsicRegExpBuiltinExec:
226 case InlinableNative::IntrinsicRegExpBuiltinExecForTest:
227 case InlinableNative::IntrinsicRegExpExec:
228 case InlinableNative::IntrinsicRegExpExecForTest:
229 case InlinableNative::IntrinsicTypedArrayLength:
230 case InlinableNative::IntrinsicTypedArrayLengthZeroOnOutOfBounds:
231 case InlinableNative::IntrinsicTypedArrayByteOffset:
232 case InlinableNative::IntrinsicTypedArrayElementSize:
233 case InlinableNative::IntrinsicArrayIteratorPrototypeOptimizable:
234 MOZ_CRASH("Unexpected cross-realm intrinsic call");
236 case InlinableNative::TestBailout:
237 case InlinableNative::TestAssertFloat32:
238 case InlinableNative::TestAssertRecoveredOnBailout:
239 // Testing functions, not worth inlining cross-realm.
240 return false;
242 case InlinableNative::ArrayIsArray:
243 case InlinableNative::ArrayJoin:
244 case InlinableNative::ArrayPop:
245 case InlinableNative::ArrayShift:
246 case InlinableNative::ArrayPush:
247 case InlinableNative::ArraySlice:
248 case InlinableNative::AtomicsCompareExchange:
249 case InlinableNative::AtomicsExchange:
250 case InlinableNative::AtomicsLoad:
251 case InlinableNative::AtomicsStore:
252 case InlinableNative::AtomicsAdd:
253 case InlinableNative::AtomicsSub:
254 case InlinableNative::AtomicsAnd:
255 case InlinableNative::AtomicsOr:
256 case InlinableNative::AtomicsXor:
257 case InlinableNative::AtomicsIsLockFree:
258 case InlinableNative::BigIntAsIntN:
259 case InlinableNative::BigIntAsUintN:
260 case InlinableNative::DataViewGetInt8:
261 case InlinableNative::DataViewGetUint8:
262 case InlinableNative::DataViewGetInt16:
263 case InlinableNative::DataViewGetUint16:
264 case InlinableNative::DataViewGetInt32:
265 case InlinableNative::DataViewGetUint32:
266 case InlinableNative::DataViewGetFloat32:
267 case InlinableNative::DataViewGetFloat64:
268 case InlinableNative::DataViewGetBigInt64:
269 case InlinableNative::DataViewGetBigUint64:
270 case InlinableNative::DataViewSetInt8:
271 case InlinableNative::DataViewSetUint8:
272 case InlinableNative::DataViewSetInt16:
273 case InlinableNative::DataViewSetUint16:
274 case InlinableNative::DataViewSetInt32:
275 case InlinableNative::DataViewSetUint32:
276 case InlinableNative::DataViewSetFloat32:
277 case InlinableNative::DataViewSetFloat64:
278 case InlinableNative::DataViewSetBigInt64:
279 case InlinableNative::DataViewSetBigUint64:
280 case InlinableNative::FunctionBind:
281 case InlinableNative::MapGet:
282 case InlinableNative::MapHas:
283 case InlinableNative::Number:
284 case InlinableNative::NumberParseInt:
285 case InlinableNative::NumberToString:
286 case InlinableNative::ReflectGetPrototypeOf:
287 case InlinableNative::SetHas:
288 case InlinableNative::SetSize:
289 case InlinableNative::String:
290 case InlinableNative::StringToString:
291 case InlinableNative::StringValueOf:
292 case InlinableNative::StringCharCodeAt:
293 case InlinableNative::StringCodePointAt:
294 case InlinableNative::StringFromCharCode:
295 case InlinableNative::StringFromCodePoint:
296 case InlinableNative::StringCharAt:
297 case InlinableNative::StringAt:
298 case InlinableNative::StringIncludes:
299 case InlinableNative::StringIndexOf:
300 case InlinableNative::StringLastIndexOf:
301 case InlinableNative::StringStartsWith:
302 case InlinableNative::StringEndsWith:
303 case InlinableNative::StringToLowerCase:
304 case InlinableNative::StringToUpperCase:
305 case InlinableNative::StringTrim:
306 case InlinableNative::StringTrimStart:
307 case InlinableNative::StringTrimEnd:
308 case InlinableNative::Object:
309 case InlinableNative::ObjectCreate:
310 case InlinableNative::ObjectIs:
311 case InlinableNative::ObjectIsPrototypeOf:
312 case InlinableNative::ObjectKeys:
313 case InlinableNative::ObjectToString:
314 case InlinableNative::TypedArrayConstructor:
315 #ifdef FUZZING_JS_FUZZILLI
316 case InlinableNative::FuzzilliHash:
317 #endif
318 // Default to false for most natives.
319 return false;
321 case InlinableNative::Limit:
322 break;
324 MOZ_CRASH("Unknown native");