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"
17 #include "jit/JSONSpewer.h"
18 #include "js/Printer.h"
19 #include "js/TypeDecls.h"
21 enum JSValueType
: uint8_t;
26 // New channels may be added below.
27 #define JITSPEW_CHANNEL_LIST(_) \
28 /* Information during sinking */ \
30 /* Information during escape analysis */ \
32 /* Information during alias analysis */ \
34 /* Information during alias analysis */ \
36 /* Information during GVN */ \
38 /* Information during sinking */ \
40 /* Information during Range analysis */ \
42 /* Information during LICM */ \
44 /* Info about fold linear constants */ \
46 /* Effective address analysis info */ \
48 /* Wasm Bounds Check Elimination */ \
50 /* Information during regalloc */ \
52 /* Information during inlining */ \
54 /* Information during codegen */ \
56 /* Debug info about safepoints */ \
58 /* Debug info about Pools*/ \
60 /* Profiling-related information */ \
62 /* Debug info about the I$ */ \
64 /* Info about redundant shape guards */ \
65 _(RedundantShapeGuards) \
66 /* Info about redundant GC barriers */ \
67 _(RedundantGCBarriers) \
68 /* Output a list of MIR expressions */ \
70 /* Spew Tracelogger summary stats */ \
73 /* BASELINE COMPILER SPEW */ \
75 /* Aborting Script Compilation. */ \
77 /* Script Compilation. */ \
79 /* Detailed op-specific spew. */ \
81 /* Inline caches. */ \
83 /* Inline cache fallbacks. */ \
84 _(BaselineICFallback) \
85 /* OSR from Baseline => Ion. */ \
89 /* Debug Mode On Stack Recompile . */ \
90 _(BaselineDebugModeOSR) \
92 /* ION COMPILER SPEW */ \
94 /* Used to abort SSA construction */ \
96 /* Information about compiled scripts */ \
98 /* Info about failing to log script */ \
100 /* Information during MIR building */ \
102 /* Information during bailouts */ \
104 /* Information during OSI */ \
106 /* Debug info about snapshots */ \
108 /* Generated inline cache stubs */ \
113 /* Generated WarpSnapshots */ \
115 /* CacheIR transpiler logging */ \
117 /* Trial inlining for Warp */ \
120 enum JitSpewChannel
{
121 #define JITSPEW_CHANNEL(name) JitSpew_##name,
122 JITSPEW_CHANNEL_LIST(JITSPEW_CHANNEL
)
123 #undef JITSPEW_CHANNEL
127 class BacktrackingAllocator
;
133 // The JitSpewer is only available on debug builds.
134 // None of the global functions have effect on non-debug builds.
137 // Class made to hold the MIR and LIR graphs of an Wasm / Ion compilation.
141 LSprinter jsonPrinter_
;
142 JSONSpewer jsonSpewer_
;
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
);
155 void dump(Fprinter
& json
);
158 void SpewBeginFunction(MIRGenerator
* mir
, JSScript
* function
);
159 void SpewBeginWasmFunction(MIRGenerator
* mir
, unsigned funcIndex
);
161 class AutoSpewEndFunction
{
166 explicit AutoSpewEndFunction(MIRGenerator
* mir
) : mir_(mir
) {}
167 ~AutoSpewEndFunction();
171 Fprinter
& JitSpewPrinter();
173 class JitSpewIndent
{
174 JitSpewChannel channel_
;
177 explicit JitSpewIndent(JitSpewChannel channel
);
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, ...) \
207 if (JitSpewEnabled(channel)) { \
208 JitSpew(channel, fmt, __VA_ARGS__); \
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
{
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
{
245 explicit JitSpewIndent(JitSpewChannel channel
) {}
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
252 static inline void JitSpewCheckArguments(JitSpewChannel channel
,
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
,
273 static inline void JitSpewDef(JitSpewChannel channel
, const char* str
,
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 */
286 #endif /* jit_JitSpewer_h */