Bug 1885489 - Part 5: Add SnapshotIterator::readInt32(). r=iain
[gecko.git] / js / src / jit / MIRGenerator.h
blob45b33618d0713762809480ee3871e307f5dcd226
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_MIRGenerator_h
8 #define jit_MIRGenerator_h
10 // This file declares the data structures used to build a control-flow graph
11 // containing MIR.
13 #include "mozilla/Assertions.h"
14 #include "mozilla/Atomics.h"
15 #include "mozilla/Attributes.h"
16 #include "mozilla/Result.h"
18 #include <stdarg.h>
19 #include <stddef.h>
20 #include <stdint.h>
22 #include "jit/CompileInfo.h"
23 #include "jit/CompileWrappers.h"
24 #include "jit/JitAllocPolicy.h"
25 #include "jit/JitContext.h"
26 #include "jit/JitSpewer.h"
27 #include "jit/PerfSpewer.h"
28 #include "js/Utility.h"
29 #include "vm/GeckoProfiler.h"
31 namespace js {
32 namespace jit {
34 class JitRuntime;
35 class MIRGraph;
36 class OptimizationInfo;
38 class MIRGenerator final {
39 public:
40 MIRGenerator(CompileRealm* realm, const JitCompileOptions& options,
41 TempAllocator* alloc, MIRGraph* graph,
42 const CompileInfo* outerInfo,
43 const OptimizationInfo* optimizationInfo);
45 void initMinWasmMemory0Length(uint64_t init) { minWasmMemory0Length_ = init; }
47 TempAllocator& alloc() { return *alloc_; }
48 MIRGraph& graph() { return *graph_; }
49 [[nodiscard]] bool ensureBallast() { return alloc().ensureBallast(); }
50 const JitRuntime* jitRuntime() const { return runtime->jitRuntime(); }
51 const CompileInfo& outerInfo() const { return *outerInfo_; }
52 const OptimizationInfo& optimizationInfo() const {
53 return *optimizationInfo_;
55 bool hasProfilingScripts() const {
56 return runtime && runtime->profilingScripts();
59 template <typename T>
60 T* allocate(size_t count = 1) {
61 size_t bytes;
62 if (MOZ_UNLIKELY(!CalculateAllocSize<T>(count, &bytes))) {
63 return nullptr;
65 return static_cast<T*>(alloc().allocate(bytes));
68 // Set an error state and prints a message. Returns false so errors can be
69 // propagated up.
70 mozilla::GenericErrorResult<AbortReason> abort(AbortReason r);
71 mozilla::GenericErrorResult<AbortReason> abort(AbortReason r,
72 const char* message, ...)
73 MOZ_FORMAT_PRINTF(3, 4);
75 mozilla::GenericErrorResult<AbortReason> abortFmt(AbortReason r,
76 const char* message,
77 va_list ap)
78 MOZ_FORMAT_PRINTF(3, 0);
80 // Collect the evaluation result of phases after WarpOracle, such that
81 // off-thread compilation can report what error got encountered.
82 void setOffThreadStatus(AbortReasonOr<Ok>&& result) {
83 MOZ_ASSERT(offThreadStatus_.isOk());
84 offThreadStatus_ = std::move(result);
86 const AbortReasonOr<Ok>& getOffThreadStatus() const {
87 return offThreadStatus_;
90 [[nodiscard]] bool instrumentedProfiling() {
91 if (!instrumentedProfilingIsCached_) {
92 instrumentedProfiling_ = runtime->geckoProfiler().enabled();
93 instrumentedProfilingIsCached_ = true;
95 return instrumentedProfiling_;
98 bool isProfilerInstrumentationEnabled() {
99 return !compilingWasm() && instrumentedProfiling();
102 gc::Heap initialStringHeap() const {
103 return stringsCanBeInNursery_ ? gc::Heap::Default : gc::Heap::Tenured;
106 gc::Heap initialBigIntHeap() const {
107 return bigIntsCanBeInNursery_ ? gc::Heap::Default : gc::Heap::Tenured;
110 // Whether the main thread is trying to cancel this build.
111 bool shouldCancel(const char* why) { return cancelBuild_; }
112 void cancel() { cancelBuild_ = true; }
114 bool compilingWasm() const { return outerInfo_->compilingWasm(); }
116 uint32_t wasmMaxStackArgBytes() const {
117 MOZ_ASSERT(compilingWasm());
118 return wasmMaxStackArgBytes_;
120 void initWasmMaxStackArgBytes(uint32_t n) {
121 MOZ_ASSERT(compilingWasm());
122 MOZ_ASSERT(wasmMaxStackArgBytes_ == 0);
123 wasmMaxStackArgBytes_ = n;
125 uint64_t minWasmMemory0Length() const { return minWasmMemory0Length_; }
127 void setNeedsOverrecursedCheck() { needsOverrecursedCheck_ = true; }
128 bool needsOverrecursedCheck() const { return needsOverrecursedCheck_; }
130 void setNeedsStaticStackAlignment() { needsStaticStackAlignment_ = true; }
131 bool needsStaticStackAlignment() const { return needsStaticStackAlignment_; }
133 public:
134 CompileRealm* realm;
135 CompileRuntime* runtime;
137 private:
138 // The CompileInfo for the outermost script.
139 const CompileInfo* outerInfo_;
141 const OptimizationInfo* optimizationInfo_;
142 TempAllocator* alloc_;
143 MIRGraph* graph_;
144 AbortReasonOr<Ok> offThreadStatus_;
145 mozilla::Atomic<bool, mozilla::Relaxed> cancelBuild_;
147 uint32_t wasmMaxStackArgBytes_;
148 bool needsOverrecursedCheck_;
149 bool needsStaticStackAlignment_;
151 bool instrumentedProfiling_;
152 bool instrumentedProfilingIsCached_;
153 bool stringsCanBeInNursery_;
154 bool bigIntsCanBeInNursery_;
156 bool disableLICM_ = false;
158 public:
159 void disableLICM() { disableLICM_ = true; }
160 bool licmEnabled() const;
162 private:
163 uint64_t minWasmMemory0Length_;
165 IonPerfSpewer wasmPerfSpewer_;
167 public:
168 IonPerfSpewer& perfSpewer() { return wasmPerfSpewer_; }
170 public:
171 const JitCompileOptions options;
173 private:
174 GraphSpewer gs_;
176 public:
177 GraphSpewer& graphSpewer() { return gs_; }
180 } // namespace jit
181 } // namespace js
183 #endif /* jit_MIRGenerator_h */