| 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_riscv64_CodeGenerator_riscv64_h |
| 8 |
#define jit_riscv64_CodeGenerator_riscv64_h |
| 9 |
|
| 10 |
#include "jit/riscv64/Assembler-riscv64.h" |
| 11 |
#include "jit/riscv64/MacroAssembler-riscv64.h" |
| 12 |
#include "jit/shared/CodeGenerator-shared.h" |
| 13 |
|
| 14 |
namespace js { |
| 15 |
namespace jit { |
| 16 |
|
| 17 |
class CodeGeneratorRiscv64; |
| 18 |
class OutOfLineTableSwitch; |
| 19 |
|
| 20 |
using OutOfLineWasmTruncateCheck = |
| 21 |
OutOfLineWasmTruncateCheckBase<CodeGeneratorRiscv64>; |
| 22 |
|
| 23 |
class CodeGeneratorRiscv64 : public CodeGeneratorShared { |
| 24 |
friend class MoveResolverLA; |
| 25 |
|
| 26 |
protected: |
| 27 |
CodeGeneratorRiscv64(MIRGenerator* gen, LIRGraph* graph, MacroAssembler* masm, |
| 28 |
const wasm::CodeMetadata* wasmCodeMeta); |
| 29 |
|
| 30 |
NonAssertingLabel deoptLabel_; |
| 31 |
|
| 32 |
Operand ToOperand(const LAllocation& a); |
| 33 |
Operand ToOperand(const LAllocation* a); |
| 34 |
Operand ToOperand(const LDefinition* def); |
| 35 |
|
| 36 |
#ifdef JS_PUNBOX64 |
| 37 |
Operand ToOperandOrRegister64(const LInt64Allocation& input); |
| 38 |
#else |
| 39 |
Register64 ToOperandOrRegister64(const LInt64Allocation& input); |
| 40 |
#endif |
| 41 |
|
| 42 |
MoveOperand toMoveOperand(LAllocation a) const; |
| 43 |
|
| 44 |
template <typename T1, typename T2> |
| 45 |
void bailoutCmp32(Assembler::Condition c, T1 lhs, T2 rhs, |
| 46 |
LSnapshot* snapshot) { |
| 47 |
Label bail; |
| 48 |
masm.branch32(c, lhs, rhs, &bail); |
| 49 |
bailoutFrom(&bail, snapshot); |
| 50 |
} |
| 51 |
template <typename T1, typename T2> |
| 52 |
void bailoutTest32(Assembler::Condition c, T1 lhs, T2 rhs, |
| 53 |
LSnapshot* snapshot) { |
| 54 |
Label bail; |
| 55 |
masm.branchTest32(c, lhs, rhs, &bail); |
| 56 |
bailoutFrom(&bail, snapshot); |
| 57 |
} |
| 58 |
template <typename T1, typename T2> |
| 59 |
void bailoutCmpPtr(Assembler::Condition c, T1 lhs, T2 rhs, |
| 60 |
LSnapshot* snapshot) { |
| 61 |
Label bail; |
| 62 |
masm.branchPtr(c, lhs, rhs, &bail); |
| 63 |
bailoutFrom(&bail, snapshot); |
| 64 |
} |
| 65 |
void bailoutTestPtr(Assembler::Condition c, Register lhs, Register rhs, |
| 66 |
LSnapshot* snapshot) { |
| 67 |
// TODO(riscv64) Didn't use branchTestPtr due to '-Wundefined-inline'. |
| 68 |
MOZ_ASSERT(c == Assembler::Zero || c == Assembler::NonZero || |
| 69 |
c == Assembler::Signed || c == Assembler::NotSigned); |
| 70 |
Label bail; |
| 71 |
if (lhs == rhs) { |
| 72 |
masm.ma_b(lhs, rhs, &bail, c); |
| 73 |
} else { |
| 74 |
ScratchRegisterScope scratch(masm); |
| 75 |
masm.and_(scratch, lhs, rhs); |
| 76 |
masm.ma_b(scratch, scratch, &bail, c); |
| 77 |
} |
| 78 |
bailoutFrom(&bail, snapshot); |
| 79 |
} |
| 80 |
void bailoutIfFalseBool(Register reg, LSnapshot* snapshot) { |
| 81 |
Label bail; |
| 82 |
ScratchRegisterScope scratch(masm); |
| 83 |
masm.ma_and(scratch, reg, Imm32(0xFF)); |
| 84 |
masm.ma_b(scratch, scratch, &bail, Assembler::Zero); |
| 85 |
bailoutFrom(&bail, snapshot); |
| 86 |
} |
| 87 |
|
| 88 |
void bailoutFrom(Label* label, LSnapshot* snapshot); |
| 89 |
void bailout(LSnapshot* snapshot); |
| 90 |
|
| 91 |
bool generateOutOfLineCode(); |
| 92 |
|
| 93 |
template <typename T> |
| 94 |
void branchToBlock(Register lhs, T rhs, MBasicBlock* mir, |
| 95 |
Assembler::Condition cond) { |
| 96 |
masm.ma_b(lhs, rhs, skipTrivialBlocks(mir)->lir()->label(), cond); |
| 97 |
} |
| 98 |
void branchToBlock(FloatFormat fmt, FloatRegister lhs, FloatRegister rhs, |
| 99 |
MBasicBlock* mir, Assembler::DoubleCondition cond); |
| 100 |
|
| 101 |
// Emits a branch that directs control flow to the true block if |cond| is |
| 102 |
// true, and the false block if |cond| is false. |
| 103 |
template <typename T> |
| 104 |
void emitBranch(Register lhs, T rhs, Assembler::Condition cond, |
| 105 |
MBasicBlock* mirTrue, MBasicBlock* mirFalse) { |
| 106 |
if (isNextBlock(mirFalse->lir())) { |
| 107 |
branchToBlock(lhs, rhs, mirTrue, cond); |
| 108 |
} else { |
| 109 |
branchToBlock(lhs, rhs, mirFalse, Assembler::InvertCondition(cond)); |
| 110 |
jumpToBlock(mirTrue); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
void emitTableSwitchDispatch(MTableSwitch* mir, Register index, |
| 115 |
Register base); |
| 116 |
|
| 117 |
template <typename T> |
| 118 |
void emitWasmLoad(T* ins); |
| 119 |
template <typename T> |
| 120 |
void emitWasmStore(T* ins); |
| 121 |
|
| 122 |
void generateInvalidateEpilogue(); |
| 123 |
|
| 124 |
// Generating a result. |
| 125 |
template <typename S, typename T> |
| 126 |
void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType, |
| 127 |
const S& value, const T& mem, |
| 128 |
Register flagTemp, Register outTemp, |
| 129 |
Register valueTemp, Register offsetTemp, |
| 130 |
Register maskTemp, AnyRegister output); |
| 131 |
|
| 132 |
// Generating no result. |
| 133 |
template <typename S, typename T> |
| 134 |
void atomicBinopToTypedIntArray(AtomicOp op, Scalar::Type arrayType, |
| 135 |
const S& value, const T& mem, |
| 136 |
Register flagTemp, Register valueTemp, |
| 137 |
Register offsetTemp, Register maskTemp); |
| 138 |
|
| 139 |
public: |
| 140 |
// Out of line visitors. |
| 141 |
void visitOutOfLineTableSwitch(OutOfLineTableSwitch* ool); |
| 142 |
void visitOutOfLineWasmTruncateCheck(OutOfLineWasmTruncateCheck* ool); |
| 143 |
|
| 144 |
protected: |
| 145 |
template <typename T> |
| 146 |
void emitWasmLoadI64(T* ins); |
| 147 |
template <typename T> |
| 148 |
void emitWasmStoreI64(T* ins); |
| 149 |
|
| 150 |
void emitBigIntPtrDiv(LBigIntPtrDiv* ins, Register dividend, Register divisor, |
| 151 |
Register output); |
| 152 |
void emitBigIntPtrMod(LBigIntPtrMod* ins, Register dividend, Register divisor, |
| 153 |
Register output); |
| 154 |
}; |
| 155 |
|
| 156 |
typedef CodeGeneratorRiscv64 CodeGeneratorSpecific; |
| 157 |
|
| 158 |
} // namespace jit |
| 159 |
} // namespace js |
| 160 |
|
| 161 |
#endif /* jit_riscv64_CodeGenerator_riscv64_h */ |