Permalink
Browse files

Merge pull request #10508 from unknownbrackets/irjit

Improve IR debug output
  • Loading branch information...
hrydgard committed Jan 5, 2018
2 parents 2709472 + ccd562d commit 94e73bcb5e38603ad90d9657e69ad554ec66fb25
Showing with 43 additions and 9 deletions.
  1. +32 −2 Core/MIPS/IR/IRJit.cpp
  2. +11 −7 UI/DevScreens.cpp
View
@@ -67,6 +67,12 @@ void IRJit::Compile(u32 em_address) {
PROFILE_THIS_SCOPE("jitc");
int block_num = blocks_.AllocateBlock(em_address);
if ((block_num & ~MIPS_EMUHACK_VALUE_MASK) != 0) {
// Ran out of block numbers - need to reset.
ERROR_LOG(JIT, "Ran out of block numbers, clearing cache");
ClearCache();
block_num = blocks_.AllocateBlock(em_address);
}
IRBlock *b = blocks_.GetBlock(block_num);
std::vector<IRInst> instructions;
@@ -234,9 +240,33 @@ JitBlockDebugInfo IRBlockCache::GetBlockDebugInfo(int blockNum) const {
}
void IRBlockCache::ComputeStats(BlockCacheStats &bcStats) const {
// TODO: Implement properly
memset(&bcStats, 0, sizeof(bcStats));
double totalBloat = 0.0;
double maxBloat = 0.0;
double minBloat = 1000000000.0;
for (const auto &b : blocks_) {
double codeSize = (double)b.GetNumInstructions() * sizeof(IRInst);
if (codeSize == 0)
continue;
u32 origAddr, mipsBytes;
b.GetRange(origAddr, mipsBytes);
double origSize = (double)mipsBytes;
double bloat = codeSize / origSize;
if (bloat < minBloat) {
minBloat = bloat;
bcStats.minBloatBlock = origAddr;
}
if (bloat > maxBloat) {
maxBloat = bloat;
bcStats.maxBloatBlock = origAddr;
}
totalBloat += bloat;
bcStats.bloatMap[bloat] = origAddr;
}
bcStats.numBlocks = (int)blocks_.size();
bcStats.minBloat = minBloat;
bcStats.maxBloat = maxBloat;
bcStats.avgBloat = totalBloat / (double)blocks_.size();
}
int IRBlockCache::GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly) const {
View
@@ -748,7 +748,7 @@ UI::EventReturn JitCompareScreen::OnAddressChange(UI::EventParams &e) {
if (!MIPSComp::jit) {
return UI::EVENT_DONE;
}
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache();
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return UI::EVENT_DONE;
u32 addr;
@@ -815,7 +815,7 @@ UI::EventReturn JitCompareScreen::OnBlockAddress(UI::EventParams &e) {
return UI::EVENT_DONE;
}
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache();
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return UI::EVENT_DONE;
@@ -859,29 +859,33 @@ void JitCompareScreen::OnRandomBlock(int flag) {
if (!MIPSComp::jit) {
return;
}
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache();
JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache)
return;
int numBlocks = blockCache->GetNumBlocks();
if (numBlocks > 0) {
bool anyWanted = false;
int tries = 0;
while (!anyWanted && tries < 10000) {
while (!anyWanted && tries < numBlocks) {
currentBlock_ = rand() % numBlocks;
const JitBlock *b = blockCache->GetBlock(currentBlock_);
for (u32 addr = b->originalAddress; addr <= b->originalAddress + b->originalSize; addr += 4) {
JitBlockDebugInfo b = blockCache->GetBlockDebugInfo(currentBlock_);
u32 mipsBytes = (u32)b.origDisasm.size() * 4;
for (u32 addr = b.originalAddress; addr <= b.originalAddress + mipsBytes; addr += 4) {
MIPSOpcode opcode = Memory::Read_Instruction(addr);
if (MIPSGetInfo(opcode) & flag) {
char temp[256];
MIPSDisAsm(opcode, addr, temp);
// INFO_LOG(HLE, "Stopping VFPU instruction: %s", temp);
// INFO_LOG(HLE, "Stopping at random instruction: %08x %s", addr, temp);
anyWanted = true;
break;
}
}
tries++;
}
if (!anyWanted)
currentBlock_ = -1;
}
UpdateDisasm();
}

0 comments on commit 94e73bc

Please sign in to comment.