Merge pull request #10976 from TellowKrinkle/StackFrames

Improve stack frames for profilers
This commit is contained in:
OatmealDome 2023-06-12 05:00:08 +02:00 committed by GitHub
commit 1a0a1e8f12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View File

@ -21,6 +21,8 @@ function(check_and_add_flag var flag)
set(genexp_config_test "1") set(genexp_config_test "1")
if(ARGV2 STREQUAL "DEBUG_ONLY") if(ARGV2 STREQUAL "DEBUG_ONLY")
set(genexp_config_test "$<CONFIG:Debug>") set(genexp_config_test "$<CONFIG:Debug>")
elseif(ARGV2 STREQUAL "NO_DEBINFO_ONLY")
set(genexp_config_test "$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>")
elseif(ARGV2 STREQUAL "RELEASE_ONLY") elseif(ARGV2 STREQUAL "RELEASE_ONLY")
set(genexp_config_test "$<NOT:$<CONFIG:Debug>>") set(genexp_config_test "$<NOT:$<CONFIG:Debug>>")
elseif(ARGV2) elseif(ARGV2)

View File

@ -372,7 +372,7 @@ else()
check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden) check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-hidden)
check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden) check_and_add_flag(VISIBILITY_HIDDEN -fvisibility=hidden)
check_and_add_flag(FOMIT_FRAME_POINTER -fomit-frame-pointer RELEASE_ONLY) check_and_add_flag(FOMIT_FRAME_POINTER -fomit-frame-pointer NO_DEBINFO_ONLY)
dolphin_compile_definitions(_DEBUG DEBUG_ONLY) dolphin_compile_definitions(_DEBUG DEBUG_ONLY)
check_and_add_flag(GGDB -ggdb DEBUG_ONLY) check_and_add_flag(GGDB -ggdb DEBUG_ONLY)

View File

@ -43,17 +43,24 @@ void XEmitter::ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_
size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment,
size_t needed_frame_size) size_t needed_frame_size)
{ {
mask[RSP] = false; // Stack pointer is never pushed
size_t shadow, subtraction, xmm_offset; size_t shadow, subtraction, xmm_offset;
ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction,
&xmm_offset); &xmm_offset);
for (int r : mask& ABI_ALL_GPRS) if (mask[RBP])
{
// Make a nice stack frame for any debuggers or profilers that might be looking at this
PUSH(RBP);
MOV(64, R(RBP), R(RSP));
}
for (int r : (mask & ABI_ALL_GPRS & ~BitSet32{RBP}))
PUSH((X64Reg)r); PUSH((X64Reg)r);
if (subtraction) if (subtraction)
SUB(64, R(RSP), subtraction >= 0x80 ? Imm32((u32)subtraction) : Imm8((u8)subtraction)); SUB(64, R(RSP), subtraction >= 0x80 ? Imm32((u32)subtraction) : Imm8((u8)subtraction));
for (int x : mask& ABI_ALL_FPRS) for (int x : (mask & ABI_ALL_FPRS))
{ {
MOVAPD(MDisp(RSP, (int)xmm_offset), (X64Reg)(x - 16)); MOVAPD(MDisp(RSP, (int)xmm_offset), (X64Reg)(x - 16));
xmm_offset += 16; xmm_offset += 16;
@ -65,11 +72,12 @@ size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_align
void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment,
size_t needed_frame_size) size_t needed_frame_size)
{ {
mask[RSP] = false; // Stack pointer is never pushed
size_t shadow, subtraction, xmm_offset; size_t shadow, subtraction, xmm_offset;
ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction,
&xmm_offset); &xmm_offset);
for (int x : mask& ABI_ALL_FPRS) for (int x : (mask & ABI_ALL_FPRS))
{ {
MOVAPD((X64Reg)(x - 16), MDisp(RSP, (int)xmm_offset)); MOVAPD((X64Reg)(x - 16), MDisp(RSP, (int)xmm_offset));
xmm_offset += 16; xmm_offset += 16;
@ -80,9 +88,12 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignmen
for (int r = 15; r >= 0; r--) for (int r = 15; r >= 0; r--)
{ {
if (mask[r]) if (r != RBP && mask[r])
POP((X64Reg)r); POP((X64Reg)r);
} }
// RSP is pushed first and popped last to make debuggers/profilers happy
if (mask[RBP])
POP(RBP);
} }
void XEmitter::MOVTwo(int bits, Gen::X64Reg dst1, Gen::X64Reg src1, s32 offset1, Gen::X64Reg dst2, void XEmitter::MOVTwo(int bits, Gen::X64Reg dst1, Gen::X64Reg src1, s32 offset1, Gen::X64Reg dst2,

View File

@ -402,6 +402,7 @@ void VertexLoaderX64::GenerateVertexLoader()
BitSet32 regs = {src_reg, dst_reg, scratch1, scratch2, BitSet32 regs = {src_reg, dst_reg, scratch1, scratch2,
scratch3, remaining_reg, skipped_reg, base_reg}; scratch3, remaining_reg, skipped_reg, base_reg};
regs &= ABI_ALL_CALLEE_SAVED; regs &= ABI_ALL_CALLEE_SAVED;
regs[RBP] = true; // Give us a stack frame
ABI_PushRegistersAndAdjustStack(regs, 0); ABI_PushRegistersAndAdjustStack(regs, 0);
// Backup count since we're going to count it down. // Backup count since we're going to count it down.