Debian Codegraph @

js/src/jit/arm/Lowering-arm.cpp

raw
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/arm/Lowering-arm.h"
8
9 #include "mozilla/MathAlgorithms.h"
10
11 #include "jit/arm/Assembler-arm.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 LBoxAllocation LIRGeneratorARM::useBoxFixed(MDefinition* mir, Register reg1,
23 Register reg2, bool useAtStart) {
24 MOZ_ASSERT(mir->type() == MIRType::Value);
25 MOZ_ASSERT(reg1 != reg2);
26
27 ensureDefined(mir);
28 return LBoxAllocation(LUse(reg1, mir->virtualRegister(), useAtStart),
29 LUse(reg2, VirtualRegisterOfPayload(mir), useAtStart));
30 }
31
32 LAllocation LIRGeneratorARM::useByteOpRegister(MDefinition* mir) {
33 return useRegister(mir);
34 }
35
36 LAllocation LIRGeneratorARM::useByteOpRegisterAtStart(MDefinition* mir) {
37 return useRegisterAtStart(mir);
38 }
39
40 LAllocation LIRGeneratorARM::useByteOpRegisterOrNonDoubleConstant(
41 MDefinition* mir) {
42 return useRegisterOrNonDoubleConstant(mir);
43 }
44
45 LDefinition LIRGeneratorARM::tempByteOpRegister() { return temp(); }
46
47 void LIRGenerator::visitBox(MBox* box) {
48 MDefinition* inner = box->getOperand(0);
49
50 // If the box wrapped a double, it needs a new register.
51 if (IsFloatingPointType(inner->type())) {
52 defineBox(new (alloc()) LBoxFloatingPoint(
53 useRegisterAtStart(inner), tempCopy(inner, 0), inner->type()),
54 box);
55 return;
56 }
57
58 if (box->canEmitAtUses()) {
59 emitAtUses(box);
60 return;
61 }
62
63 if (inner->isConstant()) {
64 defineBox(new (alloc()) LValue(inner->toConstant()->toJSValue()), box);
65 return;
66 }
67
68 LBox* lir = new (alloc()) LBox(use(inner), inner->type());
69
70 // Otherwise, we should not define a new register for the payload portion
71 // of the output, so bypass defineBox().
72 uint32_t vreg = getVirtualRegister();
73
74 // Note that because we're using BogusTemp(), we do not change the type of
75 // the definition. We also do not define the first output as "TYPE",
76 // because it has no corresponding payload at (vreg + 1). Also note that
77 // although we copy the input's original type for the payload half of the
78 // definition, this is only for clarity. BogusTemp() definitions are
79 // ignored.
80 lir->setDef(0, LDefinition(vreg, LDefinition::GENERAL));
81 lir->setDef(1, LDefinition::BogusTemp());
82 box->setVirtualRegister(vreg);
83 add(lir);
84 }
85
86 void LIRGenerator::visitUnbox(MUnbox* unbox) {
87 MDefinition* inner = unbox->getOperand(0);
88
89 // An unbox on arm reads in a type tag (either in memory or a register) and
90 // a payload. Unlike most instructions consuming a box, we ask for the type
91 // second, so that the result can re-use the first input.
92 MOZ_ASSERT(inner->type() == MIRType::Value);
93
94 ensureDefined(inner);
95
96 if (IsFloatingPointType(unbox->type())) {
97 MOZ_ASSERT(unbox->type() == MIRType::Double);
98 auto* lir = new (alloc()) LUnboxFloatingPoint(useBox(inner));
99 if (unbox->fallible()) {
100 assignSnapshot(lir, unbox->bailoutKind());
101 }
102 define(lir, unbox);
103 return;
104 }
105
106 // Swap the order we use the box pieces so we can re-use the payload register.
107 LUnbox* lir = new (alloc()) LUnbox;
108 lir->setOperand(0, usePayloadInRegisterAtStart(inner));
109 lir->setOperand(1, useType(inner, LUse::REGISTER));
110
111 if (unbox->fallible()) {
112 assignSnapshot(lir, unbox->bailoutKind());
113 }
114
115 // Types and payloads form two separate intervals. If the type becomes dead
116 // before the payload, it could be used as a Value without the type being
117 // recoverable. Unbox's purpose is to eagerly kill the definition of a type
118 // tag, so keeping both alive (for the purpose of gcmaps) is unappealing.
119 // Instead, we create a new virtual register.
120 defineReuseInput(lir, unbox, 0);
121 }
122
123 void LIRGenerator::visitReturnImpl(MDefinition* opd, bool isGenerator) {
124 MOZ_ASSERT(opd->type() == MIRType::Value);
125
126 LReturn* ins = new (alloc()) LReturn(isGenerator);
127 ins->setOperand(0, LUse(JSReturnReg_Type));
128 ins->setOperand(1, LUse(JSReturnReg_Data));
129 fillBoxUses(ins, 0, opd);
130 add(ins);
131 }
132
133 void LIRGeneratorARM::defineInt64Phi(MPhi* phi, size_t lirIndex) {
134 LPhi* low = current->getPhi(lirIndex + INT64LOW_INDEX);
135 LPhi* high = current->getPhi(lirIndex + INT64HIGH_INDEX);
136
137 uint32_t lowVreg = getVirtualRegister();
138
139 phi->setVirtualRegister(lowVreg);
140
141 uint32_t highVreg = getVirtualRegister();
142 MOZ_ASSERT(lowVreg + INT64HIGH_INDEX == highVreg + INT64LOW_INDEX);
143
144 low->setDef(0, LDefinition(lowVreg, LDefinition::INT32));
145 high->setDef(0, LDefinition(highVreg, LDefinition::INT32));
146 annotate(high);
147 annotate(low);
148 }
149
150 void LIRGeneratorARM::lowerInt64PhiInput(MPhi* phi, uint32_t inputPosition,
151 LBlock* block, size_t lirIndex) {
152 MDefinition* operand = phi->getOperand(inputPosition);
153 LPhi* low = block->getPhi(lirIndex + INT64LOW_INDEX);
154 LPhi* high = block->getPhi(lirIndex + INT64HIGH_INDEX);
155 low->setOperand(inputPosition,
156 LUse(operand->virtualRegister() + INT64LOW_INDEX, LUse::ANY));
157 high->setOperand(
158 inputPosition,
159 LUse(operand->virtualRegister() + INT64HIGH_INDEX, LUse::ANY));
160 }
161
162 // x = !y
163 void LIRGeneratorARM::lowerForALU(LInstructionHelper<1, 1, 0>* ins,
164 MDefinition* mir, MDefinition* input) {
165 ins->setOperand(
166 0, ins->snapshot() ? useRegister(input) : useRegisterAtStart(input));
167 define(
168 ins, mir,
169 LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER));
170 }
171
172 // z = x+y
173 void LIRGeneratorARM::lowerForALU(LInstructionHelper<1, 2, 0>* ins,
174 MDefinition* mir, MDefinition* lhs,
175 MDefinition* rhs) {
176 // Some operations depend on checking inputs after writing the result, e.g.
177 // MulI, but only for bail out paths so useAtStart when no bailouts.
178 ins->setOperand(0,
179 ins->snapshot() ? useRegister(lhs) : useRegisterAtStart(lhs));
180 ins->setOperand(1, ins->snapshot() ? useRegisterOrConstant(rhs)
181 : useRegisterOrConstantAtStart(rhs));
182 define(
183 ins, mir,
184 LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER));
185 }
186
187 void LIRGeneratorARM::lowerForALUInt64(
188 LInstructionHelper<INT64_PIECES, INT64_PIECES, 0>* ins, MDefinition* mir,
189 MDefinition* input) {
190 ins->setInt64Operand(0, useInt64RegisterAtStart(input));
191 defineInt64ReuseInput(ins, mir, 0);
192 }
193
194 void LIRGeneratorARM::lowerForALUInt64(
195 LInstructionHelper<INT64_PIECES, 2 * INT64_PIECES, 0>* ins,
196 MDefinition* mir, MDefinition* lhs, MDefinition* rhs) {
197 ins->setInt64Operand(0, useInt64RegisterAtStart(lhs));
198 ins->setInt64Operand(INT64_PIECES, useInt64OrConstant(rhs));
199 defineInt64ReuseInput(ins, mir, 0);
200 }
201
202 void LIRGeneratorARM::lowerForMulInt64(LMulI64* ins, MMul* mir,
203 MDefinition* lhs, MDefinition* rhs) {
204 bool needsTemp = true;
205
206 if (rhs->isConstant()) {
207 int64_t constant = rhs->toConstant()->toInt64();
208 int32_t shift = mozilla::FloorLog2(constant);
209 // See special cases in CodeGeneratorARM::visitMulI64
210 if (constant >= -1 && constant <= 2) {
211 needsTemp = false;
212 }
213 if (constant > 0 && int64_t(1) << shift == constant) {
214 needsTemp = false;
215 }
216 }
217
218 ins->setLhs(useInt64RegisterAtStart(lhs));
219 ins->setRhs(useInt64OrConstant(rhs));
220 if (needsTemp) {
221 ins->setTemp0(temp());
222 }
223
224 defineInt64ReuseInput(ins, mir, 0);
225 }
226
227 void LIRGeneratorARM::lowerForFPU(LInstructionHelper<1, 1, 0>* ins,
228 MDefinition* mir, MDefinition* input) {
229 ins->setOperand(0, useRegisterAtStart(input));
230 define(
231 ins, mir,
232 LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER));
233 }
234
235 template <size_t Temps>
236 void LIRGeneratorARM::lowerForFPU(LInstructionHelper<1, 2, Temps>* ins,
237 MDefinition* mir, MDefinition* lhs,
238 MDefinition* rhs) {
239 ins->setOperand(0, useRegisterAtStart(lhs));
240 ins->setOperand(1, useRegisterAtStart(rhs));
241 define(
242 ins, mir,
243 LDefinition(LDefinition::TypeFrom(mir->type()), LDefinition::REGISTER));
244 }
245
246 template void LIRGeneratorARM::lowerForFPU(LInstructionHelper<1, 2, 0>* ins,
247 MDefinition* mir, MDefinition* lhs,
248 MDefinition* rhs);
249 template void LIRGeneratorARM::lowerForFPU(LInstructionHelper<1, 2, 1>* ins,
250 MDefinition* mir, MDefinition* lhs,
251 MDefinition* rhs);
252
253 void LIRGeneratorARM::lowerWasmBuiltinTruncateToInt32(
254 MWasmBuiltinTruncateToInt32* ins) {
255 MDefinition* opd = ins->input();
256 MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32);
257
258 if (opd->type() == MIRType::Double) {
259 define(new (alloc()) LWasmBuiltinTruncateDToInt32(
260 useRegister(opd), useFixedAtStart(ins->instance(), InstanceReg),
261 LDefinition::BogusTemp()),
262 ins);
263 return;
264 }
265
266 define(new (alloc()) LWasmBuiltinTruncateFToInt32(
267 useRegister(opd), useFixedAtStart(ins->instance(), InstanceReg),
268 LDefinition::BogusTemp()),
269 ins);
270 }
271
272 void LIRGeneratorARM::lowerUntypedPhiInput(MPhi* phi, uint32_t inputPosition,
273 LBlock* block, size_t lirIndex) {
274 MDefinition* operand = phi->getOperand(inputPosition);
275 LPhi* type = block->getPhi(lirIndex + VREG_TYPE_OFFSET);
276 LPhi* payload = block->getPhi(lirIndex + VREG_DATA_OFFSET);
277 type->setOperand(
278 inputPosition,
279 LUse(operand->virtualRegister() + VREG_TYPE_OFFSET, LUse::ANY));
280 payload->setOperand(inputPosition,
281 LUse(VirtualRegisterOfPayload(operand), LUse::ANY));
282 }
283
284 void LIRGeneratorARM::lowerForShift(LInstructionHelper<1, 2, 0>* ins,
285 MDefinition* mir, MDefinition* lhs,
286 MDefinition* rhs) {
287 ins->setOperand(0, useRegister(lhs));
288 ins->setOperand(1, useRegisterOrConstant(rhs));
289 define(ins, mir);
290 }
291
292 template <class LInstr>
293 void LIRGeneratorARM::lowerForShiftInt64(LInstr* ins, MDefinition* mir,
294 MDefinition* lhs, MDefinition* rhs) {
295 LAllocation rhsAlloc;
296 if (rhs->isConstant()) {
297 rhsAlloc = useOrConstant(rhs);
298 } else {
299 // The operands are int64, but we only care about the lower 32 bits of the
300 // RHS. The code below will load that part and will discard the upper half.
301 rhsAlloc = useLowWordRegister(rhs);
302 }
303
304 if constexpr (std::is_same_v<LInstr, LShiftI64>) {
305 ins->setLhs(useInt64RegisterAtStart(lhs));
306 ins->setRhs(rhsAlloc);
307 defineInt64ReuseInput(ins, mir, LShiftI64::LhsIndex);
308 } else {
309 ins->setInput(useInt64RegisterAtStart(lhs));
310 ins->setCount(rhsAlloc);
311 if (!rhs->isConstant()) {
312 ins->setTemp0(temp());
313 }
314 defineInt64ReuseInput(ins, mir, LRotateI64::InputIndex);
315 }
316 }
317
318 template void LIRGeneratorARM::lowerForShiftInt64(LShiftI64* ins,
319 MDefinition* mir,
320 MDefinition* lhs,
321 MDefinition* rhs);
322 template void LIRGeneratorARM::lowerForShiftInt64(LRotateI64* ins,
323 MDefinition* mir,
324 MDefinition* lhs,
325 MDefinition* rhs);
326
327 void LIRGeneratorARM::lowerDivI(MDiv* div) {
328 if (div->isUnsigned()) {
329 lowerUDiv(div);
330 return;
331 }
332
333 // Division instructions are slow. Division by constant denominators can be
334 // rewritten to use other instructions.
335 if (div->rhs()->isConstant()) {
336 int32_t rhs = div->rhs()->toConstant()->toInt32();
337 // Check for division by a positive power of two, which is an easy and
338 // important case to optimize. Note that other optimizations are also
339 // possible; division by negative powers of two can be optimized in a
340 // similar manner as positive powers of two, and division by other
341 // constants can be optimized by a reciprocal multiplication technique.
342 int32_t shift = FloorLog2(rhs);
343 if (rhs > 0 && 1 << shift == rhs) {
344 LDivPowTwoI* lir =
345 new (alloc()) LDivPowTwoI(useRegisterAtStart(div->lhs()), shift);
346 if (div->fallible()) {
347 assignSnapshot(lir, div->bailoutKind());
348 }
349 define(lir, div);
350 return;
351 }
352 }
353
354 if (ARMFlags::HasIDIV()) {
355 LDivI* lir = new (alloc())
356 LDivI(useRegister(div->lhs()), useRegister(div->rhs()), temp());
357 if (div->fallible()) {
358 assignSnapshot(lir, div->bailoutKind());
359 }
360 define(lir, div);
361 return;
362 }
363
364 LSoftDivI* lir = new (alloc()) LSoftDivI(useFixedAtStart(div->lhs(), r0),
365 useFixedAtStart(div->rhs(), r1));
366
367 if (div->fallible()) {
368 assignSnapshot(lir, div->bailoutKind());
369 }
370
371 defineReturn(lir, div);
372 }
373
374 void LIRGeneratorARM::lowerNegI(MInstruction* ins, MDefinition* input) {
375 define(new (alloc()) LNegI(useRegisterAtStart(input)), ins);
376 }
377
378 void LIRGeneratorARM::lowerNegI64(MInstruction* ins, MDefinition* input) {
379 // Reuse the input. Define + use-at-start would create risk that the output
380 // uses the same register pair as the input but in reverse order. Reusing
381 // probably has less spilling than the alternative, define + use.
382 defineInt64ReuseInput(new (alloc()) LNegI64(useInt64RegisterAtStart(input)),
383 ins, 0);
384 }
385
386 void LIRGenerator::visitAbs(MAbs* ins) {
387 define(allocateAbs(ins, useRegisterAtStart(ins->input())), ins);
388 }
389
390 void LIRGeneratorARM::lowerMulI(MMul* mul, MDefinition* lhs, MDefinition* rhs) {
391 LMulI* lir = new (alloc()) LMulI;
392 if (mul->fallible()) {
393 assignSnapshot(lir, mul->bailoutKind());
394 }
395 lowerForALU(lir, mul, lhs, rhs);
396 }
397
398 void LIRGeneratorARM::lowerModI(MMod* mod) {
399 if (mod->isUnsigned()) {
400 lowerUMod(mod);
401 return;
402 }
403
404 if (mod->rhs()->isConstant()) {
405 int32_t rhs = mod->rhs()->toConstant()->toInt32();
406 int32_t shift = FloorLog2(rhs);
407 if (rhs > 0 && 1 << shift == rhs) {
408 LModPowTwoI* lir =
409 new (alloc()) LModPowTwoI(useRegister(mod->lhs()), shift);
410 if (mod->fallible()) {
411 assignSnapshot(lir, mod->bailoutKind());
412 }
413 define(lir, mod);
414 return;
415 }
416 if (shift < 31 && (1 << (shift + 1)) - 1 == rhs) {
417 MOZ_ASSERT(rhs);
418 LModMaskI* lir = new (alloc())
419 LModMaskI(useRegister(mod->lhs()), temp(), temp(), shift + 1);
420 if (mod->fallible()) {
421 assignSnapshot(lir, mod->bailoutKind());
422 }
423 define(lir, mod);
424 return;
425 }
426 }
427
428 if (ARMFlags::HasIDIV()) {
429 LModI* lir =
430 new (alloc()) LModI(useRegister(mod->lhs()), useRegister(mod->rhs()));
431 if (mod->fallible()) {
432 assignSnapshot(lir, mod->bailoutKind());
433 }
434 define(lir, mod);
435 return;
436 }
437
438 // The temp register must be preserved across a call to __aeabi_idivmod
439 MOZ_ASSERT(!GeneralRegisterSet(Registers::VolatileMask).hasRegisterIndex(r4));
440 LSoftModI* lir =
441 new (alloc()) LSoftModI(useFixedAtStart(mod->lhs(), r0),
442 useFixedAtStart(mod->rhs(), r1), tempFixed(r4));
443
444 if (mod->fallible()) {
445 assignSnapshot(lir, mod->bailoutKind());
446 }
447
448 defineReturn(lir, mod);
449 }
450
451 void LIRGeneratorARM::lowerDivI64(MDiv* div) {
452 MOZ_CRASH("We use MWasmBuiltinDivI64 instead.");
453 }
454
455 void LIRGeneratorARM::lowerWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
456 if (div->isUnsigned()) {
457 LUDivOrModI64* lir = new (alloc())
458 LUDivOrModI64(useInt64RegisterAtStart(div->lhs()),
459 useInt64RegisterAtStart(div->rhs()),
460 useFixedAtStart(div->instance(), InstanceReg));
461 defineReturn(lir, div);
462 return;
463 }
464
465 LDivOrModI64* lir = new (alloc()) LDivOrModI64(
466 useInt64RegisterAtStart(div->lhs()), useInt64RegisterAtStart(div->rhs()),
467 useFixedAtStart(div->instance(), InstanceReg));
468 defineReturn(lir, div);
469 }
470
471 void LIRGeneratorARM::lowerModI64(MMod* mod) {
472 MOZ_CRASH("We use MWasmBuiltinModI64 instead.");
473 }
474
475 void LIRGeneratorARM::lowerWasmBuiltinModI64(MWasmBuiltinModI64* mod) {
476 if (mod->isUnsigned()) {
477 LUDivOrModI64* lir = new (alloc())
478 LUDivOrModI64(useInt64RegisterAtStart(mod->lhs()),
479 useInt64RegisterAtStart(mod->rhs()),
480 useFixedAtStart(mod->instance(), InstanceReg));
481 defineReturn(lir, mod);
482 return;
483 }
484
485 LDivOrModI64* lir = new (alloc()) LDivOrModI64(
486 useInt64RegisterAtStart(mod->lhs()), useInt64RegisterAtStart(mod->rhs()),
487 useFixedAtStart(mod->instance(), InstanceReg));
488 defineReturn(lir, mod);
489 }
490
491 void LIRGeneratorARM::lowerUDivI64(MDiv* div) {
492 MOZ_CRASH("We use MWasmBuiltinDivI64 instead.");
493 }
494
495 void LIRGeneratorARM::lowerUModI64(MMod* mod) {
496 MOZ_CRASH("We use MWasmBuiltinModI64 instead.");
497 }
498
499 void LIRGenerator::visitPowHalf(MPowHalf* ins) {
500 MDefinition* input = ins->input();
501 MOZ_ASSERT(input->type() == MIRType::Double);
502 LPowHalfD* lir = new (alloc()) LPowHalfD(useRegisterAtStart(input));
503 defineReuseInput(lir, ins, 0);
504 }
505
506 void LIRGeneratorARM::lowerWasmSelectI(MWasmSelect* select) {
507 auto* lir = new (alloc())
508 LWasmSelect(useRegisterAtStart(select->trueExpr()),
509 useAny(select->falseExpr()), useRegister(select->condExpr()));
510 defineReuseInput(lir, select, LWasmSelect::TrueExprIndex);
511 }
512
513 void LIRGeneratorARM::lowerWasmSelectI64(MWasmSelect* select) {
514 auto* lir = new (alloc()) LWasmSelectI64(
515 useInt64RegisterAtStart(select->trueExpr()),
516 useInt64(select->falseExpr()), useRegister(select->condExpr()));
517 defineInt64ReuseInput(lir, select, LWasmSelectI64::TrueExprIndex);
518 }
519
520 LTableSwitch* LIRGeneratorARM::newLTableSwitch(const LAllocation& in,
521 const LDefinition& inputCopy) {
522 return new (alloc()) LTableSwitch(in, inputCopy, LDefinition::BogusTemp());
523 }
524
525 LTableSwitchV* LIRGeneratorARM::newLTableSwitchV(const LBoxAllocation& in) {
526 return new (alloc())
527 LTableSwitchV(in, temp(), tempDouble(), LDefinition::BogusTemp());
528 }
529
530 void LIRGeneratorARM::lowerUrshD(MUrsh* mir) {
531 MDefinition* lhs = mir->lhs();
532 MDefinition* rhs = mir->rhs();
533
534 MOZ_ASSERT(lhs->type() == MIRType::Int32);
535 MOZ_ASSERT(rhs->type() == MIRType::Int32);
536
537 LUrshD* lir = new (alloc())
538 LUrshD(useRegister(lhs), useRegisterOrConstant(rhs), temp());
539 define(lir, mir);
540 }
541
542 void LIRGeneratorARM::lowerPowOfTwoI(MPow* mir) {
543 int32_t base = mir->input()->toConstant()->toInt32();
544 MDefinition* power = mir->power();
545
546 auto* lir = new (alloc()) LPowOfTwoI(useRegister(power), base);
547 assignSnapshot(lir, mir->bailoutKind());
548 define(lir, mir);
549 }
550
551 void LIRGeneratorARM::lowerBigIntPtrLsh(MBigIntPtrLsh* ins) {
552 auto* lir = new (alloc()) LBigIntPtrLsh(
553 useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp());
554 assignSnapshot(lir, ins->bailoutKind());
555 define(lir, ins);
556 }
557
558 void LIRGeneratorARM::lowerBigIntPtrRsh(MBigIntPtrRsh* ins) {
559 auto* lir = new (alloc()) LBigIntPtrRsh(
560 useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp());
561 assignSnapshot(lir, ins->bailoutKind());
562 define(lir, ins);
563 }
564
565 void LIRGeneratorARM::lowerBigIntPtrDiv(MBigIntPtrDiv* ins) {
566 LDefinition temp1, temp2;
567 if (ARMFlags::HasIDIV()) {
568 temp1 = LDefinition::BogusTemp();
569 temp2 = LDefinition::BogusTemp();
570 } else {
571 temp1 = tempFixed(r0);
572 temp2 = tempFixed(r1);
573 }
574 auto* lir = new (alloc()) LBigIntPtrDiv(
575 useRegister(ins->lhs()), useRegister(ins->rhs()), temp1, temp2);
576 assignSnapshot(lir, ins->bailoutKind());
577 define(lir, ins);
578 if (!ARMFlags::HasIDIV()) {
579 assignSafepoint(lir, ins);
580 }
581 }
582
583 void LIRGeneratorARM::lowerBigIntPtrMod(MBigIntPtrMod* ins) {
584 LDefinition temp1, temp2;
585 if (ARMFlags::HasIDIV()) {
586 temp1 = temp();
587 temp2 = LDefinition::BogusTemp();
588 } else {
589 temp1 = tempFixed(r0);
590 temp2 = tempFixed(r1);
591 }
592 auto* lir = new (alloc()) LBigIntPtrMod(
593 useRegister(ins->lhs()), useRegister(ins->rhs()), temp1, temp2);
594 if (ins->canBeDivideByZero()) {
595 assignSnapshot(lir, ins->bailoutKind());
596 }
597 define(lir, ins);
598 if (!ARMFlags::HasIDIV()) {
599 assignSafepoint(lir, ins);
600 }
601 }
602
603 void LIRGenerator::visitWasmNeg(MWasmNeg* ins) {
604 if (ins->type() == MIRType::Int32) {
605 define(new (alloc()) LNegI(useRegisterAtStart(ins->input())), ins);
606 } else if (ins->type() == MIRType::Float32) {
607 define(new (alloc()) LNegF(useRegisterAtStart(ins->input())), ins);
608 } else {
609 MOZ_ASSERT(ins->type() == MIRType::Double);
610 define(new (alloc()) LNegD(useRegisterAtStart(ins->input())), ins);
611 }
612 }
613
614 void LIRGeneratorARM::lowerUDiv(MDiv* div) {
615 MDefinition* lhs = div->getOperand(0);
616 MDefinition* rhs = div->getOperand(1);
617
618 if (ARMFlags::HasIDIV()) {
619 LUDiv* lir = new (alloc()) LUDiv;
620 lir->setOperand(0, useRegister(lhs));
621 lir->setOperand(1, useRegister(rhs));
622 if (div->fallible()) {
623 assignSnapshot(lir, div->bailoutKind());
624 }
625 define(lir, div);
626 return;
627 }
628
629 LSoftUDivOrMod* lir = new (alloc())
630 LSoftUDivOrMod(useFixedAtStart(lhs, r0), useFixedAtStart(rhs, r1));
631
632 if (div->fallible()) {
633 assignSnapshot(lir, div->bailoutKind());
634 }
635
636 defineReturn(lir, div);
637 }
638
639 void LIRGeneratorARM::lowerUMod(MMod* mod) {
640 MDefinition* lhs = mod->getOperand(0);
641 MDefinition* rhs = mod->getOperand(1);
642
643 if (ARMFlags::HasIDIV()) {
644 LUMod* lir = new (alloc()) LUMod;
645 lir->setOperand(0, useRegister(lhs));
646 lir->setOperand(1, useRegister(rhs));
647 if (mod->fallible()) {
648 assignSnapshot(lir, mod->bailoutKind());
649 }
650 define(lir, mod);
651 return;
652 }
653
654 LSoftUDivOrMod* lir = new (alloc())
655 LSoftUDivOrMod(useFixedAtStart(lhs, r0), useFixedAtStart(rhs, r1));
656
657 if (mod->fallible()) {
658 assignSnapshot(lir, mod->bailoutKind());
659 }
660
661 defineReturn(lir, mod);
662 }
663
664 void LIRGenerator::visitWasmUnsignedToDouble(MWasmUnsignedToDouble* ins) {
665 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
666 LWasmUint32ToDouble* lir =
667 new (alloc()) LWasmUint32ToDouble(useRegisterAtStart(ins->input()));
668 define(lir, ins);
669 }
670
671 void LIRGenerator::visitWasmUnsignedToFloat32(MWasmUnsignedToFloat32* ins) {
672 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
673 LWasmUint32ToFloat32* lir =
674 new (alloc()) LWasmUint32ToFloat32(useRegisterAtStart(ins->input()));
675 define(lir, ins);
676 }
677
678 void LIRGenerator::visitWasmLoad(MWasmLoad* ins) {
679 MDefinition* base = ins->base();
680 MOZ_ASSERT(base->type() == MIRType::Int32);
681
682 const LAllocation memoryBase =
683 ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase()))
684 : LGeneralReg(HeapReg);
685
686 if (ins->access().type() == Scalar::Int64 && ins->access().isAtomic()) {
687 auto* lir =
688 new (alloc()) LWasmAtomicLoadI64(useRegisterAtStart(base), memoryBase);
689 defineInt64Fixed(lir, ins,
690 LInt64Allocation(LAllocation(AnyRegister(IntArgReg1)),
691 LAllocation(AnyRegister(IntArgReg0))));
692 return;
693 }
694
695 LAllocation ptr = useRegisterAtStart(base);
696
697 if (ins->type() == MIRType::Int64) {
698 LDefinition ptrCopy = LDefinition::BogusTemp();
699 if (ins->access().offset32() || ins->access().type() == Scalar::Int64) {
700 ptrCopy = tempCopy(base, 0);
701 }
702
703 LDefinition memoryBaseCopy = LDefinition::BogusTemp();
704 if (ins->hasMemoryBase()) {
705 memoryBaseCopy = tempCopy(ins->memoryBase(), 1);
706 }
707
708 auto* lir =
709 new (alloc()) LWasmLoadI64(ptr, memoryBase, ptrCopy, memoryBaseCopy);
710 defineInt64(lir, ins);
711 return;
712 }
713
714 LDefinition ptrCopy = LDefinition::BogusTemp();
715 if (ins->access().offset32()) {
716 ptrCopy = tempCopy(base, 0);
717 }
718
719 auto* lir = new (alloc()) LWasmLoad(ptr, memoryBase, ptrCopy);
720 define(lir, ins);
721 }
722
723 void LIRGenerator::visitWasmStore(MWasmStore* ins) {
724 MDefinition* base = ins->base();
725 MOZ_ASSERT(base->type() == MIRType::Int32);
726
727 const LAllocation memoryBase =
728 ins->hasMemoryBase() ? LAllocation(useRegisterAtStart(ins->memoryBase()))
729 : LGeneralReg(HeapReg);
730
731 if (ins->access().type() == Scalar::Int64 && ins->access().isAtomic()) {
732 auto* lir = new (alloc()) LWasmAtomicStoreI64(
733 useRegister(base),
734 useInt64Fixed(ins->value(), Register64(IntArgReg1, IntArgReg0)),
735 memoryBase, tempInt64Fixed(Register64(IntArgReg3, IntArgReg2)));
736 add(lir, ins);
737 return;
738 }
739
740 LAllocation ptr = useRegisterAtStart(base);
741
742 if (ins->access().type() == Scalar::Int64) {
743 LInt64Allocation value = useInt64RegisterAtStart(ins->value());
744 LDefinition ptrCopy = tempCopy(base, 0);
745 auto* lir = new (alloc()) LWasmStoreI64(ptr, value, memoryBase, ptrCopy);
746 add(lir, ins);
747 return;
748 }
749
750 LDefinition ptrCopy = LDefinition::BogusTemp();
751 if (ins->access().offset32()) {
752 ptrCopy = tempCopy(base, 0);
753 }
754
755 LAllocation value;
756 if (ins->value()->type() != MIRType::Int64) {
757 value = useRegisterAtStart(ins->value());
758 } else {
759 value = useLowWordRegisterAtStart(ins->value());
760 }
761
762 auto* lir = new (alloc()) LWasmStore(ptr, value, memoryBase, ptrCopy);
763 add(lir, ins);
764 }
765
766 void LIRGenerator::visitAsmJSLoadHeap(MAsmJSLoadHeap* ins) {
767 MDefinition* base = ins->base();
768 MOZ_ASSERT(base->type() == MIRType::Int32);
769
770 // For the ARM it is best to keep the 'base' in a register if a bounds check
771 // is needed.
772 LAllocation baseAlloc;
773 LAllocation limitAlloc;
774
775 if (base->isConstant() && !ins->needsBoundsCheck()) {
776 // A bounds check is only skipped for a positive index.
777 MOZ_ASSERT(base->toConstant()->toInt32() >= 0);
778 baseAlloc = LAllocation(base->toConstant());
779 } else {
780 baseAlloc = useRegisterAtStart(base);
781 if (ins->needsBoundsCheck()) {
782 MDefinition* boundsCheckLimit = ins->boundsCheckLimit();
783 MOZ_ASSERT(boundsCheckLimit->type() == MIRType::Int32);
784 limitAlloc = useRegisterAtStart(boundsCheckLimit);
785 }
786 }
787
788 define(new (alloc()) LAsmJSLoadHeap(baseAlloc, limitAlloc, LAllocation()),
789 ins);
790 }
791
792 void LIRGenerator::visitAsmJSStoreHeap(MAsmJSStoreHeap* ins) {
793 MDefinition* base = ins->base();
794 MOZ_ASSERT(base->type() == MIRType::Int32);
795
796 LAllocation baseAlloc;
797 LAllocation limitAlloc;
798
799 if (base->isConstant() && !ins->needsBoundsCheck()) {
800 MOZ_ASSERT(base->toConstant()->toInt32() >= 0);
801 baseAlloc = LAllocation(base->toConstant());
802 } else {
803 baseAlloc = useRegisterAtStart(base);
804 if (ins->needsBoundsCheck()) {
805 MDefinition* boundsCheckLimit = ins->boundsCheckLimit();
806 MOZ_ASSERT(boundsCheckLimit->type() == MIRType::Int32);
807 limitAlloc = useRegisterAtStart(boundsCheckLimit);
808 }
809 }
810
811 add(new (alloc()) LAsmJSStoreHeap(baseAlloc, useRegisterAtStart(ins->value()),
812 limitAlloc, LAllocation()),
813 ins);
814 }
815
816 void LIRGeneratorARM::lowerTruncateDToInt32(MTruncateToInt32* ins) {
817 MDefinition* opd = ins->input();
818 MOZ_ASSERT(opd->type() == MIRType::Double);
819
820 define(new (alloc())
821 LTruncateDToInt32(useRegister(opd), LDefinition::BogusTemp()),
822 ins);
823 }
824
825 void LIRGeneratorARM::lowerTruncateFToInt32(MTruncateToInt32* ins) {
826 MDefinition* opd = ins->input();
827 MOZ_ASSERT(opd->type() == MIRType::Float32);
828
829 define(new (alloc())
830 LTruncateFToInt32(useRegister(opd), LDefinition::BogusTemp()),
831 ins);
832 }
833
834 void LIRGenerator::visitAtomicExchangeTypedArrayElement(
835 MAtomicExchangeTypedArrayElement* ins) {
836 MOZ_ASSERT(ARMFlags::HasLDSTREXBHD());
837
838 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
839 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
840
841 const LUse elements = useRegister(ins->elements());
842 const LAllocation index =
843 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
844
845 if (Scalar::isBigIntType(ins->arrayType())) {
846 // The two register pairs must be distinct.
847 LInt64Allocation value = useInt64Fixed(ins->value(), XchgNew64);
848
849 auto* lir = new (alloc())
850 LAtomicExchangeTypedArrayElement64(elements, index, value);
851 defineInt64Fixed(lir, ins,
852 LInt64Allocation(LAllocation(AnyRegister(XchgOutHi)),
853 LAllocation(AnyRegister(XchgOutLo))));
854 return;
855 }
856
857 MOZ_ASSERT(ins->arrayType() <= Scalar::Uint32);
858
859 const LAllocation value = useRegister(ins->value());
860
861 // If the target is a floating register then we need a temp at the
862 // CodeGenerator level for creating the result.
863
864 LDefinition tempDef = LDefinition::BogusTemp();
865 if (ins->arrayType() == Scalar::Uint32) {
866 MOZ_ASSERT(ins->type() == MIRType::Double);
867 tempDef = temp();
868 }
869
870 LAtomicExchangeTypedArrayElement* lir = new (alloc())
871 LAtomicExchangeTypedArrayElement(elements, index, value, tempDef);
872
873 define(lir, ins);
874 }
875
876 void LIRGenerator::visitAtomicTypedArrayElementBinop(
877 MAtomicTypedArrayElementBinop* ins) {
878 MOZ_ASSERT(ins->arrayType() != Scalar::Uint8Clamped);
879 MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType()));
880
881 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
882 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
883
884 const LUse elements = useRegister(ins->elements());
885 const LAllocation index =
886 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
887
888 if (Scalar::isBigIntType(ins->arrayType())) {
889 // Wasm additionally pins the value register to `FetchOpVal64`, but it's
890 // unclear why this was deemed necessary.
891 LInt64Allocation value = useInt64Register(ins->value());
892 LInt64Definition temp = tempInt64Fixed(FetchOpTmp64);
893
894 if (ins->isForEffect()) {
895 auto* lir = new (alloc()) LAtomicTypedArrayElementBinopForEffect64(
896 elements, index, value, temp);
897 add(lir, ins);
898 return;
899 }
900
901 auto* lir = new (alloc())
902 LAtomicTypedArrayElementBinop64(elements, index, value, temp);
903 defineInt64Fixed(lir, ins,
904 LInt64Allocation(LAllocation(AnyRegister(FetchOpOutHi)),
905 LAllocation(AnyRegister(FetchOpOutLo))));
906 return;
907 }
908
909 const LAllocation value = useRegister(ins->value());
910
911 if (ins->isForEffect()) {
912 LAtomicTypedArrayElementBinopForEffect* lir = new (alloc())
913 LAtomicTypedArrayElementBinopForEffect(elements, index, value,
914 /* flagTemp= */ temp());
915 add(lir, ins);
916 return;
917 }
918
919 // For a Uint32Array with a known double result we need a temp for
920 // the intermediate output.
921 //
922 // Optimization opportunity (bug 1077317): We can do better by
923 // allowing 'value' to remain as an imm32 if it is small enough to
924 // fit in an instruction.
925
926 LDefinition flagTemp = temp();
927 LDefinition outTemp = LDefinition::BogusTemp();
928
929 if (ins->arrayType() == Scalar::Uint32 && IsFloatingPointType(ins->type())) {
930 outTemp = temp();
931 }
932
933 // On arm, map flagTemp to temp1 and outTemp to temp2, at least for now.
934
935 LAtomicTypedArrayElementBinop* lir = new (alloc())
936 LAtomicTypedArrayElementBinop(elements, index, value, flagTemp, outTemp);
937 define(lir, ins);
938 }
939
940 void LIRGenerator::visitCompareExchangeTypedArrayElement(
941 MCompareExchangeTypedArrayElement* ins) {
942 MOZ_ASSERT(!Scalar::isFloatingType(ins->arrayType()));
943 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
944 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
945
946 const LUse elements = useRegister(ins->elements());
947 const LAllocation index =
948 useRegisterOrIndexConstant(ins->index(), ins->arrayType());
949
950 if (Scalar::isBigIntType(ins->arrayType())) {
951 // The three register pairs must be distinct.
952 LInt64Allocation oldval = useInt64Fixed(ins->oldval(), CmpXchgOld64);
953 LInt64Allocation newval = useInt64Fixed(ins->newval(), CmpXchgNew64);
954
955 auto* lir = new (alloc())
956 LCompareExchangeTypedArrayElement64(elements, index, oldval, newval);
957 defineInt64Fixed(lir, ins,
958 LInt64Allocation(LAllocation(AnyRegister(CmpXchgOutHi)),
959 LAllocation(AnyRegister(CmpXchgOutLo))));
960 return;
961 }
962
963 const LAllocation oldval = useRegister(ins->oldval());
964 const LAllocation newval = useRegister(ins->newval());
965
966 // If the target is a floating register then we need a temp at the
967 // CodeGenerator level for creating the result.
968 //
969 // Optimization opportunity (bug 1077317): We could do better by
970 // allowing oldval to remain an immediate, if it is small enough
971 // to fit in an instruction.
972
973 LDefinition tempDef = LDefinition::BogusTemp();
974 if (ins->arrayType() == Scalar::Uint32 && IsFloatingPointType(ins->type())) {
975 tempDef = temp();
976 }
977
978 LCompareExchangeTypedArrayElement* lir =
979 new (alloc()) LCompareExchangeTypedArrayElement(elements, index, oldval,
980 newval, tempDef);
981
982 define(lir, ins);
983 }
984
985 void LIRGeneratorARM::lowerAtomicLoad64(MLoadUnboxedScalar* ins) {
986 const LUse elements = useRegister(ins->elements());
987 const LAllocation index =
988 useRegisterOrIndexConstant(ins->index(), ins->storageType());
989
990 auto* lir = new (alloc()) LAtomicLoad64(elements, index);
991 defineInt64Fixed(lir, ins,
992 LInt64Allocation(LAllocation(AnyRegister(IntArgReg1)),
993 LAllocation(AnyRegister(IntArgReg0))));
994 }
995
996 void LIRGeneratorARM::lowerAtomicStore64(MStoreUnboxedScalar* ins) {
997 LUse elements = useRegister(ins->elements());
998 LAllocation index =
999 useRegisterOrIndexConstant(ins->index(), ins->writeType());
1000 LInt64Allocation value =
1001 useInt64Fixed(ins->value(), Register64(IntArgReg1, IntArgReg0));
1002 LInt64Definition temp = tempInt64Fixed(Register64(IntArgReg3, IntArgReg2));
1003
1004 add(new (alloc()) LAtomicStore64(elements, index, value, temp), ins);
1005 }
1006
1007 void LIRGenerator::visitWasmCompareExchangeHeap(MWasmCompareExchangeHeap* ins) {
1008 MDefinition* base = ins->base();
1009 MOZ_ASSERT(base->type() == MIRType::Int32);
1010
1011 const LAllocation memoryBase =
1012 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
1013 : LGeneralReg(HeapReg);
1014
1015 if (ins->access().type() == Scalar::Int64) {
1016 // The three register pairs must be distinct.
1017 auto* lir = new (alloc()) LWasmCompareExchangeI64(
1018 useRegister(base), useInt64Fixed(ins->oldValue(), CmpXchgOld64),
1019 useInt64Fixed(ins->newValue(), CmpXchgNew64), memoryBase);
1020 defineInt64Fixed(lir, ins,
1021 LInt64Allocation(LAllocation(AnyRegister(CmpXchgOutHi)),
1022 LAllocation(AnyRegister(CmpXchgOutLo))));
1023 return;
1024 }
1025
1026 MOZ_ASSERT(ins->access().type() < Scalar::Float32);
1027 MOZ_ASSERT(ARMFlags::HasLDSTREXBHD(), "by HasPlatformSupport() constraints");
1028
1029 LWasmCompareExchangeHeap* lir = new (alloc())
1030 LWasmCompareExchangeHeap(useRegister(base), useRegister(ins->oldValue()),
1031 useRegister(ins->newValue()), memoryBase);
1032
1033 define(lir, ins);
1034 }
1035
1036 void LIRGenerator::visitWasmAtomicExchangeHeap(MWasmAtomicExchangeHeap* ins) {
1037 MOZ_ASSERT(ins->base()->type() == MIRType::Int32);
1038
1039 const LAllocation memoryBase =
1040 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
1041 : LGeneralReg(HeapReg);
1042
1043 if (ins->access().type() == Scalar::Int64) {
1044 auto* lir = new (alloc()) LWasmAtomicExchangeI64(
1045 useRegister(ins->base()), useInt64Fixed(ins->value(), XchgNew64),
1046 memoryBase, ins->access());
1047 defineInt64Fixed(lir, ins,
1048 LInt64Allocation(LAllocation(AnyRegister(XchgOutHi)),
1049 LAllocation(AnyRegister(XchgOutLo))));
1050 return;
1051 }
1052
1053 MOZ_ASSERT(ins->access().type() < Scalar::Float32);
1054 MOZ_ASSERT(ARMFlags::HasLDSTREXBHD(), "by HasPlatformSupport() constraints");
1055
1056 const LAllocation base = useRegister(ins->base());
1057 const LAllocation value = useRegister(ins->value());
1058 define(new (alloc()) LWasmAtomicExchangeHeap(base, value, memoryBase), ins);
1059 }
1060
1061 void LIRGenerator::visitWasmAtomicBinopHeap(MWasmAtomicBinopHeap* ins) {
1062 const LAllocation memoryBase =
1063 ins->hasMemoryBase() ? LAllocation(useRegister(ins->memoryBase()))
1064 : LGeneralReg(HeapReg);
1065
1066 if (ins->access().type() == Scalar::Int64) {
1067 auto* lir = new (alloc()) LWasmAtomicBinopI64(
1068 useRegister(ins->base()), useInt64Fixed(ins->value(), FetchOpVal64),
1069 memoryBase, tempInt64Fixed(Register64(FetchOpTmpHi, FetchOpTmpLo)),
1070 ins->access(), ins->operation());
1071 defineInt64Fixed(lir, ins,
1072 LInt64Allocation(LAllocation(AnyRegister(FetchOpOutHi)),
1073 LAllocation(AnyRegister(FetchOpOutLo))));
1074 return;
1075 }
1076
1077 MOZ_ASSERT(ins->access().type() < Scalar::Float32);
1078 MOZ_ASSERT(ARMFlags::HasLDSTREXBHD(), "by HasPlatformSupport() constraints");
1079
1080 MDefinition* base = ins->base();
1081 MOZ_ASSERT(base->type() == MIRType::Int32);
1082
1083 if (!ins->hasUses()) {
1084 auto* lir = new (alloc()) LWasmAtomicBinopHeapForEffect(
1085 useRegister(base), useRegister(ins->value()), memoryBase, temp());
1086 add(lir, ins);
1087 return;
1088 }
1089
1090 auto* lir = new (alloc()) LWasmAtomicBinopHeap(
1091 useRegister(base), useRegister(ins->value()), memoryBase, temp());
1092 define(lir, ins);
1093 }
1094
1095 void LIRGenerator::visitSubstr(MSubstr* ins) {
1096 LSubstr* lir = new (alloc())
1097 LSubstr(useRegister(ins->string()), useRegister(ins->begin()),
1098 useRegister(ins->length()), temp(), temp(), tempByteOpRegister());
1099 define(lir, ins);
1100 assignSafepoint(lir, ins);
1101 }
1102
1103 void LIRGenerator::visitWasmTruncateToInt64(MWasmTruncateToInt64* ins) {
1104 MOZ_CRASH("We don't use MWasmTruncateToInt64 for arm");
1105 }
1106
1107 void LIRGeneratorARM::lowerWasmBuiltinTruncateToInt64(
1108 MWasmBuiltinTruncateToInt64* ins) {
1109 MDefinition* opd = ins->input();
1110 MDefinition* instance = ins->instance();
1111 MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32);
1112
1113 defineReturn(new (alloc())
1114 LWasmTruncateToInt64(useRegisterAtStart(opd),
1115 useFixedAtStart(instance, InstanceReg)),
1116 ins);
1117 }
1118
1119 void LIRGenerator::visitInt64ToFloatingPoint(MInt64ToFloatingPoint* ins) {
1120 MOZ_CRASH("We use BuiltinInt64ToFloatingPoint instead.");
1121 }
1122
1123 void LIRGeneratorARM::lowerBuiltinInt64ToFloatingPoint(
1124 MBuiltinInt64ToFloatingPoint* ins) {
1125 MOZ_ASSERT(ins->type() == MIRType::Double || ins->type() == MIRType::Float32);
1126
1127 auto* lir = new (alloc())
1128 LInt64ToFloatingPointCall(useInt64RegisterAtStart(ins->input()),
1129 useFixedAtStart(ins->instance(), InstanceReg));
1130 defineReturn(lir, ins);
1131 }
1132
1133 void LIRGenerator::visitCopySign(MCopySign* ins) {
1134 MDefinition* lhs = ins->lhs();
1135 MDefinition* rhs = ins->rhs();
1136
1137 MOZ_ASSERT(IsFloatingPointType(lhs->type()));
1138 MOZ_ASSERT(lhs->type() == rhs->type());
1139 MOZ_ASSERT(lhs->type() == ins->type());
1140
1141 LInstructionHelper<1, 2, 2>* lir;
1142 if (lhs->type() == MIRType::Double) {
1143 lir = new (alloc()) LCopySignD();
1144 } else {
1145 lir = new (alloc()) LCopySignF();
1146 }
1147
1148 lir->setTemp(0, temp());
1149 lir->setTemp(1, temp());
1150
1151 lowerForFPU(lir, ins, lhs, rhs);
1152 }
1153
1154 void LIRGenerator::visitExtendInt32ToInt64(MExtendInt32ToInt64* ins) {
1155 auto* lir =
1156 new (alloc()) LExtendInt32ToInt64(useRegisterAtStart(ins->input()));
1157 defineInt64(lir, ins);
1158
1159 LDefinition def(LDefinition::GENERAL, LDefinition::MUST_REUSE_INPUT);
1160 def.setReusedInput(0);
1161 def.setVirtualRegister(ins->virtualRegister());
1162
1163 lir->setDef(0, def);
1164 }
1165
1166 void LIRGenerator::visitSignExtendInt64(MSignExtendInt64* ins) {
1167 defineInt64(new (alloc())
1168 LSignExtendInt64(useInt64RegisterAtStart(ins->input())),
1169 ins);
1170 }
1171
1172 // On arm we specialize the only cases where compare is {U,}Int32 and select
1173 // is {U,}Int32.
1174 bool LIRGeneratorShared::canSpecializeWasmCompareAndSelect(
1175 MCompare::CompareType compTy, MIRType insTy) {
1176 return insTy == MIRType::Int32 && (compTy == MCompare::Compare_Int32 ||
1177 compTy == MCompare::Compare_UInt32);
1178 }
1179
1180 void LIRGeneratorShared::lowerWasmCompareAndSelect(MWasmSelect* ins,
1181 MDefinition* lhs,
1182 MDefinition* rhs,
1183 MCompare::CompareType compTy,
1184 JSOp jsop) {
1185 MOZ_ASSERT(canSpecializeWasmCompareAndSelect(compTy, ins->type()));
1186 auto* lir = new (alloc()) LWasmCompareAndSelect(
1187 useRegister(lhs), useRegister(rhs), useRegisterAtStart(ins->trueExpr()),
1188 useRegister(ins->falseExpr()), compTy, jsop);
1189 defineReuseInput(lir, ins, LWasmCompareAndSelect::IfTrueExprIndex);
1190 }
1191
1192 void LIRGenerator::visitWasmTernarySimd128(MWasmTernarySimd128* ins) {
1193 MOZ_CRASH("ternary SIMD NYI");
1194 }
1195
1196 void LIRGenerator::visitWasmBinarySimd128(MWasmBinarySimd128* ins) {
1197 MOZ_CRASH("binary SIMD NYI");
1198 }
1199
1200 #ifdef ENABLE_WASM_SIMD
1201 bool MWasmTernarySimd128::specializeBitselectConstantMaskAsShuffle(
1202 int8_t shuffle[16]) {
1203 return false;
1204 }
1205 bool MWasmTernarySimd128::canRelaxBitselect() { return false; }
1206
1207 bool MWasmBinarySimd128::canPmaddubsw() { return false; }
1208 #endif
1209
1210 bool MWasmBinarySimd128::specializeForConstantRhs() {
1211 // Probably many we want to do here
1212 return false;
1213 }
1214
1215 void LIRGenerator::visitWasmBinarySimd128WithConstant(
1216 MWasmBinarySimd128WithConstant* ins) {
1217 MOZ_CRASH("binary SIMD with constant NYI");
1218 }
1219
1220 void LIRGenerator::visitWasmShiftSimd128(MWasmShiftSimd128* ins) {
1221 MOZ_CRASH("shift SIMD NYI");
1222 }
1223
1224 void LIRGenerator::visitWasmShuffleSimd128(MWasmShuffleSimd128* ins) {
1225 MOZ_CRASH("shuffle SIMD NYI");
1226 }
1227
1228 void LIRGenerator::visitWasmReplaceLaneSimd128(MWasmReplaceLaneSimd128* ins) {
1229 MOZ_CRASH("replace-lane SIMD NYI");
1230 }
1231
1232 void LIRGenerator::visitWasmScalarToSimd128(MWasmScalarToSimd128* ins) {
1233 MOZ_CRASH("scalar-to-SIMD NYI");
1234 }
1235
1236 void LIRGenerator::visitWasmUnarySimd128(MWasmUnarySimd128* ins) {
1237 MOZ_CRASH("unary SIMD NYI");
1238 }
1239
1240 void LIRGenerator::visitWasmReduceSimd128(MWasmReduceSimd128* ins) {
1241 MOZ_CRASH("reduce-SIMD NYI");
1242 }
1243
1244 void LIRGenerator::visitWasmLoadLaneSimd128(MWasmLoadLaneSimd128* ins) {
1245 MOZ_CRASH("load-lane SIMD NYI");
1246 }
1247
1248 void LIRGenerator::visitWasmStoreLaneSimd128(MWasmStoreLaneSimd128* ins) {
1249 MOZ_CRASH("store-lane SIMD NYI");
1250 }