Skip to content

Commit

Permalink
8292153: x86: Represent Registers as values
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, aph
  • Loading branch information
Vladimir Ivanov committed Aug 11, 2022
1 parent dedc05c commit 755ecf6
Show file tree
Hide file tree
Showing 28 changed files with 472 additions and 423 deletions.
90 changes: 45 additions & 45 deletions src/hotspot/cpu/x86/assembler_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,33 +63,33 @@ class Argument {

#ifdef _WIN64

REGISTER_DECLARATION(Register, c_rarg0, rcx);
REGISTER_DECLARATION(Register, c_rarg1, rdx);
REGISTER_DECLARATION(Register, c_rarg2, r8);
REGISTER_DECLARATION(Register, c_rarg3, r9);
constexpr Register c_rarg0 = rcx;
constexpr Register c_rarg1 = rdx;
constexpr Register c_rarg2 = r8;
constexpr Register c_rarg3 = r9;

REGISTER_DECLARATION(XMMRegister, c_farg0, xmm0);
REGISTER_DECLARATION(XMMRegister, c_farg1, xmm1);
REGISTER_DECLARATION(XMMRegister, c_farg2, xmm2);
REGISTER_DECLARATION(XMMRegister, c_farg3, xmm3);
constexpr XMMRegister c_farg0 = xmm0;
constexpr XMMRegister c_farg1 = xmm1;
constexpr XMMRegister c_farg2 = xmm2;
constexpr XMMRegister c_farg3 = xmm3;

#else

REGISTER_DECLARATION(Register, c_rarg0, rdi);
REGISTER_DECLARATION(Register, c_rarg1, rsi);
REGISTER_DECLARATION(Register, c_rarg2, rdx);
REGISTER_DECLARATION(Register, c_rarg3, rcx);
REGISTER_DECLARATION(Register, c_rarg4, r8);
REGISTER_DECLARATION(Register, c_rarg5, r9);

REGISTER_DECLARATION(XMMRegister, c_farg0, xmm0);
REGISTER_DECLARATION(XMMRegister, c_farg1, xmm1);
REGISTER_DECLARATION(XMMRegister, c_farg2, xmm2);
REGISTER_DECLARATION(XMMRegister, c_farg3, xmm3);
REGISTER_DECLARATION(XMMRegister, c_farg4, xmm4);
REGISTER_DECLARATION(XMMRegister, c_farg5, xmm5);
REGISTER_DECLARATION(XMMRegister, c_farg6, xmm6);
REGISTER_DECLARATION(XMMRegister, c_farg7, xmm7);
constexpr Register c_rarg0 = rdi;
constexpr Register c_rarg1 = rsi;
constexpr Register c_rarg2 = rdx;
constexpr Register c_rarg3 = rcx;
constexpr Register c_rarg4 = r8;
constexpr Register c_rarg5 = r9;

constexpr XMMRegister c_farg0 = xmm0;
constexpr XMMRegister c_farg1 = xmm1;
constexpr XMMRegister c_farg2 = xmm2;
constexpr XMMRegister c_farg3 = xmm3;
constexpr XMMRegister c_farg4 = xmm4;
constexpr XMMRegister c_farg5 = xmm5;
constexpr XMMRegister c_farg6 = xmm6;
constexpr XMMRegister c_farg7 = xmm7;

#endif // _WIN64

Expand All @@ -109,33 +109,33 @@ REGISTER_DECLARATION(XMMRegister, c_farg7, xmm7);
// | j_rarg5 j_rarg0 j_rarg1 j_rarg2 j_rarg3 j_rarg4 |
// |-------------------------------------------------------|

REGISTER_DECLARATION(Register, j_rarg0, c_rarg1);
REGISTER_DECLARATION(Register, j_rarg1, c_rarg2);
REGISTER_DECLARATION(Register, j_rarg2, c_rarg3);
constexpr Register j_rarg0 = c_rarg1;
constexpr Register j_rarg1 = c_rarg2;
constexpr Register j_rarg2 = c_rarg3;
// Windows runs out of register args here
#ifdef _WIN64
REGISTER_DECLARATION(Register, j_rarg3, rdi);
REGISTER_DECLARATION(Register, j_rarg4, rsi);
constexpr Register j_rarg3 = rdi;
constexpr Register j_rarg4 = rsi;
#else
REGISTER_DECLARATION(Register, j_rarg3, c_rarg4);
REGISTER_DECLARATION(Register, j_rarg4, c_rarg5);
constexpr Register j_rarg3 = c_rarg4;
constexpr Register j_rarg4 = c_rarg5;
#endif /* _WIN64 */
REGISTER_DECLARATION(Register, j_rarg5, c_rarg0);
constexpr Register j_rarg5 = c_rarg0;

REGISTER_DECLARATION(XMMRegister, j_farg0, xmm0);
REGISTER_DECLARATION(XMMRegister, j_farg1, xmm1);
REGISTER_DECLARATION(XMMRegister, j_farg2, xmm2);
REGISTER_DECLARATION(XMMRegister, j_farg3, xmm3);
REGISTER_DECLARATION(XMMRegister, j_farg4, xmm4);
REGISTER_DECLARATION(XMMRegister, j_farg5, xmm5);
REGISTER_DECLARATION(XMMRegister, j_farg6, xmm6);
REGISTER_DECLARATION(XMMRegister, j_farg7, xmm7);
constexpr XMMRegister j_farg0 = xmm0;
constexpr XMMRegister j_farg1 = xmm1;
constexpr XMMRegister j_farg2 = xmm2;
constexpr XMMRegister j_farg3 = xmm3;
constexpr XMMRegister j_farg4 = xmm4;
constexpr XMMRegister j_farg5 = xmm5;
constexpr XMMRegister j_farg6 = xmm6;
constexpr XMMRegister j_farg7 = xmm7;

REGISTER_DECLARATION(Register, rscratch1, r10); // volatile
REGISTER_DECLARATION(Register, rscratch2, r11); // volatile
constexpr Register rscratch1 = r10; // volatile
constexpr Register rscratch2 = r11; // volatile

REGISTER_DECLARATION(Register, r12_heapbase, r12); // callee-saved
REGISTER_DECLARATION(Register, r15_thread, r15); // callee-saved
constexpr Register r12_heapbase = r12; // callee-saved
constexpr Register r15_thread = r15; // callee-saved

#else
// rscratch1 will appear in 32bit code that is dead but of course must compile
Expand All @@ -149,7 +149,7 @@ REGISTER_DECLARATION(Register, r15_thread, r15); // callee-saved
// JSR 292
// On x86, the SP does not have to be saved when invoking method handle intrinsics
// or compiled lambda forms. We indicate that by setting rbp_mh_SP_save to noreg.
REGISTER_DECLARATION(Register, rbp_mh_SP_save, noreg);
constexpr Register rbp_mh_SP_save = noreg;

// Address is an abstraction used to represent a memory location
// using any of the amd64 addressing modes with one object.
Expand Down Expand Up @@ -2932,7 +2932,7 @@ class InstructionAttr {

// Set embedded opmask register specifier.
void set_embedded_opmask_register_specifier(KRegister mask) {
_embedded_opmask_register_specifier = (*mask).encoding() & 0x7;
_embedded_opmask_register_specifier = mask->encoding() & 0x7;
}

};
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/cpu/x86/c1_Defs_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ enum {

// registers
enum {
pd_nof_cpu_regs_frame_map = RegisterImpl::number_of_registers, // number of registers used during code emission
pd_nof_fpu_regs_frame_map = FloatRegisterImpl::number_of_registers, // number of registers used during code emission
pd_nof_xmm_regs_frame_map = XMMRegisterImpl::number_of_registers, // number of registers used during code emission
pd_nof_cpu_regs_frame_map = Register::number_of_registers, // number of registers used during code emission
pd_nof_fpu_regs_frame_map = FloatRegister::number_of_registers, // number of registers used during code emission
pd_nof_xmm_regs_frame_map = XMMRegister::number_of_registers, // number of registers used during code emission

#ifdef _LP64
#define UNALLOCATED 4 // rsp, rbp, r15, r10
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/c1_FrameMap_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ LIR_Opr FrameMap::_caller_save_cpu_regs[] = {};
LIR_Opr FrameMap::_caller_save_fpu_regs[] = {};
LIR_Opr FrameMap::_caller_save_xmm_regs[] = {};

XMMRegister FrameMap::_xmm_regs [] = { 0, };
XMMRegister FrameMap::_xmm_regs[] = {};

XMMRegister FrameMap::nr2xmmreg(int rnr) {
assert(_init_done, "tables not initialized");
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/c1_FrameMap_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
}

static int get_num_caller_save_xmms() {
return XMMRegisterImpl::available_xmm_registers();
return XMMRegister::available_xmm_registers();
}

static int nof_caller_save_cpu_regs() { return adjust_reg_range(pd_nof_caller_save_cpu_regs_frame_map); }
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ void LIR_Assembler::emit_compare_and_swap(LIR_OpCompareAndSwap* op) {
Register newval = op->new_value()->as_register();
Register cmpval = op->cmp_value()->as_register();
assert(cmpval == rax, "wrong register");
assert(newval != NULL, "new val must be register");
assert(newval != noreg, "new val must be register");
assert(cmpval != newval, "cmp and new values must be in different registers");
assert(cmpval != addr, "cmp and addr must be in different registers");
assert(newval != addr, "new value and addr must be in different registers");
Expand Down Expand Up @@ -1984,7 +1984,7 @@ void LIR_Assembler::emit_compare_and_swap(LIR_OpCompareAndSwap* op) {
Register newval = op->new_value()->as_register_lo();
Register cmpval = op->cmp_value()->as_register_lo();
assert(cmpval == rax, "wrong register");
assert(newval != NULL, "new val must be register");
assert(newval != noreg, "new val must be register");
assert(cmpval != newval, "cmp and new values must be in different registers");
assert(cmpval != addr, "cmp and addr must be in different registers");
assert(newval != addr, "new value and addr must be in different registers");
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/c1_LinearScan_x86.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ inline void LinearScan::pd_add_temps(LIR_Op* op) {
// Implementation of LinearScanWalker

inline bool LinearScanWalker::pd_init_regs_for_alloc(Interval* cur) {
int last_xmm_reg = pd_first_xmm_reg + XMMRegisterImpl::available_xmm_registers() - 1;
int last_xmm_reg = pd_first_xmm_reg + XMMRegister::available_xmm_registers() - 1;
if (allocator()->gen()->is_vreg_flag_set(cur->reg_num(), LIRGenerator::byte_reg)) {
assert(cur->type() != T_FLOAT && cur->type() != T_DOUBLE, "cpu regs only");
_first_reg = pd_first_byte_reg;
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/c2_init_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ void Compile::pd_compiler2_init() {
#endif // AMD64

if (UseAVX < 3) {
int delta = XMMRegisterImpl::max_slots_per_register * XMMRegisterImpl::number_of_registers;
int delta = XMMRegister::max_slots_per_register * XMMRegister::number_of_registers;
int bottom = ConcreteRegisterImpl::max_fpr;
int top = bottom + delta;
int middle = bottom + (delta / 2);
int xmm_slots = XMMRegisterImpl::max_slots_per_register;
int xmm_slots = XMMRegister::max_slots_per_register;
int lower = xmm_slots / 2;
// mark bad every register that we cannot get to if AVX less than 3, we have all slots in the array
// Note: vm2opto is allocated to ConcreteRegisterImpl::number_of_registers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void LIR_OpShenandoahCompareAndSwap::emit_code(LIR_Assembler* masm) {
Register tmp2 = _tmp2->as_register();
Register result = result_opr()->as_register();
assert(cmpval == rax, "wrong register");
assert(newval != NULL, "new val must be register");
assert(newval != noreg, "new val must be register");
assert(cmpval != newval, "cmp and new values must be in different registers");
assert(cmpval != addr, "cmp and addr must be in different registers");
assert(newval != addr, "new value and addr must be in different registers");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ void ShenandoahBarrierSetAssembler::cmpxchg_oop(MacroAssembler* masm,
__ bind(L_failure);
__ bind(L_success);
} else {
assert(res != NULL, "need result register");
assert(res != noreg, "need result register");

Label exit;
__ bind(L_failure);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_32.ad
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ instruct compareAndExchangeP_shenandoah(memory mem_ptr,

ins_encode %{
ShenandoahBarrierSet::assembler()->cmpxchg_oop(&_masm,
NULL, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
noreg, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
true, // exchange
$tmp1$$Register, $tmp2$$Register
);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/gc/shenandoah/shenandoah_x86_64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ instruct compareAndExchangeN_shenandoah(memory mem_ptr,

ins_encode %{
ShenandoahBarrierSet::assembler()->cmpxchg_oop(&_masm,
NULL, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
noreg, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
true, // exchange
$tmp1$$Register, $tmp2$$Register
);
Expand All @@ -104,7 +104,7 @@ instruct compareAndExchangeP_shenandoah(memory mem_ptr,

ins_encode %{
ShenandoahBarrierSet::assembler()->cmpxchg_oop(&_masm,
NULL, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
noreg, $mem_ptr$$Address, $oldval$$Register, $newval$$Register,
true, // exchange
$tmp1$$Register, $tmp2$$Register
);
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/cpu/x86/jvmciCodeInstaller_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ void CodeInstaller::pd_relocate_poll(address pc, jint mark, JVMCI_TRAPS) {

// convert JVMCI register indices (as used in oop maps) to HotSpot registers
VMReg CodeInstaller::get_hotspot_reg(jint jvmci_reg, JVMCI_TRAPS) {
if (jvmci_reg < RegisterImpl::number_of_registers) {
if (jvmci_reg < Register::number_of_registers) {
return as_Register(jvmci_reg)->as_VMReg();
} else {
jint floatRegisterNumber = jvmci_reg - RegisterImpl::number_of_registers;
if (floatRegisterNumber < XMMRegisterImpl::number_of_registers) {
jint floatRegisterNumber = jvmci_reg - Register::number_of_registers;
if (floatRegisterNumber < XMMRegister::number_of_registers) {
return as_XMMRegister(floatRegisterNumber)->as_VMReg();
}
JVMCI_ERROR_NULL("invalid register number: %d", jvmci_reg);
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/cpu/x86/macroAssembler_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3772,7 +3772,7 @@ RegSet MacroAssembler::call_clobbered_gp_registers() {
}

XMMRegSet MacroAssembler::call_clobbered_xmm_registers() {
int num_xmm_registers = XMMRegisterImpl::available_xmm_registers();
int num_xmm_registers = XMMRegister::available_xmm_registers();
#if defined(WINDOWS) && defined(_LP64)
XMMRegSet result = XMMRegSet::range(xmm0, xmm5);
if (num_xmm_registers > 16) {
Expand Down Expand Up @@ -3813,7 +3813,7 @@ static void restore_xmm_register(MacroAssembler* masm, int offset, XMMRegister r
int register_section_sizes(RegSet gp_registers, XMMRegSet xmm_registers, bool save_fpu,
int& gp_area_size, int& fp_area_size, int& xmm_area_size) {

gp_area_size = align_up(gp_registers.size() * RegisterImpl::max_slots_per_register * VMRegImpl::stack_slot_size,
gp_area_size = align_up(gp_registers.size() * Register::max_slots_per_register * VMRegImpl::stack_slot_size,
StackAlignmentInBytes);
#ifdef _LP64
fp_area_size = 0;
Expand Down Expand Up @@ -3906,7 +3906,7 @@ void MacroAssembler::pop_set(XMMRegSet set, int offset) {
void MacroAssembler::push_set(RegSet set, int offset) {
int spill_offset;
if (offset == -1) {
int register_push_size = set.size() * RegisterImpl::max_slots_per_register * VMRegImpl::stack_slot_size;
int register_push_size = set.size() * Register::max_slots_per_register * VMRegImpl::stack_slot_size;
int aligned_size = align_up(register_push_size, StackAlignmentInBytes);
subptr(rsp, aligned_size);
spill_offset = 0;
Expand All @@ -3916,13 +3916,13 @@ void MacroAssembler::push_set(RegSet set, int offset) {

for (RegSetIterator<Register> it = set.begin(); *it != noreg; ++it) {
movptr(Address(rsp, spill_offset), *it);
spill_offset += RegisterImpl::max_slots_per_register * VMRegImpl::stack_slot_size;
spill_offset += Register::max_slots_per_register * VMRegImpl::stack_slot_size;
}
}

void MacroAssembler::pop_set(RegSet set, int offset) {

int gp_reg_size = RegisterImpl::max_slots_per_register * VMRegImpl::stack_slot_size;
int gp_reg_size = Register::max_slots_per_register * VMRegImpl::stack_slot_size;
int restore_size = set.size() * gp_reg_size;
int aligned_size = align_up(restore_size, StackAlignmentInBytes);

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/macroAssembler_x86_aes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ void MacroAssembler::lastroundDec(XMMRegister key, int rnum) {
}

// Load key and shuffle operation
void MacroAssembler::ev_load_key(XMMRegister xmmdst, Register key, int offset, XMMRegister xmm_shuf_mask=NULL) {
void MacroAssembler::ev_load_key(XMMRegister xmmdst, Register key, int offset, XMMRegister xmm_shuf_mask) {
movdqu(xmmdst, Address(key, offset));
if (xmm_shuf_mask != NULL) {
if (xmm_shuf_mask != xnoreg) {
pshufb(xmmdst, xmm_shuf_mask);
} else {
pshufb(xmmdst, ExternalAddress(StubRoutines::x86::key_shuffle_mask_addr()));
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/methodHandles_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ void trace_method_handle_stub(const char* adaptername,
ResourceMark rm;
LogStream ls(lt);
ls.print_cr("Registers:");
const int saved_regs_count = RegisterImpl::number_of_registers;
const int saved_regs_count = Register::number_of_registers;
for (int i = 0; i < saved_regs_count; i++) {
Register r = as_Register(i);
// The registers are stored in reverse order on the stack (by pusha).
#ifdef AMD64
assert(RegisterImpl::number_of_registers == 16, "sanity");
assert(Register::number_of_registers == 16, "sanity");
if (r == rsp) {
// rsp is actually not stored by pusha(), compute the old rsp from saved_regs (rsp after pusha): saved_regs + 16 = old rsp
ls.print("%3s=" PTR_FORMAT, r->name(), (intptr_t)(&saved_regs[16]));
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/x86/registerMap_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
address RegisterMap::pd_location(VMReg reg) const {
if (reg->is_XMMRegister()) {
int reg_base = reg->value() - ConcreteRegisterImpl::max_fpr;
int base_reg_enc = (reg_base / XMMRegisterImpl::max_slots_per_register);
assert(base_reg_enc >= 0 && base_reg_enc < XMMRegisterImpl::number_of_registers, "invalid XMMRegister: %d", base_reg_enc);
int base_reg_enc = (reg_base / XMMRegister::max_slots_per_register);
assert(base_reg_enc >= 0 && base_reg_enc < XMMRegister::number_of_registers, "invalid XMMRegister: %d", base_reg_enc);
VMReg base_reg = as_XMMRegister(base_reg_enc)->as_VMReg();
intptr_t offset_in_bytes = (reg->value() - base_reg->value()) * VMRegImpl::stack_slot_size;
if (base_reg_enc > 15) {
Expand Down
Loading

1 comment on commit 755ecf6

@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.