/*
 * Copyright (C) 2008, 2012 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#pragma once

// #if ENABLE(JIT)

// Verbose logging of code generation
#define ENABLE_JIT_VERBOSE 0
// Verbose logging for OSR-related code.
#define ENABLE_JIT_VERBOSE_OSR 0

#define ENABLE_JIT_PROFILE 0

// We've run into some problems where changing the size of the class JIT leads to
// performance fluctuations.  Try forcing alignment in an attempt to stabalize this.
#if COMPILER(GCC)
#define JIT_CLASS_ALIGNMENT __attribute__ ((aligned (32)))
#else
#define JIT_CLASS_ALIGNMENT
#endif

#define ASSERT_JIT_OFFSET(actual, expected) ASSERT_WITH_MESSAGE(actual == expected, "JIT Offset \"%s\" should be %d, not %d.\n", #expected, static_cast<int>(expected), static_cast<int>(actual));

#include "CodeBlock.h"
#include "Interpreter.h"
#include "JITInlineCacheGenerator.h"
#include "JITMathIC.h"
#include "JSInterfaceJIT.h"
#include "Opcode.h"
#include "Profiler.h"
#include "UnusedPointer.h"
#include <bytecode/SamplingTool.h>
#include <wtf/PassOwnPtr.h>

namespace JSC {

class ArrayAllocationProfile;
class CallLinkInfo;
class CodeBlock;
class FunctionExecutable;
class JIT;
class Identifier;
class Interpreter;
class MarkedAllocator;
class Register;
class JSStack;
class JSScope;
class StructureChain;

struct Instruction;
struct OperandTypes;
struct SimpleJumpTable;
struct StringJumpTable;
struct StructureStubInfo;

struct CallRecord {
	MacroAssembler::Call from;
	unsigned bytecodeOffset;
	void* to;

	CallRecord()
	{
	}

	CallRecord(MacroAssembler::Call from, unsigned bytecodeOffset, void* to = 0)
		: from(from)
		, bytecodeOffset(bytecodeOffset)
		, to(to)
	{
	}
};

struct JumpTable {
	MacroAssembler::Jump from;
	unsigned toBytecodeOffset;

	JumpTable(const MacroAssembler::Jump& f, unsigned t)
		: from(f)
		, toBytecodeOffset(t)
	{
	}
};

struct SlowCaseEntry {
	MacroAssembler::Jump from;
	unsigned to;

	SlowCaseEntry(const MacroAssembler::Jump& f, unsigned t)
		: from(f)
		, to(t)
	{
	}
};

struct SwitchRecord {
	enum Type {
		Immediate,
		Character,
		String
	};

	Type type;

	union {
		SimpleJumpTable* simpleJumpTable;
		StringJumpTable* stringJumpTable;
	} jumpTable;

	unsigned bytecodeOffset;
	unsigned defaultOffset;

	SwitchRecord(SimpleJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset, Type type)
		: type(type)
		, bytecodeOffset(bytecodeOffset)
		, defaultOffset(defaultOffset)
	{
		this->jumpTable.simpleJumpTable = jumpTable;
	}

	SwitchRecord(StringJumpTable* jumpTable, unsigned bytecodeOffset, unsigned defaultOffset)
		: type(String)
		, bytecodeOffset(bytecodeOffset)
		, defaultOffset(defaultOffset)
	{
		this->jumpTable.stringJumpTable = jumpTable;
	}
};

struct ByValCompilationInfo {
	ByValCompilationInfo() { }

    ByValCompilationInfo(ByValInfo* byValInfo, unsigned bytecodeIndex, MacroAssembler::PatchableJump notIndexJump, MacroAssembler::PatchableJump badTypeJump, JITArrayMode arrayMode, ArrayProfile* arrayProfile, MacroAssembler::Label doneTarget, MacroAssembler::Label nextHotPathTarget)
        : byValInfo(byValInfo)
        , bytecodeIndex(bytecodeIndex)
        , notIndexJump(notIndexJump)
        , badTypeJump(badTypeJump)
        , arrayMode(arrayMode)
        , arrayProfile(arrayProfile)
        , doneTarget(doneTarget)
        , nextHotPathTarget(nextHotPathTarget)
    {
    }

    ByValCompilationInfo(ByValInfo* byValInfo, unsigned bytecodeIndex, MacroAssembler::PatchableJump notIndexJump, MacroAssembler::Label doneTarget, MacroAssembler::Label nextHotPathTarget)
        : byValInfo(byValInfo)
        , bytecodeIndex(bytecodeIndex)
        , notIndexJump(notIndexJump)
        , doneTarget(doneTarget)
        , nextHotPathTarget(nextHotPathTarget)
    {
    }

    ByValInfo* byValInfo { nullptr };
	unsigned bytecodeIndex { 0 };
    MacroAssembler::PatchableJump notIndexJump;
	MacroAssembler::PatchableJump badTypeJump;
	JITArrayMode arrayMode { JITInt32 };
    ArrayProfile* arrayProfile { nullptr };
	MacroAssembler::Label doneTarget;
    MacroAssembler::Label nextHotPathTarget;
	MacroAssembler::Label slowPathTarget;
	MacroAssembler::Call returnAddress;
};

struct CallCompilationInfo {
	MacroAssembler::DataLabelPtr hotPathBegin;
	MacroAssembler::Call hotPathOther;
	MacroAssembler::Call callReturnLocation;
	CallLinkInfo* callLinkInfo;
};

void ctiPatchCallByReturnAddress(ReturnAddressPtr, FunctionPtr newCalleeFunction);

class JIT final : public JSInterfaceJIT {
	friend class JITSlowPathCall;
	friend class JITStubCall;

	using MacroAssembler::Jump;
	using MacroAssembler::JumpList;
	using MacroAssembler::Label;

public:
	~JIT();

	static CompilationResult compile(JSGlobalData* vm, CodeBlock* codeBlock, JITCompilationEffort effort)
	{
		JIT jit(vm, codeBlock);
		return jit.privateCompile(effort);
	}

	static void compileGetByVal(JSGlobalData* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
	{
		JIT jit(vm, codeBlock);
		jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
		jit.privateCompileGetByVal(byValInfo, returnAddress, arrayMode);
	}

    static void compileGetByValWithCachedId(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName)
    {
		JIT jit(vm, codeBlock);
        jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
        jit.privateCompileGetByValWithCachedId(byValInfo, returnAddress, propertyName);
    }

	static void compilePutByVal(JSGlobalData* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode, ECMAMode ecmaMode)
	{
		JIT jit(vm, codeBlock);
		jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
		jit.privateCompilePutByVal(byValInfo, returnAddress, arrayMode, ecmaMode);
	}

	static void compileDirectPutByVal(JSGlobalData* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode, ECMAMode ecmaMode)
	{
		JIT jit(vm, codeBlock);
		jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
		jit.privateCompilePutByVal(byValInfo, returnAddress, arrayMode, ecmaMode);
	}

    static void compilePutByValWithCachedId(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, PutKind putKind, const Identifier& propertyName, ECMAMode ecmaMode)
    {
		JIT jit(vm, codeBlock);
        jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
        jit.privateCompilePutByValWithCachedId(byValInfo, returnAddress, putKind, propertyName, ecmaMode);
    }

    static void compilePutPrivateNameWithCachedId(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, const Identifier& propertyName)
    {
		JIT jit(vm, codeBlock);
        jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
        jit.privateCompilePutPrivateNameWithCachedId(byValInfo, returnAddress, propertyName);
    }

	static void compileHasIndexedProperty(VM* vm, CodeBlock* codeBlock, ByValInfo* byValInfo, ReturnAddressPtr returnAddress, JITArrayMode arrayMode)
	{
		JIT jit(vm, codeBlock);
		jit.m_bytecodeOffset = byValInfo->bytecodeIndex;
		jit.privateCompileHasIndexedProperty(byValInfo, returnAddress, arrayMode);
	}

	static unsigned frameRegisterCountFor(CodeBlock* codeBlock)
	{
		return codeBlock->m_numCalleeLocals;
	}

private:
	JIT(JSGlobalData*, CodeBlock*);

	bool privateCompileMainPass(JITCompilationEffort);
	void privateCompileLinkPass();
	void privateCompileSlowCases();
	CompilationResult privateCompile(JITCompilationEffort);

	void privateCompileGetByVal(ByValInfo*, ReturnAddressPtr, JITArrayMode);
	void privateCompileGetByValWithCachedId(ByValInfo*, ReturnAddressPtr, const Identifier&);
    void privateCompilePutByVal(ByValInfo*, ReturnAddressPtr, JITArrayMode, ECMAMode ecmaMode);
    void privateCompilePutByValWithCachedId(ByValInfo*, ReturnAddressPtr, PutKind, const Identifier&, ECMAMode ecmaMode);

    void privateCompilePutPrivateNameWithCachedId(ByValInfo*, ReturnAddressPtr, const Identifier&);

	void privateCompileHasIndexedProperty(ByValInfo*, ReturnAddressPtr, JITArrayMode);

	void privateCompilePatchGetArrayLength(ReturnAddressPtr returnAddress);

	// Add a call out from JIT code, without an exception check.
	ALWAYS_INLINE Call appendCall(const FunctionPtr& function)
	{
		Call functionCall = call();
		m_calls.constructAndAppend(functionCall, m_bytecodeOffset, function.value());
		return functionCall;
	}

	ALWAYS_INLINE void exceptionCheck(const Jump& jumpToHandler)
	{
		m_exceptionChecks.append(jumpToHandler);
	}

	ALWAYS_INLINE void exceptionCheck()
	{
		m_exceptionChecks.append(emitExceptionCheck());
	}

	ALWAYS_INLINE void exceptionCheckWithCallFrameRollback()
	{
		m_exceptionChecksWithCallFrameRollback.append(emitExceptionCheck());
	}

	void privateCompileExceptionHandlers();

	void addSlowCase(const Jump&);
	void addSlowCase(const JumpList&);
	void addSlowCase();
	void addJump(const Jump&, int);
    void addJump(const JumpList&, int);
	void emitJumpSlowToHot(Jump, int);

	void compileOpCall(OpcodeID, Instruction*, unsigned callLinkInfoIndex);
	void compileOpCallSlowCase(OpcodeID, Instruction*, Vector<SlowCaseEntry>::iterator&, unsigned callLinkInfoIndex);
	void compileLoadVarargs(Instruction*);
	void compileCallEval(Instruction*);
	void compileCallEvalSlowCase(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitPutCallResult(Instruction*);

    enum class CompileOpStrictEqType { StrictEq, NStrictEq };
    void compileOpStrictEq(Instruction*, CompileOpStrictEqType);
    void compileOpStrictEqJump(Instruction*, CompileOpStrictEqType);
    enum class CompileOpEqType { Eq, NEq };
    void compileOpEqJumpSlow(Vector<SlowCaseEntry>::iterator&, CompileOpEqType, int jumpTarget);
    bool isOperandConstantDouble(int src);

	void emitLoadDouble(int index, FPRegisterID value);
	void emitLoadInt32ToDouble(int index, FPRegisterID value);

	enum WriteBarrierMode { UnconditionalWriteBarrier, ShouldFilterImmediates };
	// value register in write barrier is used before any scratch registers
	// so may safely be the same as either of the scratch registers.
	void emitWriteBarrier(RegisterID owner, RegisterID valueTag, RegisterID scratch, RegisterID scratch2, WriteBarrierMode, WriteBarrierUseKind);
	void emitWriteBarrier(JSCell* owner, RegisterID value, RegisterID scratch, WriteBarrierMode, WriteBarrierUseKind);

	template<typename StructureType> // StructureType can be RegisterID or ImmPtr.
	void emitAllocateJSObject(RegisterID allocator, StructureType, RegisterID result, RegisterID scratch);

	// This assumes that the value to profile is in regT0 and that regT3 is available for
	// scratch.
	void emitValueProfilingSite(ValueProfile&, JSValueRegs);
	void emitValueProfilingSite(unsigned bytecodeOffset, JSValueRegs);
	void emitValueProfilingSite(JSValueRegs);
	void emitArrayProfilingSite(RegisterID structureAndIndexingType, ArrayProfile*);
	void emitArrayProfilingSiteForBytecodeIndex(RegisterID structureAndIndexingType, unsigned bytecodeIndex);
	void emitArrayProfileStoreToHoleSpecialCase(ArrayProfile*);
	void emitArrayProfileOutOfBoundsSpecialCase(ArrayProfile*);

	JITArrayMode chooseArrayMode(ArrayProfile*);

	// Property is in regT1, base is in regT0. regT2 contains indexing type.
	// Property is int-checked and zero extended. Base is cell checked.
	// Structure is already profiled. Returns the slow cases. Fall-through
	// case contains result in regT0, and it is not yet profiled.
	JumpList emitInt32Load(Instruction* instruction, PatchableJump& badType) { return emitContiguousLoad(instruction, badType, Int32Shape); }
	JumpList emitDoubleLoad(Instruction*, PatchableJump& badType);
	JumpList emitContiguousLoad(Instruction*, PatchableJump& badType, IndexingType expectedShape = ContiguousShape);
	JumpList emitArrayStorageLoad(Instruction*, PatchableJump& badType);
	JumpList emitLoadForArrayMode(Instruction*, JITArrayMode, PatchableJump& badType);

	JumpList emitInt32GetByVal(Instruction* instruction, PatchableJump& badType) { return emitContiguousGetByVal(instruction, badType, Int32Shape); }
	JumpList emitDoubleGetByVal(Instruction*, PatchableJump& badType);
	JumpList emitContiguousGetByVal(Instruction*, PatchableJump& badType, IndexingType expectedShape = ContiguousShape);
	JumpList emitArrayStorageGetByVal(Instruction*, PatchableJump& badType);
	JumpList emitDirectArgumentsGetByVal(Instruction*, PatchableJump& badType);
	JumpList emitScopedArgumentsGetByVal(Instruction*, PatchableJump& badType);
	JumpList emitIntTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType);
	JumpList emitFloatTypedArrayGetByVal(Instruction*, PatchableJump& badType, TypedArrayType);

#if 0
    template<typename Op>
    ECMAMode ecmaMode(Op);

    // Determines the type of private field access for a bytecode.
    template<typename Op>
    PrivateFieldPutKind privateFieldPutKind(Op);
#endif

    // Identifier check helper for GetByVal and PutByVal.
    void emitByValIdentifierCheck(ByValInfo*, RegisterID cell, RegisterID scratch, const Identifier&, JumpList& slowCases);

    JITPutByIdGenerator emitPutPrivateNameWithCachedId(ByValInfo* byValInfo, Instruction*, const Identifier&, JumpList& doneCases, JumpList& slowCases);

    JITGetByIdGenerator emitGetByValWithCachedId(ByValInfo*, Instruction*, const Identifier&, Jump& fastDoneCase, Jump& slowDoneCase, JumpList& slowCases);
    JITPutByIdGenerator emitPutByValWithCachedId(ByValInfo*, Instruction*, PutKind, const Identifier&, JumpList& doneCases, JumpList& slowCases);

	// Property is in regT1, base is in regT0. regT2 contains indecing type.
	// The value to store is not yet loaded. Property is int-checked and
	// zero-extended. Base is cell checked. Structure is already profiled.
	// returns the slow cases.
	JumpList emitInt32PutByVal(Instruction* currentInstruction, PatchableJump& badType)
	{
		return emitGenericContiguousPutByVal(currentInstruction, badType, Int32Shape);
	}
	JumpList emitDoublePutByVal(Instruction* currentInstruction, PatchableJump& badType)
	{
		return emitGenericContiguousPutByVal(currentInstruction, badType, DoubleShape);
	}
	JumpList emitContiguousPutByVal(Instruction* currentInstruction, PatchableJump& badType)
	{
		return emitGenericContiguousPutByVal(currentInstruction, badType);
	}
	JumpList emitGenericContiguousPutByVal(Instruction*, PatchableJump& badType, IndexingType indexingShape = ContiguousShape);
	JumpList emitArrayStoragePutByVal(Instruction*, PatchableJump& badType);
	JumpList emitIntTypedArrayPutByVal(Instruction*, PatchableJump& badType, TypedArrayType);
	JumpList emitFloatTypedArrayPutByVal(Instruction*, PatchableJump& badType, TypedArrayType);

	enum FinalObjectMode { MayBeFinal, KnownNotFinal };

    void emitGetVirtualRegister(int src, JSValueRegs dst);
    void emitPutVirtualRegister(int dst, JSValueRegs src);

    int32_t getOperandConstantInt(int src);
    double getOperandConstantDouble(int src);

#if USE(JSVALUE32_64)
	bool getOperandConstantImmediateInt(int op1, int op2, int& op, int32_t& constant);

	void emitLoadTag(int index, RegisterID tag);
	void emitLoadPayload(int index, RegisterID payload);

	void emitLoad(const JSValue& v, RegisterID tag, RegisterID payload);
	void emitLoad(int index, RegisterID tag, RegisterID payload);
	void emitLoad2(int index1, RegisterID tag1, RegisterID payload1, int index2, RegisterID tag2, RegisterID payload2);

	void emitStore(int index, RegisterID tag, RegisterID payload, RegisterID base = callFrameRegister);
	void emitStore(int index, const JSValue constant);
	void emitStoreInt32(int index, RegisterID payload, bool indexIsInt32 = false);
	void emitStoreInt32(int index, TrustedImm32 payload, bool indexIsInt32 = false);
	void emitStoreCell(int index, RegisterID payload, bool indexIsCell = false);
	void emitStoreBool(int index, RegisterID payload, bool indexIsBool = false);
	void emitStoreDouble(int index, FPRegisterID value);

	void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex);
	void emitJumpSlowCaseIfNotJSCell(int virtualRegisterIndex, RegisterID tag);

	void compileGetByIdHotPath(Identifier*);

	// Arithmetic opcode helpers
	void emitBinaryDoubleOp(OpcodeID, int dst, int op1, int op2, OperandTypes, JumpList& notInt32Op1, JumpList& notInt32Op2, bool op1IsInRegisters = true, bool op2IsInRegisters = true);

#else // USE(JSVALUE32_64)
	void emitGetVirtualRegister(int src, RegisterID dst);
	void emitGetVirtualRegisters(int src1, RegisterID dst1, int src2, RegisterID dst2);
	void emitPutVirtualRegister(int dst, RegisterID from = regT0);
	void emitStoreCell(int dst, RegisterID payload, bool /* only used in JSValue32_64 */ = false)
	{
		emitPutVirtualRegister(dst, payload);
	}
	void emitStoreCell(VirtualRegister dst, RegisterID payload)
	{
		emitPutVirtualRegister(dst, payload);
	}

	Jump emitJumpIfJSCell(RegisterID);
	Jump emitJumpIfBothJSCells(RegisterID, RegisterID, RegisterID);
	void emitJumpSlowCaseIfJSCell(RegisterID);
	void emitJumpSlowCaseIfNotJSCell(RegisterID);
	void emitJumpSlowCaseIfNotJSCell(RegisterID, int VReg);
	Jump emitJumpIfInt(RegisterID);
	Jump emitJumpIfNotInt(RegisterID);
	Jump emitJumpIfNotInt(RegisterID, RegisterID, RegisterID scratch);
    PatchableJump emitPatchableJumpIfNotImmediateInteger(RegisterID);
	void emitJumpSlowCaseIfNotInt(RegisterID);
	void emitJumpSlowCaseIfNotImmediateNumber(RegisterID);
	void emitJumpSlowCaseIfNotInt(RegisterID, RegisterID, RegisterID scratch);

	void emitFastArithReTagImmediate(RegisterID src, RegisterID dest);

	void emitTagBool(RegisterID reg);

	void compileGetByIdHotPath(int baseVReg, Identifier*);

#endif // USE(JSVALUE32_64)

	void emit_compareAndJump(OpcodeID, int op1, int op2, unsigned target, RelationalCondition);
	void emit_compareUnsigned(int dst, int op1, int op2, RelationalCondition);
	void emit_compareUnsignedAndJump(int op1, int op2, unsigned target, RelationalCondition);
    void emit_compareAndJumpSlow(int op1, int op2, unsigned target, DoubleCondition, size_t (JIT_OPERATION *operation)(ExecState*, EncodedJSValue, EncodedJSValue), bool invert, Vector<SlowCaseEntry>::iterator&);

	void assertStackPointerOffset();

	void emit_op_add(Instruction*);
	void emit_op_bitand(Instruction*);
	void emit_op_bitor(Instruction*);
	void emit_op_bitxor(Instruction*);
    void emit_op_bitnot(Instruction*);
	void emit_op_call(Instruction*);
	void emit_op_call_eval(Instruction*);
	void emit_op_call_varargs(Instruction*);
	void emit_op_construct_varargs(Instruction*);
	void emit_op_catch(Instruction*);
	void emit_op_construct(Instruction*);
	void emit_op_create_this(Instruction*);
	void emit_op_to_this(Instruction*);
	void emit_op_get_argument(Instruction*);
	void emit_op_argument_count(Instruction*);
    void emit_op_get_rest_length(Instruction*);
	void emit_op_check_tdz(Instruction*);
    void emit_op_identity_with_profile(Instruction*);
    void emit_op_unreachable(Instruction*);
	void emit_op_debug(Instruction*);
	void emit_op_del_by_id(Instruction*);
	void emit_op_del_by_val(Instruction*);
	void emit_op_div(Instruction*);
	void emit_op_end(Instruction*);
	void emit_op_enter(Instruction*);
	void emit_op_get_scope(Instruction*);
	void emit_op_eq(Instruction*);
	void emit_op_eq_null(Instruction*);
    void emit_op_below(Instruction*);
    void emit_op_beloweq(Instruction*);
	void emit_op_try_get_by_id(Instruction*);
	void emit_op_get_by_id(Instruction*);
	void emit_op_get_by_id_with_this(Instruction*);
    void emit_op_get_by_id_direct(Instruction*);
	void emit_op_get_by_val(Instruction*);
    void emit_op_get_private_name(Instruction*);
    void emit_op_set_private_brand(const Instruction*);
    void emit_op_check_private_brand(const Instruction*);
	void emit_op_get_argument_by_val(Instruction*);
    void emit_op_get_prototype_of(Instruction*);
	void emit_op_init_lazy_reg(Instruction*);
	void emit_op_overrides_has_instance(Instruction*);
	void emit_op_instanceof(Instruction*);
	void emit_op_instanceof_custom(Instruction*);
	void emit_op_is_empty(Instruction*);
	void emit_op_typeof_is_undefined(Instruction*);
    void emit_op_is_undefined_or_null(const Instruction*);
	void emit_op_is_boolean(Instruction*);
	void emit_op_is_number(Instruction*);
#if USE(BIGINT32)
	void emit_op_is_big_int(const Instruction*);
#else
	void emit_op_is_big_int(const Instruction*);
#endif
	void emit_op_is_object(Instruction*);
    void emit_op_is_cell_with_type(Instruction*);
	void emit_op_jeq_null(Instruction*);
	void emit_op_jfalse(Instruction*);
	void emit_op_jmp(Instruction*);
	void emit_op_jneq_null(Instruction*);
    void emit_op_jundefined_or_null(const Instruction*);
    void emit_op_jnundefined_or_null(const Instruction*);
	void emit_op_jneq_ptr(Instruction*);
	void emit_op_jless(Instruction*);
	void emit_op_jlesseq(Instruction*);
	void emit_op_jgreater(Instruction*);
	void emit_op_jgreatereq(Instruction*);
	void emit_op_jnless(Instruction*);
	void emit_op_jnlesseq(Instruction*);
	void emit_op_jngreater(Instruction*);
	void emit_op_jngreatereq(Instruction*);
    void emit_op_jeq(Instruction*);
    void emit_op_jneq(Instruction*);
    void emit_op_jstricteq(Instruction*);
    void emit_op_jnstricteq(Instruction*);
    void emit_op_jbelow(Instruction*);
    void emit_op_jbeloweq(Instruction*);
	void emit_op_jtrue(Instruction*);
	void emit_op_loop_hint(Instruction*);
	void emit_op_lshift(Instruction*);
	void emit_op_nop(Instruction*);
	void emit_op_mod(Instruction*);
	void emit_op_mov(Instruction*);
	void emit_op_mul(Instruction*);
	void emit_op_negate(Instruction*);
	void emit_op_neq(Instruction*);
	void emit_op_neq_null(Instruction*);
	void emit_op_new_array(Instruction*);
	void emit_op_new_array_with_size(Instruction*);
    void emit_op_new_array_with_spread(Instruction*);
    void emit_op_spread(Instruction*);
	void emit_op_new_func(Instruction*);
	void emit_op_new_func_exp(Instruction*);
	void emit_op_new_generator_func(Instruction*);
	void emit_op_new_generator_func_exp(Instruction*);
    void emit_op_new_async_func(Instruction*);
    void emit_op_new_async_func_exp(Instruction*);
    void emit_op_new_async_generator_func(Instruction*);
    void emit_op_new_async_generator_func_exp(Instruction*);
	void emit_op_new_object(Instruction*);
	void emit_op_new_regexp(Instruction*);
	void emit_op_not(Instruction*);
	void emit_op_nstricteq(Instruction*);
	void emit_op_dec(Instruction*);
	void emit_op_inc(Instruction*);
	void emit_op_profile_did_call(Instruction*);
	void emit_op_profile_will_call(Instruction*);
	void emit_op_get_parent_scope(Instruction*);
	void emit_op_put_by_id(Instruction*);
	void emit_op_put_by_val(Instruction*);
    void emit_op_put_private_name(Instruction*);
	void emit_op_put_getter_by_id(Instruction*);
	void emit_op_put_setter_by_id(Instruction*);
	void emit_op_put_getter_setter(Instruction*);
	void emit_op_put_getter_by_val(Instruction*);
	void emit_op_put_setter_by_val(Instruction*);
    void emit_op_define_data_property(Instruction*);
    void emit_op_define_accessor_property(Instruction*);
	void emit_op_ret(Instruction*);
	void emit_op_rshift(Instruction*);
	void emit_op_set_function_name(Instruction*);
	void emit_op_stricteq(Instruction*);
	void emit_op_sub(Instruction*);
	void emit_op_switch_char(Instruction*);
	void emit_op_switch_imm(Instruction*);
	void emit_op_switch_string(Instruction*);
	void emit_op_throw(Instruction*);
	void emit_op_to_number(Instruction*);
    void emit_op_to_numeric(Instruction*);
	void emit_op_to_string(Instruction*);
    void emit_op_to_object(Instruction*);
	void emit_op_to_primitive(Instruction*);
	void emit_op_unexpected_load(Instruction*);
	void emit_op_unsigned(Instruction*);
	void emit_op_urshift(Instruction*);
    void emit_op_has_enumerable_indexed_property(Instruction*);
    void emit_op_has_enumerable_structure_property(Instruction*);
	void emit_op_get_direct_pname(Instruction*);
	void emit_op_enumerator_structure_pname(Instruction*);
	void emit_op_enumerator_generic_pname(Instruction*);
    void emit_op_to_property_key(const Instruction*);

	void emitSlow_op_add(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_bitnot(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_bitand(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_bitor(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_bitxor(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_call(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_call_eval(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_call_varargs(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_construct_varargs(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_construct(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_this(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_create_this(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_check_tdz(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_div(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_eq(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_try_get_by_id(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_by_id(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_by_id_with_this(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_by_id_direct(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_arguments_length(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_private_name(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_set_private_brand(const Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_check_private_brand(const Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_argument_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_prototype_of(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_instanceof(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_instanceof_custom(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jless(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jlesseq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jgreater(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jgreatereq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jnless(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jnlesseq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jngreater(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jngreatereq(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_jeq(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_jneq(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_jstricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_jnstricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_jtrue(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_loop_hint(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_lshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_mod(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_mul(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_negate(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_neq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_new_object(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_not(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_nstricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_dec(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_inc(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_put_by_id(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_put_by_val(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_put_private_name(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_rshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_stricteq(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_sub(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_number(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_numeric(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_string(Instruction*, Vector<SlowCaseEntry>::iterator&);
    void emitSlow_op_to_object(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_primitive(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_unsigned(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_urshift(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_has_enumerable_indexed_property(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_has_enumerable_structure_property(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_direct_pname(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_to_property_key(Instruction*, Vector<SlowCaseEntry>::iterator&);

	void emit_op_resolve_scope(Instruction*);
    void emit_op_resolve_scope_for_hoisting_func_decl_in_eval(Instruction*);
	void emit_op_get_from_scope(Instruction*);
	void emit_op_put_to_scope(Instruction*);
	void emit_op_get_from_arguments(Instruction*);
	void emit_op_put_to_arguments(Instruction*);
	void emitSlow_op_resolve_scope(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_get_from_scope(Instruction*, Vector<SlowCaseEntry>::iterator&);
	void emitSlow_op_put_to_scope(Instruction*, Vector<SlowCaseEntry>::iterator&);

	void emitRightShift(Instruction*, bool isUnsigned);
	void emitRightShiftSlowCase(Instruction*, Vector<SlowCaseEntry>::iterator&, bool isUnsigned);

	void emitNewFuncCommon(Instruction*);
	void emitNewFuncExprCommon(Instruction*);
	void emitVarInjectionCheck(bool needsVarInjectionChecks);
    void emitVarReadOnlyCheck(ResolveType);
	void emitResolveClosure(int dst, int scope, bool needsVarInjectionChecks, unsigned depth);
	void emitLoadWithStructureCheck(int scope, Structure** structureSlot);
#if USE(JSVALUE64)
	void emitGetVarFromPointer(JSValue* operand, GPRReg);
	void emitGetVarFromIndirectPointer(JSValue** operand, GPRReg);
#else
	void emitGetVarFromIndirectPointer(JSValue** operand, GPRReg tag, GPRReg payload);
	void emitGetVarFromPointer(JSValue* operand, GPRReg tag, GPRReg payload);
#endif
	void emitGetClosureVar(int scope, uintptr_t operand);
	void emitNotifyWrite(WatchpointSet*);
	void emitNotifyWrite(GPRReg pointerToSet);
	void emitPutGlobalVariable(JSValue* operand, int value, WatchpointSet*);
	void emitPutGlobalVariableIndirect(JSValue** addressOfOperand, int value, WatchpointSet**);
	void emitPutClosureVar(int scope, uintptr_t operand, int value, WatchpointSet*);

	void emitInitRegister(int dst);

	void emitPutIntToCallFrameHeader(RegisterID from, JSStack::CallFrameHeaderEntry);
	void emitGetFromCallFrameHeaderPtr(JSStack::CallFrameHeaderEntry entry, RegisterID to, RegisterID from = callFrameRegister);
	void emitGetFromCallFrameHeader32(JSStack::CallFrameHeaderEntry entry, RegisterID to, RegisterID from = callFrameRegister);
#if USE(JSVALUE64)
	void emitGetFromCallFrameHeader64(JSStack::CallFrameHeaderEntry, RegisterID to, RegisterID from = callFrameRegister);
#endif

	JSValue getConstantOperand(int src);
	bool isOperandConstantInt(int src);
	bool isOperandConstantImmediateInt(int src) { return isOperandConstantInt(src); }
	bool isOperandConstantImmediateChar(int src);

    template <typename Generator, typename ProfiledFunction, typename NonProfiledFunction>
    void emitMathICFast(JITUnaryMathIC<Generator>*, Instruction*, ProfiledFunction, NonProfiledFunction);
    template <typename Generator, typename ProfiledFunction, typename NonProfiledFunction>
    void emitMathICFast(JITBinaryMathIC<Generator>*, Instruction*, ProfiledFunction, NonProfiledFunction);

    template <typename Generator, typename ProfiledRepatchFunction, typename ProfiledFunction, typename RepatchFunction>
    void emitMathICSlow(JITBinaryMathIC<Generator>*, Instruction*, ProfiledRepatchFunction, ProfiledFunction, RepatchFunction);
    template <typename Generator, typename ProfiledRepatchFunction, typename ProfiledFunction, typename RepatchFunction>
    void emitMathICSlow(JITUnaryMathIC<Generator>*, Instruction*, ProfiledRepatchFunction, ProfiledFunction, RepatchFunction);

	Jump getSlowCase(Vector<SlowCaseEntry>::iterator& iter)
	{
		return iter++->from;
	}
	void linkSlowCase(Vector<SlowCaseEntry>::iterator& iter)
	{
        if (iter->from.isSet())
        	iter->from.link(this);
		++iter;
	}
	void linkSlowCaseIfNotJSCell(Vector<SlowCaseEntry>::iterator&, int virtualRegisterIndex);
	ALWAYS_INLINE void linkAllSlowCasesForBytecodeOffset(Vector<SlowCaseEntry>& slowCases,
		Vector<SlowCaseEntry>::iterator&, unsigned bytecodeOffset);

	ALWAYS_INLINE void linkAllSlowCases(Vector<SlowCaseEntry>::iterator& iter)
	{
		linkAllSlowCasesForBytecodeOffset(m_slowCases, iter, m_bytecodeOffset);
	}

	MacroAssembler::Call appendCallWithExceptionCheck(const FunctionPtr&);
	MacroAssembler::Call appendCallWithCallFrameRollbackOnException(const FunctionPtr&);
	MacroAssembler::Call appendCallWithExceptionCheckSetJSValueResult(const FunctionPtr&, int);
	MacroAssembler::Call appendCallWithExceptionCheckSetJSValueResultWithProfile(const FunctionPtr&, int);

	enum WithProfileTag { WithProfile };

	MacroAssembler::Call callOperation(C_JITOperation_E);
	MacroAssembler::Call callOperation(C_JITOperation_EO, GPRReg);
	MacroAssembler::Call callOperation(C_JITOperation_EL, GPRReg);
	MacroAssembler::Call callOperation(C_JITOperation_EL, TrustedImmPtr);
	MacroAssembler::Call callOperation(C_JITOperation_ESt, Structure*);
    MacroAssembler::Call callOperation(C_JITOperation_EC, JSCell*);
	MacroAssembler::Call callOperation(C_JITOperation_EZ, int32_t);
	MacroAssembler::Call callOperation(F_JITOperation_EJZZ, GPRReg, int32_t, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_E, int);
	MacroAssembler::Call callOperation(J_JITOperation_EAapJ, int, ArrayAllocationProfile*, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EAapJcpZ, int, ArrayAllocationProfile*, GPRReg, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_EAapJcpZ, int, ArrayAllocationProfile*, const JSValue*, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_EC, int, JSCell*);
	MacroAssembler::Call callOperation(J_JITOperation_EJ, int, GPRReg);
    MacroAssembler::Call callOperation(J_JITOperation_EJ, JSValueRegs, JSValueRegs);
#if USE(JSVALUE64)
	MacroAssembler::Call callOperation(J_JITOperation_ESsiJI, int, StructureStubInfo*, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_ESsiJI, int, StructureStubInfo*, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(J_JITOperation_ESsiJJ, int, StructureStubInfo*, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_ESsiJJI, int, StructureStubInfo*, GPRReg, GPRReg, UniquedStringImpl*);
#else
	MacroAssembler::Call callOperation(J_JITOperation_ESsiJI, int, StructureStubInfo*, GPRReg, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_ESsiJI, int, StructureStubInfo*, GPRReg, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(J_JITOperation_ESsiJJ, int, StructureStubInfo*, JSValueRegs, JSValueRegs);
	MacroAssembler::Call callOperation(J_JITOperation_ESsiJJ, int, StructureStubInfo*, GPRReg, GPRReg, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_ESsiJJI, int, StructureStubInfo*, GPRReg, GPRReg, GPRReg, GPRReg, UniquedStringImpl*);
#endif
	MacroAssembler::Call callOperation(J_JITOperation_EJI, int, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJI, int, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(J_JITOperation_EJJ, int, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EJArp, JSValueRegs, JSValueRegs, ArithProfile*);
	MacroAssembler::Call callOperation(Z_JITOperation_EJOJ, GPRReg, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(C_JITOperation_EJsc, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EJscC, int, GPRReg, JSCell*);
	MacroAssembler::Call callOperation(J_JITOperation_EJscCJ, int, GPRReg, JSCell*, GPRReg);
	MacroAssembler::Call callOperation(C_JITOperation_EJscZ, GPRReg, int32_t);
	MacroAssembler::Call callOperation(C_JITOperation_EJscZ, int, GPRReg, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_EJJAp, int, GPRReg, GPRReg, ArrayProfile*);
	MacroAssembler::Call callOperation(J_JITOperation_EJJBy, int, GPRReg, GPRReg, ByValInfo*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJJAp, int, GPRReg, GPRReg, ArrayProfile*);
#if USE(JSVALUE64)
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJJ, int, GPRReg, GPRReg);
#else
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJJ, int, GPRReg, GPRReg, GPRReg, GPRReg);
#endif
	MacroAssembler::Call callOperation(J_JITOperation_EP, int, void*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EPc, int, Instruction*);
	MacroAssembler::Call callOperation(J_JITOperation_EPc, int, Instruction*);
	MacroAssembler::Call callOperation(J_JITOperation_EZ, int, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_EZZ, int, int32_t, int32_t);
	MacroAssembler::Call callOperation(P_JITOperation_EJS, GPRReg, size_t);
	MacroAssembler::Call callOperation(P_JITOperation_EZ, int32_t);
	MacroAssembler::Call callOperation(S_JITOperation_ECC, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(S_JITOperation_EJ, RegisterID);
	MacroAssembler::Call callOperation(S_JITOperation_EJI, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(S_JITOperation_EJJ, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(S_JITOperation_EOJss, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_E);
	MacroAssembler::Call callOperation(V_JITOperation_EC, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_ECC, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_ECIZC, RegisterID, UniquedStringImpl*, int32_t, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_ECIZCC, RegisterID, UniquedStringImpl*, int32_t, RegisterID, RegisterID);
#if USE(JSVALUE64)
	MacroAssembler::Call callOperation(V_JITOperation_ECJZC, RegisterID, RegisterID, int32_t, RegisterID);
#else
	MacroAssembler::Call callOperation(V_JITOperation_ECJZC, RegisterID, RegisterID, RegisterID, int32_t, RegisterID);
#endif
	MacroAssembler::Call callOperation(V_JITOperation_EZSymtabJ, int, SymbolTable*, RegisterID);
	MacroAssembler::Call callOperation(J_JITOperation_EZSymtabJ, int, SymbolTable*, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EJ, RegisterID);
    MacroAssembler::Call callOperationNoExceptionCheck(Z_JITOperation_E);
    MacroAssembler::Call callOperationNoExceptionCheck(Z_JITOperation_EVm, VM*);
#if USE(JSVALUE64)
	MacroAssembler::Call callOperationNoExceptionCheck(V_JITOperation_EJ, RegisterID);
#else
	MacroAssembler::Call callOperationNoExceptionCheck(V_JITOperation_EJ, RegisterID, RegisterID);
#endif
	MacroAssembler::Call callOperation(V_JITOperation_EJZJ, RegisterID, int32_t, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EJZ, RegisterID, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJ, RegisterID, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(J_JITOperation_EJJArp, JSValueRegs, JSValueRegs, JSValueRegs, ArithProfile*);
	MacroAssembler::Call callOperation(J_JITOperation_EJJ, JSValueRegs, JSValueRegs, JSValueRegs);
	MacroAssembler::Call callOperation(J_JITOperation_EJMic, JSValueRegs, JSValueRegs, TrustedImmPtr);
	MacroAssembler::Call callOperation(J_JITOperation_EJJMic, JSValueRegs, JSValueRegs, JSValueRegs, TrustedImmPtr);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJAp, RegisterID, RegisterID, RegisterID, ArrayProfile*);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJBy, RegisterID, RegisterID, RegisterID, ByValInfo*);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJByZ, RegisterID, RegisterID, RegisterID, ByValInfo*, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EPc, Instruction*);
	MacroAssembler::Call callOperation(V_JITOperation_EZ, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EZJ, int, GPRReg);
#if USE(JSVALUE64)
	MacroAssembler::Call callOperation(F_JITOperation_EFJJZ, RegisterID, RegisterID, RegisterID, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EJJI, RegisterID, RegisterID, UniquedStringImpl*);
	MacroAssembler::Call callOperation(V_JITOperation_ESsiJJ, StructureStubInfo*, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_ESsiJJI, StructureStubInfo*, RegisterID, RegisterID, UniquedStringImpl*);
    MacroAssembler::Call callOperation(V_JITOperation_ECIZJJ, RegisterID, UniquedStringImpl*, int32_t, RegisterID, RegisterID);
    MacroAssembler::Call callOperation(V_JITOperation_ECJ, RegisterID, RegisterID);
#else
    MacroAssembler::Call callOperation(V_JITOperation_EJJI, RegisterID, RegisterID, RegisterID, RegisterID, UniquedStringImpl*);
	MacroAssembler::Call callOperation(V_JITOperation_ESsiJJ, StructureStubInfo*, JSValueRegs, JSValueRegs);
	MacroAssembler::Call callOperation(V_JITOperation_ESsiJJI, StructureStubInfo*, RegisterID, RegisterID, RegisterID, RegisterID, UniquedStringImpl*);
	MacroAssembler::Call callOperation(V_JITOperation_ECJ, RegisterID, RegisterID, RegisterID);
#endif
	MacroAssembler::Call callOperationWithCallFrameRollbackOnException(J_JITOperation_E);
	MacroAssembler::Call callOperationWithCallFrameRollbackOnException(V_JITOperation_ECb, CodeBlock*);
	MacroAssembler::Call callOperationWithCallFrameRollbackOnException(Z_JITOperation_E);
#if USE(JSVALUE32_64)
	MacroAssembler::Call callOperation(F_JITOperation_EFJJZ, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, int32_t);
	MacroAssembler::Call callOperation(F_JITOperation_EJZZ, GPRReg, GPRReg, int32_t, int32_t);
	MacroAssembler::Call callOperation(J_JITOperation_EAapJ, int, ArrayAllocationProfile*, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EJ, int, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(Z_JITOperation_EJOJ, GPRReg, GPRReg, GPRReg, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EJI, int, GPRReg, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJI, int, GPRReg, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(J_JITOperation_EJJ, int, GPRReg, GPRReg, GPRReg, GPRReg);
	MacroAssembler::Call callOperation(J_JITOperation_EJJAp, int, GPRReg, GPRReg, GPRReg, GPRReg, ArrayProfile*);
	MacroAssembler::Call callOperation(J_JITOperation_EJJBy, int, GPRReg, GPRReg, GPRReg, GPRReg, ByValInfo*);
	MacroAssembler::Call callOperation(WithProfileTag, J_JITOperation_EJJAp, int, GPRReg, GPRReg, GPRReg, GPRReg, ArrayProfile*);
	MacroAssembler::Call callOperation(P_JITOperation_EJS, GPRReg, GPRReg, size_t);
	MacroAssembler::Call callOperation(S_JITOperation_EJ, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(S_JITOperation_EJI, GPRReg, GPRReg, UniquedStringImpl*);
	MacroAssembler::Call callOperation(S_JITOperation_EJJ, RegisterID, RegisterID, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(S_JITOperation_EJJ, JSValueRegs, JSValueRegs);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJ, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJAp, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, ArrayProfile*);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJBy, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, ByValInfo*);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJByZ, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, RegisterID, ByValInfo*, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EJJJByZ, JSValueRegs, JSValueRegs, JSValueRegs, ByValInfo*, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EJ, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EZSymtabJ, int, SymbolTable*, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EJZ, RegisterID, RegisterID, int32_t);
	MacroAssembler::Call callOperation(V_JITOperation_EJZJ, RegisterID, RegisterID, int32_t, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(V_JITOperation_EZJ, int32_t, RegisterID, RegisterID);
	MacroAssembler::Call callOperation(J_JITOperation_EJscCJ, int, GPRReg, JSCell*, GPRReg, GPRReg);
#endif

    enum class ProfilingPolicy {
        ShouldEmitProfiling,
        NoProfiling
    };

    template<typename SnippetGenerator>
    void emitBitBinaryOpFastPath(Instruction* currentInstruction, ProfilingPolicy shouldEmitProfiling = ProfilingPolicy::NoProfiling);

    void emitRightShiftFastPath(Instruction* currentInstruction, OpcodeID);

	Jump checkStructure(RegisterID reg, Structure* structure);

	void restoreArgumentReferenceForTrampoline();
	void updateTopCallFrame();

	Call emitNakedCall(CodePtr function = CodePtr());

	// Loads the character value of a single character string into dst.
	void emitLoadCharacterString(RegisterID src, RegisterID dst, JumpList& failures);

#if ENABLE(DFG_JIT)
	void emitEnterOptimizationCheck();
#else
	void emitEnterOptimizationCheck() { }
#endif

#ifndef NDEBUG
	void printBytecodeOperandTypes(int src1, int src2);
#endif

#if ENABLE(SAMPLING_FLAGS)
	void setSamplingFlag(int32_t);
	void clearSamplingFlag(int32_t);
#endif

#if ENABLE(SAMPLING_COUNTERS)
	void emitCount(AbstractSamplingCounter&, int32_t = 1);
#endif

#if ENABLE(OPCODE_SAMPLING)
	void sampleInstruction(Instruction*, bool = false);
#endif

#if ENABLE(CODEBLOCK_SAMPLING)
	void sampleCodeBlock(CodeBlock*);
#else
	void sampleCodeBlock(CodeBlock*) {}
#endif

#if ENABLE(DFG_JIT)
	bool canBeOptimized() { return m_canBeOptimized; }
	bool canBeOptimizedOrInlined() { return m_canBeOptimizedOrInlined; }
	bool shouldEmitProfiling() { return m_shouldEmitProfiling; }
#else
	bool canBeOptimized() { return false; }
	bool canBeOptimizedOrInlined() { return false; }
	// Enables use of value profiler with tiered compilation turned off,
	// in which case all code gets profiled.
	bool shouldEmitProfiling() { return false; }
#endif

	Interpreter* m_interpreter;

	Vector<CallRecord> m_calls;
	Vector<Label> m_labels;
	Vector<JITGetByIdGenerator> m_getByIds;
    Vector<JITGetByIdWithThisGenerator> m_getByIdsWithThis;
	Vector<JITPutByIdGenerator> m_putByIds;
    Vector<JITInstanceOfGenerator> m_instanceOfs;
	Vector<ByValCompilationInfo> m_byValCompilationInfo;
	Vector<CallCompilationInfo> m_callCompilationInfo;
	Vector<JumpTable> m_jmpTable;

	unsigned m_bytecodeOffset;
	Vector<SlowCaseEntry> m_slowCases;
	Vector<SwitchRecord> m_switches;

	unsigned m_getByIdIndex;
    unsigned m_getByIdWithThisIndex;
	unsigned m_putByIdIndex;
    unsigned m_instanceOfIndex;
	unsigned m_byValInstructionIndex;
	unsigned m_callLinkInfoIndex;

	bool m_canBeOptimized;
	bool m_canBeOptimizedOrInlined;
	bool m_shouldEmitProfiling;

	bool m_enableGetByIdIC;
	bool m_enableByValIC;
	bool m_forceTryGetByIdICFailure;

	bool m_enablePutByIdIC;
	bool m_enableInstanceOfIC;

	JumpList m_exceptionChecks;
	JumpList m_exceptionChecksWithCallFrameRollback;
    Label m_exceptionHandler;

    HashMap<Instruction*, void*> m_instructionToMathIC;
    HashMap<Instruction*, MathICGenerationState> m_instructionToMathICGenerationState;

#if ENABLE_JIT_PROFILE
	unsigned m_opCounts[numOpcodeIDs];
	unsigned m_slowOpCounts[numOpcodeIDs];

	unsigned m_opCodeSizes[numOpcodeIDs];
	unsigned m_slowCodeSizes[numOpcodeIDs];
#endif
} JIT_CLASS_ALIGNMENT;

} // namespace JSC

namespace WTF {

template <> struct VectorTraits<JSC::ByValCompilationInfo> : VectorTraitsBase<false, void>
{
    static const bool canInitializeWithMemset = false; // AssemblerLabel initializes offset to uint32_t::max.
    static const bool canMoveWithMemcpy = true;
    static const bool canCompareWithMemcmp = true;
};
template <> struct VectorTraits<JSC::CallCompilationInfo> : VectorTraitsBase<false, void>
{
    static const bool canInitializeWithMemset = false; // AssemblerLabel initializes offset to uint32_t::max.
    static const bool canMoveWithMemcpy = true;
    static const bool canCompareWithMemcmp = true;
};
template <> struct VectorTraits<JSC::CallRecord> : VectorTraitsBase<false, void>
{
    static const bool canInitializeWithMemset = false; // AssemblerLabel initializes offset to uint32_t::max.
    static const bool canMoveWithMemcpy = true;
    static const bool canCompareWithMemcmp = true;
};
template <> struct VectorTraits<JSC::JumpTable> : VectorTraitsBase<false, void>
{
    static const bool canInitializeWithMemset = false; // Jump default constructor does nothing.
    static const bool canMoveWithMemcpy = true;
    static const bool canCompareWithMemcmp = true;
};
template <> struct VectorTraits<JSC::SlowCaseEntry> : VectorTraitsBase<false, void>
{
    static const bool canInitializeWithMemset = false; // Jump default constructor does nothing.
    static const bool canMoveWithMemcpy = true;
    static const bool canCompareWithMemcmp = true;
};
template <> struct VectorTraits<JSC::SwitchRecord> : SimpleClassVectorTraits { };

} // namespace WTF

// #endif // ENABLE(JIT)
