Debian Codegraph @

js/src/jit/LIR.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/LIR.h"
8
9 #include "mozilla/ScopeExit.h"
10
11 #include <type_traits>
12
13 #include "jit/JitSpewer.h"
14 #include "jit/MIR-wasm.h"
15 #include "jit/MIR.h"
16 #include "jit/MIRGenerator.h"
17 #include "js/Printf.h"
18 #include "util/Unicode.h"
19
20 using namespace js;
21 using namespace js::jit;
22
23 const char* const js::jit::LIROpNames[] = {
24 #define OPNAME(op, ...) #op,
25 LIR_OPCODE_LIST(OPNAME)
26 #undef OPNAME
27 };
28
29 LIRGraph::LIRGraph(MIRGraph* mir)
30 : constantPool_(mir->alloc()),
31 constantPoolMap_(mir->alloc()),
32 numVirtualRegisters_(0),
33 numInstructions_(1), // First id is 1.
34 localSlotsSize_(0),
35 argumentSlotCount_(0),
36 extraSafepointUses_(0),
37 mir_(*mir) {}
38
39 bool LIRGraph::addConstantToPool(const Value& v, uint32_t* index) {
40 ConstantPoolMap::AddPtr p = constantPoolMap_.lookupForAdd(v);
41 if (p) {
42 *index = p->value();
43 return true;
44 }
45 *index = constantPool_.length();
46 return constantPool_.append(v) && constantPoolMap_.add(p, v, *index);
47 }
48
49 #ifdef JS_JITSPEW
50 void LIRGraph::dump(GenericPrinter& out) {
51 for (size_t i = 0; i < numBlocks(); i++) {
52 getBlock(i)->dump(out);
53 out.printf("\n");
54 }
55 }
56
57 void LIRGraph::dump() {
58 Fprinter out(stderr);
59 dump(out);
60 out.finish();
61 }
62 #endif
63
64 LBlock::LBlock(MBasicBlock* from)
65 : block_(from), entryMoveGroup_(nullptr), exitMoveGroup_(nullptr) {
66 from->assignLir(this);
67 }
68
69 bool LBlock::init(TempAllocator& alloc) {
70 // Count the number of LPhis we'll need.
71 size_t numLPhis = 0;
72 for (MPhiIterator i(block_->phisBegin()), e(block_->phisEnd()); i != e; ++i) {
73 MPhi* phi = *i;
74 switch (phi->type()) {
75 case MIRType::Value:
76 numLPhis += BOX_PIECES;
77 break;
78 case MIRType::Int64:
79 numLPhis += INT64_PIECES;
80 break;
81 default:
82 numLPhis += 1;
83 break;
84 }
85 }
86
87 // Allocate space for the LPhis.
88 if (!phis_.init(alloc, numLPhis)) {
89 return false;
90 }
91
92 // For each MIR phi, set up LIR phis as appropriate. We'll fill in their
93 // operands on each incoming edge, and set their definitions at the start of
94 // their defining block.
95 size_t phiIndex = 0;
96 size_t numPreds = block_->numPredecessors();
97 for (MPhiIterator i(block_->phisBegin()), e(block_->phisEnd()); i != e; ++i) {
98 MPhi* phi = *i;
99 MOZ_ASSERT(phi->numOperands() == numPreds);
100
101 int numPhis;
102 switch (phi->type()) {
103 case MIRType::Value:
104 numPhis = BOX_PIECES;
105 break;
106 case MIRType::Int64:
107 numPhis = INT64_PIECES;
108 break;
109 default:
110 numPhis = 1;
111 break;
112 }
113 for (int i = 0; i < numPhis; i++) {
114 LAllocation* inputs = alloc.allocateArray<LAllocation>(numPreds);
115 if (!inputs) {
116 return false;
117 }
118
119 void* addr = &phis_[phiIndex++];
120 LPhi* lphi = new (addr) LPhi(phi, inputs);
121 lphi->setBlock(this);
122 }
123 }
124 return true;
125 }
126
127 const LInstruction* LBlock::firstInstructionWithId() const {
128 for (LInstructionIterator i(instructions_.begin()); i != instructions_.end();
129 ++i) {
130 if (i->id()) {
131 return *i;
132 }
133 }
134 return 0;
135 }
136
137 LMoveGroup* LBlock::getEntryMoveGroup(TempAllocator& alloc) {
138 if (entryMoveGroup_) {
139 return entryMoveGroup_;
140 }
141 entryMoveGroup_ = LMoveGroup::New(alloc);
142 insertBefore(*begin(), entryMoveGroup_);
143 return entryMoveGroup_;
144 }
145
146 LMoveGroup* LBlock::getExitMoveGroup(TempAllocator& alloc) {
147 if (exitMoveGroup_) {
148 return exitMoveGroup_;
149 }
150 exitMoveGroup_ = LMoveGroup::New(alloc);
151 insertBefore(*rbegin(), exitMoveGroup_);
152 return exitMoveGroup_;
153 }
154
155 #ifdef JS_JITSPEW
156 void LBlock::dump(GenericPrinter& out) {
157 out.printf("block%u:\n", mir()->id());
158 for (size_t i = 0; i < numPhis(); ++i) {
159 getPhi(i)->dump(out);
160 out.printf("\n");
161 }
162 for (LInstructionIterator iter = begin(); iter != end(); iter++) {
163 iter->dump(out);
164 if (iter->safepoint()) {
165 out.printf(" SAFEPOINT(0x%p) ", iter->safepoint());
166 }
167 out.printf("\n");
168 }
169 }
170
171 void LBlock::dump() {
172 Fprinter out(stderr);
173 dump(out);
174 out.finish();
175 }
176 #endif
177
178 static size_t TotalOperandCount(LRecoverInfo* recoverInfo) {
179 size_t accum = 0;
180 for (LRecoverInfo::OperandIter it(recoverInfo); !it; ++it) {
181 if (!it->isRecoveredOnBailout()) {
182 accum++;
183 }
184 }
185 return accum;
186 }
187
188 LRecoverInfo::LRecoverInfo(TempAllocator& alloc)
189 : instructions_(alloc), recoverOffset_(INVALID_RECOVER_OFFSET) {}
190
191 LRecoverInfo* LRecoverInfo::New(MIRGenerator* gen, MResumePoint* mir) {
192 LRecoverInfo* recoverInfo = new (gen->alloc()) LRecoverInfo(gen->alloc());
193 if (!recoverInfo || !recoverInfo->init(mir)) {
194 return nullptr;
195 }
196
197 JitSpew(JitSpew_IonSnapshots, "Generating LIR recover info %p from MIR (%p)",
198 (void*)recoverInfo, (void*)mir);
199
200 return recoverInfo;
201 }
202
203 // de-virtualise MResumePoint::getOperand calls.
204 template <typename Node>
205 bool LRecoverInfo::appendOperands(Node* ins) {
206 for (size_t i = 0, end = ins->numOperands(); i < end; i++) {
207 MDefinition* def = ins->getOperand(i);
208
209 // As there is no cycle in the data-flow (without MPhi), checking for
210 // isInWorkList implies that the definition is already in the
211 // instruction vector, and not processed by a caller of the current
212 // function.
213 if (def->isRecoveredOnBailout() && !def->isInWorklist()) {
214 if (!appendDefinition(def)) {
215 return false;
216 }
217 }
218 }
219
220 return true;
221 }
222
223 bool LRecoverInfo::appendDefinition(MDefinition* def) {
224 MOZ_ASSERT(def->isRecoveredOnBailout());
225 def->setInWorklist();
226 auto clearWorklistFlagOnFailure =
227 mozilla::MakeScopeExit([&] { def->setNotInWorklist(); });
228
229 if (!appendOperands(def)) {
230 return false;
231 }
232
233 if (!instructions_.append(def)) {
234 return false;
235 }
236
237 clearWorklistFlagOnFailure.release();
238 return true;
239 }
240
241 bool LRecoverInfo::appendResumePoint(MResumePoint* rp) {
242 // Stores should be recovered first.
243 if (!rp->storesEmpty()) {
244 hasSideEffects_ = true;
245 }
246 for (auto iter(rp->storesBegin()), end(rp->storesEnd()); iter != end;
247 ++iter) {
248 if (!appendDefinition(iter->operand)) {
249 return false;
250 }
251 }
252
253 if (rp->caller() && !appendResumePoint(rp->caller())) {
254 return false;
255 }
256
257 if (!appendOperands(rp)) {
258 return false;
259 }
260
261 return instructions_.append(rp);
262 }
263
264 bool LRecoverInfo::init(MResumePoint* rp) {
265 // Before exiting this function, remove temporary flags from all definitions
266 // added in the vector.
267 auto clearWorklistFlags = mozilla::MakeScopeExit([&] {
268 for (MNode** it = begin(); it != end(); it++) {
269 if (!(*it)->isDefinition()) {
270 continue;
271 }
272 (*it)->toDefinition()->setNotInWorklist();
273 }
274 });
275
276 // Sort operations in the order in which we need to restore the stack. This
277 // implies that outer frames, as well as operations needed to recover the
278 // current frame, are located before the current frame. The inner-most
279 // resume point should be the last element in the list.
280 if (!appendResumePoint(rp)) {
281 return false;
282 }
283
284 MOZ_ASSERT(mir() == rp);
285 return true;
286 }
287
288 LSnapshot::LSnapshot(LRecoverInfo* recoverInfo, BailoutKind kind)
289 : slots_(nullptr),
290 recoverInfo_(recoverInfo),
291 snapshotOffset_(INVALID_SNAPSHOT_OFFSET),
292 numSlots_(TotalOperandCount(recoverInfo) * BOX_PIECES),
293 bailoutKind_(kind) {}
294
295 bool LSnapshot::init(MIRGenerator* gen) {
296 slots_ = gen->allocate<LAllocation>(numSlots_);
297 return !!slots_;
298 }
299
300 LSnapshot* LSnapshot::New(MIRGenerator* gen, LRecoverInfo* recover,
301 BailoutKind kind) {
302 LSnapshot* snapshot = new (gen->alloc()) LSnapshot(recover, kind);
303 if (!snapshot || !snapshot->init(gen)) {
304 return nullptr;
305 }
306
307 JitSpew(JitSpew_IonSnapshots, "Generating LIR snapshot %p from recover (%p)",
308 (void*)snapshot, (void*)recover);
309
310 return snapshot;
311 }
312
313 void LSnapshot::rewriteRecoveredInput(LUse input) {
314 // Mark any operands to this snapshot with the same value as input as being
315 // equal to the instruction's result.
316 for (size_t i = 0; i < numEntries(); i++) {
317 if (getEntry(i)->isUse() &&
318 getEntry(i)->toUse()->virtualRegister() == input.virtualRegister()) {
319 setEntry(i, LUse(input.virtualRegister(), LUse::RECOVERED_INPUT));
320 }
321 }
322 }
323
324 #ifdef JS_JITSPEW
325 void LNode::printName(GenericPrinter& out, Opcode op) {
326 static const char* const names[] = {
327 # define LIROP(x) #x,
328 LIR_OPCODE_LIST(LIROP)
329 # undef LIROP
330 };
331 const char* name = names[uint32_t(op)];
332 size_t len = strlen(name);
333 for (size_t i = 0; i < len; i++) {
334 out.printf("%c", unicode::ToLowerCase(name[i]));
335 }
336 }
337
338 void LNode::printName(GenericPrinter& out) { printName(out, op()); }
339 #endif
340
341 bool LAllocation::aliases(const LAllocation& other) const {
342 if (isFloatReg() && other.isFloatReg()) {
343 return toFloatReg()->reg().aliases(other.toFloatReg()->reg());
344 }
345 return *this == other;
346 }
347
348 #ifdef JS_JITSPEW
349 static const char* DefTypeName(LDefinition::Type type) {
350 switch (type) {
351 case LDefinition::GENERAL:
352 return "g";
353 case LDefinition::INT32:
354 return "i";
355 case LDefinition::OBJECT:
356 return "o";
357 case LDefinition::SLOTS:
358 return "s";
359 case LDefinition::WASM_ANYREF:
360 return "wr";
361 case LDefinition::FLOAT32:
362 return "f";
363 case LDefinition::DOUBLE:
364 return "d";
365 case LDefinition::SIMD128:
366 return "simd128";
367 case LDefinition::STACKRESULTS:
368 return "stackresults";
369 # ifdef JS_NUNBOX32
370 case LDefinition::TYPE:
371 return "t";
372 case LDefinition::PAYLOAD:
373 return "p";
374 # else
375 case LDefinition::BOX:
376 return "x";
377 # endif
378 }
379 MOZ_CRASH("Invalid type");
380 }
381
382 UniqueChars LDefinition::toString() const {
383 AutoEnterOOMUnsafeRegion oomUnsafe;
384
385 UniqueChars buf;
386 if (isBogusTemp()) {
387 buf = JS_smprintf("bogus");
388 } else {
389 buf = JS_smprintf("v%u<%s>", virtualRegister(), DefTypeName(type()));
390 if (buf) {
391 if (policy() == LDefinition::FIXED) {
392 buf = JS_sprintf_append(std::move(buf), ":%s",
393 output()->toString().get());
394 } else if (policy() == LDefinition::MUST_REUSE_INPUT) {
395 buf = JS_sprintf_append(std::move(buf), ":tied(%u)", getReusedInput());
396 }
397 }
398 }
399
400 if (!buf) {
401 oomUnsafe.crash("LDefinition::toString()");
402 }
403
404 return buf;
405 }
406
407 static UniqueChars PrintUse(const LUse* use) {
408 switch (use->policy()) {
409 case LUse::REGISTER:
410 return JS_smprintf("v%u:R", use->virtualRegister());
411 case LUse::FIXED:
412 return JS_smprintf("v%u:F:%s", use->virtualRegister(),
413 AnyRegister::FromCode(use->registerCode()).name());
414 case LUse::ANY:
415 return JS_smprintf("v%u:A", use->virtualRegister());
416 case LUse::KEEPALIVE:
417 return JS_smprintf("v%u:KA", use->virtualRegister());
418 case LUse::STACK:
419 return JS_smprintf("v%u:S", use->virtualRegister());
420 case LUse::RECOVERED_INPUT:
421 return JS_smprintf("v%u:RI", use->virtualRegister());
422 default:
423 MOZ_CRASH("invalid use policy");
424 }
425 }
426
427 UniqueChars LAllocation::toString() const {
428 AutoEnterOOMUnsafeRegion oomUnsafe;
429
430 UniqueChars buf;
431 if (isBogus()) {
432 buf = JS_smprintf("bogus");
433 } else {
434 switch (kind()) {
435 case LAllocation::CONSTANT_VALUE:
436 case LAllocation::CONSTANT_INDEX: {
437 const MConstant* c = toConstant();
438 switch (c->type()) {
439 case MIRType::Int32:
440 buf = JS_smprintf("%d", c->toInt32());
441 break;
442 case MIRType::Int64:
443 buf = JS_smprintf("%" PRId64, c->toInt64());
444 break;
445 case MIRType::IntPtr:
446 buf = JS_smprintf("%" PRIxPTR, c->toIntPtr());
447 break;
448 case MIRType::String:
449 // If a JSContext is a available, output the actual string
450 if (JSContext* cx = TlsContext.get()) {
451 Sprinter spr(cx);
452 if (!spr.init()) {
453 oomUnsafe.crash("LAllocation::toString()");
454 }
455 spr.putString(cx, c->toString());
456 buf = spr.release();
457 } else {
458 buf = JS_smprintf("string");
459 }
460 break;
461 case MIRType::Symbol:
462 buf = JS_smprintf("sym");
463 break;
464 case MIRType::Object:
465 case MIRType::Null:
466 buf = JS_smprintf("obj %p", c->toObjectOrNull());
467 break;
468 case MIRType::Shape:
469 buf = JS_smprintf("shape");
470 break;
471 default:
472 if (c->isTypeRepresentableAsDouble()) {
473 buf = JS_smprintf("%g", c->numberToDouble());
474 } else {
475 buf = JS_smprintf("const");
476 }
477 }
478 } break;
479 case LAllocation::GPR:
480 buf = JS_smprintf("%s", toGeneralReg()->reg().name());
481 break;
482 case LAllocation::FPU:
483 buf = JS_smprintf("%s", toFloatReg()->reg().name());
484 break;
485 case LAllocation::STACK_SLOT:
486 buf = JS_smprintf("stack:%u(%u)", toStackSlot()->slot(),
487 LStackSlot::ByteWidth(toStackSlot()->width()));
488 break;
489 case LAllocation::ARGUMENT_SLOT:
490 buf = JS_smprintf("arg:%u", toArgument()->index());
491 break;
492 case LAllocation::STACK_AREA:
493 buf = JS_smprintf("stackarea:%u+%u", toStackArea()->base(),
494 toStackArea()->size());
495 break;
496 case LAllocation::USE:
497 buf = PrintUse(toUse());
498 break;
499 default:
500 MOZ_CRASH("what?");
501 }
502 }
503
504 if (!buf) {
505 oomUnsafe.crash("LAllocation::toString()");
506 }
507
508 return buf;
509 }
510
511 void LAllocation::dump() const { fprintf(stderr, "%s\n", toString().get()); }
512
513 void LDefinition::dump() const { fprintf(stderr, "%s\n", toString().get()); }
514
515 template <typename T>
516 static void PrintOperands(GenericPrinter& out, T* node) {
517 size_t numOperands = node->numOperands();
518
519 for (size_t i = 0; i < numOperands; i++) {
520 out.printf(" (%s)", node->getOperand(i)->toString().get());
521 if (i != numOperands - 1) {
522 out.printf(",");
523 }
524 }
525 }
526
527 void LNode::printOperands(GenericPrinter& out) {
528 if (isMoveGroup()) {
529 toMoveGroup()->printOperands(out);
530 return;
531 }
532 if (isInteger()) {
533 out.printf(" (%d)", toInteger()->i32());
534 return;
535 }
536 if (isInteger64()) {
537 out.printf(" (%" PRId64 ")", toInteger64()->i64());
538 return;
539 }
540
541 if (isPhi()) {
542 PrintOperands(out, toPhi());
543 } else {
544 PrintOperands(out, toInstruction());
545 }
546 }
547 #endif
548
549 void LInstruction::assignSnapshot(LSnapshot* snapshot) {
550 MOZ_ASSERT(!snapshot_);
551 snapshot_ = snapshot;
552
553 #ifdef JS_JITSPEW
554 if (JitSpewEnabled(JitSpew_IonSnapshots)) {
555 JitSpewHeader(JitSpew_IonSnapshots);
556 Fprinter& out = JitSpewPrinter();
557 out.printf("Assigning snapshot %p to instruction %p (", (void*)snapshot,
558 (void*)this);
559 printName(out);
560 out.printf(")\n");
561 }
562 #endif
563 }
564
565 #ifdef JS_JITSPEW
566 static size_t NumSuccessorsHelper(const LNode* ins) { return 0; }
567
568 template <size_t Succs, size_t Operands, size_t Temps>
569 static size_t NumSuccessorsHelper(
570 const LControlInstructionHelper<Succs, Operands, Temps>* ins) {
571 return Succs;
572 }
573
574 static size_t NumSuccessors(const LInstruction* ins) {
575 switch (ins->op()) {
576 default:
577 MOZ_CRASH("Unexpected LIR op");
578 # define LIROP(x) \
579 case LNode::Opcode::x: \
580 return NumSuccessorsHelper(ins->to##x());
581 LIR_OPCODE_LIST(LIROP)
582 # undef LIROP
583 }
584 }
585
586 static MBasicBlock* GetSuccessorHelper(const LNode* ins, size_t i) {
587 MOZ_CRASH("Unexpected instruction with successors");
588 }
589
590 template <size_t Succs, size_t Operands, size_t Temps>
591 static MBasicBlock* GetSuccessorHelper(
592 const LControlInstructionHelper<Succs, Operands, Temps>* ins, size_t i) {
593 return ins->getSuccessor(i);
594 }
595
596 static MBasicBlock* GetSuccessor(const LInstruction* ins, size_t i) {
597 MOZ_ASSERT(i < NumSuccessors(ins));
598
599 switch (ins->op()) {
600 default:
601 MOZ_CRASH("Unexpected LIR op");
602 # define LIROP(x) \
603 case LNode::Opcode::x: \
604 return GetSuccessorHelper(ins->to##x(), i);
605 LIR_OPCODE_LIST(LIROP)
606 # undef LIROP
607 }
608 }
609 #endif
610
611 #ifdef JS_JITSPEW
612 void LNode::dump(GenericPrinter& out) {
613 if (numDefs() != 0) {
614 out.printf("{");
615 for (size_t i = 0; i < numDefs(); i++) {
616 const LDefinition* def =
617 isPhi() ? toPhi()->getDef(i) : toInstruction()->getDef(i);
618 out.printf("%s", def->toString().get());
619 if (i != numDefs() - 1) {
620 out.printf(", ");
621 }
622 }
623 out.printf("} <- ");
624 }
625
626 printName(out);
627 printOperands(out);
628
629 if (isInstruction()) {
630 LInstruction* ins = toInstruction();
631 size_t numTemps = ins->numTemps();
632 if (numTemps > 0) {
633 out.printf(" t=(");
634 for (size_t i = 0; i < numTemps; i++) {
635 out.printf("%s", ins->getTemp(i)->toString().get());
636 if (i != numTemps - 1) {
637 out.printf(", ");
638 }
639 }
640 out.printf(")");
641 }
642
643 size_t numSuccessors = NumSuccessors(ins);
644 if (numSuccessors > 0) {
645 out.printf(" s=(");
646 for (size_t i = 0; i < numSuccessors; i++) {
647 MBasicBlock* succ = GetSuccessor(ins, i);
648 out.printf("block %u", succ->id());
649 if (i != numSuccessors - 1) {
650 out.printf(", ");
651 }
652 }
653 out.printf(")");
654 }
655 }
656 }
657
658 void LNode::dump() {
659 Fprinter out(stderr);
660 dump(out);
661 out.printf("\n");
662 out.finish();
663 }
664
665 const char* LNode::getExtraName() const {
666 switch (op()) {
667 default:
668 MOZ_CRASH("Unexpected LIR op");
669 # define LIROP(x) \
670 case LNode::Opcode::x: \
671 return to##x()->extraName();
672 LIR_OPCODE_LIST(LIROP)
673 # undef LIROP
674 }
675 }
676 #endif
677
678 void LInstruction::initSafepoint(TempAllocator& alloc) {
679 MOZ_ASSERT(!safepoint_);
680 safepoint_ = new (alloc) LSafepoint(alloc);
681 MOZ_ASSERT(safepoint_);
682 }
683
684 bool LSafepoint::addGCAllocation(uint32_t vregId, LDefinition* def,
685 LAllocation a) {
686 switch (def->type()) {
687 case LDefinition::OBJECT:
688 return addGcPointer(a);
689
690 case LDefinition::SLOTS:
691 return addSlotsOrElementsPointer(a);
692
693 case LDefinition::WASM_ANYREF:
694 return addWasmAnyRef(a);
695
696 #ifdef JS_NUNBOX32
697 case LDefinition::TYPE:
698 return addNunboxPart(/* isType = */ true, vregId, a);
699
700 case LDefinition::PAYLOAD:
701 return addNunboxPart(/* isType = */ false, vregId, a);
702 #else
703 case LDefinition::BOX:
704 return addBoxedValue(a);
705 #endif
706
707 case LDefinition::STACKRESULTS: {
708 MOZ_ASSERT(a.isStackArea());
709 for (auto iter = a.toStackArea()->results(); iter; iter.next()) {
710 if (iter.isWasmAnyRef()) {
711 if (!addWasmAnyRef(iter.alloc())) {
712 return false;
713 }
714 }
715 }
716 return true;
717 }
718
719 case LDefinition::GENERAL:
720 case LDefinition::INT32:
721 case LDefinition::FLOAT32:
722 case LDefinition::DOUBLE:
723 case LDefinition::SIMD128:
724 break;
725 }
726 MOZ_CRASH("Bad register type");
727 }
728
729 bool LMoveGroup::add(LAllocation from, LAllocation to, LDefinition::Type type) {
730 #ifdef DEBUG
731 MOZ_ASSERT(from != to);
732 for (size_t i = 0; i < moves_.length(); i++) {
733 MOZ_ASSERT(to != moves_[i].to());
734 }
735
736 // Check that SIMD moves are aligned according to ABI requirements.
737 // clang-format off
738 # ifdef ENABLE_WASM_SIMD
739 // Alignment is not currently required for SIMD on x86/x64/arm64. See also
740 // CodeGeneratorShared::CodeGeneratorShared and in general everywhere
741 // SimdMemoryAignment is used. Likely, alignment requirements will return.
742 # if defined(JS_CODEGEN_X86) || defined(JS_CODEGEN_X64) || \
743 defined(JS_CODEGEN_ARM64)
744 // No need for any check on x86/x64/arm64.
745 # else
746 # error "Need to consider SIMD alignment on this target."
747 // The following code may be of use if we need alignment checks on
748 // some future target.
749 //if (LDefinition(type).type() == LDefinition::SIMD128) {
750 // MOZ_ASSERT(from.isMemory() || from.isFloatReg());
751 // if (from.isMemory()) {
752 // if (from.isArgument()) {
753 // MOZ_ASSERT(from.toArgument()->index() % SimdMemoryAlignment == 0);
754 // } else {
755 // MOZ_ASSERT(from.toStackSlot()->slot() % SimdMemoryAlignment == 0);
756 // }
757 // }
758 // MOZ_ASSERT(to.isMemory() || to.isFloatReg());
759 // if (to.isMemory()) {
760 // if (to.isArgument()) {
761 // MOZ_ASSERT(to.toArgument()->index() % SimdMemoryAlignment == 0);
762 // } else {
763 // MOZ_ASSERT(to.toStackSlot()->slot() % SimdMemoryAlignment == 0);
764 // }
765 // }
766 //}
767 # endif
768 # endif
769 // clang-format on
770
771 #endif
772 return moves_.append(LMove(from, to, type));
773 }
774
775 bool LMoveGroup::addAfter(LAllocation from, LAllocation to,
776 LDefinition::Type type) {
777 // Transform the operands to this move so that performing the result
778 // simultaneously with existing moves in the group will have the same
779 // effect as if the original move took place after the existing moves.
780
781 for (size_t i = 0; i < moves_.length(); i++) {
782 if (moves_[i].to() == from) {
783 from = moves_[i].from();
784 break;
785 }
786 }
787
788 if (from == to) {
789 return true;
790 }
791
792 for (size_t i = 0; i < moves_.length(); i++) {
793 if (to == moves_[i].to()) {
794 moves_[i] = LMove(from, to, type);
795 return true;
796 }
797 }
798
799 return add(from, to, type);
800 }
801
802 #ifdef JS_JITSPEW
803 void LMoveGroup::printOperands(GenericPrinter& out) {
804 for (size_t i = 0; i < numMoves(); i++) {
805 const LMove& move = getMove(i);
806 out.printf(" [%s -> %s", move.from().toString().get(),
807 move.to().toString().get());
808 out.printf(", %s", DefTypeName(move.type()));
809 out.printf("]");
810 if (i != numMoves() - 1) {
811 out.printf(",");
812 }
813 }
814 }
815 #endif
816
817 #define LIROP(x) \
818 static_assert(!std::is_polymorphic_v<L##x>, \
819 "LIR instructions should not have virtual methods");
820 LIR_OPCODE_LIST(LIROP)
821 #undef LIROP