Debian Codegraph @

js/src/jit/ABIFunctionList-inl.h

raw
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/. */
6
7 #ifndef jit_ABIFunctionList_inl_h
8 #define jit_ABIFunctionList_inl_h
9
10 #include "mozilla/MacroArgs.h" // MOZ_CONCAT
11 #include "mozilla/SIMD.h" // mozilla::SIMD::memchr{,2x}{8,16}
12
13 #include "jslibmath.h" // js::NumberMod
14 #include "jsmath.h" // js::ecmaPow, js::ecmaHypot, js::hypot3, js::hypot4,
15 // js::ecmaAtan2, js::UnaryMathFunctionType, js::powi
16 #include "jsnum.h" // js::StringToNumberPure, js::Int32ToStringPure,
17 // js::NumberToStringPure
18
19 #include "builtin/Array.h" // js::ArrayShiftMoveElements
20 #include "builtin/MapObject.h" // js::MapIteratorObject::next,
21 // js::SetIteratorObject::next
22 #include "builtin/Object.h" // js::ObjectClassToString
23 #include "builtin/RegExp.h" // js::RegExpPrototypeOptimizableRaw,
24 // js::RegExpInstanceOptimizableRaw
25 #include "builtin/Sorting.h" // js::ArraySortData
26 #include "builtin/TestingFunctions.h" // js::FuzzilliHash*
27
28 #include "irregexp/RegExpAPI.h"
29 // js::irregexp::CaseInsensitiveCompareNonUnicode,
30 // js::irregexp::CaseInsensitiveCompareUnicode,
31 // js::irregexp::GrowBacktrackStack,
32 // js::irregexp::IsCharacterInRangeArray
33
34 #include "jit/ABIFunctions.h"
35 #include "jit/Bailouts.h" // js::jit::FinishBailoutToBaseline, js::jit::Bailout,
36 // js::jit::InvalidationBailout
37
38 #include "jit/Ion.h" // js::jit::LazyLinkTopActivation
39 #include "jit/JitFrames.h" // HandleException
40 #include "jit/VMFunctions.h" // Rest of js::jit::* functions.
41
42 #include "js/CallArgs.h" // JSNative
43 #include "js/Conversions.h" // JS::ToInt32
44 // JSJitGetterOp, JSJitSetterOp, JSJitMethodOp
45 #include "js/experimental/JitInfo.h"
46
47 #include "proxy/Proxy.h" // js::ProxyGetProperty
48
49 #include "vm/ArgumentsObject.h" // js::ArgumentsObject::finishForIonPure
50 #include "vm/Interpreter.h" // js::TypeOfObject
51 #include "vm/NativeObject.h" // js::NativeObject
52 #include "vm/RegExpShared.h" // js::ExecuteRegExpAtomRaw
53 #include "vm/TypedArrayObject.h" // js::TypedArraySortFromJit
54 #include "wasm/WasmBuiltins.h" // js::wasm::*
55
56 #include "builtin/Boolean-inl.h" // js::EmulatesUndefined
57
58 namespace js {
59
60 namespace wasm {
61
62 class AnyRef;
63
64 } // namespace wasm
65
66 namespace jit {
67
68 // List of all ABI functions to be used with callWithABI. Each entry stores
69 // the fully qualified name of the C++ function. This list must be sorted.
70 #if JS_GC_PROBES
71 # define ABIFUNCTION_JS_GC_PROBES_LIST(_) _(js::jit::TraceCreateObject)
72 #else
73 # define ABIFUNCTION_JS_GC_PROBES_LIST(_)
74 #endif
75
76 #if defined(JS_CODEGEN_ARM)
77 # define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_) \
78 _(__aeabi_idivmod) \
79 _(__aeabi_uidivmod)
80 #else
81 # define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_)
82 #endif
83
84 #ifdef WASM_CODEGEN_DEBUG
85 # define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_) \
86 _(js::wasm::PrintF32) \
87 _(js::wasm::PrintF64) \
88 _(js::wasm::PrintI32) \
89 _(js::wasm::PrintPtr) \
90 _(js::wasm::PrintText)
91 #else
92 # define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_)
93 #endif
94
95 #ifdef FUZZING_JS_FUZZILLI
96 # define ABIFUNCTION_FUZZILLI_LIST(_) _(js::FuzzilliHashBigInt)
97 #else
98 # define ABIFUNCTION_FUZZILLI_LIST(_)
99 #endif
100
101 #define ABIFUNCTION_LIST(_) \
102 ABIFUNCTION_JS_GC_PROBES_LIST(_) \
103 ABIFUNCTION_JS_CODEGEN_ARM_LIST(_) \
104 ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_) \
105 _(js::ArgumentsObject::finishForIonPure) \
106 _(js::ArgumentsObject::finishInlineForIonPure) \
107 _(js::ArrayShiftMoveElements) \
108 _(js::ArraySortData::sortArrayWithComparator) \
109 _(js::ArraySortData::sortTypedArrayWithComparator) \
110 _(js::ArraySortFromJit) \
111 _(js::ecmaAtan2) \
112 _(js::ecmaHypot) \
113 _(js::ecmaPow) \
114 _(js::EmulatesUndefined) \
115 _(js::EmulatesUndefinedCheckFuse) \
116 _(js::ExecuteRegExpAtomRaw) \
117 _(js::hypot3) \
118 _(js::hypot4) \
119 _(js::Interpret) \
120 _(js::Int32ToStringPure) \
121 _(js::irregexp::CaseInsensitiveCompareNonUnicode) \
122 _(js::irregexp::CaseInsensitiveCompareUnicode) \
123 _(js::irregexp::GrowBacktrackStack) \
124 _(js::irregexp::IsCharacterInRangeArray) \
125 _(js::jit::AllocateAndInitTypedArrayBuffer) \
126 _(js::jit::AllocateBigIntNoGC) \
127 _(js::jit::AllocateFatInlineString) \
128 _(js::jit::AllocateDependentString) \
129 _(js::jit::AssertMapObjectHash) \
130 _(js::jit::AssertPropertyLookup) \
131 _(js::jit::AssertSetObjectHash) \
132 _(js::jit::AssertValidBigIntPtr) \
133 _(js::jit::AssertValidObjectPtr) \
134 _(js::jit::AssertValidStringPtr) \
135 _(js::jit::AssertValidSymbolPtr) \
136 _(js::jit::AssertValidValue) \
137 _(js::jit::AssumeUnreachable) \
138 _(js::jit::AtomicsStore64) \
139 _(js::jit::AtomizeStringNoGC) \
140 _(js::jit::Bailout) \
141 _(js::jit::BaselineScript::OSREntryForFrame) \
142 _(js::jit::BigIntNumberEqual<js::jit::EqualityKind::Equal>) \
143 _(js::jit::BigIntNumberEqual<js::jit::EqualityKind::NotEqual>) \
144 _(js::jit::BigIntNumberCompare<js::jit::ComparisonKind::LessThan>) \
145 _(js::jit::NumberBigIntCompare<js::jit::ComparisonKind::LessThan>) \
146 _(js::jit::NumberBigIntCompare<js::jit::ComparisonKind::GreaterThanOrEqual>) \
147 _(js::jit::BigIntNumberCompare<js::jit::ComparisonKind::GreaterThanOrEqual>) \
148 _(js::jit::DateFillLocalTimeSlots) \
149 _(js::jit::EqualStringsHelperPure) \
150 _(js::jit::FinishBailoutToBaseline) \
151 _(js::jit::Float16ToFloat32) \
152 _(js::jit::Float32ToFloat16) \
153 _(js::jit::FrameIsDebuggeeCheck) \
154 _(js::jit::GetContextSensitiveInterpreterStub) \
155 _(js::jit::GetIndexFromString) \
156 _(js::jit::GetInt32FromStringPure) \
157 _(js::jit::GetNativeDataPropertyPure) \
158 _(js::jit::GetNativeDataPropertyPureWithCacheLookup) \
159 _(js::jit::GetNativeDataPropertyByValuePure) \
160 _(js::jit::GlobalHasLiveOnDebuggerStatement) \
161 _(js::jit::HandleCodeCoverageAtPC) \
162 _(js::jit::HandleCodeCoverageAtPrologue) \
163 _(js::jit::HandleException) \
164 _(js::jit::HasNativeDataPropertyPure<false>) \
165 _(js::jit::HasNativeDataPropertyPure<true>) \
166 _(js::jit::HasNativeElementPure) \
167 _(js::jit::InitBaselineFrameForOsr) \
168 _(js::jit::InvalidationBailout) \
169 _(js::jit::InvokeFromInterpreterStub) \
170 _(js::jit::LazyLinkTopActivation) \
171 _(js::jit::LinearizeForCharAccessPure) \
172 _(js::jit::ObjectHasGetterSetterPure) \
173 _(js::jit::ObjectIsCallable) \
174 _(js::jit::ObjectIsConstructor) \
175 _(js::jit::PostGlobalWriteBarrier) \
176 _(js::jit::PostWriteBarrier) \
177 _(js::jit::PostWriteElementBarrier) \
178 _(js::jit::Printf0) \
179 _(js::jit::Printf1) \
180 _(js::jit::StringFromCharCodeNoGC) \
181 _(js::jit::StringTrimEndIndex) \
182 _(js::jit::StringTrimStartIndex) \
183 _(js::jit::TypeOfNameObject) \
184 _(js::jit::TypeOfEqObject) \
185 _(js::jit::WrapObjectPure) \
186 ABIFUNCTION_FUZZILLI_LIST(_) \
187 _(js::MapIteratorObject::next) \
188 _(js::NativeObject::addDenseElementPure) \
189 _(js::NativeObject::growSlotsPure) \
190 _(js::NumberMod) \
191 _(js::NumberToStringPure) \
192 _(js::ObjectClassToString) \
193 _(js::powi) \
194 _(js::ProxyGetProperty) \
195 _(js::RoundFloat16) \
196 _(js::SetIteratorObject::next) \
197 _(js::StringToNumberPure) \
198 _(js::TypedArraySortFromJit) \
199 _(js::TypeOfObject) \
200 _(mozilla::SIMD::memchr16) \
201 _(mozilla::SIMD::memchr2x16) \
202 _(mozilla::SIMD::memchr2x8) \
203 _(mozilla::SIMD::memchr8)
204
205 // List of all ABI functions to be used with callWithABI, which are
206 // overloaded. Each entry stores the fully qualified name of the C++ function,
207 // followed by the signature of the function to be called. When the function
208 // is not overloaded, you should prefer adding the function to
209 // ABIFUNCTION_LIST instead. This list must be sorted with the name of the C++
210 // function.
211 #define ABIFUNCTION_AND_TYPE_LIST(_) \
212 _(JS::ToInt32, int32_t (*)(double)) \
213 _(js::jit::RoundFloat16ToFloat32, float (*)(int32_t)) \
214 _(js::jit::RoundFloat16ToFloat32, float (*)(float)) \
215 _(js::jit::RoundFloat16ToFloat32, float (*)(double))
216
217 // List of all ABI function signature which are using a computed function
218 // pointer instead of a statically known function pointer.
219 #define ABIFUNCTIONSIG_LIST(_) \
220 _(AtomicsCompareExchangeFn) \
221 _(AtomicsReadWriteModifyFn) \
222 _(bool (*)(BigInt*, BigInt*)) \
223 _(bool (*)(BigInt*, double)) \
224 _(bool (*)(double, BigInt*)) \
225 _(float (*)(float)) \
226 _(JSJitGetterOp) \
227 _(JSJitMethodOp) \
228 _(JSJitSetterOp) \
229 _(JSNative) \
230 _(js::UnaryMathFunctionType) \
231 _(void (*)(js::gc::StoreBuffer*, js::gc::Cell**)) \
232 _(void (*)(JSRuntime * rt, JSObject * *objp)) \
233 _(void (*)(JSRuntime * rt, JSString * *stringp)) \
234 _(void (*)(JSRuntime * rt, Shape * *shapep)) \
235 _(void (*)(JSRuntime * rt, wasm::AnyRef * refp)) \
236 _(void (*)(JSRuntime * rt, Value * vp))
237
238 // GCC warns when the signature does not have matching attributes (for example
239 // [[nodiscard]]). Squelch this warning to avoid a GCC-only footgun.
240 #if MOZ_IS_GCC
241 # pragma GCC diagnostic push
242 # pragma GCC diagnostic ignored "-Wignored-attributes"
243 #endif
244
245 #define DEF_TEMPLATE(fp) \
246 template <> \
247 struct ABIFunctionData<decltype(&fp), fp> { \
248 static constexpr bool registered = true; \
249 };
250 ABIFUNCTION_LIST(DEF_TEMPLATE)
251 #undef DEF_TEMPLATE
252
253 #define DEF_TEMPLATE(fp, ...) \
254 template <> \
255 struct ABIFunctionData<__VA_ARGS__, fp> { \
256 static constexpr bool registered = true; \
257 };
258 ABIFUNCTION_AND_TYPE_LIST(DEF_TEMPLATE)
259 #undef DEF_TEMPLATE
260
261 // Define a known list of function signatures.
262 #define DEF_TEMPLATE(...) \
263 template <> \
264 struct ABIFunctionSignatureData<__VA_ARGS__> { \
265 static constexpr bool registered = true; \
266 };
267 ABIFUNCTIONSIG_LIST(DEF_TEMPLATE)
268 #undef DEF_TEMPLATE
269
270 #if MOZ_IS_GCC
271 # pragma GCC diagnostic pop
272 #endif
273
274 } // namespace jit
275 } // namespace js
276
277 // Make sure that all names are fully qualified (or at least, are resolvable
278 // within the toplevel namespace).
279 //
280 // Previously this was accomplished just by using `::fp` to force resolution
281 // within the toplevel namespace, but (1) that prevented using templated
282 // functions with more than one parameter (eg `void foo<T, U>`) because the
283 // macro split on the comma and wrapping it in parens doesn't work because
284 // `::(foo)` is invalid; and (2) that would only check the function name itself,
285 // not eg template parameters.
286 namespace check_fully_qualified {
287 #define CHECK_NS_VISIBILITY(fp) \
288 [[maybe_unused]] static constexpr decltype(&fp) MOZ_CONCAT( \
289 fp_, __COUNTER__) = nullptr;
290 ABIFUNCTION_LIST(CHECK_NS_VISIBILITY)
291 #undef CHECK_NS_VISIBILITY
292 } // namespace check_fully_qualified
293
294 #endif // jit_VMFunctionList_inl_h