Skip to content

Commit

Permalink
Merged: [maglev] Reset temps on CallBuiltin
Browse files Browse the repository at this point in the history
...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 <[email protected]>
Reviewed-by: Victor Gomes <[email protected]>
Cr-Commit-Position: refs/branch-heads/11.5@{v8#18}
Cr-Branched-From: 0c4044b-refs/heads/11.5.150@{#1}
Cr-Branched-From: b71d303-refs/heads/main@{#87781}
  • Loading branch information
LeszekSwirski authored and V8 LUCI CQ committed Jun 16, 2023
1 parent 571a725 commit 2c9d3c1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/maglev/arm64/maglev-assembler-arm64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions src/maglev/maglev-assembler-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/maglev/maglev-assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/maglev/x64/maglev-assembler-x64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit 2c9d3c1

Please sign in to comment.