Commit 37b59991 authored by Jiayao Lin's avatar Jiayao Lin Committed by Commit Bot

[ppc] Port native routines to use UseScratchRegisterScope

Change-Id: I8034f64ba412a7d880fdc1b7bc4dce0b41fe3114
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1696915Reviewed-by: 's avatarJunliang Yan <jyan@ca.ibm.com>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#62786}
parent 7696e532
This diff is collapsed.
...@@ -224,6 +224,7 @@ void Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) { ...@@ -224,6 +224,7 @@ void Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) {
Assembler::Assembler(const AssemblerOptions& options, Assembler::Assembler(const AssemblerOptions& options,
std::unique_ptr<AssemblerBuffer> buffer) std::unique_ptr<AssemblerBuffer> buffer)
: AssemblerBase(options, std::move(buffer)), : AssemblerBase(options, std::move(buffer)),
scratch_register_list_(ip.bit()),
constant_pool_builder_(kLoadPtrMaxReachBits, kLoadDoubleMaxReachBits) { constant_pool_builder_(kLoadPtrMaxReachBits, kLoadDoubleMaxReachBits) {
reloc_info_writer.Reposition(buffer_start_ + buffer_->size(), pc_); reloc_info_writer.Reposition(buffer_start_ + buffer_->size(), pc_);
...@@ -1947,6 +1948,24 @@ PatchingAssembler::~PatchingAssembler() { ...@@ -1947,6 +1948,24 @@ PatchingAssembler::~PatchingAssembler() {
DCHECK_EQ(reloc_info_writer.pos(), buffer_start_ + buffer_->size()); DCHECK_EQ(reloc_info_writer.pos(), buffer_start_ + buffer_->size());
} }
UseScratchRegisterScope::UseScratchRegisterScope(Assembler* assembler)
: assembler_(assembler),
old_available_(*assembler->GetScratchRegisterList()) {}
UseScratchRegisterScope::~UseScratchRegisterScope() {
*assembler_->GetScratchRegisterList() = old_available_;
}
Register UseScratchRegisterScope::Acquire() {
RegList* available = assembler_->GetScratchRegisterList();
DCHECK_NOT_NULL(available);
DCHECK_NE(*available, 0);
int index = static_cast<int>(base::bits::CountTrailingZeros32(*available));
Register reg = Register::from_code(index);
*available &= ~reg.bit();
return reg;
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -437,6 +437,7 @@ class Assembler : public AssemblerBase { ...@@ -437,6 +437,7 @@ class Assembler : public AssemblerBase {
PPC_XX3_OPCODE_LIST(DECLARE_PPC_XX3_INSTRUCTIONS) PPC_XX3_OPCODE_LIST(DECLARE_PPC_XX3_INSTRUCTIONS)
#undef DECLARE_PPC_XX3_INSTRUCTIONS #undef DECLARE_PPC_XX3_INSTRUCTIONS
RegList* GetScratchRegisterList() { return &scratch_register_list_; }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Code generation // Code generation
...@@ -1182,6 +1183,9 @@ class Assembler : public AssemblerBase { ...@@ -1182,6 +1183,9 @@ class Assembler : public AssemblerBase {
static constexpr int kMaxRelocSize = RelocInfoWriter::kMaxSize; static constexpr int kMaxRelocSize = RelocInfoWriter::kMaxSize;
std::vector<DeferredRelocInfo> relocations_; std::vector<DeferredRelocInfo> relocations_;
// Scratch registers available for use by the Assembler.
RegList scratch_register_list_;
// The bound position, before this we cannot do instruction elimination. // The bound position, before this we cannot do instruction elimination.
int last_bound_pos_; int last_bound_pos_;
// Optimizable cmpi information. // Optimizable cmpi information.
...@@ -1297,6 +1301,7 @@ class Assembler : public AssemblerBase { ...@@ -1297,6 +1301,7 @@ class Assembler : public AssemblerBase {
friend class RelocInfo; friend class RelocInfo;
friend class BlockTrampolinePoolScope; friend class BlockTrampolinePoolScope;
friend class EnsureSpace; friend class EnsureSpace;
friend class UseScratchRegisterScope;
}; };
class EnsureSpace { class EnsureSpace {
...@@ -1311,6 +1316,24 @@ class PatchingAssembler : public Assembler { ...@@ -1311,6 +1316,24 @@ class PatchingAssembler : public Assembler {
~PatchingAssembler(); ~PatchingAssembler();
}; };
class V8_EXPORT_PRIVATE UseScratchRegisterScope {
public:
explicit UseScratchRegisterScope(Assembler* assembler);
~UseScratchRegisterScope();
Register Acquire();
// Check if we have registers available to acquire.
bool CanAcquire() const { return *assembler_->GetScratchRegisterList() != 0; }
private:
friend class Assembler;
friend class TurboAssembler;
Assembler* assembler_;
RegList old_available_;
};
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -56,11 +56,13 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm, ...@@ -56,11 +56,13 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm,
__ StoreP(ToRegister(i), MemOperand(sp, kPointerSize * i)); __ StoreP(ToRegister(i), MemOperand(sp, kPointerSize * i));
} }
} }
{
__ mov(ip, Operand(ExternalReference::Create( UseScratchRegisterScope temps(masm);
IsolateAddressId::kCEntryFPAddress, isolate))); Register scratch = temps.Acquire();
__ StoreP(fp, MemOperand(ip)); __ mov(scratch, Operand(ExternalReference::Create(
IsolateAddressId::kCEntryFPAddress, isolate)));
__ StoreP(fp, MemOperand(scratch));
}
const int kSavedRegistersAreaSize = const int kSavedRegistersAreaSize =
(kNumberOfRegisters * kPointerSize) + kDoubleRegsSize + kFloatRegsSize; (kNumberOfRegisters * kPointerSize) + kDoubleRegsSize + kFloatRegsSize;
...@@ -210,19 +212,27 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm, ...@@ -210,19 +212,27 @@ void Deoptimizer::GenerateDeoptimizationEntries(MacroAssembler* masm,
__ push(r9); __ push(r9);
// Restore the registers from the last output frame. // Restore the registers from the last output frame.
DCHECK(!(ip.bit() & restored_regs)); {
__ mr(ip, r5); UseScratchRegisterScope temps(masm);
for (int i = kNumberOfRegisters - 1; i >= 0; i--) { Register scratch = temps.Acquire();
int offset = (i * kPointerSize) + FrameDescription::registers_offset(); DCHECK(!(scratch.bit() & restored_regs));
if ((restored_regs & (1 << i)) != 0) { __ mr(scratch, r5);
__ LoadP(ToRegister(i), MemOperand(ip, offset)); for (int i = kNumberOfRegisters - 1; i >= 0; i--) {
int offset = (i * kPointerSize) + FrameDescription::registers_offset();
if ((restored_regs & (1 << i)) != 0) {
__ LoadP(ToRegister(i), MemOperand(scratch, offset));
}
} }
} }
__ pop(ip); // get continuation, leave pc on stack {
__ pop(r0); UseScratchRegisterScope temps(masm);
__ mtlr(r0); Register scratch = temps.Acquire();
__ Jump(ip); __ pop(scratch); // get continuation, leave pc on stack
__ pop(r0);
__ mtlr(r0);
__ Jump(scratch);
}
__ stop(); __ stop();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment