From b5da4e9d48978cb7cd2b27717c4878ad728440cf Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Fri, 24 Jun 2022 23:01:25 -0500 Subject: [PATCH 1/3] CMake: Don't omit frame pointer on RelWithDebInfo builds --- CMake/CheckAndAddFlag.cmake | 2 ++ CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMake/CheckAndAddFlag.cmake b/CMake/CheckAndAddFlag.cmake index 226e570833..4fe7d5be18 100644 --- a/CMake/CheckAndAddFlag.cmake +++ b/CMake/CheckAndAddFlag.cmake @@ -21,6 +21,8 @@ function(check_and_add_flag var flag) set(genexp_config_test "1") if(ARGV2 STREQUAL "DEBUG_ONLY") set(genexp_config_test "$") + elseif(ARGV2 STREQUAL "NO_DEBINFO_ONLY") + set(genexp_config_test "$,$>>") elseif(ARGV2 STREQUAL "RELEASE_ONLY") set(genexp_config_test "$>") elseif(ARGV2) diff --git a/CMakeLists.txt b/CMakeLists.txt index 163ea2c943..9596373862 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,7 +354,7 @@ else() check_and_add_flag(VISIBILITY_INLINES_HIDDEN -fvisibility-inlines-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) check_and_add_flag(GGDB -ggdb DEBUG_ONLY) From f2a074f4f8c047d3037249ae940a300f431af721 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Fri, 24 Jun 2022 23:08:18 -0500 Subject: [PATCH 2/3] Common:X64ABI: Make proper stack frames --- Source/Core/Common/x64ABI.cpp | 15 +++++++++++++-- Source/Core/VideoCommon/VertexLoaderX64.cpp | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Core/Common/x64ABI.cpp b/Source/Core/Common/x64ABI.cpp index 0c4f0770ca..424e8a483e 100644 --- a/Source/Core/Common/x64ABI.cpp +++ b/Source/Core/Common/x64ABI.cpp @@ -43,11 +43,18 @@ void XEmitter::ABI_CalculateFrameSize(BitSet32 mask, size_t rsp_alignment, size_ size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, size_t needed_frame_size) { + mask[RSP] = false; // Stack pointer is never pushed size_t shadow, subtraction, xmm_offset; ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, &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); if (subtraction) @@ -65,6 +72,7 @@ size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_align void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignment, size_t needed_frame_size) { + mask[RSP] = false; // Stack pointer is never pushed size_t shadow, subtraction, xmm_offset; ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, &xmm_offset); @@ -80,9 +88,12 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignmen for (int r = 15; r >= 0; r--) { - if (mask[r]) + if (r != RBP && mask[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, diff --git a/Source/Core/VideoCommon/VertexLoaderX64.cpp b/Source/Core/VideoCommon/VertexLoaderX64.cpp index 27e24e6f28..c92f94bed9 100644 --- a/Source/Core/VideoCommon/VertexLoaderX64.cpp +++ b/Source/Core/VideoCommon/VertexLoaderX64.cpp @@ -404,6 +404,7 @@ void VertexLoaderX64::GenerateVertexLoader() BitSet32 regs = {src_reg, dst_reg, scratch1, scratch2, scratch3, remaining_reg, skipped_reg, base_reg}; regs &= ABI_ALL_CALLEE_SAVED; + regs[RBP] = true; // Give us a stack frame ABI_PushRegistersAndAdjustStack(regs, 0); // Backup count since we're going to count it down. From 235b67707f71498d7a3848eed6f4b83491795839 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 11 Aug 2022 23:57:28 -0500 Subject: [PATCH 3/3] Common:X64ABI: Work around clang-format being dumb --- Source/Core/Common/x64ABI.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/Common/x64ABI.cpp b/Source/Core/Common/x64ABI.cpp index 424e8a483e..9f45c132a6 100644 --- a/Source/Core/Common/x64ABI.cpp +++ b/Source/Core/Common/x64ABI.cpp @@ -54,13 +54,13 @@ size_t XEmitter::ABI_PushRegistersAndAdjustStack(BitSet32 mask, size_t rsp_align PUSH(RBP); MOV(64, R(RBP), R(RSP)); } - for (int r : mask& ABI_ALL_GPRS & ~BitSet32{RBP}) + for (int r : (mask & ABI_ALL_GPRS & ~BitSet32{RBP})) PUSH((X64Reg)r); if (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)); xmm_offset += 16; @@ -77,7 +77,7 @@ void XEmitter::ABI_PopRegistersAndAdjustStack(BitSet32 mask, size_t rsp_alignmen ABI_CalculateFrameSize(mask, rsp_alignment, needed_frame_size, &shadow, &subtraction, &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)); xmm_offset += 16;