Bug 1890513: Directly invoke variadic native functions. r=jandem
[gecko.git] / js / src / jit / ABIFunctionList-inl.h
blobeb2123f7a2f84bffef0b6ad0e1a6dc47c227fb22
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 #ifndef jit_ABIFunctionList_inl_h
8 #define jit_ABIFunctionList_inl_h
10 #include "mozilla/SIMD.h" // mozilla::SIMD::memchr{,2x}{8,16}
12 #include "jslibmath.h" // js::NumberMod
13 #include "jsmath.h" // js::ecmaPow, js::ecmaHypot, js::hypot3, js::hypot4,
14 // js::ecmaAtan2, js::UnaryMathFunctionType, js::powi
15 #include "jsnum.h" // js::StringToNumberPure, js::Int32ToStringPure,
16 // js::NumberToStringPure
18 #include "builtin/Array.h" // js::ArrayShiftMoveElements
19 #include "builtin/MapObject.h" // js::MapIteratorObject::next,
20 // js::SetIteratorObject::next
21 #include "builtin/Object.h" // js::ObjectClassToString
22 #include "builtin/RegExp.h" // js::RegExpPrototypeOptimizableRaw,
23 // js::RegExpInstanceOptimizableRaw
24 #include "builtin/TestingFunctions.h" // js::FuzzilliHash*
26 #include "irregexp/RegExpAPI.h"
27 // js::irregexp::CaseInsensitiveCompareNonUnicode,
28 // js::irregexp::CaseInsensitiveCompareUnicode,
29 // js::irregexp::GrowBacktrackStack,
30 // js::irregexp::IsCharacterInRangeArray
32 #include "jit/ABIFunctions.h"
33 #include "jit/Bailouts.h" // js::jit::FinishBailoutToBaseline, js::jit::Bailout,
34 // js::jit::InvalidationBailout
36 #include "jit/Ion.h" // js::jit::LazyLinkTopActivation
37 #include "jit/JitFrames.h" // HandleException
38 #include "jit/VMFunctions.h" // Rest of js::jit::* functions.
40 #include "js/CallArgs.h" // JSNative
41 #include "js/Conversions.h" // JS::ToInt32
42 // JSJitGetterOp, JSJitSetterOp, JSJitMethodOp
43 #include "js/experimental/JitInfo.h"
44 #include "js/Utility.h" // js_free
46 #include "proxy/Proxy.h" // js::ProxyGetProperty
48 #include "vm/ArgumentsObject.h" // js::ArgumentsObject::finishForIonPure
49 #include "vm/Interpreter.h" // js::TypeOfObject
50 #include "vm/NativeObject.h" // js::NativeObject
51 #include "vm/RegExpShared.h" // js::ExecuteRegExpAtomRaw
52 #include "wasm/WasmBuiltins.h" // js::wasm::*
54 #include "builtin/Boolean-inl.h" // js::EmulatesUndefined
56 namespace js {
58 namespace wasm {
60 class AnyRef;
62 } // namespace wasm
64 namespace jit {
66 // List of all ABI functions to be used with callWithABI. Each entry stores
67 // the fully qualified name of the C++ function. This list must be sorted.
68 #if JS_GC_PROBES
69 # define ABIFUNCTION_JS_GC_PROBES_LIST(_) _(js::jit::TraceCreateObject)
70 #else
71 # define ABIFUNCTION_JS_GC_PROBES_LIST(_)
72 #endif
74 #if defined(JS_CODEGEN_ARM)
75 # define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_) \
76 _(__aeabi_idivmod) \
77 _(__aeabi_uidivmod)
78 #else
79 # define ABIFUNCTION_JS_CODEGEN_ARM_LIST(_)
80 #endif
82 #ifdef WASM_CODEGEN_DEBUG
83 # define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_) \
84 _(js::wasm::PrintF32) \
85 _(js::wasm::PrintF64) \
86 _(js::wasm::PrintI32) \
87 _(js::wasm::PrintPtr) \
88 _(js::wasm::PrintText)
89 #else
90 # define ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_)
91 #endif
93 #ifdef FUZZING_JS_FUZZILLI
94 # define ABIFUNCTION_FUZZILLI_LIST(_) _(js::FuzzilliHashBigInt)
95 #else
96 # define ABIFUNCTION_FUZZILLI_LIST(_)
97 #endif
99 #define ABIFUNCTION_LIST(_) \
100 ABIFUNCTION_JS_GC_PROBES_LIST(_) \
101 ABIFUNCTION_JS_CODEGEN_ARM_LIST(_) \
102 ABIFUNCTION_WASM_CODEGEN_DEBUG_LIST(_) \
103 _(js::ArgumentsObject::finishForIonPure) \
104 _(js::ArgumentsObject::finishInlineForIonPure) \
105 _(js::ArrayShiftMoveElements) \
106 _(js::ArraySortData::sortWithComparator) \
107 _(js::ArraySortFromJit) \
108 _(js::ecmaAtan2) \
109 _(js::ecmaHypot) \
110 _(js::ecmaPow) \
111 _(js::EmulatesUndefined) \
112 _(js::EmulatesUndefinedCheckFuse) \
113 _(js::ExecuteRegExpAtomRaw) \
114 _(js_free) \
115 _(js::hypot3) \
116 _(js::hypot4) \
117 _(js::Interpret) \
118 _(js::Int32ToStringPure) \
119 _(js::irregexp::CaseInsensitiveCompareNonUnicode) \
120 _(js::irregexp::CaseInsensitiveCompareUnicode) \
121 _(js::irregexp::GrowBacktrackStack) \
122 _(js::irregexp::IsCharacterInRangeArray) \
123 _(js::jit::AllocateAndInitTypedArrayBuffer) \
124 _(js::jit::AllocateBigIntNoGC) \
125 _(js::jit::AllocateFatInlineString) \
126 _(js::jit::AllocateDependentString) \
127 _(js::jit::AssertMapObjectHash) \
128 _(js::jit::AssertPropertyLookup) \
129 _(js::jit::AssertSetObjectHash) \
130 _(js::jit::AssertValidBigIntPtr) \
131 _(js::jit::AssertValidObjectPtr) \
132 _(js::jit::AssertValidStringPtr) \
133 _(js::jit::AssertValidSymbolPtr) \
134 _(js::jit::AssertValidValue) \
135 _(js::jit::AssumeUnreachable) \
136 _(js::jit::AtomicsStore64) \
137 _(js::jit::AtomizeStringNoGC) \
138 _(js::jit::Bailout) \
139 _(js::jit::BigIntNumberEqual<EqualityKind::Equal>) \
140 _(js::jit::BigIntNumberEqual<EqualityKind::NotEqual>) \
141 _(js::jit::BigIntNumberCompare<ComparisonKind::LessThan>) \
142 _(js::jit::NumberBigIntCompare<ComparisonKind::LessThan>) \
143 _(js::jit::NumberBigIntCompare<ComparisonKind::GreaterThanOrEqual>) \
144 _(js::jit::BigIntNumberCompare<ComparisonKind::GreaterThanOrEqual>) \
145 _(js::jit::EqualStringsHelperPure) \
146 _(js::jit::FinishBailoutToBaseline) \
147 _(js::jit::FrameIsDebuggeeCheck) \
148 _(js::jit::GetContextSensitiveInterpreterStub) \
149 _(js::jit::GetIndexFromString) \
150 _(js::jit::GetInt32FromStringPure) \
151 _(js::jit::GetNativeDataPropertyPure) \
152 _(js::jit::GetNativeDataPropertyPureWithCacheLookup) \
153 _(js::jit::GetNativeDataPropertyByValuePure) \
154 _(js::jit::GlobalHasLiveOnDebuggerStatement) \
155 _(js::jit::HandleCodeCoverageAtPC) \
156 _(js::jit::HandleCodeCoverageAtPrologue) \
157 _(js::jit::HandleException) \
158 _(js::jit::HasNativeDataPropertyPure<false>) \
159 _(js::jit::HasNativeDataPropertyPure<true>) \
160 _(js::jit::HasNativeElementPure) \
161 _(js::jit::InitBaselineFrameForOsr) \
162 _(js::jit::InvalidationBailout) \
163 _(js::jit::InvokeFromInterpreterStub) \
164 _(js::jit::LazyLinkTopActivation) \
165 _(js::jit::LinearizeForCharAccessPure) \
166 _(js::jit::ObjectHasGetterSetterPure) \
167 _(js::jit::ObjectIsCallable) \
168 _(js::jit::ObjectIsConstructor) \
169 _(js::jit::PostGlobalWriteBarrier) \
170 _(js::jit::PostWriteBarrier) \
171 _(js::jit::PostWriteElementBarrier) \
172 _(js::jit::Printf0) \
173 _(js::jit::Printf1) \
174 _(js::jit::StringFromCharCodeNoGC) \
175 _(js::jit::StringTrimEndIndex) \
176 _(js::jit::StringTrimStartIndex) \
177 _(js::jit::TypeOfNameObject) \
178 _(js::jit::WrapObjectPure) \
179 ABIFUNCTION_FUZZILLI_LIST(_) \
180 _(js::MapIteratorObject::next) \
181 _(js::NativeObject::addDenseElementPure) \
182 _(js::NativeObject::growSlotsPure) \
183 _(js::NumberMod) \
184 _(js::NumberToStringPure) \
185 _(js::ObjectClassToString) \
186 _(js::powi) \
187 _(js::ProxyGetProperty) \
188 _(js::RegExpInstanceOptimizableRaw) \
189 _(js::RegExpPrototypeOptimizableRaw) \
190 _(js::SetIteratorObject::next) \
191 _(js::StringToNumberPure) \
192 _(js::TypeOfObject) \
193 _(mozilla::SIMD::memchr16) \
194 _(mozilla::SIMD::memchr2x16) \
195 _(mozilla::SIMD::memchr2x8) \
196 _(mozilla::SIMD::memchr8)
198 // List of all ABI functions to be used with callWithABI, which are
199 // overloaded. Each entry stores the fully qualified name of the C++ function,
200 // followed by the signature of the function to be called. When the function
201 // is not overloaded, you should prefer adding the function to
202 // ABIFUNCTION_LIST instead. This list must be sorted with the name of the C++
203 // function.
204 #define ABIFUNCTION_AND_TYPE_LIST(_) _(JS::ToInt32, int32_t (*)(double))
206 // List of all ABI function signature which are using a computed function
207 // pointer instead of a statically known function pointer.
208 #define ABIFUNCTIONSIG_LIST(_) \
209 _(AtomicsCompareExchangeFn) \
210 _(AtomicsReadWriteModifyFn) \
211 _(bool (*)(BigInt*, BigInt*)) \
212 _(bool (*)(BigInt*, double)) \
213 _(bool (*)(double, BigInt*)) \
214 _(float (*)(float)) \
215 _(JSJitGetterOp) \
216 _(JSJitMethodOp) \
217 _(JSJitSetterOp) \
218 _(JSNative) \
219 _(js::UnaryMathFunctionType) \
220 _(void (*)(js::gc::StoreBuffer*, js::gc::Cell**)) \
221 _(void (*)(JSRuntime * rt, JSObject * *objp)) \
222 _(void (*)(JSRuntime * rt, JSString * *stringp)) \
223 _(void (*)(JSRuntime * rt, Shape * *shapep)) \
224 _(void (*)(JSRuntime * rt, wasm::AnyRef * refp)) \
225 _(void (*)(JSRuntime * rt, Value * vp))
227 // GCC warns when the signature does not have matching attributes (for example
228 // [[nodiscard]]). Squelch this warning to avoid a GCC-only footgun.
229 #if MOZ_IS_GCC
230 # pragma GCC diagnostic push
231 # pragma GCC diagnostic ignored "-Wignored-attributes"
232 #endif
234 // Note: the use of ::fp instead of fp is intentional to enforce use of
235 // fully-qualified names in the list above.
236 #define DEF_TEMPLATE(fp) \
237 template <> \
238 struct ABIFunctionData<decltype(&(::fp)), ::fp> { \
239 static constexpr bool registered = true; \
241 ABIFUNCTION_LIST(DEF_TEMPLATE)
242 #undef DEF_TEMPLATE
244 #define DEF_TEMPLATE(fp, ...) \
245 template <> \
246 struct ABIFunctionData<__VA_ARGS__, ::fp> { \
247 static constexpr bool registered = true; \
249 ABIFUNCTION_AND_TYPE_LIST(DEF_TEMPLATE)
250 #undef DEF_TEMPLATE
252 // Define a known list of function signatures.
253 #define DEF_TEMPLATE(...) \
254 template <> \
255 struct ABIFunctionSignatureData<__VA_ARGS__> { \
256 static constexpr bool registered = true; \
258 ABIFUNCTIONSIG_LIST(DEF_TEMPLATE)
259 #undef DEF_TEMPLATE
261 #if MOZ_IS_GCC
262 # pragma GCC diagnostic pop
263 #endif
265 } // namespace jit
266 } // namespace js
268 #endif // jit_VMFunctionList_inl_h