Skip to content

Commit

Permalink
8331733: [PPC64] saving and restoring CR is not needed at most places
Browse files Browse the repository at this point in the history
Reviewed-by: mdoerr, amitkumar
  • Loading branch information
Varada M authored and TheRealMDoerr committed Jun 7, 2024
1 parent 6968770 commit 40b2fbd
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 80 deletions.
8 changes: 4 additions & 4 deletions src/hotspot/cpu/ppc/downcallLinker_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2020, 2023 SAP SE. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024 SAP SE. All rights reserved.
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -187,7 +187,7 @@ void DowncallLinker::StubGenerator::generate() {
_oop_maps = _needs_transition ? new OopMapSet() : nullptr;
address start = __ pc();

__ save_LR_CR(tmp); // Save in old frame.
__ save_LR(tmp); // Save in old frame.
__ mr(callerSP, R1_SP); // preset (used to access caller frame argument slots)
__ push_frame(allocated_frame_size, tmp);

Expand Down Expand Up @@ -302,7 +302,7 @@ void DowncallLinker::StubGenerator::generate() {
}

__ pop_frame();
__ restore_LR_CR(tmp);
__ restore_LR(tmp);
__ blr();

//////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/cpu/ppc/gc/g1/g1BarrierSetAssembler_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023 SAP SE. All rights reserved.
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -67,7 +67,7 @@ void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm
__ cmpdi(CCR0, R0, 0);
__ beq(CCR0, filtered);

__ save_LR_CR(R0);
__ save_LR(R0);
__ push_frame(frame_size, R0);
int slot_nr = 0;
__ std(from, frame_size - (++slot_nr) * wordSize, R1_SP);
Expand All @@ -89,7 +89,7 @@ void G1BarrierSetAssembler::gen_write_ref_array_pre_barrier(MacroAssembler* masm
if (preserve1 != noreg) { __ ld(preserve1, frame_size - (++slot_nr) * wordSize, R1_SP); }
if (preserve2 != noreg) { __ ld(preserve2, frame_size - (++slot_nr) * wordSize, R1_SP); }
__ addi(R1_SP, R1_SP, frame_size); // pop_frame()
__ restore_LR_CR(R0);
__ restore_LR(R0);

__ bind(filtered);
}
Expand All @@ -100,13 +100,13 @@ void G1BarrierSetAssembler::gen_write_ref_array_post_barrier(MacroAssembler* mas
int spill_slots = (preserve != noreg) ? 1 : 0;
const int frame_size = align_up(frame::native_abi_reg_args_size + spill_slots * BytesPerWord, frame::alignment_in_bytes);

__ save_LR_CR(R0);
__ save_LR(R0);
__ push_frame(frame_size, R0);
if (preserve != noreg) { __ std(preserve, frame_size - 1 * wordSize, R1_SP); }
__ call_VM_leaf(CAST_FROM_FN_PTR(address, G1BarrierSetRuntime::write_ref_array_post_entry), addr, count);
if (preserve != noreg) { __ ld(preserve, frame_size - 1 * wordSize, R1_SP); }
__ addi(R1_SP, R1_SP, frame_size); // pop_frame();
__ restore_LR_CR(R0);
__ restore_LR(R0);
}

void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, DecoratorSet decorators,
Expand Down Expand Up @@ -206,7 +206,7 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator
__ save_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
}

__ save_LR_CR(tmp1);
__ save_LR(tmp1);
__ push_frame_reg_args(nbytes_save, tmp2);
}

Expand All @@ -220,7 +220,7 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm, Decorator

if (needs_frame) {
__ pop_frame();
__ restore_LR_CR(tmp1);
__ restore_LR(tmp1);

if (preserve_gp_registers) {
__ restore_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018, 2021, Red Hat, Inc. All rights reserved.
* Copyright (c) 2012, 2021 SAP SE. All rights reserved.
* Copyright (c) 2018, 2024, Red Hat, Inc. All rights reserved.
* Copyright (c) 2012, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -150,7 +150,7 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler *masm, Dec
__ std(dst, -BytesPerWord * ++highest_preserve_register_index, R1_SP);
__ std(count, -BytesPerWord * ++highest_preserve_register_index, R1_SP);

__ save_LR_CR(R11_tmp);
__ save_LR(R11_tmp);
__ push_frame_reg_args(-BytesPerWord * highest_preserve_register_index,
R11_tmp);
}
Expand All @@ -169,7 +169,7 @@ void ShenandoahBarrierSetAssembler::arraycopy_prologue(MacroAssembler *masm, Dec
// Restore to-be-preserved registers.
{
__ pop_frame();
__ restore_LR_CR(R11_tmp);
__ restore_LR(R11_tmp);

__ ld(count, -BytesPerWord * highest_preserve_register_index--, R1_SP);
__ ld(dst, -BytesPerWord * highest_preserve_register_index--, R1_SP);
Expand Down Expand Up @@ -304,7 +304,7 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_impl(MacroAssembler *masm
__ save_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
}

__ save_LR_CR(tmp1);
__ save_LR(tmp1);
__ push_frame_reg_args(nbytes_save, tmp2);
}

Expand All @@ -325,7 +325,7 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_impl(MacroAssembler *masm

if (needs_frame) {
__ pop_frame();
__ restore_LR_CR(tmp1);
__ restore_LR(tmp1);

if (preserve_gp_registers) {
__ restore_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
Expand Down Expand Up @@ -477,7 +477,7 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier_impl(
__ save_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
}

__ save_LR_CR(tmp1);
__ save_LR(tmp1);
__ push_frame_reg_args(nbytes_save, tmp1);
}

Expand Down Expand Up @@ -517,7 +517,7 @@ void ShenandoahBarrierSetAssembler::load_reference_barrier_impl(

if (needs_frame) {
__ pop_frame();
__ restore_LR_CR(tmp1);
__ restore_LR(tmp1);

if (preserve_gp_registers) {
__ restore_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers);
Expand Down Expand Up @@ -916,15 +916,15 @@ void ShenandoahBarrierSetAssembler::generate_c1_pre_barrier_runtime_stub(StubAss
// Save to-be-preserved registers.
const int nbytes_save = (MacroAssembler::num_volatile_regs + caller_stack_slots) * BytesPerWord;
__ save_volatile_gprs(R1_SP, -nbytes_save);
__ save_LR_CR(R11_tmp1);
__ save_LR(R11_tmp1);
__ push_frame_reg_args(nbytes_save, R11_tmp1);

// Invoke runtime.
__ call_VM_leaf(CAST_FROM_FN_PTR(address, ShenandoahRuntime::write_ref_field_pre_entry), R0_pre_val, R16_thread);

// Restore to-be-preserved registers.
__ pop_frame();
__ restore_LR_CR(R11_tmp1);
__ restore_LR(R11_tmp1);
__ restore_volatile_gprs(R1_SP, -nbytes_save);

__ bind(skip_barrier);
Expand Down Expand Up @@ -989,15 +989,15 @@ void ShenandoahBarrierSetAssembler::generate_c1_load_reference_barrier_runtime_s
}
assert(jrt_address != nullptr, "load reference barrier runtime routine cannot be found");

__ save_LR_CR(R11_tmp);
__ save_LR(R11_tmp);
__ push_frame_reg_args(nbytes_save, R11_tmp);

// Invoke runtime. Arguments are already stored in the corresponding registers.
__ call_VM_leaf(jrt_address, R3_obj, R4_load_addr);

// Restore to-be-preserved registers.
__ pop_frame();
__ restore_LR_CR(R11_tmp);
__ restore_LR(R11_tmp);
__ restore_volatile_gprs(R1_SP, -nbytes_save, true, false); // Skip 'R3_RET' register.

__ blr();
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/cpu/ppc/gc/x/xBarrierSetAssembler_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 SAP SE. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -116,7 +116,7 @@ void XBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators
__ save_volatile_gprs(R1_SP, -nbytes_save, preserve_fp_registers, preserve_R3);
}

__ save_LR_CR(tmp1);
__ save_LR(tmp1);
__ push_frame_reg_args(nbytes_save, tmp1);
}

Expand All @@ -138,7 +138,7 @@ void XBarrierSetAssembler::load_at(MacroAssembler* masm, DecoratorSet decorators
Register result = R3_RET;
if (needs_frame) {
__ pop_frame();
__ restore_LR_CR(tmp1);
__ restore_LR(tmp1);

if (preserve_R3) {
__ mr(R0, R3_RET);
Expand Down Expand Up @@ -220,7 +220,7 @@ void XBarrierSetAssembler::arraycopy_prologue(MacroAssembler *masm, DecoratorSet
__ std(dst, -BytesPerWord * ++nbytes_save, R1_SP);
__ std(count, -BytesPerWord * ++nbytes_save, R1_SP);

__ save_LR_CR(tmp_R11);
__ save_LR(tmp_R11);
__ push_frame_reg_args(nbytes_save, tmp_R11);
}

Expand All @@ -243,7 +243,7 @@ void XBarrierSetAssembler::arraycopy_prologue(MacroAssembler *masm, DecoratorSet
__ call_VM_leaf(XBarrierSetRuntime::load_barrier_on_oop_array_addr());

__ pop_frame();
__ restore_LR_CR(tmp_R11);
__ restore_LR(tmp_R11);

{
__ ld(count, -BytesPerWord * nbytes_save--, R1_SP);
Expand Down Expand Up @@ -357,7 +357,7 @@ void XBarrierSetAssembler::generate_c1_load_barrier_runtime_stub(StubAssembler*
const int nbytes_save = (MacroAssembler::num_volatile_regs + stack_parameters) * BytesPerWord;

__ save_volatile_gprs(R1_SP, -nbytes_save);
__ save_LR_CR(R0);
__ save_LR(R0);

// Load arguments back again from the stack.
__ ld(R3_ARG1, (intptr_t) -1 * BytesPerWord, R1_SP); // ref
Expand All @@ -371,7 +371,7 @@ void XBarrierSetAssembler::generate_c1_load_barrier_runtime_stub(StubAssembler*
__ mr(R0, R3_RET);

__ pop_frame();
__ restore_LR_CR(R3_RET);
__ restore_LR(R3_RET);
__ restore_volatile_gprs(R1_SP, -nbytes_save);

__ blr();
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/cpu/ppc/gc/z/zBarrierSetAssembler_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -73,7 +73,7 @@ class ZRuntimeCallSpill {
__ save_volatile_gprs(R1_SP, -_nbytes_save, _preserve_fp_registers, preserve_R3);
}

__ save_LR_CR(R0);
__ save_LR(R0);
__ push_frame_reg_args(_nbytes_save, R0);
}
}
Expand All @@ -84,7 +84,7 @@ class ZRuntimeCallSpill {
Register result = R3_RET;
if (_needs_frame) {
__ pop_frame();
__ restore_LR_CR(R0);
__ restore_LR(R0);

if (_preserve_gp_registers) {
bool restore_R3 = _result != R3_ARG1;
Expand Down Expand Up @@ -785,7 +785,7 @@ void ZBarrierSetAssembler::generate_c1_load_barrier_runtime_stub(StubAssembler*
const int nbytes_save = (MacroAssembler::num_volatile_regs + stack_parameters) * BytesPerWord;

__ save_volatile_gprs(R1_SP, -nbytes_save);
__ save_LR_CR(R0);
__ save_LR(R0);

// Load arguments back again from the stack.
__ ld(R3_ARG1, -1 * BytesPerWord, R1_SP); // ref
Expand All @@ -799,7 +799,7 @@ void ZBarrierSetAssembler::generate_c1_load_barrier_runtime_stub(StubAssembler*
__ mr(R0, R3_RET);

__ pop_frame();
__ restore_LR_CR(R3_RET);
__ restore_LR(R3_RET);
__ restore_volatile_gprs(R1_SP, -nbytes_save);

__ blr();
Expand All @@ -815,7 +815,7 @@ void ZBarrierSetAssembler::generate_c1_store_barrier_runtime_stub(StubAssembler*
__ save_volatile_gprs(R1_SP, -nbytes_save);
__ mr(R3_ARG1, R0); // store address

__ save_LR_CR(R0);
__ save_LR(R0);
__ push_frame_reg_args(nbytes_save, R0);

if (self_healing) {
Expand All @@ -825,7 +825,7 @@ void ZBarrierSetAssembler::generate_c1_store_barrier_runtime_stub(StubAssembler*
}

__ pop_frame();
__ restore_LR_CR(R3_RET);
__ restore_LR(R3_RET);
__ restore_volatile_gprs(R1_SP, -nbytes_save);

__ blr();
Expand Down
20 changes: 14 additions & 6 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
* Copyright (c) 2012, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -895,18 +895,26 @@ void MacroAssembler::restore_volatile_gprs(Register src, int offset, bool includ
}
}

void MacroAssembler::save_LR_CR(Register tmp) {
mfcr(tmp);
std(tmp, _abi0(cr), R1_SP);
void MacroAssembler::save_LR(Register tmp) {
mflr(tmp);
std(tmp, _abi0(lr), R1_SP);
// Tmp must contain lr on exit! (see return_addr and prolog in ppc64.ad)
}

void MacroAssembler::restore_LR_CR(Register tmp) {
void MacroAssembler::restore_LR(Register tmp) {
assert(tmp != R1_SP, "must be distinct");
ld(tmp, _abi0(lr), R1_SP);
mtlr(tmp);
}

void MacroAssembler::save_LR_CR(Register tmp) {
mfcr(tmp);
std(tmp, _abi0(cr), R1_SP);
save_LR(tmp);
// Tmp must contain lr on exit! (see return_addr and prolog in ppc64.ad)
}

void MacroAssembler::restore_LR_CR(Register tmp) {
restore_LR(tmp);
ld(tmp, _abi0(cr), R1_SP);
mtcr(tmp);
}
Expand Down
6 changes: 4 additions & 2 deletions src/hotspot/cpu/ppc/macroAssembler_ppc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
* Copyright (c) 2012, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -298,7 +298,9 @@ class MacroAssembler: public Assembler {
bool include_fp_regs = true, bool include_R3_RET_reg = true);
void restore_volatile_gprs(Register src_base, int offset,
bool include_fp_regs = true, bool include_R3_RET_reg = true);
void save_LR_CR( Register tmp); // tmp contains LR on return.
void save_LR(Register tmp);
void restore_LR(Register tmp);
void save_LR_CR(Register tmp); // tmp contains LR on return.
void restore_LR_CR(Register tmp);

// Get current PC using bl-next-instruction trick.
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/cpu/ppc/methodHandles_ppc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023 SAP SE. All rights reserved.
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -581,7 +581,7 @@ void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adapt
const Register tmp = R11; // Will be preserved.
const int nbytes_save = MacroAssembler::num_volatile_regs * 8;
__ save_volatile_gprs(R1_SP, -nbytes_save); // except R0
__ save_LR_CR(tmp); // save in old frame
__ save_LR(tmp); // save in old frame

__ mr(R5_ARG3, R1_SP); // saved_sp
__ push_frame_reg_args(nbytes_save, tmp);
Expand All @@ -592,7 +592,7 @@ void MethodHandles::trace_method_handle(MacroAssembler* _masm, const char* adapt
__ call_VM_leaf(CAST_FROM_FN_PTR(address, trace_method_handle_stub));

__ pop_frame();
__ restore_LR_CR(tmp);
__ restore_LR(tmp);
__ restore_volatile_gprs(R1_SP, -nbytes_save); // except R0

BLOCK_COMMENT("} trace_method_handle");
Expand Down
Loading

1 comment on commit 40b2fbd

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.