js/src/jit/MIRGenerator.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/MIRGenerator.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,171 @@
     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_MIRGenerator_h
    1.11 +#define jit_MIRGenerator_h
    1.12 +
    1.13 +// This file declares the data structures used to build a control-flow graph
    1.14 +// containing MIR.
    1.15 +
    1.16 +#include "mozilla/Atomics.h"
    1.17 +
    1.18 +#include <stdarg.h>
    1.19 +
    1.20 +#include "jscntxt.h"
    1.21 +#include "jscompartment.h"
    1.22 +
    1.23 +#include "jit/CompileInfo.h"
    1.24 +#include "jit/IonAllocPolicy.h"
    1.25 +#include "jit/JitCompartment.h"
    1.26 +#ifdef JS_ION_PERF
    1.27 +# include "jit/PerfSpewer.h"
    1.28 +#endif
    1.29 +#include "jit/RegisterSets.h"
    1.30 +
    1.31 +namespace js {
    1.32 +namespace jit {
    1.33 +
    1.34 +class MBasicBlock;
    1.35 +class MIRGraph;
    1.36 +class MStart;
    1.37 +class OptimizationInfo;
    1.38 +
    1.39 +class MIRGenerator
    1.40 +{
    1.41 +  public:
    1.42 +    MIRGenerator(CompileCompartment *compartment, const JitCompileOptions &options,
    1.43 +                 TempAllocator *alloc, MIRGraph *graph,
    1.44 +                 CompileInfo *info, const OptimizationInfo *optimizationInfo);
    1.45 +
    1.46 +    TempAllocator &alloc() {
    1.47 +        return *alloc_;
    1.48 +    }
    1.49 +    MIRGraph &graph() {
    1.50 +        return *graph_;
    1.51 +    }
    1.52 +    bool ensureBallast() {
    1.53 +        return alloc().ensureBallast();
    1.54 +    }
    1.55 +    const JitRuntime *jitRuntime() const {
    1.56 +        return GetIonContext()->runtime->jitRuntime();
    1.57 +    }
    1.58 +    CompileInfo &info() {
    1.59 +        return *info_;
    1.60 +    }
    1.61 +    const OptimizationInfo &optimizationInfo() const {
    1.62 +        return *optimizationInfo_;
    1.63 +    }
    1.64 +
    1.65 +    template <typename T>
    1.66 +    T * allocate(size_t count = 1) {
    1.67 +        if (count & mozilla::tl::MulOverflowMask<sizeof(T)>::value)
    1.68 +            return nullptr;
    1.69 +        return reinterpret_cast<T *>(alloc().allocate(sizeof(T) * count));
    1.70 +    }
    1.71 +
    1.72 +    // Set an error state and prints a message. Returns false so errors can be
    1.73 +    // propagated up.
    1.74 +    bool abort(const char *message, ...);
    1.75 +    bool abortFmt(const char *message, va_list ap);
    1.76 +
    1.77 +    bool errored() const {
    1.78 +        return error_;
    1.79 +    }
    1.80 +
    1.81 +    bool instrumentedProfiling() {
    1.82 +        return GetIonContext()->runtime->spsProfiler().enabled();
    1.83 +    }
    1.84 +
    1.85 +    // Whether the main thread is trying to cancel this build.
    1.86 +    bool shouldCancel(const char *why) {
    1.87 +        return cancelBuild_;
    1.88 +    }
    1.89 +    void cancel() {
    1.90 +        cancelBuild_ = true;
    1.91 +    }
    1.92 +
    1.93 +    bool compilingAsmJS() const {
    1.94 +        return info_->script() == nullptr;
    1.95 +    }
    1.96 +
    1.97 +    uint32_t maxAsmJSStackArgBytes() const {
    1.98 +        JS_ASSERT(compilingAsmJS());
    1.99 +        return maxAsmJSStackArgBytes_;
   1.100 +    }
   1.101 +    uint32_t resetAsmJSMaxStackArgBytes() {
   1.102 +        JS_ASSERT(compilingAsmJS());
   1.103 +        uint32_t old = maxAsmJSStackArgBytes_;
   1.104 +        maxAsmJSStackArgBytes_ = 0;
   1.105 +        return old;
   1.106 +    }
   1.107 +    void setAsmJSMaxStackArgBytes(uint32_t n) {
   1.108 +        JS_ASSERT(compilingAsmJS());
   1.109 +        maxAsmJSStackArgBytes_ = n;
   1.110 +    }
   1.111 +    void setPerformsCall() {
   1.112 +        performsCall_ = true;
   1.113 +    }
   1.114 +    bool performsCall() const {
   1.115 +        return performsCall_;
   1.116 +    }
   1.117 +    void setPerformsAsmJSCall() {
   1.118 +        JS_ASSERT(compilingAsmJS());
   1.119 +        setPerformsCall();
   1.120 +        performsAsmJSCall_ = true;
   1.121 +    }
   1.122 +    bool performsAsmJSCall() const {
   1.123 +        JS_ASSERT(compilingAsmJS());
   1.124 +        return performsAsmJSCall_;
   1.125 +    }
   1.126 +    void noteMinAsmJSHeapLength(uint32_t len) {
   1.127 +        minAsmJSHeapLength_ = len;
   1.128 +    }
   1.129 +    uint32_t minAsmJSHeapLength() const {
   1.130 +        return minAsmJSHeapLength_;
   1.131 +    }
   1.132 +
   1.133 +    bool modifiesFrameArguments() const {
   1.134 +        return modifiesFrameArguments_;
   1.135 +    }
   1.136 +
   1.137 +  public:
   1.138 +    CompileCompartment *compartment;
   1.139 +
   1.140 +  protected:
   1.141 +    CompileInfo *info_;
   1.142 +    const OptimizationInfo *optimizationInfo_;
   1.143 +    TempAllocator *alloc_;
   1.144 +    JSFunction *fun_;
   1.145 +    uint32_t nslots_;
   1.146 +    MIRGraph *graph_;
   1.147 +    bool error_;
   1.148 +    mozilla::Atomic<bool, mozilla::Relaxed> cancelBuild_;
   1.149 +
   1.150 +    uint32_t maxAsmJSStackArgBytes_;
   1.151 +    bool performsCall_;
   1.152 +    bool performsAsmJSCall_;
   1.153 +    uint32_t minAsmJSHeapLength_;
   1.154 +
   1.155 +    // Keep track of whether frame arguments are modified during execution.
   1.156 +    // RegAlloc needs to know this as spilling values back to their register
   1.157 +    // slots is not compatible with that.
   1.158 +    bool modifiesFrameArguments_;
   1.159 +
   1.160 +#if defined(JS_ION_PERF)
   1.161 +    AsmJSPerfSpewer asmJSPerfSpewer_;
   1.162 +
   1.163 +  public:
   1.164 +    AsmJSPerfSpewer &perfSpewer() { return asmJSPerfSpewer_; }
   1.165 +#endif
   1.166 +
   1.167 +  public:
   1.168 +    const JitCompileOptions options;
   1.169 +};
   1.170 +
   1.171 +} // namespace jit
   1.172 +} // namespace js
   1.173 +
   1.174 +#endif /* jit_MIRGenerator_h */

mercurial