#ifndef DFGJITCompiler_h
#define DFGJITCompiler_h
#if ENABLE(DFG_JIT)
#include <assembler/MacroAssembler.h>
#include <bytecode/CodeBlock.h>
#include <dfg/DFGGraph.h>
#include <dfg/DFGRegisterBank.h>
#include <jit/JITCode.h>
#include <dfg/DFGFPRInfo.h>
#include <dfg/DFGGPRInfo.h>
namespace JSC {
class AbstractSamplingCounter;
class CodeBlock;
class JSGlobalData;
namespace DFG {
class JITCodeGenerator;
class NonSpeculativeJIT;
class SpeculativeJIT;
class SpeculationRecovery;
struct EntryLocation;
struct SpeculationCheck;
struct CallRecord {
CallRecord(MacroAssembler::Call call, FunctionPtr function)
: m_call(call)
, m_function(function)
{
}
CallRecord(MacroAssembler::Call call, FunctionPtr function, MacroAssembler::Jump exceptionCheck, ExceptionInfo exceptionInfo)
: m_call(call)
, m_function(function)
, m_exceptionCheck(exceptionCheck)
, m_exceptionInfo(exceptionInfo)
{
}
MacroAssembler::Call m_call;
FunctionPtr m_function;
MacroAssembler::Jump m_exceptionCheck;
ExceptionInfo m_exceptionInfo;
};
class JITCompiler : public MacroAssembler {
public:
JITCompiler(JSGlobalData* globalData, Graph& dfg, CodeBlock* codeBlock)
: m_globalData(globalData)
, m_graph(dfg)
, m_codeBlock(codeBlock)
{
}
void compileFunction(JITCode& entry, MacroAssemblerCodePtr& entryWithArityCheck);
Graph& graph() { return m_graph; }
CodeBlock* codeBlock() { return m_codeBlock; }
JSGlobalData* globalData() { return m_globalData; }
#if CPU(X86_64)
void preserveReturnAddressAfterCall(GPRReg reg)
{
pop(reg);
}
void restoreReturnAddressBeforeReturn(GPRReg reg)
{
push(reg);
}
void restoreReturnAddressBeforeReturn(Address address)
{
push(address);
}
void emitGetFromCallFrameHeaderPtr(RegisterFile::CallFrameHeaderEntry entry, GPRReg to)
{
loadPtr(Address(GPRInfo::callFrameRegister, entry * sizeof(Register)), to);
}
void emitPutToCallFrameHeader(GPRReg from, RegisterFile::CallFrameHeaderEntry entry)
{
storePtr(from, Address(GPRInfo::callFrameRegister, entry * sizeof(Register)));
}
void emitPutImmediateToCallFrameHeader(void* value, RegisterFile::CallFrameHeaderEntry entry)
{
storePtr(TrustedImmPtr(value), Address(GPRInfo::callFrameRegister, entry * sizeof(Register)));
}
#endif
static Address addressForGlobalVar(GPRReg global, int32_t varNumber)
{
return Address(global, varNumber * sizeof(Register));
}
static Address addressFor(VirtualRegister virtualRegister)
{
return Address(GPRInfo::callFrameRegister, virtualRegister * sizeof(Register));
}
static Address tagFor(VirtualRegister virtualRegister)
{
return Address(GPRInfo::callFrameRegister, virtualRegister * sizeof(Register) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.tag));
}
static Address payloadFor(VirtualRegister virtualRegister)
{
return Address(GPRInfo::callFrameRegister, virtualRegister * sizeof(Register) + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload));
}
void appendCall(const FunctionPtr& function)
{
m_calls.append(CallRecord(call(), function));
}
void appendCallWithExceptionCheck(const FunctionPtr& function, unsigned exceptionInfo)
{
Call functionCall = call();
Jump exceptionCheck = branchTestPtr(NonZero, AbsoluteAddress(&globalData()->exception));
m_calls.append(CallRecord(functionCall, function, exceptionCheck, exceptionInfo));
}
bool isConstant(NodeIndex nodeIndex)
{
return graph()[nodeIndex].isConstant();
}
bool isInt32Constant(NodeIndex nodeIndex)
{
return graph()[nodeIndex].op == Int32Constant;
}
bool isDoubleConstant(NodeIndex nodeIndex)
{
return graph()[nodeIndex].op == DoubleConstant;
}
bool isJSConstant(NodeIndex nodeIndex)
{
return graph()[nodeIndex].op == JSConstant;
}
int32_t valueOfInt32Constant(NodeIndex nodeIndex)
{
ASSERT(isInt32Constant(nodeIndex));
return graph()[nodeIndex].int32Constant();
}
double valueOfDoubleConstant(NodeIndex nodeIndex)
{
ASSERT(isDoubleConstant(nodeIndex));
return graph()[nodeIndex].numericConstant();
}
JSValue valueOfJSConstant(NodeIndex nodeIndex)
{
ASSERT(isJSConstant(nodeIndex));
unsigned constantIndex = graph()[nodeIndex].constantNumber();
return codeBlock()->constantRegister(FirstConstantRegisterIndex + constantIndex).get();
}
#if DFG_JIT_ASSERT
void jitAssertIsInt32(GPRReg);
void jitAssertIsJSInt32(GPRReg);
void jitAssertIsJSNumber(GPRReg);
void jitAssertIsJSDouble(GPRReg);
#else
void jitAssertIsInt32(GPRReg) {}
void jitAssertIsJSInt32(GPRReg) {}
void jitAssertIsJSNumber(GPRReg) {}
void jitAssertIsJSDouble(GPRReg) {}
#endif
#if ENABLE(SAMPLING_COUNTERS)
void emitCount(AbstractSamplingCounter&, uint32_t increment = 1);
#endif
#if ENABLE(SAMPLING_FLAGS)
void setSamplingFlag(int32_t flag);
void clearSamplingFlag(int32_t flag);
#endif
private:
void fillNumericToDouble(NodeIndex, FPRReg, GPRReg temporary);
void fillInt32ToInteger(NodeIndex, GPRReg);
void fillToJS(NodeIndex, GPRReg);
void jumpFromSpeculativeToNonSpeculative(const SpeculationCheck&, const EntryLocation&, SpeculationRecovery*);
void linkSpeculationChecks(SpeculativeJIT&, NonSpeculativeJIT&);
JSGlobalData* m_globalData;
Graph& m_graph;
CodeBlock* m_codeBlock;
Vector<CallRecord> m_calls;
};
} }
#endif
#endif