| 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 |
#include "jit/mips64/Lowering-mips64.h" |
| 8 |
|
| 9 |
#include "jit/Lowering.h" |
| 10 |
#include "jit/mips64/Assembler-mips64.h" |
| 11 |
#include "jit/MIR-wasm.h" |
| 12 |
#include "jit/MIR.h" |
| 13 |
|
| 14 |
#include "jit/shared/Lowering-shared-inl.h" |
| 15 |
|
| 16 |
using namespace js; |
| 17 |
using namespace js::jit; |
| 18 |
|
| 19 |
void LIRGeneratorMIPS64::defineInt64Phi(MPhi* phi, size_t lirIndex) { |
| 20 |
defineTypedPhi(phi, lirIndex); |
| 21 |
} |
| 22 |
|
| 23 |
void LIRGeneratorMIPS64::lowerInt64PhiInput(MPhi* phi, uint32_t inputPosition, |
| 24 |
LBlock* block, size_t lirIndex) { |
| 25 |
lowerTypedPhiInput(phi, inputPosition, block, lirIndex); |
| 26 |
} |
| 27 |
|
| 28 |
LBoxAllocation LIRGeneratorMIPS64::useBoxFixed(MDefinition* mir, Register reg1, |
| 29 |
Register reg2, bool useAtStart) { |
| 30 |
MOZ_ASSERT(mir->type() == MIRType::Value); |
| 31 |
|
| 32 |
ensureDefined(mir); |
| 33 |
return LBoxAllocation(LUse(reg1, mir->virtualRegister(), useAtStart)); |
| 34 |
} |
| 35 |
|
| 36 |
void LIRGeneratorMIPS64::lowerDivI64(MDiv* div) { |
| 37 |
if (div->isUnsigned()) { |
| 38 |
lowerUDivI64(div); |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
LDivOrModI64* lir = new (alloc()) |
| 43 |
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 44 |
defineInt64(lir, div); |
| 45 |
} |
| 46 |
|
| 47 |
void LIRGeneratorMIPS64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { |
| 48 |
MOZ_CRASH("We don't use runtime div for this architecture"); |
| 49 |
} |
| 50 |
|
| 51 |
void LIRGeneratorMIPS64::lowerModI64(MMod* mod) { |
| 52 |
if (mod->isUnsigned()) { |
| 53 |
lowerUModI64(mod); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
LDivOrModI64* lir = new (alloc()) |
| 58 |
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()), temp()); |
| 59 |
defineInt64(lir, mod); |
| 60 |
} |
| 61 |
|
| 62 |
void LIRGeneratorMIPS64::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { |
| 63 |
MOZ_CRASH("We don't use runtime mod for this architecture"); |
| 64 |
} |
| 65 |
|
| 66 |
void LIRGeneratorMIPS64::lowerUDivI64(MDiv* div) { |
| 67 |
LUDivOrModI64* lir = new (alloc()) |
| 68 |
LUDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 69 |
defineInt64(lir, div); |
| 70 |
} |
| 71 |
|
| 72 |
void LIRGeneratorMIPS64::lowerUModI64(MMod* mod) { |
| 73 |
LUDivOrModI64* lir = new (alloc()) |
| 74 |
LUDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()), temp()); |
| 75 |
defineInt64(lir, mod); |
| 76 |
} |
| 77 |
|
| 78 |
void LIRGeneratorMIPS64::lowerAtomicLoad64(MLoadUnboxedScalar* ins) { |
| 79 |
const LUse elements = useRegister(ins->elements()); |
| 80 |
const LAllocation index = |
| 81 |
useRegisterOrIndexConstant(ins->index(), ins->storageType()); |
| 82 |
|
| 83 |
auto* lir = new (alloc()) LAtomicLoad64(elements, index); |
| 84 |
defineInt64(lir, ins); |
| 85 |
} |
| 86 |
|
| 87 |
void LIRGeneratorMIPS64::lowerAtomicStore64(MStoreUnboxedScalar* ins) { |
| 88 |
LUse elements = useRegister(ins->elements()); |
| 89 |
LAllocation index = |
| 90 |
useRegisterOrIndexConstant(ins->index(), ins->writeType()); |
| 91 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 92 |
|
| 93 |
add(new (alloc()) LAtomicStore64(elements, index, value), ins); |
| 94 |
} |
| 95 |
|
| 96 |
void LIRGenerator::visitBox(MBox* box) { |
| 97 |
MDefinition* opd = box->getOperand(0); |
| 98 |
|
| 99 |
// If the operand is a constant, emit near its uses. |
| 100 |
if (opd->isConstant() && box->canEmitAtUses()) { |
| 101 |
emitAtUses(box); |
| 102 |
return; |
| 103 |
} |
| 104 |
|
| 105 |
if (opd->isConstant()) { |
| 106 |
define(new (alloc()) LValue(opd->toConstant()->toJSValue()), box, |
| 107 |
LDefinition(LDefinition::BOX)); |
| 108 |
} else { |
| 109 |
LBox* ins = new (alloc()) LBox(useRegister(opd), opd->type()); |
| 110 |
define(ins, box, LDefinition(LDefinition::BOX)); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
void LIRGenerator::visitUnbox(MUnbox* unbox) { |
| 115 |
MDefinition* box = unbox->getOperand(0); |
| 116 |
MOZ_ASSERT(box->type() == MIRType::Value); |
| 117 |
|
| 118 |
LInstructionHelper<1, BOX_PIECES, 0>* lir; |
| 119 |
if (IsFloatingPointType(unbox->type())) { |
| 120 |
MOZ_ASSERT(unbox->type() == MIRType::Double); |
| 121 |
lir = new (alloc()) LUnboxFloatingPoint(useBoxAtStart(box)); |
| 122 |
} else if (unbox->fallible()) { |
| 123 |
// If the unbox is fallible, load the Value in a register first to |
| 124 |
// avoid multiple loads. |
| 125 |
lir = new (alloc()) LUnbox(useRegisterAtStart(box)); |
| 126 |
} else { |
| 127 |
lir = new (alloc()) LUnbox(useAtStart(box)); |
| 128 |
} |
| 129 |
|
| 130 |
if (unbox->fallible()) { |
| 131 |
assignSnapshot(lir, unbox->bailoutKind()); |
| 132 |
} |
| 133 |
|
| 134 |
define(lir, unbox); |
| 135 |
} |
| 136 |
|
| 137 |
void LIRGenerator::visitReturnImpl(MDefinition* opd, bool isGenerator) { |
| 138 |
MOZ_ASSERT(opd->type() == MIRType::Value); |
| 139 |
|
| 140 |
LReturn* ins = new (alloc()) LReturn(isGenerator); |
| 141 |
ins->setOperand(0, useFixed(opd, JSReturnReg)); |
| 142 |
add(ins); |
| 143 |
} |
| 144 |
|
| 145 |
void LIRGeneratorMIPS64::lowerUntypedPhiInput(MPhi* phi, uint32_t inputPosition, |
| 146 |
LBlock* block, size_t lirIndex) { |
| 147 |
lowerTypedPhiInput(phi, inputPosition, block, lirIndex); |
| 148 |
} |
| 149 |
|
| 150 |
void LIRGeneratorMIPS64::lowerTruncateDToInt32(MTruncateToInt32* ins) { |
| 151 |
MDefinition* opd = ins->input(); |
| 152 |
MOZ_ASSERT(opd->type() == MIRType::Double); |
| 153 |
|
| 154 |
define(new (alloc()) LTruncateDToInt32(useRegister(opd), tempDouble()), ins); |
| 155 |
} |
| 156 |
|
| 157 |
void LIRGeneratorMIPS64::lowerTruncateFToInt32(MTruncateToInt32* ins) { |
| 158 |
MDefinition* opd = ins->input(); |
| 159 |
MOZ_ASSERT(opd->type() == MIRType::Float32); |
| 160 |
|
| 161 |
define(new (alloc()) LTruncateFToInt32(useRegister(opd), tempFloat32()), ins); |
| 162 |
} |
| 163 |
|
| 164 |
void LIRGenerator::visitWasmTruncateToInt64(MWasmTruncateToInt64* ins) { |
| 165 |
MDefinition* opd = ins->input(); |
| 166 |
MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32); |
| 167 |
|
| 168 |
defineInt64(new (alloc()) LWasmTruncateToInt64(useRegister(opd)), ins); |
| 169 |
} |
| 170 |
|
| 171 |
void LIRGeneratorMIPS64::lowerWasmBuiltinTruncateToInt64( |
| 172 |
MWasmBuiltinTruncateToInt64* ins) { |
| 173 |
MOZ_CRASH("We don't use it for this architecture"); |
| 174 |
} |
| 175 |
|
| 176 |
void LIRGenerator::visitInt64ToFloatingPoint(MInt64ToFloatingPoint* ins) { |
| 177 |
MDefinition* opd = ins->input(); |
| 178 |
MOZ_ASSERT(opd->type() == MIRType::Int64); |
| 179 |
MOZ_ASSERT(IsFloatingPointType(ins->type())); |
| 180 |
|
| 181 |
define(new (alloc()) LInt64ToFloatingPoint(useInt64Register(opd)), ins); |
| 182 |
} |
| 183 |
|
| 184 |
void LIRGeneratorMIPS64::lowerBuiltinInt64ToFloatingPoint( |
| 185 |
MBuiltinInt64ToFloatingPoint* ins) { |
| 186 |
MOZ_CRASH("We don't use it for this architecture"); |
| 187 |
} |