Debian Codegraph @

js/src/jit/Ion.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_Ion_h
8 #define jit_Ion_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Likely.h"
13 #include "mozilla/MemoryReporting.h"
14
15 #include <stddef.h>
16 #include <stdint.h>
17
18 #include "jsfriendapi.h"
19 #include "jspubtd.h"
20
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"
31
32 namespace js {
33
34 class RunState;
35
36 namespace jit {
37
38 class BaselineFrame;
39
40 bool CanIonCompileScript(JSContext* cx, JSScript* script);
41
42 [[nodiscard]] bool IonCompileScriptForBaselineAtEntry(JSContext* cx,
43 BaselineFrame* frame);
44
45 struct IonOsrTempData {
46 void* jitcode;
47 uint8_t* baselineFrame;
48
49 static constexpr size_t offsetOfJitCode() {
50 return offsetof(IonOsrTempData, jitcode);
51 }
52 static constexpr size_t offsetOfBaselineFrame() {
53 return offsetof(IonOsrTempData, baselineFrame);
54 }
55 };
56
57 [[nodiscard]] bool IonCompileScriptForBaselineOSR(JSContext* cx,
58 BaselineFrame* frame,
59 uint32_t frameSize,
60 jsbytecode* pc,
61 IonOsrTempData** infoPtr);
62
63 MethodStatus CanEnterIon(JSContext* cx, RunState& state);
64
65 class MIRGenerator;
66 class LIRGraph;
67 class CodeGenerator;
68 class LazyLinkExitFrameLayout;
69 class WarpSnapshot;
70
71 [[nodiscard]] bool OptimizeMIR(MIRGenerator* mir);
72 LIRGraph* GenerateLIR(MIRGenerator* mir);
73 CodeGenerator* CompileBackEnd(MIRGenerator* mir, WarpSnapshot* snapshot);
74
75 void LinkIonScript(JSContext* cx, HandleScript calleescript);
76 uint8_t* LazyLinkTopActivation(JSContext* cx, LazyLinkExitFrameLayout* frame);
77
78 inline bool IsIonInlinableGetterOrSetterOp(JSOp op) {
79 // JSOp::GetProp, JSOp::CallProp, JSOp::Length, JSOp::GetElem,
80 // and JSOp::CallElem. (Inlined Getters)
81 // JSOp::SetProp, JSOp::SetName, JSOp::SetGName (Inlined Setters)
82 return IsGetPropOp(op) || IsGetElemOp(op) || IsSetPropOp(op);
83 }
84
85 inline bool IsIonInlinableOp(JSOp op) {
86 // JSOp::Call, JSOp::FunCall, JSOp::Eval, JSOp::New (Normal Callsites) or an
87 // inlinable getter or setter.
88 return (IsInvokeOp(op) && !IsSpreadOp(op)) ||
89 IsIonInlinableGetterOrSetterOp(op);
90 }
91
92 inline bool TooManyFormalArguments(unsigned nargs) {
93 return nargs >= SNAPSHOT_MAX_NARGS || TooManyActualArguments(nargs);
94 }
95
96 inline size_t NumLocalsAndArgs(JSScript* script) {
97 size_t num = 1 /* this */ + script->nfixed();
98 if (JSFunction* fun = script->function()) {
99 num += fun->nargs();
100 }
101 return num;
102 }
103
104 // Debugging RAII class which marks the current thread as performing an Ion
105 // backend compilation.
106 class MOZ_RAII AutoEnterIonBackend {
107 public:
108 AutoEnterIonBackend() {
109 #ifdef DEBUG
110 JitContext* jcx = GetJitContext();
111 jcx->enterIonBackend();
112 #endif
113 }
114
115 #ifdef DEBUG
116 ~AutoEnterIonBackend() {
117 JitContext* jcx = GetJitContext();
118 jcx->leaveIonBackend();
119 }
120 #endif
121 };
122
123 bool OffThreadCompilationAvailable(JSContext* cx);
124
125 void ForbidCompilation(JSContext* cx, JSScript* script);
126
127 size_t SizeOfIonData(JSScript* script, mozilla::MallocSizeOf mallocSizeOf);
128
129 inline bool IsIonEnabled(JSContext* cx) {
130 if (MOZ_UNLIKELY(!IsBaselineJitEnabled(cx) || cx->options().disableIon())) {
131 return false;
132 }
133
134 if (MOZ_LIKELY(JitOptions.ion)) {
135 return true;
136 }
137 if (JitOptions.jitForTrustedPrincipals) {
138 JS::Realm* realm = js::GetContextRealm(cx);
139 return realm && JS::GetRealmPrincipals(realm) &&
140 JS::GetRealmPrincipals(realm)->isSystemOrAddonPrincipal();
141 }
142 return false;
143 }
144
145 // Implemented per-platform. Returns true if the flags will not require
146 // further (lazy) computation.
147 bool CPUFlagsHaveBeenComputed();
148
149 } // namespace jit
150 } // namespace js
151
152 #endif /* jit_Ion_h */