Debian Codegraph @

js/src/jit/JitSpewer.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_JitSpewer_h
8 #define jit_JitSpewer_h
9
10 #include "mozilla/Assertions.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/DebugOnly.h"
13 #include "mozilla/IntegerPrintfMacros.h"
14
15 #include <stdarg.h>
16
17 #include "jit/JSONSpewer.h"
18 #include "js/Printer.h"
19 #include "js/TypeDecls.h"
20 #include "wasm/WasmTypeDecls.h"
21
22 enum JSValueType : uint8_t;
23
24 namespace js {
25 namespace jit {
26
27 // New channels may be added below.
28 #define JITSPEW_CHANNEL_LIST(_) \
29 /* Information during sinking */ \
30 _(Prune) \
31 /* Information during escape analysis */ \
32 _(Escape) \
33 /* Information during alias analysis */ \
34 _(Alias) \
35 /* Information during alias analysis */ \
36 _(AliasSummaries) \
37 /* Information during GVN */ \
38 _(GVN) \
39 /* Information during sinking */ \
40 _(Sink) \
41 /* Information during Range analysis */ \
42 _(Range) \
43 /* Information during LICM */ \
44 _(LICM) \
45 /* Information during Branch Hinting */ \
46 _(BranchHint) \
47 /* Info about fold linear constants */ \
48 _(FLAC) \
49 /* Effective address analysis info */ \
50 _(EAA) \
51 /* Wasm Bounds Check Elimination */ \
52 _(WasmBCE) \
53 /* Information during regalloc */ \
54 _(RegAlloc) \
55 /* Information during inlining */ \
56 _(Inlining) \
57 /* Information during codegen */ \
58 _(Codegen) \
59 /* Debug info about safepoints */ \
60 _(Safepoints) \
61 /* Debug info about Pools*/ \
62 _(Pools) \
63 /* Profiling-related information */ \
64 _(Profiling) \
65 /* Debug info about the I$ */ \
66 _(CacheFlush) \
67 /* Info about redundant shape guards */ \
68 _(RedundantShapeGuards) \
69 /* Info about redundant GC barriers */ \
70 _(RedundantGCBarriers) \
71 /* Info about loads used as keys */ \
72 _(MarkLoadsUsedAsPropertyKeys) \
73 /* Output a list of MIR expressions */ \
74 _(MIRExpressions) \
75 /* Summary info about loop unrolling */ \
76 _(Unroll) \
77 /* Detailed info about loop unrolling */ \
78 _(UnrollDetails) \
79 /* Information about stub folding */ \
80 _(StubFolding) \
81 \
82 /* BASELINE COMPILER SPEW */ \
83 \
84 /* Aborting Script Compilation. */ \
85 _(BaselineAbort) \
86 /* Script Compilation. */ \
87 _(BaselineScripts) \
88 /* Detailed op-specific spew. */ \
89 _(BaselineOp) \
90 /* Inline caches. */ \
91 _(BaselineIC) \
92 /* Inline cache fallbacks. */ \
93 _(BaselineICFallback) \
94 /* OSR from Baseline => Ion. */ \
95 _(BaselineOSR) \
96 /* Bailouts. */ \
97 _(BaselineBailouts) \
98 /* Debug Mode On Stack Recompile . */ \
99 _(BaselineDebugModeOSR) \
100 \
101 /* ION COMPILER SPEW */ \
102 \
103 /* Used to abort SSA construction */ \
104 _(IonAbort) \
105 /* Information about compiled scripts */ \
106 _(IonScripts) \
107 /* Info about failing to log script */ \
108 _(IonSyncLogs) \
109 /* Information during MIR building */ \
110 _(IonMIR) \
111 /* Information during bailouts */ \
112 _(IonBailouts) \
113 /* Information during OSI */ \
114 _(IonInvalidate) \
115 /* Debug info about snapshots */ \
116 _(IonSnapshots) \
117 /* Generated inline cache stubs */ \
118 _(IonIC) \
119 \
120 /* WARP SPEW */ \
121 \
122 /* Generated WarpSnapshots */ \
123 _(WarpSnapshots) \
124 /* CacheIR transpiler logging */ \
125 _(WarpTranspiler) \
126 /* Trial inlining for Warp */ \
127 _(WarpTrialInlining)
128
129 enum JitSpewChannel {
130 #define JITSPEW_CHANNEL(name) JitSpew_##name,
131 JITSPEW_CHANNEL_LIST(JITSPEW_CHANNEL)
132 #undef JITSPEW_CHANNEL
133 JitSpew_Terminator
134 };
135
136 class BacktrackingAllocator;
137 class MDefinition;
138 class MIRGenerator;
139 class MIRGraph;
140 class TempAllocator;
141
142 const char* ValTypeToString(JSValueType type);
143
144 // The JitSpewer is only available on debug builds.
145 // None of the global functions have effect on non-debug builds.
146 #ifdef JS_JITSPEW
147
148 // Class made to hold the MIR and LIR graphs of an Wasm / Ion compilation.
149 class GraphSpewer {
150 private:
151 MIRGraph* graph_;
152 LSprinter jsonPrinter_;
153 JSONSpewer jsonSpewer_;
154
155 public:
156 explicit GraphSpewer(TempAllocator* alloc,
157 const wasm::CodeMetadata* wasmCodeMeta = nullptr);
158
159 bool isSpewing() const { return graph_; }
160 void init(MIRGraph* graph, JSScript* function);
161 void beginFunction(JSScript* function);
162 void beginWasmFunction(unsigned funcIndex);
163 void spewPass(const char* pass);
164 void spewPass(const char* pass, BacktrackingAllocator* ra);
165 void endFunction();
166
167 void dump(Fprinter& json);
168 };
169
170 void SpewBeginFunction(MIRGenerator* mir, JSScript* function);
171 void SpewBeginWasmFunction(MIRGenerator* mir, unsigned funcIndex);
172
173 class AutoSpewEndFunction {
174 private:
175 MIRGenerator* mir_;
176
177 public:
178 explicit AutoSpewEndFunction(MIRGenerator* mir) : mir_(mir) {}
179 ~AutoSpewEndFunction();
180 };
181
182 void CheckLogging();
183 Fprinter& JitSpewPrinter();
184
185 class JitSpewIndent {
186 JitSpewChannel channel_;
187
188 public:
189 explicit JitSpewIndent(JitSpewChannel channel);
190 ~JitSpewIndent();
191 };
192
193 void JitSpew(JitSpewChannel channel, const char* fmt, ...)
194 MOZ_FORMAT_PRINTF(2, 3);
195 void JitSpewStart(JitSpewChannel channel, const char* fmt, ...)
196 MOZ_FORMAT_PRINTF(2, 3);
197 void JitSpewCont(JitSpewChannel channel, const char* fmt, ...)
198 MOZ_FORMAT_PRINTF(2, 3);
199 void JitSpewFin(JitSpewChannel channel);
200 void JitSpewHeader(JitSpewChannel channel);
201
202 } // namespace jit
203
204 namespace jitspew::detail {
205 extern bool LoggingChecked;
206 extern uint64_t LoggingBits;
207 extern mozilla::Atomic<uint32_t, mozilla::Relaxed> filteredOutCompilations;
208 } // namespace jitspew::detail
209
210 namespace jit {
211
212 static inline bool JitSpewEnabled(JitSpewChannel channel) {
213 MOZ_ASSERT(jitspew::detail::LoggingChecked);
214 return (jitspew::detail::LoggingBits & (uint64_t(1) << uint32_t(channel))) &&
215 !jitspew::detail::filteredOutCompilations;
216 }
217
218 void JitSpewVA(JitSpewChannel channel, const char* fmt, va_list ap)
219 MOZ_FORMAT_PRINTF(2, 0);
220 void JitSpewStartVA(JitSpewChannel channel, const char* fmt, va_list ap)
221 MOZ_FORMAT_PRINTF(2, 0);
222 void JitSpewContVA(JitSpewChannel channel, const char* fmt, va_list ap)
223 MOZ_FORMAT_PRINTF(2, 0);
224 void JitSpewDef(JitSpewChannel channel, const char* str, MDefinition* def);
225
226 void EnableChannel(JitSpewChannel channel);
227 void DisableChannel(JitSpewChannel channel);
228 void EnableIonDebugSyncLogging();
229 void EnableIonDebugAsyncLogging();
230
231 # define JitSpewIfEnabled(channel, fmt, ...) \
232 do { \
233 if (JitSpewEnabled(channel)) { \
234 JitSpew(channel, fmt, __VA_ARGS__); \
235 } \
236 } while (false);
237
238 #else
239
240 class GraphSpewer {
241 public:
242 explicit GraphSpewer(TempAllocator* alloc,
243 const wasm::CodeMetadata* wasmCodeMeta = nullptr) {}
244
245 bool isSpewing() { return false; }
246 void init(MIRGraph* graph, JSScript* function) {}
247 void beginFunction(JSScript* function) {}
248 void spewPass(const char* pass) {}
249 void spewPass(const char* pass, BacktrackingAllocator* ra) {}
250 void endFunction() {}
251
252 void dump(Fprinter& c1, Fprinter& json) {}
253 };
254
255 static inline void SpewBeginFunction(MIRGenerator* mir, JSScript* function) {}
256 static inline void SpewBeginWasmFunction(MIRGenerator* mir,
257 unsigned funcIndex) {}
258
259 class AutoSpewEndFunction {
260 public:
261 explicit AutoSpewEndFunction(MIRGenerator* mir) {}
262 ~AutoSpewEndFunction() {}
263 };
264
265 static inline void CheckLogging() {}
266 static inline Fprinter& JitSpewPrinter() {
267 MOZ_CRASH("No empty backend for JitSpewPrinter");
268 }
269
270 class JitSpewIndent {
271 public:
272 explicit JitSpewIndent(JitSpewChannel channel) {}
273 ~JitSpewIndent() {}
274 };
275
276 // The computation of some of the argument of the spewing functions might be
277 // costly, thus we use variaidic macros to ignore any argument of these
278 // functions.
279 static inline void JitSpewCheckArguments(JitSpewChannel channel,
280 const char* fmt) {}
281
282 # define JitSpewCheckExpandedArgs(channel, fmt, ...) \
283 JitSpewCheckArguments(channel, fmt)
284 # define JitSpewCheckExpandedArgs_(ArgList) \
285 JitSpewCheckExpandedArgs ArgList /* Fix MSVC issue */
286 # define JitSpew(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
287 # define JitSpewStart(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
288 # define JitSpewCont(...) JitSpewCheckExpandedArgs_((__VA_ARGS__))
289
290 # define JitSpewIfEnabled(channel, fmt, ...) \
291 JitSpewCheckArguments(channel, fmt)
292
293 static inline void JitSpewFin(JitSpewChannel channel) {}
294
295 static inline void JitSpewHeader(JitSpewChannel channel) {}
296 static inline bool JitSpewEnabled(JitSpewChannel channel) { return false; }
297 static inline MOZ_FORMAT_PRINTF(2, 0) void JitSpewVA(JitSpewChannel channel,
298 const char* fmt,
299 va_list ap) {}
300 static inline void JitSpewDef(JitSpewChannel channel, const char* str,
301 MDefinition* def) {}
302
303 static inline void EnableChannel(JitSpewChannel) {}
304 static inline void DisableChannel(JitSpewChannel) {}
305 static inline void EnableIonDebugSyncLogging() {}
306 static inline void EnableIonDebugAsyncLogging() {}
307
308 #endif /* JS_JITSPEW */
309
310 } // namespace jit
311 } // namespace js
312
313 #endif /* jit_JitSpewer_h */