JitCache: Add a helper function to iterate over all blocks.

This commit is contained in:
degasus 2017-01-11 20:24:13 +01:00
parent ca026b58ab
commit 7e850361fb
4 changed files with 17 additions and 13 deletions

View File

@ -119,6 +119,12 @@ int* JitBaseBlockCache::GetICache()
return iCache.data(); return iCache.data();
} }
void JitBaseBlockCache::RunOnBlocks(std::function<void(const JitBlock&)> f)
{
for (int i = 0; i < num_blocks; i++)
f(blocks[i]);
}
JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address) JitBlock* JitBaseBlockCache::AllocateBlock(u32 em_address)
{ {
JitBlock& b = blocks[num_blocks]; JitBlock& b = blocks[num_blocks];

View File

@ -6,6 +6,7 @@
#include <array> #include <array>
#include <bitset> #include <bitset>
#include <functional>
#include <map> #include <map>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -130,6 +131,7 @@ public:
JitBlock* GetBlocks(); JitBlock* GetBlocks();
int GetNumBlocks() const; int GetNumBlocks() const;
int* GetICache(); int* GetICache();
void RunOnBlocks(std::function<void(const JitBlock&)> f);
JitBlock* AllocateBlock(u32 em_address); JitBlock* AllocateBlock(u32 em_address);
void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr); void FinalizeBlock(JitBlock& b, bool block_link, const u8* code_ptr);

View File

@ -134,26 +134,23 @@ void GetProfileResults(ProfileStats* prof_stats)
prof_stats->cost_sum = 0; prof_stats->cost_sum = 0;
prof_stats->timecost_sum = 0; prof_stats->timecost_sum = 0;
prof_stats->block_stats.clear(); prof_stats->block_stats.clear();
prof_stats->block_stats.reserve(g_jit->GetBlockCache()->GetNumBlocks());
Core::EState old_state = Core::GetState(); Core::EState old_state = Core::GetState();
if (old_state == Core::CORE_RUN) if (old_state == Core::CORE_RUN)
Core::SetState(Core::CORE_PAUSE); Core::SetState(Core::CORE_PAUSE);
QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec); QueryPerformanceFrequency((LARGE_INTEGER*)&prof_stats->countsPerSec);
for (int i = 0; i < g_jit->GetBlockCache()->GetNumBlocks(); i++) g_jit->GetBlockCache()->RunOnBlocks([&prof_stats](const JitBlock& block) {
{
const JitBlock* block = g_jit->GetBlockCache()->GetBlock(i);
// Rough heuristic. Mem instructions should cost more. // Rough heuristic. Mem instructions should cost more.
u64 cost = block->originalSize * (block->runCount / 4); u64 cost = block.originalSize * (block.runCount / 4);
u64 timecost = block->ticCounter; u64 timecost = block.ticCounter;
// Todo: tweak. // Todo: tweak.
if (block->runCount >= 1) if (block.runCount >= 1)
prof_stats->block_stats.emplace_back(i, block->effectiveAddress, cost, timecost, prof_stats->block_stats.emplace_back(block.effectiveAddress, cost, timecost, block.runCount,
block->runCount, block->codeSize); block.codeSize);
prof_stats->cost_sum += cost; prof_stats->cost_sum += cost;
prof_stats->timecost_sum += timecost; prof_stats->timecost_sum += timecost;
} });
sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end()); sort(prof_stats->block_stats.begin(), prof_stats->block_stats.end());
if (old_state == Core::CORE_RUN) if (old_state == Core::CORE_RUN)

View File

@ -43,11 +43,10 @@
struct BlockStat struct BlockStat
{ {
BlockStat(int bn, u32 _addr, u64 c, u64 ticks, u64 run, u32 size) BlockStat(u32 _addr, u64 c, u64 ticks, u64 run, u32 size)
: blockNum(bn), addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size) : addr(_addr), cost(c), tick_counter(ticks), run_count(run), block_size(size)
{ {
} }
int blockNum;
u32 addr; u32 addr;
u64 cost; u64 cost;
u64 tick_counter; u64 tick_counter;