#pragma once
#include <cstdint>
#include <wtf/Assertions.h>
namespace JSC {
class VM;
namespace DFG {
struct DoesGCCheck {
enum class Special {
Uninitialized,
DFGOSRExit,
FTLOSRExit,
NumberOfSpecials
};
DoesGCCheck()
: m_value(encode(true, Special::Uninitialized))
{ }
static uint32_t encode(bool expectDoesGC, unsigned nodeIndex, unsigned nodeOp)
{
ASSERT((nodeIndex << nodeIndexShift) >> nodeIndexShift == nodeIndex);
return nodeIndex << nodeIndexShift | nodeOp << nodeOpShift | bits(expectDoesGC);
}
static uint32_t encode(bool expectDoesGC, Special special)
{
return bits(special) << specialShift | isSpecialBit | bits(expectDoesGC);
}
void set(bool expectDoesGC, unsigned nodeIndex, unsigned nodeOp)
{
m_value = encode(expectDoesGC, nodeIndex, nodeOp);
}
void set(bool expectDoesGC, Special special)
{
m_value = encode(expectDoesGC, special);
}
bool expectDoesGC() const { return m_value & expectDoesGCBit; }
bool isSpecial() const { return m_value & isSpecialBit; }
Special special() { return static_cast<Special>(m_value >> specialShift); }
unsigned nodeOp() { return (m_value >> nodeOpShift) & nodeOpMask; }
unsigned nodeIndex() { return m_value >> nodeIndexShift; }
JS_EXPORT_PRIVATE void verifyCanGC(VM&);
private:
template<typename T> static uint32_t bits(T value) { return static_cast<uint32_t>(value); }
static constexpr unsigned expectDoesGCBit = 1 << 0;
static constexpr unsigned isSpecialBit = 1 << 1;
static constexpr unsigned commonBits = 2;
static_assert((expectDoesGCBit | isSpecialBit) == (1 << commonBits) - 1);
static constexpr unsigned specialShift = commonBits;
static constexpr unsigned nodeOpBits = 9;
static constexpr unsigned nodeOpMask = (1 << nodeOpBits) - 1;
static constexpr unsigned nodeOpShift = commonBits;
static constexpr unsigned nodeIndexBits = 21;
static constexpr unsigned nodeIndexShift = nodeOpShift + nodeOpBits;
static_assert(nodeIndexShift + nodeIndexBits == 32);
uint32_t m_value { 0 };
};
}
using DFG::DoesGCCheck;
}