#pragma once
#if ENABLE(FTL_JIT)
#include "CCallHelpers.h"
#include "FTLSlowPathCallKey.h"
#include "FTLState.h"
namespace JSC { namespace FTL {
class SlowPathCall {
public:
SlowPathCall() { }
SlowPathCall(MacroAssembler::Call call, const SlowPathCallKey& key)
: m_call(call)
, m_key(key)
{
}
MacroAssembler::Call call() const { return m_call; }
SlowPathCallKey key() const { return m_key; }
private:
MacroAssembler::Call m_call;
SlowPathCallKey m_key;
};
class SlowPathCallContext {
public:
SlowPathCallContext(RegisterSet usedRegisters, CCallHelpers&, unsigned numArgs, GPRReg returnRegister);
~SlowPathCallContext();
SlowPathCall makeCall(VM&, void* callTarget);
private:
SlowPathCallKey keyWithTarget(void* callTarget) const;
RegisterSet m_argumentRegisters;
RegisterSet m_callingConventionRegisters;
CCallHelpers& m_jit;
unsigned m_numArgs;
GPRReg m_returnRegister;
size_t m_offsetToSavingArea;
size_t m_stackBytesNeeded;
RegisterSet m_thunkSaveSet;
ptrdiff_t m_offset;
};
template<typename... ArgumentTypes>
SlowPathCall callOperation(
VM& vm, const RegisterSet& usedRegisters, CCallHelpers& jit, CCallHelpers::JumpList* exceptionTarget,
FunctionPtr function, GPRReg resultGPR, ArgumentTypes... arguments)
{
SlowPathCall call;
{
SlowPathCallContext context(usedRegisters, jit, sizeof...(ArgumentTypes) + 1, resultGPR);
jit.setupArgumentsWithExecState(arguments...);
call = context.makeCall(vm, function.value());
}
if (exceptionTarget)
exceptionTarget->append(jit.emitExceptionCheck(vm));
return call;
}
template<typename... ArgumentTypes>
SlowPathCall callOperation(
VM& vm, const RegisterSet& usedRegisters, CCallHelpers& jit, CallSiteIndex callSiteIndex,
CCallHelpers::JumpList* exceptionTarget, FunctionPtr function, GPRReg resultGPR,
ArgumentTypes... arguments)
{
if (callSiteIndex) {
jit.store32(
CCallHelpers::TrustedImm32(callSiteIndex.bits()),
CCallHelpers::tagFor(CallFrameSlot::argumentCount));
}
return callOperation(vm, usedRegisters, jit, exceptionTarget, function, resultGPR, arguments...);
}
CallSiteIndex callSiteIndexForCodeOrigin(State&, CodeOrigin);
template<typename... ArgumentTypes>
SlowPathCall callOperation(
State& state, const RegisterSet& usedRegisters, CCallHelpers& jit, CodeOrigin codeOrigin,
CCallHelpers::JumpList* exceptionTarget, FunctionPtr function, GPRReg result, ArgumentTypes... arguments)
{
return callOperation(
state.vm(), usedRegisters, jit, callSiteIndexForCodeOrigin(state, codeOrigin), exceptionTarget, function,
result, arguments...);
}
} }
#endif // ENABLE(FTL_JIT)