From 52aae9b3e659132c54befecdbd9872bc992e5a9b Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Fri, 3 Apr 2020 18:02:51 -0700 Subject: [PATCH] Optimize the syscall IR op argument loading based on syscall definition When we have function calls we can call the handler directly instead of a thunk step in between --- .../Interface/IR/Passes/SyscallOptimization.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/External/FEXCore/Source/Interface/IR/Passes/SyscallOptimization.cpp b/External/FEXCore/Source/Interface/IR/Passes/SyscallOptimization.cpp index c2b84bf3e..3e25da55c 100644 --- a/External/FEXCore/Source/Interface/IR/Passes/SyscallOptimization.cpp +++ b/External/FEXCore/Source/Interface/IR/Passes/SyscallOptimization.cpp @@ -1,3 +1,4 @@ +#include "Interface/Context/Context.h" #include "Interface/IR/PassManager.h" #include "Interface/Core/OpcodeDispatcher.h" @@ -41,10 +42,17 @@ bool SyscallOptimization::Run(OpDispatchBuilder *Disp) { // Is the first argument a constant? uint64_t Constant; if (Disp->IsValueConstant(IROp->Args[0], &Constant)) { - // XXX: We can now optimize this syscall - //Changed = true; + auto SyscallDef = Disp->CTX->SyscallHandler->GetDefinition(Constant); + // XXX: Once we have the ability to do real function calls then we can call directly in to the syscall handler + if (SyscallDef->NumArgs < FEXCore::HLE::SyscallArguments::MAX_ARGS) { + // If the number of args are less than what the IR op supports then we can remove arg usage + // We need +1 since we are still passing in syscall number here + for (uint8_t Arg = (SyscallDef->NumArgs + 1); Arg < FEXCore::HLE::SyscallArguments::MAX_ARGS; ++Arg) { + Disp->ReplaceNodeArgument(CodeNode, Arg, Disp->Invalid()); + } + Changed = true; + } } - } // CodeLast is inclusive. So we still need to dump the CodeLast op as well