From 9080192a656d0ab70f079cdb9bd3cbb31b05a0d4 Mon Sep 17 00:00:00 2001 From: degasus Date: Sat, 12 Aug 2017 22:46:50 +0200 Subject: [PATCH] Jit64: Move profiler to the end of th block. Within Cleanup(), it is called at *every* end of the block. This generates bigger code, but it is the only way to handle blocks with multiple exit nodes. --- Source/Core/Core/PowerPC/Jit64/Jit.cpp | 35 +++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/PowerPC/Jit64/Jit.cpp b/Source/Core/Core/PowerPC/Jit64/Jit.cpp index 875a3a298b..d046a639ad 100644 --- a/Source/Core/Core/PowerPC/Jit64/Jit.cpp +++ b/Source/Core/Core/PowerPC/Jit64/Jit.cpp @@ -371,6 +371,23 @@ bool Jit64::Cleanup() did_something = true; } + if (Profiler::g_ProfileBlocks) + { + ABI_PushRegistersAndAdjustStack({}, 0); + // get end tic + MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast(&js.curBlock->profile_data.ticStop))); + ABI_CallFunction(QueryPerformanceCounter); + // tic counter += (end tic - start tic) + MOV(64, R(RSCRATCH2), Imm64(reinterpret_cast(&js.curBlock->profile_data))); + MOV(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticStop))); + SUB(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticStart))); + ADD(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticCounter))); + ADD(64, MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, downcountCounter)), + Imm32(js.downcountAmount)); + MOV(64, MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticCounter)), R(RSCRATCH)); + ABI_PopRegistersAndAdjustStack({}, 0); + } + return did_something; } @@ -730,24 +747,6 @@ const u8* Jit64::DoJit(u32 em_address, PPCAnalyst::CodeBuffer* code_buf, JitBloc if (i == (code_block.m_num_instructions - 1)) { - if (Profiler::g_ProfileBlocks) - { - // TODO: Move this to WriteExit() calls. - BitSet32 registersInUse = CallerSavedRegistersInUse(); - ABI_PushRegistersAndAdjustStack(registersInUse, 0); - // get end tic - MOV(64, R(ABI_PARAM1), Imm64(reinterpret_cast(&b->profile_data.ticStop))); - ABI_CallFunction(QueryPerformanceCounter); - // tic counter += (end tic - start tic) - MOV(64, R(RSCRATCH2), Imm64(reinterpret_cast(&b->profile_data))); - MOV(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticStop))); - SUB(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticStart))); - ADD(64, R(RSCRATCH), MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticCounter))); - ADD(64, MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, downcountCounter)), - Imm32(js.downcountAmount)); - MOV(64, MDisp(RSCRATCH2, offsetof(JitBlock::ProfileData, ticCounter)), R(RSCRATCH)); - ABI_PopRegistersAndAdjustStack(registersInUse, 0); - } js.isLastInstruction = true; }