Debian Codegraph @

js/src/jit/WarpBuilder.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/WarpBuilder.h"
8
9 #include "mozilla/DebugOnly.h"
10
11 #include "jit/BaselineFrame.h"
12 #include "jit/CacheIR.h"
13 #include "jit/CompileInfo.h"
14 #include "jit/InlineScriptTree.h"
15 #include "jit/MIR-wasm.h"
16 #include "jit/MIR.h"
17 #include "jit/MIRGenerator.h"
18 #include "jit/MIRGraph.h"
19 #include "jit/WarpCacheIRTranspiler.h"
20 #include "jit/WarpSnapshot.h"
21 #include "js/friend/ErrorMessages.h" // JSMSG_BAD_CONST_ASSIGN
22 #include "vm/GeneratorObject.h"
23 #include "vm/Interpreter.h"
24 #include "vm/Opcodes.h"
25 #include "vm/TypeofEqOperand.h" // TypeofEqOperand
26 #ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT
27 # include "vm/UsingHint.h"
28 #endif
29
30 #include "gc/ObjectKind-inl.h"
31 #include "vm/BytecodeIterator-inl.h"
32 #include "vm/BytecodeLocation-inl.h"
33 #include "vm/JSObject-inl.h"
34
35 using namespace js;
36 using namespace js::jit;
37
38 // Used for building the outermost script.
39 WarpBuilder::WarpBuilder(WarpSnapshot& snapshot, MIRGenerator& mirGen,
40 WarpCompilation* warpCompilation)
41 : WarpBuilderShared(snapshot, mirGen, nullptr),
42 warpCompilation_(warpCompilation),
43 graph_(mirGen.graph()),
44 info_(mirGen.outerInfo()),
45 scriptSnapshot_(snapshot.rootScript()),
46 script_(snapshot.rootScript()->script()),
47 loopStack_(mirGen.alloc()) {
48 opSnapshotIter_ = scriptSnapshot_->opSnapshots().getFirst();
49 }
50
51 // Used for building inlined scripts.
52 WarpBuilder::WarpBuilder(WarpBuilder* caller, WarpScriptSnapshot* snapshot,
53 CompileInfo& compileInfo, CallInfo* inlineCallInfo,
54 MResumePoint* callerResumePoint)
55 : WarpBuilderShared(caller->snapshot(), caller->mirGen(), nullptr),
56 warpCompilation_(caller->warpCompilation()),
57 graph_(caller->mirGen().graph()),
58 info_(compileInfo),
59 scriptSnapshot_(snapshot),
60 script_(snapshot->script()),
61 loopStack_(caller->mirGen().alloc()),
62 callerBuilder_(caller),
63 callerResumePoint_(callerResumePoint),
64 inlineCallInfo_(inlineCallInfo) {
65 opSnapshotIter_ = snapshot->opSnapshots().getFirst();
66 }
67
68 BytecodeSite* WarpBuilder::newBytecodeSite(BytecodeLocation loc) {
69 jsbytecode* pc = loc.toRawBytecode();
70 MOZ_ASSERT(info().inlineScriptTree()->script()->containsPC(pc));
71 return new (alloc()) BytecodeSite(info().inlineScriptTree(), pc);
72 }
73
74 const WarpOpSnapshot* WarpBuilder::getOpSnapshotImpl(
75 BytecodeLocation loc, WarpOpSnapshot::Kind kind) {
76 uint32_t offset = loc.bytecodeToOffset(script_);
77
78 // Skip snapshots until we get to a snapshot with offset >= offset. This is
79 // a loop because WarpBuilder can skip unreachable bytecode ops.
80 while (opSnapshotIter_ && opSnapshotIter_->offset() < offset) {
81 opSnapshotIter_ = opSnapshotIter_->getNext();
82 }
83
84 if (!opSnapshotIter_ || opSnapshotIter_->offset() != offset ||
85 opSnapshotIter_->kind() != kind) {
86 return nullptr;
87 }
88
89 return opSnapshotIter_;
90 }
91
92 void WarpBuilder::initBlock(MBasicBlock* block) {
93 graph().addBlock(block);
94
95 block->setLoopDepth(loopDepth());
96
97 current = block;
98 }
99
100 bool WarpBuilder::startNewBlock(MBasicBlock* predecessor, BytecodeLocation loc,
101 size_t numToPop) {
102 MBasicBlock* block =
103 MBasicBlock::NewPopN(graph(), info(), predecessor, newBytecodeSite(loc),
104 MBasicBlock::NORMAL, numToPop);
105 if (!block) {
106 return false;
107 }
108
109 initBlock(block);
110 return true;
111 }
112
113 bool WarpBuilder::startNewEntryBlock(size_t stackDepth, BytecodeLocation loc) {
114 MBasicBlock* block =
115 MBasicBlock::New(graph(), stackDepth, info(), /* maybePred = */ nullptr,
116 newBytecodeSite(loc), MBasicBlock::NORMAL);
117 if (!block) {
118 return false;
119 }
120
121 initBlock(block);
122 return true;
123 }
124
125 bool WarpBuilder::startNewLoopHeaderBlock(BytecodeLocation loopHead) {
126 MBasicBlock* header = MBasicBlock::NewPendingLoopHeader(
127 graph(), info(), current, newBytecodeSite(loopHead));
128 if (!header) {
129 return false;
130 }
131
132 initBlock(header);
133 return loopStack_.emplaceBack(header);
134 }
135
136 bool WarpBuilder::startNewOsrPreHeaderBlock(BytecodeLocation loopHead) {
137 MOZ_ASSERT(loopHead.is(JSOp::LoopHead));
138 MOZ_ASSERT(loopHead.toRawBytecode() == info().osrPc());
139
140 // Create two blocks:
141 // * The OSR entry block. This is always the graph's second block and has no
142 // predecessors. This is the entry point for OSR from the Baseline JIT.
143 // * The OSR preheader block. This has two predecessors: the OSR entry block
144 // and the current block.
145
146 MBasicBlock* pred = current;
147
148 // Create the OSR entry block.
149 if (!startNewEntryBlock(pred->stackDepth(), loopHead)) {
150 return false;
151 }
152
153 MBasicBlock* osrBlock = current;
154 graph().setOsrBlock(osrBlock);
155 graph().moveBlockAfter(*graph().begin(), osrBlock);
156
157 MOsrEntry* entry = MOsrEntry::New(alloc());
158 osrBlock->add(entry);
159
160 // Initialize environment chain.
161 {
162 uint32_t slot = info().environmentChainSlot();
163 MInstruction* envv;
164 if (usesEnvironmentChain()) {
165 envv = MOsrEnvironmentChain::New(alloc(), entry);
166 } else {
167 // Use an undefined value if the script does not need its environment
168 // chain, to match the main entry point.
169 envv = MConstant::New(alloc(), UndefinedValue());
170 }
171 osrBlock->add(envv);
172 osrBlock->initSlot(slot, envv);
173 }
174
175 // Initialize return value.
176 {
177 MInstruction* returnValue;
178 if (!script_->noScriptRval()) {
179 returnValue = MOsrReturnValue::New(alloc(), entry);
180 } else {
181 returnValue = MConstant::New(alloc(), UndefinedValue());
182 }
183 osrBlock->add(returnValue);
184 osrBlock->initSlot(info().returnValueSlot(), returnValue);
185 }
186
187 // Initialize arguments object.
188 MInstruction* argsObj = nullptr;
189 if (info().needsArgsObj()) {
190 argsObj = MOsrArgumentsObject::New(alloc(), entry);
191 osrBlock->add(argsObj);
192 osrBlock->initSlot(info().argsObjSlot(), argsObj);
193 }
194
195 if (info().hasFunMaybeLazy()) {
196 // Initialize |this| parameter.
197 MParameter* thisv = MParameter::New(alloc(), MParameter::THIS_SLOT);
198 osrBlock->add(thisv);
199 osrBlock->initSlot(info().thisSlot(), thisv);
200
201 // Initialize arguments. There are three cases:
202 //
203 // 1) There's no ArgumentsObject or it doesn't alias formals. In this case
204 // we can just use the frame's argument slot.
205 // 2) The ArgumentsObject aliases formals and the argument is stored in the
206 // CallObject. Use |undefined| because we can't load from the arguments
207 // object and code will use the CallObject anyway.
208 // 3) The ArgumentsObject aliases formals and the argument isn't stored in
209 // the CallObject. We have to load it from the ArgumentsObject.
210 for (uint32_t i = 0; i < info().nargs(); i++) {
211 uint32_t slot = info().argSlotUnchecked(i);
212 MInstruction* osrv;
213 if (!info().argsObjAliasesFormals()) {
214 osrv = MParameter::New(alloc().fallible(), i);
215 } else if (script_->formalIsAliased(i)) {
216 osrv = MConstant::New(alloc().fallible(), UndefinedValue());
217 } else {
218 osrv = MGetArgumentsObjectArg::New(alloc().fallible(), argsObj, i);
219 }
220 if (!osrv) {
221 return false;
222 }
223 current->add(osrv);
224 current->initSlot(slot, osrv);
225 }
226 }
227
228 // Initialize locals.
229 uint32_t nlocals = info().nlocals();
230 for (uint32_t i = 0; i < nlocals; i++) {
231 uint32_t slot = info().localSlot(i);
232 ptrdiff_t offset = BaselineFrame::reverseOffsetOfLocal(i);
233 MOsrValue* osrv = MOsrValue::New(alloc().fallible(), entry, offset);
234 if (!osrv) {
235 return false;
236 }
237 current->add(osrv);
238 current->initSlot(slot, osrv);
239 }
240
241 // Initialize expression stack slots.
242 uint32_t numStackSlots = current->stackDepth() - info().firstStackSlot();
243 for (uint32_t i = 0; i < numStackSlots; i++) {
244 uint32_t slot = info().stackSlot(i);
245 ptrdiff_t offset = BaselineFrame::reverseOffsetOfLocal(nlocals + i);
246 MOsrValue* osrv = MOsrValue::New(alloc().fallible(), entry, offset);
247 if (!osrv) {
248 return false;
249 }
250 current->add(osrv);
251 current->initSlot(slot, osrv);
252 }
253
254 MStart* start = MStart::New(alloc());
255 current->add(start);
256
257 // Note: phi specialization can add type guard instructions to the OSR entry
258 // block if needed. See TypeAnalyzer::shouldSpecializeOsrPhis.
259
260 // Create the preheader block, with the predecessor block and OSR block as
261 // predecessors.
262 if (!startNewBlock(pred, loopHead)) {
263 return false;
264 }
265
266 pred->end(MGoto::New(alloc(), current));
267 osrBlock->end(MGoto::New(alloc(), current));
268
269 if (!current->addPredecessor(alloc(), osrBlock)) {
270 return false;
271 }
272
273 return true;
274 }
275
276 bool WarpBuilder::addPendingEdge(BytecodeLocation target, MBasicBlock* block,
277 uint32_t successor, uint32_t numToPop) {
278 MOZ_ASSERT(successor < block->lastIns()->numSuccessors());
279 MOZ_ASSERT(numToPop <= block->stackDepth());
280
281 jsbytecode* targetPC = target.toRawBytecode();
282 PendingEdgesMap::AddPtr p = pendingEdges_.lookupForAdd(targetPC);
283 if (p) {
284 return p->value().emplaceBack(block, successor, numToPop);
285 }
286
287 PendingEdges edges;
288 static_assert(PendingEdges::InlineLength >= 1,
289 "Appending one element should be infallible");
290 MOZ_ALWAYS_TRUE(edges.emplaceBack(block, successor, numToPop));
291
292 return pendingEdges_.add(p, targetPC, std::move(edges));
293 }
294
295 bool WarpBuilder::build() {
296 if (!buildPrologue()) {
297 return false;
298 }
299
300 if (!buildBody()) {
301 return false;
302 }
303
304 if (!MPhi::markIteratorPhis(*iterators())) {
305 return false;
306 }
307
308 MOZ_ASSERT_IF(info().osrPc(), graph().osrBlock());
309 MOZ_ASSERT(loopStack_.empty());
310 MOZ_ASSERT(loopDepth() == 0);
311
312 return true;
313 }
314
315 bool WarpBuilder::buildInline() {
316 if (!buildInlinePrologue()) {
317 return false;
318 }
319
320 if (!buildBody()) {
321 return false;
322 }
323
324 MOZ_ASSERT(loopStack_.empty());
325 return true;
326 }
327
328 MInstruction* WarpBuilder::buildNamedLambdaEnv(MDefinition* callee,
329 MDefinition* env,
330 NamedLambdaObject* templateObj,
331 gc::Heap initialHeap) {
332 MOZ_ASSERT(templateObj->numDynamicSlots() == 0);
333
334 MInstruction* namedLambda =
335 MNewNamedLambdaObject::New(alloc(), templateObj, initialHeap);
336 current->add(namedLambda);
337
338 // Initialize the object's reserved slots.
339 if (initialHeap == gc::Heap::Default) {
340 // No post barrier is needed here: the object will be allocated in the
341 // nursery if possible, and if the tenured heap is used instead, a minor
342 // collection will have been performed that moved env/callee to the tenured
343 // heap.
344 #ifdef DEBUG
345 current->add(
346 MAssertCanElidePostWriteBarrier::New(alloc(), namedLambda, env));
347 current->add(
348 MAssertCanElidePostWriteBarrier::New(alloc(), namedLambda, callee));
349 #endif
350 } else {
351 current->add(MPostWriteBarrier::New(alloc(), namedLambda, env));
352 current->add(MPostWriteBarrier::New(alloc(), namedLambda, callee));
353 }
354
355 size_t enclosingSlot = NamedLambdaObject::enclosingEnvironmentSlot();
356 size_t lambdaSlot = NamedLambdaObject::lambdaSlot();
357 current->add(MStoreFixedSlot::NewUnbarriered(alloc(), namedLambda,
358 enclosingSlot, env));
359 current->add(MStoreFixedSlot::NewUnbarriered(alloc(), namedLambda, lambdaSlot,
360 callee));
361
362 return namedLambda;
363 }
364
365 MInstruction* WarpBuilder::buildCallObject(MDefinition* callee,
366 MDefinition* env,
367 CallObject* templateObj,
368 gc::Heap initialHeap) {
369 MConstant* templateCst = constant(ObjectValue(*templateObj));
370
371 MNewCallObject* callObj =
372 MNewCallObject::New(alloc(), templateCst, initialHeap);
373 current->add(callObj);
374
375 // Initialize the object's reserved slots.
376 if (initialHeap == gc::Heap::Default) {
377 // No post barrier is needed here, for the same reason as in
378 // buildNamedLambdaEnv.
379 #ifdef DEBUG
380 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), callObj, env));
381 current->add(
382 MAssertCanElidePostWriteBarrier::New(alloc(), callObj, callee));
383 #endif
384 } else {
385 current->add(MPostWriteBarrier::New(alloc(), callObj, env));
386 current->add(MPostWriteBarrier::New(alloc(), callObj, callee));
387 }
388
389 size_t enclosingSlot = CallObject::enclosingEnvironmentSlot();
390 size_t calleeSlot = CallObject::calleeSlot();
391 current->add(
392 MStoreFixedSlot::NewUnbarriered(alloc(), callObj, enclosingSlot, env));
393 current->add(
394 MStoreFixedSlot::NewUnbarriered(alloc(), callObj, calleeSlot, callee));
395
396 return callObj;
397 }
398
399 bool WarpBuilder::buildEnvironmentChain() {
400 const WarpEnvironment& env = scriptSnapshot()->environment();
401
402 if (env.is<NoEnvironment>()) {
403 return true;
404 }
405
406 MInstruction* envDef = env.match(
407 [](const NoEnvironment&) -> MInstruction* {
408 MOZ_CRASH("Already handled");
409 },
410 [this](JSObject* obj) -> MInstruction* {
411 return constant(ObjectValue(*obj));
412 },
413 [this](const FunctionEnvironment& env) -> MInstruction* {
414 MDefinition* callee = getCallee();
415 MInstruction* envDef = MFunctionEnvironment::New(alloc(), callee);
416 current->add(envDef);
417 if (NamedLambdaObject* obj = env.namedLambdaTemplate) {
418 envDef = buildNamedLambdaEnv(callee, envDef, obj, env.initialHeap);
419 }
420 if (CallObject* obj = env.callObjectTemplate) {
421 envDef = buildCallObject(callee, envDef, obj, env.initialHeap);
422 if (!envDef) {
423 return nullptr;
424 }
425 }
426 return envDef;
427 });
428 if (!envDef) {
429 return false;
430 }
431
432 // Update the environment slot from UndefinedValue only after the initial
433 // environment is created so that bailout doesn't see a partial environment.
434 // See: |BaselineStackBuilder::buildBaselineFrame|
435 current->setEnvironmentChain(envDef);
436 return true;
437 }
438
439 bool WarpBuilder::buildPrologue() {
440 BytecodeLocation startLoc(script_, script_->code());
441 if (!startNewEntryBlock(info().firstStackSlot(), startLoc)) {
442 return false;
443 }
444
445 if (info().hasFunMaybeLazy()) {
446 // Initialize |this|.
447 MParameter* param = MParameter::New(alloc(), MParameter::THIS_SLOT);
448 current->add(param);
449 current->initSlot(info().thisSlot(), param);
450
451 // Initialize arguments.
452 for (uint32_t i = 0; i < info().nargs(); i++) {
453 MParameter* param = MParameter::New(alloc().fallible(), i);
454 if (!param) {
455 return false;
456 }
457 current->add(param);
458 current->initSlot(info().argSlotUnchecked(i), param);
459 }
460 }
461
462 MConstant* undef = constant(UndefinedValue());
463
464 // Initialize local slots.
465 for (uint32_t i = 0; i < info().nlocals(); i++) {
466 current->initSlot(info().localSlot(i), undef);
467 }
468
469 // Initialize the environment chain, return value, and arguments object slots.
470 current->initSlot(info().environmentChainSlot(), undef);
471 current->initSlot(info().returnValueSlot(), undef);
472 if (info().needsArgsObj()) {
473 current->initSlot(info().argsObjSlot(), undef);
474 }
475
476 current->add(MStart::New(alloc()));
477
478 // Guard against over-recursion.
479 MCheckOverRecursed* check = MCheckOverRecursed::New(alloc());
480 current->add(check);
481
482 if (!buildEnvironmentChain()) {
483 return false;
484 }
485
486 #ifdef JS_CACHEIR_SPEW
487 if (snapshot().needsFinalWarmUpCount()) {
488 MIncrementWarmUpCounter* ins =
489 MIncrementWarmUpCounter::New(alloc(), script_);
490 current->add(ins);
491 }
492 #endif
493
494 return true;
495 }
496
497 bool WarpBuilder::buildInlinePrologue() {
498 // Generate entry block.
499 BytecodeLocation startLoc(script_, script_->code());
500 if (!startNewEntryBlock(info().firstStackSlot(), startLoc)) {
501 return false;
502 }
503 current->setCallerResumePoint(callerResumePoint());
504
505 // Connect the entry block to the last block in the caller's graph.
506 MBasicBlock* pred = callerBuilder()->current;
507 MOZ_ASSERT(pred == callerResumePoint()->block());
508
509 pred->end(MGoto::New(alloc(), current));
510 if (!current->addPredecessorWithoutPhis(pred)) {
511 return false;
512 }
513
514 MConstant* undef = constant(UndefinedValue());
515
516 // Initialize env chain slot to Undefined. It's set later by
517 // |buildEnvironmentChain|.
518 current->initSlot(info().environmentChainSlot(), undef);
519
520 // Initialize |return value| slot.
521 current->initSlot(info().returnValueSlot(), undef);
522
523 // Initialize |arguments| slot if needed.
524 if (info().needsArgsObj()) {
525 current->initSlot(info().argsObjSlot(), undef);
526 }
527
528 // Initialize |this| slot.
529 current->initSlot(info().thisSlot(), inlineCallInfo()->thisArg());
530
531 uint32_t callerArgs = inlineCallInfo()->argc();
532 uint32_t actualArgs = info().nargs();
533 uint32_t passedArgs = std::min<uint32_t>(callerArgs, actualArgs);
534
535 // Initialize actually set arguments.
536 for (uint32_t i = 0; i < passedArgs; i++) {
537 MDefinition* arg = inlineCallInfo()->getArg(i);
538 current->initSlot(info().argSlotUnchecked(i), arg);
539 }
540
541 // Pass undefined for missing arguments.
542 for (uint32_t i = passedArgs; i < actualArgs; i++) {
543 current->initSlot(info().argSlotUnchecked(i), undef);
544 }
545
546 // Initialize local slots.
547 for (uint32_t i = 0; i < info().nlocals(); i++) {
548 current->initSlot(info().localSlot(i), undef);
549 }
550
551 MOZ_ASSERT(current->entryResumePoint()->stackDepth() == info().totalSlots());
552
553 if (!buildEnvironmentChain()) {
554 return false;
555 }
556
557 return true;
558 }
559
560 #ifdef DEBUG
561 // In debug builds, after compiling a bytecode op, this class is used to check
562 // that all values popped by this opcode either:
563 //
564 // (1) Have the ImplicitlyUsed flag set on them.
565 // (2) Have more uses than before compiling this op (the value is
566 // used as operand of a new MIR instruction).
567 //
568 // This is used to catch problems where WarpBuilder pops a value without
569 // adding any SSA uses and doesn't call setImplicitlyUsedUnchecked on it.
570 class MOZ_RAII WarpPoppedValueUseChecker {
571 Vector<MDefinition*, 4, SystemAllocPolicy> popped_;
572 Vector<size_t, 4, SystemAllocPolicy> poppedUses_;
573 MBasicBlock* current_;
574 BytecodeLocation loc_;
575
576 public:
577 WarpPoppedValueUseChecker(MBasicBlock* current, BytecodeLocation loc)
578 : current_(current), loc_(loc) {}
579
580 [[nodiscard]] bool init() {
581 // Don't require SSA uses for values popped by these ops.
582 switch (loc_.getOp()) {
583 case JSOp::Pop:
584 case JSOp::PopN:
585 case JSOp::DupAt:
586 case JSOp::Dup:
587 case JSOp::Dup2:
588 case JSOp::Pick:
589 case JSOp::Unpick:
590 case JSOp::Swap:
591 case JSOp::SetArg:
592 case JSOp::SetLocal:
593 case JSOp::InitLexical:
594 case JSOp::SetRval:
595 case JSOp::Void:
596 // Basic stack/local/argument management opcodes.
597 return true;
598
599 case JSOp::Case:
600 case JSOp::Default:
601 // These ops have to pop the switch value when branching but don't
602 // actually use it.
603 return true;
604
605 default:
606 break;
607 }
608
609 unsigned nuses = loc_.useCount();
610
611 for (unsigned i = 0; i < nuses; i++) {
612 MDefinition* def = current_->peek(-int32_t(i + 1));
613 if (!popped_.append(def) || !poppedUses_.append(def->defUseCount())) {
614 return false;
615 }
616 }
617
618 return true;
619 }
620
621 void checkAfterOp() {
622 for (size_t i = 0; i < popped_.length(); i++) {
623 // First value popped by JSOp::EndIter is not used at all, it's similar
624 // to JSOp::Pop above.
625 if (loc_.is(JSOp::EndIter) && i == 0) {
626 continue;
627 }
628 MOZ_ASSERT(popped_[i]->isImplicitlyUsed() ||
629 popped_[i]->defUseCount() > poppedUses_[i]);
630 }
631 }
632 };
633 #endif
634
635 bool WarpBuilder::buildBody() {
636 for (BytecodeLocation loc : AllBytecodesIterable(script_)) {
637 if (mirGen().shouldCancel("WarpBuilder (opcode loop)")) {
638 return false;
639 }
640
641 // Skip unreachable ops (for example code after a 'return' or 'throw') until
642 // we get to the next jump target.
643 if (hasTerminatedBlock()) {
644 // Finish any "broken" loops with an unreachable backedge. For example:
645 //
646 // do {
647 // ...
648 // return;
649 // ...
650 // } while (x);
651 //
652 // This loop never actually loops.
653 if (loc.isBackedge() && !loopStack_.empty()) {
654 BytecodeLocation loopHead(script_,
655 loopStack_.back().header()->entryPC());
656 if (loc.isBackedgeForLoophead(loopHead)) {
657 decLoopDepth();
658 loopStack_.popBack();
659 }
660 }
661 if (!loc.isJumpTarget()) {
662 continue;
663 }
664 }
665
666 if (!alloc().ensureBallast()) {
667 return false;
668 }
669
670 #ifdef DEBUG
671 WarpPoppedValueUseChecker useChecker(current, loc);
672 if (!useChecker.init()) {
673 return false;
674 }
675 #endif
676 bool wantPreciseLineNumbers = js::jit::PerfEnabled();
677 if (wantPreciseLineNumbers && !hasTerminatedBlock()) {
678 current->updateTrackedSite(newBytecodeSite(loc));
679 }
680
681 JSOp op = loc.getOp();
682
683 #define BUILD_OP(OP, ...) \
684 case JSOp::OP: \
685 if (MOZ_UNLIKELY(!this->build_##OP(loc))) { \
686 return false; \
687 } \
688 break;
689 switch (op) { FOR_EACH_OPCODE(BUILD_OP) }
690 #undef BUILD_OP
691
692 #ifdef DEBUG
693 useChecker.checkAfterOp();
694 #endif
695 }
696
697 return true;
698 }
699
700 #define DEF_OP(OP) \
701 bool WarpBuilder::build_##OP(BytecodeLocation) { \
702 MOZ_CRASH("Unsupported op"); \
703 }
704 WARP_UNSUPPORTED_OPCODE_LIST(DEF_OP)
705 #undef DEF_OP
706
707 bool WarpBuilder::build_Nop(BytecodeLocation) { return true; }
708
709 bool WarpBuilder::build_NopDestructuring(BytecodeLocation) { return true; }
710
711 bool WarpBuilder::build_NopIsAssignOp(BytecodeLocation) { return true; }
712
713 bool WarpBuilder::build_TryDestructuring(BytecodeLocation) {
714 // Set the hasTryBlock flag to turn off optimizations that eliminate dead
715 // resume points operands because the exception handler code for
716 // TryNoteKind::Destructuring is effectively a (specialized) catch-block.
717 graph().setHasTryBlock();
718 return true;
719 }
720
721 bool WarpBuilder::build_Lineno(BytecodeLocation) { return true; }
722
723 bool WarpBuilder::build_DebugLeaveLexicalEnv(BytecodeLocation) { return true; }
724
725 bool WarpBuilder::build_Undefined(BytecodeLocation) {
726 pushConstant(UndefinedValue());
727 return true;
728 }
729
730 bool WarpBuilder::build_Void(BytecodeLocation) {
731 current->pop();
732 pushConstant(UndefinedValue());
733 return true;
734 }
735
736 bool WarpBuilder::build_Null(BytecodeLocation) {
737 pushConstant(NullValue());
738 return true;
739 }
740
741 bool WarpBuilder::build_Hole(BytecodeLocation) {
742 pushConstant(MagicValue(JS_ELEMENTS_HOLE));
743 return true;
744 }
745
746 bool WarpBuilder::build_Uninitialized(BytecodeLocation) {
747 pushConstant(MagicValue(JS_UNINITIALIZED_LEXICAL));
748 return true;
749 }
750
751 bool WarpBuilder::build_IsConstructing(BytecodeLocation) {
752 pushConstant(MagicValue(JS_IS_CONSTRUCTING));
753 return true;
754 }
755
756 bool WarpBuilder::build_False(BytecodeLocation) {
757 pushConstant(BooleanValue(false));
758 return true;
759 }
760
761 bool WarpBuilder::build_True(BytecodeLocation) {
762 pushConstant(BooleanValue(true));
763 return true;
764 }
765
766 bool WarpBuilder::build_Pop(BytecodeLocation) {
767 current->pop();
768 return true;
769 }
770
771 bool WarpBuilder::build_PopN(BytecodeLocation loc) {
772 for (uint32_t i = 0, n = loc.getPopCount(); i < n; i++) {
773 current->pop();
774 }
775 return true;
776 }
777
778 bool WarpBuilder::build_Dup(BytecodeLocation) {
779 current->pushSlot(current->stackDepth() - 1);
780 return true;
781 }
782
783 bool WarpBuilder::build_Dup2(BytecodeLocation) {
784 uint32_t lhsSlot = current->stackDepth() - 2;
785 uint32_t rhsSlot = current->stackDepth() - 1;
786 current->pushSlot(lhsSlot);
787 current->pushSlot(rhsSlot);
788 return true;
789 }
790
791 bool WarpBuilder::build_DupAt(BytecodeLocation loc) {
792 current->pushSlot(current->stackDepth() - 1 - loc.getDupAtIndex());
793 return true;
794 }
795
796 bool WarpBuilder::build_Swap(BytecodeLocation) {
797 current->swapAt(-1);
798 return true;
799 }
800
801 bool WarpBuilder::build_Pick(BytecodeLocation loc) {
802 int32_t depth = -int32_t(loc.getPickDepth());
803 current->pick(depth);
804 return true;
805 }
806
807 bool WarpBuilder::build_Unpick(BytecodeLocation loc) {
808 int32_t depth = -int32_t(loc.getUnpickDepth());
809 current->unpick(depth);
810 return true;
811 }
812
813 bool WarpBuilder::build_Zero(BytecodeLocation) {
814 pushConstant(Int32Value(0));
815 return true;
816 }
817
818 bool WarpBuilder::build_One(BytecodeLocation) {
819 pushConstant(Int32Value(1));
820 return true;
821 }
822
823 bool WarpBuilder::build_Int8(BytecodeLocation loc) {
824 pushConstant(Int32Value(loc.getInt8()));
825 return true;
826 }
827
828 bool WarpBuilder::build_Uint16(BytecodeLocation loc) {
829 pushConstant(Int32Value(loc.getUint16()));
830 return true;
831 }
832
833 bool WarpBuilder::build_Uint24(BytecodeLocation loc) {
834 pushConstant(Int32Value(loc.getUint24()));
835 return true;
836 }
837
838 bool WarpBuilder::build_Int32(BytecodeLocation loc) {
839 pushConstant(Int32Value(loc.getInt32()));
840 return true;
841 }
842
843 bool WarpBuilder::build_Double(BytecodeLocation loc) {
844 pushConstant(loc.getInlineValue());
845 return true;
846 }
847
848 bool WarpBuilder::build_BigInt(BytecodeLocation loc) {
849 BigInt* bi = loc.getBigInt(script_);
850 pushConstant(BigIntValue(bi));
851 return true;
852 }
853
854 bool WarpBuilder::build_String(BytecodeLocation loc) {
855 JSString* str = loc.getString(script_);
856 pushConstant(StringValue(str));
857 return true;
858 }
859
860 bool WarpBuilder::build_Symbol(BytecodeLocation loc) {
861 uint32_t which = loc.getSymbolIndex();
862 JS::Symbol* sym = mirGen().runtime->wellKnownSymbols().get(which);
863 pushConstant(SymbolValue(sym));
864 return true;
865 }
866
867 bool WarpBuilder::build_RegExp(BytecodeLocation loc) {
868 RegExpObject* reObj = loc.getRegExp(script_);
869
870 auto* snapshot = getOpSnapshot<WarpRegExp>(loc);
871
872 MRegExp* regexp = MRegExp::New(alloc(), reObj, snapshot->hasShared());
873 current->add(regexp);
874 current->push(regexp);
875
876 return true;
877 }
878
879 bool WarpBuilder::build_Return(BytecodeLocation) {
880 MDefinition* def = current->pop();
881
882 MReturn* ret = MReturn::New(alloc(), def);
883 current->end(ret);
884
885 if (!graph().addReturn(current)) {
886 return false;
887 }
888
889 setTerminatedBlock();
890 return true;
891 }
892
893 bool WarpBuilder::build_RetRval(BytecodeLocation) {
894 MDefinition* rval;
895 if (script_->noScriptRval()) {
896 rval = constant(UndefinedValue());
897 } else {
898 rval = current->getSlot(info().returnValueSlot());
899 }
900
901 MReturn* ret = MReturn::New(alloc(), rval);
902 current->end(ret);
903
904 if (!graph().addReturn(current)) {
905 return false;
906 }
907
908 setTerminatedBlock();
909 return true;
910 }
911
912 bool WarpBuilder::build_SetRval(BytecodeLocation) {
913 MOZ_ASSERT(!script_->noScriptRval());
914 MDefinition* rval = current->pop();
915 current->setSlot(info().returnValueSlot(), rval);
916 return true;
917 }
918
919 bool WarpBuilder::build_GetRval(BytecodeLocation) {
920 MOZ_ASSERT(!script_->noScriptRval());
921 MDefinition* rval = current->getSlot(info().returnValueSlot());
922 current->push(rval);
923 return true;
924 }
925
926 bool WarpBuilder::build_GetLocal(BytecodeLocation loc) {
927 current->pushLocal(loc.local());
928 return true;
929 }
930
931 bool WarpBuilder::build_SetLocal(BytecodeLocation loc) {
932 current->setLocal(loc.local());
933 return true;
934 }
935
936 bool WarpBuilder::build_InitLexical(BytecodeLocation loc) {
937 current->setLocal(loc.local());
938 return true;
939 }
940
941 bool WarpBuilder::build_GetArg(BytecodeLocation loc) {
942 uint32_t arg = loc.arg();
943 if (info().argsObjAliasesFormals()) {
944 MDefinition* argsObj = current->argumentsObject();
945 auto* getArg = MGetArgumentsObjectArg::New(alloc(), argsObj, arg);
946 current->add(getArg);
947 current->push(getArg);
948 } else {
949 current->pushArg(arg);
950 }
951 return true;
952 }
953
954 bool WarpBuilder::build_GetFrameArg(BytecodeLocation loc) {
955 current->pushArgUnchecked(loc.arg());
956 return true;
957 }
958
959 bool WarpBuilder::build_SetArg(BytecodeLocation loc) {
960 uint32_t arg = loc.arg();
961 MDefinition* val = current->peek(-1);
962
963 if (!info().argsObjAliasesFormals()) {
964 // Either |arguments| is never referenced within this function, or
965 // it doesn't map to the actual arguments values. Either way, we
966 // don't need to worry about synchronizing the argument values
967 // when writing to them.
968 current->setArg(arg);
969 return true;
970 }
971
972 // If an arguments object is in use, and it aliases formals, then all SetArgs
973 // must go through the arguments object.
974 MDefinition* argsObj = current->argumentsObject();
975 current->add(MPostWriteBarrier::New(alloc(), argsObj, val));
976 auto* ins = MSetArgumentsObjectArg::New(alloc(), argsObj, val, arg);
977 current->add(ins);
978 return resumeAfter(ins, loc);
979 }
980
981 bool WarpBuilder::build_ArgumentsLength(BytecodeLocation) {
982 if (inlineCallInfo()) {
983 pushConstant(Int32Value(inlineCallInfo()->argc()));
984 } else {
985 auto* argsLength = MArgumentsLength::New(alloc());
986 current->add(argsLength);
987 current->push(argsLength);
988 }
989 return true;
990 }
991
992 bool WarpBuilder::build_GetActualArg(BytecodeLocation) {
993 MDefinition* index = current->pop();
994 MInstruction* arg;
995 if (inlineCallInfo()) {
996 arg = MGetInlinedArgument::New(alloc(), index, *inlineCallInfo());
997 if (!arg) {
998 return false;
999 }
1000 } else {
1001 arg = MGetFrameArgument::New(alloc(), index);
1002 }
1003 current->add(arg);
1004 current->push(arg);
1005 return true;
1006 }
1007
1008 bool WarpBuilder::build_ToNumeric(BytecodeLocation loc) {
1009 return buildUnaryOp(loc);
1010 }
1011
1012 bool WarpBuilder::buildUnaryOp(BytecodeLocation loc) {
1013 MDefinition* value = current->pop();
1014 return buildIC(loc, CacheKind::UnaryArith, {value});
1015 }
1016
1017 bool WarpBuilder::build_Inc(BytecodeLocation loc) { return buildUnaryOp(loc); }
1018
1019 bool WarpBuilder::build_Dec(BytecodeLocation loc) { return buildUnaryOp(loc); }
1020
1021 bool WarpBuilder::build_Pos(BytecodeLocation loc) { return buildUnaryOp(loc); }
1022
1023 bool WarpBuilder::build_Neg(BytecodeLocation loc) { return buildUnaryOp(loc); }
1024
1025 bool WarpBuilder::build_BitNot(BytecodeLocation loc) {
1026 return buildUnaryOp(loc);
1027 }
1028
1029 bool WarpBuilder::buildBinaryOp(BytecodeLocation loc) {
1030 MDefinition* right = current->pop();
1031 MDefinition* left = current->pop();
1032 return buildIC(loc, CacheKind::BinaryArith, {left, right});
1033 }
1034
1035 bool WarpBuilder::build_Add(BytecodeLocation loc) { return buildBinaryOp(loc); }
1036
1037 bool WarpBuilder::build_Sub(BytecodeLocation loc) { return buildBinaryOp(loc); }
1038
1039 bool WarpBuilder::build_Mul(BytecodeLocation loc) { return buildBinaryOp(loc); }
1040
1041 bool WarpBuilder::build_Div(BytecodeLocation loc) { return buildBinaryOp(loc); }
1042
1043 bool WarpBuilder::build_Mod(BytecodeLocation loc) { return buildBinaryOp(loc); }
1044
1045 bool WarpBuilder::build_Pow(BytecodeLocation loc) { return buildBinaryOp(loc); }
1046
1047 bool WarpBuilder::build_BitAnd(BytecodeLocation loc) {
1048 return buildBinaryOp(loc);
1049 }
1050
1051 bool WarpBuilder::build_BitOr(BytecodeLocation loc) {
1052 return buildBinaryOp(loc);
1053 }
1054
1055 bool WarpBuilder::build_BitXor(BytecodeLocation loc) {
1056 return buildBinaryOp(loc);
1057 }
1058
1059 bool WarpBuilder::build_Lsh(BytecodeLocation loc) { return buildBinaryOp(loc); }
1060
1061 bool WarpBuilder::build_Rsh(BytecodeLocation loc) { return buildBinaryOp(loc); }
1062
1063 bool WarpBuilder::build_Ursh(BytecodeLocation loc) {
1064 return buildBinaryOp(loc);
1065 }
1066
1067 bool WarpBuilder::buildCompareOp(BytecodeLocation loc) {
1068 MDefinition* right = current->pop();
1069 MDefinition* left = current->pop();
1070 return buildIC(loc, CacheKind::Compare, {left, right});
1071 }
1072
1073 bool WarpBuilder::build_Eq(BytecodeLocation loc) { return buildCompareOp(loc); }
1074
1075 bool WarpBuilder::build_Ne(BytecodeLocation loc) { return buildCompareOp(loc); }
1076
1077 bool WarpBuilder::build_Lt(BytecodeLocation loc) { return buildCompareOp(loc); }
1078
1079 bool WarpBuilder::build_Le(BytecodeLocation loc) { return buildCompareOp(loc); }
1080
1081 bool WarpBuilder::build_Gt(BytecodeLocation loc) { return buildCompareOp(loc); }
1082
1083 bool WarpBuilder::build_Ge(BytecodeLocation loc) { return buildCompareOp(loc); }
1084
1085 bool WarpBuilder::build_StrictEq(BytecodeLocation loc) {
1086 return buildCompareOp(loc);
1087 }
1088
1089 bool WarpBuilder::build_StrictNe(BytecodeLocation loc) {
1090 return buildCompareOp(loc);
1091 }
1092
1093 bool WarpBuilder::buildStrictConstantEqOp(BytecodeLocation loc,
1094 JSOp compareOp) {
1095 auto operand = loc.getConstantCompareOperand();
1096 MDefinition* value = current->pop();
1097 switch (operand.type()) {
1098 case ConstantCompareOperand::EncodedType::Int32: {
1099 if (value->type() == MIRType::Int32) {
1100 MConstant* constant =
1101 MConstant::New(alloc(), Int32Value(operand.toInt32()));
1102 current->add(constant);
1103
1104 auto* compare = MCompare::New(alloc(), value, constant, compareOp,
1105 MCompare::Compare_Int32);
1106 current->add(compare);
1107 current->push(compare);
1108 return true;
1109 }
1110
1111 auto* ins = MStrictConstantCompareInt32::New(
1112 alloc(), value, operand.toInt32(), compareOp);
1113 current->add(ins);
1114 current->push(ins);
1115 return true;
1116 }
1117
1118 case ConstantCompareOperand::EncodedType::Boolean: {
1119 if (value->type() == MIRType::Boolean) {
1120 MConstant* constant =
1121 MConstant::New(alloc(), Int32Value(operand.toBoolean()));
1122 current->add(constant);
1123
1124 auto* toBoolToInt32 = MBooleanToInt32::New(alloc(), value);
1125 current->add(toBoolToInt32);
1126
1127 auto* compare = MCompare::New(alloc(), toBoolToInt32, constant,
1128 compareOp, MCompare::Compare_Int32);
1129 current->add(compare);
1130 current->push(compare);
1131 return true;
1132 }
1133
1134 auto* ins = MStrictConstantCompareBoolean::New(
1135 alloc(), value, operand.toBoolean(), compareOp);
1136 current->add(ins);
1137 current->push(ins);
1138 return true;
1139 }
1140
1141 case ConstantCompareOperand::EncodedType::Null: {
1142 MConstant* constant = MConstant::New(alloc(), NullValue());
1143 current->add(constant);
1144
1145 auto* ins = MCompare::New(alloc(), value, constant, compareOp,
1146 MCompare::Compare_Null);
1147 current->add(ins);
1148 current->push(ins);
1149 return true;
1150 }
1151
1152 case ConstantCompareOperand::EncodedType::Undefined: {
1153 MConstant* constant = MConstant::New(alloc(), UndefinedValue());
1154 current->add(constant);
1155
1156 auto* ins = MCompare::New(alloc(), value, constant, compareOp,
1157 MCompare::Compare_Undefined);
1158 current->add(ins);
1159 current->push(ins);
1160 return true;
1161 }
1162 }
1163 return true;
1164 }
1165
1166 bool WarpBuilder::build_StrictConstantEq(BytecodeLocation loc) {
1167 return buildStrictConstantEqOp(loc, JSOp::StrictEq);
1168 }
1169
1170 bool WarpBuilder::build_StrictConstantNe(BytecodeLocation loc) {
1171 return buildStrictConstantEqOp(loc, JSOp::StrictNe);
1172 }
1173
1174 #ifdef ENABLE_EXPLICIT_RESOURCE_MANAGEMENT
1175 bool WarpBuilder::build_AddDisposable(BytecodeLocation loc) {
1176 MOZ_ASSERT(usesEnvironmentChain());
1177
1178 UsingHint hint = loc.getUsingHint();
1179 MDefinition* needsClosure = current->pop();
1180 MDefinition* method = current->pop();
1181 MDefinition* obj = current->pop();
1182 MDefinition* env = current->environmentChain();
1183
1184 MAddDisposableResource* ins = MAddDisposableResource::New(
1185 alloc(), env, obj, method, needsClosure, uint8_t(hint));
1186 current->add(ins);
1187 return resumeAfter(ins, loc);
1188 }
1189
1190 bool WarpBuilder::build_TakeDisposeCapability(BytecodeLocation loc) {
1191 MOZ_ASSERT(usesEnvironmentChain());
1192 MDefinition* env = current->environmentChain();
1193
1194 MTakeDisposeCapability* ins = MTakeDisposeCapability::New(alloc(), env);
1195 current->add(ins);
1196 current->push(ins);
1197 return resumeAfter(ins, loc);
1198 }
1199
1200 bool WarpBuilder::build_CreateSuppressedError(BytecodeLocation loc) {
1201 MDefinition* suppressed = current->pop();
1202 MDefinition* error = current->pop();
1203
1204 MCreateSuppressedError* ins =
1205 MCreateSuppressedError::New(alloc(), error, suppressed);
1206 current->add(ins);
1207 current->push(ins);
1208 return true;
1209 }
1210 #endif
1211
1212 // Returns true iff the MTest added for |op| has a true-target corresponding
1213 // with the join point in the bytecode.
1214 static bool TestTrueTargetIsJoinPoint(JSOp op) {
1215 switch (op) {
1216 case JSOp::JumpIfTrue:
1217 case JSOp::Or:
1218 case JSOp::Case:
1219 return true;
1220
1221 case JSOp::JumpIfFalse:
1222 case JSOp::And:
1223 case JSOp::Coalesce:
1224 return false;
1225
1226 default:
1227 MOZ_CRASH("Unexpected op");
1228 }
1229 }
1230
1231 bool WarpBuilder::build_JumpTarget(BytecodeLocation loc) {
1232 PendingEdgesMap::Ptr p = pendingEdges_.lookup(loc.toRawBytecode());
1233 if (!p) {
1234 // No (reachable) jumps so this is just a no-op.
1235 return true;
1236 }
1237
1238 PendingEdges edges(std::move(p->value()));
1239 pendingEdges_.remove(p);
1240
1241 MOZ_ASSERT(!edges.empty());
1242
1243 // Create join block if there's fall-through from the previous bytecode op.
1244 if (!hasTerminatedBlock()) {
1245 MBasicBlock* pred = current;
1246 if (!startNewBlock(pred, loc)) {
1247 return false;
1248 }
1249 pred->end(MGoto::New(alloc(), current));
1250 }
1251
1252 for (const PendingEdge& edge : edges) {
1253 MBasicBlock* source = edge.block();
1254 uint32_t numToPop = edge.numToPop();
1255
1256 if (hasTerminatedBlock()) {
1257 if (!startNewBlock(source, loc, numToPop)) {
1258 return false;
1259 }
1260 } else {
1261 MOZ_ASSERT(source->stackDepth() - numToPop == current->stackDepth());
1262 if (!current->addPredecessorPopN(alloc(), source, numToPop)) {
1263 return false;
1264 }
1265 }
1266
1267 MOZ_ASSERT(source->lastIns()->isTest() || source->lastIns()->isGoto() ||
1268 source->lastIns()->isTableSwitch());
1269 source->lastIns()->initSuccessor(edge.successor(), current);
1270 }
1271
1272 MOZ_ASSERT(!hasTerminatedBlock());
1273 return true;
1274 }
1275
1276 bool WarpBuilder::addIteratorLoopPhis(BytecodeLocation loopHead) {
1277 // When unwinding the stack for a thrown exception, the exception handler must
1278 // close live iterators. For ForIn and Destructuring loops, the exception
1279 // handler needs access to values on the stack. To prevent them from being
1280 // optimized away (and replaced with the JS_OPTIMIZED_OUT MagicValue), we need
1281 // to mark the phis (and phis they flow into) as having implicit uses.
1282 // See ProcessTryNotes in vm/Interpreter.cpp and CloseLiveIteratorIon in
1283 // jit/JitFrames.cpp
1284
1285 MOZ_ASSERT(current->stackDepth() >= info().firstStackSlot());
1286
1287 bool emptyStack = current->stackDepth() == info().firstStackSlot();
1288 if (emptyStack) {
1289 return true;
1290 }
1291
1292 jsbytecode* loopHeadPC = loopHead.toRawBytecode();
1293
1294 for (TryNoteIterAllNoGC tni(script_, loopHeadPC); !tni.done(); ++tni) {
1295 const TryNote& tn = **tni;
1296
1297 // Stop if we reach an outer loop because outer loops were already
1298 // processed when we visited their loop headers.
1299 if (tn.isLoop()) {
1300 BytecodeLocation tnStart = script_->offsetToLocation(tn.start);
1301 if (tnStart != loopHead) {
1302 MOZ_ASSERT(tnStart.is(JSOp::LoopHead));
1303 MOZ_ASSERT(tnStart < loopHead);
1304 return true;
1305 }
1306 }
1307
1308 switch (tn.kind()) {
1309 case TryNoteKind::Destructuring:
1310 case TryNoteKind::ForIn: {
1311 // For for-in loops we add the iterator object to iterators(). For
1312 // destructuring loops we add the "done" value that's on top of the
1313 // stack and used in the exception handler.
1314 MOZ_ASSERT(tn.stackDepth >= 1);
1315 uint32_t slot = info().stackSlot(tn.stackDepth - 1);
1316 MPhi* phi = current->getSlot(slot)->toPhi();
1317 if (!iterators()->append(phi)) {
1318 return false;
1319 }
1320 break;
1321 }
1322 case TryNoteKind::Loop:
1323 case TryNoteKind::ForOf:
1324 // Regular loops do not have iterators to close. ForOf loops handle
1325 // unwinding using catch blocks.
1326 break;
1327 default:
1328 break;
1329 }
1330 }
1331
1332 return true;
1333 }
1334
1335 bool WarpBuilder::build_LoopHead(BytecodeLocation loc) {
1336 // All loops have the following bytecode structure:
1337 //
1338 // LoopHead
1339 // ...
1340 // JumpIfTrue/Goto to LoopHead
1341
1342 if (hasTerminatedBlock()) {
1343 // The whole loop is unreachable.
1344 return true;
1345 }
1346
1347 // Handle OSR from Baseline JIT code.
1348 if (loc.toRawBytecode() == info().osrPc()) {
1349 if (!startNewOsrPreHeaderBlock(loc)) {
1350 return false;
1351 }
1352 }
1353
1354 incLoopDepth();
1355
1356 MBasicBlock* pred = current;
1357 if (!startNewLoopHeaderBlock(loc)) {
1358 return false;
1359 }
1360
1361 pred->end(MGoto::New(alloc(), current));
1362
1363 if (!addIteratorLoopPhis(loc)) {
1364 return false;
1365 }
1366
1367 MInterruptCheck* check = MInterruptCheck::New(alloc());
1368 current->add(check);
1369
1370 #ifdef JS_CACHEIR_SPEW
1371 if (snapshot().needsFinalWarmUpCount()) {
1372 MIncrementWarmUpCounter* ins =
1373 MIncrementWarmUpCounter::New(alloc(), script_);
1374 current->add(ins);
1375 }
1376 #endif
1377
1378 return true;
1379 }
1380
1381 bool WarpBuilder::buildTestOp(BytecodeLocation loc) {
1382 MDefinition* originalValue = current->peek(-1);
1383
1384 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
1385 // If we have CacheIR, we can use it to refine the input. Note that
1386 // the transpiler doesn't generate any control instructions. Instead,
1387 // we fall through and generate them below.
1388 MDefinition* value = current->pop();
1389 if (!TranspileCacheIRToMIR(this, loc, cacheIRSnapshot, {value})) {
1390 return false;
1391 }
1392 }
1393
1394 if (loc.isBackedge()) {
1395 return buildTestBackedge(loc);
1396 }
1397
1398 JSOp op = loc.getOp();
1399 BytecodeLocation target1 = loc.next();
1400 BytecodeLocation target2 = loc.getJumpTarget();
1401
1402 if (TestTrueTargetIsJoinPoint(op)) {
1403 std::swap(target1, target2);
1404 }
1405
1406 MDefinition* value = current->pop();
1407
1408 // JSOp::And and JSOp::Or leave the top stack value unchanged. The
1409 // top stack value may have been converted to bool by a transpiled
1410 // ToBool IC, so we push the original value.
1411 bool mustKeepCondition = (op == JSOp::And || op == JSOp::Or);
1412 if (mustKeepCondition) {
1413 current->push(originalValue);
1414 }
1415
1416 // If this op always branches to the same location we treat this as a
1417 // JSOp::Goto.
1418 if (target1 == target2) {
1419 value->setImplicitlyUsedUnchecked();
1420 return buildForwardGoto(target1);
1421 }
1422
1423 MTest* test = MTest::New(alloc(), value, /* ifTrue = */ nullptr,
1424 /* ifFalse = */ nullptr);
1425 current->end(test);
1426
1427 // JSOp::Case must pop a second value on the true-branch (the input to the
1428 // switch-statement).
1429 uint32_t numToPop = (loc.getOp() == JSOp::Case) ? 1 : 0;
1430
1431 if (!addPendingEdge(target1, current, MTest::TrueBranchIndex, numToPop)) {
1432 return false;
1433 }
1434 if (!addPendingEdge(target2, current, MTest::FalseBranchIndex)) {
1435 return false;
1436 }
1437
1438 if (const auto* typesSnapshot = getOpSnapshot<WarpPolymorphicTypes>(loc)) {
1439 test->setObservedTypes(typesSnapshot->list());
1440 }
1441
1442 setTerminatedBlock();
1443 return true;
1444 }
1445
1446 bool WarpBuilder::buildTestBackedge(BytecodeLocation loc) {
1447 MOZ_ASSERT(loc.is(JSOp::JumpIfTrue));
1448 MOZ_ASSERT(loopDepth() > 0);
1449
1450 MDefinition* value = current->pop();
1451
1452 BytecodeLocation loopHead = loc.getJumpTarget();
1453 MOZ_ASSERT(loopHead.is(JSOp::LoopHead));
1454
1455 BytecodeLocation successor = loc.next();
1456
1457 // We can finish the loop now. Use the loophead pc instead of the current pc
1458 // because the stack depth at the start of that op matches the current stack
1459 // depth (after popping our operand).
1460 MBasicBlock* pred = current;
1461 if (!startNewBlock(current, loopHead)) {
1462 return false;
1463 }
1464
1465 MTest* test = MTest::New(alloc(), value, /* ifTrue = */ current,
1466 /* ifFalse = */ nullptr);
1467 pred->end(test);
1468
1469 if (const auto* typesSnapshot = getOpSnapshot<WarpPolymorphicTypes>(loc)) {
1470 test->setObservedTypes(typesSnapshot->list());
1471 }
1472
1473 if (!addPendingEdge(successor, pred, MTest::FalseBranchIndex)) {
1474 return false;
1475 }
1476
1477 return buildBackedge();
1478 }
1479
1480 bool WarpBuilder::build_JumpIfFalse(BytecodeLocation loc) {
1481 return buildTestOp(loc);
1482 }
1483
1484 bool WarpBuilder::build_JumpIfTrue(BytecodeLocation loc) {
1485 return buildTestOp(loc);
1486 }
1487
1488 bool WarpBuilder::build_And(BytecodeLocation loc) { return buildTestOp(loc); }
1489
1490 bool WarpBuilder::build_Or(BytecodeLocation loc) { return buildTestOp(loc); }
1491
1492 bool WarpBuilder::build_Case(BytecodeLocation loc) { return buildTestOp(loc); }
1493
1494 bool WarpBuilder::build_Default(BytecodeLocation loc) {
1495 current->pop();
1496 return buildForwardGoto(loc.getJumpTarget());
1497 }
1498
1499 bool WarpBuilder::build_Coalesce(BytecodeLocation loc) {
1500 BytecodeLocation target1 = loc.next();
1501 BytecodeLocation target2 = loc.getJumpTarget();
1502 MOZ_ASSERT(target2 > target1);
1503
1504 MDefinition* value = current->peek(-1);
1505
1506 MInstruction* isNullOrUndefined = MIsNullOrUndefined::New(alloc(), value);
1507 current->add(isNullOrUndefined);
1508
1509 current->end(MTest::New(alloc(), isNullOrUndefined, /* ifTrue = */ nullptr,
1510 /* ifFalse = */ nullptr));
1511
1512 if (!addPendingEdge(target1, current, MTest::TrueBranchIndex)) {
1513 return false;
1514 }
1515 if (!addPendingEdge(target2, current, MTest::FalseBranchIndex)) {
1516 return false;
1517 }
1518
1519 setTerminatedBlock();
1520 return true;
1521 }
1522
1523 bool WarpBuilder::buildBackedge() {
1524 decLoopDepth();
1525
1526 MBasicBlock* header = loopStack_.popCopy().header();
1527 current->end(MGoto::New(alloc(), header));
1528
1529 if (!header->setBackedge(current)) {
1530 return false;
1531 }
1532
1533 setTerminatedBlock();
1534 return true;
1535 }
1536
1537 bool WarpBuilder::buildForwardGoto(BytecodeLocation target) {
1538 current->end(MGoto::New(alloc(), nullptr));
1539
1540 if (!addPendingEdge(target, current, MGoto::TargetIndex)) {
1541 return false;
1542 }
1543
1544 setTerminatedBlock();
1545 return true;
1546 }
1547
1548 bool WarpBuilder::build_Goto(BytecodeLocation loc) {
1549 if (loc.isBackedge()) {
1550 return buildBackedge();
1551 }
1552
1553 return buildForwardGoto(loc.getJumpTarget());
1554 }
1555
1556 bool WarpBuilder::build_IsNullOrUndefined(BytecodeLocation loc) {
1557 MDefinition* value = current->peek(-1);
1558 auto* isNullOrUndef = MIsNullOrUndefined::New(alloc(), value);
1559 current->add(isNullOrUndef);
1560 current->push(isNullOrUndef);
1561 return true;
1562 }
1563
1564 bool WarpBuilder::build_DebugCheckSelfHosted(BytecodeLocation loc) {
1565 #ifdef DEBUG
1566 MDefinition* val = current->pop();
1567 MDebugCheckSelfHosted* check = MDebugCheckSelfHosted::New(alloc(), val);
1568 current->add(check);
1569 current->push(check);
1570 if (!resumeAfter(check, loc)) {
1571 return false;
1572 }
1573 #endif
1574 return true;
1575 }
1576
1577 bool WarpBuilder::build_DynamicImport(BytecodeLocation loc) {
1578 MDefinition* options = current->pop();
1579 MDefinition* specifier = current->pop();
1580 MDynamicImport* ins = MDynamicImport::New(alloc(), specifier, options);
1581 current->add(ins);
1582 current->push(ins);
1583 return resumeAfter(ins, loc);
1584 }
1585
1586 bool WarpBuilder::build_Not(BytecodeLocation loc) {
1587 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
1588 // If we have CacheIR, we can use it to refine the input before
1589 // emitting the MNot.
1590 MDefinition* value = current->pop();
1591 if (!TranspileCacheIRToMIR(this, loc, cacheIRSnapshot, {value})) {
1592 return false;
1593 }
1594 }
1595
1596 MDefinition* value = current->pop();
1597 MNot* ins = MNot::New(alloc(), value);
1598 current->add(ins);
1599 current->push(ins);
1600
1601 if (const auto* typesSnapshot = getOpSnapshot<WarpPolymorphicTypes>(loc)) {
1602 ins->setObservedTypes(typesSnapshot->list());
1603 }
1604
1605 return true;
1606 }
1607
1608 bool WarpBuilder::build_ToString(BytecodeLocation loc) {
1609 MDefinition* value = current->pop();
1610
1611 if (value->type() == MIRType::String) {
1612 value->setImplicitlyUsedUnchecked();
1613 current->push(value);
1614 return true;
1615 }
1616
1617 MToString* ins =
1618 MToString::New(alloc(), value, MToString::SideEffectHandling::Supported);
1619 current->add(ins);
1620 current->push(ins);
1621 if (ins->isEffectful()) {
1622 return resumeAfter(ins, loc);
1623 }
1624 return true;
1625 }
1626
1627 bool WarpBuilder::usesEnvironmentChain() const {
1628 return script_->jitScript()->usesEnvironmentChain();
1629 }
1630
1631 bool WarpBuilder::build_GlobalOrEvalDeclInstantiation(BytecodeLocation loc) {
1632 MOZ_ASSERT(!script_->isForEval(), "Eval scripts not supported");
1633 auto* redeclCheck = MGlobalDeclInstantiation::New(alloc());
1634 current->add(redeclCheck);
1635 return resumeAfter(redeclCheck, loc);
1636 }
1637
1638 bool WarpBuilder::build_BindVar(BytecodeLocation) {
1639 MOZ_ASSERT(usesEnvironmentChain());
1640
1641 MDefinition* env = current->environmentChain();
1642 MCallBindVar* ins = MCallBindVar::New(alloc(), env);
1643 current->add(ins);
1644 current->push(ins);
1645 return true;
1646 }
1647
1648 bool WarpBuilder::build_MutateProto(BytecodeLocation loc) {
1649 MDefinition* value = current->pop();
1650 MDefinition* obj = current->peek(-1);
1651 MMutateProto* mutate = MMutateProto::New(alloc(), obj, value);
1652 current->add(mutate);
1653 return resumeAfter(mutate, loc);
1654 }
1655
1656 MDefinition* WarpBuilder::getCallee() {
1657 if (inlineCallInfo()) {
1658 return inlineCallInfo()->callee();
1659 }
1660
1661 MInstruction* callee = MCallee::New(alloc());
1662 current->add(callee);
1663 return callee;
1664 }
1665
1666 bool WarpBuilder::build_Callee(BytecodeLocation) {
1667 MDefinition* callee = getCallee();
1668 current->push(callee);
1669 return true;
1670 }
1671
1672 bool WarpBuilder::build_ToAsyncIter(BytecodeLocation loc) {
1673 MDefinition* nextMethod = current->pop();
1674 MDefinition* iterator = current->pop();
1675 MToAsyncIter* ins = MToAsyncIter::New(alloc(), iterator, nextMethod);
1676 current->add(ins);
1677 current->push(ins);
1678 return resumeAfter(ins, loc);
1679 }
1680
1681 bool WarpBuilder::build_ToPropertyKey(BytecodeLocation loc) {
1682 MDefinition* value = current->pop();
1683 return buildIC(loc, CacheKind::ToPropertyKey, {value});
1684 }
1685
1686 bool WarpBuilder::build_Typeof(BytecodeLocation loc) {
1687 MDefinition* input = current->pop();
1688
1689 if (const auto* typesSnapshot = getOpSnapshot<WarpPolymorphicTypes>(loc)) {
1690 auto* typeOf = MTypeOf::New(alloc(), input);
1691 typeOf->setObservedTypes(typesSnapshot->list());
1692 current->add(typeOf);
1693
1694 auto* ins = MTypeOfName::New(alloc(), typeOf);
1695 current->add(ins);
1696 current->push(ins);
1697 return true;
1698 }
1699
1700 return buildIC(loc, CacheKind::TypeOf, {input});
1701 }
1702
1703 bool WarpBuilder::build_TypeofExpr(BytecodeLocation loc) {
1704 return build_Typeof(loc);
1705 }
1706
1707 bool WarpBuilder::build_TypeofEq(BytecodeLocation loc) {
1708 auto operand = loc.getTypeofEqOperand();
1709 JSType type = operand.type();
1710 JSOp compareOp = operand.compareOp();
1711 MDefinition* input = current->pop();
1712
1713 if (const auto* typesSnapshot = getOpSnapshot<WarpPolymorphicTypes>(loc)) {
1714 auto* typeOf = MTypeOf::New(alloc(), input);
1715 typeOf->setObservedTypes(typesSnapshot->list());
1716 current->add(typeOf);
1717
1718 auto* typeInt = MConstant::New(alloc(), Int32Value(type));
1719 current->add(typeInt);
1720
1721 auto* ins = MCompare::New(alloc(), typeOf, typeInt, compareOp,
1722 MCompare::Compare_Int32);
1723 current->add(ins);
1724 current->push(ins);
1725 return true;
1726 }
1727
1728 return buildIC(loc, CacheKind::TypeOfEq, {input});
1729 }
1730
1731 bool WarpBuilder::build_Arguments(BytecodeLocation loc) {
1732 auto* snapshot = getOpSnapshot<WarpArguments>(loc);
1733 MOZ_ASSERT(info().needsArgsObj());
1734 MOZ_ASSERT(snapshot);
1735 MOZ_ASSERT(usesEnvironmentChain());
1736
1737 ArgumentsObject* templateObj = snapshot->templateObj();
1738 MDefinition* env = current->environmentChain();
1739
1740 MInstruction* argsObj;
1741 if (inlineCallInfo()) {
1742 argsObj = MCreateInlinedArgumentsObject::New(
1743 alloc(), env, getCallee(), inlineCallInfo()->argv(), templateObj);
1744 if (!argsObj) {
1745 return false;
1746 }
1747 } else {
1748 argsObj = MCreateArgumentsObject::New(alloc(), env, templateObj);
1749 }
1750 current->add(argsObj);
1751 current->setArgumentsObject(argsObj);
1752 current->push(argsObj);
1753
1754 return true;
1755 }
1756
1757 bool WarpBuilder::build_ObjWithProto(BytecodeLocation loc) {
1758 MDefinition* proto = current->pop();
1759 MInstruction* ins = MObjectWithProto::New(alloc(), proto);
1760 current->add(ins);
1761 current->push(ins);
1762 return resumeAfter(ins, loc);
1763 }
1764
1765 MDefinition* WarpBuilder::walkEnvironmentChain(uint32_t numHops) {
1766 MDefinition* env = current->environmentChain();
1767
1768 for (uint32_t i = 0; i < numHops; i++) {
1769 if (!alloc().ensureBallast()) {
1770 return nullptr;
1771 }
1772
1773 MInstruction* ins = MEnclosingEnvironment::New(alloc(), env);
1774 current->add(ins);
1775 env = ins;
1776 }
1777
1778 return env;
1779 }
1780
1781 bool WarpBuilder::build_GetAliasedVar(BytecodeLocation loc) {
1782 EnvironmentCoordinate ec = loc.getEnvironmentCoordinate();
1783 MDefinition* obj = walkEnvironmentChain(ec.hops());
1784 if (!obj) {
1785 return false;
1786 }
1787
1788 MInstruction* load;
1789 if (EnvironmentObject::nonExtensibleIsFixedSlot(ec)) {
1790 load = MLoadFixedSlot::New(alloc(), obj, ec.slot());
1791 } else {
1792 MInstruction* slots = MSlots::New(alloc(), obj);
1793 current->add(slots);
1794
1795 uint32_t slot = EnvironmentObject::nonExtensibleDynamicSlotIndex(ec);
1796 load = MLoadDynamicSlot::New(alloc(), slots, slot);
1797 }
1798
1799 current->add(load);
1800 current->push(load);
1801 return true;
1802 }
1803
1804 bool WarpBuilder::build_SetAliasedVar(BytecodeLocation loc) {
1805 EnvironmentCoordinate ec = loc.getEnvironmentCoordinate();
1806 MDefinition* val = current->peek(-1);
1807 MDefinition* obj = walkEnvironmentChain(ec.hops());
1808 if (!obj) {
1809 return false;
1810 }
1811
1812 current->add(MPostWriteBarrier::New(alloc(), obj, val));
1813
1814 MInstruction* store;
1815 if (EnvironmentObject::nonExtensibleIsFixedSlot(ec)) {
1816 store = MStoreFixedSlot::NewBarriered(alloc(), obj, ec.slot(), val);
1817 } else {
1818 MInstruction* slots = MSlots::New(alloc(), obj);
1819 current->add(slots);
1820
1821 uint32_t slot = EnvironmentObject::nonExtensibleDynamicSlotIndex(ec);
1822 store = MStoreDynamicSlot::NewBarriered(alloc(), slots, slot, val);
1823 }
1824
1825 current->add(store);
1826 return resumeAfter(store, loc);
1827 }
1828
1829 bool WarpBuilder::build_InitAliasedLexical(BytecodeLocation loc) {
1830 return build_SetAliasedVar(loc);
1831 }
1832
1833 bool WarpBuilder::build_EnvCallee(BytecodeLocation loc) {
1834 uint32_t numHops = loc.getEnvCalleeNumHops();
1835 MDefinition* env = walkEnvironmentChain(numHops);
1836 if (!env) {
1837 return false;
1838 }
1839
1840 auto* callee = MLoadFixedSlot::New(alloc(), env, CallObject::calleeSlot());
1841 current->add(callee);
1842 current->push(callee);
1843 return true;
1844 }
1845
1846 bool WarpBuilder::build_Iter(BytecodeLocation loc) {
1847 MDefinition* obj = current->pop();
1848 return buildIC(loc, CacheKind::GetIterator, {obj});
1849 }
1850
1851 bool WarpBuilder::build_MoreIter(BytecodeLocation loc) {
1852 MDefinition* iter = current->peek(-1);
1853 MInstruction* ins = MIteratorMore::New(alloc(), iter);
1854 current->add(ins);
1855 current->push(ins);
1856 return resumeAfter(ins, loc);
1857 }
1858
1859 bool WarpBuilder::build_EndIter(BytecodeLocation loc) {
1860 current->pop(); // Iterator value is not used.
1861 MDefinition* iter = current->pop();
1862 MInstruction* ins = MIteratorEnd::New(alloc(), iter);
1863 current->add(ins);
1864 return resumeAfter(ins, loc);
1865 }
1866
1867 bool WarpBuilder::build_CloseIter(BytecodeLocation loc) {
1868 MDefinition* iter = current->pop();
1869 iter = unboxObjectInfallible(iter, IsMovable::Yes);
1870 return buildIC(loc, CacheKind::CloseIter, {iter});
1871 }
1872
1873 bool WarpBuilder::build_IsNoIter(BytecodeLocation) {
1874 MDefinition* def = current->peek(-1);
1875 MOZ_ASSERT(def->isIteratorMore());
1876 MInstruction* ins = MIsNoIter::New(alloc(), def);
1877 current->add(ins);
1878 current->push(ins);
1879 return true;
1880 }
1881
1882 bool WarpBuilder::build_OptimizeGetIterator(BytecodeLocation loc) {
1883 MDefinition* value = current->pop();
1884 return buildIC(loc, CacheKind::OptimizeGetIterator, {value});
1885 }
1886
1887 bool WarpBuilder::transpileCall(BytecodeLocation loc,
1888 const WarpCacheIR* cacheIRSnapshot,
1889 CallInfo* callInfo) {
1890 // Synthesize the constant number of arguments for this call op.
1891 auto* argc = MConstant::New(alloc(), Int32Value(callInfo->argc()));
1892 current->add(argc);
1893
1894 return TranspileCacheIRToMIR(this, loc, cacheIRSnapshot, {argc}, callInfo);
1895 }
1896
1897 void WarpBuilder::buildCreateThis(CallInfo& callInfo) {
1898 MOZ_ASSERT(callInfo.constructing());
1899
1900 // Inline the this-object allocation on the caller-side.
1901 MDefinition* callee = callInfo.callee();
1902 MDefinition* newTarget = callInfo.getNewTarget();
1903 auto* createThis = MCreateThis::New(alloc(), callee, newTarget);
1904 current->add(createThis);
1905 callInfo.thisArg()->setImplicitlyUsedUnchecked();
1906 callInfo.setThis(createThis);
1907 }
1908
1909 bool WarpBuilder::buildCallOp(BytecodeLocation loc) {
1910 uint32_t argc = loc.getCallArgc();
1911 JSOp op = loc.getOp();
1912 bool constructing = IsConstructOp(op);
1913 bool ignoresReturnValue = (op == JSOp::CallIgnoresRv || loc.resultIsPopped());
1914
1915 CallInfo callInfo(alloc(), constructing, ignoresReturnValue);
1916 if (!callInfo.init(current, argc)) {
1917 return false;
1918 }
1919
1920 if (const auto* inliningSnapshot = getOpSnapshot<WarpInlinedCall>(loc)) {
1921 // Transpile the CacheIR to generate the correct guards before
1922 // inlining. In this case, CacheOp::CallInlinedFunction updates
1923 // the CallInfo, but does not generate a call.
1924 callInfo.markAsInlined();
1925 if (!transpileCall(loc, inliningSnapshot->cacheIRSnapshot(), &callInfo)) {
1926 return false;
1927 }
1928
1929 // Generate the body of the inlined function.
1930 return buildInlinedCall(loc, inliningSnapshot, callInfo);
1931 }
1932
1933 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
1934 return transpileCall(loc, cacheIRSnapshot, &callInfo);
1935 }
1936
1937 if (getOpSnapshot<WarpBailout>(loc)) {
1938 callInfo.setImplicitlyUsedUnchecked();
1939 return buildBailoutForColdIC(loc, CacheKind::Call);
1940 }
1941
1942 bool needsThisCheck = false;
1943 if (callInfo.constructing()) {
1944 buildCreateThis(callInfo);
1945 needsThisCheck = true;
1946 }
1947
1948 MCall* call = makeCall(callInfo, needsThisCheck);
1949 if (!call) {
1950 return false;
1951 }
1952
1953 current->add(call);
1954 current->push(call);
1955 return resumeAfter(call, loc);
1956 }
1957
1958 bool WarpBuilder::build_Call(BytecodeLocation loc) { return buildCallOp(loc); }
1959
1960 bool WarpBuilder::build_CallContent(BytecodeLocation loc) {
1961 return buildCallOp(loc);
1962 }
1963
1964 bool WarpBuilder::build_CallIgnoresRv(BytecodeLocation loc) {
1965 return buildCallOp(loc);
1966 }
1967
1968 bool WarpBuilder::build_CallIter(BytecodeLocation loc) {
1969 return buildCallOp(loc);
1970 }
1971
1972 bool WarpBuilder::build_CallContentIter(BytecodeLocation loc) {
1973 return buildCallOp(loc);
1974 }
1975
1976 bool WarpBuilder::build_New(BytecodeLocation loc) { return buildCallOp(loc); }
1977
1978 bool WarpBuilder::build_NewContent(BytecodeLocation loc) {
1979 return buildCallOp(loc);
1980 }
1981
1982 bool WarpBuilder::build_SuperCall(BytecodeLocation loc) {
1983 return buildCallOp(loc);
1984 }
1985
1986 bool WarpBuilder::build_FunctionThis(BytecodeLocation loc) {
1987 MOZ_ASSERT(info().hasFunMaybeLazy());
1988
1989 if (script_->strict()) {
1990 // No need to wrap primitive |this| in strict mode.
1991 current->pushSlot(info().thisSlot());
1992 return true;
1993 }
1994
1995 MOZ_ASSERT(!script_->hasNonSyntacticScope(),
1996 "WarpOracle should have aborted compilation");
1997
1998 MDefinition* def = current->getSlot(info().thisSlot());
1999 JSObject* globalThis = snapshot().globalLexicalEnvThis();
2000
2001 auto* thisObj = MBoxNonStrictThis::New(alloc(), def, globalThis);
2002 current->add(thisObj);
2003 current->push(thisObj);
2004
2005 return true;
2006 }
2007
2008 bool WarpBuilder::build_GlobalThis(BytecodeLocation loc) {
2009 MOZ_ASSERT(!script_->hasNonSyntacticScope());
2010 JSObject* obj = snapshot().globalLexicalEnvThis();
2011 pushConstant(ObjectValue(*obj));
2012 return true;
2013 }
2014
2015 MConstant* WarpBuilder::globalLexicalEnvConstant() {
2016 JSObject* globalLexical = snapshot().globalLexicalEnv();
2017 return constant(ObjectValue(*globalLexical));
2018 }
2019
2020 bool WarpBuilder::build_GetName(BytecodeLocation loc) {
2021 MOZ_ASSERT(usesEnvironmentChain());
2022
2023 MDefinition* env = current->environmentChain();
2024 env = unboxObjectInfallible(env, IsMovable::Yes);
2025 return buildIC(loc, CacheKind::GetName, {env});
2026 }
2027
2028 bool WarpBuilder::build_GetGName(BytecodeLocation loc) {
2029 MOZ_ASSERT(!script_->hasNonSyntacticScope());
2030
2031 MDefinition* env = globalLexicalEnvConstant();
2032 return buildIC(loc, CacheKind::GetName, {env});
2033 }
2034
2035 bool WarpBuilder::build_BindName(BytecodeLocation loc) {
2036 MOZ_ASSERT(usesEnvironmentChain());
2037
2038 MDefinition* env = current->environmentChain();
2039 env = unboxObjectInfallible(env, IsMovable::Yes);
2040 return buildIC(loc, CacheKind::BindName, {env});
2041 }
2042
2043 bool WarpBuilder::build_BindUnqualifiedName(BytecodeLocation loc) {
2044 MOZ_ASSERT(usesEnvironmentChain());
2045
2046 MDefinition* env = current->environmentChain();
2047 env = unboxObjectInfallible(env, IsMovable::Yes);
2048 return buildIC(loc, CacheKind::BindName, {env});
2049 }
2050
2051 bool WarpBuilder::build_BindUnqualifiedGName(BytecodeLocation loc) {
2052 MOZ_ASSERT(!script_->hasNonSyntacticScope());
2053
2054 if (const auto* snapshot = getOpSnapshot<WarpBindUnqualifiedGName>(loc)) {
2055 JSObject* globalEnv = snapshot->globalEnv();
2056 pushConstant(ObjectValue(*globalEnv));
2057 return true;
2058 }
2059
2060 MDefinition* env = globalLexicalEnvConstant();
2061 return buildIC(loc, CacheKind::BindName, {env});
2062 }
2063
2064 bool WarpBuilder::build_GetProp(BytecodeLocation loc) {
2065 MDefinition* val = current->pop();
2066 return buildIC(loc, CacheKind::GetProp, {val});
2067 }
2068
2069 bool WarpBuilder::build_GetBoundName(BytecodeLocation loc) {
2070 MDefinition* val = current->pop();
2071 return buildIC(loc, CacheKind::GetProp, {val});
2072 }
2073
2074 bool WarpBuilder::build_GetElem(BytecodeLocation loc) {
2075 MDefinition* id = current->pop();
2076 MDefinition* val = current->pop();
2077 return buildIC(loc, CacheKind::GetElem, {val, id});
2078 }
2079
2080 bool WarpBuilder::build_SetProp(BytecodeLocation loc) {
2081 MDefinition* val = current->pop();
2082 MDefinition* obj = current->pop();
2083 current->push(val);
2084 return buildIC(loc, CacheKind::SetProp, {obj, val});
2085 }
2086
2087 bool WarpBuilder::build_StrictSetProp(BytecodeLocation loc) {
2088 return build_SetProp(loc);
2089 }
2090
2091 bool WarpBuilder::build_SetName(BytecodeLocation loc) {
2092 return build_SetProp(loc);
2093 }
2094
2095 bool WarpBuilder::build_StrictSetName(BytecodeLocation loc) {
2096 return build_SetProp(loc);
2097 }
2098
2099 bool WarpBuilder::build_SetGName(BytecodeLocation loc) {
2100 return build_SetProp(loc);
2101 }
2102
2103 bool WarpBuilder::build_StrictSetGName(BytecodeLocation loc) {
2104 return build_SetProp(loc);
2105 }
2106
2107 bool WarpBuilder::build_InitGLexical(BytecodeLocation loc) {
2108 MOZ_ASSERT(!script_->hasNonSyntacticScope());
2109
2110 MDefinition* globalLexical = globalLexicalEnvConstant();
2111 MDefinition* val = current->peek(-1);
2112
2113 return buildIC(loc, CacheKind::SetProp, {globalLexical, val});
2114 }
2115
2116 bool WarpBuilder::build_SetElem(BytecodeLocation loc) {
2117 MDefinition* val = current->pop();
2118 MDefinition* id = current->pop();
2119 MDefinition* obj = current->pop();
2120 current->push(val);
2121 return buildIC(loc, CacheKind::SetElem, {obj, id, val});
2122 }
2123
2124 bool WarpBuilder::build_StrictSetElem(BytecodeLocation loc) {
2125 return build_SetElem(loc);
2126 }
2127
2128 bool WarpBuilder::build_DelProp(BytecodeLocation loc) {
2129 PropertyName* name = loc.getPropertyName(script_);
2130 MDefinition* obj = current->pop();
2131 bool strict = loc.getOp() == JSOp::StrictDelProp;
2132
2133 MInstruction* ins = MDeleteProperty::New(alloc(), obj, name, strict);
2134 current->add(ins);
2135 current->push(ins);
2136 return resumeAfter(ins, loc);
2137 }
2138
2139 bool WarpBuilder::build_StrictDelProp(BytecodeLocation loc) {
2140 return build_DelProp(loc);
2141 }
2142
2143 bool WarpBuilder::build_DelElem(BytecodeLocation loc) {
2144 MDefinition* id = current->pop();
2145 MDefinition* obj = current->pop();
2146 bool strict = loc.getOp() == JSOp::StrictDelElem;
2147
2148 MInstruction* ins = MDeleteElement::New(alloc(), obj, id, strict);
2149 current->add(ins);
2150 current->push(ins);
2151 return resumeAfter(ins, loc);
2152 }
2153
2154 bool WarpBuilder::build_StrictDelElem(BytecodeLocation loc) {
2155 return build_DelElem(loc);
2156 }
2157
2158 bool WarpBuilder::build_SetFunName(BytecodeLocation loc) {
2159 FunctionPrefixKind prefixKind = loc.getFunctionPrefixKind();
2160 MDefinition* name = current->pop();
2161 MDefinition* fun = current->pop();
2162
2163 MSetFunName* ins = MSetFunName::New(alloc(), fun, name, uint8_t(prefixKind));
2164 current->add(ins);
2165 current->push(fun);
2166 return resumeAfter(ins, loc);
2167 }
2168
2169 bool WarpBuilder::build_PushLexicalEnv(BytecodeLocation loc) {
2170 MOZ_ASSERT(usesEnvironmentChain());
2171
2172 const auto* snapshot = getOpSnapshot<WarpLexicalEnvironment>(loc);
2173 MOZ_ASSERT(snapshot);
2174
2175 MDefinition* env = current->environmentChain();
2176 MConstant* templateCst = constant(ObjectValue(*snapshot->templateObj()));
2177
2178 auto* ins = MNewLexicalEnvironmentObject::New(alloc(), templateCst);
2179 current->add(ins);
2180
2181 #ifdef DEBUG
2182 // Assert in debug mode we can elide the post write barrier.
2183 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), ins, env));
2184 #endif
2185
2186 // Initialize the object's reserved slots. No post barrier is needed here,
2187 // for the same reason as in buildNamedLambdaEnv.
2188 current->add(MStoreFixedSlot::NewUnbarriered(
2189 alloc(), ins, EnvironmentObject::enclosingEnvironmentSlot(), env));
2190
2191 current->setEnvironmentChain(ins);
2192 return true;
2193 }
2194
2195 bool WarpBuilder::build_PushClassBodyEnv(BytecodeLocation loc) {
2196 MOZ_ASSERT(usesEnvironmentChain());
2197
2198 const auto* snapshot = getOpSnapshot<WarpClassBodyEnvironment>(loc);
2199 MOZ_ASSERT(snapshot);
2200
2201 MDefinition* env = current->environmentChain();
2202 MConstant* templateCst = constant(ObjectValue(*snapshot->templateObj()));
2203
2204 auto* ins = MNewClassBodyEnvironmentObject::New(alloc(), templateCst);
2205 current->add(ins);
2206
2207 #ifdef DEBUG
2208 // Assert in debug mode we can elide the post write barrier.
2209 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), ins, env));
2210 #endif
2211
2212 // Initialize the object's reserved slots. No post barrier is needed here,
2213 // for the same reason as in buildNamedLambdaEnv.
2214 current->add(MStoreFixedSlot::NewUnbarriered(
2215 alloc(), ins, EnvironmentObject::enclosingEnvironmentSlot(), env));
2216
2217 current->setEnvironmentChain(ins);
2218 return true;
2219 }
2220
2221 bool WarpBuilder::build_PopLexicalEnv(BytecodeLocation) {
2222 MDefinition* enclosingEnv = walkEnvironmentChain(1);
2223 if (!enclosingEnv) {
2224 return false;
2225 }
2226 current->setEnvironmentChain(enclosingEnv);
2227 return true;
2228 }
2229
2230 bool WarpBuilder::build_FreshenLexicalEnv(BytecodeLocation loc) {
2231 MOZ_ASSERT(usesEnvironmentChain());
2232
2233 const auto* snapshot = getOpSnapshot<WarpLexicalEnvironment>(loc);
2234 MOZ_ASSERT(snapshot);
2235
2236 MDefinition* enclosingEnv = walkEnvironmentChain(1);
2237 if (!enclosingEnv) {
2238 return false;
2239 }
2240
2241 MDefinition* env = current->environmentChain();
2242 MConstant* templateCst = constant(ObjectValue(*snapshot->templateObj()));
2243
2244 auto* templateObj = snapshot->templateObj();
2245 auto* scope = &templateObj->scope();
2246 MOZ_ASSERT(scope->hasEnvironment());
2247
2248 auto* ins = MNewLexicalEnvironmentObject::New(alloc(), templateCst);
2249 current->add(ins);
2250
2251 #ifdef DEBUG
2252 // Assert in debug mode we can elide the post write barrier.
2253 current->add(
2254 MAssertCanElidePostWriteBarrier::New(alloc(), ins, enclosingEnv));
2255 #endif
2256
2257 // Initialize the object's reserved slots. No post barrier is needed here,
2258 // for the same reason as in buildNamedLambdaEnv.
2259 current->add(MStoreFixedSlot::NewUnbarriered(
2260 alloc(), ins, EnvironmentObject::enclosingEnvironmentSlot(),
2261 enclosingEnv));
2262
2263 // Copy environment slots.
2264 MSlots* envSlots = nullptr;
2265 MSlots* slots = nullptr;
2266 for (BindingIter iter(scope); iter; iter++) {
2267 auto loc = iter.location();
2268 if (loc.kind() != BindingLocation::Kind::Environment) {
2269 MOZ_ASSERT(loc.kind() == BindingLocation::Kind::Frame);
2270 continue;
2271 }
2272
2273 if (!alloc().ensureBallast()) {
2274 return false;
2275 }
2276
2277 uint32_t slot = loc.slot();
2278 uint32_t numFixedSlots = templateObj->numFixedSlots();
2279 if (slot >= numFixedSlots) {
2280 if (!envSlots) {
2281 envSlots = MSlots::New(alloc(), env);
2282 current->add(envSlots);
2283 }
2284 if (!slots) {
2285 slots = MSlots::New(alloc(), ins);
2286 current->add(slots);
2287 }
2288
2289 uint32_t dynamicSlot = slot - numFixedSlots;
2290
2291 auto* load = MLoadDynamicSlot::New(alloc(), envSlots, dynamicSlot);
2292 current->add(load);
2293
2294 #ifdef DEBUG
2295 // Assert in debug mode we can elide the post write barrier.
2296 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), ins, load));
2297 #endif
2298
2299 current->add(
2300 MStoreDynamicSlot::NewUnbarriered(alloc(), slots, dynamicSlot, load));
2301 } else {
2302 auto* load = MLoadFixedSlot::New(alloc(), env, slot);
2303 current->add(load);
2304
2305 #ifdef DEBUG
2306 // Assert in debug mode we can elide the post write barrier.
2307 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), ins, load));
2308 #endif
2309
2310 current->add(MStoreFixedSlot::NewUnbarriered(alloc(), ins, slot, load));
2311 }
2312 }
2313
2314 current->setEnvironmentChain(ins);
2315 return true;
2316 }
2317
2318 bool WarpBuilder::build_RecreateLexicalEnv(BytecodeLocation loc) {
2319 MOZ_ASSERT(usesEnvironmentChain());
2320
2321 const auto* snapshot = getOpSnapshot<WarpLexicalEnvironment>(loc);
2322 MOZ_ASSERT(snapshot);
2323
2324 MDefinition* enclosingEnv = walkEnvironmentChain(1);
2325 if (!enclosingEnv) {
2326 return false;
2327 }
2328
2329 MConstant* templateCst = constant(ObjectValue(*snapshot->templateObj()));
2330
2331 auto* ins = MNewLexicalEnvironmentObject::New(alloc(), templateCst);
2332 current->add(ins);
2333
2334 #ifdef DEBUG
2335 // Assert in debug mode we can elide the post write barrier.
2336 current->add(
2337 MAssertCanElidePostWriteBarrier::New(alloc(), ins, enclosingEnv));
2338 #endif
2339
2340 // Initialize the object's reserved slots. No post barrier is needed here,
2341 // for the same reason as in buildNamedLambdaEnv.
2342 current->add(MStoreFixedSlot::NewUnbarriered(
2343 alloc(), ins, EnvironmentObject::enclosingEnvironmentSlot(),
2344 enclosingEnv));
2345
2346 current->setEnvironmentChain(ins);
2347 return true;
2348 }
2349
2350 bool WarpBuilder::build_PushVarEnv(BytecodeLocation loc) {
2351 MOZ_ASSERT(usesEnvironmentChain());
2352
2353 const auto* snapshot = getOpSnapshot<WarpVarEnvironment>(loc);
2354 MOZ_ASSERT(snapshot);
2355
2356 MDefinition* env = current->environmentChain();
2357 MConstant* templateCst = constant(ObjectValue(*snapshot->templateObj()));
2358
2359 auto* ins = MNewVarEnvironmentObject::New(alloc(), templateCst);
2360 current->add(ins);
2361
2362 #ifdef DEBUG
2363 // Assert in debug mode we can elide the post write barrier.
2364 current->add(MAssertCanElidePostWriteBarrier::New(alloc(), ins, env));
2365 #endif
2366
2367 // Initialize the object's reserved slots. No post barrier is needed here,
2368 // for the same reason as in buildNamedLambdaEnv.
2369 current->add(MStoreFixedSlot::NewUnbarriered(
2370 alloc(), ins, EnvironmentObject::enclosingEnvironmentSlot(), env));
2371
2372 current->setEnvironmentChain(ins);
2373 return true;
2374 }
2375
2376 bool WarpBuilder::build_ImplicitThis(BytecodeLocation loc) {
2377 MDefinition* env = current->pop();
2378
2379 auto* ins = MImplicitThis::New(alloc(), env);
2380 current->add(ins);
2381 current->push(ins);
2382 return resumeAfter(ins, loc);
2383 }
2384
2385 bool WarpBuilder::build_CheckClassHeritage(BytecodeLocation loc) {
2386 MDefinition* def = current->pop();
2387 auto* ins = MCheckClassHeritage::New(alloc(), def);
2388 current->add(ins);
2389 current->push(ins);
2390 return resumeAfter(ins, loc);
2391 }
2392
2393 bool WarpBuilder::build_CheckThis(BytecodeLocation loc) {
2394 MDefinition* def = current->pop();
2395 auto* ins = MCheckThis::New(alloc(), def);
2396 current->add(ins);
2397 current->push(ins);
2398 return resumeAfter(ins, loc);
2399 }
2400
2401 bool WarpBuilder::build_CheckThisReinit(BytecodeLocation loc) {
2402 MDefinition* def = current->pop();
2403 auto* ins = MCheckThisReinit::New(alloc(), def);
2404 current->add(ins);
2405 current->push(ins);
2406 return resumeAfter(ins, loc);
2407 }
2408
2409 bool WarpBuilder::build_Generator(BytecodeLocation loc) {
2410 MOZ_ASSERT(usesEnvironmentChain());
2411
2412 MDefinition* callee = getCallee();
2413 MDefinition* environmentChain = current->environmentChain();
2414 MDefinition* argsObj = info().needsArgsObj() ? current->argumentsObject()
2415 : constant(Int32Value(0));
2416
2417 MGenerator* generator =
2418 MGenerator::New(alloc(), callee, environmentChain, argsObj);
2419
2420 current->add(generator);
2421 current->push(generator);
2422 return resumeAfter(generator, loc);
2423 }
2424
2425 bool WarpBuilder::build_AfterYield(BytecodeLocation loc) {
2426 // Unreachable blocks don't need to generate a bail.
2427 if (hasTerminatedBlock()) {
2428 return true;
2429 }
2430
2431 // This comes after a yield, which we generate as a return,
2432 // so we know this should be unreachable code.
2433 //
2434 // We emit an unreachable bail for this, which will assert if we
2435 // ever execute this.
2436 //
2437 // An Unreachable bail, instead of MUnreachable, because MUnreachable
2438 // is a control instruction, and injecting it in the middle of a block
2439 // causes various graph state assertions to fail.
2440 MBail* bail = MBail::New(alloc(), BailoutKind::Unreachable);
2441 current->add(bail);
2442
2443 return true;
2444 }
2445
2446 bool WarpBuilder::build_FinalYieldRval(BytecodeLocation loc) {
2447 MDefinition* gen = current->pop();
2448
2449 auto setSlotNull = [this, gen](size_t slot) {
2450 auto* ins = MStoreFixedSlot::NewBarriered(alloc(), gen, slot,
2451 constant(NullValue()));
2452 current->add(ins);
2453 };
2454
2455 // Close the generator
2456 setSlotNull(AbstractGeneratorObject::calleeSlot());
2457 setSlotNull(AbstractGeneratorObject::envChainSlot());
2458 setSlotNull(AbstractGeneratorObject::argsObjectSlot());
2459 setSlotNull(AbstractGeneratorObject::stackStorageSlot());
2460 setSlotNull(AbstractGeneratorObject::resumeIndexSlot());
2461
2462 // Return
2463 return build_RetRval(loc);
2464 }
2465
2466 bool WarpBuilder::build_AsyncResolve(BytecodeLocation loc) {
2467 MDefinition* generator = current->pop();
2468 MDefinition* value = current->pop();
2469
2470 auto* resolve = MAsyncResolve::New(alloc(), generator, value);
2471 current->add(resolve);
2472 current->push(resolve);
2473 return resumeAfter(resolve, loc);
2474 }
2475
2476 bool WarpBuilder::build_AsyncReject(BytecodeLocation loc) {
2477 MDefinition* generator = current->pop();
2478 MDefinition* stack = current->pop();
2479 MDefinition* reason = current->pop();
2480
2481 auto* reject = MAsyncReject::New(alloc(), generator, reason, stack);
2482 current->add(reject);
2483 current->push(reject);
2484 return resumeAfter(reject, loc);
2485 }
2486
2487 bool WarpBuilder::build_ResumeKind(BytecodeLocation loc) {
2488 GeneratorResumeKind resumeKind = loc.resumeKind();
2489
2490 current->push(constant(Int32Value(static_cast<int32_t>(resumeKind))));
2491 return true;
2492 }
2493
2494 bool WarpBuilder::build_CheckResumeKind(BytecodeLocation loc) {
2495 // Outside of `yield*`, this is normally unreachable code in Warp,
2496 // so we just manipulate the stack appropriately to ensure correct
2497 // MIR generation.
2498 //
2499 // However, `yield*` emits a forced generator return which can be
2500 // warp compiled, so in order to correctly handle these semantics
2501 // we also generate a bailout, so that the forced generator return
2502 // runs in baseline.
2503 MDefinition* resumeKind = current->pop();
2504 MDefinition* gen = current->pop();
2505 MDefinition* rval = current->peek(-1);
2506
2507 // Mark operands as implicitly used.
2508 resumeKind->setImplicitlyUsedUnchecked();
2509 gen->setImplicitlyUsedUnchecked();
2510 rval->setImplicitlyUsedUnchecked();
2511
2512 // Bail out if we encounter CheckResumeKind.
2513 MBail* bail = MBail::New(alloc(), BailoutKind::Inevitable);
2514 current->add(bail);
2515 current->setAlwaysBails();
2516
2517 return true;
2518 }
2519
2520 bool WarpBuilder::build_CanSkipAwait(BytecodeLocation loc) {
2521 MDefinition* val = current->pop();
2522
2523 MCanSkipAwait* canSkip = MCanSkipAwait::New(alloc(), val);
2524 current->add(canSkip);
2525
2526 current->push(val);
2527 current->push(canSkip);
2528
2529 return resumeAfter(canSkip, loc);
2530 }
2531
2532 bool WarpBuilder::build_MaybeExtractAwaitValue(BytecodeLocation loc) {
2533 MDefinition* canSkip = current->pop();
2534 MDefinition* value = current->pop();
2535
2536 MMaybeExtractAwaitValue* extracted =
2537 MMaybeExtractAwaitValue::New(alloc(), value, canSkip);
2538 current->add(extracted);
2539
2540 current->push(extracted);
2541 current->push(canSkip);
2542
2543 return resumeAfter(extracted, loc);
2544 }
2545
2546 bool WarpBuilder::build_InitialYield(BytecodeLocation loc) {
2547 MDefinition* gen = current->pop();
2548 return buildSuspend(loc, gen, gen);
2549 }
2550
2551 bool WarpBuilder::build_Await(BytecodeLocation loc) {
2552 MDefinition* gen = current->pop();
2553 MDefinition* promiseOrGenerator = current->pop();
2554
2555 return buildSuspend(loc, gen, promiseOrGenerator);
2556 }
2557 bool WarpBuilder::build_Yield(BytecodeLocation loc) { return build_Await(loc); }
2558
2559 bool WarpBuilder::buildSuspend(BytecodeLocation loc, MDefinition* gen,
2560 MDefinition* retVal) {
2561 // If required, unbox the generator object explicitly and infallibly.
2562 //
2563 // This is done to avoid fuzz-bugs where ApplyTypeInformation does the
2564 // unboxing, and generates fallible unboxes which can lead to torn object
2565 // state due to `bailAfter`.
2566 MDefinition* genObj = gen;
2567 if (genObj->type() != MIRType::Object) {
2568 auto* unbox =
2569 MUnbox::New(alloc(), gen, MIRType::Object, MUnbox::Mode::Infallible);
2570 current->add(unbox);
2571
2572 genObj = unbox;
2573 }
2574
2575 int32_t slotsToCopy = current->stackDepth() - info().firstLocalSlot();
2576 MOZ_ASSERT(slotsToCopy >= 0);
2577 if (slotsToCopy > 0) {
2578 auto* arrayObj = MLoadFixedSlotAndUnbox::New(
2579 alloc(), genObj, AbstractGeneratorObject::stackStorageSlot(),
2580 MUnbox::Mode::Infallible, MIRType::Object);
2581 current->add(arrayObj);
2582
2583 auto* stackStorage = MElements::New(alloc(), arrayObj);
2584 current->add(stackStorage);
2585
2586 for (int32_t i = 0; i < slotsToCopy; i++) {
2587 if (!alloc().ensureBallast()) {
2588 return false;
2589 }
2590 // Use peekUnchecked because we're also writing out the argument slots
2591 int32_t peek = -slotsToCopy + i;
2592 MDefinition* stackElem = current->peekUnchecked(peek);
2593 auto* store = MStoreElement::NewUnbarriered(
2594 alloc(), stackStorage, constant(Int32Value(i)), stackElem,
2595 /* needsHoleCheck = */ false);
2596
2597 current->add(store);
2598 current->add(MPostWriteBarrier::New(alloc(), arrayObj, stackElem));
2599 }
2600
2601 auto* len = constant(Int32Value(slotsToCopy - 1));
2602
2603 auto* setInitLength =
2604 MSetInitializedLength::New(alloc(), stackStorage, len);
2605 current->add(setInitLength);
2606
2607 auto* setLength = MSetArrayLength::New(alloc(), stackStorage, len);
2608 current->add(setLength);
2609 }
2610
2611 // Update Generator Object state
2612 uint32_t resumeIndex = loc.getResumeIndex();
2613
2614 // This store is unbarriered, as it's only ever storing an integer, and as
2615 // such doesn't partake of object tracing.
2616 current->add(MStoreFixedSlot::NewUnbarriered(
2617 alloc(), genObj, AbstractGeneratorObject::resumeIndexSlot(),
2618 constant(Int32Value(resumeIndex))));
2619
2620 // This store is barriered because it stores an object value.
2621 current->add(MStoreFixedSlot::NewBarriered(
2622 alloc(), genObj, AbstractGeneratorObject::envChainSlot(),
2623 current->environmentChain()));
2624
2625 current->add(
2626 MPostWriteBarrier::New(alloc(), genObj, current->environmentChain()));
2627
2628 // GeneratorReturn will return from the method, however to support MIR
2629 // generation isn't treated like the end of a block
2630 MGeneratorReturn* ret = MGeneratorReturn::New(alloc(), retVal);
2631 current->add(ret);
2632
2633 // To ensure the rest of the MIR generation looks correct, fill the stack with
2634 // the appropriately typed MUnreachable's for the stack pushes from this
2635 // opcode.
2636 auto* unreachableResumeKind =
2637 MUnreachableResult::New(alloc(), MIRType::Int32);
2638 current->add(unreachableResumeKind);
2639 current->push(unreachableResumeKind);
2640
2641 auto* unreachableGenerator =
2642 MUnreachableResult::New(alloc(), MIRType::Object);
2643 current->add(unreachableGenerator);
2644 current->push(unreachableGenerator);
2645
2646 auto* unreachableRval = MUnreachableResult::New(alloc(), MIRType::Value);
2647 current->add(unreachableRval);
2648 current->push(unreachableRval);
2649
2650 return true;
2651 }
2652
2653 bool WarpBuilder::build_AsyncAwait(BytecodeLocation loc) {
2654 MDefinition* gen = current->pop();
2655 MDefinition* value = current->pop();
2656
2657 MAsyncAwait* asyncAwait = MAsyncAwait::New(alloc(), value, gen);
2658 current->add(asyncAwait);
2659 current->push(asyncAwait);
2660 return resumeAfter(asyncAwait, loc);
2661 }
2662
2663 bool WarpBuilder::build_CheckReturn(BytecodeLocation loc) {
2664 MOZ_ASSERT(!script_->noScriptRval());
2665
2666 MDefinition* returnValue = current->getSlot(info().returnValueSlot());
2667 MDefinition* thisValue = current->pop();
2668
2669 auto* ins = MCheckReturn::New(alloc(), returnValue, thisValue);
2670 current->add(ins);
2671 current->push(ins);
2672 return resumeAfter(ins, loc);
2673 }
2674
2675 void WarpBuilder::buildCheckLexicalOp(BytecodeLocation loc) {
2676 JSOp op = loc.getOp();
2677 MOZ_ASSERT(op == JSOp::CheckLexical || op == JSOp::CheckAliasedLexical);
2678
2679 MDefinition* input = current->pop();
2680 MInstruction* lexicalCheck = MLexicalCheck::New(alloc(), input);
2681 current->add(lexicalCheck);
2682 current->push(lexicalCheck);
2683
2684 if (snapshot().bailoutInfo().failedLexicalCheck()) {
2685 // If we have previously had a failed lexical check in Ion, we want to avoid
2686 // hoisting any lexical checks, which can cause spurious failures. In this
2687 // case, we also have to be careful not to hoist any loads of this lexical
2688 // past the check. For unaliased lexical variables, we can set the local
2689 // slot to create a dependency (see below). For aliased lexicals, that
2690 // doesn't work, so we disable LICM instead.
2691 lexicalCheck->setNotMovable();
2692 if (op == JSOp::CheckAliasedLexical) {
2693 mirGen().disableLICM();
2694 }
2695 }
2696
2697 if (op == JSOp::CheckLexical) {
2698 // Set the local slot so that a subsequent GetLocal without a CheckLexical
2699 // (the frontend can elide lexical checks) doesn't let a definition with
2700 // MIRType::MagicUninitializedLexical escape to arbitrary MIR instructions.
2701 // Note that in this case the GetLocal would be unreachable because we throw
2702 // an exception here, but we still generate MIR instructions for it.
2703 uint32_t slot = info().localSlot(loc.local());
2704 current->setSlot(slot, lexicalCheck);
2705 }
2706 }
2707
2708 bool WarpBuilder::build_CheckLexical(BytecodeLocation loc) {
2709 buildCheckLexicalOp(loc);
2710 return true;
2711 }
2712
2713 bool WarpBuilder::build_CheckAliasedLexical(BytecodeLocation loc) {
2714 buildCheckLexicalOp(loc);
2715 return true;
2716 }
2717
2718 bool WarpBuilder::build_InitHomeObject(BytecodeLocation loc) {
2719 MDefinition* homeObject = current->pop();
2720 MDefinition* function = current->pop();
2721
2722 current->add(MPostWriteBarrier::New(alloc(), function, homeObject));
2723
2724 auto* ins = MInitHomeObject::New(alloc(), function, homeObject);
2725 current->add(ins);
2726 current->push(ins);
2727 return true;
2728 }
2729
2730 bool WarpBuilder::build_SuperBase(BytecodeLocation) {
2731 MDefinition* callee = current->pop();
2732
2733 auto* homeObject = MHomeObject::New(alloc(), callee);
2734 current->add(homeObject);
2735
2736 auto* superBase = MHomeObjectSuperBase::New(alloc(), homeObject);
2737 current->add(superBase);
2738 current->push(superBase);
2739 return true;
2740 }
2741
2742 bool WarpBuilder::build_SuperFun(BytecodeLocation) {
2743 MDefinition* callee = current->pop();
2744 auto* ins = MSuperFunction::New(alloc(), callee);
2745 current->add(ins);
2746 current->push(ins);
2747 return true;
2748 }
2749
2750 bool WarpBuilder::build_BuiltinObject(BytecodeLocation loc) {
2751 if (auto* snapshot = getOpSnapshot<WarpBuiltinObject>(loc)) {
2752 JSObject* builtin = snapshot->builtin();
2753 pushConstant(ObjectValue(*builtin));
2754 return true;
2755 }
2756
2757 auto kind = loc.getBuiltinObjectKind();
2758 auto* ins = MBuiltinObject::New(alloc(), kind);
2759 current->add(ins);
2760 current->push(ins);
2761 return resumeAfter(ins, loc);
2762 }
2763
2764 bool WarpBuilder::build_GetIntrinsic(BytecodeLocation loc) {
2765 if (auto* snapshot = getOpSnapshot<WarpGetIntrinsic>(loc)) {
2766 Value intrinsic = snapshot->intrinsic();
2767 pushConstant(intrinsic);
2768 return true;
2769 }
2770
2771 PropertyName* name = loc.getPropertyName(script_);
2772 MCallGetIntrinsicValue* ins = MCallGetIntrinsicValue::New(alloc(), name);
2773 current->add(ins);
2774 current->push(ins);
2775 return resumeAfter(ins, loc);
2776 }
2777
2778 bool WarpBuilder::build_ImportMeta(BytecodeLocation loc) {
2779 ModuleObject* moduleObj = scriptSnapshot()->moduleObject();
2780 MOZ_ASSERT(moduleObj);
2781
2782 MModuleMetadata* ins = MModuleMetadata::New(alloc(), moduleObj);
2783 current->add(ins);
2784 current->push(ins);
2785 return resumeAfter(ins, loc);
2786 }
2787
2788 bool WarpBuilder::build_CallSiteObj(BytecodeLocation loc) {
2789 return build_Object(loc);
2790 }
2791
2792 bool WarpBuilder::build_NewArray(BytecodeLocation loc) {
2793 return buildIC(loc, CacheKind::NewArray, {});
2794 }
2795
2796 bool WarpBuilder::build_NewObject(BytecodeLocation loc) {
2797 return buildIC(loc, CacheKind::NewObject, {});
2798 }
2799
2800 bool WarpBuilder::build_NewInit(BytecodeLocation loc) {
2801 return build_NewObject(loc);
2802 }
2803
2804 bool WarpBuilder::build_Object(BytecodeLocation loc) {
2805 JSObject* obj = loc.getObject(script_);
2806 MConstant* objConst = constant(ObjectValue(*obj));
2807
2808 current->push(objConst);
2809 return true;
2810 }
2811
2812 bool WarpBuilder::buildInitPropGetterSetterOp(BytecodeLocation loc) {
2813 PropertyName* name = loc.getPropertyName(script_);
2814 MDefinition* value = current->pop();
2815 MDefinition* obj = current->peek(-1);
2816
2817 auto* ins = MInitPropGetterSetter::New(alloc(), obj, value, name);
2818 current->add(ins);
2819 return resumeAfter(ins, loc);
2820 }
2821
2822 bool WarpBuilder::build_InitPropGetter(BytecodeLocation loc) {
2823 return buildInitPropGetterSetterOp(loc);
2824 }
2825
2826 bool WarpBuilder::build_InitPropSetter(BytecodeLocation loc) {
2827 return buildInitPropGetterSetterOp(loc);
2828 }
2829
2830 bool WarpBuilder::build_InitHiddenPropGetter(BytecodeLocation loc) {
2831 return buildInitPropGetterSetterOp(loc);
2832 }
2833
2834 bool WarpBuilder::build_InitHiddenPropSetter(BytecodeLocation loc) {
2835 return buildInitPropGetterSetterOp(loc);
2836 }
2837
2838 bool WarpBuilder::buildInitElemGetterSetterOp(BytecodeLocation loc) {
2839 MDefinition* value = current->pop();
2840 MDefinition* id = current->pop();
2841 MDefinition* obj = current->peek(-1);
2842
2843 auto* ins = MInitElemGetterSetter::New(alloc(), obj, id, value);
2844 current->add(ins);
2845 return resumeAfter(ins, loc);
2846 }
2847
2848 bool WarpBuilder::build_InitElemGetter(BytecodeLocation loc) {
2849 return buildInitElemGetterSetterOp(loc);
2850 }
2851
2852 bool WarpBuilder::build_InitElemSetter(BytecodeLocation loc) {
2853 return buildInitElemGetterSetterOp(loc);
2854 }
2855
2856 bool WarpBuilder::build_InitHiddenElemGetter(BytecodeLocation loc) {
2857 return buildInitElemGetterSetterOp(loc);
2858 }
2859
2860 bool WarpBuilder::build_InitHiddenElemSetter(BytecodeLocation loc) {
2861 return buildInitElemGetterSetterOp(loc);
2862 }
2863
2864 bool WarpBuilder::build_In(BytecodeLocation loc) {
2865 MDefinition* obj = current->pop();
2866 MDefinition* id = current->pop();
2867 return buildIC(loc, CacheKind::In, {id, obj});
2868 }
2869
2870 bool WarpBuilder::build_HasOwn(BytecodeLocation loc) {
2871 MDefinition* obj = current->pop();
2872 MDefinition* id = current->pop();
2873 return buildIC(loc, CacheKind::HasOwn, {id, obj});
2874 }
2875
2876 bool WarpBuilder::build_CheckPrivateField(BytecodeLocation loc) {
2877 MDefinition* id = current->peek(-1);
2878 MDefinition* obj = current->peek(-2);
2879 return buildIC(loc, CacheKind::CheckPrivateField, {obj, id});
2880 }
2881
2882 bool WarpBuilder::build_NewPrivateName(BytecodeLocation loc) {
2883 JSAtom* name = loc.getAtom(script_);
2884
2885 auto* ins = MNewPrivateName::New(alloc(), name);
2886 current->add(ins);
2887 current->push(ins);
2888 return resumeAfter(ins, loc);
2889 }
2890
2891 bool WarpBuilder::build_Instanceof(BytecodeLocation loc) {
2892 MDefinition* rhs = current->pop();
2893 MDefinition* obj = current->pop();
2894 return buildIC(loc, CacheKind::InstanceOf, {obj, rhs});
2895 }
2896
2897 bool WarpBuilder::build_NewTarget(BytecodeLocation loc) {
2898 MOZ_ASSERT(script_->isFunction());
2899 MOZ_ASSERT(info().hasFunMaybeLazy());
2900 MOZ_ASSERT(!scriptSnapshot()->isArrowFunction());
2901
2902 if (inlineCallInfo()) {
2903 if (inlineCallInfo()->constructing()) {
2904 current->push(inlineCallInfo()->getNewTarget());
2905 } else {
2906 pushConstant(UndefinedValue());
2907 }
2908 return true;
2909 }
2910
2911 MNewTarget* ins = MNewTarget::New(alloc());
2912 current->add(ins);
2913 current->push(ins);
2914 return true;
2915 }
2916
2917 bool WarpBuilder::build_CheckIsObj(BytecodeLocation loc) {
2918 CheckIsObjectKind kind = loc.getCheckIsObjectKind();
2919
2920 MDefinition* toCheck = current->peek(-1);
2921 if (toCheck->type() == MIRType::Object) {
2922 toCheck->setImplicitlyUsedUnchecked();
2923 return true;
2924 }
2925
2926 MDefinition* val = current->pop();
2927 MCheckIsObj* ins = MCheckIsObj::New(alloc(), val, uint8_t(kind));
2928 current->add(ins);
2929 current->push(ins);
2930 return resumeAfter(ins, loc);
2931 }
2932
2933 bool WarpBuilder::build_CheckObjCoercible(BytecodeLocation loc) {
2934 MDefinition* val = current->pop();
2935 MCheckObjCoercible* ins = MCheckObjCoercible::New(alloc(), val);
2936 current->add(ins);
2937 current->push(ins);
2938 return resumeAfter(ins, loc);
2939 }
2940
2941 MInstruction* WarpBuilder::buildLoadSlot(MDefinition* obj,
2942 uint32_t numFixedSlots,
2943 uint32_t slot) {
2944 if (slot < numFixedSlots) {
2945 MLoadFixedSlot* load = MLoadFixedSlot::New(alloc(), obj, slot);
2946 current->add(load);
2947 return load;
2948 }
2949
2950 MSlots* slots = MSlots::New(alloc(), obj);
2951 current->add(slots);
2952
2953 MLoadDynamicSlot* load =
2954 MLoadDynamicSlot::New(alloc(), slots, slot - numFixedSlots);
2955 current->add(load);
2956 return load;
2957 }
2958
2959 bool WarpBuilder::build_GetImport(BytecodeLocation loc) {
2960 auto* snapshot = getOpSnapshot<WarpGetImport>(loc);
2961
2962 ModuleEnvironmentObject* targetEnv = snapshot->targetEnv();
2963
2964 // Load the target environment slot.
2965 MConstant* obj = constant(ObjectValue(*targetEnv));
2966 auto* load = buildLoadSlot(obj, snapshot->numFixedSlots(), snapshot->slot());
2967
2968 if (snapshot->needsLexicalCheck()) {
2969 // TODO: IonBuilder has code to mark non-movable. See buildCheckLexicalOp.
2970 MInstruction* lexicalCheck = MLexicalCheck::New(alloc(), load);
2971 current->add(lexicalCheck);
2972 current->push(lexicalCheck);
2973 } else {
2974 current->push(load);
2975 }
2976
2977 return true;
2978 }
2979
2980 bool WarpBuilder::build_GetPropSuper(BytecodeLocation loc) {
2981 MDefinition* obj = current->pop();
2982 MDefinition* receiver = current->pop();
2983 return buildIC(loc, CacheKind::GetPropSuper, {obj, receiver});
2984 }
2985
2986 bool WarpBuilder::build_GetElemSuper(BytecodeLocation loc) {
2987 MDefinition* obj = current->pop();
2988 MDefinition* id = current->pop();
2989 MDefinition* receiver = current->pop();
2990 return buildIC(loc, CacheKind::GetElemSuper, {obj, id, receiver});
2991 }
2992
2993 bool WarpBuilder::build_InitProp(BytecodeLocation loc) {
2994 MDefinition* val = current->pop();
2995 MDefinition* obj = current->peek(-1);
2996 return buildIC(loc, CacheKind::SetProp, {obj, val});
2997 }
2998
2999 bool WarpBuilder::build_InitLockedProp(BytecodeLocation loc) {
3000 return build_InitProp(loc);
3001 }
3002
3003 bool WarpBuilder::build_InitHiddenProp(BytecodeLocation loc) {
3004 return build_InitProp(loc);
3005 }
3006
3007 bool WarpBuilder::build_InitElem(BytecodeLocation loc) {
3008 MDefinition* val = current->pop();
3009 MDefinition* id = current->pop();
3010 MDefinition* obj = current->peek(-1);
3011 return buildIC(loc, CacheKind::SetElem, {obj, id, val});
3012 }
3013
3014 bool WarpBuilder::build_InitLockedElem(BytecodeLocation loc) {
3015 return build_InitElem(loc);
3016 }
3017
3018 bool WarpBuilder::build_InitHiddenElem(BytecodeLocation loc) {
3019 return build_InitElem(loc);
3020 }
3021
3022 bool WarpBuilder::build_InitElemArray(BytecodeLocation loc) {
3023 MDefinition* val = current->pop();
3024 MDefinition* obj = current->peek(-1);
3025
3026 // Note: getInitElemArrayIndex asserts the index fits in int32_t.
3027 uint32_t index = loc.getInitElemArrayIndex();
3028 MConstant* indexConst = constant(Int32Value(index));
3029
3030 // Note: InitArrayElemOperation asserts the index does not exceed the array's
3031 // dense element capacity.
3032
3033 auto* elements = MElements::New(alloc(), obj);
3034 current->add(elements);
3035
3036 if (val->type() == MIRType::MagicHole) {
3037 val->setImplicitlyUsedUnchecked();
3038 auto* store = MStoreHoleValueElement::New(alloc(), elements, indexConst);
3039 current->add(store);
3040 } else {
3041 current->add(MPostWriteBarrier::New(alloc(), obj, val));
3042 auto* store =
3043 MStoreElement::NewUnbarriered(alloc(), elements, indexConst, val,
3044 /* needsHoleCheck = */ false);
3045 current->add(store);
3046 }
3047
3048 auto* setLength = MSetInitializedLength::New(alloc(), elements, indexConst);
3049 current->add(setLength);
3050
3051 return resumeAfter(setLength, loc);
3052 }
3053
3054 bool WarpBuilder::build_InitElemInc(BytecodeLocation loc) {
3055 MDefinition* val = current->pop();
3056 MDefinition* index = current->pop();
3057 MDefinition* obj = current->peek(-1);
3058
3059 // Push index + 1.
3060 MConstant* constOne = constant(Int32Value(1));
3061 MAdd* nextIndex = MAdd::New(alloc(), index, constOne, TruncateKind::Truncate);
3062 current->add(nextIndex);
3063 current->push(nextIndex);
3064
3065 return buildIC(loc, CacheKind::SetElem, {obj, index, val});
3066 }
3067
3068 bool WarpBuilder::build_Lambda(BytecodeLocation loc) {
3069 MOZ_ASSERT(usesEnvironmentChain());
3070 return buildIC(loc, CacheKind::Lambda, {});
3071 }
3072
3073 bool WarpBuilder::build_FunWithProto(BytecodeLocation loc) {
3074 MOZ_ASSERT(usesEnvironmentChain());
3075
3076 MDefinition* proto = current->pop();
3077 MDefinition* env = current->environmentChain();
3078
3079 JSFunction* fun = loc.getFunction(script_);
3080 MConstant* funConst = constant(ObjectValue(*fun));
3081
3082 auto* ins = MFunctionWithProto::New(alloc(), env, proto, funConst);
3083 current->add(ins);
3084 current->push(ins);
3085 return resumeAfter(ins, loc);
3086 }
3087
3088 bool WarpBuilder::build_SpreadCall(BytecodeLocation loc) {
3089 bool constructing = false;
3090 CallInfo callInfo(alloc(), constructing, loc.resultIsPopped());
3091 callInfo.initForSpreadCall(current);
3092
3093 // The argument must be an array object. Add an infallible MUnbox if needed,
3094 // but ensure it's not loop hoisted before the branch in the bytecode guarding
3095 // that it's not undefined.
3096 MOZ_ASSERT(callInfo.argc() == 1);
3097 callInfo.setArg(0, unboxObjectInfallible(callInfo.getArg(0), IsMovable::No));
3098
3099 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
3100 return transpileCall(loc, cacheIRSnapshot, &callInfo);
3101 }
3102
3103 bool needsThisCheck = false;
3104 MInstruction* call = makeSpreadCall(callInfo, needsThisCheck);
3105 if (!call) {
3106 return false;
3107 }
3108 call->setBailoutKind(BailoutKind::TooManyArguments);
3109 current->add(call);
3110 current->push(call);
3111 return resumeAfter(call, loc);
3112 }
3113
3114 bool WarpBuilder::build_SpreadNew(BytecodeLocation loc) {
3115 bool constructing = true;
3116 CallInfo callInfo(alloc(), constructing, loc.resultIsPopped());
3117 callInfo.initForSpreadCall(current);
3118
3119 // See build_SpreadCall.
3120 MOZ_ASSERT(callInfo.argc() == 1);
3121 callInfo.setArg(0, unboxObjectInfallible(callInfo.getArg(0), IsMovable::No));
3122
3123 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
3124 return transpileCall(loc, cacheIRSnapshot, &callInfo);
3125 }
3126
3127 buildCreateThis(callInfo);
3128
3129 bool needsThisCheck = true;
3130 MInstruction* call = makeSpreadCall(callInfo, needsThisCheck);
3131 if (!call) {
3132 return false;
3133 }
3134 call->setBailoutKind(BailoutKind::TooManyArguments);
3135 current->add(call);
3136 current->push(call);
3137 return resumeAfter(call, loc);
3138 }
3139
3140 bool WarpBuilder::build_SpreadSuperCall(BytecodeLocation loc) {
3141 return build_SpreadNew(loc);
3142 }
3143
3144 bool WarpBuilder::build_OptimizeSpreadCall(BytecodeLocation loc) {
3145 MDefinition* value = current->pop();
3146 return buildIC(loc, CacheKind::OptimizeSpreadCall, {value});
3147 }
3148
3149 bool WarpBuilder::build_Debugger(BytecodeLocation loc) {
3150 // The |debugger;| statement will bail out to Baseline if the realm is a
3151 // debuggee realm with an onDebuggerStatement hook.
3152 MDebugger* debugger = MDebugger::New(alloc());
3153 current->add(debugger);
3154 return resumeAfter(debugger, loc);
3155 }
3156
3157 bool WarpBuilder::build_TableSwitch(BytecodeLocation loc) {
3158 int32_t low = loc.getTableSwitchLow();
3159 int32_t high = loc.getTableSwitchHigh();
3160 size_t numCases = high - low + 1;
3161
3162 MDefinition* input = current->pop();
3163 MTableSwitch* tableswitch = MTableSwitch::New(alloc(), input, low, high);
3164 current->end(tableswitch);
3165
3166 // Table mapping from target bytecode offset to MTableSwitch successor index.
3167 // This prevents adding multiple predecessor/successor edges to the same
3168 // target block, which isn't valid in MIR.
3169 using TargetToSuccessorMap =
3170 InlineMap<uint32_t, uint32_t, 8, DefaultHasher<uint32_t>,
3171 SystemAllocPolicy>;
3172 TargetToSuccessorMap targetToSuccessor;
3173
3174 // Create |default| edge.
3175 {
3176 BytecodeLocation defaultLoc = loc.getTableSwitchDefaultTarget();
3177 uint32_t defaultOffset = defaultLoc.bytecodeToOffset(script_);
3178
3179 size_t index;
3180 if (!tableswitch->addDefault(nullptr, &index)) {
3181 return false;
3182 }
3183 if (!addPendingEdge(defaultLoc, current, index)) {
3184 return false;
3185 }
3186 if (!targetToSuccessor.put(defaultOffset, index)) {
3187 return false;
3188 }
3189 }
3190
3191 // Add all cases.
3192 for (size_t i = 0; i < numCases; i++) {
3193 BytecodeLocation caseLoc = loc.getTableSwitchCaseTarget(script_, i);
3194 uint32_t caseOffset = caseLoc.bytecodeToOffset(script_);
3195
3196 size_t index;
3197 if (auto p = targetToSuccessor.lookupForAdd(caseOffset)) {
3198 index = p->value();
3199 } else {
3200 if (!tableswitch->addSuccessor(nullptr, &index)) {
3201 return false;
3202 }
3203 if (!addPendingEdge(caseLoc, current, index)) {
3204 return false;
3205 }
3206 if (!targetToSuccessor.add(p, caseOffset, index)) {
3207 return false;
3208 }
3209 }
3210 if (!tableswitch->addCase(index)) {
3211 return false;
3212 }
3213 }
3214
3215 setTerminatedBlock();
3216 return true;
3217 }
3218
3219 bool WarpBuilder::build_Rest(BytecodeLocation loc) {
3220 auto* snapshot = getOpSnapshot<WarpRest>(loc);
3221 Shape* shape = snapshot ? snapshot->shape() : nullptr;
3222
3223 // NOTE: Keep this code in sync with |ArgumentsReplacer|.
3224
3225 if (inlineCallInfo()) {
3226 // If we are inlining, we know the actual arguments.
3227 unsigned numActuals = inlineCallInfo()->argc();
3228 unsigned numFormals = info().nargs() - 1;
3229 unsigned numRest = numActuals > numFormals ? numActuals - numFormals : 0;
3230
3231 // TODO: support pre-tenuring.
3232 gc::Heap heap = gc::Heap::Default;
3233
3234 // Allocate an array of the correct size.
3235 MInstruction* newArray;
3236 if (shape && gc::CanUseFixedElementsForArray(numRest)) {
3237 auto* shapeConstant = MConstant::NewShape(alloc(), shape);
3238 current->add(shapeConstant);
3239 newArray = MNewArrayObject::New(alloc(), shapeConstant, numRest, heap);
3240 } else {
3241 MConstant* templateConst = constant(NullValue());
3242 newArray = MNewArray::NewVM(alloc(), numRest, templateConst, heap);
3243 }
3244 current->add(newArray);
3245 current->push(newArray);
3246
3247 if (numRest == 0) {
3248 // No more updating to do.
3249 return true;
3250 }
3251
3252 MElements* elements = MElements::New(alloc(), newArray);
3253 current->add(elements);
3254
3255 // Unroll the argument copy loop. We don't need to do any bounds or hole
3256 // checking here.
3257 MConstant* index = nullptr;
3258 for (uint32_t i = numFormals; i < numActuals; i++) {
3259 if (!alloc().ensureBallast()) {
3260 return false;
3261 }
3262
3263 index = MConstant::New(alloc(), Int32Value(i - numFormals));
3264 current->add(index);
3265
3266 MDefinition* arg = inlineCallInfo()->argv()[i];
3267 MStoreElement* store =
3268 MStoreElement::NewUnbarriered(alloc(), elements, index, arg,
3269 /* needsHoleCheck = */ false);
3270 current->add(store);
3271 current->add(MPostWriteBarrier::New(alloc(), newArray, arg));
3272 }
3273
3274 // Update the initialized length for all the (necessarily non-hole)
3275 // elements added.
3276 MSetInitializedLength* initLength =
3277 MSetInitializedLength::New(alloc(), elements, index);
3278 current->add(initLength);
3279
3280 return true;
3281 }
3282
3283 MArgumentsLength* numActuals = MArgumentsLength::New(alloc());
3284 current->add(numActuals);
3285
3286 // Pass in the number of actual arguments, the number of formals (not
3287 // including the rest parameter slot itself), and the shape.
3288 unsigned numFormals = info().nargs() - 1;
3289 MRest* rest = MRest::New(alloc(), numActuals, numFormals, shape);
3290 current->add(rest);
3291 current->push(rest);
3292 return true;
3293 }
3294
3295 bool WarpBuilder::build_Try(BytecodeLocation loc) {
3296 graph().setHasTryBlock();
3297
3298 MBasicBlock* pred = current;
3299 if (!startNewBlock(pred, loc.next())) {
3300 return false;
3301 }
3302
3303 pred->end(MGoto::New(alloc(), current));
3304 return true;
3305 }
3306
3307 bool WarpBuilder::build_Finally(BytecodeLocation loc) {
3308 MOZ_ASSERT(graph().hasTryBlock());
3309 return true;
3310 }
3311
3312 bool WarpBuilder::build_Exception(BytecodeLocation) {
3313 MOZ_CRASH("Unreachable because we skip catch-blocks");
3314 }
3315
3316 bool WarpBuilder::build_ExceptionAndStack(BytecodeLocation) {
3317 MOZ_CRASH("Unreachable because we skip catch-blocks");
3318 }
3319
3320 bool WarpBuilder::build_Throw(BytecodeLocation loc) {
3321 MDefinition* def = current->pop();
3322
3323 MThrow* ins = MThrow::New(alloc(), def);
3324 current->add(ins);
3325 if (!resumeAfter(ins, loc)) {
3326 return false;
3327 }
3328
3329 // Terminate the block.
3330 current->end(MUnreachable::New(alloc()));
3331 setTerminatedBlock();
3332 return true;
3333 }
3334
3335 bool WarpBuilder::build_ThrowWithStack(BytecodeLocation loc) {
3336 MDefinition* stack = current->pop();
3337 MDefinition* value = current->pop();
3338
3339 auto* ins = MThrowWithStack::New(alloc(), value, stack);
3340 current->add(ins);
3341 if (!resumeAfter(ins, loc)) {
3342 return false;
3343 }
3344
3345 // Terminate the block.
3346 current->end(MUnreachable::New(alloc()));
3347 setTerminatedBlock();
3348 return true;
3349 }
3350
3351 bool WarpBuilder::build_ThrowSetConst(BytecodeLocation loc) {
3352 auto* ins = MThrowRuntimeLexicalError::New(alloc(), JSMSG_BAD_CONST_ASSIGN);
3353 current->add(ins);
3354 if (!resumeAfter(ins, loc)) {
3355 return false;
3356 }
3357
3358 // Terminate the block.
3359 current->end(MUnreachable::New(alloc()));
3360 setTerminatedBlock();
3361 return true;
3362 }
3363
3364 bool WarpBuilder::build_ThrowMsg(BytecodeLocation loc) {
3365 auto* ins = MThrowMsg::New(alloc(), loc.throwMsgKind());
3366 current->add(ins);
3367 if (!resumeAfter(ins, loc)) {
3368 return false;
3369 }
3370
3371 // Terminate the block.
3372 current->end(MUnreachable::New(alloc()));
3373 setTerminatedBlock();
3374 return true;
3375 }
3376
3377 bool WarpBuilder::buildIC(BytecodeLocation loc, CacheKind kind,
3378 std::initializer_list<MDefinition*> inputs) {
3379 MOZ_ASSERT(loc.opHasIC());
3380
3381 mozilla::DebugOnly<size_t> numInputs = inputs.size();
3382 MOZ_ASSERT(numInputs == NumInputsForCacheKind(kind));
3383
3384 if (auto* cacheIRSnapshot = getOpSnapshot<WarpCacheIR>(loc)) {
3385 return TranspileCacheIRToMIR(this, loc, cacheIRSnapshot, inputs);
3386 }
3387
3388 if (getOpSnapshot<WarpBailout>(loc)) {
3389 for (MDefinition* input : inputs) {
3390 input->setImplicitlyUsedUnchecked();
3391 }
3392 return buildBailoutForColdIC(loc, kind);
3393 }
3394
3395 if (const auto* inliningSnapshot = getOpSnapshot<WarpInlinedCall>(loc)) {
3396 // The CallInfo will be initialized by the transpiler.
3397 bool ignoresRval = BytecodeIsPopped(loc.toRawBytecode());
3398 CallInfo callInfo(alloc(), /*constructing =*/false, ignoresRval);
3399 callInfo.markAsInlined();
3400
3401 if (!TranspileCacheIRToMIR(this, loc, inliningSnapshot->cacheIRSnapshot(),
3402 inputs, &callInfo)) {
3403 return false;
3404 }
3405 return buildInlinedCall(loc, inliningSnapshot, callInfo);
3406 }
3407
3408 // Work around std::initializer_list not defining operator[].
3409 auto getInput = [&](size_t index) -> MDefinition* {
3410 MOZ_ASSERT(index < numInputs);
3411 return inputs.begin()[index];
3412 };
3413
3414 switch (kind) {
3415 case CacheKind::UnaryArith: {
3416 MOZ_ASSERT(numInputs == 1);
3417 auto* ins = MUnaryCache::New(alloc(), getInput(0));
3418 current->add(ins);
3419 current->push(ins);
3420 return resumeAfter(ins, loc);
3421 }
3422 case CacheKind::ToPropertyKey: {
3423 MOZ_ASSERT(numInputs == 1);
3424 auto* ins = MToPropertyKeyCache::New(alloc(), getInput(0));
3425 current->add(ins);
3426 current->push(ins);
3427 return resumeAfter(ins, loc);
3428 }
3429 case CacheKind::BinaryArith: {
3430 MOZ_ASSERT(numInputs == 2);
3431 auto* ins =
3432 MBinaryCache::New(alloc(), getInput(0), getInput(1), MIRType::Value);
3433 current->add(ins);
3434 current->push(ins);
3435 return resumeAfter(ins, loc);
3436 }
3437 case CacheKind::Compare: {
3438 MOZ_ASSERT(numInputs == 2);
3439 auto* ins = MBinaryCache::New(alloc(), getInput(0), getInput(1),
3440 MIRType::Boolean);
3441 current->add(ins);
3442 current->push(ins);
3443 return resumeAfter(ins, loc);
3444 }
3445 case CacheKind::In: {
3446 MOZ_ASSERT(numInputs == 2);
3447 auto* ins = MInCache::New(alloc(), getInput(0), getInput(1));
3448 current->add(ins);
3449 current->push(ins);
3450 return resumeAfter(ins, loc);
3451 }
3452 case CacheKind::HasOwn: {
3453 MOZ_ASSERT(numInputs == 2);
3454 // Note: the MHasOwnCache constructor takes obj/id instead of id/obj.
3455 auto* ins = MHasOwnCache::New(alloc(), getInput(1), getInput(0));
3456 current->add(ins);
3457 current->push(ins);
3458 return resumeAfter(ins, loc);
3459 }
3460 case CacheKind::CheckPrivateField: {
3461 MOZ_ASSERT(numInputs == 2);
3462 auto* ins =
3463 MCheckPrivateFieldCache::New(alloc(), getInput(0), getInput(1));
3464 current->add(ins);
3465 current->push(ins);
3466 return resumeAfter(ins, loc);
3467 }
3468 case CacheKind::InstanceOf: {
3469 MOZ_ASSERT(numInputs == 2);
3470 auto* ins = MInstanceOfCache::New(alloc(), getInput(0), getInput(1));
3471 current->add(ins);
3472 current->push(ins);
3473 return resumeAfter(ins, loc);
3474 }
3475 case CacheKind::BindName: {
3476 MOZ_ASSERT(numInputs == 1);
3477 auto* ins = MBindNameCache::New(alloc(), getInput(0));
3478 current->add(ins);
3479 current->push(ins);
3480 return resumeAfter(ins, loc);
3481 }
3482 case CacheKind::GetIterator: {
3483 MOZ_ASSERT(numInputs == 1);
3484 auto* ins = MGetIteratorCache::New(alloc(), getInput(0));
3485 current->add(ins);
3486 current->push(ins);
3487 return resumeAfter(ins, loc);
3488 }
3489 case CacheKind::GetName: {
3490 MOZ_ASSERT(numInputs == 1);
3491 auto* ins = MGetNameCache::New(alloc(), getInput(0));
3492 current->add(ins);
3493 current->push(ins);
3494 return resumeAfter(ins, loc);
3495 }
3496 case CacheKind::GetProp: {
3497 MOZ_ASSERT(numInputs == 1);
3498 PropertyName* name = loc.getPropertyName(script_);
3499 MConstant* id = constant(StringValue(name));
3500 MDefinition* val = getInput(0);
3501 auto* ins = MGetPropertyCache::New(alloc(), val, id);
3502 current->add(ins);
3503 current->push(ins);
3504 return resumeAfter(ins, loc);
3505 }
3506 case CacheKind::GetElem: {
3507 MOZ_ASSERT(numInputs == 2);
3508 MDefinition* val = getInput(0);
3509 auto* ins = MGetPropertyCache::New(alloc(), val, getInput(1));
3510 current->add(ins);
3511 current->push(ins);
3512 return resumeAfter(ins, loc);
3513 }
3514 case CacheKind::SetProp: {
3515 MOZ_ASSERT(numInputs == 2);
3516 PropertyName* name = loc.getPropertyName(script_);
3517 MConstant* id = constant(StringValue(name));
3518 bool strict = loc.isStrictSetOp();
3519 auto* ins =
3520 MSetPropertyCache::New(alloc(), getInput(0), id, getInput(1), strict);
3521 current->add(ins);
3522 return resumeAfter(ins, loc);
3523 }
3524 case CacheKind::SetElem: {
3525 MOZ_ASSERT(numInputs == 3);
3526 bool strict = loc.isStrictSetOp();
3527 auto* ins = MSetPropertyCache::New(alloc(), getInput(0), getInput(1),
3528 getInput(2), strict);
3529 current->add(ins);
3530 return resumeAfter(ins, loc);
3531 }
3532 case CacheKind::GetPropSuper: {
3533 MOZ_ASSERT(numInputs == 2);
3534 PropertyName* name = loc.getPropertyName(script_);
3535 MConstant* id = constant(StringValue(name));
3536 auto* ins =
3537 MGetPropSuperCache::New(alloc(), getInput(0), getInput(1), id);
3538 current->add(ins);
3539 current->push(ins);
3540 return resumeAfter(ins, loc);
3541 }
3542 case CacheKind::GetElemSuper: {
3543 MOZ_ASSERT(numInputs == 3);
3544 // Note: CacheIR expects obj/id/receiver but MGetPropSuperCache takes
3545 // obj/receiver/id so swap the last two inputs.
3546 auto* ins = MGetPropSuperCache::New(alloc(), getInput(0), getInput(2),
3547 getInput(1));
3548 current->add(ins);
3549 current->push(ins);
3550 return resumeAfter(ins, loc);
3551 }
3552 case CacheKind::OptimizeSpreadCall: {
3553 MOZ_ASSERT(numInputs == 1);
3554 auto* ins = MOptimizeSpreadCallCache::New(alloc(), getInput(0));
3555 current->add(ins);
3556 current->push(ins);
3557 return resumeAfter(ins, loc);
3558 }
3559 case CacheKind::TypeOf: {
3560 // Note: Warp does not have a TypeOf IC, it just inlines the operation.
3561 MOZ_ASSERT(numInputs == 1);
3562 auto* typeOf = MTypeOf::New(alloc(), getInput(0));
3563 current->add(typeOf);
3564
3565 auto* ins = MTypeOfName::New(alloc(), typeOf);
3566 current->add(ins);
3567 current->push(ins);
3568 return true;
3569 }
3570 case CacheKind::TypeOfEq: {
3571 MOZ_ASSERT(numInputs == 1);
3572 auto operand = loc.getTypeofEqOperand();
3573 JSType type = operand.type();
3574 JSOp compareOp = operand.compareOp();
3575 auto* typeOf = MTypeOf::New(alloc(), getInput(0));
3576 current->add(typeOf);
3577
3578 auto* typeInt = MConstant::New(alloc(), Int32Value(type));
3579 current->add(typeInt);
3580
3581 auto* ins = MCompare::New(alloc(), typeOf, typeInt, compareOp,
3582 MCompare::Compare_Int32);
3583 current->add(ins);
3584 current->push(ins);
3585 return true;
3586 }
3587 case CacheKind::NewObject: {
3588 auto* templateConst = constant(NullValue());
3589 MNewObject* ins = MNewObject::NewVM(
3590 alloc(), templateConst, gc::Heap::Default, MNewObject::ObjectLiteral);
3591 current->add(ins);
3592 current->push(ins);
3593 return resumeAfter(ins, loc);
3594 }
3595 case CacheKind::NewArray: {
3596 uint32_t length = loc.getNewArrayLength();
3597 MConstant* templateConst = constant(NullValue());
3598 MNewArray* ins =
3599 MNewArray::NewVM(alloc(), length, templateConst, gc::Heap::Default);
3600 current->add(ins);
3601 current->push(ins);
3602 return true;
3603 }
3604 case CacheKind::CloseIter: {
3605 MOZ_ASSERT(numInputs == 1);
3606 static_assert(sizeof(CompletionKind) == sizeof(uint8_t));
3607 CompletionKind kind = loc.getCompletionKind();
3608 auto* ins = MCloseIterCache::New(alloc(), getInput(0), uint8_t(kind));
3609 current->add(ins);
3610 return resumeAfter(ins, loc);
3611 }
3612 case CacheKind::OptimizeGetIterator: {
3613 MOZ_ASSERT(numInputs == 1);
3614 auto* ins = MOptimizeGetIteratorCache::New(alloc(), getInput(0));
3615 current->add(ins);
3616 current->push(ins);
3617 return resumeAfter(ins, loc);
3618 }
3619 case CacheKind::Lambda: {
3620 MDefinition* env = current->environmentChain();
3621 JSFunction* fun = loc.getFunction(script_);
3622 MConstant* funConst = constant(ObjectValue(*fun));
3623 auto* ins = MLambda::New(alloc(), env, funConst, gc::Heap::Default);
3624 current->add(ins);
3625 current->push(ins);
3626 return resumeAfter(ins, loc);
3627 }
3628 case CacheKind::LazyConstant:
3629 case CacheKind::ToBool:
3630 case CacheKind::Call:
3631 case CacheKind::GetImport:
3632 // We're currently not using an IC or transpiling CacheIR for these kinds.
3633 MOZ_CRASH("Unexpected kind");
3634 }
3635
3636 return true;
3637 }
3638
3639 bool WarpBuilder::buildBailoutForColdIC(BytecodeLocation loc, CacheKind kind) {
3640 MOZ_ASSERT(loc.opHasIC());
3641
3642 MBail* bail = MBail::New(alloc(), BailoutKind::FirstExecution);
3643 current->add(bail);
3644 current->setAlwaysBails();
3645
3646 MIRType resultType;
3647 switch (kind) {
3648 case CacheKind::UnaryArith:
3649 case CacheKind::BinaryArith:
3650 case CacheKind::GetName:
3651 case CacheKind::GetProp:
3652 case CacheKind::GetElem:
3653 case CacheKind::GetPropSuper:
3654 case CacheKind::GetElemSuper:
3655 case CacheKind::GetImport:
3656 case CacheKind::LazyConstant:
3657 case CacheKind::Call:
3658 case CacheKind::ToPropertyKey:
3659 case CacheKind::OptimizeSpreadCall:
3660 resultType = MIRType::Value;
3661 break;
3662 case CacheKind::BindName:
3663 case CacheKind::GetIterator:
3664 case CacheKind::NewArray:
3665 case CacheKind::NewObject:
3666 case CacheKind::Lambda:
3667 resultType = MIRType::Object;
3668 break;
3669 case CacheKind::TypeOf:
3670 resultType = MIRType::String;
3671 break;
3672 case CacheKind::ToBool:
3673 case CacheKind::Compare:
3674 case CacheKind::In:
3675 case CacheKind::HasOwn:
3676 case CacheKind::CheckPrivateField:
3677 case CacheKind::InstanceOf:
3678 case CacheKind::OptimizeGetIterator:
3679 case CacheKind::TypeOfEq:
3680 resultType = MIRType::Boolean;
3681 break;
3682 case CacheKind::SetProp:
3683 case CacheKind::SetElem:
3684 case CacheKind::CloseIter:
3685 return true; // No result.
3686 }
3687
3688 auto* ins = MUnreachableResult::New(alloc(), resultType);
3689 current->add(ins);
3690 current->push(ins);
3691
3692 return true;
3693 }
3694
3695 class MOZ_RAII AutoAccumulateReturns {
3696 MIRGraph& graph_;
3697 MIRGraphReturns* prev_;
3698
3699 public:
3700 AutoAccumulateReturns(MIRGraph& graph, MIRGraphReturns& returns)
3701 : graph_(graph) {
3702 prev_ = graph_.returnAccumulator();
3703 graph_.setReturnAccumulator(&returns);
3704 }
3705 ~AutoAccumulateReturns() { graph_.setReturnAccumulator(prev_); }
3706 };
3707
3708 bool WarpBuilder::buildInlinedCall(BytecodeLocation loc,
3709 const WarpInlinedCall* inlineSnapshot,
3710 CallInfo& callInfo) {
3711 jsbytecode* pc = loc.toRawBytecode();
3712
3713 if (callInfo.isSetter()) {
3714 // build_SetProp pushes the rhs argument onto the stack. Remove it
3715 // in preparation for pushCallStack.
3716 current->pop();
3717 }
3718
3719 callInfo.setImplicitlyUsedUnchecked();
3720
3721 // Capture formals in the outer resume point.
3722 if (!callInfo.pushCallStack(current)) {
3723 return false;
3724 }
3725 MResumePoint* outerResumePoint =
3726 MResumePoint::New(alloc(), current, pc, callInfo.inliningResumeMode());
3727 if (!outerResumePoint) {
3728 return false;
3729 }
3730 current->setOuterResumePoint(outerResumePoint);
3731
3732 // Pop formals again, except leave |callee| on stack for duration of call.
3733 callInfo.popCallStack(current);
3734 current->push(callInfo.callee());
3735
3736 // Build the graph.
3737 CompileInfo* calleeCompileInfo = inlineSnapshot->info();
3738 MIRGraphReturns returns(alloc());
3739 AutoAccumulateReturns aar(graph(), returns);
3740 WarpBuilder inlineBuilder(this, inlineSnapshot->scriptSnapshot(),
3741 *calleeCompileInfo, &callInfo, outerResumePoint);
3742 if (!inlineBuilder.buildInline()) {
3743 // Note: Inlining only aborts on OOM. If inlining would fail for
3744 // any other reason, we detect it in advance and don't inline.
3745 return false;
3746 }
3747
3748 // We mark scripts as uninlineable in BytecodeAnalysis if we cannot
3749 // reach a return statement (without going through a catch/finally).
3750 MOZ_ASSERT(!returns.empty());
3751
3752 // Create return block
3753 BytecodeLocation postCall = loc.next();
3754 MBasicBlock* prev = current;
3755 if (!startNewEntryBlock(prev->stackDepth(), postCall)) {
3756 return false;
3757 }
3758 // Restore previous value of callerResumePoint.
3759 current->setCallerResumePoint(callerResumePoint());
3760 current->inheritSlots(prev);
3761
3762 // Pop |callee|.
3763 current->pop();
3764
3765 // Accumulate return values.
3766 MDefinition* returnValue =
3767 patchInlinedReturns(calleeCompileInfo, callInfo, returns, current);
3768 if (!returnValue) {
3769 return false;
3770 }
3771 current->push(returnValue);
3772
3773 // Initialize entry slots
3774 if (!current->initEntrySlots(alloc())) {
3775 return false;
3776 }
3777
3778 return true;
3779 }
3780
3781 MDefinition* WarpBuilder::patchInlinedReturns(CompileInfo* calleeCompileInfo,
3782 CallInfo& callInfo,
3783 MIRGraphReturns& exits,
3784 MBasicBlock* returnBlock) {
3785 if (exits.length() == 1) {
3786 return patchInlinedReturn(calleeCompileInfo, callInfo, exits[0],
3787 returnBlock);
3788 }
3789
3790 // Accumulate multiple returns with a phi.
3791 MPhi* phi = MPhi::New(alloc());
3792 if (!phi->reserveLength(exits.length())) {
3793 return nullptr;
3794 }
3795
3796 for (auto* exit : exits) {
3797 MDefinition* rdef =
3798 patchInlinedReturn(calleeCompileInfo, callInfo, exit, returnBlock);
3799 if (!rdef) {
3800 return nullptr;
3801 }
3802 phi->addInput(rdef);
3803 }
3804 returnBlock->addPhi(phi);
3805 return phi;
3806 }
3807
3808 MDefinition* WarpBuilder::patchInlinedReturn(CompileInfo* calleeCompileInfo,
3809 CallInfo& callInfo,
3810 MBasicBlock* exit,
3811 MBasicBlock* returnBlock) {
3812 // Replace the MReturn in the exit block with an MGoto branching to
3813 // the return block.
3814 MDefinition* rdef = exit->lastIns()->toReturn()->input();
3815 exit->discardLastIns();
3816
3817 // Constructors must be patched by the caller to always return an object.
3818 // Derived class constructors contain extra bytecode to ensure an object
3819 // is always returned, so no additional patching is needed.
3820 if (callInfo.constructing() &&
3821 !calleeCompileInfo->isDerivedClassConstructor()) {
3822 auto* filter = MReturnFromCtor::New(alloc(), rdef, callInfo.thisArg());
3823 exit->add(filter);
3824 rdef = filter;
3825 } else if (callInfo.isSetter()) {
3826 // Setters return the rhs argument, not whatever value is returned.
3827 rdef = callInfo.getArg(0);
3828 }
3829
3830 exit->end(MGoto::New(alloc(), returnBlock));
3831 if (!returnBlock->addPredecessorWithoutPhis(exit)) {
3832 return nullptr;
3833 }
3834
3835 return rdef;
3836 }