js/src/jit/BytecodeAnalysis.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/BytecodeAnalysis.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     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_BytecodeAnalysis_h
    1.11 +#define jit_BytecodeAnalysis_h
    1.12 +
    1.13 +#include "jsscript.h"
    1.14 +#include "jit/IonAllocPolicy.h"
    1.15 +#include "js/Vector.h"
    1.16 +
    1.17 +namespace js {
    1.18 +namespace jit {
    1.19 +
    1.20 +// Basic information about bytecodes in the script.  Used to help baseline compilation.
    1.21 +struct BytecodeInfo
    1.22 +{
    1.23 +    static const uint16_t MAX_STACK_DEPTH = 0xffffU;
    1.24 +    uint16_t stackDepth;
    1.25 +    bool initialized : 1;
    1.26 +    bool jumpTarget : 1;
    1.27 +    bool jumpFallthrough : 1;
    1.28 +    bool fallthrough : 1;
    1.29 +
    1.30 +    // If true, this is a JSOP_LOOPENTRY op inside a catch or finally block.
    1.31 +    bool loopEntryInCatchOrFinally : 1;
    1.32 +
    1.33 +    void init(unsigned depth) {
    1.34 +        JS_ASSERT(depth <= MAX_STACK_DEPTH);
    1.35 +        JS_ASSERT_IF(initialized, stackDepth == depth);
    1.36 +        initialized = true;
    1.37 +        stackDepth = depth;
    1.38 +    }
    1.39 +};
    1.40 +
    1.41 +class BytecodeAnalysis
    1.42 +{
    1.43 +    JSScript *script_;
    1.44 +    Vector<BytecodeInfo, 0, IonAllocPolicy> infos_;
    1.45 +
    1.46 +    bool usesScopeChain_;
    1.47 +    bool hasTryFinally_;
    1.48 +    bool hasSetArg_;
    1.49 +
    1.50 +  public:
    1.51 +    explicit BytecodeAnalysis(TempAllocator &alloc, JSScript *script);
    1.52 +
    1.53 +    bool init(TempAllocator &alloc, GSNCache &gsn);
    1.54 +
    1.55 +    BytecodeInfo &info(jsbytecode *pc) {
    1.56 +        JS_ASSERT(infos_[script_->pcToOffset(pc)].initialized);
    1.57 +        return infos_[script_->pcToOffset(pc)];
    1.58 +    }
    1.59 +
    1.60 +    BytecodeInfo *maybeInfo(jsbytecode *pc) {
    1.61 +        if (infos_[script_->pcToOffset(pc)].initialized)
    1.62 +            return &infos_[script_->pcToOffset(pc)];
    1.63 +        return nullptr;
    1.64 +    }
    1.65 +
    1.66 +    bool usesScopeChain() const {
    1.67 +        return usesScopeChain_;
    1.68 +    }
    1.69 +
    1.70 +    bool hasTryFinally() const {
    1.71 +        return hasTryFinally_;
    1.72 +    }
    1.73 +
    1.74 +    bool hasSetArg() const {
    1.75 +        return hasSetArg_;
    1.76 +    }
    1.77 +};
    1.78 +
    1.79 +
    1.80 +} // namespace jit
    1.81 +} // namespace js
    1.82 +
    1.83 +#endif /* jit_BytecodeAnalysis_h */

mercurial