Debian Codegraph @

js/src/jit/Recover.h

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 #ifndef jit_Recover_h
8 #define jit_Recover_h
9
10 #include "mozilla/Attributes.h"
11
12 #include "jit/MIR-wasm.h"
13 #include "jit/MIR.h"
14 #include "jit/Snapshots.h"
15
16 namespace js {
17 namespace jit {
18
19 // [SMDOC] IonMonkey Recover Instructions
20 //
21 // This file contains all recover instructions.
22 //
23 // A recover instruction is an equivalent of a MIR instruction which is executed
24 // before the reconstruction of a baseline frame. Recover instructions are used
25 // by resume points to fill the value which are not produced by the code
26 // compiled by IonMonkey. For example, if a value is optimized away by
27 // IonMonkey, but required by Baseline, then we should have a recover
28 // instruction to fill the missing baseline frame slot.
29 //
30 // Recover instructions are executed either during a bailout, or under a call
31 // when the stack frame is introspected. If the stack is introspected, then any
32 // use of recover instruction must lead to an invalidation of the code.
33 //
34 // For each MIR instruction where |canRecoverOnBailout| might return true, we
35 // have a RInstruction of the same name.
36 //
37 // Recover instructions are encoded by the code generator into a compact buffer
38 // (RecoverWriter). The MIR instruction method |writeRecoverData| should write a
39 // tag in the |CompactBufferWriter| which is used by
40 // |RInstruction::readRecoverData| to dispatch to the right Recover
41 // instruction. Then |writeRecoverData| writes any local fields which are
42 // necessary for the execution of the |recover| method. These fields are decoded
43 // by the Recover instruction constructor which has a |CompactBufferReader| as
44 // argument. The constructor of the Recover instruction should follow the same
45 // sequence as the |writeRecoverData| method of the MIR instruction.
46 //
47 // Recover instructions are decoded by the |SnapshotIterator| (RecoverReader),
48 // which is given as argument of the |recover| methods, in order to read the
49 // operands. The number of operands read should be the same as the result of
50 // |numOperands|, which corresponds to the number of operands of the MIR
51 // instruction. Operands should be decoded in the same order as the operands of
52 // the MIR instruction.
53 //
54 // The result of the |recover| method should either be a failure, or a value
55 // stored on the |SnapshotIterator|, by using the |storeInstructionResult|
56 // method.
57
58 #define RECOVER_OPCODE_LIST(_) \
59 _(ResumePoint) \
60 _(BitNot) \
61 _(BitAnd) \
62 _(BitOr) \
63 _(BitXor) \
64 _(Lsh) \
65 _(Rsh) \
66 _(Ursh) \
67 _(SignExtendInt32) \
68 _(Add) \
69 _(Sub) \
70 _(Mul) \
71 _(Div) \
72 _(Mod) \
73 _(Not) \
74 _(BigIntAdd) \
75 _(BigIntSub) \
76 _(BigIntMul) \
77 _(BigIntDiv) \
78 _(BigIntMod) \
79 _(BigIntPow) \
80 _(BigIntBitAnd) \
81 _(BigIntBitOr) \
82 _(BigIntBitXor) \
83 _(BigIntLsh) \
84 _(BigIntRsh) \
85 _(BigIntIncrement) \
86 _(BigIntDecrement) \
87 _(BigIntNegate) \
88 _(BigIntBitNot) \
89 _(BigIntToIntPtr) \
90 _(IntPtrToBigInt) \
91 _(BigIntPtrAdd) \
92 _(BigIntPtrSub) \
93 _(BigIntPtrMul) \
94 _(BigIntPtrDiv) \
95 _(BigIntPtrMod) \
96 _(BigIntPtrPow) \
97 _(BigIntPtrBitAnd) \
98 _(BigIntPtrBitOr) \
99 _(BigIntPtrBitXor) \
100 _(BigIntPtrLsh) \
101 _(BigIntPtrRsh) \
102 _(BigIntPtrBitNot) \
103 _(Compare) \
104 _(StrictConstantCompareInt32) \
105 _(StrictConstantCompareBoolean) \
106 _(Concat) \
107 _(StringLength) \
108 _(ArgumentsLength) \
109 _(Floor) \
110 _(Ceil) \
111 _(Round) \
112 _(Trunc) \
113 _(CharCodeAt) \
114 _(FromCharCode) \
115 _(FromCharCodeEmptyIfNegative) \
116 _(Pow) \
117 _(PowHalf) \
118 _(MinMax) \
119 _(Abs) \
120 _(Sqrt) \
121 _(Atan2) \
122 _(Hypot) \
123 _(NearbyInt) \
124 _(Sign) \
125 _(MathFunction) \
126 _(Random) \
127 _(StringSplit) \
128 _(NaNToZero) \
129 _(StringReplace) \
130 _(Substr) \
131 _(TypeOf) \
132 _(TypeOfName) \
133 _(ToDouble) \
134 _(ToFloat32) \
135 _(ToFloat16) \
136 _(TruncateToInt32) \
137 _(NewObject) \
138 _(NewPlainObject) \
139 _(NewArrayObject) \
140 _(NewTypedArray) \
141 _(NewArray) \
142 _(NewIterator) \
143 _(NewCallObject) \
144 _(Lambda) \
145 _(FunctionWithProto) \
146 _(ObjectKeys) \
147 _(ObjectState) \
148 _(ArrayState) \
149 _(AtomicIsLockFree) \
150 _(Int64ToBigInt) \
151 _(BigIntAsIntN) \
152 _(BigIntAsUintN) \
153 _(CreateArgumentsObject) \
154 _(CreateInlinedArgumentsObject) \
155 _(Rest) \
156 _(AssertRecoveredOnBailout)
157
158 class RResumePoint;
159 class SnapshotIterator;
160
161 class MOZ_NON_PARAM RInstruction {
162 public:
163 enum Opcode {
164 #define DEFINE_OPCODES_(op) Recover_##op,
165 RECOVER_OPCODE_LIST(DEFINE_OPCODES_)
166 #undef DEFINE_OPCODES_
167 Recover_Invalid
168 };
169
170 virtual Opcode opcode() const = 0;
171
172 // As opposed to the MIR, there is no need to add more methods as every
173 // other instruction is well abstracted under the "recover" method.
174 bool isResumePoint() const { return opcode() == Recover_ResumePoint; }
175 inline const RResumePoint* toResumePoint() const;
176
177 // Call the copy constructor of a specific RInstruction, to do a copy of the
178 // RInstruction content.
179 virtual void cloneInto(RInstructionStorage* raw) const = 0;
180
181 // Number of allocations which are encoded in the Snapshot for recovering
182 // the current instruction.
183 virtual uint32_t numOperands() const = 0;
184
185 // Function used to recover the value computed by this instruction. This
186 // function reads its arguments from the allocations listed on the snapshot
187 // iterator and stores its returned value on the snapshot iterator too.
188 [[nodiscard]] virtual bool recover(JSContext* cx,
189 SnapshotIterator& iter) const = 0;
190
191 // Decode an RInstruction on top of the reserved storage space, based on the
192 // tag written by the writeRecoverData function of the corresponding MIR
193 // instruction.
194 static void readRecoverData(CompactBufferReader& reader,
195 RInstructionStorage* raw);
196 };
197
198 #define RINSTRUCTION_HEADER_(op) \
199 private: \
200 friend class RInstruction; \
201 explicit R##op(CompactBufferReader& reader); \
202 explicit R##op(const R##op& src) = default; \
203 \
204 public: \
205 Opcode opcode() const override { return RInstruction::Recover_##op; } \
206 void cloneInto(RInstructionStorage* raw) const override { \
207 new (raw->addr()) R##op(*this); \
208 }
209
210 #define RINSTRUCTION_HEADER_NUM_OP_MAIN(op, numOp) \
211 RINSTRUCTION_HEADER_(op) \
212 uint32_t numOperands() const override { return numOp; }
213
214 #ifdef DEBUG
215 # define RINSTRUCTION_HEADER_NUM_OP_(op, numOp) \
216 RINSTRUCTION_HEADER_NUM_OP_MAIN(op, numOp) \
217 static_assert( \
218 M##op::staticNumOperands == numOp, \
219 "The recover instructions's numOperands should equal to the " \
220 "MIR's numOperands");
221 #else
222 # define RINSTRUCTION_HEADER_NUM_OP_(op, numOp) \
223 RINSTRUCTION_HEADER_NUM_OP_MAIN(op, numOp)
224 #endif
225
226 class RResumePoint final : public RInstruction {
227 private:
228 uint32_t pcOffsetAndMode_; // Offset from script->code and ResumeMode.
229 uint32_t numOperands_; // Number of slots.
230
231 public:
232 RINSTRUCTION_HEADER_(ResumePoint)
233
234 // Used to encode/decode pcOffsetAndMode_.
235 static constexpr uint32_t PCOffsetShift = 4;
236 static constexpr uint32_t ResumeModeMask = 0b1111;
237 static_assert(uint32_t(ResumeMode::Last) <= ResumeModeMask);
238
239 uint32_t pcOffset() const { return pcOffsetAndMode_ >> PCOffsetShift; }
240 ResumeMode mode() const {
241 return ResumeMode(pcOffsetAndMode_ & ResumeModeMask);
242 }
243
244 uint32_t numOperands() const override { return numOperands_; }
245 [[nodiscard]] bool recover(JSContext* cx,
246 SnapshotIterator& iter) const override;
247 };
248
249 class RBitNot final : public RInstruction {
250 public:
251 RINSTRUCTION_HEADER_NUM_OP_(BitNot, 1)
252
253 [[nodiscard]] bool recover(JSContext* cx,
254 SnapshotIterator& iter) const override;
255 };
256
257 class RBitAnd final : public RInstruction {
258 public:
259 RINSTRUCTION_HEADER_NUM_OP_(BitAnd, 2)
260
261 [[nodiscard]] bool recover(JSContext* cx,
262 SnapshotIterator& iter) const override;
263 };
264
265 class RBitOr final : public RInstruction {
266 public:
267 RINSTRUCTION_HEADER_NUM_OP_(BitOr, 2)
268
269 [[nodiscard]] bool recover(JSContext* cx,
270 SnapshotIterator& iter) const override;
271 };
272
273 class RBitXor final : public RInstruction {
274 public:
275 RINSTRUCTION_HEADER_NUM_OP_(BitXor, 2)
276
277 [[nodiscard]] bool recover(JSContext* cx,
278 SnapshotIterator& iter) const override;
279 };
280
281 class RLsh final : public RInstruction {
282 public:
283 RINSTRUCTION_HEADER_NUM_OP_(Lsh, 2)
284
285 [[nodiscard]] bool recover(JSContext* cx,
286 SnapshotIterator& iter) const override;
287 };
288
289 class RRsh final : public RInstruction {
290 public:
291 RINSTRUCTION_HEADER_NUM_OP_(Rsh, 2)
292
293 [[nodiscard]] bool recover(JSContext* cx,
294 SnapshotIterator& iter) const override;
295 };
296
297 class RUrsh final : public RInstruction {
298 public:
299 RINSTRUCTION_HEADER_NUM_OP_(Ursh, 2)
300
301 [[nodiscard]] bool recover(JSContext* cx,
302 SnapshotIterator& iter) const override;
303 };
304
305 class RSignExtendInt32 final : public RInstruction {
306 private:
307 uint8_t mode_;
308
309 public:
310 RINSTRUCTION_HEADER_NUM_OP_(SignExtendInt32, 1)
311
312 [[nodiscard]] bool recover(JSContext* cx,
313 SnapshotIterator& iter) const override;
314 };
315
316 class RAdd final : public RInstruction {
317 private:
318 bool isFloatOperation_;
319
320 public:
321 RINSTRUCTION_HEADER_NUM_OP_(Add, 2)
322
323 [[nodiscard]] bool recover(JSContext* cx,
324 SnapshotIterator& iter) const override;
325 };
326
327 class RSub final : public RInstruction {
328 private:
329 bool isFloatOperation_;
330
331 public:
332 RINSTRUCTION_HEADER_NUM_OP_(Sub, 2)
333
334 [[nodiscard]] bool recover(JSContext* cx,
335 SnapshotIterator& iter) const override;
336 };
337
338 class RMul final : public RInstruction {
339 private:
340 bool isFloatOperation_;
341 uint8_t mode_;
342
343 public:
344 RINSTRUCTION_HEADER_NUM_OP_(Mul, 2)
345
346 [[nodiscard]] bool recover(JSContext* cx,
347 SnapshotIterator& iter) const override;
348 };
349
350 class RDiv final : public RInstruction {
351 private:
352 bool isFloatOperation_;
353
354 public:
355 RINSTRUCTION_HEADER_NUM_OP_(Div, 2)
356
357 [[nodiscard]] bool recover(JSContext* cx,
358 SnapshotIterator& iter) const override;
359 };
360
361 class RMod final : public RInstruction {
362 public:
363 RINSTRUCTION_HEADER_NUM_OP_(Mod, 2)
364
365 [[nodiscard]] bool recover(JSContext* cx,
366 SnapshotIterator& iter) const override;
367 };
368
369 class RNot final : public RInstruction {
370 public:
371 RINSTRUCTION_HEADER_NUM_OP_(Not, 1)
372
373 [[nodiscard]] bool recover(JSContext* cx,
374 SnapshotIterator& iter) const override;
375 };
376
377 class RBigIntAdd final : public RInstruction {
378 public:
379 RINSTRUCTION_HEADER_NUM_OP_(BigIntAdd, 2)
380
381 [[nodiscard]] bool recover(JSContext* cx,
382 SnapshotIterator& iter) const override;
383 };
384
385 class RBigIntSub final : public RInstruction {
386 public:
387 RINSTRUCTION_HEADER_NUM_OP_(BigIntSub, 2)
388
389 [[nodiscard]] bool recover(JSContext* cx,
390 SnapshotIterator& iter) const override;
391 };
392
393 class RBigIntMul final : public RInstruction {
394 public:
395 RINSTRUCTION_HEADER_NUM_OP_(BigIntMul, 2)
396
397 [[nodiscard]] bool recover(JSContext* cx,
398 SnapshotIterator& iter) const override;
399 };
400
401 class RBigIntDiv final : public RInstruction {
402 public:
403 RINSTRUCTION_HEADER_NUM_OP_(BigIntDiv, 2)
404
405 [[nodiscard]] bool recover(JSContext* cx,
406 SnapshotIterator& iter) const override;
407 };
408
409 class RBigIntMod final : public RInstruction {
410 public:
411 RINSTRUCTION_HEADER_NUM_OP_(BigIntMod, 2)
412
413 [[nodiscard]] bool recover(JSContext* cx,
414 SnapshotIterator& iter) const override;
415 };
416
417 class RBigIntPow final : public RInstruction {
418 public:
419 RINSTRUCTION_HEADER_NUM_OP_(BigIntPow, 2)
420
421 [[nodiscard]] bool recover(JSContext* cx,
422 SnapshotIterator& iter) const override;
423 };
424
425 class RBigIntBitAnd final : public RInstruction {
426 public:
427 RINSTRUCTION_HEADER_NUM_OP_(BigIntBitAnd, 2)
428
429 [[nodiscard]] bool recover(JSContext* cx,
430 SnapshotIterator& iter) const override;
431 };
432
433 class RBigIntBitOr final : public RInstruction {
434 public:
435 RINSTRUCTION_HEADER_NUM_OP_(BigIntBitOr, 2)
436
437 [[nodiscard]] bool recover(JSContext* cx,
438 SnapshotIterator& iter) const override;
439 };
440
441 class RBigIntBitXor final : public RInstruction {
442 public:
443 RINSTRUCTION_HEADER_NUM_OP_(BigIntBitXor, 2)
444
445 [[nodiscard]] bool recover(JSContext* cx,
446 SnapshotIterator& iter) const override;
447 };
448
449 class RBigIntLsh final : public RInstruction {
450 public:
451 RINSTRUCTION_HEADER_NUM_OP_(BigIntLsh, 2)
452
453 [[nodiscard]] bool recover(JSContext* cx,
454 SnapshotIterator& iter) const override;
455 };
456
457 class RBigIntRsh final : public RInstruction {
458 public:
459 RINSTRUCTION_HEADER_NUM_OP_(BigIntRsh, 2)
460
461 [[nodiscard]] bool recover(JSContext* cx,
462 SnapshotIterator& iter) const override;
463 };
464
465 class RBigIntIncrement final : public RInstruction {
466 public:
467 RINSTRUCTION_HEADER_NUM_OP_(BigIntIncrement, 1)
468
469 [[nodiscard]] bool recover(JSContext* cx,
470 SnapshotIterator& iter) const override;
471 };
472
473 class RBigIntDecrement final : public RInstruction {
474 public:
475 RINSTRUCTION_HEADER_NUM_OP_(BigIntDecrement, 1)
476
477 [[nodiscard]] bool recover(JSContext* cx,
478 SnapshotIterator& iter) const override;
479 };
480
481 class RBigIntNegate final : public RInstruction {
482 public:
483 RINSTRUCTION_HEADER_NUM_OP_(BigIntNegate, 1)
484
485 [[nodiscard]] bool recover(JSContext* cx,
486 SnapshotIterator& iter) const override;
487 };
488
489 class RBigIntBitNot final : public RInstruction {
490 public:
491 RINSTRUCTION_HEADER_NUM_OP_(BigIntBitNot, 1)
492
493 [[nodiscard]] bool recover(JSContext* cx,
494 SnapshotIterator& iter) const override;
495 };
496
497 class RBigIntToIntPtr final : public RInstruction {
498 public:
499 RINSTRUCTION_HEADER_NUM_OP_(BigIntToIntPtr, 1)
500
501 [[nodiscard]] bool recover(JSContext* cx,
502 SnapshotIterator& iter) const override;
503 };
504
505 class RIntPtrToBigInt final : public RInstruction {
506 public:
507 RINSTRUCTION_HEADER_NUM_OP_(IntPtrToBigInt, 1)
508
509 [[nodiscard]] bool recover(JSContext* cx,
510 SnapshotIterator& iter) const override;
511 };
512
513 class RBigIntPtrAdd final : public RInstruction {
514 public:
515 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrAdd, 2)
516
517 [[nodiscard]] bool recover(JSContext* cx,
518 SnapshotIterator& iter) const override;
519 };
520
521 class RBigIntPtrSub final : public RInstruction {
522 public:
523 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrSub, 2)
524
525 [[nodiscard]] bool recover(JSContext* cx,
526 SnapshotIterator& iter) const override;
527 };
528
529 class RBigIntPtrMul final : public RInstruction {
530 public:
531 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrMul, 2)
532
533 [[nodiscard]] bool recover(JSContext* cx,
534 SnapshotIterator& iter) const override;
535 };
536
537 class RBigIntPtrDiv final : public RInstruction {
538 public:
539 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrDiv, 2)
540
541 [[nodiscard]] bool recover(JSContext* cx,
542 SnapshotIterator& iter) const override;
543 };
544
545 class RBigIntPtrMod final : public RInstruction {
546 public:
547 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrMod, 2)
548
549 [[nodiscard]] bool recover(JSContext* cx,
550 SnapshotIterator& iter) const override;
551 };
552
553 class RBigIntPtrPow final : public RInstruction {
554 public:
555 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrPow, 2)
556
557 [[nodiscard]] bool recover(JSContext* cx,
558 SnapshotIterator& iter) const override;
559 };
560
561 class RBigIntPtrBitAnd final : public RInstruction {
562 public:
563 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrBitAnd, 2)
564
565 [[nodiscard]] bool recover(JSContext* cx,
566 SnapshotIterator& iter) const override;
567 };
568
569 class RBigIntPtrBitOr final : public RInstruction {
570 public:
571 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrBitOr, 2)
572
573 [[nodiscard]] bool recover(JSContext* cx,
574 SnapshotIterator& iter) const override;
575 };
576
577 class RBigIntPtrBitXor final : public RInstruction {
578 public:
579 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrBitXor, 2)
580
581 [[nodiscard]] bool recover(JSContext* cx,
582 SnapshotIterator& iter) const override;
583 };
584
585 class RBigIntPtrLsh final : public RInstruction {
586 public:
587 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrLsh, 2)
588
589 [[nodiscard]] bool recover(JSContext* cx,
590 SnapshotIterator& iter) const override;
591 };
592
593 class RBigIntPtrRsh final : public RInstruction {
594 public:
595 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrRsh, 2)
596
597 [[nodiscard]] bool recover(JSContext* cx,
598 SnapshotIterator& iter) const override;
599 };
600
601 class RBigIntPtrBitNot final : public RInstruction {
602 public:
603 RINSTRUCTION_HEADER_NUM_OP_(BigIntPtrBitNot, 1)
604
605 [[nodiscard]] bool recover(JSContext* cx,
606 SnapshotIterator& iter) const override;
607 };
608
609 class RCompare final : public RInstruction {
610 JSOp jsop_;
611
612 public:
613 RINSTRUCTION_HEADER_NUM_OP_(Compare, 2)
614
615 [[nodiscard]] bool recover(JSContext* cx,
616 SnapshotIterator& iter) const override;
617 };
618
619 class RStrictConstantCompareInt32 final : public RInstruction {
620 JSOp jsop_;
621 int32_t constant_;
622
623 public:
624 RINSTRUCTION_HEADER_NUM_OP_(StrictConstantCompareInt32, 1)
625
626 [[nodiscard]] bool recover(JSContext* cx,
627 SnapshotIterator& iter) const override;
628 };
629
630 class RStrictConstantCompareBoolean final : public RInstruction {
631 JSOp jsop_;
632 bool constant_;
633
634 public:
635 RINSTRUCTION_HEADER_NUM_OP_(StrictConstantCompareBoolean, 1)
636
637 [[nodiscard]] bool recover(JSContext* cx,
638 SnapshotIterator& iter) const override;
639 };
640
641 class RConcat final : public RInstruction {
642 public:
643 RINSTRUCTION_HEADER_NUM_OP_(Concat, 2)
644
645 [[nodiscard]] bool recover(JSContext* cx,
646 SnapshotIterator& iter) const override;
647 };
648
649 class RStringLength final : public RInstruction {
650 public:
651 RINSTRUCTION_HEADER_NUM_OP_(StringLength, 1)
652
653 [[nodiscard]] bool recover(JSContext* cx,
654 SnapshotIterator& iter) const override;
655 };
656
657 class RArgumentsLength final : public RInstruction {
658 public:
659 RINSTRUCTION_HEADER_NUM_OP_(ArgumentsLength, 0)
660
661 [[nodiscard]] bool recover(JSContext* cx,
662 SnapshotIterator& iter) const override;
663 };
664
665 class RFloor final : public RInstruction {
666 public:
667 RINSTRUCTION_HEADER_NUM_OP_(Floor, 1)
668
669 [[nodiscard]] bool recover(JSContext* cx,
670 SnapshotIterator& iter) const override;
671 };
672
673 class RCeil final : public RInstruction {
674 public:
675 RINSTRUCTION_HEADER_NUM_OP_(Ceil, 1)
676
677 [[nodiscard]] bool recover(JSContext* cx,
678 SnapshotIterator& iter) const override;
679 };
680
681 class RRound final : public RInstruction {
682 public:
683 RINSTRUCTION_HEADER_NUM_OP_(Round, 1)
684
685 [[nodiscard]] bool recover(JSContext* cx,
686 SnapshotIterator& iter) const override;
687 };
688
689 class RTrunc final : public RInstruction {
690 public:
691 RINSTRUCTION_HEADER_NUM_OP_(Trunc, 1)
692
693 [[nodiscard]] bool recover(JSContext* cx,
694 SnapshotIterator& iter) const override;
695 };
696
697 class RCharCodeAt final : public RInstruction {
698 public:
699 RINSTRUCTION_HEADER_NUM_OP_(CharCodeAt, 2)
700
701 [[nodiscard]] bool recover(JSContext* cx,
702 SnapshotIterator& iter) const override;
703 };
704
705 class RFromCharCode final : public RInstruction {
706 public:
707 RINSTRUCTION_HEADER_NUM_OP_(FromCharCode, 1)
708
709 [[nodiscard]] bool recover(JSContext* cx,
710 SnapshotIterator& iter) const override;
711 };
712
713 class RFromCharCodeEmptyIfNegative final : public RInstruction {
714 public:
715 RINSTRUCTION_HEADER_NUM_OP_(FromCharCodeEmptyIfNegative, 1)
716
717 [[nodiscard]] bool recover(JSContext* cx,
718 SnapshotIterator& iter) const override;
719 };
720
721 class RPow final : public RInstruction {
722 public:
723 RINSTRUCTION_HEADER_NUM_OP_(Pow, 2)
724
725 [[nodiscard]] bool recover(JSContext* cx,
726 SnapshotIterator& iter) const override;
727 };
728
729 class RPowHalf final : public RInstruction {
730 public:
731 RINSTRUCTION_HEADER_NUM_OP_(PowHalf, 1)
732
733 [[nodiscard]] bool recover(JSContext* cx,
734 SnapshotIterator& iter) const override;
735 };
736
737 class RMinMax final : public RInstruction {
738 private:
739 bool isMax_;
740
741 public:
742 RINSTRUCTION_HEADER_NUM_OP_(MinMax, 2)
743
744 [[nodiscard]] bool recover(JSContext* cx,
745 SnapshotIterator& iter) const override;
746 };
747
748 class RAbs final : public RInstruction {
749 public:
750 RINSTRUCTION_HEADER_NUM_OP_(Abs, 1)
751
752 [[nodiscard]] bool recover(JSContext* cx,
753 SnapshotIterator& iter) const override;
754 };
755
756 class RSqrt final : public RInstruction {
757 private:
758 bool isFloatOperation_;
759
760 public:
761 RINSTRUCTION_HEADER_NUM_OP_(Sqrt, 1)
762
763 [[nodiscard]] bool recover(JSContext* cx,
764 SnapshotIterator& iter) const override;
765 };
766
767 class RAtan2 final : public RInstruction {
768 public:
769 RINSTRUCTION_HEADER_NUM_OP_(Atan2, 2)
770
771 [[nodiscard]] bool recover(JSContext* cx,
772 SnapshotIterator& iter) const override;
773 };
774
775 class RHypot final : public RInstruction {
776 private:
777 uint32_t numOperands_;
778
779 public:
780 RINSTRUCTION_HEADER_(Hypot)
781
782 uint32_t numOperands() const override { return numOperands_; }
783
784 [[nodiscard]] bool recover(JSContext* cx,
785 SnapshotIterator& iter) const override;
786 };
787
788 class RNearbyInt final : public RInstruction {
789 private:
790 uint8_t roundingMode_;
791
792 public:
793 RINSTRUCTION_HEADER_NUM_OP_(NearbyInt, 1)
794
795 [[nodiscard]] bool recover(JSContext* cx,
796 SnapshotIterator& iter) const override;
797 };
798
799 class RSign final : public RInstruction {
800 public:
801 RINSTRUCTION_HEADER_NUM_OP_(Sign, 1)
802
803 [[nodiscard]] bool recover(JSContext* cx,
804 SnapshotIterator& iter) const override;
805 };
806
807 class RMathFunction final : public RInstruction {
808 private:
809 UnaryMathFunction function_;
810
811 public:
812 RINSTRUCTION_HEADER_NUM_OP_(MathFunction, 1)
813
814 [[nodiscard]] bool recover(JSContext* cx,
815 SnapshotIterator& iter) const override;
816 };
817
818 class RRandom final : public RInstruction {
819 RINSTRUCTION_HEADER_NUM_OP_(Random, 0)
820 public:
821 [[nodiscard]] bool recover(JSContext* cx,
822 SnapshotIterator& iter) const override;
823 };
824
825 class RStringSplit final : public RInstruction {
826 public:
827 RINSTRUCTION_HEADER_NUM_OP_(StringSplit, 2)
828
829 [[nodiscard]] bool recover(JSContext* cx,
830 SnapshotIterator& iter) const override;
831 };
832
833 class RNaNToZero final : public RInstruction {
834 public:
835 RINSTRUCTION_HEADER_NUM_OP_(NaNToZero, 1);
836
837 bool recover(JSContext* cx, SnapshotIterator& iter) const override;
838 };
839
840 class RStringReplace final : public RInstruction {
841 private:
842 bool isFlatReplacement_;
843
844 public:
845 RINSTRUCTION_HEADER_NUM_OP_(StringReplace, 3)
846
847 [[nodiscard]] bool recover(JSContext* cx,
848 SnapshotIterator& iter) const override;
849 };
850
851 class RSubstr final : public RInstruction {
852 public:
853 RINSTRUCTION_HEADER_NUM_OP_(Substr, 3)
854
855 [[nodiscard]] bool recover(JSContext* cx,
856 SnapshotIterator& iter) const override;
857 };
858
859 class RTypeOf final : public RInstruction {
860 public:
861 RINSTRUCTION_HEADER_NUM_OP_(TypeOf, 1)
862
863 [[nodiscard]] bool recover(JSContext* cx,
864 SnapshotIterator& iter) const override;
865 };
866
867 class RTypeOfName final : public RInstruction {
868 public:
869 RINSTRUCTION_HEADER_NUM_OP_(TypeOfName, 1)
870
871 [[nodiscard]] bool recover(JSContext* cx,
872 SnapshotIterator& iter) const override;
873 };
874
875 class RToDouble final : public RInstruction {
876 public:
877 RINSTRUCTION_HEADER_NUM_OP_(ToDouble, 1)
878
879 [[nodiscard]] bool recover(JSContext* cx,
880 SnapshotIterator& iter) const override;
881 };
882
883 class RToFloat32 final : public RInstruction {
884 public:
885 RINSTRUCTION_HEADER_NUM_OP_(ToFloat32, 1)
886
887 [[nodiscard]] bool recover(JSContext* cx,
888 SnapshotIterator& iter) const override;
889 };
890
891 class RToFloat16 final : public RInstruction {
892 public:
893 RINSTRUCTION_HEADER_NUM_OP_(ToFloat16, 1)
894
895 [[nodiscard]] bool recover(JSContext* cx,
896 SnapshotIterator& iter) const override;
897 };
898
899 class RTruncateToInt32 final : public RInstruction {
900 public:
901 RINSTRUCTION_HEADER_NUM_OP_(TruncateToInt32, 1)
902
903 [[nodiscard]] bool recover(JSContext* cx,
904 SnapshotIterator& iter) const override;
905 };
906
907 class RNewObject final : public RInstruction {
908 public:
909 RINSTRUCTION_HEADER_NUM_OP_(NewObject, 1)
910
911 [[nodiscard]] bool recover(JSContext* cx,
912 SnapshotIterator& iter) const override;
913 };
914
915 class RNewPlainObject final : public RInstruction {
916 private:
917 gc::AllocKind allocKind_;
918 gc::Heap initialHeap_;
919
920 public:
921 RINSTRUCTION_HEADER_NUM_OP_(NewPlainObject, 1)
922
923 [[nodiscard]] bool recover(JSContext* cx,
924 SnapshotIterator& iter) const override;
925 };
926
927 class RNewArrayObject final : public RInstruction {
928 private:
929 uint32_t length_;
930 gc::Heap initialHeap_;
931
932 public:
933 RINSTRUCTION_HEADER_NUM_OP_(NewArrayObject, 1)
934
935 [[nodiscard]] bool recover(JSContext* cx,
936 SnapshotIterator& iter) const override;
937 };
938
939 class RNewTypedArray final : public RInstruction {
940 public:
941 RINSTRUCTION_HEADER_NUM_OP_(NewTypedArray, 1)
942
943 [[nodiscard]] bool recover(JSContext* cx,
944 SnapshotIterator& iter) const override;
945 };
946
947 class RNewArray final : public RInstruction {
948 private:
949 uint32_t count_;
950
951 public:
952 RINSTRUCTION_HEADER_NUM_OP_(NewArray, 1)
953
954 [[nodiscard]] bool recover(JSContext* cx,
955 SnapshotIterator& iter) const override;
956 };
957
958 class RNewIterator final : public RInstruction {
959 private:
960 uint8_t type_;
961
962 public:
963 RINSTRUCTION_HEADER_NUM_OP_(NewIterator, 1)
964
965 [[nodiscard]] bool recover(JSContext* cx,
966 SnapshotIterator& iter) const override;
967 };
968
969 class RLambda final : public RInstruction {
970 public:
971 RINSTRUCTION_HEADER_NUM_OP_(Lambda, 2)
972
973 [[nodiscard]] bool recover(JSContext* cx,
974 SnapshotIterator& iter) const override;
975 };
976
977 class RFunctionWithProto final : public RInstruction {
978 public:
979 RINSTRUCTION_HEADER_NUM_OP_(FunctionWithProto, 3)
980
981 [[nodiscard]] bool recover(JSContext* cx,
982 SnapshotIterator& iter) const override;
983 };
984
985 class RNewCallObject final : public RInstruction {
986 public:
987 RINSTRUCTION_HEADER_NUM_OP_(NewCallObject, 1)
988
989 [[nodiscard]] bool recover(JSContext* cx,
990 SnapshotIterator& iter) const override;
991 };
992
993 class RObjectKeys final : public RInstruction {
994 public:
995 RINSTRUCTION_HEADER_NUM_OP_(ObjectKeys, 1)
996
997 [[nodiscard]] bool recover(JSContext* cx,
998 SnapshotIterator& iter) const override;
999 };
1000
1001 class RObjectState final : public RInstruction {
1002 private:
1003 uint32_t numSlots_; // Number of slots.
1004
1005 public:
1006 RINSTRUCTION_HEADER_(ObjectState)
1007
1008 uint32_t numSlots() const { return numSlots_; }
1009 uint32_t numOperands() const override {
1010 // +1 for the object.
1011 return numSlots() + 1;
1012 }
1013
1014 [[nodiscard]] bool recover(JSContext* cx,
1015 SnapshotIterator& iter) const override;
1016 };
1017
1018 class RArrayState final : public RInstruction {
1019 private:
1020 uint32_t numElements_;
1021
1022 public:
1023 RINSTRUCTION_HEADER_(ArrayState)
1024
1025 uint32_t numElements() const { return numElements_; }
1026 uint32_t numOperands() const override {
1027 // +1 for the array.
1028 // +1 for the initalized length.
1029 return numElements() + 2;
1030 }
1031
1032 [[nodiscard]] bool recover(JSContext* cx,
1033 SnapshotIterator& iter) const override;
1034 };
1035
1036 class RAtomicIsLockFree final : public RInstruction {
1037 public:
1038 RINSTRUCTION_HEADER_NUM_OP_(AtomicIsLockFree, 1)
1039
1040 [[nodiscard]] bool recover(JSContext* cx,
1041 SnapshotIterator& iter) const override;
1042 };
1043
1044 class RInt64ToBigInt final : public RInstruction {
1045 bool isSigned_;
1046
1047 public:
1048 RINSTRUCTION_HEADER_NUM_OP_(Int64ToBigInt, 1)
1049
1050 [[nodiscard]] bool recover(JSContext* cx,
1051 SnapshotIterator& iter) const override;
1052 };
1053
1054 class RBigIntAsIntN final : public RInstruction {
1055 public:
1056 RINSTRUCTION_HEADER_NUM_OP_(BigIntAsIntN, 2)
1057
1058 [[nodiscard]] bool recover(JSContext* cx,
1059 SnapshotIterator& iter) const override;
1060 };
1061
1062 class RBigIntAsUintN final : public RInstruction {
1063 public:
1064 RINSTRUCTION_HEADER_NUM_OP_(BigIntAsUintN, 2)
1065
1066 [[nodiscard]] bool recover(JSContext* cx,
1067 SnapshotIterator& iter) const override;
1068 };
1069
1070 class RCreateArgumentsObject final : public RInstruction {
1071 public:
1072 RINSTRUCTION_HEADER_NUM_OP_(CreateArgumentsObject, 1)
1073
1074 [[nodiscard]] bool recover(JSContext* cx,
1075 SnapshotIterator& iter) const override;
1076 };
1077
1078 class RCreateInlinedArgumentsObject final : public RInstruction {
1079 private:
1080 uint32_t numActuals_;
1081
1082 public:
1083 RINSTRUCTION_HEADER_(CreateInlinedArgumentsObject)
1084
1085 uint32_t numActuals() const { return numActuals_; }
1086 uint32_t numOperands() const override {
1087 // +1 for the callObj.
1088 // +1 for the callee.
1089 return numActuals() + 2;
1090 }
1091
1092 [[nodiscard]] bool recover(JSContext* cx,
1093 SnapshotIterator& iter) const override;
1094 };
1095
1096 class RRest final : public RInstruction {
1097 uint32_t numFormals_;
1098
1099 public:
1100 RINSTRUCTION_HEADER_NUM_OP_(Rest, 1)
1101
1102 [[nodiscard]] bool recover(JSContext* cx,
1103 SnapshotIterator& iter) const override;
1104 };
1105
1106 class RAssertRecoveredOnBailout final : public RInstruction {
1107 public:
1108 RINSTRUCTION_HEADER_NUM_OP_(AssertRecoveredOnBailout, 1)
1109
1110 [[nodiscard]] bool recover(JSContext* cx,
1111 SnapshotIterator& iter) const override;
1112 };
1113
1114 #undef RINSTRUCTION_HEADER_
1115 #undef RINSTRUCTION_HEADER_NUM_OP_
1116 #undef RINSTRUCTION_HEADER_NUM_OP_MAIN
1117
1118 const RResumePoint* RInstruction::toResumePoint() const {
1119 MOZ_ASSERT(isResumePoint());
1120 return static_cast<const RResumePoint*>(this);
1121 }
1122
1123 } // namespace jit
1124 } // namespace js
1125
1126 #endif /* jit_Recover_h */