js/src/jit/BaselineCompiler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/BaselineCompiler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,275 @@
     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_BaselineCompiler_h
    1.11 +#define jit_BaselineCompiler_h
    1.12 +
    1.13 +#ifdef JS_ION
    1.14 +
    1.15 +#include "jit/FixedList.h"
    1.16 +#if defined(JS_CODEGEN_X86)
    1.17 +# include "jit/x86/BaselineCompiler-x86.h"
    1.18 +#elif defined(JS_CODEGEN_X64)
    1.19 +# include "jit/x64/BaselineCompiler-x64.h"
    1.20 +#elif defined(JS_CODEGEN_ARM)
    1.21 +# include "jit/arm/BaselineCompiler-arm.h"
    1.22 +#elif defined(JS_CODEGEN_MIPS)
    1.23 +# include "jit/mips/BaselineCompiler-mips.h"
    1.24 +#else
    1.25 +# error "Unknown architecture!"
    1.26 +#endif
    1.27 +
    1.28 +namespace js {
    1.29 +namespace jit {
    1.30 +
    1.31 +#define OPCODE_LIST(_)         \
    1.32 +    _(JSOP_NOP)                \
    1.33 +    _(JSOP_LABEL)              \
    1.34 +    _(JSOP_POP)                \
    1.35 +    _(JSOP_POPN)               \
    1.36 +    _(JSOP_DUPAT)              \
    1.37 +    _(JSOP_ENTERWITH)          \
    1.38 +    _(JSOP_LEAVEWITH)          \
    1.39 +    _(JSOP_DUP)                \
    1.40 +    _(JSOP_DUP2)               \
    1.41 +    _(JSOP_SWAP)               \
    1.42 +    _(JSOP_PICK)               \
    1.43 +    _(JSOP_GOTO)               \
    1.44 +    _(JSOP_IFEQ)               \
    1.45 +    _(JSOP_IFNE)               \
    1.46 +    _(JSOP_AND)                \
    1.47 +    _(JSOP_OR)                 \
    1.48 +    _(JSOP_NOT)                \
    1.49 +    _(JSOP_POS)                \
    1.50 +    _(JSOP_LOOPHEAD)           \
    1.51 +    _(JSOP_LOOPENTRY)          \
    1.52 +    _(JSOP_VOID)               \
    1.53 +    _(JSOP_UNDEFINED)          \
    1.54 +    _(JSOP_HOLE)               \
    1.55 +    _(JSOP_NULL)               \
    1.56 +    _(JSOP_THIS)               \
    1.57 +    _(JSOP_TRUE)               \
    1.58 +    _(JSOP_FALSE)              \
    1.59 +    _(JSOP_ZERO)               \
    1.60 +    _(JSOP_ONE)                \
    1.61 +    _(JSOP_INT8)               \
    1.62 +    _(JSOP_INT32)              \
    1.63 +    _(JSOP_UINT16)             \
    1.64 +    _(JSOP_UINT24)             \
    1.65 +    _(JSOP_DOUBLE)             \
    1.66 +    _(JSOP_STRING)             \
    1.67 +    _(JSOP_OBJECT)             \
    1.68 +    _(JSOP_REGEXP)             \
    1.69 +    _(JSOP_LAMBDA)             \
    1.70 +    _(JSOP_LAMBDA_ARROW)       \
    1.71 +    _(JSOP_BITOR)              \
    1.72 +    _(JSOP_BITXOR)             \
    1.73 +    _(JSOP_BITAND)             \
    1.74 +    _(JSOP_LSH)                \
    1.75 +    _(JSOP_RSH)                \
    1.76 +    _(JSOP_URSH)               \
    1.77 +    _(JSOP_ADD)                \
    1.78 +    _(JSOP_SUB)                \
    1.79 +    _(JSOP_MUL)                \
    1.80 +    _(JSOP_DIV)                \
    1.81 +    _(JSOP_MOD)                \
    1.82 +    _(JSOP_LT)                 \
    1.83 +    _(JSOP_LE)                 \
    1.84 +    _(JSOP_GT)                 \
    1.85 +    _(JSOP_GE)                 \
    1.86 +    _(JSOP_EQ)                 \
    1.87 +    _(JSOP_NE)                 \
    1.88 +    _(JSOP_STRICTEQ)           \
    1.89 +    _(JSOP_STRICTNE)           \
    1.90 +    _(JSOP_CONDSWITCH)         \
    1.91 +    _(JSOP_CASE)               \
    1.92 +    _(JSOP_DEFAULT)            \
    1.93 +    _(JSOP_LINENO)             \
    1.94 +    _(JSOP_BITNOT)             \
    1.95 +    _(JSOP_NEG)                \
    1.96 +    _(JSOP_NEWARRAY)           \
    1.97 +    _(JSOP_INITELEM_ARRAY)     \
    1.98 +    _(JSOP_NEWOBJECT)          \
    1.99 +    _(JSOP_NEWINIT)            \
   1.100 +    _(JSOP_INITELEM)           \
   1.101 +    _(JSOP_INITELEM_GETTER)    \
   1.102 +    _(JSOP_INITELEM_SETTER)    \
   1.103 +    _(JSOP_MUTATEPROTO)        \
   1.104 +    _(JSOP_INITPROP)           \
   1.105 +    _(JSOP_INITPROP_GETTER)    \
   1.106 +    _(JSOP_INITPROP_SETTER)    \
   1.107 +    _(JSOP_ENDINIT)            \
   1.108 +    _(JSOP_ARRAYPUSH)          \
   1.109 +    _(JSOP_GETELEM)            \
   1.110 +    _(JSOP_SETELEM)            \
   1.111 +    _(JSOP_CALLELEM)           \
   1.112 +    _(JSOP_DELELEM)            \
   1.113 +    _(JSOP_IN)                 \
   1.114 +    _(JSOP_GETGNAME)           \
   1.115 +    _(JSOP_BINDGNAME)          \
   1.116 +    _(JSOP_SETGNAME)           \
   1.117 +    _(JSOP_SETNAME)            \
   1.118 +    _(JSOP_GETPROP)            \
   1.119 +    _(JSOP_SETPROP)            \
   1.120 +    _(JSOP_CALLPROP)           \
   1.121 +    _(JSOP_DELPROP)            \
   1.122 +    _(JSOP_LENGTH)             \
   1.123 +    _(JSOP_GETXPROP)           \
   1.124 +    _(JSOP_GETALIASEDVAR)      \
   1.125 +    _(JSOP_SETALIASEDVAR)      \
   1.126 +    _(JSOP_NAME)               \
   1.127 +    _(JSOP_BINDNAME)           \
   1.128 +    _(JSOP_DELNAME)            \
   1.129 +    _(JSOP_GETINTRINSIC)       \
   1.130 +    _(JSOP_DEFVAR)             \
   1.131 +    _(JSOP_DEFCONST)           \
   1.132 +    _(JSOP_SETCONST)           \
   1.133 +    _(JSOP_DEFFUN)             \
   1.134 +    _(JSOP_GETLOCAL)           \
   1.135 +    _(JSOP_SETLOCAL)           \
   1.136 +    _(JSOP_GETARG)             \
   1.137 +    _(JSOP_SETARG)             \
   1.138 +    _(JSOP_CALL)               \
   1.139 +    _(JSOP_FUNCALL)            \
   1.140 +    _(JSOP_FUNAPPLY)           \
   1.141 +    _(JSOP_NEW)                \
   1.142 +    _(JSOP_EVAL)               \
   1.143 +    _(JSOP_IMPLICITTHIS)       \
   1.144 +    _(JSOP_INSTANCEOF)         \
   1.145 +    _(JSOP_TYPEOF)             \
   1.146 +    _(JSOP_TYPEOFEXPR)         \
   1.147 +    _(JSOP_SETCALL)            \
   1.148 +    _(JSOP_THROW)              \
   1.149 +    _(JSOP_TRY)                \
   1.150 +    _(JSOP_FINALLY)            \
   1.151 +    _(JSOP_GOSUB)              \
   1.152 +    _(JSOP_RETSUB)             \
   1.153 +    _(JSOP_PUSHBLOCKSCOPE)     \
   1.154 +    _(JSOP_POPBLOCKSCOPE)      \
   1.155 +    _(JSOP_DEBUGLEAVEBLOCK)    \
   1.156 +    _(JSOP_EXCEPTION)          \
   1.157 +    _(JSOP_DEBUGGER)           \
   1.158 +    _(JSOP_ARGUMENTS)          \
   1.159 +    _(JSOP_RUNONCE)            \
   1.160 +    _(JSOP_REST)               \
   1.161 +    _(JSOP_TOID)               \
   1.162 +    _(JSOP_TABLESWITCH)        \
   1.163 +    _(JSOP_ITER)               \
   1.164 +    _(JSOP_MOREITER)           \
   1.165 +    _(JSOP_ITERNEXT)           \
   1.166 +    _(JSOP_ENDITER)            \
   1.167 +    _(JSOP_CALLEE)             \
   1.168 +    _(JSOP_SETRVAL)            \
   1.169 +    _(JSOP_RETRVAL)            \
   1.170 +    _(JSOP_RETURN)
   1.171 +
   1.172 +class BaselineCompiler : public BaselineCompilerSpecific
   1.173 +{
   1.174 +    FixedList<Label>            labels_;
   1.175 +    NonAssertingLabel           return_;
   1.176 +#ifdef JSGC_GENERATIONAL
   1.177 +    NonAssertingLabel           postBarrierSlot_;
   1.178 +#endif
   1.179 +
   1.180 +    // Native code offset right before the scope chain is initialized.
   1.181 +    CodeOffsetLabel prologueOffset_;
   1.182 +
   1.183 +    // Native code offset right before the frame is popped and the method
   1.184 +    // returned from.
   1.185 +    CodeOffsetLabel epilogueOffset_;
   1.186 +
   1.187 +    // Native code offset right after debug prologue and epilogue, or
   1.188 +    // equivalent positions when debug mode is off.
   1.189 +    CodeOffsetLabel postDebugPrologueOffset_;
   1.190 +
   1.191 +    // Whether any on stack arguments are modified.
   1.192 +    bool modifiesArguments_;
   1.193 +
   1.194 +    Label *labelOf(jsbytecode *pc) {
   1.195 +        return &labels_[script->pcToOffset(pc)];
   1.196 +    }
   1.197 +
   1.198 +    // If a script has more |nslots| than this, then emit code to do an
   1.199 +    // early stack check.
   1.200 +    static const unsigned EARLY_STACK_CHECK_SLOT_COUNT = 128;
   1.201 +    bool needsEarlyStackCheck() const {
   1.202 +        return script->nslots() > EARLY_STACK_CHECK_SLOT_COUNT;
   1.203 +    }
   1.204 +
   1.205 +  public:
   1.206 +    BaselineCompiler(JSContext *cx, TempAllocator &alloc, JSScript *script);
   1.207 +    bool init();
   1.208 +
   1.209 +    MethodStatus compile();
   1.210 +
   1.211 +  private:
   1.212 +    MethodStatus emitBody();
   1.213 +
   1.214 +    bool emitPrologue();
   1.215 +    bool emitEpilogue();
   1.216 +#ifdef JSGC_GENERATIONAL
   1.217 +    bool emitOutOfLinePostBarrierSlot();
   1.218 +#endif
   1.219 +    bool emitIC(ICStub *stub, ICEntry::Kind kind);
   1.220 +    bool emitOpIC(ICStub *stub) {
   1.221 +        return emitIC(stub, ICEntry::Kind_Op);
   1.222 +    }
   1.223 +    bool emitNonOpIC(ICStub *stub) {
   1.224 +        return emitIC(stub, ICEntry::Kind_NonOp);
   1.225 +    }
   1.226 +
   1.227 +    bool emitStackCheck(bool earlyCheck=false);
   1.228 +    bool emitInterruptCheck();
   1.229 +    bool emitUseCountIncrement(bool allowOsr=true);
   1.230 +    bool emitArgumentTypeChecks();
   1.231 +    bool emitDebugPrologue();
   1.232 +    bool emitDebugTrap();
   1.233 +    bool emitSPSPush();
   1.234 +    void emitSPSPop();
   1.235 +
   1.236 +    bool initScopeChain();
   1.237 +
   1.238 +    void storeValue(const StackValue *source, const Address &dest,
   1.239 +                    const ValueOperand &scratch);
   1.240 +
   1.241 +#define EMIT_OP(op) bool emit_##op();
   1.242 +    OPCODE_LIST(EMIT_OP)
   1.243 +#undef EMIT_OP
   1.244 +
   1.245 +    // JSOP_NEG, JSOP_BITNOT
   1.246 +    bool emitUnaryArith();
   1.247 +
   1.248 +    // JSOP_BITXOR, JSOP_LSH, JSOP_ADD etc.
   1.249 +    bool emitBinaryArith();
   1.250 +
   1.251 +    // Handles JSOP_LT, JSOP_GT, and friends
   1.252 +    bool emitCompare();
   1.253 +
   1.254 +    bool emitReturn();
   1.255 +
   1.256 +    bool emitToBoolean();
   1.257 +    bool emitTest(bool branchIfTrue);
   1.258 +    bool emitAndOr(bool branchIfTrue);
   1.259 +    bool emitCall();
   1.260 +
   1.261 +    bool emitInitPropGetterSetter();
   1.262 +    bool emitInitElemGetterSetter();
   1.263 +
   1.264 +    bool emitFormalArgAccess(uint32_t arg, bool get);
   1.265 +
   1.266 +    bool addPCMappingEntry(bool addIndexEntry);
   1.267 +
   1.268 +    void getScopeCoordinateObject(Register reg);
   1.269 +    Address getScopeCoordinateAddressFromObject(Register objReg, Register reg);
   1.270 +    Address getScopeCoordinateAddress(Register reg);
   1.271 +};
   1.272 +
   1.273 +} // namespace jit
   1.274 +} // namespace js
   1.275 +
   1.276 +#endif // JS_ION
   1.277 +
   1.278 +#endif /* jit_BaselineCompiler_h */

mercurial