Skip to content

Instantly share code, notes, and snippets.

@pwq1989
Created March 2, 2015 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwq1989/d8cb802816af4d921af5 to your computer and use it in GitHub Desktop.
Save pwq1989/d8cb802816af4d921af5 to your computer and use it in GitHub Desktop.
remove rbp from normal reg set, and save rsp to rbp
diff --git a/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp b/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp
index 576d338..ae335b4 100644
--- a/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp
+++ b/src/cpu/x86/vm/c1_MacroAssembler_x86.cpp
@@ -358,6 +358,7 @@ void C1_MacroAssembler::build_frame(int frame_size_in_bytes) {
generate_stack_overflow_check(frame_size_in_bytes);
push(rbp);
+ mov(rbp, rsp);
#ifdef TIERED
// c2 leaves fpu stack dirty. Clean it on entry
if (UseSSE < 2 ) {
diff --git a/src/cpu/x86/vm/x86_64.ad b/src/cpu/x86/vm/x86_64.ad
index d836054..57a2e05 100644
--- a/src/cpu/x86/vm/x86_64.ad
+++ b/src/cpu/x86/vm/x86_64.ad
@@ -285,7 +285,6 @@ alloc_class chunk2(RFLAGS);
// Class for all pointer registers (including RSP)
reg_class any_reg(RAX, RAX_H,
RDX, RDX_H,
- RBP, RBP_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -303,7 +302,6 @@ reg_class any_reg(RAX, RAX_H,
// Class for all pointer registers except RSP
reg_class ptr_reg(RAX, RAX_H,
RDX, RDX_H,
- RBP, RBP_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -317,7 +315,6 @@ reg_class ptr_reg(RAX, RAX_H,
// Class for all pointer registers except RAX and RSP
reg_class ptr_no_rax_reg(RDX, RDX_H,
- RBP, RBP_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -344,7 +341,6 @@ reg_class ptr_no_rbp_reg(RDX, RDX_H,
// Class for all pointer registers except RAX, RBX and RSP
reg_class ptr_no_rax_rbx_reg(RDX, RDX_H,
- RBP, RBP_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -379,7 +375,6 @@ reg_class ptr_r15_reg(R15, R15_H);
// Class for all long registers (except RSP)
reg_class long_reg(RAX, RAX_H,
RDX, RDX_H,
- RBP, RBP_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -392,8 +387,7 @@ reg_class long_reg(RAX, RAX_H,
R14, R14_H);
// Class for all long registers except RAX, RDX (and RSP)
-reg_class long_no_rax_rdx_reg(RBP, RBP_H,
- RDI, RDI_H,
+reg_class long_no_rax_rdx_reg(RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
RBX, RBX_H,
@@ -405,8 +399,7 @@ reg_class long_no_rax_rdx_reg(RBP, RBP_H,
R14, R14_H);
// Class for all long registers except RCX (and RSP)
-reg_class long_no_rcx_reg(RBP, RBP_H,
- RDI, RDI_H,
+reg_class long_no_rcx_reg(RDI, RDI_H,
RSI, RSI_H,
RAX, RAX_H,
RDX, RDX_H,
@@ -419,8 +412,7 @@ reg_class long_no_rcx_reg(RBP, RBP_H,
R14, R14_H);
// Class for all long registers except RAX (and RSP)
-reg_class long_no_rax_reg(RBP, RBP_H,
- RDX, RDX_H,
+reg_class long_no_rax_reg(RDX, RDX_H,
RDI, RDI_H,
RSI, RSI_H,
RCX, RCX_H,
@@ -444,7 +436,6 @@ reg_class long_rdx_reg(RDX, RDX_H);
// Class for all int registers (except RSP)
reg_class int_reg(RAX,
RDX,
- RBP,
RDI,
RSI,
RCX,
@@ -459,7 +450,6 @@ reg_class int_reg(RAX,
// Class for all int registers except RCX (and RSP)
reg_class int_no_rcx_reg(RAX,
RDX,
- RBP,
RDI,
RSI,
RBX,
@@ -471,8 +461,7 @@ reg_class int_no_rcx_reg(RAX,
R14);
// Class for all int registers except RAX, RDX (and RSP)
-reg_class int_no_rax_rdx_reg(RBP,
- RDI,
+reg_class int_no_rax_rdx_reg(RDI,
RSI,
RCX,
RBX,
@@ -883,7 +872,9 @@ void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const
st->print_cr("# stack bang"); st->print("\t");
need_nop = false;
}
- st->print_cr("pushq rbp"); st->print("\t");
+ st->print_cr("pushq rbp");
+ st->print_cr("movq rbp, rsp");
+ st->print("\t");
if (VerifyStackAtCalls) {
// Majik cookie to verify stack depth
@@ -937,6 +928,11 @@ void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const
// restored correctly and we can correct the stack.
emit_opcode(cbuf, 0x50 | RBP_enc);
+ // push rsp, rbp
+ emit_opcode(cbuf, 0x48);
+ emit_opcode(cbuf, 0x89);
+ emit_opcode(cbuf, 0xE5);
+
if (VerifyStackAtCalls) {
// Majik cookie to verify stack depth
emit_opcode(cbuf, 0x68); // pushq (sign-extended) 0xbadb100d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment