void CodeGeneratorMIPS64::visitUnbox(LUnbox* unbox) { MUnbox* mir = unbox->mir(); if (mir->fallible()) { const ValueOperand value = ToValue(unbox, LUnbox::Input); masm.splitTag(value, SecondScratchReg); bailoutCmp32(Assembler::NotEqual, SecondScratchReg, Imm32(MIRTypeToTag(mir->type())), unbox->snapshot()); } LAllocation* input = unbox->getOperand(LUnbox::Input); Register result = ToRegister(unbox->output()); if (input->isRegister()) { Register inputReg = ToRegister(input); switch (mir->type()) { case MIRType::Int32: masm.unboxInt32(inputReg, result); break; case MIRType::Boolean: masm.unboxBoolean(inputReg, result); break; case MIRType::Object: masm.unboxObject(inputReg, result); break; case MIRType::String: masm.unboxString(inputReg, result); break; case MIRType::Symbol: masm.unboxSymbol(inputReg, result); break; default: MOZ_CRASH("Given MIRType cannot be unboxed."); } return; } Address inputAddr = ToAddress(input); switch (mir->type()) { case MIRType::Int32: masm.unboxInt32(inputAddr, result); break; case MIRType::Boolean: masm.unboxBoolean(inputAddr, result); break; case MIRType::Object: masm.unboxObject(inputAddr, result); break; case MIRType::String: masm.unboxString(inputAddr, result); break; case MIRType::Symbol: masm.unboxSymbol(inputAddr, result); break; default: MOZ_CRASH("Given MIRType cannot be unboxed."); } }
bool AllocationIntegrityState::checkSafepointAllocation(LInstruction* ins, uint32_t vreg, LAllocation alloc, bool populateSafepoints) { LSafepoint* safepoint = ins->safepoint(); MOZ_ASSERT(safepoint); if (ins->isCall() && alloc.isRegister()) return true; if (alloc.isRegister()) { AnyRegister reg = alloc.toRegister(); if (populateSafepoints) safepoint->addLiveRegister(reg); MOZ_ASSERT(safepoint->liveRegs().has(reg)); } // The |this| argument slot is implicitly included in all safepoints. if (alloc.isArgument() && alloc.toArgument()->index() < THIS_FRAME_ARGSLOT + sizeof(Value)) return true; LDefinition::Type type = virtualRegisters[vreg] ? virtualRegisters[vreg]->type() : LDefinition::GENERAL; switch (type) { case LDefinition::OBJECT: if (populateSafepoints) { JitSpew(JitSpew_RegAlloc, "Safepoint object v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addGcPointer(alloc)) return false; } MOZ_ASSERT(safepoint->hasGcPointer(alloc)); break; case LDefinition::SLOTS: if (populateSafepoints) { JitSpew(JitSpew_RegAlloc, "Safepoint slots v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addSlotsOrElementsPointer(alloc)) return false; } MOZ_ASSERT(safepoint->hasSlotsOrElementsPointer(alloc)); break; #ifdef JS_NUNBOX32 // Do not assert that safepoint information for nunbox types is complete, // as if a vreg for a value's components are copied in multiple places // then the safepoint information may not reflect all copies. All copies // of payloads must be reflected, however, for generational GC. case LDefinition::TYPE: if (populateSafepoints) { JitSpew(JitSpew_RegAlloc, "Safepoint type v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addNunboxType(vreg, alloc)) return false; } break; case LDefinition::PAYLOAD: if (populateSafepoints) { JitSpew(JitSpew_RegAlloc, "Safepoint payload v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addNunboxPayload(vreg, alloc)) return false; } MOZ_ASSERT(safepoint->hasNunboxPayload(alloc)); break; #else case LDefinition::BOX: if (populateSafepoints) { JitSpew(JitSpew_RegAlloc, "Safepoint boxed value v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addBoxedValue(alloc)) return false; } MOZ_ASSERT(safepoint->hasBoxedValue(alloc)); break; #endif default: break; } return true; }
bool GreedyAllocator::allocateDefinition(LInstruction *ins, LDefinition *def) { VirtualRegister *vr = getVirtualRegister(def); LAllocation output; switch (def->policy()) { case LDefinition::PASSTHROUGH: // This is purely passthru, so ignore it. return true; case LDefinition::DEFAULT: case LDefinition::MUST_REUSE_INPUT: { AnyRegister reg; // Either take the register requested, or allocate a new one. if (def->policy() == LDefinition::MUST_REUSE_INPUT && ins->getOperand(def->getReusedInput())->toUse()->isFixedRegister()) { LAllocation *a = ins->getOperand(def->getReusedInput()); VirtualRegister *vuse = getVirtualRegister(a->toUse()); reg = GetFixedRegister(vuse->def, a->toUse()); } else if (vr->hasRegister()) { reg = vr->reg(); } else { if (!allocate(vr->type(), DISALLOW, ®)) return false; } if (def->policy() == LDefinition::MUST_REUSE_INPUT) { LUse *use = ins->getOperand(def->getReusedInput())->toUse(); VirtualRegister *vuse = getVirtualRegister(use); // If the use already has the given register, we need to evict. if (vuse->hasRegister() && vuse->reg() == reg) { if (!evict(reg)) return false; } // Make sure our input is using a fixed register. if (reg.isFloat()) *use = LUse(reg.fpu(), use->virtualRegister()); else *use = LUse(reg.gpr(), use->virtualRegister()); } output = LAllocation(reg); break; } case LDefinition::PRESET: { // Eviction and disallowing occurred during the definition // pre-scan pass. output = *def->output(); break; } } if (output.isRegister()) { JS_ASSERT_IF(output.isFloatReg(), disallowed.has(output.toFloatReg()->reg())); JS_ASSERT_IF(output.isGeneralReg(), disallowed.has(output.toGeneralReg()->reg())); } // Finally, set the output. def->setOutput(output); return true; }
bool AllocationIntegrityState::checkSafepointAllocation(LInstruction *ins, uint32_t vreg, LAllocation alloc, bool populateSafepoints) { LSafepoint *safepoint = ins->safepoint(); JS_ASSERT(safepoint); if (ins->isCall() && alloc.isRegister()) return true; if (alloc.isRegister()) { AnyRegister reg = alloc.toRegister(); if (populateSafepoints) safepoint->addLiveRegister(reg); JS_ASSERT(safepoint->liveRegs().has(reg)); } LDefinition::Type type = virtualRegisters[vreg] ? virtualRegisters[vreg]->type() : LDefinition::GENERAL; switch (type) { case LDefinition::OBJECT: if (populateSafepoints) { IonSpew(IonSpew_RegAlloc, "Safepoint object v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addGcPointer(alloc)) return false; } JS_ASSERT(safepoint->hasGcPointer(alloc)); break; #ifdef JS_NUNBOX32 // Do not assert that safepoint information for nunboxes is complete, // as if a vreg for a value's components are copied in multiple places // then the safepoint information may not reflect all copies. // See SafepointWriter::writeNunboxParts. case LDefinition::TYPE: if (populateSafepoints) { IonSpew(IonSpew_RegAlloc, "Safepoint type v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addNunboxType(vreg, alloc)) return false; } break; case LDefinition::PAYLOAD: if (populateSafepoints) { IonSpew(IonSpew_RegAlloc, "Safepoint payload v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addNunboxPayload(vreg, alloc)) return false; } break; #else case LDefinition::BOX: if (populateSafepoints) { IonSpew(IonSpew_RegAlloc, "Safepoint boxed value v%u i%u %s", vreg, ins->id(), alloc.toString()); if (!safepoint->addBoxedValue(alloc)) return false; } JS_ASSERT(safepoint->hasBoxedValue(alloc)); break; #endif default: break; } return true; }