js/src/jit/IonSpewer.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/IonSpewer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,205 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef jit_IonSpewer_h
    1.11 +#define jit_IonSpewer_h
    1.12 +
    1.13 +#include "mozilla/DebugOnly.h"
    1.14 +
    1.15 +#include <stdarg.h>
    1.16 +
    1.17 +#include "jit/C1Spewer.h"
    1.18 +#include "jit/JSONSpewer.h"
    1.19 +#include "js/RootingAPI.h"
    1.20 +
    1.21 +namespace js {
    1.22 +namespace jit {
    1.23 +
    1.24 +// New channels may be added below.
    1.25 +#define IONSPEW_CHANNEL_LIST(_)             \
    1.26 +    /* Used to abort SSA construction */    \
    1.27 +    _(Abort)                                \
    1.28 +    /* Information about compiled scripts */\
    1.29 +    _(Scripts)                              \
    1.30 +    /* Information during MIR building */   \
    1.31 +    _(Logs)                                 \
    1.32 +    /* Info about failing to log script */  \
    1.33 +    _(MIR)                                  \
    1.34 +    /* Information during alias analysis */ \
    1.35 +    _(Alias)                                \
    1.36 +    /* Information during GVN */            \
    1.37 +    _(GVN)                                  \
    1.38 +    /* Information during Range analysis */ \
    1.39 +    _(Range)                                \
    1.40 +    /* Information during LICM */           \
    1.41 +    _(LICM)                                 \
    1.42 +    /* Information during regalloc */       \
    1.43 +    _(RegAlloc)                             \
    1.44 +    /* Information during inlining */       \
    1.45 +    _(Inlining)                             \
    1.46 +    /* Information during codegen */        \
    1.47 +    _(Codegen)                              \
    1.48 +    /* Information during bailouts */       \
    1.49 +    _(Bailouts)                             \
    1.50 +    /* Information during OSI */            \
    1.51 +    _(Invalidate)                           \
    1.52 +    /* Debug info about snapshots */        \
    1.53 +    _(Snapshots)                            \
    1.54 +    /* Generated inline cache stubs */      \
    1.55 +    _(InlineCaches)                         \
    1.56 +    /* Debug info about safepoints */       \
    1.57 +    _(Safepoints)                           \
    1.58 +    /* Debug info about Pools*/             \
    1.59 +    _(Pools)                                \
    1.60 +    /* Calls to js::jit::Trace() */         \
    1.61 +    _(Trace)                                \
    1.62 +    /* Debug info about the I$ */           \
    1.63 +    _(CacheFlush)                           \
    1.64 +                                            \
    1.65 +    /* BASELINE COMPILER SPEW */            \
    1.66 +                                            \
    1.67 +    /* Aborting Script Compilation. */      \
    1.68 +    _(BaselineAbort)                        \
    1.69 +    /* Script Compilation. */               \
    1.70 +    _(BaselineScripts)                      \
    1.71 +    /* Detailed op-specific spew. */        \
    1.72 +    _(BaselineOp)                           \
    1.73 +    /* Inline caches. */                    \
    1.74 +    _(BaselineIC)                           \
    1.75 +    /* Inline cache fallbacks. */           \
    1.76 +    _(BaselineICFallback)                   \
    1.77 +    /* OSR from Baseline => Ion. */         \
    1.78 +    _(BaselineOSR)                          \
    1.79 +    /* Bailouts. */                         \
    1.80 +    _(BaselineBailouts)                     \
    1.81 +    /* Debug Mode On Stack Recompile . */   \
    1.82 +    _(BaselineDebugModeOSR)
    1.83 +
    1.84 +
    1.85 +enum IonSpewChannel {
    1.86 +#define IONSPEW_CHANNEL(name) IonSpew_##name,
    1.87 +    IONSPEW_CHANNEL_LIST(IONSPEW_CHANNEL)
    1.88 +#undef IONSPEW_CHANNEL
    1.89 +    IonSpew_Terminator
    1.90 +};
    1.91 +
    1.92 +
    1.93 +// The IonSpewer is only available on debug builds.
    1.94 +// None of the global functions have effect on non-debug builds.
    1.95 +static const int NULL_ID = -1;
    1.96 +
    1.97 +#ifdef DEBUG
    1.98 +
    1.99 +class IonSpewer
   1.100 +{
   1.101 +  private:
   1.102 +    MIRGraph *graph;
   1.103 +    JS::HandleScript function;
   1.104 +    C1Spewer c1Spewer;
   1.105 +    JSONSpewer jsonSpewer;
   1.106 +    bool inited_;
   1.107 +
   1.108 +  public:
   1.109 +    IonSpewer()
   1.110 +      : graph(nullptr), function(NullPtr()), inited_(false)
   1.111 +    { }
   1.112 +
   1.113 +    // File output is terminated safely upon destruction.
   1.114 +    ~IonSpewer();
   1.115 +
   1.116 +    bool init();
   1.117 +    void beginFunction(MIRGraph *graph, JS::HandleScript);
   1.118 +    bool isSpewingFunction() const;
   1.119 +    void spewPass(const char *pass);
   1.120 +    void spewPass(const char *pass, LinearScanAllocator *ra);
   1.121 +    void endFunction();
   1.122 +};
   1.123 +
   1.124 +void IonSpewNewFunction(MIRGraph *graph, JS::HandleScript function);
   1.125 +void IonSpewPass(const char *pass);
   1.126 +void IonSpewPass(const char *pass, LinearScanAllocator *ra);
   1.127 +void IonSpewEndFunction();
   1.128 +
   1.129 +void CheckLogging();
   1.130 +extern FILE *IonSpewFile;
   1.131 +void IonSpew(IonSpewChannel channel, const char *fmt, ...);
   1.132 +void IonSpewStart(IonSpewChannel channel, const char *fmt, ...);
   1.133 +void IonSpewCont(IonSpewChannel channel, const char *fmt, ...);
   1.134 +void IonSpewFin(IonSpewChannel channel);
   1.135 +void IonSpewHeader(IonSpewChannel channel);
   1.136 +bool IonSpewEnabled(IonSpewChannel channel);
   1.137 +void IonSpewVA(IonSpewChannel channel, const char *fmt, va_list ap);
   1.138 +void IonSpewStartVA(IonSpewChannel channel, const char *fmt, va_list ap);
   1.139 +void IonSpewContVA(IonSpewChannel channel, const char *fmt, va_list ap);
   1.140 +
   1.141 +void EnableChannel(IonSpewChannel channel);
   1.142 +void DisableChannel(IonSpewChannel channel);
   1.143 +void EnableIonDebugLogging();
   1.144 +
   1.145 +#else
   1.146 +
   1.147 +static inline void IonSpewNewFunction(MIRGraph *graph, JS::HandleScript function)
   1.148 +{ }
   1.149 +static inline void IonSpewPass(const char *pass)
   1.150 +{ }
   1.151 +static inline void IonSpewPass(const char *pass, LinearScanAllocator *ra)
   1.152 +{ }
   1.153 +static inline void IonSpewEndFunction()
   1.154 +{ }
   1.155 +
   1.156 +static inline void CheckLogging()
   1.157 +{ }
   1.158 +static FILE *const IonSpewFile = nullptr;
   1.159 +static inline void IonSpew(IonSpewChannel, const char *fmt, ...)
   1.160 +{ }
   1.161 +static inline void IonSpewStart(IonSpewChannel channel, const char *fmt, ...)
   1.162 +{ }
   1.163 +static inline void IonSpewCont(IonSpewChannel channel, const char *fmt, ...)
   1.164 +{ }
   1.165 +static inline void IonSpewFin(IonSpewChannel channel)
   1.166 +{ }
   1.167 +
   1.168 +static inline void IonSpewHeader(IonSpewChannel channel)
   1.169 +{ }
   1.170 +static inline bool IonSpewEnabled(IonSpewChannel channel)
   1.171 +{ return false; }
   1.172 +static inline void IonSpewVA(IonSpewChannel channel, const char *fmt, va_list ap)
   1.173 +{ }
   1.174 +
   1.175 +static inline void EnableChannel(IonSpewChannel)
   1.176 +{ }
   1.177 +static inline void DisableChannel(IonSpewChannel)
   1.178 +{ }
   1.179 +static inline void EnableIonDebugLogging()
   1.180 +{ }
   1.181 +
   1.182 +#endif /* DEBUG */
   1.183 +
   1.184 +template <IonSpewChannel Channel>
   1.185 +class AutoDisableSpew
   1.186 +{
   1.187 +    mozilla::DebugOnly<bool> enabled_;
   1.188 +
   1.189 +  public:
   1.190 +    AutoDisableSpew()
   1.191 +      : enabled_(IonSpewEnabled(Channel))
   1.192 +    {
   1.193 +        DisableChannel(Channel);
   1.194 +    }
   1.195 +
   1.196 +    ~AutoDisableSpew()
   1.197 +    {
   1.198 +#ifdef DEBUG
   1.199 +        if (enabled_)
   1.200 +            EnableChannel(Channel);
   1.201 +#endif
   1.202 +    }
   1.203 +};
   1.204 +
   1.205 +} /* ion */
   1.206 +} /* js */
   1.207 +
   1.208 +#endif /* jit_IonSpewer_h */

mercurial