Skip to content

Commit

Permalink
Merge pull request #10508 from unknownbrackets/irjit
Browse files Browse the repository at this point in the history
Improve IR debug output
  • Loading branch information
hrydgard committed Jan 5, 2018
2 parents 2709472 + ccd562d commit 94e73bc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
34 changes: 32 additions & 2 deletions Core/MIPS/IR/IRJit.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ void IRJit::Compile(u32 em_address) {
PROFILE_THIS_SCOPE("jitc"); PROFILE_THIS_SCOPE("jitc");


int block_num = blocks_.AllocateBlock(em_address); 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); IRBlock *b = blocks_.GetBlock(block_num);


std::vector<IRInst> instructions; std::vector<IRInst> instructions;
Expand Down Expand Up @@ -234,9 +240,33 @@ JitBlockDebugInfo IRBlockCache::GetBlockDebugInfo(int blockNum) const {
} }


void IRBlockCache::ComputeStats(BlockCacheStats &bcStats) const { void IRBlockCache::ComputeStats(BlockCacheStats &bcStats) const {
// TODO: Implement properly double totalBloat = 0.0;
memset(&bcStats, 0, sizeof(bcStats)); 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.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 { int IRBlockCache::GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly) const {
Expand Down
18 changes: 11 additions & 7 deletions UI/DevScreens.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ UI::EventReturn JitCompareScreen::OnAddressChange(UI::EventParams &e) {
if (!MIPSComp::jit) { if (!MIPSComp::jit) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache(); JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache) if (!blockCache)
return UI::EVENT_DONE; return UI::EVENT_DONE;
u32 addr; u32 addr;
Expand Down Expand Up @@ -815,7 +815,7 @@ UI::EventReturn JitCompareScreen::OnBlockAddress(UI::EventParams &e) {
return UI::EVENT_DONE; return UI::EVENT_DONE;
} }


JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache(); JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache) if (!blockCache)
return UI::EVENT_DONE; return UI::EVENT_DONE;


Expand Down Expand Up @@ -859,29 +859,33 @@ void JitCompareScreen::OnRandomBlock(int flag) {
if (!MIPSComp::jit) { if (!MIPSComp::jit) {
return; return;
} }
JitBlockCache *blockCache = MIPSComp::jit->GetBlockCache(); JitBlockCacheDebugInterface *blockCache = MIPSComp::jit->GetBlockCacheDebugInterface();
if (!blockCache) if (!blockCache)
return; return;


int numBlocks = blockCache->GetNumBlocks(); int numBlocks = blockCache->GetNumBlocks();
if (numBlocks > 0) { if (numBlocks > 0) {
bool anyWanted = false; bool anyWanted = false;
int tries = 0; int tries = 0;
while (!anyWanted && tries < 10000) { while (!anyWanted && tries < numBlocks) {
currentBlock_ = rand() % numBlocks; currentBlock_ = rand() % numBlocks;
const JitBlock *b = blockCache->GetBlock(currentBlock_); JitBlockDebugInfo b = blockCache->GetBlockDebugInfo(currentBlock_);
for (u32 addr = b->originalAddress; addr <= b->originalAddress + b->originalSize; addr += 4) { u32 mipsBytes = (u32)b.origDisasm.size() * 4;
for (u32 addr = b.originalAddress; addr <= b.originalAddress + mipsBytes; addr += 4) {
MIPSOpcode opcode = Memory::Read_Instruction(addr); MIPSOpcode opcode = Memory::Read_Instruction(addr);
if (MIPSGetInfo(opcode) & flag) { if (MIPSGetInfo(opcode) & flag) {
char temp[256]; char temp[256];
MIPSDisAsm(opcode, addr, temp); 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; anyWanted = true;
break; break;
} }
} }
tries++; tries++;
} }

if (!anyWanted)
currentBlock_ = -1;
} }
UpdateDisasm(); UpdateDisasm();
} }
Expand Down

0 comments on commit 94e73bc

Please sign in to comment.