Skip to content

Commit

Permalink
irjit: Skip preloading blocks with jump to 0.
Browse files Browse the repository at this point in the history
These will be changed before executing anyway.
  • Loading branch information
unknownbrackets committed Jan 7, 2018
1 parent cc8e9a9 commit 97674b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
9 changes: 5 additions & 4 deletions Core/MIPS/IR/IRCompBranch.cpp
Expand Up @@ -295,11 +295,12 @@ void IRFrontend::Comp_Jump(MIPSOpcode op) {


// Might be a stubbed address or something? // Might be a stubbed address or something?
if (!Memory::IsValidAddress(targetAddr)) { if (!Memory::IsValidAddress(targetAddr)) {
if (js.nextExit == 0) { // If preloading, flush - this block will likely be fixed later.
if (js.preloading)
js.cancel = true;
else
ERROR_LOG_REPORT(JIT, "Jump to invalid address: %08x", targetAddr); ERROR_LOG_REPORT(JIT, "Jump to invalid address: %08x", targetAddr);
} else { js.compiling = false;
js.compiling = false;
}
// TODO: Mark this block dirty or something? May be indication it will be changed by imports. // TODO: Mark this block dirty or something? May be indication it will be changed by imports.
return; return;
} }
Expand Down
8 changes: 7 additions & 1 deletion Core/MIPS/IR/IRFrontend.cpp
Expand Up @@ -219,8 +219,9 @@ MIPSOpcode IRFrontend::GetOffsetInstruction(int offset) {
return Memory::Read_Instruction(GetCompilerPC() + 4 * offset); return Memory::Read_Instruction(GetCompilerPC() + 4 * offset);
} }


void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes) { void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes, bool preload) {
js.cancel = false; js.cancel = false;
js.preloading = preload;
js.blockStart = em_address; js.blockStart = em_address;
js.compilerPC = em_address; js.compilerPC = em_address;
js.lastContinuedPC = 0; js.lastContinuedPC = 0;
Expand All @@ -246,6 +247,11 @@ void IRFrontend::DoJit(u32 em_address, std::vector<IRInst> &instructions, u32 &m
js.numInstructions++; js.numInstructions++;
} }


if (js.cancel) {
// Clear the instructions to signal this was not compiled.
ir.Clear();
}

mipsBytes = js.compilerPC - em_address; mipsBytes = js.compilerPC - em_address;


IRWriter simplified; IRWriter simplified;
Expand Down
2 changes: 1 addition & 1 deletion Core/MIPS/IR/IRFrontend.h
Expand Up @@ -88,7 +88,7 @@ class IRFrontend : public MIPSFrontendInterface {
void DoState(PointerWrap &p); void DoState(PointerWrap &p);
bool CheckRounding(u32 blockAddress); // returns true if we need a do-over bool CheckRounding(u32 blockAddress); // returns true if we need a do-over


void DoJit(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes); void DoJit(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes, bool preload);


void EatPrefix() override { void EatPrefix() override {
js.EatPrefix(); js.EatPrefix();
Expand Down
9 changes: 7 additions & 2 deletions Core/MIPS/IR/IRJit.cpp
Expand Up @@ -98,14 +98,19 @@ void IRJit::Compile(u32 em_address) {
} }


bool IRJit::CompileBlock(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes, bool preload) { bool IRJit::CompileBlock(u32 em_address, std::vector<IRInst> &instructions, u32 &mipsBytes, bool preload) {
frontend_.DoJit(em_address, instructions, mipsBytes, preload);
if (instructions.empty()) {
_dbg_assert_(JIT, preload);
// We return true when preloading so it doesn't abort.
return preload;
}

int block_num = blocks_.AllocateBlock(em_address); int block_num = blocks_.AllocateBlock(em_address);
if ((block_num & ~MIPS_EMUHACK_VALUE_MASK) != 0) { if ((block_num & ~MIPS_EMUHACK_VALUE_MASK) != 0) {
// Out of block numbers. Caller will handle. // Out of block numbers. Caller will handle.
return false; return false;
} }


frontend_.DoJit(em_address, instructions, mipsBytes);

IRBlock *b = blocks_.GetBlock(block_num); IRBlock *b = blocks_.GetBlock(block_num);
b->SetInstructions(instructions); b->SetInstructions(instructions);
b->SetOriginalSize(mipsBytes); b->SetOriginalSize(mipsBytes);
Expand Down
24 changes: 8 additions & 16 deletions Core/MIPS/JitCommon/JitState.h
Expand Up @@ -56,15 +56,6 @@ namespace MIPSComp {
AFTER_MEMCHECK_CLEANUP = 0x04, AFTER_MEMCHECK_CLEANUP = 0x04,
}; };


JitState()
: hasSetRounding(0),
lastSetRounding(0),
currentRoundingFunc(nullptr),
startDefaultPrefix(true),
prefixSFlag(PREFIX_UNKNOWN),
prefixTFlag(PREFIX_UNKNOWN),
prefixDFlag(PREFIX_UNKNOWN) {}

u32 compilerPC; u32 compilerPC;
u32 blockStart; u32 blockStart;
u32 lastContinuedPC; u32 lastContinuedPC;
Expand All @@ -78,20 +69,21 @@ namespace MIPSComp {
int numInstructions; int numInstructions;
bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block bool compiling; // TODO: get rid of this in favor of using analysis results to determine end of block
bool hadBreakpoints; bool hadBreakpoints;
bool preloading = false;
JitBlock *curBlock; JitBlock *curBlock;


u8 hasSetRounding; u8 hasSetRounding = 0;
u8 lastSetRounding; u8 lastSetRounding = 0;
const u8 *currentRoundingFunc; const u8 *currentRoundingFunc = nullptr;


// VFPU prefix magic // VFPU prefix magic
bool startDefaultPrefix; bool startDefaultPrefix = true;
u32 prefixS; u32 prefixS;
u32 prefixT; u32 prefixT;
u32 prefixD; u32 prefixD;
PrefixState prefixSFlag; PrefixState prefixSFlag = PREFIX_UNKNOWN;
PrefixState prefixTFlag; PrefixState prefixTFlag = PREFIX_UNKNOWN;
PrefixState prefixDFlag; PrefixState prefixDFlag = PREFIX_UNKNOWN;


void PrefixStart() { void PrefixStart() {
if (startDefaultPrefix) { if (startDefaultPrefix) {
Expand Down

0 comments on commit 97674b8

Please sign in to comment.