Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / js / src / jit / JitSpewer.h
blob5706cedb307826a7c0d6c21f39ff7ca204d22dd3
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_JitSpewer_h
8 #define jit_JitSpewer_h
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/DebugOnly.h"
13 #include "mozilla/IntegerPrintfMacros.h"
15 #include <stdarg.h>
17 #include "jit/JSONSpewer.h"
18 #include "js/Printer.h"
19 #include "js/TypeDecls.h"
21 enum JSValueType : uint8_t;
23 namespace js {
24 namespace jit {
26 // New channels may be added below.
27 #define JITSPEW_CHANNEL_LIST(_) \
28 /* Information during sinking */ \
29 _(Prune) \
30 /* Information during escape analysis */ \
31 _(Escape) \
32 /* Information during alias analysis */ \
33 _(Alias) \
34 /* Information during alias analysis */ \
35 _(AliasSummaries) \
36 /* Information during GVN */ \
37 _(GVN) \
38 /* Information during sinking */ \
39 _(Sink) \
40 /* Information during Range analysis */ \
41 _(Range) \
42 /* Information during LICM */ \
43 _(LICM) \
44 /* Info about fold linear constants */ \
45 _(FLAC) \
46 /* Effective address analysis info */ \
47 _(EAA) \
48 /* Wasm Bounds Check Elimination */ \
49 _(WasmBCE) \
50 /* Information during regalloc */ \
51 _(RegAlloc) \
52 /* Information during inlining */ \
53 _(Inlining) \
54 /* Information during codegen */ \
55 _(Codegen) \
56 /* Debug info about safepoints */ \
57 _(Safepoints) \
58 /* Debug info about Pools*/ \
59 _(Pools) \
60 /* Profiling-related information */ \
61 _(Profiling) \
62 /* Debug info about the I$ */ \
63 _(CacheFlush) \
64 /* Info about redundant shape guards */ \
65 _(RedundantShapeGuards) \
66 /* Info about redundant GC barriers */ \
67 _(RedundantGCBarriers) \
68 /* Output a list of MIR expressions */ \
69 _(MIRExpressions) \
70 /* Spew Tracelogger summary stats */ \
71 _(ScriptStats) \
73 /* BASELINE COMPILER SPEW */ \
75 /* Aborting Script Compilation. */ \
76 _(BaselineAbort) \
77 /* Script Compilation. */ \
78 _(BaselineScripts) \
79 /* Detailed op-specific spew. */ \
80 _(BaselineOp) \
81 /* Inline caches. */ \
82 _(BaselineIC) \
83 /* Inline cache fallbacks. */ \
84 _(BaselineICFallback) \
85 /* OSR from Baseline => Ion. */ \
86 _(BaselineOSR) \
87 /* Bailouts. */ \
88 _(BaselineBailouts) \
89 /* Debug Mode On Stack Recompile . */ \
90 _(BaselineDebugModeOSR) \
92 /* ION COMPILER SPEW */ \
94 /* Used to abort SSA construction */ \
95 _(IonAbort) \
96 /* Information about compiled scripts */ \
97 _(IonScripts) \
98 /* Info about failing to log script */ \
99 _(IonSyncLogs) \
100 /* Information during MIR building */ \
101 _(IonMIR) \
102 /* Information during bailouts */ \
103 _(IonBailouts) \
104 /* Information during OSI */ \
105 _(IonInvalidate) \
106 /* Debug info about snapshots */ \
107 _(IonSnapshots) \
108 /* Generated inline cache stubs */ \
109 _(IonIC) \
111 /* WARP SPEW */ \
113 /* Generated WarpSnapshots */ \
114 _(WarpSnapshots) \
115 /* CacheIR transpiler logging */ \
116 _(WarpTranspiler) \
117 /* Trial inlining for Warp */ \
118 _(WarpTrialInlining)
120 enum JitSpewChannel {
121 #define JITSPEW_CHANNEL(name) JitSpew_##name,
122 JITSPEW_CHANNEL_LIST(JITSPEW_CHANNEL)
123 #undef JITSPEW_CHANNEL
124 JitSpew_Terminator
127 class BacktrackingAllocator;
128 class MDefinition;
129 class MIRGenerator;
130 class MIRGraph;
131 class TempAllocator;
133 // The JitSpewer is only available on debug builds.
134 // None of the global functions have effect on non-debug builds.
135 #ifdef JS_JITSPEW
137 // Class made to hold the MIR and LIR graphs of an Wasm / Ion compilation.
138 class GraphSpewer {
139 private:
140 MIRGraph* graph_;
141 LSprinter jsonPrinter_;
142 JSONSpewer jsonSpewer_;
144 public:
145 explicit GraphSpewer(TempAllocator* alloc);
147 bool isSpewing() const { return graph_; }
148 void init(MIRGraph* graph, JSScript* function);
149 void beginFunction(JSScript* function);
150 void beginWasmFunction(unsigned funcIndex);
151 void spewPass(const char* pass);
152 void spewPass(const char* pass, BacktrackingAllocator* ra);
153 void endFunction();
155 void dump(Fprinter& json);
158 void SpewBeginFunction(MIRGenerator* mir, JSScript* function);
159 void SpewBeginWasmFunction(MIRGenerator* mir, unsigned funcIndex);
161 class AutoSpewEndFunction {
162 private:
163 MIRGenerator* mir_;
165 public:
166 explicit AutoSpewEndFunction(MIRGenerator* mir) : mir_(mir) {}
167 ~AutoSpewEndFunction();
170 void CheckLogging();
171 Fprinter& JitSpewPrinter();
173 class JitSpewIndent {
174 JitSpewChannel channel_;
176 public:
177 explicit JitSpewIndent(JitSpewChannel channel);
178 ~JitSpewIndent();
181 void JitSpew(JitSpewChannel channel, const char* fmt, ...)
182 MOZ_FORMAT_PRINTF(2, 3);
183 void JitSpewStart(JitSpewChannel channel, const char* fmt, ...)
184 MOZ_FORMAT_PRINTF(2, 3);
185 void JitSpewCont(JitSpewChannel channel, const char* fmt, ...)
186 MOZ_FORMAT_PRINTF(2, 3);
187 void JitSpewFin(JitSpewChannel channel);
188 void JitSpewHeader(JitSpewChannel channel);
189 bool JitSpewEnabled(JitSpewChannel channel);
190 void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap)
191 MOZ_FORMAT_PRINTF(2, 0);
192 void JitSpewStartVA(JitSpewChannel channel, const char* fmt, va_list ap)
193 MOZ_FORMAT_PRINTF(2, 0);
194 void JitSpewContVA(JitSpewChannel channel, const char* fmt, va_list ap)
195 MOZ_FORMAT_PRINTF(2, 0);
196 void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def);
198 void EnableChannel(JitSpewChannel channel);
199 void DisableChannel(JitSpewChannel channel);
200 void EnableIonDebugSyncLogging();
201 void EnableIonDebugAsyncLogging();
203 const char* ValTypeToString(JSValueType type);
205 # define JitSpewIfEnabled(channel, fmt, ...) \
206 do { \
207 if (JitSpewEnabled(channel)) { \
208 JitSpew(channel, fmt, __VA_ARGS__); \
210 } while (false);
212 #else
214 class GraphSpewer {
215 public:
216 explicit GraphSpewer(TempAllocator* alloc) {}
218 bool isSpewing() { return false; }
219 void init(MIRGraph* graph, JSScript* function) {}
220 void beginFunction(JSScript* function) {}
221 void spewPass(const char* pass) {}
222 void spewPass(const char* pass, BacktrackingAllocator* ra) {}
223 void endFunction() {}
225 void dump(Fprinter& c1, Fprinter& json) {}
228 static inline void SpewBeginFunction(MIRGenerator* mir, JSScript* function) {}
229 static inline void SpewBeginWasmFunction(MIRGenerator* mir,
230 unsigned funcIndex) {}
232 class AutoSpewEndFunction {
233 public:
234 explicit AutoSpewEndFunction(MIRGenerator* mir) {}
235 ~AutoSpewEndFunction() {}
238 static inline void CheckLogging() {}
239 static inline Fprinter& JitSpewPrinter() {
240 MOZ_CRASH("No empty backend for JitSpewPrinter");
243 class JitSpewIndent {
244 public:
245 explicit JitSpewIndent(JitSpewChannel channel) {}
246 ~JitSpewIndent() {}
249 // The computation of some of the argument of the spewing functions might be
250 // costly, thus we use variaidic macros to ignore any argument of these
251 // functions.
252 static inline void JitSpewCheckArguments(JitSpewChannel channel,
253 const char* fmt) {}
255 # define JitSpewCheckExpandedArgs(channel, fmt, ...) \
256 JitSpewCheckArguments(channel, fmt)
257 # define JitSpewCheckExpandedArgs_(ArgList) \
258 JitSpewCheckExpandedArgs ArgList /* Fix MSVC issue */
259 # define JitSpew(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
260 # define JitSpewStart(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
261 # define JitSpewCont(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
263 # define JitSpewIfEnabled(channel, fmt, ...) \
264 JitSpewCheckArguments(channel, fmt)
266 static inline void JitSpewFin(JitSpewChannel channel) {}
268 static inline void JitSpewHeader(JitSpewChannel channel) {}
269 static inline bool JitSpewEnabled(JitSpewChannel channel) { return false; }
270 static inline MOZ_FORMAT_PRINTF(2, 0) void JitSpewVA(JitSpewChannel channel,
271 const char* fmt,
272 va_list ap) {}
273 static inline void JitSpewDef(JitSpewChannel channel, const char* str,
274 MDefinition* def) {}
276 static inline void EnableChannel(JitSpewChannel) {}
277 static inline void DisableChannel(JitSpewChannel) {}
278 static inline void EnableIonDebugSyncLogging() {}
279 static inline void EnableIonDebugAsyncLogging() {}
281 #endif /* JS_JITSPEW */
283 } // namespace jit
284 } // namespace js
286 #endif /* jit_JitSpewer_h */