Debian Codegraph @

js/src/jit/Lowering.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/Lowering.h"
8
9 #include "mozilla/DebugOnly.h"
10 #include "mozilla/EndianUtils.h"
11 #include "mozilla/FloatingPoint.h"
12 #include "mozilla/MathAlgorithms.h"
13
14 #include <type_traits>
15
16 #include "jit/ABIArgGenerator.h"
17 #include "jit/IonGenericCallStub.h"
18 #include "jit/IonOptimizationLevels.h"
19 #include "jit/JitSpewer.h"
20 #include "jit/LIR.h"
21 #include "jit/MacroAssembler.h"
22 #include "jit/MIR-wasm.h"
23 #include "jit/MIR.h"
24 #include "jit/MIRGraph.h"
25 #include "jit/SharedICRegisters.h"
26 #include "js/experimental/JitInfo.h" // JSJitInfo
27 #include "util/Memory.h"
28 #include "wasm/WasmCodegenTypes.h"
29 #include "wasm/WasmFeatures.h" // for wasm::ReportSimdAnalysis
30 #include "wasm/WasmInstanceData.h"
31
32 #include "jit/shared/Lowering-shared-inl.h"
33 #include "vm/BytecodeUtil-inl.h"
34
35 using namespace js;
36 using namespace jit;
37
38 using JS::GenericNaN;
39 using mozilla::DebugOnly;
40
41 LBoxAllocation LIRGenerator::useBoxFixedAtStart(MDefinition* mir,
42 ValueOperand op) {
43 #if defined(JS_NUNBOX32)
44 return useBoxFixed(mir, op.typeReg(), op.payloadReg(), true);
45 #elif defined(JS_PUNBOX64)
46 return useBoxFixed(mir, op.valueReg(), op.scratchReg(), true);
47 #endif
48 }
49
50 LBoxAllocation LIRGenerator::useBoxAtStart(MDefinition* mir,
51 LUse::Policy policy) {
52 return useBox(mir, policy, /* useAtStart = */ true);
53 }
54
55 void LIRGenerator::visitParameter(MParameter* param) {
56 ptrdiff_t offset;
57 if (param->index() == MParameter::THIS_SLOT) {
58 offset = THIS_FRAME_ARGSLOT;
59 } else {
60 offset = 1 + param->index();
61 }
62
63 LParameter* ins = new (alloc()) LParameter;
64 defineBox(ins, param, LDefinition::FIXED);
65
66 offset *= sizeof(Value);
67 #if defined(JS_NUNBOX32)
68 # if MOZ_BIG_ENDIAN()
69 ins->getDef(0)->setOutput(LArgument(offset));
70 ins->getDef(1)->setOutput(LArgument(offset + 4));
71 # else
72 ins->getDef(0)->setOutput(LArgument(offset + 4));
73 ins->getDef(1)->setOutput(LArgument(offset));
74 # endif
75 #elif defined(JS_PUNBOX64)
76 ins->getDef(0)->setOutput(LArgument(offset));
77 #endif
78 }
79
80 void LIRGenerator::visitCallee(MCallee* ins) {
81 define(new (alloc()) LCallee(), ins);
82 }
83
84 void LIRGenerator::visitIsConstructing(MIsConstructing* ins) {
85 define(new (alloc()) LIsConstructing(), ins);
86 }
87
88 void LIRGenerator::visitGoto(MGoto* ins) {
89 add(new (alloc()) LGoto(ins->target()));
90 }
91
92 void LIRGenerator::visitTableSwitch(MTableSwitch* tableswitch) {
93 MDefinition* opd = tableswitch->getOperand(0);
94
95 // There should be at least 1 successor. The default case!
96 MOZ_ASSERT(tableswitch->numSuccessors() > 0);
97
98 // If there are no cases, the default case is always taken.
99 if (tableswitch->numSuccessors() == 1) {
100 add(new (alloc()) LGoto(tableswitch->getDefault()));
101 return;
102 }
103
104 // If we don't know the type.
105 if (opd->type() == MIRType::Value) {
106 add(newLTableSwitchV(useBox(opd)), tableswitch);
107 return;
108 }
109
110 // Case indices are numeric, so other types will always go to the default
111 // case.
112 if (opd->type() != MIRType::Int32 && opd->type() != MIRType::Double) {
113 add(new (alloc()) LGoto(tableswitch->getDefault()));
114 return;
115 }
116
117 // Return an LTableSwitch, capable of handling either an integer or
118 // floating-point index.
119 LAllocation index;
120 LDefinition tempInt;
121 if (opd->type() == MIRType::Int32) {
122 index = useRegisterAtStart(opd);
123 tempInt = tempCopy(opd, 0);
124 } else {
125 index = useRegister(opd);
126 tempInt = temp();
127 }
128 add(newLTableSwitch(index, tempInt), tableswitch);
129 }
130
131 void LIRGenerator::visitCheckOverRecursed(MCheckOverRecursed* ins) {
132 LCheckOverRecursed* lir = new (alloc()) LCheckOverRecursed();
133 add(lir, ins);
134 assignSafepoint(lir, ins);
135 }
136
137 void LIRGenerator::visitNewArray(MNewArray* ins) {
138 LNewArray* lir = new (alloc()) LNewArray(temp());
139 define(lir, ins);
140 assignSafepoint(lir, ins);
141 }
142
143 void LIRGenerator::visitNewArrayDynamicLength(MNewArrayDynamicLength* ins) {
144 MDefinition* length = ins->length();
145 MOZ_ASSERT(length->type() == MIRType::Int32);
146
147 LNewArrayDynamicLength* lir =
148 new (alloc()) LNewArrayDynamicLength(useRegister(length), temp());
149 define(lir, ins);
150 assignSafepoint(lir, ins);
151 }
152
153 void LIRGenerator::visitNewIterator(MNewIterator* ins) {
154 LNewIterator* lir = new (alloc()) LNewIterator(temp());
155 define(lir, ins);
156 assignSafepoint(lir, ins);
157 }
158
159 void LIRGenerator::visitNewTypedArray(MNewTypedArray* ins) {
160 LNewTypedArray* lir = new (alloc()) LNewTypedArray(temp(), temp());
161 define(lir, ins);
162 assignSafepoint(lir, ins);
163 }
164
165 void LIRGenerator::visitNewTypedArrayDynamicLength(
166 MNewTypedArrayDynamicLength* ins) {
167 MDefinition* length = ins->length();
168 MOZ_ASSERT(length->type() == MIRType::Int32);
169
170 LNewTypedArrayDynamicLength* lir =
171 new (alloc()) LNewTypedArrayDynamicLength(useRegister(length), temp());
172 define(lir, ins);
173 assignSafepoint(lir, ins);
174 }
175
176 void LIRGenerator::visitNewTypedArrayFromArray(MNewTypedArrayFromArray* ins) {
177 MDefinition* array = ins->array();
178 MOZ_ASSERT(array->type() == MIRType::Object);
179
180 auto* lir = new (alloc()) LNewTypedArrayFromArray(useRegisterAtStart(array));
181 defineReturn(lir, ins);
182 assignSafepoint(lir, ins);
183 }
184
185 void LIRGenerator::visitNewTypedArrayFromArrayBuffer(
186 MNewTypedArrayFromArrayBuffer* ins) {
187 MDefinition* arrayBuffer = ins->arrayBuffer();
188 MDefinition* byteOffset = ins->byteOffset();
189 MDefinition* length = ins->length();
190 MOZ_ASSERT(arrayBuffer->type() == MIRType::Object);
191 MOZ_ASSERT(byteOffset->type() == MIRType::Value);
192 MOZ_ASSERT(length->type() == MIRType::Value);
193
194 auto* lir = new (alloc()) LNewTypedArrayFromArrayBuffer(
195 useRegisterAtStart(arrayBuffer), useBoxAtStart(byteOffset),
196 useBoxAtStart(length));
197 defineReturn(lir, ins);
198 assignSafepoint(lir, ins);
199 }
200
201 void LIRGenerator::visitNewObject(MNewObject* ins) {
202 LNewObject* lir = new (alloc()) LNewObject(temp());
203 define(lir, ins);
204 assignSafepoint(lir, ins);
205 }
206
207 void LIRGenerator::visitBindFunction(MBindFunction* ins) {
208 MDefinition* target = ins->target();
209 MOZ_ASSERT(target->type() == MIRType::Object);
210
211 if (!lowerCallArguments(ins)) {
212 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitBindFunction");
213 return;
214 }
215
216 auto* lir = new (alloc())
217 LBindFunction(useFixedAtStart(target, CallTempReg0),
218 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
219 defineReturn(lir, ins);
220 assignSafepoint(lir, ins);
221 }
222
223 void LIRGenerator::visitNewBoundFunction(MNewBoundFunction* ins) {
224 auto* lir = new (alloc()) LNewBoundFunction(temp());
225 define(lir, ins);
226 assignSafepoint(lir, ins);
227 }
228
229 void LIRGenerator::visitNewPlainObject(MNewPlainObject* ins) {
230 LNewPlainObject* lir = new (alloc()) LNewPlainObject(temp(), temp(), temp());
231 define(lir, ins);
232 assignSafepoint(lir, ins);
233 }
234
235 void LIRGenerator::visitNewArrayObject(MNewArrayObject* ins) {
236 LNewArrayObject* lir = new (alloc()) LNewArrayObject(temp(), temp());
237 define(lir, ins);
238 assignSafepoint(lir, ins);
239 }
240
241 void LIRGenerator::visitNewNamedLambdaObject(MNewNamedLambdaObject* ins) {
242 LNewNamedLambdaObject* lir = new (alloc()) LNewNamedLambdaObject(temp());
243 define(lir, ins);
244 assignSafepoint(lir, ins);
245 }
246
247 void LIRGenerator::visitNewCallObject(MNewCallObject* ins) {
248 LNewCallObject* lir = new (alloc()) LNewCallObject(temp());
249 define(lir, ins);
250 assignSafepoint(lir, ins);
251 }
252
253 void LIRGenerator::visitNewMapObject(MNewMapObject* ins) {
254 auto* lir = new (alloc()) LNewMapObject(temp());
255 define(lir, ins);
256 assignSafepoint(lir, ins);
257 }
258
259 void LIRGenerator::visitNewSetObject(MNewSetObject* ins) {
260 auto* lir = new (alloc()) LNewSetObject(temp());
261 define(lir, ins);
262 assignSafepoint(lir, ins);
263 }
264
265 void LIRGenerator::visitNewMapObjectFromIterable(
266 MNewMapObjectFromIterable* ins) {
267 MOZ_ASSERT(ins->iterable()->type() == MIRType::Value);
268 auto* lir = new (alloc()) LNewMapObjectFromIterable(
269 useBoxFixedAtStart(ins->iterable(), CallTempReg0, CallTempReg1),
270 tempFixed(CallTempReg2), tempFixed(CallTempReg3));
271 defineReturn(lir, ins);
272 assignSafepoint(lir, ins);
273 }
274
275 void LIRGenerator::visitNewSetObjectFromIterable(
276 MNewSetObjectFromIterable* ins) {
277 MOZ_ASSERT(ins->iterable()->type() == MIRType::Value);
278 auto* lir = new (alloc()) LNewSetObjectFromIterable(
279 useBoxFixedAtStart(ins->iterable(), CallTempReg0, CallTempReg1),
280 tempFixed(CallTempReg2), tempFixed(CallTempReg3));
281 defineReturn(lir, ins);
282 assignSafepoint(lir, ins);
283 }
284
285 void LIRGenerator::visitNewStringObject(MNewStringObject* ins) {
286 MOZ_ASSERT(ins->input()->type() == MIRType::String);
287
288 LNewStringObject* lir =
289 new (alloc()) LNewStringObject(useRegister(ins->input()), temp());
290 define(lir, ins);
291 assignSafepoint(lir, ins);
292 }
293
294 void LIRGenerator::visitInitElemGetterSetter(MInitElemGetterSetter* ins) {
295 LInitElemGetterSetter* lir = new (alloc()) LInitElemGetterSetter(
296 useRegisterAtStart(ins->object()), useBoxAtStart(ins->id()),
297 useRegisterAtStart(ins->value()));
298 add(lir, ins);
299 assignSafepoint(lir, ins);
300 }
301
302 void LIRGenerator::visitMutateProto(MMutateProto* ins) {
303 LMutateProto* lir = new (alloc()) LMutateProto(
304 useRegisterAtStart(ins->object()), useBoxAtStart(ins->value()));
305 add(lir, ins);
306 assignSafepoint(lir, ins);
307 }
308
309 void LIRGenerator::visitInitPropGetterSetter(MInitPropGetterSetter* ins) {
310 LInitPropGetterSetter* lir = new (alloc()) LInitPropGetterSetter(
311 useRegisterAtStart(ins->object()), useRegisterAtStart(ins->value()));
312 add(lir, ins);
313 assignSafepoint(lir, ins);
314 }
315
316 void LIRGenerator::visitCreateThis(MCreateThis* ins) {
317 LCreateThis* lir =
318 new (alloc()) LCreateThis(useRegisterOrConstantAtStart(ins->callee()),
319 useRegisterOrConstantAtStart(ins->newTarget()));
320 defineReturn(lir, ins);
321 assignSafepoint(lir, ins);
322 }
323
324 void LIRGenerator::visitCreateArgumentsObject(MCreateArgumentsObject* ins) {
325 LAllocation callObj = useRegisterAtStart(ins->getCallObject());
326 LCreateArgumentsObject* lir = new (alloc())
327 LCreateArgumentsObject(callObj, tempFixed(CallTempReg0),
328 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
329 defineReturn(lir, ins);
330 assignSafepoint(lir, ins);
331 }
332
333 void LIRGenerator::visitCreateInlinedArgumentsObject(
334 MCreateInlinedArgumentsObject* ins) {
335 LAllocation callObj = useRegisterAtStart(ins->getCallObject());
336 LAllocation callee = useRegisterAtStart(ins->getCallee());
337 uint32_t numActuals = ins->numActuals();
338 uint32_t numOperands = numActuals * BOX_PIECES +
339 LCreateInlinedArgumentsObject::NumNonArgumentOperands;
340
341 auto* lir = allocateVariadic<LCreateInlinedArgumentsObject>(
342 numOperands, tempFixed(CallTempReg0), tempFixed(CallTempReg1));
343 if (!lir) {
344 abort(AbortReason::Alloc,
345 "OOM: LIRGenerator::visitCreateInlinedArgumentsObject");
346 return;
347 }
348
349 lir->setOperand(LCreateInlinedArgumentsObject::CallObj, callObj);
350 lir->setOperand(LCreateInlinedArgumentsObject::Callee, callee);
351 for (uint32_t i = 0; i < numActuals; i++) {
352 MDefinition* arg = ins->getArg(i);
353 uint32_t index = LCreateInlinedArgumentsObject::ArgIndex(i);
354 lir->setBoxOperand(index, useBoxOrTypedOrConstant(arg,
355 /*useConstant = */ true,
356 /*useAtStart = */ true));
357 }
358
359 defineReturn(lir, ins);
360 assignSafepoint(lir, ins);
361 }
362
363 void LIRGenerator::visitGetInlinedArgument(MGetInlinedArgument* ins) {
364 #if defined(JS_PUNBOX64)
365 // On 64-bit architectures, we don't support boxing a typed register
366 // in-place without using a scratch register, so the result register
367 // can't be the same as any of the inputs. Fortunately, those
368 // architectures have registers to spare.
369 const bool useAtStart = false;
370 #else
371 const bool useAtStart = true;
372 #endif
373
374 LAllocation index =
375 useAtStart ? useRegisterAtStart(ins->index()) : useRegister(ins->index());
376 uint32_t numActuals = ins->numActuals();
377 uint32_t numOperands =
378 numActuals * BOX_PIECES + LGetInlinedArgument::NumNonArgumentOperands;
379
380 auto* lir = allocateVariadic<LGetInlinedArgument>(numOperands);
381 if (!lir) {
382 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitGetInlinedArgument");
383 return;
384 }
385
386 lir->setOperand(LGetInlinedArgument::Index, index);
387 for (uint32_t i = 0; i < numActuals; i++) {
388 MDefinition* arg = ins->getArg(i);
389 uint32_t index = LGetInlinedArgument::ArgIndex(i);
390 lir->setBoxOperand(
391 index, useBoxOrTypedOrConstant(arg,
392 /*useConstant = */ true, useAtStart));
393 }
394 defineBox(lir, ins);
395 }
396
397 void LIRGenerator::visitGetInlinedArgumentHole(MGetInlinedArgumentHole* ins) {
398 #if defined(JS_CODEGEN_X64) || defined(JS_CODEGEN_MIPS64)
399 // On some 64-bit architectures, we don't support boxing a typed
400 // register in-place without using a scratch register, so the result
401 // register can't be the same as any of the inputs. Fortunately,
402 // those architectures have registers to spare.
403 const bool useAtStart = false;
404 #else
405 const bool useAtStart = true;
406 #endif
407
408 LAllocation index =
409 useAtStart ? useRegisterAtStart(ins->index()) : useRegister(ins->index());
410 uint32_t numActuals = ins->numActuals();
411 uint32_t numOperands =
412 numActuals * BOX_PIECES + LGetInlinedArgumentHole::NumNonArgumentOperands;
413
414 auto* lir = allocateVariadic<LGetInlinedArgumentHole>(numOperands);
415 if (!lir) {
416 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitGetInlinedArgumentHole");
417 return;
418 }
419
420 lir->setOperand(LGetInlinedArgumentHole::Index, index);
421 for (uint32_t i = 0; i < numActuals; i++) {
422 MDefinition* arg = ins->getArg(i);
423 uint32_t index = LGetInlinedArgumentHole::ArgIndex(i);
424 lir->setBoxOperand(
425 index, useBoxOrTypedOrConstant(arg,
426 /*useConstant = */ true, useAtStart));
427 }
428 assignSnapshot(lir, ins->bailoutKind());
429 defineBox(lir, ins);
430 }
431
432 void LIRGenerator::visitGetArgumentsObjectArg(MGetArgumentsObjectArg* ins) {
433 LAllocation argsObj = useRegister(ins->argsObject());
434 LGetArgumentsObjectArg* lir =
435 new (alloc()) LGetArgumentsObjectArg(argsObj, temp());
436 defineBox(lir, ins);
437 }
438
439 void LIRGenerator::visitSetArgumentsObjectArg(MSetArgumentsObjectArg* ins) {
440 LAllocation argsObj = useRegister(ins->argsObject());
441 LSetArgumentsObjectArg* lir = new (alloc())
442 LSetArgumentsObjectArg(argsObj, useBox(ins->value()), temp());
443 add(lir, ins);
444 }
445
446 void LIRGenerator::visitLoadArgumentsObjectArg(MLoadArgumentsObjectArg* ins) {
447 MDefinition* argsObj = ins->argsObject();
448 MOZ_ASSERT(argsObj->type() == MIRType::Object);
449
450 MDefinition* index = ins->index();
451 MOZ_ASSERT(index->type() == MIRType::Int32);
452
453 auto* lir = new (alloc())
454 LLoadArgumentsObjectArg(useRegister(argsObj), useRegister(index), temp());
455 assignSnapshot(lir, ins->bailoutKind());
456 defineBox(lir, ins);
457 }
458
459 void LIRGenerator::visitLoadArgumentsObjectArgHole(
460 MLoadArgumentsObjectArgHole* ins) {
461 MDefinition* argsObj = ins->argsObject();
462 MOZ_ASSERT(argsObj->type() == MIRType::Object);
463
464 MDefinition* index = ins->index();
465 MOZ_ASSERT(index->type() == MIRType::Int32);
466
467 auto* lir = new (alloc()) LLoadArgumentsObjectArgHole(
468 useRegister(argsObj), useRegister(index), temp());
469 assignSnapshot(lir, ins->bailoutKind());
470 defineBox(lir, ins);
471 }
472
473 void LIRGenerator::visitInArgumentsObjectArg(MInArgumentsObjectArg* ins) {
474 MDefinition* argsObj = ins->argsObject();
475 MOZ_ASSERT(argsObj->type() == MIRType::Object);
476
477 MDefinition* index = ins->index();
478 MOZ_ASSERT(index->type() == MIRType::Int32);
479
480 auto* lir = new (alloc())
481 LInArgumentsObjectArg(useRegister(argsObj), useRegister(index), temp());
482 assignSnapshot(lir, ins->bailoutKind());
483 define(lir, ins);
484 }
485
486 void LIRGenerator::visitArgumentsObjectLength(MArgumentsObjectLength* ins) {
487 MDefinition* argsObj = ins->argsObject();
488 MOZ_ASSERT(argsObj->type() == MIRType::Object);
489
490 auto* lir = new (alloc()) LArgumentsObjectLength(useRegister(argsObj));
491 assignSnapshot(lir, ins->bailoutKind());
492 define(lir, ins);
493 }
494
495 void LIRGenerator::visitArrayFromArgumentsObject(
496 MArrayFromArgumentsObject* ins) {
497 MDefinition* argsObj = ins->argsObject();
498 MOZ_ASSERT(argsObj->type() == MIRType::Object);
499
500 auto* lir =
501 new (alloc()) LArrayFromArgumentsObject(useRegisterAtStart(argsObj));
502 defineReturn(lir, ins);
503 assignSafepoint(lir, ins);
504 }
505
506 void LIRGenerator::visitGuardArgumentsObjectFlags(
507 MGuardArgumentsObjectFlags* ins) {
508 MDefinition* argsObj = ins->argsObject();
509 MOZ_ASSERT(argsObj->type() == MIRType::Object);
510
511 auto* lir =
512 new (alloc()) LGuardArgumentsObjectFlags(useRegister(argsObj), temp());
513 assignSnapshot(lir, ins->bailoutKind());
514 add(lir, ins);
515 redefine(ins, argsObj);
516 }
517
518 void LIRGenerator::visitGuardObjectHasSameRealm(MGuardObjectHasSameRealm* ins) {
519 MDefinition* obj = ins->object();
520 MOZ_ASSERT(obj->type() == MIRType::Object);
521
522 auto* lir = new (alloc()) LGuardObjectHasSameRealm(useRegister(obj), temp());
523 assignSnapshot(lir, ins->bailoutKind());
524 add(lir, ins);
525 redefine(ins, obj);
526 }
527
528 void LIRGenerator::visitBoundFunctionNumArgs(MBoundFunctionNumArgs* ins) {
529 MDefinition* obj = ins->object();
530 MOZ_ASSERT(obj->type() == MIRType::Object);
531
532 auto* lir = new (alloc()) LBoundFunctionNumArgs(useRegisterAtStart(obj));
533 define(lir, ins);
534 }
535
536 void LIRGenerator::visitGuardBoundFunctionIsConstructor(
537 MGuardBoundFunctionIsConstructor* ins) {
538 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
539
540 auto* lir = new (alloc())
541 LGuardBoundFunctionIsConstructor(useRegister(ins->object()));
542 assignSnapshot(lir, ins->bailoutKind());
543 add(lir, ins);
544 redefine(ins, ins->object());
545 }
546
547 void LIRGenerator::visitReturnFromCtor(MReturnFromCtor* ins) {
548 LReturnFromCtor* lir = new (alloc())
549 LReturnFromCtor(useBox(ins->value()), useRegister(ins->object()));
550 define(lir, ins);
551 }
552
553 void LIRGenerator::visitBoxNonStrictThis(MBoxNonStrictThis* ins) {
554 MOZ_ASSERT(ins->type() == MIRType::Object);
555 MOZ_ASSERT(ins->input()->type() == MIRType::Value);
556
557 auto* lir = new (alloc()) LBoxNonStrictThis(useBox(ins->input()));
558 define(lir, ins);
559 assignSafepoint(lir, ins);
560 }
561
562 void LIRGenerator::visitImplicitThis(MImplicitThis* ins) {
563 MDefinition* env = ins->env();
564 MOZ_ASSERT(env->type() == MIRType::Object);
565
566 auto* lir = new (alloc()) LImplicitThis(useRegister(env));
567 defineBox(lir, ins);
568 assignSafepoint(lir, ins);
569 }
570
571 template <typename T>
572 bool LIRGenerator::lowerCallArguments(T* call) {
573 uint32_t argc = call->numStackArgs();
574
575 // Align the arguments of a call such that the callee would keep the same
576 // alignment as the caller.
577 uint32_t baseSlot = 0;
578 if (JitStackValueAlignment > 1) {
579 baseSlot = AlignBytes(argc, JitStackValueAlignment);
580 } else {
581 baseSlot = argc;
582 }
583
584 // Save the maximum number of argument, such that we can have one unique
585 // frame size.
586 if (baseSlot > maxargslots_) {
587 maxargslots_ = baseSlot;
588 }
589
590 for (size_t i = 0; i < argc; i++) {
591 MDefinition* arg = call->getArg(i);
592 uint32_t argslot = baseSlot - i;
593
594 // Values take a slow path.
595 if (arg->type() == MIRType::Value) {
596 LStackArgV* stack = new (alloc()) LStackArgV(useBox(arg), argslot);
597 add(stack);
598 } else {
599 // Known types can move constant types and/or payloads.
600 LStackArgT* stack = new (alloc())
601 LStackArgT(useRegisterOrConstant(arg), argslot, arg->type());
602 add(stack);
603 }
604
605 if (!alloc().ensureBallast()) {
606 return false;
607 }
608 }
609 return true;
610 }
611
612 void LIRGenerator::visitCall(MCall* call) {
613 MOZ_ASSERT(call->getCallee()->type() == MIRType::Object);
614
615 // In case of oom, skip the rest of the allocations.
616 if (!lowerCallArguments(call)) {
617 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitCall");
618 return;
619 }
620
621 WrappedFunction* target = call->getSingleTarget();
622
623 LInstruction* lir;
624
625 if (call->isCallDOMNative()) {
626 // Call DOM functions.
627 MOZ_ASSERT(target && target->isNativeWithoutJitEntry());
628 Register cxReg, objReg, privReg, argsReg;
629 GetTempRegForIntArg(0, 0, &cxReg);
630 GetTempRegForIntArg(1, 0, &objReg);
631 GetTempRegForIntArg(2, 0, &privReg);
632 mozilla::DebugOnly<bool> ok = GetTempRegForIntArg(3, 0, &argsReg);
633 MOZ_ASSERT(ok, "How can we not have four temp registers?");
634 lir = new (alloc()) LCallDOMNative(tempFixed(cxReg), tempFixed(objReg),
635 tempFixed(privReg), tempFixed(argsReg));
636 } else if (target) {
637 // Call known functions.
638 if (target->isNativeWithoutJitEntry()) {
639 Register cxReg, numReg, vpReg, tmpReg;
640 GetTempRegForIntArg(0, 0, &cxReg);
641 GetTempRegForIntArg(1, 0, &numReg);
642 GetTempRegForIntArg(2, 0, &vpReg);
643
644 // Even though this is just a temp reg, use the same API to avoid
645 // register collisions.
646 mozilla::DebugOnly<bool> ok = GetTempRegForIntArg(3, 0, &tmpReg);
647 MOZ_ASSERT(ok, "How can we not have four temp registers?");
648
649 lir = new (alloc()) LCallNative(tempFixed(cxReg), tempFixed(numReg),
650 tempFixed(vpReg), tempFixed(tmpReg));
651 } else {
652 lir = new (alloc()) LCallKnown(useRegisterAtStart(call->getCallee()),
653 tempFixed(CallTempReg0));
654 }
655 } else {
656 // Call anything, using the most generic code.
657 lir = new (alloc()) LCallGeneric(
658 useFixedAtStart(call->getCallee(), IonGenericCallCalleeReg),
659 tempFixed(IonGenericCallArgcReg));
660 }
661 defineReturn(lir, call);
662 assignSafepoint(lir, call);
663 }
664
665 void LIRGenerator::visitCallClassHook(MCallClassHook* call) {
666 MDefinition* callee = call->getCallee();
667 MOZ_ASSERT(callee->type() == MIRType::Object);
668
669 // In case of oom, skip the rest of the allocations.
670 if (!lowerCallArguments(call)) {
671 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitCallClassHook");
672 return;
673 }
674
675 Register cxReg, numReg, vpReg, tmpReg;
676 GetTempRegForIntArg(0, 0, &cxReg);
677 GetTempRegForIntArg(1, 0, &numReg);
678 GetTempRegForIntArg(2, 0, &vpReg);
679
680 // Even though this is just a temp reg, use the same API to avoid
681 // register collisions.
682 mozilla::DebugOnly<bool> ok = GetTempRegForIntArg(3, 0, &tmpReg);
683 MOZ_ASSERT(ok, "How can we not have four temp registers?");
684
685 auto* lir = new (alloc())
686 LCallClassHook(useRegisterAtStart(callee), tempFixed(cxReg),
687 tempFixed(numReg), tempFixed(vpReg), tempFixed(tmpReg));
688 defineReturn(lir, call);
689 assignSafepoint(lir, call);
690 }
691
692 void LIRGenerator::visitApplyArgs(MApplyArgs* apply) {
693 MOZ_ASSERT(apply->getFunction()->type() == MIRType::Object);
694
695 // Assert if the return value is already erased.
696 static_assert(CallTempReg2 != JSReturnReg_Type);
697 static_assert(CallTempReg2 != JSReturnReg_Data);
698
699 auto argc = useFixedAtStart(apply->getArgc(), CallTempReg0);
700 auto thisValue =
701 useBoxFixedAtStart(apply->getThis(), CallTempReg4, CallTempReg5);
702 auto tempObj = tempFixed(CallTempReg1); // object register
703 auto tempCopy = tempFixed(CallTempReg2); // copy register
704
705 auto* target = apply->getSingleTarget();
706
707 LInstruction* lir;
708 if (target && target->isNativeWithoutJitEntry()) {
709 auto temp = tempFixed(CallTempReg3);
710
711 lir = new (alloc())
712 LApplyArgsNative(argc, thisValue, tempObj, tempCopy, temp);
713 } else {
714 auto function = useFixedAtStart(apply->getFunction(), CallTempReg3);
715
716 lir = new (alloc())
717 LApplyArgsGeneric(function, argc, thisValue, tempObj, tempCopy);
718 lirGraph_.addExtraSafepointUses(1);
719 }
720
721 // Bailout is needed in the case of too many values in the arguments array.
722 assignSnapshot(lir, apply->bailoutKind());
723
724 defineReturn(lir, apply);
725 assignSafepoint(lir, apply);
726 }
727
728 void LIRGenerator::visitApplyArgsObj(MApplyArgsObj* apply) {
729 MOZ_ASSERT(apply->getFunction()->type() == MIRType::Object);
730
731 // Assert if the return value is already erased.
732 static_assert(CallTempReg2 != JSReturnReg_Type);
733 static_assert(CallTempReg2 != JSReturnReg_Data);
734
735 auto argsObj = useFixedAtStart(apply->getArgsObj(), CallTempReg0);
736 auto thisValue =
737 useBoxFixedAtStart(apply->getThis(), CallTempReg4, CallTempReg5);
738 auto tempObj = tempFixed(CallTempReg1); // object register
739 auto tempCopy = tempFixed(CallTempReg2); // copy register
740
741 auto* target = apply->getSingleTarget();
742
743 LInstruction* lir;
744 if (target && target->isNativeWithoutJitEntry()) {
745 auto temp = tempFixed(CallTempReg3);
746
747 lir = new (alloc())
748 LApplyArgsObjNative(argsObj, thisValue, tempObj, tempCopy, temp);
749 } else {
750 auto function = useFixedAtStart(apply->getFunction(), CallTempReg3);
751
752 lir = new (alloc())
753 LApplyArgsObj(function, argsObj, thisValue, tempObj, tempCopy);
754 lirGraph_.addExtraSafepointUses(1);
755 }
756
757 // Bailout is needed in the case of too many values in the arguments array.
758 assignSnapshot(lir, apply->bailoutKind());
759
760 defineReturn(lir, apply);
761 assignSafepoint(lir, apply);
762 }
763
764 void LIRGenerator::visitApplyArray(MApplyArray* apply) {
765 MOZ_ASSERT(apply->getFunction()->type() == MIRType::Object);
766
767 // Assert if the return value is already erased.
768 static_assert(CallTempReg2 != JSReturnReg_Type);
769 static_assert(CallTempReg2 != JSReturnReg_Data);
770
771 auto elements = useFixedAtStart(apply->getElements(), CallTempReg0);
772 auto thisValue =
773 useBoxFixedAtStart(apply->getThis(), CallTempReg4, CallTempReg5);
774 auto tempObj = tempFixed(CallTempReg1); // object register
775 auto tempCopy = tempFixed(CallTempReg2); // copy register
776
777 auto* target = apply->getSingleTarget();
778
779 LInstruction* lir;
780 if (target && target->isNativeWithoutJitEntry()) {
781 auto temp = tempFixed(CallTempReg3);
782
783 lir = new (alloc())
784 LApplyArrayNative(elements, thisValue, tempObj, tempCopy, temp);
785 } else {
786 auto function = useFixedAtStart(apply->getFunction(), CallTempReg3);
787
788 lir = new (alloc())
789 LApplyArrayGeneric(function, elements, thisValue, tempObj, tempCopy);
790 lirGraph_.addExtraSafepointUses(1);
791 }
792
793 // Bailout is needed in the case of too many values in the array, or empty
794 // space at the end of the array.
795 assignSnapshot(lir, apply->bailoutKind());
796
797 defineReturn(lir, apply);
798 assignSafepoint(lir, apply);
799 }
800
801 void LIRGenerator::visitConstructArgs(MConstructArgs* mir) {
802 MOZ_ASSERT(mir->getFunction()->type() == MIRType::Object);
803 MOZ_ASSERT(mir->getArgc()->type() == MIRType::Int32);
804 MOZ_ASSERT(mir->getNewTarget()->type() == MIRType::Object);
805 MOZ_ASSERT(mir->getThis()->type() == MIRType::Value);
806
807 // Assert if the return value is already erased.
808 static_assert(CallTempReg2 != JSReturnReg_Type);
809 static_assert(CallTempReg2 != JSReturnReg_Data);
810
811 auto argc = useFixedAtStart(mir->getArgc(), CallTempReg0);
812 auto newTarget = useFixedAtStart(mir->getNewTarget(), CallTempReg1);
813 auto temp = tempFixed(CallTempReg2);
814
815 auto* target = mir->getSingleTarget();
816
817 LInstruction* lir;
818 if (target && target->isNativeWithoutJitEntry()) {
819 auto temp2 = tempFixed(CallTempReg3);
820 auto temp3 = tempFixed(CallTempReg4);
821
822 lir =
823 new (alloc()) LConstructArgsNative(argc, newTarget, temp, temp2, temp3);
824 } else {
825 auto function = useFixedAtStart(mir->getFunction(), CallTempReg3);
826 auto thisValue =
827 useBoxFixedAtStart(mir->getThis(), CallTempReg4, CallTempReg5);
828
829 lir = new (alloc())
830 LConstructArgsGeneric(function, argc, newTarget, thisValue, temp);
831 lirGraph_.addExtraSafepointUses(1);
832 }
833
834 // Bailout is needed in the case of too many values in the arguments array.
835 assignSnapshot(lir, mir->bailoutKind());
836
837 defineReturn(lir, mir);
838 assignSafepoint(lir, mir);
839 }
840
841 void LIRGenerator::visitConstructArray(MConstructArray* mir) {
842 MOZ_ASSERT(mir->getFunction()->type() == MIRType::Object);
843 MOZ_ASSERT(mir->getElements()->type() == MIRType::Elements);
844 MOZ_ASSERT(mir->getNewTarget()->type() == MIRType::Object);
845 MOZ_ASSERT(mir->getThis()->type() == MIRType::Value);
846
847 // Assert if the return value is already erased.
848 static_assert(CallTempReg2 != JSReturnReg_Type);
849 static_assert(CallTempReg2 != JSReturnReg_Data);
850
851 auto elements = useFixedAtStart(mir->getElements(), CallTempReg0);
852 auto newTarget = useFixedAtStart(mir->getNewTarget(), CallTempReg1);
853 auto temp = tempFixed(CallTempReg2);
854
855 auto* target = mir->getSingleTarget();
856
857 LInstruction* lir;
858 if (target && target->isNativeWithoutJitEntry()) {
859 auto temp2 = tempFixed(CallTempReg3);
860 auto temp3 = tempFixed(CallTempReg4);
861
862 lir = new (alloc())
863 LConstructArrayNative(elements, newTarget, temp, temp2, temp3);
864 } else {
865 auto function = useFixedAtStart(mir->getFunction(), CallTempReg3);
866 auto thisValue =
867 useBoxFixedAtStart(mir->getThis(), CallTempReg4, CallTempReg5);
868
869 lir = new (alloc())
870 LConstructArrayGeneric(function, elements, newTarget, thisValue, temp);
871 lirGraph_.addExtraSafepointUses(1);
872 }
873
874 // Bailout is needed in the case of too many values in the array, or empty
875 // space at the end of the array.
876 assignSnapshot(lir, mir->bailoutKind());
877
878 defineReturn(lir, mir);
879 assignSafepoint(lir, mir);
880 }
881
882 void LIRGenerator::visitBail(MBail* bail) {
883 LBail* lir = new (alloc()) LBail();
884 assignSnapshot(lir, bail->bailoutKind());
885 add(lir, bail);
886 }
887
888 void LIRGenerator::visitUnreachable(MUnreachable* unreachable) {
889 LUnreachable* lir = new (alloc()) LUnreachable();
890 add(lir, unreachable);
891 }
892
893 void LIRGenerator::visitEncodeSnapshot(MEncodeSnapshot* mir) {
894 LEncodeSnapshot* lir = new (alloc()) LEncodeSnapshot();
895 assignSnapshot(lir, mir->bailoutKind());
896 add(lir, mir);
897 }
898
899 void LIRGenerator::visitUnreachableResult(MUnreachableResult* mir) {
900 if (mir->type() == MIRType::Value) {
901 auto* lir = new (alloc()) LUnreachableResultV();
902 defineBox(lir, mir);
903 } else {
904 auto* lir = new (alloc()) LUnreachableResultT();
905 define(lir, mir);
906 }
907 }
908
909 void LIRGenerator::visitAssertFloat32(MAssertFloat32* assertion) {
910 MIRType type = assertion->input()->type();
911 DebugOnly<bool> checkIsFloat32 = assertion->mustBeFloat32();
912
913 if (type != MIRType::Value && !JitOptions.eagerIonCompilation()) {
914 MOZ_ASSERT_IF(checkIsFloat32, type == MIRType::Float32);
915 MOZ_ASSERT_IF(!checkIsFloat32, type != MIRType::Float32);
916 }
917 }
918
919 void LIRGenerator::visitAssertRecoveredOnBailout(
920 MAssertRecoveredOnBailout* assertion) {
921 MOZ_CRASH("AssertRecoveredOnBailout nodes are always recovered on bailouts.");
922 }
923
924 [[nodiscard]] static JSOp ReorderComparison(JSOp op, MDefinition** lhsp,
925 MDefinition** rhsp) {
926 MDefinition* lhs = *lhsp;
927 MDefinition* rhs = *rhsp;
928
929 if (lhs->maybeConstantValue()) {
930 *rhsp = lhs;
931 *lhsp = rhs;
932 return ReverseCompareOp(op);
933 }
934 return op;
935 }
936
937 void LIRGenerator::visitTest(MTest* test) {
938 MDefinition* opd = test->getOperand(0);
939 MBasicBlock* ifTrue = test->ifTrue();
940 MBasicBlock* ifFalse = test->ifFalse();
941
942 // String is converted to length of string in the type analysis phase (see
943 // TestPolicy).
944 MOZ_ASSERT(opd->type() != MIRType::String);
945
946 // Testing a constant.
947 if (MConstant* constant = opd->maybeConstantValue()) {
948 bool b;
949 if (constant->valueToBoolean(&b)) {
950 add(new (alloc()) LGoto(b ? ifTrue : ifFalse));
951 return;
952 }
953 }
954
955 if (opd->type() == MIRType::Value) {
956 auto* lir = new (alloc()) LTestVAndBranch(
957 ifTrue, ifFalse, useBox(opd), tempDouble(), tempToUnbox(), temp());
958 add(lir, test);
959 return;
960 }
961
962 // Objects are truthy, except if it might emulate undefined.
963 if (opd->type() == MIRType::Object) {
964 add(new (alloc())
965 LTestOAndBranch(ifTrue, ifFalse, useRegister(opd), temp()),
966 test);
967 return;
968 }
969
970 // These must be explicitly sniffed out since they are constants and have
971 // no payload.
972 if (opd->type() == MIRType::Undefined || opd->type() == MIRType::Null) {
973 add(new (alloc()) LGoto(ifFalse));
974 return;
975 }
976
977 // All symbols are truthy.
978 if (opd->type() == MIRType::Symbol) {
979 add(new (alloc()) LGoto(ifTrue));
980 return;
981 }
982
983 // Try to match the pattern
984 // test=MTest(
985 // comp=MCompare(
986 // {EQ,NE} for {Int,UInt}{32,64},
987 // bitAnd={MBitAnd,MWasmBinaryBitwise(And{32,64})}(x, y),
988 // MConstant(0)
989 // )
990 // )
991 // and produce a single LBitAnd{,64}AndBranch node. This requires both `comp`
992 // and `bitAnd` to be marked emit-at-uses.
993 if (opd->isCompare() && opd->isEmittedAtUses()) {
994 MCompare* comp = opd->toCompare();
995 Assembler::Condition compCond =
996 JSOpToCondition(comp->compareType(), comp->jsop());
997 MDefinition* compL = comp->lhs();
998 MDefinition* compR = comp->rhs();
999 if ((comp->compareType() == MCompare::Compare_Int32 ||
1000 comp->compareType() == MCompare::Compare_UInt32 ||
1001 (comp->compareType() == MCompare::Compare_Int64) ||
1002 (comp->compareType() == MCompare::Compare_UInt64)) &&
1003 (compCond == Assembler::Equal || compCond == Assembler::NotEqual) &&
1004 compR->isConstant() &&
1005 (compR->toConstant()->isInt32(0) ||
1006 (compR->toConstant()->isInt64(0))) &&
1007 (compL->isBitAnd() || (compL->isWasmBinaryBitwise() &&
1008 compL->toWasmBinaryBitwise()->subOpcode() ==
1009 MWasmBinaryBitwise::SubOpcode::And))) {
1010 // The MCompare is OK; now check its first operand (the and-ish node).
1011 MDefinition* bitAnd = compL;
1012 MDefinition* bitAndL = bitAnd->getOperand(0);
1013 MDefinition* bitAndR = bitAnd->getOperand(1);
1014 MIRType bitAndLTy = bitAndL->type();
1015 MIRType bitAndRTy = bitAndR->type();
1016 if (bitAnd->isEmittedAtUses() && bitAndLTy == bitAndRTy &&
1017 (bitAndLTy == MIRType::Int32 || (bitAndLTy == MIRType::Int64))) {
1018 // Pattern match succeeded.
1019 ReorderCommutative(&bitAndL, &bitAndR, test);
1020 if (compCond == Assembler::Equal) {
1021 compCond = Assembler::Zero;
1022 } else if (compCond == Assembler::NotEqual) {
1023 compCond = Assembler::NonZero;
1024 } else {
1025 MOZ_ASSERT_UNREACHABLE("inequality operators cannot be folded");
1026 }
1027
1028 if (bitAndLTy == MIRType::Int64) {
1029 auto lhs = useInt64RegisterAtStart(bitAndL);
1030 auto rhs = useInt64RegisterOrConstantAtStart(bitAndR);
1031 auto* lir = new (alloc())
1032 LBitAnd64AndBranch(ifTrue, ifFalse, lhs, rhs, compCond);
1033 add(lir, test);
1034 return;
1035 }
1036
1037 LAllocation lhs = useRegisterAtStart(bitAndL);
1038 LAllocation rhs = useRegisterOrConstantAtStart(bitAndR);
1039 auto* lir =
1040 new (alloc()) LBitAndAndBranch(ifTrue, ifFalse, lhs, rhs, compCond);
1041 add(lir, test);
1042 return;
1043 }
1044 }
1045 }
1046
1047 // Check if the operand for this test is a compare operation. If it is, we
1048 // want to emit an LCompare*AndBranch rather than an LTest*AndBranch, to fuse
1049 // the compare and jump instructions.
1050 if (opd->isCompare() && opd->isEmittedAtUses()) {
1051 MCompare* comp = opd->toCompare();
1052 MDefinition* left = comp->lhs();
1053 MDefinition* right = comp->rhs();
1054
1055 // Try to fold the comparison so that we don't have to handle all cases.
1056 bool result;
1057 if (comp->tryFold(&result)) {
1058 add(new (alloc()) LGoto(result ? ifTrue : ifFalse));
1059 return;
1060 }
1061
1062 // Emit LCompare*AndBranch.
1063
1064 // Compare and branch null/undefined.
1065 // The second operand has known null/undefined type,
1066 // so just test the first operand.
1067 if (comp->compareType() == MCompare::Compare_Null ||
1068 comp->compareType() == MCompare::Compare_Undefined) {
1069 if (left->type() == MIRType::Object) {
1070 auto* lir = new (alloc()) LIsNullOrLikeUndefinedAndBranchT(
1071 ifTrue, ifFalse, useRegister(left), temp(), comp);
1072 add(lir, test);
1073 return;
1074 }
1075
1076 if (IsLooseEqualityOp(comp->jsop())) {
1077 auto* lir = new (alloc()) LIsNullOrLikeUndefinedAndBranchV(
1078 ifTrue, ifFalse, useBox(left), temp(), tempToUnbox(), comp);
1079 add(lir, test);
1080 return;
1081 }
1082
1083 if (comp->compareType() == MCompare::Compare_Null) {
1084 auto* lir =
1085 new (alloc()) LIsNullAndBranch(ifTrue, ifFalse, useBox(left), comp);
1086 add(lir, test);
1087 return;
1088 }
1089
1090 auto* lir = new (alloc())
1091 LIsUndefinedAndBranch(ifTrue, ifFalse, useBox(left), comp);
1092 add(lir, test);
1093 return;
1094 }
1095
1096 // Compare and branch Int32, Symbol, Object, or WasmAnyRef pointers.
1097 if (comp->isInt32Comparison() ||
1098 comp->compareType() == MCompare::Compare_UInt32 ||
1099 comp->compareType() == MCompare::Compare_IntPtr ||
1100 comp->compareType() == MCompare::Compare_UIntPtr ||
1101 comp->compareType() == MCompare::Compare_Object ||
1102 comp->compareType() == MCompare::Compare_Symbol ||
1103 comp->compareType() == MCompare::Compare_WasmAnyRef) {
1104 JSOp op = ReorderComparison(comp->jsop(), &left, &right);
1105 LAllocation lhs = useRegister(left);
1106 LAllocation rhs;
1107 if (comp->isInt32Comparison() ||
1108 comp->compareType() == MCompare::Compare_UInt32 ||
1109 comp->compareType() == MCompare::Compare_IntPtr ||
1110 comp->compareType() == MCompare::Compare_UIntPtr) {
1111 rhs = useAnyOrInt32Constant(right);
1112 } else {
1113 rhs = useAny(right);
1114 }
1115 auto* lir =
1116 new (alloc()) LCompareAndBranch(ifTrue, ifFalse, lhs, rhs, comp, op);
1117 add(lir, test);
1118 return;
1119 }
1120
1121 // Compare and branch Int64.
1122 if (comp->compareType() == MCompare::Compare_Int64 ||
1123 comp->compareType() == MCompare::Compare_UInt64) {
1124 JSOp op = ReorderComparison(comp->jsop(), &left, &right);
1125 LInt64Allocation lhs = useInt64Register(left);
1126 LInt64Allocation rhs = useInt64OrConstant(right);
1127 auto* lir = new (alloc())
1128 LCompareI64AndBranch(ifTrue, ifFalse, lhs, rhs, comp, op);
1129 add(lir, test);
1130 return;
1131 }
1132
1133 // Compare and branch doubles.
1134 if (comp->isDoubleComparison()) {
1135 LAllocation lhs = useRegister(left);
1136 LAllocation rhs = useRegister(right);
1137 auto* lir =
1138 new (alloc()) LCompareDAndBranch(ifTrue, ifFalse, lhs, rhs, comp);
1139 add(lir, test);
1140 return;
1141 }
1142
1143 // Compare and branch floats.
1144 if (comp->isFloat32Comparison()) {
1145 LAllocation lhs = useRegister(left);
1146 LAllocation rhs = useRegister(right);
1147 auto* lir =
1148 new (alloc()) LCompareFAndBranch(ifTrue, ifFalse, lhs, rhs, comp);
1149 add(lir, test);
1150 return;
1151 }
1152
1153 // Compare and branch BigInt with Int32.
1154 if (comp->compareType() == MCompare::Compare_BigInt_Int32) {
1155 LAllocation lhs = useRegister(left);
1156 LAllocation rhs = useRegisterOrInt32Constant(right);
1157 LDefinition temp1 = temp();
1158 LDefinition temp2 = !rhs.isConstant() ? temp() : LDefinition::BogusTemp();
1159 auto* lir = new (alloc()) LCompareBigIntInt32AndBranch(
1160 ifTrue, ifFalse, lhs, rhs, temp1, temp2, comp);
1161 add(lir, test);
1162 return;
1163 }
1164 }
1165
1166 // Check if the operand for this test is a bitand operation. If it is, we want
1167 // to emit an LBitAndAndBranch rather than an LTest*AndBranch.
1168 if (opd->isBitAnd() && opd->isEmittedAtUses()) {
1169 MBitAnd* bitAnd = opd->toBitAnd();
1170 MDefinition* left = bitAnd->lhs();
1171 MDefinition* right = bitAnd->rhs();
1172 if (left->type() == MIRType::Int32 && right->type() == MIRType::Int32) {
1173 ReorderCommutative(&left, &right, test);
1174 LAllocation lhs = useRegisterAtStart(left);
1175 LAllocation rhs = useRegisterOrConstantAtStart(right);
1176 auto* lir = new (alloc())
1177 LBitAndAndBranch(ifTrue, ifFalse, lhs, rhs, Assembler::NonZero);
1178 add(lir, test);
1179 return;
1180 }
1181 }
1182
1183 #if defined(ENABLE_WASM_SIMD) && \
1184 (defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || \
1185 defined(JS_CODEGEN_ARM64))
1186 // Check if the operand for this test is an any_true/all_true SIMD operation.
1187 // If it is, we want to emit an LWasmReduceAndBranchSimd128 node to avoid
1188 // generating an intermediate boolean result.
1189 if (opd->isWasmReduceSimd128() && opd->isEmittedAtUses()) {
1190 MWasmReduceSimd128* node = opd->toWasmReduceSimd128();
1191 if (canFoldReduceSimd128AndBranch(node->simdOp())) {
1192 # ifdef DEBUG
1193 js::wasm::ReportSimdAnalysis("simd128-to-scalar-and-branch -> folded");
1194 # endif
1195 auto* lir = new (alloc()) LWasmReduceAndBranchSimd128(
1196 ifTrue, ifFalse, useRegister(node->input()), node->simdOp());
1197 add(lir, test);
1198 return;
1199 }
1200 }
1201 #endif
1202
1203 if (opd->isIsObject() && opd->isEmittedAtUses()) {
1204 MDefinition* input = opd->toIsObject()->input();
1205 MOZ_ASSERT(input->type() == MIRType::Value);
1206
1207 LIsObjectAndBranch* lir =
1208 new (alloc()) LIsObjectAndBranch(ifTrue, ifFalse, useBoxAtStart(input));
1209 add(lir, test);
1210 return;
1211 }
1212
1213 if (opd->isWasmRefTestAbstract() && opd->isEmittedAtUses()) {
1214 MWasmRefTestAbstract* refTest = opd->toWasmRefTestAbstract();
1215
1216 LAllocation ref = useRegister(refTest->ref());
1217 WasmRefIsSubtypeDefs regs =
1218 useWasmRefIsSubtype(refTest->destType(), /*superSTV=*/nullptr);
1219 add(new (alloc()) LWasmRefTestAbstractAndBranch(
1220 ifTrue, ifFalse, ref, regs.scratch1, refTest->ref()->wasmRefType(),
1221 refTest->destType()),
1222 test);
1223 return;
1224 }
1225
1226 if (opd->isWasmRefTestConcrete() && opd->isEmittedAtUses()) {
1227 MWasmRefTestConcrete* refTest = opd->toWasmRefTestConcrete();
1228
1229 LAllocation ref = useRegister(refTest->ref());
1230 WasmRefIsSubtypeDefs regs =
1231 useWasmRefIsSubtype(refTest->destType(), refTest->superSTV());
1232 add(new (alloc()) LWasmRefTestConcreteAndBranch(
1233 ifTrue, ifFalse, ref, regs.superSTV, regs.scratch1, regs.scratch2,
1234 refTest->ref()->wasmRefType(), refTest->destType()),
1235 test);
1236 return;
1237 }
1238
1239 if (opd->isIsNullOrUndefined() && opd->isEmittedAtUses()) {
1240 MIsNullOrUndefined* isNullOrUndefined = opd->toIsNullOrUndefined();
1241 MDefinition* input = isNullOrUndefined->value();
1242
1243 if (input->type() == MIRType::Value) {
1244 auto* lir = new (alloc())
1245 LIsNullOrUndefinedAndBranch(ifTrue, ifFalse, useBoxAtStart(input));
1246 add(lir, test);
1247 } else {
1248 auto* target = IsNullOrUndefined(input->type()) ? ifTrue : ifFalse;
1249 add(new (alloc()) LGoto(target));
1250 }
1251 return;
1252 }
1253
1254 if (opd->isIsNoIter()) {
1255 MOZ_ASSERT(opd->isEmittedAtUses());
1256
1257 MDefinition* input = opd->toIsNoIter()->input();
1258 MOZ_ASSERT(input->type() == MIRType::Value);
1259
1260 LIsNoIterAndBranch* lir =
1261 new (alloc()) LIsNoIterAndBranch(ifTrue, ifFalse, useBox(input));
1262 add(lir, test);
1263 return;
1264 }
1265
1266 if (opd->isIteratorHasIndices()) {
1267 MOZ_ASSERT(opd->isEmittedAtUses());
1268
1269 MDefinition* object = opd->toIteratorHasIndices()->object();
1270 MDefinition* iterator = opd->toIteratorHasIndices()->iterator();
1271 LIteratorHasIndicesAndBranch* lir = new (alloc())
1272 LIteratorHasIndicesAndBranch(ifTrue, ifFalse, useRegister(object),
1273 useRegister(iterator), temp(), temp());
1274 add(lir, test);
1275 return;
1276 }
1277
1278 switch (opd->type()) {
1279 case MIRType::Double:
1280 add(new (alloc()) LTestDAndBranch(ifTrue, ifFalse, useRegister(opd)));
1281 break;
1282 case MIRType::Float32:
1283 add(new (alloc()) LTestFAndBranch(ifTrue, ifFalse, useRegister(opd)));
1284 break;
1285 case MIRType::Int32:
1286 case MIRType::Boolean:
1287 add(new (alloc()) LTestIAndBranch(ifTrue, ifFalse, useRegister(opd)));
1288 break;
1289 case MIRType::IntPtr:
1290 add(new (alloc()) LTestIPtrAndBranch(ifTrue, ifFalse, useRegister(opd)));
1291 break;
1292 case MIRType::Int64:
1293 add(new (alloc())
1294 LTestI64AndBranch(ifTrue, ifFalse, useInt64Register(opd)));
1295 break;
1296 case MIRType::BigInt:
1297 add(new (alloc()) LTestBIAndBranch(ifTrue, ifFalse, useRegister(opd)));
1298 break;
1299 default:
1300 MOZ_CRASH("Bad type");
1301 }
1302 }
1303
1304 static inline bool CanEmitCompareAtUses(MInstruction* ins) {
1305 if (!ins->canEmitAtUses()) {
1306 return false;
1307 }
1308
1309 // If the result is never used, we can usefully defer emission to the use
1310 // point, since that will never happen.
1311 MUseIterator iter(ins->usesBegin());
1312 if (iter == ins->usesEnd()) {
1313 return true;
1314 }
1315
1316 // If the first use isn't of the expected form, the answer is No.
1317 MNode* node = iter->consumer();
1318 if (!node->isDefinition()) {
1319 return false;
1320 }
1321
1322 MDefinition* use = node->toDefinition();
1323 if (!use->isTest() && !use->isWasmSelect()) {
1324 return false;
1325 }
1326
1327 // Emission can be deferred to the first use point, but only if there are no
1328 // other use points.
1329 iter++;
1330 return iter == ins->usesEnd();
1331 }
1332
1333 void LIRGenerator::visitCompare(MCompare* comp) {
1334 MDefinition* left = comp->lhs();
1335 MDefinition* right = comp->rhs();
1336
1337 // Try to fold the comparison so that we don't have to handle all cases.
1338 bool result;
1339 if (comp->tryFold(&result)) {
1340 define(new (alloc()) LInteger(result), comp);
1341 return;
1342 }
1343
1344 // Move below the emitAtUses call if we ever implement
1345 // LCompareSAndBranch. Doing this now wouldn't be wrong, but doesn't
1346 // make sense and avoids confusion.
1347 if (comp->compareType() == MCompare::Compare_String) {
1348 MConstant* constant = nullptr;
1349 MDefinition* input = nullptr;
1350 if (left->isConstant()) {
1351 constant = left->toConstant();
1352 input = right;
1353 } else if (right->isConstant()) {
1354 constant = right->toConstant();
1355 input = left;
1356 }
1357
1358 if (constant) {
1359 JSLinearString* linear = &constant->toString()->asLinear();
1360
1361 if (IsEqualityOp(comp->jsop())) {
1362 if (MacroAssembler::canCompareStringCharsInline(linear)) {
1363 auto* lir = new (alloc()) LCompareSInline(useRegister(input), linear);
1364 define(lir, comp);
1365 assignSafepoint(lir, comp);
1366 return;
1367 }
1368 } else {
1369 MOZ_ASSERT(IsRelationalOp(comp->jsop()));
1370
1371 if (linear->length() == 1) {
1372 // Move the constant value into the right-hand side operand.
1373 JSOp op = comp->jsop();
1374 if (left == constant) {
1375 op = ReverseCompareOp(op);
1376 }
1377
1378 auto* lir = new (alloc())
1379 LCompareSSingle(useRegister(input), temp(), op, linear);
1380 define(lir, comp);
1381 return;
1382 }
1383 }
1384 }
1385
1386 LCompareS* lir =
1387 new (alloc()) LCompareS(useRegister(left), useRegister(right));
1388 define(lir, comp);
1389 assignSafepoint(lir, comp);
1390 return;
1391 }
1392
1393 // Compare two BigInts.
1394 if (comp->compareType() == MCompare::Compare_BigInt) {
1395 auto* lir = new (alloc()) LCompareBigInt(
1396 useRegister(left), useRegister(right), temp(), temp(), temp());
1397 define(lir, comp);
1398 return;
1399 }
1400
1401 // Compare BigInt with Double.
1402 if (comp->compareType() == MCompare::Compare_BigInt_Double) {
1403 auto* lir = new (alloc()) LCompareBigIntDouble(useRegisterAtStart(left),
1404 useRegisterAtStart(right));
1405 defineReturn(lir, comp);
1406 return;
1407 }
1408
1409 // Compare BigInt with String.
1410 if (comp->compareType() == MCompare::Compare_BigInt_String) {
1411 auto* lir = new (alloc()) LCompareBigIntString(useRegisterAtStart(left),
1412 useRegisterAtStart(right));
1413 defineReturn(lir, comp);
1414 assignSafepoint(lir, comp);
1415 return;
1416 }
1417
1418 // Sniff out if the output of this compare is used only for a branching.
1419 // If it is, then we will emit an LCompare*AndBranch instruction in place
1420 // of this compare and any test that uses this compare. Thus, we can
1421 // ignore this Compare.
1422 if (CanEmitCompareAtUses(comp)) {
1423 emitAtUses(comp);
1424 return;
1425 }
1426
1427 // Compare Null and Undefined.
1428 if (comp->compareType() == MCompare::Compare_Null ||
1429 comp->compareType() == MCompare::Compare_Undefined) {
1430 if (left->type() == MIRType::Object) {
1431 define(new (alloc()) LIsNullOrLikeUndefinedT(useRegister(left)), comp);
1432 return;
1433 }
1434
1435 if (IsLooseEqualityOp(comp->jsop())) {
1436 auto* lir =
1437 new (alloc()) LIsNullOrLikeUndefinedV(useBox(left), tempToUnbox());
1438 define(lir, comp);
1439 return;
1440 }
1441
1442 if (comp->compareType() == MCompare::Compare_Null) {
1443 auto* lir = new (alloc()) LIsNull(useBox(left));
1444 define(lir, comp);
1445 return;
1446 }
1447
1448 auto* lir = new (alloc()) LIsUndefined(useBox(left));
1449 define(lir, comp);
1450 return;
1451 }
1452
1453 // Compare Int32, Symbol, Object or Wasm pointers.
1454 if (comp->isInt32Comparison() ||
1455 comp->compareType() == MCompare::Compare_UInt32 ||
1456 comp->compareType() == MCompare::Compare_IntPtr ||
1457 comp->compareType() == MCompare::Compare_UIntPtr ||
1458 comp->compareType() == MCompare::Compare_Object ||
1459 comp->compareType() == MCompare::Compare_Symbol ||
1460 comp->compareType() == MCompare::Compare_WasmAnyRef) {
1461 JSOp op = ReorderComparison(comp->jsop(), &left, &right);
1462 LAllocation lhs = useRegister(left);
1463 LAllocation rhs;
1464 if (comp->isInt32Comparison() ||
1465 comp->compareType() == MCompare::Compare_UInt32 ||
1466 comp->compareType() == MCompare::Compare_IntPtr ||
1467 comp->compareType() == MCompare::Compare_UIntPtr) {
1468 rhs = useAnyOrInt32Constant(right);
1469 } else {
1470 rhs = useAny(right);
1471 }
1472 define(new (alloc()) LCompare(lhs, rhs, op), comp);
1473 return;
1474 }
1475
1476 // Compare Int64.
1477 if (comp->compareType() == MCompare::Compare_Int64 ||
1478 comp->compareType() == MCompare::Compare_UInt64) {
1479 JSOp op = ReorderComparison(comp->jsop(), &left, &right);
1480 define(new (alloc()) LCompareI64(useInt64Register(left),
1481 useInt64OrConstant(right), op),
1482 comp);
1483 return;
1484 }
1485
1486 // Compare doubles.
1487 if (comp->isDoubleComparison()) {
1488 define(new (alloc()) LCompareD(useRegister(left), useRegister(right)),
1489 comp);
1490 return;
1491 }
1492
1493 // Compare float32.
1494 if (comp->isFloat32Comparison()) {
1495 define(new (alloc()) LCompareF(useRegister(left), useRegister(right)),
1496 comp);
1497 return;
1498 }
1499
1500 // Compare BigInt with Int32.
1501 if (comp->compareType() == MCompare::Compare_BigInt_Int32) {
1502 LAllocation lhs = useRegister(left);
1503 LAllocation rhs = useRegisterOrInt32Constant(right);
1504 LDefinition temp1 = temp();
1505 LDefinition temp2 = !rhs.isConstant() ? temp() : LDefinition::BogusTemp();
1506 auto* lir = new (alloc()) LCompareBigIntInt32(lhs, rhs, temp1, temp2);
1507 define(lir, comp);
1508 return;
1509 }
1510
1511 MOZ_CRASH("Unrecognized compare type.");
1512 }
1513
1514 void LIRGenerator::visitStrictConstantCompareInt32(
1515 MStrictConstantCompareInt32* ins) {
1516 MDefinition* value = ins->value();
1517
1518 auto* lir = new (alloc())
1519 LStrictConstantCompareInt32(useBox(value), tempDouble(), tempDouble());
1520 define(lir, ins);
1521 }
1522
1523 void LIRGenerator::visitStrictConstantCompareBoolean(
1524 MStrictConstantCompareBoolean* ins) {
1525 MDefinition* value = ins->value();
1526
1527 auto* lir =
1528 new (alloc()) LStrictConstantCompareBoolean(useBox(value), temp());
1529 define(lir, ins);
1530 }
1531
1532 void LIRGenerator::visitSameValueDouble(MSameValueDouble* ins) {
1533 MDefinition* lhs = ins->lhs();
1534 MDefinition* rhs = ins->rhs();
1535
1536 MOZ_ASSERT(lhs->type() == MIRType::Double);
1537 MOZ_ASSERT(rhs->type() == MIRType::Double);
1538
1539 auto* lir = new (alloc())
1540 LSameValueDouble(useRegister(lhs), useRegister(rhs), tempDouble());
1541 define(lir, ins);
1542 }
1543
1544 void LIRGenerator::visitSameValue(MSameValue* ins) {
1545 MDefinition* lhs = ins->lhs();
1546 MDefinition* rhs = ins->rhs();
1547
1548 MOZ_ASSERT(lhs->type() == MIRType::Value);
1549 MOZ_ASSERT(rhs->type() == MIRType::Value);
1550
1551 auto* lir = new (alloc()) LSameValue(useBox(lhs), useBox(rhs));
1552 define(lir, ins);
1553 assignSafepoint(lir, ins);
1554 }
1555
1556 void LIRGenerator::lowerBitOp(JSOp op, MBinaryInstruction* ins) {
1557 MDefinition* lhs = ins->getOperand(0);
1558 MDefinition* rhs = ins->getOperand(1);
1559 MOZ_ASSERT(IsIntType(ins->type()));
1560
1561 if (ins->type() == MIRType::Int32) {
1562 MOZ_ASSERT(lhs->type() == MIRType::Int32);
1563 MOZ_ASSERT(rhs->type() == MIRType::Int32);
1564 ReorderCommutative(&lhs, &rhs, ins);
1565 lowerForALU(new (alloc()) LBitOpI(op), ins, lhs, rhs);
1566 return;
1567 }
1568
1569 if (ins->type() == MIRType::Int64) {
1570 MOZ_ASSERT(lhs->type() == MIRType::Int64);
1571 MOZ_ASSERT(rhs->type() == MIRType::Int64);
1572 ReorderCommutative(&lhs, &rhs, ins);
1573 lowerForALUInt64(new (alloc()) LBitOpI64(op), ins, lhs, rhs);
1574 return;
1575 }
1576
1577 MOZ_CRASH("Unhandled integer specialization");
1578 }
1579
1580 void LIRGenerator::visitTypeOf(MTypeOf* ins) {
1581 MDefinition* opd = ins->input();
1582
1583 if (opd->type() == MIRType::Object) {
1584 auto* lir = new (alloc()) LTypeOfO(useRegister(opd));
1585 define(lir, ins);
1586 return;
1587 }
1588
1589 MOZ_ASSERT(opd->type() == MIRType::Value);
1590
1591 LTypeOfV* lir = new (alloc()) LTypeOfV(useBox(opd), tempToUnbox());
1592 define(lir, ins);
1593 }
1594
1595 void LIRGenerator::visitTypeOfName(MTypeOfName* ins) {
1596 MDefinition* input = ins->input();
1597 MOZ_ASSERT(input->type() == MIRType::Int32);
1598
1599 auto* lir = new (alloc()) LTypeOfName(useRegister(input));
1600 define(lir, ins);
1601 }
1602
1603 void LIRGenerator::visitTypeOfIs(MTypeOfIs* ins) {
1604 MDefinition* input = ins->input();
1605
1606 MOZ_ASSERT(input->type() == MIRType::Object ||
1607 input->type() == MIRType::Value);
1608
1609 switch (ins->jstype()) {
1610 case JSTYPE_UNDEFINED:
1611 case JSTYPE_OBJECT:
1612 case JSTYPE_FUNCTION: {
1613 if (input->type() == MIRType::Object) {
1614 auto* lir = new (alloc()) LTypeOfIsNonPrimitiveO(useRegister(input));
1615 define(lir, ins);
1616 } else {
1617 auto* lir =
1618 new (alloc()) LTypeOfIsNonPrimitiveV(useBox(input), tempToUnbox());
1619 define(lir, ins);
1620 }
1621 return;
1622 }
1623
1624 case JSTYPE_STRING:
1625 case JSTYPE_NUMBER:
1626 case JSTYPE_BOOLEAN:
1627 case JSTYPE_SYMBOL:
1628 case JSTYPE_BIGINT: {
1629 MOZ_ASSERT(input->type() == MIRType::Value);
1630
1631 auto* lir = new (alloc()) LTypeOfIsPrimitive(useBoxAtStart(input));
1632 define(lir, ins);
1633 return;
1634 }
1635
1636 case JSTYPE_LIMIT:
1637 break;
1638 }
1639 MOZ_CRASH("Unhandled JSType");
1640 }
1641
1642 void LIRGenerator::visitToAsyncIter(MToAsyncIter* ins) {
1643 LToAsyncIter* lir = new (alloc()) LToAsyncIter(
1644 useRegisterAtStart(ins->iterator()), useBoxAtStart(ins->nextMethod()));
1645 defineReturn(lir, ins);
1646 assignSafepoint(lir, ins);
1647 }
1648
1649 void LIRGenerator::visitToPropertyKeyCache(MToPropertyKeyCache* ins) {
1650 MDefinition* input = ins->getOperand(0);
1651 MOZ_ASSERT(ins->type() == MIRType::Value);
1652
1653 auto* lir = new (alloc()) LToPropertyKeyCache(useBox(input));
1654 defineBox(lir, ins);
1655 assignSafepoint(lir, ins);
1656 }
1657
1658 void LIRGenerator::visitBitNot(MBitNot* ins) {
1659 MDefinition* input = ins->getOperand(0);
1660
1661 if (ins->type() == MIRType::Int32) {
1662 MOZ_ASSERT(input->type() == MIRType::Int32);
1663 lowerForALU(new (alloc()) LBitNotI(), ins, input);
1664 return;
1665 }
1666
1667 if (ins->type() == MIRType::Int64) {
1668 MOZ_ASSERT(input->type() == MIRType::Int64);
1669 lowerForALUInt64(new (alloc()) LBitNotI64(), ins, input);
1670 return;
1671 }
1672
1673 MOZ_CRASH("Unhandled integer specialization");
1674 }
1675
1676 static bool CanEmitBitAndAtUses(MInstruction* ins) {
1677 if (!ins->canEmitAtUses()) {
1678 return false;
1679 }
1680
1681 MIRType tyL = ins->getOperand(0)->type();
1682 MIRType tyR = ins->getOperand(1)->type();
1683 if (tyL != tyR || (tyL != MIRType::Int32 && tyL != MIRType::Int64)) {
1684 return false;
1685 }
1686
1687 MUseIterator iter(ins->usesBegin());
1688 if (iter == ins->usesEnd()) {
1689 return false;
1690 }
1691
1692 MNode* node = iter->consumer();
1693 if (!node->isDefinition() || !node->toDefinition()->isInstruction()) {
1694 return false;
1695 }
1696
1697 MInstruction* use = node->toDefinition()->toInstruction();
1698 if (!use->isTest() && !(use->isCompare() && CanEmitCompareAtUses(use))) {
1699 return false;
1700 }
1701
1702 iter++;
1703 return iter == ins->usesEnd();
1704 }
1705
1706 void LIRGenerator::visitBitAnd(MBitAnd* ins) {
1707 // Sniff out if the output of this bitand is used only for a branching.
1708 // If it is, then we will emit an LBitAndAndBranch instruction in place
1709 // of this bitand and any test that uses this bitand. Thus, we can
1710 // ignore this BitAnd.
1711 if (CanEmitBitAndAtUses(ins)) {
1712 emitAtUses(ins);
1713 } else {
1714 lowerBitOp(JSOp::BitAnd, ins);
1715 }
1716 }
1717
1718 void LIRGenerator::visitBitOr(MBitOr* ins) { lowerBitOp(JSOp::BitOr, ins); }
1719
1720 void LIRGenerator::visitBitXor(MBitXor* ins) { lowerBitOp(JSOp::BitXor, ins); }
1721
1722 void LIRGenerator::visitWasmBinaryBitwise(MWasmBinaryBitwise* ins) {
1723 switch (ins->subOpcode()) {
1724 case MWasmBinaryBitwise::SubOpcode::And:
1725 if (CanEmitBitAndAtUses(ins)) {
1726 emitAtUses(ins);
1727 } else {
1728 lowerBitOp(JSOp::BitAnd, ins);
1729 }
1730 break;
1731 case MWasmBinaryBitwise::SubOpcode::Or:
1732 lowerBitOp(JSOp::BitOr, ins);
1733 break;
1734 case MWasmBinaryBitwise::SubOpcode::Xor:
1735 lowerBitOp(JSOp::BitXor, ins);
1736 break;
1737 default:
1738 MOZ_CRASH();
1739 }
1740 }
1741
1742 void LIRGenerator::lowerShiftOp(JSOp op, MShiftInstruction* ins) {
1743 MDefinition* lhs = ins->getOperand(0);
1744 MDefinition* rhs = ins->getOperand(1);
1745
1746 if (op == JSOp::Ursh && ins->type() == MIRType::Double) {
1747 MOZ_ASSERT(lhs->type() == MIRType::Int32);
1748 MOZ_ASSERT(rhs->type() == MIRType::Int32);
1749 lowerUrshD(ins->toUrsh());
1750 return;
1751 }
1752
1753 MOZ_ASSERT(IsIntType(ins->type()));
1754
1755 if (ins->type() == MIRType::Int32) {
1756 MOZ_ASSERT(lhs->type() == MIRType::Int32);
1757 MOZ_ASSERT(rhs->type() == MIRType::Int32);
1758
1759 LShiftI* lir = new (alloc()) LShiftI(op);
1760 if (op == JSOp::Ursh) {
1761 if (ins->toUrsh()->fallible()) {
1762 assignSnapshot(lir, ins->bailoutKind());
1763 }
1764 }
1765 lowerForShift(lir, ins, lhs, rhs);
1766 return;
1767 }
1768
1769 if (ins->type() == MIRType::Int64) {
1770 MOZ_ASSERT(lhs->type() == MIRType::Int64);
1771 MOZ_ASSERT(rhs->type() == MIRType::Int64);
1772 lowerForShiftInt64(new (alloc()) LShiftI64(op), ins, lhs, rhs);
1773 return;
1774 }
1775
1776 MOZ_CRASH("Unhandled integer specialization");
1777 }
1778
1779 void LIRGenerator::visitLsh(MLsh* ins) { lowerShiftOp(JSOp::Lsh, ins); }
1780
1781 void LIRGenerator::visitRsh(MRsh* ins) { lowerShiftOp(JSOp::Rsh, ins); }
1782
1783 void LIRGenerator::visitUrsh(MUrsh* ins) { lowerShiftOp(JSOp::Ursh, ins); }
1784
1785 void LIRGenerator::visitSignExtendInt32(MSignExtendInt32* ins) {
1786 LInstructionHelper<1, 1, 0>* lir;
1787
1788 if (ins->mode() == MSignExtendInt32::Byte) {
1789 lir =
1790 new (alloc()) LSignExtendInt32(useByteOpRegisterAtStart(ins->input()));
1791 } else {
1792 lir = new (alloc()) LSignExtendInt32(useRegisterAtStart(ins->input()));
1793 }
1794
1795 define(lir, ins);
1796 }
1797
1798 void LIRGenerator::visitSignExtendIntPtr(MSignExtendIntPtr* ins) {
1799 LInstructionHelper<1, 1, 0>* lir;
1800
1801 if (ins->mode() == MSignExtendIntPtr::Byte) {
1802 lir =
1803 new (alloc()) LSignExtendIntPtr(useByteOpRegisterAtStart(ins->input()));
1804 } else {
1805 lir = new (alloc()) LSignExtendIntPtr(useRegisterAtStart(ins->input()));
1806 }
1807
1808 define(lir, ins);
1809 }
1810
1811 void LIRGenerator::visitRotate(MRotate* ins) {
1812 MDefinition* input = ins->input();
1813 MDefinition* count = ins->count();
1814
1815 if (ins->type() == MIRType::Int32) {
1816 auto* lir = new (alloc()) LRotate();
1817 lowerForShift(lir, ins, input, count);
1818 } else if (ins->type() == MIRType::Int64) {
1819 auto* lir = new (alloc()) LRotateI64();
1820 lowerForShiftInt64(lir, ins, input, count);
1821 } else {
1822 MOZ_CRASH("unexpected type in visitRotate");
1823 }
1824 }
1825
1826 void LIRGenerator::visitFloor(MFloor* ins) {
1827 MIRType type = ins->input()->type();
1828 MOZ_ASSERT(IsFloatingPointType(type));
1829
1830 LInstructionHelper<1, 1, 0>* lir;
1831 if (type == MIRType::Double) {
1832 lir = new (alloc()) LFloor(useRegister(ins->input()));
1833 } else {
1834 lir = new (alloc()) LFloorF(useRegister(ins->input()));
1835 }
1836
1837 assignSnapshot(lir, ins->bailoutKind());
1838 define(lir, ins);
1839 }
1840
1841 void LIRGenerator::visitCeil(MCeil* ins) {
1842 MIRType type = ins->input()->type();
1843 MOZ_ASSERT(IsFloatingPointType(type));
1844
1845 LInstructionHelper<1, 1, 0>* lir;
1846 if (type == MIRType::Double) {
1847 lir = new (alloc()) LCeil(useRegister(ins->input()));
1848 } else {
1849 lir = new (alloc()) LCeilF(useRegister(ins->input()));
1850 }
1851
1852 assignSnapshot(lir, ins->bailoutKind());
1853 define(lir, ins);
1854 }
1855
1856 void LIRGenerator::visitRound(MRound* ins) {
1857 MIRType type = ins->input()->type();
1858 MOZ_ASSERT(IsFloatingPointType(type));
1859
1860 LInstructionHelper<1, 1, 1>* lir;
1861 if (type == MIRType::Double) {
1862 lir = new (alloc()) LRound(useRegister(ins->input()), tempDouble());
1863 } else {
1864 lir = new (alloc()) LRoundF(useRegister(ins->input()), tempFloat32());
1865 }
1866
1867 assignSnapshot(lir, ins->bailoutKind());
1868 define(lir, ins);
1869 }
1870
1871 void LIRGenerator::visitTrunc(MTrunc* ins) {
1872 MIRType type = ins->input()->type();
1873 MOZ_ASSERT(IsFloatingPointType(type));
1874
1875 LInstructionHelper<1, 1, 0>* lir;
1876 if (type == MIRType::Double) {
1877 lir = new (alloc()) LTrunc(useRegister(ins->input()));
1878 } else {
1879 lir = new (alloc()) LTruncF(useRegister(ins->input()));
1880 }
1881
1882 assignSnapshot(lir, ins->bailoutKind());
1883 define(lir, ins);
1884 }
1885
1886 void LIRGenerator::visitNearbyInt(MNearbyInt* ins) {
1887 MIRType inputType = ins->input()->type();
1888 MOZ_ASSERT(IsFloatingPointType(inputType));
1889 MOZ_ASSERT(ins->type() == inputType);
1890
1891 LInstructionHelper<1, 1, 0>* lir;
1892 if (inputType == MIRType::Double) {
1893 lir = new (alloc()) LNearbyInt(useRegisterAtStart(ins->input()));
1894 } else {
1895 lir = new (alloc()) LNearbyIntF(useRegisterAtStart(ins->input()));
1896 }
1897
1898 define(lir, ins);
1899 }
1900
1901 void LIRGenerator::visitMinMax(MMinMax* ins) {
1902 MDefinition* first = ins->getOperand(0);
1903 MDefinition* second = ins->getOperand(1);
1904
1905 ReorderCommutative(&first, &second, ins);
1906
1907 LInstructionHelper<1, 2, 0>* lir;
1908 switch (ins->type()) {
1909 case MIRType::Int32:
1910 lir = new (alloc())
1911 LMinMaxI(useRegisterAtStart(first), useRegisterOrConstant(second));
1912 break;
1913 case MIRType::Float32:
1914 lir = new (alloc())
1915 LMinMaxF(useRegisterAtStart(first), useRegister(second));
1916 break;
1917 case MIRType::Double:
1918 lir = new (alloc())
1919 LMinMaxD(useRegisterAtStart(first), useRegister(second));
1920 break;
1921 default:
1922 MOZ_CRASH();
1923 }
1924
1925 // Input reuse is OK (for now) even on ARM64: floating min/max are fairly
1926 // expensive due to SNaN -> QNaN conversion, and int min/max is for asm.js.
1927 defineReuseInput(lir, ins, 0);
1928 }
1929
1930 void LIRGenerator::visitMinMaxArray(MMinMaxArray* ins) {
1931 LInstructionHelper<1, 1, 3>* lir;
1932 if (ins->type() == MIRType::Int32) {
1933 lir = new (alloc())
1934 LMinMaxArrayI(useRegisterAtStart(ins->array()), temp(), temp(), temp());
1935 } else {
1936 MOZ_ASSERT(ins->type() == MIRType::Double);
1937 lir = new (alloc()) LMinMaxArrayD(useRegisterAtStart(ins->array()),
1938 tempDouble(), temp(), temp());
1939 }
1940 assignSnapshot(lir, ins->bailoutKind());
1941 define(lir, ins);
1942 }
1943
1944 LInstructionHelper<1, 1, 0>* LIRGenerator::allocateAbs(MAbs* ins,
1945 LAllocation input) {
1946 MDefinition* num = ins->input();
1947 MOZ_ASSERT(IsNumberType(num->type()));
1948
1949 LInstructionHelper<1, 1, 0>* lir;
1950 switch (num->type()) {
1951 case MIRType::Int32:
1952 lir = new (alloc()) LAbsI(input);
1953 // needed to handle abs(INT32_MIN)
1954 if (ins->fallible()) {
1955 assignSnapshot(lir, ins->bailoutKind());
1956 }
1957 break;
1958 case MIRType::Float32:
1959 lir = new (alloc()) LAbsF(input);
1960 break;
1961 case MIRType::Double:
1962 lir = new (alloc()) LAbsD(input);
1963 break;
1964 default:
1965 MOZ_CRASH();
1966 }
1967 return lir;
1968 }
1969
1970 void LIRGenerator::visitClz(MClz* ins) {
1971 MDefinition* num = ins->num();
1972
1973 MOZ_ASSERT(IsIntType(ins->type()));
1974
1975 if (ins->type() == MIRType::Int32) {
1976 LClzI* lir = new (alloc()) LClzI(useRegisterAtStart(num));
1977 define(lir, ins);
1978 return;
1979 }
1980
1981 auto* lir = new (alloc()) LClzI64(useInt64RegisterAtStart(num));
1982 defineInt64(lir, ins);
1983 }
1984
1985 void LIRGenerator::visitCtz(MCtz* ins) {
1986 MDefinition* num = ins->num();
1987
1988 MOZ_ASSERT(IsIntType(ins->type()));
1989
1990 if (ins->type() == MIRType::Int32) {
1991 LCtzI* lir = new (alloc()) LCtzI(useRegisterAtStart(num));
1992 define(lir, ins);
1993 return;
1994 }
1995
1996 auto* lir = new (alloc()) LCtzI64(useInt64RegisterAtStart(num));
1997 defineInt64(lir, ins);
1998 }
1999
2000 void LIRGenerator::visitPopcnt(MPopcnt* ins) {
2001 MDefinition* num = ins->num();
2002
2003 MOZ_ASSERT(IsIntType(ins->type()));
2004
2005 if (ins->type() == MIRType::Int32) {
2006 LPopcntI* lir = new (alloc()) LPopcntI(useRegisterAtStart(num), temp());
2007 define(lir, ins);
2008 return;
2009 }
2010
2011 auto* lir = new (alloc()) LPopcntI64(useInt64RegisterAtStart(num), temp());
2012 defineInt64(lir, ins);
2013 }
2014
2015 void LIRGenerator::visitSqrt(MSqrt* ins) {
2016 MDefinition* num = ins->input();
2017 MOZ_ASSERT(IsFloatingPointType(num->type()));
2018
2019 LInstructionHelper<1, 1, 0>* lir;
2020 if (num->type() == MIRType::Double) {
2021 lir = new (alloc()) LSqrtD(useRegisterAtStart(num));
2022 } else {
2023 lir = new (alloc()) LSqrtF(useRegisterAtStart(num));
2024 }
2025 define(lir, ins);
2026 }
2027
2028 void LIRGenerator::visitAtan2(MAtan2* ins) {
2029 MDefinition* y = ins->y();
2030 MOZ_ASSERT(y->type() == MIRType::Double);
2031
2032 MDefinition* x = ins->x();
2033 MOZ_ASSERT(x->type() == MIRType::Double);
2034
2035 LAtan2D* lir =
2036 new (alloc()) LAtan2D(useRegisterAtStart(y), useRegisterAtStart(x));
2037 defineReturn(lir, ins);
2038 }
2039
2040 void LIRGenerator::visitHypot(MHypot* ins) {
2041 LHypot* lir = nullptr;
2042 uint32_t length = ins->numOperands();
2043 for (uint32_t i = 0; i < length; ++i) {
2044 MOZ_ASSERT(ins->getOperand(i)->type() == MIRType::Double);
2045 }
2046
2047 switch (length) {
2048 case 2:
2049 lir = new (alloc()) LHypot(useRegisterAtStart(ins->getOperand(0)),
2050 useRegisterAtStart(ins->getOperand(1)));
2051 break;
2052 case 3:
2053 lir = new (alloc()) LHypot(useRegisterAtStart(ins->getOperand(0)),
2054 useRegisterAtStart(ins->getOperand(1)),
2055 useRegisterAtStart(ins->getOperand(2)));
2056 break;
2057 case 4:
2058 lir = new (alloc()) LHypot(useRegisterAtStart(ins->getOperand(0)),
2059 useRegisterAtStart(ins->getOperand(1)),
2060 useRegisterAtStart(ins->getOperand(2)),
2061 useRegisterAtStart(ins->getOperand(3)));
2062 break;
2063 default:
2064 MOZ_CRASH("Unexpected number of arguments to LHypot.");
2065 }
2066
2067 defineReturn(lir, ins);
2068 }
2069
2070 void LIRGenerator::visitPow(MPow* ins) {
2071 MDefinition* input = ins->input();
2072 MDefinition* power = ins->power();
2073
2074 if (ins->type() == MIRType::Int32) {
2075 MOZ_ASSERT(input->type() == MIRType::Int32);
2076 MOZ_ASSERT(power->type() == MIRType::Int32);
2077
2078 if (input->isConstant()) {
2079 // Restrict this optimization to |base <= 256| to avoid generating too
2080 // many consecutive shift instructions.
2081 int32_t base = input->toConstant()->toInt32();
2082 if (2 <= base && base <= 256 && mozilla::IsPowerOfTwo(uint32_t(base))) {
2083 lowerPowOfTwoI(ins);
2084 return;
2085 }
2086 }
2087
2088 auto* lir = new (alloc())
2089 LPowII(useRegister(input), useRegister(power), temp(), temp());
2090 assignSnapshot(lir, ins->bailoutKind());
2091 define(lir, ins);
2092 return;
2093 }
2094
2095 MOZ_ASSERT(ins->type() == MIRType::Double);
2096 MOZ_ASSERT(input->type() == MIRType::Double);
2097 MOZ_ASSERT(power->type() == MIRType::Int32 ||
2098 power->type() == MIRType::Double);
2099
2100 LInstruction* lir;
2101 if (power->type() == MIRType::Int32) {
2102 lir = new (alloc())
2103 LPowI(useRegisterAtStart(input), useRegisterAtStart(power));
2104 } else {
2105 lir = new (alloc())
2106 LPowD(useRegisterAtStart(input), useRegisterAtStart(power));
2107 }
2108 defineReturn(lir, ins);
2109 }
2110
2111 void LIRGenerator::visitSign(MSign* ins) {
2112 MOZ_ASSERT(ins->type() == MIRType::Int32 || ins->type() == MIRType::Double);
2113 MOZ_ASSERT(ins->input()->type() == MIRType::Int32 ||
2114 ins->input()->type() == MIRType::Double);
2115
2116 if (ins->type() == ins->input()->type()) {
2117 if (ins->type() == MIRType::Int32) {
2118 define(new (alloc()) LSignI(useRegister(ins->input())), ins);
2119 } else {
2120 define(new (alloc()) LSignD(useRegister(ins->input())), ins);
2121 }
2122 } else {
2123 if (ins->type() == MIRType::Int32) {
2124 auto* lir =
2125 new (alloc()) LSignDI(useRegister(ins->input()), tempDouble());
2126 assignSnapshot(lir, ins->bailoutKind());
2127 define(lir, ins);
2128 } else {
2129 define(new (alloc()) LSignID(useRegister(ins->input()), temp()), ins);
2130 }
2131 }
2132 }
2133
2134 void LIRGenerator::visitMathFunction(MMathFunction* ins) {
2135 MOZ_ASSERT(IsFloatingPointType(ins->type()));
2136 MOZ_ASSERT(ins->type() == ins->input()->type());
2137
2138 LInstruction* lir;
2139 if (ins->type() == MIRType::Double) {
2140 lir = new (alloc()) LMathFunctionD(useRegisterAtStart(ins->input()));
2141 } else {
2142 lir = new (alloc()) LMathFunctionF(useRegisterAtStart(ins->input()));
2143 }
2144 defineReturn(lir, ins);
2145 }
2146
2147 void LIRGenerator::visitRandom(MRandom* ins) {
2148 auto* lir = new (alloc()) LRandom(temp(), tempInt64(), tempInt64());
2149 define(lir, ins);
2150 }
2151
2152 // Try to mark an add or sub instruction as able to recover its input when
2153 // bailing out.
2154 template <typename S, typename T>
2155 static void MaybeSetRecoversInput(S* mir, T* lir) {
2156 MOZ_ASSERT(lir->mirRaw() == mir);
2157 if (!mir->fallible() || !lir->snapshot()) {
2158 return;
2159 }
2160
2161 if (lir->output()->policy() != LDefinition::MUST_REUSE_INPUT) {
2162 return;
2163 }
2164
2165 // The original operands to an add or sub can't be recovered if they both
2166 // use the same register.
2167 if (lir->lhs()->isUse() && lir->rhs()->isUse() &&
2168 lir->lhs()->toUse()->virtualRegister() ==
2169 lir->rhs()->toUse()->virtualRegister()) {
2170 return;
2171 }
2172
2173 // Add instructions that are on two different values can recover
2174 // the input they clobbered via MUST_REUSE_INPUT. Thus, a copy
2175 // of that input does not need to be kept alive in the snapshot
2176 // for the instruction.
2177
2178 lir->setRecoversInput();
2179
2180 const LUse* input = lir->getOperand(lir->output()->getReusedInput())->toUse();
2181 lir->snapshot()->rewriteRecoveredInput(*input);
2182 }
2183
2184 void LIRGenerator::visitAdd(MAdd* ins) {
2185 MDefinition* lhs = ins->getOperand(0);
2186 MDefinition* rhs = ins->getOperand(1);
2187
2188 MOZ_ASSERT(lhs->type() == rhs->type());
2189 MOZ_ASSERT(IsNumberType(ins->type()));
2190
2191 if (ins->type() == MIRType::Int32) {
2192 MOZ_ASSERT(lhs->type() == MIRType::Int32);
2193 ReorderCommutative(&lhs, &rhs, ins);
2194 LAddI* lir = new (alloc()) LAddI;
2195
2196 if (ins->fallible()) {
2197 assignSnapshot(lir, ins->bailoutKind());
2198 }
2199
2200 lowerForALU(lir, ins, lhs, rhs);
2201 MaybeSetRecoversInput(ins, lir);
2202 return;
2203 }
2204
2205 if (ins->type() == MIRType::Int64) {
2206 MOZ_ASSERT(lhs->type() == MIRType::Int64);
2207 ReorderCommutative(&lhs, &rhs, ins);
2208 LAddI64* lir = new (alloc()) LAddI64;
2209 lowerForALUInt64(lir, ins, lhs, rhs);
2210 return;
2211 }
2212
2213 if (ins->type() == MIRType::Double) {
2214 MOZ_ASSERT(lhs->type() == MIRType::Double);
2215 ReorderCommutative(&lhs, &rhs, ins);
2216 lowerForFPU(new (alloc()) LMathD(JSOp::Add), ins, lhs, rhs);
2217 return;
2218 }
2219
2220 if (ins->type() == MIRType::Float32) {
2221 MOZ_ASSERT(lhs->type() == MIRType::Float32);
2222 ReorderCommutative(&lhs, &rhs, ins);
2223 lowerForFPU(new (alloc()) LMathF(JSOp::Add), ins, lhs, rhs);
2224 return;
2225 }
2226
2227 MOZ_CRASH("Unhandled number specialization");
2228 }
2229
2230 void LIRGenerator::visitSub(MSub* ins) {
2231 MDefinition* lhs = ins->lhs();
2232 MDefinition* rhs = ins->rhs();
2233
2234 MOZ_ASSERT(lhs->type() == rhs->type());
2235 MOZ_ASSERT(IsNumberType(ins->type()));
2236
2237 if (ins->type() == MIRType::Int32) {
2238 MOZ_ASSERT(lhs->type() == MIRType::Int32);
2239
2240 LSubI* lir = new (alloc()) LSubI;
2241 if (ins->fallible()) {
2242 assignSnapshot(lir, ins->bailoutKind());
2243 }
2244
2245 // If our LHS is a constant 0 and we don't have to worry about results that
2246 // can't be represented as an int32, we can optimize to an LNegI.
2247 if (!ins->fallible() && lhs->isConstant() &&
2248 lhs->toConstant()->toInt32() == 0) {
2249 lowerNegI(ins, rhs);
2250 return;
2251 }
2252
2253 lowerForALU(lir, ins, lhs, rhs);
2254 MaybeSetRecoversInput(ins, lir);
2255 return;
2256 }
2257
2258 if (ins->type() == MIRType::Int64) {
2259 MOZ_ASSERT(lhs->type() == MIRType::Int64);
2260
2261 // If our LHS is a constant 0, we can optimize to an LNegI64.
2262 if (lhs->isConstant() && lhs->toConstant()->toInt64() == 0) {
2263 lowerNegI64(ins, rhs);
2264 return;
2265 }
2266
2267 LSubI64* lir = new (alloc()) LSubI64;
2268 lowerForALUInt64(lir, ins, lhs, rhs);
2269 return;
2270 }
2271
2272 if (ins->type() == MIRType::Double) {
2273 MOZ_ASSERT(lhs->type() == MIRType::Double);
2274 lowerForFPU(new (alloc()) LMathD(JSOp::Sub), ins, lhs, rhs);
2275 return;
2276 }
2277
2278 if (ins->type() == MIRType::Float32) {
2279 MOZ_ASSERT(lhs->type() == MIRType::Float32);
2280 lowerForFPU(new (alloc()) LMathF(JSOp::Sub), ins, lhs, rhs);
2281 return;
2282 }
2283
2284 MOZ_CRASH("Unhandled number specialization");
2285 }
2286
2287 void LIRGenerator::visitMul(MMul* ins) {
2288 MDefinition* lhs = ins->lhs();
2289 MDefinition* rhs = ins->rhs();
2290 MOZ_ASSERT(lhs->type() == rhs->type());
2291 MOZ_ASSERT(IsNumberType(ins->type()));
2292
2293 if (ins->type() == MIRType::Int32) {
2294 MOZ_ASSERT(lhs->type() == MIRType::Int32);
2295 ReorderCommutative(&lhs, &rhs, ins);
2296
2297 // If our RHS is a constant -1 and we don't have to worry about results that
2298 // can't be represented as an int32, we can optimize to an LNegI.
2299 if (!ins->fallible() && rhs->isConstant() &&
2300 rhs->toConstant()->toInt32() == -1) {
2301 lowerNegI(ins, lhs);
2302 return;
2303 }
2304
2305 lowerMulI(ins, lhs, rhs);
2306 return;
2307 }
2308
2309 if (ins->type() == MIRType::Int64) {
2310 MOZ_ASSERT(lhs->type() == MIRType::Int64);
2311 ReorderCommutative(&lhs, &rhs, ins);
2312
2313 // If our RHS is a constant -1, we can optimize to an LNegI64.
2314 if (rhs->isConstant() && rhs->toConstant()->toInt64() == -1) {
2315 lowerNegI64(ins, lhs);
2316 return;
2317 }
2318
2319 LMulI64* lir = new (alloc()) LMulI64;
2320 lowerForMulInt64(lir, ins, lhs, rhs);
2321 return;
2322 }
2323
2324 if (ins->type() == MIRType::Double) {
2325 MOZ_ASSERT(lhs->type() == MIRType::Double);
2326 ReorderCommutative(&lhs, &rhs, ins);
2327
2328 // If our RHS is a constant -1.0, we can optimize to an LNegD.
2329 if (!ins->mustPreserveNaN() && rhs->isConstant() &&
2330 rhs->toConstant()->toDouble() == -1.0) {
2331 defineReuseInput(new (alloc()) LNegD(useRegisterAtStart(lhs)), ins, 0);
2332 return;
2333 }
2334
2335 lowerForFPU(new (alloc()) LMathD(JSOp::Mul), ins, lhs, rhs);
2336 return;
2337 }
2338
2339 if (ins->type() == MIRType::Float32) {
2340 MOZ_ASSERT(lhs->type() == MIRType::Float32);
2341 ReorderCommutative(&lhs, &rhs, ins);
2342
2343 // We apply the same optimizations as for doubles
2344 if (!ins->mustPreserveNaN() && rhs->isConstant() &&
2345 rhs->toConstant()->toFloat32() == -1.0f) {
2346 defineReuseInput(new (alloc()) LNegF(useRegisterAtStart(lhs)), ins, 0);
2347 return;
2348 }
2349
2350 lowerForFPU(new (alloc()) LMathF(JSOp::Mul), ins, lhs, rhs);
2351 return;
2352 }
2353
2354 MOZ_CRASH("Unhandled number specialization");
2355 }
2356
2357 void LIRGenerator::visitDiv(MDiv* ins) {
2358 MDefinition* lhs = ins->lhs();
2359 MDefinition* rhs = ins->rhs();
2360 MOZ_ASSERT(lhs->type() == rhs->type());
2361 MOZ_ASSERT(IsNumberType(ins->type()));
2362
2363 if (ins->type() == MIRType::Int32) {
2364 MOZ_ASSERT(lhs->type() == MIRType::Int32);
2365 lowerDivI(ins);
2366 return;
2367 }
2368
2369 if (ins->type() == MIRType::Int64) {
2370 MOZ_ASSERT(lhs->type() == MIRType::Int64);
2371 lowerDivI64(ins);
2372 return;
2373 }
2374
2375 if (ins->type() == MIRType::Double) {
2376 MOZ_ASSERT(lhs->type() == MIRType::Double);
2377 lowerForFPU(new (alloc()) LMathD(JSOp::Div), ins, lhs, rhs);
2378 return;
2379 }
2380
2381 if (ins->type() == MIRType::Float32) {
2382 MOZ_ASSERT(lhs->type() == MIRType::Float32);
2383 lowerForFPU(new (alloc()) LMathF(JSOp::Div), ins, lhs, rhs);
2384 return;
2385 }
2386
2387 MOZ_CRASH("Unhandled number specialization");
2388 }
2389
2390 void LIRGenerator::visitWasmBuiltinDivI64(MWasmBuiltinDivI64* div) {
2391 lowerWasmBuiltinDivI64(div);
2392 }
2393
2394 void LIRGenerator::visitWasmBuiltinModI64(MWasmBuiltinModI64* mod) {
2395 lowerWasmBuiltinModI64(mod);
2396 }
2397
2398 void LIRGenerator::visitBuiltinInt64ToFloatingPoint(
2399 MBuiltinInt64ToFloatingPoint* ins) {
2400 lowerBuiltinInt64ToFloatingPoint(ins);
2401 }
2402
2403 void LIRGenerator::visitWasmBuiltinTruncateToInt64(
2404 MWasmBuiltinTruncateToInt64* ins) {
2405 lowerWasmBuiltinTruncateToInt64(ins);
2406 }
2407
2408 void LIRGenerator::visitWasmBuiltinModD(MWasmBuiltinModD* ins) {
2409 MOZ_ASSERT(gen->compilingWasm());
2410 LWasmBuiltinModD* lir = new (alloc()) LWasmBuiltinModD(
2411 useRegisterAtStart(ins->lhs()), useRegisterAtStart(ins->rhs()),
2412 useFixedAtStart(ins->instance(), InstanceReg));
2413 defineReturn(lir, ins);
2414 }
2415
2416 void LIRGenerator::visitMod(MMod* ins) {
2417 MOZ_ASSERT(ins->lhs()->type() == ins->rhs()->type());
2418 MOZ_ASSERT(IsNumberType(ins->type()));
2419
2420 if (ins->type() == MIRType::Int32) {
2421 MOZ_ASSERT(ins->type() == MIRType::Int32);
2422 MOZ_ASSERT(ins->lhs()->type() == MIRType::Int32);
2423 lowerModI(ins);
2424 return;
2425 }
2426
2427 if (ins->type() == MIRType::Int64) {
2428 MOZ_ASSERT(ins->type() == MIRType::Int64);
2429 MOZ_ASSERT(ins->lhs()->type() == MIRType::Int64);
2430 lowerModI64(ins);
2431 return;
2432 }
2433
2434 if (ins->type() == MIRType::Double) {
2435 MOZ_ASSERT(ins->lhs()->type() == MIRType::Double);
2436 MOZ_ASSERT(ins->rhs()->type() == MIRType::Double);
2437
2438 MOZ_ASSERT(!gen->compilingWasm());
2439
2440 if (Assembler::HasRoundInstruction(RoundingMode::TowardsZero)) {
2441 if (ins->rhs()->isConstant()) {
2442 double d = ins->rhs()->toConstant()->toDouble();
2443 int32_t div;
2444 if (mozilla::NumberIsInt32(d, &div) && div > 0 &&
2445 mozilla::IsPowerOfTwo(uint32_t(div))) {
2446 auto* lir = new (alloc()) LModPowTwoD(useRegister(ins->lhs()), div);
2447 define(lir, ins);
2448 return;
2449 }
2450 }
2451 }
2452
2453 LModD* lir = new (alloc())
2454 LModD(useRegisterAtStart(ins->lhs()), useRegisterAtStart(ins->rhs()));
2455 defineReturn(lir, ins);
2456 return;
2457 }
2458
2459 MOZ_CRASH("Unhandled number specialization");
2460 }
2461
2462 void LIRGenerator::visitBigIntAdd(MBigIntAdd* ins) {
2463 auto* lir = new (alloc()) LBigIntAdd(useRegisterAtStart(ins->lhs()),
2464 useRegisterAtStart(ins->rhs()));
2465 defineReturn(lir, ins);
2466 assignSafepoint(lir, ins);
2467 }
2468
2469 void LIRGenerator::visitBigIntSub(MBigIntSub* ins) {
2470 auto* lir = new (alloc()) LBigIntSub(useRegisterAtStart(ins->lhs()),
2471 useRegisterAtStart(ins->rhs()));
2472 defineReturn(lir, ins);
2473 assignSafepoint(lir, ins);
2474 }
2475
2476 void LIRGenerator::visitBigIntMul(MBigIntMul* ins) {
2477 auto* lir = new (alloc()) LBigIntMul(useRegisterAtStart(ins->lhs()),
2478 useRegisterAtStart(ins->rhs()));
2479 defineReturn(lir, ins);
2480 assignSafepoint(lir, ins);
2481 }
2482
2483 void LIRGenerator::visitBigIntDiv(MBigIntDiv* ins) {
2484 auto* lir = new (alloc()) LBigIntDiv(useRegisterAtStart(ins->lhs()),
2485 useRegisterAtStart(ins->rhs()));
2486 defineReturn(lir, ins);
2487 assignSafepoint(lir, ins);
2488 }
2489
2490 void LIRGenerator::visitBigIntMod(MBigIntMod* ins) {
2491 auto* lir = new (alloc()) LBigIntMod(useRegisterAtStart(ins->lhs()),
2492 useRegisterAtStart(ins->rhs()));
2493 defineReturn(lir, ins);
2494 assignSafepoint(lir, ins);
2495 }
2496
2497 void LIRGenerator::visitBigIntPow(MBigIntPow* ins) {
2498 auto* lir = new (alloc()) LBigIntPow(useRegisterAtStart(ins->lhs()),
2499 useRegisterAtStart(ins->rhs()));
2500 defineReturn(lir, ins);
2501 assignSafepoint(lir, ins);
2502 }
2503
2504 void LIRGenerator::visitBigIntBitAnd(MBigIntBitAnd* ins) {
2505 auto* lir = new (alloc()) LBigIntBitAnd(useRegisterAtStart(ins->lhs()),
2506 useRegisterAtStart(ins->rhs()));
2507 defineReturn(lir, ins);
2508 assignSafepoint(lir, ins);
2509 }
2510
2511 void LIRGenerator::visitBigIntBitOr(MBigIntBitOr* ins) {
2512 auto* lir = new (alloc()) LBigIntBitOr(useRegisterAtStart(ins->lhs()),
2513 useRegisterAtStart(ins->rhs()));
2514 defineReturn(lir, ins);
2515 assignSafepoint(lir, ins);
2516 }
2517
2518 void LIRGenerator::visitBigIntBitXor(MBigIntBitXor* ins) {
2519 auto* lir = new (alloc()) LBigIntBitXor(useRegisterAtStart(ins->lhs()),
2520 useRegisterAtStart(ins->rhs()));
2521 defineReturn(lir, ins);
2522 assignSafepoint(lir, ins);
2523 }
2524
2525 void LIRGenerator::visitBigIntLsh(MBigIntLsh* ins) {
2526 auto* lir = new (alloc()) LBigIntLsh(useRegisterAtStart(ins->lhs()),
2527 useRegisterAtStart(ins->rhs()));
2528 defineReturn(lir, ins);
2529 assignSafepoint(lir, ins);
2530 }
2531
2532 void LIRGenerator::visitBigIntRsh(MBigIntRsh* ins) {
2533 auto* lir = new (alloc()) LBigIntRsh(useRegisterAtStart(ins->lhs()),
2534 useRegisterAtStart(ins->rhs()));
2535 defineReturn(lir, ins);
2536 assignSafepoint(lir, ins);
2537 }
2538
2539 void LIRGenerator::visitBigIntIncrement(MBigIntIncrement* ins) {
2540 auto* lir = new (alloc()) LBigIntIncrement(useRegisterAtStart(ins->input()));
2541 defineReturn(lir, ins);
2542 assignSafepoint(lir, ins);
2543 }
2544
2545 void LIRGenerator::visitBigIntDecrement(MBigIntDecrement* ins) {
2546 auto* lir = new (alloc()) LBigIntDecrement(useRegisterAtStart(ins->input()));
2547 defineReturn(lir, ins);
2548 assignSafepoint(lir, ins);
2549 }
2550
2551 void LIRGenerator::visitBigIntNegate(MBigIntNegate* ins) {
2552 auto* lir = new (alloc()) LBigIntNegate(useRegister(ins->input()), temp());
2553 define(lir, ins);
2554 assignSafepoint(lir, ins);
2555 }
2556
2557 void LIRGenerator::visitBigIntBitNot(MBigIntBitNot* ins) {
2558 auto* lir = new (alloc()) LBigIntBitNot(useRegisterAtStart(ins->input()));
2559 defineReturn(lir, ins);
2560 assignSafepoint(lir, ins);
2561 }
2562
2563 void LIRGenerator::visitBigIntToIntPtr(MBigIntToIntPtr* ins) {
2564 MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
2565
2566 auto* lir = new (alloc()) LBigIntToIntPtr(useRegister(ins->input()));
2567 assignSnapshot(lir, ins->bailoutKind());
2568 define(lir, ins);
2569 }
2570
2571 void LIRGenerator::visitIntPtrToBigInt(MIntPtrToBigInt* ins) {
2572 MOZ_ASSERT(ins->input()->type() == MIRType::IntPtr);
2573
2574 auto* lir = new (alloc()) LIntPtrToBigInt(useRegister(ins->input()), temp());
2575 define(lir, ins);
2576 assignSafepoint(lir, ins);
2577 }
2578
2579 void LIRGenerator::visitBigIntPtrAdd(MBigIntPtrAdd* ins) {
2580 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2581 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2582
2583 MDefinition* lhs = ins->lhs();
2584 MDefinition* rhs = ins->rhs();
2585 ReorderCommutative(&lhs, &rhs, ins);
2586
2587 auto* lir =
2588 new (alloc()) LBigIntPtrAdd(useRegister(lhs), useRegisterOrConstant(rhs));
2589 assignSnapshot(lir, ins->bailoutKind());
2590 define(lir, ins);
2591 }
2592
2593 void LIRGenerator::visitBigIntPtrSub(MBigIntPtrSub* ins) {
2594 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2595 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2596
2597 auto* lir = new (alloc())
2598 LBigIntPtrSub(useRegister(ins->lhs()), useRegister(ins->rhs()));
2599 assignSnapshot(lir, ins->bailoutKind());
2600 define(lir, ins);
2601 }
2602
2603 void LIRGenerator::visitBigIntPtrMul(MBigIntPtrMul* ins) {
2604 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2605 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2606
2607 MDefinition* lhs = ins->lhs();
2608 MDefinition* rhs = ins->rhs();
2609 ReorderCommutative(&lhs, &rhs, ins);
2610
2611 auto* lir =
2612 new (alloc()) LBigIntPtrMul(useRegister(lhs), useRegisterOrConstant(rhs));
2613 assignSnapshot(lir, ins->bailoutKind());
2614 define(lir, ins);
2615 }
2616
2617 void LIRGenerator::visitBigIntPtrDiv(MBigIntPtrDiv* ins) {
2618 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2619 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2620
2621 if (ins->rhs()->isConstant()) {
2622 intptr_t rhs = ins->rhs()->toConstant()->toIntPtr();
2623 if (mozilla::IsPowerOfTwo(mozilla::Abs(rhs))) {
2624 int32_t shift = mozilla::FloorLog2(mozilla::Abs(rhs));
2625 auto* lir = new (alloc())
2626 LBigIntPtrDivPowTwo(useRegister(ins->lhs()), shift, rhs < 0);
2627 if (shift == 0 && rhs < 0) {
2628 assignSnapshot(lir, ins->bailoutKind());
2629 }
2630 define(lir, ins);
2631 return;
2632 }
2633 }
2634
2635 lowerBigIntPtrDiv(ins);
2636 }
2637
2638 void LIRGenerator::visitBigIntPtrMod(MBigIntPtrMod* ins) {
2639 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2640 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2641
2642 if (ins->rhs()->isConstant()) {
2643 intptr_t rhs = ins->rhs()->toConstant()->toIntPtr();
2644 if (mozilla::IsPowerOfTwo(mozilla::Abs(rhs))) {
2645 int32_t shift = mozilla::FloorLog2(mozilla::Abs(rhs));
2646 auto* lir = new (alloc())
2647 LBigIntPtrModPowTwo(useRegister(ins->lhs()), temp(), shift);
2648 define(lir, ins);
2649 return;
2650 }
2651 }
2652
2653 lowerBigIntPtrMod(ins);
2654 }
2655
2656 void LIRGenerator::visitBigIntPtrPow(MBigIntPtrPow* ins) {
2657 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2658 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2659
2660 auto* lir = new (alloc()) LBigIntPtrPow(
2661 useRegister(ins->lhs()), useRegister(ins->rhs()), temp(), temp());
2662 assignSnapshot(lir, ins->bailoutKind());
2663 define(lir, ins);
2664 }
2665
2666 void LIRGenerator::visitBigIntPtrBitAnd(MBigIntPtrBitAnd* ins) {
2667 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2668 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2669
2670 MDefinition* lhs = ins->lhs();
2671 MDefinition* rhs = ins->rhs();
2672 ReorderCommutative(&lhs, &rhs, ins);
2673
2674 auto* lir = new (alloc())
2675 LBigIntPtrBitAnd(useRegister(lhs), useRegisterOrConstant(rhs));
2676 define(lir, ins);
2677 }
2678
2679 void LIRGenerator::visitBigIntPtrBitOr(MBigIntPtrBitOr* ins) {
2680 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2681 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2682
2683 MDefinition* lhs = ins->lhs();
2684 MDefinition* rhs = ins->rhs();
2685 ReorderCommutative(&lhs, &rhs, ins);
2686
2687 auto* lir = new (alloc())
2688 LBigIntPtrBitOr(useRegister(lhs), useRegisterOrConstant(rhs));
2689 define(lir, ins);
2690 }
2691
2692 void LIRGenerator::visitBigIntPtrBitXor(MBigIntPtrBitXor* ins) {
2693 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2694 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2695
2696 MDefinition* lhs = ins->lhs();
2697 MDefinition* rhs = ins->rhs();
2698 ReorderCommutative(&lhs, &rhs, ins);
2699
2700 auto* lir = new (alloc())
2701 LBigIntPtrBitXor(useRegister(lhs), useRegisterOrConstant(rhs));
2702 define(lir, ins);
2703 }
2704
2705 void LIRGenerator::visitBigIntPtrLsh(MBigIntPtrLsh* ins) {
2706 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2707 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2708
2709 if (ins->rhs()->isConstant()) {
2710 // Need an additional temp when the operation is fallible.
2711 auto tmp = ins->fallible() ? temp() : LDefinition::BogusTemp();
2712
2713 auto* lir = new (alloc()) LBigIntPtrLsh(useRegister(ins->lhs()),
2714 useRegisterOrConstant(ins->rhs()),
2715 tmp, LDefinition::BogusTemp());
2716 if (ins->fallible()) {
2717 assignSnapshot(lir, ins->bailoutKind());
2718 }
2719 define(lir, ins);
2720 return;
2721 }
2722
2723 lowerBigIntPtrLsh(ins);
2724 }
2725
2726 void LIRGenerator::visitBigIntPtrRsh(MBigIntPtrRsh* ins) {
2727 MOZ_ASSERT(ins->lhs()->type() == MIRType::IntPtr);
2728 MOZ_ASSERT(ins->rhs()->type() == MIRType::IntPtr);
2729
2730 if (ins->rhs()->isConstant()) {
2731 // Need an additional temp when the operation is fallible.
2732 auto tmp = ins->fallible() ? temp() : LDefinition::BogusTemp();
2733
2734 auto* lir = new (alloc()) LBigIntPtrRsh(useRegister(ins->lhs()),
2735 useRegisterOrConstant(ins->rhs()),
2736 tmp, LDefinition::BogusTemp());
2737 if (ins->fallible()) {
2738 assignSnapshot(lir, ins->bailoutKind());
2739 }
2740 define(lir, ins);
2741 return;
2742 }
2743
2744 lowerBigIntPtrRsh(ins);
2745 }
2746
2747 void LIRGenerator::visitBigIntPtrBitNot(MBigIntPtrBitNot* ins) {
2748 MOZ_ASSERT(ins->input()->type() == MIRType::IntPtr);
2749
2750 auto* lir = new (alloc()) LBigIntPtrBitNot(useRegister(ins->input()));
2751 define(lir, ins);
2752 }
2753
2754 void LIRGenerator::visitInt32ToStringWithBase(MInt32ToStringWithBase* ins) {
2755 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
2756 MOZ_ASSERT(ins->base()->type() == MIRType::Int32);
2757
2758 int32_t baseInt =
2759 ins->base()->isConstant() ? ins->base()->toConstant()->toInt32() : 0;
2760
2761 LAllocation base;
2762 if (2 <= baseInt && baseInt <= 36) {
2763 base = useRegisterOrConstant(ins->base());
2764 } else {
2765 base = useRegister(ins->base());
2766 }
2767
2768 auto* lir = new (alloc())
2769 LInt32ToStringWithBase(useRegister(ins->input()), base, temp(), temp());
2770 define(lir, ins);
2771 assignSafepoint(lir, ins);
2772 }
2773
2774 void LIRGenerator::visitNumberParseInt(MNumberParseInt* ins) {
2775 MOZ_ASSERT(ins->string()->type() == MIRType::String);
2776 MOZ_ASSERT(ins->radix()->type() == MIRType::Int32);
2777
2778 auto* lir = new (alloc()) LNumberParseInt(useRegisterAtStart(ins->string()),
2779 useRegisterAtStart(ins->radix()),
2780 tempFixed(CallTempReg0));
2781 defineReturn(lir, ins);
2782 assignSafepoint(lir, ins);
2783 }
2784
2785 void LIRGenerator::visitDoubleParseInt(MDoubleParseInt* ins) {
2786 MOZ_ASSERT(ins->number()->type() == MIRType::Double);
2787
2788 auto* lir =
2789 new (alloc()) LDoubleParseInt(useRegister(ins->number()), tempDouble());
2790 assignSnapshot(lir, ins->bailoutKind());
2791 define(lir, ins);
2792 }
2793
2794 void LIRGenerator::visitConcat(MConcat* ins) {
2795 MDefinition* lhs = ins->getOperand(0);
2796 MDefinition* rhs = ins->getOperand(1);
2797
2798 MOZ_ASSERT(lhs->type() == MIRType::String);
2799 MOZ_ASSERT(rhs->type() == MIRType::String);
2800 MOZ_ASSERT(ins->type() == MIRType::String);
2801
2802 LConcat* lir = new (alloc()) LConcat(
2803 useFixedAtStart(lhs, CallTempReg0), useFixedAtStart(rhs, CallTempReg1),
2804 tempFixed(CallTempReg0), tempFixed(CallTempReg1), tempFixed(CallTempReg2),
2805 tempFixed(CallTempReg3), tempFixed(CallTempReg4));
2806 defineFixed(lir, ins, LAllocation(AnyRegister(CallTempReg5)));
2807 assignSafepoint(lir, ins);
2808 }
2809
2810 void LIRGenerator::visitLinearizeString(MLinearizeString* ins) {
2811 MDefinition* str = ins->string();
2812 MOZ_ASSERT(str->type() == MIRType::String);
2813
2814 auto* lir = new (alloc()) LLinearizeString(useRegister(str));
2815 define(lir, ins);
2816 assignSafepoint(lir, ins);
2817 }
2818
2819 void LIRGenerator::visitLinearizeForCharAccess(MLinearizeForCharAccess* ins) {
2820 MDefinition* str = ins->string();
2821 MDefinition* idx = ins->index();
2822
2823 MOZ_ASSERT(str->type() == MIRType::String);
2824 MOZ_ASSERT(idx->type() == MIRType::Int32);
2825
2826 auto* lir =
2827 new (alloc()) LLinearizeForCharAccess(useRegister(str), useRegister(idx));
2828 define(lir, ins);
2829 assignSafepoint(lir, ins);
2830 }
2831
2832 void LIRGenerator::visitLinearizeForCodePointAccess(
2833 MLinearizeForCodePointAccess* ins) {
2834 MDefinition* str = ins->string();
2835 MDefinition* idx = ins->index();
2836
2837 MOZ_ASSERT(str->type() == MIRType::String);
2838 MOZ_ASSERT(idx->type() == MIRType::Int32);
2839
2840 auto* lir = new (alloc())
2841 LLinearizeForCodePointAccess(useRegister(str), useRegister(idx), temp());
2842 define(lir, ins);
2843 assignSafepoint(lir, ins);
2844 }
2845
2846 void LIRGenerator::visitToRelativeStringIndex(MToRelativeStringIndex* ins) {
2847 MDefinition* index = ins->index();
2848 MDefinition* length = ins->length();
2849
2850 MOZ_ASSERT(index->type() == MIRType::Int32);
2851 MOZ_ASSERT(length->type() == MIRType::Int32);
2852
2853 auto* lir = new (alloc())
2854 LToRelativeStringIndex(useRegister(index), useRegister(length));
2855 define(lir, ins);
2856 }
2857
2858 void LIRGenerator::visitCharCodeAt(MCharCodeAt* ins) {
2859 MDefinition* str = ins->string();
2860 MDefinition* idx = ins->index();
2861
2862 MOZ_ASSERT(str->type() == MIRType::String);
2863 MOZ_ASSERT(idx->type() == MIRType::Int32);
2864
2865 auto* lir = new (alloc())
2866 LCharCodeAt(useRegister(str), useRegisterOrZero(idx), temp(), temp());
2867 define(lir, ins);
2868 assignSafepoint(lir, ins);
2869 }
2870
2871 void LIRGenerator::visitCharCodeAtOrNegative(MCharCodeAtOrNegative* ins) {
2872 MDefinition* str = ins->string();
2873 MDefinition* idx = ins->index();
2874
2875 MOZ_ASSERT(str->type() == MIRType::String);
2876 MOZ_ASSERT(idx->type() == MIRType::Int32);
2877
2878 auto* lir = new (alloc()) LCharCodeAtOrNegative(
2879 useRegister(str), useRegisterOrZero(idx), temp(), temp());
2880 define(lir, ins);
2881 assignSafepoint(lir, ins);
2882 }
2883
2884 void LIRGenerator::visitCodePointAt(MCodePointAt* ins) {
2885 MDefinition* str = ins->string();
2886 MDefinition* idx = ins->index();
2887
2888 MOZ_ASSERT(str->type() == MIRType::String);
2889 MOZ_ASSERT(idx->type() == MIRType::Int32);
2890
2891 auto* lir = new (alloc())
2892 LCodePointAt(useRegister(str), useRegister(idx), temp(), temp());
2893 define(lir, ins);
2894 assignSafepoint(lir, ins);
2895 }
2896
2897 void LIRGenerator::visitCodePointAtOrNegative(MCodePointAtOrNegative* ins) {
2898 MDefinition* str = ins->string();
2899 MDefinition* idx = ins->index();
2900
2901 MOZ_ASSERT(str->type() == MIRType::String);
2902 MOZ_ASSERT(idx->type() == MIRType::Int32);
2903
2904 auto* lir = new (alloc()) LCodePointAtOrNegative(
2905 useRegister(str), useRegister(idx), temp(), temp());
2906 define(lir, ins);
2907 assignSafepoint(lir, ins);
2908 }
2909
2910 void LIRGenerator::visitNegativeToNaN(MNegativeToNaN* ins) {
2911 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
2912
2913 auto* lir = new (alloc()) LNegativeToNaN(useRegister(ins->input()));
2914 defineBox(lir, ins);
2915 }
2916
2917 void LIRGenerator::visitNegativeToUndefined(MNegativeToUndefined* ins) {
2918 MOZ_ASSERT(ins->input()->type() == MIRType::Int32);
2919
2920 auto* lir = new (alloc()) LNegativeToUndefined(useRegister(ins->input()));
2921 defineBox(lir, ins);
2922 }
2923
2924 void LIRGenerator::visitFromCharCode(MFromCharCode* ins) {
2925 MDefinition* code = ins->code();
2926
2927 MOZ_ASSERT(code->type() == MIRType::Int32);
2928
2929 LFromCharCode* lir = new (alloc()) LFromCharCode(useRegister(code));
2930 define(lir, ins);
2931 assignSafepoint(lir, ins);
2932 }
2933
2934 void LIRGenerator::visitFromCharCodeEmptyIfNegative(
2935 MFromCharCodeEmptyIfNegative* ins) {
2936 MDefinition* code = ins->code();
2937
2938 MOZ_ASSERT(code->type() == MIRType::Int32);
2939
2940 auto* lir = new (alloc()) LFromCharCodeEmptyIfNegative(useRegister(code));
2941 define(lir, ins);
2942 assignSafepoint(lir, ins);
2943 }
2944
2945 void LIRGenerator::visitFromCharCodeUndefinedIfNegative(
2946 MFromCharCodeUndefinedIfNegative* ins) {
2947 MDefinition* code = ins->code();
2948
2949 MOZ_ASSERT(code->type() == MIRType::Int32);
2950
2951 auto* lir = new (alloc()) LFromCharCodeUndefinedIfNegative(useRegister(code));
2952 defineBox(lir, ins);
2953 assignSafepoint(lir, ins);
2954 }
2955
2956 void LIRGenerator::visitFromCodePoint(MFromCodePoint* ins) {
2957 MDefinition* codePoint = ins->codePoint();
2958
2959 MOZ_ASSERT(codePoint->type() == MIRType::Int32);
2960
2961 LFromCodePoint* lir =
2962 new (alloc()) LFromCodePoint(useRegister(codePoint), temp(), temp());
2963 assignSnapshot(lir, ins->bailoutKind());
2964 define(lir, ins);
2965 assignSafepoint(lir, ins);
2966 }
2967
2968 void LIRGenerator::visitStringIncludes(MStringIncludes* ins) {
2969 auto* string = ins->string();
2970 MOZ_ASSERT(string->type() == MIRType::String);
2971
2972 auto* searchStr = ins->searchString();
2973 MOZ_ASSERT(searchStr->type() == MIRType::String);
2974
2975 if (searchStr->isConstant()) {
2976 JSLinearString* linear = &searchStr->toConstant()->toString()->asLinear();
2977 size_t length = linear->length();
2978 if (length == 1 || length == 2) {
2979 LDefinition tempDef = LDefinition::BogusTemp();
2980 if (length > 1) {
2981 tempDef = temp();
2982 }
2983
2984 auto* lir = new (alloc()) LStringIncludesSIMD(useRegister(string), temp(),
2985 temp(), tempDef, linear);
2986 define(lir, ins);
2987 assignSafepoint(lir, ins);
2988 return;
2989 }
2990 }
2991
2992 auto* lir = new (alloc()) LStringIncludes(useRegisterAtStart(string),
2993 useRegisterAtStart(searchStr));
2994 defineReturn(lir, ins);
2995 assignSafepoint(lir, ins);
2996 }
2997
2998 void LIRGenerator::visitStringIndexOf(MStringIndexOf* ins) {
2999 auto* string = ins->string();
3000 MOZ_ASSERT(string->type() == MIRType::String);
3001
3002 auto* searchStr = ins->searchString();
3003 MOZ_ASSERT(searchStr->type() == MIRType::String);
3004
3005 if (searchStr->isConstant()) {
3006 JSLinearString* linear = &searchStr->toConstant()->toString()->asLinear();
3007 size_t length = linear->length();
3008 if (length == 1 || length == 2) {
3009 LDefinition tempDef = LDefinition::BogusTemp();
3010 if (length > 1) {
3011 tempDef = temp();
3012 }
3013
3014 auto* lir = new (alloc()) LStringIndexOfSIMD(useRegister(string), temp(),
3015 temp(), tempDef, linear);
3016 define(lir, ins);
3017 assignSafepoint(lir, ins);
3018 return;
3019 }
3020 }
3021
3022 auto* lir = new (alloc())
3023 LStringIndexOf(useRegisterAtStart(string), useRegisterAtStart(searchStr));
3024 defineReturn(lir, ins);
3025 assignSafepoint(lir, ins);
3026 }
3027
3028 void LIRGenerator::visitStringLastIndexOf(MStringLastIndexOf* ins) {
3029 auto* string = ins->string();
3030 MOZ_ASSERT(string->type() == MIRType::String);
3031
3032 auto* searchStr = ins->searchString();
3033 MOZ_ASSERT(searchStr->type() == MIRType::String);
3034
3035 auto* lir = new (alloc()) LStringLastIndexOf(useRegisterAtStart(string),
3036 useRegisterAtStart(searchStr));
3037 defineReturn(lir, ins);
3038 assignSafepoint(lir, ins);
3039 }
3040
3041 void LIRGenerator::visitStringStartsWith(MStringStartsWith* ins) {
3042 auto* string = ins->string();
3043 MOZ_ASSERT(string->type() == MIRType::String);
3044
3045 auto* searchStr = ins->searchString();
3046 MOZ_ASSERT(searchStr->type() == MIRType::String);
3047
3048 if (searchStr->isConstant()) {
3049 JSLinearString* linear = &searchStr->toConstant()->toString()->asLinear();
3050
3051 if (MacroAssembler::canCompareStringCharsInline(linear)) {
3052 auto* lir = new (alloc())
3053 LStringStartsWithInline(useRegister(string), temp(), linear);
3054 define(lir, ins);
3055 assignSafepoint(lir, ins);
3056 return;
3057 }
3058 }
3059
3060 auto* lir = new (alloc()) LStringStartsWith(useRegisterAtStart(string),
3061 useRegisterAtStart(searchStr));
3062 defineReturn(lir, ins);
3063 assignSafepoint(lir, ins);
3064 }
3065
3066 void LIRGenerator::visitStringEndsWith(MStringEndsWith* ins) {
3067 auto* string = ins->string();
3068 MOZ_ASSERT(string->type() == MIRType::String);
3069
3070 auto* searchStr = ins->searchString();
3071 MOZ_ASSERT(searchStr->type() == MIRType::String);
3072
3073 if (searchStr->isConstant()) {
3074 JSLinearString* linear = &searchStr->toConstant()->toString()->asLinear();
3075
3076 if (MacroAssembler::canCompareStringCharsInline(linear)) {
3077 auto* lir = new (alloc())
3078 LStringEndsWithInline(useRegister(string), temp(), linear);
3079 define(lir, ins);
3080 assignSafepoint(lir, ins);
3081 return;
3082 }
3083 }
3084
3085 auto* lir = new (alloc()) LStringEndsWith(useRegisterAtStart(string),
3086 useRegisterAtStart(searchStr));
3087 defineReturn(lir, ins);
3088 assignSafepoint(lir, ins);
3089 }
3090
3091 void LIRGenerator::visitStringConvertCase(MStringConvertCase* ins) {
3092 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3093
3094 if (ins->mode() == MStringConvertCase::LowerCase) {
3095 #ifdef JS_CODEGEN_X86
3096 // Due to lack of registers on x86, we reuse the string register as
3097 // temporary. As a result we only need four temporary registers and take a
3098 // bogus temporary as the fifth argument.
3099 LDefinition temp4 = LDefinition::BogusTemp();
3100 #else
3101 LDefinition temp4 = temp();
3102 #endif
3103 auto* lir = new (alloc())
3104 LStringToLowerCase(useRegister(ins->string()), temp(), temp(), temp(),
3105 temp4, tempByteOpRegister());
3106 define(lir, ins);
3107 assignSafepoint(lir, ins);
3108 } else {
3109 auto* lir =
3110 new (alloc()) LStringToUpperCase(useRegisterAtStart(ins->string()));
3111 defineReturn(lir, ins);
3112 assignSafepoint(lir, ins);
3113 }
3114 }
3115
3116 void LIRGenerator::visitCharCodeConvertCase(MCharCodeConvertCase* ins) {
3117 MOZ_ASSERT(ins->code()->type() == MIRType::Int32);
3118
3119 if (ins->mode() == MCharCodeConvertCase::LowerCase) {
3120 auto* lir = new (alloc())
3121 LCharCodeToLowerCase(useRegister(ins->code()), tempByteOpRegister());
3122 define(lir, ins);
3123 assignSafepoint(lir, ins);
3124 } else {
3125 auto* lir = new (alloc())
3126 LCharCodeToUpperCase(useRegister(ins->code()), tempByteOpRegister());
3127 define(lir, ins);
3128 assignSafepoint(lir, ins);
3129 }
3130 }
3131
3132 void LIRGenerator::visitStringTrimStartIndex(MStringTrimStartIndex* ins) {
3133 auto* string = ins->string();
3134 MOZ_ASSERT(string->type() == MIRType::String);
3135
3136 auto* lir = new (alloc()) LStringTrimStartIndex(useRegister(string));
3137 define(lir, ins);
3138 assignSafepoint(lir, ins);
3139 }
3140
3141 void LIRGenerator::visitStringTrimEndIndex(MStringTrimEndIndex* ins) {
3142 auto* string = ins->string();
3143 MOZ_ASSERT(string->type() == MIRType::String);
3144
3145 auto* start = ins->start();
3146 MOZ_ASSERT(start->type() == MIRType::Int32);
3147
3148 auto* lir = new (alloc())
3149 LStringTrimEndIndex(useRegister(string), useRegister(start));
3150 define(lir, ins);
3151 assignSafepoint(lir, ins);
3152 }
3153
3154 void LIRGenerator::visitStart(MStart* start) {}
3155
3156 void LIRGenerator::visitNop(MNop* nop) {}
3157
3158 void LIRGenerator::visitLimitedTruncate(MLimitedTruncate* nop) {
3159 redefine(nop, nop->input());
3160 }
3161
3162 void LIRGenerator::visitIntPtrLimitedTruncate(MIntPtrLimitedTruncate* ins) {
3163 MOZ_ASSERT(ins->input()->type() == MIRType::IntPtr);
3164
3165 // This is a no-op.
3166 redefine(ins, ins->input());
3167 }
3168
3169 void LIRGenerator::visitInt64LimitedTruncate(MInt64LimitedTruncate* ins) {
3170 MOZ_ASSERT(ins->input()->type() == MIRType::Int64);
3171
3172 // This is a no-op.
3173 redefine(ins, ins->input());
3174 }
3175
3176 void LIRGenerator::visitOsrEntry(MOsrEntry* entry) {
3177 LOsrEntry* lir = new (alloc()) LOsrEntry(temp());
3178 defineFixed(lir, entry, LAllocation(AnyRegister(OsrFrameReg)));
3179 }
3180
3181 void LIRGenerator::visitOsrValue(MOsrValue* value) {
3182 LOsrValue* lir = new (alloc()) LOsrValue(useRegister(value->entry()));
3183 defineBox(lir, value);
3184 }
3185
3186 void LIRGenerator::visitOsrReturnValue(MOsrReturnValue* value) {
3187 LOsrReturnValue* lir =
3188 new (alloc()) LOsrReturnValue(useRegister(value->entry()));
3189 defineBox(lir, value);
3190 }
3191
3192 void LIRGenerator::visitOsrEnvironmentChain(MOsrEnvironmentChain* object) {
3193 LOsrEnvironmentChain* lir =
3194 new (alloc()) LOsrEnvironmentChain(useRegister(object->entry()));
3195 define(lir, object);
3196 }
3197
3198 void LIRGenerator::visitOsrArgumentsObject(MOsrArgumentsObject* object) {
3199 LOsrArgumentsObject* lir =
3200 new (alloc()) LOsrArgumentsObject(useRegister(object->entry()));
3201 define(lir, object);
3202 }
3203
3204 void LIRGenerator::visitToDouble(MToDouble* convert) {
3205 MDefinition* opd = convert->input();
3206
3207 switch (opd->type()) {
3208 case MIRType::Value: {
3209 LValueToDouble* lir = new (alloc()) LValueToDouble(useBox(opd));
3210 assignSnapshot(lir, convert->bailoutKind());
3211 define(lir, convert);
3212 break;
3213 }
3214
3215 case MIRType::Null:
3216 lowerConstantDouble(0, convert);
3217 break;
3218
3219 case MIRType::Undefined:
3220 lowerConstantDouble(GenericNaN(), convert);
3221 break;
3222
3223 case MIRType::Boolean:
3224 case MIRType::Int32: {
3225 LInt32ToDouble* lir =
3226 new (alloc()) LInt32ToDouble(useRegisterAtStart(opd));
3227 define(lir, convert);
3228 break;
3229 }
3230
3231 case MIRType::Float32: {
3232 LFloat32ToDouble* lir =
3233 new (alloc()) LFloat32ToDouble(useRegisterAtStart(opd));
3234 define(lir, convert);
3235 break;
3236 }
3237
3238 case MIRType::Double:
3239 redefine(convert, opd);
3240 break;
3241
3242 default:
3243 // Objects might be effectful. Symbols will throw.
3244 // Strings are complicated - we don't handle them yet.
3245 MOZ_CRASH("unexpected type");
3246 }
3247 }
3248
3249 void LIRGenerator::visitToFloat32(MToFloat32* convert) {
3250 MDefinition* opd = convert->input();
3251
3252 switch (opd->type()) {
3253 case MIRType::Value: {
3254 LValueToFloat32* lir = new (alloc()) LValueToFloat32(useBox(opd));
3255 assignSnapshot(lir, convert->bailoutKind());
3256 define(lir, convert);
3257 break;
3258 }
3259
3260 case MIRType::Null:
3261 lowerConstantFloat32(0, convert);
3262 break;
3263
3264 case MIRType::Undefined:
3265 lowerConstantFloat32(GenericNaN(), convert);
3266 break;
3267
3268 case MIRType::Boolean:
3269 case MIRType::Int32: {
3270 LInt32ToFloat32* lir =
3271 new (alloc()) LInt32ToFloat32(useRegisterAtStart(opd));
3272 define(lir, convert);
3273 break;
3274 }
3275
3276 case MIRType::Double: {
3277 LDoubleToFloat32* lir =
3278 new (alloc()) LDoubleToFloat32(useRegisterAtStart(opd));
3279 define(lir, convert);
3280 break;
3281 }
3282
3283 case MIRType::Float32:
3284 redefine(convert, opd);
3285 break;
3286
3287 default:
3288 // Objects might be effectful. Symbols will throw.
3289 // Strings are complicated - we don't handle them yet.
3290 MOZ_CRASH("unexpected type");
3291 }
3292 }
3293
3294 void LIRGenerator::visitToFloat16(MToFloat16* convert) {
3295 MDefinition* opd = convert->input();
3296
3297 switch (opd->type()) {
3298 case MIRType::Value: {
3299 LDefinition tempDef = LDefinition::BogusTemp();
3300 if (!MacroAssembler::SupportsFloat64To16()) {
3301 tempDef = temp();
3302 }
3303
3304 auto* lir = new (alloc()) LValueToFloat16(useBox(opd), tempDef);
3305 assignSnapshot(lir, convert->bailoutKind());
3306 define(lir, convert);
3307
3308 if (!MacroAssembler::SupportsFloat64To16()) {
3309 assignSafepoint(lir, convert);
3310 }
3311 break;
3312 }
3313
3314 case MIRType::Null:
3315 lowerConstantFloat32(0, convert);
3316 break;
3317
3318 case MIRType::Undefined:
3319 lowerConstantFloat32(GenericNaN(), convert);
3320 break;
3321
3322 case MIRType::Boolean:
3323 case MIRType::Int32: {
3324 LDefinition tempDef = LDefinition::BogusTemp();
3325 if (!MacroAssembler::SupportsFloat32To16()) {
3326 tempDef = temp();
3327 }
3328
3329 auto* lir =
3330 new (alloc()) LInt32ToFloat16(useRegisterAtStart(opd), tempDef);
3331 define(lir, convert);
3332
3333 if (!MacroAssembler::SupportsFloat32To16()) {
3334 assignSafepoint(lir, convert);
3335 }
3336 break;
3337 }
3338
3339 case MIRType::Double: {
3340 if (MacroAssembler::SupportsFloat64To16()) {
3341 auto* lir = new (alloc())
3342 LDoubleToFloat16(useRegisterAtStart(opd), LDefinition::BogusTemp());
3343 define(lir, convert);
3344 } else if (MacroAssembler::SupportsFloat32To16()) {
3345 auto* lir = new (alloc())
3346 LDoubleToFloat32ToFloat16(useRegister(opd), temp(), temp());
3347 define(lir, convert);
3348 } else {
3349 auto* lir =
3350 new (alloc()) LDoubleToFloat16(useRegisterAtStart(opd), temp());
3351 define(lir, convert);
3352 assignSafepoint(lir, convert);
3353 }
3354 break;
3355 }
3356
3357 case MIRType::Float32: {
3358 LDefinition tempDef = LDefinition::BogusTemp();
3359 if (!MacroAssembler::SupportsFloat32To16()) {
3360 tempDef = temp();
3361 }
3362
3363 auto* lir =
3364 new (alloc()) LFloat32ToFloat16(useRegisterAtStart(opd), tempDef);
3365 define(lir, convert);
3366
3367 if (!MacroAssembler::SupportsFloat32To16()) {
3368 assignSafepoint(lir, convert);
3369 }
3370 break;
3371 }
3372
3373 default:
3374 // Objects might be effectful. Symbols will throw.
3375 // Strings are complicated - we don't handle them yet.
3376 MOZ_CRASH("unexpected type");
3377 }
3378 }
3379
3380 void LIRGenerator::visitToNumberInt32(MToNumberInt32* convert) {
3381 MDefinition* opd = convert->input();
3382
3383 switch (opd->type()) {
3384 case MIRType::Value: {
3385 auto* lir = new (alloc()) LValueToNumberInt32(useBox(opd), tempDouble());
3386 assignSnapshot(lir, convert->bailoutKind());
3387 define(lir, convert);
3388 break;
3389 }
3390
3391 case MIRType::Null:
3392 MOZ_ASSERT(convert->conversion() == IntConversionInputKind::Any);
3393 define(new (alloc()) LInteger(0), convert);
3394 break;
3395
3396 case MIRType::Boolean:
3397 MOZ_ASSERT(convert->conversion() == IntConversionInputKind::Any);
3398 redefine(convert, opd);
3399 break;
3400
3401 case MIRType::Int32:
3402 redefine(convert, opd);
3403 break;
3404
3405 case MIRType::Float32: {
3406 LFloat32ToInt32* lir = new (alloc()) LFloat32ToInt32(useRegister(opd));
3407 assignSnapshot(lir, convert->bailoutKind());
3408 define(lir, convert);
3409 break;
3410 }
3411
3412 case MIRType::Double: {
3413 LDoubleToInt32* lir = new (alloc()) LDoubleToInt32(useRegister(opd));
3414 assignSnapshot(lir, convert->bailoutKind());
3415 define(lir, convert);
3416 break;
3417 }
3418
3419 case MIRType::String:
3420 case MIRType::Symbol:
3421 case MIRType::BigInt:
3422 case MIRType::Object:
3423 case MIRType::Undefined:
3424 // Objects might be effectful. Symbols and BigInts throw. Undefined
3425 // coerces to NaN, not int32.
3426 MOZ_CRASH("ToInt32 invalid input type");
3427
3428 default:
3429 MOZ_CRASH("unexpected type");
3430 }
3431 }
3432
3433 void LIRGenerator::visitBooleanToInt32(MBooleanToInt32* convert) {
3434 MDefinition* opd = convert->input();
3435 MOZ_ASSERT(opd->type() == MIRType::Boolean);
3436 redefine(convert, opd);
3437 }
3438
3439 void LIRGenerator::visitTruncateToInt32(MTruncateToInt32* truncate) {
3440 MDefinition* opd = truncate->input();
3441
3442 switch (opd->type()) {
3443 case MIRType::Value: {
3444 auto* lir = new (alloc())
3445 LValueTruncateToInt32(useBox(opd), tempDouble(), temp());
3446 assignSnapshot(lir, truncate->bailoutKind());
3447 define(lir, truncate);
3448 assignSafepoint(lir, truncate);
3449 break;
3450 }
3451
3452 case MIRType::Null:
3453 case MIRType::Undefined:
3454 define(new (alloc()) LInteger(0), truncate);
3455 break;
3456
3457 case MIRType::Int32:
3458 case MIRType::Boolean:
3459 redefine(truncate, opd);
3460 break;
3461
3462 case MIRType::Double:
3463 // May call into JS::ToInt32() on the slow OOL path.
3464 gen->setNeedsStaticStackAlignment();
3465 lowerTruncateDToInt32(truncate);
3466 break;
3467
3468 case MIRType::Float32:
3469 // May call into JS::ToInt32() on the slow OOL path.
3470 gen->setNeedsStaticStackAlignment();
3471 lowerTruncateFToInt32(truncate);
3472 break;
3473
3474 default:
3475 // Objects might be effectful. Symbols throw.
3476 // Strings are complicated - we don't handle them yet.
3477 MOZ_CRASH("unexpected type");
3478 }
3479 }
3480
3481 void LIRGenerator::visitInt32ToIntPtr(MInt32ToIntPtr* ins) {
3482 MDefinition* input = ins->input();
3483 MOZ_ASSERT(input->type() == MIRType::Int32);
3484 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
3485
3486 #ifdef JS_64BIT
3487 // If the result is only used by instructions that expect a bounds-checked
3488 // index, we must have eliminated or hoisted a bounds check and we can assume
3489 // the index is non-negative. This lets us generate more efficient code.
3490 //
3491 // The no-op lowering with |redefine| shares the input's virtual register and
3492 // 32-bit spill slot, so all instruction uses must read from a register:
3493 // registers hold Int32 values zero-extended, which matches the sign-extended
3494 // IntPtr value because we only do this when the value is non-negative. A
3495 // pointer-width memory read would instead also consume bytes from the
3496 // adjacent stack slot. Snapshots handle this separately with
3497 // RValueAllocation::IntPtrInt32.
3498 bool canBeNegative = false;
3499 bool canRedefine = true;
3500 for (MUseDefIterator iter(ins); iter; iter++) {
3501 MDefinition* def = iter.def();
3502 size_t index = def->indexOf(iter.use());
3503 if (def->isLoadUnboxedScalar() || def->isStoreUnboxedScalar() ||
3504 def->isLoadDataViewElement() || def->isStoreDataViewElement()) {
3505 // The bounds-checked index is lowered with useRegisterOrIndexConstant.
3506 static_assert(MLoadUnboxedScalar::indexOperand == 1);
3507 static_assert(MStoreUnboxedScalar::indexOperand == 1);
3508 static_assert(MLoadDataViewElement::indexOperand == 1);
3509 static_assert(MStoreDataViewElement::indexOperand == 1);
3510 MOZ_RELEASE_ASSERT(index == 1);
3511 continue;
3512 }
3513 if (def->isSpectreMaskIndex() && index == MSpectreMaskIndex::indexOperand) {
3514 // The bounds-checked index is lowered with useRegister.
3515 continue;
3516 }
3517 if (def->isBoundsCheck() && index == MBoundsCheck::indexOperand) {
3518 // The index operand is lowered with useRegisterOrInt32Constant, but
3519 // because this is the instruction performing the check it implies
3520 // nothing about the sign.
3521 canBeNegative = true;
3522 continue;
3523 }
3524 // Don't optimize other uses.
3525 canBeNegative = true;
3526 canRedefine = false;
3527 break;
3528 }
3529 if (!canBeNegative) {
3530 ins->setCanNotBeNegative();
3531 }
3532
3533 if (ins->canBeNegative() || !canRedefine) {
3534 auto* lir = new (alloc()) LInt32ToIntPtr(useAnyAtStart(input));
3535 define(lir, ins);
3536 } else {
3537 redefine(ins, input);
3538 }
3539 #else
3540 // On 32-bit platforms this is a no-op.
3541 redefine(ins, input);
3542 #endif
3543 }
3544
3545 void LIRGenerator::visitNonNegativeIntPtrToInt32(
3546 MNonNegativeIntPtrToInt32* ins) {
3547 MDefinition* input = ins->input();
3548 MOZ_ASSERT(input->type() == MIRType::IntPtr);
3549 MOZ_ASSERT(ins->type() == MIRType::Int32);
3550
3551 #ifdef JS_64BIT
3552 auto* lir =
3553 new (alloc()) LNonNegativeIntPtrToInt32(useRegisterAtStart(input));
3554 assignSnapshot(lir, ins->bailoutKind());
3555 defineReuseInput(lir, ins, 0);
3556 #else
3557 // On 32-bit platforms this is a no-op.
3558 redefine(ins, input);
3559 #endif
3560 }
3561
3562 void LIRGenerator::visitWasmExtendU32Index(MWasmExtendU32Index* ins) {
3563 #ifdef JS_64BIT
3564 // Technically this produces an Int64 register and I guess we could clean that
3565 // up, but it's a 64-bit only operation, so it doesn't actually matter.
3566
3567 MDefinition* input = ins->input();
3568 MOZ_ASSERT(input->type() == MIRType::Int32);
3569 MOZ_ASSERT(ins->type() == MIRType::Int64);
3570
3571 // Input reuse is OK even on ARM64 because this node *must* reuse its input in
3572 // order not to generate any code at all, as is the intent.
3573 auto* lir = new (alloc()) LWasmExtendU32Index(useRegisterAtStart(input));
3574 defineReuseInput(lir, ins, 0);
3575 #else
3576 MOZ_CRASH("64-bit only");
3577 #endif
3578 }
3579
3580 void LIRGenerator::visitWasmWrapU32Index(MWasmWrapU32Index* ins) {
3581 MDefinition* input = ins->input();
3582 MOZ_ASSERT(input->type() == MIRType::Int64);
3583 MOZ_ASSERT(ins->type() == MIRType::Int32);
3584
3585 // Tricky: On 64-bit, this just returns its input (except on MIPS64 there may
3586 // be a sign/zero extension). On 32-bit, it returns the low register of the
3587 // input, and should generate no code.
3588
3589 #ifdef JS_64BIT
3590 LAllocation index = useRegisterAtStart(input);
3591 #else
3592 LAllocation index = useLowWordRegisterAtStart(input);
3593 #endif
3594
3595 auto* lir = new (alloc()) LWasmWrapU32Index(index);
3596 defineReuseInput(lir, ins, 0);
3597 }
3598
3599 void LIRGenerator::visitWasmClampTable64Address(MWasmClampTable64Address* ins) {
3600 MDefinition* input = ins->address();
3601 MOZ_ASSERT(input->type() == MIRType::Int64);
3602 MOZ_ASSERT(ins->type() == MIRType::Int32);
3603
3604 auto* lir =
3605 new (alloc()) LWasmClampTable64Address(useInt64RegisterAtStart(input));
3606 define(lir, ins);
3607 }
3608
3609 void LIRGenerator::visitIntPtrToDouble(MIntPtrToDouble* ins) {
3610 MDefinition* input = ins->input();
3611 MOZ_ASSERT(input->type() == MIRType::IntPtr);
3612 MOZ_ASSERT(ins->type() == MIRType::Double);
3613
3614 auto* lir = new (alloc()) LIntPtrToDouble(useRegister(input));
3615 define(lir, ins);
3616 }
3617
3618 void LIRGenerator::visitAdjustDataViewLength(MAdjustDataViewLength* ins) {
3619 MDefinition* input = ins->input();
3620 MOZ_ASSERT(input->type() == MIRType::IntPtr);
3621
3622 auto* lir = new (alloc()) LAdjustDataViewLength(useRegisterAtStart(input));
3623 assignSnapshot(lir, ins->bailoutKind());
3624 defineReuseInput(lir, ins, 0);
3625 }
3626
3627 void LIRGenerator::visitToBigInt(MToBigInt* ins) {
3628 MDefinition* opd = ins->input();
3629
3630 switch (opd->type()) {
3631 case MIRType::Value: {
3632 auto* lir = new (alloc()) LValueToBigInt(useBox(opd));
3633 assignSnapshot(lir, ins->bailoutKind());
3634 define(lir, ins);
3635 assignSafepoint(lir, ins);
3636 break;
3637 }
3638
3639 case MIRType::BigInt:
3640 redefine(ins, opd);
3641 break;
3642
3643 default:
3644 MOZ_CRASH("unexpected type");
3645 }
3646 }
3647
3648 void LIRGenerator::visitToInt64(MToInt64* ins) {
3649 MDefinition* opd = ins->input();
3650
3651 switch (opd->type()) {
3652 case MIRType::Value: {
3653 auto* lir = new (alloc()) LValueToInt64(useBox(opd), temp());
3654 assignSnapshot(lir, ins->bailoutKind());
3655 defineInt64(lir, ins);
3656 assignSafepoint(lir, ins);
3657 break;
3658 }
3659
3660 case MIRType::Boolean: {
3661 auto* lir = new (alloc()) LBooleanToInt64(useRegisterAtStart(opd));
3662 defineInt64(lir, ins);
3663 break;
3664 }
3665
3666 case MIRType::String: {
3667 auto* lir = new (alloc()) LStringToInt64(useRegister(opd));
3668 defineInt64(lir, ins);
3669 assignSafepoint(lir, ins);
3670 break;
3671 }
3672
3673 // An Int64 may be passed here from a BigInt to Int64 conversion.
3674 case MIRType::Int64: {
3675 redefine(ins, opd);
3676 break;
3677 }
3678
3679 default:
3680 // Undefined, Null, Number, and Symbol throw.
3681 // Objects may be effectful.
3682 // BigInt operands are eliminated by the type policy.
3683 MOZ_CRASH("unexpected type");
3684 }
3685 }
3686
3687 void LIRGenerator::visitTruncateBigIntToInt64(MTruncateBigIntToInt64* ins) {
3688 MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
3689 auto* lir = new (alloc()) LTruncateBigIntToInt64(useRegister(ins->input()));
3690 defineInt64(lir, ins);
3691 }
3692
3693 void LIRGenerator::visitInt64ToBigInt(MInt64ToBigInt* ins) {
3694 MOZ_ASSERT(ins->input()->type() == MIRType::Int64);
3695
3696 if (ins->isSigned()) {
3697 auto* lir = new (alloc())
3698 LInt64ToBigInt(useInt64Register(ins->input()), tempInt64());
3699 define(lir, ins);
3700 assignSafepoint(lir, ins);
3701 } else {
3702 auto* lir =
3703 new (alloc()) LUint64ToBigInt(useInt64Register(ins->input()), temp());
3704 define(lir, ins);
3705 assignSafepoint(lir, ins);
3706 }
3707 }
3708
3709 void LIRGenerator::visitInt64ToIntPtr(MInt64ToIntPtr* ins) {
3710 MOZ_ASSERT(ins->input()->type() == MIRType::Int64);
3711
3712 #ifdef JS_64BIT
3713 if (ins->isSigned()) {
3714 redefine(ins, ins->input());
3715 return;
3716 }
3717 #endif
3718
3719 auto* lir =
3720 new (alloc()) LInt64ToIntPtr(useInt64RegisterAtStart(ins->input()));
3721 assignSnapshot(lir, ins->bailoutKind());
3722 #ifdef JS_64BIT
3723 defineReuseInput(lir, ins, 0);
3724 #else
3725 define(lir, ins);
3726 #endif
3727 }
3728
3729 void LIRGenerator::visitIntPtrToInt64(MIntPtrToInt64* ins) {
3730 MOZ_ASSERT(ins->input()->type() == MIRType::IntPtr);
3731
3732 #ifdef JS_64BIT
3733 redefine(ins, ins->input());
3734 #else
3735 auto* lir = new (alloc()) LIntPtrToInt64(useRegister(ins->input()));
3736 defineInt64(lir, ins);
3737 #endif
3738 }
3739
3740 void LIRGenerator::visitWasmTruncateToInt32(MWasmTruncateToInt32* ins) {
3741 MDefinition* input = ins->input();
3742 switch (input->type()) {
3743 case MIRType::Double:
3744 case MIRType::Float32: {
3745 auto* lir = new (alloc()) LWasmTruncateToInt32(useRegisterAtStart(input));
3746 define(lir, ins);
3747 break;
3748 }
3749 default:
3750 MOZ_CRASH("unexpected type in WasmTruncateToInt32");
3751 }
3752 }
3753
3754 void LIRGenerator::visitWasmBuiltinTruncateToInt32(
3755 MWasmBuiltinTruncateToInt32* truncate) {
3756 mozilla::DebugOnly<MDefinition*> opd = truncate->input();
3757 MOZ_ASSERT(opd->type() == MIRType::Double || opd->type() == MIRType::Float32);
3758
3759 // May call into JS::ToInt32() on the slow OOL path.
3760 gen->setNeedsStaticStackAlignment();
3761 lowerWasmBuiltinTruncateToInt32(truncate);
3762 }
3763
3764 void LIRGenerator::visitWasmAnyRefFromJSValue(MWasmAnyRefFromJSValue* ins) {
3765 LWasmAnyRefFromJSValue* lir =
3766 new (alloc()) LWasmAnyRefFromJSValue(useBox(ins->input()), tempDouble());
3767 define(lir, ins);
3768 assignSafepoint(lir, ins);
3769 }
3770
3771 void LIRGenerator::visitWasmAnyRefFromJSObject(MWasmAnyRefFromJSObject* ins) {
3772 LWasmAnyRefFromJSObject* lir =
3773 new (alloc()) LWasmAnyRefFromJSObject(useRegisterAtStart(ins->input()));
3774 define(lir, ins);
3775 }
3776
3777 void LIRGenerator::visitWasmAnyRefFromJSString(MWasmAnyRefFromJSString* ins) {
3778 LWasmAnyRefFromJSString* lir =
3779 new (alloc()) LWasmAnyRefFromJSString(useRegisterAtStart(ins->input()));
3780 define(lir, ins);
3781 }
3782
3783 void LIRGenerator::visitWasmAnyRefIsJSString(MWasmAnyRefIsJSString* ins) {
3784 LWasmAnyRefIsJSString* lir = new (alloc())
3785 LWasmAnyRefIsJSString(useRegisterAtStart(ins->input()), temp());
3786 define(lir, ins);
3787 }
3788
3789 void LIRGenerator::visitWasmTrapIfAnyRefIsNotJSString(
3790 MWasmTrapIfAnyRefIsNotJSString* ins) {
3791 LWasmTrapIfAnyRefIsNotJSString* lir = new (alloc())
3792 LWasmTrapIfAnyRefIsNotJSString(useRegisterAtStart(ins->input()), temp());
3793 add(lir, ins);
3794 }
3795
3796 void LIRGenerator::visitWasmAnyRefJSStringLength(
3797 MWasmAnyRefJSStringLength* ins) {
3798 LWasmAnyRefJSStringLength* lir = new (alloc())
3799 LWasmAnyRefJSStringLength(useRegisterAtStart(ins->input()), temp());
3800 define(lir, ins);
3801 }
3802
3803 void LIRGenerator::visitWasmNewI31Ref(MWasmNewI31Ref* ins) {
3804 // If it's a constant, it will be put directly into the register.
3805 LWasmNewI31Ref* lir =
3806 new (alloc()) LWasmNewI31Ref(useRegisterOrConstant(ins->input()));
3807 define(lir, ins);
3808 }
3809
3810 void LIRGenerator::visitWasmI31RefGet(MWasmI31RefGet* ins) {
3811 LWasmI31RefGet* lir = new (alloc()) LWasmI31RefGet(useRegister(ins->input()));
3812 define(lir, ins);
3813 }
3814
3815 void LIRGenerator::visitWrapInt64ToInt32(MWrapInt64ToInt32* ins) {
3816 define(new (alloc()) LWrapInt64ToInt32(useInt64AtStart(ins->input())), ins);
3817 }
3818
3819 void LIRGenerator::visitToString(MToString* ins) {
3820 MDefinition* opd = ins->input();
3821
3822 switch (opd->type()) {
3823 case MIRType::Null: {
3824 const JSAtomState& names = gen->runtime->names();
3825 LPointer* lir = new (alloc()) LPointer(names.null);
3826 define(lir, ins);
3827 break;
3828 }
3829
3830 case MIRType::Undefined: {
3831 const JSAtomState& names = gen->runtime->names();
3832 LPointer* lir = new (alloc()) LPointer(names.undefined);
3833 define(lir, ins);
3834 break;
3835 }
3836
3837 case MIRType::Boolean: {
3838 LBooleanToString* lir = new (alloc()) LBooleanToString(useRegister(opd));
3839 define(lir, ins);
3840 break;
3841 }
3842
3843 case MIRType::Double: {
3844 LDoubleToString* lir =
3845 new (alloc()) LDoubleToString(useRegister(opd), temp());
3846
3847 define(lir, ins);
3848 assignSafepoint(lir, ins);
3849 break;
3850 }
3851
3852 case MIRType::Int32: {
3853 LIntToString* lir = new (alloc()) LIntToString(useRegister(opd));
3854
3855 define(lir, ins);
3856 assignSafepoint(lir, ins);
3857 break;
3858 }
3859
3860 case MIRType::String:
3861 redefine(ins, ins->input());
3862 break;
3863
3864 case MIRType::Value: {
3865 LValueToString* lir =
3866 new (alloc()) LValueToString(useBox(opd), tempToUnbox());
3867 if (ins->needsSnapshot()) {
3868 assignSnapshot(lir, ins->bailoutKind());
3869 }
3870 define(lir, ins);
3871 assignSafepoint(lir, ins);
3872 break;
3873 }
3874
3875 default:
3876 // Float32, symbols, bigint, and objects are not supported.
3877 MOZ_CRASH("unexpected type");
3878 }
3879 }
3880
3881 void LIRGenerator::visitRegExp(MRegExp* ins) {
3882 LRegExp* lir = new (alloc()) LRegExp(temp());
3883 define(lir, ins);
3884 assignSafepoint(lir, ins);
3885 }
3886
3887 void LIRGenerator::visitRegExpMatcher(MRegExpMatcher* ins) {
3888 MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
3889 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3890 MOZ_ASSERT(ins->lastIndex()->type() == MIRType::Int32);
3891
3892 LRegExpMatcher* lir = new (alloc()) LRegExpMatcher(
3893 useFixedAtStart(ins->regexp(), RegExpMatcherRegExpReg),
3894 useFixedAtStart(ins->string(), RegExpMatcherStringReg),
3895 useFixedAtStart(ins->lastIndex(), RegExpMatcherLastIndexReg));
3896 defineReturn(lir, ins);
3897 assignSafepoint(lir, ins);
3898 }
3899
3900 void LIRGenerator::visitRegExpSearcher(MRegExpSearcher* ins) {
3901 MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
3902 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3903 MOZ_ASSERT(ins->lastIndex()->type() == MIRType::Int32);
3904
3905 LRegExpSearcher* lir = new (alloc()) LRegExpSearcher(
3906 useFixedAtStart(ins->regexp(), RegExpSearcherRegExpReg),
3907 useFixedAtStart(ins->string(), RegExpSearcherStringReg),
3908 useFixedAtStart(ins->lastIndex(), RegExpSearcherLastIndexReg));
3909 defineReturn(lir, ins);
3910 assignSafepoint(lir, ins);
3911 }
3912
3913 void LIRGenerator::visitRegExpSearcherLastLimit(MRegExpSearcherLastLimit* ins) {
3914 auto* lir = new (alloc()) LRegExpSearcherLastLimit(temp());
3915 define(lir, ins);
3916 }
3917
3918 void LIRGenerator::visitRegExpExecMatch(MRegExpExecMatch* ins) {
3919 MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
3920 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3921
3922 auto* lir = new (alloc())
3923 LRegExpExecMatch(useFixedAtStart(ins->regexp(), RegExpMatcherRegExpReg),
3924 useFixedAtStart(ins->string(), RegExpMatcherStringReg));
3925 defineReturn(lir, ins);
3926 assignSafepoint(lir, ins);
3927 }
3928
3929 void LIRGenerator::visitRegExpExecTest(MRegExpExecTest* ins) {
3930 MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
3931 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3932
3933 auto* lir = new (alloc())
3934 LRegExpExecTest(useFixedAtStart(ins->regexp(), RegExpExecTestRegExpReg),
3935 useFixedAtStart(ins->string(), RegExpExecTestStringReg));
3936 defineReturn(lir, ins);
3937 assignSafepoint(lir, ins);
3938 }
3939
3940 void LIRGenerator::visitRegExpHasCaptureGroups(MRegExpHasCaptureGroups* ins) {
3941 MOZ_ASSERT(ins->regexp()->type() == MIRType::Object);
3942 MOZ_ASSERT(ins->input()->type() == MIRType::String);
3943 MOZ_ASSERT(ins->type() == MIRType::Boolean);
3944
3945 auto* lir = new (alloc()) LRegExpHasCaptureGroups(useRegister(ins->regexp()),
3946 useRegister(ins->input()));
3947 define(lir, ins);
3948 assignSafepoint(lir, ins);
3949 }
3950
3951 void LIRGenerator::visitGetFirstDollarIndex(MGetFirstDollarIndex* ins) {
3952 MOZ_ASSERT(ins->str()->type() == MIRType::String);
3953 MOZ_ASSERT(ins->type() == MIRType::Int32);
3954 LGetFirstDollarIndex* lir = new (alloc())
3955 LGetFirstDollarIndex(useRegister(ins->str()), temp(), temp(), temp());
3956 define(lir, ins);
3957 assignSafepoint(lir, ins);
3958 }
3959
3960 void LIRGenerator::visitStringReplace(MStringReplace* ins) {
3961 MOZ_ASSERT(ins->pattern()->type() == MIRType::String);
3962 MOZ_ASSERT(ins->string()->type() == MIRType::String);
3963 MOZ_ASSERT(ins->replacement()->type() == MIRType::String);
3964
3965 LStringReplace* lir = new (alloc())
3966 LStringReplace(useRegisterOrConstantAtStart(ins->string()),
3967 useRegisterAtStart(ins->pattern()),
3968 useRegisterOrConstantAtStart(ins->replacement()));
3969 defineReturn(lir, ins);
3970 assignSafepoint(lir, ins);
3971 }
3972
3973 void LIRGenerator::visitBinaryCache(MBinaryCache* ins) {
3974 MDefinition* lhs = ins->getOperand(0);
3975 MDefinition* rhs = ins->getOperand(1);
3976
3977 MOZ_ASSERT(ins->type() == MIRType::Value || ins->type() == MIRType::Boolean);
3978 LInstruction* lir;
3979 if (ins->type() == MIRType::Value) {
3980 LBinaryValueCache* valueLir = new (alloc()) LBinaryValueCache(
3981 useBox(lhs), useBox(rhs), tempFixed(FloatReg0), tempFixed(FloatReg1));
3982 defineBox(valueLir, ins);
3983 lir = valueLir;
3984 } else {
3985 MOZ_ASSERT(ins->type() == MIRType::Boolean);
3986 LBinaryBoolCache* boolLir = new (alloc()) LBinaryBoolCache(
3987 useBox(lhs), useBox(rhs), tempFixed(FloatReg0), tempFixed(FloatReg1));
3988 define(boolLir, ins);
3989 lir = boolLir;
3990 }
3991 assignSafepoint(lir, ins);
3992 }
3993
3994 void LIRGenerator::visitUnaryCache(MUnaryCache* ins) {
3995 MDefinition* input = ins->getOperand(0);
3996 MOZ_ASSERT(ins->type() == MIRType::Value);
3997
3998 LUnaryCache* lir = new (alloc()) LUnaryCache(useBox(input));
3999 defineBox(lir, ins);
4000 assignSafepoint(lir, ins);
4001 }
4002
4003 void LIRGenerator::visitModuleMetadata(MModuleMetadata* ins) {
4004 LModuleMetadata* lir = new (alloc()) LModuleMetadata();
4005 defineReturn(lir, ins);
4006 assignSafepoint(lir, ins);
4007 }
4008
4009 void LIRGenerator::visitDynamicImport(MDynamicImport* ins) {
4010 LDynamicImport* lir = new (alloc()) LDynamicImport(
4011 useBoxAtStart(ins->specifier()), useBoxAtStart(ins->options()));
4012 defineReturn(lir, ins);
4013 assignSafepoint(lir, ins);
4014 }
4015
4016 void LIRGenerator::visitLambda(MLambda* ins) {
4017 MOZ_ASSERT(ins->environmentChain()->type() == MIRType::Object);
4018
4019 auto* lir =
4020 new (alloc()) LLambda(useRegister(ins->environmentChain()), temp());
4021 define(lir, ins);
4022 assignSafepoint(lir, ins);
4023 }
4024
4025 void LIRGenerator::visitFunctionWithProto(MFunctionWithProto* ins) {
4026 MOZ_ASSERT(ins->environmentChain()->type() == MIRType::Object);
4027 MOZ_ASSERT(ins->prototype()->type() == MIRType::Object);
4028
4029 auto* lir = new (alloc())
4030 LFunctionWithProto(useRegisterAtStart(ins->environmentChain()),
4031 useRegisterAtStart(ins->prototype()));
4032 defineReturn(lir, ins);
4033 assignSafepoint(lir, ins);
4034 }
4035
4036 void LIRGenerator::visitSetFunName(MSetFunName* ins) {
4037 MOZ_ASSERT(ins->fun()->type() == MIRType::Object);
4038 MOZ_ASSERT(ins->name()->type() == MIRType::Value);
4039
4040 LSetFunName* lir = new (alloc())
4041 LSetFunName(useRegisterAtStart(ins->fun()), useBoxAtStart(ins->name()));
4042 add(lir, ins);
4043 assignSafepoint(lir, ins);
4044 }
4045
4046 void LIRGenerator::visitNewLexicalEnvironmentObject(
4047 MNewLexicalEnvironmentObject* ins) {
4048 auto* lir = new (alloc()) LNewLexicalEnvironmentObject(temp());
4049
4050 define(lir, ins);
4051 assignSafepoint(lir, ins);
4052 }
4053
4054 void LIRGenerator::visitNewClassBodyEnvironmentObject(
4055 MNewClassBodyEnvironmentObject* ins) {
4056 auto* lir = new (alloc()) LNewClassBodyEnvironmentObject(temp());
4057
4058 define(lir, ins);
4059 assignSafepoint(lir, ins);
4060 }
4061
4062 void LIRGenerator::visitNewVarEnvironmentObject(MNewVarEnvironmentObject* ins) {
4063 auto* lir = new (alloc()) LNewVarEnvironmentObject(temp());
4064
4065 define(lir, ins);
4066 assignSafepoint(lir, ins);
4067 }
4068
4069 void LIRGenerator::visitKeepAliveObject(MKeepAliveObject* ins) {
4070 MDefinition* obj = ins->object();
4071 MOZ_ASSERT(obj->type() == MIRType::Object);
4072
4073 add(new (alloc()) LKeepAliveObject(useKeepalive(obj)), ins);
4074 }
4075
4076 void LIRGenerator::visitDebugEnterGCUnsafeRegion(
4077 MDebugEnterGCUnsafeRegion* ins) {
4078 add(new (alloc()) LDebugEnterGCUnsafeRegion(temp()), ins);
4079 }
4080
4081 void LIRGenerator::visitDebugLeaveGCUnsafeRegion(
4082 MDebugLeaveGCUnsafeRegion* ins) {
4083 add(new (alloc()) LDebugLeaveGCUnsafeRegion(temp()), ins);
4084 }
4085
4086 void LIRGenerator::visitSlots(MSlots* ins) {
4087 define(new (alloc()) LSlots(useRegisterAtStart(ins->object())), ins);
4088 }
4089
4090 void LIRGenerator::visitElements(MElements* ins) {
4091 define(new (alloc()) LElements(useRegisterAtStart(ins->object())), ins);
4092 }
4093
4094 void LIRGenerator::visitLoadDynamicSlot(MLoadDynamicSlot* ins) {
4095 MOZ_ASSERT(ins->type() == MIRType::Value);
4096 if (ins->usedAsPropertyKey()) {
4097 auto* lir = new (alloc())
4098 LLoadDynamicSlotAndAtomize(useRegister(ins->slots()), temp());
4099 defineBox(lir, ins);
4100 assignSafepoint(lir, ins);
4101 } else {
4102 defineBox(new (alloc()) LLoadDynamicSlotV(useRegisterAtStart(ins->slots())),
4103 ins);
4104 }
4105 }
4106
4107 void LIRGenerator::visitFunctionEnvironment(MFunctionEnvironment* ins) {
4108 define(new (alloc())
4109 LFunctionEnvironment(useRegisterAtStart(ins->function())),
4110 ins);
4111 }
4112
4113 void LIRGenerator::visitHomeObject(MHomeObject* ins) {
4114 define(new (alloc()) LHomeObject(useRegisterAtStart(ins->function())), ins);
4115 }
4116
4117 void LIRGenerator::visitHomeObjectSuperBase(MHomeObjectSuperBase* ins) {
4118 MOZ_ASSERT(ins->homeObject()->type() == MIRType::Object);
4119 MOZ_ASSERT(ins->type() == MIRType::Value);
4120
4121 auto lir =
4122 new (alloc()) LHomeObjectSuperBase(useRegisterAtStart(ins->homeObject()));
4123 defineBox(lir, ins);
4124 }
4125
4126 void LIRGenerator::visitInterruptCheck(MInterruptCheck* ins) {
4127 LInstruction* lir = new (alloc()) LInterruptCheck();
4128 add(lir, ins);
4129 assignSafepoint(lir, ins);
4130 }
4131
4132 void LIRGenerator::visitWasmInterruptCheck(MWasmInterruptCheck* ins) {
4133 auto* lir =
4134 new (alloc()) LWasmInterruptCheck(useRegisterAtStart(ins->instance()));
4135 add(lir, ins);
4136 assignWasmSafepoint(lir);
4137 }
4138
4139 void LIRGenerator::visitWasmTrap(MWasmTrap* ins) {
4140 add(new (alloc()) LWasmTrap, ins);
4141 }
4142
4143 void LIRGenerator::visitWasmRefAsNonNull(MWasmRefAsNonNull* ins) {
4144 defineReuseInput(
4145 new (alloc()) LWasmRefAsNonNull(useRegisterAtStart(ins->ref())), ins, 0);
4146 }
4147
4148 void LIRGenerator::visitReinterpretCast(MReinterpretCast* ins) {
4149 if (ins->type() == MIRType::Int64) {
4150 defineInt64(new (alloc())
4151 LReinterpretCastToI64(useRegisterAtStart(ins->input())),
4152 ins);
4153 } else if (ins->input()->type() == MIRType::Int64) {
4154 define(new (alloc())
4155 LReinterpretCastFromI64(useInt64RegisterAtStart(ins->input())),
4156 ins);
4157 } else {
4158 define(new (alloc()) LReinterpretCast(useRegisterAtStart(ins->input())),
4159 ins);
4160 }
4161 }
4162
4163 void LIRGenerator::visitStoreDynamicSlot(MStoreDynamicSlot* ins) {
4164 LInstruction* lir;
4165
4166 switch (ins->value()->type()) {
4167 case MIRType::Value:
4168 lir = new (alloc())
4169 LStoreDynamicSlotV(useRegister(ins->slots()), useBox(ins->value()));
4170 add(lir, ins);
4171 break;
4172
4173 case MIRType::Double:
4174 add(new (alloc()) LStoreDynamicSlotT(useRegister(ins->slots()),
4175 useRegister(ins->value())),
4176 ins);
4177 break;
4178
4179 case MIRType::Float32:
4180 MOZ_CRASH("Float32 shouldn't be stored in a slot.");
4181
4182 default:
4183 add(new (alloc()) LStoreDynamicSlotT(useRegister(ins->slots()),
4184 useRegisterOrConstant(ins->value())),
4185 ins);
4186 break;
4187 }
4188 }
4189
4190 // Returns true iff |def| is a constant that's either not a GC thing or is not
4191 // allocated in the nursery.
4192 static bool IsNonNurseryConstant(MDefinition* def) {
4193 if (!def->isConstant()) {
4194 return false;
4195 }
4196 Value v = def->toConstant()->toJSValue();
4197 return !v.isGCThing() || !IsInsideNursery(v.toGCThing());
4198 }
4199
4200 void LIRGenerator::visitPostWriteBarrier(MPostWriteBarrier* ins) {
4201 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4202
4203 // LPostWriteBarrier assumes that if it has a constant object then that
4204 // object is tenured, and does not need to be tested for being in the
4205 // nursery. Ensure that assumption holds by lowering constant nursery
4206 // objects to a register.
4207 bool useConstantObject = IsNonNurseryConstant(ins->object());
4208
4209 switch (ins->value()->type()) {
4210 case MIRType::Object: {
4211 LDefinition tmp =
4212 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4213 LPostWriteBarrierO* lir = new (alloc())
4214 LPostWriteBarrierO(useConstantObject ? useOrConstant(ins->object())
4215 : useRegister(ins->object()),
4216 useRegister(ins->value()), tmp);
4217 add(lir, ins);
4218 assignSafepoint(lir, ins);
4219 break;
4220 }
4221 case MIRType::String: {
4222 LDefinition tmp =
4223 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4224 LPostWriteBarrierS* lir = new (alloc())
4225 LPostWriteBarrierS(useConstantObject ? useOrConstant(ins->object())
4226 : useRegister(ins->object()),
4227 useRegister(ins->value()), tmp);
4228 add(lir, ins);
4229 assignSafepoint(lir, ins);
4230 break;
4231 }
4232 case MIRType::BigInt: {
4233 LDefinition tmp =
4234 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4235 auto* lir = new (alloc())
4236 LPostWriteBarrierBI(useConstantObject ? useOrConstant(ins->object())
4237 : useRegister(ins->object()),
4238 useRegister(ins->value()), tmp);
4239 add(lir, ins);
4240 assignSafepoint(lir, ins);
4241 break;
4242 }
4243 case MIRType::Value: {
4244 LDefinition tmp =
4245 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4246 LPostWriteBarrierV* lir = new (alloc())
4247 LPostWriteBarrierV(useConstantObject ? useOrConstant(ins->object())
4248 : useRegister(ins->object()),
4249 useBox(ins->value()), tmp);
4250 add(lir, ins);
4251 assignSafepoint(lir, ins);
4252 break;
4253 }
4254 default:
4255 // Currently, only objects and strings can be in the nursery. Other
4256 // instruction types cannot hold nursery pointers.
4257 break;
4258 }
4259 }
4260
4261 void LIRGenerator::visitPostWriteElementBarrier(MPostWriteElementBarrier* ins) {
4262 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4263 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4264
4265 // LPostWriteElementBarrier assumes that if it has a constant object then that
4266 // object is tenured, and does not need to be tested for being in the
4267 // nursery. Ensure that assumption holds by lowering constant nursery
4268 // objects to a register.
4269 bool useConstantObject =
4270 ins->object()->isConstant() &&
4271 !IsInsideNursery(&ins->object()->toConstant()->toObject());
4272
4273 switch (ins->value()->type()) {
4274 case MIRType::Object: {
4275 LDefinition tmp =
4276 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4277 LPostWriteElementBarrierO* lir = new (alloc()) LPostWriteElementBarrierO(
4278 useConstantObject ? useOrConstant(ins->object())
4279 : useRegister(ins->object()),
4280 useRegister(ins->value()), useRegister(ins->index()), tmp);
4281 add(lir, ins);
4282 assignSafepoint(lir, ins);
4283 break;
4284 }
4285 case MIRType::String: {
4286 LDefinition tmp =
4287 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4288 LPostWriteElementBarrierS* lir = new (alloc()) LPostWriteElementBarrierS(
4289 useConstantObject ? useOrConstant(ins->object())
4290 : useRegister(ins->object()),
4291 useRegister(ins->value()), useRegister(ins->index()), tmp);
4292 add(lir, ins);
4293 assignSafepoint(lir, ins);
4294 break;
4295 }
4296 case MIRType::BigInt: {
4297 LDefinition tmp =
4298 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4299 auto* lir = new (alloc()) LPostWriteElementBarrierBI(
4300 useConstantObject ? useOrConstant(ins->object())
4301 : useRegister(ins->object()),
4302 useRegister(ins->value()), useRegister(ins->index()), tmp);
4303 add(lir, ins);
4304 assignSafepoint(lir, ins);
4305 break;
4306 }
4307 case MIRType::Value: {
4308 LDefinition tmp =
4309 needTempForPostBarrier() ? temp() : LDefinition::BogusTemp();
4310 LPostWriteElementBarrierV* lir = new (alloc()) LPostWriteElementBarrierV(
4311 useConstantObject ? useOrConstant(ins->object())
4312 : useRegister(ins->object()),
4313 useRegister(ins->index()), useBox(ins->value()), tmp);
4314 add(lir, ins);
4315 assignSafepoint(lir, ins);
4316 break;
4317 }
4318 default:
4319 // Currently, only objects, strings, and bigints can be in the nursery.
4320 // Other instruction types cannot hold nursery pointers.
4321 break;
4322 }
4323 }
4324
4325 void LIRGenerator::visitAssertCanElidePostWriteBarrier(
4326 MAssertCanElidePostWriteBarrier* ins) {
4327 auto* lir = new (alloc()) LAssertCanElidePostWriteBarrier(
4328 useRegister(ins->object()), useBox(ins->value()), temp());
4329 add(lir, ins);
4330 }
4331
4332 void LIRGenerator::visitArrayLength(MArrayLength* ins) {
4333 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4334 auto* lir = new (alloc()) LArrayLength(useRegisterAtStart(ins->elements()));
4335 assignSnapshot(lir, ins->bailoutKind());
4336 define(lir, ins);
4337 }
4338
4339 void LIRGenerator::visitSetArrayLength(MSetArrayLength* ins) {
4340 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4341 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4342
4343 MOZ_ASSERT(ins->index()->isConstant());
4344 add(new (alloc()) LSetArrayLength(useRegister(ins->elements()),
4345 useRegisterOrConstant(ins->index())),
4346 ins);
4347 }
4348
4349 void LIRGenerator::visitFunctionLength(MFunctionLength* ins) {
4350 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
4351
4352 auto* lir = new (alloc()) LFunctionLength(useRegister(ins->function()));
4353 assignSnapshot(lir, ins->bailoutKind());
4354 define(lir, ins);
4355 }
4356
4357 void LIRGenerator::visitFunctionName(MFunctionName* ins) {
4358 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
4359
4360 auto* lir = new (alloc()) LFunctionName(useRegister(ins->function()));
4361 assignSnapshot(lir, ins->bailoutKind());
4362 define(lir, ins);
4363 }
4364
4365 void LIRGenerator::visitGetNextEntryForIterator(MGetNextEntryForIterator* ins) {
4366 MOZ_ASSERT(ins->iter()->type() == MIRType::Object);
4367 MOZ_ASSERT(ins->result()->type() == MIRType::Object);
4368 auto lir = new (alloc()) LGetNextEntryForIterator(useRegister(ins->iter()),
4369 useRegister(ins->result()),
4370 temp(), temp(), temp());
4371 define(lir, ins);
4372 }
4373
4374 static auto SynchronizeLoad(MemoryBarrierRequirement requiresBarrier) {
4375 if (requiresBarrier == MemoryBarrierRequirement::Required) {
4376 return Synchronization::Load();
4377 }
4378 return Synchronization::None();
4379 }
4380
4381 static auto SynchronizeStore(MemoryBarrierRequirement requiresBarrier) {
4382 if (requiresBarrier == MemoryBarrierRequirement::Required) {
4383 return Synchronization::Store();
4384 }
4385 return Synchronization::None();
4386 }
4387
4388 void LIRGenerator::visitArrayBufferByteLength(MArrayBufferByteLength* ins) {
4389 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4390 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4391
4392 auto* lir =
4393 new (alloc()) LArrayBufferByteLength(useRegisterAtStart(ins->object()));
4394 define(lir, ins);
4395 }
4396
4397 void LIRGenerator::visitArrayBufferViewLength(MArrayBufferViewLength* ins) {
4398 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4399 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4400
4401 auto* lir =
4402 new (alloc()) LArrayBufferViewLength(useRegisterAtStart(ins->object()));
4403 define(lir, ins);
4404 }
4405
4406 void LIRGenerator::visitArrayBufferViewByteOffset(
4407 MArrayBufferViewByteOffset* ins) {
4408 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4409 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4410
4411 auto* lir = new (alloc())
4412 LArrayBufferViewByteOffset(useRegisterAtStart(ins->object()));
4413 define(lir, ins);
4414 }
4415
4416 void LIRGenerator::visitArrayBufferViewElements(MArrayBufferViewElements* ins) {
4417 MOZ_ASSERT(ins->type() == MIRType::Elements);
4418 define(new (alloc())
4419 LArrayBufferViewElements(useRegisterAtStart(ins->object())),
4420 ins);
4421 }
4422
4423 void LIRGenerator::visitTypedArrayElementSize(MTypedArrayElementSize* ins) {
4424 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4425 define(new (alloc())
4426 LTypedArrayElementSize(useRegisterAtStart(ins->object())),
4427 ins);
4428 }
4429
4430 void LIRGenerator::visitResizableTypedArrayLength(
4431 MResizableTypedArrayLength* ins) {
4432 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4433 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4434
4435 auto sync = SynchronizeLoad(ins->requiresMemoryBarrier());
4436 auto* lir = new (alloc())
4437 LResizableTypedArrayLength(useRegister(ins->object()), temp(), sync);
4438 define(lir, ins);
4439 }
4440
4441 void LIRGenerator::visitResizableTypedArrayByteOffsetMaybeOutOfBounds(
4442 MResizableTypedArrayByteOffsetMaybeOutOfBounds* ins) {
4443 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4444 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4445
4446 auto* lir = new (alloc()) LResizableTypedArrayByteOffsetMaybeOutOfBounds(
4447 useRegister(ins->object()), temp());
4448 define(lir, ins);
4449 }
4450
4451 void LIRGenerator::visitResizableDataViewByteLength(
4452 MResizableDataViewByteLength* ins) {
4453 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4454 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4455
4456 auto sync = SynchronizeLoad(ins->requiresMemoryBarrier());
4457 auto* lir = new (alloc())
4458 LResizableDataViewByteLength(useRegister(ins->object()), temp(), sync);
4459 define(lir, ins);
4460 }
4461
4462 void LIRGenerator::visitGrowableSharedArrayBufferByteLength(
4463 MGrowableSharedArrayBufferByteLength* ins) {
4464 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4465 MOZ_ASSERT(ins->type() == MIRType::IntPtr);
4466
4467 auto* lir = new (alloc())
4468 LGrowableSharedArrayBufferByteLength(useRegisterAtStart(ins->object()));
4469 define(lir, ins);
4470 }
4471
4472 void LIRGenerator::visitGuardResizableArrayBufferViewInBounds(
4473 MGuardResizableArrayBufferViewInBounds* ins) {
4474 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4475
4476 auto* lir = new (alloc()) LGuardResizableArrayBufferViewInBounds(
4477 useRegister(ins->object()), temp());
4478 assignSnapshot(lir, ins->bailoutKind());
4479 add(lir, ins);
4480 redefine(ins, ins->object());
4481 }
4482
4483 void LIRGenerator::visitGuardResizableArrayBufferViewInBoundsOrDetached(
4484 MGuardResizableArrayBufferViewInBoundsOrDetached* ins) {
4485 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4486
4487 auto* lir = new (alloc()) LGuardResizableArrayBufferViewInBoundsOrDetached(
4488 useRegister(ins->object()), temp());
4489 assignSnapshot(lir, ins->bailoutKind());
4490 add(lir, ins);
4491 redefine(ins, ins->object());
4492 }
4493
4494 void LIRGenerator::visitGuardHasAttachedArrayBuffer(
4495 MGuardHasAttachedArrayBuffer* ins) {
4496 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4497
4498 auto* lir = new (alloc())
4499 LGuardHasAttachedArrayBuffer(useRegister(ins->object()), temp());
4500 assignSnapshot(lir, ins->bailoutKind());
4501 add(lir, ins);
4502 redefine(ins, ins->object());
4503 }
4504
4505 void LIRGenerator::visitGuardNumberToIntPtrIndex(
4506 MGuardNumberToIntPtrIndex* ins) {
4507 MDefinition* input = ins->input();
4508 MOZ_ASSERT(input->type() == MIRType::Double);
4509
4510 auto* lir = new (alloc()) LGuardNumberToIntPtrIndex(useRegister(input));
4511 if (!ins->supportOOB()) {
4512 assignSnapshot(lir, ins->bailoutKind());
4513 }
4514 define(lir, ins);
4515 }
4516
4517 void LIRGenerator::visitInitializedLength(MInitializedLength* ins) {
4518 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4519 define(new (alloc()) LInitializedLength(useRegisterAtStart(ins->elements())),
4520 ins);
4521 }
4522
4523 void LIRGenerator::visitSetInitializedLength(MSetInitializedLength* ins) {
4524 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4525 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4526
4527 MOZ_ASSERT(ins->index()->isConstant());
4528 add(new (alloc()) LSetInitializedLength(useRegister(ins->elements()),
4529 useRegisterOrConstant(ins->index())),
4530 ins);
4531 }
4532
4533 void LIRGenerator::visitNot(MNot* ins) {
4534 MDefinition* op = ins->input();
4535
4536 // String is converted to length of string in the type analysis phase (see
4537 // TestPolicy).
4538 MOZ_ASSERT(op->type() != MIRType::String);
4539
4540 // - boolean: x xor 1
4541 // - int32: LCompare(x, 0)
4542 // - double: LCompare(x, 0)
4543 // - null or undefined: true
4544 // - symbol: false
4545 // - bigint: LNotBI(x)
4546 // - object: false if it never emulates undefined, else LNotO(x)
4547 switch (op->type()) {
4548 case MIRType::Boolean: {
4549 MConstant* cons = MConstant::New(alloc(), Int32Value(1));
4550 ins->block()->insertBefore(ins, cons);
4551 lowerForALU(new (alloc()) LBitOpI(JSOp::BitXor), ins, op, cons);
4552 break;
4553 }
4554 case MIRType::Int32:
4555 define(new (alloc()) LNotI(useRegisterAtStart(op)), ins);
4556 break;
4557 case MIRType::IntPtr:
4558 define(new (alloc()) LNotIPtr(useRegisterAtStart(op)), ins);
4559 break;
4560 case MIRType::Int64:
4561 define(new (alloc()) LNotI64(useInt64RegisterAtStart(op)), ins);
4562 break;
4563 case MIRType::Double:
4564 define(new (alloc()) LNotD(useRegister(op)), ins);
4565 break;
4566 case MIRType::Float32:
4567 define(new (alloc()) LNotF(useRegister(op)), ins);
4568 break;
4569 case MIRType::Undefined:
4570 case MIRType::Null:
4571 define(new (alloc()) LInteger(1), ins);
4572 break;
4573 case MIRType::Symbol:
4574 define(new (alloc()) LInteger(0), ins);
4575 break;
4576 case MIRType::BigInt:
4577 define(new (alloc()) LNotBI(useRegisterAtStart(op)), ins);
4578 break;
4579 case MIRType::Object:
4580 define(new (alloc()) LNotO(useRegister(op)), ins);
4581 break;
4582 case MIRType::Value: {
4583 auto* lir = new (alloc()) LNotV(useBox(op), tempDouble(), tempToUnbox());
4584 define(lir, ins);
4585 break;
4586 }
4587
4588 default:
4589 MOZ_CRASH("Unexpected MIRType.");
4590 }
4591 }
4592
4593 void LIRGenerator::visitBoundsCheck(MBoundsCheck* ins) {
4594 MOZ_ASSERT(ins->type() == MIRType::Int32 || ins->type() == MIRType::IntPtr);
4595 MOZ_ASSERT(ins->index()->type() == ins->type());
4596 MOZ_ASSERT(ins->length()->type() == ins->type());
4597
4598 if (!ins->fallible()) {
4599 return;
4600 }
4601
4602 LInstruction* check;
4603 if (ins->minimum() || ins->maximum()) {
4604 check = new (alloc())
4605 LBoundsCheckRange(useRegisterOrInt32Constant(ins->index()),
4606 useAny(ins->length()), temp());
4607 } else {
4608 check = new (alloc()) LBoundsCheck(useRegisterOrInt32Constant(ins->index()),
4609 useAnyOrInt32Constant(ins->length()));
4610 }
4611 assignSnapshot(check, ins->bailoutKind());
4612 add(check, ins);
4613 }
4614
4615 void LIRGenerator::visitSpectreMaskIndex(MSpectreMaskIndex* ins) {
4616 MOZ_ASSERT(ins->type() == MIRType::Int32 || ins->type() == MIRType::IntPtr);
4617 MOZ_ASSERT(ins->index()->type() == ins->type());
4618 MOZ_ASSERT(ins->length()->type() == ins->type());
4619
4620 auto* lir = new (alloc())
4621 LSpectreMaskIndex(useRegister(ins->index()), useAny(ins->length()));
4622 define(lir, ins);
4623 }
4624
4625 void LIRGenerator::visitBoundsCheckLower(MBoundsCheckLower* ins) {
4626 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4627
4628 if (!ins->fallible()) {
4629 return;
4630 }
4631
4632 LInstruction* check =
4633 new (alloc()) LBoundsCheckLower(useRegister(ins->index()));
4634 assignSnapshot(check, ins->bailoutKind());
4635 add(check, ins);
4636 }
4637
4638 void LIRGenerator::visitInArray(MInArray* ins) {
4639 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4640 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4641 MOZ_ASSERT(ins->initLength()->type() == MIRType::Int32);
4642 MOZ_ASSERT(ins->type() == MIRType::Boolean);
4643
4644 auto* lir = new (alloc()) LInArray(useRegister(ins->elements()),
4645 useRegisterOrConstant(ins->index()),
4646 useRegister(ins->initLength()));
4647 if (ins->needsNegativeIntCheck()) {
4648 assignSnapshot(lir, ins->bailoutKind());
4649 }
4650 define(lir, ins);
4651 }
4652
4653 void LIRGenerator::visitGuardElementNotHole(MGuardElementNotHole* ins) {
4654 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4655 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4656
4657 auto* guard = new (alloc())
4658 LGuardElementNotHole(useRegisterAtStart(ins->elements()),
4659 useRegisterOrConstantAtStart(ins->index()));
4660 assignSnapshot(guard, ins->bailoutKind());
4661 add(guard, ins);
4662 }
4663
4664 void LIRGenerator::visitLoadElement(MLoadElement* ins) {
4665 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4666 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4667 MOZ_ASSERT(ins->type() == MIRType::Value);
4668
4669 auto* lir = new (alloc()) LLoadElementV(useRegister(ins->elements()),
4670 useRegisterOrConstant(ins->index()));
4671 assignSnapshot(lir, ins->bailoutKind());
4672 defineBox(lir, ins);
4673 }
4674
4675 void LIRGenerator::visitLoadElementHole(MLoadElementHole* ins) {
4676 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4677 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4678 MOZ_ASSERT(ins->initLength()->type() == MIRType::Int32);
4679 MOZ_ASSERT(ins->type() == MIRType::Value);
4680
4681 LLoadElementHole* lir = new (alloc())
4682 LLoadElementHole(useRegister(ins->elements()), useRegister(ins->index()),
4683 useRegister(ins->initLength()));
4684 if (ins->needsNegativeIntCheck()) {
4685 assignSnapshot(lir, ins->bailoutKind());
4686 }
4687 defineBox(lir, ins);
4688 }
4689
4690 void LIRGenerator::visitStoreElement(MStoreElement* ins) {
4691 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4692 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4693
4694 const LUse elements = useRegister(ins->elements());
4695 const LAllocation index = useRegisterOrConstant(ins->index());
4696
4697 switch (ins->value()->type()) {
4698 case MIRType::Value: {
4699 LInstruction* lir =
4700 new (alloc()) LStoreElementV(elements, index, useBox(ins->value()));
4701 if (ins->fallible()) {
4702 assignSnapshot(lir, ins->bailoutKind());
4703 }
4704 add(lir, ins);
4705 break;
4706 }
4707
4708 default: {
4709 const LAllocation value = useRegisterOrNonDoubleConstant(ins->value());
4710 LInstruction* lir = new (alloc()) LStoreElementT(elements, index, value);
4711 if (ins->fallible()) {
4712 assignSnapshot(lir, ins->bailoutKind());
4713 }
4714 add(lir, ins);
4715 break;
4716 }
4717 }
4718 }
4719
4720 void LIRGenerator::visitStoreHoleValueElement(MStoreHoleValueElement* ins) {
4721 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4722 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4723
4724 auto* lir = new (alloc()) LStoreHoleValueElement(useRegister(ins->elements()),
4725 useRegister(ins->index()));
4726 add(lir, ins);
4727 }
4728
4729 static bool BoundsCheckNeedsSpectreTemp() {
4730 // On x86, spectreBoundsCheck32 can emit better code if it has a scratch
4731 // register and index masking is enabled.
4732 #ifdef JS_CODEGEN_X86
4733 return JitOptions.spectreIndexMasking;
4734 #else
4735 return false;
4736 #endif
4737 }
4738
4739 void LIRGenerator::visitStoreElementHole(MStoreElementHole* ins) {
4740 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4741 MOZ_ASSERT(ins->index()->type() == MIRType::Int32);
4742
4743 const LUse object = useRegister(ins->object());
4744 const LUse elements = useRegister(ins->elements());
4745 const LAllocation index = useRegister(ins->index());
4746
4747 LInstruction* lir;
4748 switch (ins->value()->type()) {
4749 case MIRType::Value:
4750 lir = new (alloc()) LStoreElementHoleV(object, elements, index,
4751 useBox(ins->value()), temp());
4752 break;
4753
4754 default: {
4755 const LAllocation value = useRegisterOrNonDoubleConstant(ins->value());
4756 lir = new (alloc())
4757 LStoreElementHoleT(object, elements, index, value, temp());
4758 break;
4759 }
4760 }
4761
4762 assignSnapshot(lir, ins->bailoutKind());
4763 add(lir, ins);
4764 assignSafepoint(lir, ins);
4765 }
4766
4767 void LIRGenerator::visitEffectiveAddress(MEffectiveAddress* ins) {
4768 define(new (alloc()) LEffectiveAddress(useRegister(ins->base()),
4769 useRegister(ins->index())),
4770 ins);
4771 }
4772
4773 void LIRGenerator::visitArrayPopShift(MArrayPopShift* ins) {
4774 MOZ_ASSERT(ins->type() == MIRType::Value);
4775
4776 auto* lir =
4777 new (alloc()) LArrayPopShift(useRegister(ins->object()), temp(), temp());
4778 assignSnapshot(lir, ins->bailoutKind());
4779 defineBox(lir, ins);
4780
4781 if (ins->mode() == MArrayPopShift::Shift) {
4782 assignSafepoint(lir, ins);
4783 }
4784 }
4785
4786 void LIRGenerator::visitArrayPush(MArrayPush* ins) {
4787 MOZ_ASSERT(ins->type() == MIRType::Int32);
4788 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
4789
4790 LUse object = useRegister(ins->object());
4791
4792 LDefinition spectreTemp =
4793 BoundsCheckNeedsSpectreTemp() ? temp() : LDefinition::BogusTemp();
4794
4795 auto* lir = new (alloc())
4796 LArrayPush(object, useBox(ins->value()), temp(), spectreTemp);
4797 // We will bailout before pushing if the length would overflow INT32_MAX.
4798 assignSnapshot(lir, ins->bailoutKind());
4799 define(lir, ins);
4800 assignSafepoint(lir, ins);
4801 }
4802
4803 void LIRGenerator::visitArraySlice(MArraySlice* ins) {
4804 MOZ_ASSERT(ins->type() == MIRType::Object);
4805 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4806 MOZ_ASSERT(ins->begin()->type() == MIRType::Int32);
4807 MOZ_ASSERT(ins->end()->type() == MIRType::Int32);
4808
4809 LArraySlice* lir = new (alloc()) LArraySlice(
4810 useRegisterAtStart(ins->object()), useRegisterAtStart(ins->begin()),
4811 useRegisterAtStart(ins->end()), tempFixed(CallTempReg0),
4812 tempFixed(CallTempReg1));
4813 assignSnapshot(lir, ins->bailoutKind());
4814 defineReturn(lir, ins);
4815 assignSafepoint(lir, ins);
4816 }
4817
4818 void LIRGenerator::visitArgumentsSlice(MArgumentsSlice* ins) {
4819 MOZ_ASSERT(ins->type() == MIRType::Object);
4820 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4821 MOZ_ASSERT(ins->begin()->type() == MIRType::Int32);
4822 MOZ_ASSERT(ins->end()->type() == MIRType::Int32);
4823
4824 auto* lir = new (alloc()) LArgumentsSlice(
4825 useRegisterAtStart(ins->object()), useRegisterAtStart(ins->begin()),
4826 useRegisterAtStart(ins->end()), tempFixed(CallTempReg0),
4827 tempFixed(CallTempReg1));
4828 defineReturn(lir, ins);
4829 assignSafepoint(lir, ins);
4830 }
4831
4832 void LIRGenerator::visitFrameArgumentsSlice(MFrameArgumentsSlice* ins) {
4833 MOZ_ASSERT(ins->type() == MIRType::Object);
4834 MOZ_ASSERT(ins->begin()->type() == MIRType::Int32);
4835 MOZ_ASSERT(ins->count()->type() == MIRType::Int32);
4836
4837 auto* lir = new (alloc()) LFrameArgumentsSlice(
4838 useRegister(ins->begin()), useRegister(ins->count()), temp());
4839 define(lir, ins);
4840 assignSafepoint(lir, ins);
4841 }
4842
4843 void LIRGenerator::visitInlineArgumentsSlice(MInlineArgumentsSlice* ins) {
4844 LAllocation begin = useRegisterOrConstant(ins->begin());
4845 LAllocation count = useRegisterOrConstant(ins->count());
4846 uint32_t numActuals = ins->numActuals();
4847 uint32_t numOperands =
4848 numActuals * BOX_PIECES + LInlineArgumentsSlice::NumNonArgumentOperands;
4849
4850 auto* lir = allocateVariadic<LInlineArgumentsSlice>(numOperands, temp());
4851 if (!lir) {
4852 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitInlineArgumentsSlice");
4853 return;
4854 }
4855
4856 lir->setOperand(LInlineArgumentsSlice::Begin, begin);
4857 lir->setOperand(LInlineArgumentsSlice::Count, count);
4858 for (uint32_t i = 0; i < numActuals; i++) {
4859 MDefinition* arg = ins->getArg(i);
4860 uint32_t index = LInlineArgumentsSlice::ArgIndex(i);
4861 lir->setBoxOperand(index,
4862 useBoxOrTypedOrConstant(arg, /*useConstant = */ true));
4863 }
4864 define(lir, ins);
4865 assignSafepoint(lir, ins);
4866 }
4867
4868 void LIRGenerator::visitNormalizeSliceTerm(MNormalizeSliceTerm* ins) {
4869 MOZ_ASSERT(ins->type() == MIRType::Int32);
4870 MOZ_ASSERT(ins->value()->type() == MIRType::Int32);
4871 MOZ_ASSERT(ins->length()->type() == MIRType::Int32);
4872
4873 auto* lir = new (alloc()) LNormalizeSliceTerm(useRegister(ins->value()),
4874 useRegister(ins->length()));
4875 define(lir, ins);
4876 }
4877
4878 void LIRGenerator::visitArrayJoin(MArrayJoin* ins) {
4879 MOZ_ASSERT(ins->type() == MIRType::String);
4880 MOZ_ASSERT(ins->array()->type() == MIRType::Object);
4881 MOZ_ASSERT(ins->separator()->type() == MIRType::String);
4882
4883 auto* lir = new (alloc())
4884 LArrayJoin(useRegisterAtStart(ins->array()),
4885 useRegisterAtStart(ins->separator()), tempFixed(CallTempReg0));
4886 defineReturn(lir, ins);
4887 assignSafepoint(lir, ins);
4888 }
4889
4890 void LIRGenerator::visitObjectKeys(MObjectKeys* ins) {
4891 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4892 MOZ_ASSERT(ins->type() == MIRType::Object);
4893
4894 auto* lir = new (alloc()) LObjectKeys(useRegisterAtStart(ins->object()));
4895 defineReturn(lir, ins);
4896 assignSafepoint(lir, ins);
4897 }
4898
4899 void LIRGenerator::visitObjectKeysLength(MObjectKeysLength* ins) {
4900 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
4901 MOZ_ASSERT(ins->type() == MIRType::Int32);
4902
4903 auto* lir =
4904 new (alloc()) LObjectKeysLength(useRegisterAtStart(ins->object()));
4905 defineReturn(lir, ins);
4906 assignSafepoint(lir, ins);
4907 }
4908
4909 void LIRGenerator::visitStringSplit(MStringSplit* ins) {
4910 MOZ_ASSERT(ins->type() == MIRType::Object);
4911 MOZ_ASSERT(ins->string()->type() == MIRType::String);
4912 MOZ_ASSERT(ins->separator()->type() == MIRType::String);
4913
4914 LStringSplit* lir = new (alloc()) LStringSplit(
4915 useRegisterAtStart(ins->string()), useRegisterAtStart(ins->separator()));
4916 defineReturn(lir, ins);
4917 assignSafepoint(lir, ins);
4918 }
4919
4920 void LIRGenerator::visitLoadUnboxedScalar(MLoadUnboxedScalar* ins) {
4921 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4922 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
4923 MOZ_ASSERT(IsNumberType(ins->type()));
4924
4925 auto sync = SynchronizeLoad(ins->requiresMemoryBarrier());
4926
4927 if (Scalar::isBigIntType(ins->storageType()) && !sync.isNone()) {
4928 lowerAtomicLoad64(ins);
4929 return;
4930 }
4931
4932 const LUse elements = useRegister(ins->elements());
4933 const LAllocation index = useRegisterOrIndexConstant(
4934 ins->index(), ins->storageType(), ins->offsetAdjustment());
4935
4936 if (Scalar::isBigIntType(ins->storageType())) {
4937 MOZ_ASSERT(ins->type() == MIRType::Int64);
4938
4939 auto* lir = new (alloc()) LLoadUnboxedInt64(elements, index);
4940 defineInt64(lir, ins);
4941 return;
4942 }
4943
4944 // NOTE: the generated code must match the assembly code in gen_load in
4945 // GenerateAtomicOperations.py
4946 if (!sync.isNone()) {
4947 LMemoryBarrier* fence = new (alloc()) LMemoryBarrier(sync.barrierBefore);
4948 add(fence, ins);
4949 }
4950
4951 // We need a temp register for Uint32Array with known double result and for
4952 // Float16Array.
4953 LDefinition temp1 = LDefinition::BogusTemp();
4954 if ((ins->storageType() == Scalar::Uint32 &&
4955 IsFloatingPointType(ins->type())) ||
4956 ins->storageType() == Scalar::Float16) {
4957 temp1 = temp();
4958 }
4959
4960 // Additional temp when Float16 to Float32 conversion requires a call.
4961 LDefinition temp2 = LDefinition::BogusTemp();
4962 if (MacroAssembler::LoadRequiresCall(ins->storageType())) {
4963 temp2 = temp();
4964 }
4965
4966 auto* lir = new (alloc()) LLoadUnboxedScalar(elements, index, temp1, temp2);
4967 if (ins->fallible()) {
4968 assignSnapshot(lir, ins->bailoutKind());
4969 }
4970 define(lir, ins);
4971
4972 if (MacroAssembler::LoadRequiresCall(ins->storageType())) {
4973 assignSafepoint(lir, ins);
4974 }
4975
4976 if (!sync.isNone()) {
4977 LMemoryBarrier* fence = new (alloc()) LMemoryBarrier(sync.barrierAfter);
4978 add(fence, ins);
4979 }
4980 }
4981
4982 void LIRGenerator::visitLoadDataViewElement(MLoadDataViewElement* ins) {
4983 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
4984 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
4985
4986 MOZ_ASSERT(IsNumberType(ins->type()));
4987
4988 const LUse elements = useRegister(ins->elements());
4989 const LUse index = useRegister(ins->index());
4990 const LAllocation littleEndian = useRegisterOrConstant(ins->littleEndian());
4991
4992 if (Scalar::isBigIntType(ins->storageType())) {
4993 auto* lir =
4994 new (alloc()) LLoadDataViewElement64(elements, index, littleEndian);
4995 defineInt64(lir, ins);
4996 return;
4997 }
4998
4999 // We need a temp register for:
5000 // - Uint32Array with known double result,
5001 // - Float16Array,
5002 // - Float32Array.
5003 LDefinition temp1 = LDefinition::BogusTemp();
5004 if ((ins->storageType() == Scalar::Uint32 &&
5005 IsFloatingPointType(ins->type())) ||
5006 ins->storageType() == Scalar::Float16 ||
5007 ins->storageType() == Scalar::Float32) {
5008 temp1 = temp();
5009 }
5010
5011 // Additional temp when Float16 to Float64 conversion requires a call.
5012 LDefinition temp2 = LDefinition::BogusTemp();
5013 if (MacroAssembler::LoadRequiresCall(ins->storageType())) {
5014 temp2 = temp();
5015 }
5016
5017 // We also need a separate 64-bit temp register for Float64Array.
5018 LInt64Definition temp64 = LInt64Definition::BogusTemp();
5019 if (ins->storageType() == Scalar::Float64) {
5020 temp64 = tempInt64();
5021 }
5022
5023 auto* lir = new (alloc())
5024 LLoadDataViewElement(elements, index, littleEndian, temp1, temp2, temp64);
5025 if (ins->fallible()) {
5026 assignSnapshot(lir, ins->bailoutKind());
5027 }
5028 define(lir, ins);
5029 if (MacroAssembler::LoadRequiresCall(ins->storageType())) {
5030 assignSafepoint(lir, ins);
5031 }
5032 }
5033
5034 void LIRGenerator::visitClampToUint8(MClampToUint8* ins) {
5035 MDefinition* in = ins->input();
5036
5037 switch (in->type()) {
5038 case MIRType::Int32:
5039 defineReuseInput(new (alloc()) LClampIToUint8(useRegisterAtStart(in)),
5040 ins, 0);
5041 break;
5042
5043 case MIRType::Double:
5044 // LClampDToUint8 clobbers its input register. Making it available as
5045 // a temp copy describes this behavior to the register allocator.
5046 define(new (alloc())
5047 LClampDToUint8(useRegisterAtStart(in), tempCopy(in, 0)),
5048 ins);
5049 break;
5050
5051 case MIRType::Value: {
5052 LClampVToUint8* lir =
5053 new (alloc()) LClampVToUint8(useBox(in), tempDouble());
5054 assignSnapshot(lir, ins->bailoutKind());
5055 define(lir, ins);
5056 assignSafepoint(lir, ins);
5057 break;
5058 }
5059
5060 default:
5061 MOZ_CRASH("unexpected type");
5062 }
5063 }
5064
5065 void LIRGenerator::visitLoadTypedArrayElementHole(
5066 MLoadTypedArrayElementHole* ins) {
5067 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
5068 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
5069 MOZ_ASSERT(ins->length()->type() == MIRType::IntPtr);
5070
5071 MOZ_ASSERT(ins->type() == MIRType::Value);
5072
5073 const LUse elements = useRegister(ins->elements());
5074 const LAllocation index = useRegister(ins->index());
5075 const LAllocation length = useRegister(ins->length());
5076
5077 if (!Scalar::isBigIntType(ins->arrayType())) {
5078 LDefinition tempDef = LDefinition::BogusTemp();
5079 if (MacroAssembler::LoadRequiresCall(ins->arrayType())) {
5080 tempDef = temp();
5081 }
5082
5083 auto* lir = new (alloc())
5084 LLoadTypedArrayElementHole(elements, index, length, tempDef);
5085 if (ins->fallible()) {
5086 assignSnapshot(lir, ins->bailoutKind());
5087 }
5088 defineBox(lir, ins);
5089
5090 if (MacroAssembler::LoadRequiresCall(ins->arrayType())) {
5091 assignSafepoint(lir, ins);
5092 }
5093 } else {
5094 #ifdef JS_CODEGEN_X86
5095 LInt64Definition temp64 = LInt64Definition::BogusTemp();
5096 #else
5097 LInt64Definition temp64 = tempInt64();
5098 #endif
5099
5100 auto* lir = new (alloc()) LLoadTypedArrayElementHoleBigInt(
5101 elements, index, length, temp(), temp64);
5102 defineBox(lir, ins);
5103 assignSafepoint(lir, ins);
5104 }
5105 }
5106
5107 void LIRGenerator::visitStoreUnboxedScalar(MStoreUnboxedScalar* ins) {
5108 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
5109 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
5110
5111 if (ins->isFloatWrite()) {
5112 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float16,
5113 ins->value()->type() == MIRType::Float32);
5114 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float32,
5115 ins->value()->type() == MIRType::Float32);
5116 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float64,
5117 ins->value()->type() == MIRType::Double);
5118 } else if (ins->isBigIntWrite()) {
5119 MOZ_ASSERT(ins->value()->type() == MIRType::Int64);
5120 } else {
5121 MOZ_ASSERT(ins->value()->type() == MIRType::Int32);
5122 }
5123
5124 auto sync = SynchronizeStore(ins->requiresMemoryBarrier());
5125
5126 if (ins->isBigIntWrite() && !sync.isNone()) {
5127 lowerAtomicStore64(ins);
5128 return;
5129 }
5130
5131 LUse elements = useRegister(ins->elements());
5132 LAllocation index =
5133 useRegisterOrIndexConstant(ins->index(), ins->writeType());
5134
5135 if (ins->isBigIntWrite()) {
5136 LInt64Allocation value = useInt64RegisterOrConstant(ins->value());
5137 add(new (alloc()) LStoreUnboxedInt64(elements, index, value), ins);
5138 return;
5139 }
5140
5141 // For byte arrays, the value has to be in a byte register on x86.
5142 LAllocation value;
5143 if (ins->isByteWrite()) {
5144 value = useByteOpRegisterOrNonDoubleConstant(ins->value());
5145 } else {
5146 value = useRegisterOrNonDoubleConstant(ins->value());
5147 }
5148
5149 // Optimization opportunity for atomics: on some platforms there
5150 // is a store instruction that incorporates the necessary
5151 // barriers, and we could use that instead of separate barrier and
5152 // store instructions. See bug #1077027.
5153 //
5154 // NOTE: the generated code must match the assembly code in gen_store in
5155 // GenerateAtomicOperations.py
5156 if (!sync.isNone()) {
5157 LMemoryBarrier* fence = new (alloc()) LMemoryBarrier(sync.barrierBefore);
5158 add(fence, ins);
5159 }
5160
5161 // We need a temp register for Float16Array.
5162 LDefinition tempDef = LDefinition::BogusTemp();
5163 if (ins->writeType() == Scalar::Float16) {
5164 tempDef = temp();
5165 }
5166
5167 auto* lir =
5168 new (alloc()) LStoreUnboxedScalar(elements, index, value, tempDef);
5169 add(lir, ins);
5170
5171 if (MacroAssembler::StoreRequiresCall(ins->writeType())) {
5172 assignSafepoint(lir, ins);
5173 }
5174
5175 if (!sync.isNone()) {
5176 LMemoryBarrier* fence = new (alloc()) LMemoryBarrier(sync.barrierAfter);
5177 add(fence, ins);
5178 }
5179 }
5180
5181 void LIRGenerator::visitStoreDataViewElement(MStoreDataViewElement* ins) {
5182 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
5183 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
5184 MOZ_ASSERT(ins->littleEndian()->type() == MIRType::Boolean);
5185
5186 if (ins->isFloatWrite()) {
5187 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float16,
5188 ins->value()->type() == MIRType::Float32);
5189 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float32,
5190 ins->value()->type() == MIRType::Float32);
5191 MOZ_ASSERT_IF(ins->writeType() == Scalar::Float64,
5192 ins->value()->type() == MIRType::Double);
5193 } else if (ins->isBigIntWrite()) {
5194 MOZ_ASSERT(ins->value()->type() == MIRType::Int64);
5195 } else {
5196 MOZ_ASSERT(ins->value()->type() == MIRType::Int32);
5197 }
5198
5199 LUse elements = useRegister(ins->elements());
5200 LUse index = useRegister(ins->index());
5201 LAllocation littleEndian = useRegisterOrConstant(ins->littleEndian());
5202
5203 if (ins->isBigIntWrite()) {
5204 #ifdef JS_CODEGEN_X86
5205 LInt64Allocation value = useInt64Register(ins->value());
5206 LInt64Definition temp = LInt64Definition::BogusTemp();
5207 if (littleEndian.isConstant()) {
5208 temp = tempInt64();
5209 }
5210 #else
5211 LInt64Allocation value = useInt64RegisterOrConstant(ins->value());
5212 LInt64Definition temp = tempInt64();
5213 #endif
5214
5215 auto* lir = new (alloc())
5216 LStoreDataViewElement64(elements, index, value, littleEndian, temp);
5217 add(lir, ins);
5218 return;
5219 }
5220
5221 LAllocation value = useRegisterOrNonDoubleConstant(ins->value());
5222
5223 LDefinition tempDef = LDefinition::BogusTemp();
5224 LInt64Definition temp64Def = LInt64Definition::BogusTemp();
5225 if (ins->writeType() != Scalar::Float64) {
5226 tempDef = temp();
5227 } else {
5228 temp64Def = tempInt64();
5229 }
5230
5231 auto* lir = new (alloc()) LStoreDataViewElement(
5232 elements, index, value, littleEndian, tempDef, temp64Def);
5233 add(lir, ins);
5234
5235 if (MacroAssembler::StoreRequiresCall(ins->writeType())) {
5236 assignSafepoint(lir, ins);
5237 }
5238 }
5239
5240 void LIRGenerator::visitStoreTypedArrayElementHole(
5241 MStoreTypedArrayElementHole* ins) {
5242 MOZ_ASSERT(ins->elements()->type() == MIRType::Elements);
5243 MOZ_ASSERT(ins->index()->type() == MIRType::IntPtr);
5244 MOZ_ASSERT(ins->length()->type() == MIRType::IntPtr);
5245
5246 if (ins->isFloatWrite()) {
5247 MOZ_ASSERT_IF(ins->arrayType() == Scalar::Float16,
5248 ins->value()->type() == MIRType::Float32);
5249 MOZ_ASSERT_IF(ins->arrayType() == Scalar::Float32,
5250 ins->value()->type() == MIRType::Float32);
5251 MOZ_ASSERT_IF(ins->arrayType() == Scalar::Float64,
5252 ins->value()->type() == MIRType::Double);
5253 } else if (ins->isBigIntWrite()) {
5254 MOZ_ASSERT(ins->value()->type() == MIRType::Int64);
5255 } else {
5256 MOZ_ASSERT(ins->value()->type() == MIRType::Int32);
5257 }
5258
5259 LUse elements = useRegister(ins->elements());
5260 LAllocation length = useAny(ins->length());
5261 LAllocation index = useRegister(ins->index());
5262
5263 if (ins->isBigIntWrite()) {
5264 LInt64Allocation value = useInt64RegisterOrConstant(ins->value());
5265 LDefinition spectreTemp =
5266 BoundsCheckNeedsSpectreTemp() ? temp() : LDefinition::BogusTemp();
5267
5268 auto* lir = new (alloc()) LStoreTypedArrayElementHoleInt64(
5269 elements, length, index, value, spectreTemp);
5270 add(lir, ins);
5271 return;
5272 }
5273
5274 // For byte arrays, the value has to be in a byte register on x86.
5275 LAllocation value;
5276 if (ins->isByteWrite()) {
5277 value = useByteOpRegisterOrNonDoubleConstant(ins->value());
5278 } else {
5279 value = useRegisterOrNonDoubleConstant(ins->value());
5280 }
5281
5282 LDefinition tempDef = LDefinition::BogusTemp();
5283 if (BoundsCheckNeedsSpectreTemp() || ins->arrayType() == Scalar::Float16) {
5284 tempDef = temp();
5285 }
5286
5287 auto* lir = new (alloc())
5288 LStoreTypedArrayElementHole(elements, length, index, value, tempDef);
5289 add(lir, ins);
5290
5291 if (MacroAssembler::StoreRequiresCall(ins->arrayType())) {
5292 assignSafepoint(lir, ins);
5293 }
5294 }
5295
5296 void LIRGenerator::visitLoadScriptedProxyHandler(
5297 MLoadScriptedProxyHandler* ins) {
5298 LLoadScriptedProxyHandler* lir = new (alloc())
5299 LLoadScriptedProxyHandler(useRegisterAtStart(ins->object()));
5300 assignSnapshot(lir, ins->bailoutKind());
5301 define(lir, ins);
5302 }
5303
5304 void LIRGenerator::visitIdToStringOrSymbol(MIdToStringOrSymbol* ins) {
5305 LIdToStringOrSymbol* lir =
5306 new (alloc()) LIdToStringOrSymbol(useBoxAtStart(ins->idVal()), temp());
5307 assignSnapshot(lir, ins->bailoutKind());
5308 defineBox(lir, ins);
5309 assignSafepoint(lir, ins);
5310 }
5311
5312 void LIRGenerator::visitLoadFixedSlot(MLoadFixedSlot* ins) {
5313 MDefinition* obj = ins->object();
5314 MOZ_ASSERT(obj->type() == MIRType::Object);
5315
5316 MIRType type = ins->type();
5317
5318 if (type == MIRType::Value) {
5319 if (ins->usedAsPropertyKey()) {
5320 LLoadFixedSlotAndAtomize* lir =
5321 new (alloc()) LLoadFixedSlotAndAtomize(useRegister(obj), temp());
5322 defineBox(lir, ins);
5323 assignSafepoint(lir, ins);
5324 } else {
5325 LLoadFixedSlotV* lir =
5326 new (alloc()) LLoadFixedSlotV(useRegisterAtStart(obj));
5327 defineBox(lir, ins);
5328 }
5329 } else {
5330 LLoadFixedSlotT* lir =
5331 new (alloc()) LLoadFixedSlotT(useRegisterForTypedLoad(obj, type));
5332 define(lir, ins);
5333 }
5334 }
5335
5336 void LIRGenerator::visitLoadFixedSlotAndUnbox(MLoadFixedSlotAndUnbox* ins) {
5337 MDefinition* obj = ins->object();
5338 MOZ_ASSERT(obj->type() == MIRType::Object);
5339
5340 if (ins->usedAsPropertyKey() && ins->type() == MIRType::String) {
5341 LLoadFixedSlotUnboxAndAtomize* lir =
5342 new (alloc()) LLoadFixedSlotUnboxAndAtomize(useRegister(obj));
5343 if (ins->fallible()) {
5344 assignSnapshot(lir, ins->bailoutKind());
5345 }
5346 define(lir, ins);
5347 assignSafepoint(lir, ins);
5348 } else {
5349 LLoadFixedSlotAndUnbox* lir =
5350 new (alloc()) LLoadFixedSlotAndUnbox(useRegisterAtStart(obj));
5351 if (ins->fallible()) {
5352 assignSnapshot(lir, ins->bailoutKind());
5353 }
5354 define(lir, ins);
5355 }
5356 }
5357
5358 void LIRGenerator::visitLoadDynamicSlotAndUnbox(MLoadDynamicSlotAndUnbox* ins) {
5359 MDefinition* slots = ins->slots();
5360 MOZ_ASSERT(slots->type() == MIRType::Slots);
5361
5362 if (ins->usedAsPropertyKey() && ins->type() == MIRType::String) {
5363 auto* lir =
5364 new (alloc()) LLoadDynamicSlotUnboxAndAtomize(useRegister(slots));
5365 if (ins->fallible()) {
5366 assignSnapshot(lir, ins->bailoutKind());
5367 }
5368 define(lir, ins);
5369 assignSafepoint(lir, ins);
5370 } else {
5371 auto* lir =
5372 new (alloc()) LLoadDynamicSlotAndUnbox(useRegisterAtStart(slots));
5373 if (ins->fallible()) {
5374 assignSnapshot(lir, ins->bailoutKind());
5375 }
5376 define(lir, ins);
5377 }
5378 }
5379
5380 void LIRGenerator::visitLoadElementAndUnbox(MLoadElementAndUnbox* ins) {
5381 MDefinition* elements = ins->elements();
5382 MDefinition* index = ins->index();
5383 MOZ_ASSERT(elements->type() == MIRType::Elements);
5384 MOZ_ASSERT(index->type() == MIRType::Int32);
5385
5386 auto* lir = new (alloc())
5387 LLoadElementAndUnbox(useRegister(elements), useRegisterOrConstant(index));
5388 if (ins->fallible()) {
5389 assignSnapshot(lir, ins->bailoutKind());
5390 }
5391 define(lir, ins);
5392 }
5393
5394 void LIRGenerator::visitAddAndStoreSlot(MAddAndStoreSlot* ins) {
5395 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5396
5397 LDefinition maybeTemp = LDefinition::BogusTemp();
5398 if (ins->kind() != MAddAndStoreSlot::Kind::FixedSlot) {
5399 maybeTemp = temp();
5400 }
5401
5402 auto* lir = new (alloc()) LAddAndStoreSlot(useRegister(ins->object()),
5403 useBox(ins->value()), maybeTemp);
5404 add(lir, ins);
5405 }
5406
5407 void LIRGenerator::visitAllocateAndStoreSlot(MAllocateAndStoreSlot* ins) {
5408 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5409
5410 auto* lir = new (alloc()) LAllocateAndStoreSlot(
5411 useRegisterAtStart(ins->object()), useBoxAtStart(ins->value()),
5412 tempFixed(CallTempReg0), tempFixed(CallTempReg1));
5413 assignSnapshot(lir, ins->bailoutKind());
5414 add(lir, ins);
5415 }
5416
5417 void LIRGenerator::visitAddSlotAndCallAddPropHook(
5418 MAddSlotAndCallAddPropHook* ins) {
5419 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5420 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
5421
5422 auto* lir = new (alloc()) LAddSlotAndCallAddPropHook(
5423 useRegisterAtStart(ins->object()), useBoxAtStart(ins->value()));
5424 add(lir, ins);
5425 assignSafepoint(lir, ins);
5426 }
5427
5428 void LIRGenerator::visitStoreFixedSlot(MStoreFixedSlot* ins) {
5429 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5430
5431 if (ins->value()->type() == MIRType::Value) {
5432 LStoreFixedSlotV* lir = new (alloc())
5433 LStoreFixedSlotV(useRegister(ins->object()), useBox(ins->value()));
5434 add(lir, ins);
5435 } else {
5436 LStoreFixedSlotT* lir = new (alloc()) LStoreFixedSlotT(
5437 useRegister(ins->object()), useRegisterOrConstant(ins->value()));
5438 add(lir, ins);
5439 }
5440 }
5441
5442 void LIRGenerator::visitGetNameCache(MGetNameCache* ins) {
5443 MOZ_ASSERT(ins->envObj()->type() == MIRType::Object);
5444
5445 // Emit an overrecursed check: this is necessary because the cache can
5446 // attach a scripted getter stub that calls this script recursively.
5447 gen->setNeedsOverrecursedCheck();
5448
5449 LGetNameCache* lir =
5450 new (alloc()) LGetNameCache(useRegister(ins->envObj()), temp());
5451 defineBox(lir, ins);
5452 assignSafepoint(lir, ins);
5453 }
5454
5455 void LIRGenerator::visitCallGetIntrinsicValue(MCallGetIntrinsicValue* ins) {
5456 LCallGetIntrinsicValue* lir = new (alloc()) LCallGetIntrinsicValue();
5457 defineReturn(lir, ins);
5458 assignSafepoint(lir, ins);
5459 }
5460
5461 void LIRGenerator::visitGetPropSuperCache(MGetPropSuperCache* ins) {
5462 MDefinition* obj = ins->object();
5463 MDefinition* receiver = ins->receiver();
5464 MDefinition* id = ins->idval();
5465
5466 gen->setNeedsOverrecursedCheck();
5467
5468 bool useConstId =
5469 id->type() == MIRType::String || id->type() == MIRType::Symbol;
5470
5471 auto* lir = new (alloc())
5472 LGetPropSuperCache(useRegister(obj), useBoxOrTyped(receiver),
5473 useBoxOrTypedOrConstant(id, useConstId));
5474 defineBox(lir, ins);
5475 assignSafepoint(lir, ins);
5476 }
5477
5478 void LIRGenerator::visitGetPropertyCache(MGetPropertyCache* ins) {
5479 MDefinition* value = ins->value();
5480 MOZ_ASSERT(value->type() == MIRType::Object ||
5481 value->type() == MIRType::Value);
5482
5483 MDefinition* id = ins->idval();
5484 MOZ_ASSERT(id->type() == MIRType::String || id->type() == MIRType::Symbol ||
5485 id->type() == MIRType::Int32 || id->type() == MIRType::Value);
5486
5487 // Emit an overrecursed check: this is necessary because the cache can
5488 // attach a scripted getter stub that calls this script recursively.
5489 gen->setNeedsOverrecursedCheck();
5490
5491 // If this is a GetProp, the id is a constant string. Allow passing it as a
5492 // constant to reduce register allocation pressure.
5493 bool useConstId =
5494 id->type() == MIRType::String || id->type() == MIRType::Symbol;
5495
5496 auto* lir = new (alloc()) LGetPropertyCache(
5497 useBoxOrTyped(value), useBoxOrTypedOrConstant(id, useConstId));
5498 defineBox(lir, ins);
5499 assignSafepoint(lir, ins);
5500 }
5501
5502 void LIRGenerator::visitBindNameCache(MBindNameCache* ins) {
5503 MOZ_ASSERT(ins->environmentChain()->type() == MIRType::Object);
5504 MOZ_ASSERT(ins->type() == MIRType::Object);
5505
5506 LBindNameCache* lir = new (alloc())
5507 LBindNameCache(useRegister(ins->environmentChain()), temp());
5508 define(lir, ins);
5509 assignSafepoint(lir, ins);
5510 }
5511
5512 void LIRGenerator::visitCallBindVar(MCallBindVar* ins) {
5513 MOZ_ASSERT(ins->environmentChain()->type() == MIRType::Object);
5514 MOZ_ASSERT(ins->type() == MIRType::Object);
5515
5516 LCallBindVar* lir =
5517 new (alloc()) LCallBindVar(useRegister(ins->environmentChain()));
5518 define(lir, ins);
5519 }
5520
5521 void LIRGenerator::visitGuardObjectIdentity(MGuardObjectIdentity* ins) {
5522 LGuardObjectIdentity* guard = new (alloc()) LGuardObjectIdentity(
5523 useRegister(ins->object()), useRegister(ins->expected()));
5524 assignSnapshot(guard, ins->bailoutKind());
5525 add(guard, ins);
5526 redefine(ins, ins->object());
5527 }
5528
5529 void LIRGenerator::visitGuardSpecificFunction(MGuardSpecificFunction* ins) {
5530 auto* guard = new (alloc()) LGuardSpecificFunction(
5531 useRegister(ins->function()), useRegister(ins->expected()));
5532 assignSnapshot(guard, ins->bailoutKind());
5533 add(guard, ins);
5534 redefine(ins, ins->function());
5535 }
5536
5537 void LIRGenerator::visitGuardSpecificAtom(MGuardSpecificAtom* ins) {
5538 auto* guard =
5539 new (alloc()) LGuardSpecificAtom(useRegister(ins->str()), temp());
5540 assignSnapshot(guard, ins->bailoutKind());
5541 add(guard, ins);
5542 redefine(ins, ins->str());
5543 assignSafepoint(guard, ins);
5544 }
5545
5546 void LIRGenerator::visitGuardSpecificSymbol(MGuardSpecificSymbol* ins) {
5547 auto* guard = new (alloc()) LGuardSpecificSymbol(useRegister(ins->symbol()));
5548 assignSnapshot(guard, ins->bailoutKind());
5549 add(guard, ins);
5550 redefine(ins, ins->symbol());
5551 }
5552
5553 void LIRGenerator::visitGuardSpecificInt32(MGuardSpecificInt32* ins) {
5554 auto* guard = new (alloc()) LGuardSpecificInt32(useRegister(ins->num()));
5555 assignSnapshot(guard, ins->bailoutKind());
5556 add(guard, ins);
5557 redefine(ins, ins->num());
5558 }
5559
5560 void LIRGenerator::visitGuardStringToIndex(MGuardStringToIndex* ins) {
5561 MOZ_ASSERT(ins->string()->type() == MIRType::String);
5562 auto* guard = new (alloc()) LGuardStringToIndex(useRegister(ins->string()));
5563 assignSnapshot(guard, ins->bailoutKind());
5564 define(guard, ins);
5565 assignSafepoint(guard, ins);
5566 }
5567
5568 void LIRGenerator::visitGuardStringToInt32(MGuardStringToInt32* ins) {
5569 MOZ_ASSERT(ins->string()->type() == MIRType::String);
5570 auto* guard =
5571 new (alloc()) LGuardStringToInt32(useRegister(ins->string()), temp());
5572 assignSnapshot(guard, ins->bailoutKind());
5573 define(guard, ins);
5574 assignSafepoint(guard, ins);
5575 }
5576
5577 void LIRGenerator::visitGuardStringToDouble(MGuardStringToDouble* ins) {
5578 MOZ_ASSERT(ins->string()->type() == MIRType::String);
5579 auto* guard = new (alloc())
5580 LGuardStringToDouble(useRegister(ins->string()), temp(), temp());
5581 assignSnapshot(guard, ins->bailoutKind());
5582 define(guard, ins);
5583 assignSafepoint(guard, ins);
5584 }
5585
5586 void LIRGenerator::visitGuardNoDenseElements(MGuardNoDenseElements* ins) {
5587 auto* guard =
5588 new (alloc()) LGuardNoDenseElements(useRegister(ins->object()), temp());
5589 assignSnapshot(guard, ins->bailoutKind());
5590 add(guard, ins);
5591 redefine(ins, ins->object());
5592 }
5593
5594 void LIRGenerator::visitGuardShape(MGuardShape* ins) {
5595 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5596
5597 if (JitOptions.spectreObjectMitigations) {
5598 auto* lir =
5599 new (alloc()) LGuardShape(useRegisterAtStart(ins->object()), temp());
5600 assignSnapshot(lir, ins->bailoutKind());
5601 defineReuseInput(lir, ins, 0);
5602 } else {
5603 auto* lir = new (alloc())
5604 LGuardShape(useRegister(ins->object()), LDefinition::BogusTemp());
5605 assignSnapshot(lir, ins->bailoutKind());
5606 add(lir, ins);
5607 redefine(ins, ins->object());
5608 }
5609 }
5610
5611 void LIRGenerator::visitGuardMultipleShapes(MGuardMultipleShapes* ins) {
5612 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5613
5614 if (JitOptions.spectreObjectMitigations) {
5615 auto* lir = new (alloc()) LGuardMultipleShapes(
5616 useRegisterAtStart(ins->object()), useRegister(ins->shapeList()),
5617 temp(), temp(), temp(), temp());
5618 assignSnapshot(lir, ins->bailoutKind());
5619 defineReuseInput(lir, ins, 0);
5620 } else {
5621 auto* lir = new (alloc()) LGuardMultipleShapes(
5622 useRegister(ins->object()), useRegister(ins->shapeList()), temp(),
5623 temp(), temp(), LDefinition::BogusTemp());
5624 assignSnapshot(lir, ins->bailoutKind());
5625 add(lir, ins);
5626 redefine(ins, ins->object());
5627 }
5628 }
5629
5630 void LIRGenerator::visitGuardProto(MGuardProto* ins) {
5631 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5632 MOZ_ASSERT(ins->expected()->type() == MIRType::Object);
5633
5634 auto* lir = new (alloc()) LGuardProto(useRegister(ins->object()),
5635 useRegister(ins->expected()), temp());
5636 assignSnapshot(lir, ins->bailoutKind());
5637 add(lir, ins);
5638 redefine(ins, ins->object());
5639 }
5640
5641 void LIRGenerator::visitGuardNullProto(MGuardNullProto* ins) {
5642 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5643
5644 auto* lir = new (alloc()) LGuardNullProto(useRegister(ins->object()), temp());
5645 assignSnapshot(lir, ins->bailoutKind());
5646 add(lir, ins);
5647 redefine(ins, ins->object());
5648 }
5649
5650 void LIRGenerator::visitGuardIsNativeObject(MGuardIsNativeObject* ins) {
5651 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5652
5653 auto* lir =
5654 new (alloc()) LGuardIsNativeObject(useRegister(ins->object()), temp());
5655 assignSnapshot(lir, ins->bailoutKind());
5656 add(lir, ins);
5657 redefine(ins, ins->object());
5658 }
5659
5660 void LIRGenerator::visitGuardGlobalGeneration(MGuardGlobalGeneration* ins) {
5661 auto* lir = new (alloc()) LGuardGlobalGeneration(temp());
5662 assignSnapshot(lir, ins->bailoutKind());
5663 add(lir, ins);
5664 }
5665
5666 void LIRGenerator::visitGuardFuse(MGuardFuse* ins) {
5667 auto* lir = new (alloc()) LGuardFuse(temp());
5668 assignSnapshot(lir, ins->bailoutKind());
5669 add(lir, ins);
5670 }
5671
5672 void LIRGenerator::visitGuardIsProxy(MGuardIsProxy* ins) {
5673 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5674
5675 auto* lir = new (alloc()) LGuardIsProxy(useRegister(ins->object()), temp());
5676 assignSnapshot(lir, ins->bailoutKind());
5677 add(lir, ins);
5678 redefine(ins, ins->object());
5679 }
5680
5681 void LIRGenerator::visitGuardIsNotProxy(MGuardIsNotProxy* ins) {
5682 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5683
5684 auto* lir =
5685 new (alloc()) LGuardIsNotProxy(useRegister(ins->object()), temp());
5686 assignSnapshot(lir, ins->bailoutKind());
5687 add(lir, ins);
5688 redefine(ins, ins->object());
5689 }
5690
5691 void LIRGenerator::visitGuardIsNotDOMProxy(MGuardIsNotDOMProxy* ins) {
5692 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5693
5694 auto* lir =
5695 new (alloc()) LGuardIsNotDOMProxy(useRegister(ins->proxy()), temp());
5696 assignSnapshot(lir, ins->bailoutKind());
5697 add(lir, ins);
5698 redefine(ins, ins->proxy());
5699 }
5700
5701 void LIRGenerator::visitProxyGet(MProxyGet* ins) {
5702 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5703 auto* lir = new (alloc())
5704 LProxyGet(useRegisterAtStart(ins->proxy()), tempFixed(CallTempReg0));
5705 defineReturn(lir, ins);
5706 assignSafepoint(lir, ins);
5707 }
5708
5709 void LIRGenerator::visitProxyGetByValue(MProxyGetByValue* ins) {
5710 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5711 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5712 auto* lir = new (alloc()) LProxyGetByValue(useRegisterAtStart(ins->proxy()),
5713 useBoxAtStart(ins->idVal()));
5714 defineReturn(lir, ins);
5715 assignSafepoint(lir, ins);
5716 }
5717
5718 void LIRGenerator::visitProxyHasProp(MProxyHasProp* ins) {
5719 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5720 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5721 auto* lir = new (alloc()) LProxyHasProp(useRegisterAtStart(ins->proxy()),
5722 useBoxAtStart(ins->idVal()));
5723 defineReturn(lir, ins);
5724 assignSafepoint(lir, ins);
5725 }
5726
5727 void LIRGenerator::visitProxySet(MProxySet* ins) {
5728 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5729 MOZ_ASSERT(ins->rhs()->type() == MIRType::Value);
5730 auto* lir = new (alloc())
5731 LProxySet(useRegisterAtStart(ins->proxy()), useBoxAtStart(ins->rhs()),
5732 tempFixed(CallTempReg0));
5733 add(lir, ins);
5734 assignSafepoint(lir, ins);
5735 }
5736
5737 void LIRGenerator::visitProxySetByValue(MProxySetByValue* ins) {
5738 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
5739 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5740 MOZ_ASSERT(ins->rhs()->type() == MIRType::Value);
5741 auto* lir = new (alloc())
5742 LProxySetByValue(useRegisterAtStart(ins->proxy()),
5743 useBoxAtStart(ins->idVal()), useBoxAtStart(ins->rhs()));
5744 add(lir, ins);
5745 assignSafepoint(lir, ins);
5746 }
5747
5748 void LIRGenerator::visitCallSetArrayLength(MCallSetArrayLength* ins) {
5749 MOZ_ASSERT(ins->obj()->type() == MIRType::Object);
5750 MOZ_ASSERT(ins->rhs()->type() == MIRType::Value);
5751 auto* lir = new (alloc()) LCallSetArrayLength(useRegisterAtStart(ins->obj()),
5752 useBoxAtStart(ins->rhs()));
5753 add(lir, ins);
5754 assignSafepoint(lir, ins);
5755 }
5756
5757 void LIRGenerator::visitMegamorphicLoadSlot(MMegamorphicLoadSlot* ins) {
5758 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5759 auto* lir = new (alloc())
5760 LMegamorphicLoadSlot(useRegisterAtStart(ins->object()),
5761 tempFixed(CallTempReg0), tempFixed(CallTempReg1),
5762 tempFixed(CallTempReg2), tempFixed(CallTempReg3));
5763 assignSnapshot(lir, ins->bailoutKind());
5764 defineReturn(lir, ins);
5765 }
5766
5767 void LIRGenerator::visitMegamorphicLoadSlotPermissive(
5768 MMegamorphicLoadSlotPermissive* ins) {
5769 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5770 static_assert(IonGenericCallCalleeReg == CallTempReg1);
5771 static_assert(IonGenericCallArgcReg == CallTempReg2);
5772
5773 auto* lir = new (alloc()) LMegamorphicLoadSlotPermissive(
5774 useRegisterAtStart(ins->object()), tempFixed(CallTempReg0),
5775 tempFixed(IonGenericCallCalleeReg), tempFixed(IonGenericCallArgcReg),
5776 tempFixed(CallTempReg4));
5777 defineReturn(lir, ins);
5778 assignSafepoint(lir, ins);
5779 lirGraph_.addExtraSafepointUses(1);
5780 }
5781
5782 void LIRGenerator::visitMegamorphicLoadSlotByValue(
5783 MMegamorphicLoadSlotByValue* ins) {
5784 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5785 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5786 auto* lir = new (alloc()) LMegamorphicLoadSlotByValue(
5787 useRegisterAtStart(ins->object()), useBoxAtStart(ins->idVal()),
5788 tempFixed(CallTempReg0), tempFixed(CallTempReg1),
5789 tempFixed(CallTempReg2));
5790 assignSnapshot(lir, ins->bailoutKind());
5791 defineReturn(lir, ins);
5792 }
5793
5794 void LIRGenerator::visitMegamorphicLoadSlotByValuePermissive(
5795 MMegamorphicLoadSlotByValuePermissive* ins) {
5796 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5797 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5798 #ifdef JS_CODEGEN_X86
5799 auto* lir = new (alloc()) LMegamorphicLoadSlotByValuePermissive(
5800 useRegisterAtStart(ins->object()), useBoxAtStart(ins->idVal()),
5801 tempFixed(CallTempReg0), tempFixed(IonGenericCallCalleeReg),
5802 tempFixed(IonGenericCallArgcReg));
5803 defineReturn(lir, ins);
5804 assignSafepoint(lir, ins);
5805 #else
5806 static_assert(IonGenericCallCalleeReg == CallTempReg1);
5807 static_assert(IonGenericCallArgcReg == CallTempReg2);
5808
5809 auto* lir = new (alloc()) LMegamorphicLoadSlotByValuePermissive(
5810 useRegisterAtStart(ins->object()), useBoxAtStart(ins->idVal()),
5811 tempFixed(CallTempReg0), tempFixed(IonGenericCallCalleeReg),
5812 tempFixed(IonGenericCallArgcReg), tempFixed(CallTempReg4));
5813 defineReturn(lir, ins);
5814 assignSafepoint(lir, ins);
5815 lirGraph_.addExtraSafepointUses(1);
5816 #endif
5817 }
5818
5819 void LIRGenerator::visitMegamorphicStoreSlot(MMegamorphicStoreSlot* ins) {
5820 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5821 MOZ_ASSERT(ins->rhs()->type() == MIRType::Value);
5822
5823 #ifdef JS_CODEGEN_X86
5824 auto* lir = new (alloc()) LMegamorphicStoreSlot(
5825 useFixedAtStart(ins->object(), CallTempReg0),
5826 useBoxFixedAtStart(ins->rhs(), CallTempReg1, CallTempReg2),
5827 tempFixed(CallTempReg5));
5828 #else
5829 auto* lir = new (alloc())
5830 LMegamorphicStoreSlot(useRegisterAtStart(ins->object()),
5831 useBoxAtStart(ins->rhs()), tempFixed(CallTempReg0),
5832 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
5833 #endif
5834
5835 add(lir, ins);
5836 assignSafepoint(lir, ins);
5837 }
5838
5839 void LIRGenerator::visitMegamorphicHasProp(MMegamorphicHasProp* ins) {
5840 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5841 MOZ_ASSERT(ins->idVal()->type() == MIRType::Value);
5842 auto* lir = new (alloc())
5843 LMegamorphicHasProp(useRegisterAtStart(ins->object()),
5844 useBoxAtStart(ins->idVal()), tempFixed(CallTempReg0),
5845 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
5846 assignSnapshot(lir, ins->bailoutKind());
5847 defineReturn(lir, ins);
5848 }
5849
5850 void LIRGenerator::visitSmallObjectVariableKeyHasProp(
5851 MSmallObjectVariableKeyHasProp* ins) {
5852 MOZ_ASSERT(ins->idStr()->type() == MIRType::String);
5853 auto* lir = new (alloc())
5854 LSmallObjectVariableKeyHasProp(useRegisterAtStart(ins->idStr()));
5855 define(lir, ins);
5856 assignSafepoint(lir, ins);
5857 }
5858
5859 void LIRGenerator::visitGuardIsNotArrayBufferMaybeShared(
5860 MGuardIsNotArrayBufferMaybeShared* ins) {
5861 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5862
5863 auto* lir = new (alloc())
5864 LGuardIsNotArrayBufferMaybeShared(useRegister(ins->object()), temp());
5865 assignSnapshot(lir, ins->bailoutKind());
5866 add(lir, ins);
5867 redefine(ins, ins->object());
5868 }
5869
5870 void LIRGenerator::visitGuardIsTypedArray(MGuardIsTypedArray* ins) {
5871 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5872
5873 auto* lir =
5874 new (alloc()) LGuardIsTypedArray(useRegister(ins->object()), temp());
5875 assignSnapshot(lir, ins->bailoutKind());
5876 add(lir, ins);
5877 redefine(ins, ins->object());
5878 }
5879
5880 void LIRGenerator::visitGuardIsFixedLengthTypedArray(
5881 MGuardIsFixedLengthTypedArray* ins) {
5882 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5883
5884 auto* lir = new (alloc())
5885 LGuardIsFixedLengthTypedArray(useRegister(ins->object()), temp());
5886 assignSnapshot(lir, ins->bailoutKind());
5887 add(lir, ins);
5888 redefine(ins, ins->object());
5889 }
5890
5891 void LIRGenerator::visitGuardIsResizableTypedArray(
5892 MGuardIsResizableTypedArray* ins) {
5893 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5894
5895 auto* lir = new (alloc())
5896 LGuardIsResizableTypedArray(useRegister(ins->object()), temp());
5897 assignSnapshot(lir, ins->bailoutKind());
5898 add(lir, ins);
5899 redefine(ins, ins->object());
5900 }
5901
5902 void LIRGenerator::visitGuardHasProxyHandler(MGuardHasProxyHandler* ins) {
5903 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
5904
5905 auto* lir = new (alloc()) LGuardHasProxyHandler(useRegister(ins->object()));
5906 assignSnapshot(lir, ins->bailoutKind());
5907 add(lir, ins);
5908 redefine(ins, ins->object());
5909 }
5910
5911 void LIRGenerator::visitNurseryObject(MNurseryObject* ins) {
5912 MOZ_ASSERT(ins->type() == MIRType::Object);
5913
5914 auto* lir = new (alloc()) LNurseryObject();
5915 define(lir, ins);
5916 }
5917
5918 void LIRGenerator::visitGuardValue(MGuardValue* ins) {
5919 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
5920 LDefinition nanTemp =
5921 ins->expected().isNaN() ? temp() : LDefinition::BogusTemp();
5922 auto* lir = new (alloc()) LGuardValue(useBox(ins->value()), nanTemp);
5923 assignSnapshot(lir, ins->bailoutKind());
5924 add(lir, ins);
5925 redefine(ins, ins->value());
5926 }
5927
5928 void LIRGenerator::visitGuardNullOrUndefined(MGuardNullOrUndefined* ins) {
5929 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
5930 auto* lir = new (alloc()) LGuardNullOrUndefined(useBox(ins->value()));
5931 assignSnapshot(lir, ins->bailoutKind());
5932 add(lir, ins);
5933 redefine(ins, ins->value());
5934 }
5935
5936 void LIRGenerator::visitGuardIsNotObject(MGuardIsNotObject* ins) {
5937 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
5938 auto* lir = new (alloc()) LGuardIsNotObject(useBox(ins->value()));
5939 assignSnapshot(lir, ins->bailoutKind());
5940 add(lir, ins);
5941 redefine(ins, ins->value());
5942 }
5943
5944 void LIRGenerator::visitGuardFunctionFlags(MGuardFunctionFlags* ins) {
5945 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
5946
5947 auto* lir = new (alloc()) LGuardFunctionFlags(useRegister(ins->function()));
5948 assignSnapshot(lir, ins->bailoutKind());
5949 add(lir, ins);
5950 redefine(ins, ins->function());
5951 }
5952
5953 void LIRGenerator::visitGuardFunctionIsNonBuiltinCtor(
5954 MGuardFunctionIsNonBuiltinCtor* ins) {
5955 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
5956
5957 auto* lir = new (alloc())
5958 LGuardFunctionIsNonBuiltinCtor(useRegister(ins->function()), temp());
5959 assignSnapshot(lir, ins->bailoutKind());
5960 add(lir, ins);
5961 redefine(ins, ins->function());
5962 }
5963
5964 void LIRGenerator::visitGuardFunctionKind(MGuardFunctionKind* ins) {
5965 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
5966
5967 auto* lir =
5968 new (alloc()) LGuardFunctionKind(useRegister(ins->function()), temp());
5969 assignSnapshot(lir, ins->bailoutKind());
5970 add(lir, ins);
5971 redefine(ins, ins->function());
5972 }
5973
5974 void LIRGenerator::visitGuardFunctionScript(MGuardFunctionScript* ins) {
5975 MOZ_ASSERT(ins->function()->type() == MIRType::Object);
5976
5977 auto* lir = new (alloc()) LGuardFunctionScript(useRegister(ins->function()));
5978 assignSnapshot(lir, ins->bailoutKind());
5979 add(lir, ins);
5980 redefine(ins, ins->function());
5981 }
5982
5983 void LIRGenerator::visitAssertRange(MAssertRange* ins) {
5984 MDefinition* input = ins->input();
5985 LInstruction* lir = nullptr;
5986
5987 switch (input->type()) {
5988 case MIRType::Boolean:
5989 case MIRType::Int32:
5990 case MIRType::IntPtr:
5991 lir = new (alloc()) LAssertRangeI(useRegisterAtStart(input));
5992 break;
5993
5994 case MIRType::Double:
5995 lir = new (alloc()) LAssertRangeD(useRegister(input), tempDouble());
5996 break;
5997
5998 case MIRType::Float32:
5999 lir = new (alloc())
6000 LAssertRangeF(useRegister(input), tempDouble(), tempDouble());
6001 break;
6002
6003 case MIRType::Value:
6004 lir = new (alloc()) LAssertRangeV(useBox(input), tempToUnbox(),
6005 tempDouble(), tempDouble());
6006 break;
6007
6008 default:
6009 MOZ_CRASH("Unexpected Range for MIRType");
6010 break;
6011 }
6012
6013 lir->setMir(ins);
6014 add(lir);
6015 }
6016
6017 void LIRGenerator::visitAssertClass(MAssertClass* ins) {
6018 auto* lir =
6019 new (alloc()) LAssertClass(useRegisterAtStart(ins->input()), temp());
6020 add(lir, ins);
6021 }
6022
6023 void LIRGenerator::visitAssertShape(MAssertShape* ins) {
6024 auto* lir = new (alloc()) LAssertShape(useRegisterAtStart(ins->input()));
6025 add(lir, ins);
6026 }
6027
6028 void LIRGenerator::visitDeleteProperty(MDeleteProperty* ins) {
6029 LCallDeleteProperty* lir =
6030 new (alloc()) LCallDeleteProperty(useBoxAtStart(ins->value()));
6031 defineReturn(lir, ins);
6032 assignSafepoint(lir, ins);
6033 }
6034
6035 void LIRGenerator::visitDeleteElement(MDeleteElement* ins) {
6036 LCallDeleteElement* lir = new (alloc()) LCallDeleteElement(
6037 useBoxAtStart(ins->value()), useBoxAtStart(ins->index()));
6038 defineReturn(lir, ins);
6039 assignSafepoint(lir, ins);
6040 }
6041
6042 void LIRGenerator::visitObjectToIterator(MObjectToIterator* ins) {
6043 auto* lir = new (alloc())
6044 LObjectToIterator(useRegister(ins->object()), temp(), temp(), temp());
6045 define(lir, ins);
6046 assignSafepoint(lir, ins);
6047 }
6048
6049 void LIRGenerator::visitValueToIterator(MValueToIterator* ins) {
6050 auto* lir = new (alloc()) LValueToIterator(useBoxAtStart(ins->value()));
6051 defineReturn(lir, ins);
6052 assignSafepoint(lir, ins);
6053 }
6054
6055 void LIRGenerator::visitLoadSlotByIteratorIndex(MLoadSlotByIteratorIndex* ins) {
6056 auto* lir = new (alloc()) LLoadSlotByIteratorIndex(
6057 useRegisterAtStart(ins->object()), useRegisterAtStart(ins->iterator()),
6058 temp(), temp());
6059 defineBox(lir, ins);
6060 }
6061
6062 void LIRGenerator::visitStoreSlotByIteratorIndex(
6063 MStoreSlotByIteratorIndex* ins) {
6064 auto* lir = new (alloc()) LStoreSlotByIteratorIndex(
6065 useRegister(ins->object()), useRegister(ins->iterator()),
6066 useBox(ins->value()), temp(), temp());
6067 add(lir, ins);
6068 }
6069
6070 void LIRGenerator::visitIteratorHasIndices(MIteratorHasIndices* ins) {
6071 MOZ_ASSERT(ins->hasOneUse());
6072 emitAtUses(ins);
6073 }
6074
6075 void LIRGenerator::visitSetPropertyCache(MSetPropertyCache* ins) {
6076 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6077
6078 MDefinition* id = ins->idval();
6079 MOZ_ASSERT(id->type() == MIRType::String || id->type() == MIRType::Symbol ||
6080 id->type() == MIRType::Int32 || id->type() == MIRType::Value);
6081
6082 // If this is a SetProp, the id is a constant string. Allow passing it as a
6083 // constant to reduce register allocation pressure.
6084 bool useConstId =
6085 id->type() == MIRType::String || id->type() == MIRType::Symbol;
6086 bool useConstValue = IsNonNurseryConstant(ins->value());
6087
6088 // Emit an overrecursed check: this is necessary because the cache can
6089 // attach a scripted setter stub that calls this script recursively.
6090 gen->setNeedsOverrecursedCheck();
6091
6092 // We need a double temp register for TypedArray stubs.
6093 LDefinition tempD = tempFixed(FloatReg0);
6094
6095 LInstruction* lir = new (alloc()) LSetPropertyCache(
6096 useRegister(ins->object()), useBoxOrTypedOrConstant(id, useConstId),
6097 useBoxOrTypedOrConstant(ins->value(), useConstValue), temp(), tempD);
6098 add(lir, ins);
6099 assignSafepoint(lir, ins);
6100 }
6101
6102 void LIRGenerator::visitMegamorphicSetElement(MMegamorphicSetElement* ins) {
6103 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6104 MOZ_ASSERT(ins->index()->type() == MIRType::Value);
6105 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
6106
6107 // See comment in LIROps.yaml (x86 is short on registers)
6108 #ifdef JS_CODEGEN_X86
6109 auto* lir = new (alloc()) LMegamorphicSetElement(
6110 useFixedAtStart(ins->object(), CallTempReg0),
6111 useBoxFixedAtStart(ins->index(), CallTempReg1, CallTempReg2),
6112 useBoxFixedAtStart(ins->value(), CallTempReg3, CallTempReg4),
6113 tempFixed(CallTempReg5));
6114 #else
6115 auto* lir = new (alloc()) LMegamorphicSetElement(
6116 useRegisterAtStart(ins->object()), useBoxAtStart(ins->index()),
6117 useBoxAtStart(ins->value()), tempFixed(CallTempReg0),
6118 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
6119 #endif
6120 add(lir, ins);
6121 assignSafepoint(lir, ins);
6122 }
6123
6124 void LIRGenerator::visitGetIteratorCache(MGetIteratorCache* ins) {
6125 MDefinition* value = ins->value();
6126 MOZ_ASSERT(value->type() == MIRType::Object ||
6127 value->type() == MIRType::Value);
6128
6129 LGetIteratorCache* lir =
6130 new (alloc()) LGetIteratorCache(useBoxOrTyped(value), temp(), temp());
6131 define(lir, ins);
6132 assignSafepoint(lir, ins);
6133 }
6134
6135 void LIRGenerator::visitOptimizeSpreadCallCache(MOptimizeSpreadCallCache* ins) {
6136 MDefinition* value = ins->value();
6137 MOZ_ASSERT(value->type() == MIRType::Value);
6138
6139 auto* lir = new (alloc()) LOptimizeSpreadCallCache(useBox(value), temp());
6140 defineBox(lir, ins);
6141 assignSafepoint(lir, ins);
6142 }
6143
6144 void LIRGenerator::visitIteratorMore(MIteratorMore* ins) {
6145 LIteratorMore* lir =
6146 new (alloc()) LIteratorMore(useRegister(ins->iterator()), temp());
6147 defineBox(lir, ins);
6148 }
6149
6150 void LIRGenerator::visitIsNoIter(MIsNoIter* ins) {
6151 MOZ_ASSERT(ins->hasOneUse());
6152 emitAtUses(ins);
6153 }
6154
6155 void LIRGenerator::visitIteratorEnd(MIteratorEnd* ins) {
6156 LIteratorEnd* lir = new (alloc())
6157 LIteratorEnd(useRegister(ins->iterator()), temp(), temp(), temp());
6158 add(lir, ins);
6159 }
6160
6161 void LIRGenerator::visitCloseIterCache(MCloseIterCache* ins) {
6162 LCloseIterCache* lir =
6163 new (alloc()) LCloseIterCache(useRegister(ins->iter()), temp());
6164 add(lir, ins);
6165 assignSafepoint(lir, ins);
6166 }
6167
6168 void LIRGenerator::visitOptimizeGetIteratorCache(
6169 MOptimizeGetIteratorCache* ins) {
6170 MDefinition* value = ins->value();
6171 MOZ_ASSERT(value->type() == MIRType::Value);
6172
6173 auto* lir = new (alloc()) LOptimizeGetIteratorCache(useBox(value), temp());
6174 define(lir, ins);
6175 assignSafepoint(lir, ins);
6176 }
6177
6178 void LIRGenerator::visitStringLength(MStringLength* ins) {
6179 MOZ_ASSERT(ins->string()->type() == MIRType::String);
6180 define(new (alloc()) LStringLength(useRegisterAtStart(ins->string())), ins);
6181 }
6182
6183 void LIRGenerator::visitArgumentsLength(MArgumentsLength* ins) {
6184 define(new (alloc()) LArgumentsLength(), ins);
6185 }
6186
6187 void LIRGenerator::visitGetFrameArgument(MGetFrameArgument* ins) {
6188 LGetFrameArgument* lir =
6189 new (alloc()) LGetFrameArgument(useRegisterOrConstant(ins->index()));
6190 defineBox(lir, ins);
6191 }
6192
6193 void LIRGenerator::visitGetFrameArgumentHole(MGetFrameArgumentHole* ins) {
6194 LDefinition spectreTemp =
6195 BoundsCheckNeedsSpectreTemp() ? temp() : LDefinition::BogusTemp();
6196
6197 auto* lir = new (alloc()) LGetFrameArgumentHole(
6198 useRegister(ins->index()), useRegister(ins->length()), spectreTemp);
6199 assignSnapshot(lir, ins->bailoutKind());
6200 defineBox(lir, ins);
6201 }
6202
6203 void LIRGenerator::visitNewTarget(MNewTarget* ins) {
6204 LNewTarget* lir = new (alloc()) LNewTarget();
6205 defineBox(lir, ins);
6206 }
6207
6208 void LIRGenerator::visitRest(MRest* ins) {
6209 MOZ_ASSERT(ins->numActuals()->type() == MIRType::Int32);
6210
6211 LRest* lir =
6212 new (alloc()) LRest(useRegisterAtStart(ins->numActuals()),
6213 tempFixed(CallTempReg0), tempFixed(CallTempReg1),
6214 tempFixed(CallTempReg2), tempFixed(CallTempReg3));
6215 defineReturn(lir, ins);
6216 assignSafepoint(lir, ins);
6217 }
6218
6219 void LIRGenerator::visitThrow(MThrow* ins) {
6220 MDefinition* value = ins->value();
6221 MOZ_ASSERT(value->type() == MIRType::Value);
6222
6223 LThrow* lir = new (alloc()) LThrow(useBoxAtStart(value));
6224 add(lir, ins);
6225 assignSafepoint(lir, ins);
6226 }
6227
6228 void LIRGenerator::visitThrowWithStack(MThrowWithStack* ins) {
6229 MDefinition* value = ins->value();
6230 MOZ_ASSERT(value->type() == MIRType::Value);
6231
6232 MDefinition* stack = ins->stack();
6233 MOZ_ASSERT(stack->type() == MIRType::Value);
6234
6235 auto* lir =
6236 new (alloc()) LThrowWithStack(useBoxAtStart(value), useBoxAtStart(stack));
6237 add(lir, ins);
6238 assignSafepoint(lir, ins);
6239 }
6240
6241 void LIRGenerator::visitInCache(MInCache* ins) {
6242 MDefinition* lhs = ins->lhs();
6243 MDefinition* rhs = ins->rhs();
6244
6245 MOZ_ASSERT(lhs->type() == MIRType::String || lhs->type() == MIRType::Symbol ||
6246 lhs->type() == MIRType::Int32 || lhs->type() == MIRType::Value);
6247 MOZ_ASSERT(rhs->type() == MIRType::Object);
6248
6249 LInCache* lir =
6250 new (alloc()) LInCache(useBoxOrTyped(lhs), useRegister(rhs), temp());
6251 define(lir, ins);
6252 assignSafepoint(lir, ins);
6253 }
6254
6255 void LIRGenerator::visitHasOwnCache(MHasOwnCache* ins) {
6256 MDefinition* value = ins->value();
6257 MOZ_ASSERT(value->type() == MIRType::Object ||
6258 value->type() == MIRType::Value);
6259
6260 MDefinition* id = ins->idval();
6261 MOZ_ASSERT(id->type() == MIRType::String || id->type() == MIRType::Symbol ||
6262 id->type() == MIRType::Int32 || id->type() == MIRType::Value);
6263
6264 // Emit an overrecursed check: this is necessary because the cache can
6265 // attach a scripted getter stub that calls this script recursively.
6266 gen->setNeedsOverrecursedCheck();
6267
6268 LHasOwnCache* lir =
6269 new (alloc()) LHasOwnCache(useBoxOrTyped(value), useBoxOrTyped(id));
6270 define(lir, ins);
6271 assignSafepoint(lir, ins);
6272 }
6273
6274 void LIRGenerator::visitCheckPrivateFieldCache(MCheckPrivateFieldCache* ins) {
6275 MDefinition* value = ins->value();
6276 MOZ_ASSERT(value->type() == MIRType::Object ||
6277 value->type() == MIRType::Value);
6278
6279 MDefinition* id = ins->idval();
6280 MOZ_ASSERT(id->type() == MIRType::String || id->type() == MIRType::Symbol ||
6281 id->type() == MIRType::Int32 || id->type() == MIRType::Value);
6282
6283 LCheckPrivateFieldCache* lir = new (alloc())
6284 LCheckPrivateFieldCache(useBoxOrTyped(value), useBoxOrTyped(id));
6285 define(lir, ins);
6286 assignSafepoint(lir, ins);
6287 }
6288
6289 void LIRGenerator::visitNewPrivateName(MNewPrivateName* ins) {
6290 auto* lir = new (alloc()) LNewPrivateName();
6291 defineReturn(lir, ins);
6292 assignSafepoint(lir, ins);
6293 }
6294
6295 void LIRGenerator::visitInstanceOf(MInstanceOf* ins) {
6296 MDefinition* lhs = ins->lhs();
6297 MDefinition* rhs = ins->rhs();
6298
6299 MOZ_ASSERT(lhs->type() == MIRType::Value || lhs->type() == MIRType::Object);
6300 MOZ_ASSERT(rhs->type() == MIRType::Object);
6301
6302 if (lhs->type() == MIRType::Object) {
6303 auto* lir = new (alloc()) LInstanceOfO(useRegister(lhs), useRegister(rhs));
6304 define(lir, ins);
6305 assignSafepoint(lir, ins);
6306 } else {
6307 auto* lir = new (alloc()) LInstanceOfV(useBox(lhs), useRegister(rhs));
6308 define(lir, ins);
6309 assignSafepoint(lir, ins);
6310 }
6311 }
6312
6313 void LIRGenerator::visitInstanceOfCache(MInstanceOfCache* ins) {
6314 MDefinition* lhs = ins->lhs();
6315 MDefinition* rhs = ins->rhs();
6316
6317 MOZ_ASSERT(lhs->type() == MIRType::Value);
6318 MOZ_ASSERT(rhs->type() == MIRType::Object);
6319
6320 LInstanceOfCache* lir =
6321 new (alloc()) LInstanceOfCache(useBox(lhs), useRegister(rhs));
6322 define(lir, ins);
6323 assignSafepoint(lir, ins);
6324 }
6325
6326 void LIRGenerator::visitIsArray(MIsArray* ins) {
6327 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6328
6329 if (ins->value()->type() == MIRType::Object) {
6330 LIsArrayO* lir = new (alloc()) LIsArrayO(useRegister(ins->value()));
6331 define(lir, ins);
6332 assignSafepoint(lir, ins);
6333 } else {
6334 MOZ_ASSERT(ins->value()->type() == MIRType::Value);
6335 LIsArrayV* lir = new (alloc()) LIsArrayV(useBox(ins->value()), temp());
6336 define(lir, ins);
6337 assignSafepoint(lir, ins);
6338 }
6339 }
6340
6341 void LIRGenerator::visitIsTypedArray(MIsTypedArray* ins) {
6342 MOZ_ASSERT(ins->value()->type() == MIRType::Object);
6343 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6344
6345 auto* lir = new (alloc()) LIsTypedArray(useRegister(ins->value()));
6346 define(lir, ins);
6347
6348 if (ins->isPossiblyWrapped()) {
6349 assignSafepoint(lir, ins);
6350 }
6351 }
6352
6353 void LIRGenerator::visitIsCallable(MIsCallable* ins) {
6354 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6355
6356 if (ins->object()->type() == MIRType::Object) {
6357 define(new (alloc()) LIsCallableO(useRegister(ins->object())), ins);
6358 } else {
6359 MOZ_ASSERT(ins->object()->type() == MIRType::Value);
6360 define(new (alloc()) LIsCallableV(useBox(ins->object()), temp()), ins);
6361 }
6362 }
6363
6364 void LIRGenerator::visitIsConstructor(MIsConstructor* ins) {
6365 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6366 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6367 define(new (alloc()) LIsConstructor(useRegister(ins->object())), ins);
6368 }
6369
6370 void LIRGenerator::visitIsCrossRealmArrayConstructor(
6371 MIsCrossRealmArrayConstructor* ins) {
6372 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6373 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6374 define(new (alloc())
6375 LIsCrossRealmArrayConstructor(useRegister(ins->object())),
6376 ins);
6377 }
6378
6379 static bool CanEmitAtUseForSingleTest(MInstruction* ins) {
6380 if (!ins->canEmitAtUses()) {
6381 return false;
6382 }
6383
6384 MUseIterator iter(ins->usesBegin());
6385 if (iter == ins->usesEnd()) {
6386 return false;
6387 }
6388
6389 MNode* node = iter->consumer();
6390 if (!node->isDefinition()) {
6391 return false;
6392 }
6393
6394 if (!node->toDefinition()->isTest()) {
6395 return false;
6396 }
6397
6398 iter++;
6399 return iter == ins->usesEnd();
6400 }
6401
6402 void LIRGenerator::visitIsObject(MIsObject* ins) {
6403 if (CanEmitAtUseForSingleTest(ins)) {
6404 emitAtUses(ins);
6405 return;
6406 }
6407
6408 MDefinition* opd = ins->input();
6409 MOZ_ASSERT(opd->type() == MIRType::Value);
6410 LIsObject* lir = new (alloc()) LIsObject(useBoxAtStart(opd));
6411 define(lir, ins);
6412 }
6413
6414 void LIRGenerator::visitIsNullOrUndefined(MIsNullOrUndefined* ins) {
6415 if (CanEmitAtUseForSingleTest(ins)) {
6416 emitAtUses(ins);
6417 return;
6418 }
6419
6420 MDefinition* opd = ins->input();
6421 if (opd->type() == MIRType::Value) {
6422 auto* lir = new (alloc()) LIsNullOrUndefined(useBoxAtStart(opd));
6423 define(lir, ins);
6424 } else {
6425 define(new (alloc()) LInteger(IsNullOrUndefined(opd->type())), ins);
6426 }
6427 }
6428
6429 void LIRGenerator::visitHasClass(MHasClass* ins) {
6430 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6431 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6432 define(new (alloc()) LHasClass(useRegister(ins->object())), ins);
6433 }
6434
6435 void LIRGenerator::visitHasShape(MHasShape* ins) {
6436 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6437 MOZ_ASSERT(ins->type() == MIRType::Boolean);
6438 define(new (alloc()) LHasShape(useRegister(ins->object())), ins);
6439 }
6440
6441 void LIRGenerator::visitGuardToClass(MGuardToClass* ins) {
6442 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6443 MOZ_ASSERT(ins->type() == MIRType::Object);
6444 LGuardToClass* lir =
6445 new (alloc()) LGuardToClass(useRegisterAtStart(ins->object()), temp());
6446 assignSnapshot(lir, ins->bailoutKind());
6447 defineReuseInput(lir, ins, 0);
6448 }
6449
6450 void LIRGenerator::visitGuardToEitherClass(MGuardToEitherClass* ins) {
6451 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6452 MOZ_ASSERT(ins->type() == MIRType::Object);
6453 auto* lir = new (alloc())
6454 LGuardToEitherClass(useRegisterAtStart(ins->object()), temp());
6455 assignSnapshot(lir, ins->bailoutKind());
6456 defineReuseInput(lir, ins, 0);
6457 }
6458
6459 void LIRGenerator::visitGuardToFunction(MGuardToFunction* ins) {
6460 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6461 MOZ_ASSERT(ins->type() == MIRType::Object);
6462 LGuardToFunction* lir =
6463 new (alloc()) LGuardToFunction(useRegisterAtStart(ins->object()), temp());
6464 assignSnapshot(lir, ins->bailoutKind());
6465 defineReuseInput(lir, ins, 0);
6466 }
6467
6468 void LIRGenerator::visitObjectClassToString(MObjectClassToString* ins) {
6469 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
6470 MOZ_ASSERT(ins->type() == MIRType::String);
6471 auto* lir = new (alloc()) LObjectClassToString(
6472 useRegisterAtStart(ins->object()), tempFixed(CallTempReg0));
6473 assignSnapshot(lir, ins->bailoutKind());
6474 defineReturn(lir, ins);
6475 }
6476
6477 void LIRGenerator::visitWasmAddOffset(MWasmAddOffset* ins) {
6478 MOZ_ASSERT(ins->offset());
6479 if (ins->base()->type() == MIRType::Int32) {
6480 MOZ_ASSERT(ins->type() == MIRType::Int32);
6481 MOZ_ASSERT(ins->offset() <= UINT32_MAX); // Because memory32
6482 define(new (alloc()) LWasmAddOffset(useRegisterAtStart(ins->base())), ins);
6483 } else {
6484 MOZ_ASSERT(ins->type() == MIRType::Int64);
6485 #ifdef JS_64BIT
6486 defineInt64(new (alloc())
6487 LWasmAddOffset64(useInt64RegisterAtStart(ins->base())),
6488 ins);
6489 #else
6490 // Avoid situation where the input is (a,b) and the output is (b,a).
6491 defineInt64ReuseInput(
6492 new (alloc()) LWasmAddOffset64(useInt64RegisterAtStart(ins->base())),
6493 ins, 0);
6494 #endif
6495 }
6496 }
6497
6498 void LIRGenerator::visitWasmLoadInstance(MWasmLoadInstance* ins) {
6499 if (ins->type() == MIRType::Int64) {
6500 #ifdef JS_PUNBOX64
6501 LAllocation instance = useRegisterAtStart(ins->instance());
6502 #else
6503 // Avoid reusing instance for a 64-bit output pair as the load clobbers the
6504 // first half of that pair before loading the second half.
6505 LAllocation instance = useRegister(ins->instance());
6506 #endif
6507 auto* lir = new (alloc()) LWasmLoadInstance64(instance);
6508 defineInt64(lir, ins);
6509 } else {
6510 auto* lir =
6511 new (alloc()) LWasmLoadInstance(useRegisterAtStart(ins->instance()));
6512 define(lir, ins);
6513 }
6514 }
6515
6516 void LIRGenerator::visitWasmStoreInstance(MWasmStoreInstance* ins) {
6517 MDefinition* value = ins->value();
6518 if (value->type() == MIRType::Int64) {
6519 #ifdef JS_PUNBOX64
6520 LAllocation instance = useRegisterAtStart(ins->instance());
6521 LInt64Allocation valueAlloc = useInt64RegisterAtStart(value);
6522 #else
6523 LAllocation instance = useRegister(ins->instance());
6524 LInt64Allocation valueAlloc = useInt64Register(value);
6525 #endif
6526 add(new (alloc()) LWasmStoreSlotI64(valueAlloc, instance, ins->offset(),
6527 mozilla::Nothing()),
6528 ins);
6529 } else {
6530 MOZ_ASSERT(value->type() != MIRType::WasmAnyRef);
6531 LAllocation instance = useRegisterAtStart(ins->instance());
6532 LAllocation valueAlloc = useRegisterAtStart(value);
6533 add(new (alloc())
6534 LWasmStoreSlot(valueAlloc, instance, ins->offset(), value->type(),
6535 MNarrowingOp::None, mozilla::Nothing()),
6536 ins);
6537 }
6538 }
6539
6540 void LIRGenerator::visitWasmHeapReg(MWasmHeapReg* ins) {
6541 #ifdef WASM_HAS_HEAPREG
6542 auto* lir = new (alloc()) LWasmHeapReg();
6543 define(lir, ins);
6544 #else
6545 MOZ_CRASH();
6546 #endif
6547 }
6548
6549 void LIRGenerator::visitWasmBoundsCheck(MWasmBoundsCheck* ins) {
6550 MOZ_ASSERT(!ins->isRedundant());
6551
6552 MDefinition* index = ins->index();
6553 MDefinition* boundsCheckLimit = ins->boundsCheckLimit();
6554
6555 MOZ_ASSERT(boundsCheckLimit->type() == index->type());
6556
6557 if (index->type() == MIRType::Int64) {
6558 if (JitOptions.spectreIndexMasking) {
6559 auto* lir = new (alloc()) LWasmBoundsCheck64(
6560 useInt64RegisterAtStart(index), useInt64Register(boundsCheckLimit));
6561 defineInt64ReuseInput(lir, ins, 0);
6562 } else {
6563 auto* lir = new (alloc())
6564 LWasmBoundsCheck64(useInt64RegisterAtStart(index),
6565 useInt64RegisterAtStart(boundsCheckLimit));
6566 add(lir, ins);
6567 }
6568 } else {
6569 MOZ_ASSERT(index->type() == MIRType::Int32);
6570
6571 if (JitOptions.spectreIndexMasking) {
6572 auto* lir = new (alloc()) LWasmBoundsCheck(useRegisterAtStart(index),
6573 useRegister(boundsCheckLimit));
6574 defineReuseInput(lir, ins, 0);
6575 } else {
6576 auto* lir = new (alloc()) LWasmBoundsCheck(
6577 useRegisterAtStart(index), useRegisterAtStart(boundsCheckLimit));
6578 add(lir, ins);
6579 }
6580 }
6581 }
6582
6583 void LIRGenerator::visitWasmBoundsCheckRange32(MWasmBoundsCheckRange32* ins) {
6584 MDefinition* index = ins->index();
6585 MDefinition* length = ins->length();
6586 MDefinition* limit = ins->limit();
6587
6588 MOZ_ASSERT(index->type() == MIRType::Int32);
6589 MOZ_ASSERT(length->type() == MIRType::Int32);
6590 MOZ_ASSERT(limit->type() == MIRType::Int32);
6591
6592 add(new (alloc()) LWasmBoundsCheckRange32(
6593 useRegister(index), useRegister(length), useRegister(limit), temp()),
6594 ins);
6595 }
6596
6597 void LIRGenerator::visitWasmAlignmentCheck(MWasmAlignmentCheck* ins) {
6598 MDefinition* index = ins->index();
6599 if (index->type() == MIRType::Int64) {
6600 auto* lir =
6601 new (alloc()) LWasmAlignmentCheck64(useInt64RegisterAtStart(index));
6602 add(lir, ins);
6603 } else {
6604 auto* lir = new (alloc()) LWasmAlignmentCheck(useRegisterAtStart(index));
6605 add(lir, ins);
6606 }
6607 }
6608
6609 void LIRGenerator::visitWasmLoadInstanceDataField(
6610 MWasmLoadInstanceDataField* ins) {
6611 size_t offs = wasm::Instance::offsetInData(ins->instanceDataOffset());
6612 if (ins->type() == MIRType::Int64) {
6613 #ifdef JS_PUNBOX64
6614 LAllocation instance = useRegisterAtStart(ins->instance());
6615 #else
6616 // Avoid reusing instance for the output pair as the load clobbers the first
6617 // half of that pair before loading the second half.
6618 LAllocation instance = useRegister(ins->instance());
6619 #endif
6620 defineInt64(new (alloc())
6621 LWasmLoadSlotI64(instance, offs, mozilla::Nothing()),
6622 ins);
6623 } else {
6624 LAllocation instance = useRegisterAtStart(ins->instance());
6625 define(new (alloc()) LWasmLoadSlot(instance, offs, ins->type(),
6626 MWideningOp::None, mozilla::Nothing()),
6627 ins);
6628 }
6629 }
6630
6631 void LIRGenerator::visitWasmLoadGlobalCell(MWasmLoadGlobalCell* ins) {
6632 if (ins->type() == MIRType::Int64) {
6633 #ifdef JS_PUNBOX64
6634 LAllocation cellPtr = useRegisterAtStart(ins->cellPtr());
6635 #else
6636 // Avoid reusing cellPtr for the output pair as the load clobbers the first
6637 // half of that pair before loading the second half.
6638 LAllocation cellPtr = useRegister(ins->cellPtr());
6639 #endif
6640 defineInt64(new (alloc())
6641 LWasmLoadSlotI64(cellPtr, /*offset=*/0, mozilla::Nothing()),
6642 ins);
6643 } else {
6644 LAllocation cellPtr = useRegisterAtStart(ins->cellPtr());
6645 define(new (alloc()) LWasmLoadSlot(cellPtr, /*offset=*/0, ins->type(),
6646 MWideningOp::None, mozilla::Nothing()),
6647 ins);
6648 }
6649 }
6650
6651 void LIRGenerator::visitWasmLoadTableElement(MWasmLoadTableElement* ins) {
6652 LAllocation elements = useRegisterAtStart(ins->elements());
6653 LAllocation index = useRegisterAtStart(ins->index());
6654 define(new (alloc()) LWasmLoadTableElement(elements, index), ins);
6655 }
6656
6657 void LIRGenerator::visitWasmStoreInstanceDataField(
6658 MWasmStoreInstanceDataField* ins) {
6659 MDefinition* value = ins->value();
6660 size_t offs = wasm::Instance::offsetInData(ins->instanceDataOffset());
6661 if (value->type() == MIRType::Int64) {
6662 #ifdef JS_PUNBOX64
6663 LAllocation instance = useRegisterAtStart(ins->instance());
6664 LInt64Allocation valueAlloc = useInt64RegisterAtStart(value);
6665 #else
6666 LAllocation instance = useRegister(ins->instance());
6667 LInt64Allocation valueAlloc = useInt64Register(value);
6668 #endif
6669 add(new (alloc())
6670 LWasmStoreSlotI64(valueAlloc, instance, offs, mozilla::Nothing()),
6671 ins);
6672 } else {
6673 MOZ_ASSERT(value->type() != MIRType::WasmAnyRef);
6674 LAllocation instance = useRegisterAtStart(ins->instance());
6675 LAllocation valueAlloc = useRegisterAtStart(value);
6676 add(new (alloc()) LWasmStoreSlot(valueAlloc, instance, offs, value->type(),
6677 MNarrowingOp::None, mozilla::Nothing()),
6678 ins);
6679 }
6680 }
6681
6682 void LIRGenerator::visitWasmStoreGlobalCell(MWasmStoreGlobalCell* ins) {
6683 MDefinition* value = ins->value();
6684 size_t offs = 0;
6685 if (value->type() == MIRType::Int64) {
6686 #ifdef JS_PUNBOX64
6687 LAllocation cellPtr = useRegisterAtStart(ins->cellPtr());
6688 LInt64Allocation valueAlloc = useInt64RegisterAtStart(value);
6689 #else
6690 LAllocation cellPtr = useRegister(ins->cellPtr());
6691 LInt64Allocation valueAlloc = useInt64Register(value);
6692 #endif
6693 add(new (alloc())
6694 LWasmStoreSlotI64(valueAlloc, cellPtr, offs, mozilla::Nothing()));
6695 } else {
6696 MOZ_ASSERT(value->type() != MIRType::WasmAnyRef);
6697 LAllocation cellPtr = useRegisterAtStart(ins->cellPtr());
6698 LAllocation valueAlloc = useRegisterAtStart(value);
6699 add(new (alloc()) LWasmStoreSlot(valueAlloc, cellPtr, offs, value->type(),
6700 MNarrowingOp::None, mozilla::Nothing()));
6701 }
6702 }
6703
6704 void LIRGenerator::visitWasmStoreStackResult(MWasmStoreStackResult* ins) {
6705 MDefinition* stackResultArea = ins->stackResultArea();
6706 MDefinition* value = ins->value();
6707 size_t offs = ins->offset();
6708 LInstruction* lir;
6709 if (value->type() == MIRType::Int64) {
6710 lir = new (alloc())
6711 LWasmStoreStackResultI64(useInt64Register(value), useRegister(stackResultArea),
6712 offs);
6713 } else {
6714 lir = new (alloc())
6715 LWasmStoreStackResult(useRegister(value), useRegister(stackResultArea), offs,
6716 value->type());
6717 }
6718 add(lir, ins);
6719 }
6720
6721 void LIRGenerator::visitWasmDerivedPointer(MWasmDerivedPointer* ins) {
6722 LAllocation base = useRegisterAtStart(ins->base());
6723 define(new (alloc()) LWasmDerivedPointer(base), ins);
6724 }
6725
6726 void LIRGenerator::visitWasmDerivedIndexPointer(MWasmDerivedIndexPointer* ins) {
6727 LAllocation base = useRegisterAtStart(ins->base());
6728 LAllocation index = useRegisterAtStart(ins->index());
6729 define(new (alloc()) LWasmDerivedIndexPointer(base, index), ins);
6730 }
6731
6732 void LIRGenerator::visitWasmStoreRef(MWasmStoreRef* ins) {
6733 LAllocation instance = useRegister(ins->instance());
6734 LAllocation valueBase = useFixed(ins->valueBase(), PreBarrierReg);
6735 LAllocation value = useRegister(ins->value());
6736 uint32_t valueOffset = ins->offset();
6737 add(new (alloc())
6738 LWasmStoreRef(instance, valueBase, value, temp(), valueOffset,
6739 mozilla::Nothing(), ins->preBarrierKind()),
6740 ins);
6741 }
6742
6743 void LIRGenerator::visitWasmPostWriteBarrierWholeCell(
6744 MWasmPostWriteBarrierWholeCell* ins) {
6745 LWasmPostWriteBarrierWholeCell* lir = new (alloc())
6746 LWasmPostWriteBarrierWholeCell(useFixed(ins->instance(), InstanceReg),
6747 useRegister(ins->object()),
6748 useRegister(ins->value()), temp());
6749 add(lir, ins);
6750 assignWasmSafepoint(lir);
6751 }
6752
6753 void LIRGenerator::visitWasmPostWriteBarrierEdgeAtIndex(
6754 MWasmPostWriteBarrierEdgeAtIndex* ins) {
6755 LWasmPostWriteBarrierEdgeAtIndex* lir =
6756 new (alloc()) LWasmPostWriteBarrierEdgeAtIndex(
6757 useFixed(ins->instance(), InstanceReg), useRegister(ins->object()),
6758 useRegister(ins->valueBase()), useRegister(ins->index()),
6759 useRegister(ins->value()), temp(), ins->elemSize());
6760 add(lir, ins);
6761 assignWasmSafepoint(lir);
6762 }
6763
6764 void LIRGenerator::visitWasmParameter(MWasmParameter* ins) {
6765 ABIArg abi = ins->abi();
6766 if (ins->type() == MIRType::StackResults) {
6767 // Functions that return stack results receive an extra incoming parameter
6768 // with type MIRType::StackResults. This value is a pointer to fresh
6769 // memory. Here we treat it as if it were in fact MIRType::Pointer.
6770 auto* lir = new (alloc()) LWasmParameter;
6771 LDefinition def(LDefinition::TypeFrom(MIRType::Pointer),
6772 LDefinition::FIXED);
6773 def.setOutput(abi.argInRegister() ? LAllocation(abi.reg())
6774 : LArgument(abi.offsetFromArgBase()));
6775 define(lir, ins, def);
6776 return;
6777 }
6778 if (abi.argInRegister()) {
6779 #if defined(JS_NUNBOX32)
6780 if (abi.isGeneralRegPair()) {
6781 defineInt64Fixed(
6782 new (alloc()) LWasmParameterI64, ins,
6783 LInt64Allocation(LAllocation(AnyRegister(abi.gpr64().high)),
6784 LAllocation(AnyRegister(abi.gpr64().low))));
6785 return;
6786 }
6787 #endif
6788 defineFixed(new (alloc()) LWasmParameter, ins, LAllocation(abi.reg()));
6789 return;
6790 }
6791 if (ins->type() == MIRType::Int64) {
6792 MOZ_ASSERT(!abi.argInRegister());
6793 defineInt64Fixed(
6794 new (alloc()) LWasmParameterI64, ins,
6795 #if defined(JS_NUNBOX32)
6796 LInt64Allocation(LArgument(abi.offsetFromArgBase() + INT64HIGH_OFFSET),
6797 LArgument(abi.offsetFromArgBase() + INT64LOW_OFFSET))
6798 #else
6799 LInt64Allocation(LArgument(abi.offsetFromArgBase()))
6800 #endif
6801 );
6802 } else {
6803 MOZ_ASSERT(IsNumberType(ins->type()) || ins->type() == MIRType::WasmAnyRef
6804 #ifdef ENABLE_WASM_SIMD
6805 || ins->type() == MIRType::Simd128
6806 #endif
6807 );
6808 defineFixed(new (alloc()) LWasmParameter, ins,
6809 LArgument(abi.offsetFromArgBase()));
6810 }
6811 }
6812
6813 void LIRGenerator::visitWasmReturn(MWasmReturn* ins) {
6814 MDefinition* rval = ins->getOperand(0);
6815 MDefinition* instance = ins->getOperand(1);
6816
6817 if (rval->type() == MIRType::Int64) {
6818 add(new (alloc()) LWasmReturnI64(useInt64Fixed(rval, ReturnReg64),
6819 useFixed(instance, InstanceReg)));
6820 return;
6821 }
6822
6823 LAllocation returnReg;
6824 if (rval->type() == MIRType::Float32) {
6825 returnReg = useFixed(rval, ReturnFloat32Reg);
6826 } else if (rval->type() == MIRType::Double) {
6827 returnReg = useFixed(rval, ReturnDoubleReg);
6828 #ifdef ENABLE_WASM_SIMD
6829 } else if (rval->type() == MIRType::Simd128) {
6830 returnReg = useFixed(rval, ReturnSimd128Reg);
6831 #endif
6832 } else if (rval->type() == MIRType::Int32 ||
6833 rval->type() == MIRType::WasmAnyRef) {
6834 returnReg = useFixed(rval, ReturnReg);
6835 } else {
6836 MOZ_CRASH("Unexpected wasm return type");
6837 }
6838
6839 LWasmReturn* lir =
6840 new (alloc()) LWasmReturn(useFixed(instance, InstanceReg), returnReg);
6841 add(lir);
6842 }
6843
6844 void LIRGenerator::visitWasmReturnVoid(MWasmReturnVoid* ins) {
6845 MDefinition* instance = ins->getOperand(0);
6846 LWasmReturnVoid* lir =
6847 new (alloc()) LWasmReturnVoid(useFixed(instance, InstanceReg));
6848 add(lir);
6849 }
6850
6851 void LIRGenerator::visitWasmStackArg(MWasmStackArg* ins) {
6852 if (ins->arg()->type() == MIRType::Int64) {
6853 add(new (alloc())
6854 LWasmStackArgI64(useInt64RegisterOrConstantAtStart(ins->arg())),
6855 ins);
6856 } else if (IsFloatingPointType(ins->arg()->type())) {
6857 MOZ_ASSERT(!ins->arg()->isEmittedAtUses());
6858 add(new (alloc()) LWasmStackArg(useRegisterAtStart(ins->arg())), ins);
6859 } else {
6860 add(new (alloc()) LWasmStackArg(useRegisterOrConstantAtStart(ins->arg())),
6861 ins);
6862 }
6863 }
6864
6865 void LIRGenerator::visitWasmRegisterResult(MWasmRegisterResult* ins) {
6866 auto* lir = new (alloc()) LWasmRegisterResult();
6867 uint32_t vreg = getVirtualRegister();
6868 MOZ_ASSERT(ins->type() != MIRType::Int64);
6869 auto type = LDefinition::TypeFrom(ins->type());
6870 lir->setDef(0, LDefinition(vreg, type, LGeneralReg(ins->loc())));
6871 ins->setVirtualRegister(vreg);
6872 add(lir, ins);
6873 }
6874
6875 void LIRGenerator::visitWasmFloatRegisterResult(MWasmFloatRegisterResult* ins) {
6876 auto* lir = new (alloc()) LWasmRegisterResult();
6877 uint32_t vreg = getVirtualRegister();
6878 auto type = LDefinition::TypeFrom(ins->type());
6879 lir->setDef(0, LDefinition(vreg, type, LFloatReg(ins->loc())));
6880 ins->setVirtualRegister(vreg);
6881 add(lir, ins);
6882 }
6883
6884 void LIRGenerator::visitWasmRegister64Result(MWasmRegister64Result* ins) {
6885 MOZ_ASSERT(ins->type() == MIRType::Int64);
6886 uint32_t vreg = getVirtualRegister();
6887
6888 #if defined(JS_NUNBOX32)
6889 auto* lir = new (alloc()) LWasmRegisterPairResult();
6890 lir->setDef(INT64LOW_INDEX,
6891 LDefinition(vreg + INT64LOW_INDEX, LDefinition::GENERAL,
6892 LGeneralReg(ins->loc().low)));
6893 lir->setDef(INT64HIGH_INDEX,
6894 LDefinition(vreg + INT64HIGH_INDEX, LDefinition::GENERAL,
6895 LGeneralReg(ins->loc().high)));
6896 getVirtualRegister();
6897 #elif defined(JS_PUNBOX64)
6898 auto* lir = new (alloc()) LWasmRegisterResult();
6899 lir->setDef(
6900 0, LDefinition(vreg, LDefinition::GENERAL, LGeneralReg(ins->loc().reg)));
6901 #else
6902 # error expected either JS_NUNBOX32 or JS_PUNBOX64
6903 #endif
6904
6905 ins->setVirtualRegister(vreg);
6906 add(lir, ins);
6907 }
6908
6909 void LIRGenerator::visitWasmStackResultArea(MWasmStackResultArea* ins) {
6910 MOZ_ASSERT(ins->type() == MIRType::StackResults);
6911 auto* lir = new (alloc()) LWasmStackResultArea(temp());
6912 uint32_t vreg = getVirtualRegister();
6913 lir->setDef(0,
6914 LDefinition(vreg, LDefinition::STACKRESULTS, LDefinition::STACK));
6915 ins->setVirtualRegister(vreg);
6916 add(lir, ins);
6917 }
6918
6919 void LIRGenerator::visitWasmStackResult(MWasmStackResult* ins) {
6920 MWasmStackResultArea* area = ins->resultArea()->toWasmStackResultArea();
6921 LDefinition::Policy pol = LDefinition::STACK;
6922
6923 if (ins->type() == MIRType::Int64) {
6924 auto* lir = new (alloc()) LWasmStackResult64;
6925 lir->setOperand(0, use(area, LUse(LUse::STACK, /* usedAtStart = */ true)));
6926 uint32_t vreg = getVirtualRegister();
6927 LDefinition::Type typ = LDefinition::GENERAL;
6928 #if defined(JS_NUNBOX32)
6929 getVirtualRegister();
6930 lir->setDef(INT64LOW_INDEX, LDefinition(vreg + INT64LOW_INDEX, typ, pol));
6931 lir->setDef(INT64HIGH_INDEX, LDefinition(vreg + INT64HIGH_INDEX, typ, pol));
6932 #else
6933 lir->setDef(0, LDefinition(vreg, typ, pol));
6934 #endif
6935 ins->setVirtualRegister(vreg);
6936 add(lir, ins);
6937 return;
6938 }
6939
6940 auto* lir = new (alloc()) LWasmStackResult;
6941 lir->setOperand(0, use(area, LUse(LUse::STACK, /* usedAtStart = */ true)));
6942 uint32_t vreg = getVirtualRegister();
6943 LDefinition::Type typ = LDefinition::TypeFrom(ins->type());
6944 lir->setDef(0, LDefinition(vreg, typ, pol));
6945 ins->setVirtualRegister(vreg);
6946 add(lir, ins);
6947 }
6948
6949 void LIRGenerator::visitWasmStackSwitchToSuspendable(
6950 MWasmStackSwitchToSuspendable* ins) {
6951 #ifdef ENABLE_WASM_JSPI
6952 auto* lir = new (alloc()) LWasmStackSwitchToSuspendable(
6953 useFixedAtStart(ins->suspender(), ABINonArgReg0),
6954 useFixedAtStart(ins->fn(), ABINonArgReg1),
6955 useFixedAtStart(ins->data(), ABINonArgReg2));
6956
6957 add(lir, ins);
6958 assignWasmSafepoint(lir);
6959 #else
6960 MOZ_CRASH("NYI");
6961 #endif
6962 }
6963
6964 void LIRGenerator::visitWasmStackSwitchToMain(MWasmStackSwitchToMain* ins) {
6965 #ifdef ENABLE_WASM_JSPI
6966 auto* lir = new (alloc())
6967 LWasmStackSwitchToMain(useFixedAtStart(ins->suspender(), ABINonArgReg0),
6968 useFixedAtStart(ins->fn(), ABINonArgReg1),
6969 useFixedAtStart(ins->data(), ABINonArgReg2));
6970
6971 defineReturn(lir, ins);
6972 assignWasmSafepoint(lir);
6973 #else
6974 MOZ_CRASH("NYI");
6975 #endif
6976 }
6977
6978 void LIRGenerator::visitWasmStackContinueOnSuspendable(
6979 MWasmStackContinueOnSuspendable* ins) {
6980 #ifdef ENABLE_WASM_JSPI
6981 auto* lir = new (alloc()) LWasmStackContinueOnSuspendable(
6982 useFixedAtStart(ins->suspender(), ABINonArgReg0),
6983 useFixedAtStart(ins->result(), ABINonArgReg2));
6984
6985 add(lir, ins);
6986 assignWasmSafepoint(lir);
6987 #else
6988 MOZ_CRASH("NYI");
6989 #endif
6990 }
6991
6992 template <class MWasmCallT>
6993 void LIRGenerator::visitWasmCall(MWasmCallT ins) {
6994 bool needsBoundsCheck = true;
6995 mozilla::Maybe<uint32_t> tableSize;
6996
6997 if (ins->callee().isTable()) {
6998 MDefinition* index = ins->getOperand(ins->numArgs());
6999
7000 if (ins->callee().which() == wasm::CalleeDesc::WasmTable) {
7001 uint64_t minLength = ins->callee().wasmTableMinLength();
7002 mozilla::Maybe<uint64_t> maxLength = ins->callee().wasmTableMaxLength();
7003 if (index->isConstant() &&
7004 uint32_t(index->toConstant()->toInt32()) < minLength) {
7005 needsBoundsCheck = false;
7006 }
7007 if (minLength <= UINT32_MAX && maxLength.isSome() &&
7008 *maxLength == minLength) {
7009 tableSize = maxLength;
7010 }
7011 }
7012 }
7013
7014 auto* lir = allocateVariadic<LWasmCall>(ins->numOperands(), needsBoundsCheck,
7015 tableSize);
7016 if (!lir) {
7017 abort(AbortReason::Alloc, "OOM: LIRGenerator::lowerWasmCall");
7018 return;
7019 }
7020
7021 for (unsigned i = 0; i < ins->numArgs(); i++) {
7022 lir->setOperand(
7023 i, useFixedAtStart(ins->getOperand(i), ins->registerForArg(i)));
7024 }
7025
7026 if (ins->callee().isTable()) {
7027 MDefinition* index = ins->getOperand(ins->numArgs());
7028 lir->setOperand(ins->numArgs(),
7029 useFixedAtStart(index, WasmTableCallIndexReg));
7030 }
7031 if (ins->callee().isFuncRef()) {
7032 MDefinition* ref = ins->getOperand(ins->numArgs());
7033 lir->setOperand(ins->numArgs(), useFixedAtStart(ref, WasmCallRefReg));
7034 }
7035
7036 add(lir, ins);
7037 assignWasmSafepoint(lir);
7038
7039 // WasmCall with WasmTable has two call instructions, and they both need a
7040 // safepoint associated with them. Create a second safepoint here; the node
7041 // otherwise does nothing, and codegen for it only marks the safepoint at the
7042 // node.
7043 if ((ins->callee().which() == wasm::CalleeDesc::WasmTable ||
7044 ins->callee().which() == wasm::CalleeDesc::FuncRef) &&
7045 !ins->isWasmReturnCall()) {
7046 auto* adjunctSafepoint = new (alloc()) LWasmCallIndirectAdjunctSafepoint();
7047 add(adjunctSafepoint);
7048 assignWasmSafepoint(adjunctSafepoint);
7049 lir->setAdjunctSafepoint(adjunctSafepoint);
7050 }
7051 }
7052
7053 void LIRGenerator::visitWasmCallCatchable(MWasmCallCatchable* ins) {
7054 visitWasmCall(ins);
7055 }
7056
7057 void LIRGenerator::visitWasmCallUncatchable(MWasmCallUncatchable* ins) {
7058 visitWasmCall(ins);
7059 }
7060
7061 void LIRGenerator::visitWasmReturnCall(MWasmReturnCall* ins) {
7062 visitWasmCall(ins);
7063 }
7064
7065 void LIRGenerator::visitWasmCallLandingPrePad(MWasmCallLandingPrePad* ins) {
7066 add(new (alloc()) LWasmCallLandingPrePad, ins);
7067 }
7068
7069 void LIRGenerator::visitSetDOMProperty(MSetDOMProperty* ins) {
7070 MDefinition* val = ins->value();
7071
7072 Register cxReg, objReg, privReg, valueReg;
7073 GetTempRegForIntArg(0, 0, &cxReg);
7074 GetTempRegForIntArg(1, 0, &objReg);
7075 GetTempRegForIntArg(2, 0, &privReg);
7076 GetTempRegForIntArg(3, 0, &valueReg);
7077
7078 // Keep using GetTempRegForIntArg, since we want to make sure we
7079 // don't clobber registers we're already using.
7080 Register tempReg1, tempReg2;
7081 GetTempRegForIntArg(4, 0, &tempReg1);
7082 mozilla::DebugOnly<bool> ok = GetTempRegForIntArg(5, 0, &tempReg2);
7083 MOZ_ASSERT(ok, "How can we not have six temp registers?");
7084
7085 auto* lir = new (alloc()) LSetDOMProperty(
7086 useFixedAtStart(ins->object(), objReg),
7087 useBoxFixedAtStart(val, tempReg1, tempReg2), tempFixed(cxReg),
7088 tempFixed(privReg), tempFixed(valueReg));
7089 add(lir, ins);
7090 assignSafepoint(lir, ins);
7091 }
7092
7093 void LIRGenerator::visitGetDOMProperty(MGetDOMProperty* ins) {
7094 Register cxReg, objReg, privReg, valueReg;
7095 GetTempRegForIntArg(0, 0, &cxReg);
7096 GetTempRegForIntArg(1, 0, &objReg);
7097 GetTempRegForIntArg(2, 0, &privReg);
7098 mozilla::DebugOnly<bool> ok = GetTempRegForIntArg(3, 0, &valueReg);
7099 MOZ_ASSERT(ok, "How can we not have four temp registers?");
7100 auto* lir = new (alloc())
7101 LGetDOMProperty(useFixedAtStart(ins->object(), objReg), tempFixed(cxReg),
7102 tempFixed(privReg), tempFixed(valueReg));
7103
7104 defineReturn(lir, ins);
7105 assignSafepoint(lir, ins);
7106 }
7107
7108 void LIRGenerator::visitGetDOMMember(MGetDOMMember* ins) {
7109 MOZ_ASSERT(ins->isDomMovable(), "Members had better be movable");
7110 // We wish we could assert that ins->domAliasSet() == JSJitInfo::AliasNone,
7111 // but some MGetDOMMembers are for [Pure], not [Constant] properties, whose
7112 // value can in fact change as a result of DOM setters and method calls.
7113 MOZ_ASSERT(ins->domAliasSet() != JSJitInfo::AliasEverything,
7114 "Member gets had better not alias the world");
7115
7116 MDefinition* obj = ins->object();
7117 MOZ_ASSERT(obj->type() == MIRType::Object);
7118
7119 MIRType type = ins->type();
7120
7121 if (type == MIRType::Value) {
7122 LGetDOMMemberV* lir = new (alloc()) LGetDOMMemberV(useRegisterAtStart(obj));
7123 defineBox(lir, ins);
7124 } else {
7125 LGetDOMMemberT* lir =
7126 new (alloc()) LGetDOMMemberT(useRegisterForTypedLoad(obj, type));
7127 define(lir, ins);
7128 }
7129 }
7130
7131 void LIRGenerator::visitLoadDOMExpandoValue(MLoadDOMExpandoValue* ins) {
7132 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
7133 auto* lir =
7134 new (alloc()) LLoadDOMExpandoValue(useRegisterAtStart(ins->proxy()));
7135 defineBox(lir, ins);
7136 }
7137
7138 void LIRGenerator::visitLoadDOMExpandoValueGuardGeneration(
7139 MLoadDOMExpandoValueGuardGeneration* ins) {
7140 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
7141 auto* lir = new (alloc())
7142 LLoadDOMExpandoValueGuardGeneration(useRegisterAtStart(ins->proxy()));
7143 assignSnapshot(lir, ins->bailoutKind());
7144 defineBox(lir, ins);
7145 }
7146
7147 void LIRGenerator::visitLoadDOMExpandoValueIgnoreGeneration(
7148 MLoadDOMExpandoValueIgnoreGeneration* ins) {
7149 MOZ_ASSERT(ins->proxy()->type() == MIRType::Object);
7150 auto* lir = new (alloc())
7151 LLoadDOMExpandoValueIgnoreGeneration(useRegisterAtStart(ins->proxy()));
7152 defineBox(lir, ins);
7153 }
7154
7155 void LIRGenerator::visitGuardDOMExpandoMissingOrGuardShape(
7156 MGuardDOMExpandoMissingOrGuardShape* ins) {
7157 MOZ_ASSERT(ins->expando()->type() == MIRType::Value);
7158 auto* lir = new (alloc())
7159 LGuardDOMExpandoMissingOrGuardShape(useBox(ins->expando()), temp());
7160 assignSnapshot(lir, ins->bailoutKind());
7161 add(lir, ins);
7162 redefine(ins, ins->expando());
7163 }
7164
7165 void LIRGenerator::visitIncrementWarmUpCounter(MIncrementWarmUpCounter* ins) {
7166 LIncrementWarmUpCounter* lir = new (alloc()) LIncrementWarmUpCounter(temp());
7167 add(lir, ins);
7168 }
7169
7170 void LIRGenerator::visitLexicalCheck(MLexicalCheck* ins) {
7171 MDefinition* input = ins->input();
7172 MOZ_ASSERT(input->type() == MIRType::Value);
7173 LLexicalCheck* lir = new (alloc()) LLexicalCheck(useBox(input));
7174 assignSnapshot(lir, ins->bailoutKind());
7175 add(lir, ins);
7176 redefine(ins, input);
7177 }
7178
7179 void LIRGenerator::visitThrowRuntimeLexicalError(
7180 MThrowRuntimeLexicalError* ins) {
7181 LThrowRuntimeLexicalError* lir = new (alloc()) LThrowRuntimeLexicalError();
7182 add(lir, ins);
7183 assignSafepoint(lir, ins);
7184 }
7185
7186 void LIRGenerator::visitThrowMsg(MThrowMsg* ins) {
7187 LThrowMsg* lir = new (alloc()) LThrowMsg();
7188 add(lir, ins);
7189 assignSafepoint(lir, ins);
7190 }
7191
7192 void LIRGenerator::visitGlobalDeclInstantiation(MGlobalDeclInstantiation* ins) {
7193 LGlobalDeclInstantiation* lir = new (alloc()) LGlobalDeclInstantiation();
7194 add(lir, ins);
7195 assignSafepoint(lir, ins);
7196 }
7197
7198 void LIRGenerator::visitDebugger(MDebugger* ins) {
7199 auto* lir = new (alloc()) LDebugger(tempFixed(CallTempReg0));
7200 assignSnapshot(lir, ins->bailoutKind());
7201 add(lir, ins);
7202 }
7203
7204 void LIRGenerator::visitAtomicIsLockFree(MAtomicIsLockFree* ins) {
7205 define(new (alloc()) LAtomicIsLockFree(useRegister(ins->input())), ins);
7206 }
7207
7208 void LIRGenerator::visitAtomicPause(MAtomicPause* ins) {
7209 add(new (alloc()) LAtomicPause());
7210 }
7211
7212 void LIRGenerator::visitCheckReturn(MCheckReturn* ins) {
7213 MDefinition* retVal = ins->returnValue();
7214 MDefinition* thisVal = ins->thisValue();
7215 MOZ_ASSERT(retVal->type() == MIRType::Value);
7216 MOZ_ASSERT(thisVal->type() == MIRType::Value);
7217
7218 auto* lir =
7219 new (alloc()) LCheckReturn(useBoxAtStart(retVal), useBoxAtStart(thisVal));
7220 defineBox(lir, ins);
7221 assignSafepoint(lir, ins);
7222 }
7223
7224 void LIRGenerator::visitCheckIsObj(MCheckIsObj* ins) {
7225 MDefinition* input = ins->input();
7226 MOZ_ASSERT(input->type() == MIRType::Value);
7227
7228 LCheckIsObj* lir = new (alloc()) LCheckIsObj(useBox(input));
7229 define(lir, ins);
7230 assignSafepoint(lir, ins);
7231 }
7232
7233 #ifdef JS_PUNBOX64
7234 void LIRGenerator::visitCheckScriptedProxyGetResult(
7235 MCheckScriptedProxyGetResult* ins) {
7236 MDefinition* target = ins->target();
7237 MDefinition* id = ins->id();
7238 MDefinition* value = ins->value();
7239
7240 LCheckScriptedProxyGetResult* lir =
7241 new (alloc()) LCheckScriptedProxyGetResult(useBox(target), useBox(id),
7242 useBox(value), temp(), temp());
7243 add(lir, ins);
7244 assignSafepoint(lir, ins);
7245 }
7246 #endif
7247
7248 void LIRGenerator::visitCheckObjCoercible(MCheckObjCoercible* ins) {
7249 MDefinition* checkVal = ins->checkValue();
7250 MOZ_ASSERT(checkVal->type() == MIRType::Value);
7251
7252 auto* lir = new (alloc()) LCheckObjCoercible(useBoxAtStart(checkVal));
7253 redefine(ins, checkVal);
7254 add(lir, ins);
7255 assignSafepoint(lir, ins);
7256 }
7257
7258 void LIRGenerator::visitCheckClassHeritage(MCheckClassHeritage* ins) {
7259 MDefinition* heritage = ins->heritage();
7260 MOZ_ASSERT(heritage->type() == MIRType::Value);
7261
7262 auto* lir =
7263 new (alloc()) LCheckClassHeritage(useBox(heritage), temp(), temp());
7264 redefine(ins, heritage);
7265 add(lir, ins);
7266 assignSafepoint(lir, ins);
7267 }
7268
7269 void LIRGenerator::visitCheckThis(MCheckThis* ins) {
7270 MDefinition* thisValue = ins->thisValue();
7271 MOZ_ASSERT(thisValue->type() == MIRType::Value);
7272
7273 auto* lir = new (alloc()) LCheckThis(useBoxAtStart(thisValue));
7274 redefine(ins, thisValue);
7275 add(lir, ins);
7276 assignSafepoint(lir, ins);
7277 }
7278
7279 void LIRGenerator::visitCheckThisReinit(MCheckThisReinit* ins) {
7280 MDefinition* thisValue = ins->thisValue();
7281 MOZ_ASSERT(thisValue->type() == MIRType::Value);
7282
7283 auto* lir = new (alloc()) LCheckThisReinit(useBoxAtStart(thisValue));
7284 redefine(ins, thisValue);
7285 add(lir, ins);
7286 assignSafepoint(lir, ins);
7287 }
7288
7289 void LIRGenerator::visitGenerator(MGenerator* ins) {
7290 auto* lir =
7291 new (alloc()) LGenerator(useRegisterAtStart(ins->callee()),
7292 useRegisterAtStart(ins->environmentChain()),
7293 useRegisterAtStart(ins->argsObject()));
7294 defineReturn(lir, ins);
7295 assignSafepoint(lir, ins);
7296 }
7297
7298 void LIRGenerator::visitAsyncResolve(MAsyncResolve* ins) {
7299 auto* lir = new (alloc()) LAsyncResolve(useRegisterAtStart(ins->generator()),
7300 useBoxAtStart(ins->value()));
7301 defineReturn(lir, ins);
7302 assignSafepoint(lir, ins);
7303 }
7304
7305 void LIRGenerator::visitAsyncReject(MAsyncReject* ins) {
7306 auto* lir = new (alloc())
7307 LAsyncReject(useRegisterAtStart(ins->generator()),
7308 useBoxAtStart(ins->reason()), useBoxAtStart(ins->stack()));
7309 defineReturn(lir, ins);
7310 assignSafepoint(lir, ins);
7311 }
7312
7313 void LIRGenerator::visitAsyncAwait(MAsyncAwait* ins) {
7314 MOZ_ASSERT(ins->generator()->type() == MIRType::Object);
7315 auto* lir = new (alloc()) LAsyncAwait(useBoxAtStart(ins->value()),
7316 useRegisterAtStart(ins->generator()));
7317 defineReturn(lir, ins);
7318 assignSafepoint(lir, ins);
7319 }
7320
7321 void LIRGenerator::visitCanSkipAwait(MCanSkipAwait* ins) {
7322 auto* lir = new (alloc()) LCanSkipAwait(useBoxAtStart(ins->value()));
7323 defineReturn(lir, ins);
7324 assignSafepoint(lir, ins);
7325 }
7326
7327 void LIRGenerator::visitMaybeExtractAwaitValue(MMaybeExtractAwaitValue* ins) {
7328 auto* lir = new (alloc()) LMaybeExtractAwaitValue(
7329 useBoxAtStart(ins->value()), useRegisterAtStart(ins->canSkip()));
7330 defineReturn(lir, ins);
7331 assignSafepoint(lir, ins);
7332 }
7333
7334 void LIRGenerator::visitDebugCheckSelfHosted(MDebugCheckSelfHosted* ins) {
7335 MDefinition* checkVal = ins->checkValue();
7336 MOZ_ASSERT(checkVal->type() == MIRType::Value);
7337
7338 LDebugCheckSelfHosted* lir =
7339 new (alloc()) LDebugCheckSelfHosted(useBoxAtStart(checkVal));
7340 redefine(ins, checkVal);
7341 add(lir, ins);
7342 assignSafepoint(lir, ins);
7343 }
7344
7345 void LIRGenerator::visitIsPackedArray(MIsPackedArray* ins) {
7346 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
7347 MOZ_ASSERT(ins->type() == MIRType::Boolean);
7348
7349 auto lir = new (alloc()) LIsPackedArray(useRegister(ins->object()), temp());
7350 define(lir, ins);
7351 }
7352
7353 void LIRGenerator::visitGuardArrayIsPacked(MGuardArrayIsPacked* ins) {
7354 MOZ_ASSERT(ins->array()->type() == MIRType::Object);
7355
7356 auto* lir = new (alloc())
7357 LGuardArrayIsPacked(useRegister(ins->array()), temp(), temp());
7358 assignSnapshot(lir, ins->bailoutKind());
7359 add(lir, ins);
7360 redefine(ins, ins->array());
7361 }
7362
7363 void LIRGenerator::visitGetPrototypeOf(MGetPrototypeOf* ins) {
7364 MOZ_ASSERT(ins->target()->type() == MIRType::Object);
7365 MOZ_ASSERT(ins->type() == MIRType::Value);
7366
7367 auto lir = new (alloc()) LGetPrototypeOf(useRegister(ins->target()));
7368 defineBox(lir, ins);
7369 assignSafepoint(lir, ins);
7370 }
7371
7372 void LIRGenerator::visitObjectWithProto(MObjectWithProto* ins) {
7373 MOZ_ASSERT(ins->prototype()->type() == MIRType::Value);
7374 MOZ_ASSERT(ins->type() == MIRType::Object);
7375
7376 auto* lir = new (alloc()) LObjectWithProto(useBoxAtStart(ins->prototype()));
7377 defineReturn(lir, ins);
7378 assignSafepoint(lir, ins);
7379 }
7380
7381 void LIRGenerator::visitObjectStaticProto(MObjectStaticProto* ins) {
7382 MOZ_ASSERT(ins->object()->type() == MIRType::Object);
7383 MOZ_ASSERT(ins->type() == MIRType::Object);
7384
7385 auto* lir =
7386 new (alloc()) LObjectStaticProto(useRegisterAtStart(ins->object()));
7387 define(lir, ins);
7388 };
7389
7390 void LIRGenerator::visitBuiltinObject(MBuiltinObject* ins) {
7391 MOZ_ASSERT(ins->type() == MIRType::Object);
7392
7393 auto* lir = new (alloc()) LBuiltinObject();
7394 defineReturn(lir, ins);
7395 assignSafepoint(lir, ins);
7396 }
7397
7398 void LIRGenerator::visitReturn(MReturn* ret) {
7399 return visitReturnImpl(ret->getOperand(0));
7400 }
7401
7402 void LIRGenerator::visitGeneratorReturn(MGeneratorReturn* ret) {
7403 return visitReturnImpl(ret->getOperand(0), true);
7404 }
7405
7406 void LIRGenerator::visitSuperFunction(MSuperFunction* ins) {
7407 MOZ_ASSERT(ins->callee()->type() == MIRType::Object);
7408 MOZ_ASSERT(ins->type() == MIRType::Value);
7409
7410 auto* lir = new (alloc()) LSuperFunction(useRegister(ins->callee()), temp());
7411 defineBox(lir, ins);
7412 }
7413
7414 void LIRGenerator::visitInitHomeObject(MInitHomeObject* ins) {
7415 MDefinition* function = ins->function();
7416 MOZ_ASSERT(function->type() == MIRType::Object);
7417
7418 MDefinition* homeObject = ins->homeObject();
7419 MOZ_ASSERT(homeObject->type() == MIRType::Value);
7420
7421 MOZ_ASSERT(ins->type() == MIRType::Object);
7422
7423 auto* lir = new (alloc())
7424 LInitHomeObject(useRegisterAtStart(function), useBoxAtStart(homeObject));
7425 redefine(ins, function);
7426 add(lir, ins);
7427 }
7428
7429 void LIRGenerator::visitIsTypedArrayConstructor(MIsTypedArrayConstructor* ins) {
7430 MDefinition* object = ins->object();
7431 MOZ_ASSERT(object->type() == MIRType::Object);
7432
7433 auto* lir = new (alloc()) LIsTypedArrayConstructor(useRegister(object));
7434 define(lir, ins);
7435 }
7436
7437 void LIRGenerator::visitLoadValueTag(MLoadValueTag* ins) {
7438 MDefinition* value = ins->value();
7439 MOZ_ASSERT(value->type() == MIRType::Value);
7440
7441 define(new (alloc()) LLoadValueTag(useBoxAtStart(value)), ins);
7442 }
7443
7444 void LIRGenerator::visitGuardTagNotEqual(MGuardTagNotEqual* ins) {
7445 MDefinition* lhs = ins->lhs();
7446 MOZ_ASSERT(lhs->type() == MIRType::Int32);
7447
7448 MDefinition* rhs = ins->rhs();
7449 MOZ_ASSERT(rhs->type() == MIRType::Int32);
7450
7451 auto* guard =
7452 new (alloc()) LGuardTagNotEqual(useRegister(lhs), useRegister(rhs));
7453 assignSnapshot(guard, ins->bailoutKind());
7454 add(guard, ins);
7455 }
7456
7457 void LIRGenerator::visitLoadWrapperTarget(MLoadWrapperTarget* ins) {
7458 MDefinition* object = ins->object();
7459 MOZ_ASSERT(object->type() == MIRType::Object);
7460
7461 auto* lir = new (alloc()) LLoadWrapperTarget(useRegisterAtStart(object));
7462 if (ins->fallible()) {
7463 assignSnapshot(lir, ins->bailoutKind());
7464 }
7465 define(lir, ins);
7466 }
7467
7468 void LIRGenerator::visitGuardHasGetterSetter(MGuardHasGetterSetter* ins) {
7469 MDefinition* object = ins->object();
7470 MOZ_ASSERT(object->type() == MIRType::Object);
7471
7472 auto* guard = new (alloc())
7473 LGuardHasGetterSetter(useRegisterAtStart(object), tempFixed(CallTempReg0),
7474 tempFixed(CallTempReg1), tempFixed(CallTempReg2));
7475 assignSnapshot(guard, ins->bailoutKind());
7476 add(guard, ins);
7477 redefine(ins, object);
7478 }
7479
7480 void LIRGenerator::visitGuardIsExtensible(MGuardIsExtensible* ins) {
7481 MDefinition* object = ins->object();
7482 MOZ_ASSERT(object->type() == MIRType::Object);
7483
7484 auto* guard = new (alloc()) LGuardIsExtensible(useRegister(object), temp());
7485 assignSnapshot(guard, ins->bailoutKind());
7486 add(guard, ins);
7487 redefine(ins, object);
7488 }
7489
7490 void LIRGenerator::visitGuardInt32IsNonNegative(MGuardInt32IsNonNegative* ins) {
7491 MDefinition* index = ins->index();
7492 MOZ_ASSERT(index->type() == MIRType::Int32);
7493
7494 auto* guard = new (alloc()) LGuardInt32IsNonNegative(useRegister(index));
7495 assignSnapshot(guard, ins->bailoutKind());
7496 add(guard, ins);
7497 redefine(ins, index);
7498 }
7499
7500 void LIRGenerator::visitGuardInt32Range(MGuardInt32Range* ins) {
7501 MDefinition* input = ins->input();
7502 MOZ_ASSERT(input->type() == MIRType::Int32);
7503
7504 auto* guard = new (alloc()) LGuardInt32Range(useRegister(input));
7505 assignSnapshot(guard, ins->bailoutKind());
7506 add(guard, ins);
7507 redefine(ins, input);
7508 }
7509
7510 void LIRGenerator::visitGuardIndexIsNotDenseElement(
7511 MGuardIndexIsNotDenseElement* ins) {
7512 MDefinition* object = ins->object();
7513 MOZ_ASSERT(object->type() == MIRType::Object);
7514
7515 MDefinition* index = ins->index();
7516 MOZ_ASSERT(index->type() == MIRType::Int32);
7517
7518 LDefinition spectreTemp =
7519 BoundsCheckNeedsSpectreTemp() ? temp() : LDefinition::BogusTemp();
7520
7521 auto* guard = new (alloc()) LGuardIndexIsNotDenseElement(
7522 useRegister(object), useRegister(index), temp(), spectreTemp);
7523 assignSnapshot(guard, ins->bailoutKind());
7524 add(guard, ins);
7525 redefine(ins, index);
7526 }
7527
7528 void LIRGenerator::visitGuardIndexIsValidUpdateOrAdd(
7529 MGuardIndexIsValidUpdateOrAdd* ins) {
7530 MDefinition* object = ins->object();
7531 MOZ_ASSERT(object->type() == MIRType::Object);
7532
7533 MDefinition* index = ins->index();
7534 MOZ_ASSERT(index->type() == MIRType::Int32);
7535
7536 LDefinition spectreTemp =
7537 BoundsCheckNeedsSpectreTemp() ? temp() : LDefinition::BogusTemp();
7538
7539 auto* guard = new (alloc()) LGuardIndexIsValidUpdateOrAdd(
7540 useRegister(object), useRegister(index), temp(), spectreTemp);
7541 assignSnapshot(guard, ins->bailoutKind());
7542 add(guard, ins);
7543 redefine(ins, index);
7544 }
7545
7546 void LIRGenerator::visitCallAddOrUpdateSparseElement(
7547 MCallAddOrUpdateSparseElement* ins) {
7548 MDefinition* object = ins->object();
7549 MOZ_ASSERT(object->type() == MIRType::Object);
7550
7551 MDefinition* index = ins->index();
7552 MOZ_ASSERT(index->type() == MIRType::Int32);
7553
7554 MDefinition* value = ins->value();
7555 MOZ_ASSERT(value->type() == MIRType::Value);
7556
7557 auto* lir = new (alloc()) LCallAddOrUpdateSparseElement(
7558 useRegisterAtStart(object), useRegisterAtStart(index),
7559 useBoxAtStart(value));
7560 add(lir, ins);
7561 assignSafepoint(lir, ins);
7562 }
7563
7564 void LIRGenerator::visitCallGetSparseElement(MCallGetSparseElement* ins) {
7565 MDefinition* object = ins->object();
7566 MOZ_ASSERT(object->type() == MIRType::Object);
7567
7568 MDefinition* index = ins->index();
7569 MOZ_ASSERT(index->type() == MIRType::Int32);
7570
7571 auto* lir = new (alloc()) LCallGetSparseElement(useRegisterAtStart(object),
7572 useRegisterAtStart(index));
7573 defineReturn(lir, ins);
7574 assignSafepoint(lir, ins);
7575 }
7576
7577 void LIRGenerator::visitCallNativeGetElement(MCallNativeGetElement* ins) {
7578 MDefinition* object = ins->object();
7579 MOZ_ASSERT(object->type() == MIRType::Object);
7580
7581 MDefinition* index = ins->index();
7582 MOZ_ASSERT(index->type() == MIRType::Int32);
7583
7584 auto* lir = new (alloc()) LCallNativeGetElement(useRegisterAtStart(object),
7585 useRegisterAtStart(index));
7586 defineReturn(lir, ins);
7587 assignSafepoint(lir, ins);
7588 }
7589
7590 void LIRGenerator::visitCallNativeGetElementSuper(
7591 MCallNativeGetElementSuper* ins) {
7592 MDefinition* object = ins->object();
7593 MOZ_ASSERT(object->type() == MIRType::Object);
7594
7595 MDefinition* index = ins->index();
7596 MOZ_ASSERT(index->type() == MIRType::Int32);
7597
7598 MDefinition* receiver = ins->receiver();
7599
7600 auto* lir = new (alloc()) LCallNativeGetElementSuper(
7601 useRegisterAtStart(object), useRegisterAtStart(index),
7602 useBoxAtStart(receiver));
7603 defineReturn(lir, ins);
7604 assignSafepoint(lir, ins);
7605 }
7606
7607 void LIRGenerator::visitCallObjectHasSparseElement(
7608 MCallObjectHasSparseElement* ins) {
7609 MDefinition* object = ins->object();
7610 MOZ_ASSERT(object->type() == MIRType::Object);
7611
7612 MDefinition* index = ins->index();
7613 MOZ_ASSERT(index->type() == MIRType::Int32);
7614
7615 auto* lir = new (alloc()) LCallObjectHasSparseElement(
7616 useRegisterAtStart(object), useRegisterAtStart(index),
7617 tempFixed(CallTempReg0), tempFixed(CallTempReg1));
7618 assignSnapshot(lir, ins->bailoutKind());
7619 defineReturn(lir, ins);
7620 }
7621
7622 void LIRGenerator::visitBigIntAsIntN(MBigIntAsIntN* ins) {
7623 MOZ_ASSERT(ins->bits()->type() == MIRType::Int32);
7624 MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
7625
7626 auto* lir = new (alloc()) LBigIntAsIntN(useRegisterAtStart(ins->bits()),
7627 useRegisterAtStart(ins->input()));
7628 defineReturn(lir, ins);
7629 assignSafepoint(lir, ins);
7630 }
7631
7632 void LIRGenerator::visitBigIntAsUintN(MBigIntAsUintN* ins) {
7633 MOZ_ASSERT(ins->bits()->type() == MIRType::Int32);
7634 MOZ_ASSERT(ins->input()->type() == MIRType::BigInt);
7635
7636 auto* lir = new (alloc()) LBigIntAsUintN(useRegisterAtStart(ins->bits()),
7637 useRegisterAtStart(ins->input()));
7638 defineReturn(lir, ins);
7639 assignSafepoint(lir, ins);
7640 }
7641
7642 void LIRGenerator::visitGuardNonGCThing(MGuardNonGCThing* ins) {
7643 MDefinition* input = ins->input();
7644
7645 auto* guard = new (alloc()) LGuardNonGCThing(useBox(input));
7646 assignSnapshot(guard, ins->bailoutKind());
7647 add(guard, ins);
7648 redefine(ins, input);
7649 }
7650
7651 void LIRGenerator::visitToHashableNonGCThing(MToHashableNonGCThing* ins) {
7652 auto* lir =
7653 new (alloc()) LToHashableNonGCThing(useBox(ins->input()), tempDouble());
7654 defineBox(lir, ins);
7655 }
7656
7657 void LIRGenerator::visitToHashableString(MToHashableString* ins) {
7658 auto* lir = new (alloc()) LToHashableString(useRegister(ins->input()));
7659 define(lir, ins);
7660 assignSafepoint(lir, ins);
7661 }
7662
7663 void LIRGenerator::visitToHashableValue(MToHashableValue* ins) {
7664 auto* lir =
7665 new (alloc()) LToHashableValue(useBox(ins->input()), tempDouble());
7666 defineBox(lir, ins);
7667 assignSafepoint(lir, ins);
7668 }
7669
7670 void LIRGenerator::visitHashNonGCThing(MHashNonGCThing* ins) {
7671 auto* lir = new (alloc()) LHashNonGCThing(useBox(ins->input()), temp());
7672 define(lir, ins);
7673 }
7674
7675 void LIRGenerator::visitHashString(MHashString* ins) {
7676 auto* lir = new (alloc()) LHashString(useRegister(ins->input()), temp());
7677 define(lir, ins);
7678 }
7679
7680 void LIRGenerator::visitHashSymbol(MHashSymbol* ins) {
7681 auto* lir = new (alloc()) LHashSymbol(useRegister(ins->input()));
7682 define(lir, ins);
7683 }
7684
7685 void LIRGenerator::visitHashBigInt(MHashBigInt* ins) {
7686 auto* lir = new (alloc())
7687 LHashBigInt(useRegister(ins->input()), temp(), temp(), temp());
7688 define(lir, ins);
7689 }
7690
7691 void LIRGenerator::visitHashObject(MHashObject* ins) {
7692 auto* lir = new (alloc())
7693 LHashObject(useRegister(ins->setObject()), useBox(ins->input()), temp(),
7694 temp(), temp(), temp());
7695 define(lir, ins);
7696 }
7697
7698 void LIRGenerator::visitHashValue(MHashValue* ins) {
7699 auto* lir = new (alloc())
7700 LHashValue(useRegister(ins->setObject()), useBox(ins->input()), temp(),
7701 temp(), temp(), temp());
7702 define(lir, ins);
7703 }
7704
7705 void LIRGenerator::visitSetObjectHasNonBigInt(MSetObjectHasNonBigInt* ins) {
7706 auto* lir = new (alloc()) LSetObjectHasNonBigInt(
7707 useRegister(ins->setObject()), useBox(ins->value()),
7708 useRegister(ins->hash()), temp(), temp());
7709 define(lir, ins);
7710 }
7711
7712 void LIRGenerator::visitSetObjectHasBigInt(MSetObjectHasBigInt* ins) {
7713 auto* lir = new (alloc()) LSetObjectHasBigInt(
7714 useRegister(ins->setObject()), useBox(ins->value()),
7715 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7716 define(lir, ins);
7717 }
7718
7719 void LIRGenerator::visitSetObjectHasValue(MSetObjectHasValue* ins) {
7720 auto* lir = new (alloc()) LSetObjectHasValue(
7721 useRegister(ins->setObject()), useBox(ins->value()),
7722 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7723 define(lir, ins);
7724 }
7725
7726 void LIRGenerator::visitSetObjectHasValueVMCall(MSetObjectHasValueVMCall* ins) {
7727 auto* lir = new (alloc()) LSetObjectHasValueVMCall(
7728 useRegisterAtStart(ins->setObject()), useBoxAtStart(ins->value()));
7729 defineReturn(lir, ins);
7730 assignSafepoint(lir, ins);
7731 }
7732
7733 void LIRGenerator::visitSetObjectDelete(MSetObjectDelete* ins) {
7734 auto* lir = new (alloc()) LSetObjectDelete(
7735 useRegisterAtStart(ins->setObject()), useBoxAtStart(ins->key()));
7736 defineReturn(lir, ins);
7737 assignSafepoint(lir, ins);
7738 }
7739
7740 void LIRGenerator::visitSetObjectAdd(MSetObjectAdd* ins) {
7741 auto* lir = new (alloc()) LSetObjectAdd(useRegisterAtStart(ins->setObject()),
7742 useBoxAtStart(ins->key()));
7743 add(lir, ins);
7744 assignSafepoint(lir, ins);
7745 }
7746
7747 void LIRGenerator::visitSetObjectSize(MSetObjectSize* ins) {
7748 auto* lir =
7749 new (alloc()) LSetObjectSize(useRegisterAtStart(ins->setObject()));
7750 define(lir, ins);
7751 }
7752
7753 void LIRGenerator::visitMapObjectHasNonBigInt(MMapObjectHasNonBigInt* ins) {
7754 auto* lir = new (alloc()) LMapObjectHasNonBigInt(
7755 useRegister(ins->mapObject()), useBox(ins->value()),
7756 useRegister(ins->hash()), temp(), temp());
7757 define(lir, ins);
7758 }
7759
7760 void LIRGenerator::visitMapObjectHasBigInt(MMapObjectHasBigInt* ins) {
7761 auto* lir = new (alloc()) LMapObjectHasBigInt(
7762 useRegister(ins->mapObject()), useBox(ins->value()),
7763 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7764 define(lir, ins);
7765 }
7766
7767 void LIRGenerator::visitMapObjectHasValue(MMapObjectHasValue* ins) {
7768 auto* lir = new (alloc()) LMapObjectHasValue(
7769 useRegister(ins->mapObject()), useBox(ins->value()),
7770 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7771 define(lir, ins);
7772 }
7773
7774 void LIRGenerator::visitMapObjectHasValueVMCall(MMapObjectHasValueVMCall* ins) {
7775 auto* lir = new (alloc()) LMapObjectHasValueVMCall(
7776 useRegisterAtStart(ins->mapObject()), useBoxAtStart(ins->value()));
7777 defineReturn(lir, ins);
7778 assignSafepoint(lir, ins);
7779 }
7780
7781 void LIRGenerator::visitMapObjectGetNonBigInt(MMapObjectGetNonBigInt* ins) {
7782 auto* lir = new (alloc()) LMapObjectGetNonBigInt(
7783 useRegister(ins->mapObject()), useBox(ins->value()),
7784 useRegister(ins->hash()), temp(), temp());
7785 defineBox(lir, ins);
7786 }
7787
7788 void LIRGenerator::visitMapObjectGetBigInt(MMapObjectGetBigInt* ins) {
7789 auto* lir = new (alloc()) LMapObjectGetBigInt(
7790 useRegister(ins->mapObject()), useBox(ins->value()),
7791 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7792 defineBox(lir, ins);
7793 }
7794
7795 void LIRGenerator::visitMapObjectGetValue(MMapObjectGetValue* ins) {
7796 auto* lir = new (alloc()) LMapObjectGetValue(
7797 useRegister(ins->mapObject()), useBox(ins->value()),
7798 useRegister(ins->hash()), temp(), temp(), temp(), temp());
7799 defineBox(lir, ins);
7800 }
7801
7802 void LIRGenerator::visitMapObjectGetValueVMCall(MMapObjectGetValueVMCall* ins) {
7803 auto* lir = new (alloc()) LMapObjectGetValueVMCall(
7804 useRegisterAtStart(ins->mapObject()), useBoxAtStart(ins->value()));
7805 defineReturn(lir, ins);
7806 assignSafepoint(lir, ins);
7807 }
7808
7809 void LIRGenerator::visitMapObjectDelete(MMapObjectDelete* ins) {
7810 auto* lir = new (alloc()) LMapObjectDelete(
7811 useRegisterAtStart(ins->mapObject()), useBoxAtStart(ins->key()));
7812 defineReturn(lir, ins);
7813 assignSafepoint(lir, ins);
7814 }
7815
7816 void LIRGenerator::visitMapObjectSet(MMapObjectSet* ins) {
7817 auto* lir = new (alloc())
7818 LMapObjectSet(useRegisterAtStart(ins->mapObject()),
7819 useBoxAtStart(ins->key()), useBoxAtStart(ins->value()));
7820 add(lir, ins);
7821 assignSafepoint(lir, ins);
7822 }
7823
7824 void LIRGenerator::visitMapObjectSize(MMapObjectSize* ins) {
7825 auto* lir =
7826 new (alloc()) LMapObjectSize(useRegisterAtStart(ins->mapObject()));
7827 define(lir, ins);
7828 }
7829
7830 void LIRGenerator::visitDateFillLocalTimeSlots(MDateFillLocalTimeSlots* ins) {
7831 auto* lir =
7832 new (alloc()) LDateFillLocalTimeSlots(useRegister(ins->date()), temp());
7833 add(lir, ins);
7834 assignSafepoint(lir, ins);
7835 }
7836
7837 void LIRGenerator::visitDateHoursFromSecondsIntoYear(
7838 MDateHoursFromSecondsIntoYear* ins) {
7839 auto* lir = new (alloc()) LDateHoursFromSecondsIntoYear(
7840 useBox(ins->secondsIntoYear()), temp(), temp());
7841 defineBox(lir, ins);
7842 }
7843
7844 void LIRGenerator::visitDateMinutesFromSecondsIntoYear(
7845 MDateMinutesFromSecondsIntoYear* ins) {
7846 auto* lir = new (alloc()) LDateMinutesFromSecondsIntoYear(
7847 useBox(ins->secondsIntoYear()), temp(), temp());
7848 defineBox(lir, ins);
7849 }
7850
7851 void LIRGenerator::visitDateSecondsFromSecondsIntoYear(
7852 MDateSecondsFromSecondsIntoYear* ins) {
7853 auto* lir = new (alloc()) LDateSecondsFromSecondsIntoYear(
7854 useBox(ins->secondsIntoYear()), temp(), temp());
7855 defineBox(lir, ins);
7856 }
7857
7858 void LIRGenerator::visitPostIntPtrConversion(MPostIntPtrConversion* ins) {
7859 // This operation is a no-op.
7860 redefine(ins, ins->input());
7861 }
7862
7863 void LIRGenerator::visitCanonicalizeNaN(MCanonicalizeNaN* ins) {
7864 MOZ_ASSERT(ins->type() == ins->input()->type());
7865
7866 auto input = useRegisterAtStart(ins->input());
7867 switch (ins->type()) {
7868 case MIRType::Double:
7869 defineReuseInput(new (alloc()) LCanonicalizeNaND(input), ins, 0);
7870 return;
7871 case MIRType::Float32:
7872 defineReuseInput(new (alloc()) LCanonicalizeNaNF(input), ins, 0);
7873 return;
7874 default:
7875 MOZ_CRASH("unexpected floating point type");
7876 }
7877 }
7878
7879 void LIRGenerator::visitConstant(MConstant* ins) {
7880 if (!IsFloatingPointType(ins->type()) && ins->canEmitAtUses()) {
7881 emitAtUses(ins);
7882 return;
7883 }
7884
7885 switch (ins->type()) {
7886 case MIRType::Double:
7887 define(new (alloc()) LDouble(ins->toDouble()), ins);
7888 break;
7889 case MIRType::Float32:
7890 define(new (alloc()) LFloat32(ins->toFloat32()), ins);
7891 break;
7892 case MIRType::Boolean:
7893 define(new (alloc()) LInteger(ins->toBoolean()), ins);
7894 break;
7895 case MIRType::Int32:
7896 define(new (alloc()) LInteger(ins->toInt32()), ins);
7897 break;
7898 case MIRType::Int64:
7899 defineInt64(new (alloc()) LInteger64(ins->toInt64()), ins);
7900 break;
7901 case MIRType::IntPtr:
7902 #ifdef JS_64BIT
7903 defineInt64(new (alloc()) LInteger64(ins->toIntPtr()), ins);
7904 #else
7905 define(new (alloc()) LInteger(ins->toIntPtr()), ins);
7906 #endif
7907 break;
7908 case MIRType::String:
7909 define(new (alloc()) LPointer(ins->toString()), ins);
7910 break;
7911 case MIRType::Symbol:
7912 define(new (alloc()) LPointer(ins->toSymbol()), ins);
7913 break;
7914 case MIRType::BigInt:
7915 define(new (alloc()) LPointer(ins->toBigInt()), ins);
7916 break;
7917 case MIRType::Object:
7918 define(new (alloc()) LPointer(&ins->toObject()), ins);
7919 break;
7920 case MIRType::Shape:
7921 MOZ_ASSERT(ins->isEmittedAtUses());
7922 break;
7923 default:
7924 // Constants of special types (undefined, null) should never flow into
7925 // here directly. Operations blindly consuming them require a Box.
7926 MOZ_CRASH("unexpected constant type");
7927 }
7928 }
7929
7930 void LIRGenerator::visitConstantProto(MConstantProto* ins) {
7931 JSObject* obj = &ins->protoObject()->toConstant()->toObject();
7932 define(new (alloc()) LPointer(obj), ins);
7933 }
7934
7935 void LIRGenerator::visitWasmNullConstant(MWasmNullConstant* ins) {
7936 define(new (alloc()) LWasmNullConstant(), ins);
7937 }
7938
7939 void LIRGenerator::visitWasmFloatConstant(MWasmFloatConstant* ins) {
7940 switch (ins->type()) {
7941 case MIRType::Double:
7942 define(new (alloc()) LDouble(ins->toDouble()), ins);
7943 break;
7944 case MIRType::Float32:
7945 define(new (alloc()) LFloat32(ins->toFloat32()), ins);
7946 break;
7947 #ifdef ENABLE_WASM_SIMD
7948 case MIRType::Simd128:
7949 define(new (alloc()) LSimd128(ins->toSimd128()), ins);
7950 break;
7951 #endif
7952 default:
7953 MOZ_CRASH("unexpected constant type");
7954 }
7955 }
7956
7957 #ifdef JS_JITSPEW
7958 static void SpewResumePoint(MBasicBlock* block, MInstruction* ins,
7959 MResumePoint* resumePoint) {
7960 Fprinter& out = JitSpewPrinter();
7961 out.printf("Current resume point %p details:\n", (void*)resumePoint);
7962 out.printf(" frame count: %u\n", resumePoint->frameCount());
7963
7964 if (ins) {
7965 out.printf(" taken after: ");
7966 ins->printName(out);
7967 } else {
7968 out.printf(" taken at block %u entry", block->id());
7969 }
7970 out.printf("\n");
7971
7972 out.printf(" pc: %p (script: %p, offset: %d)\n", (void*)resumePoint->pc(),
7973 (void*)resumePoint->block()->info().script(),
7974 int(resumePoint->block()->info().script()->pcToOffset(
7975 resumePoint->pc())));
7976
7977 for (size_t i = 0, e = resumePoint->numOperands(); i < e; i++) {
7978 MDefinition* in = resumePoint->getOperand(i);
7979 out.printf(" slot%u: ", (unsigned)i);
7980 in->printName(out);
7981 out.printf("\n");
7982 }
7983 }
7984 #endif
7985
7986 void LIRGenerator::visitInstructionDispatch(MInstruction* ins) {
7987 #ifdef JS_CODEGEN_NONE
7988 // Don't compile the switch-statement below so that we don't have to define
7989 // the platform-specific visit* methods for the none-backend.
7990 MOZ_CRASH();
7991 #else
7992 switch (ins->op()) {
7993 # define MIR_OP(op) \
7994 case MDefinition::Opcode::op: \
7995 visit##op(ins->to##op()); \
7996 break;
7997 MIR_OPCODE_LIST(MIR_OP)
7998 # undef MIR_OP
7999 default:
8000 MOZ_CRASH("Invalid instruction");
8001 }
8002 #endif
8003 }
8004
8005 void LIRGeneratorShared::visitEmittedAtUses(MInstruction* ins) {
8006 static_cast<LIRGenerator*>(this)->visitInstructionDispatch(ins);
8007 }
8008
8009 bool LIRGenerator::visitInstruction(MInstruction* ins) {
8010 MOZ_ASSERT(!errored());
8011
8012 if (ins->isRecoveredOnBailout()) {
8013 MOZ_ASSERT(!JitOptions.disableRecoverIns);
8014 return true;
8015 }
8016
8017 if (!gen->ensureBallast()) {
8018 return false;
8019 }
8020 visitInstructionDispatch(ins);
8021
8022 if (ins->resumePoint()) {
8023 updateResumeState(ins);
8024 }
8025
8026 #ifdef DEBUG
8027 ins->setInWorklistUnchecked();
8028 #endif
8029
8030 // If no safepoint was created, there's no need for an OSI point.
8031 if (LOsiPoint* osiPoint = popOsiPoint()) {
8032 add(osiPoint);
8033 }
8034
8035 return !errored();
8036 }
8037
8038 bool LIRGenerator::definePhis() {
8039 size_t lirIndex = 0;
8040 MBasicBlock* block = current->mir();
8041 for (MPhiIterator phi(block->phisBegin()); phi != block->phisEnd(); phi++) {
8042 if (phi->type() == MIRType::Value) {
8043 defineUntypedPhi(*phi, lirIndex);
8044 lirIndex += BOX_PIECES;
8045 } else if (phi->type() == MIRType::Int64) {
8046 defineInt64Phi(*phi, lirIndex);
8047 lirIndex += INT64_PIECES;
8048 } else {
8049 defineTypedPhi(*phi, lirIndex);
8050 lirIndex += 1;
8051 }
8052 }
8053 return !errored();
8054 }
8055
8056 void LIRGenerator::updateResumeState(MInstruction* ins) {
8057 lastResumePoint_ = ins->resumePoint();
8058 #ifdef JS_JITSPEW
8059 if (JitSpewEnabled(JitSpew_IonSnapshots) && lastResumePoint_) {
8060 SpewResumePoint(nullptr, ins, lastResumePoint_);
8061 }
8062 #endif
8063 }
8064
8065 void LIRGenerator::updateResumeState(MBasicBlock* block) {
8066 // Note: RangeAnalysis can flag blocks as unreachable, but they are only
8067 // removed iff GVN (including UCE) is enabled.
8068 MOZ_ASSERT_IF(!mir()->compilingWasm() && !block->unreachable(),
8069 block->entryResumePoint());
8070 MOZ_ASSERT_IF(block->unreachable(), !mir()->optimizationInfo().gvnEnabled());
8071 lastResumePoint_ = block->entryResumePoint();
8072 #ifdef JS_JITSPEW
8073 if (JitSpewEnabled(JitSpew_IonSnapshots) && lastResumePoint_) {
8074 SpewResumePoint(block, nullptr, lastResumePoint_);
8075 }
8076 #endif
8077 }
8078
8079 bool LIRGenerator::visitBlock(MBasicBlock* block) {
8080 current = block->lir();
8081 updateResumeState(block);
8082
8083 if (!definePhis()) {
8084 return false;
8085 }
8086
8087 MOZ_ASSERT_IF(block->unreachable(), !mir()->optimizationInfo().gvnEnabled());
8088 for (MInstructionIterator iter = block->begin(); *iter != block->lastIns();
8089 iter++) {
8090 if (gen->shouldCancel("Lowering (instruction loop)")) {
8091 return false;
8092 }
8093 if (!visitInstruction(*iter)) {
8094 return false;
8095 }
8096 }
8097
8098 if (block->successorWithPhis()) {
8099 // If we have a successor with phis, lower the phi input now that we
8100 // are approaching the join point.
8101 MBasicBlock* successor = block->successorWithPhis();
8102 uint32_t position = block->positionInPhiSuccessor();
8103 size_t lirIndex = 0;
8104 for (MPhiIterator phi(successor->phisBegin()); phi != successor->phisEnd();
8105 phi++) {
8106 if (!gen->ensureBallast()) {
8107 return false;
8108 }
8109
8110 MDefinition* opd = phi->getOperand(position);
8111 ensureDefined(opd);
8112
8113 MOZ_ASSERT(opd->type() == phi->type());
8114
8115 if (phi->type() == MIRType::Value) {
8116 lowerUntypedPhiInput(*phi, position, successor->lir(), lirIndex);
8117 lirIndex += BOX_PIECES;
8118 } else if (phi->type() == MIRType::Int64) {
8119 lowerInt64PhiInput(*phi, position, successor->lir(), lirIndex);
8120 lirIndex += INT64_PIECES;
8121 } else {
8122 lowerTypedPhiInput(*phi, position, successor->lir(), lirIndex);
8123 lirIndex += 1;
8124 }
8125 }
8126 }
8127
8128 // Now emit the last instruction, which is some form of branch.
8129 if (!visitInstruction(block->lastIns())) {
8130 return false;
8131 }
8132
8133 return true;
8134 }
8135
8136 void LIRGenerator::visitNaNToZero(MNaNToZero* ins) {
8137 MDefinition* input = ins->input();
8138
8139 if (ins->operandIsNeverNaN() && ins->operandIsNeverNegativeZero()) {
8140 redefine(ins, input);
8141 return;
8142 }
8143 LNaNToZero* lir =
8144 new (alloc()) LNaNToZero(useRegisterAtStart(input), tempDouble());
8145 defineReuseInput(lir, ins, 0);
8146 }
8147
8148 bool LIRGenerator::generate() {
8149 // Create all blocks and prep all phis beforehand.
8150 for (ReversePostorderIterator block(graph.rpoBegin());
8151 block != graph.rpoEnd(); block++) {
8152 if (gen->shouldCancel("Lowering (preparation loop)")) {
8153 return false;
8154 }
8155
8156 if (!lirGraph_.initBlock(*block)) {
8157 return false;
8158 }
8159 }
8160
8161 for (ReversePostorderIterator block(graph.rpoBegin());
8162 block != graph.rpoEnd(); block++) {
8163 if (gen->shouldCancel("Lowering (main loop)")) {
8164 return false;
8165 }
8166
8167 if (!visitBlock(*block)) {
8168 return false;
8169 }
8170 }
8171
8172 lirGraph_.setArgumentSlotCount(maxargslots_);
8173 return true;
8174 }
8175
8176 void LIRGenerator::visitPhi(MPhi* phi) {
8177 // Phi nodes are not lowered because they are only meaningful for the register
8178 // allocator.
8179 MOZ_CRASH("Unexpected Phi node during Lowering.");
8180 }
8181
8182 void LIRGenerator::visitBeta(MBeta* beta) {
8183 // Beta nodes are supposed to be removed before because they are
8184 // only used to carry the range information for Range analysis
8185 MOZ_CRASH("Unexpected Beta node during Lowering.");
8186 }
8187
8188 void LIRGenerator::visitObjectState(MObjectState* objState) {
8189 // ObjectState nodes are always recovered on bailouts
8190 MOZ_CRASH("Unexpected ObjectState node during Lowering.");
8191 }
8192
8193 void LIRGenerator::visitArrayState(MArrayState* objState) {
8194 // ArrayState nodes are always recovered on bailouts
8195 MOZ_CRASH("Unexpected ArrayState node during Lowering.");
8196 }
8197
8198 void LIRGenerator::visitIonToWasmCall(MIonToWasmCall* ins) {
8199 // The instruction needs a temp register:
8200 // - that's not the FramePointer, since wasm is going to use it in the
8201 // function.
8202 // - that's not aliasing an input register.
8203 LDefinition scratch = tempFixed(ABINonArgReg0);
8204
8205 // Note that since this is a LIR call instruction, regalloc will prevent
8206 // the use*AtStart below from reusing any of the temporaries.
8207
8208 LInstruction* lir;
8209 if (ins->type() == MIRType::Value) {
8210 lir = allocateVariadic<LIonToWasmCallV>(ins->numOperands(), scratch);
8211 } else if (ins->type() == MIRType::Int64) {
8212 lir = allocateVariadic<LIonToWasmCallI64>(ins->numOperands(), scratch);
8213 } else {
8214 lir = allocateVariadic<LIonToWasmCall>(ins->numOperands(), scratch);
8215 }
8216 if (!lir) {
8217 abort(AbortReason::Alloc, "OOM: LIRGenerator::visitIonToWasmCall");
8218 return;
8219 }
8220
8221 ABIArgGenerator abi;
8222 for (unsigned i = 0; i < ins->numOperands(); i++) {
8223 MDefinition* argDef = ins->getOperand(i);
8224 ABIArg arg = abi.next(ToMIRType(argDef->type()));
8225 switch (arg.kind()) {
8226 case ABIArg::GPR:
8227 case ABIArg::FPU:
8228 lir->setOperand(i, useFixedAtStart(argDef, arg.reg()));
8229 break;
8230 case ABIArg::Stack:
8231 lir->setOperand(i, useAtStart(argDef));
8232 break;
8233 #ifdef JS_CODEGEN_REGISTER_PAIR
8234 case ABIArg::GPR_PAIR:
8235 MOZ_CRASH(
8236 "no way to pass i64, and wasm uses hardfp for function calls");
8237 #endif
8238 case ABIArg::Uninitialized:
8239 MOZ_CRASH("Uninitialized ABIArg kind");
8240 }
8241 }
8242
8243 defineReturn(lir, ins);
8244 assignSafepoint(lir, ins);
8245 }
8246
8247 void LIRGenerator::visitWasmSelect(MWasmSelect* ins) {
8248 MDefinition* condExpr = ins->condExpr();
8249
8250 // Pick off specific cases that we can do with LWasmCompareAndSelect to avoid
8251 // generating a boolean that we then have to test again.
8252 if (condExpr->isCompare() && condExpr->isEmittedAtUses()) {
8253 MCompare* comp = condExpr->toCompare();
8254 MCompare::CompareType compTy = comp->compareType();
8255 if (canSpecializeWasmCompareAndSelect(compTy, ins->type())) {
8256 JSOp jsop = comp->jsop();
8257 // We don't currently generate any other JSOPs for the comparison, and if
8258 // that changes, we want to know about it. Hence this assertion.
8259 MOZ_ASSERT(jsop == JSOp::Eq || jsop == JSOp::Ne || jsop == JSOp::Lt ||
8260 jsop == JSOp::Gt || jsop == JSOp::Le || jsop == JSOp::Ge);
8261 MDefinition* lhs = comp->lhs();
8262 MDefinition* rhs = comp->rhs();
8263 jsop = ReorderComparison(jsop, &lhs, &rhs);
8264 lowerWasmCompareAndSelect(ins, lhs, rhs, compTy, jsop);
8265 return;
8266 }
8267 }
8268 // Fall through to code that generates a boolean and selects on that.
8269
8270 if (ins->type() == MIRType::Int64) {
8271 lowerWasmSelectI64(ins);
8272 return;
8273 }
8274
8275 lowerWasmSelectI(ins);
8276 }
8277
8278 void LIRGenerator::visitWasmFence(MWasmFence* ins) {
8279 add(new (alloc()) LWasmFence, ins);
8280 }
8281
8282 void LIRGenerator::visitWasmLoadField(MWasmLoadField* ins) {
8283 uint32_t offset = ins->offset();
8284 LAllocation data = useRegisterAtStart(ins->base());
8285 MWideningOp wideningOp = ins->wideningOp();
8286 if (ins->type() == MIRType::Int64) {
8287 MOZ_RELEASE_ASSERT(wideningOp == MWideningOp::None);
8288 defineInt64(new (alloc()) LWasmLoadSlotI64(data, offset, ins->maybeTrap()),
8289 ins);
8290 } else {
8291 define(new (alloc()) LWasmLoadSlot(data, offset, ins->type(), wideningOp,
8292 ins->maybeTrap()),
8293 ins);
8294 }
8295 if (ins->keepAlive() != ins->base()) {
8296 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8297 }
8298 }
8299
8300 void LIRGenerator::visitWasmLoadElement(MWasmLoadElement* ins) {
8301 LAllocation base = useRegister(ins->base());
8302 LAllocation index = useRegister(ins->index());
8303 MWideningOp wideningOp = ins->wideningOp();
8304 Scale scale = ins->scale();
8305 if (ins->type() == MIRType::Int64) {
8306 MOZ_RELEASE_ASSERT(wideningOp == MWideningOp::None);
8307 defineInt64(
8308 new (alloc()) LWasmLoadElementI64(base, index, ins->maybeTrap()), ins);
8309 } else {
8310 LDefinition tmp =
8311 ins->type() == MIRType::Simd128 ? temp() : LDefinition::BogusTemp();
8312 define(new (alloc()) LWasmLoadElement(base, index, tmp, ins->type(),
8313 wideningOp, scale, ins->maybeTrap()),
8314 ins);
8315 }
8316 if (ins->keepAlive() != ins->base()) {
8317 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8318 }
8319 }
8320
8321 void LIRGenerator::visitWasmStoreField(MWasmStoreField* ins) {
8322 MDefinition* value = ins->value();
8323 uint32_t offs = ins->offset();
8324 MNarrowingOp narrowingOp = ins->narrowingOp();
8325 LAllocation base = useRegister(ins->base());
8326 LInstruction* lir;
8327 if (value->type() == MIRType::Int64) {
8328 MOZ_RELEASE_ASSERT(narrowingOp == MNarrowingOp::None);
8329 lir = new (alloc()) LWasmStoreSlotI64(useInt64Register(value), base, offs,
8330 ins->maybeTrap());
8331 } else {
8332 lir = new (alloc())
8333 LWasmStoreSlot(useRegister(value), base, offs, value->type(),
8334 narrowingOp, ins->maybeTrap());
8335 }
8336 add(lir, ins);
8337 if (ins->keepAlive() != ins->base()) {
8338 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8339 }
8340 }
8341
8342 void LIRGenerator::visitWasmStoreFieldRef(MWasmStoreFieldRef* ins) {
8343 LAllocation instance = useRegister(ins->instance());
8344 LAllocation base = useFixed(ins->base(), PreBarrierReg);
8345 LAllocation value = useRegister(ins->value());
8346 uint32_t offset = ins->offset();
8347 add(new (alloc()) LWasmStoreRef(instance, base, value, temp(), offset,
8348 ins->maybeTrap(), ins->preBarrierKind()),
8349 ins);
8350 if (ins->keepAlive() != ins->base()) {
8351 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8352 }
8353 }
8354
8355 void LIRGenerator::visitWasmStoreElement(MWasmStoreElement* ins) {
8356 LAllocation base = useRegister(ins->base());
8357 LAllocation index = useRegister(ins->index());
8358 MDefinition* value = ins->value();
8359 MNarrowingOp narrowingOp = ins->narrowingOp();
8360 Scale scale = ins->scale();
8361 LInstruction* lir;
8362 if (value->type() == MIRType::Int64) {
8363 MOZ_RELEASE_ASSERT(narrowingOp == MNarrowingOp::None);
8364 lir = new (alloc()) LWasmStoreElementI64(
8365 base, index, useInt64Register(value), ins->maybeTrap());
8366 } else {
8367 LDefinition tmp =
8368 value->type() == MIRType::Simd128 ? temp() : LDefinition::BogusTemp();
8369 lir = new (alloc())
8370 LWasmStoreElement(base, index, useRegister(value), tmp, value->type(),
8371 narrowingOp, scale, ins->maybeTrap());
8372 }
8373 add(lir, ins);
8374 if (ins->keepAlive() != ins->base()) {
8375 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8376 }
8377 }
8378
8379 void LIRGenerator::visitWasmStoreElementRef(MWasmStoreElementRef* ins) {
8380 LAllocation instance = useRegister(ins->instance());
8381 LAllocation base = useFixed(ins->base(), PreBarrierReg);
8382 LAllocation index = useRegister(ins->index());
8383 LAllocation value = useRegister(ins->value());
8384 bool needTemps = ins->preBarrierKind() == WasmPreBarrierKind::Normal;
8385 LDefinition temp0 = needTemps ? temp() : LDefinition::BogusTemp();
8386 LDefinition temp1 = needTemps ? temp() : LDefinition::BogusTemp();
8387 add(new (alloc())
8388 LWasmStoreElementRef(instance, base, index, value, temp0, temp1,
8389 ins->maybeTrap(), ins->preBarrierKind()),
8390 ins);
8391 if (ins->keepAlive() != ins->base()) {
8392 add(new (alloc()) LKeepAliveObject(useKeepalive(ins->keepAlive())), ins);
8393 }
8394 }
8395
8396 WasmRefIsSubtypeDefs LIRGenerator::useWasmRefIsSubtype(wasm::RefType destType,
8397 MDefinition* superSTV) {
8398 BranchWasmRefIsSubtypeRegisters needs =
8399 MacroAssembler::regsForBranchWasmRefIsSubtype(destType);
8400 return WasmRefIsSubtypeDefs{
8401 .superSTV = needs.needSuperSTV ? useRegister(superSTV) : LAllocation(),
8402 .scratch1 = needs.needScratch1 ? temp() : LDefinition(),
8403 .scratch2 = needs.needScratch2 ? temp() : LDefinition(),
8404 };
8405 }
8406
8407 void LIRGenerator::visitWasmRefTestAbstract(MWasmRefTestAbstract* ins) {
8408 if (CanEmitAtUseForSingleTest(ins)) {
8409 emitAtUses(ins);
8410 return;
8411 }
8412
8413 LAllocation ref = useRegister(ins->ref());
8414 WasmRefIsSubtypeDefs regs =
8415 useWasmRefIsSubtype(ins->destType(), /*superSTV=*/nullptr);
8416 define(new (alloc()) LWasmRefTestAbstract(ref, regs.scratch1), ins);
8417 }
8418
8419 void LIRGenerator::visitWasmRefTestConcrete(MWasmRefTestConcrete* ins) {
8420 if (CanEmitAtUseForSingleTest(ins)) {
8421 emitAtUses(ins);
8422 return;
8423 }
8424
8425 LAllocation ref = useRegister(ins->ref());
8426 WasmRefIsSubtypeDefs regs =
8427 useWasmRefIsSubtype(ins->destType(), ins->superSTV());
8428 define(new (alloc()) LWasmRefTestConcrete(ref, regs.superSTV, regs.scratch1,
8429 regs.scratch2),
8430 ins);
8431 }
8432
8433 void LIRGenerator::visitWasmRefCastAbstract(MWasmRefCastAbstract* ins) {
8434 LAllocation ref = useRegisterAtStart(ins->ref());
8435 WasmRefIsSubtypeDefs regs =
8436 useWasmRefIsSubtype(ins->destType(), /*superSTV=*/nullptr);
8437 defineReuseInput(new (alloc()) LWasmRefCastAbstract(ref, regs.scratch1), ins,
8438 0);
8439 }
8440
8441 void LIRGenerator::visitWasmRefCastConcrete(MWasmRefCastConcrete* ins) {
8442 LAllocation ref = useRegisterAtStart(ins->ref());
8443 WasmRefIsSubtypeDefs regs =
8444 useWasmRefIsSubtype(ins->destType(), ins->superSTV());
8445 defineReuseInput(new (alloc()) LWasmRefCastConcrete(
8446 ref, regs.superSTV, regs.scratch1, regs.scratch2),
8447 ins, 0);
8448 }
8449
8450 void LIRGenerator::visitWasmRefConvertAnyExtern(MWasmRefConvertAnyExtern* ins) {
8451 // Because any and extern have the same representation, this is a no-op.
8452 return redefine(ins, ins->ref());
8453 }
8454
8455 void LIRGenerator::visitWasmNewStructObject(MWasmNewStructObject* ins) {
8456 LWasmNewStructObject* lir =
8457 new (alloc()) LWasmNewStructObject(useFixed(ins->instance(), InstanceReg),
8458 useRegister(ins->allocSite()), temp());
8459 define(lir, ins);
8460 assignWasmSafepoint(lir);
8461 }
8462
8463 void LIRGenerator::visitWasmNewArrayObject(MWasmNewArrayObject* ins) {
8464 LWasmNewArrayObject* lir = new (alloc())
8465 LWasmNewArrayObject(useFixed(ins->instance(), InstanceReg),
8466 useRegisterOrConstant(ins->numElements()),
8467 useRegister(ins->allocSite()), temp(), temp());
8468 define(lir, ins);
8469 assignWasmSafepoint(lir);
8470 }
8471
8472 #ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT
8473 void LIRGenerator::visitAddDisposableResource(MAddDisposableResource* ins) {
8474 MDefinition* env = ins->environment();
8475
8476 MOZ_ASSERT(env->type() == MIRType::Object);
8477
8478 MDefinition* resource = ins->resource();
8479 MDefinition* method = ins->method();
8480 MDefinition* needsClosure = ins->needsClosure();
8481
8482 uint8_t hint = ins->hint();
8483
8484 auto* lir = new (alloc()) LAddDisposableResource(
8485 useRegisterAtStart(env), useBoxAtStart(resource), useBoxAtStart(method),
8486 useRegisterAtStart(needsClosure), hint);
8487 add(lir, ins);
8488 assignSafepoint(lir, ins);
8489 }
8490
8491 void LIRGenerator::visitTakeDisposeCapability(MTakeDisposeCapability* ins) {
8492 MDefinition* env = ins->environment();
8493
8494 LTakeDisposeCapability* lir =
8495 new (alloc()) LTakeDisposeCapability(useRegister(env));
8496 defineBox(lir, ins);
8497 assignSafepoint(lir, ins);
8498 }
8499
8500 void LIRGenerator::visitCreateSuppressedError(MCreateSuppressedError* ins) {
8501 MDefinition* error = ins->error();
8502 MDefinition* suppressed = ins->suppressed();
8503
8504 LCreateSuppressedError* lir = new (alloc())
8505 LCreateSuppressedError(useBoxAtStart(error), useBoxAtStart(suppressed));
8506 define(lir, ins);
8507 assignSafepoint(lir, ins);
8508 }
8509 #endif
8510
8511 #ifdef FUZZING_JS_FUZZILLI
8512 void LIRGenerator::visitFuzzilliHash(MFuzzilliHash* ins) {
8513 MDefinition* value = ins->input();
8514
8515 switch (value->type()) {
8516 case MIRType::Undefined:
8517 case MIRType::Null: {
8518 auto* lir =
8519 new (alloc()) LFuzzilliHashT(LAllocation(), temp(), tempDouble());
8520 define(lir, ins);
8521 break;
8522 }
8523
8524 case MIRType::Int32:
8525 case MIRType::Double:
8526 case MIRType::Float32:
8527 case MIRType::Boolean: {
8528 auto* lir = new (alloc())
8529 LFuzzilliHashT(useRegister(value), temp(), tempDouble());
8530 define(lir, ins);
8531 break;
8532 }
8533
8534 case MIRType::BigInt:
8535 case MIRType::Object: {
8536 auto* lir = new (alloc())
8537 LFuzzilliHashT(useRegister(value), LDefinition::BogusTemp(),
8538 LDefinition::BogusTemp());
8539 define(lir, ins);
8540 assignSafepoint(lir, ins);
8541 break;
8542 }
8543
8544 case MIRType::Value: {
8545 auto* lir =
8546 new (alloc()) LFuzzilliHashV(useBox(value), temp(), tempDouble());
8547 define(lir, ins);
8548 assignSafepoint(lir, ins);
8549 break;
8550 }
8551
8552 case MIRType::String:
8553 case MIRType::Symbol: {
8554 define(new (alloc()) LInteger(0), ins);
8555 break;
8556 }
8557
8558 default:
8559 MOZ_CRASH("Bad type");
8560 }
8561 }
8562
8563 void LIRGenerator::visitFuzzilliHashStore(MFuzzilliHashStore* ins) {
8564 MDefinition* value = ins->input();
8565 MOZ_ASSERT(value->type() == MIRType::Int32);
8566 add(new (alloc()) LFuzzilliHashStore(useRegister(value), temp(), temp()),
8567 ins);
8568 }
8569 #endif
8570
8571 static_assert(!std::is_polymorphic_v<LIRGenerator>,
8572 "LIRGenerator should not have any virtual methods");
8573
8574 #ifdef JS_CODEGEN_NONE
8575 void LIRGenerator::visitReturnImpl(MDefinition*, bool) { MOZ_CRASH(); }
8576 #endif