mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-15 18:49:51 +01:00
Merge pull request #17814 from unknownbrackets/riscv-jit-debug
riscv: Implement block debug interface
This commit is contained in:
2 files changed
+97
-2
No files matched your search
@@ -69,7 +69,8 @@ static void LogDebugNotCompiled() {
|
||||
WARN_LOG(JIT, "Most not compiled op: %s (%d)", worstName, worstVal);
|
||||
}
|
||||
|
||||
RiscVJit::RiscVJit(MIPSState *mipsState) : IRJit(mipsState), gpr(mipsState, &jo), fpr(mipsState, &jo) {
|
||||
RiscVJit::RiscVJit(MIPSState *mipsState)
|
||||
: IRJit(mipsState), gpr(mipsState, &jo), fpr(mipsState, &jo), debugInterface_(blocks_, *this) {
|
||||
// Automatically disable incompatible options.
|
||||
if (((intptr_t)Memory::base & 0x00000000FFFFFFFFUL) != 0) {
|
||||
jo.enablePointerify = false;
|
||||
@@ -98,6 +99,10 @@ void RiscVJit::RunLoopUntil(u64 globalticks) {
|
||||
((void (*)())enterDispatcher_)();
|
||||
}
|
||||
|
||||
JitBlockCacheDebugInterface *MIPSComp::RiscVJit::GetBlockCacheDebugInterface() {
|
||||
return &debugInterface_;
|
||||
}
|
||||
|
||||
static void NoBlockExits() {
|
||||
_assert_msg_(false, "Never exited block, invalid IR?");
|
||||
}
|
||||
@@ -616,4 +621,76 @@ RiscVReg RiscVJit::NormalizeR(IRRegIndex rs, IRRegIndex rd, RiscVReg tempReg) {
|
||||
}
|
||||
}
|
||||
|
||||
RiscVBlockCacheDebugInterface::RiscVBlockCacheDebugInterface(IRBlockCache &irBlocks, RiscVJit &jit)
|
||||
: irBlocks_(irBlocks), jit_(jit) {}
|
||||
|
||||
int RiscVBlockCacheDebugInterface::GetNumBlocks() const {
|
||||
return irBlocks_.GetNumBlocks();
|
||||
}
|
||||
|
||||
int RiscVBlockCacheDebugInterface::GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly) const {
|
||||
return irBlocks_.GetBlockNumberFromStartAddress(em_address, realBlocksOnly);
|
||||
}
|
||||
|
||||
void RiscVBlockCacheDebugInterface::GetBlockCodeRange(int blockNum, int *startOffset, int *size) const {
|
||||
int blockOffset = irBlocks_.GetBlock(blockNum)->GetTargetOffset();
|
||||
int endOffset;
|
||||
// We assume linear allocation. Maybe a bit dangerous, should always be right.
|
||||
if (blockNum + 1 >= GetNumBlocks()) {
|
||||
// Last block, get from current code pointer.
|
||||
endOffset = (int)jit_.GetOffset(jit_.GetCodePointer());
|
||||
} else {
|
||||
endOffset = irBlocks_.GetBlock(blockNum + 1)->GetTargetOffset();
|
||||
_assert_msg_(endOffset >= blockOffset, "Next block not sequential, block=%d/%08x, next=%d/%08x", blockNum, blockOffset, blockNum + 1, endOffset);
|
||||
}
|
||||
|
||||
*startOffset = blockOffset;
|
||||
*size = endOffset - blockOffset;
|
||||
}
|
||||
|
||||
JitBlockDebugInfo RiscVBlockCacheDebugInterface::GetBlockDebugInfo(int blockNum) const {
|
||||
JitBlockDebugInfo debugInfo = irBlocks_.GetBlockDebugInfo(blockNum);
|
||||
|
||||
int blockOffset, codeSize;
|
||||
GetBlockCodeRange(blockNum, &blockOffset, &codeSize);
|
||||
debugInfo.targetDisasm = DisassembleRV64(jit_.GetBasePtr() + blockOffset, codeSize);
|
||||
return debugInfo;
|
||||
}
|
||||
|
||||
void RiscVBlockCacheDebugInterface::ComputeStats(BlockCacheStats &bcStats) const {
|
||||
double totalBloat = 0.0;
|
||||
double maxBloat = 0.0;
|
||||
double minBloat = 1000000000.0;
|
||||
int numBlocks = GetNumBlocks();
|
||||
for (int i = 0; i < numBlocks; ++i) {
|
||||
const IRBlock &b = *irBlocks_.GetBlock(i);
|
||||
|
||||
// RISC-V (jit) size.
|
||||
int blockOffset, codeSize;
|
||||
GetBlockCodeRange(i, &blockOffset, &codeSize);
|
||||
if (codeSize == 0)
|
||||
continue;
|
||||
|
||||
// MIPS (PSP) size.
|
||||
u32 origAddr, mipsBytes;
|
||||
b.GetRange(origAddr, mipsBytes);
|
||||
|
||||
double bloat = (double)codeSize / (double)mipsBytes;
|
||||
if (bloat < minBloat) {
|
||||
minBloat = bloat;
|
||||
bcStats.minBloatBlock = origAddr;
|
||||
}
|
||||
if (bloat > maxBloat) {
|
||||
maxBloat = bloat;
|
||||
bcStats.maxBloatBlock = origAddr;
|
||||
}
|
||||
totalBloat += bloat;
|
||||
bcStats.bloatMap[bloat] = origAddr;
|
||||
}
|
||||
bcStats.numBlocks = numBlocks;
|
||||
bcStats.minBloat = minBloat;
|
||||
bcStats.maxBloat = maxBloat;
|
||||
bcStats.avgBloat = totalBloat / (double)numBlocks;
|
||||
}
|
||||
|
||||
} // namespace MIPSComp
|
||||
@@ -28,6 +28,23 @@
|
||||
|
||||
namespace MIPSComp {
|
||||
|
||||
class RiscVJit;
|
||||
|
||||
class RiscVBlockCacheDebugInterface : public JitBlockCacheDebugInterface {
|
||||
public:
|
||||
RiscVBlockCacheDebugInterface(IRBlockCache &irBlocks, RiscVJit &jit);
|
||||
int GetNumBlocks() const;
|
||||
int GetBlockNumberFromStartAddress(u32 em_address, bool realBlocksOnly = true) const;
|
||||
JitBlockDebugInfo GetBlockDebugInfo(int blockNum) const;
|
||||
void ComputeStats(BlockCacheStats &bcStats) const;
|
||||
|
||||
private:
|
||||
void GetBlockCodeRange(int blockNum, int *startOffset, int *size) const;
|
||||
|
||||
IRBlockCache &irBlocks_;
|
||||
RiscVJit &jit_;
|
||||
};
|
||||
|
||||
class RiscVJit : public RiscVGen::RiscVCodeBlock, public IRJit {
|
||||
public:
|
||||
RiscVJit(MIPSState *mipsState);
|
||||
@@ -43,7 +60,7 @@ public:
|
||||
|
||||
void ClearCache() override;
|
||||
|
||||
// TODO: GetBlockCacheDebugInterface, block linking?
|
||||
JitBlockCacheDebugInterface *GetBlockCacheDebugInterface() override;
|
||||
|
||||
protected:
|
||||
bool CompileTargetBlock(IRBlock *block, int block_num, bool preload) override;
|
||||
@@ -116,6 +133,7 @@ private:
|
||||
|
||||
RiscVRegCache gpr;
|
||||
RiscVRegCacheFPU fpr;
|
||||
RiscVBlockCacheDebugInterface debugInterface_;
|
||||
|
||||
const u8 *enterDispatcher_ = nullptr;
|
||||
|
||||
|
||||
Reference in new issue
Block a user