Skip to content

Commit

Permalink
JIT-Compile all functions during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoLuis0 authored and madame-rachelle committed Dec 6, 2023
1 parent aed85a2 commit 43c70cd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/common/scripting/backend/vmbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

CVAR(Bool, strictdecorate, false, CVAR_GLOBALCONFIG | CVAR_ARCHIVE)

EXTERN_CVAR(Bool, vm_jit)
EXTERN_CVAR(Bool, vm_jit_aot)

struct VMRemap
{
uint8_t altOp, kReg, kType;
Expand Down Expand Up @@ -928,6 +931,13 @@ void FFunctionBuildList::Build()
disasmdump.Write(sfunc, item.PrintableName);

sfunc->Unsafe = ctx.Unsafe;

#if HAVE_VM_JIT
if(vm_jit && vm_jit_aot)
{
sfunc->JitCompile();
}
#endif
}
catch (CRecoverableError &err)
{
Expand Down Expand Up @@ -1094,8 +1104,6 @@ void FunctionCallEmitter::AddParameterStringConst(const FString &konst)
});
}

EXTERN_CVAR(Bool, vm_jit)

ExpEmit FunctionCallEmitter::EmitCall(VMFunctionBuilder *build, TArray<ExpEmit> *ReturnRegs)
{
unsigned paramcount = 0;
Expand Down
39 changes: 27 additions & 12 deletions src/common/scripting/vm/vmframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ CUSTOM_CVAR(Bool, vm_jit, true, CVAR_NOINITCALL)
Printf("You must restart " GAMENAME " for this change to take effect.\n");
Printf("This cvar is currently not saved. You must specify it on the command line.");
}
CUSTOM_CVAR(Bool, vm_jit_aot, true, CVAR_NOINITCALL)
{
Printf("You must restart " GAMENAME " for this change to take effect.\n");
Printf("This cvar is currently not saved. You must specify it on the command line.");
}
#else
CVAR(Bool, vm_jit, false, CVAR_NOINITCALL|CVAR_NOSET)
CVAR(Bool, vm_jit_aot, false, CVAR_NOINITCALL|CVAR_NOSET)
FString JitCaptureStackTrace(int framesToSkip, bool includeNativeFrames, int maxFrames) { return FString(); }
void JitRelease() {}
#endif
Expand Down Expand Up @@ -282,6 +288,25 @@ static bool CanJit(VMScriptFunction *func)
return false;
}

void VMScriptFunction::JitCompile()
{
if(!(VarFlags & VARF_Abstract))
{
#ifdef HAVE_VM_JIT
if (vm_jit && CanJit(this))
{
ScriptCall = ::JitCompile(this);
if (!ScriptCall)
ScriptCall = VMExec;
}
else
#endif // HAVE_VM_JIT
{
ScriptCall = VMExec;
}
}
}

int VMScriptFunction::FirstScriptCall(VMFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret)
{
// [Player701] Check that we aren't trying to call an abstract function.
Expand All @@ -291,18 +316,8 @@ int VMScriptFunction::FirstScriptCall(VMFunction *func, VMValue *params, int num
{
ThrowAbortException(X_OTHER, "attempt to call abstract function %s.", func->PrintableName);
}
#ifdef HAVE_VM_JIT
if (vm_jit && CanJit(static_cast<VMScriptFunction*>(func)))
{
func->ScriptCall = JitCompile(static_cast<VMScriptFunction*>(func));
if (!func->ScriptCall)
func->ScriptCall = VMExec;
}
else
#endif // HAVE_VM_JIT
{
func->ScriptCall = VMExec;
}

static_cast<VMScriptFunction*>(func)->JitCompile();

return func->ScriptCall(func, params, numparams, ret, numret);
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/scripting/vm/vmintern.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,6 @@ class VMScriptFunction : public VMFunction

private:
static int FirstScriptCall(VMFunction *func, VMValue *params, int numparams, VMReturn *ret, int numret);
void JitCompile();
friend class FFunctionBuildList;
};

0 comments on commit 43c70cd

Please sign in to comment.