From 2c9d3c1d6ab2efbc4c45b7051bbe18847078d1d2 Mon Sep 17 00:00:00 2001 From: Leszek Swirski Date: Wed, 7 Jun 2023 11:53:55 +0200 Subject: [PATCH] Merged: [maglev] Reset temps on CallBuiltin ...to avoid temporaries clobbering parameters. Bug: v8:7700 (cherry picked from commit f7eda06b95654722f1b0720b9dfe0ff959564d71) Change-Id: I92e1bbb91913d618bf66562ee79c8a5cc8d5c483 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4614667 Commit-Queue: Leszek Swirski Reviewed-by: Victor Gomes Cr-Commit-Position: refs/branch-heads/11.5@{#18} Cr-Branched-From: 0c4044b7336787781646e48b2f98f0c7d1b400a5-refs/heads/11.5.150@{#1} Cr-Branched-From: b71d3038a7d99c79e1c21239e8ae07da5fc8c90b-refs/heads/main@{#87781} --- src/maglev/arm64/maglev-assembler-arm64-inl.h | 5 +++++ src/maglev/maglev-assembler-inl.h | 19 +++++++++++++++++++ src/maglev/maglev-assembler.h | 1 + src/maglev/x64/maglev-assembler-x64-inl.h | 5 +++++ 4 files changed, 30 insertions(+) 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; }