diff --git a/src/common/scripting/jit/jit.cpp b/src/common/scripting/jit/jit.cpp index dd499bdd400..ea10ec79cd1 100644 --- a/src/common/scripting/jit/jit.cpp +++ b/src/common/scripting/jit/jit.cpp @@ -7,23 +7,24 @@ extern PString *TypeString; extern PStruct *TypeVector2; extern PStruct *TypeVector3; -IRContext* JitGetIRContext(); +JITRuntime* GetJITRuntime(); JitFuncPtr JitCompile(VMScriptFunction* sfunc) { -#if 1 +#if 0 if (strcmp(sfunc->PrintableName.GetChars(), "StatusScreen.drawNum") != 0) return nullptr; #endif try { - IRContext* context = JitGetIRContext(); - JitCompiler compiler(context, sfunc); + JITRuntime* jit = GetJITRuntime(); + IRContext context; + JitCompiler compiler(&context, sfunc); IRFunction* func = compiler.Codegen(); - context->codegen(); - std::string text = context->getFunctionAssembly(func); - return reinterpret_cast(context->getPointerToFunction(func)); + jit->add(&context); + //std::string text = context->getFunctionAssembly(func); + return reinterpret_cast(jit->getPointerToFunction(func->name)); } catch (...) { @@ -36,10 +37,10 @@ void JitDumpLog(FILE* file, VMScriptFunction* sfunc) { try { - IRContext* context = JitGetIRContext(); - JitCompiler compiler(context, sfunc); + IRContext context; + JitCompiler compiler(&context, sfunc); IRFunction* func = compiler.Codegen(); - std::string text = context->getFunctionAssembly(func); + std::string text = context.getFunctionAssembly(func); fwrite(text.data(), text.size(), 1, file); } catch (const std::exception& e) diff --git a/src/common/scripting/jit/jit_runtime.cpp b/src/common/scripting/jit/jit_runtime.cpp index c17ac3a76a8..c374c86148f 100644 --- a/src/common/scripting/jit/jit_runtime.cpp +++ b/src/common/scripting/jit/jit_runtime.cpp @@ -5,15 +5,15 @@ #if 1 -static IRContext* JitIRContext = nullptr; +static JITRuntime* JITRuntimeVar = nullptr; -IRContext* JitGetIRContext() +JITRuntime* GetJITRuntime() { - if (!JitIRContext) + if (!JITRuntimeVar) { - JitIRContext = new IRContext(); + JITRuntimeVar = new JITRuntime(); } - return JitIRContext; + return JITRuntimeVar; } FString JitCaptureStackTrace(int framesToSkip, bool includeNativeFrames) @@ -23,8 +23,8 @@ FString JitCaptureStackTrace(int framesToSkip, bool includeNativeFrames) void JitRelease() { - delete JitIRContext; - JitIRContext = nullptr; + delete JITRuntimeVar; + JITRuntimeVar = nullptr; } #else diff --git a/src/common/scripting/vm/vmframe.cpp b/src/common/scripting/vm/vmframe.cpp index 7c2a63b1f71..6f26d2af369 100644 --- a/src/common/scripting/vm/vmframe.cpp +++ b/src/common/scripting/vm/vmframe.cpp @@ -264,24 +264,10 @@ int VMScriptFunction::PCToLine(const VMOP *pc) return -1; } -static bool CanJit(VMScriptFunction *func) -{ - // Asmjit has a 256 register limit. Stay safely away from it as the jit compiler uses a few for temporaries as well. - // Any function exceeding the limit will use the VM - a fair punishment to someone for writing a function so bloated ;) - - int maxregs = 200; - if (func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS < maxregs) - return true; - - Printf(TEXTCOLOR_ORANGE "%s is using too many registers (%d of max %d)! Function will not use native code.\n", func->PrintableName.GetChars(), func->NumRegA + func->NumRegD + func->NumRegF + func->NumRegS, maxregs); - - return false; -} - int VMScriptFunction::FirstScriptCall(VMFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret) { #ifdef HAVE_VM_JIT - if (vm_jit && CanJit(static_cast(func))) + if (vm_jit) { func->ScriptCall = JitCompile(static_cast(func)); if (!func->ScriptCall)