diff --git a/src/maglev/arm64/maglev-assembler-arm64-inl.h b/src/maglev/arm64/maglev-assembler-arm64-inl.h index 3172031464bb..57d4da944c91 100644 --- a/src/maglev/arm64/maglev-assembler-arm64-inl.h +++ b/src/maglev/arm64/maglev-assembler-arm64-inl.h @@ -64,6 +64,11 @@ class MaglevAssembler::ScratchRegisterScope { ~ScratchRegisterScope() { masm_->scratch_register_scope_ = prev_scope_; } + void ResetToDefault() { + wrapped_scope_.SetAvailable(masm_->DefaultTmpList()); + wrapped_scope_.SetAvailableFP(masm_->DefaultFPTmpList()); + } + Register Acquire() { return wrapped_scope_.AcquireX(); } void Include(Register reg) { wrapped_scope_.Include(reg); } void Include(const RegList list) { diff --git a/src/maglev/maglev-assembler-inl.h b/src/maglev/maglev-assembler-inl.h index 44b3b75d3409..e7a29b6f8cfa 100644 --- a/src/maglev/maglev-assembler-inl.h +++ b/src/maglev/maglev-assembler-inl.h @@ -282,6 +282,25 @@ inline void MaglevAssembler::LoadTaggedSignedField(Register result, MacroAssembler::LoadTaggedField(result, FieldMemOperand(object, offset)); } +inline void MaglevAssembler::CallBuiltin(Builtin builtin) { + // Temporaries have to be reset before calling CallBuiltin, in case it uses + // temporaries that alias register parameters. + ScratchRegisterScope reset_temps(this); + reset_temps.ResetToDefault(); + + // Make sure that none of the register parameters alias the default + // temporaries. +#ifdef DEBUG + CallInterfaceDescriptor descriptor = + Builtins::CallInterfaceDescriptorFor(builtin); + for (int i = 0; i < descriptor.GetRegisterParameterCount(); ++i) { + DCHECK(!reset_temps.Available().has(descriptor.GetRegisterParameter(i))); + } +#endif + + MacroAssembler::CallBuiltin(builtin); +} + } // namespace maglev } // namespace internal } // namespace v8 diff --git a/src/maglev/maglev-assembler.h b/src/maglev/maglev-assembler.h index c5b3fc29ec66..ba5d8df05880 100644 --- a/src/maglev/maglev-assembler.h +++ b/src/maglev/maglev-assembler.h @@ -281,6 +281,7 @@ class MaglevAssembler : public MacroAssembler { inline void CompareFloat64(DoubleRegister src1, DoubleRegister src2); inline void CallSelf(); + inline void CallBuiltin(Builtin builtin); inline void Jump(Label* target, Label::Distance distance = Label::kFar); inline void JumpIf(Condition cond, Label* target, diff --git a/src/maglev/x64/maglev-assembler-x64-inl.h b/src/maglev/x64/maglev-assembler-x64-inl.h index 110de7d73b1d..94482e77c998 100644 --- a/src/maglev/x64/maglev-assembler-x64-inl.h +++ b/src/maglev/x64/maglev-assembler-x64-inl.h @@ -88,6 +88,11 @@ class MaglevAssembler::ScratchRegisterScope { } ~ScratchRegisterScope() { masm_->scratch_register_scope_ = prev_scope_; } + void ResetToDefault() { + available_ = {}; + available_double_ = {}; + } + Register Acquire() { return available_.PopFirst(); } void Include(Register reg) { available_.set(reg); } void Include(const RegList list) { available_ = available_ | list; }