CodeGenerator-x86-shared.h (3674B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef jit_x86_shared_CodeGenerator_x86_shared_h 8 #define jit_x86_shared_CodeGenerator_x86_shared_h 9 10 #include "jit/shared/CodeGenerator-shared.h" 11 #include "js/ScalarType.h" // js::Scalar::Type 12 13 namespace js { 14 namespace jit { 15 16 class CodeGeneratorX86Shared; 17 class ModOverflowCheck; 18 class OutOfLineTableSwitch; 19 20 using OutOfLineWasmTruncateCheck = 21 OutOfLineWasmTruncateCheckBase<CodeGeneratorX86Shared>; 22 23 class CodeGeneratorX86Shared : public CodeGeneratorShared { 24 friend class MoveResolverX86; 25 26 template <typename T> 27 void bailout(const T& t, LSnapshot* snapshot); 28 29 protected: 30 CodeGeneratorX86Shared(MIRGenerator* gen, LIRGraph* graph, 31 MacroAssembler* masm, 32 const wasm::CodeMetadata* wasmCodeMeta); 33 34 NonAssertingLabel deoptLabel_; 35 36 Operand ToOperand(const LAllocation& a); 37 Operand ToOperand(const LAllocation* a); 38 39 #ifdef JS_PUNBOX64 40 Operand ToOperandOrRegister64(const LInt64Allocation& input); 41 #else 42 Register64 ToOperandOrRegister64(const LInt64Allocation& input); 43 #endif 44 45 MoveOperand toMoveOperand(LAllocation a) const; 46 47 void bailoutIf(Assembler::Condition condition, LSnapshot* snapshot); 48 void bailoutIf(Assembler::DoubleCondition condition, LSnapshot* snapshot); 49 void bailoutFrom(Label* label, LSnapshot* snapshot); 50 void bailout(LSnapshot* snapshot); 51 52 template <typename T1, typename T2> 53 void bailoutCmpPtr(Assembler::Condition c, T1 lhs, T2 rhs, 54 LSnapshot* snapshot) { 55 masm.cmpPtr(lhs, rhs); 56 bailoutIf(c, snapshot); 57 } 58 template <typename T1, typename T2> 59 void bailoutCmp32(Assembler::Condition c, T1 lhs, T2 rhs, 60 LSnapshot* snapshot) { 61 masm.cmp32(lhs, rhs); 62 bailoutIf(c, snapshot); 63 } 64 template <typename T1, typename T2> 65 void bailoutTest32(Assembler::Condition c, T1 lhs, T2 rhs, 66 LSnapshot* snapshot) { 67 masm.test32(lhs, rhs); 68 bailoutIf(c, snapshot); 69 } 70 void bailoutIfFalseBool(Register reg, LSnapshot* snapshot) { 71 masm.test32(reg, Imm32(0xFF)); 72 bailoutIf(Assembler::Zero, snapshot); 73 } 74 75 bool generateOutOfLineCode(); 76 77 // Emits a branch that directs control flow to the true block if |cond| is 78 // true, and the false block if |cond| is false. 79 void emitBranch(Assembler::Condition cond, MBasicBlock* ifTrue, 80 MBasicBlock* ifFalse); 81 void emitBranch(Assembler::DoubleCondition cond, MBasicBlock* ifTrue, 82 MBasicBlock* ifFalse, Assembler::NaNCond ifNaN); 83 84 void emitTableSwitchDispatch(MTableSwitch* mir, Register index, 85 Register base); 86 87 // Emit out-of-line code to zero |output| if |rhs| is zero. Used for truncated 88 // division and modulus instructions. 89 OutOfLineCode* emitOutOfLineZeroForDivideByZero(Register rhs, 90 Register output); 91 92 void generateInvalidateEpilogue(); 93 94 template <typename T> 95 Operand toMemoryAccessOperand(T* lir, int32_t disp); 96 97 public: 98 void emitUndoALUOperationOOL(LInstruction* ins); 99 100 // Out of line visitors. 101 void visitModOverflowCheck(ModOverflowCheck* ool); 102 void visitOutOfLineTableSwitch(OutOfLineTableSwitch* ool); 103 void visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateCheck* ool); 104 }; 105 106 } // namespace jit 107 } // namespace js 108 109 #endif /* jit_x86_shared_CodeGenerator_x86_shared_h */