js/src/jit/IonOptimizationLevels.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/IonOptimizationLevels.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,224 @@
     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_IonOptimizationLevels_h
    1.11 +#define jit_IonOptimizationLevels_h
    1.12 +
    1.13 +#include "jsbytecode.h"
    1.14 +#include "jstypes.h"
    1.15 +
    1.16 +#include "jit/JitOptions.h"
    1.17 +#include "js/TypeDecls.h"
    1.18 +
    1.19 +namespace js {
    1.20 +namespace jit {
    1.21 +
    1.22 +enum OptimizationLevel
    1.23 +{
    1.24 +    Optimization_DontCompile,
    1.25 +    Optimization_Normal,
    1.26 +    Optimization_AsmJS,
    1.27 +    Optimization_Count
    1.28 +};
    1.29 +
    1.30 +#ifdef JS_ION
    1.31 +
    1.32 +#ifdef DEBUG
    1.33 +inline const char *
    1.34 +OptimizationLevelString(OptimizationLevel level)
    1.35 +{
    1.36 +    switch (level) {
    1.37 +      case Optimization_DontCompile:
    1.38 +        return "Optimization_DontCompile";
    1.39 +      case Optimization_Normal:
    1.40 +        return "Optimization_Normal";
    1.41 +      case Optimization_AsmJS:
    1.42 +        return "Optimization_AsmJS";
    1.43 +      default:
    1.44 +        MOZ_ASSUME_UNREACHABLE("Invalid OptimizationLevel");
    1.45 +    }
    1.46 +}
    1.47 +#endif
    1.48 +
    1.49 +class OptimizationInfo
    1.50 +{
    1.51 +  public:
    1.52 +    OptimizationLevel level_;
    1.53 +
    1.54 +    // Toggles whether Effective Address Analysis is performed.
    1.55 +    bool eaa_;
    1.56 +
    1.57 +    // Toggles whether Edge Case Analysis is used.
    1.58 +    bool edgeCaseAnalysis_;
    1.59 +
    1.60 +    // Toggles whether redundant checks get removed.
    1.61 +    bool eliminateRedundantChecks_;
    1.62 +
    1.63 +    // Toggles whether interpreted scripts get inlined.
    1.64 +    bool inlineInterpreted_;
    1.65 +
    1.66 +    // Toggles whether native scripts get inlined.
    1.67 +    bool inlineNative_;
    1.68 +
    1.69 +    // Toggles whether global value numbering is used.
    1.70 +    bool gvn_;
    1.71 +
    1.72 +    // Toggles whether global value numbering is optimistic or pessimistic.
    1.73 +    IonGvnKind gvnKind_;
    1.74 +
    1.75 +    // Toggles whether loop invariant code motion is performed.
    1.76 +    bool licm_;
    1.77 +
    1.78 +    // Toggles whether Unreachable Code Elimination is performed.
    1.79 +    bool uce_;
    1.80 +
    1.81 +    // Toggles whether Range Analysis is used.
    1.82 +    bool rangeAnalysis_;
    1.83 +
    1.84 +    // Describes which register allocator to use.
    1.85 +    IonRegisterAllocator registerAllocator_;
    1.86 +
    1.87 +    // The maximum total bytecode size of an inline call site.
    1.88 +    uint32_t inlineMaxTotalBytecodeLength_;
    1.89 +
    1.90 +    // The maximum bytecode length the caller may have,
    1.91 +    // before we stop inlining large functions in that caller.
    1.92 +    uint32_t inliningMaxCallerBytecodeLength_;
    1.93 +
    1.94 +    // The maximum inlining depth.
    1.95 +    uint32_t maxInlineDepth_;
    1.96 +
    1.97 +    // The maximum inlining depth for functions.
    1.98 +    //
    1.99 +    // Inlining small functions has almost no compiling overhead
   1.100 +    // and removes the otherwise needed call overhead.
   1.101 +    // The value is currently very low.
   1.102 +    // Actually it is only needed to make sure we don't blow out the stack.
   1.103 +    uint32_t smallFunctionMaxInlineDepth_;
   1.104 +
   1.105 +    // How many invocations or loop iterations are needed before functions
   1.106 +    // are compiled.
   1.107 +    uint32_t usesBeforeCompile_;
   1.108 +
   1.109 +    // How many invocations or loop iterations are needed before calls
   1.110 +    // are inlined, as a fraction of usesBeforeCompile.
   1.111 +    double usesBeforeInliningFactor_;
   1.112 +
   1.113 +    OptimizationInfo()
   1.114 +    { }
   1.115 +
   1.116 +    void initNormalOptimizationInfo();
   1.117 +    void initAsmjsOptimizationInfo();
   1.118 +
   1.119 +    OptimizationLevel level() const {
   1.120 +        return level_;
   1.121 +    }
   1.122 +
   1.123 +    bool inlineInterpreted() const {
   1.124 +        return inlineInterpreted_ && !js_JitOptions.disableInlining;
   1.125 +    }
   1.126 +
   1.127 +    bool inlineNative() const {
   1.128 +        return inlineNative_ && !js_JitOptions.disableInlining;
   1.129 +    }
   1.130 +
   1.131 +    uint32_t usesBeforeCompile(JSScript *script, jsbytecode *pc = nullptr) const;
   1.132 +
   1.133 +    bool gvnEnabled() const {
   1.134 +        return gvn_ && !js_JitOptions.disableGvn;
   1.135 +    }
   1.136 +
   1.137 +    bool licmEnabled() const {
   1.138 +        return licm_ && !js_JitOptions.disableLicm;
   1.139 +    }
   1.140 +
   1.141 +    bool uceEnabled() const {
   1.142 +        return uce_ && !js_JitOptions.disableUce;
   1.143 +    }
   1.144 +
   1.145 +    bool rangeAnalysisEnabled() const {
   1.146 +        return rangeAnalysis_ && !js_JitOptions.disableRangeAnalysis;
   1.147 +    }
   1.148 +
   1.149 +    bool eaaEnabled() const {
   1.150 +        return eaa_ && !js_JitOptions.disableEaa;
   1.151 +    }
   1.152 +
   1.153 +    bool edgeCaseAnalysisEnabled() const {
   1.154 +        return edgeCaseAnalysis_ && !js_JitOptions.disableEdgeCaseAnalysis;
   1.155 +    }
   1.156 +
   1.157 +    bool eliminateRedundantChecksEnabled() const {
   1.158 +        return eliminateRedundantChecks_;
   1.159 +    }
   1.160 +
   1.161 +    IonGvnKind gvnKind() const {
   1.162 +        if (!js_JitOptions.forceGvnKind)
   1.163 +            return gvnKind_;
   1.164 +        return js_JitOptions.forcedGvnKind;
   1.165 +    }
   1.166 +
   1.167 +    IonRegisterAllocator registerAllocator() const {
   1.168 +        if (!js_JitOptions.forceRegisterAllocator)
   1.169 +            return registerAllocator_;
   1.170 +        return js_JitOptions.forcedRegisterAllocator;
   1.171 +    }
   1.172 +
   1.173 +    uint32_t smallFunctionMaxInlineDepth() const {
   1.174 +        return smallFunctionMaxInlineDepth_;
   1.175 +    }
   1.176 +
   1.177 +    bool isSmallFunction(JSScript *script) const;
   1.178 +
   1.179 +    uint32_t maxInlineDepth() const {
   1.180 +        return maxInlineDepth_;
   1.181 +    }
   1.182 +
   1.183 +    uint32_t inlineMaxTotalBytecodeLength() const {
   1.184 +        return inlineMaxTotalBytecodeLength_;
   1.185 +    }
   1.186 +
   1.187 +    uint32_t inliningMaxCallerBytecodeLength() const {
   1.188 +        return inlineMaxTotalBytecodeLength_;
   1.189 +    }
   1.190 +
   1.191 +    uint32_t usesBeforeInlining() const {
   1.192 +        uint32_t usesBeforeCompile = usesBeforeCompile_;
   1.193 +        if (js_JitOptions.forceDefaultIonUsesBeforeCompile)
   1.194 +            usesBeforeCompile = js_JitOptions.forcedDefaultIonUsesBeforeCompile;
   1.195 +        return usesBeforeCompile * usesBeforeInliningFactor_;
   1.196 +    }
   1.197 +};
   1.198 +
   1.199 +class OptimizationInfos
   1.200 +{
   1.201 +  private:
   1.202 +    OptimizationInfo infos_[Optimization_Count - 1];
   1.203 +
   1.204 +  public:
   1.205 +    OptimizationInfos();
   1.206 +
   1.207 +    const OptimizationInfo *get(OptimizationLevel level) const {
   1.208 +        JS_ASSERT(level < Optimization_Count);
   1.209 +        JS_ASSERT(level != Optimization_DontCompile);
   1.210 +
   1.211 +        return &infos_[level - 1];
   1.212 +    }
   1.213 +
   1.214 +    OptimizationLevel nextLevel(OptimizationLevel level) const;
   1.215 +    OptimizationLevel firstLevel() const;
   1.216 +    bool isLastLevel(OptimizationLevel level) const;
   1.217 +    OptimizationLevel levelForScript(JSScript *script, jsbytecode *pc = nullptr) const;
   1.218 +};
   1.219 +
   1.220 +extern OptimizationInfos js_IonOptimizations;
   1.221 +
   1.222 +#endif // JS_ION
   1.223 +
   1.224 +} // namespace jit
   1.225 +} // namespace js
   1.226 +
   1.227 +#endif /* jit_IonOptimizationLevels_h */

mercurial