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/. */
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Likely.h"
13 #include "mozilla/MemoryReporting.h"
18 #include "jsfriendapi.h"
21 #include "jit/BaselineJIT.h"
22 #include "jit/IonTypes.h"
23 #include "jit/JitContext.h"
24 #include "jit/JitOptions.h"
25 #include "js/Principals.h"
26 #include "js/TypeDecls.h"
27 #include "vm/BytecodeUtil.h"
28 #include "vm/JSContext.h"
29 #include "vm/JSFunction.h"
30 #include "vm/JSScript.h"
40 bool CanIonCompileScript(JSContext
* cx
, JSScript
* script
);
42 [[nodiscard
]] bool IonCompileScriptForBaselineAtEntry(JSContext
* cx
,
43 BaselineFrame
* frame
);
45 struct IonOsrTempData
{
47 uint8_t* baselineFrame
;
49 static constexpr size_t offsetOfJitCode() {
50 return offsetof(IonOsrTempData
, jitcode
);
52 static constexpr size_t offsetOfBaselineFrame() {
53 return offsetof(IonOsrTempData
, baselineFrame
);
57 [[nodiscard
]] bool IonCompileScriptForBaselineOSR(JSContext
* cx
,
61 IonOsrTempData
** infoPtr
);
63 MethodStatus
CanEnterIon(JSContext
* cx
, RunState
& state
);
68 class LazyLinkExitFrameLayout
;
71 [[nodiscard
]] bool OptimizeMIR(MIRGenerator
* mir
);
72 LIRGraph
* GenerateLIR(MIRGenerator
* mir
);
73 CodeGenerator
* GenerateCode(MIRGenerator
* mir
, LIRGraph
* lir
);
74 CodeGenerator
* CompileBackEnd(MIRGenerator
* mir
, WarpSnapshot
* snapshot
);
76 void LinkIonScript(JSContext
* cx
, HandleScript calleescript
);
77 uint8_t* LazyLinkTopActivation(JSContext
* cx
, LazyLinkExitFrameLayout
* frame
);
79 inline bool IsIonInlinableGetterOrSetterOp(JSOp op
) {
80 // JSOp::GetProp, JSOp::CallProp, JSOp::Length, JSOp::GetElem,
81 // and JSOp::CallElem. (Inlined Getters)
82 // JSOp::SetProp, JSOp::SetName, JSOp::SetGName (Inlined Setters)
83 return IsGetPropOp(op
) || IsGetElemOp(op
) || IsSetPropOp(op
);
86 inline bool IsIonInlinableOp(JSOp op
) {
87 // JSOp::Call, JSOp::FunCall, JSOp::Eval, JSOp::New (Normal Callsites) or an
88 // inlinable getter or setter.
89 return (IsInvokeOp(op
) && !IsSpreadOp(op
)) ||
90 IsIonInlinableGetterOrSetterOp(op
);
93 inline bool TooManyFormalArguments(unsigned nargs
) {
94 return nargs
>= SNAPSHOT_MAX_NARGS
|| TooManyActualArguments(nargs
);
97 inline size_t NumLocalsAndArgs(JSScript
* script
) {
98 size_t num
= 1 /* this */ + script
->nfixed();
99 if (JSFunction
* fun
= script
->function()) {
105 // Debugging RAII class which marks the current thread as performing an Ion
106 // backend compilation.
107 class MOZ_RAII AutoEnterIonBackend
{
109 AutoEnterIonBackend() {
111 JitContext
* jcx
= GetJitContext();
112 jcx
->enterIonBackend();
117 ~AutoEnterIonBackend() {
118 JitContext
* jcx
= GetJitContext();
119 jcx
->leaveIonBackend();
124 bool OffThreadCompilationAvailable(JSContext
* cx
);
126 void ForbidCompilation(JSContext
* cx
, JSScript
* script
);
128 size_t SizeOfIonData(JSScript
* script
, mozilla::MallocSizeOf mallocSizeOf
);
130 inline bool IsIonEnabled(JSContext
* cx
) {
131 if (MOZ_UNLIKELY(!IsBaselineJitEnabled(cx
) || cx
->options().disableIon())) {
135 if (MOZ_LIKELY(JitOptions
.ion
)) {
138 if (JitOptions
.jitForTrustedPrincipals
) {
139 JS::Realm
* realm
= js::GetContextRealm(cx
);
140 return realm
&& JS::GetRealmPrincipals(realm
) &&
141 JS::GetRealmPrincipals(realm
)->isSystemOrAddonPrincipal();
146 // Implemented per-platform. Returns true if the flags will not require
147 // further (lazy) computation.
148 bool CPUFlagsHaveBeenComputed();
153 #endif /* jit_Ion_h */