|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
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_IonSpewer_h |
|
8 #define jit_IonSpewer_h |
|
9 |
|
10 #include "mozilla/DebugOnly.h" |
|
11 |
|
12 #include <stdarg.h> |
|
13 |
|
14 #include "jit/C1Spewer.h" |
|
15 #include "jit/JSONSpewer.h" |
|
16 #include "js/RootingAPI.h" |
|
17 |
|
18 namespace js { |
|
19 namespace jit { |
|
20 |
|
21 // New channels may be added below. |
|
22 #define IONSPEW_CHANNEL_LIST(_) \ |
|
23 /* Used to abort SSA construction */ \ |
|
24 _(Abort) \ |
|
25 /* Information about compiled scripts */\ |
|
26 _(Scripts) \ |
|
27 /* Information during MIR building */ \ |
|
28 _(Logs) \ |
|
29 /* Info about failing to log script */ \ |
|
30 _(MIR) \ |
|
31 /* Information during alias analysis */ \ |
|
32 _(Alias) \ |
|
33 /* Information during GVN */ \ |
|
34 _(GVN) \ |
|
35 /* Information during Range analysis */ \ |
|
36 _(Range) \ |
|
37 /* Information during LICM */ \ |
|
38 _(LICM) \ |
|
39 /* Information during regalloc */ \ |
|
40 _(RegAlloc) \ |
|
41 /* Information during inlining */ \ |
|
42 _(Inlining) \ |
|
43 /* Information during codegen */ \ |
|
44 _(Codegen) \ |
|
45 /* Information during bailouts */ \ |
|
46 _(Bailouts) \ |
|
47 /* Information during OSI */ \ |
|
48 _(Invalidate) \ |
|
49 /* Debug info about snapshots */ \ |
|
50 _(Snapshots) \ |
|
51 /* Generated inline cache stubs */ \ |
|
52 _(InlineCaches) \ |
|
53 /* Debug info about safepoints */ \ |
|
54 _(Safepoints) \ |
|
55 /* Debug info about Pools*/ \ |
|
56 _(Pools) \ |
|
57 /* Calls to js::jit::Trace() */ \ |
|
58 _(Trace) \ |
|
59 /* Debug info about the I$ */ \ |
|
60 _(CacheFlush) \ |
|
61 \ |
|
62 /* BASELINE COMPILER SPEW */ \ |
|
63 \ |
|
64 /* Aborting Script Compilation. */ \ |
|
65 _(BaselineAbort) \ |
|
66 /* Script Compilation. */ \ |
|
67 _(BaselineScripts) \ |
|
68 /* Detailed op-specific spew. */ \ |
|
69 _(BaselineOp) \ |
|
70 /* Inline caches. */ \ |
|
71 _(BaselineIC) \ |
|
72 /* Inline cache fallbacks. */ \ |
|
73 _(BaselineICFallback) \ |
|
74 /* OSR from Baseline => Ion. */ \ |
|
75 _(BaselineOSR) \ |
|
76 /* Bailouts. */ \ |
|
77 _(BaselineBailouts) \ |
|
78 /* Debug Mode On Stack Recompile . */ \ |
|
79 _(BaselineDebugModeOSR) |
|
80 |
|
81 |
|
82 enum IonSpewChannel { |
|
83 #define IONSPEW_CHANNEL(name) IonSpew_##name, |
|
84 IONSPEW_CHANNEL_LIST(IONSPEW_CHANNEL) |
|
85 #undef IONSPEW_CHANNEL |
|
86 IonSpew_Terminator |
|
87 }; |
|
88 |
|
89 |
|
90 // The IonSpewer is only available on debug builds. |
|
91 // None of the global functions have effect on non-debug builds. |
|
92 static const int NULL_ID = -1; |
|
93 |
|
94 #ifdef DEBUG |
|
95 |
|
96 class IonSpewer |
|
97 { |
|
98 private: |
|
99 MIRGraph *graph; |
|
100 JS::HandleScript function; |
|
101 C1Spewer c1Spewer; |
|
102 JSONSpewer jsonSpewer; |
|
103 bool inited_; |
|
104 |
|
105 public: |
|
106 IonSpewer() |
|
107 : graph(nullptr), function(NullPtr()), inited_(false) |
|
108 { } |
|
109 |
|
110 // File output is terminated safely upon destruction. |
|
111 ~IonSpewer(); |
|
112 |
|
113 bool init(); |
|
114 void beginFunction(MIRGraph *graph, JS::HandleScript); |
|
115 bool isSpewingFunction() const; |
|
116 void spewPass(const char *pass); |
|
117 void spewPass(const char *pass, LinearScanAllocator *ra); |
|
118 void endFunction(); |
|
119 }; |
|
120 |
|
121 void IonSpewNewFunction(MIRGraph *graph, JS::HandleScript function); |
|
122 void IonSpewPass(const char *pass); |
|
123 void IonSpewPass(const char *pass, LinearScanAllocator *ra); |
|
124 void IonSpewEndFunction(); |
|
125 |
|
126 void CheckLogging(); |
|
127 extern FILE *IonSpewFile; |
|
128 void IonSpew(IonSpewChannel channel, const char *fmt, ...); |
|
129 void IonSpewStart(IonSpewChannel channel, const char *fmt, ...); |
|
130 void IonSpewCont(IonSpewChannel channel, const char *fmt, ...); |
|
131 void IonSpewFin(IonSpewChannel channel); |
|
132 void IonSpewHeader(IonSpewChannel channel); |
|
133 bool IonSpewEnabled(IonSpewChannel channel); |
|
134 void IonSpewVA(IonSpewChannel channel, const char *fmt, va_list ap); |
|
135 void IonSpewStartVA(IonSpewChannel channel, const char *fmt, va_list ap); |
|
136 void IonSpewContVA(IonSpewChannel channel, const char *fmt, va_list ap); |
|
137 |
|
138 void EnableChannel(IonSpewChannel channel); |
|
139 void DisableChannel(IonSpewChannel channel); |
|
140 void EnableIonDebugLogging(); |
|
141 |
|
142 #else |
|
143 |
|
144 static inline void IonSpewNewFunction(MIRGraph *graph, JS::HandleScript function) |
|
145 { } |
|
146 static inline void IonSpewPass(const char *pass) |
|
147 { } |
|
148 static inline void IonSpewPass(const char *pass, LinearScanAllocator *ra) |
|
149 { } |
|
150 static inline void IonSpewEndFunction() |
|
151 { } |
|
152 |
|
153 static inline void CheckLogging() |
|
154 { } |
|
155 static FILE *const IonSpewFile = nullptr; |
|
156 static inline void IonSpew(IonSpewChannel, const char *fmt, ...) |
|
157 { } |
|
158 static inline void IonSpewStart(IonSpewChannel channel, const char *fmt, ...) |
|
159 { } |
|
160 static inline void IonSpewCont(IonSpewChannel channel, const char *fmt, ...) |
|
161 { } |
|
162 static inline void IonSpewFin(IonSpewChannel channel) |
|
163 { } |
|
164 |
|
165 static inline void IonSpewHeader(IonSpewChannel channel) |
|
166 { } |
|
167 static inline bool IonSpewEnabled(IonSpewChannel channel) |
|
168 { return false; } |
|
169 static inline void IonSpewVA(IonSpewChannel channel, const char *fmt, va_list ap) |
|
170 { } |
|
171 |
|
172 static inline void EnableChannel(IonSpewChannel) |
|
173 { } |
|
174 static inline void DisableChannel(IonSpewChannel) |
|
175 { } |
|
176 static inline void EnableIonDebugLogging() |
|
177 { } |
|
178 |
|
179 #endif /* DEBUG */ |
|
180 |
|
181 template <IonSpewChannel Channel> |
|
182 class AutoDisableSpew |
|
183 { |
|
184 mozilla::DebugOnly<bool> enabled_; |
|
185 |
|
186 public: |
|
187 AutoDisableSpew() |
|
188 : enabled_(IonSpewEnabled(Channel)) |
|
189 { |
|
190 DisableChannel(Channel); |
|
191 } |
|
192 |
|
193 ~AutoDisableSpew() |
|
194 { |
|
195 #ifdef DEBUG |
|
196 if (enabled_) |
|
197 EnableChannel(Channel); |
|
198 #endif |
|
199 } |
|
200 }; |
|
201 |
|
202 } /* ion */ |
|
203 } /* js */ |
|
204 |
|
205 #endif /* jit_IonSpewer_h */ |