Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / js / src / jit / Ion.h
blob621575e59d1961ad1d21d5995e400473cdc42670
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_Ion_h
8 #define jit_Ion_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Likely.h"
13 #include "mozilla/MemoryReporting.h"
15 #include <stddef.h>
16 #include <stdint.h>
18 #include "jsfriendapi.h"
19 #include "jspubtd.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"
32 namespace js {
34 class RunState;
36 namespace jit {
38 class BaselineFrame;
40 bool CanIonCompileScript(JSContext* cx, JSScript* script);
42 [[nodiscard]] bool IonCompileScriptForBaselineAtEntry(JSContext* cx,
43 BaselineFrame* frame);
45 struct IonOsrTempData {
46 void* jitcode;
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,
58 BaselineFrame* frame,
59 uint32_t frameSize,
60 jsbytecode* pc,
61 IonOsrTempData** infoPtr);
63 MethodStatus CanEnterIon(JSContext* cx, RunState& state);
65 class MIRGenerator;
66 class LIRGraph;
67 class CodeGenerator;
68 class LazyLinkExitFrameLayout;
69 class WarpSnapshot;
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()) {
100 num += fun->nargs();
102 return num;
105 // Debugging RAII class which marks the current thread as performing an Ion
106 // backend compilation.
107 class MOZ_RAII AutoEnterIonBackend {
108 public:
109 AutoEnterIonBackend() {
110 #ifdef DEBUG
111 JitContext* jcx = GetJitContext();
112 jcx->enterIonBackend();
113 #endif
116 #ifdef DEBUG
117 ~AutoEnterIonBackend() {
118 JitContext* jcx = GetJitContext();
119 jcx->leaveIonBackend();
121 #endif
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())) {
132 return false;
135 if (MOZ_LIKELY(JitOptions.ion)) {
136 return true;
138 if (JitOptions.jitForTrustedPrincipals) {
139 JS::Realm* realm = js::GetContextRealm(cx);
140 return realm && JS::GetRealmPrincipals(realm) &&
141 JS::GetRealmPrincipals(realm)->isSystemOrAddonPrincipal();
143 return false;
146 // Implemented per-platform. Returns true if the flags will not require
147 // further (lazy) computation.
148 bool CPUFlagsHaveBeenComputed();
150 } // namespace jit
151 } // namespace js
153 #endif /* jit_Ion_h */