| 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/loong64/Lowering-loong64.h" |
| 8 |
|
| 9 |
#include "mozilla/MathAlgorithms.h" |
| 10 |
|
| 11 |
#include "jit/loong64/Assembler-loong64.h" |
| 12 |
#include "jit/Lowering.h" |
| 13 |
#include "jit/MIR-wasm.h" |
| 14 |
#include "jit/MIR.h" |
| 15 |
#include "jit/shared/Lowering-shared-inl.h" |
| 16 |
|
| 17 |
using namespace js; |
| 18 |
using namespace js::jit; |
| 19 |
|
| 20 |
using mozilla::FloorLog2; |
| 21 |
|
| 22 |
LTableSwitch* LIRGeneratorLOONG64::newLTableSwitch( |
| 23 |
const LAllocation& in, const LDefinition& inputCopy) { |
| 24 |
return new (alloc()) LTableSwitch(in, inputCopy, temp()); |
| 25 |
} |
| 26 |
|
| 27 |
LTableSwitchV* LIRGeneratorLOONG64::newLTableSwitchV(const LBoxAllocation& in) { |
| 28 |
return new (alloc()) LTableSwitchV(in, temp(), tempDouble(), temp()); |
| 29 |
} |
| 30 |
|
| 31 |
void LIRGeneratorLOONG64::lowerForShift(LInstructionHelper<1, 2, 0>* ins, |
| 32 |
MDefinition* mir, MDefinition* lhs, |
| 33 |
MDefinition* rhs) { |
| 34 |
ins->setOperand(0, useRegister(lhs)); |
| 35 |
ins->setOperand(1, useRegisterOrConstant(rhs)); |
| 36 |
define(ins, mir); |
| 37 |
} |
| 38 |
|
| 39 |
template <class LInstr> |
| 40 |
void LIRGeneratorLOONG64::lowerForShiftInt64(LInstr* ins, MDefinition* mir, |
| 41 |
MDefinition* lhs, |
| 42 |
MDefinition* rhs) { |
| 43 |
if constexpr (std::is_same_v<LInstr, LShiftI64>) { |
| 44 |
ins->setLhs(useInt64RegisterAtStart(lhs)); |
| 45 |
ins->setRhs(useRegisterOrConstant(rhs)); |
| 46 |
defineInt64ReuseInput(ins, mir, LShiftI64::LhsIndex); |
| 47 |
} else { |
| 48 |
ins->setInput(useInt64RegisterAtStart(lhs)); |
| 49 |
ins->setCount(useRegisterOrConstant(rhs)); |
| 50 |
defineInt64ReuseInput(ins, mir, LRotateI64::InputIndex); |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
template void LIRGeneratorLOONG64::lowerForShiftInt64(LShiftI64* ins, |
| 55 |
MDefinition* mir, |
| 56 |
MDefinition* lhs, |
| 57 |
MDefinition* rhs); |
| 58 |
template void LIRGeneratorLOONG64::lowerForShiftInt64(LRotateI64* ins, |
| 59 |
MDefinition* mir, |
| 60 |
MDefinition* lhs, |
| 61 |
MDefinition* rhs); |
| 62 |
|
| 63 |
// x = !y |
| 64 |
void LIRGeneratorLOONG64::lowerForALU(LInstructionHelper<1, 1, 0>* ins, |
| 65 |
MDefinition* mir, MDefinition* input) { |
| 66 |
ins->setOperand(0, useRegister(input)); |
| 67 |
define( |
| 68 |
ins, mir, |
| 69 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 70 |
} |
| 71 |
|
| 72 |
// z = x + y |
| 73 |
void LIRGeneratorLOONG64::lowerForALU(LInstructionHelper<1, 2, 0>* ins, |
| 74 |
MDefinition* mir, MDefinition* lhs, |
| 75 |
MDefinition* rhs) { |
| 76 |
ins->setOperand(0, useRegister(lhs)); |
| 77 |
ins->setOperand(1, useRegisterOrConstant(rhs)); |
| 78 |
define( |
| 79 |
ins, mir, |
| 80 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 81 |
} |
| 82 |
|
| 83 |
void LIRGeneratorLOONG64::lowerForALUInt64( |
| 84 |
LInstructionHelper<INT64_PIECES, INT64_PIECES, 0>* ins, MDefinition* mir, |
| 85 |
MDefinition* input) { |
| 86 |
ins->setInt64Operand(0, useInt64RegisterAtStart(input)); |
| 87 |
defineInt64ReuseInput(ins, mir, 0); |
| 88 |
} |
| 89 |
|
| 90 |
void LIRGeneratorLOONG64::lowerForALUInt64( |
| 91 |
LInstructionHelper<INT64_PIECES, 2 * INT64_PIECES, 0>* ins, |
| 92 |
MDefinition* mir, MDefinition* lhs, MDefinition* rhs) { |
| 93 |
ins->setInt64Operand(0, useInt64RegisterAtStart(lhs)); |
| 94 |
ins->setInt64Operand(INT64_PIECES, willHaveDifferentLIRNodes(lhs, rhs) |
| 95 |
? useInt64OrConstant(rhs) |
| 96 |
: useInt64OrConstantAtStart(rhs)); |
| 97 |
defineInt64ReuseInput(ins, mir, 0); |
| 98 |
} |
| 99 |
|
| 100 |
void LIRGeneratorLOONG64::lowerForMulInt64(LMulI64* ins, MMul* mir, |
| 101 |
MDefinition* lhs, MDefinition* rhs) { |
| 102 |
bool needsTemp = false; |
| 103 |
bool cannotAliasRhs = false; |
| 104 |
bool reuseInput = true; |
| 105 |
|
| 106 |
ins->setLhs(useInt64RegisterAtStart(lhs)); |
| 107 |
ins->setRhs((willHaveDifferentLIRNodes(lhs, rhs) || cannotAliasRhs) |
| 108 |
? useInt64OrConstant(rhs) |
| 109 |
: useInt64OrConstantAtStart(rhs)); |
| 110 |
|
| 111 |
if (needsTemp) { |
| 112 |
ins->setTemp0(temp()); |
| 113 |
} |
| 114 |
if (reuseInput) { |
| 115 |
defineInt64ReuseInput(ins, mir, 0); |
| 116 |
} else { |
| 117 |
defineInt64(ins, mir); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
void LIRGeneratorLOONG64::lowerForFPU(LInstructionHelper<1, 1, 0>* ins, |
| 122 |
MDefinition* mir, MDefinition* input) { |
| 123 |
ins->setOperand(0, useRegister(input)); |
| 124 |
define( |
| 125 |
ins, mir, |
| 126 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 127 |
} |
| 128 |
|
| 129 |
template <size_t Temps> |
| 130 |
void LIRGeneratorLOONG64::lowerForFPU(LInstructionHelper<1, 2, Temps>* ins, |
| 131 |
MDefinition* mir, MDefinition* lhs, |
| 132 |
MDefinition* rhs) { |
| 133 |
ins->setOperand(0, useRegister(lhs)); |
| 134 |
ins->setOperand(1, useRegister(rhs)); |
| 135 |
define( |
| 136 |
ins, mir, |
| 137 |
LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER)); |
| 138 |
} |
| 139 |
|
| 140 |
template void LIRGeneratorLOONG64::lowerForFPU(LInstructionHelper<1, 2, 0>* ins, |
| 141 |
MDefinition* mir, |
| 142 |
MDefinition* lhs, |
| 143 |
MDefinition* rhs); |
| 144 |
template void LIRGeneratorLOONG64::lowerForFPU(LInstructionHelper<1, 2, 1>* ins, |
| 145 |
MDefinition* mir, |
| 146 |
MDefinition* lhs, |
| 147 |
MDefinition* rhs); |
| 148 |
|
| 149 |
LBoxAllocation LIRGeneratorLOONG64::useBoxFixed(MDefinition* mir, Register reg1, |
| 150 |
Register reg2, |
| 151 |
bool useAtStart) { |
| 152 |
MOZ_ASSERT(mir->type() == MIRType::Value); |
| 153 |
|
| 154 |
ensureDefined(mir); |
| 155 |
return LBoxAllocation(LUse(reg1, mir->virtualRegister(), useAtStart)); |
| 156 |
} |
| 157 |
|
| 158 |
LAllocation LIRGeneratorLOONG64::useByteOpRegister(MDefinition* mir) { |
| 159 |
return useRegister(mir); |
| 160 |
} |
| 161 |
|
| 162 |
LAllocation LIRGeneratorLOONG64::useByteOpRegisterAtStart(MDefinition* mir) { |
| 163 |
return useRegisterAtStart(mir); |
| 164 |
} |
| 165 |
|
| 166 |
LAllocation LIRGeneratorLOONG64::useByteOpRegisterOrNonDoubleConstant( |
| 167 |
MDefinition* mir) { |
| 168 |
return useRegisterOrNonDoubleConstant(mir); |
| 169 |
} |
| 170 |
|
| 171 |
LDefinition LIRGeneratorLOONG64::tempByteOpRegister() { return temp(); } |
| 172 |
|
| 173 |
LDefinition LIRGeneratorLOONG64::tempToUnbox() { return temp(); } |
| 174 |
|
| 175 |
void LIRGeneratorLOONG64::lowerUntypedPhiInput(MPhi* phi, |
| 176 |
uint32_t inputPosition, |
| 177 |
LBlock* block, size_t lirIndex) { |
| 178 |
lowerTypedPhiInput(phi, inputPosition, block, lirIndex); |
| 179 |
} |
| 180 |
void LIRGeneratorLOONG64::lowerInt64PhiInput(MPhi* phi, uint32_t inputPosition, |
| 181 |
LBlock* block, size_t lirIndex) { |
| 182 |
lowerTypedPhiInput(phi, inputPosition, block, lirIndex); |
| 183 |
} |
| 184 |
void LIRGeneratorLOONG64::defineInt64Phi(MPhi* phi, size_t lirIndex) { |
| 185 |
defineTypedPhi(phi, lirIndex); |
| 186 |
} |
| 187 |
|
| 188 |
void LIRGeneratorLOONG64::lowerNegI(MInstruction* ins, MDefinition* input) { |
| 189 |
define(new (alloc()) LNegI(useRegisterAtStart(input)), ins); |
| 190 |
} |
| 191 |
void LIRGeneratorLOONG64::lowerNegI64(MInstruction* ins, MDefinition* input) { |
| 192 |
defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)), |
| 193 |
ins, 0); |
| 194 |
} |
| 195 |
|
| 196 |
void LIRGeneratorLOONG64::lowerMulI(MMul* mul, MDefinition* lhs, |
| 197 |
MDefinition* rhs) { |
| 198 |
LMulI* lir = new (alloc()) LMulI; |
| 199 |
if (mul->fallible()) { |
| 200 |
assignSnapshot(lir, mul->bailoutKind()); |
| 201 |
} |
| 202 |
|
| 203 |
lowerForALU(lir, mul, lhs, rhs); |
| 204 |
} |
| 205 |
|
| 206 |
void LIRGeneratorLOONG64::lowerDivI(MDiv* div) { |
| 207 |
if (div->isUnsigned()) { |
| 208 |
lowerUDiv(div); |
| 209 |
return; |
| 210 |
} |
| 211 |
|
| 212 |
// Division instructions are slow. Division by constant denominators can be |
| 213 |
// rewritten to use other instructions. |
| 214 |
if (div->rhs()->isConstant()) { |
| 215 |
int32_t rhs = div->rhs()->toConstant()->toInt32(); |
| 216 |
// Check for division by a positive power of two, which is an easy and |
| 217 |
// important case to optimize. Note that other optimizations are also |
| 218 |
// possible; division by negative powers of two can be optimized in a |
| 219 |
// similar manner as positive powers of two, and division by other |
| 220 |
// constants can be optimized by a reciprocal multiplication technique. |
| 221 |
int32_t shift = FloorLog2(rhs); |
| 222 |
if (rhs > 0 && 1 << shift == rhs) { |
| 223 |
LDivPowTwoI* lir = |
| 224 |
new (alloc()) LDivPowTwoI(useRegister(div->lhs()), temp(), shift); |
| 225 |
if (div->fallible()) { |
| 226 |
assignSnapshot(lir, div->bailoutKind()); |
| 227 |
} |
| 228 |
define(lir, div); |
| 229 |
return; |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
LDivI* lir = new (alloc()) |
| 234 |
LDivI(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 235 |
if (div->fallible()) { |
| 236 |
assignSnapshot(lir, div->bailoutKind()); |
| 237 |
} |
| 238 |
define(lir, div); |
| 239 |
} |
| 240 |
|
| 241 |
void LIRGeneratorLOONG64::lowerDivI64(MDiv* div) { |
| 242 |
if (div->isUnsigned()) { |
| 243 |
lowerUDivI64(div); |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 247 |
LDivOrModI64* lir = new (alloc()) |
| 248 |
LDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 249 |
defineInt64(lir, div); |
| 250 |
} |
| 251 |
|
| 252 |
void LIRGeneratorLOONG64::lowerModI(MMod* mod) { |
| 253 |
if (mod->isUnsigned()) { |
| 254 |
lowerUMod(mod); |
| 255 |
return; |
| 256 |
} |
| 257 |
|
| 258 |
if (mod->rhs()->isConstant()) { |
| 259 |
int32_t rhs = mod->rhs()->toConstant()->toInt32(); |
| 260 |
int32_t shift = FloorLog2(rhs); |
| 261 |
if (rhs > 0 && 1 << shift == rhs) { |
| 262 |
LModPowTwoI* lir = |
| 263 |
new (alloc()) LModPowTwoI(useRegister(mod->lhs()), shift); |
| 264 |
if (mod->fallible()) { |
| 265 |
assignSnapshot(lir, mod->bailoutKind()); |
| 266 |
} |
| 267 |
define(lir, mod); |
| 268 |
return; |
| 269 |
} else if (shift < 31 && (1 << (shift + 1)) - 1 == rhs) { |
| 270 |
LModMaskI* lir = new (alloc()) |
| 271 |
LModMaskI(useRegister(mod->lhs()), temp(), temp(), shift + 1); |
| 272 |
if (mod->fallible()) { |
| 273 |
assignSnapshot(lir, mod->bailoutKind()); |
| 274 |
} |
| 275 |
define(lir, mod); |
| 276 |
return; |
| 277 |
} |
| 278 |
} |
| 279 |
LModI* lir = new (alloc()) |
| 280 |
LModI(useRegister(mod->lhs()), useRegister(mod->rhs()), temp()); |
| 281 |
|
| 282 |
if (mod->fallible()) { |
| 283 |
assignSnapshot(lir, mod->bailoutKind()); |
| 284 |
} |
| 285 |
define(lir, mod); |
| 286 |
} |
| 287 |
|
| 288 |
void LIRGeneratorLOONG64::lowerModI64(MMod* mod) { |
| 289 |
if (mod->isUnsigned()) { |
| 290 |
lowerUModI64(mod); |
| 291 |
return; |
| 292 |
} |
| 293 |
|
| 294 |
LDivOrModI64* lir = new (alloc()) |
| 295 |
LDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()), temp()); |
| 296 |
defineInt64(lir, mod); |
| 297 |
} |
| 298 |
|
| 299 |
void LIRGeneratorLOONG64::lowerUDiv(MDiv* div) { |
| 300 |
MDefinition* lhs = div->getOperand(0); |
| 301 |
MDefinition* rhs = div->getOperand(1); |
| 302 |
|
| 303 |
LUDivOrMod* lir = new (alloc()) LUDivOrMod; |
| 304 |
lir->setOperand(0, useRegister(lhs)); |
| 305 |
lir->setOperand(1, useRegister(rhs)); |
| 306 |
if (div->fallible()) { |
| 307 |
assignSnapshot(lir, div->bailoutKind()); |
| 308 |
} |
| 309 |
|
| 310 |
define(lir, div); |
| 311 |
} |
| 312 |
|
| 313 |
void LIRGeneratorLOONG64::lowerUDivI64(MDiv* div) { |
| 314 |
LUDivOrModI64* lir = new (alloc()) |
| 315 |
LUDivOrModI64(useRegister(div->lhs()), useRegister(div->rhs()), temp()); |
| 316 |
defineInt64(lir, div); |
| 317 |
} |
| 318 |
|
| 319 |
void LIRGeneratorLOONG64::lowerUMod(MMod* mod) { |
| 320 |
MDefinition* lhs = mod->getOperand(0); |
| 321 |
MDefinition* rhs = mod->getOperand(1); |
| 322 |
|
| 323 |
LUDivOrMod* lir = new (alloc()) LUDivOrMod; |
| 324 |
lir->setOperand(0, useRegister(lhs)); |
| 325 |
lir->setOperand(1, useRegister(rhs)); |
| 326 |
if (mod->fallible()) { |
| 327 |
assignSnapshot(lir, mod->bailoutKind()); |
| 328 |
} |
| 329 |
|
| 330 |
define(lir, mod); |
| 331 |
} |
| 332 |
|
| 333 |
void LIRGeneratorLOONG64::lowerUModI64(MMod* mod) { |
| 334 |
LUDivOrModI64* lir = new (alloc()) |
| 335 |
LUDivOrModI64(useRegister(mod->lhs()), useRegister(mod->rhs()), temp()); |
| 336 |
defineInt64(lir, mod); |
| 337 |
} |
| 338 |
|
| 339 |
void LIRGeneratorLOONG64::lowerUrshD(MUrsh* mir) { |
| 340 |
MDefinition* lhs = mir->lhs(); |
| 341 |
MDefinition* rhs = mir->rhs(); |
| 342 |
|
| 343 |
MOZ_ASSERT(lhs->type() == MIRType::Int32); |
| 344 |
MOZ_ASSERT(rhs->type() == MIRType::Int32); |
| 345 |
|
| 346 |
LUrshD* lir = new (alloc()) |
| 347 |
LUrshD(useRegister(lhs), useRegisterOrConstant(rhs), temp()); |
| 348 |
define(lir, mir); |
| 349 |
} |
| 350 |
|
| 351 |
void LIRGeneratorLOONG64::lowerPowOfTwoI(MPow* mir) { |
| 352 |
int32_t base = mir->input()->toConstant()->toInt32(); |
| 353 |
MDefinition* power = mir->power(); |
| 354 |
|
| 355 |
auto* lir = new (alloc()) LPowOfTwoI(useRegister(power), base); |
| 356 |
assignSnapshot(lir, mir->bailoutKind()); |
| 357 |
define(lir, mir); |
| 358 |
} |
| 359 |
|
| 360 |
void LIRGeneratorLOONG64::lowerBigIntPtrLsh(MBigIntPtrLsh* ins) { |
| 361 |
auto* lir = new (alloc()) LBigIntPtrLsh( |
| 362 |
useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp()); |
| 363 |
assignSnapshot(lir, ins->bailoutKind()); |
| 364 |
define(lir, ins); |
| 365 |
} |
| 366 |
|
| 367 |
void LIRGeneratorLOONG64::lowerBigIntPtrRsh(MBigIntPtrRsh* ins) { |
| 368 |
auto* lir = new (alloc()) LBigIntPtrRsh( |
| 369 |
useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp()); |
| 370 |
assignSnapshot(lir, ins->bailoutKind()); |
| 371 |
define(lir, ins); |
| 372 |
} |
| 373 |
|
| 374 |
void LIRGeneratorLOONG64::lowerBigIntPtrDiv(MBigIntPtrDiv* ins) { |
| 375 |
auto* lir = new (alloc()) |
| 376 |
LBigIntPtrDiv(useRegister(ins->lhs()), useRegister(ins->rhs()), |
| 377 |
LDefinition::BogusTemp(), LDefinition::BogusTemp()); |
| 378 |
assignSnapshot(lir, ins->bailoutKind()); |
| 379 |
define(lir, ins); |
| 380 |
} |
| 381 |
|
| 382 |
void LIRGeneratorLOONG64::lowerBigIntPtrMod(MBigIntPtrMod* ins) { |
| 383 |
auto* lir = new (alloc()) |
| 384 |
LBigIntPtrMod(useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), |
| 385 |
LDefinition::BogusTemp()); |
| 386 |
if (ins->canBeDivideByZero()) { |
| 387 |
assignSnapshot(lir, ins->bailoutKind()); |
| 388 |
} |
| 389 |
define(lir, ins); |
| 390 |
} |
| 391 |
|
| 392 |
void LIRGeneratorLOONG64::lowerTruncateDToInt32(MTruncateToInt32* ins) { |
| 393 |
MDefinition* opd = ins->input(); |
| 394 |
MOZ_ASSERT(opd->type() == MIRType::Double); |
| 395 |
|
| 396 |
define(new (alloc()) LTruncateDToInt32(useRegister(opd), tempDouble()), ins); |
| 397 |
} |
| 398 |
|
| 399 |
void LIRGeneratorLOONG64::lowerTruncateFToInt32(MTruncateToInt32* ins) { |
| 400 |
MDefinition* opd = ins->input(); |
| 401 |
MOZ_ASSERT(opd->type() == MIRType::Float32); |
| 402 |
|
| 403 |
define(new (alloc()) LTruncateFToInt32(useRegister(opd), tempFloat32()), ins); |
| 404 |
} |
| 405 |
|
| 406 |
void LIRGeneratorLOONG64::lowerBuiltinInt64ToFloatingPoint( |
| 407 |
MBuiltinInt64ToFloatingPoint* ins) { |
| 408 |
MOZ_CRASH("We don't use it for this architecture"); |
| 409 |
} |
| 410 |
|
| 411 |
void LIRGeneratorLOONG64::lowerWasmSelectI(MWasmSelect* select) { |
| 412 |
auto* lir = new (alloc()) |
| 413 |
LWasmSelect(useRegisterAtStart(select->trueExpr()), |
| 414 |
useAny(select->falseExpr()), useRegister(select->condExpr())); |
| 415 |
defineReuseInput(lir, select, LWasmSelect::TrueExprIndex); |
| 416 |
} |
| 417 |
|
| 418 |
void LIRGeneratorLOONG64::lowerWasmSelectI64(MWasmSelect* select) { |
| 419 |
auto* lir = new (alloc()) LWasmSelectI64( |
| 420 |
useInt64RegisterAtStart(select->trueExpr()), |
| 421 |
useInt64(select->falseExpr()), useRegister(select->condExpr())); |
| 422 |
defineInt64ReuseInput(lir, select, LWasmSelectI64::TrueExprIndex); |
| 423 |
} |
| 424 |
|
| 425 |
// On loong64 we specialize the only cases where compare is {U,}Int32 and select |
| 426 |
// is {U,}Int32. |
| 427 |
bool LIRGeneratorShared::canSpecializeWasmCompareAndSelect( |
| 428 |
MCompare::CompareType compTy, MIRType insTy) { |
| 429 |
return insTy == MIRType::Int32 && (compTy == MCompare::Compare_Int32 || |
| 430 |
compTy == MCompare::Compare_UInt32); |
| 431 |
} |
| 432 |
|
| 433 |
void LIRGeneratorShared::lowerWasmCompareAndSelect(MWasmSelect* ins, |
| 434 |
MDefinition* lhs, |
| 435 |
MDefinition* rhs, |
| 436 |
MCompare::CompareType compTy, |
| 437 |
JSOp jsop) { |
| 438 |
MOZ_ASSERT(canSpecializeWasmCompareAndSelect(compTy, ins->type())); |
| 439 |
auto* lir = new (alloc()) LWasmCompareAndSelect( |
| 440 |
useRegister(lhs), useRegister(rhs), useRegisterAtStart(ins->trueExpr()), |
| 441 |
useRegister(ins->falseExpr()), compTy, jsop); |
| 442 |
defineReuseInput(lir, ins, LWasmCompareAndSelect::IfTrueExprIndex); |
| 443 |
} |
| 444 |
|
| 445 |
void LIRGeneratorLOONG64::lowerWasmBuiltinTruncateToInt32( |
| 446 |
MWasmBuiltinTruncateToInt32* ins) { |
| 447 |
MDefinition* opd = ins->input(); |
| 448 |
MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32); |
| 449 |
|
| 450 |
if (opd->type() == MIRType::Double) { |
| 451 |
define(new (alloc()) LWasmBuiltinTruncateDToInt32( |
| 452 |
useRegister(opd), useFixed(ins->instance(), InstanceReg), |
| 453 |
LDefinition::BogusTemp()), |
| 454 |
ins); |
| 455 |
return; |
| 456 |
} |
| 457 |
|
| 458 |
define(new (alloc()) LWasmBuiltinTruncateFToInt32( |
| 459 |
useRegister(opd), useFixed(ins->instance(), InstanceReg), |
| 460 |
LDefinition::BogusTemp()), |
| 461 |
ins); |
| 462 |
} |
| 463 |
|
| 464 |
void LIRGeneratorLOONG64::lowerWasmBuiltinTruncateToInt64( |
| 465 |
MWasmBuiltinTruncateToInt64* ins) { |
| 466 |
MOZ_CRASH("We don't use it for this architecture"); |
| 467 |
} |
| 468 |
|
| 469 |
void LIRGeneratorLOONG64::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) { |
| 470 |
MOZ_CRASH("We don't use runtime div for this architecture"); |
| 471 |
} |
| 472 |
|
| 473 |
void LIRGeneratorLOONG64::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) { |
| 474 |
MOZ_CRASH("We don't use runtime mod for this architecture"); |
| 475 |
} |
| 476 |
|
| 477 |
void LIRGeneratorLOONG64::lowerAtomicLoad64(MLoadUnboxedScalar* ins) { |
| 478 |
const LUse elements = useRegister(ins->elements()); |
| 479 |
const LAllocation index = |
| 480 |
useRegisterOrIndexConstant(ins->index(), ins->storageType()); |
| 481 |
|
| 482 |
auto* lir = new (alloc()) LAtomicLoad64(elements, index); |
| 483 |
defineInt64(lir, ins); |
| 484 |
} |
| 485 |
|
| 486 |
void LIRGeneratorLOONG64::lowerAtomicStore64(MStoreUnboxedScalar* ins) { |
| 487 |
LUse elements = useRegister(ins->elements()); |
| 488 |
LAllocation index = |
| 489 |
useRegisterOrIndexConstant(ins->index(), ins->writeType()); |
| 490 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 491 |
|
| 492 |
add(new (alloc()) LAtomicStore64(elements, index, value), ins); |
| 493 |
} |
| 494 |
|
| 495 |
void LIRGenerator::visitBox(MBox* box) { |
| 496 |
MDefinition* opd = box->getOperand(0); |
| 497 |
|
| 498 |
// If the operand is a constant, emit near its uses. |
| 499 |
if (opd->isConstant() && box->canEmitAtUses()) { |
| 500 |
emitAtUses(box); |
| 501 |
return; |
| 502 |
} |
| 503 |
|
| 504 |
if (opd->isConstant()) { |
| 505 |
define(new (alloc()) LValue(opd->toConstant()->toJSValue()), box, |
| 506 |
LDefinition(LDefinition::BOX)); |
| 507 |
} else { |
| 508 |
LBox* ins = new (alloc()) LBox(useRegister(opd), opd->type()); |
| 509 |
define(ins, box, LDefinition(LDefinition::BOX)); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
void LIRGenerator::visitUnbox(MUnbox* unbox) { |
| 514 |
MDefinition* box = unbox->getOperand(0); |
| 515 |
MOZ_ASSERT(box->type() == MIRType::Value); |
| 516 |
|
| 517 |
LInstructionHelper<1, BOX_PIECES, 0>* lir; |
| 518 |
if (IsFloatingPointType(unbox->type())) { |
| 519 |
MOZ_ASSERT(unbox->type() == MIRType::Double); |
| 520 |
lir = new (alloc()) LUnboxFloatingPoint(useBoxAtStart(box)); |
| 521 |
} else if (unbox->fallible()) { |
| 522 |
// If the unbox is fallible, load the Value in a register first to |
| 523 |
// avoid multiple loads. |
| 524 |
lir = new (alloc()) LUnbox(useRegisterAtStart(box)); |
| 525 |
} else { |
| 526 |
lir = new (alloc()) LUnbox(useAtStart(box)); |
| 527 |
} |
| 528 |
|
| 529 |
if (unbox->fallible()) { |
| 530 |
assignSnapshot(lir, unbox->bailoutKind()); |
| 531 |
} |
| 532 |
|
| 533 |
define(lir, unbox); |
| 534 |
} |
| 535 |
|
| 536 |
void LIRGenerator::visitAbs(MAbs* ins) { |
| 537 |
define(allocateAbs(ins, useRegisterAtStart(ins->input())), ins); |
| 538 |
} |
| 539 |
|
| 540 |
void LIRGenerator::visitCopySign(MCopySign* ins) { |
| 541 |
MDefinition* lhs = ins->lhs(); |
| 542 |
MDefinition* rhs = ins->rhs(); |
| 543 |
|
| 544 |
MOZ_ASSERT(IsFloatingPointType(lhs->type())); |
| 545 |
MOZ_ASSERT(lhs->type() == rhs->type()); |
| 546 |
MOZ_ASSERT(lhs->type() == ins->type()); |
| 547 |
|
| 548 |
LInstructionHelper<1, 2, 2>* lir; |
| 549 |
if (lhs->type() == MIRType::Double) { |
| 550 |
lir = new (alloc()) LCopySignD(); |
| 551 |
} else { |
| 552 |
lir = new (alloc()) LCopySignF(); |
| 553 |
} |
| 554 |
|
| 555 |
lir->setTemp(0, temp()); |
| 556 |
lir->setTemp(1, temp()); |
| 557 |
|
| 558 |
lir->setOperand(0, useRegisterAtStart(lhs)); |
| 559 |
lir->setOperand(1, willHaveDifferentLIRNodes(lhs, rhs) |
| 560 |
? useRegister(rhs) |
| 561 |
: useRegisterAtStart(rhs)); |
| 562 |
defineReuseInput(lir, ins, 0); |
| 563 |
} |
| 564 |
|
| 565 |
void LIRGenerator::visitPowHalf(MPowHalf* ins) { |
| 566 |
MDefinition* input = ins->input(); |
| 567 |
MOZ_ASSERT(input->type() == MIRType::Double); |
| 568 |
LPowHalfD* lir = new (alloc()) LPowHalfD(useRegisterAtStart(input)); |
| 569 |
defineReuseInput(lir, ins, 0); |
| 570 |
} |
| 571 |
|
| 572 |
void LIRGenerator::visitExtendInt32ToInt64(MExtendInt32ToInt64* ins) { |
| 573 |
defineInt64( |
| 574 |
new (alloc()) LExtendInt32ToInt64(useRegisterAtStart(ins->input())), ins); |
| 575 |
} |
| 576 |
|
| 577 |
void LIRGenerator::visitSignExtendInt64(MSignExtendInt64* ins) { |
| 578 |
defineInt64(new (alloc()) |
| 579 |
LSignExtendInt64(useInt64RegisterAtStart(ins->input())), |
| 580 |
ins); |
| 581 |
} |
| 582 |
|
| 583 |
void LIRGenerator::visitInt64ToFloatingPoint(MInt64ToFloatingPoint* ins) { |
| 584 |
MDefinition* opd = ins->input(); |
| 585 |
MOZ_ASSERT(opd->type() == MIRType::Int64); |
| 586 |
MOZ_ASSERT(IsFloatingPointType(ins->type())); |
| 587 |
|
| 588 |
define(new (alloc()) LInt64ToFloatingPoint(useInt64Register(opd)), ins); |
| 589 |
} |
| 590 |
|
| 591 |
void LIRGenerator::visitSubstr(MSubstr* ins) { |
| 592 |
LSubstr* lir = new (alloc()) |
| 593 |
LSubstr(useRegister(ins->string()), useRegister(ins->begin()), |
| 594 |
useRegister(ins->length()), temp(), temp(), temp()); |
| 595 |
define(lir, ins); |
| 596 |
assignSafepoint(lir, ins); |
| 597 |
} |
| 598 |
|
| 599 |
void LIRGenerator::visitCompareExchangeTypedArrayElement( |
| 600 |
MCompareExchangeTypedArrayElement* ins) { |
| 601 |
MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType())); |
| 602 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 603 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 604 |
|
| 605 |
const LUse elements = useRegister(ins->elements()); |
| 606 |
const LAllocation index = |
| 607 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 608 |
|
| 609 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 610 |
LInt64Allocation oldval = useInt64Register(ins->oldval()); |
| 611 |
LInt64Allocation newval = useInt64Register(ins->newval()); |
| 612 |
|
| 613 |
auto* lir = new (alloc()) |
| 614 |
LCompareExchangeTypedArrayElement64(elements, index, oldval, newval); |
| 615 |
defineInt64(lir, ins); |
| 616 |
return; |
| 617 |
} |
| 618 |
|
| 619 |
const LAllocation oldval = useRegister(ins->oldval()); |
| 620 |
const LAllocation newval = useRegister(ins->newval()); |
| 621 |
|
| 622 |
// If the target is a floating register then we need a temp at the |
| 623 |
// CodeGenerator level for creating the result. |
| 624 |
|
| 625 |
LDefinition outTemp = LDefinition::BogusTemp(); |
| 626 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 627 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 628 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 629 |
|
| 630 |
if (ins->arrayType() == Scalar::Uint32 && IsFloatingPointType(ins->type())) { |
| 631 |
outTemp = temp(); |
| 632 |
} |
| 633 |
|
| 634 |
if (Scalar::byteSize(ins->arrayType()) < 4) { |
| 635 |
valueTemp = temp(); |
| 636 |
offsetTemp = temp(); |
| 637 |
maskTemp = temp(); |
| 638 |
} |
| 639 |
|
| 640 |
LCompareExchangeTypedArrayElement* lir = new (alloc()) |
| 641 |
LCompareExchangeTypedArrayElement(elements, index, oldval, newval, |
| 642 |
outTemp, valueTemp, offsetTemp, |
| 643 |
maskTemp); |
| 644 |
|
| 645 |
define(lir, ins); |
| 646 |
} |
| 647 |
|
| 648 |
void LIRGenerator::visitAtomicExchangeTypedArrayElement( |
| 649 |
MAtomicExchangeTypedArrayElement* ins) { |
| 650 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 651 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 652 |
|
| 653 |
const LUse elements = useRegister(ins->elements()); |
| 654 |
const LAllocation index = |
| 655 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 656 |
|
| 657 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 658 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 659 |
|
| 660 |
auto* lir = new (alloc()) |
| 661 |
LAtomicExchangeTypedArrayElement64(elements, index, value); |
| 662 |
defineInt64(lir, ins); |
| 663 |
return; |
| 664 |
} |
| 665 |
|
| 666 |
// If the target is a floating register then we need a temp at the |
| 667 |
// CodeGenerator level for creating the result. |
| 668 |
|
| 669 |
MOZ_ASSERT(ins->arrayType() <= Scalar::Uint32); |
| 670 |
|
| 671 |
const LAllocation value = useRegister(ins->value()); |
| 672 |
|
| 673 |
LDefinition outTemp = LDefinition::BogusTemp(); |
| 674 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 675 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 676 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 677 |
|
| 678 |
if (ins->arrayType() == Scalar::Uint32) { |
| 679 |
MOZ_ASSERT(ins->type() == MIRType::Double); |
| 680 |
outTemp = temp(); |
| 681 |
} |
| 682 |
|
| 683 |
if (Scalar::byteSize(ins->arrayType()) < 4) { |
| 684 |
valueTemp = temp(); |
| 685 |
offsetTemp = temp(); |
| 686 |
maskTemp = temp(); |
| 687 |
} |
| 688 |
|
| 689 |
LAtomicExchangeTypedArrayElement* lir = |
| 690 |
new (alloc()) LAtomicExchangeTypedArrayElement( |
| 691 |
elements, index, value, outTemp, valueTemp, offsetTemp, maskTemp); |
| 692 |
|
| 693 |
define(lir, ins); |
| 694 |
} |
| 695 |
|
| 696 |
void LIRGenerator::visitAtomicTypedArrayElementBinop( |
| 697 |
MAtomicTypedArrayElementBinop* ins) { |
| 698 |
MOZ_ASSERT(ins->arrayType() != Scalar::Uint8Clamped); |
| 699 |
MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType())); |
| 700 |
MOZ_ASSERT(ins->elements()->type() == MIRType::Elements); |
| 701 |
MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr); |
| 702 |
|
| 703 |
const LUse elements = useRegister(ins->elements()); |
| 704 |
const LAllocation index = |
| 705 |
useRegisterOrIndexConstant(ins->index(), ins->arrayType()); |
| 706 |
|
| 707 |
if (Scalar::isBigIntType(ins->arrayType())) { |
| 708 |
LInt64Allocation value = useInt64Register(ins->value()); |
| 709 |
LInt64Definition temp = tempInt64(); |
| 710 |
|
| 711 |
// Case 1: the result of the operation is not used. |
| 712 |
|
| 713 |
if (ins->isForEffect()) { |
| 714 |
auto* lir = new (alloc()) LAtomicTypedArrayElementBinopForEffect64( |
| 715 |
elements, index, value, temp); |
| 716 |
add(lir, ins); |
| 717 |
return; |
| 718 |
} |
| 719 |
|
| 720 |
// Case 2: the result of the operation is used. |
| 721 |
|
| 722 |
auto* lir = new (alloc()) |
| 723 |
LAtomicTypedArrayElementBinop64(elements, index, value, temp); |
| 724 |
defineInt64(lir, ins); |
| 725 |
return; |
| 726 |
} |
| 727 |
|
| 728 |
LAllocation value = useRegister(ins->value()); |
| 729 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 730 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 731 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 732 |
|
| 733 |
if (Scalar::byteSize(ins->arrayType()) < 4) { |
| 734 |
valueTemp = temp(); |
| 735 |
offsetTemp = temp(); |
| 736 |
maskTemp = temp(); |
| 737 |
} |
| 738 |
|
| 739 |
if (ins->isForEffect()) { |
| 740 |
LAtomicTypedArrayElementBinopForEffect* lir = |
| 741 |
new (alloc()) LAtomicTypedArrayElementBinopForEffect( |
| 742 |
elements, index, value, valueTemp, offsetTemp, maskTemp); |
| 743 |
add(lir, ins); |
| 744 |
return; |
| 745 |
} |
| 746 |
|
| 747 |
// For a Uint32Array with a known double result we need a temp for |
| 748 |
// the intermediate output. |
| 749 |
|
| 750 |
LDefinition outTemp = LDefinition::BogusTemp(); |
| 751 |
|
| 752 |
if (ins->arrayType() == Scalar::Uint32 && IsFloatingPointType(ins->type())) { |
| 753 |
outTemp = temp(); |
| 754 |
} |
| 755 |
|
| 756 |
LAtomicTypedArrayElementBinop* lir = |
| 757 |
new (alloc()) LAtomicTypedArrayElementBinop( |
| 758 |
elements, index, value, outTemp, valueTemp, offsetTemp, maskTemp); |
| 759 |
define(lir, ins); |
| 760 |
} |
| 761 |
|
| 762 |
void LIRGenerator::visitReturnImpl(MDefinition* opd, bool isGenerator) { |
| 763 |
MOZ_ASSERT(opd->type() == MIRType::Value); |
| 764 |
|
| 765 |
LReturn* ins = new (alloc()) LReturn(isGenerator); |
| 766 |
ins->setOperand(0, useFixed(opd, JSReturnReg)); |
| 767 |
add(ins); |
| 768 |
} |
| 769 |
|
| 770 |
void LIRGenerator::visitAsmJSLoadHeap(MAsmJSLoadHeap* ins) { |
| 771 |
MDefinition* base = ins->base(); |
| 772 |
MOZ_ASSERT(base->type() == MIRType::Int32); |
| 773 |
|
| 774 |
MDefinition* boundsCheckLimit = ins->boundsCheckLimit(); |
| 775 |
MOZ_ASSERT_IF(ins->needsBoundsCheck(), |
| 776 |
boundsCheckLimit->type() == MIRType::Int32); |
| 777 |
|
| 778 |
LAllocation baseAlloc = useRegisterAtStart(base); |
| 779 |
|
| 780 |
LAllocation limitAlloc = ins->needsBoundsCheck() |
| 781 |
? useRegisterAtStart(boundsCheckLimit) |
| 782 |
: LAllocation(); |
| 783 |
|
| 784 |
// We have no memory-base value, meaning that HeapReg is to be used as the |
| 785 |
// memory base. This follows from the definition of |
| 786 |
// FunctionCompiler::maybeLoadMemoryBase() in WasmIonCompile.cpp. |
| 787 |
MOZ_ASSERT(!ins->hasMemoryBase()); |
| 788 |
auto* lir = |
| 789 |
new (alloc()) LAsmJSLoadHeap(baseAlloc, limitAlloc, LAllocation()); |
| 790 |
define(lir, ins); |
| 791 |
} |
| 792 |
|
| 793 |
void LIRGenerator::visitAsmJSStoreHeap(MAsmJSStoreHeap* ins) { |
| 794 |
MDefinition* base = ins->base(); |
| 795 |
MOZ_ASSERT(base->type() == MIRType::Int32); |
| 796 |
|
| 797 |
MDefinition* boundsCheckLimit = ins->boundsCheckLimit(); |
| 798 |
MOZ_ASSERT_IF(ins->needsBoundsCheck(), |
| 799 |
boundsCheckLimit->type() == MIRType::Int32); |
| 800 |
|
| 801 |
LAllocation baseAlloc = useRegisterAtStart(base); |
| 802 |
|
| 803 |
LAllocation limitAlloc = ins->needsBoundsCheck() |
| 804 |
? useRegisterAtStart(boundsCheckLimit) |
| 805 |
: LAllocation(); |
| 806 |
|
| 807 |
// See comment in LIRGenerator::visitAsmJSStoreHeap just above. |
| 808 |
MOZ_ASSERT(!ins->hasMemoryBase()); |
| 809 |
add(new (alloc()) LAsmJSStoreHeap(baseAlloc, useRegisterAtStart(ins->value()), |
| 810 |
limitAlloc, LAllocation()), |
| 811 |
ins); |
| 812 |
} |
| 813 |
|
| 814 |
void LIRGenerator::visitWasmLoad(MWasmLoad* ins) { |
| 815 |
MDefinition* base = ins->base(); |
| 816 |
// 'base' is a GPR but may be of either type. If it is 32-bit, it is |
| 817 |
// sign-extended on loongarch64 platform and we should explicitly promote it |
| 818 |
// to 64-bit by zero-extension when use it as an index register in memory |
| 819 |
// accesses. |
| 820 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 821 |
|
| 822 |
LAllocation memoryBase = |
| 823 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 824 |
: LGeneralReg(HeapReg); |
| 825 |
|
| 826 |
LAllocation ptr = useRegisterAtStart(base); |
| 827 |
|
| 828 |
LDefinition ptrCopy = LDefinition::BogusTemp(); |
| 829 |
if (ins->access().offset32()) { |
| 830 |
ptrCopy = tempCopy(base, 0); |
| 831 |
} |
| 832 |
|
| 833 |
if (ins->type() == MIRType::Int64) { |
| 834 |
auto* lir = new (alloc()) LWasmLoadI64(ptr, memoryBase, ptrCopy); |
| 835 |
defineInt64(lir, ins); |
| 836 |
return; |
| 837 |
} |
| 838 |
|
| 839 |
auto* lir = new (alloc()) LWasmLoad(ptr, memoryBase, ptrCopy); |
| 840 |
define(lir, ins); |
| 841 |
} |
| 842 |
|
| 843 |
void LIRGenerator::visitWasmStore(MWasmStore* ins) { |
| 844 |
MDefinition* base = ins->base(); |
| 845 |
// See comment in visitWasmLoad re the type of 'base'. |
| 846 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 847 |
|
| 848 |
MDefinition* value = ins->value(); |
| 849 |
LAllocation memoryBase = |
| 850 |
ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase())) |
| 851 |
: LGeneralReg(HeapReg); |
| 852 |
|
| 853 |
LAllocation baseAlloc = useRegisterAtStart(base); |
| 854 |
|
| 855 |
LDefinition ptrCopy = LDefinition::BogusTemp(); |
| 856 |
if (ins->access().offset32()) { |
| 857 |
ptrCopy = tempCopy(base, 0); |
| 858 |
} |
| 859 |
|
| 860 |
if (ins->access().type() == Scalar::Int64) { |
| 861 |
LInt64Allocation valueAlloc = useInt64RegisterAtStart(value); |
| 862 |
auto* lir = |
| 863 |
new (alloc()) LWasmStoreI64(baseAlloc, valueAlloc, memoryBase, ptrCopy); |
| 864 |
add(lir, ins); |
| 865 |
return; |
| 866 |
} |
| 867 |
|
| 868 |
LAllocation valueAlloc = useRegisterAtStart(value); |
| 869 |
auto* lir = |
| 870 |
new (alloc()) LWasmStore(baseAlloc, valueAlloc, memoryBase, ptrCopy); |
| 871 |
add(lir, ins); |
| 872 |
} |
| 873 |
|
| 874 |
void LIRGenerator::visitWasmNeg(MWasmNeg* ins) { |
| 875 |
if (ins->type() == MIRType::Int32) { |
| 876 |
define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins); |
| 877 |
} else if (ins->type() == MIRType::Float32) { |
| 878 |
define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins); |
| 879 |
} else { |
| 880 |
MOZ_ASSERT(ins->type() == MIRType::Double); |
| 881 |
define(new (alloc()) LNegD(useRegisterAtStart(ins->input())), ins); |
| 882 |
} |
| 883 |
} |
| 884 |
|
| 885 |
void LIRGenerator::visitWasmTruncateToInt64(MWasmTruncateToInt64* ins) { |
| 886 |
MDefinition* opd = ins->input(); |
| 887 |
MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32); |
| 888 |
|
| 889 |
defineInt64(new (alloc()) LWasmTruncateToInt64(useRegister(opd)), ins); |
| 890 |
} |
| 891 |
|
| 892 |
void LIRGenerator::visitWasmUnsignedToDouble(MWasmUnsignedToDouble* ins) { |
| 893 |
MOZ_ASSERT(ins->input()->type() == MIRType::Int32); |
| 894 |
LWasmUint32ToDouble* lir = |
| 895 |
new (alloc()) LWasmUint32ToDouble(useRegisterAtStart(ins->input())); |
| 896 |
define(lir, ins); |
| 897 |
} |
| 898 |
|
| 899 |
void LIRGenerator::visitWasmUnsignedToFloat32(MWasmUnsignedToFloat32* ins) { |
| 900 |
MOZ_ASSERT(ins->input()->type() == MIRType::Int32); |
| 901 |
LWasmUint32ToFloat32* lir = |
| 902 |
new (alloc()) LWasmUint32ToFloat32(useRegisterAtStart(ins->input())); |
| 903 |
define(lir, ins); |
| 904 |
} |
| 905 |
|
| 906 |
void LIRGenerator::visitWasmCompareExchangeHeap(MWasmCompareExchangeHeap* ins) { |
| 907 |
MDefinition* base = ins->base(); |
| 908 |
// See comment in visitWasmLoad re the type of 'base'. |
| 909 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 910 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 911 |
? LAllocation(useRegister(ins->memoryBase())) |
| 912 |
: LGeneralReg(HeapReg); |
| 913 |
|
| 914 |
if (ins->access().type() == Scalar::Int64) { |
| 915 |
auto* lir = new (alloc()) LWasmCompareExchangeI64( |
| 916 |
useRegister(base), useInt64Register(ins->oldValue()), |
| 917 |
useInt64Register(ins->newValue()), memoryBase); |
| 918 |
defineInt64(lir, ins); |
| 919 |
return; |
| 920 |
} |
| 921 |
|
| 922 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 923 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 924 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 925 |
|
| 926 |
if (ins->access().byteSize() < 4) { |
| 927 |
valueTemp = temp(); |
| 928 |
offsetTemp = temp(); |
| 929 |
maskTemp = temp(); |
| 930 |
} |
| 931 |
|
| 932 |
auto* lir = new (alloc()) |
| 933 |
LWasmCompareExchangeHeap(useRegister(base), useRegister(ins->oldValue()), |
| 934 |
useRegister(ins->newValue()), memoryBase, |
| 935 |
valueTemp, offsetTemp, maskTemp); |
| 936 |
|
| 937 |
define(lir, ins); |
| 938 |
} |
| 939 |
|
| 940 |
void LIRGenerator::visitWasmAtomicExchangeHeap(MWasmAtomicExchangeHeap* ins) { |
| 941 |
MDefinition* base = ins->base(); |
| 942 |
// See comment in visitWasmLoad re the type of 'base'. |
| 943 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 944 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 945 |
? LAllocation(useRegister(ins->memoryBase())) |
| 946 |
: LGeneralReg(HeapReg); |
| 947 |
|
| 948 |
if (ins->access().type() == Scalar::Int64) { |
| 949 |
auto* lir = new (alloc()) LWasmAtomicExchangeI64( |
| 950 |
useRegister(base), useInt64Register(ins->value()), memoryBase); |
| 951 |
defineInt64(lir, ins); |
| 952 |
return; |
| 953 |
} |
| 954 |
|
| 955 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 956 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 957 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 958 |
|
| 959 |
if (ins->access().byteSize() < 4) { |
| 960 |
valueTemp = temp(); |
| 961 |
offsetTemp = temp(); |
| 962 |
maskTemp = temp(); |
| 963 |
} |
| 964 |
|
| 965 |
auto* lir = new (alloc()) |
| 966 |
LWasmAtomicExchangeHeap(useRegister(base), useRegister(ins->value()), |
| 967 |
memoryBase, valueTemp, offsetTemp, maskTemp); |
| 968 |
define(lir, ins); |
| 969 |
} |
| 970 |
|
| 971 |
void LIRGenerator::visitWasmAtomicBinopHeap(MWasmAtomicBinopHeap* ins) { |
| 972 |
MDefinition* base = ins->base(); |
| 973 |
// See comment in visitWasmLoad re the type of 'base'. |
| 974 |
MOZ_ASSERT(base->type() == MIRType::Int32 || base->type() == MIRType::Int64); |
| 975 |
LAllocation memoryBase = ins->hasMemoryBase() |
| 976 |
? LAllocation(useRegister(ins->memoryBase())) |
| 977 |
: LGeneralReg(HeapReg); |
| 978 |
|
| 979 |
if (ins->access().type() == Scalar::Int64) { |
| 980 |
auto* lir = new (alloc()) |
| 981 |
LWasmAtomicBinopI64(useRegister(base), useInt64Register(ins->value()), |
| 982 |
memoryBase, tempInt64()); |
| 983 |
defineInt64(lir, ins); |
| 984 |
return; |
| 985 |
} |
| 986 |
|
| 987 |
LDefinition valueTemp = LDefinition::BogusTemp(); |
| 988 |
LDefinition offsetTemp = LDefinition::BogusTemp(); |
| 989 |
LDefinition maskTemp = LDefinition::BogusTemp(); |
| 990 |
|
| 991 |
if (ins->access().byteSize() < 4) { |
| 992 |
valueTemp = temp(); |
| 993 |
offsetTemp = temp(); |
| 994 |
maskTemp = temp(); |
| 995 |
} |
| 996 |
|
| 997 |
if (!ins->hasUses()) { |
| 998 |
LWasmAtomicBinopHeapForEffect* lir = new (alloc()) |
| 999 |
LWasmAtomicBinopHeapForEffect(useRegister(base), |
| 1000 |
useRegister(ins->value()), memoryBase, |
| 1001 |
valueTemp, offsetTemp, maskTemp); |
| 1002 |
add(lir, ins); |
| 1003 |
return; |
| 1004 |
} |
| 1005 |
|
| 1006 |
auto* lir = new (alloc()) |
| 1007 |
LWasmAtomicBinopHeap(useRegister(base), useRegister(ins->value()), |
| 1008 |
memoryBase, valueTemp, offsetTemp, maskTemp); |
| 1009 |
|
| 1010 |
define(lir, ins); |
| 1011 |
} |
| 1012 |
|
| 1013 |
void LIRGenerator::visitWasmTernarySimd128(MWasmTernarySimd128* ins) { |
| 1014 |
MOZ_CRASH("ternary SIMD NYI"); |
| 1015 |
} |
| 1016 |
|
| 1017 |
void LIRGenerator::visitWasmBinarySimd128(MWasmBinarySimd128* ins) { |
| 1018 |
MOZ_CRASH("binary SIMD NYI"); |
| 1019 |
} |
| 1020 |
|
| 1021 |
#ifdef ENABLE_WASM_SIMD |
| 1022 |
bool MWasmTernarySimd128::specializeBitselectConstantMaskAsShuffle( |
| 1023 |
int8_t shuffle[16]) { |
| 1024 |
return false; |
| 1025 |
} |
| 1026 |
#endif |
| 1027 |
|
| 1028 |
bool MWasmBinarySimd128::specializeForConstantRhs() { |
| 1029 |
// Probably many we want to do here |
| 1030 |
return false; |
| 1031 |
} |
| 1032 |
|
| 1033 |
void LIRGenerator::visitWasmBinarySimd128WithConstant( |
| 1034 |
MWasmBinarySimd128WithConstant* ins) { |
| 1035 |
MOZ_CRASH("binary SIMD with constant NYI"); |
| 1036 |
} |
| 1037 |
|
| 1038 |
void LIRGenerator::visitWasmShiftSimd128(MWasmShiftSimd128* ins) { |
| 1039 |
MOZ_CRASH("shift SIMD NYI"); |
| 1040 |
} |
| 1041 |
|
| 1042 |
void LIRGenerator::visitWasmShuffleSimd128(MWasmShuffleSimd128* ins) { |
| 1043 |
MOZ_CRASH("shuffle SIMD NYI"); |
| 1044 |
} |
| 1045 |
|
| 1046 |
void LIRGenerator::visitWasmReplaceLaneSimd128(MWasmReplaceLaneSimd128* ins) { |
| 1047 |
MOZ_CRASH("replace-lane SIMD NYI"); |
| 1048 |
} |
| 1049 |
|
| 1050 |
void LIRGenerator::visitWasmScalarToSimd128(MWasmScalarToSimd128* ins) { |
| 1051 |
MOZ_CRASH("scalar-to-SIMD NYI"); |
| 1052 |
} |
| 1053 |
|
| 1054 |
void LIRGenerator::visitWasmUnarySimd128(MWasmUnarySimd128* ins) { |
| 1055 |
MOZ_CRASH("unary SIMD NYI"); |
| 1056 |
} |
| 1057 |
|
| 1058 |
void LIRGenerator::visitWasmReduceSimd128(MWasmReduceSimd128* ins) { |
| 1059 |
MOZ_CRASH("reduce-SIMD NYI"); |
| 1060 |
} |
| 1061 |
|
| 1062 |
void LIRGenerator::visitWasmLoadLaneSimd128(MWasmLoadLaneSimd128* ins) { |
| 1063 |
MOZ_CRASH("load-lane SIMD NYI"); |
| 1064 |
} |
| 1065 |
|
| 1066 |
void LIRGenerator::visitWasmStoreLaneSimd128(MWasmStoreLaneSimd128* ins) { |
| 1067 |
MOZ_CRASH("store-lane SIMD NYI"); |
| 1068 |
} |