jit: Add interface to precompile functions.

This doesn't actually do any preloading yet, it just adds an API.
This commit is contained in:
Unknown W. Brackets 2018-01-06 16:43:38 -08:00
parent ccd562d934
commit 6149ac584f
7 changed files with 38 additions and 2 deletions

View File

@ -406,6 +406,7 @@ static ConfigSetting cpuSettings[] = {
ConfigSetting("FastMemoryAccess", &g_Config.bFastMemory, true, true, true),
ReportedConfigSetting("FuncReplacements", &g_Config.bFuncReplacements, true, true, true),
ConfigSetting("HideSlowWarnings", &g_Config.bHideSlowWarnings, false, true, false),
ConfigSetting("PreloadFunctions", &g_Config.bPreloadFunctions, false, true, true),
ReportedConfigSetting("CPUSpeed", &g_Config.iLockedCPUSpeed, 0, true, true),
ConfigSetting(false),

View File

@ -126,6 +126,7 @@ public:
bool bForceLagSync;
bool bFuncReplacements;
bool bHideSlowWarnings;
bool bPreloadFunctions;
bool bSeparateSASThread;
bool bSeparateIOThread;

View File

@ -712,6 +712,7 @@ void ImportFuncSymbol(const FuncSymbolImport &func, bool reimporting) {
}
WriteSyscall(func.moduleName, func.nid, func.stubAddr);
currentMIPS->InvalidateICache(func.stubAddr, 8);
MIPSAnalyst::PrecompileFunction(func.stubAddr, 8);
return;
}
@ -730,6 +731,7 @@ void ImportFuncSymbol(const FuncSymbolImport &func, bool reimporting) {
}
WriteFuncStub(func.stubAddr, it->symAddr);
currentMIPS->InvalidateICache(func.stubAddr, 8);
MIPSAnalyst::PrecompileFunction(func.stubAddr, 8);
return;
}
}
@ -768,6 +770,7 @@ void ExportFuncSymbol(const FuncSymbolExport &func) {
INFO_LOG(LOADER, "Resolving function %s/%08x", func.moduleName, func.nid);
WriteFuncStub(it->stubAddr, func.symAddr);
currentMIPS->InvalidateICache(it->stubAddr, 8);
MIPSAnalyst::PrecompileFunction(it->stubAddr, 8);
}
}
}
@ -1450,6 +1453,9 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
// use module_start_func instead of entry_addr if entry_addr is 0
if (module->nm.entry_addr == 0)
module->nm.entry_addr = module->nm.module_start_func;
MIPSAnalyst::PrecompileFunctions();
} else {
module->nm.entry_addr = -1;
}

View File

@ -26,7 +26,7 @@
#include "Common/CommonTypes.h"
#include "Core/HLE/HLE.h"
#include "Core/HLE/HLETables.h"
#include "Core/MIPS/MIPSInt.h"
#include "Core/MIPS/MIPSAnalyst.h"
#include "Core/MIPS/MIPSCodeUtils.h"
#include "Core/MIPS/MIPS.h"
#include "Core/CoreTiming.h"
@ -887,6 +887,7 @@ static void __KernelWriteFakeSysCall(u32 nid, u32 *ptr, u32 &pos)
*ptr = pos;
pos += 8;
WriteSyscall("FakeSysCalls", nid, *ptr);
MIPSAnalyst::PrecompileFunction(*ptr, 8);
}
void __KernelThreadingInit()

View File

@ -129,6 +129,7 @@ namespace MIPSComp {
virtual void DoState(PointerWrap &p) = 0;
virtual void RunLoopUntil(u64 globalticks) = 0;
virtual void Compile(u32 em_address) = 0;
virtual void CompileFunction(u32 start_address, u32 length) { }
virtual void ClearCache() = 0;
virtual MIPSOpcode GetOriginalOp(MIPSOpcode op) = 0;

View File

@ -21,6 +21,7 @@
#include <unordered_set>
#include <mutex>
#include "base/timeutil.h"
#include "ext/cityhash/city.h"
#include "Common/FileUtil.h"
#include "Core/Config.h"
@ -904,6 +905,30 @@ skip:
}
}
void PrecompileFunction(u32 startAddr, u32 length) {
// Direct calls to this ignore the bPreloadFunctions flag, since it's just for stubs.
if (MIPSComp::jit) {
MIPSComp::jit->CompileFunction(startAddr, length);
}
}
void PrecompileFunctions() {
if (!g_Config.bPreloadFunctions) {
return;
}
std::lock_guard<std::recursive_mutex> guard(functions_lock);
double st = real_time_now();
for (auto iter = functions.begin(), end = functions.end(); iter != end; iter++) {
const AnalyzedFunction &f = *iter;
PrecompileFunction(f.start, f.end - f.start + 4);
}
double et = real_time_now();
NOTICE_LOG(JIT, "Precompiled %d MIPS functions in %0.2f milliseconds", (int)functions.size(), (et - st) * 1000.0);
}
static const char *DefaultFunctionName(char buffer[256], u32 startAddr) {
sprintf(buffer, "z_un_%08x", startAddr);
return buffer;

View File

@ -107,7 +107,8 @@ namespace MIPSAnalyst
void RegisterFunction(u32 startAddr, u32 size, const char *name);
void ScanForFunctions(u32 startAddr, u32 endAddr, bool insertSymbols);
void ForgetFunctions(u32 startAddr, u32 endAddr);
void CompileLeafs();
void PrecompileFunctions();
void PrecompileFunction(u32 startAddr, u32 length);
void SetHashMapFilename(const std::string& filename = "");
void LoadBuiltinHashMap();