js/src/jit/shared/CodeGenerator-x86-shared.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit/shared/CodeGenerator-x86-shared.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,197 @@
     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_shared_CodeGenerator_x86_shared_h
    1.11 +#define jit_shared_CodeGenerator_x86_shared_h
    1.12 +
    1.13 +#include "jit/shared/CodeGenerator-shared.h"
    1.14 +
    1.15 +namespace js {
    1.16 +namespace jit {
    1.17 +
    1.18 +class OutOfLineBailout;
    1.19 +class OutOfLineUndoALUOperation;
    1.20 +class MulNegativeZeroCheck;
    1.21 +class ModOverflowCheck;
    1.22 +class ReturnZero;
    1.23 +class OutOfLineTableSwitch;
    1.24 +
    1.25 +class CodeGeneratorX86Shared : public CodeGeneratorShared
    1.26 +{
    1.27 +    friend class MoveResolverX86;
    1.28 +
    1.29 +    CodeGeneratorX86Shared *thisFromCtor() {
    1.30 +        return this;
    1.31 +    }
    1.32 +
    1.33 +    template <typename T>
    1.34 +    bool bailout(const T &t, LSnapshot *snapshot);
    1.35 +
    1.36 +  protected:
    1.37 +    // Label for the common return path.
    1.38 +    NonAssertingLabel returnLabel_;
    1.39 +    NonAssertingLabel deoptLabel_;
    1.40 +
    1.41 +    inline Operand ToOperand(const LAllocation &a) {
    1.42 +        if (a.isGeneralReg())
    1.43 +            return Operand(a.toGeneralReg()->reg());
    1.44 +        if (a.isFloatReg())
    1.45 +            return Operand(a.toFloatReg()->reg());
    1.46 +        return Operand(StackPointer, ToStackOffset(&a));
    1.47 +    }
    1.48 +    inline Operand ToOperand(const LAllocation *a) {
    1.49 +        return ToOperand(*a);
    1.50 +    }
    1.51 +    inline Operand ToOperand(const LDefinition *def) {
    1.52 +        return ToOperand(def->output());
    1.53 +    }
    1.54 +
    1.55 +    MoveOperand toMoveOperand(const LAllocation *a) const;
    1.56 +
    1.57 +    bool bailoutIf(Assembler::Condition condition, LSnapshot *snapshot);
    1.58 +    bool bailoutIf(Assembler::DoubleCondition condition, LSnapshot *snapshot);
    1.59 +    bool bailoutFrom(Label *label, LSnapshot *snapshot);
    1.60 +    bool bailout(LSnapshot *snapshot);
    1.61 +
    1.62 +    template <typename T1, typename T2>
    1.63 +    bool bailoutCmpPtr(Assembler::Condition c, T1 lhs, T2 rhs, LSnapshot *snapshot) {
    1.64 +        masm.cmpPtr(lhs, rhs);
    1.65 +        return bailoutIf(c, snapshot);
    1.66 +    }
    1.67 +    bool bailoutTestPtr(Assembler::Condition c, Register lhs, Register rhs, LSnapshot *snapshot) {
    1.68 +        masm.testPtr(lhs, rhs);
    1.69 +        return bailoutIf(c, snapshot);
    1.70 +    }
    1.71 +    template <typename T1, typename T2>
    1.72 +    bool bailoutCmp32(Assembler::Condition c, T1 lhs, T2 rhs, LSnapshot *snapshot) {
    1.73 +        masm.cmp32(lhs, rhs);
    1.74 +        return bailoutIf(c, snapshot);
    1.75 +    }
    1.76 +    template <typename T1, typename T2>
    1.77 +    bool bailoutTest32(Assembler::Condition c, T1 lhs, T2 rhs, LSnapshot *snapshot) {
    1.78 +        masm.test32(lhs, rhs);
    1.79 +        return bailoutIf(c, snapshot);
    1.80 +    }
    1.81 +
    1.82 +  protected:
    1.83 +    bool generatePrologue();
    1.84 +    bool generateAsmJSPrologue(Label *stackOverflowLabe);
    1.85 +    bool generateEpilogue();
    1.86 +    bool generateOutOfLineCode();
    1.87 +
    1.88 +    Operand createArrayElementOperand(Register elements, const LAllocation *index);
    1.89 +
    1.90 +    void emitCompare(MCompare::CompareType type, const LAllocation *left, const LAllocation *right);
    1.91 +
    1.92 +    // Emits a branch that directs control flow to the true block if |cond| is
    1.93 +    // true, and the false block if |cond| is false.
    1.94 +    void emitBranch(Assembler::Condition cond, MBasicBlock *ifTrue, MBasicBlock *ifFalse,
    1.95 +                    Assembler::NaNCond ifNaN = Assembler::NaN_HandledByCond);
    1.96 +    void emitBranch(Assembler::DoubleCondition cond, MBasicBlock *ifTrue, MBasicBlock *ifFalse);
    1.97 +
    1.98 +    void testNullEmitBranch(Assembler::Condition cond, const ValueOperand &value,
    1.99 +                            MBasicBlock *ifTrue, MBasicBlock *ifFalse)
   1.100 +    {
   1.101 +        cond = masm.testNull(cond, value);
   1.102 +        emitBranch(cond, ifTrue, ifFalse);
   1.103 +    }
   1.104 +    void testUndefinedEmitBranch(Assembler::Condition cond, const ValueOperand &value,
   1.105 +                                 MBasicBlock *ifTrue, MBasicBlock *ifFalse)
   1.106 +    {
   1.107 +        cond = masm.testUndefined(cond, value);
   1.108 +        emitBranch(cond, ifTrue, ifFalse);
   1.109 +    }
   1.110 +
   1.111 +    bool emitTableSwitchDispatch(MTableSwitch *mir, const Register &index, const Register &base);
   1.112 +
   1.113 +  public:
   1.114 +    CodeGeneratorX86Shared(MIRGenerator *gen, LIRGraph *graph, MacroAssembler *masm);
   1.115 +
   1.116 +  public:
   1.117 +    // Instruction visitors.
   1.118 +    virtual bool visitDouble(LDouble *ins);
   1.119 +    virtual bool visitFloat32(LFloat32 *ins);
   1.120 +    virtual bool visitMinMaxD(LMinMaxD *ins);
   1.121 +    virtual bool visitAbsD(LAbsD *ins);
   1.122 +    virtual bool visitAbsF(LAbsF *ins);
   1.123 +    virtual bool visitSqrtD(LSqrtD *ins);
   1.124 +    virtual bool visitSqrtF(LSqrtF *ins);
   1.125 +    virtual bool visitPowHalfD(LPowHalfD *ins);
   1.126 +    virtual bool visitAddI(LAddI *ins);
   1.127 +    virtual bool visitSubI(LSubI *ins);
   1.128 +    virtual bool visitMulI(LMulI *ins);
   1.129 +    virtual bool visitDivI(LDivI *ins);
   1.130 +    virtual bool visitDivPowTwoI(LDivPowTwoI *ins);
   1.131 +    virtual bool visitDivOrModConstantI(LDivOrModConstantI *ins);
   1.132 +    virtual bool visitModI(LModI *ins);
   1.133 +    virtual bool visitModPowTwoI(LModPowTwoI *ins);
   1.134 +    virtual bool visitBitNotI(LBitNotI *ins);
   1.135 +    virtual bool visitBitOpI(LBitOpI *ins);
   1.136 +    virtual bool visitShiftI(LShiftI *ins);
   1.137 +    virtual bool visitUrshD(LUrshD *ins);
   1.138 +    virtual bool visitTestIAndBranch(LTestIAndBranch *test);
   1.139 +    virtual bool visitTestDAndBranch(LTestDAndBranch *test);
   1.140 +    virtual bool visitTestFAndBranch(LTestFAndBranch *test);
   1.141 +    virtual bool visitCompare(LCompare *comp);
   1.142 +    virtual bool visitCompareAndBranch(LCompareAndBranch *comp);
   1.143 +    virtual bool visitCompareD(LCompareD *comp);
   1.144 +    virtual bool visitCompareDAndBranch(LCompareDAndBranch *comp);
   1.145 +    virtual bool visitCompareF(LCompareF *comp);
   1.146 +    virtual bool visitCompareFAndBranch(LCompareFAndBranch *comp);
   1.147 +    virtual bool visitBitAndAndBranch(LBitAndAndBranch *baab);
   1.148 +    virtual bool visitNotI(LNotI *comp);
   1.149 +    virtual bool visitNotD(LNotD *comp);
   1.150 +    virtual bool visitNotF(LNotF *comp);
   1.151 +    virtual bool visitMathD(LMathD *math);
   1.152 +    virtual bool visitMathF(LMathF *math);
   1.153 +    virtual bool visitFloor(LFloor *lir);
   1.154 +    virtual bool visitFloorF(LFloorF *lir);
   1.155 +    virtual bool visitRound(LRound *lir);
   1.156 +    virtual bool visitRoundF(LRoundF *lir);
   1.157 +    virtual bool visitGuardShape(LGuardShape *guard);
   1.158 +    virtual bool visitGuardObjectType(LGuardObjectType *guard);
   1.159 +    virtual bool visitGuardClass(LGuardClass *guard);
   1.160 +    virtual bool visitEffectiveAddress(LEffectiveAddress *ins);
   1.161 +    virtual bool visitUDivOrMod(LUDivOrMod *ins);
   1.162 +    virtual bool visitAsmJSPassStackArg(LAsmJSPassStackArg *ins);
   1.163 +
   1.164 +    bool visitForkJoinGetSlice(LForkJoinGetSlice *ins);
   1.165 +
   1.166 +    bool visitNegI(LNegI *lir);
   1.167 +    bool visitNegD(LNegD *lir);
   1.168 +    bool visitNegF(LNegF *lir);
   1.169 +
   1.170 +    // Out of line visitors.
   1.171 +    bool visitOutOfLineBailout(OutOfLineBailout *ool);
   1.172 +    bool visitOutOfLineUndoALUOperation(OutOfLineUndoALUOperation *ool);
   1.173 +    bool visitMulNegativeZeroCheck(MulNegativeZeroCheck *ool);
   1.174 +    bool visitModOverflowCheck(ModOverflowCheck *ool);
   1.175 +    bool visitReturnZero(ReturnZero *ool);
   1.176 +    bool visitOutOfLineTableSwitch(OutOfLineTableSwitch *ool);
   1.177 +    bool generateInvalidateEpilogue();
   1.178 +};
   1.179 +
   1.180 +// An out-of-line bailout thunk.
   1.181 +class OutOfLineBailout : public OutOfLineCodeBase<CodeGeneratorX86Shared>
   1.182 +{
   1.183 +    LSnapshot *snapshot_;
   1.184 +
   1.185 +  public:
   1.186 +    OutOfLineBailout(LSnapshot *snapshot)
   1.187 +      : snapshot_(snapshot)
   1.188 +    { }
   1.189 +
   1.190 +    bool accept(CodeGeneratorX86Shared *codegen);
   1.191 +
   1.192 +    LSnapshot *snapshot() const {
   1.193 +        return snapshot_;
   1.194 +    }
   1.195 +};
   1.196 +
   1.197 +} // namespace jit
   1.198 +} // namespace js
   1.199 +
   1.200 +#endif /* jit_shared_CodeGenerator_x86_shared_h */

mercurial